Roscoe has asked for the wisdom of the Perl Monks concerning the following question:

The Praise section of cperl's Micro-docs brags that cperl:
b) Can lineup vertically "middles" of rows, like '=' in a = b; cc = d;
Great! Now how is this done? I tried using cperl-lineup on a marked region, but that wasn't it.

Replies are listed 'Best First'.
Re: Emacs cperl-mode: how to line up middles of rows?
by samtregar (Abbot) on Feb 02, 2006 at 23:55 UTC
    Dunno, but I use perltidy to do stuff like this. I call it from emacs using:

    (defun perltidy-region () "Run perltidy on the current region." (interactive) (save-excursion (shell-command-on-region (point) (mark) "perltidy -q" nil t))) (global-set-key "\M-t" `perltidy-region)

    Then I just mark a region and hit alt-t to pretty it up. I also have a binding to allow me to perltidy the whole file.

    -sam

Re: Emacs cperl-mode: how to line up middles of rows?
by duelafn (Parson) on Feb 03, 2006 at 02:46 UTC

    cperl-lineup is the correct function, but you have to use it carefully. The mark must be at the character that you wish to line up (hit C-space while on the first "="). Then go to the end of the region and execute cperl-lineup (C-M-| by default I believe).

    Good Day,
        Dean

      Thanks duelafn, this is exactly what I was looking for. It works!
Re: Emacs cperl-mode: how to line up middles of rows?
by superfrink (Curate) on Feb 03, 2006 at 04:05 UTC
    I have used the align-regex function in several buffer modes.

    Select your region. M-x align-regex . Press the '=' key. Press the 'Enter' key.

      It's probably a useful idea to set align-indent-before-aligning t (true) before using align-regexp, otherwise it may muck up the code indentation.

      emc

      " When in doubt, use brute force." — Ken Thompson