emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Patch proposal: display symbol source code in help buffers


From: Ihor Radchenko
Subject: Re: Patch proposal: display symbol source code in help buffers
Date: Tue, 21 Sep 2021 17:17:19 +0800

Eli Zaretskii <eliz@gnu.org> writes:

>> Ihor Radchenko <yantar92@gmail.com> writes:
>> 
>> > I like this idea. Maybe we can simply change the default value of
>> > find-function-after-hook like in the attached patch?
>> 
>> We generally prefer not to add hooks like this if we can avoid it.  We
>> can usually just change the code instead.
>> 
>> For example, in this case maybe we could just call `push-mark' at the
>> end of `help-function-def--button-function'.
>
> Indeed, especially since the proposed change to find-func.el would
> affect all users of that package.

Agree. I updated the patch and also added support for
widen-automatically variable. See below.

Best,
Ihor

>From e94ae3711796679e330637921b980f970b9d7025 Mon Sep 17 00:00:00 2001
Message-Id: 
<e94ae3711796679e330637921b980f970b9d7025.1632215537.git.yantar92@gmail.com>
From: Ihor Radchenko <yantar92@gmail.com>
Date: Tue, 21 Sep 2021 17:00:50 +0800
Subject: [PATCH 1/2] Save position in mark ring before jumping to definition

* lisp/help-mode.el (help-function-def--button-function): Current
point is saved in the mark ring before jumping to definition.

Following up:
https://lists.gnu.org/archive/html/emacs-devel/2021-09/msg01561.html
---
 etc/NEWS          | 3 +++
 lisp/help-mode.el | 1 +
 2 files changed, 4 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index 2bdcb6434b..2132e8babc 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -648,7 +648,10 @@ clicking the "X" icon in the tool bar.
 
 ---
 *** 'g' ('revert-buffer') in 'help-mode' no longer requires confirmation.
+*** Jumping to function/variable source now saves mark before moving point
+Jumping to source from "*Help*" buffer moves the point when the source buffer 
is already open.  Now, the old point is pushed to mark ring.
 
+---
 ** File Locks
 
 +++
diff --git a/lisp/help-mode.el b/lisp/help-mode.el
index 551cf7e1a3..57655db337 100644
--- a/lisp/help-mode.el
+++ b/lisp/help-mode.el
@@ -268,6 +268,7 @@ help-function-def--button-function
             (when (or (< position (point-min))
                       (> position (point-max)))
               (widen))
+            (push-mark nil t)
             (goto-char position))
         (message "Unable to find location in file")))))
 
-- 
2.32.0

>From 109bd7192b5b672508b9fa1d53c10a5a8aec3846 Mon Sep 17 00:00:00 2001
Message-Id: 
<109bd7192b5b672508b9fa1d53c10a5a8aec3846.1632215537.git.yantar92@gmail.com>
In-Reply-To: 
<e94ae3711796679e330637921b980f970b9d7025.1632215537.git.yantar92@gmail.com>
References: 
<e94ae3711796679e330637921b980f970b9d7025.1632215537.git.yantar92@gmail.com>
From: Ihor Radchenko <yantar92@gmail.com>
Date: Tue, 21 Sep 2021 17:10:10 +0800
Subject: [PATCH 2/2] Honor widen-automatically in
 help-function-def--button-function

* lisp/help-mode.el (help-function-def--button-function): Ask user to
widen the buffer when `widen-automatically' is set to nil.
---
 lisp/help-mode.el | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lisp/help-mode.el b/lisp/help-mode.el
index 57655db337..5d566ca083 100644
--- a/lisp/help-mode.el
+++ b/lisp/help-mode.el
@@ -263,11 +263,14 @@ help-function-def--button-function
       (pop-to-buffer (car location))
       (run-hooks 'find-function-after-hook)
       (if position
-          (progn
+          (catch :exit
             ;; Widen the buffer if necessary to go to this position.
             (when (or (< position (point-min))
                       (> position (point-max)))
-              (widen))
+              (if (or widen-automatically
+                      (yes-or-no-p "The location is outside narrowing. Widen? 
"))
+                  (widen)
+                (throw :exit nil)))
             (push-mark nil t)
             (goto-char position))
         (message "Unable to find location in file")))))
-- 
2.32.0


reply via email to

[Prev in Thread] Current Thread [Next in Thread]