help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: parens matching not matching all matching parens


From: Arjan Bos
Subject: Re: parens matching not matching all matching parens
Date: Fri, 17 Sep 2004 19:29:34 +0200
User-agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7.3) Gecko/20040910

Greg Hill wrote:

At 9:19 PM +0200 9/16/04, Arjan Bos wrote:

Hi all,

I'm currently developing yet another rich text format writer. And as you might know, RTF is using curly braces a lot. Alas, every now and then, a normal parentheses pops up between a set of matching {}. Both the parens matching colouring and the forward-sexp / backward-sexp can't handle this. How can I (help to) solve this?

An rtf snippet is included here:

{\rtf1\mac\ansicpg10000\uc1
{\*\pnseclvl4\pnlcltr\pnstart1\pnindent720\pnhang{\pntxta )}}}


This is a complete piece of (non-sensical, but correct) rtf. The first `{' matches the last `}'. Only C-M-f jumps from the first `{' to the one-to-last `}'.


I'm wondering if this is a bug or not.

TIA,

Arjan


Arjan,

Personally, I would call it a bug in the 'scan-sexps built-in function, which is called by 'forward-sexp, which is normally bound to "C-M-f". For some reason 'scan-sexps seems to treat a ")" as matching a "{". You might want to submit a bug report, but there is no guanentee the maintainers of Emacs will not call that odd behavior a "feature."

Thanks,
I'll submit a bug.


On the other hand, if you just want to get on with life, you can try putting something like the following code in your .emacs file. The 'defun defines a function that scans forward for the first '(', '[', '<' or '{' following point, whatever it see first, then scans for a matching closing character, ignoring any other characters. The '(setq forward-sexp-function... effectively replaces the guts of 'forward-sexp with the new function, so you will not have to rebind your keystroke. It works in the backward direction as well ("C-M-b").

<snip gone="code"/>


I should warn you, by the way, that I just hacked this code together in a few minutes after work tonight, and have not tested it exhuastively. Let me know if you have any questions or problems.

Greg,

I already had something similar. Looking at the current bracket under point, finding its opposite and start counting the brackets you encounter. Another of the same bracket ups the ante, the opposite pops one from the ante. When the ante is empty, all bets are off, and the bracket is found.

My code isn't perfect, so I will borrow heavily from yours.

Thanks!

--Greg


--
--
If you really want to contact me, then replace the "I see you" text by its three letter accronym, ICU.

Fabricate Diem PVNC, Motto of the Night Watch -- Terry Pratchett

reply via email to

[Prev in Thread] Current Thread [Next in Thread]