Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^7: How would you indent this?

by no longer just digit (Beadle)
on Mar 18, 2021 at 23:04 UTC ( [id://11129931]=note: print w/replies, xml ) Need Help??


in reply to Re^6: How would you indent this?
in thread How would you indent this?

Quoth Rolf:
The OP is using a function which is not standard indenting, hitting TAB is.°

I quite categorically am using the standard indenting of cperl-mode. Copy the original example into a file called, say "test.pl", then edit with emacs -Q test.pl, and take the following sequence of instructions:

M-X cperl-mode C-SPC M-> M-C-\
gives me (copy-pasting from Emacs window):
my @headings = ( { key => 'k', name => 'Kanji', class => 'kanji'}, { key => 'skip', name => 'SKIP', class => 'skip-code'}, { key => 'co', name => 'Suggestion', class => 'skip-code'}, { key => 'disc', name => 'Discussion'}, );

The version of Emacs I am using is as follows:

GNU Emacs 27.1 (build 1, i386-portbld-freebsd12.1, GTK+ Version 3.24.2 +4, cairo version 1.16.0) Copyright (C) 2020 Free Software Foundation, Inc.

The cperl-mode is the default supplied with the above.

Replies are listed 'Best First'.
Re^8: How would you indent this?
by LanX (Saint) on Mar 19, 2021 at 12:48 UTC
    Hi

    M-C-\ is supposed to run indent-region resp. cperl-indent-region right?

    (Running C-h k will show the function bound to a key-combi)

    Guess what, I can't even activate this key-combination on my laptop with Windows + German keyboard with remapped CTRL.° (I'm too lazy to figure out why)

    I'm using emacs since university, it's only a few years I'm even actively using indent-region (and only since I remapped a closing curly } to run it automatically on the Perl block)

    Now if you take 100 average emacs hackers, how many will know indent-region ? I bet all will know TAB .

    indent-region is not even in the menus of emacs, cperl-mode is adding it's own version when activated.

    That's why I couldn't replicate your problem at first.

    Now from the docs of indent-region (all demos with 'emacs27 -Q')

    C-h f indent-region ... 3) Indent each line via ‘indent-according-to-mode’. ...

    from here on you can click on the links and navigate back with l (last)

    (indent-according-to-mode) Indent line in proper way for current major mode. *Normally*, this is done by calling the function specified by the variable ‘indent-line-function’.

    indent-line-function is a variable defined in ‘indent.el’. ... Setting this function is all you need to make TAB indent appropriately +. ...

    as you can see the default behavior is supposed to be that of TAB in a single line.

    Cperl-mode extended regional indentation with line-breaks for {blocks}

    And that feature is biting you with nested hashes.

    > The cperl-mode is the default supplied with the above.

    you are contradicting yourself since your recipe says M-x cperl-mode

    Emacs default is still perl-mode

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

    °) And here we are at the very heart why many vimmers hate emacs - byzantine hotkeys. Which gets even worse with non US keyboards. A problem shared by Perl's sigils.

      > Which get even worse with non US keyboards

      With Emacs, the solution can be easy. I use the US keyboard and switch the Emacs input method (C-\) to Czech when I need to type Czech characters - but all the hotkeys still work.

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      I'm using emacs since university,...

      I guess this is part of the problem. Emacs isn't the same as it was back then.

      I bet all will know TAB

      Sure. Users of Org mode use it to cycle entry visibility, or to proceed to the next field in an Org table. Practically every input in the minibuffer uses <TAB> for completion. Younger users see using <TAB> for indentation of a single line as a relic from the distant past.

      Now from the docs of indent-region (all demos with 'emacs27 -Q')
      C-h f indent-region ... 3) Indent each line via ‘indent-according-to-mode’. ...

      I guess you deliberately left out the relevant paragraph here?

      2) If ‘indent-region-function’ is non-nil, call that function to indent the region.

      CPerl mode does set ‘indent-region-function’ to cperl-indent-region, so option 3) from your quote is irrelevant in CPerl mode. The docstring for cperl-indent-region ends with:

      If ‘cperl-indent-region-fix-constructs’, will improve spacing on conditional/loop constructs.

      Well, some might disagree on "improve" in our case, which is neither a conditional nor a loop. And this is why I call the current behavior a bug.

      > The cperl-mode is the default supplied with the above.

      you are contradicting yourself since your recipe says M-x cperl-mode

      Emacs default is still perl-mode

      This is close to trolling. Emacs supplies cperl-mode and it should be obvious that "default" refers to this version, as opposed to one of the various clones from GitHub and other repos. The author did not claim that cperl-mode is Emacs' default for opening Perl sources.

        > This is close to trolling.

        and this is close to BS...

        I think it's better to stop here.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11129931]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-19 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found