emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r115390: Add caching variant of `completion-table-dy


From: Dmitry Gutov
Subject: [Emacs-diffs] trunk r115390: Add caching variant of `completion-table-dynamic'
Date: Fri, 06 Dec 2013 00:48:59 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 115390
revision-id: address@hidden
parent: address@hidden
fixes bug: http://debbugs.gnu.org/11906
committer: Dmitry Gutov <address@hidden>
branch nick: trunk
timestamp: Fri 2013-12-06 02:48:52 +0200
message:
  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.
modified:
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/minibuffer.el             
minibuffer.el-20091113204419-o5vbwnq5f7feedwu-8622
  lisp/progmodes/octave.el       
octavemod.el-20091113204419-o5vbwnq5f7feedwu-1028
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-12-05 20:25:54 +0000
+++ b/lisp/ChangeLog    2013-12-06 00:48:52 +0000
@@ -1,3 +1,11 @@
+2013-12-06  Dmitry Gutov  <address@hidden>
+
+       * 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  <address@hidden>  (tiny change)
 
        * emacs-lisp/regexp-opt.el (regexp-opt-charset): Fix ^ (bug#16046).

=== modified file 'lisp/minibuffer.el'
--- a/lisp/minibuffer.el        2013-11-24 14:08:02 +0000
+++ b/lisp/minibuffer.el        2013-12-06 00:48:52 +0000
@@ -190,6 +190,24 @@
                                (current-buffer)))
         (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
+         (new-fun
+          (lambda (arg)
+            (if (and last-arg (string-prefix-p last-arg arg ignore-case))
+                last-result
+              (prog1
+                  (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

=== modified file 'lisp/progmodes/octave.el'
--- a/lisp/progmodes/octave.el  2013-12-02 07:13:01 +0000
+++ b/lisp/progmodes/octave.el  2013-12-06 00:48:52 +0000
@@ -838,21 +838,13 @@
     ;; `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 - http://debbugs.gnu.org/11906 - which may cause
-  ;; noticeable delay.  CACHE: (CMD . VALUE).
-  (let ((cache))
-    (completion-table-dynamic
-     (lambda (command)
-       (unless (equal (car cache) command)
-         (inferior-octave-send-list-and-digest
-          (list (format "completion_matches ('%s');\n" command)))
-         (setq cache (cons command
-                           (delete-consecutive-dups
-                            (sort inferior-octave-output-list 
'string-lessp)))))
-       (cdr cache)))))
+(defun inferior-octave-completion-table ()
+  (completion-table-with-cache
+   (lambda (command)
+     (inferior-octave-send-list-and-digest
+      (list (format "completion_matches ('%s');\n" command)))
+     (delete-consecutive-dups
+      (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 @@
           (end (point)))
       (when (and beg (> end beg))
         (list beg end (completion-table-in-turn
-                       inferior-octave-completion-table
+                       (inferior-octave-completion-table)
                        'comint-completion-file-name-table))))))
 
 (define-obsolete-function-alias 'inferior-octave-complete
@@ -1022,7 +1014,7 @@
     (completing-read
      (format (if def "Function (default %s): "
                "Function: ") def)
-     inferior-octave-completion-table
+     (inferior-octave-completion-table)
      nil nil nil nil def)))
 
 (defun octave-goto-function-definition (fn)
@@ -1406,7 +1398,7 @@
                         (setq end (point))))
     (when (> end beg)
       (list beg end (or (and (inferior-octave-process-live-p)
-                             inferior-octave-completion-table)
+                             (inferior-octave-completion-table))
                         octave-reserved-words)))))
 
 (define-obsolete-function-alias 'octave-complete-symbol


reply via email to

[Prev in Thread] Current Thread [Next in Thread]