From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: "Charles A. Roelli" Newsgroups: gmane.emacs.bugs Subject: bug#26712: other-window/frame versions of find-library Date: Mon, 29 May 2017 21:39:10 +0200 Message-ID: References: <8897133a-0836-23a6-6bbe-aecc6ec8b7c8@aurox.ch> <9b566259-457c-faf2-10e1-42c084afccea@aurox.ch> <83tw4k61bv.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------5EE484FA2A7C99027B26908A" X-Trace: blaine.gmane.org 1496087590 12247 195.159.176.226 (29 May 2017 19:53:10 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 29 May 2017 19:53:10 +0000 (UTC) User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 To: 26712@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon May 29 21:53:06 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dFQiv-000312-HJ for geb-bug-gnu-emacs@m.gmane.org; Mon, 29 May 2017 21:53:05 +0200 Original-Received: from localhost ([::1]:50305 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFQj0-0004md-V6 for geb-bug-gnu-emacs@m.gmane.org; Mon, 29 May 2017 15:53:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42700) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFQWM-0002Vf-11 for bug-gnu-emacs@gnu.org; Mon, 29 May 2017 15:40:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFQWI-0002zI-OY for bug-gnu-emacs@gnu.org; Mon, 29 May 2017 15:40:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:41101) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dFQWI-0002zE-Kh for bug-gnu-emacs@gnu.org; Mon, 29 May 2017 15:40:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dFQWI-0003w5-ED for bug-gnu-emacs@gnu.org; Mon, 29 May 2017 15:40:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Charles A. Roelli" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 29 May 2017 19:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 26712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Cc: 26712@debbugs.gnu.org, Eli Zaretskii , Drew Adams Original-Received: via spool by submit@debbugs.gnu.org id=B.149608677815089 (code B ref -1); Mon, 29 May 2017 19:40:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 29 May 2017 19:39:38 +0000 Original-Received: from localhost ([127.0.0.1]:43777 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dFQVu-0003vJ-AJ for submit@debbugs.gnu.org; Mon, 29 May 2017 15:39:38 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:51511) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dFQVt-0003v7-3c for submit@debbugs.gnu.org; Mon, 29 May 2017 15:39:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFQVm-0002re-GY for submit@debbugs.gnu.org; Mon, 29 May 2017 15:39:31 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:60813) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFQVm-0002ra-CA for submit@debbugs.gnu.org; Mon, 29 May 2017 15:39:30 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42473) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFQVk-00025W-Hz for bug-gnu-emacs@gnu.org; Mon, 29 May 2017 15:39:30 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFQVh-0002qC-C4 for bug-gnu-emacs@gnu.org; Mon, 29 May 2017 15:39:28 -0400 Original-Received: from [195.159.176.226] (port=48255 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dFQVg-0002pg-VI for bug-gnu-emacs@gnu.org; Mon, 29 May 2017 15:39:25 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1dFQVY-0003DH-Ob for bug-gnu-emacs@gnu.org; Mon, 29 May 2017 21:39:16 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 185 Original-X-Complaints-To: usenet@blaine.gmane.org In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] 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: 208.118.235.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:133003 Archived-At: This is a multi-part message in MIME format. --------------5EE484FA2A7C99027B26908A Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Good idea. Is the attached patch OK? It augments 'C-x F', 'C-x 4 F' and 'C-x 5 F' to suggest library names too. On 21/05/2017 05:23, Richard Stallman wrote: > [[[ To any NSA and FBI agents reading my email: please consider ]]] > [[[ whether defending the US Constitution against all enemies, ]]] > [[[ foreign or domestic, requires you to follow Snowden's example. ]]] > > I think find-function is more useful to put on a key than > find-library. Or perhaps they can be combined. It should not be hard > to accept an argument and try it first as a function, then as a library. > > If the name is both a function and a library, the function definition > is almost surely in that library. > --------------5EE484FA2A7C99027B26908A Content-Type: text/x-patch; name="0001-New-commands-find-function-or-library-other-window-f.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-New-commands-find-function-or-library-other-window-f.pa"; filename*1="tch" >From 0c309fb5ad41d4c8c7e356ef365a02b6550a0e2e Mon Sep 17 00:00:00 2001 From: Charles A. Roelli Date: Mon, 29 May 2017 21:35:24 +0200 Subject: [PATCH] New commands: find-function-or-library (-other-window/-frame) * lisp/emacs-lisp/find-func.el (read-function-or-library-name): New function for reading a function or library name. (find-function-or-library, find-function-or-library-other-window) (find-function-or-library-other-frame): New commands. (find-function-setup-keys): Replace 'find-function' bindings with bindings to 'find-function-or-library'. * etc/NEWS: Mention 'find-function-or-library' and new bindings made by 'find-function-setup-keys'. --- etc/NEWS | 6 +++ lisp/emacs-lisp/find-func.el | 90 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 93 insertions(+), 3 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 60066b7..ee6efb9 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -363,6 +363,12 @@ large integers from being displayed as characters. ** Two new commands for finding the source code of Emacs Lisp libraries: 'find-library-other-window' and 'find-library-other-frame'. +** 'find-function-setup-keys' now binds 'C-x F', 'C-x 4 F' and 'C-x 5 +F' to the new command 'find-function-or-library' and its +other-window/-frame counterparts. The new commands find the Emacs +Lisp source code of a function or library, defaulting to the function +or library closest to point. + * Editing Changes in Emacs 26.1 diff --git a/lisp/emacs-lisp/find-func.el b/lisp/emacs-lisp/find-func.el index 9b98f05..9943598 100644 --- a/lisp/emacs-lisp/find-func.el +++ b/lisp/emacs-lisp/find-func.el @@ -310,6 +310,40 @@ read-library-name "Library name: ") table nil nil nil nil def))) +(defun read-function-or-library-name () + "Read and return a function or library name, defaulting to the one near point. + +A function name is the name of a symbol that satisfies the +predicate `fboundp'. A library name is the filename of an Emacs +Lisp library located in a directory under `load-path' (or +`find-function-source-path', if non-nil)." + (let* ((dirs (or find-function-source-path load-path)) + (suffixes (find-library-suffixes)) + (table (completion-table-merge + (apply-partially 'completion-table-with-predicate + obarray 'fboundp t) + (apply-partially 'locate-file-completion-table + dirs suffixes))) + (def (if (eq (function-called-at-point) 'require) + ;; `function-called-at-point' may return 'require + ;; with `point' anywhere on this line. So wrap the + ;; `save-excursion' below in a `condition-case' to + ;; avoid reporting a scan-error here. + (condition-case nil + (save-excursion + (backward-up-list) + (forward-char) + (forward-sexp 2) + (thing-at-point 'symbol)) + (error nil)) + (symbol-name (function-called-at-point))))) + (when (and def (not (test-completion def table))) + (setq def nil)) + (completing-read (if def + (format "Function or library name (default %s): " def) + "Function or library name: ") + table nil nil nil nil def))) + ;;;###autoload (defun find-library-other-window (library) "Find the Emacs Lisp source of LIBRARY in another window. @@ -537,6 +571,56 @@ find-function-other-frame (find-function-do-it function nil 'switch-to-buffer-other-frame)) ;;;###autoload +(defun find-function-or-library (function-or-library) + "Find the definition of the FUNCTION-OR-LIBRARY near point. + +Finds the source file containing the definition of the +function (selected by `function-called-at-point') or +library (loaded with `require') near point in a buffer and places +point before the definition. + +FUNCTION-OR-LIBRARY is searched for in +`find-function-source-path', if non-nil, otherwise in +`load-path'. See also `find-function-recenter-line' and +`find-function-after-hook'. + +If FUNCTION-OR-LIBRARY names both a function and a library, finds +the corresponding function definition." + (interactive (list (read-function-or-library-name))) + (let ((sym (if (stringp function-or-library) + (intern function-or-library) + function-or-library))) + (if (fboundp sym) + (find-function-do-it sym nil 'switch-to-buffer) + (find-library function-or-library)))) + +;;;###autoload +(defun find-function-or-library-other-window (function-or-library) + "Find, in another window, the definition of FUNCTION-OR-LIBRARY near point. + +See `find-function' for more details." + (interactive (list (read-function-or-library-name))) + (let ((sym (if (stringp function-or-library) + (intern function-or-library) + function-or-library))) + (if (fboundp sym) + (find-function-do-it sym nil 'switch-to-buffer-other-window) + (find-library-other-window function-or-library)))) + +;;;###autoload +(defun find-function-or-library-other-frame (function-or-library) + "Find, in another frame, the definition of FUNCTION-OR-LIBRARY near point. + +See `find-function' for more details." + (interactive (list (read-function-or-library-name))) + (let ((sym (if (stringp function-or-library) + (intern function-or-library) + function-or-library))) + (if (fboundp sym) + (find-function-do-it sym nil 'switch-to-buffer-other-frame) + (find-library-other-frame function-or-library)))) + +;;;###autoload (defun find-variable-noselect (variable &optional file) "Return a pair `(BUFFER . POINT)' pointing to the definition of VARIABLE. @@ -691,9 +775,9 @@ find-variable-at-point ;;;###autoload (defun find-function-setup-keys () "Define some key bindings for the find-function family of functions." - (define-key ctl-x-map "F" 'find-function) - (define-key ctl-x-4-map "F" 'find-function-other-window) - (define-key ctl-x-5-map "F" 'find-function-other-frame) + (define-key ctl-x-map "F" 'find-function-or-library) + (define-key ctl-x-4-map "F" 'find-function-or-library-other-window) + (define-key ctl-x-5-map "F" 'find-function-or-library-other-frame) (define-key ctl-x-map "K" 'find-function-on-key) (define-key ctl-x-4-map "K" 'find-function-on-key-other-window) (define-key ctl-x-5-map "K" 'find-function-on-key-other-frame) -- 1.7.4.4 --------------5EE484FA2A7C99027B26908A--