Subject: bug#35487: closed (Re: bug#35487: Make visiting function from help-mode more customizable)

From: [email-masked] (GNU bug Tracking System)
Date: Tue, 28 May 2019 21:11:02 +0000

Your bug report

#35487: Make visiting function from help-mode more customizable

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
35487: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=35487
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#35487: Make visiting function from help-mode more customizable
From: Juri Linkov <[email-masked]>
To: Tak Kunihiro <[email-masked]>
Cc: [email-masked], martin rudalics <[email-masked]>, [email-masked]
Date: Wed, 29 May 2019 00:09:58 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

> I configured `f' in help-mode in following way based on comments
> and now it works good.
>
> Thank you Juri and Martin for the responses!

You are welcome.  Since it works good, I'm closing this request.

Subject: Make visiting function from help-mode more customizable
From: Tak Kunihiro <[email-masked]>
To: [email-masked]
Cc: [email-masked]
Date: Mon, 29 Apr 2019 21:30:14 +0900 (JST)
List-Id: <debbugs-submit.debbugs.gnu.org>

* Message

I often want to visit function from help-mode in `this window' in
stead of `other window'.  To do so, I found that to revise
help-function in help-function-def works.

I propose to (1) move help-function described as lambda function out
of button definition and (2) make function to visit function from
help-mode customizable.

After the revision, I can visit function from help-mode in `this
windows' as shown below.

#+begin_src emacs-lisp
(define-key help-mode-map (kbd "f")
  (lambda ()
    (interactive)
    (let ((help-switch-buffer-function 'switch-to-buffer))
      (push-button))))
#+end_src

I attach commit log and patch.

* Commit log

Author: Tak Kunihiro <[email-masked]>

    Make visiting function from help-mode more customizable
    
    * lisp/help-mode.el
    (define-button-type): Move definition of help-function out.
    (help-switch-buffer-function): Function to display buffer in help-mode.
    (help-find-function): Define help-function using a new variable
    `help-switch-buffer-function'.

* Patch

diff --git a/lisp/help-mode.el b/lisp/help-mode.el
index 6cc3f0d4f7..4e01e73181 100644
--- a/lisp/help-mode.el
+++ b/lisp/help-mode.el
@@ -192,32 +192,39 @@ 'help-customize-face
 
 (define-button-type 'help-function-def
   :supertype 'help-xref
-  'help-function (lambda (fun &optional file type)
-                   (or file
-                       (setq file (find-lisp-object-file-name fun type)))
-                   (if (not file)
-                       (message "Unable to find defining file")
-                     (require 'find-func)
-                     (when (eq file 'C-source)
-                       (setq file
-                             (help-C-file-name (indirect-function fun) 'fun)))
-                     ;; Don't use find-function-noselect because it follows
-                     ;; aliases (which fails for built-in functions).
-                     (let* ((location
-                             (find-function-search-for-symbol fun type file))
-                            (position (cdr location)))
-                       (pop-to-buffer (car location))
-                       (run-hooks 'find-function-after-hook)
-                       (if position
-                           (progn
-                             ;; Widen the buffer if necessary to go to this position.
-                             (when (or (< position (point-min))
-                                       (> position (point-max)))
-                               (widen))
-                             (goto-char position))
-                         (message "Unable to find location in file")))))
+  'help-function 'help-find-function
   'help-echo (purecopy "mouse-2, RET: find function's definition"))
 
+(defvar help-switch-buffer-function 'pop-to-buffer
+  "Function to display buffer in help-mode.")
+
+(defun help-find-function (fun &optional file type)
+  "Find object shown in help-mode."
+  (or file
+      (setq file (find-lisp-object-file-name fun type)))
+  (if (not file)
+      (message "Unable to find defining file")
+    (require 'find-func)
+    (when (eq file 'C-source)
+      (setq file
+            (help-C-file-name (indirect-function fun) 'fun)))
+    ;; Don't use find-function-noselect because it follows
+    ;; aliases (which fails for built-in functions).
+    (let* ((location
+            (find-function-search-for-symbol fun type file))
+           (position (cdr location)))
+      ;; (pop-to-buffer (car location))
+      (funcall help-switch-buffer-function (car location))
+      (run-hooks 'find-function-after-hook)
+      (if position
+          (progn
+            ;; Widen the buffer if necessary to go to this position.
+            (when (or (< position (point-min))
+                      (> position (point-max)))
+              (widen))
+            (goto-char position))
+        (message "Unable to find location in file")))))
+
 (define-button-type 'help-function-cmacro ; FIXME: Obsolete since 24.4.
   :supertype 'help-xref
   'help-function (lambda (fun file)