unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Indentation of hashes (?) in perl-mode
@ 2024-06-19 10:17 Tim Landscheidt
  2024-07-05 14:03 ` Stefan Monnier via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 2+ messages in thread
From: Tim Landscheidt @ 2024-06-19 10:17 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

when writing anonymous subroutines for Find::File::find, I
get the following indentation with Emacs 29.3's perl-mode:

| find ({ wanted => sub {
|     return;
|         }, follow => 1 }, '/tmp');

IMHO it would seem more natural if the last line's opening
bracket was in the first column (i. e., no indentation).

A similar question was asked on Stack Exchange
(https://emacs.stackexchange.com/questions/78606/perl-mode-brace-indentation)
with the additional condition "without switching to
cperl-mode".

Is it possible to make perl-mode indent these structures
more naturally?  (I'm open to other ways to phrase this code
as well.)

TIA,
Tim



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Indentation of hashes (?) in perl-mode
  2024-06-19 10:17 Indentation of hashes (?) in perl-mode Tim Landscheidt
@ 2024-07-05 14:03 ` Stefan Monnier via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2024-07-05 14:03 UTC (permalink / raw)
  To: help-gnu-emacs

> when writing anonymous subroutines for Find::File::find, I
> get the following indentation with Emacs 29.3's perl-mode:
>
> | find ({ wanted => sub {
> |     return;
> |         }, follow => 1 }, '/tmp');
>
> IMHO it would seem more natural if the last line's opening
> bracket was in the first column (i. e., no indentation).

[ In my view it's the `return` above that's wrong. 🙂  ]
But what about:

    find ({ wanted => sub {
                return;
            }, follow => 1,
            other => 3},
          '/tmp');

Would you want the indentation I just used or would you prefer

    find ({ wanted => sub {
        return;
    }, follow => 1,
            other => 3},
          '/tmp');

Usually indentation rules look only at the text that comes *before*, so
the indentation of `return` and of the line with `follow` should be the
same regardless of what comes on subsequent lines.

> Is it possible to make perl-mode indent these structures
> more naturally?  (I'm open to other ways to phrase this code
> as well.)

I'd suggest

    find ({ wanted => sub {
                return;
            }, follow => 1,
            other => 3},
          '/tmp');

BTW, I just installed on `master` the patch below which fixes the
indentation of `return`.


        Stefan


diff --git a/lisp/progmodes/perl-mode.el b/lisp/progmodes/perl-mode.el
index 68685fb6625..ff71970d41b 100644
--- a/lisp/progmodes/perl-mode.el
+++ b/lisp/progmodes/perl-mode.el
@@ -1130,14 +1130,7 @@ perl-calculate-indent
             ;; add the perl-brace-imaginary-offset.
             (progn (skip-chars-backward " \t")
                    (if (bolp) 0 perl-brace-imaginary-offset))
-            ;; If the openbrace is preceded by a parenthesized exp,
-            ;; move to the beginning of that;
-            ;; possibly a different line
-            (progn
-              (if (eq (preceding-char) ?\))
-                  (forward-sexp -1))
-              ;; Get initial indentation of the line we are on.
-              (current-indentation)))))))))
+            (perl-indent-new-calculate 'virtual))))))))
 
 (defun perl-backward-to-noncomment ()
   "Move point backward to after the first non-white-space, skipping comments."




^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-07-05 14:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-19 10:17 Indentation of hashes (?) in perl-mode Tim Landscheidt
2024-07-05 14:03 ` Stefan Monnier via Users list for the GNU Emacs text editor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).