1778 |
(save-current-buffer |
(save-current-buffer |
1779 |
(set-buffer ,old-buffer) |
(set-buffer ,old-buffer) |
1780 |
(set-syntax-table ,old-table)))))) |
(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)))) |
1818 |
|
|
1819 |
;;; Matching and substitution |
;;; Matching and substitution |
1820 |
|
|