Commit d92df117 authored by Stefan Monnier's avatar Stefan Monnier
Browse files

* lisp/minibuffer.el (completion--all-sorted-completions-location): New var.

(completion--cache-all-sorted-completions)
(completion--flush-all-sorted-completions): Use it.
(completion-in-region, completion-in-region--postch)
(completion-at-point, completion-help-at-point): Use markers in
completion-in-region--data.

Fixes: debbugs:12619
parent 9eadb1a9
2012-10-24 Stefan Monnier <monnier@iro.umontreal.ca>
* minibuffer.el (completion--all-sorted-completions-location): New var.
(completion--cache-all-sorted-completions)
(completion--flush-all-sorted-completions): Use it.
(completion-in-region, completion-in-region--postch)
(completion-at-point, completion-help-at-point): Use markers in
completion-in-region--data (bug#12619).
2012-10-23 Stefan Monnier <monnier@iro.umontreal.ca> 2012-10-23 Stefan Monnier <monnier@iro.umontreal.ca>
   
* progmodes/compile.el (compilation-start): Try to handle common * progmodes/compile.el (compilation-start): Try to handle common
......
...@@ -871,6 +871,7 @@ completion candidates than this number." ...@@ -871,6 +871,7 @@ completion candidates than this number."
(defvar completion-all-sorted-completions nil) (defvar completion-all-sorted-completions nil)
(make-variable-buffer-local 'completion-all-sorted-completions) (make-variable-buffer-local 'completion-all-sorted-completions)
(defvar-local completion--all-sorted-completions-location nil)
(defvar completion-cycling nil) (defvar completion-cycling nil)
(defvar completion-fail-discreetly nil (defvar completion-fail-discreetly nil
...@@ -1049,13 +1050,18 @@ scroll the window of possible completions." ...@@ -1049,13 +1050,18 @@ scroll the window of possible completions."
(defun completion--cache-all-sorted-completions (comps) (defun completion--cache-all-sorted-completions (comps)
(add-hook 'after-change-functions (add-hook 'after-change-functions
'completion--flush-all-sorted-completions nil t) 'completion--flush-all-sorted-completions nil t)
(setq completion--all-sorted-completions-location
(cons (copy-marker (field-beginning)) (copy-marker (field-end))))
(setq completion-all-sorted-completions comps)) (setq completion-all-sorted-completions comps))
(defun completion--flush-all-sorted-completions (&rest _ignore) (defun completion--flush-all-sorted-completions (&rest start end len)
(unless (and start end
(or (> start (cdr completion--all-sorted-completions-location))
(< end (car completion--all-sorted-completions-location))))
(remove-hook 'after-change-functions (remove-hook 'after-change-functions
'completion--flush-all-sorted-completions t) 'completion--flush-all-sorted-completions t)
(setq completion-cycling nil) (setq completion-cycling nil)
(setq completion-all-sorted-completions nil)) (setq completion-all-sorted-completions nil)))
(defun completion--metadata (string base md-at-point table pred) (defun completion--metadata (string base md-at-point table pred)
;; Like completion-metadata, but for the specific case of getting the ;; Like completion-metadata, but for the specific case of getting the
...@@ -1758,7 +1764,10 @@ exit." ...@@ -1758,7 +1764,10 @@ exit."
(when completion-in-region-mode-predicate (when completion-in-region-mode-predicate
(completion-in-region-mode 1) (completion-in-region-mode 1)
(setq completion-in-region--data (setq completion-in-region--data
(list (current-buffer) start end collection))) (list (if (markerp start) start (copy-marker start))
(copy-marker end) collection)))
;; FIXME: `minibuffer-complete' should call `completion-in-region' rather
;; than the other way around!
(unwind-protect (unwind-protect
(call-interactively 'minibuffer-complete) (call-interactively 'minibuffer-complete)
(delete-overlay ol))))) (delete-overlay ol)))))
...@@ -1782,12 +1791,12 @@ exit." ...@@ -1782,12 +1791,12 @@ exit."
(or unread-command-events ;Don't pop down the completions in the middle of (or unread-command-events ;Don't pop down the completions in the middle of
;mouse-drag-region/mouse-set-point. ;mouse-drag-region/mouse-set-point.
(and completion-in-region--data (and completion-in-region--data
(and (eq (car completion-in-region--data) (and (eq (marker-buffer (nth 0 completion-in-region--data))
(current-buffer)) (current-buffer))
(>= (point) (nth 1 completion-in-region--data)) (>= (point) (nth 0 completion-in-region--data))
(<= (point) (<= (point)
(save-excursion (save-excursion
(goto-char (nth 2 completion-in-region--data)) (goto-char (nth 1 completion-in-region--data))
(line-end-position))) (line-end-position)))
(funcall completion-in-region-mode--predicate))) (funcall completion-in-region-mode--predicate)))
(completion-in-region-mode -1))) (completion-in-region-mode -1)))
...@@ -1894,11 +1903,13 @@ The completion method is determined by `completion-at-point-functions'." ...@@ -1894,11 +1903,13 @@ The completion method is determined by `completion-at-point-functions'."
(pcase res (pcase res
(`(,_ . ,(and (pred functionp) f)) (funcall f)) (`(,_ . ,(and (pred functionp) f)) (funcall f))
(`(,hookfun . (,start ,end ,collection . ,plist)) (`(,hookfun . (,start ,end ,collection . ,plist))
(unless (markerp start) (setq start (copy-marker start)))
(let* ((completion-extra-properties plist) (let* ((completion-extra-properties plist)
(completion-in-region-mode-predicate (completion-in-region-mode-predicate
(lambda () (lambda ()
;; We're still in the same completion field. ;; We're still in the same completion field.
(eq (car-safe (funcall hookfun)) start)))) (let ((newstart (car-safe (funcall hookfun))))
(and newstart (= newstart start))))))
(completion-in-region start end collection (completion-in-region start end collection
(plist-get plist :predicate)))) (plist-get plist :predicate))))
;; Maybe completion already happened and the function returned t. ;; Maybe completion already happened and the function returned t.
...@@ -1915,13 +1926,15 @@ The completion method is determined by `completion-at-point-functions'." ...@@ -1915,13 +1926,15 @@ The completion method is determined by `completion-at-point-functions'."
(`(,_ . ,(and (pred functionp) f)) (`(,_ . ,(and (pred functionp) f))
(message "Don't know how to show completions for %S" f)) (message "Don't know how to show completions for %S" f))
(`(,hookfun . (,start ,end ,collection . ,plist)) (`(,hookfun . (,start ,end ,collection . ,plist))
(unless (markerp start) (setq start (copy-marker start)))
(let* ((minibuffer-completion-table collection) (let* ((minibuffer-completion-table collection)
(minibuffer-completion-predicate (plist-get plist :predicate)) (minibuffer-completion-predicate (plist-get plist :predicate))
(completion-extra-properties plist) (completion-extra-properties plist)
(completion-in-region-mode-predicate (completion-in-region-mode-predicate
(lambda () (lambda ()
;; We're still in the same completion field. ;; We're still in the same completion field.
(eq (car-safe (funcall hookfun)) start))) (let ((newstart (car-safe (funcall hookfun))))
(and newstart (= newstart start)))))
(ol (make-overlay start end nil nil t))) (ol (make-overlay start end nil nil t)))
;; FIXME: We should somehow (ab)use completion-in-region-function or ;; FIXME: We should somehow (ab)use completion-in-region-function or
;; introduce a corresponding hook (plus another for word-completion, ;; introduce a corresponding hook (plus another for word-completion,
...@@ -1930,7 +1943,7 @@ The completion method is determined by `completion-at-point-functions'." ...@@ -1930,7 +1943,7 @@ The completion method is determined by `completion-at-point-functions'."
(overlay-put ol 'priority 100) (overlay-put ol 'priority 100)
(completion-in-region-mode 1) (completion-in-region-mode 1)
(setq completion-in-region--data (setq completion-in-region--data
(list (current-buffer) start end collection)) (list start (copy-marker end) collection))
(unwind-protect (unwind-protect
(call-interactively 'minibuffer-completion-help) (call-interactively 'minibuffer-completion-help)
(delete-overlay ol)))) (delete-overlay ol))))
......
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