Mercurial > emacs
comparison lisp/font-lock.el @ 17543:9b75a01e03e5
Respect font-lock-face-attributes and custom fixes.
author | Simon Marshall <simon@gnu.org> |
---|---|
date | Wed, 23 Apr 1997 07:10:09 +0000 |
parents | fd87760f20cd |
children | 9f9f522cdc27 |
comparison
equal
deleted
inserted
replaced
17542:653ef38fd02e | 17543:9b75a01e03e5 |
---|---|
181 ;; Don't use it to, say, highlight keywords in commented out code or strings. | 181 ;; Don't use it to, say, highlight keywords in commented out code or strings. |
182 ;; - Err, that's it. | 182 ;; - Err, that's it. |
183 | 183 |
184 ;;; Code: | 184 ;;; Code: |
185 | 185 |
186 ;; Define core `font-lock' group. | |
186 (defgroup font-lock nil | 187 (defgroup font-lock nil |
187 "Font Lock mode text highlighting package." | 188 "Font Lock mode text highlighting package." |
188 :link '(custom-manual "(emacs)Font Lock") | 189 :link '(custom-manual "(emacs)Font Lock") |
189 :group 'faces) | 190 :group 'faces) |
190 | 191 |
191 (defgroup font-lock-faces nil | 192 (defgroup font-lock-highlighting-faces nil |
192 "Font Lock mode faces." | 193 "Faces for highlighting text." |
193 :prefix "font-lock-" | 194 :prefix "font-lock-" |
194 :link '(custom-manual "(emacs)Font Lock") | 195 :group 'font-lock) |
196 | |
197 (defgroup font-lock-extra-types nil | |
198 "Extra mode-specific type names for highlighting declarations." | |
199 :group 'font-lock) | |
200 | |
201 ;; Define support mode groups here for nicer `font-lock' group order. | |
202 (defgroup fast-lock nil | |
203 "Font Lock support mode to cache fontification." | |
204 :link '(custom-manual "(emacs)Support Modes") | |
205 :load 'fast-lock | |
206 :group 'font-lock) | |
207 | |
208 (defgroup lazy-lock nil | |
209 "Font Lock support mode to fontify lazily." | |
210 :link '(custom-manual "(emacs)Support Modes") | |
211 :load 'lazy-lock | |
195 :group 'font-lock) | 212 :group 'font-lock) |
196 | 213 |
197 ;; User variables. | 214 ;; User variables. |
198 | 215 |
199 (defcustom font-lock-verbose (* 0 1024) | 216 (defcustom font-lock-verbose (* 0 1024) |
281 Where MATCHER can be either the regexp to search for, or the function name to | 298 Where MATCHER can be either the regexp to search for, or the function name to |
282 call to make the search (called with one argument, the limit of the search). | 299 call to make the search (called with one argument, the limit of the search). |
283 MATCH is the subexpression of MATCHER to be highlighted. MATCH can be | 300 MATCH is the subexpression of MATCHER to be highlighted. MATCH can be |
284 calculated via the function `font-lock-keyword-depth'. FACENAME is an | 301 calculated via the function `font-lock-keyword-depth'. FACENAME is an |
285 expression whose value is the face name to use. FACENAME's default attributes | 302 expression whose value is the face name to use. FACENAME's default attributes |
286 can be defined via the variable `font-lock-face-attributes'. | 303 can be modified via \\[customize]. |
287 | 304 |
288 OVERRIDE and LAXMATCH are flags. If OVERRIDE is t, existing fontification can | 305 OVERRIDE and LAXMATCH are flags. If OVERRIDE is t, existing fontification can |
289 be overwritten. If `keep', only parts not already fontified are highlighted. | 306 be overwritten. If `keep', only parts not already fontified are highlighted. |
290 If `prepend' or `append', existing fontification is merged with the new, in | 307 If `prepend' or `append', existing fontification is merged with the new, in |
291 which the new or existing fontification, respectively, takes precedence. | 308 which the new or existing fontification, respectively, takes precedence. |
606 | 623 |
607 To fontify a block (the function or paragraph containing point, or a number of | 624 To fontify a block (the function or paragraph containing point, or a number of |
608 lines around point), perhaps because modification on the current line caused | 625 lines around point), perhaps because modification on the current line caused |
609 syntactic change on other lines, you can use \\[font-lock-fontify-block]. | 626 syntactic change on other lines, you can use \\[font-lock-fontify-block]. |
610 | 627 |
611 The default Font Lock mode faces and their attributes are defined in the | 628 See the variable `font-lock-defaults-alist' for the Font Lock mode default |
612 variable `font-lock-face-attributes', and Font Lock mode default settings in | 629 settings. You can set your own default settings for some mode, by setting a |
613 the variable `font-lock-defaults-alist'. You can set your own default settings | 630 buffer local value for `font-lock-defaults', via its mode hook." |
614 for some mode, by setting a buffer local value for `font-lock-defaults', via | |
615 its mode hook." | |
616 (interactive "P") | 631 (interactive "P") |
617 ;; Don't turn on Font Lock mode if we don't have a display (we're running a | 632 ;; Don't turn on Font Lock mode if we don't have a display (we're running a |
618 ;; batch job) or if the buffer is invisible (the name starts with a space). | 633 ;; batch job) or if the buffer is invisible (the name starts with a space). |
619 (let ((on-p (and (not noninteractive) | 634 (let ((on-p (and (not noninteractive) |
620 (not (eq (aref (buffer-name) 0) ?\ )) | 635 (not (eq (aref (buffer-name) 0) ?\ )) |
1430 "Face name to use for reference names.") | 1445 "Face name to use for reference names.") |
1431 | 1446 |
1432 (defvar font-lock-warning-face 'font-lock-warning-face | 1447 (defvar font-lock-warning-face 'font-lock-warning-face |
1433 "Face name to use for things that should stand out.") | 1448 "Face name to use for things that should stand out.") |
1434 | 1449 |
1450 ;; Originally face attributes were specified via `font-lock-face-attributes'. | |
1451 ;; Users then changed the default face attributes by setting this variable. | |
1452 ;; However, we try and be back-compatible and respect its value if set except | |
1453 ;; for faces where M-x customize has been used to save changes for the face. | |
1454 (when (boundp 'font-lock-face-attributes) | |
1455 (let ((face-attributes font-lock-face-attributes)) | |
1456 (while face-attributes | |
1457 (let* ((face-attribute (pop face-attributes)) | |
1458 (face (car face-attribute))) | |
1459 ;; Rustle up a `defface' SPEC from a `font-lock-face-attributes' entry. | |
1460 (unless (get face 'saved-face) | |
1461 (let ((foreground (nth 1 face-attribute)) | |
1462 (background (nth 2 face-attribute)) | |
1463 (bold-p (nth 3 face-attribute)) | |
1464 (italic-p (nth 4 face-attribute)) | |
1465 (underline-p (nth 5 face-attribute)) | |
1466 face-spec) | |
1467 (when foreground | |
1468 (setq face-spec (cons ':foreground (cons foreground face-spec)))) | |
1469 (when background | |
1470 (setq face-spec (cons ':background (cons background face-spec)))) | |
1471 (when bold-p | |
1472 (setq face-spec (append '(:bold t) face-spec))) | |
1473 (when italic-p | |
1474 (setq face-spec (append '(:italic t) face-spec))) | |
1475 (when underline-p | |
1476 (setq face-spec (append '(:underline t) face-spec))) | |
1477 (custom-declare-face face (list (list t face-spec)) nil))))))) | |
1478 | |
1479 ;; But now we do it the custom way. Note that `defface' will not overwrite any | |
1480 ;; faces declared above via `custom-declare-face'. | |
1435 (defface font-lock-comment-face | 1481 (defface font-lock-comment-face |
1436 '((((class grayscale) (background light)) | 1482 '((((class grayscale) (background light)) |
1437 (:foreground "DimGray" :bold t :italic t)) | 1483 (:foreground "DimGray" :bold t :italic t)) |
1438 (((class grayscale) (background dark)) | 1484 (((class grayscale) (background dark)) |
1439 (:foreground "LightGray" :bold t :italic t)) | 1485 (:foreground "LightGray" :bold t :italic t)) |
1440 (((class color) (background light)) (:foreground "Firebrick")) | 1486 (((class color) (background light)) (:foreground "Firebrick")) |
1441 (((class color) (background dark)) (:foreground "OrangeRed")) | 1487 (((class color) (background dark)) (:foreground "OrangeRed")) |
1442 (t (:bold t :italic t))) | 1488 (t (:bold t :italic t))) |
1443 "Font Lock mode face used to highlight comments." | 1489 "Font Lock mode face used to highlight comments." |
1444 :group 'font-lock-faces) | 1490 :group 'font-lock-highlighting-faces) |
1445 | 1491 |
1446 (defface font-lock-string-face | 1492 (defface font-lock-string-face |
1447 '((((class grayscale) (background light)) (:foreground "DimGray" :italic t)) | 1493 '((((class grayscale) (background light)) (:foreground "DimGray" :italic t)) |
1448 (((class grayscale) (background dark)) (:foreground "LightGray" :italic t)) | 1494 (((class grayscale) (background dark)) (:foreground "LightGray" :italic t)) |
1449 (((class color) (background light)) (:foreground "RosyBrown")) | 1495 (((class color) (background light)) (:foreground "RosyBrown")) |
1450 (((class color) (background dark)) (:foreground "LightSalmon")) | 1496 (((class color) (background dark)) (:foreground "LightSalmon")) |
1451 (t (:italic t))) | 1497 (t (:italic t))) |
1452 "Font Lock mode face used to highlight strings." | 1498 "Font Lock mode face used to highlight strings." |
1453 :group 'font-lock-faces) | 1499 :group 'font-lock-highlighting-faces) |
1454 | 1500 |
1455 (defface font-lock-keyword-face | 1501 (defface font-lock-keyword-face |
1456 '((((class grayscale) (background light)) (:foreground "LightGray" :bold t)) | 1502 '((((class grayscale) (background light)) (:foreground "LightGray" :bold t)) |
1457 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t)) | 1503 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t)) |
1458 (((class color) (background light)) (:foreground "Purple")) | 1504 (((class color) (background light)) (:foreground "Purple")) |
1459 (((class color) (background dark)) (:foreground "Cyan")) | 1505 (((class color) (background dark)) (:foreground "Cyan")) |
1460 (t (:bold t))) | 1506 (t (:bold t))) |
1461 "Font Lock mode face used to highlight keywords." | 1507 "Font Lock mode face used to highlight keywords." |
1462 :group 'font-lock-faces) | 1508 :group 'font-lock-highlighting-faces) |
1463 | 1509 |
1464 (defface font-lock-builtin-face | 1510 (defface font-lock-builtin-face |
1465 '((((class grayscale) (background light)) (:foreground "LightGray" :bold t)) | 1511 '((((class grayscale) (background light)) (:foreground "LightGray" :bold t)) |
1466 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t)) | 1512 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t)) |
1467 (((class color) (background light)) (:foreground "Orchid")) | 1513 (((class color) (background light)) (:foreground "Orchid")) |
1468 (((class color) (background dark)) (:foreground "LightSteelBlue")) | 1514 (((class color) (background dark)) (:foreground "LightSteelBlue")) |
1469 (t (:bold t))) | 1515 (t (:bold t))) |
1470 "Font Lock mode face used to highlight builtins." | 1516 "Font Lock mode face used to highlight builtins." |
1471 :group 'font-lock-faces) | 1517 :group 'font-lock-highlighting-faces) |
1472 | 1518 |
1473 (defface font-lock-function-name-face | 1519 (defface font-lock-function-name-face |
1474 ;; Currently, Emacs/Custom does not support a :reverse or :invert spec. | 1520 ;; Currently, Emacs/Custom does not support a :reverse or :invert spec. |
1475 '((((class color) (background light)) (:foreground "Blue")) | 1521 '((((class color) (background light)) (:foreground "Blue")) |
1476 (((class color) (background dark)) (:foreground "LightSkyBlue")) | 1522 (((class color) (background dark)) (:foreground "LightSkyBlue")) |
1477 (t ;(:reverse t :bold t) | 1523 (t ;(:reverse t :bold t) |
1478 (:italic t :bold t))) | 1524 (:italic t :bold t))) |
1479 "Font Lock mode face used to highlight function names." | 1525 "Font Lock mode face used to highlight function names." |
1480 :group 'font-lock-faces) | 1526 :group 'font-lock-highlighting-faces) |
1481 | 1527 |
1482 (defface font-lock-variable-name-face | 1528 (defface font-lock-variable-name-face |
1483 '((((class grayscale) (background light)) | 1529 '((((class grayscale) (background light)) |
1484 (:foreground "Gray90" :bold t :italic t)) | 1530 (:foreground "Gray90" :bold t :italic t)) |
1485 (((class grayscale) (background dark)) | 1531 (((class grayscale) (background dark)) |
1486 (:foreground "DimGray" :bold t :italic t)) | 1532 (:foreground "DimGray" :bold t :italic t)) |
1487 (((class color) (background light)) (:foreground "DarkGoldenrod")) | 1533 (((class color) (background light)) (:foreground "DarkGoldenrod")) |
1488 (((class color) (background dark)) (:foreground "LightGoldenrod")) | 1534 (((class color) (background dark)) (:foreground "LightGoldenrod")) |
1489 (t (:bold t :italic t))) | 1535 (t (:bold t :italic t))) |
1490 "Font Lock mode face used to highlight variable names." | 1536 "Font Lock mode face used to highlight variable names." |
1491 :group 'font-lock-faces) | 1537 :group 'font-lock-highlighting-faces) |
1492 | 1538 |
1493 (defface font-lock-type-face | 1539 (defface font-lock-type-face |
1494 '((((class grayscale) (background light)) (:foreground "Gray90" :bold t)) | 1540 '((((class grayscale) (background light)) (:foreground "Gray90" :bold t)) |
1495 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t)) | 1541 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t)) |
1496 (((class color) (background light)) (:foreground "DarkOliveGreen")) | 1542 (((class color) (background light)) (:foreground "DarkOliveGreen")) |
1497 (((class color) (background dark)) (:foreground "PaleGreen")) | 1543 (((class color) (background dark)) (:foreground "PaleGreen")) |
1498 (t (:bold t :underline t))) | 1544 (t (:bold t :underline t))) |
1499 "Font Lock mode face used to highlight types." | 1545 "Font Lock mode face used to highlight types." |
1500 :group 'font-lock-faces) | 1546 :group 'font-lock-highlighting-faces) |
1501 | 1547 |
1502 (defface font-lock-reference-face | 1548 (defface font-lock-reference-face |
1503 '((((class grayscale) (background light)) | 1549 '((((class grayscale) (background light)) |
1504 (:foreground "LightGray" :bold t :underline t)) | 1550 (:foreground "LightGray" :bold t :underline t)) |
1505 (((class grayscale) (background dark)) | 1551 (((class grayscale) (background dark)) |
1506 (:foreground "Gray50" :bold t :underline t)) | 1552 (:foreground "Gray50" :bold t :underline t)) |
1507 (((class color) (background light)) (:foreground "CadetBlue")) | 1553 (((class color) (background light)) (:foreground "CadetBlue")) |
1508 (((class color) (background dark)) (:foreground "Aquamarine")) | 1554 (((class color) (background dark)) (:foreground "Aquamarine")) |
1509 (t (:bold t :underline t))) | 1555 (t (:bold t :underline t))) |
1510 "Font Lock mode face used to highlight references." | 1556 "Font Lock mode face used to highlight references." |
1511 :group 'font-lock-faces) | 1557 :group 'font-lock-highlighting-faces) |
1512 | 1558 |
1513 (defface font-lock-warning-face | 1559 (defface font-lock-warning-face |
1514 ;; Currently, Emacs/Custom does not support a :reverse or :invert spec. | 1560 ;; Currently, Emacs/Custom does not support a :reverse or :invert spec. |
1515 '((((class color) (background light)) (:foreground "Red" :bold t)) | 1561 '((((class color) (background light)) (:foreground "Red" :bold t)) |
1516 (((class color) (background dark)) (:foreground "Pink" :bold t)) | 1562 (((class color) (background dark)) (:foreground "Pink" :bold t)) |
1517 (t ;(:reverse t :bold t) | 1563 (t ;(:reverse t :bold t) |
1518 (:italic t :bold t))) | 1564 (:italic t :bold t))) |
1519 "Font Lock mode face used to highlight warnings." | 1565 "Font Lock mode face used to highlight warnings." |
1520 :group 'font-lock-faces) | 1566 :group 'font-lock-highlighting-faces) |
1521 | 1567 |
1522 ;;; End of Colour etc. support. | 1568 ;;; End of Colour etc. support. |
1523 | 1569 |
1524 ;;; Menu support. | 1570 ;;; Menu support. |
1525 | 1571 |
1677 ;; | 1723 ;; |
1678 ;; Definitions. | 1724 ;; Definitions. |
1679 (list (concat "(\\(def\\(" | 1725 (list (concat "(\\(def\\(" |
1680 ;; Function declarations. | 1726 ;; Function declarations. |
1681 "\\(advice\\|alias\\|" | 1727 "\\(advice\\|alias\\|" |
1682 "ine-\\(derived-mode\\|function\\|skeleton\\)\\|" | 1728 "ine-\\(derived-mode\\|function\\|skeleton\\|widget\\)\\|" |
1683 "macro\\|subst\\|un\\)\\|" | 1729 "macro\\|subst\\|un\\)\\|" |
1684 ;; Variable declarations. | 1730 ;; Variable declarations. |
1685 "\\(const\\|custom\\|face\\|var\\)\\|" | 1731 "\\(const\\|custom\\|face\\|var\\)\\|" |
1686 ;; Structure declarations. | 1732 ;; Structure declarations. |
1687 "\\(class\\|group\\|struct\\|type\\)" | 1733 "\\(class\\|group\\|struct\\|type\\)" |
1853 | 1899 |
1854 ;; These provide a means to fontify types not defined by the language. Those | 1900 ;; These provide a means to fontify types not defined by the language. Those |
1855 ;; types might be the user's own or they might be generally accepted and used. | 1901 ;; types might be the user's own or they might be generally accepted and used. |
1856 ;; Generally accepted types are used to provide default variable values. | 1902 ;; Generally accepted types are used to provide default variable values. |
1857 | 1903 |
1858 (defvar c-font-lock-extra-types '("FILE" "\\sw+_t") | 1904 (define-widget 'font-lock-extra-types-widget 'radio |
1905 "Widget `:type' for members of the custom group `font-lock-extra-types'. | |
1906 Members should `:load' the package `font-lock' to use this widget." | |
1907 :args '((const :tag "none" nil) | |
1908 (repeat :tag "types" | |
1909 (string :tag "regexp")))) | |
1910 | |
1911 (defcustom c-font-lock-extra-types '("FILE" "\\sw+_t") | |
1859 "*List of extra types to fontify in C mode. | 1912 "*List of extra types to fontify in C mode. |
1860 Each list item should be a regexp not containing word-delimiters. | 1913 Each list item should be a regexp not containing word-delimiters. |
1861 For example, a value of (\"FILE\" \"\\\\sw+_t\") means the word FILE and words | 1914 For example, a value of (\"FILE\" \"\\\\sw+_t\") means the word FILE and words |
1862 ending in _t are treated as type names. | 1915 ending in _t are treated as type names. |
1863 | 1916 |
1864 The value of this variable is used when Font Lock mode is turned on.") | 1917 The value of this variable is used when Font Lock mode is turned on." |
1865 | 1918 :type 'font-lock-extra-types-widget |
1866 (defvar c++-font-lock-extra-types '("string") | 1919 :group 'font-lock-extra-types) |
1920 | |
1921 (defcustom c++-font-lock-extra-types '("string") | |
1867 "*List of extra types to fontify in C++ mode. | 1922 "*List of extra types to fontify in C++ mode. |
1868 Each list item should be a regexp not containing word-delimiters. | 1923 Each list item should be a regexp not containing word-delimiters. |
1869 For example, a value of (\"string\") means the word string is treated as a type | 1924 For example, a value of (\"string\") means the word string is treated as a type |
1870 name. | 1925 name. |
1871 | 1926 |
1872 The value of this variable is used when Font Lock mode is turned on.") | 1927 The value of this variable is used when Font Lock mode is turned on." |
1873 | 1928 :type 'font-lock-extra-types-widget |
1874 (defvar objc-font-lock-extra-types '("Class" "BOOL" "IMP" "SEL") | 1929 :group 'font-lock-extra-types) |
1930 | |
1931 (defcustom objc-font-lock-extra-types '("Class" "BOOL" "IMP" "SEL") | |
1875 "*List of extra types to fontify in Objective-C mode. | 1932 "*List of extra types to fontify in Objective-C mode. |
1876 Each list item should be a regexp not containing word-delimiters. | 1933 Each list item should be a regexp not containing word-delimiters. |
1877 For example, a value of (\"Class\" \"BOOL\" \"IMP\" \"SEL\") means the words | 1934 For example, a value of (\"Class\" \"BOOL\" \"IMP\" \"SEL\") means the words |
1878 Class, BOOL, IMP and SEL are treated as type names. | 1935 Class, BOOL, IMP and SEL are treated as type names. |
1879 | 1936 |
1880 The value of this variable is used when Font Lock mode is turned on.") | 1937 The value of this variable is used when Font Lock mode is turned on." |
1881 | 1938 :type 'font-lock-extra-types-widget |
1882 (defvar java-font-lock-extra-types '("[A-Z\300-\326\330-\337]\\sw+") | 1939 :group 'font-lock-extra-types) |
1940 | |
1941 (defcustom java-font-lock-extra-types '("[A-Z\300-\326\330-\337]\\sw+") | |
1883 "*List of extra types to fontify in Java mode. | 1942 "*List of extra types to fontify in Java mode. |
1884 Each list item should be a regexp not containing word-delimiters. | 1943 Each list item should be a regexp not containing word-delimiters. |
1885 For example, a value of (\"[A-Z\300-\326\330-\337]\\\\sw+\") means capitalised | 1944 For example, a value of (\"[A-Z\300-\326\330-\337]\\\\sw+\") means capitalised |
1886 words (and words conforming to the Java id spec) are treated as type names. | 1945 words (and words conforming to the Java id spec) are treated as type names. |
1887 | 1946 |
1888 The value of this variable is used when Font Lock mode is turned on.") | 1947 The value of this variable is used when Font Lock mode is turned on." |
1948 :type 'font-lock-extra-types-widget | |
1949 :group 'font-lock-extra-types) | |
1889 | 1950 |
1890 ;;; C. | 1951 ;;; C. |
1891 | 1952 |
1892 ;; [Murmur murmur murmur] Maestro, drum-roll please... [Murmur murmur murmur.] | 1953 ;; [Murmur murmur murmur] Maestro, drum-roll please... [Murmur murmur murmur.] |
1893 ;; Ahem. [Murmur murmur murmur] Lay-dees an Gennel-men. [Murmur murmur shhh!] | 1954 ;; Ahem. [Murmur murmur murmur] Lay-dees an Gennel-men. [Murmur murmur shhh!] |