Subject: bug#50139: 27.2; An issue with outline-move-subtree-down

From: Alex <[email-masked]>
Date: Fri, 20 Aug 2021 23:15:27 +0300

Consider a buffer in |outline-mode| having the following text (it is 
important that the buffer ends in a newline):

* first heading
the body of the first heading
* second heading
the body of the second heading

Now position point on the second heading and invoke |M-x 
outline-hide-subtree|, after which go to the first heading and invoke 
|M-x outline-move-subtree-down|. On my computer, this resulted in the 
first heading appearing to be on the same visual line as the second.

I've figured out why this happens. It is because 
|outline-end-of-subtree| works a bit differently depending on whether 
the subtree is the last one in the buffer. In this case, point will be 
positioned at the end of the buffer, but when the subtree is not the 
last one, it will be positioned on the last position of the last line of 
the subtree, before the newline which separates it from the next 
heading. I think this implementation is more consistent, as it works the 
same in both cases:

|(defun outline-end-of-subtree ()
   "Move to the end of the current subtree.
More precisely, move to the last position of the last line of the 
subtree: the
position before the newline character of that line."
   (outline-back-to-heading)
   (let ((level (funcall outline-level)))
     ;; this loop stops at the end of the buffer or on the first heading 
whose
     ;; level is not less than that of the current subtree
     (while (and (not (eobp))
                 (> (progn (outline-next-heading)
                           (funcall outline-level))
                    level)))
     (if (eobp)
         (if (= (char-before) ?\n) (backward-char))
       (backward-char)))) |