"Apply FUN to each element of XS in turn.
Return the first non-nil returned value.
Like CL's `some'."
- (let ((firsterror nil)
- res)
+ (lexical-let ((firsterror nil)
+ res)
(while (and (not res) xs)
(condition-case err
(setq res (funcall fun (pop xs)))
(defconst completion-styles-alist
'((emacs21
completion-emacs21-try-completion completion-emacs21-all-completions
- "Simple prefix-based completion.")
+ "Simple prefix-based completion.
+I.e. when completing \"foo_bar\" (where _ is the position of point),
+it will consider all completions candidates matching the glob
+pattern \"foobar*\".")
(emacs22
completion-emacs22-try-completion completion-emacs22-all-completions
- "Prefix completion that only operates on the text before point.")
+ "Prefix completion that only operates on the text before point.
+I.e. when completing \"foo_bar\" (where _ is the position of point),
+it will consider all completions candidates matching the glob
+pattern \"foo*\" and will add back \"bar\" to the end of it.")
(basic
completion-basic-try-completion completion-basic-all-completions
- "Completion of the prefix before point and the suffix after point.")
+ "Completion of the prefix before point and the suffix after point.
+I.e. when completing \"foo_bar\" (where _ is the position of point),
+it will consider all completions candidates matching the glob
+pattern \"foo*bar*\".")
(partial-completion
completion-pcm-try-completion completion-pcm-all-completions
"Completion of multiple words, each one taken as a prefix.
-E.g. M-x l-c-h can complete to list-command-history
-and C-x C-f /u/m/s to /usr/monnier/src.")
+I.e. when completing \"l-co_h\" (where _ is the position of point),
+it will consider all completions candidates matching the glob
+pattern \"l*-co*h*\".
+Furthermore, for completions that are done step by step in subfields,
+the method is applied to all the preceding fields that do not yet match.
+E.g. C-x C-f /u/mo/s TAB could complete to /usr/monnier/src.
+Additionally the user can use the char \"*\" as a glob pattern.")
(initials
completion-initials-try-completion completion-initials-all-completions
"Completion of acronyms and initialisms.
follow the calling convention of `completion-all-completions'),
and DOC describes the way this style of completion works.")
-(defcustom completion-styles '(basic partial-completion emacs22)
+(defcustom completion-styles
+ ;; First, use `basic' because prefix completion has been the standard
+ ;; for "ever" and works well in most cases, so using it first
+ ;; ensures that we obey previous behavior in most cases.
+ '(basic
+ ;; Then use `partial-completion' because it has proven to
+ ;; be a very convenient extension.
+ partial-completion
+ ;; Finally use `emacs22' so as to maintain (in many/most cases)
+ ;; the previous behavior that when completing "foobar" with point
+ ;; between "foo" and "bar" the completion try to complete "foo"
+ ;; and simply add "bar" to the end of the result.
+ emacs22)
"List of completion styles to use.
The available styles are listed in `completion-styles-alist'."
:type `(repeat (choice ,@(mapcar (lambda (x) (list 'const (car x)))
(defun completion--replace (beg end newtext)
"Replace the buffer text between BEG and END with NEWTEXT.
Moves point to the end of the new text."
- ;; This should be in subr.el.
+ ;; Maybe this should be in subr.el.
;; You'd think this is trivial to do, but details matter if you want
;; to keep markers "at the right place" and be robust in the face of
;; after-change-functions that may themselves modify the buffer.
+ (let ((prefix-len 0))
+ ;; Don't touch markers in the shared prefix (if any).
+ (while (and (< prefix-len (length newtext))
+ (< (+ beg prefix-len) end)
+ (eq (char-after (+ beg prefix-len))
+ (aref newtext prefix-len)))
+ (setq prefix-len (1+ prefix-len)))
+ (unless (zerop prefix-len)
+ (setq beg (+ beg prefix-len))
+ (setq newtext (substring newtext prefix-len))))
+ (let ((suffix-len 0))
+ ;; Don't touch markers in the shared suffix (if any).
+ (while (and (< suffix-len (length newtext))
+ (< beg (- end suffix-len))
+ (eq (char-before (- end suffix-len))
+ (aref newtext (- (length newtext) suffix-len 1))))
+ (setq suffix-len (1+ suffix-len)))
+ (unless (zerop suffix-len)
+ (setq end (- end suffix-len))
+ (setq newtext (substring newtext 0 (- suffix-len)))))
(goto-char beg)
(insert newtext)
(delete-region (point) (+ (point) (- end beg))))
101 5 ??? impossible
110 6 some completion happened
111 7 completed to an exact completion"
- (let* ((beg (field-beginning))
- (end (field-end))
- (string (buffer-substring beg end))
- (comp (funcall (or try-completion-function
- 'completion-try-completion)
- string
- minibuffer-completion-table
- minibuffer-completion-predicate
- (- (point) beg))))
+ (lexical-let*
+ ((beg (field-beginning))
+ (end (field-end))
+ (string (buffer-substring beg end))
+ (comp (funcall (or try-completion-function
+ 'completion-try-completion)
+ string
+ minibuffer-completion-table
+ minibuffer-completion-predicate
+ (- (point) beg))))
(cond
((null comp)
(minibuffer-hide-completions)
;; `completed' should be t if some completion was done, which doesn't
;; include simply changing the case of the entered string. However,
;; for appearance, the string is rewritten if the case changes.
- (let* ((comp-pos (cdr comp))
- (completion (car comp))
- (completed (not (eq t (compare-strings completion nil nil
- string nil nil t))))
- (unchanged (eq t (compare-strings completion nil nil
- string nil nil nil))))
+ (lexical-let*
+ ((comp-pos (cdr comp))
+ (completion (car comp))
+ (completed (not (eq t (compare-strings completion nil nil
+ string nil nil t))))
+ (unchanged (eq t (compare-strings completion nil nil
+ string nil nil nil))))
(if unchanged
- (goto-char end)
+ (goto-char end)
;; Insert in minibuffer the chars we got.
(completion--replace beg end completion))
;; Move point to its completion-mandated destination.
`minibuffer-confirm-exit-commands', and accept the input
otherwise."
(interactive)
- (let ((beg (field-beginning))
- (end (field-end)))
+ (lexical-let ((beg (field-beginning))
+ (end (field-end)))
(cond
;; Allow user to specify null string
((= beg end) (exit-minibuffer))
"Display a list of possible completions of the current minibuffer contents."
(interactive)
(message "Making completion list...")
- (let* ((start (field-beginning))
- (string (field-string))
- (completions (completion-all-completions
- string
- minibuffer-completion-table
- minibuffer-completion-predicate
- (- (point) (field-beginning)))))
+ (lexical-let* ((start (field-beginning))
+ (string (field-string))
+ (completions (completion-all-completions
+ string
+ minibuffer-completion-table
+ minibuffer-completion-predicate
+ (- (point) (field-beginning)))))
(message nil)
(if (and completions
(or (consp (cdr completions))
The functions on this special hook are called with 5 arguments:
NEXT-FUN START END COLLECTION PREDICATE.
NEXT-FUN is a function of four arguments (START END COLLECTION PREDICATE)
-that performs the default operation. The other four argument are like
+that performs the default operation. The other four arguments are like
the ones passed to `completion-in-region'. The functions on this hook
are expected to perform completion on START..END using COLLECTION
and PREDICATE, either by calling NEXT-FUN or by doing it themselves.")
`:annotation-function' the value to use for `completion-annotate-function'.")
(defun completion-at-point ()
- "Complete the thing at point according to local mode."
+ "Complete the thing at point according to local mode.
+This runs the hook `completion-at-point-functions' until a member returns
+non-nil."
(interactive)
(let ((res (run-hook-with-args-until-success
'completion-at-point-functions)))
suffix))
(defun completion-basic-try-completion (string table pred point)
- (let* ((beforepoint (substring string 0 point))
- (afterpoint (substring string point))
- (bounds (completion-boundaries beforepoint table pred afterpoint)))
+ (lexical-let*
+ ((beforepoint (substring string 0 point))
+ (afterpoint (substring string point))
+ (bounds (completion-boundaries beforepoint table pred afterpoint)))
(if (zerop (cdr bounds))
;; `try-completion' may return a subtly different result
;; than `all+merge', so try to use it whenever possible.
(concat completion
(completion--merge-suffix completion point afterpoint))
(length completion))))
- (let* ((suffix (substring afterpoint (cdr bounds)))
- (prefix (substring beforepoint 0 (car bounds)))
- (pattern (delete
- "" (list (substring beforepoint (car bounds))
- 'point
- (substring afterpoint 0 (cdr bounds)))))
- (all (completion-pcm--all-completions prefix pattern table pred)))
+ (lexical-let*
+ ((suffix (substring afterpoint (cdr bounds)))
+ (prefix (substring beforepoint 0 (car bounds)))
+ (pattern (delete
+ "" (list (substring beforepoint (car bounds))
+ 'point
+ (substring afterpoint 0 (cdr bounds)))))
+ (all (completion-pcm--all-completions prefix pattern table pred)))
(if minibuffer-completing-file-name
(setq all (completion-pcm--filename-try-filter all)))
(completion-pcm--merge-try pattern all prefix suffix)))))
(defun completion-basic-all-completions (string table pred point)
- (let* ((beforepoint (substring string 0 point))
- (afterpoint (substring string point))
- (bounds (completion-boundaries beforepoint table pred afterpoint))
- (suffix (substring afterpoint (cdr bounds)))
- (prefix (substring beforepoint 0 (car bounds)))
- (pattern (delete
- "" (list (substring beforepoint (car bounds))
- 'point
- (substring afterpoint 0 (cdr bounds)))))
- (all (completion-pcm--all-completions prefix pattern table pred)))
+ (lexical-let*
+ ((beforepoint (substring string 0 point))
+ (afterpoint (substring string point))
+ (bounds (completion-boundaries beforepoint table pred afterpoint))
+ (suffix (substring afterpoint (cdr bounds)))
+ (prefix (substring beforepoint 0 (car bounds)))
+ (pattern (delete
+ "" (list (substring beforepoint (car bounds))
+ 'point
+ (substring afterpoint 0 (cdr bounds)))))
+ (all (completion-pcm--all-completions prefix pattern table pred)))
(completion-hilit-commonality all point (car bounds))))
;;; Partial-completion-mode style completion.
FILTER is a function applied to the return value, that can be used, e.g. to
filter out additional entries (because TABLE migth not obey PRED)."
(unless filter (setq filter 'identity))
- (let* ((beforepoint (substring string 0 point))
- (afterpoint (substring string point))
- (bounds (completion-boundaries beforepoint table pred afterpoint))
- (prefix (substring beforepoint 0 (car bounds)))
- (suffix (substring afterpoint (cdr bounds)))
- firsterror)
+ (lexical-let*
+ ((beforepoint (substring string 0 point))
+ (afterpoint (substring string point))
+ (bounds (completion-boundaries beforepoint table pred afterpoint))
+ (prefix (substring beforepoint 0 (car bounds)))
+ (suffix (substring afterpoint (cdr bounds)))
+ firsterror)
(setq string (substring string (car bounds) (+ point (cdr bounds))))
(let* ((relpoint (- point (car bounds)))
(pattern (completion-pcm--string->pattern string relpoint))