unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Kevin Rodgers <ihs_4664@yahoo.com>
Subject: Re: Name completion for library
Date: Mon, 08 Aug 2005 13:20:07 -0600	[thread overview]
Message-ID: <dd8b98$qr8$1@sea.gmane.org> (raw)
In-Reply-To: <42F511F4.6050302@student.lu.se>

Lennart Borgman wrote:
 > Tim Johnson wrote:
 >>  Shucks! Xemacs will complete a library name, was hoping GNU
 >>  emacs would also.
 >>
 > It will. Soon I hope. When next version is released.

Or you can crib the Emacs 22 code from CVS.  I've almost got it working
in Emacs 21 (see the comments):

;; From Emacs 22 src/lread.c:
(defvar load-suffixes '(".elc" ".el")
   "List of suffixes to try for files to load.
This list should not include the empty string.")

(eval-when-compile
   (require 'cl))			; Emacs 21

;; From Emacs 22 lisp/files.el:
(defun locate-file-completion (string path-and-suffixes action)
   "Do completion for file names passed to `locate-file'.
PATH-AND-SUFFIXES is a pair of lists, (DIRECTORIES . SUFFIXES)."
   (if (file-name-absolute-p string)
       (read-file-name-internal string nil action)
     (let ((names nil)
	  (suffix (concat (regexp-opt (cdr path-and-suffixes) t) "\\'"))
	  (string-dir (file-name-directory string)))
       (dolist (dir (car path-and-suffixes))
	(unless dir
	  (setq dir default-directory))
	(if string-dir (setq dir (expand-file-name string-dir dir)))
	(when (file-directory-p dir)
	  (dolist (file (file-name-all-completions
			 (file-name-nondirectory string) dir))
	    (push (if string-dir (concat string-dir file) file) names)
	    (when (string-match suffix file)
	      (setq file (substring file 0 (match-beginning 0)))
	      (push (if string-dir (concat string-dir file) file) names)))))
       (setq names (mapcar 'list names))	; Emacs 21
       (cond
        ((eq action t) (all-completions string names))
        ((null action) (try-completion string names))
        (t nil)				; Emacs 21
        (t (test-completion string names))))))

(defadvice load-library (before interactive activate)
   "Provide completion when reading the library name."
   (interactive (list
                 (completing-read "Load library: "
                                  'locate-file-completion
                                  (cons load-path load-suffixes)))))

-- 
Kevin Rodgers

      reply	other threads:[~2005-08-08 19:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-06 18:36 Name completion for library Tim Johnson
2005-08-06 18:51 ` Peter Dyballa
2005-08-06 19:31   ` Tim Johnson
2005-08-06 19:38     ` Peter Dyballa
2005-08-06 19:39     ` Lennart Borgman
2005-08-08 19:20       ` Kevin Rodgers [this message]

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='dd8b98$qr8$1@sea.gmane.org' \
    --to=ihs_4664@yahoo.com \
    /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.
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).