From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.bugs Subject: bug#71374: [PATCH] Simplify 'help-enable-variable-value-editing' using Date: Wed, 05 Jun 2024 06:55:46 +0000 Message-ID: <87ikync1zh.fsf@posteo.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7423"; mail-complaints-to="usenet@ciao.gmane.io" To: 71374@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jun 05 09:15:09 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sEkrT-0001l3-QW for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 05 Jun 2024 09:15:07 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sEkrC-0005VQ-Ja; Wed, 05 Jun 2024 03:14:50 -0400 Original-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 ) id 1sEkrA-0005VA-Qx for bug-gnu-emacs@gnu.org; Wed, 05 Jun 2024 03:14:49 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sEkrA-0001RQ-JP for bug-gnu-emacs@gnu.org; Wed, 05 Jun 2024 03:14:48 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sEkrO-0000Bp-Dm for bug-gnu-emacs@gnu.org; Wed, 05 Jun 2024 03:15:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 05 Jun 2024 07:15:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 71374 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.1717571670601 (code B ref -1); Wed, 05 Jun 2024 07:15:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 5 Jun 2024 07:14:30 +0000 Original-Received: from localhost ([127.0.0.1]:36043 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sEkqq-00009Z-Tb for submit@debbugs.gnu.org; Wed, 05 Jun 2024 03:14:29 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:44344) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sEkqn-000095-3V for submit@debbugs.gnu.org; Wed, 05 Jun 2024 03:14:27 -0400 Original-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 ) id 1sEkYs-0001Ah-00 for bug-gnu-emacs@gnu.org; Wed, 05 Jun 2024 02:55:54 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sEkYp-0005KB-0L for bug-gnu-emacs@gnu.org; Wed, 05 Jun 2024 02:55:53 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 2B590240027 for ; Wed, 5 Jun 2024 08:55:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1717570547; bh=lnig+xxjrkO8chI1zxJfJtoTYJvPltKjLOgq8MAl0Mc=; h=From:To:Subject:OpenPGP:Date:Message-ID:MIME-Version:Content-Type: From; b=Mr4E3ifeLPdB/CjSInIJ/AT9UGBZXkD0a8u8Q1iuWwkXsKIgwYAtaeRNdP6dDoeCL RThFkBfQqJROEGTGjA6XjPnybxHW6a1VuIr1ajo2BIQAsFXw3+h8qx3ATskTF94EiT FszR90xT+8SgZoEBF/x86tmQwK2GsHVilRSbwJJX3ed+goyNtmKnZIXXgh3viBDztW ZuhLPOghEvjBcC8utrdg6StOnaJDpv41Ke3UKw+XHjfLk/TTnPbKlaR8Eqchenkw5p t/3l6KfgWDozjqNO9uM6RRyVIPubvB2lMrqWafiLVuzA7AhKyVVPGVAp+DbNVuilHK rjtyMTmkRdAOA== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4VvJBp4Bfyz6txr for ; Wed, 5 Jun 2024 08:55:46 +0200 (CEST) OpenPGP: id=7126E1DE2F0CE35C770BED01F2C3CC513DB89F66; url="https://keys.openpgp.org/vks/v1/by-fingerprint/7126E1DE2F0CE35C770BED01F2C3CC513DB89F66"; preference=signencrypt Received-SPF: pass client-ip=185.67.36.65; envelope-from=philipk@posteo.net; helo=mout01.posteo.de 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:286579 Archived-At: --=-=-= Content-Type: text/plain The main issue with this patch is that it drops the syntax highlighting in the *string edit* buffer, but we could fix that in a second patch by adding support to specify a major mode to inherit from when editing a string. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Simplify-'help-enable-variable-value-editing'-usin.patch Content-Description: [PATCH] Simplify 'help-enable-variable-value-editing' using >From fa1fff88e295bee0380665d623a6266842f91af6 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Wed, 5 Jun 2024 08:26:37 +0200 Subject: [PATCH] Simplify 'help-enable-variable-value-editing' using 'string-edit' * lisp/help-fns.el (help-fns--edit-variable): Remove variable declaration, as 'string-edit' makes manually storing the variable name unnecessary. (help-fns-edit-variable): Use 'read-string-from-buffer' instead of custom major mode. (help-fns--edit-value-mode-map, help-fns--edit-value-mode) (help-fns-edit-mode-done, help-fns-edit-mode-cancel): Remove functionality provided by 'string-edit'. --- lisp/help-fns.el | 55 ++++++------------------------------------------ 1 file changed, 7 insertions(+), 48 deletions(-) diff --git a/lisp/help-fns.el b/lisp/help-fns.el index 1ffe1b16588..8ea5b301684 100644 --- a/lisp/help-fns.el +++ b/lisp/help-fns.el @@ -1502,60 +1502,19 @@ help-fns--editable-variable :parent button-map "e" #'help-fns-edit-variable))))) -(defvar help-fns--edit-variable) - (put 'help-fns-edit-variable 'disabled t) (defun help-fns-edit-variable () "Edit the variable under point." (declare (completion ignore)) (interactive) - (let ((var (get-text-property (point) 'help-fns--edit-variable))) - (unless var + (let* ((val (thing-at-point 'sexp)) + (var (get-text-property 0 'help-fns--edit-variable val))) + (unless val (error "No variable under point")) - (pop-to-buffer-same-window (format "*edit %s*" (nth 0 var))) - (prin1 (nth 1 var) (current-buffer)) - (pp-buffer) - (goto-char (point-min)) - (help-fns--edit-value-mode) - (insert (format ";; Edit the `%s' variable.\n" (nth 0 var)) - (substitute-command-keys - ";; `\\[help-fns-edit-mode-done]' to update the value and exit; \ -`\\[help-fns-edit-mode-cancel]' to cancel.\n\n")) - (setq-local help-fns--edit-variable var))) - -(defvar-keymap help-fns--edit-value-mode-map - "C-c C-c" #'help-fns-edit-mode-done - "C-c C-k" #'help-fns-edit-mode-cancel) - -(define-derived-mode help-fns--edit-value-mode emacs-lisp-mode "Elisp" - :interactive nil) - -(defun help-fns-edit-mode-done (&optional kill) - "Update the value of the variable being edited and kill the edit buffer. -If KILL (the prefix), don't update the value, but just kill the -current buffer." - (interactive "P" help-fns--edit-value-mode) - (unless help-fns--edit-variable - (error "Invalid buffer")) - (goto-char (point-min)) - (cl-destructuring-bind (variable _ buffer help-buffer) - help-fns--edit-variable - (unless (buffer-live-p buffer) - (error "Original buffer is gone; can't update")) - (unless kill - (let ((value (read (current-buffer)))) - (with-current-buffer buffer - (set variable value)))) - (kill-buffer (current-buffer)) - (when (buffer-live-p help-buffer) - (with-current-buffer help-buffer - (revert-buffer))))) - -(defun help-fns-edit-mode-cancel () - "Kill the edit buffer and cancel editing of the value. -This cancels value editing without updating the value." - (interactive nil help-fns--edit-value-mode) - (help-fns-edit-mode-done t)) + (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))))) (defun help-fns--run-describe-functions (functions &rest args) (with-current-buffer standard-output -- 2.45.1 --=-=-= Content-Type: text/plain -- Philip Kaludercic on peregrine --=-=-=--