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

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

Re: changing visuals of code in emacs


From: Andrei Alexandrescu
Subject: Re: changing visuals of code in emacs
Date: Sun, 12 Oct 2008 16:06:24 -0500
User-agent: Thunderbird 2.0.0.17 (X11/20080925)

Pascal J. Bourguignon wrote:
Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> writes:

Hello,


I'd like to change code visuals for the D programming language as
follows. I'd like the construct:

Symbol!(balanced_parens)

to be visualized as:

Symbol«balanced_parens»

The chevrons should appear electrically when I type the closing
")". Note that balanced_parens could in turn nested use of "!()", as
in A!(B!(C)), and they should all be paired using chevrons. The
underlying file should not contain the chevrons, just the ASCII
representation using "!(" and ")".

I haven't done much elisp programming beyond the common .emacs
configuration tricks, so I don't know where to start. A few searches
suggested that overlays may be what I'm looking for... any ideas and
pointers? Thank you.

If you didn't ask for recursion, this could have be done with
font-locking.

(font-lock-add-keywords nil
'(("\\(!(\\)[^()]*\\()\\)" 0 (progn
         (compose-region (match-beginning 1) (match-end 1) ?« 'decompose-region)
         (compose-region (match-beginning 2) (match-end 2) ?» 'decompose-region)
         nil))))

But since this uses regular expressions, it won't work for recursive
!(...).


You can still use compose-region, but you'll have to implement the
parsing yourself.  Perhaps this could be hooked on the code doing the
parenthesis balancing?

I think I'd be happy with a nonrecursive region to get my feet wet. How do I use your font-lock-add-keywords code? I added it to both my .emacs and my d-mode.el file, to no avail.

Thank you,

Andrei


reply via email to

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