From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Bob Nnamtrop Newsgroups: gmane.emacs.bugs Subject: bug#5805: 23.3 abbrev-insert needs a limited save-excursion Date: Thu, 7 Jul 2011 18:02:15 -0600 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1310083415 27549 80.91.229.12 (8 Jul 2011 00:03:35 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 8 Jul 2011 00:03:35 +0000 (UTC) Cc: 5805@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Jul 08 02:03:31 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QeyXZ-0007Zw-9m for geb-bug-gnu-emacs@m.gmane.org; Fri, 08 Jul 2011 02:03:29 +0200 Original-Received: from localhost ([::1]:40834 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QeyXY-0001qo-2F for geb-bug-gnu-emacs@m.gmane.org; Thu, 07 Jul 2011 20:03:28 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:41305) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QeyXC-0001pr-CY for bug-gnu-emacs@gnu.org; Thu, 07 Jul 2011 20:03:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QeyX9-0002hA-Mk for bug-gnu-emacs@gnu.org; Thu, 07 Jul 2011 20:03:05 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:55986) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QeyX9-0002h3-5T for bug-gnu-emacs@gnu.org; Thu, 07 Jul 2011 20:03:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1QeyX7-0000xT-TA; Thu, 07 Jul 2011 20:03:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Bob Nnamtrop Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 08 Jul 2011 00:03:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 5805 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 5805-submit@debbugs.gnu.org id=B5805.13100833443611 (code B ref 5805); Fri, 08 Jul 2011 00:03:01 +0000 Original-Received: (at 5805) by debbugs.gnu.org; 8 Jul 2011 00:02:24 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QeyWV-0000wC-D7 for submit@debbugs.gnu.org; Thu, 07 Jul 2011 20:02:24 -0400 Original-Received: from mail-vx0-f172.google.com ([209.85.220.172]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QeyWS-0000vw-W4 for 5805@debbugs.gnu.org; Thu, 07 Jul 2011 20:02:22 -0400 Original-Received: by vxi40 with SMTP id 40so1073323vxi.3 for <5805@debbugs.gnu.org>; Thu, 07 Jul 2011 17:02:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=xCVXv+Ekv1WDQ/G4OVbVZ+JimTBxpnHJR6MLmThJqCY=; b=bqq3GtCSjqfbMbNk5N9xeBTaFw60f1aSsKW+Nqt1Lku/YfycNsH8HUAVB7Z3R3j208 vsVzirRfdhTHQ922/kznLThpE4dwJxyhtzFVnA8wJe/r3fqEIVrKrtyBWIuwTNgUw+Bt rkbpPtf2lUmGyCjGhdHkCC6pdxa06lBk7yrts= Original-Received: by 10.52.108.231 with SMTP id hn7mr1964197vdb.283.1310083335248; Thu, 07 Jul 2011 17:02:15 -0700 (PDT) Original-Received: by 10.52.184.34 with HTTP; Thu, 7 Jul 2011 17:02:15 -0700 (PDT) In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Thu, 07 Jul 2011 20:03:01 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) 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:48226 Archived-At: On Thu, Jul 7, 2011 at 3:46 PM, Bob Nnamtrop wrote: > On Thu, Jul 7, 2011 at 2:59 PM, Stefan Monnier = wrote: >> tags 5805 patch >> thanks >> >>> I agree with the original poster that a save-excursion is needed in >>> abbrev-expand and by making its scope limited (see below) it will not >>> interfere with abbrevs that want to change point. The reason I find it >>> annoying the way it is now is that some modes (e.g., idlwave) use >>> abbrev's extensively to change keywords (e.g. capitalize them). These >>> are defined without the leading "\". So if I am any number of lines >>> with only whitespace below a keyword defined in this way (e.g. endfor) >>> and run expand-abbrev then the point moves even if no visible change >>> takes place. This is a VERY common occurrence for me since in viper >>> mode changing from insert to vi mode runs expand-abbrev! Placing the >>> save-excursion just around the part of abbrev-insert that actually >>> expands the abbrev fixes this problem and does not limit abbrev's from >>> moving the point (idlwave does this extensively as well and I've >>> tested that it is not impacted). >> >> Hmm... sounds like an interesting solution. =A0I'll take a closer look a= nd >> get back to you. =A0Thank you. >> >>> Here is the diff against the >>> abbrev.el in emacs 23.3 (note that whitespace not adjusted). >> >> Highly appreciated. >> >> >> =A0 =A0 =A0 =A0Stefan >> > > (SNIP) > The rule should be "if a space (or any other non-word character) would > not cause an abbrev to expand then exiting from viper insert state > should not cause an abbrev to expand". And vise-versa. This would fix > all the issues I have with abbrev. > (SNIP) Here are two patches that do what I explained above. I am new to elisp so be kind :-) Note that these apply against the trunk (sorry to be switching back of forth). I left in the save-excursion fix but it is not absolutely necessary at this point but I still think it is the right thing to do. Let me know what you think. Bob --- trunk/lisp/emulation/viper-cmd.el 2011-07-07 13:00:22.000000000 -0600 +++ local-fixes/lisp/emulation/viper-cmd.el 2011-07-07 17:45:14.000000000 -0600 @@ -617,7 +617,7 @@ (or (viper-overlay-p viper-replace-overlay) (viper-set-replace-overlay (point-min) (point-min))) (viper-hide-replace-overlay) - (if abbrev-mode (expand-abbrev)) + (if abbrev-mode (expand-abbrev t)) (if (and auto-fill-function (> (current-column) fill-column)) (funcall auto-fill-function)) ;; don't leave whitespace lines around --- trunk/lisp/abbrev.el 2011-07-07 13:00:22.000000000 -0600 +++ local-fixes/lisp/abbrev.el 2011-07-07 17:49:26.000000000 -0600 @@ -752,6 +752,7 @@ ;; If this abbrev has an expansion, delete the abbrev ;; and insert the expansion. (when (stringp (symbol-value abbrev)) + (save-excursion (goto-char wordstart) ;; Insert at beginning so that markers at the end (e.g. point) ;; are preserved. @@ -780,7 +781,7 @@ (skip-syntax-forward "^w" (1- end)) ;; Change just that. (upcase-initials-region (point) (1+ (point))) - (goto-char end)))))) + (goto-char end))))))) ;; Now point is at the end of the expansion and the beginning is ;; in last-abbrev-location. (when (symbol-function abbrev) @@ -804,16 +805,18 @@ a function that performs the abbrev expansion. It should return the abbrev symbol if expansion took place.") -(defun expand-abbrev () +(defun expand-abbrev (&optional strict) "Expand the abbrev before point, if there is an abbrev there. Effective when explicitly called even when `abbrev-mode' is nil. +If strict is t then point must be directly after then end of the +abbrev for the expansion to take place. (interactive) (run-hooks 'pre-abbrev-expand-hook) (with-wrapper-hook abbrev-expand-functions () (destructuring-bind (&optional sym name wordstart wordend) (abbrev--before-point) - (when sym + (when (and sym (or (not strict) (=3D wordend (point)))) (unless (or ;; executing-kbd-macro noninteractive (window-minibuffer-p (selected-window)))