help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Name completion for library


From: Kevin Rodgers
Subject: Re: Name completion for library
Date: Mon, 08 Aug 2005 13:20:07 -0600
User-agent: Mozilla Thunderbird 0.9 (X11/20041105)

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 via email to

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