unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#8036: [PATCH] Prevent hide-show mode from getting confused by braces in comments
@ 2011-02-14  7:02 Dima Kogan
       [not found] ` <handler.8036.B.129767263825636.ack@debbugs.gnu.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Dima Kogan @ 2011-02-14  7:02 UTC (permalink / raw)
  To: 8036

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

Emacs bug #700 (http://debbugs.gnu.org/cgi/bugreport.cgi?bug=700)
contained a patch by Dmitry Bolshakov addressing 2 issues in hide-show
minor mode. The fix to one of the issues got integrated into the code
base, but the other one fell through the cracks, I think. The issue it
fixes is to prevent hide-show mode from parsing braces inside comments.
These braces can confuse the parser, since they don't necessarily match
up.

I'm attaching Dmitry's test case that demonstrates the issue, and his patch to
fix it.

dima

[-- Attachment #2: unbalanced-braces-test.pl --]
[-- Type: application/x-perl, Size: 155 bytes --]

[-- Attachment #3: hs.patch --]
[-- Type: text/x-patch, Size: 1258 bytes --]

--- hideshow.el.original_emacs_22.2	2008-01-10 12:15:42.000000000 -0800
+++ hideshow_my.el	2008-08-12 15:39:12.000000000 -0700
@@ -541,7 +541,10 @@
              (q
               ;; `q' is the point at the end of the block
               (progn (hs-forward-sexp mdata 1)
-                     (end-of-line)
+					 ;; see http://www.emacswiki.org/cgi-bin/wiki/HideShow and search page for "hs-block-includes-last-line"
+					 ;(forward-line -1)
+                     ;(end-of-line)
+					 (backward-char 1) ; better
                      (point)))
              ov)
         (when (and (< p (point)) (> (count-lines p q) 1))
@@ -672,10 +675,13 @@
            (forward-comment (buffer-size))
            (and (< (point) maxp)
                 (re-search-forward hs-block-start-regexp maxp t)))
-    (if (> arg 1)
-        (hs-hide-level-recursive (1- arg) minp maxp)
-      (goto-char (match-beginning hs-block-start-mdata-select))
-      (hs-hide-block-at-point t)))
+	(when (not (nth 4 (syntax-ppss))) ; not inside comments
+	  (if (> arg 1)
+		  (hs-hide-level-recursive (1- arg) minp maxp)
+		(goto-char (match-beginning hs-block-start-mdata-select))
+		(hs-hide-block-at-point t))
+	  )
+	)
   (goto-char maxp))
 
 (defmacro hs-life-goes-on (&rest body)

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

* bug#8036: Acknowledgement ([PATCH] Prevent hide-show mode from getting confused by braces in comments)
       [not found] ` <handler.8036.B.129767263825636.ack@debbugs.gnu.org>
@ 2011-02-15  4:20   ` Dima Kogan
  2011-02-16  5:01   ` bug#8036: [PATCH] Prevent hide-show mode from getting confused by braces in comments Dima Kogan
  1 sibling, 0 replies; 4+ messages in thread
From: Dima Kogan @ 2011-02-15  4:20 UTC (permalink / raw)
  To: 8036

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

I accidentally attached the Dmitry's original patch file, that
contains both the merged and unmerged fixes. Further, it appears that
Dmitry's original patch handles the case where hs-hide-all is called
in the attached sample perl script, BUT it does not handle the case
where hs-hide-level is called with the point at the end of the
buffer. I'm attaching a new patch that ONLY contains the pertinent
changes and that addresses the second issue also.

[-- Attachment #2: hideshow-comments.patch --]
[-- Type: text/x-patch, Size: 1188 bytes --]

--- hideshow.orig.el	2011-02-13 23:01:07.000000000 -0800
+++ hideshow.el	2011-02-14 20:11:17.000000000 -0800
@@ -690,6 +690,7 @@
         (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
                              (< here (save-excursion
                                        (hs-forward-sexp (match-data t) 1)
@@ -712,10 +713,11 @@
            (forward-comment (buffer-size))
            (and (< (point) maxp)
                 (re-search-forward hs-block-start-regexp maxp t)))
-    (if (> arg 1)
-        (hs-hide-level-recursive (1- arg) minp maxp)
-      (goto-char (match-beginning hs-block-start-mdata-select))
-      (hs-hide-block-at-point t)))
+    (when (not (nth 4 (syntax-ppss))) ; not inside comments
+      (if (> arg 1)
+          (hs-hide-level-recursive (1- arg) minp maxp)
+        (goto-char (match-beginning hs-block-start-mdata-select))
+        (hs-hide-block-at-point t))))
   (goto-char maxp))
 
 (defmacro hs-life-goes-on (&rest body)

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

* bug#8036: [PATCH] Prevent hide-show mode from getting confused by braces in comments
       [not found] ` <handler.8036.B.129767263825636.ack@debbugs.gnu.org>
  2011-02-15  4:20   ` bug#8036: Acknowledgement ([PATCH] Prevent hide-show mode from getting confused by braces in comments) Dima Kogan
@ 2011-02-16  5:01   ` Dima Kogan
  2011-02-19 22:20     ` Chong Yidong
  1 sibling, 1 reply; 4+ messages in thread
From: Dima Kogan @ 2011-02-16  5:01 UTC (permalink / raw)
  To: 8036

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

I have discovered a case where the previous patch causes an infinite
loop. The new patch I'm attaching resolves that issue

[-- Attachment #2: hideshow-comments.patch --]
[-- Type: text/x-patch, Size: 1206 bytes --]

--- hideshow.orig.el	2011-02-13 23:01:07.000000000 -0800
+++ hideshow.el	2011-02-15 20:58:14.000000000 -0800
@@ -690,6 +690,7 @@
         (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
                              (< here (save-excursion
                                        (hs-forward-sexp (match-data t) 1)
@@ -712,10 +713,11 @@
            (forward-comment (buffer-size))
            (and (< (point) maxp)
                 (re-search-forward hs-block-start-regexp maxp t)))
-    (if (> arg 1)
-        (hs-hide-level-recursive (1- arg) minp maxp)
-      (goto-char (match-beginning hs-block-start-mdata-select))
-      (hs-hide-block-at-point t)))
+    (when (save-match-data (not (nth 4 (syntax-ppss)))) ; not inside comments
+      (if (> arg 1)
+          (hs-hide-level-recursive (1- arg) minp maxp)
+        (goto-char (match-beginning hs-block-start-mdata-select))
+        (hs-hide-block-at-point t))))
   (goto-char maxp))
 
 (defmacro hs-life-goes-on (&rest body)

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

* bug#8036: [PATCH] Prevent hide-show mode from getting confused by braces in comments
  2011-02-16  5:01   ` bug#8036: [PATCH] Prevent hide-show mode from getting confused by braces in comments Dima Kogan
@ 2011-02-19 22:20     ` Chong Yidong
  0 siblings, 0 replies; 4+ messages in thread
From: Chong Yidong @ 2011-02-19 22:20 UTC (permalink / raw)
  To: Dima Kogan; +Cc: 8036

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

> I have discovered a case where the previous patch causes an infinite
> loop. The new patch I'm attaching resolves that issue

Looks reasonable.  Committed, and thanks.





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

end of thread, other threads:[~2011-02-19 22:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-14  7:02 bug#8036: [PATCH] Prevent hide-show mode from getting confused by braces in comments Dima Kogan
     [not found] ` <handler.8036.B.129767263825636.ack@debbugs.gnu.org>
2011-02-15  4:20   ` bug#8036: Acknowledgement ([PATCH] Prevent hide-show mode from getting confused by braces in comments) Dima Kogan
2011-02-16  5:01   ` bug#8036: [PATCH] Prevent hide-show mode from getting confused by braces in comments Dima Kogan
2011-02-19 22:20     ` Chong Yidong

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