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: Tue, 24 Sep 2024 19:59:47 +0100 [thread overview]
Message-ID: <871q18op24.fsf@ice9.digital> (raw)
In-Reply-To: <86cyktdx68.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 24 Sep 2024 15:59:59 +0300")
[-- Attachment #1: Type: text/plain, Size: 446 bytes --]
Eli Zaretskii <eliz@gnu.org> writes:
>> From: João Távora <joaotavora@gmail.com>
>> Date: Tue, 24 Sep 2024 13:12:24 +0100
>> Cc: Morgan Willcock <morgan@ice9.digital>, emacs-devel@gnu.org
>>
>> No, it wasn't. I was probably experimenting with something.
>>
>> You can revert it (or make it optional), etc.
>
> Thanks. So Morgan, please post a patch that makes this feature
> opt-in.
Patch is attached.
--
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: 2030 bytes --]
From 0fe0d66aff7d4969e99478469afadede7e40f4ac Mon Sep 17 00:00:00 2001
From: Morgan Willcock <morgan@ice9.digital>
Date: Tue, 24 Sep 2024 19:33:11 +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. The recent behavior can be restored by setting the
new variable 'electric-layout-allow-in-comment-or-string' to a
non-nil value.
* lisp/electric.el (electric-layout-allow-in-comment-or-string):
New variable to determine whether inserting newlines is
permitted within comments or strings.
(electric-layout-post-self-insert-function-1): Restore the
previous default behavior of not inserting newlines within
comments or strings.
---
lisp/electric.el | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/lisp/electric.el b/lisp/electric.el
index d02bcb4735b..d84faf5433f 100644
--- a/lisp/electric.el
+++ b/lisp/electric.el
@@ -385,6 +385,9 @@ electric-layout-rules
(defvar electric-layout-allow-duplicate-newlines nil
"If non-nil, allow duplication of `before' newlines.")
+(defvar electric-layout-allow-in-comment-or-string nil
+ "If non-nil, allow inserting newlines inside a comment or string.")
+
(defun electric-layout-post-self-insert-function ()
(when electric-layout-mode
(electric-layout-post-self-insert-function-1)))
@@ -409,7 +412,10 @@ 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
+ (or electric-layout-allow-in-comment-or-string
+ ;; Not in a comment or string.
+ (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-24 18:59 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 [this message]
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
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
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=871q18op24.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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).