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: Tue, 16 May 2017 21:08:07 +0200 Message-ID: References: <8897133a-0836-23a6-6bbe-aecc6ec8b7c8@aurox.ch> <9b566259-457c-faf2-10e1-42c084afccea@aurox.ch> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------7748E0D1FDA0E834DAB5C8FB" X-Trace: blaine.gmane.org 1494961755 16093 195.159.176.226 (16 May 2017 19:09:15 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 16 May 2017 19:09:15 +0000 (UTC) User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 To: Drew Adams , Philipp Stephani , 26712@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue May 16 21:09:09 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 1dAhqH-00041q-2Q for geb-bug-gnu-emacs@m.gmane.org; Tue, 16 May 2017 21:09:09 +0200 Original-Received: from localhost ([::1]:43579 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dAhqM-0007vm-Ox for geb-bug-gnu-emacs@m.gmane.org; Tue, 16 May 2017 15:09:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43772) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dAhqF-0007vW-Vh for bug-gnu-emacs@gnu.org; Tue, 16 May 2017 15:09:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dAhqB-0002hJ-Td for bug-gnu-emacs@gnu.org; Tue, 16 May 2017 15:09:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:46369) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dAhqB-0002h5-Nk for bug-gnu-emacs@gnu.org; Tue, 16 May 2017 15:09:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dAhqB-0007zq-I2 for bug-gnu-emacs@gnu.org; Tue, 16 May 2017 15:09:03 -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: Tue, 16 May 2017 19:09:03 +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: Original-Received: via spool by 26712-submit@debbugs.gnu.org id=B26712.149496168830677 (code B ref 26712); Tue, 16 May 2017 19:09:03 +0000 Original-Received: (at 26712) by debbugs.gnu.org; 16 May 2017 19:08:08 +0000 Original-Received: from localhost ([127.0.0.1]:49046 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dAhpI-0007yi-B1 for submit@debbugs.gnu.org; Tue, 16 May 2017 15:08:08 -0400 Original-Received: from sinyavsky.aurox.ch ([37.35.109.145]:48795) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dAhpG-0007yA-0T for 26712@debbugs.gnu.org; Tue, 16 May 2017 15:08:06 -0400 Original-Received: from sinyavsky.aurox.ch (sinyavsky.aurox.ch [127.0.0.1]) by sinyavsky.aurox.ch (Postfix) with ESMTP id 895B02242F for <26712@debbugs.gnu.org>; Tue, 16 May 2017 19:03:40 +0000 (UTC) Authentication-Results: sinyavsky.aurox.ch (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=aurox.ch DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=aurox.ch; h= content-type:content-type:in-reply-to:mime-version:user-agent :date:date:message-id:from:from:references:to:subject:subject; s=dkim; t=1494961417; x=1495825418; bh=1ZtCQ7zQTkl5u4BS0kDy49ml KxM3sEVgWaHtJqTuCTA=; b=QoL0C96aUJ0km5NkXrVridHV+wT+I3nsxSRw/Al2 lQo1p1X7BN4ks5vkXPmNUOItQ/aRf3YArF6/G7Tnu/O1NdflNAnOqKl0vy84qRMx i9mTUe+zbuK++a0YGrmz59F/k94K88giamhnLQ3Xz2WsCVYyR3Jj3PI0ZVr/Awv7 XVQ= X-Virus-Scanned: Debian amavisd-new at test.virtualizor.com Original-Received: from sinyavsky.aurox.ch ([127.0.0.1]) by sinyavsky.aurox.ch (sinyavsky.aurox.ch [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id tmRWINUBIQ0K for <26712@debbugs.gnu.org>; Tue, 16 May 2017 19:03:37 +0000 (UTC) Original-Received: from [192.168.1.121] (179.133.105.92.dynamic.wline.res.cust.swisscom.ch [92.105.133.179]) by sinyavsky.aurox.ch (Postfix) with ESMTPSA id 97D8822412; Tue, 16 May 2017 19:03:37 +0000 (UTC) In-Reply-To: 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:132545 Archived-At: This is a multi-part message in MIME format. --------------7748E0D1FDA0E834DAB5C8FB Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit I agree. Not sure if the `read-library' function should go in a different file, but in any case it makes sense to let users take advantage of it in their code. Attached is a revised patch with Philipp's other suggestions taken into account. On 07/05/2017 17:07, Drew Adams wrote: >> - Consider renaming `find-library-read' to >> `find-func--read-library' to make it internal. >> It's probably not intended as a public API. > Why? No. Please do not consider that. Not for a moment. > > FWIW, I completely disagree with this point of view and > approach to Emacs Lisp. Just the opposite. Unless there is > some _very_ important reason why something _must_ be branded > as "internal", it should not be. > > It may be a hard habit to break, but the notion of a "public > API" is generally inappropriate for Emacs Lisp. Emacs users > are also Emacs-Lisp developers. And yes, they do write their > own libraries that read input. > > Just imagine, if an input-reading function such as > `ffap-read-file-or-url', `read-file-name', `completing-read', > `read-face-name', or `read-char' were declared at the outset > to be "internal". What's the point of such an artificial > separation? > > In fact, I'd suggest that the library prefix be removed from > `find-library-read' - just call it `read-library-name'. > Elevate it; don't hide or suppress it. > > GNU Emacs in particular, and free software in general, have > the explicit intention that users _are_ developers and that > they look under the hood, tinker with engine parts, modify > or make their own use of them, to create new and better > things. > > And yes, Emacs development is driven not only by its > maintainers or those most active in its C code or fixing > its bugs. It is driven also, and importantly, by users, > who write their own code for their own uses, and who > sometimes extend that code into 3rd-party libraries. > > Some such development even finds its way into distributed > Emacs itself - either directly, by incorporating it, or > indirectly, by copy or inspiration. The latter happens > more than most people, including Emacs maintainers, are > aware of. > > Emacs would not be what it is today if it did not offer > features written by its users (think Org). And this has > been true of Emacs since Day One - even before GNU Emacs. > > So let's please stop with the tendency to view Emacs > development as an internal-vs-external thing: we core > developers and the code we maintain vs you "lusers" and > your customizations. > > If we are to have _any_ "internal" functions or variables > then the burden should be to demonstrate strongly why > a given one really _needs_ to be internal. A priori, > every single one should be "external" or, more exactly, > "nil-ternal". > > I see no good reason why a general function that reads a > library name should be flagged "internal". Why should > anyone be discouraged from using it in their code? Why > shouldn't everyone be encouraged to use it, if they want > to read a library name? > > This kind of not-for-the-users attitude smacks of > elitism, or at least seems control-freakish, even if it > is unconscious. Open the corral, please. Emacs, and > all of its code, belongs to its users. > > There is nothing special about this function. It is > useful generally. And it should be called something > like `read-library-name'. --------------7748E0D1FDA0E834DAB5C8FB Content-Type: text/x-patch; name="0001-New-commands-find-library-other-window-find-library-.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-New-commands-find-library-other-window-find-library-.pa"; filename*1="tch" >From 7edba19c49edeaa5efe244397dcd93f99fa6705d Mon Sep 17 00:00:00 2001 From: Charles A. Roelli Date: Tue, 16 May 2017 20:40:50 +0200 Subject: [PATCH] New commands: find-library-other-window, find-library-other-frame * lisp/emacs-lisp/find-func.el (find-library-other-window) (find-library-other-frame): New commands to complement the existing `find-library' command. (read-library-name): New function to read a library name. --- etc/NEWS | 3 + lisp/emacs-lisp/find-func.el | 90 +++++++++++++++++++++++++----------------- 2 files changed, 57 insertions(+), 36 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 25f0f18..bea4928 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -344,6 +344,9 @@ for DNS-querying functions 'nslookup-host', 'dns-lookup-host', and 'run-dig'. Each function now accepts an optional name server argument interactively (with a prefix argument) and non-interactively. +** Two new commands 'find-library-other-window' and +'find-library-other-frame'. + * Editing Changes in Emacs 26.1 diff --git a/lisp/emacs-lisp/find-func.el b/lisp/emacs-lisp/find-func.el index d0acc14..43be71b 100644 --- a/lisp/emacs-lisp/find-func.el +++ b/lisp/emacs-lisp/find-func.el @@ -271,44 +271,61 @@ find-function-C-source (cons (current-buffer) (match-beginning 0)))) ;;;###autoload -(defun find-library (library &optional other-window) - "Find the Emacs Lisp source of LIBRARY. -LIBRARY should be a string (the name of the library). If the -optional OTHER-WINDOW argument (i.e., the command argument) is -specified, pop to a different window before displaying the -buffer." - (interactive - (let* ((dirs (or find-function-source-path load-path)) - (suffixes (find-library-suffixes)) - (table (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)) - (thing-at-point 'symbol)))) - (when (and def (not (test-completion def table))) - (setq def nil)) - (list - (completing-read (if def - (format "Library name (default %s): " def) - "Library name: ") - table nil nil nil nil def) - current-prefix-arg))) +(defun find-library (library) + "Find the Emacs Lisp source of the LIBRARY near point. + +LIBRARY should be a string (the name of the library)." + (interactive (list (read-library-name))) + (prog1 + (switch-to-buffer (find-file-noselect (find-library-name library))) + (run-hooks 'find-function-after-hook))) + +(defun read-library-name () + "Read and return a library name, defaulting to the one near point." + (let* ((dirs (or find-function-source-path load-path)) + (suffixes (find-library-suffixes)) + (table (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)) + (thing-at-point 'symbol)))) + (when (and def (not (test-completion def table))) + (setq def nil)) + (completing-read (if def + (format "Library name (default %s): " def) + "Library name: ") + table nil nil nil nil def))) + +;;;###autoload +(defun find-library-other-window (library) + "Find, in another window, the file defining LIBRARY at or near point. + +See `find-library' for more details." + (interactive (list (read-library-name))) + (prog1 + (switch-to-buffer-other-window (find-file-noselect + (find-library-name library))) + (run-hooks 'find-function-after-hook))) + +;;;###autoload +(defun find-library-other-frame (library) + "Find, in another frame, the file defining LIBRARY at or near point. + +See `find-library' for more details." + (interactive (list (read-library-name))) (prog1 - (funcall (if other-window - 'pop-to-buffer - 'pop-to-buffer-same-window) - (find-file-noselect (find-library-name library))) + (switch-to-buffer-other-frame (find-file-noselect + (find-library-name library))) (run-hooks 'find-function-after-hook))) ;;;###autoload -- 1.7.4.4 --------------7748E0D1FDA0E834DAB5C8FB--