unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Kevin Rodgers <kevin.d.rodgers@gmail.com>
To: bug-gnu-emacs@gnu.org
Cc: 6679@debbugs.gnu.org
Subject: bug#6679: locate-library does not provide a default when called interactively
Date: Tue, 20 Jul 2010 21:14:09 -0600	[thread overview]
Message-ID: <4C466601.5060707@gmail.com> (raw)
In-Reply-To: <i249ol$o2q$1@dough.gmane.org>

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






  reply	other threads:[~2010-07-21  3:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2020-03-28 21:59   ` Štěpán Němec
2020-04-03 12:01     ` bug#6652: " Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4C466601.5060707@gmail.com \
    --to=kevin.d.rodgers@gmail.com \
    --cc=6679@debbugs.gnu.org \
    --cc=bug-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).