bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#10856: 24.0.93; hs-hide-block changes cursor column when collapsing


From: Lars Ingebrigtsen
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
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

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 via email to

[Prev in Thread] Current Thread [Next in Thread]