From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dima Kogan Newsgroups: gmane.emacs.bugs Subject: bug#8279: [PATCH] More fixes to prevent hide-show from being confused by commented-out braces Date: Fri, 18 Mar 2011 00:33:15 -0700 Message-ID: <20110318003315.788002f0@smart> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/G9ftT4A85K0lXj_Ej5laC15" X-Trace: dough.gmane.org 1300433964 23562 80.91.229.12 (18 Mar 2011 07:39:24 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 18 Mar 2011 07:39:24 +0000 (UTC) To: 8279@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Mar 18 08:39:20 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Q0UHG-00035C-Jh for geb-bug-gnu-emacs@m.gmane.org; Fri, 18 Mar 2011 08:39:20 +0100 Original-Received: from localhost ([127.0.0.1]:56825 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q0UHF-0003Lq-AV for geb-bug-gnu-emacs@m.gmane.org; Fri, 18 Mar 2011 03:39:17 -0400 Original-Received: from [140.186.70.92] (port=37115 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q0UFC-00030Y-H7 for bug-gnu-emacs@gnu.org; Fri, 18 Mar 2011 03:39:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q0UF4-0006al-FK for bug-gnu-emacs@gnu.org; Fri, 18 Mar 2011 03:37:03 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:42713) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q0UF4-0006ah-A7 for bug-gnu-emacs@gnu.org; Fri, 18 Mar 2011 03:37:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1Q0UCA-0007br-Bm; Fri, 18 Mar 2011 03:34:02 -0400 X-Loop: help-debbugs@gnu.org 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: Fri, 18 Mar 2011 07:34:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 8279 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.130043361529216 (code B ref -1); Fri, 18 Mar 2011 07:34:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 18 Mar 2011 07:33:35 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q0UBi-0007bB-Ng for submit@debbugs.gnu.org; Fri, 18 Mar 2011 03:33:35 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q0UBh-0007az-4C for submit@debbugs.gnu.org; Fri, 18 Mar 2011 03:33:34 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q0UBa-00061v-T7 for submit@debbugs.gnu.org; Fri, 18 Mar 2011 03:33:27 -0400 Original-Received: from lists.gnu.org ([199.232.76.165]:43600) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q0UBa-00061i-B5 for submit@debbugs.gnu.org; Fri, 18 Mar 2011 03:33:26 -0400 Original-Received: from [140.186.70.92] (port=36128 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q0UBY-0002Mv-5s for bug-gnu-emacs@gnu.org; Fri, 18 Mar 2011 03:33:25 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q0UBV-00060k-B4 for bug-gnu-emacs@gnu.org; Fri, 18 Mar 2011 03:33:22 -0400 Original-Received: from ibar.cds.caltech.edu ([131.215.42.49]:39596) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q0UBV-00060K-1u for bug-gnu-emacs@gnu.org; Fri, 18 Mar 2011 03:33:21 -0400 Original-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 8427CBA846E for ; Fri, 18 Mar 2011 00:33:17 -0700 (PDT) X-Mailer: Claws Mail 3.7.8 (GTK+ 2.24.0; x86_64-pc-linux-gnu) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Fri, 18 Mar 2011 03:34:02 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:45138 Archived-At: --MP_/G9ftT4A85K0lXj_Ej5laC15 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline 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. --MP_/G9ftT4A85K0lXj_Ej5laC15 Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=0001-hideshow.el-corrected-improper-handling-of-braces-in.patch >From fad432dc00b7ba1103041b9fd87d4adcf4ac7fd1 Mon Sep 17 00:00:00 2001 From: Dima Kogan 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 --MP_/G9ftT4A85K0lXj_Ej5laC15--