GNU bug report logs - #6679
locate-library does not provide a default when called interactively

Previous Next

Package: emacs;

Reported by: Kevin Rodgers <kevin.d.rodgers <at> gmail.com>

Date: Tue, 20 Jul 2010 13:54:02 UTC

Severity: wishlist

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 6679 in the body.
You can then email your comments to 6679 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#6679; Package emacs. (Tue, 20 Jul 2010 13:54:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Kevin Rodgers <kevin.d.rodgers <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 20 Jul 2010 13:54:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Kevin Rodgers <kevin.d.rodgers <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: locate-library does not provide a default when called interactively
Date: Tue, 20 Jul 2010 07:53:32 -0600
See bug 6652 for a use case.

Here's a patch -- should the default be included in the prompt, or
is the user expected to know to try M-n?

2010-07-20  Kevin Rodgers  <kevin.d.rodgers <at> gmail.com>

	* subr.el (locate-library):  Provide a default LIBRARY
	when called interactively.


*** emacs-23.2/lisp/subr.el~	Sat Apr  3 16:26:12 2010
--- emacs-23.2/lisp/subr.el	Tue Jul 20 07:38:58 2010
***************
*** 1583,1589 ****
    (interactive (list (completing-read "Locate library: "
  				      (apply-partially
                                         'locate-file-completion-table
!                                        load-path (get-load-suffixes)))
  		     nil nil
  		     t))
    (let ((file (locate-file library
--- 1583,1594 ----
    (interactive (list (completing-read "Locate library: "
  				      (apply-partially
                                         'locate-file-completion-table
!                                        load-path (get-load-suffixes))
! 				      nil nil nil nil
! 				      ;; discard text props from default
! 				      ;; to avoid side-effects (visiting file):
! 				      (substring-no-properties
! 				       (thing-at-point 'filename)))
  		     nil nil
  		     t))
    (let ((file (locate-file library


-- 
Kevin Rodgers
Denver, Colorado, USA





Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#6679; Package emacs. (Wed, 21 Jul 2010 03:14:01 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Kevin Rodgers <kevin.d.rodgers <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Cc: 6679 <at> debbugs.gnu.org
Subject: Re: bug#6679: locate-library does not provide a default when called
	interactively
Date: Tue, 20 Jul 2010 21:14:09 -0600
Kevin Rodgers wrote:
> See bug 6652 for a use case.
> 
> Here's a patch -- should the default be included in the prompt, or
> is the user expected to know to try M-n?

I thought to check what find-library does, and found something rather
more complicated than (completing-read ... (thing-at-point 'filename)):

  (interactive
   (let* ((dirs (or find-function-source-path load-path))
          (suffixes (find-library-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 def
       (setq def (and (locate-file-completion-table
                       dirs suffixes def nil 'lambda)
                      def)))
     (list
      (completing-read (if def (format "Library name (default %s): " def)
			 "Library name: ")
		       (apply-partially 'locate-file-completion-table
                                        dirs suffixes)
                       nil nil nil nil def))))

Assuming that complexity is justified, it ought to be factored into a
read-library-name utility that both find-library and locate-library use.

Note that for some reason the DEF argument to completing-read needs to be
(substring-no-properties def), to prevent completing read from visiting the
file itself when point is on a file name hyperlink in a *Help* buffer (with
help-args text property).  But I suppose that is a separate bug.

`C-h a -library\'' returns apropos-library and load-library in addition to
find-library and locate-library, but it's not clear to me that they would
benefit from a default.

-- 
Kevin Rodgers
Denver, Colorado, USA





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#6679; Package emacs. (Mon, 30 Mar 2020 02:36:44 GMT) Full text and rfc822 format available.

Message #11 received at 6679 <at> debbugs.gnu.org (full text, mbox):

From: Štěpán Němec <stepnem <at> gmail.com>
To: Kevin Rodgers <kevin.d.rodgers <at> gmail.com>
Cc: 6679 <at> debbugs.gnu.org
Subject: Re: bug#6679: locate-library does not provide a default when called
 interactively
Date: Sat, 28 Mar 2020 22:59:44 +0100
[Message part 1 (text/plain, inline)]
tags 6679 + patch
thanks

On Tue, 20 Jul 2010 21:14:09 -0600
Kevin Rodgers wrote:

> Assuming that complexity is justified, it ought to be factored into a
> read-library-name utility that both find-library and locate-library use.

The first part has since happened (`read-library-name'), all that is
needed is the latter. Patch attached.

> `C-h a -library\'' returns apropos-library and load-library in addition to
> find-library and locate-library, but it's not clear to me that they would
> benefit from a default.

The patch also handles `load-library'. The set of arguments/completions
expected/provided by `apropos-library' is slightly different and
requires other validation, so `read-library-name' wouldn't really help
there.

-- 
Štěpán

[0001-load-library-locate-library-Use-read-library-name.patch (text/x-patch, inline)]
>From 14acebb7a31da36423c8601033fe209efc95d1da Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20N=C4=9Bmec?= <stepnem <at> gmail.com>
Date: Sat, 28 Mar 2020 22:16:28 +0100
Subject: [PATCH] load-library, locate-library: Use read-library-name

* lisp/emacs-lisp/find-func.el (read-library-name): Add autoload
cookie.
* lisp/files.el (load-library)
* lisp/subr.el (locate-library): Use 'read-library-name' when called
interactively. (bug#6652 bug#6679)
---
 lisp/emacs-lisp/find-func.el | 1 +
 lisp/files.el                | 7 +------
 lisp/subr.el                 | 7 +------
 3 files changed, 3 insertions(+), 12 deletions(-)

diff --git a/lisp/emacs-lisp/find-func.el b/lisp/emacs-lisp/find-func.el
index 167ead3ce0..e35db56550 100644
--- a/lisp/emacs-lisp/find-func.el
+++ b/lisp/emacs-lisp/find-func.el
@@ -279,6 +279,7 @@ find-library
       (switch-to-buffer (find-file-noselect (find-library-name library)))
     (run-hooks 'find-function-after-hook)))
 
+;;;###autoload
 (defun read-library-name ()
   "Read and return a library name, defaulting to the one near point.
 
diff --git a/lisp/files.el b/lisp/files.el
index 8ce0187f5b..5249b150c5 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1101,12 +1101,7 @@ load-library
 
 See Info node `(emacs)Lisp Libraries' for more details.
 See `load-file' for a different interface to `load'."
-  (interactive
-   (let (completion-ignored-extensions)
-     (list (completing-read "Load library: "
-                            (apply-partially 'locate-file-completion-table
-                                             load-path
-                                             (get-load-suffixes))))))
+  (interactive (list (read-library-name)))
   (load library))
 
 (defun file-remote-p (file &optional identification connected)
diff --git a/lisp/subr.el b/lisp/subr.el
index 70f33ee5bd..70a74fba66 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2301,12 +2301,7 @@ locate-library
 When called from a program, the file name is normally returned as a
 string.  When run interactively, the argument INTERACTIVE-CALL is t,
 and the file name is displayed in the echo area."
-  (interactive (list (completing-read "Locate library: "
-				      (apply-partially
-                                       'locate-file-completion-table
-                                       load-path (get-load-suffixes)))
-		     nil nil
-		     t))
+  (interactive (list (read-library-name) nil nil t))
   (let ((file (locate-file library
 			   (or path load-path)
 			   (append (unless nosuffix (get-load-suffixes))
-- 
2.26.0


Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Fri, 03 Apr 2020 12:02:02 GMT) Full text and rfc822 format available.

Notification sent to Kevin Rodgers <kevin.d.rodgers <at> gmail.com>:
bug acknowledged by developer. (Fri, 03 Apr 2020 12:02:03 GMT) Full text and rfc822 format available.

Message #16 received at 6679-done <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Štěpán Němec <stepnem <at> gmail.com>
Cc: 6679-done <at> debbugs.gnu.org, kevin.d.rodgers <at> gmail.com,
 6652-done <at> debbugs.gnu.org
Subject: Re: bug#6679: locate-library does not provide a default when called
 interactively
Date: Fri, 03 Apr 2020 15:01:08 +0300
> From: Štěpán Němec
>  <stepnem <at> gmail.com>
> Date: Sat, 28 Mar 2020 22:59:44 +0100
> Cc: 6679 <at> debbugs.gnu.org
> 
> On Tue, 20 Jul 2010 21:14:09 -0600
> Kevin Rodgers wrote:
> 
> > Assuming that complexity is justified, it ought to be factored into a
> > read-library-name utility that both find-library and locate-library use.
> 
> The first part has since happened (`read-library-name'), all that is
> needed is the latter. Patch attached.
> 
> > `C-h a -library\'' returns apropos-library and load-library in addition to
> > find-library and locate-library, but it's not clear to me that they would
> > benefit from a default.
> 
> The patch also handles `load-library'. The set of arguments/completions
> expected/provided by `apropos-library' is slightly different and
> requires other validation, so `read-library-name' wouldn't really help
> there.

Thanks, pushed to the master branch.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 02 May 2020 11:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 360 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.