diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2010-09-18 02:35:00 +0200 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2010-09-18 02:35:00 +0200 |
commit | b879a6e2974d913d0c6dc1e290b2c246d7888b4f (patch) | |
tree | f8d6bc12c185cf77892012bc4052efeb1f95fdc3 /lisp/progmodes/fortran.el | |
parent | 269c197ee9d1c3c0b8c03c278d76a570740dd624 (diff) | |
download | emacs-b879a6e2974d913d0c6dc1e290b2c246d7888b4f.tar.gz |
Fix and improve last syntax-propertize patch
* lisp/emacs-lisp/syntax.el (syntax-propertize-precompile-rules): New macro.
(syntax-propertize-rules): Add var-ref case. Fix offset computation
when adding surrounding \(..\).
* lisp/progmodes/fortran.el (fortran--font-lock-syntactic-keywords): Remove.
(fortran-make-syntax-propertize-function): New function; replaces
fortran-font-lock-syntactic-keywords.
(fortran-mode): Use it.
(fortran-line-length): Use it. Improve interactive spec.
* lisp/progmodes/js.el (js-mode): Fix last change (bug#7054).
* lisp/textmodes/tex-mode.el (tex-syntax-propertize-rules)
(latex-syntax-propertize-rules): New consts; replace
tex-font-lock-syntactic-keywords.
(tex-env-mark, latex-env-before-change): New functions.
(latex-electric-env-pair-mode): New minor mode.
(tex-font-lock-verb): Change arguments; do move point.
(tex-font-lock-syntactic-face-function): Adjust to new verbatim
representation as a form of comment.
(tex-font-lock-keywords-1): Remove workaround, now unneeded.
(doctex-syntax-propertize-rules): New const; replaces
doctex-font-lock-syntactic-keywords.
(tex-common-initialization, doctex-mode): Use syntax-propertize-rules.
Diffstat (limited to 'lisp/progmodes/fortran.el')
-rw-r--r-- | lisp/progmodes/fortran.el | 69 |
1 files changed, 39 insertions, 30 deletions
diff --git a/lisp/progmodes/fortran.el b/lisp/progmodes/fortran.el index daa0fd07364..91cfb646b66 100644 --- a/lisp/progmodes/fortran.el +++ b/lisp/progmodes/fortran.el @@ -483,19 +483,27 @@ The only difference is, it returns t in a case when the default returns nil." "Maximum highlighting for Fortran mode. Consists of level 3 plus all other intrinsics not already highlighted.") -(defvar fortran--font-lock-syntactic-keywords) ;; Comments are real pain in Fortran because there is no way to ;; represent the standard comment syntax in an Emacs syntax table. ;; (We can do so for F90-style). Therefore an unmatched quote in a ;; standard comment will throw fontification off on the wrong track. ;; So we do syntactic fontification with regexps. -(defun fortran-font-lock-syntactic-keywords () - "Return a value for `font-lock-syntactic-keywords' in Fortran mode. -This varies according to the value of `fortran-line-length'. +(defun fortran-make-syntax-propertize-function (line-length) + "Return a value for `syntax-propertize-function' in Fortran mode. +This varies according to the value of LINE-LENGTH. This is used to fontify fixed-format Fortran comments." - `(("^[cd\\*]" 0 (11)) - (,(format "^[^cd\\*\t\n].\\{%d\\}\\([^\n]+\\)" (1- fortran-line-length)) - 1 (11)))) + ;; This results in a non-byte-compiled function. We could pass it through + ;; `byte-compile', but simple benchmarks indicate that it's probably not + ;; worth the trouble (about ½% of slow down). + (eval ;I hate `eval', but it's hard to avoid it here. + `(syntax-propertize-rules + ("^[cd\\*]" (0 "<")) + ;; We mark all chars after line-length as "comment-start", rather than + ;; just the first one. This is so that a closing ' that's past the + ;; line-length will indeed be ignored (and will result in a string that + ;; leaks into subsequent lines). + ((format "^[^cd\\*\t\n].\\{%d\\}\\(.+\\)" (1- line-length)) + (1 "<"))))) (defvar fortran-font-lock-keywords fortran-font-lock-keywords-1 "Default expressions to highlight in Fortran mode.") @@ -889,10 +897,8 @@ with no args, if that value is non-nil." fortran-font-lock-keywords-4) nil t ((?/ . "$/") ("_$" . "w")) fortran-beginning-of-subprogram)) - (set (make-local-variable 'fortran--font-lock-syntactic-keywords) - (fortran-make-syntax-propertize-function)) (set (make-local-variable 'syntax-propertize-function) - (syntax-propertize-via-font-lock fortran--font-lock-syntactic-keywords)) + (fortran-make-syntax-propertize-function fortran-line-length)) (set (make-local-variable 'imenu-case-fold-search) t) (set (make-local-variable 'imenu-generic-expression) fortran-imenu-generic-expression) @@ -912,27 +918,30 @@ with no args, if that value is non-nil." "Set the length of fixed-form Fortran lines to NCHARS. This normally only affects the current buffer, which must be in Fortran mode. If the optional argument GLOBAL is non-nil, it -affects all Fortran buffers, and also the default." - (interactive "p") - (let (new) - (mapc (lambda (buff) - (with-current-buffer buff - (when (eq major-mode 'fortran-mode) - (setq fortran-line-length nchars - fill-column fortran-line-length - new (fortran-make-syntax-propertize-function)) - ;; Refontify only if necessary. - (unless (equal new fortran--font-lock-syntactic-keywords) - (setq fortran--font-lock-syntactic-keywords new) - (setq syntax-propertize-function - (syntax-propertize-via-font-lock new)) - (syntax-ppss-flush-cache (point-min)) - (if font-lock-mode (font-lock-mode 1)))))) +affects all Fortran buffers, and also the default. +If a numeric prefix argument is specified, it will be used as NCHARS, +otherwise is a non-numeric prefix arg is specified, the length will be +provided via the minibuffer, and otherwise the current column is used." + (interactive + (list (cond + ((numberp current-prefix-arg) current-prefix-arg) + (current-prefix-arg + (read-number "Line length: " (default-value 'fortran-line-length))) + (t (current-column))))) + (dolist (buff (if global + (buffer-list) + (list (current-buffer)))) + (with-current-buffer buff + (when (derived-mode-p 'fortran-mode) + (unless (eq fortran-line-length nchars) + (setq fortran-line-length nchars + fill-column fortran-line-length + syntax-propertize-function + (fortran-make-syntax-propertize-function nchars)) + (syntax-ppss-flush-cache (point-min)) + (if font-lock-mode (font-lock-mode 1)))))) (if global - (buffer-list) - (list (current-buffer)))) - (if global - (setq-default fortran-line-length nchars)))) + (setq-default fortran-line-length nchars))) (defun fortran-hack-local-variables () "Fortran mode adds this to `hack-local-variables-hook'." |