From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Marcin Borkowski Newsgroups: gmane.emacs.bugs Subject: bug#20663: page.el (forward-page): Avoid skipping pages Date: Wed, 20 Apr 2016 09:32:37 +0200 Message-ID: <871t607n1m.fsf@mbork.pl> References: <20150526171440.GG647@gmail.com> <87h9fbum2w.fsf@mbork.pl> <83h9fbhu0p.fsf@gnu.org> <871t6eve9c.fsf@mbork.pl> <837fg6injl.fsf@gnu.org> <20160410012924.GA23097@gmail.com> <87fuus30rs.fsf@mbork.pl> <8337qsgnvc.fsf@gnu.org> <87a8kxcs4k.fsf@mbork.pl> <83shylbxqc.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1461137608 29972 80.91.229.3 (20 Apr 2016 07:33:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 20 Apr 2016 07:33:28 +0000 (UTC) Cc: 20663@debbugs.gnu.org, ambrevar@gmail.com To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Apr 20 09:33:13 2016 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 1asmdM-00018h-NA for geb-bug-gnu-emacs@m.gmane.org; Wed, 20 Apr 2016 09:33:12 +0200 Original-Received: from localhost ([::1]:44177 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asmdL-0001qr-HU for geb-bug-gnu-emacs@m.gmane.org; Wed, 20 Apr 2016 03:33:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49532) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asmdH-0001nJ-Oe for bug-gnu-emacs@gnu.org; Wed, 20 Apr 2016 03:33:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1asmdC-00087V-R1 for bug-gnu-emacs@gnu.org; Wed, 20 Apr 2016 03:33:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:56853) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asmdC-000871-Nw for bug-gnu-emacs@gnu.org; Wed, 20 Apr 2016 03:33:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1asmdC-00035K-Gt for bug-gnu-emacs@gnu.org; Wed, 20 Apr 2016 03:33:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Marcin Borkowski Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 20 Apr 2016 07:33:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20663 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 20663-submit@debbugs.gnu.org id=B20663.146113757211841 (code B ref 20663); Wed, 20 Apr 2016 07:33:02 +0000 Original-Received: (at 20663) by debbugs.gnu.org; 20 Apr 2016 07:32:52 +0000 Original-Received: from localhost ([127.0.0.1]:40957 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1asmd1-00034v-KO for submit@debbugs.gnu.org; Wed, 20 Apr 2016 03:32:51 -0400 Original-Received: from mail.mojserwer.eu ([195.110.48.8]:35572) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1asmcz-00034l-CJ for 20663@debbugs.gnu.org; Wed, 20 Apr 2016 03:32:50 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by mail.mojserwer.eu (Postfix) with ESMTP id 6F486AE51C9; Wed, 20 Apr 2016 09:32:47 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mail.mojserwer.eu Original-Received: from mail.mojserwer.eu ([127.0.0.1]) by localhost (mail.mojserwer.eu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7+ZzZw2aYPr3; Wed, 20 Apr 2016 09:32:41 +0200 (CEST) Original-Received: from localhost (98-171.echostar.pl [213.156.98.171]) by mail.mojserwer.eu (Postfix) with ESMTPSA id 0EAE2AE51C7; Wed, 20 Apr 2016 09:32:41 +0200 (CEST) User-agent: mu4e 0.9.13; emacs 25.1.50.8 In-reply-to: <83shylbxqc.fsf@gnu.org> 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:116623 Archived-At: On 2016-04-16, at 11:26, Eli Zaretskii wrote: >> From: Marcin Borkowski >> Cc: ambrevar@gmail.com, 20663@debbugs.gnu.org >> Date: Wed, 13 Apr 2016 19:53:31 +0200 >> >> > Can one of you please explain why the original code misbehaves? >> >> Quoting from the original report: >> >> --8<---------------cut here---------------start------------->8--- >> > Running `emacs -Q example.txt`: >> > >> > M-< >> > C-x n p >> > M-> >> > M-1 C-x n p >> > >> > This should bring us from page 1 to page 2, but page 3 gets displayed instead. >> --8<---------------cut here---------------end--------------->8--- > > Yes, I've read that. I asked for an explanation of _why_ the code > currently in Emacs misbehaves in this recipe. Can one of you describe > that? Let me try (note: this is partly my conjecture!). Since the concept of a "page delimiter" is vague in Emacs (the manual suggests that a page delimiter is a _line_ such that `page-delimiter' matches at its beginning, common sense suggests that it is a _substring_ of the buffer matching `page-delimiter', it's probable that someone decided that if the point is at the beginning of a line and matches `page-delimiter', then `forward-page' shouldn't just move past the text matching `page-delimiter' we are on, but the next one. So the author of the current version of `forward-page' decided just to move one character forward (in case we are at the line beginning), so that `page-delimiter' won't match. This I consider a Bad Idea™. As I mentioned earlier, I think the concept of a "page" and "page delimiter" should be made more precise; then, it should be enough to correct `forward-page' (basically all other functions in page.el depend on it, directly or not). Currently Emacs seems to treat the _line_ as the page delimiter, but as the OP noted, this yields strange/unintuitive results with narrowing. And by the way, the patch the OP gave is also wrong, though in a different way. (I should have noticed that earlier.) The OP proposed this instead of (if (bolp) (forward-char 1)): (if (string= page-delimiter "") (forward-char 1)) Of course, this condition should never be true: if `page-delimiter' is "", functions from page.el will most probably never work correctly anyway. What (maybe) should have been tested would be (eq (match-beginning 0) (match-end 0)) but anyway, since Emacs regex engine does not have a lot of zero-width assertions, this is not going to happen very often anyway (certainly never with the default value of `page-delimiter', which explains why the OP hasn't noticed any problems with his patch). One possible value of `page-delimiter' that comes to my mind which could lead to the above condition holding would be "^$" -- though I can hardly see any practical use for it. So my proposal would be to just delete the offending line altogether. I'd be very surprised if we heard any complaints afterwards. BTW, the analogous code for moving back one page seems also suspicious to me. I'll look into it tomorrow. > Thanks. Best, -- Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Faculty of Mathematics and Computer Science Adam Mickiewicz University