Mercurial > emacs
comparison lisp/complete.el @ 89909:68c22ea6027c
Sync to HEAD
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Fri, 16 Apr 2004 12:51:06 +0000 |
parents | 375f2633d815 |
children | 4da4a09e8b1b |
comparison
equal
deleted
inserted
replaced
89908:ee1402f7b568 | 89909:68c22ea6027c |
---|---|
1 ;;; complete.el --- partial completion mechanism plus other goodies | 1 ;;; complete.el --- partial completion mechanism plus other goodies |
2 | 2 |
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 1999, 2000 | 3 ;; Copyright (C) 1990, 1991, 1992, 1993, 1999, 2000, 2003 |
4 ;; Free Software Foundation, Inc. | 4 ;; Free Software Foundation, Inc. |
5 | 5 |
6 ;; Author: Dave Gillespie <daveg@synaptics.com> | 6 ;; Author: Dave Gillespie <daveg@synaptics.com> |
7 ;; Keywords: abbrev convenience | 7 ;; Keywords: abbrev convenience |
8 ;; Special thanks to Hallvard Furuseth for his many ideas and contributions. | 8 ;; Special thanks to Hallvard Furuseth for his many ideas and contributions. |
366 helpposs | 366 helpposs |
367 (case-fold-search completion-ignore-case)) | 367 (case-fold-search completion-ignore-case)) |
368 | 368 |
369 ;; Check if buffer contents can already be considered complete | 369 ;; Check if buffer contents can already be considered complete |
370 (if (and (eq mode 'exit) | 370 (if (and (eq mode 'exit) |
371 (PC-is-complete-p str table pred)) | 371 (test-completion str table pred)) |
372 'complete | 372 'complete |
373 | 373 |
374 ;; Do substitutions in directory names | 374 ;; Do substitutions in directory names |
375 (and filename | 375 (and filename |
376 (setq basestr (or (file-name-directory str) "")) | 376 (setq basestr (or (file-name-directory str) "")) |
392 PC-delims-list (append PC-delims nil))) | 392 PC-delims-list (append PC-delims nil))) |
393 | 393 |
394 ;; Add wildcards if necessary | 394 ;; Add wildcards if necessary |
395 (and filename | 395 (and filename |
396 (let ((dir (file-name-directory str)) | 396 (let ((dir (file-name-directory str)) |
397 (file (file-name-nondirectory str))) | 397 (file (file-name-nondirectory str)) |
398 ;; The base dir for file-completion is passed in `predicate'. | |
399 (default-directory (expand-file-name pred))) | |
398 (while (and (stringp dir) (not (file-directory-p dir))) | 400 (while (and (stringp dir) (not (file-directory-p dir))) |
399 (setq dir (directory-file-name dir)) | 401 (setq dir (directory-file-name dir)) |
400 (setq file (concat (replace-regexp-in-string | 402 (setq file (concat (replace-regexp-in-string |
401 PC-delim-regex "*\\&" | 403 PC-delim-regex "*\\&" |
402 (file-name-nondirectory dir)) | 404 (file-name-nondirectory dir)) |
406 | 408 |
407 ;; Look for wildcard expansions in directory name | 409 ;; Look for wildcard expansions in directory name |
408 (and filename | 410 (and filename |
409 (string-match "\\*.*/" str) | 411 (string-match "\\*.*/" str) |
410 (let ((pat str) | 412 (let ((pat str) |
413 ;; The base dir for file-completion is passed in `predicate'. | |
414 (default-directory (expand-file-name pred)) | |
411 files) | 415 files) |
412 (setq p (1+ (string-match "/[^/]*\\'" pat))) | 416 (setq p (1+ (string-match "/[^/]*\\'" pat))) |
413 (while (setq p (string-match PC-delim-regex pat p)) | 417 (while (setq p (string-match PC-delim-regex pat p)) |
414 (setq pat (concat (substring pat 0 p) | 418 (setq pat (concat (substring pat 0 p) |
415 "*" | 419 "*" |
635 (not PC-word-failed-flag)) | 639 (not PC-word-failed-flag)) |
636 | 640 |
637 (if improved | 641 (if improved |
638 | 642 |
639 ;; We changed it... would it be complete without the space? | 643 ;; We changed it... would it be complete without the space? |
640 (if (PC-is-complete-p (buffer-substring 1 (1- end)) | 644 (if (test-completion (buffer-substring 1 (1- end)) |
641 table pred) | 645 table pred) |
642 (delete-region (1- end) end))) | 646 (delete-region (1- end) end))) |
643 | 647 |
644 (if improved | 648 (if improved |
645 | 649 |
646 ;; We changed it... enough to be complete? | 650 ;; We changed it... enough to be complete? |
647 (and (eq mode 'exit) | 651 (and (eq mode 'exit) |
648 (PC-is-complete-p (field-string) table pred)) | 652 (test-completion (field-string) table pred)) |
649 | 653 |
650 ;; If totally ambiguous, display a list of completions | 654 ;; If totally ambiguous, display a list of completions |
651 (if (or (eq completion-auto-help t) | 655 (if (or (eq completion-auto-help t) |
652 (and completion-auto-help | 656 (and completion-auto-help |
653 (eq last-command this-command)) | 657 (eq last-command this-command)) |
673 (insert (format "%s" | 677 (insert (format "%s" |
674 (if filename | 678 (if filename |
675 (substitute-in-file-name (concat dirname (car poss))) | 679 (substitute-in-file-name (concat dirname (car poss))) |
676 (car poss))))) | 680 (car poss))))) |
677 t))))) | 681 t))))) |
678 | |
679 | |
680 (defun PC-is-complete-p (str table pred) | |
681 (let ((res (if (listp table) | |
682 (assoc str table) | |
683 (if (vectorp table) | |
684 (or (equal str "nil") ; heh, heh, heh | |
685 (intern-soft str table)) | |
686 (funcall table str pred 'lambda))))) | |
687 (and res | |
688 (or (not pred) | |
689 (and (not (listp table)) (not (vectorp table))) | |
690 (funcall pred res)) | |
691 res))) | |
692 | 682 |
693 (defun PC-chop-word (new old) | 683 (defun PC-chop-word (new old) |
694 (let ((i -1) | 684 (let ((i -1) |
695 (j -1)) | 685 (j -1)) |
696 (while (and (setq i (string-match PC-delim-regex old (1+ i))) | 686 (while (and (setq i (string-match PC-delim-regex old (1+ i))) |
952 (funcall PC-old-read-file-name-internal string dir action))) | 942 (funcall PC-old-read-file-name-internal string dir action))) |
953 | 943 |
954 | 944 |
955 (provide 'complete) | 945 (provide 'complete) |
956 | 946 |
947 ;;; arch-tag: fc7e2768-ff44-4e22-b579-4d825b968458 | |
957 ;;; complete.el ends here | 948 ;;; complete.el ends here |