unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Lars Ingebrigtsen <larsi@gnus.org>
To: John Yates <john@yates-sheets.org>
Cc: 10856@debbugs.gnu.org
Subject: bug#10856: 24.0.93; hs-hide-block changes cursor column when collapsing a comment
Date: Thu, 03 Oct 2019 18:56:18 +0200	[thread overview]
Message-ID: <87h84phiod.fsf@gnus.org> (raw)
In-Reply-To: <CAJnXXohay2Q-LGt+VWoSXPeo=3VkNiofSmoqLBDH_GTJU-qHzA@mail.gmail.com> (John Yates's message of "Mon, 20 Feb 2012 09:02:25 -0500")

John Yates <john@yates-sheets.org> writes:

> When hs-show-block reveals a collapsed comment block it preserves the
> position of the cursor.  This honors the "principle of least
> astonishment".  By contrast when hs-hide-block collapses a comment
> block it moves the cursor to the comment's left boundary.  This is
> unexpected and a jarring asymmetry w.r.t. hs-show-block.
>
> The following patch maintain the cursor column whenever possible:
>
> --- cur/hideshow.el
> +++ fix/hideshow.el
> @@ -552,11 +552,13 @@
>  (defun hs-hide-comment-region (beg end &optional repos-end)
>   "Hide a region from BEG to END, marking it as a comment.
>  Optional arg REPOS-END means reposition at end."
> -  (let ((beg-eol (progn (goto-char beg) (line-end-position)))
> +  (let ((goal-col (current-column))
> +        (beg-bol (progn (goto-char beg) (line-beginning-position)))
> +        (beg-eol (line-end-position))
>         (end-eol (progn (goto-char end) (line-end-position))))
>     (hs-discard-overlays beg-eol end-eol)
> -    (hs-make-overlay beg-eol end-eol 'comment beg end))
> -  (goto-char (if repos-end end beg)))
> +    (hs-make-overlay beg-eol end-eol 'comment beg end)
> +    (goto-char (if repos-end end (min end (+ beg-bol goal-col))))))

I tried the patch, and it does indeed make the behaviour more logical,
so I've now applied it to Emacs 27.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





      reply	other threads:[~2019-10-03 16:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-20 14:02 bug#10856: 24.0.93; hs-hide-block changes cursor column when collapsing a comment John Yates
2019-10-03 16:56 ` Lars Ingebrigtsen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h84phiod.fsf@gnus.org \
    --to=larsi@gnus.org \
    --cc=10856@debbugs.gnu.org \
    --cc=john@yates-sheets.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).