Re: Bug in syntax highlighting
Ralf Angeli <[email protected]> Sun, 27 Mar 2005 12:35:37 +0200
| Newsgroups | gmane.emacs.auc-tex |
|---|---|
| Message-ID | <[email protected]> |
--=-=-=
* Ralf Angeli (2005-03-26) writes:
> AFAICS this is an infinite loop triggered by point not advancing
> inside of the function `font-latex-match-command-with-arguments'. I
> already have a way to prevent the infloop from appearing but have to
> check if it is the right way to fix it.
It should be fixed in CVS now. Thanks for the report.
A note for developers: `font-latex-match-command-with-arguments'
currently can fontify partial matches of such commands. That means,
suppose the macro \foo expects a mandatory argument and you only have
"\foo" in the buffer, it will get fontified. What I'd like it to do
is to fontify it only if the mandatory argument is actually present,
that means if there is "\foo{bar}" in the buffer. I attached a patch
to this message which shows how this could be done. The problem with
it is that it breaks some things which rely on the function being able
to fontify partial matches. For example \item won't get fontified
anymore. Fixing this correctly, would require information about the
arguments a command accepts. You know, that "[{{" thingy mentioned
before. Once we have that, the attached patch might become
interesting again.
--
Ralf
--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment; filename=font-latex.patch
--- font-latex.el 18 Mar 2005 14:48:25 -0000 5.100
+++ font-latex.el 27 Mar 2005 10:10:58 -0000
@@ -1210,7 +1227,8 @@
(skip-chars-forward " \n\t" limit)
(setq kend (point))
;; Optional arguments [...]
- (while (eq (following-char) ?\[)
+ (while (and (< (point) limit)
+ (eq (following-char) ?\[))
(setq sbeg kend)
(save-restriction
;; Restrict to LIMIT.
@@ -1221,18 +1239,27 @@
(setq send (point-max))
(goto-char send))))
;; Mandatory arguments {...}
- (dotimes (i arg-count)
- (skip-chars-forward " \n\t" limit)
- (when (eq (following-char) ?\{)
- (when (= i 0) (setq cbeg (point)))
- (save-restriction
- ;; Restrict to LIMIT.
- (narrow-to-region (point-min) limit)
- (if (font-latex-find-matching-close ?\{ ?\})
- (setq cend (point))
- (setq cache-reset t)
- (setq cend (point-max))
- (goto-char cend)))))
+ (condition-case nil
+ (dotimes (i arg-count)
+ (skip-chars-forward " \n\t" limit)
+ (if (and (< (point) limit)
+ (eq (following-char) ?\{))
+ (progn
+ (when (= i 0) (setq cbeg (point)))
+ (save-restriction
+ ;; Restrict to LIMIT.
+ (narrow-to-region (point-min) limit)
+ (if (font-latex-find-matching-close ?\{ ?\})
+ (setq cend (point))
+ (setq cache-reset t)
+;; (goto-char (point-max))
+ (error "No mandatory argument found"))))
+ (error "No mandatory argument found")))
+ ;; In case no mandatory argument could be found, set the match
+ ;; data to dummy values. We have to return t nevertheless in
+ ;; order to tell font lock that there might still be other
+ ;; macros to be found.
+ (error (setq kend kbeg sbeg kbeg send kbeg cbeg kbeg cend kbeg)))
(store-match-data (list kbeg kend sbeg send cbeg cend))
;; Handle cache
--=-=-=--