From: Jeronimo Pellegrini <j_p@aleph0.info>
To: help-gnu-emacs@gnu.org
Subject: Re: elisp: Replacing dots in strings (. -> \.)
Date: Sun, 8 Jul 2007 14:25:01 -0300 [thread overview]
Message-ID: <20070708172501.GA6598@randomnode.info> (raw)
In-Reply-To: <m2fy3zt499.fsf@nschum.de>
On Sun, Jul 08, 2007 at 03:27:14PM +0200, Nikolaj Schumacher wrote:
> Jeronimo Pellegrini <j_p@aleph0.info> 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.
prev parent reply other threads:[~2007-07-08 17:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-08 11:10 elisp: Replacing dots in strings (. -> \.) Jeronimo Pellegrini
2007-07-08 13:27 ` Nikolaj Schumacher
2007-07-08 15:07 ` Eric Hanchrow
2007-07-08 17:25 ` Jeronimo Pellegrini [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070708172501.GA6598@randomnode.info \
--to=j_p@aleph0.info \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.