diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2008-04-11 22:28:02 +0000 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2008-04-11 22:28:02 +0000 |
commit | 21622c6d1045fc8c1ce909ffe9db980b79f3dd3a (patch) | |
tree | 16a3e964899bfcd71908a4f6f39c61cbd944087e /lisp/subr.el | |
parent | 629f618d69f177ff6b95483cc6232d6374cb4b0c (diff) | |
download | emacs-21622c6d1045fc8c1ce909ffe9db980b79f3dd3a.tar.gz |
* minibuffer.el (complete-with-action, lazy-completion-table):
Move from subr.el.
(apply-partially, completion-table-dynamic)
(completion-table-with-context, completion-table-with-terminator)
(completion-table-in-turn): New funs.
(completion--make-envvar-table, completion--embedded-envvar-table): New funs.
(read-file-name-internal): Use them.
(completion-setup-hook): Move from simple.el.
* subr.el (complete-with-action, lazy-completion-table):
* simple.el (completion-setup-hook): Move to minibuffer.el.
Diffstat (limited to 'lisp/subr.el')
-rw-r--r-- | lisp/subr.el | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index 17fe146aff6..d81dfae4575 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -2688,92 +2688,6 @@ The value returned is the value of the last form in BODY." (with-current-buffer ,old-buffer (set-case-table ,old-case-table)))))) -;;;; Constructing completion tables. - -(defun complete-with-action (action table string pred) - "Perform completion ACTION. -STRING is the string to complete. -TABLE is the completion table, which should not be a function. -PRED is a completion predicate. -ACTION can be one of nil, t or `lambda'." - ;; (assert (not (functionp table))) - (funcall - (cond - ((null action) 'try-completion) - ((eq action t) 'all-completions) - (t 'test-completion)) - string table pred)) - -(defmacro dynamic-completion-table (fun) - "Use function FUN as a dynamic completion table. -FUN is called with one argument, the string for which completion is required, -and it should return an alist containing all the intended possible -completions. This alist may be a full list of possible completions so that FUN -can ignore the value of its argument. If completion is performed in the -minibuffer, FUN will be called in the buffer from which the minibuffer was -entered. - -The result of the `dynamic-completion-table' form is a function -that can be used as the ALIST argument to `try-completion' and -`all-completion'. See Info node `(elisp)Programmed Completion'." - (declare (debug (lambda-expr))) - (let ((win (make-symbol "window")) - (string (make-symbol "string")) - (predicate (make-symbol "predicate")) - (mode (make-symbol "mode"))) - `(lambda (,string ,predicate ,mode) - (with-current-buffer (let ((,win (minibuffer-selected-window))) - (if (window-live-p ,win) (window-buffer ,win) - (current-buffer))) - (complete-with-action ,mode (,fun ,string) ,string ,predicate))))) - -(defmacro lazy-completion-table (var fun) - ;; We used to have `&rest args' where `args' were evaluated late (at the - ;; time of the call to `fun'), which was counter intuitive. But to get - ;; them to be evaluated early, we have to either use lexical-let (which is - ;; not available in subr.el) or use `(lambda (,str) ...) which prevents the use - ;; of lexical-let in the callers. - ;; So we just removed the argument. Callers can then simply use either of: - ;; (lazy-completion-table var (lambda () (fun x y))) - ;; or - ;; (lazy-completion-table var `(lambda () (fun ',x ',y))) - ;; or - ;; (lexical-let ((x x)) ((y y)) - ;; (lazy-completion-table var (lambda () (fun x y)))) - ;; depending on the behavior they want. - "Initialize variable VAR as a lazy completion table. -If the completion table VAR is used for the first time (e.g., by passing VAR -as an argument to `try-completion'), the function FUN is called with no -arguments. FUN must return the completion table that will be stored in VAR. -If completion is requested in the minibuffer, FUN will be called in the buffer -from which the minibuffer was entered. The return value of -`lazy-completion-table' must be used to initialize the value of VAR. - -You should give VAR a non-nil `risky-local-variable' property." - (declare (debug (symbol lambda-expr))) - (let ((str (make-symbol "string"))) - `(dynamic-completion-table - (lambda (,str) - (when (functionp ,var) - (setq ,var (,fun))) - ,var)))) - -(defmacro complete-in-turn (a b) - "Create a completion table that first tries completion in A and then in B. -A and B should not be costly (or side-effecting) expressions." - (declare (debug (def-form def-form))) - `(lambda (string predicate mode) - (cond - ((eq mode t) - (or (all-completions string ,a predicate) - (all-completions string ,b predicate))) - ((eq mode nil) - (or (try-completion string ,a predicate) - (try-completion string ,b predicate))) - (t - (or (test-completion string ,a predicate) - (test-completion string ,b predicate)))))) - ;;; Matching and match data. (defvar save-match-data-internal) |