all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Comment lines and matching parentheses
@ 2010-03-18 20:14 dnquark
  2010-03-18 21:27 ` Alan Mackenzie
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: dnquark @ 2010-03-18 20:14 UTC (permalink / raw)
  To: help-gnu-emacs

What determines whether or not parentheses that are part of comments
are included when performing paren matching?..  For instance, in C
mode, both
  // (
  // )
and
  foo //(
  bar //)
are reported as mismatched parentheses. Similar behavior is observed
in lisp mode.

Is there a way to make emacs ignore all parentheses that are parts of
comments?..  This behavior sometimes breaks hs-minor-mode's ability to
fold code in buffers.


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

* Re: Comment lines and matching parentheses
  2010-03-18 20:14 Comment lines and matching parentheses dnquark
@ 2010-03-18 21:27 ` Alan Mackenzie
  2010-03-19  2:26   ` dnquark
  2010-03-18 21:29 ` David Rogoff
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 7+ messages in thread
From: Alan Mackenzie @ 2010-03-18 21:27 UTC (permalink / raw)
  To: help-gnu-emacs

dnquark <dnquark@gmail.com> wrote:
> What determines whether or not parentheses that are part of comments
> are included when performing paren matching?..  For instance, in C
> mode, both
>  // (
>  // )
> and
>  foo //(
>  bar //)
> are reported as mismatched parentheses. Similar behavior is observed
> in lisp mode.

> Is there a way to make emacs ignore all parentheses that are parts of
> comments?..  This behavior sometimes breaks hs-minor-mode's ability to
> fold code in buffers.

No, there isn't.  A paren in a comment will only balance a matching one
in the same comment.  If you're able and willing to change the source
code, you could rewrite the first example as:
  /* (
     ) */
.

But it sounds more like there's a bug in hs-minor-mode, which you might
"want" to report.

-- 
Alan Mackenzie (Nuremberg, Germany).



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

* Re: Comment lines and matching parentheses
  2010-03-18 20:14 Comment lines and matching parentheses dnquark
  2010-03-18 21:27 ` Alan Mackenzie
@ 2010-03-18 21:29 ` David Rogoff
  2010-03-18 22:43 ` Pascal J. Bourguignon
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: David Rogoff @ 2010-03-18 21:29 UTC (permalink / raw)
  To: help-gnu-emacs

On 2010-03-18 13:14:24 -0700, dnquark said:

> What determines whether or not parentheses that are part of comments
> are included when performing paren matching?..  For instance, in C
> mode, both
>   // (
>   // )
> and
>   foo //(
>   bar //)
> are reported as mismatched parentheses. Similar behavior is observed
> in lisp mode.
> 
> Is there a way to make emacs ignore all parentheses that are parts of
> comments?..  This behavior sometimes breaks hs-minor-mode's ability to
> fold code in buffers.

Yes - I get hit by this in verilog-mode all the time!  I'd love to have 
it ignore parans in comments.




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

* Re: Comment lines and matching parentheses
  2010-03-18 20:14 Comment lines and matching parentheses dnquark
  2010-03-18 21:27 ` Alan Mackenzie
  2010-03-18 21:29 ` David Rogoff
@ 2010-03-18 22:43 ` Pascal J. Bourguignon
  2010-03-18 23:48 ` A.Politz
  2010-03-19  3:46 ` Stefan Monnier
  4 siblings, 0 replies; 7+ messages in thread
From: Pascal J. Bourguignon @ 2010-03-18 22:43 UTC (permalink / raw)
  To: help-gnu-emacs

dnquark <dnquark@gmail.com> writes:

> What determines whether or not parentheses that are part of comments
> are included when performing paren matching?..  For instance, in C
> mode, both
>   // (
>   // )
> and
>   foo //(
>   bar //)
> are reported as mismatched parentheses. Similar behavior is observed
> in lisp mode.
>
> Is there a way to make emacs ignore all parentheses that are parts of
> comments?..  This behavior sometimes breaks hs-minor-mode's ability to
> fold code in buffers.

In lisp-mode (or emacs-lisp-mode), parentheses in comments are not
identified as parentheses to be matched.  The following check-parens
correctly:

(
 ;; (
 ;; ))
 )

And similarly in c-mode (and derived such as c++-mode):

{
    (
     // (
     // ))
     )
    }

check-parens correctly too.


So I don't observe what you're saying.  Here I use emacs-version
"22.3.1", but I never noticed the bad behavior your describe in any
emacs version from 18 to 23, as long as the correct mode is applied to
the buffer.

Now, I don't use hs-minor-mode.  Perhaps this is the problem.  Perhaps
check-parens and other parenthesis balancing code cannot deal with
parentheses that are hidden by hs-minor-mode?


-- 
__Pascal Bourguignon__


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

* Re: Comment lines and matching parentheses
  2010-03-18 20:14 Comment lines and matching parentheses dnquark
                   ` (2 preceding siblings ...)
  2010-03-18 22:43 ` Pascal J. Bourguignon
@ 2010-03-18 23:48 ` A.Politz
  2010-03-19  3:46 ` Stefan Monnier
  4 siblings, 0 replies; 7+ messages in thread
From: A.Politz @ 2010-03-18 23:48 UTC (permalink / raw)
  To: help-gnu-emacs

On Mar 18, 9:14 pm, dnquark <dnqu...@gmail.com> wrote:
> What determines whether or not parentheses that are part of comments
> are included when performing paren matching?..  For instance, in C
> mode, both
>   // (
>   // )
> and
>   foo //(
>   bar //)
> are reported as mismatched parentheses. Similar behavior is observed
> in lisp mode.
>
> Is there a way to make emacs ignore all parentheses that are parts of
> comments?..  This behavior sometimes breaks hs-minor-mode's ability to
> fold code in buffers.

Try to toggle `parse-sexp-ignore-comment', but don't get confused.

-ap


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

* Re: Comment lines and matching parentheses
  2010-03-18 21:27 ` Alan Mackenzie
@ 2010-03-19  2:26   ` dnquark
  0 siblings, 0 replies; 7+ messages in thread
From: dnquark @ 2010-03-19  2:26 UTC (permalink / raw)
  To: help-gnu-emacs

> > Is there a way to make emacs ignore all parentheses that are parts of
> > comments?..  This behavior sometimes breaks hs-minor-mode's ability to
> > fold code in buffers.
>
> No, there isn't.  A paren in a comment will only balance a matching one
> in the same comment.  If you're able and willing to change the source
> code, you could rewrite the first example as:
>   /* (
>      ) */
> .
>
> But it sounds more like there's a bug in hs-minor-mode, which you might
> "want" to report.

Thanks everyone for the replies.  I was basing my definition of
"mismatched parentheses" on whether or not the closing paren resulted
in "mismatched parentheses" message in the echo area.  Despite this
message, check-parens ignores comments, as it should.

The problem indeed appears to be a bug in hs-minor-mode.  It doesn't
handle well the case where commented parens appear on a line that
starts with regular code, e.g.
foo ## (
     ## )
In this case, hs-hide-all results in "scan error: unbalanced
parentheses".  If the lines start with comments, it runs fine (I
believe hs-hide-all handles such lines differently in the first
place).  Looking at the code for hideshow.el, it looks like it simply
searches for open parens using re-search-forward, and doesn't ignore
comments...


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

* Re: Comment lines and matching parentheses
  2010-03-18 20:14 Comment lines and matching parentheses dnquark
                   ` (3 preceding siblings ...)
  2010-03-18 23:48 ` A.Politz
@ 2010-03-19  3:46 ` Stefan Monnier
  4 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2010-03-19  3:46 UTC (permalink / raw)
  To: help-gnu-emacs

> What determines whether or not parentheses that are part of comments
> are included when performing paren matching?..  For instance, in C
> mode, both
>   // (
>   // )
> and
>   foo //(
>   bar //)
> are reported as mismatched parentheses. Similar behavior is observed
> in lisp mode.

The problem is that even though font-lock displays comments and strings
in a particular face, this information is not used by the code that
warns of "mismatched paren".  More specifically, this code always
assumes that point is outside of strings and comments, so any
string/comment boundary between the opening and the matching closing
paren will tend to throw it off.

Arguably, the code should check the "state at point" to see if we're in
a comment (or a string) and if so, only match against parentheses that are
themselves within comments (or strings), just like it correctly ignores
parens in strings and comments when point is not itself in a string or
a comment.  Patches welcome,


        Stefan


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

end of thread, other threads:[~2010-03-19  3:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-18 20:14 Comment lines and matching parentheses dnquark
2010-03-18 21:27 ` Alan Mackenzie
2010-03-19  2:26   ` dnquark
2010-03-18 21:29 ` David Rogoff
2010-03-18 22:43 ` Pascal J. Bourguignon
2010-03-18 23:48 ` A.Politz
2010-03-19  3:46 ` Stefan Monnier

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.