Commit 67982e2b authored by Stefan Monnier's avatar Stefan Monnier
Browse files

* 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.
parent e17d94a5
......@@ -172,6 +172,10 @@ You can pick the name of the function and the variables with `C-x 4 a'.
* Changes in Specialized Modes and Packages in Emacs 24.4
** Icomplete-mode by defaults applies to all forms of minibuffer completion.
(setq icomplete-with-completion-tables '(internal-complete-buffer))
will revert to the old behavior.
** The debugger's `e' command evaluates the code in the context at point.
This includes using the lexical environment at point, which means that
`e' now lets you access lexical variables as well.
......@@ -756,6 +760,11 @@ used in place of the 9th element of `file-attributes'.
`preserve-extended-attributes' as it now handles both SELinux context
and ACL entries.
** The `common-substring' argument of display-completion-list is obsolete.
Either use `completion-all-completions' which already returns highlighted
strings (including for partial or substring completion) or call
`completion-hilit-commonality' to add the highlight.
** Changes to the Emacs Lisp Coding Conventions in Emacs 24.4
*** The package descriptor and name of global variables, constants,
......
2013-09-06 Stefan Monnier <monnier@iro.umontreal.ca>
* 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'.
* 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.
* 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.
2013-09-06 Stefan Monnier <monnier@iro.umontreal.ca>
* dired-x.el (dired-mark-sexp): Bind the vars lexically rather
......
......@@ -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)))
......
......@@ -158,11 +158,13 @@ minibuffer completion.")
(add-hook 'icomplete-post-command-hook 'icomplete-exhibit)
;;;_ = icomplete-with-completion-tables
(defvar icomplete-with-completion-tables '(internal-complete-buffer)
(defcustom icomplete-with-completion-tables t
"Specialized completion tables with which icomplete should operate.
Icomplete does not operate with any specialized completion tables
except those on this list.")
except those on this list."
:type '(choice (const :tag "All" t)
(repeat function)))
(defvar icomplete-minibuffer-map
(let ((map (make-sparse-keymap)))
......@@ -177,24 +179,28 @@ except those on this list.")
Second entry becomes the first and can be selected with
`minibuffer-force-complete-and-exit'."
(interactive)
(let* ((comps (completion-all-sorted-completions))
(let* ((beg (minibuffer-prompt-end))
(end (point-max))
(comps (completion-all-sorted-completions beg end))
(last (last comps)))
(when comps
(setcdr last (cons (car comps) (cdr last)))
(completion--cache-all-sorted-completions (cdr comps)))))
(completion--cache-all-sorted-completions beg end (cdr comps)))))
(defun icomplete-backward-completions ()
"Step backward completions by one entry.
Last entry becomes the first and can be selected with
`minibuffer-force-complete-and-exit'."
(interactive)
(let* ((comps (completion-all-sorted-completions))
(let* ((beg (minibuffer-prompt-end))
(end (point-max))
(comps (completion-all-sorted-completions beg end))
(last-but-one (last comps 2))
(last (cdr last-but-one)))
(when (consp last) ; At least two elements in comps
(setcdr last-but-one (cdr last))
(push (car last) comps)
(completion--cache-all-sorted-completions comps))))
(completion--cache-all-sorted-completions beg end comps))))
;;;_ > icomplete-mode (&optional prefix)
;;;###autoload
......@@ -263,7 +269,8 @@ and `minibuffer-setup-hook'."
"Insert icomplete completions display.
Should be run via minibuffer `post-command-hook'. See `icomplete-mode'
and `minibuffer-setup-hook'."
(when (and icomplete-mode (icomplete-simple-completing-p))
(when (and icomplete-mode
(icomplete-simple-completing-p)) ;Shouldn't be necessary.
(save-excursion
(goto-char (point-max))
; Insert the match-status information:
......@@ -319,7 +326,8 @@ matches exist. \(Keybindings for uniquely matched commands
are exhibited within the square braces.)"
(let* ((md (completion--field-metadata (field-beginning)))
(comps (completion-all-sorted-completions))
(comps (completion-all-sorted-completions
(minibuffer-prompt-end) (point-max)))
(last (if (consp comps) (last comps)))
(base-size (cdr last))
(open-bracket (if require-match "(" "["))
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment