From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#11906: 24.1; completion-at-point failures Date: Thu, 05 Dec 2013 05:23:37 +0200 Message-ID: <87pppcasli.fsf@yandex.ru> References: <87li776gym.fsf@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1386213858 30753 80.91.229.3 (5 Dec 2013 03:24:18 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 5 Dec 2013 03:24:18 +0000 (UTC) Cc: Leo Liu , 11906@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Dec 05 04:24:21 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VoPY4-00075d-9S for geb-bug-gnu-emacs@m.gmane.org; Thu, 05 Dec 2013 04:24:20 +0100 Original-Received: from localhost ([::1]:51584 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VoPY3-0003Sb-Bw for geb-bug-gnu-emacs@m.gmane.org; Wed, 04 Dec 2013 22:24:19 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57450) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VoPXr-0003Fv-UI for bug-gnu-emacs@gnu.org; Wed, 04 Dec 2013 22:24:13 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VoPXm-0001eM-LV for bug-gnu-emacs@gnu.org; Wed, 04 Dec 2013 22:24:07 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:44672) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VoPXm-0001e8-HN for bug-gnu-emacs@gnu.org; Wed, 04 Dec 2013 22:24:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1VoPXm-0003eh-A7 for bug-gnu-emacs@gnu.org; Wed, 04 Dec 2013 22:24:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 05 Dec 2013 03:24:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 11906 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 11906-submit@debbugs.gnu.org id=B11906.138621383014027 (code B ref 11906); Thu, 05 Dec 2013 03:24:02 +0000 Original-Received: (at 11906) by debbugs.gnu.org; 5 Dec 2013 03:23:50 +0000 Original-Received: from localhost ([127.0.0.1]:58691 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VoPXZ-0003eB-NI for submit@debbugs.gnu.org; Wed, 04 Dec 2013 22:23:50 -0500 Original-Received: from mail-ea0-f171.google.com ([209.85.215.171]:52748) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VoPXW-0003e0-FK for 11906@debbugs.gnu.org; Wed, 04 Dec 2013 22:23:47 -0500 Original-Received: by mail-ea0-f171.google.com with SMTP id h10so11086853eak.16 for <11906@debbugs.gnu.org>; Wed, 04 Dec 2013 19:23:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=SrcKdBBaaeOqLgupWYnR00/q+dUGnNMSEAtcGjpU9O4=; b=rOklNRWfeohaUu7dj0etkeRDB9XC1fqZUsQ7f4LGedct9zZY6Zdi1lRxT8KCFEFfUn iSKFP8XL9cKA5CE3ArsknDaHotkYcsDRrq5jMryb9g8fw4ZAV6perlCMizt9QtSxnKjP 29pTxV5c37yzTAjjy8+upMOfo7BQjRhLDew99hsNpzp0OiUkGuwcU6xBA00EfU670rd6 Ful6c7djlmRn2mkC3fmMydi2HdpRC4zrusi0g+va7owQ2KPmzYmfONN4n2r0VVxuhPqL fp/TIKd/qMu2I90HAU9117IHD4Ma3KRQXwu6lINbz1Dv29AqKgdMf8iwjK/fkTPey1yX KO1Q== X-Received: by 10.14.119.136 with SMTP id n8mr10041131eeh.82.1386213825409; Wed, 04 Dec 2013 19:23:45 -0800 (PST) Original-Received: from axl ([62.228.136.233]) by mx.google.com with ESMTPSA id p45sm11039711eeg.1.2013.12.04.19.23.43 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 04 Dec 2013 19:23:44 -0800 (PST) In-Reply-To: (Stefan Monnier's message of "Wed, 22 May 2013 15:16:01 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:81413 Archived-At: --=-=-= Content-Type: text/plain Stefan Monnier 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). --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=completion-table-with-cache.diff === 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 --=-=-=--