From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jeronimo Pellegrini Newsgroups: gmane.emacs.help Subject: Re: elisp: Replacing dots in strings (. -> \.) Date: Sun, 8 Jul 2007 14:25:01 -0300 Message-ID: <20070708172501.GA6598@randomnode.info> References: <20070708111051.GA15999@randomnode.info> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1183915537 10501 80.91.229.12 (8 Jul 2007 17:25:37 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 8 Jul 2007 17:25:37 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Jul 08 19:25:35 2007 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 1I7aVk-00066Z-S3 for geh-help-gnu-emacs@m.gmane.org; Sun, 08 Jul 2007 19:25:29 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I7aVk-0003ch-45 for geh-help-gnu-emacs@m.gmane.org; Sun, 08 Jul 2007 13:25:28 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1I7aVV-0003bs-TQ for help-gnu-emacs@gnu.org; Sun, 08 Jul 2007 13:25:13 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1I7aVU-0003ZY-E6 for help-gnu-emacs@gnu.org; Sun, 08 Jul 2007 13:25:12 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I7aVU-0003ZP-7S for help-gnu-emacs@gnu.org; Sun, 08 Jul 2007 13:25:12 -0400 Original-Received: from li7-90.members.linode.com ([64.62.231.90] helo=randomnode.info) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1I7aVT-0004K6-NT for help-gnu-emacs@gnu.org; Sun, 08 Jul 2007 13:25:11 -0400 Original-Received: from localhost.randomnode.info (localhost [127.0.0.1]) by randomnode.info (Postfix) with ESMTP id A358242390 for ; Sun, 8 Jul 2007 14:25:10 -0300 (BRT) Original-Received: from 127.0.0.1 by localhost.randomnode.info (amavisd-lite) with LMTP id 1183915510-18405-1 for ; Sun Jul 8 14:25:10 2007 Original-Received: from socrates.dnsalias.org (c925891a.virtua.com.br [201.37.137.26]) by randomnode.info (Postfix) with ESMTP id 1F90A4238A; Sun, 8 Jul 2007 14:25:10 -0300 (BRT) Original-Received: by socrates.dnsalias.org (Postfix, from userid 1001) id 06569741EE; Sun, 8 Jul 2007 14:25:02 -0300 (BRT) Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.16 (2007-06-11) X-detected-kernel: Linux 2.6, seldom 2.4 (older, 4) 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:45543 Archived-At: On Sun, Jul 08, 2007 at 03:27:14PM +0200, Nikolaj Schumacher wrote: > Jeronimo Pellegrini wrote: > > > ;; Adds one symbol to be highlighted as special-face. > > ;; > > (defun add-special-at-point () > > "Adds the symbol at point to the list of symbols to be highlighted > > with special-face." > > (interactive) > > (let ((name (symbol-name (symbol-at-point)))) > > (message name) > > (let ((newname (replace-regexp-in-string "\\." "\\\\." name t t))) > > (font-lock-add-keywords nil `((,name . 'special-face)))))) > > Shouldn't you pass newname instead of name to `font-lock-add-keywords'? Ouch! I read it several times and missed that. > > This doesn't work really well, because when I write a symbol that starts > > with a dot: > > > > .my_special_var > > Beware that `symbol-at-point' will only include that period, if it has > symbol syntax in the current buffer. Yes, that's OK -- I'll use this with Lisp mode. > > (replace-regexp-in-string "\\." "\\\." "aaa . bbb" t t) > > ==> "aaa \\. bbb" > > > > Now, that confuses me since I was explicitly asking the replacement to > > be treated literally. What I am doing wrong? > > You're asking the function to treat the input literally, yet the > backslash has a special meaning while being _parsed_. That is "\\" is a > string with just one backslash. Try `insert' on those results, and > there will be fewer of them. > The reason some of them are missing, is that Emacs apparently ignores > the single backslash in "\.", which is actually undefined Ah, now I see what happened. > > Or, is there an easier way to replace the dots in a string so that > > function will work properly? > > Yes. You're probably looking for `regexp-quote'. And that definetely fixed it. Thanks! > Also, you might want to check out this package of mine: > http://nschum.de/src/emacs/highlight-symbol/ Thanks -- that's also very nice! I see it uses hi-lock, so I'll probably keep my function until I find some time to switch to hi-lock (I use font-lock currently). J.