[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#6679: locate-library does not provide a default when called interact
bug#6679: locate-library does not provide a default when called interactively
Tue, 20 Jul 2010 21:14:09 -0600
Thunderbird 22.214.171.124 (Macintosh/20100228)
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)):
(let* ((dirs (or find-function-source-path load-path))
(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.
(setq def (and (locate-file-completion-table
dirs suffixes def nil 'lambda)
(completing-read (if def (format "Library name (default %s): " def)
"Library name: ")
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.
Denver, Colorado, USA