* changing visuals of code in emacs
@ 2008-10-12 20:11 Andrei Alexandrescu
2008-10-12 20:48 ` Pascal J. Bourguignon
0 siblings, 1 reply; 5+ messages in thread
From: Andrei Alexandrescu @ 2008-10-12 20:11 UTC (permalink / raw
To: help-gnu-emacs
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.
Andrei
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: changing visuals of code in emacs
2008-10-12 20:11 changing visuals of code in emacs Andrei Alexandrescu
@ 2008-10-12 20:48 ` Pascal J. Bourguignon
2008-10-12 21:06 ` Andrei Alexandrescu
0 siblings, 1 reply; 5+ messages in thread
From: Pascal J. Bourguignon @ 2008-10-12 20:48 UTC (permalink / raw
To: help-gnu-emacs
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?
--
__Pascal Bourguignon__ http://www.informatimago.com/
You never feed me.
Perhaps I'll sleep on your face.
That will sure show you.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: changing visuals of code in emacs
2008-10-12 20:48 ` Pascal J. Bourguignon
@ 2008-10-12 21:06 ` Andrei Alexandrescu
2008-10-12 21:44 ` Pascal J. Bourguignon
0 siblings, 1 reply; 5+ messages in thread
From: Andrei Alexandrescu @ 2008-10-12 21:06 UTC (permalink / raw
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: changing visuals of code in emacs
2008-10-12 21:06 ` Andrei Alexandrescu
@ 2008-10-12 21:44 ` Pascal J. Bourguignon
2008-10-12 22:18 ` Andrei Alexandrescu
0 siblings, 1 reply; 5+ messages in thread
From: Pascal J. Bourguignon @ 2008-10-12 21:44 UTC (permalink / raw
To: help-gnu-emacs
Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> writes:
> 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.
You could run it from a d-mode-hook if it exists, ensuring that
font-lock-mode is enabled.
(add-hook 'd-mode-hook
(lambda ()
(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))))
(font-lock-mode 1)))
--
__Pascal Bourguignon__ http://www.informatimago.com/
Pour moi, la grande question n'a jamais été: «Qui suis-je? Où vais-je?»
comme l'a formulé si adroitement notre ami Pascal, mais plutôt:
«Comment vais-je m'en tirer?» -- Jean Yanne
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: changing visuals of code in emacs
2008-10-12 21:44 ` Pascal J. Bourguignon
@ 2008-10-12 22:18 ` Andrei Alexandrescu
0 siblings, 0 replies; 5+ messages in thread
From: Andrei Alexandrescu @ 2008-10-12 22:18 UTC (permalink / raw
To: help-gnu-emacs
Pascal J. Bourguignon wrote:
> Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> writes:
>
>> 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.
>
> You could run it from a d-mode-hook if it exists, ensuring that
> font-lock-mode is enabled.
>
> (add-hook 'd-mode-hook
> (lambda ()
> (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))))
> (font-lock-mode 1)))
>
Thanks! I got that working. It ought to get me started.
Regards,
Andrei
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-10-12 22:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-12 20:11 changing visuals of code in emacs Andrei Alexandrescu
2008-10-12 20:48 ` Pascal J. Bourguignon
2008-10-12 21:06 ` Andrei Alexandrescu
2008-10-12 21:44 ` Pascal J. Bourguignon
2008-10-12 22:18 ` Andrei Alexandrescu
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.