From unknown Sun Jun 22 08:04:18 2025 X-Loop: help-debbugs@gnu.org Subject: bug#8036: [PATCH] Prevent hide-show mode from getting confused by braces in comments Resent-From: Dima Kogan Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 14 Feb 2011 08:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 8036 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 8036@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.129767263825636 (code B ref -1); Mon, 14 Feb 2011 08:38:02 +0000 Received: (at submit) by debbugs.gnu.org; 14 Feb 2011 08:37:18 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Potvp-0006fQ-OH for submit@debbugs.gnu.org; Mon, 14 Feb 2011 03:37:18 -0500 Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PosK5-0003oI-Vh for submit@debbugs.gnu.org; Mon, 14 Feb 2011 01:54:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PosSj-00029j-VG for submit@debbugs.gnu.org; Mon, 14 Feb 2011 02:03:10 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_RP_MATCHES_RCVD autolearn=unavailable version=3.3.1 Received: from lists.gnu.org ([199.232.76.165]:39156) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PosSj-00029f-QT for submit@debbugs.gnu.org; Mon, 14 Feb 2011 02:03:09 -0500 Received: from [140.186.70.92] (port=52319 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PosSi-00069d-IX for bug-gnu-emacs@gnu.org; Mon, 14 Feb 2011 02:03:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PosSh-000291-HE for bug-gnu-emacs@gnu.org; Mon, 14 Feb 2011 02:03:08 -0500 Received: from ibar.cds.caltech.edu ([131.215.42.49]:55646) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PosSh-00027P-5G for bug-gnu-emacs@gnu.org; Mon, 14 Feb 2011 02:03:07 -0500 Received: from smart (cpe-76-175-234-46.socal.res.rr.com [76.175.234.46]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by ibar.cds.caltech.edu (Postfix) with ESMTP id 16DE6BA81F7 for ; Sun, 13 Feb 2011 23:03:01 -0800 (PST) Date: Sun, 13 Feb 2011 23:02:57 -0800 From: Dima Kogan Message-ID: <20110213230257.784a9843@smart> X-Mailer: Claws Mail 3.7.6 (GTK+ 2.20.1; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/FpMwibEevf+++6Yh2XCaGd5" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 131.215.42.49 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 199.232.76.165 X-Spam-Score: -6.6 (------) X-Mailman-Approved-At: Mon, 14 Feb 2011 03:37:16 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -6.6 (------) --MP_/FpMwibEevf+++6Yh2XCaGd5 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 --MP_/FpMwibEevf+++6Yh2XCaGd5 Content-Type: application/x-perl Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=unbalanced-braces-test.pl IyEvdXNyL2Jpbi9wZXJsCgp1c2Ugc3RyaWN0OwoKIyBsZWZ0IGJyYWNlIGluc2lkZSBjb21tZW50 cyB7IGNhdXNlIGVycm9yCnN1YiBibGFibGEgewoJZm9yIChteSAkaSA9IDA7ICRpIDwgMTA7ICRp KyspIHsKCQlwcmludGYoIlwkaSBpcyAlZFxuIiwgJGkpOwoJfQp9Cgo= --MP_/FpMwibEevf+++6Yh2XCaGd5 Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=hs.patch --- 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) --MP_/FpMwibEevf+++6Yh2XCaGd5-- From unknown Sun Jun 22 08:04:18 2025 X-Loop: help-debbugs@gnu.org Subject: bug#8036: Acknowledgement ([PATCH] Prevent hide-show mode from getting confused by braces in comments) Resent-From: Dima Kogan Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 15 Feb 2011 04:12:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 8036 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 8036@debbugs.gnu.org Received: via spool by 8036-submit@debbugs.gnu.org id=B8036.129774310724743 (code B ref 8036); Tue, 15 Feb 2011 04:12:02 +0000 Received: (at 8036) by debbugs.gnu.org; 15 Feb 2011 04:11:47 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PpCGR-0006R2-7A for submit@debbugs.gnu.org; Mon, 14 Feb 2011 23:11:47 -0500 Received: from ibar.cds.caltech.edu ([131.215.42.49]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PpCGN-0006Qo-SG for 8036@debbugs.gnu.org; Mon, 14 Feb 2011 23:11:45 -0500 Received: from smart (cpe-76-175-234-46.socal.res.rr.com [76.175.234.46]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by ibar.cds.caltech.edu (Postfix) with ESMTP id DCECEBA8276 for <8036@debbugs.gnu.org>; Mon, 14 Feb 2011 20:20:39 -0800 (PST) Date: Mon, 14 Feb 2011 20:20:38 -0800 From: Dima Kogan Message-ID: <20110214202038.4dc03ccc@smart> In-Reply-To: References: <20110213230257.784a9843@smart> X-Mailer: Claws Mail 3.7.6 (GTK+ 2.20.1; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/wao/WWZRLIu=tMb33Zg7r1y" X-Spam-Score: -4.6 (----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -3.9 (---) --MP_/wao/WWZRLIu=tMb33Zg7r1y Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline 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. --MP_/wao/WWZRLIu=tMb33Zg7r1y Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=hideshow-comments.patch --- 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) --MP_/wao/WWZRLIu=tMb33Zg7r1y-- From unknown Sun Jun 22 08:04:18 2025 X-Loop: help-debbugs@gnu.org Subject: bug#8036: [PATCH] Prevent hide-show mode from getting confused by braces in comments Resent-From: Dima Kogan Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 16 Feb 2011 04:54:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 8036 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 8036@debbugs.gnu.org Received: via spool by 8036-submit@debbugs.gnu.org id=B8036.129783198329874 (code B ref 8036); Wed, 16 Feb 2011 04:54:02 +0000 Received: (at 8036) by debbugs.gnu.org; 16 Feb 2011 04:53:03 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PpZNv-0007ln-3H for submit@debbugs.gnu.org; Tue, 15 Feb 2011 23:53:03 -0500 Received: from ibar.cds.caltech.edu ([131.215.42.49]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PpZNt-0007lK-HK for 8036@debbugs.gnu.org; Tue, 15 Feb 2011 23:53:02 -0500 Received: from smart (cpe-76-175-234-46.socal.res.rr.com [76.175.234.46]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by ibar.cds.caltech.edu (Postfix) with ESMTP id 06AE0BA81F7 for <8036@debbugs.gnu.org>; Tue, 15 Feb 2011 21:02:00 -0800 (PST) Date: Tue, 15 Feb 2011 21:01:59 -0800 From: Dima Kogan Message-ID: <20110215210159.4ea00047@smart> In-Reply-To: References: <20110213230257.784a9843@smart> X-Mailer: Claws Mail 3.7.6 (GTK+ 2.20.1; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/0L_ZWdUQ=D0WBot6KcStFul" X-Spam-Score: -3.6 (---) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -3.4 (---) --MP_/0L_ZWdUQ=D0WBot6KcStFul Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline I have discovered a case where the previous patch causes an infinite loop. The new patch I'm attaching resolves that issue --MP_/0L_ZWdUQ=D0WBot6KcStFul Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=hideshow-comments.patch --- 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) --MP_/0L_ZWdUQ=D0WBot6KcStFul-- From unknown Sun Jun 22 08:04:18 2025 X-Loop: help-debbugs@gnu.org Subject: bug#8036: [PATCH] Prevent hide-show mode from getting confused by braces in comments Resent-From: Chong Yidong Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 19 Feb 2011 22:21:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 8036 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Dima Kogan Cc: 8036@debbugs.gnu.org Received: via spool by 8036-submit@debbugs.gnu.org id=B8036.12981540543781 (code B ref 8036); Sat, 19 Feb 2011 22:21:03 +0000 Received: (at 8036) by debbugs.gnu.org; 19 Feb 2011 22:20:54 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PqvAb-0000yv-VH for submit@debbugs.gnu.org; Sat, 19 Feb 2011 17:20:54 -0500 Received: from vm-emlprdomr-04.its.yale.edu ([130.132.50.145]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PqvAZ-0000yk-Hd for 8036@debbugs.gnu.org; Sat, 19 Feb 2011 17:20:52 -0500 Received: from furball ([64.134.67.165]) (authenticated bits=0) by vm-emlprdomr-04.its.yale.edu (8.14.4/8.14.4) with ESMTP id p1JMKhUT015253 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sat, 19 Feb 2011 17:20:44 -0500 Received: by furball (Postfix, from userid 1000) id 240AB16081E; Sat, 19 Feb 2011 17:20:44 -0500 (EST) From: Chong Yidong References: <20110213230257.784a9843@smart> <20110215210159.4ea00047@smart> Date: Sat, 19 Feb 2011 17:20:43 -0500 In-Reply-To: <20110215210159.4ea00047@smart> (Dima Kogan's message of "Tue, 15 Feb 2011 21:01:59 -0800") Message-ID: <87r5b3vf7o.fsf@stupidchicken.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.71 on 130.132.50.145 X-Spam-Score: -2.6 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.6 (--) Dima Kogan 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. From debbugs-submit-bounces@debbugs.gnu.org Sat Feb 19 17:21:02 2011 Received: (at control) by debbugs.gnu.org; 19 Feb 2011 22:21:02 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PqvAk-0000zN-M7 for submit@debbugs.gnu.org; Sat, 19 Feb 2011 17:21:02 -0500 Received: from vm-emlprdomr-06.its.yale.edu ([130.132.50.147]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1PqvAi-0000z3-KO for control@debbugs.gnu.org; Sat, 19 Feb 2011 17:21:00 -0500 Received: from furball ([64.134.67.165]) (authenticated bits=0) by vm-emlprdomr-06.its.yale.edu (8.14.4/8.14.4) with ESMTP id p1JMKscv015101 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Sat, 19 Feb 2011 17:20:55 -0500 Received: by furball (Postfix, from userid 1000) id 118F216081E; Sat, 19 Feb 2011 17:20:55 -0500 (EST) From: Chong Yidong To: control@debbugs.gnu.org Subject: close 8036 Date: Sat, 19 Feb 2011 17:20:54 -0500 Message-ID: <8762sf4qex.fsf@stupidchicken.com> MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.71 on 130.132.50.147 X-Spam-Score: -2.6 (--) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.6 (--) close 8036 thanks