unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dgutov@yandex.ru>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Leo Liu <sdl.web@gmail.com>, 11906@debbugs.gnu.org
Subject: bug#11906: 24.1; completion-at-point failures
Date: Thu, 05 Dec 2013 05:23:37 +0200	[thread overview]
Message-ID: <87pppcasli.fsf@yandex.ru> (raw)
In-Reply-To: <jwv8v36kf3y.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Wed, 22 May 2013 15:16:01 -0400")

[-- Attachment #1: Type: text/plain, Size: 405 bytes --]

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> Probably, yes.  It would turn test-completion and try-completion into
> calls to all-completions and then cache one "arg+result" of
> all-completions (this pair would be sufficient to cover all calls to
> test/try/all-completion for any argument string which has `arg' as its
> prefix).

How does this patch look?

(The Octave part is 100% untested).


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: completion-table-with-cache.diff --]
[-- Type: text/x-diff, Size: 3729 bytes --]

=== modified file 'lisp/minibuffer.el'
--- lisp/minibuffer.el	2013-11-24 14:08:02 +0000
+++ lisp/minibuffer.el	2013-12-05 03:22:09 +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'
--- lisp/progmodes/octave.el	2013-12-02 07:13:01 +0000
+++ lisp/progmodes/octave.el	2013-12-05 03:15:06 +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	other threads:[~2013-12-05  3:23 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-11  5:54 bug#11906: 24.1; completion-at-point failures Leo
2012-07-12 14:00 ` Stefan Monnier
2013-05-10  6:38   ` Leo Liu
2013-05-10 20:36     ` Stefan Monnier
2013-05-11  1:50       ` Leo Liu
2013-05-11  3:40         ` Stefan Monnier
2013-05-11  4:47           ` Leo Liu
2013-05-11 14:51             ` Stefan Monnier
2013-05-13  1:28               ` Leo Liu
2013-05-13 15:27                 ` Stefan Monnier
2013-05-14  0:56                   ` Leo Liu
2013-05-14  2:53                     ` Stefan Monnier
2013-05-14  3:30                       ` Leo Liu
2013-05-11 20:18             ` Andreas Röhler
2013-05-11 23:11           ` Daimrod
2013-05-13 15:28             ` Stefan Monnier
2013-05-21 23:39           ` Dmitry Gutov
2013-05-22 19:16             ` Stefan Monnier
2013-12-05  3:23               ` Dmitry Gutov [this message]
2013-12-05  4:33                 ` Stefan Monnier
2013-12-06  1:02                   ` Dmitry Gutov
2013-12-06  4:00                     ` Leo Liu
2013-12-06  4:32                       ` Dmitry Gutov
2013-12-06  5:36                         ` Leo Liu
2013-12-06 13:15                           ` Dmitry Gutov
2013-12-06 14:04                             ` Leo Liu
2013-12-06 17:35                               ` Stefan Monnier
2013-12-07  2:05                                 ` Leo Liu
2013-12-07 22:45                                   ` Stefan Monnier
2013-12-06 17:36                               ` Stefan Monnier
2013-12-07  2:02                               ` Dmitry Gutov
2013-12-07  2:40                                 ` Leo Liu
2013-12-07 16:13                                   ` Dmitry Gutov
2013-12-09  2:27                                     ` Leo Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87pppcasli.fsf@yandex.ru \
    --to=dgutov@yandex.ru \
    --cc=11906@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=sdl.web@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).