unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: John Yates <john@yates-sheets.org>
To: 10856@debbugs.gnu.org
Subject: bug#10856: 24.0.93; hs-hide-block changes cursor column when collapsing a comment
Date: Mon, 20 Feb 2012 09:02:25 -0500	[thread overview]
Message-ID: <CAJnXXohay2Q-LGt+VWoSXPeo=3VkNiofSmoqLBDH_GTJU-qHzA@mail.gmail.com> (raw)

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





             reply	other threads:[~2012-02-20 14:02 UTC|newest]

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

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='CAJnXXohay2Q-LGt+VWoSXPeo=3VkNiofSmoqLBDH_GTJU-qHzA@mail.gmail.com' \
    --to=john@yates-sheets.org \
    --cc=10856@debbugs.gnu.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).