unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#6679: locate-library does not provide a default when called interactively
@ 2010-07-20 13:53 Kevin Rodgers
  2010-07-21  3:14 ` Kevin Rodgers
  0 siblings, 1 reply; 4+ messages in thread
From: Kevin Rodgers @ 2010-07-20 13:53 UTC (permalink / raw)
  To: 6679

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@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






^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#6679: locate-library does not provide a default when called interactively
  2010-07-20 13:53 bug#6679: locate-library does not provide a default when called interactively Kevin Rodgers
@ 2010-07-21  3:14 ` Kevin Rodgers
  2020-03-28 21:59   ` Štěpán Němec
  0 siblings, 1 reply; 4+ messages in thread
From: Kevin Rodgers @ 2010-07-21  3:14 UTC (permalink / raw)
  To: bug-gnu-emacs; +Cc: 6679

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






^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#6679: locate-library does not provide a default when called interactively
  2010-07-21  3:14 ` Kevin Rodgers
@ 2020-03-28 21:59   ` Štěpán Němec
  2020-04-03 12:01     ` bug#6652: " Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Štěpán Němec @ 2020-03-28 21:59 UTC (permalink / raw)
  To: Kevin Rodgers; +Cc: 6679

[-- Attachment #1: Type: text/plain, Size: 774 bytes --]

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-load-library-locate-library-Use-read-library-name.patch --]
[-- Type: text/x-patch, Size: 2573 bytes --]

>From 14acebb7a31da36423c8601033fe209efc95d1da Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20N=C4=9Bmec?= <stepnem@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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#6652: bug#6679: locate-library does not provide a default when called interactively
  2020-03-28 21:59   ` Štěpán Němec
@ 2020-04-03 12:01     ` Eli Zaretskii
  0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2020-04-03 12:01 UTC (permalink / raw)
  To: Štěpán Němec; +Cc: 6679-done, kevin.d.rodgers, 6652-done

> From: Štěpán Němec
>  <stepnem@gmail.com>
> Date: Sat, 28 Mar 2020 22:59:44 +0100
> Cc: 6679@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.





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-04-03 12:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-20 13:53 bug#6679: locate-library does not provide a default when called interactively Kevin Rodgers
2010-07-21  3:14 ` Kevin Rodgers
2020-03-28 21:59   ` Štěpán Němec
2020-04-03 12:01     ` bug#6652: " Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).