From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jorgen Schaefer Newsgroups: gmane.emacs.bugs Subject: bug#12619: completion-at-point and changing buffer Date: Thu, 11 Oct 2012 20:19:25 +0200 Message-ID: <20121011201925.76b56a54@forcix.kollektiv-hamburg.de> References: <20121010213913.46dc940b@forcix.kollektiv-hamburg.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1349979970 31218 80.91.229.3 (11 Oct 2012 18:26:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 11 Oct 2012 18:26:10 +0000 (UTC) Cc: 12619@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Oct 11 20:26:16 2012 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 1TMNSZ-0006F9-Rh for geb-bug-gnu-emacs@m.gmane.org; Thu, 11 Oct 2012 20:26:16 +0200 Original-Received: from localhost ([::1]:57572 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TMNST-0004fQ-9U for geb-bug-gnu-emacs@m.gmane.org; Thu, 11 Oct 2012 14:26:09 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:35265) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TMNSR-0004eW-4A for bug-gnu-emacs@gnu.org; Thu, 11 Oct 2012 14:26:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TMNSP-0004yN-PK for bug-gnu-emacs@gnu.org; Thu, 11 Oct 2012 14:26:07 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:57824) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TMNMo-0002RB-EQ for bug-gnu-emacs@gnu.org; Thu, 11 Oct 2012 14:20:18 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1TMNNW-00010H-61 for bug-gnu-emacs@gnu.org; Thu, 11 Oct 2012 14:21:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jorgen Schaefer Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 11 Oct 2012 18:21:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 12619 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 12619-submit@debbugs.gnu.org id=B12619.13499796173802 (code B ref 12619); Thu, 11 Oct 2012 18:21:02 +0000 Original-Received: (at 12619) by debbugs.gnu.org; 11 Oct 2012 18:20:17 +0000 Original-Received: from localhost ([127.0.0.1]:39842 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TMNMn-0000zH-4e for submit@debbugs.gnu.org; Thu, 11 Oct 2012 14:20:17 -0400 Original-Received: from istinn.electusmatari.com ([83.169.37.145]:44498) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TMNMj-0000z7-ST for 12619@debbugs.gnu.org; Thu, 11 Oct 2012 14:20:15 -0400 Original-Received: from forcix.kollektiv-hamburg.de (hmbg-5f77d9d0.pool.mediaWays.net [95.119.217.208]) by istinn.electusmatari.com (Postfix) with ESMTPSA id 0077FD10037E; Thu, 11 Oct 2012 20:19:26 +0200 (CEST) In-Reply-To: X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; i486-pc-linux-gnu) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) 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:65493 Archived-At: On Wed, 10 Oct 2012 20:37:42 -0400 Stefan Monnier wrote: > > First, in `completion-at-point', > > `completion-in-region-mode-predicate' is set to a function that > > compares the old start value with the new using `eq'. This prevents > > markers to work in this case. Simply replacing `eq' with `=' means > > markers work, so the positions used by completion just move > > together with text changes. > > Sounds OK, tho we should make sure that those values can't be nil > or some other non-numeric thingy. True, I think some of those values can be nil in some cases (didn't happen during my testing, though). Pity that neither `eql' nor `equal' work on markers. > > Second, `completion--cache-all-sorted-completions' adds a function > > to `after-change-functions' that cleans up the cache of sorted > > completions. I'm not entirely sure why it does so, but my patch adds > > that function only if not both of the returned positions are > > markers. > > Hmm...but if the buffer modification happens right in the middle of > the completion text what should we do? Should we really ignore > this modification? Actually, I have no idea what would happen then and couldn't make a test case to reproduce it easily. :-) The patch below flushes the cache if the changed text intersects with the completion text. --- lisp/minibuffer.el 2012-10-06 17:29:15 +0000 +++ lisp/minibuffer.el 2012-10-11 17:56:42 +0000 @@ -1048,12 +1048,29 @@ (defun completion--cache-all-sorted-completions (comps) (add-hook 'after-change-functions - 'completion--flush-all-sorted-completions nil t) + 'completion--flush-all-sorted-completions-after-change nil t) (setq completion-all-sorted-completions comps)) -(defun completion--flush-all-sorted-completions (&rest _ignore) +(defun completion--flush-all-sorted-completions-after-change (change-start change-end pre-change-length) + (let ((start (nth 1 completion-in-region--data)) + (end (nth 2 completion-in-region--data))) + (when (or + ;; We don't even have completion data + (not start) + (not end) + ;; Change completely before our completion, but our + ;; completion didn't use markers. + (and (<= change-end start) + (not (and (markerp start) + (markerp end)))) + ;; Change overlaps our completion, regardless of markers. + (not (or (< change-end start) + (< end change-start)))) + (completion--flush-all-sorted-completions)))) + +(defun completion--flush-all-sorted-completions () (remove-hook 'after-change-functions - 'completion--flush-all-sorted-completions t) + 'completion--flush-all-sorted-completions-after-change t) (setq completion-cycling nil) (setq completion-all-sorted-completions nil)) @@ -1882,8 +1899,12 @@ (let* ((completion-extra-properties plist) (completion-in-region-mode-predicate (lambda () - ;; We're still in the same completion field. - (eq (car-safe (funcall hookfun)) start)))) + (let ((old-start (car-safe (funcall hookfun)))) + ;; We're still in the same completion field. + (condition-case error + (= old-start start) + (error + (eq old-start start))))))) (completion-in-region start end collection (plist-get plist :predicate)))) ;; Maybe completion already happened and the function returned t. (I have no idea at what point patches are considered non-trivial for copyright reasons, but there should be an assignment "for all future contributions to Emacs" with the FSF.) Regards, -- Jorgen