From: Morgan Willcock <morgan@ice9.digital>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Accidental change of behaviour for electric-layout-mode?
Date: Wed, 25 Sep 2024 14:50:19 +0100 [thread overview]
Message-ID: <87h6a37sh0.fsf@ice9.digital> (raw)
In-Reply-To: <86jzf0c6rw.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 25 Sep 2024 14:27:47 +0300")
[-- Attachment #1: Type: text/plain, Size: 2955 bytes --]
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Morgan Willcock <morgan@ice9.digital>
>> Cc: emacs-devel@gnu.org
>> Date: Tue, 24 Sep 2024 20:39:42 +0100
>>
>> Eli Zaretskii <eliz@gnu.org> writes:
>>
>> >> Patch is attached.
>> >
>> > Thanks, but shouldn't the new variable be a defcustom, i.e. a user
>> > option? AFAIU, the preference is on the user level.
>>
>> I am following the lead of electric-layout-allow-duplicate-newlines
>> which is not a user option.
>
> Which ironically has the following comment:
>
> ;; TODO: Make this a defcustom?
> (defvar electric-layout-allow-duplicate-newlines nil
>
> So I think this new variable should be a defcustom, and maybe we
> should also make electric-layout-allow-duplicate-newlines a defcustom.
>
>> For my use case, electric-layout-rules is being set by a major-mode and
>> the functions in those rules would need to be paired with the ability to
>> insert a newline within a comment.
>
> If you are saying that it never makes sense to modify the value of
> this variable given specific rules, i.e. that any set of rules will
> either always support embedded newlines or be unable to support them,
> but will never be able to sensibly support both alternatives, then I
> agree. (But in that case, why do we need a variable at all? why not
> let the rules specify this directly?)
With the current setup, functions which are used within rules cannot
decide for themselves on the context - the function call happens before
the guards that have traditionally been in place are checked.
>> If you needed another example of a major-mode configuring it,
>> python-mode is also setting rules at the mode level:
>>
>> https://git.savannah.gnu.org/cgit/emacs.git/commit/lisp/progmodes/python.el?id=dfecd6037d5ebe5778c40ff7b38bfcbaa3ef779e
>
> The way to let modes control this behavior to introduce an internal
> variable which the mode could set and whose initial default value is
> taken from the user option.
>
>>
>> If there is any doubt about the usage of the new variable I am happy to
>> just put the original behaviour back and omit the new option for the
>> moment.
>
> Do you really have such strong feelings about this not being a user
> option that you'd rather forget the whole issue? Why are you so
> convinced that no user will ever want to customize this behavior, when
> you are the first example of such users?
It is more that I don't have strong enough feelings to be making
modifications which significantly change the user experience or design.
Just to make sure everything works in Emacs 30, I'd rather just revert
the accidental change than get further involved in the development of
this feature (at least in the short term).
I've attached a patch which just reverts the change that was
accidentally applied. This should be all that is needed unless you
specifically want to accommodate features which accidentally worked in
an unreleased version of Emacs.
--
Morgan Willcock
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Restore-comment-string-check-for-electric-layout-mod.patch --]
[-- Type: text/x-diff, Size: 1262 bytes --]
From 89463c6c5aeeae14868a69922719b5c154fbf69d Mon Sep 17 00:00:00 2001
From: Morgan Willcock <morgan@ice9.digital>
Date: Wed, 25 Sep 2024 14:30:13 +0100
Subject: [PATCH] Restore comment/string check for electric-layout-mode
This reverts an accidental change which allowed
electric-layout-mode to insert newlines inside strings and
comments.
* lisp/electric.el
(electric-layout-post-self-insert-function-1): Restore the
previous default behavior of not inserting newlines within
comments or strings.
---
lisp/electric.el | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lisp/electric.el b/lisp/electric.el
index d02bcb4735b..2fcb90efe7d 100644
--- a/lisp/electric.el
+++ b/lisp/electric.el
@@ -409,7 +409,9 @@ electric-layout-post-self-insert-function-1
(goto-char pos)
(funcall probe last-command-event))))
(when res (throw 'done res))))))))))
- (when rule
+ (when (and rule
+ ;; Not in a string or comment.
+ (not (nth 8 (save-excursion (syntax-ppss pos)))))
(goto-char pos)
(when (functionp rule) (setq rule (funcall rule)))
(dolist (sym (if (symbolp rule) (list rule) rule))
--
2.39.5
next prev parent reply other threads:[~2024-09-25 13:50 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-23 20:58 Accidental change of behaviour for electric-layout-mode? Morgan Willcock
2024-09-24 11:23 ` Eli Zaretskii
2024-09-24 12:12 ` João Távora
2024-09-24 12:59 ` Eli Zaretskii
2024-09-24 18:59 ` Morgan Willcock
2024-09-24 19:03 ` Eli Zaretskii
2024-09-24 19:39 ` Morgan Willcock
2024-09-25 11:27 ` Eli Zaretskii
2024-09-25 13:50 ` Morgan Willcock [this message]
2024-09-25 15:57 ` Eli Zaretskii
2024-10-03 16:22 ` Morgan Willcock
2024-10-03 18:06 ` Eli Zaretskii
2024-10-05 10:13 ` Eli Zaretskii
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87h6a37sh0.fsf@ice9.digital \
--to=morgan@ice9.digital \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
/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.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.