Mercurial > emacs
comparison lisp/minibuffer.el @ 110855:bec49af30c2f
Merge changes from emacs-23 branch.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Fri, 08 Oct 2010 12:14:47 +0200 |
parents | 280c8ae2476d e4f63401c6eb |
children | 1e7d8f405703 |
comparison
equal
deleted
inserted
replaced
110820:e60b0b3ed516 | 110855:bec49af30c2f |
---|---|
131 | 131 |
132 (defun completion--some (fun xs) | 132 (defun completion--some (fun xs) |
133 "Apply FUN to each element of XS in turn. | 133 "Apply FUN to each element of XS in turn. |
134 Return the first non-nil returned value. | 134 Return the first non-nil returned value. |
135 Like CL's `some'." | 135 Like CL's `some'." |
136 (let ((firsterror nil) | 136 (lexical-let ((firsterror nil) |
137 res) | 137 res) |
138 (while (and (not res) xs) | 138 (while (and (not res) xs) |
139 (condition-case err | 139 (condition-case err |
140 (setq res (funcall fun (pop xs))) | 140 (setq res (funcall fun (pop xs))) |
141 (error (unless firsterror (setq firsterror err)) nil))) | 141 (error (unless firsterror (setq firsterror err)) nil))) |
142 (or res | 142 (or res |
483 (if exact 1 0))) | 483 (if exact 1 0))) |
484 | 484 |
485 (defun completion--replace (beg end newtext) | 485 (defun completion--replace (beg end newtext) |
486 "Replace the buffer text between BEG and END with NEWTEXT. | 486 "Replace the buffer text between BEG and END with NEWTEXT. |
487 Moves point to the end of the new text." | 487 Moves point to the end of the new text." |
488 ;; This should be in subr.el. | 488 ;; Maybe this should be in subr.el. |
489 ;; You'd think this is trivial to do, but details matter if you want | 489 ;; You'd think this is trivial to do, but details matter if you want |
490 ;; to keep markers "at the right place" and be robust in the face of | 490 ;; to keep markers "at the right place" and be robust in the face of |
491 ;; after-change-functions that may themselves modify the buffer. | 491 ;; after-change-functions that may themselves modify the buffer. |
492 (let ((prefix-len 0)) | |
493 ;; Don't touch markers in the shared prefix (if any). | |
494 (while (and (< prefix-len (length newtext)) | |
495 (< (+ beg prefix-len) end) | |
496 (eq (char-after (+ beg prefix-len)) | |
497 (aref newtext prefix-len))) | |
498 (setq prefix-len (1+ prefix-len))) | |
499 (unless (zerop prefix-len) | |
500 (setq beg (+ beg prefix-len)) | |
501 (setq newtext (substring newtext prefix-len)))) | |
502 (let ((suffix-len 0)) | |
503 ;; Don't touch markers in the shared suffix (if any). | |
504 (while (and (< suffix-len (length newtext)) | |
505 (< beg (- end suffix-len)) | |
506 (eq (char-before (- end suffix-len)) | |
507 (aref newtext (- (length newtext) suffix-len 1)))) | |
508 (setq suffix-len (1+ suffix-len))) | |
509 (unless (zerop suffix-len) | |
510 (setq end (- end suffix-len)) | |
511 (setq newtext (substring newtext 0 (- suffix-len))))) | |
492 (goto-char beg) | 512 (goto-char beg) |
493 (insert newtext) | 513 (insert newtext) |
494 (delete-region (point) (+ (point) (- end beg)))) | 514 (delete-region (point) (+ (point) (- end beg)))) |
495 | 515 |
496 (defcustom completion-cycle-threshold nil | 516 (defcustom completion-cycle-threshold nil |
518 011 3 was already an exact completion | 538 011 3 was already an exact completion |
519 100 4 ??? impossible | 539 100 4 ??? impossible |
520 101 5 ??? impossible | 540 101 5 ??? impossible |
521 110 6 some completion happened | 541 110 6 some completion happened |
522 111 7 completed to an exact completion" | 542 111 7 completed to an exact completion" |
523 (let* ((beg (field-beginning)) | 543 (lexical-let* |
524 (end (field-end)) | 544 ((beg (field-beginning)) |
525 (string (buffer-substring beg end)) | 545 (end (field-end)) |
526 (comp (funcall (or try-completion-function | 546 (string (buffer-substring beg end)) |
527 'completion-try-completion) | 547 (comp (funcall (or try-completion-function |
528 string | 548 'completion-try-completion) |
529 minibuffer-completion-table | 549 string |
530 minibuffer-completion-predicate | 550 minibuffer-completion-table |
531 (- (point) beg)))) | 551 minibuffer-completion-predicate |
552 (- (point) beg)))) | |
532 (cond | 553 (cond |
533 ((null comp) | 554 ((null comp) |
534 (minibuffer-hide-completions) | 555 (minibuffer-hide-completions) |
535 (ding) (minibuffer-message "No match") (minibuffer--bitset nil nil nil)) | 556 (ding) (minibuffer-message "No match") (minibuffer--bitset nil nil nil)) |
536 ((eq t comp) | 557 ((eq t comp) |
539 (minibuffer--bitset nil nil t)) ;Exact and unique match. | 560 (minibuffer--bitset nil nil t)) ;Exact and unique match. |
540 (t | 561 (t |
541 ;; `completed' should be t if some completion was done, which doesn't | 562 ;; `completed' should be t if some completion was done, which doesn't |
542 ;; include simply changing the case of the entered string. However, | 563 ;; include simply changing the case of the entered string. However, |
543 ;; for appearance, the string is rewritten if the case changes. | 564 ;; for appearance, the string is rewritten if the case changes. |
544 (let* ((comp-pos (cdr comp)) | 565 (lexical-let* |
545 (completion (car comp)) | 566 ((comp-pos (cdr comp)) |
546 (completed (not (eq t (compare-strings completion nil nil | 567 (completion (car comp)) |
547 string nil nil t)))) | 568 (completed (not (eq t (compare-strings completion nil nil |
548 (unchanged (eq t (compare-strings completion nil nil | 569 string nil nil t)))) |
549 string nil nil nil)))) | 570 (unchanged (eq t (compare-strings completion nil nil |
571 string nil nil nil)))) | |
550 (if unchanged | 572 (if unchanged |
551 (goto-char end) | 573 (goto-char end) |
552 ;; Insert in minibuffer the chars we got. | 574 ;; Insert in minibuffer the chars we got. |
553 (completion--replace beg end completion)) | 575 (completion--replace beg end completion)) |
554 ;; Move point to its completion-mandated destination. | 576 ;; Move point to its completion-mandated destination. |
555 (forward-char (- comp-pos (length completion))) | 577 (forward-char (- comp-pos (length completion))) |
556 | 578 |
727 do not try to complete; instead, ask for confirmation if the | 749 do not try to complete; instead, ask for confirmation if the |
728 preceding minibuffer command was a member of | 750 preceding minibuffer command was a member of |
729 `minibuffer-confirm-exit-commands', and accept the input | 751 `minibuffer-confirm-exit-commands', and accept the input |
730 otherwise." | 752 otherwise." |
731 (interactive) | 753 (interactive) |
732 (let ((beg (field-beginning)) | 754 (lexical-let ((beg (field-beginning)) |
733 (end (field-end))) | 755 (end (field-end))) |
734 (cond | 756 (cond |
735 ;; Allow user to specify null string | 757 ;; Allow user to specify null string |
736 ((= beg end) (exit-minibuffer)) | 758 ((= beg end) (exit-minibuffer)) |
737 ((test-completion (buffer-substring beg end) | 759 ((test-completion (buffer-substring beg end) |
738 minibuffer-completion-table | 760 minibuffer-completion-table |
1105 | 1127 |
1106 (defun minibuffer-completion-help () | 1128 (defun minibuffer-completion-help () |
1107 "Display a list of possible completions of the current minibuffer contents." | 1129 "Display a list of possible completions of the current minibuffer contents." |
1108 (interactive) | 1130 (interactive) |
1109 (message "Making completion list...") | 1131 (message "Making completion list...") |
1110 (let* ((non-essential t) | 1132 (lexical-let* ((start (field-beginning)) |
1111 (start (field-beginning)) | 1133 (string (field-string)) |
1112 (string (field-string)) | 1134 (completions (completion-all-completions |
1113 (completions (completion-all-completions | 1135 string |
1114 string | 1136 minibuffer-completion-table |
1115 minibuffer-completion-table | 1137 minibuffer-completion-predicate |
1116 minibuffer-completion-predicate | 1138 (- (point) (field-beginning))))) |
1117 (- (point) (field-beginning))))) | |
1118 (message nil) | 1139 (message nil) |
1119 (if (and completions | 1140 (if (and completions |
1120 (or (consp (cdr completions)) | 1141 (or (consp (cdr completions)) |
1121 (not (equal (car completions) string)))) | 1142 (not (equal (car completions) string)))) |
1122 (let* ((last (last completions)) | 1143 (let* ((last (last completions)) |
1765 "" (list (substring beforepoint (car bounds)) | 1786 "" (list (substring beforepoint (car bounds)) |
1766 'point | 1787 'point |
1767 (substring afterpoint 0 (cdr bounds))))) | 1788 (substring afterpoint 0 (cdr bounds))))) |
1768 | 1789 |
1769 (defun completion-basic-try-completion (string table pred point) | 1790 (defun completion-basic-try-completion (string table pred point) |
1770 (let* ((beforepoint (substring string 0 point)) | 1791 (lexical-let* |
1771 (afterpoint (substring string point)) | 1792 ((beforepoint (substring string 0 point)) |
1772 (bounds (completion-boundaries beforepoint table pred afterpoint))) | 1793 (afterpoint (substring string point)) |
1794 (bounds (completion-boundaries beforepoint table pred afterpoint))) | |
1773 (if (zerop (cdr bounds)) | 1795 (if (zerop (cdr bounds)) |
1774 ;; `try-completion' may return a subtly different result | 1796 ;; `try-completion' may return a subtly different result |
1775 ;; than `all+merge', so try to use it whenever possible. | 1797 ;; than `all+merge', so try to use it whenever possible. |
1776 (let ((completion (try-completion beforepoint table pred))) | 1798 (let ((completion (try-completion beforepoint table pred))) |
1777 (if (not (stringp completion)) | 1799 (if (not (stringp completion)) |
1778 completion | 1800 completion |
1779 (cons | 1801 (cons |
1780 (concat completion | 1802 (concat completion |
1781 (completion--merge-suffix completion point afterpoint)) | 1803 (completion--merge-suffix completion point afterpoint)) |
1782 (length completion)))) | 1804 (length completion)))) |
1783 (let* ((suffix (substring afterpoint (cdr bounds))) | 1805 (lexical-let* |
1784 (prefix (substring beforepoint 0 (car bounds))) | 1806 ((suffix (substring afterpoint (cdr bounds))) |
1785 (pattern (completion-basic--pattern | 1807 (prefix (substring beforepoint 0 (car bounds))) |
1786 beforepoint afterpoint bounds)) | 1808 (pattern (delete |
1787 (all (completion-pcm--all-completions prefix pattern table pred))) | 1809 "" (list (substring beforepoint (car bounds)) |
1810 'point | |
1811 (substring afterpoint 0 (cdr bounds))))) | |
1812 (all (completion-pcm--all-completions prefix pattern table pred))) | |
1788 (if minibuffer-completing-file-name | 1813 (if minibuffer-completing-file-name |
1789 (setq all (completion-pcm--filename-try-filter all))) | 1814 (setq all (completion-pcm--filename-try-filter all))) |
1790 (completion-pcm--merge-try pattern all prefix suffix))))) | 1815 (completion-pcm--merge-try pattern all prefix suffix))))) |
1791 | 1816 |
1792 (defun completion-basic-all-completions (string table pred point) | 1817 (defun completion-basic-all-completions (string table pred point) |
1793 (let* ((beforepoint (substring string 0 point)) | 1818 (lexical-let* |
1794 (afterpoint (substring string point)) | 1819 ((beforepoint (substring string 0 point)) |
1795 (bounds (completion-boundaries beforepoint table pred afterpoint)) | 1820 (afterpoint (substring string point)) |
1796 (prefix (substring beforepoint 0 (car bounds))) | 1821 (bounds (completion-boundaries beforepoint table pred afterpoint)) |
1797 (pattern (completion-basic--pattern beforepoint afterpoint bounds)) | 1822 (suffix (substring afterpoint (cdr bounds))) |
1798 (all (completion-pcm--all-completions prefix pattern table pred))) | 1823 (prefix (substring beforepoint 0 (car bounds))) |
1824 (pattern (delete | |
1825 "" (list (substring beforepoint (car bounds)) | |
1826 'point | |
1827 (substring afterpoint 0 (cdr bounds))))) | |
1828 (all (completion-pcm--all-completions prefix pattern table pred))) | |
1799 (completion-hilit-commonality all point (car bounds)))) | 1829 (completion-hilit-commonality all point (car bounds)))) |
1800 | 1830 |
1801 ;;; Partial-completion-mode style completion. | 1831 ;;; Partial-completion-mode style completion. |
1802 | 1832 |
1803 (defvar completion-pcm--delim-wild-regex nil | 1833 (defvar completion-pcm--delim-wild-regex nil |
1956 "Find all completions for STRING at POINT in TABLE, satisfying PRED. | 1986 "Find all completions for STRING at POINT in TABLE, satisfying PRED. |
1957 POINT is a position inside STRING. | 1987 POINT is a position inside STRING. |
1958 FILTER is a function applied to the return value, that can be used, e.g. to | 1988 FILTER is a function applied to the return value, that can be used, e.g. to |
1959 filter out additional entries (because TABLE migth not obey PRED)." | 1989 filter out additional entries (because TABLE migth not obey PRED)." |
1960 (unless filter (setq filter 'identity)) | 1990 (unless filter (setq filter 'identity)) |
1961 (let* ((beforepoint (substring string 0 point)) | 1991 (lexical-let* |
1962 (afterpoint (substring string point)) | 1992 ((beforepoint (substring string 0 point)) |
1963 (bounds (completion-boundaries beforepoint table pred afterpoint)) | 1993 (afterpoint (substring string point)) |
1964 (prefix (substring beforepoint 0 (car bounds))) | 1994 (bounds (completion-boundaries beforepoint table pred afterpoint)) |
1965 (suffix (substring afterpoint (cdr bounds))) | 1995 (prefix (substring beforepoint 0 (car bounds))) |
1966 firsterror) | 1996 (suffix (substring afterpoint (cdr bounds))) |
1997 firsterror) | |
1967 (setq string (substring string (car bounds) (+ point (cdr bounds)))) | 1998 (setq string (substring string (car bounds) (+ point (cdr bounds)))) |
1968 (let* ((relpoint (- point (car bounds))) | 1999 (let* ((relpoint (- point (car bounds))) |
1969 (pattern (completion-pcm--string->pattern string relpoint)) | 2000 (pattern (completion-pcm--string->pattern string relpoint)) |
1970 (all (condition-case err | 2001 (all (condition-case err |
1971 (funcall filter | 2002 (funcall filter |