Commit 16588fad authored by Dmitry Gutov's avatar Dmitry Gutov
Browse files

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

Fixes: debbugs:11906
parent bf4906d7
2013-12-06 Dmitry Gutov <>
* progmodes/octave.el (inferior-octave-completion-table): Turn
back into function, use `completion-table-with-cache'
(Bug#11906). Update all references.
* minibuffer.el (completion-table-with-cache): New function.
2013-12-05 Cameron Desautels <> (tiny change)
* emacs-lisp/regexp-opt.el (regexp-opt-charset): Fix ^ (bug#16046).
......@@ -190,6 +190,24 @@ that can be used as the COLLECTION argument to `try-completion' and
(complete-with-action action (funcall fun string) string pred)))))
(defun completion-table-with-cache (fun &optional ignore-case)
"Create dynamic completion table from FUN, with cache.
This wraps `completion-table-dynamic', but saves the last
argument-result pair from FUN, so that several lookups with the
same argument (or with an argument that starts with the first one)
only need to call FUN once. Most useful when FUN performs a relatively
slow operation, such as calling an external process (see Bug#11906).
When IGNORE-CASE is non-nil, FUN is expected to be case-insensitive."
(let* (last-arg last-result
(lambda (arg)
(if (and last-arg (string-prefix-p last-arg arg ignore-case))
(setq last-result (funcall fun arg))
(setq last-arg arg))))))
(completion-table-dynamic new-fun)))
(defmacro lazy-completion-table (var fun)
"Initialize variable VAR as a lazy completion table.
If the completion table VAR is used for the first time (e.g., by passing VAR
......@@ -838,21 +838,13 @@ startup file, `~/.emacs-octave'."
;; `comint-history-isearch-backward-regexp'. Bug#14433.
(comint-send-string proc "\n")))
(defvar inferior-octave-completion-table
;; Use cache to avoid repetitive computation of completions due to
;; bug#11906 - - which may cause
;; noticeable delay. CACHE: (CMD . VALUE).
(let ((cache))
(lambda (command)
(unless (equal (car cache) command)
(list (format "completion_matches ('%s');\n" command)))
(setq cache (cons command
(sort inferior-octave-output-list 'string-lessp)))))
(cdr cache)))))
(defun inferior-octave-completion-table ()
(lambda (command)
(list (format "completion_matches ('%s');\n" command)))
(sort inferior-octave-output-list 'string-lessp)))))
(defun inferior-octave-completion-at-point ()
"Return the data to complete the Octave symbol at point."
......@@ -864,7 +856,7 @@ startup file, `~/.emacs-octave'."
(end (point)))
(when (and beg (> end beg))
(list beg end (completion-table-in-turn
(define-obsolete-function-alias 'inferior-octave-complete
......@@ -1022,7 +1014,7 @@ directory and makes this the current buffer's default directory."
(format (if def "Function (default %s): "
"Function: ") def)
nil nil nil nil def)))
(defun octave-goto-function-definition (fn)
......@@ -1406,7 +1398,7 @@ The block marked is the one that contains point or follows point."
(setq end (point))))
(when (> end beg)
(list beg end (or (and (inferior-octave-process-live-p)
(define-obsolete-function-alias 'octave-complete-symbol
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment