Hello Uwe!
Ar an dara lá de mí Lúnasa, scríobh Uwe Brauer:
[...] The problem is that there at least two constructs which have a
similar starting but different ending, \a an \al.
So I thought I replace
(while (search-forward (car trans-this) nil t)
by
(while (search-forward-regexp (car trans-this) nil t)
And the table
(defvar old2new-trans-tab
'(
("\b\al\b" "\\alpha")
("\b\a\b" "\\\[0.2cm]")))
But it does not work. Does anybody know how to add some
regexp-functionality like word boundaries in the code?
Keep the original translation table, and search like so:
(let* ((trans-this (car trans-tab))
(search-string (concat "\\b" (regexp-quote (car trans-this))
"\\b")))
(while (search-forward-regexp (search-string nil t))
(replace-match (car (cdr trans-this)) t t)))
Part of your problem with your new translation table is that there are
multiple levels of backslash interpretation, in the Lisp reader and in the
regexp engine. If the Lisp reader eats the backslash the regexp code won’t
see it. A workaround is to use raw strings (where backslashes are not
interpreted):
(#r"\b\al\b" "\\alpha")
Or double your backslashes:
("\\b\\al\\b" "\\alpha")
But keeping the original translation table and using #'regexp-quote is much
less likely to introduce bugs.
--
‘Liston operated so fast that he once accidentally amputated an assistant’s
fingers along with a patient’s leg, […] The patient and the assistant both
died of sepsis, and a spectator reportedly died of shock, resulting in the
only known procedure with a 300% mortality.’ (Atul Gawande, NEJM, 2012)
_______________________________________________
XEmacs-Beta mailing list
XEmacs-Beta(a)xemacs.org
http://lists.xemacs.org/mailman/listinfo/xemacs-beta