all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* hideshow: two minor tweaks
@ 2012-02-08  5:46 John Yates
  0 siblings, 0 replies; only message in thread
From: John Yates @ 2012-02-08  5:46 UTC (permalink / raw)
  To: emacs-devel

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;



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2012-02-08  5:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-08  5:46 hideshow: two minor tweaks John Yates

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.