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: Fri, 3 Mar 2017 11:17:15 -0800 (PST) Message-ID: <55d34807-bfb8-4543-842b-220af90d5557@default> References: <1efbacdb-7d86-454d-b0e0-7a783c47b804@default> <87poi4e7mv.fsf@users.sourceforge.net> <877f4beok7.fsf@users.sourceforge.net> <87tw7edi9d.fsf@users.sourceforge.net> <512a3db8-49d0-4802-aecc-2d71049e0b25@default> <87zih4bhhz.fsf@users.sourceforge.net> <2560c8d7-532e-4882-b3d4-3845312d218f@default> <8737evaz7b.fsf@users.sourceforge.net> <9d559ea2-b66f-4b05-9b95-243651239e13@default> <87zih2a3qg.fsf@users.sourceforge.net> <2b01eb6e-53b3-4ca1-abe9-ef3090981863@default> 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 1488568701 24790 195.159.176.226 (3 Mar 2017 19:18:21 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 3 Mar 2017 19:18:21 +0000 (UTC) Cc: 25777@debbugs.gnu.org To: Noam Postavsky Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Mar 03 20:18:17 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 1cjsiO-00053k-KY for geb-bug-gnu-emacs@m.gmane.org; Fri, 03 Mar 2017 20:18:08 +0100 Original-Received: from localhost ([::1]:59842 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjsiU-0002NU-Oj for geb-bug-gnu-emacs@m.gmane.org; Fri, 03 Mar 2017 14:18:14 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48504) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjsiL-0002MO-8f for bug-gnu-emacs@gnu.org; Fri, 03 Mar 2017 14:18:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cjsiI-000625-29 for bug-gnu-emacs@gnu.org; Fri, 03 Mar 2017 14:18:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:40586) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cjsiH-00061y-UR for bug-gnu-emacs@gnu.org; Fri, 03 Mar 2017 14:18:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cjsiH-0006za-JZ for bug-gnu-emacs@gnu.org; Fri, 03 Mar 2017 14:18:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Drew Adams Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 03 Mar 2017 19:18:01 +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: Original-Received: via spool by 25777-submit@debbugs.gnu.org id=B25777.148856864726835 (code B ref 25777); Fri, 03 Mar 2017 19:18:01 +0000 Original-Received: (at 25777) by debbugs.gnu.org; 3 Mar 2017 19:17:27 +0000 Original-Received: from localhost ([127.0.0.1]:38785 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cjshi-0006yl-OS for submit@debbugs.gnu.org; Fri, 03 Mar 2017 14:17:26 -0500 Original-Received: from userp1040.oracle.com ([156.151.31.81]:41259) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cjshh-0006yY-9Q for 25777@debbugs.gnu.org; Fri, 03 Mar 2017 14:17:25 -0500 Original-Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v23JHIHV006060 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 3 Mar 2017 19:17:19 GMT Original-Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id v23JHHVo027352 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 3 Mar 2017 19:17:18 GMT Original-Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id v23JHGvx017001; Fri, 3 Mar 2017 19:17:17 GMT In-Reply-To: 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: aserv0022.oracle.com [141.146.126.234] 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:130128 Archived-At: > Ah, with this hint I figured out what the user-visible side-effect is, > from 'emacs -Q' do: >=20 > C-x SPC > C-3 C-p M-f ;; the bottom 2 lines of the rectangle now extend past eol > C-x C-x ;; point is now past eol > M-: (save-excursion (rectangle--pos-cols 1 3)) RET ;; =3D> (0 . 2) > C-f ;; Now point jumps to column 1 instead of 8. Thanks. Yes, I see that. Except that even though point is in column 1, M-: (current-column) says it is in column 0 (should it?). > So calling rectangle--pos-cols with START and END not corresponding to > the current rectangle can mess with the selection. (I call it only with START and END for the selection, i.e., the active region.) > > The use case I have, in `modeline-posn.el', is about the > > rectangular region. It tries to report on displayed > > columns, not buffer positions. So I think that for my > > use case, at least, I need the full-blown > > `rectangle--pos-cols' code (under whatever name). >=20 > Perhaps you want this: >=20 > (defun rectangle-columns () > "Return the current rectangle's columns. > The return value is a cons of the form (START-COLUMN . END-COLUMN)." > (save-excursion > (rectangle--pos-cols (region-beginning) (region-end)))) (save-excursion (rectangle--pos-cols (region-beginning) (region-end))) is indeed what I use. > Which should call rectangle--pos-cols only with positions > corresponding to the current rectangle, and so won't be able to affect > the selection (I think?). That makes sense. But I don't think that is what a function called `rectangle-columns' should do. What you show is a function that is better called something like `rectangle-region-columns', and its doc string would need to say that it returns the columns for the region. And I think it is probably not useful when the region is active - in that case, what you showed before, which just uses `current-column', is probably more useful. I'm not sure where we should go from here. The fix to _this bug_ is to add `save-excursion', however you want to do that. Whether this function should be renamed or another function should be created, and in the latter case, whether it should be able to work correctly whether or not the region is active, I'm not sure. I propose that you (please) fix and close this bug by adding `save-excursion', and you (please) submit a question to emacs-devel about what should be done for a (new) function that returns the column positions of an arbitrary rectangle (defined by START and END positions). Is such a function useful, and if yes, just what should it do? One possibility might be to give such a function conditional behavior: . If region is active, use it (as you do above, and as I do in my code). . If not, do the simpler calculation, not trying to take any special display matters into account, beyond what `current-column' handles. Dunno. I have the answer for my code (I wrap the `rectangle--pos-cols' calls with `save-excursion'). And I think it would be good to fix `r--p-c' by adding `save-excursion'. (And I suspect that other `goto-char' occurrences added for Emacs 25 to rect.el should also be so wrapped.) Beyond that, what might be a useful `rectangle-pos-cols' function, I'm not sure. We'd want a function that, given `pos' (i.e., two positions START and END) returns `cols' (i.e., two columns). And I think we'd want it to DTRT for both the active-region case and the case where the region is not active (and so not taken into account). When the region is not active, I don't think (but I'm not sure) that things need to be complicated, since `current-column' should already DTRT wrt wide chars etc.