Mercurial > emacs
comparison lisp/complete.el @ 82302:c0e2cbf10e3a
(PC-lisp-complete-symbol): Complete symbol around point.
(PC-do-completion): Add "acronym completion" for symbols and
filenames, so e.g. "mvbl" expands to "make-variable-buffer-local".
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 07 Aug 2007 03:02:04 +0000 |
parents | b98604865ea0 |
children | f839eef40802 424b655804ca |
comparison
equal
deleted
inserted
replaced
82301:d01b1c1a072f | 82302:c0e2cbf10e3a |
---|---|
448 (ambig nil) | 448 (ambig nil) |
449 basestr origstr | 449 basestr origstr |
450 env-on | 450 env-on |
451 regex | 451 regex |
452 p offset | 452 p offset |
453 abbreviated | |
453 (poss nil) | 454 (poss nil) |
454 helpposs | 455 helpposs |
455 (case-fold-search completion-ignore-case)) | 456 (case-fold-search completion-ignore-case)) |
456 | 457 |
457 ;; Check if buffer contents can already be considered complete | 458 ;; Check if buffer contents can already be considered complete |
584 (setq env-on t | 585 (setq env-on t |
585 table PC-env-vars-alist | 586 table PC-env-vars-alist |
586 pred nil)) | 587 pred nil)) |
587 | 588 |
588 ;; Find an initial list of possible completions | 589 ;; Find an initial list of possible completions |
589 (if (not (setq p (string-match (concat PC-delim-regex | 590 (unless (setq p (string-match (concat PC-delim-regex |
590 (if filename "\\|\\*" "")) | 591 (if filename "\\|\\*" "")) |
591 str | 592 str |
592 (+ (length dirname) offset)))) | 593 (+ (length dirname) offset))) |
593 | 594 |
594 ;; Minibuffer contains no hyphens -- simple case! | 595 ;; Minibuffer contains no hyphens -- simple case! |
595 (setq poss (all-completions (if env-on | 596 (setq poss (all-completions (if env-on basestr str) |
596 basestr str) | |
597 table | 597 table |
598 pred)) | 598 pred)) |
599 | 599 (unless poss |
600 ;; Try completion as an abbreviation, e.g. "mvb" -> | |
601 ;; "m-v-b" -> "multiple-value-bind" | |
602 (setq origstr str | |
603 abbreviated t) | |
604 (if filename | |
605 (cond | |
606 ;; "alpha" or "/alpha" -> expand whole path. | |
607 ((string-match "^/?\\([A-Za-z0-9]+\\)$" str) | |
608 (setq | |
609 basestr "" | |
610 p nil | |
611 poss (PC-expand-many-files | |
612 (concat "/" | |
613 (mapconcat #'list (match-string 1 str) "*/") | |
614 "*")) | |
615 beg (1- beg))) | |
616 ;; Alphanumeric trailer -> expand trailing file | |
617 ((string-match "^\\(.+/\\)\\([A-Za-z0-9]+\\)$" str) | |
618 (setq regex (concat "\\`" | |
619 (mapconcat #'list | |
620 (match-string 2 str) | |
621 "[A-Za-z0-9]*[^A-Za-z0-9]")) | |
622 p (1+ (length (match-string 1 str)))))) | |
623 (setq regex (concat "\\`" (mapconcat #'list str "[^-]*-")) | |
624 p 1)))) | |
625 (when p | |
600 ;; Use all-completions to do an initial cull. This is a big win, | 626 ;; Use all-completions to do an initial cull. This is a big win, |
601 ;; since all-completions is written in C! | 627 ;; since all-completions is written in C! |
602 (let ((compl (all-completions (if env-on | 628 (let ((compl (all-completions (if env-on |
603 (file-name-nondirectory (substring str 0 p)) | 629 (file-name-nondirectory (substring str 0 p)) |
604 (substring str 0 p)) | 630 (substring str 0 p)) |
605 table | 631 table |
606 pred))) | 632 pred))) |
607 (setq p compl) | 633 (setq p compl) |
634 (when (and compl abbreviated) | |
635 (if filename | |
636 (progn | |
637 (setq p nil) | |
638 (dolist (x compl) | |
639 (when (string-match regex x) | |
640 (push x p))) | |
641 (setq basestr (try-completion "" p))) | |
642 (setq basestr (mapconcat 'list str "-")) | |
643 (delete-region beg end) | |
644 (setq end (+ beg (length basestr))) | |
645 (insert basestr)))) | |
608 (while p | 646 (while p |
609 (and (string-match regex (car p)) | 647 (and (string-match regex (car p)) |
610 (progn | 648 (progn |
611 (set-text-properties 0 (length (car p)) '() (car p)) | 649 (set-text-properties 0 (length (car p)) '() (car p)) |
612 (setq poss (cons (car p) poss)))) | 650 (setq poss (cons (car p) poss)))) |
613 (setq p (cdr p))))) | 651 (setq p (cdr p)))) |
614 | 652 |
615 ;; If table had duplicates, they can be here. | 653 ;; If table had duplicates, they can be here. |
616 (delete-dups poss) | 654 (delete-dups poss) |
617 | 655 |
618 ;; Handle completion-ignored-extensions | 656 ;; Handle completion-ignored-extensions |
642 | 680 |
643 ;; If there are "good" names, use them | 681 ;; If there are "good" names, use them |
644 (and p (setq poss p)))) | 682 (and p (setq poss p)))) |
645 | 683 |
646 ;; Now we have a list of possible completions | 684 ;; Now we have a list of possible completions |
685 | |
647 (cond | 686 (cond |
648 | 687 |
649 ;; No valid completions found | 688 ;; No valid completions found |
650 ((null poss) | 689 ((null poss) |
651 (if (and (eq mode 'word) | 690 (if (and (eq mode 'word) |
652 (not PC-word-failed-flag)) | 691 (not PC-word-failed-flag)) |
653 (let ((PC-word-failed-flag t)) | 692 (let ((PC-word-failed-flag t)) |
654 (delete-backward-char 1) | 693 (delete-backward-char 1) |
655 (PC-do-completion 'word)) | 694 (PC-do-completion 'word)) |
695 (when abbreviated | |
696 (delete-region beg end) | |
697 (insert origstr)) | |
656 (beep) | 698 (beep) |
657 (PC-temp-minibuffer-message (if ambig | 699 (PC-temp-minibuffer-message (if ambig |
658 " [Ambiguous dir name]" | 700 " [Ambiguous dir name]" |
659 (if (eq mode 'help) | 701 (if (eq mode 'help) |
660 " [No completions]" | 702 " [No completions]" |
787 ;; Note that choose-completion-string-functions | 829 ;; Note that choose-completion-string-functions |
788 ;; plays around with point. | 830 ;; plays around with point. |
789 (setq completion-base-size (if dirname | 831 (setq completion-base-size (if dirname |
790 dirlength | 832 dirlength |
791 (- beg prompt-end)))))) | 833 (- beg prompt-end)))))) |
792 (PC-temp-minibuffer-message " [Next char not unique]")) | 834 (PC-temp-minibuffer-message " [Next char not unique]")))))) |
793 nil))))) | 835 ;; Expansion of filenames is not reversible, so just keep |
836 ;; the prefix. | |
837 (when (and abbreviated filename) | |
838 (delete-region (point) end)) | |
839 nil) | |
794 | 840 |
795 ;; Only one possible completion | 841 ;; Only one possible completion |
796 (t | 842 (t |
797 (if (and (equal basestr (car poss)) | 843 (if (and (equal basestr (car poss)) |
798 (not (and env-on filename))) | 844 (not (and env-on filename)) |
845 (not abbreviated)) | |
799 (if (null mode) | 846 (if (null mode) |
800 (PC-temp-minibuffer-message " [Sole completion]")) | 847 (PC-temp-minibuffer-message " [Sole completion]")) |
801 (delete-region beg end) | 848 (delete-region beg end) |
802 (insert (format "%s" | 849 (insert (format "%s" |
803 (if filename | 850 (if filename |
851 If the symbol starts just after an open-parenthesis, | 898 If the symbol starts just after an open-parenthesis, |
852 only symbols with function definitions are considered. | 899 only symbols with function definitions are considered. |
853 Otherwise, all symbols with function definitions, values | 900 Otherwise, all symbols with function definitions, values |
854 or properties are considered." | 901 or properties are considered." |
855 (interactive) | 902 (interactive) |
856 (let* ((end (point)) | 903 (let* ((end |
857 ;; To complete the word under point, rather than just the portion | 904 (save-excursion |
858 ;; before point, use this: | 905 (with-syntax-table lisp-mode-syntax-table |
859 ;;; (save-excursion | 906 (skip-syntax-forward "_w") |
860 ;;; (with-syntax-table lisp-mode-syntax-table | 907 (point)))) |
861 ;;; (forward-sexp 1) | |
862 ;;; (point)))) | |
863 (beg (save-excursion | 908 (beg (save-excursion |
864 (with-syntax-table lisp-mode-syntax-table | 909 (with-syntax-table lisp-mode-syntax-table |
865 (backward-sexp 1) | 910 (backward-sexp 1) |
866 (while (= (char-syntax (following-char)) ?\') | 911 (while (= (char-syntax (following-char)) ?\') |
867 (forward-char 1)) | 912 (forward-char 1)) |