From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: changing visuals of code in emacs Date: Sun, 12 Oct 2008 23:44:25 +0200 Organization: Informatimago Message-ID: <874p3h1oau.fsf@hubble.informatimago.com> References: <878wst1qvn.fsf@hubble.informatimago.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1223851257 13905 80.91.229.12 (12 Oct 2008 22:40:57 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 12 Oct 2008 22:40:57 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Oct 13 00:41:55 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Kp9dK-0007MF-SG for geh-help-gnu-emacs@m.gmane.org; Mon, 13 Oct 2008 00:41:55 +0200 Original-Received: from localhost ([127.0.0.1]:34881 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kp9cE-0002eQ-Vv for geh-help-gnu-emacs@m.gmane.org; Sun, 12 Oct 2008 18:40:47 -0400 Original-Path: news.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!proxad.net!feeder1-2.proxad.net!cleanfeed1-b.proxad.net!nnrp2-2.free.fr!not-for-mail Original-Newsgroups: gnu.emacs.help Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.2 (gnu/linux) Cancel-Lock: sha1:TGIOrtAh3eOz2mpnlHiNv9IunGs= Original-Lines: 62 Original-NNTP-Posting-Date: 12 Oct 2008 23:44:26 MEST Original-NNTP-Posting-Host: 88.182.134.169 Original-X-Trace: 1223847866 news-1.free.fr 14748 88.182.134.169:60181 Original-X-Complaints-To: abuse@proxad.net Original-Xref: news.stanford.edu gnu.emacs.help:163371 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:58711 Archived-At: Andrei Alexandrescu writes: > Pascal J. Bourguignon wrote: >> Andrei Alexandrescu 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