diff options
| author | Richard M. Stallman | 2003-06-30 10:33:52 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2003-06-30 10:33:52 +0000 |
| commit | dd929b41f1ad46e54a9767c84751223c8e9d1f8f (patch) | |
| tree | b188960c6d0d1b8b45f3b7894fad78cacec5b845 /lisp | |
| parent | 1f42cc71708966327adab4b64a9830de06b891a4 (diff) | |
| download | emacs-dd929b41f1ad46e54a9767c84751223c8e9d1f8f.tar.gz emacs-dd929b41f1ad46e54a9767c84751223c8e9d1f8f.zip | |
(lazy-completion-table, dynamic-completion-table): New macros.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/subr.el | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index 4f8003f4d01..31903a895a5 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -1778,6 +1778,43 @@ Value is what BODY returns." | |||
| 1778 | (save-current-buffer | 1778 | (save-current-buffer |
| 1779 | (set-buffer ,old-buffer) | 1779 | (set-buffer ,old-buffer) |
| 1780 | (set-syntax-table ,old-table)))))) | 1780 | (set-syntax-table ,old-table)))))) |
| 1781 | |||
| 1782 | (defmacro dynamic-completion-table (fun) | ||
| 1783 | "Use function FUN as a dynamic completion table. | ||
| 1784 | FUN is called with one argument, the string for which completion is required, | ||
| 1785 | and it should return an alist containing all the intended possible | ||
| 1786 | completions. This alist may be a full list of possible completions so that FUN | ||
| 1787 | can ignore the value of its argument. If completion is performed in the | ||
| 1788 | minibuffer, FUN will be called in the buffer from which the minibuffer was | ||
| 1789 | entered. `dynamic-completion-table' then computes the completion, see Info | ||
| 1790 | node `(elisp)Programmed Completion'." | ||
| 1791 | (let ((win (make-symbol "window")) | ||
| 1792 | (string (make-symbol "string")) | ||
| 1793 | (predicate (make-symbol "predicate")) | ||
| 1794 | (mode (make-symbol "mode"))) | ||
| 1795 | `(lambda (,string ,predicate ,mode) | ||
| 1796 | (with-current-buffer (let ((,win (minibuffer-selected-window))) | ||
| 1797 | (if (window-live-p ,win) (window-buffer ,win) | ||
| 1798 | (current-buffer))) | ||
| 1799 | (cond | ||
| 1800 | ((eq ,mode t) (all-completions ,string (,fun ,string) ,predicate)) | ||
| 1801 | ((not ,mode) (try-completion ,string (,fun ,string) ,predicate)) | ||
| 1802 | (t (test-completion ,string (,fun ,string) ,predicate))))))) | ||
| 1803 | |||
| 1804 | (defmacro lazy-completion-table (var fun &rest args) | ||
| 1805 | "Initialize variable VAR as a lazy completion table. | ||
| 1806 | If the completion table VAR is used for the first time (e.g., by passing VAR | ||
| 1807 | as an argument to `try-completion'), the function FUN is called with arguments | ||
| 1808 | ARGS. FUN must return the completion table that will be stored in VAR. If | ||
| 1809 | completion is requested in the minibuffer, FUN will be called in the buffer | ||
| 1810 | from which the minibuffer was entered. The return value of | ||
| 1811 | `lazy-completion-table' must be used to initialize the value of VAR." | ||
| 1812 | (let ((str (make-symbol "string"))) | ||
| 1813 | `(dynamic-completion-table | ||
| 1814 | (lambda (,str) | ||
| 1815 | (unless (listp ,var) | ||
| 1816 | (setq ,var (funcall ',fun ,@args))) | ||
| 1817 | ,var)))) | ||
| 1781 | 1818 | ||
| 1782 | ;;; Matching and substitution | 1819 | ;;; Matching and substitution |
| 1783 | 1820 | ||