From: Stefan Monnier via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Indentation of hashes (?) in perl-mode
Date: Fri, 05 Jul 2024 10:03:07 -0400 [thread overview]
Message-ID: <jwvjzi0c5gf.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: 878qz1grsd.fsf@vagabond.tim-landscheidt.de
> 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."
prev parent reply other threads:[~2024-07-05 14:03 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvjzi0c5gf.fsf-monnier+emacs@gnu.org \
--to=help-gnu-emacs@gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).