Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

CPerl-Mode Indentation

by azbok (Initiate)
on Jun 14, 2010 at 20:27 UTC ( #844726=perlquestion: print w/ replies, xml ) Need Help??
azbok has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I just setup CPerl-Mode 6.2 and I'm using Emacs version 21.4.1 and I'm wondering about:
# The way it indents my %a = ( a => 4, b => 4, );
# The way I'd like it to indent my %a = ( a => 4, b => 4, );

Anyone know how to configure that aspect of the indentation? I've messed around with a number of the configuration settings and can't figure it out.

Thanks!

Comment on CPerl-Mode Indentation
Select or Download Code
Re: CPerl-Mode Indentation
by LanX (Canon) on Jun 14, 2010 at 20:44 UTC
      Wow thanks for the quick reply and the thread about the issue. I like the elisp for perl programmers, that's great! I may poke around with the indentation code, but I don't know lisp very well. Thanks again :)
        if you can read python http://norvig.com/python-lisp.html could be of interest.

        But I disagree with the author, Perl is IMHO closer to LISP than Python.

        Learning LISP helped me understand some design decisions Larry took.

        Cheers Rolf

Re: CPerl-Mode Indentation
by bluescreen (Friar) on Jun 15, 2010 at 01:45 UTC
    Did you try with perltidy? I've it integrated to emacs with the following code in the .emacs
    (global-set-key "\C-xt" 'perltidy-region) (defun perltidy-region () "Run perltidy on the current region or the whole buffer." (interactive) (save-excursion (let ((beg (if mark-active (point) (point-min))) (end (if mark-active (mark) (point-max)))) (shell-command-on-region beg end "perltidy -q" nil t))))
    Originally from Specific Indentation request for perl in Emacs and then I modified it a little bit, so before checking in my code I run it thru perl tidy by pressing Ctrl+xt
      I know this approach but unfortunately this is not very compatible to the emacs way...

      Indentation is an integral part and main advantage of emacs editing, where ever you are in the code, just hitting TAB is enough to perfectly interactively indent the whole line ... I even bound it to RET to get it automatically when ending lines.

      It's not only cosmetics, you immediately get a feedback for multiline syntax errors (eg forgotten ";") when the indentation is wrong! So each time you insert an new line in a hash the perltity indentation will be broken again by emacs! That means you will have to mark the whole structure again and pipe it through perltidy.

      To make this more comfortable you will have to write a elisp-key-macro bound to TAB which automatically detects to be within a structure, to ignore normal emacs indentation, select the structure and to pipe it through perltidy...

      While this is perfectly possible, it's easier now to extend cperl-mode, it has a more natural UI and has a much better return of investment.

      I have it on my TODO list, but regarding the number of open projects it has only low priority. :)

      Cheers Rolf

        Absolutely I'm not taking away cperl-mode responsibilities, I'm just giving you a workaround

        BTW the small change that I made to that function was that if you have nothing selected it'll send perltidy the whole buffer, so that might help in your case

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://844726]
Approved by LanX
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2014-12-18 18:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (59 votes), past polls