From: John Yates <john@yates-sheets.org>
To: emacs-devel@gnu.org
Subject: hideshow: two minor tweaks
Date: Wed, 8 Feb 2012 00:46:10 -0500 [thread overview]
Message-ID: <CAJnXXoiDKavoziZ3_6kdrt6LvQ2eCZS_gZ-rc2uNWhfTU6Ee4w@mail.gmail.com> (raw)
At present hs-show-block expands a hidden comment block irrespective
of where the cursor happens to be on the collapsed comment line. It
also leaves the cursor position unchanged.
By contrast hs-hide-block's handling of comment blocks exhibits two rough edges:
(1) It fails to recognize a comment block if the cursor is in white
space to the left. Fixed by having hs-inside-comment-p skip leading
white space.
(2) It always positions the cursor at the first character of the
collapsed comment. Fixed by having hs-hide-comment-region maintian
the cursor column if 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))))))
(defun hs-hide-block-at-point (&optional end comment-reg)
"Hide block if on block beginning.
@@ -607,6 +609,7 @@
;; forward comment, and see if we are inside, then extend
;; forward and backward as long as we have comments
(let ((q (point)))
+ (skip-chars-forward "[:blank:]")
(when (or (looking-at hs-c-start-regexp)
(re-search-backward hs-c-start-regexp (point-min) t))
;; first get to the beginning of this comment...
I use the following fragment to explore the behavior of with the
cursor left of comment start, on comment start, and within the comment
text.
/john
/* adjl
ajdlf
ajdfla */
int a;
/* ajdklfj
** ajsdfljl
** adsfjll
*/
int b;
/* adhfkah
* adslj
* ajdlfk
*/
int c;
// asdjflj
// ajdlfj
// ajsdflj
int d;
// adjfla
// jalsdfjla
// jlasd
int e;
// asdfjl
// ajdflj
// jasdfjl
int f;
reply other threads:[~2012-02-08 5:46 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAJnXXoiDKavoziZ3_6kdrt6LvQ2eCZS_gZ-rc2uNWhfTU6Ee4w@mail.gmail.com \
--to=john@yates-sheets.org \
--cc=emacs-devel@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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.