home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / lucid / help-lucid-emacs / text0096.txt < prev    next >
Encoding:
Text File  |  1993-07-14  |  11.3 KB  |  281 lines

  1. I don't have any objection to making it possible to specify extent priorities
  2. and other things in font-lock mode, so long as it doesn't slow down the simple
  3. cases.  But I don't see the things that you currently can't do as being very
  4. much of a limitation, so someone who disagrees should write the code and send
  5. it to me.
  6.  
  7. (Instead of parsing font-lock-keywords in place, it might be worth considering
  8. having the format of font-lock-keywords be human-readable, perhaps with
  9. keyword instead of positional arguments, and have font-lock mode internally
  10. compile it to a form that is faster to traverse at fontification time.)
  11.  
  12. Here's a patch against the 19.6 version of font-lock.el that fixes a few minor
  13. bugs, and adds highlighting for dired buffers.
  14.  
  15.     -- Jamie
  16.  
  17. *** /cadillac-th2/lemacs-19.6/lisp/packages/font-lock.el    Wed Mar 24 15:17:19 1993
  18. --- font-lock.el    Sat Apr 17 16:27:36 1993
  19. ***************
  20. *** 28,33 ****
  21. --- 28,38 ----
  22.   ;;  displayed in `font-lock-function-name-face'.
  23.   ;; Reserved words will be displayed in `font-lock-keyword-face'.
  24.   ;;
  25. + ;; Don't let the name fool you: you can highlight things using different
  26. + ;; colors or background stipples instead of fonts, though that is not the
  27. + ;; default.  See the documentation on faces and how to change their
  28. + ;; attributes.
  29. + ;;
  30.   ;; To make the text you type be fontified, use M-x font-lock-mode.
  31.   ;; When this minor mode is on, the fonts of the current line will be
  32.   ;; updated with every insertion or deletion.
  33. ***************
  34. *** 36,52 ****
  35.   ;; The default font-lock-mode-hook sets it to the value of the variables
  36.   ;; lisp-font-lock-keywords, c-font-lock-keywords, etc, as appropriate.
  37.   ;; The easiest way to change the highlighting patterns is to change the
  38. ! ;; values of c-font-lock-keywords and related variables.
  39.   ;;
  40.   ;; To turn this on automatically, add this to your .emacs file:
  41.   ;;
  42.   ;;    (setq emacs-lisp-mode-hook '(lambda () (font-lock-mode 1)))
  43.   ;;
  44.   ;; On a Sparc2, the initial fontification takes about 12 seconds for a 120k
  45.   ;; file of C code, using the default configuration.  You can speed this up
  46.   ;; substantially by removing some of the patterns that are highlighted by
  47.   ;; default.  Fontifying lisp code is significantly faster, because lisp has a
  48.   ;; more regular syntax than C, so the expressions don't have to be as hairy.
  49.   
  50.   
  51.   (make-face 'font-lock-comment-face)
  52. --- 41,71 ----
  53.   ;; The default font-lock-mode-hook sets it to the value of the variables
  54.   ;; lisp-font-lock-keywords, c-font-lock-keywords, etc, as appropriate.
  55.   ;; The easiest way to change the highlighting patterns is to change the
  56. ! ;; values of c-font-lock-keywords and related variables.  See the doc
  57. ! ;; string of the variable `font-lock-keywords' for the appropriate syntax.
  58.   ;;
  59.   ;; To turn this on automatically, add this to your .emacs file:
  60.   ;;
  61.   ;;    (setq emacs-lisp-mode-hook '(lambda () (font-lock-mode 1)))
  62. + ;;    (setq c-mode-hook        '(lambda () (font-lock-mode 1)))
  63. + ;;    (setq c++-mode-hook       '(lambda () (font-lock-mode 1)))
  64. + ;;    (setq dired-mode-hook       '(lambda () (font-lock-mode 1)))
  65.   ;;
  66. + ;; and so on.
  67. + ;;
  68.   ;; On a Sparc2, the initial fontification takes about 12 seconds for a 120k
  69.   ;; file of C code, using the default configuration.  You can speed this up
  70.   ;; substantially by removing some of the patterns that are highlighted by
  71.   ;; default.  Fontifying lisp code is significantly faster, because lisp has a
  72.   ;; more regular syntax than C, so the expressions don't have to be as hairy.
  73. + ;;
  74. + ;; The default value for `lisp-font-lock-keywords' is the value of the variable
  75. + ;; `lisp-font-lock-keywords-1'.  You may like `lisp-font-lock-keywords-2' 
  76. + ;; better; it highlights many more words, but is slower and makes your buffers
  77. + ;; be very visually noisy.
  78. + ;;
  79. + ;; The same is true of `c-font-lock-keywords-1' and `c-font-lock-keywords-2';
  80. + ;; the former is subdued, the latter is loud.
  81.   
  82.   
  83.   (make-face 'font-lock-comment-face)
  84. ***************
  85. *** 137,150 ****
  86.       (t nil)))
  87.   
  88.   
  89.   (defun font-lock-fontify-region (start end)
  90. !   (goto-char start)
  91. !   (if (> end (point-max)) (setq end (point-max)))
  92. !   (syntactically-sectionize start end
  93. !     (function
  94. !      (lambda (extent context depth)
  95. !        (set-extent-face extent (font-lock-context-face context depth))))
  96. !    'font-lock))
  97.   
  98.   (defun font-lock-unfontify-region (beg end)
  99.     ;; First delete all extents on this line (really, in this region).
  100. --- 156,179 ----
  101.       (t nil)))
  102.   
  103.   
  104. + (defvar font-lock-use-syntax-tables t
  105. +   "Whether font-lock should bother doing syntactic fontification.
  106. + This should be true for all ``language'' modes, but other modes, like
  107. + dired, do not have anything useful in the syntax tables (no comment
  108. + or string delimiters, etc) and so there is no need to use them.
  109. + You should not set this variable; its value is automatically computed
  110. + by examining the syntax table.")
  111.   (defun font-lock-fontify-region (start end)
  112. !   (if (not font-lock-use-syntax-tables)
  113. !       nil
  114. !     (goto-char start)
  115. !     (if (> end (point-max)) (setq end (point-max)))
  116. !     (syntactically-sectionize start end
  117. !       (function
  118. !        (lambda (extent context depth)
  119. !      (set-extent-face extent (font-lock-context-face context depth))))
  120. !       'font-lock)))
  121.   
  122.   (defun font-lock-unfontify-region (beg end)
  123.     ;; First delete all extents on this line (really, in this region).
  124. ***************
  125. *** 272,278 ****
  126.   
  127.   When font-lock mode is turned on/off, the buffer is fontified/defontified.
  128.   To fontify a buffer without having newly typed text become fontified, you
  129. ! can use \\[font-lock-fontify-buffer]."
  130.     (interactive "P")
  131.     (let ((on-p (if (null arg)
  132.             (not font-lock-mode)
  133. --- 301,309 ----
  134.   
  135.   When font-lock mode is turned on/off, the buffer is fontified/defontified.
  136.   To fontify a buffer without having newly typed text become fontified, you
  137. ! can use \\[font-lock-fontify-buffer].
  138. ! See the variable `font-lock-keywords' for customization."
  139.     (interactive "P")
  140.     (let ((on-p (if (null arg)
  141.             (not font-lock-mode)
  142. ***************
  143. *** 281,287 ****
  144.       (setq on-p nil))
  145.       (or (memq after-change-function
  146.             '(nil font-lock-after-change-function))
  147. !     (error "after-change-function is %s" after-change-function))
  148.       (set (make-local-variable 'after-change-function)
  149.        (if on-p 'font-lock-after-change-function nil))
  150.       (set (make-local-variable 'font-lock-mode) on-p)
  151. --- 312,319 ----
  152.       (setq on-p nil))
  153.       (or (memq after-change-function
  154.             '(nil font-lock-after-change-function))
  155. !     (error "after-change-function is %S" after-change-function))
  156. !     (if on-p (font-lock-examine-syntax-table))
  157.       (set (make-local-variable 'after-change-function)
  158.        (if on-p 'font-lock-after-change-function nil))
  159.       (set (make-local-variable 'font-lock-mode) on-p)
  160. ***************
  161. *** 312,321 ****
  162.       (if font-lock-verbose (message "Fontifying %s..." (buffer-name)))
  163.       ;; Turn it on to run hooks and get the right font-lock-keywords.
  164.       (or was-on (font-lock-mode 1))
  165. !     (map-extents (function (lambda (x y)
  166. !                  (if (eq 'font-lock (extent-data x))
  167. !                  (delete-extent x))))
  168. !          (current-buffer) (point-min) (point-max) nil)
  169.       (if font-lock-verbose (message "Fontifying %s... (syntactically...)"
  170.                      (buffer-name)))
  171.       (buffer-syntactic-context-flush-cache)
  172. --- 344,350 ----
  173.       (if font-lock-verbose (message "Fontifying %s..." (buffer-name)))
  174.       ;; Turn it on to run hooks and get the right font-lock-keywords.
  175.       (or was-on (font-lock-mode 1))
  176. !     (font-lock-unfontify-region (point-min) (point-max))
  177.       (if font-lock-verbose (message "Fontifying %s... (syntactically...)"
  178.                      (buffer-name)))
  179.       (buffer-syntactic-context-flush-cache)
  180. ***************
  181. *** 324,334 ****
  182.         (if font-lock-verbose (message "Fontifying %s... (regexps...)"
  183.                        (buffer-name)))
  184.         (font-lock-hack-keywords (point-min) (point-max) font-lock-verbose))
  185. !     (or was-on (font-lock-mode 0)) ; turn it off if it was off.
  186.       (set (make-local-variable 'font-lock-fontified) t)
  187.       (if font-lock-verbose (message "Fontifying %s... done." (buffer-name)))
  188.       ))
  189.   
  190.   
  191.   ;;; various mode interfaces
  192.   
  193. --- 353,382 ----
  194.         (if font-lock-verbose (message "Fontifying %s... (regexps...)"
  195.                        (buffer-name)))
  196.         (font-lock-hack-keywords (point-min) (point-max) font-lock-verbose))
  197. !     (or was-on        ; turn it off if it was off.
  198. !     (let ((font-lock-fontified nil)) ; kludge to prevent defontification
  199. !       (font-lock-mode 0)))
  200.       (set (make-local-variable 'font-lock-fontified) t)
  201.       (if font-lock-verbose (message "Fontifying %s... done." (buffer-name)))
  202.       ))
  203.   
  204. + (defun font-lock-examine-syntax-table ()
  205. +   "Computes the value of font-lock-use-syntax-tables for this buffer."
  206. +   (let ((i (1- (length (syntax-table))))
  207. +     (got-one nil))
  208. +     (if (eq (syntax-table) (standard-syntax-table))
  209. +     ;; Assume that modes which haven't bothered to install their own
  210. +     ;; syntax table don't do anything syntactically interesting.
  211. +     ;; Really, the standard-syntax-table shouldn't have comments and
  212. +     ;; strings in it, but changing that now might break things.
  213. +     nil
  214. +       ;; else map over the syntax table looking for strings or comments.
  215. +       (while (>= i 0)
  216. +     (if (memq (char-syntax i) '(?\" ?\< ?\> ?\$))
  217. +         (setq got-one t i 0))
  218. +     (setq i (1- i))))
  219. +     (set (make-local-variable 'font-lock-use-syntax-tables) got-one)))
  220.   
  221.   ;;; various mode interfaces
  222.   
  223. ***************
  224. *** 527,536 ****
  225.      )
  226.     "Additional expressions to highlight in TeXinfo-mode.")
  227.   
  228.   
  229.   ;; Kludge
  230.   (defun dummy-font-lock-mode-hook ()
  231. !   "sets font-lock-keywords to something appropriate for this mode."
  232.     (setq font-lock-keywords
  233.       (cond ((eq major-mode 'lisp-mode)    lisp-font-lock-keywords)
  234.             ((eq major-mode 'emacs-lisp-mode)    lisp-font-lock-keywords)
  235. --- 575,599 ----
  236.      )
  237.     "Additional expressions to highlight in TeXinfo-mode.")
  238.   
  239. + (defconst dired-font-lock-keywords
  240. +   (let ((bn (concat "\\(Jan\\|Feb\\|Mar\\|Apr\\|May\\|Jun\\|Jul\\|"
  241. +             "Aug\\|Sep\\|Oct\\|Nov\\|Dec\\) +[0-9]+ +[0-9:]+")))
  242. +     (list
  243. +      '("^  [/~].*:$" . bold-italic)                   ; Header
  244. +      (list (concat "^\\(\\([^ ].*\\)" bn "\\) \\(.*\\)$") 1 'bold) ; Marked
  245. +      (list (concat "^. +d.*" bn " \\(.*\\)$") 2 'bold)           ; Subdirs
  246. +      (list (concat "^. +l.*" bn " \\(.*\\)$") 2 'italic)       ; Links
  247. +      (cons (concat "^. +-..[xsS]......\\|"    ; Regular files with executable
  248. +            "^. +-.....[xsS]...\\|"    ; or setuid/setgid bits set
  249. +            "^. +-........[xsS]")
  250. +        'bold)
  251. +      ))
  252. +   "Expressions to highlight in Dired buffers.")
  253.   
  254.   ;; Kludge
  255.   (defun dummy-font-lock-mode-hook ()
  256. !   "Sets font-lock-keywords to something appropriate for this mode."
  257.     (setq font-lock-keywords
  258.       (cond ((eq major-mode 'lisp-mode)    lisp-font-lock-keywords)
  259.             ((eq major-mode 'emacs-lisp-mode)    lisp-font-lock-keywords)
  260. ***************
  261. *** 540,545 ****
  262.             ((eq major-mode 'perl-mode)    perl-font-lock-keywords)
  263.             ((eq major-mode 'tex-mode)    tex-font-lock-keywords)
  264.             ((eq major-mode 'texinfo-mode)    texi-font-lock-keywords)
  265. !           (t nil))))
  266.   
  267.   (add-hook 'font-lock-mode-hook 'dummy-font-lock-mode-hook)
  268. --- 603,609 ----
  269.             ((eq major-mode 'perl-mode)    perl-font-lock-keywords)
  270.             ((eq major-mode 'tex-mode)    tex-font-lock-keywords)
  271.             ((eq major-mode 'texinfo-mode)    texi-font-lock-keywords)
  272. !           ((eq major-mode 'dired-mode)    dired-font-lock-keywords)
  273. !           (t font-lock-keywords))))
  274.   
  275.   (add-hook 'font-lock-mode-hook 'dummy-font-lock-mode-hook)
  276.  
  277.