diff options
| author | Dmitry Gutov | 2013-12-06 02:48:52 +0200 |
|---|---|---|
| committer | Dmitry Gutov | 2013-12-06 02:48:52 +0200 |
| commit | 16588fadd0bf0b0a19a3ccc279944ed0220b915c (patch) | |
| tree | 08bb32f7c6b7c59c83ffc8bf904df5a5e966706b | |
| parent | bf4906d7ca3833f11f929d0feae0feb622131604 (diff) | |
| download | emacs-16588fadd0bf0b0a19a3ccc279944ed0220b915c.tar.gz emacs-16588fadd0bf0b0a19a3ccc279944ed0220b915c.zip | |
Add caching variant of `completion-table-dynamic'
* lisp/minibuffer.el (completion-table-with-cache): New function.
* lisp/progmodes/octave.el (inferior-octave-completion-table): Turn
back into function, use `completion-table-with-cache'. Update all
references.
Fixes: debbugs:11906
| -rw-r--r-- | lisp/ChangeLog | 8 | ||||
| -rw-r--r-- | lisp/minibuffer.el | 18 | ||||
| -rw-r--r-- | lisp/progmodes/octave.el | 28 |
3 files changed, 36 insertions, 18 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a8c3f273a4b..27a7e75ccef 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2013-12-06 Dmitry Gutov <dgutov@yandex.ru> | ||
| 2 | |||
| 3 | * progmodes/octave.el (inferior-octave-completion-table): Turn | ||
| 4 | back into function, use `completion-table-with-cache' | ||
| 5 | (Bug#11906). Update all references. | ||
| 6 | |||
| 7 | * minibuffer.el (completion-table-with-cache): New function. | ||
| 8 | |||
| 1 | 2013-12-05 Cameron Desautels <camdez@gmail.com> (tiny change) | 9 | 2013-12-05 Cameron Desautels <camdez@gmail.com> (tiny change) |
| 2 | 10 | ||
| 3 | * emacs-lisp/regexp-opt.el (regexp-opt-charset): Fix ^ (bug#16046). | 11 | * emacs-lisp/regexp-opt.el (regexp-opt-charset): Fix ^ (bug#16046). |
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 4f445855739..178f87c768b 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el | |||
| @@ -190,6 +190,24 @@ that can be used as the COLLECTION argument to `try-completion' and | |||
| 190 | (current-buffer))) | 190 | (current-buffer))) |
| 191 | (complete-with-action action (funcall fun string) string pred))))) | 191 | (complete-with-action action (funcall fun string) string pred))))) |
| 192 | 192 | ||
| 193 | (defun completion-table-with-cache (fun &optional ignore-case) | ||
| 194 | "Create dynamic completion table from FUN, with cache. | ||
| 195 | This wraps `completion-table-dynamic', but saves the last | ||
| 196 | argument-result pair from FUN, so that several lookups with the | ||
| 197 | same argument (or with an argument that starts with the first one) | ||
| 198 | only need to call FUN once. Most useful when FUN performs a relatively | ||
| 199 | slow operation, such as calling an external process (see Bug#11906). | ||
| 200 | When IGNORE-CASE is non-nil, FUN is expected to be case-insensitive." | ||
| 201 | (let* (last-arg last-result | ||
| 202 | (new-fun | ||
| 203 | (lambda (arg) | ||
| 204 | (if (and last-arg (string-prefix-p last-arg arg ignore-case)) | ||
| 205 | last-result | ||
| 206 | (prog1 | ||
| 207 | (setq last-result (funcall fun arg)) | ||
| 208 | (setq last-arg arg)))))) | ||
| 209 | (completion-table-dynamic new-fun))) | ||
| 210 | |||
| 193 | (defmacro lazy-completion-table (var fun) | 211 | (defmacro lazy-completion-table (var fun) |
| 194 | "Initialize variable VAR as a lazy completion table. | 212 | "Initialize variable VAR as a lazy completion table. |
| 195 | If the completion table VAR is used for the first time (e.g., by passing VAR | 213 | If the completion table VAR is used for the first time (e.g., by passing VAR |
diff --git a/lisp/progmodes/octave.el b/lisp/progmodes/octave.el index 7b9d7c97f85..4246b46e238 100644 --- a/lisp/progmodes/octave.el +++ b/lisp/progmodes/octave.el | |||
| @@ -838,21 +838,13 @@ startup file, `~/.emacs-octave'." | |||
| 838 | ;; `comint-history-isearch-backward-regexp'. Bug#14433. | 838 | ;; `comint-history-isearch-backward-regexp'. Bug#14433. |
| 839 | (comint-send-string proc "\n"))) | 839 | (comint-send-string proc "\n"))) |
| 840 | 840 | ||
| 841 | (defvar inferior-octave-completion-table | 841 | (defun inferior-octave-completion-table () |
| 842 | ;; | 842 | (completion-table-with-cache |
| 843 | ;; Use cache to avoid repetitive computation of completions due to | 843 | (lambda (command) |
| 844 | ;; bug#11906 - http://debbugs.gnu.org/11906 - which may cause | 844 | (inferior-octave-send-list-and-digest |
| 845 | ;; noticeable delay. CACHE: (CMD . VALUE). | 845 | (list (format "completion_matches ('%s');\n" command))) |
| 846 | (let ((cache)) | 846 | (delete-consecutive-dups |
| 847 | (completion-table-dynamic | 847 | (sort inferior-octave-output-list 'string-lessp))))) |
| 848 | (lambda (command) | ||
| 849 | (unless (equal (car cache) command) | ||
| 850 | (inferior-octave-send-list-and-digest | ||
| 851 | (list (format "completion_matches ('%s');\n" command))) | ||
| 852 | (setq cache (cons command | ||
| 853 | (delete-consecutive-dups | ||
| 854 | (sort inferior-octave-output-list 'string-lessp))))) | ||
| 855 | (cdr cache))))) | ||
| 856 | 848 | ||
| 857 | (defun inferior-octave-completion-at-point () | 849 | (defun inferior-octave-completion-at-point () |
| 858 | "Return the data to complete the Octave symbol at point." | 850 | "Return the data to complete the Octave symbol at point." |
| @@ -864,7 +856,7 @@ startup file, `~/.emacs-octave'." | |||
| 864 | (end (point))) | 856 | (end (point))) |
| 865 | (when (and beg (> end beg)) | 857 | (when (and beg (> end beg)) |
| 866 | (list beg end (completion-table-in-turn | 858 | (list beg end (completion-table-in-turn |
| 867 | inferior-octave-completion-table | 859 | (inferior-octave-completion-table) |
| 868 | 'comint-completion-file-name-table)))))) | 860 | 'comint-completion-file-name-table)))))) |
| 869 | 861 | ||
| 870 | (define-obsolete-function-alias 'inferior-octave-complete | 862 | (define-obsolete-function-alias 'inferior-octave-complete |
| @@ -1022,7 +1014,7 @@ directory and makes this the current buffer's default directory." | |||
| 1022 | (completing-read | 1014 | (completing-read |
| 1023 | (format (if def "Function (default %s): " | 1015 | (format (if def "Function (default %s): " |
| 1024 | "Function: ") def) | 1016 | "Function: ") def) |
| 1025 | inferior-octave-completion-table | 1017 | (inferior-octave-completion-table) |
| 1026 | nil nil nil nil def))) | 1018 | nil nil nil nil def))) |
| 1027 | 1019 | ||
| 1028 | (defun octave-goto-function-definition (fn) | 1020 | (defun octave-goto-function-definition (fn) |
| @@ -1406,7 +1398,7 @@ The block marked is the one that contains point or follows point." | |||
| 1406 | (setq end (point)))) | 1398 | (setq end (point)))) |
| 1407 | (when (> end beg) | 1399 | (when (> end beg) |
| 1408 | (list beg end (or (and (inferior-octave-process-live-p) | 1400 | (list beg end (or (and (inferior-octave-process-live-p) |
| 1409 | inferior-octave-completion-table) | 1401 | (inferior-octave-completion-table)) |
| 1410 | octave-reserved-words))))) | 1402 | octave-reserved-words))))) |
| 1411 | 1403 | ||
| 1412 | (define-obsolete-function-alias 'octave-complete-symbol | 1404 | (define-obsolete-function-alias 'octave-complete-symbol |