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.

Full log


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





This bug report was last modified 5 years and 51 days ago.

Previous Next


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