comparison lisp/lib-complete.el @ 398:74fd4e045ea6 r21-2-29

Import from CVS: tag r21-2-29
author cvs
date Mon, 13 Aug 2007 11:13:30 +0200
parents 8626e4521993
children 697ef44129c6
comparison
equal deleted inserted replaced
397:f4aeb21a5bad 398:74fd4e045ea6
36 ;; Author : Mike Williams <mike-w@cs.aukuni.ac.nz> 36 ;; Author : Mike Williams <mike-w@cs.aukuni.ac.nz>
37 ;; Created On : Sat Apr 20 17:47:21 1991 37 ;; Created On : Sat Apr 20 17:47:21 1991
38 ;; Last Modified By: Heiko M|nkel <muenkel@tnt.uni-hannover.de> 38 ;; Last Modified By: Heiko M|nkel <muenkel@tnt.uni-hannover.de>
39 ;; Additional XEmacs integration By: Chuck Thompson <cthomp@cs.uiuc.edu> 39 ;; Additional XEmacs integration By: Chuck Thompson <cthomp@cs.uiuc.edu>
40 ;; Last Modified On: Thu Jul 1 14:23:00 1994 40 ;; Last Modified On: Thu Jul 1 14:23:00 1994
41 ;; RCS Info : $Revision: 1.3.2.1 $ $Locker: $
42 ;; ======================================================================== 41 ;; ========================================================================
43 ;; NOTE: XEmacs must be redumped if this file is changed. 42 ;; NOTE: XEmacs must be redumped if this file is changed.
44 ;; 43 ;;
45 ;; Copyright (C) Mike Williams <mike-w@cs.aukuni.ac.nz> 1991 44 ;; Copyright (C) Mike Williams <mike-w@cs.aukuni.ac.nz> 1991
46 ;; 45 ;;
55 ;; There is now the new function find-library in this package. 54 ;; There is now the new function find-library in this package.
56 55
57 ;;; ChangeLog: 56 ;;; ChangeLog:
58 57
59 ;; 4/26/97: sb Mule-ize. 58 ;; 4/26/97: sb Mule-ize.
59 ;; 6/24/1999 much rewriting from Bob Weiner
60 60
61 ;;; Code: 61 ;;; Code:
62 62
63 ;;=== Determine completions for filename in search path =================== 63 ;;=== Determine completions for filename in search path ===================
64 64
215 ;; Trim cache 215 ;; Trim cache
216 (let ((tail (nthcdr lib-complete:max-cache-size lib-complete:cache))) 216 (let ((tail (nthcdr lib-complete:max-cache-size lib-complete:cache)))
217 (if tail (setcdr tail nil))))) 217 (if tail (setcdr tail nil)))))
218 218
219 ;;=== Read a filename, with completion in a search path =================== 219 ;;=== Read a filename, with completion in a search path ===================
220 (defvar read-library-internal-search-path)
221 220
222 (defun read-library-internal (FILE FILTER FLAG) 221 (defun read-library-internal (FILE FILTER FLAG)
223 "Don't call this." 222 "Don't call this."
224 ;; Relies on read-library-internal-search-path being let-bound 223 ;; Relies on read-library-internal-search-path being let-bound
225 (let ((completion-table 224 (let ((completion-table
253 (library (completing-read PROMPT 'read-library-internal 252 (library (completing-read PROMPT 'read-library-internal
254 FILTER (or MUST-MATCH FULL) nil))) 253 FILTER (or MUST-MATCH FULL) nil)))
255 (cond 254 (cond
256 ((equal library "") DEFAULT) 255 ((equal library "") DEFAULT)
257 (FULL (locate-file library read-library-internal-search-path 256 (FULL (locate-file library read-library-internal-search-path
258 ;; decompression doesn't work with Mule -slb 257 '(".el" ".el.gz" ".elc")))
259 (if (featurep 'mule)
260 ".el:.elc"
261 ".el:.el.gz:.elc")))
262 (t library)))) 258 (t library))))
259
260 (defun read-library-name (prompt)
261 "PROMPTs for and returns an existing Elisp library name (without any suffix) or the empty string."
262 (interactive)
263 (let ((read-library-internal-search-path load-path))
264 (completing-read prompt
265 'read-library-internal
266 (lambda (fn)
267 (cond
268 ((string-match "\\.el\\(\\.gz\\|\\.Z\\)?$" fn)
269 (substring fn 0 (match-beginning 0)))))
270 t nil)))
263 271
264 ;; NOTE: as a special case, read-library may be used to read a filename 272 ;; NOTE: as a special case, read-library may be used to read a filename
265 ;; relative to the current directory, returning a *relative* pathname 273 ;; relative to the current directory, returning a *relative* pathname
266 ;; (read-file-name returns a full pathname). 274 ;; (read-file-name returns a full pathname).
267 ;; 275 ;;
268 ;; eg. (read-library "Local header: " '(nil) nil) 276 ;; eg. (read-library "Local header: " '(nil) nil)
269 277
270 (defun get-library-path ()
271 "Front end to read-library"
272 (read-library "Find Library file: " load-path nil t t
273 (function (lambda (fn)
274 (cond
275 ;; decompression doesn't work with mule -slb
276 ((string-match (if (featurep 'mule)
277 "\\.el$"
278 "\\.el\\(\\.gz\\)?$") fn)
279 (substring fn 0 (match-beginning 0))))))
280 ))
281
282 ;;=== Replacement for load-library with completion ======================== 278 ;;=== Replacement for load-library with completion ========================
283 279
284 (defun load-library (library) 280 (defun load-library (library)
285 "Load the library named LIBRARY. 281 "Load the library named LIBRARY.
286 This is an interface to the function `load'." 282 This is an interface to the function `load'."
287 (interactive 283 (interactive
288 (list (read-library "Load Library: " load-path nil nil nil 284 (list (read-library "Load library: " load-path nil nil nil
289 (function (lambda (fn) 285 (function (lambda (fn)
290 (cond 286 (cond
291 ((string-match "\\.elc?$" fn) 287 ((string-match "\\.elc?$" fn)
292 (substring fn 0 (match-beginning 0)))))) 288 (substring fn 0 (match-beginning 0))))))
293 ))) 289 )))
294 (load library)) 290 (load library))
295 291
296 ;;=== find-library with completion (Author: Heiko Muenkel) =================== 292 ;;=== find-library with completion (Author: Bob Weiner) ===================
297 293
298 (defun find-library (library &optional codesys) 294 (defun find-library (library &optional codesys display-function)
299 "Find and edit the source for the library named LIBRARY. 295 "Find and display in the current window the source for the Elisp LIBRARY.
300 The extension of the LIBRARY must be omitted. 296 LIBRARY should be a name without any path information and may include or omit
301 Under XEmacs/Mule, the optional second argument specifies the 297 the \".el\" suffix. Under XEmacs/Mule, the optional second argument CODESYS
302 coding system to use when decoding the file. Interactively, 298 specifies the coding system to use when decoding the file. Interactively,
303 with a prefix argument, you will be prompted for the coding system." 299 with a prefix argument, this prompts for the coding system. Optional third
300 argument DISPLAY-FUNCTION must take two arguments, the filename to display
301 and CODESYS. The default for DISPLAY-FUNCTION is `find-file'."
304 (interactive 302 (interactive
305 (list (get-library-path) 303 (list (read-library-name "Find library: ")
306 (if current-prefix-arg 304 (if current-prefix-arg
307 (read-coding-system "Coding System: ")))) 305 (read-coding-system "Coding System: "))))
308 (find-file library codesys)) 306 (let ((path (if (or (null library) (equal library ""))
307 nil
308 (locate-file library load-path
309 ;; decompression doesn't work with Mule -slb
310 (if (featurep 'mule)
311 ":.el:.elc"
312 ":.el:.el.gz:.el.Z:.elc")))))
313 (if path (funcall (if (fboundp display-function)
314 display-function 'find-file)
315 path codesys)
316 (error "(find-library): Cannot locate library `%s'" library))))
309 317
310 (defun find-library-other-window (library &optional codesys) 318 (defun find-library-other-window (library &optional codesys)
311 "Load the library named LIBRARY in another window. 319 "Find and display in another window the source for the Elisp LIBRARY.
312 Under XEmacs/Mule, the optional second argument specifies the 320 LIBRARY should be a name without any path information and may include or omit
313 coding system to use when decoding the file. Interactively, 321 the \".el\" suffix. Under XEmacs/Mule, the optional second argument CODESYS
314 with a prefix argument, you will be prompted for the coding system." 322 specifies the coding system to use when decoding the file. Interactively,
323 with a prefix argument, this prompts for the coding system."
315 (interactive 324 (interactive
316 (list (get-library-path) 325 (list (read-library-name "Find library in other window: ")
317 (if current-prefix-arg
318 (read-coding-system "Coding System: "))))
319 (find-file-other-window library codesys))
320
321 (defun find-library-other-frame (library &optional codesys)
322 "Load the library named LIBRARY in a newly-created frame.
323 Under XEmacs/Mule, the optional second argument specifies the
324 coding system to use when decoding the file. Interactively,
325 with a prefix argument, you will be prompted for the coding system."
326 (interactive
327 (list (get-library-path)
328 (if current-prefix-arg 326 (if current-prefix-arg
329 (read-coding-system "Coding System: ")))) 327 (read-coding-system "Coding System: "))))
330 (find-file-other-frame library codesys)) 328 (find-library library codesys 'find-file-other-window))
331 329
332 ; This conflicts with an existing binding 330 (defun find-library-other-frame (library &optional codesys)
333 ;(define-key global-map "\C-xl" 'find-library) 331 "Find and display in another frame the source for the Elisp LIBRARY.
332 LIBRARY should be a name without any path information and may include or omit
333 the \".el\" suffix. Under XEmacs/Mule, the optional second argument CODESYS
334 specifies the coding system to use when decoding the file. Interactively,
335 with a prefix argument, this prompts for the coding system."
336 (interactive
337 (list (read-library-name "Find library in other frame: ")
338 (if current-prefix-arg
339 (read-coding-system "Coding System: "))))
340 (find-library library codesys 'find-file-other-frame))
341
342 ;; This conflicts with an existing binding.
343 ;;(define-key global-map "\C-xl" 'find-library)
334 (define-key global-map "\C-x4l" 'find-library-other-window) 344 (define-key global-map "\C-x4l" 'find-library-other-window)
335 (define-key global-map "\C-x5l" 'find-library-other-frame) 345 (define-key global-map "\C-x5l" 'find-library-other-frame)
336 346
337 (provide 'lib-complete) 347 (provide 'lib-complete)
338 348