Mercurial > hg > xemacs-beta
comparison lisp/lib-complete.el @ 412:697ef44129c6 r21-2-14
Import from CVS: tag r21-2-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:20:41 +0200 |
parents | 74fd4e045ea6 |
children | 41dbb7a9d5f2 |
comparison
equal
deleted
inserted
replaced
411:12e008d41344 | 412:697ef44129c6 |
---|---|
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: $ | |
41 ;; ======================================================================== | 42 ;; ======================================================================== |
42 ;; NOTE: XEmacs must be redumped if this file is changed. | 43 ;; NOTE: XEmacs must be redumped if this file is changed. |
43 ;; | 44 ;; |
44 ;; Copyright (C) Mike Williams <mike-w@cs.aukuni.ac.nz> 1991 | 45 ;; Copyright (C) Mike Williams <mike-w@cs.aukuni.ac.nz> 1991 |
45 ;; | 46 ;; |
54 ;; There is now the new function find-library in this package. | 55 ;; There is now the new function find-library in this package. |
55 | 56 |
56 ;;; ChangeLog: | 57 ;;; ChangeLog: |
57 | 58 |
58 ;; 4/26/97: sb Mule-ize. | 59 ;; 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) | |
220 | 221 |
221 (defun read-library-internal (FILE FILTER FLAG) | 222 (defun read-library-internal (FILE FILTER FLAG) |
222 "Don't call this." | 223 "Don't call this." |
223 ;; Relies on read-library-internal-search-path being let-bound | 224 ;; Relies on read-library-internal-search-path being let-bound |
224 (let ((completion-table | 225 (let ((completion-table |
252 (library (completing-read PROMPT 'read-library-internal | 253 (library (completing-read PROMPT 'read-library-internal |
253 FILTER (or MUST-MATCH FULL) nil))) | 254 FILTER (or MUST-MATCH FULL) nil))) |
254 (cond | 255 (cond |
255 ((equal library "") DEFAULT) | 256 ((equal library "") DEFAULT) |
256 (FULL (locate-file library read-library-internal-search-path | 257 (FULL (locate-file library read-library-internal-search-path |
257 '(".el" ".el.gz" ".elc"))) | 258 '(".el" ".el.gz" ".elc"))) |
258 (t library)))) | 259 (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))) | |
271 | 260 |
272 ;; NOTE: as a special case, read-library may be used to read a filename | 261 ;; NOTE: as a special case, read-library may be used to read a filename |
273 ;; relative to the current directory, returning a *relative* pathname | 262 ;; relative to the current directory, returning a *relative* pathname |
274 ;; (read-file-name returns a full pathname). | 263 ;; (read-file-name returns a full pathname). |
275 ;; | 264 ;; |
276 ;; eg. (read-library "Local header: " '(nil) nil) | 265 ;; eg. (read-library "Local header: " '(nil) nil) |
277 | 266 |
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 | |
278 ;;=== Replacement for load-library with completion ======================== | 279 ;;=== Replacement for load-library with completion ======================== |
279 | 280 |
280 (defun load-library (library) | 281 (defun load-library (library) |
281 "Load the library named LIBRARY. | 282 "Load the library named LIBRARY. |
282 This is an interface to the function `load'." | 283 This is an interface to the function `load'." |
283 (interactive | 284 (interactive |
284 (list (read-library "Load library: " load-path nil nil nil | 285 (list (read-library "Load Library: " load-path nil nil nil |
285 (function (lambda (fn) | 286 (function (lambda (fn) |
286 (cond | 287 (cond |
287 ((string-match "\\.elc?$" fn) | 288 ((string-match "\\.elc?$" fn) |
288 (substring fn 0 (match-beginning 0)))))) | 289 (substring fn 0 (match-beginning 0)))))) |
289 ))) | 290 ))) |
290 (load library)) | 291 (load library)) |
291 | 292 |
292 ;;=== find-library with completion (Author: Bob Weiner) =================== | 293 ;;=== find-library with completion (Author: Heiko Muenkel) =================== |
293 | 294 |
294 (defun find-library (library &optional codesys display-function) | 295 (defun find-library (library &optional codesys) |
295 "Find and display in the current window the source for the Elisp LIBRARY. | 296 "Find and edit the source for the library named LIBRARY. |
296 LIBRARY should be a name without any path information and may include or omit | 297 The extension of the LIBRARY must be omitted. |
297 the \".el\" suffix. Under XEmacs/Mule, the optional second argument CODESYS | 298 Under XEmacs/Mule, the optional second argument specifies the |
298 specifies the coding system to use when decoding the file. Interactively, | 299 coding system to use when decoding the file. Interactively, |
299 with a prefix argument, this prompts for the coding system. Optional third | 300 with a prefix argument, you will be prompted for the coding system." |
300 argument DISPLAY-FUNCTION must take two arguments, the filename to display | |
301 and CODESYS. The default for DISPLAY-FUNCTION is `find-file'." | |
302 (interactive | 301 (interactive |
303 (list (read-library-name "Find library: ") | 302 (list (get-library-path) |
304 (if current-prefix-arg | 303 (if current-prefix-arg |
305 (read-coding-system "Coding System: ")))) | 304 (read-coding-system "Coding System: ")))) |
306 (let ((path (if (or (null library) (equal library "")) | 305 (find-file library codesys)) |
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)))) | |
317 | 306 |
318 (defun find-library-other-window (library &optional codesys) | 307 (defun find-library-other-window (library &optional codesys) |
319 "Find and display in another window the source for the Elisp LIBRARY. | 308 "Load the library named LIBRARY in another window. |
320 LIBRARY should be a name without any path information and may include or omit | 309 Under XEmacs/Mule, the optional second argument specifies the |
321 the \".el\" suffix. Under XEmacs/Mule, the optional second argument CODESYS | 310 coding system to use when decoding the file. Interactively, |
322 specifies the coding system to use when decoding the file. Interactively, | 311 with a prefix argument, you will be prompted for the coding system." |
323 with a prefix argument, this prompts for the coding system." | |
324 (interactive | 312 (interactive |
325 (list (read-library-name "Find library in other window: ") | 313 (list (get-library-path) |
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) | |
326 (if current-prefix-arg | 325 (if current-prefix-arg |
327 (read-coding-system "Coding System: ")))) | 326 (read-coding-system "Coding System: ")))) |
328 (find-library library codesys 'find-file-other-window)) | 327 (find-file-other-frame library codesys)) |
329 | 328 |
330 (defun find-library-other-frame (library &optional codesys) | 329 ; This conflicts with an existing binding |
331 "Find and display in another frame the source for the Elisp LIBRARY. | 330 ;(define-key global-map "\C-xl" 'find-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) | |
344 (define-key global-map "\C-x4l" 'find-library-other-window) | 331 (define-key global-map "\C-x4l" 'find-library-other-window) |
345 (define-key global-map "\C-x5l" 'find-library-other-frame) | 332 (define-key global-map "\C-x5l" 'find-library-other-frame) |
346 | 333 |
347 (provide 'lib-complete) | 334 (provide 'lib-complete) |
348 | 335 |