[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#6679: locate-library does not provide a default when called interact

From: Kevin Rodgers
Subject: bug#6679: locate-library does not provide a default when called interactively
Date: Tue, 20 Jul 2010 21:14:09 -0600
User-agent: Thunderbird (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))
          (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
                         (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)
      (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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]