From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#11953: 23.4; tex-mode does not fontify \url{foo/$(bar)} correctly Date: Tue, 17 Jul 2012 04:11:08 -0400 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1342512747 7080 80.91.229.3 (17 Jul 2012 08:12:27 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 17 Jul 2012 08:12:27 +0000 (UTC) Cc: 11953@debbugs.gnu.org To: Norman Ramsey Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jul 17 10:12:26 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Sr2tK-0003dG-6m for geb-bug-gnu-emacs@m.gmane.org; Tue, 17 Jul 2012 10:12:22 +0200 Original-Received: from localhost ([::1]:48023 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sr2tJ-0004bC-Dp for geb-bug-gnu-emacs@m.gmane.org; Tue, 17 Jul 2012 04:12:21 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:58280) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sr2t8-0004b3-3g for bug-gnu-emacs@gnu.org; Tue, 17 Jul 2012 04:12:19 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sr2t1-0006ai-PZ for bug-gnu-emacs@gnu.org; Tue, 17 Jul 2012 04:12:10 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:35652) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sr2t1-0006ae-MD for bug-gnu-emacs@gnu.org; Tue, 17 Jul 2012 04:12:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1Sr2yo-0005pU-AZ for bug-gnu-emacs@gnu.org; Tue, 17 Jul 2012 04:18:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 17 Jul 2012 08:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 11953 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 11953-submit@debbugs.gnu.org id=B11953.134251303622355 (code B ref 11953); Tue, 17 Jul 2012 08:18:02 +0000 Original-Received: (at 11953) by debbugs.gnu.org; 17 Jul 2012 08:17:16 +0000 Original-Received: from localhost ([127.0.0.1]:45198 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Sr2y3-0005oV-Ki for submit@debbugs.gnu.org; Tue, 17 Jul 2012 04:17:16 -0400 Original-Received: from pruche.dit.umontreal.ca ([132.204.246.22]:39260) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Sr2y0-0005oN-8w for 11953@debbugs.gnu.org; Tue, 17 Jul 2012 04:17:13 -0400 Original-Received: from fmsmemgm.homelinux.net (lechon.iro.umontreal.ca [132.204.27.242]) by pruche.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id q6H8B9YN003834; Tue, 17 Jul 2012 04:11:10 -0400 Original-Received: by fmsmemgm.homelinux.net (Postfix, from userid 20848) id 5F940AE508; Tue, 17 Jul 2012 04:11:08 -0400 (EDT) In-Reply-To: (Norman Ramsey's message of "Mon, 16 Jul 2012 14:14:46 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux) X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV4281=0 X-NAI-Spam-Version: 2.2.0.9309 : core <4281> : streams <786055> : uri <1167378> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:62030 Archived-At: > 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