comparison lisp/font-lock.el @ 18332:ee997de5b74b

Rearrange custom options. Also enable custom control of Global Font Lock mode.
author Simon Marshall <simon@gnu.org>
date Thu, 19 Jun 1997 08:49:04 +0000
parents 9f9f522cdc27
children 4f630b3e8f43
comparison
equal deleted inserted replaced
18331:6156115816da 18332:ee997de5b74b
234 :load 'lazy-lock 234 :load 'lazy-lock
235 :group 'font-lock) 235 :group 'font-lock)
236 236
237 ;; User variables. 237 ;; User variables.
238 238
239 (defcustom font-lock-verbose (* 0 1024) 239 (defcustom font-lock-maximum-size (* 250 1024)
240 "*If non-nil, means show status messages for buffer fontification. 240 "*Maximum size of a buffer for buffer fontification.
241 If a number, only buffers greater than this size have fontification messages." 241 Only buffers less than this can be fontified when Font Lock mode is turned on.
242 :type '(choice (const :tag "never" nil) 242 If nil, means size is irrelevant.
243 (const :tag "always" t) 243 If a list, each element should be a cons pair of the form (MAJOR-MODE . SIZE),
244 (integer :tag "size")) 244 where MAJOR-MODE is a symbol or t (meaning the default). For example:
245 ((c-mode . 256000) (c++-mode . 256000) (rmail-mode . 1048576))
246 means that the maximum size is 250K for buffers in C or C++ modes, one megabyte
247 for buffers in Rmail mode, and size is irrelevant otherwise."
248 :type '(choice (const :tag "none" nil)
249 (integer :tag "size")
250 (repeat :menu-tag "mode specific" :tag "mode specific"
251 :value ((t . nil))
252 (cons :tag "Instance"
253 (radio :tag "Mode"
254 (const :tag "all" t)
255 (symbol :tag "name"))
256 (radio :tag "Size"
257 (const :tag "none" nil)
258 (integer :tag "size")))))
245 :group 'font-lock) 259 :group 'font-lock)
246 260
247 (defcustom font-lock-maximum-decoration t 261 (defcustom font-lock-maximum-decoration t
248 "*Maximum decoration level for fontification. 262 "*Maximum decoration level for fontification.
249 If nil, use the default decoration (typically the minimum available). 263 If nil, use the default decoration (typically the minimum available).
267 (const :tag "default" nil) 281 (const :tag "default" nil)
268 (const :tag "maximum" t) 282 (const :tag "maximum" t)
269 (integer :tag "level" 1))))) 283 (integer :tag "level" 1)))))
270 :group 'font-lock) 284 :group 'font-lock)
271 285
272 (defcustom font-lock-maximum-size (* 250 1024) 286 (defcustom font-lock-verbose (* 0 1024)
273 "*Maximum size of a buffer for buffer fontification. 287 "*If non-nil, means show status messages for buffer fontification.
274 Only buffers less than this can be fontified when Font Lock mode is turned on. 288 If a number, only buffers greater than this size have fontification messages."
275 If nil, means size is irrelevant. 289 :type '(choice (const :tag "never" nil)
276 If a list, each element should be a cons pair of the form (MAJOR-MODE . SIZE), 290 (const :tag "always" t)
277 where MAJOR-MODE is a symbol or t (meaning the default). For example: 291 (integer :tag "size"))
278 ((c-mode . 256000) (c++-mode . 256000) (rmail-mode . 1048576))
279 means that the maximum size is 250K for buffers in C or C++ modes, one megabyte
280 for buffers in Rmail mode, and size is irrelevant otherwise."
281 :type '(choice (const :tag "none" nil)
282 (integer :tag "size")
283 (repeat :menu-tag "mode specific" :tag "mode specific"
284 :value ((t . nil))
285 (cons :tag "Instance"
286 (radio :tag "Mode"
287 (const :tag "all" t)
288 (symbol :tag "name"))
289 (radio :tag "Size"
290 (const :tag "none" nil)
291 (integer :tag "size")))))
292 :group 'font-lock) 292 :group 'font-lock)
293 293
294 ;; Fontification variables: 294 ;; Fontification variables:
295 295
296 (defvar font-lock-keywords nil 296 (defvar font-lock-keywords nil
797 ;; turned on everywhere. That would not be intuitive or informative because 797 ;; turned on everywhere. That would not be intuitive or informative because
798 ;; loading a file tells you nothing about the feature or how to control it. It 798 ;; loading a file tells you nothing about the feature or how to control it. It
799 ;; would also be contrary to the Principle of Least Surprise. sm. 799 ;; would also be contrary to the Principle of Least Surprise. sm.
800 800
801 (defvar font-lock-buffers nil) ; For remembering buffers. 801 (defvar font-lock-buffers nil) ; For remembering buffers.
802 (defvar global-font-lock-mode nil) 802
803 ;;;###autoload
804 (defun global-font-lock-mode (&optional arg message)
805 "Toggle Global Font Lock mode.
806 With prefix ARG, turn Global Font Lock mode on if and only if ARG is positive.
807 Displays a message saying whether the mode is on or off if MESSAGE is non-nil.
808 Returns the new status of Global Font Lock mode (non-nil means on).
809
810 When Global Font Lock mode is enabled, Font Lock mode is automagically
811 turned on in a buffer if its major mode is one of `font-lock-global-modes'."
812 (interactive "P\np")
813 (let ((off-p (if arg
814 (<= (prefix-numeric-value arg) 0)
815 global-font-lock-mode)))
816 (if off-p
817 (remove-hook 'find-file-hooks 'turn-on-font-lock-if-enabled)
818 (add-hook 'find-file-hooks 'turn-on-font-lock-if-enabled)
819 (add-hook 'post-command-hook 'turn-on-font-lock-if-enabled)
820 (setq font-lock-buffers (buffer-list)))
821 (when message
822 (message "Global Font Lock mode is now %s." (if off-p "OFF" "ON")))
823 (setq global-font-lock-mode (not off-p))))
824
825 ;; Naughty hack. This variable was originally a `defvar' to keep track of
826 ;; whether Global Font Lock mode was turned on or not. As a `defcustom' with
827 ;; special `:set' and `:require' forms, we can provide custom mode control.
828 (defcustom global-font-lock-mode nil
829 "Toggle Global Font Lock mode.
830 When Global Font Lock mode is enabled, Font Lock mode is automagically
831 turned on in a buffer if its major mode is one of `font-lock-global-modes'.
832 You must modify via \\[customize] for this variable to have an effect."
833 :set (lambda (symbol value)
834 (global-font-lock-mode (or value 0)))
835 :type 'boolean
836 :group 'font-lock
837 :require 'font-lock)
803 838
804 (defcustom font-lock-global-modes t 839 (defcustom font-lock-global-modes t
805 "*Modes for which Font Lock mode is automagically turned on. 840 "*Modes for which Font Lock mode is automagically turned on.
806 Global Font Lock mode is controlled by the `global-font-lock-mode' command. 841 Global Font Lock mode is controlled by the `global-font-lock-mode' command.
807 If nil, means no modes have Font Lock mode automatically turned on. 842 If nil, means no modes have Font Lock mode automatically turned on.
816 (set :menu-tag "mode specific" :tag "modes" 851 (set :menu-tag "mode specific" :tag "modes"
817 :value (not) 852 :value (not)
818 (const :tag "Except" not) 853 (const :tag "Except" not)
819 (repeat :inline t (symbol :tag "mode")))) 854 (repeat :inline t (symbol :tag "mode"))))
820 :group 'font-lock) 855 :group 'font-lock)
821
822 ;;;###autoload
823 (defun global-font-lock-mode (&optional arg message)
824 "Toggle Global Font Lock mode.
825 With prefix ARG, turn Global Font Lock mode on if and only if ARG is positive.
826 Displays a message saying whether the mode is on or off if MESSAGE is non-nil.
827 Returns the new status of Global Font Lock mode (non-nil means on).
828
829 When Global Font Lock mode is enabled, Font Lock mode is automagically
830 turned on in a buffer if its major mode is one of `font-lock-global-modes'."
831 (interactive "P\np")
832 (let ((off-p (if arg
833 (<= (prefix-numeric-value arg) 0)
834 global-font-lock-mode)))
835 (if off-p
836 (remove-hook 'find-file-hooks 'turn-on-font-lock-if-enabled)
837 (add-hook 'find-file-hooks 'turn-on-font-lock-if-enabled)
838 (add-hook 'post-command-hook 'turn-on-font-lock-if-enabled)
839 (setq font-lock-buffers (buffer-list)))
840 (when message
841 (message "Global Font Lock mode is now %s." (if off-p "OFF" "ON")))
842 (setq global-font-lock-mode (not off-p))))
843 856
844 (defun font-lock-change-major-mode () 857 (defun font-lock-change-major-mode ()
845 ;; Turn off Font Lock mode if it's on. 858 ;; Turn off Font Lock mode if it's on.
846 (when font-lock-mode 859 (when font-lock-mode
847 (font-lock-mode)) 860 (font-lock-mode))
1589 1602
1590 (defvar font-lock-warning-face 'font-lock-warning-face 1603 (defvar font-lock-warning-face 'font-lock-warning-face
1591 "Face name to use for things that should stand out.") 1604 "Face name to use for things that should stand out.")
1592 1605
1593 ;; Originally face attributes were specified via `font-lock-face-attributes'. 1606 ;; Originally face attributes were specified via `font-lock-face-attributes'.
1594 ;; Users then changed the default face attributes by setting this variable. 1607 ;; Users then changed the default face attributes by setting that variable.
1595 ;; However, we try and be back-compatible and respect its value if set except 1608 ;; However, we try and be back-compatible and respect its value if set except
1596 ;; for faces where M-x customize has been used to save changes for the face. 1609 ;; for faces where M-x customize has been used to save changes for the face.
1597 (when (boundp 'font-lock-face-attributes) 1610 (when (boundp 'font-lock-face-attributes)
1598 (let ((face-attributes font-lock-face-attributes)) 1611 (let ((face-attributes font-lock-face-attributes))
1599 (while face-attributes 1612 (while face-attributes
1888 ;; Control structures. Emacs Lisp forms. 1901 ;; Control structures. Emacs Lisp forms.
1889 (cons (concat 1902 (cons (concat
1890 "(" (regexp-opt 1903 "(" (regexp-opt
1891 '("cond" "if" "while" "catch" "throw" "let" "let*" 1904 '("cond" "if" "while" "catch" "throw" "let" "let*"
1892 "prog" "progn" "progv" "prog1" "prog2" "prog*" 1905 "prog" "progn" "progv" "prog1" "prog2" "prog*"
1906 "closure" "preparse-closure" "make-closure"
1893 "inline" "save-restriction" "save-excursion" 1907 "inline" "save-restriction" "save-excursion"
1894 "save-window-excursion" "save-selected-window" 1908 "save-window-excursion" "save-selected-window"
1895 "save-match-data" "save-current-buffer" "unwind-protect" 1909 "save-match-data" "save-current-buffer" "unwind-protect"
1896 "condition-case" "track-mouse" "dont-compile" 1910 "condition-case" "track-mouse" "dont-compile"
1897 "eval-after-load" "eval-and-compile" "eval-when-compile" 1911 "eval-after-load" "eval-and-compile" "eval-when-compile"
1992 ; ;; not be able to display those fonts. 2006 ; ;; not be able to display those fonts.
1993 ; ("{\\\\bf\\([^}]+\\)}" 1 'bold keep) 2007 ; ("{\\\\bf\\([^}]+\\)}" 1 'bold keep)
1994 ; ("{\\\\\\(em\\|it\\|sl\\)\\([^}]+\\)}" 2 'italic keep) 2008 ; ("{\\\\\\(em\\|it\\|sl\\)\\([^}]+\\)}" 2 'italic keep)
1995 ; ("\\\\\\([a-zA-Z@]+\\|.\\)" . font-lock-keyword-face) 2009 ; ("\\\\\\([a-zA-Z@]+\\|.\\)" . font-lock-keyword-face)
1996 ; ("^[ \t\n]*\\\\def[\\\\@]\\(\\w+\\)" 1 font-lock-function-name-face keep)) 2010 ; ("^[ \t\n]*\\\\def[\\\\@]\\(\\w+\\)" 1 font-lock-function-name-face keep))
1997 ;; Rewritten and extended for LaTeX2e by Ulrik Dickow <dickow@nbi.dk>. 2011 ; ;; Rewritten and extended for LaTeX2e by Ulrik Dickow <dickow@nbi.dk>.
1998 '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}" 2012 ; '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}"
1999 2 font-lock-function-name-face) 2013 ; 2 font-lock-function-name-face)
2000 ("\\\\\\(cite\\|label\\|pageref\\|ref\\){\\([^} \t\n]+\\)}" 2014 ; ("\\\\\\(cite\\|label\\|pageref\\|ref\\){\\([^} \t\n]+\\)}"
2001 2 font-lock-reference-face) 2015 ; 2 font-lock-reference-face)
2002 ("^[ \t]*\\\\def\\\\\\(\\(\\w\\|@\\)+\\)" 1 font-lock-function-name-face) 2016 ; ("^[ \t]*\\\\def\\\\\\(\\(\\w\\|@\\)+\\)" 1 font-lock-function-name-face)
2003 "\\\\\\([a-zA-Z@]+\\|.\\)" 2017 ; "\\\\\\([a-zA-Z@]+\\|.\\)"
2004 ;; It seems a bit dubious to use `bold' and `italic' faces since we might 2018 ; ;; It seems a bit dubious to use `bold' and `italic' faces since we might
2005 ;; not be able to display those fonts. 2019 ; ;; not be able to display those fonts.
2006 ;; LaTeX2e: \emph{This is emphasized}. 2020 ; ;; LaTeX2e: \emph{This is emphasized}.
2007 ("\\\\emph{\\([^}]+\\)}" 1 'italic keep) 2021 ; ("\\\\emph{\\([^}]+\\)}" 1 'italic keep)
2008 ;; LaTeX2e: \textbf{This is bold}, \textit{...}, \textsl{...} 2022 ; ;; LaTeX2e: \textbf{This is bold}, \textit{...}, \textsl{...}
2009 ("\\\\text\\(\\(bf\\)\\|it\\|sl\\){\\([^}]+\\)}" 2023 ; ("\\\\text\\(\\(bf\\)\\|it\\|sl\\){\\([^}]+\\)}"
2010 3 (if (match-beginning 2) 'bold 'italic) keep) 2024 ; 3 (if (match-beginning 2) 'bold 'italic) keep)
2011 ;; Old-style bf/em/it/sl. Stop at `\\' and un-escaped `&', for good tables. 2025 ; ;; Old-style bf/em/it/sl. Stop at `\\' and un-escaped `&', for tables.
2012 ("\\\\\\(\\(bf\\)\\|em\\|it\\|sl\\)\\>\\(\\([^}&\\]\\|\\\\[^\\]\\)+\\)" 2026 ; ("\\\\\\(\\(bf\\)\\|em\\|it\\|sl\\)\\>\\(\\([^}&\\]\\|\\\\[^\\]\\)+\\)"
2013 3 (if (match-beginning 2) 'bold 'italic) keep)) 2027 ; 3 (if (match-beginning 2) 'bold 'italic) keep))
2028 ;;
2029 ;; Rewritten with the help of Alexandra Bac <abac@welcome.disi.unige.it>.
2030 (eval-when-compile
2031 (let (;;
2032 ;; Names of commands whose arg should be fontified with fonts.
2033 (bold (regexp-opt '("bf" "textbf" "textsc" "textup"
2034 "boldsymbol" "pmb") t))
2035 (italic (regexp-opt '("it" "textit" "textsl" "emph") t))
2036 (type (regexp-opt '("texttt" "textmd" "textrm" "textsf") t))
2037 ;;
2038 ;; Names of commands whose arg should be fontified as a heading, etc.
2039 (headings (regexp-opt
2040 '("title" "chapter" "part" "begin" "end"
2041 "section" "subsection" "subsubsection"
2042 "section*" "subsection*" "subsubsection*"
2043 "paragraph" "subparagraph" "subsubparagraph"
2044 "newcommand" "renewcommand" "newenvironment"
2045 "newtheorem"
2046 "newcommand*" "renewcommand*" "newenvironment*"
2047 "newtheorem*")
2048 t))
2049 (variables (regexp-opt
2050 '("newcounter" "newcounter*" "setcounter" "addtocounter"
2051 "setlength" "addtolength" "settowidth")
2052 t))
2053 (citations (regexp-opt
2054 '("cite" "label" "index" "glossary"
2055 "footnote" "footnotemark" "footnotetext"
2056 "ref" "pageref" "vref" "eqref" "caption")
2057 t))
2058 (includes (regexp-opt
2059 '("input" "include" "includeonly" "nofiles"
2060 "includegraphics" "includegraphics*" "usepackage"
2061 "bibliography" "epsfig" "psfig" "epsf")
2062 t))
2063 ;;
2064 ;; Names of commands that should be fontified.
2065 (specials (regexp-opt
2066 '("\\" "linebreak" "nolinebreak" "pagebreak" "nopagebreak"
2067 "newline" "newpage" "clearpage" "cleardoublepage"
2068 "displaybreak" "allowdisplaybreaks" "enlargethispage")
2069 t))
2070 (general "\\([a-zA-Z@]+\\|[^ \t\n]\\)")
2071 ;;
2072 ;; Miscellany.
2073 (slash "\\\\")
2074 (arg "\\(\\[[^]]*\\]\\)?{\\([^}]+\\)")
2075 )
2076 (list
2077 ;;
2078 ;; Heading args.
2079 (list (concat slash headings arg)
2080 (+ (regexp-opt-depth headings) (regexp-opt-depth arg))
2081 'font-lock-function-name-face)
2082 ;;
2083 ;; Variable args.
2084 (list (concat slash variables arg)
2085 (+ (regexp-opt-depth variables) (regexp-opt-depth arg))
2086 'font-lock-variable-name-face)
2087 ;;
2088 ;; Citation args.
2089 (list (concat slash citations arg)
2090 (+ (regexp-opt-depth citations) (regexp-opt-depth arg))
2091 'font-lock-reference-face)
2092 ;;
2093 ;; Include args.
2094 (list (concat slash includes arg)
2095 (+ (regexp-opt-depth includes) (regexp-opt-depth arg))
2096 'font-lock-builtin-face)
2097 ;;
2098 ;; Definitions. I think.
2099 '("^[ \t]*\\\\def\\\\\\(\\(\\w\\|@\\)+\\)"
2100 1 font-lock-function-name-face)
2101 ;;
2102 ;; Command names, special and general.
2103 (cons (concat slash specials) 'font-lock-warning-face)
2104 (concat slash general)
2105 ;;
2106 ;; Font environments. It seems a bit dubious to use `bold' and `italic'
2107 ;; faces since we might not be able to display those fonts.
2108 (list (concat slash bold arg)
2109 (+ (regexp-opt-depth bold) (regexp-opt-depth arg))
2110 '(quote bold) 'keep)
2111 (list (concat slash italic arg)
2112 (+ (regexp-opt-depth italic) (regexp-opt-depth arg))
2113 '(quote italic) 'keep)
2114 (list (concat slash type arg)
2115 (+ (regexp-opt-depth type) (regexp-opt-depth arg))
2116 '(quote bold-italic) 'keep)
2117 ;;
2118 ;; Old-style bf/em/it/sl. Stop at `\\' and un-escaped `&', for tables.
2119 '("\\\\\\(\\(bf\\)\\|em\\|it\\|sl\\)\\>\\(\\([^}&\\]\\|\\\\[^\\]\\)+\\)"
2120 3 (if (match-beginning 2) 'bold 'italic) keep)
2121 )))
2014 "Default expressions to highlight in TeX modes.") 2122 "Default expressions to highlight in TeX modes.")
2015 2123
2016 ;;; User choices. 2124 ;;; User choices.
2017 2125
2018 ;; These provide a means to fontify types not defined by the language. Those 2126 ;; These provide a means to fontify types not defined by the language. Those
2259 "while" "asm" "catch" "delete" "new" "operator" "sizeof" "this" 2367 "while" "asm" "catch" "delete" "new" "operator" "sizeof" "this"
2260 "throw" "try" 2368 "throw" "try"
2261 ;; Eric Hopper <hopper@omnifarious.mn.org> says these are new. 2369 ;; Eric Hopper <hopper@omnifarious.mn.org> says these are new.
2262 "static_cast" "dynamic_cast" "const_cast" "reinterpret_cast") t))) 2370 "static_cast" "dynamic_cast" "const_cast" "reinterpret_cast") t)))
2263 (c++-operators 2371 (c++-operators
2264 (mapconcat 'identity 2372 (eval-when-compile
2265 (mapcar 'regexp-quote 2373 (regexp-opt
2266 ;; Taken from Stroustrup, minus keywords otherwise fontified. 2374 ;; Taken from Stroustrup, minus keywords otherwise fontified.
2267 (sort '("+" "-" "*" "/" "%" "^" "&" "|" "~" "!" "=" "<" ">" 2375 '("+" "-" "*" "/" "%" "^" "&" "|" "~" "!" "=" "<" ">" "+=" "-="
2268 "+=" "-=" "*=" "/=" "%=" "^=" "&=" "|=" "<<" ">>" 2376 "*=" "/=" "%=" "^=" "&=" "|=" "<<" ">>" ">>=" "<<=" "==" "!="
2269 ">>=" "<<=" "==" "!=" "<=" ">=" "&&" "||" "++" "--" 2377 "<=" ">=" "&&" "||" "++" "--" "->*" "," "->" "[]" "()"))))
2270 "->*" "," "->" "[]" "()")
2271 #'(lambda (a b) (> (length a) (length b)))))
2272 "\\|"))
2273 (c++-type-types 2378 (c++-type-types
2274 `(mapconcat 'identity 2379 `(mapconcat 'identity
2275 (cons 2380 (cons
2276 (,@ (eval-when-compile 2381 (,@ (eval-when-compile
2277 (regexp-opt 2382 (regexp-opt