regex - Match one backlash; match two backslashes; match tilde + two backslashes -
i'm interested in seeing if possible match 1 backslash, , 2 backslashes, , tilde plus 2 backslashes. i'm using emacs in latex-mode , setting keywords font-lock. defining single backslash keyword wreaks havoc on variety of other definitions. i'd 1 backslash red; 2 backslashes blue; , tilde+two-back-slashes green. don't think tilde pose problem, i'd red itself. i've got font-lock-add-keywords format, not special regex type of situation. similar situation use \b before , after, won't work backslashes far know.
~
-- red
\
-- red, except
when touching alphanumeric characters.
\\
-- blue
~\\
-- green
(defvar lawlist-face-a (make-face 'lawlist-face-a)) (set-face-attribute 'lawlist-face-a nil :foreground "red" :bold t) (defvar lawlist-face-b (make-face 'lawlist-face-b)) (set-face-attribute 'lawlist-face-b nil :foreground "blue" :bold t) (defvar lawlist-face-c (make-face 'lawlist-face-c)) (set-face-attribute 'lawlist-face-c nil :foreground "green" :bold t) (font-lock-add-keywords 'latex-mode '( ("~\\|\\\\" 0 lawlist-face-a prepend) ("\\\\\\\\" 0 lawlist-face-b prepend) ("~\\\\\\\\" 0 lawlist-face-c prepend) ))
in context of example mentioned above, defining single backslash nullifies predefined warnings of font-latex.el
within auctex-11.86
@ lines 280-285. removing "\\"
fourth line of code doesn't remedy situation. typing \newpage
, example, no longer associated font-latex-warning-face
-- instead, comes undefined, assigned font-latex-sedate-face
.
(defvar font-latex-built-in-keyword-classes '(("warning" ("nopagebreak" "pagebreak" "newpage" "clearpage" "cleardoublepage" "enlargethispage" "nolinebreak" "linebreak" "newline" "-" "\\*" "\\" "appendix" "displaybreak" "allowdisplaybreaks" "include") 'font-latex-warning-face 1 noarg)
buffer example -- latex-mode:
\newpage
-- font face should font-latex-warning-face
\newpage
-- font face erroneously appears font-latex-sedate-face
when defining single backslash noted hereinabove.
edit -- troubleshooting -- testing -- screenshots of re-builder
, latex document:
\\(\\\\\\)[^a-za-z@]
re-builder http://www.lawlist.com/images/re-builder_01.png
test01 http://www.lawlist.com/images/test01.png
(defvar lawlist-face-a (make-face 'lawlist-face-a)) (set-face-attribute 'lawlist-face-a nil :background "black" :foreground "red" :bold t) (defvar lawlist-face-b (make-face 'lawlist-face-b)) (set-face-attribute 'lawlist-face-b nil :foreground "blue" :bold t) (defvar lawlist-face-c (make-face 'lawlist-face-c)) (set-face-attribute 'lawlist-face-c nil :foreground "green" :bold t) (font-lock-add-keywords 'latex-mode '(("~\\|\\(\\\\\\)[^a-za-z@]" 0 lawlist-face-a prepend) ("\\\\\\\\" 0 lawlist-face-b prepend) ("~\\\\\\\\" 0 lawlist-face-c prepend)))
latex commands can composed of letters (and @
symbol in libraries). therefore sufficient following distinguish between single slash , beginning of command:
(defvar lawlist-face-a (make-face 'lawlist-face-a)) (set-face-attribute 'lawlist-face-a nil :foreground "red" :bold t) (defvar lawlist-face-b (make-face 'lawlist-face-b)) (set-face-attribute 'lawlist-face-b nil :foreground "blue" :bold t) (defvar lawlist-face-c (make-face 'lawlist-face-c)) (set-face-attribute 'lawlist-face-c nil :foreground "green" :bold t) (font-lock-add-keywords 'latex-mode '(("~" 0 lawlist-face-a prepend) ("\\(\\\\\\)[^a-za-z@]" 1 lawlist-face-a prepend) ("\\\\\\\\" 0 lawlist-face-b prepend) ("~\\\\\\\\" 0 lawlist-face-c prepend)))
Comments
Post a Comment