[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#11953: 23.4; tex-mode does not fontify \url{foo/$(bar)} correctly
From: |
Stefan Monnier |
Subject: |
bug#11953: 23.4; tex-mode does not fontify \url{foo/$(bar)} correctly |
Date: |
Tue, 17 Jul 2012 04:11:08 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux) |
> The latex-mode fontifier is not aware that the (nonstandard)
> \url{...} and \path{...} commands should have their contents treated
> as if verbatim. Here's an example that sends fontification around
> the bend (key text on middle line):
> To fix this, remove the \url{sn9c102.ko} from where it appears in
> \url{/lib/modules/$(uname -r)},
> and install the appropriate \url{gspca-modules} package.
> N.B. The mode appears aware of the \url command but not the \path
> command. The two commands are provided by the same package and they
> have similar semantics: the arguments may contain characters that are
> 'special' to {\TeX}, but these characters are treated as if verbatim.
I installed a patch in the trunk which fixes your example.
It does not really handle \url specially but instead changes the
handling of $ to be a bit more conservative.
So \url{foo$bar$baz} will still highlight "$bar$" with the tex-math
face, for example. But a lone $ should not cause the whole rest of the
document to be mis-fontified any more, or at least much less often.
OTOH it will probably cause some valid $...$ math uses to fail to be
highlighted with the tex-math face.
Stefan
--- lisp/textmodes/tex-mode.el 2012-07-11 23:13:41 +0000
+++ lisp/textmodes/tex-mode.el 2012-07-17 07:59:18 +0000
@@ -476,25 +476,28 @@
'("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)
+ (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.
- (list (concat slash headings "\\*?" opt arg)
+ (,(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
@@ -507,15 +510,17 @@
;; 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)
+ 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.
- (list (concat slash variables " *" arg) 2 'font-lock-variable-name-face)
+ (,(concat slash variables " *" arg) 2 font-lock-variable-name-face)
;; Include args.
- (list (concat slash includes opt arg) 3 'font-lock-builtin-face)
+ (,(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\\|@\\)+\\)"
+ ("^[ \t]*\\\\def *\\\\\\(\\(\\w\\|@\\)+\\)"
1 font-lock-function-name-face))))
"Subdued expressions to highlight in TeX modes.")
@@ -629,7 +634,7 @@
(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 @@
(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