[ESS] Highlighting matching parentheses
Marc Schwartz
marc_schwartz at me.com
Sun Apr 26 01:22:20 CEST 2009
On Apr 25, 2009, at 6:05 PM, Frank E Harrell Jr wrote:
> Marc Schwartz wrote:
>> On Apr 25, 2009, at 9:13 AM, Frank E Harrell Jr wrote:
>>> Chris Evans wrote:
>>>> Kevin W sent the following at 24/04/2009 01:20:
>>>>> I have been using show-paren-mode to highlight matching
>>>>> parentheses, but
>>>>> wished that I could highlight more than one par of matching
>>>>> parentheses at a
>>>>> time. (Similar to the way Excel highlights parentheses when
>>>>> editing
>>>>> formulas).
>>>>>
>>>>> I'm excited to report that I have discovered a way to do this
>>>>> and offer the
>>>>> following bit from my .emacs file for your enjoyment.
>>>>>
>>>>> ; Download this into your emacs lisp directory
>>>>> ; http://nschum.de/src/emacs/highlight-parentheses/highlight-parentheses.el
>>>>> (require 'highlight-parentheses)
>>>>> (setq hl-paren-colors '("gold" "IndianRed" "cyan" "green" "orange"
>>>>> "magenta"))
>>>>> (defun hpm-on ()
>>>>> (highlight-parentheses-mode t))
>>>>> (add-hook 'ess-mode-hook 'hpm-on)
>>>>> (add-hook 'inferior-ess-mode-hook 'hpm-on)
>>>>>
>>>>> I think you can add more colors to the list if needed. hl-paren-
>>>>> colors can
>>>>> also be set via customization groups if you want.
>>>>>
>>>>> Kevin Wright
>>>> I not infrequently mess up with parentheses so this sounded very
>>>> good to
>>>> me too, though I wasn't entirely sure what Excel had that was being
>>>> emulated. I had a quick play with Excel and still wasn't that sure.
>>>> However, I think I have installed highlight-parentheses.el
>>>> correctly and
>>>> put those lines (above) where they should be but I'm not seeing
>>>> anything
>>>> different in ESS.
>>>> Could it be that I'm using XEmacs (21.4.21 on Windoze XP sp3)? I
>>>> have
>>>> downloaded highlight-parentheses.el at:
>>>> D:\XEmacs\site-packages\lisp\highlight-parentheses.el
>>>> and put those lines above in
>>>> C:\Documents and Settings\admin\.xemacs\init.el
>>>> which are the appropriate places in XEmacs in my set up I think.
>>>> However, I don't see any change as I say.
>>>> Several questions for people, including, and great thanks to,
>>>> Kevin, but
>>>> also perhaps to fellow XEmacs users.
>>>> 1) what should I see that would indicate that things are working
>>>> (I'll
>>>> put my glasses on!)?
>>>> 2) what could I do that would confirm that XEmacs has loaded
>>>> those lines
>>>> correctly, invoking highlight-parentheses.el?
>>>> TIA and continued thanks to everyone who makes ESS so wonderful.
>>>> Chris
>>>
>>> I installed the new .el file in /usr/share/emacs22/site-lisp/ess
>>> and added the above lines to .emacs, then restarted Emacs22. I
>>> see gold highlighting, but I don't see usage of any of the other
>>> colors listed.
>> Here is a PNG screen grab from OSX using Emacs 23. Copy and paste
>> the following into a buffer:
>> (((((((((Some Text)))))))))
>> Then *move* the cursor along the parens and if all is well, you
>> should see cycling of the colors as you go in or out from one
>> pairing of parens to another.
>> Note that it looks like the color nesting is limited to perhaps
>> five levels as, after that the outer parens are just black.
>> You can ignore the background yellow line highlight, which is not
>> part of this but something else that I do to highlight the current
>> line of the cursor.
>> I slightly modified the above code to add hooks for text and tex
>> modes:
>> (add-hook 'tex-mode-hook 'hpm-on)
>> (add-hook 'text-mode-hook 'hpm-on)
>> and set my colors as:
>> (setq hl-paren-colors '("gold" "red" "blue" "green" "orange"))
>> Also, from what I can tell, this will work with emacs >=22, so
>> those on X[emacs] 21 may not be able to use this.
>> Thanks to Kevin for this.
>> HTH,
>> Marc Schwartz
>> ------------------------------------------------------------------------
>
> Thanks Marc for the improvements and the demo. I see my main
> problem now: I was expecting the color coding to go across lines but
> it only works within a line.
>
> Frank
Frank,
See the attached. It does work across lines, but only the actual
matching parens get colored, not the text or lines in between...my
initial example may have been misleading.
Regards,
Marc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: emacs.png
Type: image/png
Size: 10181 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/ess-help/attachments/20090425/9953c0ab/attachment.png>
-------------- next part --------------
More information about the ESS-help
mailing list