From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Tak Kunihiro Newsgroups: gmane.emacs.bugs Subject: bug#35487: Make visiting function from help-mode more customizable Date: Mon, 29 Apr 2019 21:30:14 +0900 (JST) Message-ID: <20190429.213014.526232842075202623.tkk@misasa.okayama-u.ac.jp> Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="54757"; mail-complaints-to="usenet@blaine.gmane.org" Cc: tkk@misasa.okayama-u.ac.jp To: 35487@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Apr 29 14:31:23 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hL5RK-000E4S-QN for geb-bug-gnu-emacs@m.gmane.org; Mon, 29 Apr 2019 14:31:23 +0200 Original-Received: from localhost ([127.0.0.1]:57017 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hL5RJ-0002yn-Sp for geb-bug-gnu-emacs@m.gmane.org; Mon, 29 Apr 2019 08:31:21 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:45379) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hL5RB-0002yT-To for bug-gnu-emacs@gnu.org; Mon, 29 Apr 2019 08:31:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hL5R6-0000SZ-6J for bug-gnu-emacs@gnu.org; Mon, 29 Apr 2019 08:31:10 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:53269) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hL5R0-0000Of-UL for bug-gnu-emacs@gnu.org; Mon, 29 Apr 2019 08:31:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hL5R0-00019L-LE for bug-gnu-emacs@gnu.org; Mon, 29 Apr 2019 08:31:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tak Kunihiro Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 29 Apr 2019 12:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 35487 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.15565410454394 (code B ref -1); Mon, 29 Apr 2019 12:31:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 29 Apr 2019 12:30:45 +0000 Original-Received: from localhost ([127.0.0.1]:38580 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hL5Qi-00018o-Lf for submit@debbugs.gnu.org; Mon, 29 Apr 2019 08:30:44 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:59183) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hL5Qh-00018a-1Q for submit@debbugs.gnu.org; Mon, 29 Apr 2019 08:30:43 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:55537) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hL5Qb-0008UT-3R for submit@debbugs.gnu.org; Mon, 29 Apr 2019 08:30:37 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:45326) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hL5QZ-0002a8-R3 for bug-gnu-emacs@gnu.org; Mon, 29 Apr 2019 08:30:36 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hL5QY-0008R0-KN for bug-gnu-emacs@gnu.org; Mon, 29 Apr 2019 08:30:35 -0400 Original-Received: from mlsec.cc.okayama-u.ac.jp ([42.127.236.175]:34214) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hL5QW-0008Gx-O2 for bug-gnu-emacs@gnu.org; Mon, 29 Apr 2019 08:30:34 -0400 Original-Received: from alml002.ouadm.okayama-u.ac.jp (unknown [42.127.236.168]) by mlsec.cc.okayama-u.ac.jp with smtp id 3aba_b6bd_50bf60fd_adcf_4a20_acd2_458995c877f6; Mon, 29 Apr 2019 21:30:20 +0900 Original-Received: from localhost (p282048-ipngn200211tottori.tottori.ocn.ne.jp [114.151.88.48]) by alml002.ouadm.okayama-u.ac.jp (Postfix) with ESMTPSA id 663BE4C09A8; Mon, 29 Apr 2019 21:30:12 +0900 (JST) X-Mailer: Mew version 6.8 on Emacs 26.2 X-NAI-Spam-Flag: NO X-NAI-Spam-Level: ********** X-NAI-Spam-Threshold: 11 X-NAI-Spam-Score: 10.1 X-NAI-Spam-Rules: 6 Rules triggered TS_MSG_REP_80_512=10, RCVD_BAD_SIP=0.1, EDT_SA_AU_PASS=0, EDT_SA_DN_PASS=0, EDT_SA_TS_FAIL=0, RV6534=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6534> : inlines <7062> : streams <1820067> : uri <2838474> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:158425 Archived-At: * 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 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)