all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#8279: [PATCH] More fixes to prevent hide-show from being confused by commented-out braces
@ 2011-03-18  7:33 Dima Kogan
  2011-05-28 18:35 ` Chong Yidong
  0 siblings, 1 reply; 2+ messages in thread
From: Dima Kogan @ 2011-03-18  7:33 UTC (permalink / raw)
  To: 8279

[-- Attachment #1: Type: text/plain, Size: 554 bytes --]

Earlier I submitted some fixes to hideshow.el to improve handling of
braces in comments (bug#8036). These fixes were incomplete and in one
case, incorrect. The attached patch improves hideshow.el further:

1. The previous patch made hs-find-block-beginning quit searching if a brace was
found inside a comment. This patch ignores that match and keeps searching.

2. There were some false positives of (looking-at hs-block-start-regexp) if the
point was at a commented-out brace. This patch wraps all instances of that in a
function to check for comments.

[-- Attachment #2: 0001-hideshow.el-corrected-improper-handling-of-braces-in.patch --]
[-- Type: text/x-patch, Size: 4070 bytes --]

From fad432dc00b7ba1103041b9fd87d4adcf4ac7fd1 Mon Sep 17 00:00:00 2001
From: Dima Kogan <dkogan@cds.caltech.edu>
Date: Sun, 6 Mar 2011 16:28:08 -0800
Subject: [PATCH] hideshow.el: corrected improper handling of braces in comments.

Previous fix in bug #8036 would stop searching for a block start as
soon as one was encountered in a comment. This patch keeps searching,
until a non-commented block start is found. Furthermore, this patch
resolves some corner cases by wrapping all searches for
hs-block-start-regexp into a function that also checks for comments
---
 lisp/progmodes/hideshow.el |   24 +++++++++++++++---------
 1 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/lisp/progmodes/hideshow.el b/lisp/progmodes/hideshow.el
index 9468d7b..708a0b4 100644
--- a/lisp/progmodes/hideshow.el
+++ b/lisp/progmodes/hideshow.el
@@ -536,6 +536,13 @@ property of an overlay."
         (overlay-put ov 'display nil))))
   (overlay-put ov 'invisible (and hide-p 'hs)))
 
+(defun hs-looking-at-block-start-p ()
+  "Returns non-nil if the point is at the block start.
+A function is useful for this to cleanly disregard commented-out
+blocks"
+  (and (looking-at hs-block-start-regexp)
+       (save-match-data (not (nth 4 (syntax-ppss))))))
+
 (defun hs-forward-sexp (match-data arg)
   "Adjust point based on MATCH-DATA and call `hs-forward-sexp-func' w/ ARG.
 Original match data is restored upon return."
@@ -564,7 +571,7 @@ The block beginning is adjusted by `hs-adjust-block-beginning'
 and then further adjusted to be at the end of the line."
   (if comment-reg
       (hs-hide-comment-region (car comment-reg) (cadr comment-reg) end)
-    (when (looking-at hs-block-start-regexp)
+    (when (hs-looking-at-block-start-p)
       (let* ((mdata (match-data t))
 	     (header-beg (match-beginning 0))
              (header-end (match-end 0))
@@ -685,16 +692,15 @@ Return point, or nil if original point was not in a block."
   (let ((done nil)
         (here (point)))
     ;; look if current line is block start
-    (if (looking-at hs-block-start-regexp)
+    (if (hs-looking-at-block-start-p)
         (point)
       ;; look backward for the start of a block that contains the cursor
       (while (and (re-search-backward hs-block-start-regexp nil t)
-		  (save-match-data
-		    (not (nth 4 (syntax-ppss)))) ; not inside comments
-                  (not (setq done
+                  (or (save-match-data (nth 4 (syntax-ppss))) ; go again if in a comment
+                      (not (setq done
                              (< here (save-excursion
                                        (hs-forward-sexp (match-data t) 1)
-                                       (point)))))))
+                                       (point))))))))
       (if done
           (point)
         (goto-char here)
@@ -751,7 +757,7 @@ and `case-fold-search' are both t."
         (end-of-line)
         (when (and (not c-reg)
                    (hs-find-block-beginning)
-                   (looking-at hs-block-start-regexp))
+                   (hs-looking-at-block-start-p))
           ;; point is inside a block
           (goto-char (match-end 0)))))
     (end-of-line)
@@ -836,7 +842,7 @@ Upon completion, point is repositioned and the normal hook
                       (<= (count-lines (car c-reg) (nth 1 c-reg)) 1)))
        (message "(not enough comment lines to hide)"))
       ((or c-reg
-           (looking-at hs-block-start-regexp)
+           (hs-looking-at-block-start-p)
            (hs-find-block-beginning))
        (hs-hide-block-at-point end c-reg)
        (run-hooks 'hs-hide-hook))))))
@@ -868,7 +874,7 @@ See documentation for functions `hs-hide-block' and `run-hooks'."
                      q (cadr c-reg))))
             ((and (hs-find-block-beginning)
                   ;; ugh, fresh match-data
-                  (looking-at hs-block-start-regexp))
+                  (hs-looking-at-block-start-p))
              (setq p (point)
                    q (progn (hs-forward-sexp (match-data t) 1) (point)))))
       (when (and p q)
-- 
1.7.4.1


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

* bug#8279: [PATCH] More fixes to prevent hide-show from being confused by commented-out braces
  2011-03-18  7:33 bug#8279: [PATCH] More fixes to prevent hide-show from being confused by commented-out braces Dima Kogan
@ 2011-05-28 18:35 ` Chong Yidong
  0 siblings, 0 replies; 2+ messages in thread
From: Chong Yidong @ 2011-05-28 18:35 UTC (permalink / raw)
  To: Dima Kogan; +Cc: 8279

Dima Kogan <dkogan@cds.caltech.edu> writes:

> Earlier I submitted some fixes to hideshow.el to improve handling of
> braces in comments (bug#8036). These fixes were incomplete and in one
> case, incorrect. The attached patch improves hideshow.el further:

+  "Returns non-nil if the point is at the block start.
+A function is useful for this to cleanly disregard commented-out
+blocks"

This docstring should use the active voice, i.e. "Returns non-nil if the
point is at the block start."  And there's no need to justify the use of
a function.

Otherwise, the patch looks reasonable; I've commited it.  Thanks.





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

end of thread, other threads:[~2011-05-28 18:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-18  7:33 bug#8279: [PATCH] More fixes to prevent hide-show from being confused by commented-out braces Dima Kogan
2011-05-28 18:35 ` Chong Yidong

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.