From 45fd731c4dcba0db0ac7e8f4a12d30274396eac7 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Tue, 17 Jul 2012 04:11:31 -0400 Subject: [PATCH] * lisp/textmodes/tex-mode.el (tex-font-lock-keywords-1): Highlight not only $$..$$ but also $..$ using regexps. Use tex-verbatim for \url and \path. (tex-font-lock-keywords): Define as defconst like the others. (tex-common-initialization): Don't use font-lock-syntax-table any more. * test/indent/latex-mode.tex: New file. Fixes: debbugs:11953 --- lisp/ChangeLog | 24 ++++++++---- lisp/textmodes/tex-mode.el | 75 ++++++++++++++++++++------------------ test/ChangeLog | 4 ++ test/indent/latex-mode.tex | 11 ++++++ 4 files changed, 71 insertions(+), 43 deletions(-) create mode 100644 test/indent/latex-mode.tex diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 6606940740c..709daf405a7 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,11 @@ +2012-07-17 Stefan Monnier + + * textmodes/tex-mode.el (tex-font-lock-keywords-1): Highlight not only + $$..$$ but also $..$ using regexps (bug#11953). + Use tex-verbatim for \url and \path. + (tex-font-lock-keywords): Define as defconst like the others. + (tex-common-initialization): Don't use font-lock-syntax-table any more. + 2012-07-16 René Kyllingstad (tiny change) * international/mule-cmds.el (ucs-insert): Make it an obsolete @@ -14,8 +22,8 @@ Remove vars. (python-nav-list-defun-positions, python-nav-read-defun) (python-imenu-tree-assoc, python-imenu-make-element-tree) - (python-imenu-make-tree, python-imenu-create-index): Remove - functions. + (python-imenu-make-tree, python-imenu-create-index): + Remove functions. (python-mode): Update to interact with imenu by setting `imenu-extract-index-name-function' only. @@ -56,8 +64,8 @@ (xterm-mouse-event): New arg specifying mouse protocol. (turn-on-xterm-mouse-tracking-on-terminal) (turn-off-xterm-mouse-tracking-on-terminal): Send DEC 1006 - sequence to toggle extended coordinates on newer XTerms. This - appears to be harmless on terminals which do not support this. + sequence to toggle extended coordinates on newer XTerms. + This appears to be harmless on terminals which do not support this. 2012-07-14 Leo Liu @@ -81,8 +89,8 @@ 2012-07-14 Chong Yidong - * bindings.el: Consolidate ctl-x-r-map bindings. Bind - copy-rectangle-as-kill to C-x r w. + * bindings.el: Consolidate ctl-x-r-map bindings. + Bind copy-rectangle-as-kill to C-x r w. * rect.el, register.el: Move bindings to bindings.el. @@ -123,8 +131,8 @@ Remove toggle-read-only. * bs.el (bs-toggle-readonly): - * buff-menu.el (Buffer-menu-toggle-read-only): Remove - with-no-warnings around toggle-read-only. + * buff-menu.el (Buffer-menu-toggle-read-only): + Remove with-no-warnings around toggle-read-only. * ffap.el (ffap--toggle-read-only): Accept a list of buffers. Remove with-no-warnings around toggle-read-only. diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el index a0e282c6fcc..5571af1ad9b 100644 --- a/lisp/textmodes/tex-mode.el +++ b/lisp/textmodes/tex-mode.el @@ -476,46 +476,51 @@ An alternative value is \" . \", if you use a font with a narrow period." '("input" "include" "includeonly" "bibliography" "epsfig" "psfig" "epsf" "nofiles" "usepackage" "documentstyle" "documentclass" "verbatiminput" - "includegraphics" "includegraphics*" - "url" "nolinkurl") + "includegraphics" "includegraphics*") t)) + (verbish (regexp-opt '("url" "nolinkurl" "path") t)) ;; Miscellany. (slash "\\\\") (opt " *\\(\\[[^]]*\\] *\\)*") ;; This would allow highlighting \newcommand\CMD but requires ;; adapting subgroup numbers below. ;; (arg "\\(?:{\\(\\(?:[^{}\\]+\\|\\\\.\\|{[^}]*}\\)+\\)\\|\\\\[a-z*]+\\)")) - (arg "{\\(\\(?:[^{}\\]+\\|\\\\.\\|{[^}]*}\\)+\\)")) - (list - ;; display $$ math $$ - ;; We only mark the match between $$ and $$ because the $$ delimiters - ;; themselves have already been marked (along with $..$) by syntactic - ;; fontification. Also this is done at the very beginning so as to - ;; interact with the other keywords in the same way as $...$ does. - (list "\\$\\$\\([^$]+\\)\\$\\$" 1 'tex-math-face) - ;; Heading args. - (list (concat slash headings "\\*?" opt arg) - ;; If ARG ends up matching too much (if the {} don't match, e.g.) - ;; jit-lock will do funny things: when updating the buffer - ;; the re-highlighting is only done locally so it will just - ;; match the local line, but defer-contextually will - ;; match more lines at a time, so ARG will end up matching - ;; a lot more, which might suddenly include a comment - ;; so you get things highlighted bold when you type them - ;; but they get turned back to normal a little while later - ;; because "there's already a face there". - ;; Using `keep' works around this un-intuitive behavior as well - ;; as improves the behavior in the very rare case where you do - ;; have a comment in ARG. - 3 'font-lock-function-name-face 'keep) - (list (concat slash "\\(?:provide\\|\\(?:re\\)?new\\)command\\** *\\(\\\\[A-Za-z@]+\\)") - 1 'font-lock-function-name-face 'keep) - ;; Variable args. - (list (concat slash variables " *" arg) 2 'font-lock-variable-name-face) - ;; Include args. - (list (concat slash includes opt arg) 3 'font-lock-builtin-face) - ;; Definitions. I think. - '("^[ \t]*\\\\def *\\\\\\(\\(\\w\\|@\\)+\\)" + (inbraces-re (lambda (re) + (concat "\\(?:[^{}\\]\\|\\\\.\\|" re "\\)"))) + (arg (concat "{\\(" (funcall inbraces-re "{[^}]*}") "+\\)"))) + `( ;; Highlight $$math$$ and $math$. + ;; This is done at the very beginning so as to interact with the other + ;; keywords in the same way as comments and strings. + (,(concat "\\$\\$?\\(?:[^$\\{}]\\|\\\\.\\|{" + (funcall inbraces-re + (concat "{" (funcall inbraces-re "{[^}]*}") "*}")) + "*}\\)+\\$?\\$") + (0 tex-math-face)) + ;; Heading args. + (,(concat slash headings "\\*?" opt arg) + ;; If ARG ends up matching too much (if the {} don't match, e.g.) + ;; jit-lock will do funny things: when updating the buffer + ;; the re-highlighting is only done locally so it will just + ;; match the local line, but defer-contextually will + ;; match more lines at a time, so ARG will end up matching + ;; a lot more, which might suddenly include a comment + ;; so you get things highlighted bold when you type them + ;; but they get turned back to normal a little while later + ;; because "there's already a face there". + ;; Using `keep' works around this un-intuitive behavior as well + ;; as improves the behavior in the very rare case where you do + ;; have a comment in ARG. + 3 font-lock-function-name-face keep) + (,(concat slash "\\(?:provide\\|\\(?:re\\)?new\\)command\\** *\\(\\\\[A-Za-z@]+\\)") + 1 font-lock-function-name-face keep) + ;; Variable args. + (,(concat slash variables " *" arg) 2 font-lock-variable-name-face) + ;; Include args. + (,(concat slash includes opt arg) 3 font-lock-builtin-face) + ;; Verbatim-like args. + (,(concat slash verbish opt arg) 3 'tex-verbatim) + ;; Definitions. I think. + ("^[ \t]*\\\\def *\\\\\\(\\(\\w\\|@\\)+\\)" 1 font-lock-function-name-face)))) "Subdued expressions to highlight in TeX modes.") @@ -629,7 +634,7 @@ An alternative value is \" . \", if you use a font with a narrow period." (1 (tex-font-lock-suscript (match-beginning 0)) append)))) "Experimental expressions to highlight in TeX modes.") -(defvar tex-font-lock-keywords tex-font-lock-keywords-1 +(defconst tex-font-lock-keywords tex-font-lock-keywords-1 "Default expressions to highlight in TeX modes.") (defvar tex-verbatim-environments @@ -1219,7 +1224,7 @@ Entering SliTeX mode runs the hook `text-mode-hook', then the hook (set (make-local-variable 'font-lock-defaults) '((tex-font-lock-keywords tex-font-lock-keywords-1 tex-font-lock-keywords-2 tex-font-lock-keywords-3) - nil nil ((?$ . "\"")) nil + nil nil nil nil ;; Who ever uses that anyway ??? (font-lock-mark-block-function . mark-paragraph) (font-lock-syntactic-face-function diff --git a/test/ChangeLog b/test/ChangeLog index 489298dbebe..ce7e2f02284 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,7 @@ +2012-07-17 Stefan Monnier + + * indent/latex-mode.tex: New file. + 2012-07-11 Stefan Monnier * eshell.el: Use cl-lib. diff --git a/test/indent/latex-mode.tex b/test/indent/latex-mode.tex new file mode 100644 index 00000000000..55c8e7033bd --- /dev/null +++ b/test/indent/latex-mode.tex @@ -0,0 +1,11 @@ +\documentclass{article} % -*- eval: (bug-reference-mode 1) -*- + +\usepackage[utf8]{inputenc} + +\begin{document} + +To fix this, remove the \url{sn9c102.ko} from where it appears in +\url{/lib/modules/$(uname -r)}, %bug#11953. +and install the appropriate \url{gspca-modules} package. + +\end{document} -- 2.39.2