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: elisp: Replacing dots in strings (. -> \.) Date: Sun, 8 Jul 2007 08:10:51 -0300 Message-ID: <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 1183898265 14427 80.91.229.12 (8 Jul 2007 12:37:45 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 8 Jul 2007 12:37:45 +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 14:37:44 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 1I7W1F-0003s0-Hf for geh-help-gnu-emacs@m.gmane.org; Sun, 08 Jul 2007 14:37:41 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I7W1E-0004dv-Vw for geh-help-gnu-emacs@m.gmane.org; Sun, 08 Jul 2007 08:37:41 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1I7Ug9-0006OK-NC for help-gnu-emacs@gnu.org; Sun, 08 Jul 2007 07:11:49 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1I7Ug8-0006Nw-Vp for help-gnu-emacs@gnu.org; Sun, 08 Jul 2007 07:11:49 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I7Ug8-0006Nq-Oi for help-gnu-emacs@gnu.org; Sun, 08 Jul 2007 07:11:48 -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 1I7Ug8-0001E8-Ap for help-gnu-emacs@gnu.org; Sun, 08 Jul 2007 07:11:48 -0400 Original-Received: from localhost.randomnode.info (localhost [127.0.0.1]) by randomnode.info (Postfix) with ESMTP id 27CA1423BB for ; Sun, 8 Jul 2007 08:11:00 -0300 (BRT) Original-Received: from 127.0.0.1 by localhost.randomnode.info (amavisd-lite) with LMTP id 1183893059-24175-1 for ; Sun Jul 8 08:11:00 2007 Original-Received: from socrates.dnsalias.org (c925891a.virtua.com.br [201.37.137.26]) by randomnode.info (Postfix) with ESMTP id AABE042390; Sun, 8 Jul 2007 08:10:59 -0300 (BRT) Original-Received: by socrates.dnsalias.org (Postfix, from userid 1001) id E1B44741EE; Sun, 8 Jul 2007 08:10:51 -0300 (BRT) Content-Disposition: inline User-Agent: Mutt/1.5.16 (2007-06-11) X-detected-kernel: Linux 2.6, seldom 2.4 (older, 4) X-Mailman-Approved-At: Sun, 08 Jul 2007 08:37:26 -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:45537 Archived-At: Hi. I'm using Emacs 22.1, and while working on my .emacs file I found a problem. I have written functions to add a face to font-lock, and then let me add words to be highlighted with a different color. ;; The new special face: ;; (defface special-face '((t (:foreground "red" :background "black"))) "Special face used to dynamically add words to be highlighted.") (set-face-foreground 'special-face "red") ;; 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)))))) ;; f9 will add the symbol at point: ;; (global-set-key [f9] 'add-special-at-point) This doesn't work really well, because when I write a symbol that starts with a dot: .my_special_var And put it in the list, then Emacs will treat the leading dot as in a regexp, and here: (my_special_var ...) the opening parenthesis would be highlighted also. This seems to be because replace-regexp-in-string is ignoring the :literal argument (I'm guessing). I have tried passing "t" for the "literal" argument in replace-regexp-in-string, and tried several different amounts of backslashes in the replacement string and found something funny: (replace-regexp-in-string "\\." "\." "aaa . bbb" t t) ==> "aaa . bbb" (replace-regexp-in-string "\\." "\\." "aaa . bbb" t t) ==> "aaa \\. bbb" (replace-regexp-in-string "\\." "\\\." "aaa . bbb" t t) ==> "aaa \\. bbb" (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? Or, is there an easier way to replace the dots in a string so that function will work properly? Thanks a lot, J.