comparison lisp/progmodes/fortran.el @ 110403:14dab55b2888

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.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sat, 18 Sep 2010 02:35:00 +0200
parents b10051866f51
children 56b71cddc9c5
comparison
equal deleted inserted replaced
110402:c848ff4a679b 110403:14dab55b2888
481 "sinh" "dsinh" "cosh" "dcosh" "tanh" "dtanh") 481 "sinh" "dsinh" "cosh" "dcosh" "tanh" "dtanh")
482 'paren) "[ \t]*(") '(1 font-lock-builtin-face)))) 482 'paren) "[ \t]*(") '(1 font-lock-builtin-face))))
483 "Maximum highlighting for Fortran mode. 483 "Maximum highlighting for Fortran mode.
484 Consists of level 3 plus all other intrinsics not already highlighted.") 484 Consists of level 3 plus all other intrinsics not already highlighted.")
485 485
486 (defvar fortran--font-lock-syntactic-keywords)
487 ;; Comments are real pain in Fortran because there is no way to 486 ;; Comments are real pain in Fortran because there is no way to
488 ;; represent the standard comment syntax in an Emacs syntax table. 487 ;; represent the standard comment syntax in an Emacs syntax table.
489 ;; (We can do so for F90-style). Therefore an unmatched quote in a 488 ;; (We can do so for F90-style). Therefore an unmatched quote in a
490 ;; standard comment will throw fontification off on the wrong track. 489 ;; standard comment will throw fontification off on the wrong track.
491 ;; So we do syntactic fontification with regexps. 490 ;; So we do syntactic fontification with regexps.
492 (defun fortran-font-lock-syntactic-keywords () 491 (defun fortran-make-syntax-propertize-function (line-length)
493 "Return a value for `font-lock-syntactic-keywords' in Fortran mode. 492 "Return a value for `syntax-propertize-function' in Fortran mode.
494 This varies according to the value of `fortran-line-length'. 493 This varies according to the value of LINE-LENGTH.
495 This is used to fontify fixed-format Fortran comments." 494 This is used to fontify fixed-format Fortran comments."
496 `(("^[cd\\*]" 0 (11)) 495 ;; This results in a non-byte-compiled function. We could pass it through
497 (,(format "^[^cd\\*\t\n].\\{%d\\}\\([^\n]+\\)" (1- fortran-line-length)) 496 ;; `byte-compile', but simple benchmarks indicate that it's probably not
498 1 (11)))) 497 ;; worth the trouble (about ½% of slow down).
498 (eval ;I hate `eval', but it's hard to avoid it here.
499 `(syntax-propertize-rules
500 ("^[cd\\*]" (0 "<"))
501 ;; We mark all chars after line-length as "comment-start", rather than
502 ;; just the first one. This is so that a closing ' that's past the
503 ;; line-length will indeed be ignored (and will result in a string that
504 ;; leaks into subsequent lines).
505 ((format "^[^cd\\*\t\n].\\{%d\\}\\(.+\\)" (1- line-length))
506 (1 "<")))))
499 507
500 (defvar fortran-font-lock-keywords fortran-font-lock-keywords-1 508 (defvar fortran-font-lock-keywords fortran-font-lock-keywords-1
501 "Default expressions to highlight in Fortran mode.") 509 "Default expressions to highlight in Fortran mode.")
502 510
503 (defvar fortran-imenu-generic-expression 511 (defvar fortran-imenu-generic-expression
887 fortran-font-lock-keywords-2 895 fortran-font-lock-keywords-2
888 fortran-font-lock-keywords-3 896 fortran-font-lock-keywords-3
889 fortran-font-lock-keywords-4) 897 fortran-font-lock-keywords-4)
890 nil t ((?/ . "$/") ("_$" . "w")) 898 nil t ((?/ . "$/") ("_$" . "w"))
891 fortran-beginning-of-subprogram)) 899 fortran-beginning-of-subprogram))
892 (set (make-local-variable 'fortran--font-lock-syntactic-keywords)
893 (fortran-make-syntax-propertize-function))
894 (set (make-local-variable 'syntax-propertize-function) 900 (set (make-local-variable 'syntax-propertize-function)
895 (syntax-propertize-via-font-lock fortran--font-lock-syntactic-keywords)) 901 (fortran-make-syntax-propertize-function fortran-line-length))
896 (set (make-local-variable 'imenu-case-fold-search) t) 902 (set (make-local-variable 'imenu-case-fold-search) t)
897 (set (make-local-variable 'imenu-generic-expression) 903 (set (make-local-variable 'imenu-generic-expression)
898 fortran-imenu-generic-expression) 904 fortran-imenu-generic-expression)
899 (set (make-local-variable 'imenu-syntax-alist) '(("_$" . "w"))) 905 (set (make-local-variable 'imenu-syntax-alist) '(("_$" . "w")))
900 (set (make-local-variable 'beginning-of-defun-function) 906 (set (make-local-variable 'beginning-of-defun-function)
910 916
911 (defun fortran-line-length (nchars &optional global) 917 (defun fortran-line-length (nchars &optional global)
912 "Set the length of fixed-form Fortran lines to NCHARS. 918 "Set the length of fixed-form Fortran lines to NCHARS.
913 This normally only affects the current buffer, which must be in 919 This normally only affects the current buffer, which must be in
914 Fortran mode. If the optional argument GLOBAL is non-nil, it 920 Fortran mode. If the optional argument GLOBAL is non-nil, it
915 affects all Fortran buffers, and also the default." 921 affects all Fortran buffers, and also the default.
916 (interactive "p") 922 If a numeric prefix argument is specified, it will be used as NCHARS,
917 (let (new) 923 otherwise is a non-numeric prefix arg is specified, the length will be
918 (mapc (lambda (buff) 924 provided via the minibuffer, and otherwise the current column is used."
919 (with-current-buffer buff 925 (interactive
920 (when (eq major-mode 'fortran-mode) 926 (list (cond
921 (setq fortran-line-length nchars 927 ((numberp current-prefix-arg) current-prefix-arg)
922 fill-column fortran-line-length 928 (current-prefix-arg
923 new (fortran-make-syntax-propertize-function)) 929 (read-number "Line length: " (default-value 'fortran-line-length)))
924 ;; Refontify only if necessary. 930 (t (current-column)))))
925 (unless (equal new fortran--font-lock-syntactic-keywords) 931 (dolist (buff (if global
926 (setq fortran--font-lock-syntactic-keywords new) 932 (buffer-list)
927 (setq syntax-propertize-function 933 (list (current-buffer))))
928 (syntax-propertize-via-font-lock new)) 934 (with-current-buffer buff
929 (syntax-ppss-flush-cache (point-min)) 935 (when (derived-mode-p 'fortran-mode)
930 (if font-lock-mode (font-lock-mode 1)))))) 936 (unless (eq fortran-line-length nchars)
937 (setq fortran-line-length nchars
938 fill-column fortran-line-length
939 syntax-propertize-function
940 (fortran-make-syntax-propertize-function nchars))
941 (syntax-ppss-flush-cache (point-min))
942 (if font-lock-mode (font-lock-mode 1))))))
931 (if global 943 (if global
932 (buffer-list) 944 (setq-default fortran-line-length nchars)))
933 (list (current-buffer))))
934 (if global
935 (setq-default fortran-line-length nchars))))
936 945
937 (defun fortran-hack-local-variables () 946 (defun fortran-hack-local-variables ()
938 "Fortran mode adds this to `hack-local-variables-hook'." 947 "Fortran mode adds this to `hack-local-variables-hook'."
939 (fortran-line-length fortran-line-length)) 948 (fortran-line-length fortran-line-length))
940 949