Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^6: How would you indent this?

by LanX (Saint)
on Mar 18, 2021 at 20:48 UTC ( [id://11129920]=note: print w/replies, xml ) Need Help??


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

> Is it that it is emacs?

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

This function offers plenty of interactive real-time benefits, without needing to wait 2 sec till a Perl::Tidy background process returned.

Komodo has nothing like this to offer.

And contrary to you I know both editors pretty well.

So please cut the FUD out.

> The way I would write it if I were taking appropriate care

That's BS, no software can decide what the best choice is, it can only assist at best.

See AnoMonks demo here: Re: How would you indent this? Which identation style do you prefer?

The editor shouldn't interfere automatically in the formatting after the author has chosen a representation.

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

°) or activating auto-indent, which seems to be default now.

Replies are listed 'Best First'.
Re^7: How would you indent this?
by haj (Vicar) on Mar 19, 2021 at 00:02 UTC

    > Is it that it is emacs?
    The OP is using a function which is not standard indenting, hitting TAB is.°

    That's an oversimplification.

    1. <TAB> is equivalent to M-x cperl-indent-line if (as per default) tab-always-indent is set to a true value. It indents the current line.
    2. M-x cperl-indent-exp indents the current expression and reformats if (as per default) cperl-indent-region-fix-constructs is set to 1.
    3. M-x cperl-indent-region indents the current region and reformats if (as per default) cperl-indent-region-fix-constructs is set to 1.
    4. <RET> is, per default, equivalent to M-x newline which, also per default, indents the current and the new (empty) line.

    None of these functions are more standard than the others, and with the current settings there's rarely the need to use <TAB> at all.

    °) or activating auto-indent, which seems to be default now.

    That's electric-indent-mode, which isn't actually overdocumented right now. One of the consequences of this mode is that the PBP recommendation to remap <RET> to M-x newline-and-indent is outdated and should no longer be used. Also, in Python buffers, where indentation can't be inferred from braces and such, Electric Indent mode is switched off.

      > <RET> ... also per default, indents the current and the new (empty) line.

      do you happen to know since which version?

      It would be nice if the GNU folks published the emacs info with a version number.

      > That's electric-indent-mode, which isn't actually overdocumented right now

      I welcome freeing up TAB for completion, but this makes my setups even more complicated if they are supposed to work with different emacs versions.

      Which is why I'm still stuck on 24 btw :)

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

        It would be nice if the GNU folks published the emacs info with a version number.

        Actually, they do, sort of, since Emacs 27:

        electric-indent-mode is an interactive compiled Lisp function in ‘electric.el’. (electric-indent-mode &optional ARG) Probably introduced at or before Emacs version 24.1. ...

        Note, however, that Probably indicates that this is based on guesswork (grepping NEWS files). We had cases where it was off by two versions, and the Emacs maintainers made clear that it is extremely unlikely that they'll spend the effort to make that exact.

Re^7: How would you indent this?
by GrandFather (Saint) on Mar 18, 2021 at 21:13 UTC

    I agree that the "editor shouldn't interfere automatically". One of the worst editors I ever worked with was the UCSD Pascal system which forced its own idea of indentation live while editing, including disallowing multi-line comments. I run perltidy occasionally to clean up after things like a big code refactor, and I pretty much always use it to clean up code from PerlMonks questions.

    The impressive thing about perltidy is that I have tuned it to produce almost exactly what I write most of the time. Some of the modern C++ pretty printer type tools are pretty good too. Modern Visual Studio can do a pretty good job and the C++ Code Style Formatter provided by Eclipse is very configurable aside from some weird omissions (why does it insist on a space before a : in a constructor declerator list?). So yes, pretty printing tools can get extremely close to making the same code style decisions I do, partly because I have thought hard about my style choices and understand what I want to achieve, so results are consistent and fairly easy to codify.

    I apologize for the perceived attack on emacs. Never fear, I treat vi equally. :-D

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
      Perl::Tidy is an awesome tool. Unfortunately configuring it not so much.

      > I apologize for the perceived attack on emacs. Never fear, I treat vi equally. :-D

      Cheap attacks are cheap to get. That's the economics of FUD.

      Actually I like Komodo, it has indeed one feature I want to port back to emacs.

      Sadly it might not survive the next 5 years after Mozilla ended XUL and Activestate saw the need to Open Source it.

      Good luck!

      PS: No worries, I treat Pythonistas equally! :-D

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

        Actually I like Komodo ... Sadly it might not survive the next 5 years

        I may not care in five years, but assuming I do it isn't likely to suddenly stop working the day ActiveState stop actively supporting it.

        PS: I know some fine people who prefer Python - I don't hold that against them (much). I know some fine people who use PHP - I try manfully not to hold that against them.

        Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
Re^7: How would you indent this?
by no longer just digit (Beadle) on Mar 18, 2021 at 23:04 UTC
    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.

      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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-20 00:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found