From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alex Newsgroups: gmane.emacs.bugs Subject: bug#50139: 27.2; An issue with outline-move-subtree-down Date: Fri, 20 Aug 2021 23:15:27 +0300 Message-ID: <1bf8567a-7b33-fa88-85ef-a7d5b8f55603@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="------------4F8D795FBB6314464CEFFFCF" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11580"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 To: 50139@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Aug 20 22:27:19 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mHB6k-0002hu-8J for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 20 Aug 2021 22:27:18 +0200 Original-Received: from localhost ([::1]:39644 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mHB6i-0004iS-UP for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 20 Aug 2021 16:27:16 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48384) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mHB6U-0004iK-O9 for bug-gnu-emacs@gnu.org; Fri, 20 Aug 2021 16:27:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:52281) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mHB6U-0005gd-Gg for bug-gnu-emacs@gnu.org; Fri, 20 Aug 2021 16:27:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mHB6U-0008SD-BP for bug-gnu-emacs@gnu.org; Fri, 20 Aug 2021 16:27:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alex Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 20 Aug 2021 20:27:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 50139 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.162949120132467 (code B ref -1); Fri, 20 Aug 2021 20:27:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 20 Aug 2021 20:26:41 +0000 Original-Received: from localhost ([127.0.0.1]:35594 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mHB68-0008Rb-TJ for submit@debbugs.gnu.org; Fri, 20 Aug 2021 16:26:41 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:38392) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mHAvO-0008Bt-20 for submit@debbugs.gnu.org; Fri, 20 Aug 2021 16:15:34 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46998) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mHAvN-0000wc-QU for bug-gnu-emacs@gnu.org; Fri, 20 Aug 2021 16:15:33 -0400 Original-Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]:42687) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mHAvM-0006Oc-2A for bug-gnu-emacs@gnu.org; Fri, 20 Aug 2021 16:15:33 -0400 Original-Received: by mail-ed1-x52b.google.com with SMTP id bo19so15591392edb.9 for ; Fri, 20 Aug 2021 13:15:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:subject:from:message-id:date:user-agent:mime-version :content-language; bh=0c/+dnnlK7GEOROp85DDhUN8Uh8I9+SE8YK+LTPGwMs=; b=L0AmiiLJXD62pXiGil0cXeTtUkdKfPlbwOYyea7M9Vq33hpoENZzR8RaTciQFiSmJZ TTCxQcSK0v59JfT191GYtJx6f3EkGie4JD2oBRWX307Aaf9KS7NHLzynOUQXiIf2vlYQ G9Bt9AlVCSAGdH+JVKUBeMzJlrqm5DtFE5h/Moqhw4XPwjpOy01mmEqgnHZwCf+aMoAj PJu8mmH1tgAalGcHCe8tackgZY13SyXb0khuFyvFaiPNOH7VgW81Y+k1j9YrWXCl8Mpv SW6V5l+L6ZVnbYdfhKDEUbKyRP5f5jk0z5XMH35dEm87xChZVoIPAED3287wfIH6lbx5 lfVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:subject:from:message-id:date:user-agent :mime-version:content-language; bh=0c/+dnnlK7GEOROp85DDhUN8Uh8I9+SE8YK+LTPGwMs=; b=f/TzoS+tbqxwsxzlWvCML7q1DClSgBpJQOLTZaKOmyHfWyrqS7f8PMvivxJ3vDZUzF QJUtDkguNe7t4cm+R/7Eed3EXwtOElUn1QxQX4ArCbX4JkT6jDJ/O+6p4U0DY0IdSRnQ ql4wTy8LJHOxeBaq/gfDhM+lLJR/DOqbGBjSNbHUD2spBn4oMU6Sw4xdywphNt+LSP4w 3kablhWQ3sXl8uAkxkGm7p4bCxWtUELQ6GU+adEfH6Ae9Jk4utM5gECYq/cHPihVKiUj FQxYKrrw7+2iTxDxuQ2GBYxApM895x4DcHBWjC/J6ekv4WtJZ2mkUvueAZrJbQPl2zlH Jl+Q== X-Gm-Message-State: AOAM533dXaVtlWN6y1n/dorf2iOL5Btdc4LK/w4oJ7D4ocn8Pct5Z+/y BAu+Hoqf7NfLX7qS6+X0SSw8Cviottw= X-Google-Smtp-Source: ABdhPJzgkv1JHERWJPq1OTqceHYoQNXjjhuiyj60rlKt82uS3AWDCDWkmZtGPB+pLG+LktOtTILvkg== X-Received: by 2002:a05:6402:2049:: with SMTP id bc9mr24067366edb.130.1629490529278; Fri, 20 Aug 2021 13:15:29 -0700 (PDT) Original-Received: from [192.168.1.8] ([37.157.175.121]) by smtp.gmail.com with ESMTPSA id r16sm3273559ejz.41.2021.08.20.13.15.28 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 20 Aug 2021 13:15:28 -0700 (PDT) Content-Language: en-US Received-SPF: pass client-ip=2a00:1450:4864:20::52b; envelope-from=alex.giorev@gmail.com; helo=mail-ed1-x52b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Fri, 20 Aug 2021 16:26:39 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:212305 Archived-At: This is a multi-part message in MIME format. --------------4F8D795FBB6314464CEFFFCF Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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)))) | --------------4F8D795FBB6314464CEFFFCF Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
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))))


--------------4F8D795FBB6314464CEFFFCF--