diff options
| author | Richard M. Stallman | 2007-08-07 03:02:04 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2007-08-07 03:02:04 +0000 |
| commit | 03ed845e65b9c563d7215befd6d8073ba3abe617 (patch) | |
| tree | 1566e704b43862ceac257130a988f3119a72ae25 | |
| parent | edc779d4cf70d08ed2257c993d7d267f6111375e (diff) | |
| download | emacs-03ed845e65b9c563d7215befd6d8073ba3abe617.tar.gz emacs-03ed845e65b9c563d7215befd6d8073ba3abe617.zip | |
(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".
| -rw-r--r-- | lisp/complete.el | 77 |
1 files changed, 61 insertions, 16 deletions
diff --git a/lisp/complete.el b/lisp/complete.el index 9be68d833e5..75774b65db0 100644 --- a/lisp/complete.el +++ b/lisp/complete.el | |||
| @@ -450,6 +450,7 @@ GOTO-END is non-nil, however, it instead replaces up to END." | |||
| 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)) |
| @@ -586,17 +587,42 @@ GOTO-END is non-nil, however, it instead replaces up to END." | |||
| 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 |
| @@ -605,12 +631,24 @@ GOTO-END is non-nil, however, it instead replaces up to END." | |||
| 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) |
| @@ -644,6 +682,7 @@ GOTO-END is non-nil, however, it instead replaces up to END." | |||
| 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 |
| @@ -653,6 +692,9 @@ GOTO-END is non-nil, however, it instead replaces up to END." | |||
| 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]" |
| @@ -789,13 +831,18 @@ GOTO-END is non-nil, however, it instead replaces up to END." | |||
| 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) |
| @@ -853,13 +900,11 @@ 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) |