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, 26 Nov 2014 14:38:01 +0100 Message-ID: <8761e26q12.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> <8761easv3s.fsf@rosalinde.fritz.box> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1417009170 11869 80.91.229.3 (26 Nov 2014 13:39:30 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 26 Nov 2014 13:39:30 +0000 (UTC) Cc: paul@tilk.co, 19102@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Nov 26 14:39: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 1XtcoR-000187-WB for geb-bug-gnu-emacs@m.gmane.org; Wed, 26 Nov 2014 14:39:20 +0100 Original-Received: from localhost ([::1]:33941 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XtcoR-0001gp-JX for geb-bug-gnu-emacs@m.gmane.org; Wed, 26 Nov 2014 08:39:19 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37972) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XtcoH-0001gT-NC for bug-gnu-emacs@gnu.org; Wed, 26 Nov 2014 08:39:15 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XtcoB-0005QA-Je for bug-gnu-emacs@gnu.org; Wed, 26 Nov 2014 08:39:09 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:48482) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XtcoB-0005Q5-GN for bug-gnu-emacs@gnu.org; Wed, 26 Nov 2014 08:39:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1XtcoA-0004xm-T6 for bug-gnu-emacs@gnu.org; Wed, 26 Nov 2014 08:39:03 -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, 26 Nov 2014 13:39:02 +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.141700908919001 (code B ref 19102); Wed, 26 Nov 2014 13:39:02 +0000 Original-Received: (at 19102) by debbugs.gnu.org; 26 Nov 2014 13:38:09 +0000 Original-Received: from localhost ([127.0.0.1]:45692 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XtcnI-0004wL-2l for submit@debbugs.gnu.org; Wed, 26 Nov 2014 08:38:08 -0500 Original-Received: from mout.gmx.net ([212.227.17.22]:63950) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XtcnE-0004wC-Km for 19102@debbugs.gnu.org; Wed, 26 Nov 2014 08:38:05 -0500 Original-Received: from rosalinde.fritz.box ([89.245.127.251]) by mail.gmx.com (mrgmx102) with ESMTPSA (Nemesis) id 0Lyj4F-1Xx0DF1eQJ-0167EJ; Wed, 26 Nov 2014 14:38:02 +0100 In-Reply-To: (Stefan Monnier's message of "Tue, 25 Nov 2014 21:43:02 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-Provags-ID: V03:K0:hb780ZyYmUpJfydCOZfkMjmTPuf8Kr5Xi1/DmaoftY9hOVgKIRp PBdZxSHRySch3e7g7PWw8RlHZ2C5r2gxbdgSi1XwCiXtn4QJ1+JcbWOOFp9MKBwLclZAX00 4Dced2wE0fS6yjhfZrm5eBdCItVy9/LZieQpGk7ixbeepX7f5SnXwQga0jBPiyFvkyIPeen ZfzNHx+a5pHXREkxnmjmg== 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:96613 Archived-At: --=-=-= Content-Type: text/plain On Tue, 25 Nov 2014 21:43:02 -0500 Stefan Monnier wrote: >> + (maybe-forward-char (lambda () >> + (and (eobp) (not (bolp)) (newline)) >> + (and (eolp) (not (bolp)) (forward-char 1)))) > > If we add a newline, we know don't want to do a `forward-char'. So: Oops, you commented on the last version of my patch, which, however, I had already considered superseded by the last version of the command subsequently posted by Paul Rankin, which in effect already addressed your concerns. Rather than repost the diff for the latter, I'm appending the two corrected versions of outline-move-subtree-down to facilitate comparison and deciding which to use. The only thing I added to both is a condition for triggering the user-error, since the message doesn't seem appropriate when you try to move a subtree down at eob or up at bob (if you don't think it's worth avoiding the message there, I'll remove the condition). Here's the version of my patch with your improvements: --=-=-= Content-Type: text/x-emacs-lisp Content-Disposition: inline Content-Description: outline-move-subtree-down (1) (defun outline-move-subtree-down (&optional arg) "Move the current subtree down past ARG headlines of the same level." (interactive "p") (let ((movfunc (if (> arg 0) 'outline-get-next-sibling '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 () (if (eq (char-after) ?\n) (forward-char 1) (if (and (eobp) (not (bolp))) (insert "\n"))))) beg end folded) ;; 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)) (funcall maybe-forward-char) (setq end (point)) ;; Find insertion point, with error handling. (goto-char beg) (while (> cnt 0) (or (funcall movfunc) (unless (or (bobp) (eobp)) (goto-char beg) (user-error "Cannot move past superior level"))) (setq cnt (1- cnt))) (if (> arg 0) ;; Moving forward - still need to move over subtree. (progn (outline-end-of-subtree) (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))) --=-=-= Content-Type: text/plain And here's Paul's version (tweaked to make it closer to the outline.el style): --=-=-= Content-Type: text/x-emacs-lisp Content-Disposition: inline Content-Description: outline-move-subtree-down (2) (defun outline-move-subtree-down (&optional arg) "Move the current subtree down past ARG headlines of the same level." (interactive "p") (outline-back-to-heading) (let* ((movfunc (if (> arg 0) 'outline-get-next-sibling 'outline-get-last-sibling)) ;; Find the end of the subtree to be moved as well as the point to ;; move it to, adding a newline if necessary, to ensure these points ;; are at bol on the line below the subtree. (end-point-func (lambda () (outline-end-of-subtree) (if (and (eobp) (eolp) (not (bolp))) (insert-char ?\n)) (unless (eobp) (forward-char 1)) (point))) (beg (point)) (folded (save-match-data (outline-end-of-heading) (outline-invisible-p))) (end (save-match-data (funcall end-point-func))) (ins-point (make-marker)) (cnt (abs arg))) ;; Find insertion point, with error handling. (goto-char beg) (while (> cnt 0) (or (funcall movfunc) (unless (or (bobp) (eobp)) (goto-char beg) (user-error "Cannot move past superior level"))) (setq cnt (1- cnt))) (if (> arg 0) ;; Moving forward - still need to move over subtree. (funcall end-point-func)) (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))) --=-=-= Content-Type: text/plain Which should we use? Steve Berman --=-=-=--