From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.bugs Subject: bug#19102: 24.4; outline-move-subtree-up/down error at last and second-last subtree Date: Wed, 19 Nov 2014 23:07:03 +0100 Message-ID: <8761easv3s.fsf@rosalinde.fritz.box> References: <87lhn7s522.fsf@rosalinde.fritz.box> <83lhn789tq.fsf@gnu.org> <87h9xvruan.fsf@rosalinde.fritz.box> <83tx1v6mur.fsf@gnu.org> <87a93nrlql.fsf@rosalinde.fritz.box> <83lhn76iex.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1416434910 24241 80.91.229.3 (19 Nov 2014 22:08:30 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 19 Nov 2014 22:08:30 +0000 (UTC) Cc: paul@tilk.co, 19102@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Nov 19 23:08:23 2014 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 1XrDQA-0002qb-4b for geb-bug-gnu-emacs@m.gmane.org; Wed, 19 Nov 2014 23:08:18 +0100 Original-Received: from localhost ([::1]:60937 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XrDQ9-0006UM-MH for geb-bug-gnu-emacs@m.gmane.org; Wed, 19 Nov 2014 17:08:17 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37784) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XrDQ0-0006UD-1r for bug-gnu-emacs@gnu.org; Wed, 19 Nov 2014 17:08:13 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XrDPu-000660-Lm for bug-gnu-emacs@gnu.org; Wed, 19 Nov 2014 17:08:08 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:41576) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XrDPu-00065u-Hc for bug-gnu-emacs@gnu.org; Wed, 19 Nov 2014 17:08:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1XrDPu-0007hO-2Q for bug-gnu-emacs@gnu.org; Wed, 19 Nov 2014 17:08:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stephen Berman Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 19 Nov 2014 22:08:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 19102 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 19102-submit@debbugs.gnu.org id=B19102.141643483429536 (code B ref 19102); Wed, 19 Nov 2014 22:08:01 +0000 Original-Received: (at 19102) by debbugs.gnu.org; 19 Nov 2014 22:07:14 +0000 Original-Received: from localhost ([127.0.0.1]:38789 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XrDP7-0007gJ-Sp for submit@debbugs.gnu.org; Wed, 19 Nov 2014 17:07:14 -0500 Original-Received: from mout.gmx.net ([212.227.15.15]:65123) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XrDP5-0007g9-0y for 19102@debbugs.gnu.org; Wed, 19 Nov 2014 17:07:12 -0500 Original-Received: from rosalinde.fritz.box ([89.245.64.17]) by mail.gmx.com (mrgmx002) with ESMTPSA (Nemesis) id 0M23zf-1Y76h239Rr-00u5sL; Wed, 19 Nov 2014 23:07:03 +0100 In-Reply-To: <83lhn76iex.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 19 Nov 2014 22:32:06 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-Provags-ID: V03:K0:dc5JR3m7Dgq3jRDTSW4hqsEp6ukzAm/V3BHvJHjucP9oV/n8Tkh jFPehyGbls2ESZ+HQnrVxP8u82SRm84mlBnh50BAh1CDgb9/9cYEBiUcPbokZFM6r8ic9D4 20I2Ku6MNWeaDzPj1jQet31Ekp3sxqk3FoJ1L53+1RFNqAX87bglGVNkd9dWs7n9HxYiROG IixvVg+a6EG3GpmlFJElA== X-UI-Out-Filterresults: notjunk:1; X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x 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:96290 --=-=-= Content-Type: text/plain On Wed, 19 Nov 2014 22:32:06 +0200 Eli Zaretskii wrote: >> From: Stephen Berman >> Cc: paul@tilk.co, 19102@debbugs.gnu.org >> Date: Wed, 19 Nov 2014 21:14:42 +0100 >> >> > Wouldn't using eolp instead of the comparison solve that problem more >> > easily? >> >> Well, that eliminates the wrong-type-argument error in the current code, >> but it instead signals "End of buffer" > > From forward-char? If so, you could avoid the call if eobp. Or wrap > the call in condition-case and ignore errors. Those solutions work only if there's an empty line after the last subtree. If there isn't, I can't see any way other than my patch. >> Do you see any other problems with the patch or more room for >> improvement? > > I was worried by the complexity of maybe-forward-char, but maybe now > it is much simpler. I simplified it just a bit more, but that's all I can think of. I also had overlooked a side-effect of the error signaled when trying to move the last subtree down: it leaves a dangling newline; this is avoided using with-demoted-errors. The revised patch is appended. Steve Berman --=-=-= Content-Type: text/x-patch Content-Disposition: inline Content-Description: bug#19102 patch diff --git a/lisp/outline.el b/lisp/outline.el index c7cad31..a34ff12 100644 --- a/lisp/outline.el +++ b/lisp/outline.el @@ -649,32 +649,46 @@ the match data is set appropriately." 'outline-get-last-sibling)) (ins-point (make-marker)) (cnt (abs arg)) + ;; Make sure we can move forward to find the end of the + ;; subtree and the insertion point. + (maybe-forward-char (lambda () + (and (eobp) (not (bolp)) (newline)) + (and (eolp) (not (bolp)) (forward-char 1)))) + (empty-last-line (save-excursion + (goto-char (point-max)) + (and (bolp) (eolp)))) beg end folded) - ;; Select the tree + ;; Select the tree. (outline-back-to-heading) (setq beg (point)) (save-match-data (save-excursion (outline-end-of-heading) (setq folded (outline-invisible-p))) (outline-end-of-subtree)) - (if (= (char-after) ?\n) (forward-char 1)) + (funcall maybe-forward-char) (setq end (point)) - ;; Find insertion point, with error handling + ;; Find insertion point, with error handling. (goto-char beg) (while (> cnt 0) (or (funcall movfunc) (progn (goto-char beg) - (error "Cannot move past superior level"))) + (with-demoted-errors "%s" + (message "Cannot move past superior level")))) (setq cnt (1- cnt))) (if (> arg 0) - ;; Moving forward - still need to move over subtree + ;; Moving forward - still need to move over subtree. (progn (outline-end-of-subtree) - (if (= (char-after) ?\n) (forward-char 1)))) + (funcall maybe-forward-char))) (move-marker ins-point (point)) (insert (delete-and-extract-region beg end)) (goto-char ins-point) (if folded (hide-subtree)) - (move-marker ins-point nil))) + (move-marker ins-point nil) + ;; If we added a newline to move forward, delete it. + (save-excursion + (goto-char (point-max)) + (when (and (bolp) (eolp) (not empty-last-line)) + (delete-char -1))))) (defun outline-end-of-heading () (if (re-search-forward outline-heading-end-regexp nil 'move) --=-=-=--