From 0ff8e1ba6b4819aca0c95e15e2255908e3d276d3 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Fri, 27 May 2011 23:10:32 -0300 Subject: [PATCH] * lisp/minibuffer.el (completion--capf-wrapper): Check applicability before retuning non-nil for non-exclusive completion data. * lisp/progmodes/etags.el (tags-completion-at-point-function): * lisp/info-look.el (info-lookup-completions-at-point): Mark as non-exclusive. (info-complete): Adjust accordingly. * lisp/erc/erc-pcomplete.el (erc-pcompletions-at-point): Mark the completion data as non-exclusive if it's using the default-completion-function. (pcomplete-erc-parse-arguments): Rename pcomplete-parse-erc-arguments. (pcomplete-erc-setup): Use new name. --- lisp/ChangeLog | 7 +++++++ lisp/erc/ChangeLog | 7 +++++++ lisp/erc/erc-pcomplete.el | 9 ++++++--- lisp/info-look.el | 5 +++-- lisp/minibuffer.el | 31 ++++++++++++++++++++++++++----- lisp/progmodes/etags.el | 2 +- 6 files changed, 50 insertions(+), 11 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d2b495ae669..0b55fb4bba2 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,12 @@ 2011-05-28 Stefan Monnier + * minibuffer.el (completion--capf-wrapper): Check applicability before + retuning non-nil for non-exclusive completion data. + * progmodes/etags.el (tags-completion-at-point-function): + * info-look.el (info-lookup-completions-at-point): Mark as + non-exclusive. + (info-complete): Adjust accordingly. + * info-look.el: Convert to lexical-binding and completion-at-point. (info-lookup-completions-at-point): New function. (info-complete): Use it and completion-in-region. diff --git a/lisp/erc/ChangeLog b/lisp/erc/ChangeLog index 187d338c1bc..f1c0b2d1c65 100644 --- a/lisp/erc/ChangeLog +++ b/lisp/erc/ChangeLog @@ -1,3 +1,10 @@ +2011-05-28 Stefan Monnier + + * erc-pcomplete.el (erc-pcompletions-at-point): Mark the completion + data as non-exclusive if it's using the default-completion-function. + (pcomplete-erc-parse-arguments): Rename pcomplete-parse-erc-arguments. + (pcomplete-erc-setup): Use new name. + 2011-05-03 Debarshi Ray (tiny change) * erc-backend.el (671): New response handler. diff --git a/lisp/erc/erc-pcomplete.el b/lisp/erc/erc-pcomplete.el index eb1398d5b05..a390fcfe84d 100644 --- a/lisp/erc/erc-pcomplete.el +++ b/lisp/erc/erc-pcomplete.el @@ -73,7 +73,10 @@ the most recent speakers are listed first." "ERC completion data from pcomplete. for use on `completion-at-point-function'." (when (> (point) (erc-beg-of-input-line)) - (pcomplete-completions-at-point))) + (or (let ((pcomplete-default-completion-function #'ignore)) + (pcomplete-completions-at-point)) + (let ((c (pcomplete-completions-at-point))) + (if c (nconc c '(:exclusive no))))))) (defun erc-pcomplete () "Complete the nick before point." @@ -94,7 +97,7 @@ for use on `completion-at-point-function'." (set (make-local-variable 'pcomplete-use-paring) nil) (set (make-local-variable 'pcomplete-parse-arguments-function) - 'pcomplete-parse-erc-arguments) + 'pcomplete-erc-parse-arguments) (set (make-local-variable 'pcomplete-command-completion-function) 'pcomplete/erc-mode/complete-command) (set (make-local-variable 'pcomplete-command-name-function) @@ -254,7 +257,7 @@ If optional argument IGNORE-SELF is non-nil, don't return the current nick." (upcase (substring (pcomplete-arg 'first) 1)) "SAY")) -(defun pcomplete-parse-erc-arguments () +(defun pcomplete-erc-parse-arguments () "Returns a list of parsed whitespace-separated arguments. These are the words from the beginning of the line after the prompt up to where point is right now." diff --git a/lisp/info-look.el b/lisp/info-look.el index 26a89ca956e..2cfaa81d4c7 100644 --- a/lisp/info-look.el +++ b/lisp/info-look.el @@ -667,7 +667,8 @@ Return nil if there is nothing appropriate in the buffer near point." (end-of-line) (while (and (search-backward try nil t) (< start (point)))) - (list (match-beginning 0) (match-end 0) completions)))))))) + (list (match-beginning 0) (match-end 0) completions + :exclusive 'no)))))))) (defun info-complete (topic mode) "Try to complete a help item." @@ -675,7 +676,7 @@ Return nil if there is nothing appropriate in the buffer near point." (let ((data (info-lookup-completions-at-point topic mode))) (if (null data) (error "No %s completion available for `%s' at point" topic mode) - (apply #'completion-in-region data)))) + (completion-in-region (nth 0 data) (nth 1 data) (nth 2 data))))) ;;; Initialize some common modes. diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index f3d92b18722..7af602c629b 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -1433,12 +1433,19 @@ or a list of the form (START END COLLECTION &rest PROPS) where PROPS is a property list for additional information. Currently supported properties are all the properties that can appear in `completion-extra-properties' plus: - `:predicate' a predicate that completion candidates need to satisfy.") + `:predicate' a predicate that completion candidates need to satisfy. + `:exclusive' If `no', means that if the completion data does not match the + text at point failure, then instead of reporting a completion failure, + the completion should try the next completion function.") (defvar completion--capf-misbehave-funs nil - "List of functions found on `completion-at-point-functions' that misbehave.") + "List of functions found on `completion-at-point-functions' that misbehave. +These are functions that neither return completion data nor a completion +function but instead perform completion right away.") (defvar completion--capf-safe-funs nil - "List of well-behaved functions found on `completion-at-point-functions'.") + "List of well-behaved functions found on `completion-at-point-functions'. +These are functions which return proper completion data rather than +a completion function or god knows what else.") (defun completion--capf-wrapper (fun which) ;; FIXME: The safe/misbehave handling assumes that a given function will @@ -1451,9 +1458,23 @@ Currently supported properties are all the properties that can appear in (optimist (not (member fun completion--capf-misbehave-funs)))) (let ((res (funcall fun))) (cond - ((consp res) + ((and (consp res) (not (functionp res))) (unless (member fun completion--capf-safe-funs) - (push fun completion--capf-safe-funs))) + (push fun completion--capf-safe-funs)) + (and (eq 'no (plist-get (nthcdr 3 res) :exclusive)) + ;; FIXME: Here we'd need to decide whether there are + ;; valid completions against the current text. But this depends + ;; on the actual completion UI (e.g. with the default completion + ;; it depends on completion-style) ;-( + ;; We approximate this result by checking whether prefix + ;; completion might work, which means that non-prefix completion + ;; will not work (or not right) for completion functions that + ;; are non-exclusive. + (null (try-completion (buffer-substring-no-properties + (car res) (point)) + (nth 2 res) + (plist-get (nthcdr 3 res) :predicate))) + (setq res nil))) ((not (or (listp res) (functionp res))) (unless (member fun completion--capf-misbehave-funs) (message diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el index 6bd2de992cb..8abf298bb76 100644 --- a/lisp/progmodes/etags.el +++ b/lisp/progmodes/etags.el @@ -812,7 +812,7 @@ If no tags table is loaded, do nothing and return nil." (search-backward pattern) ;FIXME: will fail if we're inside pattern. (setq beg (point)) (forward-char (length pattern)) - (list beg (point) (tags-lazy-completion-table))))))) + (list beg (point) (tags-lazy-completion-table) :exclusive 'no)))))) (defun find-tag-tag (string) "Read a tag name, with defaulting and completion." -- 2.39.2