Received: (at 77834) by debbugs.gnu.org; 16 Apr 2025 16:29:47 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Wed Apr 16 12:29:46 2025 Received: from localhost ([127.0.0.1]:40884 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1u55du-0007pi-3M for submit <at> debbugs.gnu.org; Wed, 16 Apr 2025 12:29:46 -0400 Received: from mxout5.mail.janestreet.com ([64.215.233.18]:38657) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <sbaugh@HIDDEN>) id 1u55dk-0007o2-Bz for 77834 <at> debbugs.gnu.org; Wed, 16 Apr 2025 12:29:38 -0400 From: Spencer Baugh <sbaugh@HIDDEN> To: Eli Zaretskii <eliz@HIDDEN> Subject: Re: bug#77834: [PATCH] Improve help-fns-edit-variable for Lisp editing In-Reply-To: <86plhcfsc7.fsf@HIDDEN> (Eli Zaretskii's message of "Wed, 16 Apr 2025 11:01:12 +0300") References: <ier34e99l8y.fsf@HIDDEN> <86plhcfsc7.fsf@HIDDEN> Date: Wed, 16 Apr 2025 12:29:26 -0400 Message-ID: <ierwmbk83yx.fsf@HIDDEN> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1744820966; bh=rg0YEKfsXvmSisZ7BIBDcJzuxk2VZ7HRb9k04DUjxeo=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=Dk8LfZ+Taqw8/tBuTKjHrnJ8DrwEQ39qQyGpmkSULFHg/PPceZQ86Xo5/ZFbGDu7j y/KFSv0kTfXIuAf+6zWBg8hyuuflvCbGdxR4LbL4TdtjsnOUtXBSARVNA8nBaUS6jp ZIZxsUgp9hOgnKdCH5baqiVsgOhuOkJ1H3elzegG6RPIRDiib7J4PP2gemcfJhxqxb DRgjJR40gwDJBA5rGTA8xNtNjYKRoUu+nOB3EwPgrY68FL3mrwL1RObi70kUWXnfYe 7In//Hv2r7ET7xPyeGUbT81+dcyOxPsa1OpZEKXrClIV67xBJ89C8e79cx0ph9Xfxi mraxi9vJrzTug== X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 77834 Cc: 77834 <at> debbugs.gnu.org, larsi@HIDDEN, philipk@HIDDEN, azeng@HIDDEN X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -3.3 (---) Eli Zaretskii <eliz@HIDDEN> writes: >> Cc: azeng@HIDDEN, Philip Kaludercic <philipk@HIDDEN>, >> Lars Ingebrigtsen <larsi@HIDDEN> >> Date: Tue, 15 Apr 2025 17:18:37 -0400 >> From: Spencer Baugh via "Bug reports for GNU Emacs, >> the Swiss army knife of text editors" <bug-gnu-emacs@HIDDEN> >> >> Before d50c82f3e98e ("Simplify >> 'help-enable-variable-value-editing' using 'string-edit'"), >> help-fns-edit-variable would open a buffer in emacs-lisp-mode >> and would not allow exiting that buffer with an invalid Lisp >> expression. Restore that functionality by enhancing string-edit >> to allow choosing a major mode and allow passing a function to >> validate the buffer contents before returning. > > Why is it better to use emacs-lisp-mode in this case? what are the > advantages and disadvantages? It provides syntax highlighting and completion and all the other features of emacs-lisp-mode. We're editing a Lisp form after all. > Philip, was this side-effect of commit d50c82f3e98e intentional or > just an oversight? Maybe we should simply revert that commit instead? I don't think we should revert the commit - I think using string-edit is a good change since it's almost exactly what we want for help-fns-edit-variable. Plus, the new functionality I'm adding to string-edit is useful in other places too - I plan to also use it for other later changes. >> (cl-defun string-edit (prompt string success-callback >> - &key abort-callback) >> + &key abort-callback major-mode read) >> "Switch to a new buffer to edit STRING. >> -When the user finishes editing (with \\<string-edit-mode-map>\\[string-edit-done]), SUCCESS-CALLBACK >> -is called with the resulting string. >> +When the user finishes editing (with `string-edit-done'), >> +SUCCESS-CALLBACK is called with the resulting string. If READ is >> +non-nil, it is called on the string and its result is passed to >> +SUCCESS-CALLBACK instead. If READ signals an error, the buffer remains >> +open, giving the user a chance to correct a typo. >> >> -If the user aborts (with \\<string-edit-mode-map>\\[string-edit-abort]), ABORT-CALLBACK (if any) is >> +If the user aborts (with `string-edit-abort'), ABORT-CALLBACK (if any) is >> called with no parameters. >> >> PROMPT will be inserted at the start of the buffer, but won't be >> included in the resulting string. If PROMPT is nil, no help text >> will be inserted. >> >> +MAJOR-MODE is called to set up the new buffer; if not passed, >> +`string-edit-mode' is used. > > This doc string, both its old parts and the new additions, are > replete with unnecessary uses of passive tense; please fix that as > part of the changeset. Will do so in the next version of the patch. >> ;;;###autoload >> -(defun read-string-from-buffer (prompt string) >> +(cl-defun read-string-from-buffer (prompt string >> + &key major-mode >> + read) > > I don't see any reasons to make this a cl-defun, just to add 2 more > optional arguments. It's to match the existing cl-defun for string-edit. string-edit takes keyword arguments - read-string-from-buffer probably should match it. Alternatively, I could just not change read-string-from-buffer and only change string-edit. Then help-fns-edit-variable could call string-edit directly. That would duplicate a bit more code though. >> "Switch to a new buffer to edit STRING in a recursive edit. >> -The user finishes editing with \\<string-edit-mode-map>\\[string-edit-done], or aborts with \\<string-edit-mode-map>\\[string-edit-abort]). >> + >> +When the user finishes editing with `string-edit-done', this function > > Why did you remove the keymap and command markup? That loses useful > features. > >> +If the user aborts with `string-edit-abort', this function signals an >> +error. > > Same here. I removed these because neither of these are user-facing functions; the docstrings are only read by Lisp hackers writing new packages using these functions. And it seems to me that for a Lisp programmer it's more useful to know the name of the commands which the user uses to finish editing, rather than the bindings for those commands. But this is not an important change, if you prefer it to have the keymap markup instead.
bug-gnu-emacs@HIDDEN
:bug#77834
; Package emacs
.
Full text available.Received: (at 77834) by debbugs.gnu.org; 16 Apr 2025 08:01:55 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Wed Apr 16 04:01:55 2025 Received: from localhost ([127.0.0.1]:34409 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1u4xiU-0006XJ-Ow for submit <at> debbugs.gnu.org; Wed, 16 Apr 2025 04:01:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37076) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1u4xiN-0006W9-J1 for 77834 <at> debbugs.gnu.org; Wed, 16 Apr 2025 04:01:51 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <eliz@HIDDEN>) id 1u4xiE-0003LP-1m; Wed, 16 Apr 2025 04:01:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=b+ChpNRwt1WJGCGIRSkgqZp0WlcLGQ258PJ7NtS2x0E=; b=T3E+u0sN8jBO 2GVzMfqelLfes3VMqHpq10dvjZVTzO11ZjVKKTPuLiqAWdG+8ZA3JYkR92vjM1YUNmy2csBOxy226 mJ5mBG0KxrHsYw0DxwfzkgDYo8/714gzBqGNH/uQytk3pRnHoIABgWriwJ9XXR0K84zfw7L3kncUL KGKacjt1aoZwrDCDXF2e6omMKnmul8Wd6AzsVapBIoMxVxf9Hgh/azfr85z7OtV1c0PM7haIv255D tc1CpsRjkcky3QeyGC8wfv0m8CLU56HQQuFIo1JumSwLYi/tXwBPXbVgRJ6Sik8psr8lm8YyYCOY5 eVNRV4zr4wnVzlV9DIqu8Q==; Date: Wed, 16 Apr 2025 11:01:12 +0300 Message-Id: <86plhcfsc7.fsf@HIDDEN> From: Eli Zaretskii <eliz@HIDDEN> To: Spencer Baugh <sbaugh@HIDDEN> In-Reply-To: <ier34e99l8y.fsf@HIDDEN> (bug-gnu-emacs@HIDDEN) Subject: Re: bug#77834: [PATCH] Improve help-fns-edit-variable for Lisp editing References: <ier34e99l8y.fsf@HIDDEN> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 77834 Cc: 77834 <at> debbugs.gnu.org, larsi@HIDDEN, philipk@HIDDEN, azeng@HIDDEN X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -3.3 (---) > Cc: azeng@HIDDEN, Philip Kaludercic <philipk@HIDDEN>, > Lars Ingebrigtsen <larsi@HIDDEN> > Date: Tue, 15 Apr 2025 17:18:37 -0400 > From: Spencer Baugh via "Bug reports for GNU Emacs, > the Swiss army knife of text editors" <bug-gnu-emacs@HIDDEN> > > Before d50c82f3e98e ("Simplify > 'help-enable-variable-value-editing' using 'string-edit'"), > help-fns-edit-variable would open a buffer in emacs-lisp-mode > and would not allow exiting that buffer with an invalid Lisp > expression. Restore that functionality by enhancing string-edit > to allow choosing a major mode and allow passing a function to > validate the buffer contents before returning. Why is it better to use emacs-lisp-mode in this case? what are the advantages and disadvantages? Philip, was this side-effect of commit d50c82f3e98e intentional or just an oversight? Maybe we should simply revert that commit instead? > (cl-defun string-edit (prompt string success-callback > - &key abort-callback) > + &key abort-callback major-mode read) > "Switch to a new buffer to edit STRING. > -When the user finishes editing (with \\<string-edit-mode-map>\\[string-edit-done]), SUCCESS-CALLBACK > -is called with the resulting string. > +When the user finishes editing (with `string-edit-done'), > +SUCCESS-CALLBACK is called with the resulting string. If READ is > +non-nil, it is called on the string and its result is passed to > +SUCCESS-CALLBACK instead. If READ signals an error, the buffer remains > +open, giving the user a chance to correct a typo. > > -If the user aborts (with \\<string-edit-mode-map>\\[string-edit-abort]), ABORT-CALLBACK (if any) is > +If the user aborts (with `string-edit-abort'), ABORT-CALLBACK (if any) is > called with no parameters. > > PROMPT will be inserted at the start of the buffer, but won't be > included in the resulting string. If PROMPT is nil, no help text > will be inserted. > > +MAJOR-MODE is called to set up the new buffer; if not passed, > +`string-edit-mode' is used. This doc string, both its old parts and the new additions, are replete with unnecessary uses of passive tense; please fix that as part of the changeset. > ;;;###autoload > -(defun read-string-from-buffer (prompt string) > +(cl-defun read-string-from-buffer (prompt string > + &key major-mode > + read) I don't see any reasons to make this a cl-defun, just to add 2 more optional arguments. > "Switch to a new buffer to edit STRING in a recursive edit. > -The user finishes editing with \\<string-edit-mode-map>\\[string-edit-done], or aborts with \\<string-edit-mode-map>\\[string-edit-abort]). > + > +When the user finishes editing with `string-edit-done', this function Why did you remove the keymap and command markup? That loses useful features. > +If the user aborts with `string-edit-abort', this function signals an > +error. Same here.
bug-gnu-emacs@HIDDEN
:bug#77834
; Package emacs
.
Full text available.Received: (at submit) by debbugs.gnu.org; 15 Apr 2025 21:19:12 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Tue Apr 15 17:19:12 2025 Received: from localhost ([127.0.0.1]:56732 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1u4ngQ-0004CC-LP for submit <at> debbugs.gnu.org; Tue, 15 Apr 2025 17:19:11 -0400 Received: from lists.gnu.org ([2001:470:142::17]:60666) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <sbaugh@HIDDEN>) id 1u4ngK-00048n-Cg for submit <at> debbugs.gnu.org; Tue, 15 Apr 2025 17:19:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <sbaugh@HIDDEN>) id 1u4ng4-0003IM-Kd for bug-gnu-emacs@HIDDEN; Tue, 15 Apr 2025 17:18:44 -0400 Received: from mxout5.mail.janestreet.com ([64.215.233.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <sbaugh@HIDDEN>) id 1u4ng0-0003cM-Lc for bug-gnu-emacs@HIDDEN; Tue, 15 Apr 2025 17:18:44 -0400 From: Spencer Baugh <sbaugh@HIDDEN> To: bug-gnu-emacs@HIDDEN Subject: [PATCH] Improve help-fns-edit-variable for Lisp editing X-Debbugs-Cc: azeng@HIDDEN, Philip Kaludercic <philipk@HIDDEN>, Lars Ingebrigtsen <larsi@HIDDEN> Date: Tue, 15 Apr 2025 17:18:37 -0400 Message-ID: <ier34e99l8y.fsf@HIDDEN> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1744751917; bh=Mma7W9yiacEHGhTJiAOMmopFQ7OiS0163RWzo9S1eaw=; h=From:To:Subject:Date; b=2/pxBvvs66fOm6OLyAbzL9FKINnoTiAKGPoQFIoX0wtbWhI6sigXegU+BYf3qGEwW q5/5s5H6NgFcKbnUM0fU2yKsd/i4LpnXNcJUtM732psRg4VSLqAyPZaz1vE6NWA86x DYvAXYb5r3rncD8ebroUgi1fMu3SmCOrDVc/5C8t+rL3z0VxZb6YnAZyCCUp1WUrOr /aTYs1N4hWNTFV16pLglCVYRgH05X47dyi8UJIh1LRnQnf0UjCer9AxbWuNnZAGcJY CLi3pBrdBQ8imBDBLVQByuoWwxZaIjaRR8T8gIdnKaRj3y75ypZVwfmGvHD+5106XT UlpzgRFfx0PFA== Received-SPF: pass client-ip=64.215.233.18; envelope-from=sbaugh@HIDDEN; helo=mxout5.mail.janestreet.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.9 (/) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -0.1 (/) --=-=-= Content-Type: text/plain Tags: patch Before d50c82f3e98e ("Simplify 'help-enable-variable-value-editing' using 'string-edit'"), help-fns-edit-variable would open a buffer in emacs-lisp-mode and would not allow exiting that buffer with an invalid Lisp expression. Restore that functionality by enhancing string-edit to allow choosing a major mode and allow passing a function to validate the buffer contents before returning. In GNU Emacs 30.1.50 (build 8, x86_64-pc-linux-gnu, X toolkit, cairo version 1.15.12, Xaw scroll bars) of 2025-04-10 built on igm-qws-u22796a Repository revision: 128bc06bfcc56a35d6b5555cc546faaf0d964df0 Repository branch: emacs-30 Windowing system distributor 'The X.Org Foundation', version 11.0.12011000 System Description: Rocky Linux 8.10 (Green Obsidian) Configured using: 'configure --config-cache --with-x-toolkit=lucid --without-gpm --without-gconf --without-selinux --without-imagemagick --with-modules --with-gif=no --with-cairo --with-rsvg --without-compress-install --with-tree-sitter --with-native-compilation=aot' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Improve-help-fns-edit-variable-for-Lisp-editing.patch From 26ea5e0cbbe85950d4362489ffe054cd570395c8 Mon Sep 17 00:00:00 2001 From: Spencer Baugh <sbaugh@HIDDEN> Date: Tue, 15 Apr 2025 17:17:27 -0400 Subject: [PATCH] Improve help-fns-edit-variable for Lisp editing Before d50c82f3e98e ("Simplify 'help-enable-variable-value-editing' using 'string-edit'"), help-fns-edit-variable would open a buffer in emacs-lisp-mode and would not allow exiting that buffer with an invalid Lisp expression. Restore that functionality by enhancing string-edit to allow choosing a major mode and allow passing a function to validate the buffer contents before returning. * lisp/help-fns.el (help-fns-edit-variable): Pass emacs-lisp-mode and read to read-string-from-buffer. * lisp/textmodes/string-edit.el (string-edit--read): Add. (string-edit, read-string-from-buffer): Add :major-mode and :read arguments. (string-edit-mode-map, string-edit-minor-mode-map) (string-edit-mode, string-edit-minor-mode): Move string-edit keybindings to a minor mode. (string-edit-done): Call string-edit--read before exiting. --- lisp/help-fns.el | 10 +++-- lisp/textmodes/string-edit.el | 70 +++++++++++++++++++++++++---------- 2 files changed, 56 insertions(+), 24 deletions(-) diff --git a/lisp/help-fns.el b/lisp/help-fns.el index 0eb0a7a40be..57aab4d82e1 100644 --- a/lisp/help-fns.el +++ b/lisp/help-fns.el @@ -1561,10 +1561,12 @@ help-fns-edit-variable (let ((var (get-text-property (point) 'help-fns--edit-variable))) (unless var (error "No variable under point")) - (let ((str (read-string-from-buffer - (format ";; Edit the `%s' variable." (nth 0 var)) - (prin1-to-string (nth 1 var))))) - (set (nth 0 var) (read str)) + (let ((expr (read-string-from-buffer + (format ";; Edit the `%s' variable." (nth 0 var)) + (prin1-to-string (nth 1 var)) + :major-mode #'emacs-lisp-mode + :read #'read))) + (set (nth 0 var) expr) (revert-buffer)))) (autoload 'shortdoc-help-fns-examples-function "shortdoc") diff --git a/lisp/textmodes/string-edit.el b/lisp/textmodes/string-edit.el index 3c76db202c7..47b5d4c337d 100644 --- a/lisp/textmodes/string-edit.el +++ b/lisp/textmodes/string-edit.el @@ -33,21 +33,28 @@ string-edit-prompt (defvar string-edit--success-callback) (defvar string-edit--abort-callback) +(defvar string-edit--read) ;;;###autoload (cl-defun string-edit (prompt string success-callback - &key abort-callback) + &key abort-callback major-mode read) "Switch to a new buffer to edit STRING. -When the user finishes editing (with \\<string-edit-mode-map>\\[string-edit-done]), SUCCESS-CALLBACK -is called with the resulting string. +When the user finishes editing (with `string-edit-done'), +SUCCESS-CALLBACK is called with the resulting string. If READ is +non-nil, it is called on the string and its result is passed to +SUCCESS-CALLBACK instead. If READ signals an error, the buffer remains +open, giving the user a chance to correct a typo. -If the user aborts (with \\<string-edit-mode-map>\\[string-edit-abort]), ABORT-CALLBACK (if any) is +If the user aborts (with `string-edit-abort'), ABORT-CALLBACK (if any) is called with no parameters. PROMPT will be inserted at the start of the buffer, but won't be included in the resulting string. If PROMPT is nil, no help text will be inserted. +MAJOR-MODE is called to set up the new buffer; if not passed, +`string-edit-mode' is used. + Also see `read-string-from-buffer'." (with-current-buffer (generate-new-buffer "*edit string*") (when prompt @@ -74,26 +81,39 @@ string-edit (set-buffer-modified-p nil) (setq buffer-undo-list nil) - (string-edit-mode) + (funcall (or major-mode #'string-edit-mode)) + (string-edit-minor-mode) (setq-local string-edit--success-callback success-callback) (setq-local string-edit--abort-callback abort-callback) + (setq-local string-edit--read read) (setq-local header-line-format (substitute-command-keys - "Type \\<string-edit-mode-map>\\[string-edit-done] when you've finished editing or \\[string-edit-abort] to abort")) + "Type \\<string-edit-minor-mode-map>\\[string-edit-done] when you've finished editing or \\[string-edit-abort] to abort")) (message "%s" (substitute-command-keys - "Type \\<string-edit-mode-map>\\[string-edit-done] when you've finished editing")))) + "Type \\<string-edit-minor-mode-map>\\[string-edit-done] when you've finished editing")))) ;;;###autoload -(defun read-string-from-buffer (prompt string) +(cl-defun read-string-from-buffer (prompt string + &key major-mode + read) "Switch to a new buffer to edit STRING in a recursive edit. -The user finishes editing with \\<string-edit-mode-map>\\[string-edit-done], or aborts with \\<string-edit-mode-map>\\[string-edit-abort]). + +When the user finishes editing with `string-edit-done', this function +returns that string. If READ is non-nil, it is called on the string and +its return value is returned instead. If READ signals an error, the +buffer remains open, giving the user a chance to correct a typo. + +If the user aborts with `string-edit-abort', this function signals an +error. PROMPT will be inserted at the start of the buffer, but won't be included in the resulting string. If nil, no prompt will be inserted in the buffer. -When the user exits recursive edit, this function returns the -edited STRING. +MAJOR-MODE is called to set up the new buffer; if not passed, +`string-edit-mode' is used. + +When the user finished editing Also see `string-edit'." (string-edit @@ -104,15 +124,22 @@ read-string-from-buffer (exit-recursive-edit)) :abort-callback (lambda () (exit-recursive-edit) - (error "Aborted edit"))) + (error "Aborted edit")) + :major-mode major-mode + :read read) (recursive-edit) string) -(defvar-keymap string-edit-mode-map +(defvar-keymap string-edit-minor-mode-map "C-c C-c" #'string-edit-done "C-c C-k" #'string-edit-abort) -(define-derived-mode string-edit-mode text-mode "String" +(define-minor-mode string-edit-minor-mode + "Minor mode for editing strings" + :lighter "String" + :interactive nil) + +(define-derived-mode string-edit-mode text-mode "Text" "Mode for editing strings." :interactive nil) @@ -120,13 +147,16 @@ string-edit-done "Finish editing the string and call the callback function. This will kill the current buffer." (interactive) - (goto-char (point-min)) - ;; Skip past the help text. - (text-property-search-forward 'string-edit--prompt) - (let ((string (buffer-substring (point) (point-max))) - (callback string-edit--success-callback)) + (let* ((string + (save-excursion + (goto-char (point-min)) + ;; Skip past the help text. + (text-property-search-forward 'string-edit--prompt) + (buffer-substring (point) (point-max)))) + (valid (funcall string-edit--read string)) + (callback string-edit--success-callback)) (quit-window 'kill) - (funcall callback string))) + (funcall callback valid))) (defun string-edit-abort () "Abort editing the current string." -- 2.39.3 --=-=-=--
Spencer Baugh <sbaugh@HIDDEN>
:azeng@HIDDEN, philipk@HIDDEN, larsi@HIDDEN, bug-gnu-emacs@HIDDEN
.
Full text available.azeng@HIDDEN, philipk@HIDDEN, larsi@HIDDEN, bug-gnu-emacs@HIDDEN
:bug#77834
; Package emacs
.
Full text available.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997 nCipher Corporation Ltd,
1994-97 Ian Jackson.