diff options
| author | Stefan Monnier | 2011-05-23 23:45:50 -0300 |
|---|---|---|
| committer | Stefan Monnier | 2011-05-23 23:45:50 -0300 |
| commit | a2a25d24350857dda87e28d6b2695cccc41bb32e (patch) | |
| tree | 59bf876837e64b92932a52bf8ea8c526de285eb1 | |
| parent | 2df215b52612a739eedcc024e47b6a9fa720dfda (diff) | |
| download | emacs-a2a25d24350857dda87e28d6b2695cccc41bb32e.tar.gz emacs-a2a25d24350857dda87e28d6b2695cccc41bb32e.zip | |
Add an :exit-function for completion-at-point.
* lisp/minibuffer.el (completion--done): New fun.
(completion--do-completion): Use it. New arg `expect-exact'.
(minibuffer-complete, minibuffer-complete-word): Don't output message,
since completion--do-completion does it for us now.
(minibuffer-force-complete): Use completion--done and
completion--replace. Handle sole-completion case with more care.
(minibuffer-complete-and-exit): Use new `expect-exact' arg.
(completion-extra-properties): New var.
(completion-annotate-function): Make obsolete.
(minibuffer-completion-help): Adjust accordingly.
Use completion-list-insert-choice-function.
(completion-at-point, completion-help-at-point):
Bind completion-extra-properties.
(completion-pcm-word-delimiters): Add | (for uniquify, for example).
* lisp/simple.el (completion-list-insert-choice-function): New var.
(completion-setup-function): Preserve it.
(choose-completion): Pay attention to it, shuffle the code a bit.
(choose-completion-string): New arg `insert-function'.
* lisp/textmodes/bibtex.el: Convert to lexical binding.
(bibtex-mode-map): Use completion-at-point.
(bibtex-mode): Use define-derived-mode&completion-at-point-functions.
(bibtex-completion-at-point-function): New fun, from bibtex-complete.
(bibtex-complete): Define as obsolete alias.
(bibtex-complete-internal): Remove.
(bibtex-format-entry): Remove unused sub-group in regexp.
* lisp/shell.el (shell--command-completion-data)
(shell-environment-variable-completion):
* lisp/pcomplete.el (pcomplete-completions-at-point):
* lisp/comint.el (comint--complete-file-name-data): Use :exit-function
instead of completion-table-with-terminator so it also works for
choose-completion.
| -rw-r--r-- | etc/NEWS | 29 | ||||
| -rw-r--r-- | lisp/ChangeLog | 37 | ||||
| -rw-r--r-- | lisp/comint.el | 27 | ||||
| -rw-r--r-- | lisp/minibuffer.el | 257 | ||||
| -rw-r--r-- | lisp/pcomplete.el | 20 | ||||
| -rw-r--r-- | lisp/shell.el | 38 | ||||
| -rw-r--r-- | lisp/simple.el | 106 | ||||
| -rw-r--r-- | lisp/textmodes/bibtex.el | 165 |
8 files changed, 399 insertions, 280 deletions
| @@ -68,9 +68,6 @@ and also when HOME is set to C:\ by default. | |||
| 68 | 68 | ||
| 69 | * Changes in Emacs 24.1 | 69 | * Changes in Emacs 24.1 |
| 70 | 70 | ||
| 71 | ** Completion in a non-minibuffer now tries to detect the end of completion | ||
| 72 | and pops down the *Completions* buffer accordingly. | ||
| 73 | |||
| 74 | ** emacsclient changes | 71 | ** emacsclient changes |
| 75 | 72 | ||
| 76 | *** New emacsclient argument --parent-id ID can be used to open a | 73 | *** New emacsclient argument --parent-id ID can be used to open a |
| @@ -83,9 +80,18 @@ client frame in parent X window ID, via XEmbed. This works like the | |||
| 83 | *** If emacsclient shuts down as a result of Emacs signalling an | 80 | *** If emacsclient shuts down as a result of Emacs signalling an |
| 84 | error, its exit status is 1. | 81 | error, its exit status is 1. |
| 85 | 82 | ||
| 86 | ** Completion can cycle, depending on completion-cycle-threshold. | 83 | ** Completion |
| 84 | *** Many packages have been changed to use completion-at-point rather than | ||
| 85 | their own completion code. | ||
| 86 | |||
| 87 | *** Completion in a non-minibuffer now tries to detect the end of completion | ||
| 88 | and pops down the *Completions* buffer accordingly. | ||
| 89 | |||
| 90 | *** Completion can cycle, depending on completion-cycle-threshold. | ||
| 87 | 91 | ||
| 88 | ** `completing-read' can be customized using the new variable | 92 | *** New completion style `substring'. |
| 93 | |||
| 94 | *** `completing-read' can be customized using the new variable | ||
| 89 | `completing-read-function'. | 95 | `completing-read-function'. |
| 90 | 96 | ||
| 91 | ** auto-mode-case-fold is now enabled by default. | 97 | ** auto-mode-case-fold is now enabled by default. |
| @@ -833,6 +839,17 @@ sc.el, x-menu.el, rnews.el, rnewspost.el | |||
| 833 | 839 | ||
| 834 | * Lisp changes in Emacs 24.1 | 840 | * Lisp changes in Emacs 24.1 |
| 835 | 841 | ||
| 842 | ** Completion | ||
| 843 | *** New variable completion-extra-properties used to specify extra properties | ||
| 844 | of the current completion: | ||
| 845 | - :annotate-function, same as the old completion-annotate-function. | ||
| 846 | - :exit-function, function to call after completion took place. | ||
| 847 | |||
| 848 | *** Functions on completion-at-point-functions can return any of the properties | ||
| 849 | valid for completion-extra-properties. | ||
| 850 | |||
| 851 | *** completion-annotate-function is obsolete. | ||
| 852 | |||
| 836 | ** `glyphless-char-display' can now distinguish between graphical and | 853 | ** `glyphless-char-display' can now distinguish between graphical and |
| 837 | text terminal display, via a char-table entry that is a cons cell. | 854 | text terminal display, via a char-table entry that is a cons cell. |
| 838 | 855 | ||
| @@ -909,8 +926,6 @@ argument is supplied (see Trash changes, above). | |||
| 909 | 926 | ||
| 910 | ** buffer-substring-filters is obsoleted by filter-buffer-substring-functions. | 927 | ** buffer-substring-filters is obsoleted by filter-buffer-substring-functions. |
| 911 | 928 | ||
| 912 | ** New completion style `substring'. | ||
| 913 | |||
| 914 | ** `facemenu-read-color' is now an alias for `read-color'. | 929 | ** `facemenu-read-color' is now an alias for `read-color'. |
| 915 | The command `read-color' now requires a match for a color name or RGB | 930 | The command `read-color' now requires a match for a color name or RGB |
| 916 | triplet, instead of signalling an error if the user provides a invalid | 931 | triplet, instead of signalling an error if the user provides a invalid |
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index cb00357c23e..ce0f3e8733b 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,40 @@ | |||
| 1 | 2011-05-24 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | Add an :exit-function for completion-at-point. | ||
| 4 | |||
| 5 | * minibuffer.el (completion--done): New fun. | ||
| 6 | (completion--do-completion): Use it. New arg `expect-exact'. | ||
| 7 | (minibuffer-complete, minibuffer-complete-word): Don't output message, | ||
| 8 | since completion--do-completion does it for us now. | ||
| 9 | (minibuffer-force-complete): Use completion--done and | ||
| 10 | completion--replace. Handle sole-completion case with more care. | ||
| 11 | (minibuffer-complete-and-exit): Use new `expect-exact' arg. | ||
| 12 | (completion-extra-properties): New var. | ||
| 13 | (completion-annotate-function): Make obsolete. | ||
| 14 | (minibuffer-completion-help): Adjust accordingly. | ||
| 15 | Use completion-list-insert-choice-function. | ||
| 16 | (completion-at-point, completion-help-at-point): | ||
| 17 | Bind completion-extra-properties. | ||
| 18 | (completion-pcm-word-delimiters): Add | (for uniquify, for example). | ||
| 19 | * simple.el (completion-list-insert-choice-function): New var. | ||
| 20 | (completion-setup-function): Preserve it. | ||
| 21 | (choose-completion): Pay attention to it, shuffle the code a bit. | ||
| 22 | (choose-completion-string): New arg `insert-function'. | ||
| 23 | |||
| 24 | * textmodes/bibtex.el: Convert to lexical binding. | ||
| 25 | (bibtex-mode-map): Use completion-at-point. | ||
| 26 | (bibtex-mode): Use define-derived-mode&completion-at-point-functions. | ||
| 27 | (bibtex-completion-at-point-function): New fun, from bibtex-complete. | ||
| 28 | (bibtex-complete): Define as obsolete alias. | ||
| 29 | (bibtex-complete-internal): Remove. | ||
| 30 | (bibtex-format-entry): Remove unused sub-group in regexp. | ||
| 31 | * shell.el (shell--command-completion-data) | ||
| 32 | (shell-environment-variable-completion): | ||
| 33 | * pcomplete.el (pcomplete-completions-at-point): | ||
| 34 | * comint.el (comint--complete-file-name-data): Use :exit-function | ||
| 35 | instead of completion-table-with-terminator so it also works for | ||
| 36 | choose-completion. | ||
| 37 | |||
| 1 | 2011-05-23 Stefan Monnier <monnier@iro.umontreal.ca> | 38 | 2011-05-23 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 39 | ||
| 3 | * <lots-of-files>.el: Don't quote lambda expressions with `quote'. | 40 | * <lots-of-files>.el: Don't quote lambda expressions with `quote'. |
diff --git a/lisp/comint.el b/lisp/comint.el index 8608c0d31e9..e4bc530f361 100644 --- a/lisp/comint.el +++ b/lisp/comint.el | |||
| @@ -3134,19 +3134,20 @@ in the same way as TABLE completes strings of the form (concat S2 S)." | |||
| 3134 | #'comint--table-subvert | 3134 | #'comint--table-subvert |
| 3135 | #'completion-file-name-table | 3135 | #'completion-file-name-table |
| 3136 | (cdr prefixes) (car prefixes))))) | 3136 | (cdr prefixes) (car prefixes))))) |
| 3137 | (list | 3137 | (nconc |
| 3138 | filename-beg filename-end | 3138 | (list |
| 3139 | (lambda (string pred action) | 3139 | filename-beg filename-end |
| 3140 | (let ((completion-ignore-case read-file-name-completion-ignore-case) | 3140 | (lambda (string pred action) |
| 3141 | (completion-ignored-extensions comint-completion-fignore)) | 3141 | (let ((completion-ignore-case read-file-name-completion-ignore-case) |
| 3142 | (if (zerop (length filesuffix)) | 3142 | (completion-ignored-extensions comint-completion-fignore)) |
| 3143 | (complete-with-action action table string pred) | 3143 | (complete-with-action action table string pred)))) |
| 3144 | ;; Add a space at the end of completion. Use a terminator-regexp | 3144 | (unless (zerop (length filesuffix)) |
| 3145 | ;; that never matches since the terminator cannot appear | 3145 | (list :exit-function |
| 3146 | ;; within the completion field anyway. | 3146 | (lambda (_s finished) |
| 3147 | (completion-table-with-terminator | 3147 | (when (memq finished '(sole finished)) |
| 3148 | (cons filesuffix "\\`a\\`") | 3148 | (if (looking-at (regexp-quote filesuffix)) |
| 3149 | table string pred action))))))) | 3149 | (goto-char (match-end 0)) |
| 3150 | (insert filesuffix))))))))) | ||
| 3150 | 3151 | ||
| 3151 | (defun comint-dynamic-complete-as-filename () | 3152 | (defun comint-dynamic-complete-as-filename () |
| 3152 | "Dynamically complete at point as a filename. | 3153 | "Dynamically complete at point as a filename. |
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 41399f3f141..f3d92b18722 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el | |||
| @@ -58,12 +58,9 @@ | |||
| 58 | 58 | ||
| 59 | ;;; Todo: | 59 | ;;; Todo: |
| 60 | 60 | ||
| 61 | ;; - for M-x, cycle-sort commands that have no key binding first. | ||
| 61 | ;; - Make things like icomplete-mode or lightning-completion work with | 62 | ;; - Make things like icomplete-mode or lightning-completion work with |
| 62 | ;; completion-in-region-mode. | 63 | ;; completion-in-region-mode. |
| 63 | ;; - completion-insert-complete-hook (called after inserting a complete | ||
| 64 | ;; completion), typically used for "complete-abbrev" where it would expand | ||
| 65 | ;; the abbrev. Tho we'd probably want to provide it from the | ||
| 66 | ;; completion-table. | ||
| 67 | ;; - extend `boundaries' to provide various other meta-data about the | 64 | ;; - extend `boundaries' to provide various other meta-data about the |
| 68 | ;; output of `all-completions': | 65 | ;; output of `all-completions': |
| 69 | ;; - preferred sorting order when displayed in *Completions*. | 66 | ;; - preferred sorting order when displayed in *Completions*. |
| @@ -74,10 +71,6 @@ | |||
| 74 | ;; - indicate how to turn all-completion's output into | 71 | ;; - indicate how to turn all-completion's output into |
| 75 | ;; try-completion's output: e.g. completion-ignored-extensions. | 72 | ;; try-completion's output: e.g. completion-ignored-extensions. |
| 76 | ;; maybe that could be merged with the "quote" operation above. | 73 | ;; maybe that could be merged with the "quote" operation above. |
| 77 | ;; - completion hook to run when the completion is | ||
| 78 | ;; selected/inserted (maybe this should be provided some other | ||
| 79 | ;; way, e.g. as text-property, so `try-completion can also return it?) | ||
| 80 | ;; both for when it's inserted via TAB or via choose-completion. | ||
| 81 | ;; - indicate that `all-completions' doesn't do prefix-completion | 74 | ;; - indicate that `all-completions' doesn't do prefix-completion |
| 82 | ;; but just returns some list that relates in some other way to | 75 | ;; but just returns some list that relates in some other way to |
| 83 | ;; the provided string (as is the case in filecache.el), in which | 76 | ;; the provided string (as is the case in filecache.el), in which |
| @@ -87,18 +80,6 @@ | |||
| 87 | ;; \n into something else, add special boundaries between | 80 | ;; \n into something else, add special boundaries between |
| 88 | ;; completions). E.g. when completing from the kill-ring. | 81 | ;; completions). E.g. when completing from the kill-ring. |
| 89 | 82 | ||
| 90 | ;; - make partial-completion-mode obsolete: | ||
| 91 | ;; - (?) <foo.h> style completion for file names. | ||
| 92 | ;; This can't be done identically just by tweaking completion, | ||
| 93 | ;; because partial-completion-mode's behavior is to expand <string.h> | ||
| 94 | ;; to /usr/include/string.h only when exiting the minibuffer, at which | ||
| 95 | ;; point the completion code is actually not involved normally. | ||
| 96 | ;; Partial-completion-mode does it via a find-file-not-found-function. | ||
| 97 | ;; - special code for C-x C-f <> to visit the file ref'd at point | ||
| 98 | ;; via (require 'foo) or #include "foo". ffap seems like a better | ||
| 99 | ;; place for this feature (supplemented with major-mode-provided | ||
| 100 | ;; functions to find the file ref'd at point). | ||
| 101 | |||
| 102 | ;; - case-sensitivity currently confuses two issues: | 83 | ;; - case-sensitivity currently confuses two issues: |
| 103 | ;; - whether or not a particular completion table should be case-sensitive | 84 | ;; - whether or not a particular completion table should be case-sensitive |
| 104 | ;; (i.e. whether strings that differ only by case are semantically | 85 | ;; (i.e. whether strings that differ only by case are semantically |
| @@ -562,7 +543,8 @@ candidates than this number." | |||
| 562 | (if completion-show-inline-help | 543 | (if completion-show-inline-help |
| 563 | (minibuffer-message msg))) | 544 | (minibuffer-message msg))) |
| 564 | 545 | ||
| 565 | (defun completion--do-completion (&optional try-completion-function) | 546 | (defun completion--do-completion (&optional try-completion-function |
| 547 | expect-exact) | ||
| 566 | "Do the completion and return a summary of what happened. | 548 | "Do the completion and return a summary of what happened. |
| 567 | M = completion was performed, the text was Modified. | 549 | M = completion was performed, the text was Modified. |
| 568 | C = there were available Completions. | 550 | C = there were available Completions. |
| @@ -576,7 +558,11 @@ E = after completion we now have an Exact match. | |||
| 576 | 100 4 ??? impossible | 558 | 100 4 ??? impossible |
| 577 | 101 5 ??? impossible | 559 | 101 5 ??? impossible |
| 578 | 110 6 some completion happened | 560 | 110 6 some completion happened |
| 579 | 111 7 completed to an exact completion" | 561 | 111 7 completed to an exact completion |
| 562 | |||
| 563 | TRY-COMPLETION-FUNCTION is a function to use in place of `try-completion'. | ||
| 564 | EXPECT-EXACT, if non-nil, means that there is no need to tell the user | ||
| 565 | when the buffer's text is already an exact match." | ||
| 580 | (let* ((beg (field-beginning)) | 566 | (let* ((beg (field-beginning)) |
| 581 | (end (field-end)) | 567 | (end (field-end)) |
| 582 | (string (buffer-substring beg end)) | 568 | (string (buffer-substring beg end)) |
| @@ -595,7 +581,9 @@ E = after completion we now have an Exact match. | |||
| 595 | (minibuffer--bitset nil nil nil)) | 581 | (minibuffer--bitset nil nil nil)) |
| 596 | ((eq t comp) | 582 | ((eq t comp) |
| 597 | (minibuffer-hide-completions) | 583 | (minibuffer-hide-completions) |
| 598 | (goto-char (field-end)) | 584 | (goto-char end) |
| 585 | (completion--done string 'finished | ||
| 586 | (unless expect-exact "Sole completion")) | ||
| 599 | (minibuffer--bitset nil nil t)) ;Exact and unique match. | 587 | (minibuffer--bitset nil nil t)) ;Exact and unique match. |
| 600 | (t | 588 | (t |
| 601 | ;; `completed' should be t if some completion was done, which doesn't | 589 | ;; `completed' should be t if some completion was done, which doesn't |
| @@ -619,12 +607,12 @@ E = after completion we now have an Exact match. | |||
| 619 | ;; whether this is a unique completion or not, so try again using | 607 | ;; whether this is a unique completion or not, so try again using |
| 620 | ;; the real case (this shouldn't recurse again, because the next | 608 | ;; the real case (this shouldn't recurse again, because the next |
| 621 | ;; time try-completion will return either t or the exact string). | 609 | ;; time try-completion will return either t or the exact string). |
| 622 | (completion--do-completion try-completion-function) | 610 | (completion--do-completion try-completion-function expect-exact) |
| 623 | 611 | ||
| 624 | ;; It did find a match. Do we match some possibility exactly now? | 612 | ;; It did find a match. Do we match some possibility exactly now? |
| 625 | (let ((exact (test-completion completion | 613 | (let ((exact (test-completion completion |
| 626 | minibuffer-completion-table | 614 | minibuffer-completion-table |
| 627 | minibuffer-completion-predicate)) | 615 | minibuffer-completion-predicate)) |
| 628 | (comps | 616 | (comps |
| 629 | ;; Check to see if we want to do cycling. We do it | 617 | ;; Check to see if we want to do cycling. We do it |
| 630 | ;; here, after having performed the normal completion, | 618 | ;; here, after having performed the normal completion, |
| @@ -658,7 +646,13 @@ E = after completion we now have an Exact match. | |||
| 658 | ;; We could also decide to refresh the completions, | 646 | ;; We could also decide to refresh the completions, |
| 659 | ;; if they're displayed (and assuming there are | 647 | ;; if they're displayed (and assuming there are |
| 660 | ;; completions left). | 648 | ;; completions left). |
| 661 | (minibuffer-hide-completions)) | 649 | (minibuffer-hide-completions) |
| 650 | (if exact | ||
| 651 | ;; If completion did not put point at end of field, | ||
| 652 | ;; it's a sign that completion is not finished. | ||
| 653 | (completion--done completion | ||
| 654 | (if (< comp-pos (length completion)) | ||
| 655 | 'exact 'unknown)))) | ||
| 662 | ;; Show the completion table, if requested. | 656 | ;; Show the completion table, if requested. |
| 663 | ((not exact) | 657 | ((not exact) |
| 664 | (if (case completion-auto-help | 658 | (if (case completion-auto-help |
| @@ -669,8 +663,12 @@ E = after completion we now have an Exact match. | |||
| 669 | ;; If the last exact completion and this one were the same, it | 663 | ;; If the last exact completion and this one were the same, it |
| 670 | ;; means we've already given a "Complete, but not unique" message | 664 | ;; means we've already given a "Complete, but not unique" message |
| 671 | ;; and the user's hit TAB again, so now we give him help. | 665 | ;; and the user's hit TAB again, so now we give him help. |
| 672 | ((eq this-command last-command) | 666 | (t |
| 673 | (if completion-auto-help (minibuffer-completion-help)))) | 667 | (if (and (eq this-command last-command) completion-auto-help) |
| 668 | (minibuffer-completion-help)) | ||
| 669 | (completion--done completion 'exact | ||
| 670 | (unless expect-exact | ||
| 671 | "Complete, but not unique")))) | ||
| 674 | 672 | ||
| 675 | (minibuffer--bitset completed t exact)))))))) | 673 | (minibuffer--bitset completed t exact)))))))) |
| 676 | 674 | ||
| @@ -705,10 +703,6 @@ scroll the window of possible completions." | |||
| 705 | t) | 703 | t) |
| 706 | (t (case (completion--do-completion) | 704 | (t (case (completion--do-completion) |
| 707 | (#b000 nil) | 705 | (#b000 nil) |
| 708 | (#b001 (completion--message "Sole completion") | ||
| 709 | t) | ||
| 710 | (#b011 (completion--message "Complete, but not unique") | ||
| 711 | t) | ||
| 712 | (t t))))) | 706 | (t t))))) |
| 713 | 707 | ||
| 714 | (defun completion--flush-all-sorted-completions (&rest _ignore) | 708 | (defun completion--flush-all-sorted-completions (&rest _ignore) |
| @@ -742,10 +736,11 @@ scroll the window of possible completions." | |||
| 742 | ;; Prefer recently used completions. | 736 | ;; Prefer recently used completions. |
| 743 | ;; FIXME: Additional sorting ideas: | 737 | ;; FIXME: Additional sorting ideas: |
| 744 | ;; - for M-x, prefer commands that have no key binding. | 738 | ;; - for M-x, prefer commands that have no key binding. |
| 745 | (let ((hist (symbol-value minibuffer-history-variable))) | 739 | (when (minibufferp) |
| 746 | (setq all (sort all (lambda (c1 c2) | 740 | (let ((hist (symbol-value minibuffer-history-variable))) |
| 747 | (> (length (member c1 hist)) | 741 | (setq all (sort all (lambda (c1 c2) |
| 748 | (length (member c2 hist))))))) | 742 | (> (length (member c1 hist)) |
| 743 | (length (member c2 hist)))))))) | ||
| 749 | ;; Cache the result. This is not just for speed, but also so that | 744 | ;; Cache the result. This is not just for speed, but also so that |
| 750 | ;; repeated calls to minibuffer-force-complete can cycle through | 745 | ;; repeated calls to minibuffer-force-complete can cycle through |
| 751 | ;; all possibilities. | 746 | ;; all possibilities. |
| @@ -763,14 +758,21 @@ Repeated uses step through the possible completions." | |||
| 763 | ;; ~/src/emacs/trunk/ and throws away lisp/minibuffer.el. | 758 | ;; ~/src/emacs/trunk/ and throws away lisp/minibuffer.el. |
| 764 | (let* ((start (field-beginning)) | 759 | (let* ((start (field-beginning)) |
| 765 | (end (field-end)) | 760 | (end (field-end)) |
| 766 | (all (completion-all-sorted-completions))) | 761 | (all (completion-all-sorted-completions)) |
| 767 | (if (not (consp all)) | 762 | (base (+ start (or (cdr (last all)) 0)))) |
| 763 | (cond | ||
| 764 | ((not (consp all)) | ||
| 768 | (completion--message | 765 | (completion--message |
| 769 | (if all "No more completions" "No completions")) | 766 | (if all "No more completions" "No completions"))) |
| 767 | ((not (consp (cdr all))) | ||
| 768 | (let ((mod (equal (car all) (buffer-substring-no-properties base end)))) | ||
| 769 | (if mod (completion--replace base end (car all))) | ||
| 770 | (completion--done (buffer-substring-no-properties start (point)) | ||
| 771 | 'finished (unless mod "Sole completion")))) | ||
| 772 | (t | ||
| 770 | (setq completion-cycling t) | 773 | (setq completion-cycling t) |
| 771 | (goto-char end) | 774 | (completion--replace base end (car all)) |
| 772 | (insert (car all)) | 775 | (completion--done (buffer-substring-no-properties start (point)) 'sole) |
| 773 | (delete-region (+ start (cdr (last all))) end) | ||
| 774 | ;; If completing file names, (car all) may be a directory, so we'd now | 776 | ;; If completing file names, (car all) may be a directory, so we'd now |
| 775 | ;; have a new set of possible completions and might want to reset | 777 | ;; have a new set of possible completions and might want to reset |
| 776 | ;; completion-all-sorted-completions to nil, but we prefer not to, | 778 | ;; completion-all-sorted-completions to nil, but we prefer not to, |
| @@ -778,7 +780,7 @@ Repeated uses step through the possible completions." | |||
| 778 | ;; through the previous possible completions. | 780 | ;; through the previous possible completions. |
| 779 | (let ((last (last all))) | 781 | (let ((last (last all))) |
| 780 | (setcdr last (cons (car all) (cdr last))) | 782 | (setcdr last (cons (car all) (cdr last))) |
| 781 | (setq completion-all-sorted-completions (cdr all)))))) | 783 | (setq completion-all-sorted-completions (cdr all))))))) |
| 782 | 784 | ||
| 783 | (defvar minibuffer-confirm-exit-commands | 785 | (defvar minibuffer-confirm-exit-commands |
| 784 | '(minibuffer-complete minibuffer-complete-word PC-complete PC-complete-word) | 786 | '(minibuffer-complete minibuffer-complete-word PC-complete PC-complete-word) |
| @@ -850,7 +852,7 @@ If `minibuffer-completion-confirm' is `confirm-after-completion', | |||
| 850 | (t | 852 | (t |
| 851 | ;; Call do-completion, but ignore errors. | 853 | ;; Call do-completion, but ignore errors. |
| 852 | (case (condition-case nil | 854 | (case (condition-case nil |
| 853 | (completion--do-completion) | 855 | (completion--do-completion nil 'expect-exact) |
| 854 | (error 1)) | 856 | (error 1)) |
| 855 | ((#b001 #b011) (exit-minibuffer)) | 857 | ((#b001 #b011) (exit-minibuffer)) |
| 856 | (#b111 (if (not minibuffer-completion-confirm) | 858 | (#b111 (if (not minibuffer-completion-confirm) |
| @@ -954,10 +956,6 @@ Return nil if there is no valid completion, else t." | |||
| 954 | (interactive) | 956 | (interactive) |
| 955 | (case (completion--do-completion 'completion--try-word-completion) | 957 | (case (completion--do-completion 'completion--try-word-completion) |
| 956 | (#b000 nil) | 958 | (#b000 nil) |
| 957 | (#b001 (completion--message "Sole completion") | ||
| 958 | t) | ||
| 959 | (#b011 (completion--message "Complete, but not unique") | ||
| 960 | t) | ||
| 961 | (t t))) | 959 | (t t))) |
| 962 | 960 | ||
| 963 | (defface completions-annotations '((t :inherit italic)) | 961 | (defface completions-annotations '((t :inherit italic)) |
| @@ -1157,6 +1155,21 @@ the completions buffer." | |||
| 1157 | (run-hooks 'completion-setup-hook))) | 1155 | (run-hooks 'completion-setup-hook))) |
| 1158 | nil) | 1156 | nil) |
| 1159 | 1157 | ||
| 1158 | (defvar completion-extra-properties nil | ||
| 1159 | "Property list of extra properties of the current completion job. | ||
| 1160 | These include: | ||
| 1161 | `:annotation-function': Function to add annotations in the completions buffer. | ||
| 1162 | The function takes a completion and should either return nil, or a string | ||
| 1163 | that will be displayed next to the completion. The function can access the | ||
| 1164 | completion data via `minibuffer-completion-table' and related variables. | ||
| 1165 | `:exit-function': Function to run after completion is performed. | ||
| 1166 | The function takes at least 2 parameters (STRING and STATUS) where STRING | ||
| 1167 | is the text to which the field was completed and STATUS indicates what | ||
| 1168 | kind of operation happened: if text is now complete it's `finished', if text | ||
| 1169 | cannot be further completed but completion is not finished, it's `sole', if | ||
| 1170 | text is a valid completion but may be further completed, it's `exact', and | ||
| 1171 | other STATUSes may be added in the future.") | ||
| 1172 | |||
| 1160 | (defvar completion-annotate-function | 1173 | (defvar completion-annotate-function |
| 1161 | nil | 1174 | nil |
| 1162 | ;; Note: there's a lot of scope as for when to add annotations and | 1175 | ;; Note: there's a lot of scope as for when to add annotations and |
| @@ -1173,6 +1186,27 @@ The function takes a completion and should either return nil, or a string that | |||
| 1173 | will be displayed next to the completion. The function can access the | 1186 | will be displayed next to the completion. The function can access the |
| 1174 | completion table and predicates via `minibuffer-completion-table' and related | 1187 | completion table and predicates via `minibuffer-completion-table' and related |
| 1175 | variables.") | 1188 | variables.") |
| 1189 | (make-obsolete-variable 'completion-annotate-function | ||
| 1190 | 'completion-extra-properties "24.1") | ||
| 1191 | |||
| 1192 | (defun completion--done (string &optional finished message) | ||
| 1193 | (let* ((exit-fun (plist-get completion-extra-properties :exit-function)) | ||
| 1194 | (pre-msg (and exit-fun (current-message)))) | ||
| 1195 | (assert (memq finished '(exact sole finished unknown))) | ||
| 1196 | ;; FIXME: exit-fun should receive `finished' as a parameter. | ||
| 1197 | (when exit-fun | ||
| 1198 | (when (eq finished 'unknown) | ||
| 1199 | (setq finished | ||
| 1200 | (if (eq (try-completion string | ||
| 1201 | minibuffer-completion-table | ||
| 1202 | minibuffer-completion-predicate) | ||
| 1203 | t) | ||
| 1204 | 'finished 'exact))) | ||
| 1205 | (funcall exit-fun string finished)) | ||
| 1206 | (when (and message | ||
| 1207 | ;; Don't output any message if the exit-fun already did so. | ||
| 1208 | (equal pre-msg (and exit-fun (current-message)))) | ||
| 1209 | (completion--message message)))) | ||
| 1176 | 1210 | ||
| 1177 | (defun minibuffer-completion-help () | 1211 | (defun minibuffer-completion-help () |
| 1178 | "Display a list of possible completions of the current minibuffer contents." | 1212 | "Display a list of possible completions of the current minibuffer contents." |
| @@ -1187,44 +1221,77 @@ variables.") | |||
| 1187 | minibuffer-completion-predicate | 1221 | minibuffer-completion-predicate |
| 1188 | (- (point) (field-beginning))))) | 1222 | (- (point) (field-beginning))))) |
| 1189 | (message nil) | 1223 | (message nil) |
| 1190 | (if (and completions | 1224 | (if (or (null completions) |
| 1191 | (or (consp (cdr completions)) | 1225 | (and (not (consp (cdr completions))) |
| 1192 | (not (equal (car completions) string)))) | 1226 | (equal (car completions) string))) |
| 1193 | (let* ((last (last completions)) | 1227 | (progn |
| 1194 | (base-size (cdr last)) | 1228 | ;; If there are no completions, or if the current input is already |
| 1195 | ;; If the *Completions* buffer is shown in a new | 1229 | ;; the sole completion, then hide (previous&stale) completions. |
| 1196 | ;; window, mark it as softly-dedicated, so bury-buffer in | 1230 | (minibuffer-hide-completions) |
| 1197 | ;; minibuffer-hide-completions will know whether to | 1231 | (ding) |
| 1198 | ;; delete the window or not. | 1232 | (minibuffer-message |
| 1199 | (display-buffer-mark-dedicated 'soft)) | 1233 | (if completions "Sole completion" "No completions"))) |
| 1200 | (with-output-to-temp-buffer "*Completions*" | 1234 | |
| 1201 | ;; Remove the base-size tail because `sort' requires a properly | 1235 | (let* ((last (last completions)) |
| 1202 | ;; nil-terminated list. | 1236 | (base-size (cdr last)) |
| 1203 | (when last (setcdr last nil)) | 1237 | (prefix (unless (zerop base-size) (substring string 0 base-size))) |
| 1204 | (setq completions (sort completions 'string-lessp)) | 1238 | (global-af (or (plist-get completion-extra-properties |
| 1205 | (when completion-annotate-function | 1239 | :annotation-function) |
| 1206 | (setq completions | 1240 | completion-annotate-function)) |
| 1207 | (mapcar (lambda (s) | 1241 | ;; If the *Completions* buffer is shown in a new |
| 1208 | (let ((ann | 1242 | ;; window, mark it as softly-dedicated, so bury-buffer in |
| 1209 | (funcall completion-annotate-function s))) | 1243 | ;; minibuffer-hide-completions will know whether to |
| 1210 | (if ann (list s ann) s))) | 1244 | ;; delete the window or not. |
| 1211 | completions))) | 1245 | (display-buffer-mark-dedicated 'soft)) |
| 1212 | (with-current-buffer standard-output | 1246 | (with-output-to-temp-buffer "*Completions*" |
| 1213 | (set (make-local-variable 'completion-base-position) | 1247 | ;; Remove the base-size tail because `sort' requires a properly |
| 1214 | (list (+ start base-size) | 1248 | ;; nil-terminated list. |
| 1215 | ;; FIXME: We should pay attention to completion | 1249 | (when last (setcdr last nil)) |
| 1216 | ;; boundaries here, but currently | 1250 | (setq completions (sort completions 'string-lessp)) |
| 1217 | ;; completion-all-completions does not give us the | 1251 | (setq completions |
| 1218 | ;; necessary information. | 1252 | (cond |
| 1219 | end))) | 1253 | (global-af |
| 1220 | (display-completion-list completions))) | 1254 | (mapcar (lambda (s) |
| 1221 | 1255 | (let ((ann (funcall global-af s))) | |
| 1222 | ;; If there are no completions, or if the current input is already the | 1256 | (if ann (list s ann) s))) |
| 1223 | ;; only possible completion, then hide (previous&stale) completions. | 1257 | completions)) |
| 1224 | (minibuffer-hide-completions) | 1258 | (t completions))) |
| 1225 | (ding) | 1259 | |
| 1226 | (minibuffer-message | 1260 | (with-current-buffer standard-output |
| 1227 | (if completions "Sole completion" "No completions"))) | 1261 | (set (make-local-variable 'completion-base-position) |
| 1262 | (list (+ start base-size) | ||
| 1263 | ;; FIXME: We should pay attention to completion | ||
| 1264 | ;; boundaries here, but currently | ||
| 1265 | ;; completion-all-completions does not give us the | ||
| 1266 | ;; necessary information. | ||
| 1267 | end)) | ||
| 1268 | (set (make-local-variable 'completion-list-insert-choice-function) | ||
| 1269 | (let ((ctable minibuffer-completion-table) | ||
| 1270 | (cpred minibuffer-completion-predicate) | ||
| 1271 | (cprops completion-extra-properties)) | ||
| 1272 | (lambda (start end choice) | ||
| 1273 | (unless | ||
| 1274 | (or (zerop (length prefix)) | ||
| 1275 | (equal prefix | ||
| 1276 | (buffer-substring-no-properties | ||
| 1277 | (max (point-min) (- start (length prefix))) | ||
| 1278 | start))) | ||
| 1279 | (message "*Completions* out of date")) | ||
| 1280 | ;; FIXME: Use `md' to do quoting&terminator here. | ||
| 1281 | (completion--replace start end choice) | ||
| 1282 | (let* ((minibuffer-completion-table ctable) | ||
| 1283 | (minibuffer-completion-predicate cpred) | ||
| 1284 | (completion-extra-properties cprops) | ||
| 1285 | (result (concat prefix choice)) | ||
| 1286 | (bounds (completion-boundaries | ||
| 1287 | result ctable cpred ""))) | ||
| 1288 | ;; If the completion introduces a new field, then | ||
| 1289 | ;; completion is not finished. | ||
| 1290 | (completion--done result | ||
| 1291 | (if (eq (car bounds) (length result)) | ||
| 1292 | 'exact 'finished))))))) | ||
| 1293 | |||
| 1294 | (display-completion-list completions)))) | ||
| 1228 | nil)) | 1295 | nil)) |
| 1229 | 1296 | ||
| 1230 | (defun minibuffer-hide-completions () | 1297 | (defun minibuffer-hide-completions () |
| @@ -1364,9 +1431,9 @@ or a list of the form (START END COLLECTION &rest PROPS) where | |||
| 1364 | START and END delimit the entity to complete and should include point, | 1431 | START and END delimit the entity to complete and should include point, |
| 1365 | COLLECTION is the completion table to use to complete it, and | 1432 | COLLECTION is the completion table to use to complete it, and |
| 1366 | PROPS is a property list for additional information. | 1433 | PROPS is a property list for additional information. |
| 1367 | Currently supported properties are: | 1434 | Currently supported properties are all the properties that can appear in |
| 1368 | `:predicate' a predicate that completion candidates need to satisfy. | 1435 | `completion-extra-properties' plus: |
| 1369 | `:annotation-function' the value to use for `completion-annotate-function'.") | 1436 | `:predicate' a predicate that completion candidates need to satisfy.") |
| 1370 | 1437 | ||
| 1371 | (defvar completion--capf-misbehave-funs nil | 1438 | (defvar completion--capf-misbehave-funs nil |
| 1372 | "List of functions found on `completion-at-point-functions' that misbehave.") | 1439 | "List of functions found on `completion-at-point-functions' that misbehave.") |
| @@ -1403,9 +1470,7 @@ The completion method is determined by `completion-at-point-functions'." | |||
| 1403 | (pcase res | 1470 | (pcase res |
| 1404 | (`(,_ . ,(and (pred functionp) f)) (funcall f)) | 1471 | (`(,_ . ,(and (pred functionp) f)) (funcall f)) |
| 1405 | (`(,hookfun . (,start ,end ,collection . ,plist)) | 1472 | (`(,hookfun . (,start ,end ,collection . ,plist)) |
| 1406 | (let* ((completion-annotate-function | 1473 | (let* ((completion-extra-properties plist) |
| 1407 | (or (plist-get plist :annotation-function) | ||
| 1408 | completion-annotate-function)) | ||
| 1409 | (completion-in-region-mode-predicate | 1474 | (completion-in-region-mode-predicate |
| 1410 | (lambda () | 1475 | (lambda () |
| 1411 | ;; We're still in the same completion field. | 1476 | ;; We're still in the same completion field. |
| @@ -1428,9 +1493,7 @@ The completion method is determined by `completion-at-point-functions'." | |||
| 1428 | (`(,hookfun . (,start ,end ,collection . ,plist)) | 1493 | (`(,hookfun . (,start ,end ,collection . ,plist)) |
| 1429 | (let* ((minibuffer-completion-table collection) | 1494 | (let* ((minibuffer-completion-table collection) |
| 1430 | (minibuffer-completion-predicate (plist-get plist :predicate)) | 1495 | (minibuffer-completion-predicate (plist-get plist :predicate)) |
| 1431 | (completion-annotate-function | 1496 | (completion-extra-properties plist) |
| 1432 | (or (plist-get plist :annotation-function) | ||
| 1433 | completion-annotate-function)) | ||
| 1434 | (completion-in-region-mode-predicate | 1497 | (completion-in-region-mode-predicate |
| 1435 | (lambda () | 1498 | (lambda () |
| 1436 | ;; We're still in the same completion field. | 1499 | ;; We're still in the same completion field. |
| @@ -2029,7 +2092,7 @@ from lowercase to uppercase characters).") | |||
| 2029 | (defun completion-pcm--prepare-delim-re (delims) | 2092 | (defun completion-pcm--prepare-delim-re (delims) |
| 2030 | (setq completion-pcm--delim-wild-regex (concat "[" delims "*]"))) | 2093 | (setq completion-pcm--delim-wild-regex (concat "[" delims "*]"))) |
| 2031 | 2094 | ||
| 2032 | (defcustom completion-pcm-word-delimiters "-_./: " | 2095 | (defcustom completion-pcm-word-delimiters "-_./:| " |
| 2033 | "A string of characters treated as word delimiters for completion. | 2096 | "A string of characters treated as word delimiters for completion. |
| 2034 | Some arcane rules: | 2097 | Some arcane rules: |
| 2035 | If `]' is in this string, it must come first. | 2098 | If `]' is in this string, it must come first. |
diff --git a/lisp/pcomplete.el b/lisp/pcomplete.el index 2f5dcdfb5e8..932436df8c9 100644 --- a/lisp/pcomplete.el +++ b/lisp/pcomplete.el | |||
| @@ -527,19 +527,19 @@ Same as `pcomplete' but using the standard completion UI." | |||
| 527 | (funcall pcomplete-norm-func | 527 | (funcall pcomplete-norm-func |
| 528 | (directory-file-name f)) | 528 | (directory-file-name f)) |
| 529 | pcomplete-seen))))))) | 529 | pcomplete-seen))))))) |
| 530 | (unless (zerop (length pcomplete-termination-string)) | ||
| 531 | ;; Add a space at the end of completion. Use a terminator-regexp | ||
| 532 | ;; that never matches since the terminator cannot appear | ||
| 533 | ;; within the completion field anyway. | ||
| 534 | (setq table | ||
| 535 | (apply-partially #'completion-table-with-terminator | ||
| 536 | (cons pcomplete-termination-string | ||
| 537 | "\\`a\\`") | ||
| 538 | table))) | ||
| 539 | (when pcomplete-ignore-case | 530 | (when pcomplete-ignore-case |
| 540 | (setq table | 531 | (setq table |
| 541 | (apply-partially #'completion-table-case-fold table))) | 532 | (apply-partially #'completion-table-case-fold table))) |
| 542 | (list beg (point) table :predicate pred)))))) | 533 | (list beg (point) table |
| 534 | :predicate pred | ||
| 535 | :exit-function | ||
| 536 | (unless (zerop (length pcomplete-termination-string)) | ||
| 537 | (lambda (_s finished) | ||
| 538 | (when (memq finished '(sole finished)) | ||
| 539 | (if (looking-at | ||
| 540 | (regexp-quote pcomplete-termination-string)) | ||
| 541 | (goto-char (match-end 0)) | ||
| 542 | (insert pcomplete-termination-string))))))))))) | ||
| 543 | 543 | ||
| 544 | ;; I don't think such commands are usable before first setting up buffer-local | 544 | ;; I don't think such commands are usable before first setting up buffer-local |
| 545 | ;; variables to parse args, so there's no point autoloading it. | 545 | ;; variables to parse args, so there's no point autoloading it. |
diff --git a/lisp/shell.el b/lisp/shell.el index cba50038bc0..53455944ee6 100644 --- a/lisp/shell.el +++ b/lisp/shell.el | |||
| @@ -1074,12 +1074,15 @@ Returns t if successful." | |||
| 1074 | (list | 1074 | (list |
| 1075 | start end | 1075 | start end |
| 1076 | (lambda (string pred action) | 1076 | (lambda (string pred action) |
| 1077 | (completion-table-with-terminator | 1077 | (if (string-match "/" string) |
| 1078 | " " (lambda (string pred action) | 1078 | (completion-file-name-table string pred action) |
| 1079 | (if (string-match "/" string) | 1079 | (complete-with-action action completions string pred))) |
| 1080 | (completion-file-name-table string pred action) | 1080 | :exit-function |
| 1081 | (complete-with-action action completions string pred))) | 1081 | (lambda (_string finished) |
| 1082 | string pred action))))) | 1082 | (when (memq finished '(sole finished)) |
| 1083 | (if (looking-at " ") | ||
| 1084 | (goto-char (match-end 0)) | ||
| 1085 | (insert " "))))))) | ||
| 1083 | 1086 | ||
| 1084 | ;; (defun shell-dynamic-complete-as-command () | 1087 | ;; (defun shell-dynamic-complete-as-command () |
| 1085 | ;; "Dynamically complete at point as a command. | 1088 | ;; "Dynamically complete at point as a command. |
| @@ -1150,18 +1153,17 @@ Returns non-nil if successful." | |||
| 1150 | (substring x 0 (string-match "=" x))) | 1153 | (substring x 0 (string-match "=" x))) |
| 1151 | process-environment)) | 1154 | process-environment)) |
| 1152 | (suffix (case (char-before start) (?\{ "}") (?\( ")") (t "")))) | 1155 | (suffix (case (char-before start) (?\{ "}") (?\( ")") (t "")))) |
| 1153 | (list | 1156 | (list start end variables |
| 1154 | start end | 1157 | :exit-function |
| 1155 | (apply-partially | 1158 | (lambda (s finished) |
| 1156 | #'completion-table-with-terminator | 1159 | (when (memq finished '(sole finished)) |
| 1157 | (cons (lambda (comp) | 1160 | (let ((suf (concat suffix |
| 1158 | (concat comp | 1161 | (if (file-directory-p |
| 1159 | suffix | 1162 | (comint-directory (getenv s))) |
| 1160 | (if (file-directory-p | 1163 | "/")))) |
| 1161 | (comint-directory (getenv comp))) | 1164 | (if (looking-at (regexp-quote suf)) |
| 1162 | "/"))) | 1165 | (goto-char (match-end 0)) |
| 1163 | "\\`a\\`") | 1166 | (insert suf)))))))))) |
| 1164 | variables)))))) | ||
| 1165 | 1167 | ||
| 1166 | 1168 | ||
| 1167 | (defun shell-c-a-p-replace-by-expanded-directory () | 1169 | (defun shell-c-a-p-replace-by-expanded-directory () |
diff --git a/lisp/simple.el b/lisp/simple.el index ac53ce3add1..4cf38178357 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -5968,6 +5968,12 @@ Its value is a list of the form (START END) where START is the place | |||
| 5968 | where the completion should be inserted and END (if non-nil) is the end | 5968 | where the completion should be inserted and END (if non-nil) is the end |
| 5969 | of the text to replace. If END is nil, point is used instead.") | 5969 | of the text to replace. If END is nil, point is used instead.") |
| 5970 | 5970 | ||
| 5971 | (defvar completion-list-insert-choice-function #'completion--replace | ||
| 5972 | "Function to use to insert the text chosen in *Completions*. | ||
| 5973 | Called with 3 arguments (BEG END TEXT), it should replace the text | ||
| 5974 | between BEG and END with TEXT. Expected to be set buffer-locally | ||
| 5975 | in the *Completions* buffer.") | ||
| 5976 | |||
| 5971 | (defvar completion-base-size nil | 5977 | (defvar completion-base-size nil |
| 5972 | "Number of chars before point not involved in completion. | 5978 | "Number of chars before point not involved in completion. |
| 5973 | This is a local variable in the completion list buffer. | 5979 | This is a local variable in the completion list buffer. |
| @@ -6031,26 +6037,30 @@ With prefix argument N, move N items (negative N means move backward)." | |||
| 6031 | ;; In case this is run via the mouse, give temporary modes such as | 6037 | ;; In case this is run via the mouse, give temporary modes such as |
| 6032 | ;; isearch a chance to turn off. | 6038 | ;; isearch a chance to turn off. |
| 6033 | (run-hooks 'mouse-leave-buffer-hook) | 6039 | (run-hooks 'mouse-leave-buffer-hook) |
| 6034 | (let (buffer base-size base-position choice) | 6040 | (with-current-buffer (window-buffer (posn-window (event-start event))) |
| 6035 | (with-current-buffer (window-buffer (posn-window (event-start event))) | 6041 | (let ((buffer completion-reference-buffer) |
| 6036 | (setq buffer completion-reference-buffer) | 6042 | (base-size completion-base-size) |
| 6037 | (setq base-size completion-base-size) | 6043 | (base-position completion-base-position) |
| 6038 | (setq base-position completion-base-position) | 6044 | (insert-function completion-list-insert-choice-function) |
| 6039 | (save-excursion | 6045 | (choice |
| 6040 | (goto-char (posn-point (event-start event))) | 6046 | (save-excursion |
| 6041 | (let (beg end) | 6047 | (goto-char (posn-point (event-start event))) |
| 6042 | (if (and (not (eobp)) (get-text-property (point) 'mouse-face)) | 6048 | (let (beg end) |
| 6043 | (setq end (point) beg (1+ (point)))) | 6049 | (cond |
| 6044 | (if (and (not (bobp)) (get-text-property (1- (point)) 'mouse-face)) | 6050 | ((and (not (eobp)) (get-text-property (point) 'mouse-face)) |
| 6045 | (setq end (1- (point)) beg (point))) | 6051 | (setq end (point) beg (1+ (point)))) |
| 6046 | (if (null beg) | 6052 | ((and (not (bobp)) |
| 6047 | (error "No completion here")) | 6053 | (get-text-property (1- (point)) 'mouse-face)) |
| 6048 | (setq beg (previous-single-property-change beg 'mouse-face)) | 6054 | (setq end (1- (point)) beg (point))) |
| 6049 | (setq end (or (next-single-property-change end 'mouse-face) | 6055 | (t (error "No completion here"))) |
| 6050 | (point-max))) | 6056 | (setq beg (previous-single-property-change beg 'mouse-face)) |
| 6051 | (setq choice (buffer-substring-no-properties beg end))))) | 6057 | (setq end (or (next-single-property-change end 'mouse-face) |
| 6052 | 6058 | (point-max))) | |
| 6053 | (let ((owindow (selected-window))) | 6059 | (buffer-substring-no-properties beg end)))) |
| 6060 | (owindow (selected-window))) | ||
| 6061 | |||
| 6062 | (unless (buffer-live-p buffer) | ||
| 6063 | (error "Destination buffer is dead")) | ||
| 6054 | (select-window (posn-window (event-start event))) | 6064 | (select-window (posn-window (event-start event))) |
| 6055 | (if (and (one-window-p t 'selected-frame) | 6065 | (if (and (one-window-p t 'selected-frame) |
| 6056 | (window-dedicated-p (selected-window))) | 6066 | (window-dedicated-p (selected-window))) |
| @@ -6059,20 +6069,20 @@ With prefix argument N, move N items (negative N means move backward)." | |||
| 6059 | (or (window-dedicated-p (selected-window)) | 6069 | (or (window-dedicated-p (selected-window)) |
| 6060 | (bury-buffer))) | 6070 | (bury-buffer))) |
| 6061 | (select-window | 6071 | (select-window |
| 6062 | (or (and (buffer-live-p buffer) | 6072 | (or (get-buffer-window buffer 0) |
| 6063 | (get-buffer-window buffer 0)) | 6073 | owindow)) |
| 6064 | owindow))) | 6074 | |
| 6065 | 6075 | (with-current-buffer buffer | |
| 6066 | (choose-completion-string | 6076 | (choose-completion-string |
| 6067 | choice buffer | 6077 | choice buffer |
| 6068 | (or base-position | 6078 | (or base-position |
| 6069 | (when base-size | 6079 | (when base-size |
| 6070 | ;; Someone's using old completion code that doesn't know | 6080 | ;; Someone's using old completion code that doesn't know |
| 6071 | ;; about base-position yet. | 6081 | ;; about base-position yet. |
| 6072 | (list (+ base-size (with-current-buffer buffer (field-beginning))))) | 6082 | (list (+ base-size (field-beginning)))) |
| 6073 | ;; If all else fails, just guess. | 6083 | ;; If all else fails, just guess. |
| 6074 | (with-current-buffer buffer | 6084 | (list (choose-completion-guess-base-position choice))) |
| 6075 | (list (choose-completion-guess-base-position choice))))))) | 6085 | insert-function))))) |
| 6076 | 6086 | ||
| 6077 | ;; Delete the longest partial match for STRING | 6087 | ;; Delete the longest partial match for STRING |
| 6078 | ;; that can be found before POINT. | 6088 | ;; that can be found before POINT. |
| @@ -6118,7 +6128,8 @@ the minibuffer; no further functions will be called. | |||
| 6118 | If all functions in the list return nil, that means to use | 6128 | If all functions in the list return nil, that means to use |
| 6119 | the default method of inserting the completion in BUFFER.") | 6129 | the default method of inserting the completion in BUFFER.") |
| 6120 | 6130 | ||
| 6121 | (defun choose-completion-string (choice &optional buffer base-position) | 6131 | (defun choose-completion-string (choice &optional |
| 6132 | buffer base-position insert-function) | ||
| 6122 | "Switch to BUFFER and insert the completion choice CHOICE. | 6133 | "Switch to BUFFER and insert the completion choice CHOICE. |
| 6123 | BASE-POSITION, says where to insert the completion." | 6134 | BASE-POSITION, says where to insert the completion." |
| 6124 | 6135 | ||
| @@ -6138,8 +6149,8 @@ BASE-POSITION, says where to insert the completion." | |||
| 6138 | ;; If BUFFER is a minibuffer, barf unless it's the currently | 6149 | ;; If BUFFER is a minibuffer, barf unless it's the currently |
| 6139 | ;; active minibuffer. | 6150 | ;; active minibuffer. |
| 6140 | (if (and mini-p | 6151 | (if (and mini-p |
| 6141 | (or (not (active-minibuffer-window)) | 6152 | (not (and (active-minibuffer-window) |
| 6142 | (not (equal buffer | 6153 | (equal buffer |
| 6143 | (window-buffer (active-minibuffer-window)))))) | 6154 | (window-buffer (active-minibuffer-window)))))) |
| 6144 | (error "Minibuffer is not active for completion") | 6155 | (error "Minibuffer is not active for completion") |
| 6145 | ;; Set buffer so buffer-local choose-completion-string-functions works. | 6156 | ;; Set buffer so buffer-local choose-completion-string-functions works. |
| @@ -6151,13 +6162,15 @@ BASE-POSITION, says where to insert the completion." | |||
| 6151 | ;; and indeed unused. The last used to be `base-size', so we | 6162 | ;; and indeed unused. The last used to be `base-size', so we |
| 6152 | ;; keep it to try and avoid breaking old code. | 6163 | ;; keep it to try and avoid breaking old code. |
| 6153 | choice buffer base-position nil) | 6164 | choice buffer base-position nil) |
| 6165 | ;; This remove-text-properties should be unnecessary since `choice' | ||
| 6166 | ;; comes from buffer-substring-no-properties. | ||
| 6167 | ;;(remove-text-properties 0 (lenth choice) '(mouse-face nil) choice) | ||
| 6154 | ;; Insert the completion into the buffer where it was requested. | 6168 | ;; Insert the completion into the buffer where it was requested. |
| 6155 | (delete-region (or (car base-position) (point)) | 6169 | (funcall (or insert-function completion-list-insert-choice-function) |
| 6156 | (or (cadr base-position) (point))) | 6170 | (or (car base-position) (point)) |
| 6157 | (insert choice) | 6171 | (or (cadr base-position) (point)) |
| 6158 | (remove-text-properties (- (point) (length choice)) (point) | 6172 | choice) |
| 6159 | '(mouse-face nil)) | 6173 | ;; Update point in the window that BUFFER is showing in. |
| 6160 | ;; Update point in the window that BUFFER is showing in. | ||
| 6161 | (let ((window (get-buffer-window buffer t))) | 6174 | (let ((window (get-buffer-window buffer t))) |
| 6162 | (set-window-point window (point))) | 6175 | (set-window-point window (point))) |
| 6163 | ;; If completing for the minibuffer, exit it with this choice. | 6176 | ;; If completing for the minibuffer, exit it with this choice. |
| @@ -6223,10 +6236,13 @@ Called from `temp-buffer-show-hook'." | |||
| 6223 | 0 (or completion-base-size 0))))))) | 6236 | 0 (or completion-base-size 0))))))) |
| 6224 | (with-current-buffer standard-output | 6237 | (with-current-buffer standard-output |
| 6225 | (let ((base-size completion-base-size) ;Read before killing localvars. | 6238 | (let ((base-size completion-base-size) ;Read before killing localvars. |
| 6226 | (base-position completion-base-position)) | 6239 | (base-position completion-base-position) |
| 6240 | (insert-fun completion-list-insert-choice-function)) | ||
| 6227 | (completion-list-mode) | 6241 | (completion-list-mode) |
| 6228 | (set (make-local-variable 'completion-base-size) base-size) | 6242 | (set (make-local-variable 'completion-base-size) base-size) |
| 6229 | (set (make-local-variable 'completion-base-position) base-position)) | 6243 | (set (make-local-variable 'completion-base-position) base-position) |
| 6244 | (set (make-local-variable 'completion-list-insert-choice-function) | ||
| 6245 | insert-fun)) | ||
| 6230 | (set (make-local-variable 'completion-reference-buffer) mainbuf) | 6246 | (set (make-local-variable 'completion-reference-buffer) mainbuf) |
| 6231 | (if base-dir (setq default-directory base-dir)) | 6247 | (if base-dir (setq default-directory base-dir)) |
| 6232 | ;; Maybe insert help string. | 6248 | ;; Maybe insert help string. |
diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el index e49d7549776..9d05728ffad 100644 --- a/lisp/textmodes/bibtex.el +++ b/lisp/textmodes/bibtex.el | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | ;;; bibtex.el --- BibTeX mode for GNU Emacs | 1 | ;;; bibtex.el --- BibTeX mode for GNU Emacs -*- lexical-binding: t -*- |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1992, 1994-1999, 2001-2011 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1992, 1994-1999, 2001-2011 Free Software Foundation, Inc. |
| 4 | 4 | ||
| @@ -204,7 +204,7 @@ See also `bibtex-sort-ignore-string-entries'." | |||
| 204 | (const entry-class) | 204 | (const entry-class) |
| 205 | (const t))) | 205 | (const t))) |
| 206 | (put 'bibtex-maintain-sorted-entries 'safe-local-variable | 206 | (put 'bibtex-maintain-sorted-entries 'safe-local-variable |
| 207 | '(lambda (a) (memq a '(nil t plain crossref entry-class)))) | 207 | (lambda (a) (memq a '(nil t plain crossref entry-class)))) |
| 208 | 208 | ||
| 209 | (defcustom bibtex-sort-entry-class | 209 | (defcustom bibtex-sort-entry-class |
| 210 | '(("String") | 210 | '(("String") |
| @@ -968,7 +968,7 @@ Set this variable before loading BibTeX mode." | |||
| 968 | (modify-syntax-entry ?\" "\"" st) | 968 | (modify-syntax-entry ?\" "\"" st) |
| 969 | (modify-syntax-entry ?$ "$$ " st) | 969 | (modify-syntax-entry ?$ "$$ " st) |
| 970 | (modify-syntax-entry ?% "< " st) | 970 | (modify-syntax-entry ?% "< " st) |
| 971 | (modify-syntax-entry ?' "w " st) | 971 | (modify-syntax-entry ?' "w " st) ;FIXME: Not allowed in @string keys. |
| 972 | (modify-syntax-entry ?@ "w " st) | 972 | (modify-syntax-entry ?@ "w " st) |
| 973 | (modify-syntax-entry ?\\ "\\" st) | 973 | (modify-syntax-entry ?\\ "\\" st) |
| 974 | (modify-syntax-entry ?\f "> " st) | 974 | (modify-syntax-entry ?\f "> " st) |
| @@ -984,7 +984,7 @@ Set this variable before loading BibTeX mode." | |||
| 984 | ;; The Key `C-c&' is reserved for reftex.el | 984 | ;; The Key `C-c&' is reserved for reftex.el |
| 985 | (define-key km "\t" 'bibtex-find-text) | 985 | (define-key km "\t" 'bibtex-find-text) |
| 986 | (define-key km "\n" 'bibtex-next-field) | 986 | (define-key km "\n" 'bibtex-next-field) |
| 987 | (define-key km "\M-\t" 'bibtex-complete) | 987 | (define-key km "\M-\t" 'completion-at-point) |
| 988 | (define-key km "\C-c\"" 'bibtex-remove-delimiters) | 988 | (define-key km "\C-c\"" 'bibtex-remove-delimiters) |
| 989 | (define-key km "\C-c{" 'bibtex-remove-delimiters) | 989 | (define-key km "\C-c{" 'bibtex-remove-delimiters) |
| 990 | (define-key km "\C-c}" 'bibtex-remove-delimiters) | 990 | (define-key km "\C-c}" 'bibtex-remove-delimiters) |
| @@ -2018,7 +2018,7 @@ Formats current entry according to variable `bibtex-entry-format'." | |||
| 2018 | ;; remove delimiters from purely numerical fields | 2018 | ;; remove delimiters from purely numerical fields |
| 2019 | (when (and (memq 'numerical-fields format) | 2019 | (when (and (memq 'numerical-fields format) |
| 2020 | (progn (goto-char beg-text) | 2020 | (progn (goto-char beg-text) |
| 2021 | (looking-at "\\(\"[0-9]+\"\\)\\|\\({[0-9]+}\\)"))) | 2021 | (looking-at "\"[0-9]+\"\\|{[0-9]+}"))) |
| 2022 | (goto-char end-text) | 2022 | (goto-char end-text) |
| 2023 | (delete-char -1) | 2023 | (delete-char -1) |
| 2024 | (goto-char beg-text) | 2024 | (goto-char beg-text) |
| @@ -2247,10 +2247,11 @@ applied to the content of FIELD. It is an alist with pairs | |||
| 2247 | (content (bibtex-text-in-field field bibtex-autokey-use-crossref)) | 2247 | (content (bibtex-text-in-field field bibtex-autokey-use-crossref)) |
| 2248 | case-fold-search) | 2248 | case-fold-search) |
| 2249 | (unless content (setq content "")) | 2249 | (unless content (setq content "")) |
| 2250 | (dolist (pattern change-list content) | 2250 | (dolist (pattern change-list) |
| 2251 | (setq content (replace-regexp-in-string (car pattern) | 2251 | (setq content (replace-regexp-in-string (car pattern) |
| 2252 | (cdr pattern) | 2252 | (cdr pattern) |
| 2253 | content t))))) | 2253 | content t))) |
| 2254 | content)) | ||
| 2254 | 2255 | ||
| 2255 | (defun bibtex-autokey-get-names () | 2256 | (defun bibtex-autokey-get-names () |
| 2256 | "Get contents of the name field of the current entry. | 2257 | "Get contents of the name field of the current entry. |
| @@ -2521,7 +2522,7 @@ for parsing BibTeX keys. If parsing fails, try to set this variable to nil." | |||
| 2521 | (bibtex-sort-ignore-string-entries t) | 2522 | (bibtex-sort-ignore-string-entries t) |
| 2522 | bounds) | 2523 | bounds) |
| 2523 | (bibtex-map-entries | 2524 | (bibtex-map-entries |
| 2524 | (lambda (key beg end) | 2525 | (lambda (key _beg end) |
| 2525 | (if (and abortable | 2526 | (if (and abortable |
| 2526 | (input-pending-p)) | 2527 | (input-pending-p)) |
| 2527 | ;; user has aborted by typing a key: return `aborted' | 2528 | ;; user has aborted by typing a key: return `aborted' |
| @@ -2714,20 +2715,6 @@ When called interactively, FORCE is t, CURRENT is t if current buffer uses | |||
| 2714 | (message "No BibTeX buffers defined"))) | 2715 | (message "No BibTeX buffers defined"))) |
| 2715 | buffer-list)) | 2716 | buffer-list)) |
| 2716 | 2717 | ||
| 2717 | (defun bibtex-complete-internal (completions) | ||
| 2718 | "Complete word fragment before point to longest prefix of COMPLETIONS. | ||
| 2719 | COMPLETIONS is an alist of strings. If point is not after the part | ||
| 2720 | of a word, all strings are listed. Return completion." | ||
| 2721 | ;; Return value is used by cleanup functions. | ||
| 2722 | ;; Code inspired by `lisp-complete-symbol'. | ||
| 2723 | (let ((beg (save-excursion | ||
| 2724 | (re-search-backward "[ \t{\"]") | ||
| 2725 | (forward-char) | ||
| 2726 | (point))) | ||
| 2727 | (end (point))) | ||
| 2728 | (when (completion-in-region beg end completions) | ||
| 2729 | (buffer-substring beg (point))))) | ||
| 2730 | |||
| 2731 | (defun bibtex-complete-string-cleanup (str compl) | 2718 | (defun bibtex-complete-string-cleanup (str compl) |
| 2732 | "Cleanup after inserting string STR. | 2719 | "Cleanup after inserting string STR. |
| 2733 | Remove enclosing field delimiters for STR. Display message with | 2720 | Remove enclosing field delimiters for STR. Display message with |
| @@ -2941,7 +2928,7 @@ BOUND limits the search." | |||
| 2941 | ;; Interactive Functions: | 2928 | ;; Interactive Functions: |
| 2942 | 2929 | ||
| 2943 | ;;;###autoload | 2930 | ;;;###autoload |
| 2944 | (defun bibtex-mode () | 2931 | (define-derived-mode bibtex-mode nil "BibTeX" |
| 2945 | "Major mode for editing BibTeX files. | 2932 | "Major mode for editing BibTeX files. |
| 2946 | 2933 | ||
| 2947 | General information on working with BibTeX mode: | 2934 | General information on working with BibTeX mode: |
| @@ -2953,7 +2940,7 @@ new entry with the command \\[bibtex-clean-entry]. | |||
| 2953 | 2940 | ||
| 2954 | Some features of BibTeX mode are available only by setting the variable | 2941 | Some features of BibTeX mode are available only by setting the variable |
| 2955 | `bibtex-maintain-sorted-entries' to non-nil. However, then BibTeX mode | 2942 | `bibtex-maintain-sorted-entries' to non-nil. However, then BibTeX mode |
| 2956 | works only with buffers containing valid (syntactical correct) and sorted | 2943 | works only with buffers containing valid (syntactically correct) and sorted |
| 2957 | entries. This is usually the case, if you have created a buffer completely | 2944 | entries. This is usually the case, if you have created a buffer completely |
| 2958 | with BibTeX mode and finished every new entry with \\[bibtex-clean-entry]. | 2945 | with BibTeX mode and finished every new entry with \\[bibtex-clean-entry]. |
| 2959 | 2946 | ||
| @@ -2975,7 +2962,7 @@ the name of a field with \\[bibtex-remove-OPT-or-ALT]. | |||
| 2975 | \\[bibtex-remove-delimiters] removes the double-quotes or braces around the text of the current field. | 2962 | \\[bibtex-remove-delimiters] removes the double-quotes or braces around the text of the current field. |
| 2976 | \\[bibtex-empty-field] replaces the text of the current field with the default \"\" or {}. | 2963 | \\[bibtex-empty-field] replaces the text of the current field with the default \"\" or {}. |
| 2977 | \\[bibtex-find-text] moves point to the end of the current field. | 2964 | \\[bibtex-find-text] moves point to the end of the current field. |
| 2978 | \\[bibtex-complete] completes word fragment before point according to context. | 2965 | \\[completion-at-point] completes word fragment before point according to context. |
| 2979 | 2966 | ||
| 2980 | The command \\[bibtex-clean-entry] cleans the current entry, i.e. it removes OPT/ALT | 2967 | The command \\[bibtex-clean-entry] cleans the current entry, i.e. it removes OPT/ALT |
| 2981 | from the names of all non-empty optional or alternative fields, checks that | 2968 | from the names of all non-empty optional or alternative fields, checks that |
| @@ -2993,12 +2980,8 @@ Entry to BibTeX mode calls the value of `bibtex-mode-hook' | |||
| 2993 | if that value is non-nil. | 2980 | if that value is non-nil. |
| 2994 | 2981 | ||
| 2995 | \\{bibtex-mode-map}" | 2982 | \\{bibtex-mode-map}" |
| 2996 | (interactive) | 2983 | (add-hook 'completion-at-point-functions |
| 2997 | (kill-all-local-variables) | 2984 | 'bibtex-completion-at-point-function nil 'local) |
| 2998 | (use-local-map bibtex-mode-map) | ||
| 2999 | (setq major-mode 'bibtex-mode) | ||
| 3000 | (setq mode-name "BibTeX") | ||
| 3001 | (set-syntax-table bibtex-mode-syntax-table) | ||
| 3002 | (make-local-variable 'bibtex-buffer-last-parsed-tick) | 2985 | (make-local-variable 'bibtex-buffer-last-parsed-tick) |
| 3003 | ;; Install stealthy parse function if not already installed | 2986 | ;; Install stealthy parse function if not already installed |
| 3004 | (unless bibtex-parse-idle-timer | 2987 | (unless bibtex-parse-idle-timer |
| @@ -3013,9 +2996,8 @@ if that value is non-nil. | |||
| 3013 | (set (make-local-variable 'defun-prompt-regexp) "^[ \t]*@[[:alnum:]]+[ \t]*") | 2996 | (set (make-local-variable 'defun-prompt-regexp) "^[ \t]*@[[:alnum:]]+[ \t]*") |
| 3014 | (set (make-local-variable 'outline-regexp) "[ \t]*@") | 2997 | (set (make-local-variable 'outline-regexp) "[ \t]*@") |
| 3015 | (set (make-local-variable 'fill-paragraph-function) 'bibtex-fill-field) | 2998 | (set (make-local-variable 'fill-paragraph-function) 'bibtex-fill-field) |
| 3016 | (set (make-local-variable 'fill-prefix) (make-string (+ bibtex-entry-offset | 2999 | (set (make-local-variable 'fill-prefix) |
| 3017 | bibtex-contline-indentation) | 3000 | (make-string (+ bibtex-entry-offset bibtex-contline-indentation) ?\s)) |
| 3018 | ?\s)) | ||
| 3019 | (set (make-local-variable 'font-lock-defaults) | 3001 | (set (make-local-variable 'font-lock-defaults) |
| 3020 | '(bibtex-font-lock-keywords | 3002 | '(bibtex-font-lock-keywords |
| 3021 | nil t ((?$ . "\"") | 3003 | nil t ((?$ . "\"") |
| @@ -3037,11 +3019,9 @@ if that value is non-nil. | |||
| 3037 | (setq imenu-generic-expression | 3019 | (setq imenu-generic-expression |
| 3038 | (list (list nil bibtex-entry-head bibtex-key-in-head)) | 3020 | (list (list nil bibtex-entry-head bibtex-key-in-head)) |
| 3039 | imenu-case-fold-search t) | 3021 | imenu-case-fold-search t) |
| 3040 | (make-local-variable 'choose-completion-string-functions) | ||
| 3041 | ;; XEmacs needs `easy-menu-add', Emacs does not care | 3022 | ;; XEmacs needs `easy-menu-add', Emacs does not care |
| 3042 | (easy-menu-add bibtex-edit-menu) | 3023 | (easy-menu-add bibtex-edit-menu) |
| 3043 | (easy-menu-add bibtex-entry-menu) | 3024 | (easy-menu-add bibtex-entry-menu)) |
| 3044 | (run-mode-hooks 'bibtex-mode-hook)) | ||
| 3045 | 3025 | ||
| 3046 | (defun bibtex-field-list (entry-type) | 3026 | (defun bibtex-field-list (entry-type) |
| 3047 | "Return list of allowed fields for entry ENTRY-TYPE. | 3027 | "Return list of allowed fields for entry ENTRY-TYPE. |
| @@ -3383,7 +3363,7 @@ If mark is active count entries in region, if not in whole buffer." | |||
| 3383 | (bibtex-sort-ignore-string-entries (not count-string-entries))) | 3363 | (bibtex-sort-ignore-string-entries (not count-string-entries))) |
| 3384 | (save-restriction | 3364 | (save-restriction |
| 3385 | (if mark-active (narrow-to-region (region-beginning) (region-end))) | 3365 | (if mark-active (narrow-to-region (region-beginning) (region-end))) |
| 3386 | (bibtex-map-entries (lambda (key beg end) (setq number (1+ number))))) | 3366 | (bibtex-map-entries (lambda (_key _beg _end) (setq number (1+ number))))) |
| 3387 | (message "%s contains %d entries." | 3367 | (message "%s contains %d entries." |
| 3388 | (if mark-active "Region" "Buffer") | 3368 | (if mark-active "Region" "Buffer") |
| 3389 | number))) | 3369 | number))) |
| @@ -3438,12 +3418,13 @@ of the head of the entry found. Return nil if no entry found." | |||
| 3438 | (unless (local-variable-p 'bibtex-sort-entry-class-alist) | 3418 | (unless (local-variable-p 'bibtex-sort-entry-class-alist) |
| 3439 | (set (make-local-variable 'bibtex-sort-entry-class-alist) | 3419 | (set (make-local-variable 'bibtex-sort-entry-class-alist) |
| 3440 | (let ((i -1) alist) | 3420 | (let ((i -1) alist) |
| 3441 | (dolist (class bibtex-sort-entry-class alist) | 3421 | (dolist (class bibtex-sort-entry-class) |
| 3442 | (setq i (1+ i)) | 3422 | (setq i (1+ i)) |
| 3443 | (dolist (entry class) | 3423 | (dolist (entry class) |
| 3444 | ;; All entry types should be downcase (for ease of comparison). | 3424 | ;; All entry types should be downcase (for ease of comparison). |
| 3445 | (push (cons (if (stringp entry) (downcase entry) entry) i) | 3425 | (push (cons (if (stringp entry) (downcase entry) entry) i) |
| 3446 | alist))))))) | 3426 | alist))) |
| 3427 | alist)))) | ||
| 3447 | 3428 | ||
| 3448 | (defun bibtex-lessp (index1 index2) | 3429 | (defun bibtex-lessp (index1 index2) |
| 3449 | "Predicate for sorting BibTeX entries with indices INDEX1 and INDEX2. | 3430 | "Predicate for sorting BibTeX entries with indices INDEX1 and INDEX2. |
| @@ -3735,7 +3716,7 @@ Return t if test was successful, nil otherwise." | |||
| 3735 | (let (previous current key-list) | 3716 | (let (previous current key-list) |
| 3736 | (bibtex-progress-message "Checking for duplicate keys") | 3717 | (bibtex-progress-message "Checking for duplicate keys") |
| 3737 | (bibtex-map-entries | 3718 | (bibtex-map-entries |
| 3738 | (lambda (key beg end) | 3719 | (lambda (key _beg _end) |
| 3739 | (bibtex-progress-message) | 3720 | (bibtex-progress-message) |
| 3740 | (setq current (bibtex-entry-index)) | 3721 | (setq current (bibtex-entry-index)) |
| 3741 | (cond ((not previous)) | 3722 | (cond ((not previous)) |
| @@ -3773,7 +3754,7 @@ Return t if test was successful, nil otherwise." | |||
| 3773 | "Checking required fields and month fields") | 3754 | "Checking required fields and month fields") |
| 3774 | (let ((bibtex-sort-ignore-string-entries t)) | 3755 | (let ((bibtex-sort-ignore-string-entries t)) |
| 3775 | (bibtex-map-entries | 3756 | (bibtex-map-entries |
| 3776 | (lambda (key beg end) | 3757 | (lambda (_key beg _end) |
| 3777 | (bibtex-progress-message) | 3758 | (bibtex-progress-message) |
| 3778 | (let* ((entry-list (assoc-string (bibtex-type-in-head) | 3759 | (let* ((entry-list (assoc-string (bibtex-type-in-head) |
| 3779 | bibtex-entry-field-alist t)) | 3760 | bibtex-entry-field-alist t)) |
| @@ -4440,7 +4421,7 @@ If mark is active reformat entries in region, if not in whole buffer." | |||
| 4440 | (if (memq 'realign bibtex-entry-format) | 4421 | (if (memq 'realign bibtex-entry-format) |
| 4441 | (bibtex-realign)) | 4422 | (bibtex-realign)) |
| 4442 | (bibtex-progress-message "Formatting" 1) | 4423 | (bibtex-progress-message "Formatting" 1) |
| 4443 | (bibtex-map-entries (lambda (key beg end) | 4424 | (bibtex-map-entries (lambda (_key _beg _end) |
| 4444 | (bibtex-progress-message) | 4425 | (bibtex-progress-message) |
| 4445 | (bibtex-clean-entry reformat-reference-keys t))) | 4426 | (bibtex-clean-entry reformat-reference-keys t))) |
| 4446 | (bibtex-progress-message 'done)) | 4427 | (bibtex-progress-message 'done)) |
| @@ -4473,17 +4454,15 @@ entries from minibuffer." | |||
| 4473 | (goto-char (point-max)) | 4454 | (goto-char (point-max)) |
| 4474 | (message "Buffer is now parsable. Please save it."))) | 4455 | (message "Buffer is now parsable. Please save it."))) |
| 4475 | 4456 | ||
| 4476 | (defun bibtex-complete () | 4457 | (define-obsolete-function-alias 'bibtex-complete 'completion-at-point "24.1") |
| 4477 | "Complete word fragment before point according to context. | 4458 | (defun bibtex-completion-at-point-function () |
| 4478 | If point is inside key or crossref field perform key completion based on | ||
| 4479 | `bibtex-reference-keys'. Inside a month field perform key completion | ||
| 4480 | based on `bibtex-predefined-month-strings'. Inside any other field | ||
| 4481 | \(including a String or Preamble definition) perform string completion | ||
| 4482 | based on `bibtex-strings'. | ||
| 4483 | An error is signaled if point is outside key or BibTeX field." | ||
| 4484 | (interactive) | ||
| 4485 | (let ((pnt (point)) | 4459 | (let ((pnt (point)) |
| 4486 | (case-fold-search t) | 4460 | (case-fold-search t) |
| 4461 | (beg (save-excursion | ||
| 4462 | (re-search-backward "[ \t{\"]") | ||
| 4463 | (forward-char) | ||
| 4464 | (point))) | ||
| 4465 | (end (point)) | ||
| 4487 | bounds name compl) | 4466 | bounds name compl) |
| 4488 | (save-excursion | 4467 | (save-excursion |
| 4489 | (if (and (setq bounds (bibtex-enclosing-field nil t)) | 4468 | (if (and (setq bounds (bibtex-enclosing-field nil t)) |
| @@ -4524,49 +4503,56 @@ An error is signaled if point is outside key or BibTeX field." | |||
| 4524 | (setq compl 'key))))) | 4503 | (setq compl 'key))))) |
| 4525 | 4504 | ||
| 4526 | (cond ((eq compl 'key) | 4505 | (cond ((eq compl 'key) |
| 4527 | ;; key completion: no cleanup needed | 4506 | ;; Key completion: no cleanup needed. |
| 4528 | (setq choose-completion-string-functions nil) | 4507 | (list beg end |
| 4529 | (let (completion-ignore-case) | 4508 | (lambda (s p a) |
| 4530 | (bibtex-complete-internal (bibtex-global-key-alist)))) | 4509 | (let (completion-ignore-case) |
| 4510 | (complete-with-action a (bibtex-global-key-alist) s p))))) | ||
| 4531 | 4511 | ||
| 4532 | ((eq compl 'crossref-key) | 4512 | ((eq compl 'crossref-key) |
| 4533 | ;; crossref key completion | 4513 | ;; Crossref key completion. |
| 4534 | ;; | 4514 | (let* ((buf (current-buffer))) |
| 4535 | ;; If we quit the *Completions* buffer without requesting | 4515 | (list beg end |
| 4536 | ;; a completion, `choose-completion-string-functions' is still | 4516 | (lambda (s p a) |
| 4537 | ;; non-nil. Therefore, `choose-completion-string-functions' is | 4517 | (cond |
| 4538 | ;; always set (either to non-nil or nil) when a new completion | 4518 | ((eq a 'metadata) `(metadata (category . bibtex-key))) |
| 4539 | ;; is requested. | 4519 | (t (let ((completion-ignore-case nil)) |
| 4540 | (let (completion-ignore-case) | 4520 | (complete-with-action |
| 4541 | (setq choose-completion-string-functions | 4521 | a (bibtex-global-key-alist) s p))))) |
| 4542 | (lambda (choice buffer base-position &rest ignored) | 4522 | :exit-function |
| 4543 | (setq choose-completion-string-functions nil) | 4523 | (lambda (string status) |
| 4544 | (choose-completion-string choice buffer base-position) | 4524 | (when (memq status '(exact sole finished)) |
| 4545 | (bibtex-complete-crossref-cleanup choice) | 4525 | (let ((summary |
| 4546 | t)) ; needed by choose-completion-string-functions | 4526 | (with-current-buffer buf |
| 4547 | (bibtex-complete-crossref-cleanup | 4527 | (save-excursion |
| 4548 | (bibtex-complete-internal (bibtex-global-key-alist))))) | 4528 | (if (bibtex-search-entry string) |
| 4529 | (funcall bibtex-summary-function)))))) | ||
| 4530 | (when summary | ||
| 4531 | (message "%s %s" string summary)))))))) | ||
| 4549 | 4532 | ||
| 4550 | ((eq compl 'string) | 4533 | ((eq compl 'string) |
| 4551 | ;; string key completion: no cleanup needed | 4534 | ;; String key completion: no cleanup needed. |
| 4552 | (setq choose-completion-string-functions nil) | 4535 | (list beg end |
| 4553 | (let ((completion-ignore-case t)) | 4536 | (lambda (s p a) |
| 4554 | (bibtex-complete-internal bibtex-strings))) | 4537 | (let ((completion-ignore-case t)) |
| 4538 | (complete-with-action a bibtex-strings s p))))) | ||
| 4555 | 4539 | ||
| 4556 | (compl | 4540 | (compl |
| 4557 | ;; string completion | 4541 | ;; String completion. |
| 4558 | (let ((completion-ignore-case t)) | 4542 | (list beg end |
| 4559 | (setq choose-completion-string-functions | 4543 | (lambda (s p a) |
| 4560 | `(lambda (choice buffer base-position &rest ignored) | 4544 | (cond |
| 4561 | (setq choose-completion-string-functions nil) | 4545 | ((eq a 'metadata) `(metadata (category . bibtex-string))) |
| 4562 | (choose-completion-string choice buffer base-position) | 4546 | (t (let ((completion-ignore-case t)) |
| 4563 | (bibtex-complete-string-cleanup choice ',compl) | 4547 | (complete-with-action a compl s p))))) |
| 4564 | t)) ; needed by `choose-completion-string-functions' | 4548 | :exit-function |
| 4565 | (bibtex-complete-string-cleanup (bibtex-complete-internal compl) | 4549 | (lambda (string status) |
| 4566 | compl))) | 4550 | (when (memq status '(exact finished sole)) |
| 4567 | 4551 | (let ((abbr (cdr (assoc-string string compl t)))) | |
| 4568 | (t (setq choose-completion-string-functions nil) | 4552 | (when abbr |
| 4569 | (error "Point outside key or BibTeX field"))))) | 4553 | (message "%s = abbreviation for `%s'" string abbr)))) |
| 4554 | (when (eq status 'finished) | ||
| 4555 | (save-excursion (bibtex-remove-delimiters))))))))) | ||
| 4570 | 4556 | ||
| 4571 | (defun bibtex-Article () | 4557 | (defun bibtex-Article () |
| 4572 | "Insert a new BibTeX @Article entry; see also `bibtex-entry'." | 4558 | "Insert a new BibTeX @Article entry; see also `bibtex-entry'." |
| @@ -4772,5 +4758,4 @@ Return the URL or nil if none can be generated." | |||
| 4772 | ;; Make BibTeX a Feature | 4758 | ;; Make BibTeX a Feature |
| 4773 | 4759 | ||
| 4774 | (provide 'bibtex) | 4760 | (provide 'bibtex) |
| 4775 | |||
| 4776 | ;;; bibtex.el ends here | 4761 | ;;; bibtex.el ends here |