From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andrei Alexandrescu Newsgroups: gmane.emacs.help Subject: Re: changing visuals of code in emacs Date: Sun, 12 Oct 2008 17:18:37 -0500 Organization: Computer Science & Engineering, U of Washington, Seattle Message-ID: References: <878wst1qvn.fsf@hubble.informatimago.com> <874p3h1oau.fsf@hubble.informatimago.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1223871643 21390 80.91.229.12 (13 Oct 2008 04:20:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 13 Oct 2008 04:20:43 +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 06:21:42 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 1KpEw6-0002k3-PH for geh-help-gnu-emacs@m.gmane.org; Mon, 13 Oct 2008 06:21:39 +0200 Original-Received: from localhost ([127.0.0.1]:54898 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KpEv1-0000zN-Jh for geh-help-gnu-emacs@m.gmane.org; Mon, 13 Oct 2008 00:20:31 -0400 Original-Newsgroups: gnu.emacs.help Original-Path: news.stanford.edu!newsfeed.stanford.edu!bloom-beacon.mit.edu!micro-heart-of-gold.mit.edu!uw-beaver!news User-Agent: Thunderbird 2.0.0.17 (X11/20080925) In-Reply-To: <874p3h1oau.fsf@hubble.informatimago.com> X-Nntp-Posting-Host: 216.80.148.146 Original-Lines: 62 Original-Xref: news.stanford.edu gnu.emacs.help:163372 X-Mailman-Approved-At: Mon, 13 Oct 2008 00:18:00 -0400 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:58718 Archived-At: Pascal J. Bourguignon wrote: > 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))) > Thanks! I got that working. It ought to get me started. Regards, Andrei