unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#10856: 24.0.93; hs-hide-block changes cursor column when collapsing a comment
@ 2012-02-20 14:02 John Yates
  2019-10-03 16:56 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 2+ messages in thread
From: John Yates @ 2012-02-20 14:02 UTC (permalink / raw)
  To: 10856

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))))))





^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#10856: 24.0.93; hs-hide-block changes cursor column when collapsing a comment
  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
  0 siblings, 0 replies; 2+ messages in thread
From: Lars Ingebrigtsen @ 2019-10-03 16:56 UTC (permalink / raw)
  To: John Yates; +Cc: 10856

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





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-10-03 16:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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

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).