[Top][All Lists]

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

hideshow: two minor tweaks

From: John Yates
Subject: hideshow: two minor tweaks
Date: Wed, 8 Feb 2012 00:46:10 -0500

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


/* adjl
   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 via email to

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