summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/crm.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2013-09-06 18:46:44 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2013-09-06 18:46:44 -0400
commit67982e2b74ad72987459a6995f34161053a1dbfb (patch)
tree373ee631b05b07ea3e9572b2068b6af48c5edd58 /lisp/emacs-lisp/crm.el
parente17d94a507d3ab2b2998880861b28badf8ecf0e7 (diff)
downloademacs-67982e2b74ad72987459a6995f34161053a1dbfb.tar.gz
* lisp/minibuffer.el: Make minibuffer-complete call completion-in-region
rather than other way around. (completion--some, completion-pcm--find-all-completions): Don't delay signals when debugging. (minibuffer-completion-contents): Beware fields within the minibuffer contents. (completion-all-sorted-completions): Use defvar-local. (completion--do-completion, completion--cache-all-sorted-completions) (completion-all-sorted-completions, minibuffer-force-complete): Add args `beg' and `end'. (completion--in-region-1): New fun, extracted from minibuffer-complete. (minibuffer-complete): Use completion-in-region. (completion-complete-and-exit): New fun, extracted from minibuffer-complete-and-exit. (minibuffer-complete-and-exit): Use it. (completion--complete-and-exit): Rename from minibuffer--complete-and-exit. (completion-in-region--single-word): New function, extracted from minibuffer-complete-word. (minibuffer-complete-word): Use it. (display-completion-list): Make `common-substring' argument obsolete. (completion--in-region): Call completion--in-region-1 instead of minibuffer-complete. (completion-help-at-point): Pass boundaries to minibuffer-completion-help as args rather than via an overlay. (completion-pcm--string->pattern): Use `any-delim'. (completion-pcm--optimize-pattern): New function. (completion-pcm--pattern->regex): Handle `any-delim'. * lisp/icomplete.el (icomplete-forward-completions) (icomplete-backward-completions, icomplete-completions): Adjust calls to completion-all-sorted-completions and completion--cache-all-sorted-completions. (icomplete-with-completion-tables): Default to t. * lisp/emacs-lisp/crm.el (crm--current-element): Rename from crm--select-current-element. Don't put an overlay but return the boundaries instead. (crm--completion-command): Take two new args to bind to the boundaries. (crm-completion-help): Adjust accordingly. (crm-complete): Use completion-in-region. (crm-complete-word): Use completion-in-region--single-word. (crm-complete-and-exit): Use completion-complete-and-exit.
Diffstat (limited to 'lisp/emacs-lisp/crm.el')
-rw-r--r--lisp/emacs-lisp/crm.el62
1 files changed, 32 insertions, 30 deletions
diff --git a/lisp/emacs-lisp/crm.el b/lisp/emacs-lisp/crm.el
index b8e327625e7..750e0709591 100644
--- a/lisp/emacs-lisp/crm.el
+++ b/lisp/emacs-lisp/crm.el
@@ -157,33 +157,32 @@ Functions'."
predicate
flag)))
-(defun crm--select-current-element ()
+(defun crm--current-element ()
"Parse the minibuffer to find the current element.
-Place an overlay on the element, with a `field' property, and return it."
- (let* ((bob (minibuffer-prompt-end))
- (start (save-excursion
+Return the element's boundaries as (START . END)."
+ (let ((bob (minibuffer-prompt-end)))
+ (cons (save-excursion
(if (re-search-backward crm-separator bob t)
(match-end 0)
- bob)))
- (end (save-excursion
+ bob))
+ (save-excursion
(if (re-search-forward crm-separator nil t)
(match-beginning 0)
- (point-max))))
- (ol (make-overlay start end nil nil t)))
- (overlay-put ol 'field (make-symbol "crm"))
- ol))
-
-(defmacro crm--completion-command (command)
- "Make COMMAND a completion command for `completing-read-multiple'."
- `(let ((ol (crm--select-current-element)))
- (unwind-protect
- ,command
- (delete-overlay ol))))
+ (point-max))))))
+
+(defmacro crm--completion-command (beg end &rest body)
+ "Run BODY with BEG and END bound to the current element's boundaries."
+ (declare (indent 2) (debug (sexp sexp &rest body)))
+ `(let* ((crm--boundaries (crm--current-element))
+ (,beg (car crm--boundaries))
+ (,end (cdr crm--boundaries)))
+ ,@body))
(defun crm-completion-help ()
"Display a list of possible completions of the current minibuffer element."
(interactive)
- (crm--completion-command (minibuffer-completion-help))
+ (crm--completion-command beg end
+ (minibuffer-completion-help beg end))
nil)
(defun crm-complete ()
@@ -192,13 +191,18 @@ If no characters can be completed, display a list of possible completions.
Return t if the current element is now a valid match; otherwise return nil."
(interactive)
- (crm--completion-command (minibuffer-complete)))
+ (crm--completion-command beg end
+ (completion-in-region beg end
+ minibuffer-completion-table
+ minibuffer-completion-predicate)))
(defun crm-complete-word ()
"Complete the current element at most a single word.
Like `minibuffer-complete-word' but for `completing-read-multiple'."
(interactive)
- (crm--completion-command (minibuffer-complete-word)))
+ (crm--completion-command beg end
+ (completion-in-region--single-word
+ beg end minibuffer-completion-table minibuffer-completion-predicate)))
(defun crm-complete-and-exit ()
"If all of the minibuffer elements are valid completions then exit.
@@ -211,16 +215,14 @@ This function is modeled after `minibuffer-complete-and-exit'."
(goto-char (minibuffer-prompt-end))
(while
(and doexit
- (let ((ol (crm--select-current-element)))
- (goto-char (overlay-end ol))
- (unwind-protect
- (catch 'exit
- (minibuffer-complete-and-exit)
- ;; This did not throw `exit', so there was a problem.
- (setq doexit nil))
- (goto-char (overlay-end ol))
- (delete-overlay ol))
- (not (eobp)))
+ (crm--completion-command beg end
+ (let ((end (copy-marker end t)))
+ (goto-char end)
+ (setq doexit nil)
+ (completion-complete-and-exit beg end
+ (lambda () (setq doexit t)))
+ (goto-char end)
+ (not (eobp))))
(looking-at crm-separator))
;; Skip to the next element.
(goto-char (match-end 0)))