From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.bugs Subject: bug#25777: 25.1; [PATCH] `rectangle--pos-cols' should not move point Date: Sun, 26 Feb 2017 22:24:59 -0800 (PST) Message-ID: References: <1efbacdb-7d86-454d-b0e0-7a783c47b804@default> <87poi4e7mv.fsf@users.sourceforge.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1488176778 13543 195.159.176.226 (27 Feb 2017 06:26:18 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 27 Feb 2017 06:26:18 +0000 (UTC) Cc: 25777@debbugs.gnu.org To: npostavs@users.sourceforge.net Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Feb 27 07:26:13 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ciEl8-0002fJ-QK for geb-bug-gnu-emacs@m.gmane.org; Mon, 27 Feb 2017 07:26:11 +0100 Original-Received: from localhost ([::1]:50652 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciElD-00005R-6b for geb-bug-gnu-emacs@m.gmane.org; Mon, 27 Feb 2017 01:26:15 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45775) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciEl5-00005J-Ty for bug-gnu-emacs@gnu.org; Mon, 27 Feb 2017 01:26:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciEl0-0007U8-Vb for bug-gnu-emacs@gnu.org; Mon, 27 Feb 2017 01:26:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:59241) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ciEl0-0007U4-SW for bug-gnu-emacs@gnu.org; Mon, 27 Feb 2017 01:26:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ciEl0-0006X2-KF for bug-gnu-emacs@gnu.org; Mon, 27 Feb 2017 01:26:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Drew Adams Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 27 Feb 2017 06:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25777 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 25777-submit@debbugs.gnu.org id=B25777.148817671525053 (code B ref 25777); Mon, 27 Feb 2017 06:26:02 +0000 Original-Received: (at 25777) by debbugs.gnu.org; 27 Feb 2017 06:25:15 +0000 Original-Received: from localhost ([127.0.0.1]:57440 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ciEkE-0006W1-Jb for submit@debbugs.gnu.org; Mon, 27 Feb 2017 01:25:14 -0500 Original-Received: from aserp1040.oracle.com ([141.146.126.69]:34778) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ciEkD-0006Vl-0l for 25777@debbugs.gnu.org; Mon, 27 Feb 2017 01:25:13 -0500 Original-Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v1R6P4i6010537 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Feb 2017 06:25:05 GMT Original-Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id v1R6P3RO029491 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 27 Feb 2017 06:25:04 GMT Original-Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id v1R6P1wP011621; Mon, 27 Feb 2017 06:25:02 GMT In-Reply-To: <87poi4e7mv.fsf@users.sourceforge.net> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 12.0.6753.5000 (x86)] X-Source-IP: userv0022.oracle.com [156.151.31.74] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.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" Xref: news.gmane.org gmane.emacs.bugs:129867 Archived-At: > > As I mentioned, this is a regression. I think the bug and the patch > > are pretty self-explanatory, but if you feel you need a recipe to > > show that this causes cursor movement then let me know. >=20 > Yes, an example would be useful. Perhaps it's the callers of > rectangle--pos-cols that should use save-excursion. I can certainly wrap all calls of `rectangle--pos-cols' with `save-excursion'. But that should not be necessary. There is no reason for that function to leave point moved. It's only aim in moving point is to do so temporarily. Point is moved in Emacs 25, and it was not moved before. It's a gratuitous regression. `rectangle--pos-cols' does not benefit in any way by leaving point moved. Anyway, thanks for looking at this. Here is a recipe. You can try to make it more minimal if you like, but it is pretty simple and it shows the problem easily enough. Download library `modeline-posn.el', from here: https://www.emacswiki.org/emacs/download/modeline-posn.el Evaluate these 3 variables: option `modelinepos-style' and defvars `modelinepos-region-acting-on' and `modelinepos-rect-p'. Evaluate this: (defadvice rectangle-mark-mode (after bind-modelinepos-region-acting-on activate) (setq modelinepos-region-acting-on rectangle-mark-mode modelinepos-rect-p rectangle-mark-mode) =20 (redisplay 'force)) And evaluate the setq-default sexp for `mode-line-position' (the one for Emacs > 22). In buffer *scratch*: M-x show-paren-mode RET M-x set-variable RET show-paren-style RET mixed RET Type this at the beginning of a line at the end of the buffer (in *scratch*): () RET () RET So you see this, with the cursor (_) at eob, i.e., after the final newline: () () _ Then do `C-x SPC C-p'. The cursor moves briefly up one line and then immediately jumps back to where mark was, at the end of the buffer. It should stay where `C-p' put it, on the second left paren. The problem seems to come from an error being raised in the context of the show-paren code. An easier way to repro it is to just load file modeline-posn.el and then do what I described starting with "In buffer *scratch:". In that case you will see the intended effect of the library when the region is active in `rectangle-mark-mode': The mode line says how many rows & columns are in the rectangular region. Of course, for the recipe the cursor will not move, but stays stuck at eob, so the mode line just reads "0 rows, 0 cols". Actually, you can see it briefly change to "1 rows, 0 cols" and then change back to "0 rows, 0 cols". To debug this, since I could not use the debugger (the code is initiated while updating the mode-line during redisplay), I had to just insert calls to `message' etc. I commented out parts of `modelinepos-style', to find the part that matters. Commenting out this, and replacing it by 999, prevents the problem: (let ((rpc (rectangle--pos-cols (region-beginning) (region-end)))) (abs (- (car rpc) (cdr rpc)))) I then replaced just the (abs...) with this: (message "RPC: %S" rpc) 999 That printed (0 . 0) for RPC, but the problem was reproduced. That told me that the problem came from just calling `rectangle--pos-cols'. Changing the above to just this removed the problem: (let ((rpc '(0 . 0))) (abs (- (car rpc) (cdr rpc)))) I checked the code of `rectangle--pos-cols' and saw that it now does `goto-char' (and it did not do so before Emacs 25.1). Wrapping it in `save-excursion' fixed the problem, without any negative effect on the function (it does not need point to remain moved). Such code should not gratuitously add cursor motion. Other `goto-char' calls were also added, in other parts of the same file, for Emacs 25. Perhaps the person who updated the code did not think about the consequence. Point is not moved by the code in order to leave it in a different place. It is changed only for a temporary effect. That point-moving code should be wrapped in `save-excursion'. My advice is to check the other such bare `goto-char' occurrences that were added in Emacs 25. I'm guessing that none of them need to leave point moved. Code should be able to call `rectangle--pos-cols' just for its value, without getting side effects like cursor movement. If `rectangle--pos-cols' needed, or intended, to leave point moved somewhere for some reason then yes, of course, any calling code that doesn't want that should be responsible for wrapping the calls with `save-excursion'. But that's not the case: There is no reason for the function to have the side effect of leaving point in a different position.