Mercurial > hg > xemacs-beta
comparison lisp/lib-complete.el @ 420:41dbb7a9d5f2 r21-2-18
Import from CVS: tag r21-2-18
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:24:09 +0200 |
parents | 697ef44129c6 |
children |
comparison
equal
deleted
inserted
replaced
419:66615b78f1a5 | 420:41dbb7a9d5f2 |
---|---|
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.2 $ $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 '(".el" ".el.gz" ".elc"))) | 257 '(".el" ".el.gz" ".elc"))) |
259 (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))) | |
260 | 271 |
261 ;; 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 |
262 ;; relative to the current directory, returning a *relative* pathname | 273 ;; relative to the current directory, returning a *relative* pathname |
263 ;; (read-file-name returns a full pathname). | 274 ;; (read-file-name returns a full pathname). |
264 ;; | 275 ;; |
265 ;; eg. (read-library "Local header: " '(nil) nil) | 276 ;; eg. (read-library "Local header: " '(nil) nil) |
266 | 277 |
267 (defun get-library-path () | |
268 "Front end to read-library" | |
269 (read-library "Find Library file: " load-path nil t t | |
270 (function (lambda (fn) | |
271 (cond | |
272 ;; decompression doesn't work with mule -slb | |
273 ((string-match (if (featurep 'mule) | |
274 "\\.el$" | |
275 "\\.el\\(\\.gz\\)?$") fn) | |
276 (substring fn 0 (match-beginning 0)))))) | |
277 )) | |
278 | |
279 ;;=== Replacement for load-library with completion ======================== | 278 ;;=== Replacement for load-library with completion ======================== |
280 | 279 |
281 (defun load-library (library) | 280 (defun load-library (library) |
282 "Load the library named LIBRARY. | 281 "Load the library named LIBRARY. |
283 This is an interface to the function `load'." | 282 This is an interface to the function `load'." |
284 (interactive | 283 (interactive |
285 (list (read-library "Load Library: " load-path nil nil nil | 284 (list (read-library "Load library: " load-path nil nil nil |
286 (function (lambda (fn) | 285 (function (lambda (fn) |
287 (cond | 286 (cond |
288 ((string-match "\\.elc?$" fn) | 287 ((string-match "\\.elc?$" fn) |
289 (substring fn 0 (match-beginning 0)))))) | 288 (substring fn 0 (match-beginning 0)))))) |
290 ))) | 289 ))) |
291 (load library)) | 290 (load library)) |
292 | 291 |
293 ;;=== find-library with completion (Author: Heiko Muenkel) =================== | 292 ;;=== find-library with completion (Author: Bob Weiner) =================== |
294 | 293 |
295 (defun find-library (library &optional codesys) | 294 (defun find-library (library &optional codesys display-function) |
296 "Find and edit the source for the library named LIBRARY. | 295 "Find and display in the current window the source for the Elisp LIBRARY. |
297 The extension of the LIBRARY must be omitted. | 296 LIBRARY should be a name without any path information and may include or omit |
298 Under XEmacs/Mule, the optional second argument specifies the | 297 the \".el\" suffix. Under XEmacs/Mule, the optional second argument CODESYS |
299 coding system to use when decoding the file. Interactively, | 298 specifies the coding system to use when decoding the file. Interactively, |
300 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'." | |
301 (interactive | 302 (interactive |
302 (list (get-library-path) | 303 (list (read-library-name "Find library: ") |
303 (if current-prefix-arg | 304 (if current-prefix-arg |
304 (read-coding-system "Coding System: ")))) | 305 (read-coding-system "Coding System: ")))) |
305 (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)))) | |
306 | 317 |
307 (defun find-library-other-window (library &optional codesys) | 318 (defun find-library-other-window (library &optional codesys) |
308 "Load the library named LIBRARY in another window. | 319 "Find and display in another window the source for the Elisp LIBRARY. |
309 Under XEmacs/Mule, the optional second argument specifies the | 320 LIBRARY should be a name without any path information and may include or omit |
310 coding system to use when decoding the file. Interactively, | 321 the \".el\" suffix. Under XEmacs/Mule, the optional second argument CODESYS |
311 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." | |
312 (interactive | 324 (interactive |
313 (list (get-library-path) | 325 (list (read-library-name "Find library in other window: ") |
314 (if current-prefix-arg | |
315 (read-coding-system "Coding System: ")))) | |
316 (find-file-other-window library codesys)) | |
317 | |
318 (defun find-library-other-frame (library &optional codesys) | |
319 "Load the library named LIBRARY in a newly-created frame. | |
320 Under XEmacs/Mule, the optional second argument specifies the | |
321 coding system to use when decoding the file. Interactively, | |
322 with a prefix argument, you will be prompted for the coding system." | |
323 (interactive | |
324 (list (get-library-path) | |
325 (if current-prefix-arg | 326 (if current-prefix-arg |
326 (read-coding-system "Coding System: ")))) | 327 (read-coding-system "Coding System: ")))) |
327 (find-file-other-frame library codesys)) | 328 (find-library library codesys 'find-file-other-window)) |
328 | 329 |
329 ; This conflicts with an existing binding | 330 (defun find-library-other-frame (library &optional codesys) |
330 ;(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) | |
331 (define-key global-map "\C-x4l" 'find-library-other-window) | 344 (define-key global-map "\C-x4l" 'find-library-other-window) |
332 (define-key global-map "\C-x5l" 'find-library-other-frame) | 345 (define-key global-map "\C-x5l" 'find-library-other-frame) |
333 | 346 |
334 (provide 'lib-complete) | 347 (provide 'lib-complete) |
335 | 348 |