From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Rankin Newsgroups: gmane.emacs.bugs Subject: bug#19102: 24.4; outline-move-subtree-up/down error at last and second-last subtree Date: Thu, 20 Nov 2014 23:43:10 +1000 Message-ID: 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> <87ppcitc7x.fsf@rosalinde.fritz.box> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1416491066 20764 80.91.229.3 (20 Nov 2014 13:44:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 20 Nov 2014 13:44:26 +0000 (UTC) Cc: 19102@debbugs.gnu.org To: Stephen Berman Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Nov 20 14:44:20 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 1XrS1z-000656-Rr for geb-bug-gnu-emacs@m.gmane.org; Thu, 20 Nov 2014 14:44:20 +0100 Original-Received: from localhost ([::1]:35358 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XrS1w-0003UH-O4 for geb-bug-gnu-emacs@m.gmane.org; Thu, 20 Nov 2014 08:44:16 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38001) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XrS1o-0003U7-33 for bug-gnu-emacs@gnu.org; Thu, 20 Nov 2014 08:44:13 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XrS1i-0004YA-Gg for bug-gnu-emacs@gnu.org; Thu, 20 Nov 2014 08:44:08 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:41908) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XrS1i-0004Y6-Cp for bug-gnu-emacs@gnu.org; Thu, 20 Nov 2014 08:44:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1XrS1h-00070k-Vx for bug-gnu-emacs@gnu.org; Thu, 20 Nov 2014 08:44:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Paul Rankin Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 20 Nov 2014 13:44: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.141649100226891 (code B ref 19102); Thu, 20 Nov 2014 13:44:01 +0000 Original-Received: (at 19102) by debbugs.gnu.org; 20 Nov 2014 13:43:22 +0000 Original-Received: from localhost ([127.0.0.1]:39121 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XrS13-0006zf-Eg for submit@debbugs.gnu.org; Thu, 20 Nov 2014 08:43:21 -0500 Original-Received: from out4-smtp.messagingengine.com ([66.111.4.28]:45451) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XrS0z-0006zT-JB for 19102@debbugs.gnu.org; Thu, 20 Nov 2014 08:43:18 -0500 Original-Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 60A6F20C0F; Thu, 20 Nov 2014 08:43:17 -0500 (EST) Original-Received: from frontend1 ([10.202.2.160]) by compute5.internal (MEProxy); Thu, 20 Nov 2014 08:43:17 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=tilk.co; h= x-sasl-enc:references:from:to:cc:subject:in-reply-to:date :message-id:mime-version:content-type; s=mesmtp; bh=VCBL3J01v0dh fmery+G7boGVZDY=; b=NTA20nM7grMtYj/2gyLnVLfZW81Gf2tmuTVk3L3rv5QP ufYPDuqbpU9XYTdj04IQO8ZqS8uKUq5e61E0M2qLRSjKFPJCNalxyBqZ6RaqzOmZ 9ZSA7B5VBhDM9rjzC/ulmFsnX1yssMgczrOfeBaX5gfvKwwXem6SCtJEtIqL8hY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=x-sasl-enc:references:from:to:cc:subject :in-reply-to:date:message-id:mime-version:content-type; s= smtpout; bh=VCBL3J01v0dhfmery+G7boGVZDY=; b=pbKUT8e9m7TpSh/ICDet 3bEOdHZcbWo7NOi7v+ZlygLGlnOEjM6XqwWwRg2H26Xcyd8yT6PboGYPUoUzkwrC dvD5/f9ZF4xLMqKpY6MgJCSACipLjqYlLKWXvN1Hrm56doagM6trJiPa8p/fq0h2 PoTVVxh/3j9dkBUbUDzSTss= X-Sasl-enc: MSehGm7q7bUPO7YEYPYhLVKzwjimOrKy0wWr2qAqzkpv 1416490996 Original-Received: from Paul-Rankins-MacBook-Pro.local (unknown [202.0.190.43]) by mail.messagingengine.com (Postfix) with ESMTPA id A5BFAC0000E; Thu, 20 Nov 2014 08:43:15 -0500 (EST) In-reply-to: <87ppcitc7x.fsf@rosalinde.fritz.box> 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:96318 Stephen Berman writes: > This basically does the same thing as the patch I proposed -- adding a > newline if necessary to ensure forward movement -- except that if there > was no empty line after the last subtree, your code leaves the added > newline dangling. If you add that bit then there is effectively no > difference between your version and mine. For my package's purposes I think it might be better to have that dangling newline created it's not already there, but yeah, not for outline-mode. (This may be a faux pas on my part.) However, how about this for the dangling line code? --8<---------------cut here---------------start------------->8--- (unless empty-last-line (save-excursion (goto-char (point-max)) (if (and (bolp) (eolp)) (delete-char -1))))) --8<---------------cut here---------------end--------------->8--- That way it doesn't execute if it doesn't need to. Or am I over-thinking it? > However, yours is slightly shorter and slightly cleaner, since it > avoids a couple of setq's of let-bound variables, so maybe it's the > better fix (after adding the line deletion bit; also, it's not > necessary and AFAIK stylistically discouraged to quote a lambda form; > and finally, I'm not sure if open-line is more or less appropriate > here than newline -- maybe both are too heavyweight and (insert "\n") > or even (terpri) would suffice? Awesome, thanks. I'm not proposing any of my code go into Emacs, so go with whatever you think is best. >> The only thing I'm not sure about is the line marked above. This is not >> intended for Emacs, just wanna see if I'm on the right track :) > > The line you marked tests whether we're moving the subtree down > (positive arg) and if so ensures we find the insertion point after it. > Or are you asking about something else? Thanks. Yes that was all, please do not be under any impression that I have any idea what I'm doing. I did find some problems with saving match data though, so just for the heck of it, I've pasted the function I ended up going with for my package (it probably looks like I rewrote things from your patch just to be contrary, but it's just to fit with the internal style of the package): --8<---------------cut here---------------start------------->8--- (defun fountain-outline-shift-down (&optional n) (interactive "p") (outline-back-to-heading) (let* ((move-func (if (< 0 n) 'outline-get-next-sibling 'outline-get-last-sibling)) (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))) (insert-point (make-marker)) (i (abs n))) (goto-char beg) (while (< 0 i) (or (funcall move-func) (progn (goto-char beg) (message "Cannot shift past higher level"))) (setq i (1- i))) (if (< 0 n) (funcall end-point-func)) (move-marker insert-point (point)) (insert (delete-and-extract-region beg end)) (goto-char insert-point) (if folded (hide-subtree)) (set-marker insert-point nil))) --8<---------------cut here---------------end--------------->8--- -- Paul W. Rankin http://www.paulwrankin.com