From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nikolaj Schumacher Newsgroups: gmane.emacs.help Subject: Re: elisp: Replacing dots in strings (. -> \.) Date: Sun, 08 Jul 2007 15:27:14 +0200 Message-ID: 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 1183901251 22438 80.91.229.12 (8 Jul 2007 13:27:31 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 8 Jul 2007 13:27:31 +0000 (UTC) Cc: Jeronimo Pellegrini 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 15:27:28 2007 connect(): Connection refused 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 1I7WnQ-0002HY-02 for geh-help-gnu-emacs@m.gmane.org; Sun, 08 Jul 2007 15:27:28 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I7WnP-0005P9-Hx for geh-help-gnu-emacs@m.gmane.org; Sun, 08 Jul 2007 09:27:27 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1I7WnB-0005Ob-9F for help-gnu-emacs@gnu.org; Sun, 08 Jul 2007 09:27:13 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1I7Wn9-0005OD-MX for help-gnu-emacs@gnu.org; Sun, 08 Jul 2007 09:27:12 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I7Wn9-0005OA-FB for help-gnu-emacs@gnu.org; Sun, 08 Jul 2007 09:27:11 -0400 Original-Received: from fmmailgate02.web.de ([217.72.192.227]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1I7Wn8-0002pq-Sx for help-gnu-emacs@gnu.org; Sun, 08 Jul 2007 09:27:11 -0400 Original-Received: from smtp05.web.de (fmsmtp05.dlan.cinetic.de [172.20.4.166]) by fmmailgate02.web.de (Postfix) with ESMTP id 53D9C8BCABFC; Sun, 8 Jul 2007 15:27:10 +0200 (CEST) Original-Received: from [89.59.156.30] (helo=wednesday) by smtp05.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.108 #197) id 1I7Wn7-0006tO-00; Sun, 08 Jul 2007 15:27:09 +0200 In-Reply-To: <20070708111051.GA15999@randomnode.info> (Jeronimo Pellegrini's message of "Sun\, 8 Jul 2007 08\:10\:51 -0300") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (darwin) X-Sender: n_schumacher@web.de X-Provags-ID: V01U2FsdGVkX18CAkly3Zc9ahTWYwBX6paPNwfzeJZi4XpBrnEw GUl83kWe8MdeiMXqIuCf+P/1p9Zv7SsOH163AAZW6rTg+WOsYz K5KnZRT1gaJtuf7Eyt0g== X-detected-kernel: Linux 2.4-2.6 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:45540 Archived-At: 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'? > 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. > (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 > 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'. Also, you might want to check out this package of mine: http://nschum.de/src/emacs/highlight-symbol/ regards, Nikolaj Schumacher