1 ;;; cheat-font-lock.el --- modify font-lock-keywords
2 ;;; Copyright (C) 2002, 2003, 2004, 2005-2021
3 ;;; HIRAOKA Kazuyuki <khi@users.osdn.me>
5 ;;; This program is free software; you can redistribute it and/or modify
6 ;;; it under the terms of the GNU General Public License as published by
7 ;;; the Free Software Foundation; either version 1, or (at your option)
10 ;;; This program is distributed in the hope that it will be useful,
11 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;;; GNU General Public License for more details.
15 ;;; The GNU General Public License is available by anonymouse ftp from
16 ;;; prep.ai.mit.edu in pub/gnu/COPYING. Alternately, you can write to
17 ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
19 ;;--------------------------------------------------------------------
21 ;; depends on internal implementation of font-lock.el
23 ;; renamed from howm-font-lock.el [2003-12-12]
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29 ;; This code is canceled because it caused a bug on howm-1.2.2rc5.
30 ;; cheat-font-lock-merge-keywords must support compiled keywords for current
31 ;; implementation of riffle-contents-mode. [2005-04-28]
33 ;; snap:///~/elisp/howm/howm-view.el#223:(define-derived-mode howm-view-contents-mode riffle-contents-mode "HowmC"
34 ;; snap:///~/elisp/howm/howm-view.el#256:(cheat-font-lock-merge-keywords howm-view-contents-font-lock-keywords
36 ;; (if (and (fboundp 'font-lock-add-keywords) (>= emacs-major-version 21))
38 ;; (defun cheat-font-lock-merge-keywords (&rest keywords-list)
39 ;; ;; compiled keywords are not supported in keywords-list.
40 ;; (font-lock-add-keywords nil (apply #'append keywords-list) 'set))
41 ;; (defun cheat-font-lock-append-keywords (entries)
42 ;; (font-lock-add-keywords nil entries 'append))
43 ;; (defun cheat-font-lock-prepend-keywords (entries)
44 ;; (font-lock-add-keywords nil entries))
45 ;; ;; inhibit warning. sigh...
46 ;; (defun cheat-font-lock-20040624-format-p () nil)
47 ;; (defun cheat-font-lock-compiled-p (keywords) nil)
48 ;; (defun cheat-font-lock-compiled-body (keywords) nil)
51 ;; ;; for xemacs and emacs20
54 (defun cheat-font-lock-20040624-format-p ()
55 ;; need to call font-lock-set-defaults before font-lock-compile-keywords.
56 ;; see http://lists.gnu.org/archive/html/emacs-diffs/2005-12/msg00961.html
57 (font-lock-set-defaults)
58 (>= (length (font-lock-compile-keywords '(("dummy" . 'dummy)))) 3)) ;; dirty
59 (defun cheat-font-lock-compiled-p (keywords)
60 (eq (car-safe keywords) t))
61 (defun cheat-font-lock-compiled-body (keywords)
63 (when (cheat-font-lock-20040624-format-p)
64 ;; re-defun for avoiding the warning:
65 ;; "the function `...' is not known to be defined."
66 (defun cheat-font-lock-compiled-body (keywords)
68 (defun cheat-font-lock-keywords (keywords)
69 (if (cheat-font-lock-compiled-p keywords)
70 (cheat-font-lock-compiled-body keywords)
72 (defun cheat-font-lock-merge-keywords (&rest keywords-list)
73 (let ((bodies-list (mapcar #'cheat-font-lock-keywords keywords-list)))
74 (setq font-lock-keywords
75 (apply #'append bodies-list))))
76 (defun cheat-font-lock-append-keywords (entries)
77 (cheat-font-lock-merge-keywords font-lock-keywords entries))
78 (defun cheat-font-lock-prepend-keywords (entries)
79 (cheat-font-lock-merge-keywords entries font-lock-keywords))
81 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
83 (defun cheat-font-lock-mode (&optional silent)
84 "Enable font-lock-mode without calling fontify-buffer."
85 ;; For xemacs. But this seems to have no effect. ;_; [2004-01-14]
87 (set (make-local-variable 'font-lock-verbose) nil))
88 ;; Keywords are not highlighted on the fly in emacs-21.3.50.1
89 ;; when font-lock-defaults is nil. I don't understand this. [2003-11-28]
90 (when (null font-lock-defaults)
91 (set (make-local-variable 'font-lock-defaults) '(nil)))
92 ;; Without the next line, global value is changed to t. [2003-12-30]
93 ;; (emacs-20.7.2 on Vine Linux 2.6)
94 (make-local-variable 'font-lock-fontified)
95 (let* (;; Stop cheating font-lock in such a way. [2021-02-15]
96 ;; This seems troublesome and font-lock is not slow today.
97 ;; (font-lock-fontified t) ;; adjourn fontify-buffer
99 (need-rename (eq (aref (buffer-name) 0) ?\ )))
100 ;; Rename invisible buffer in order to force font-lock-mode.
101 ;; cf. snap:///usr/share/emacs/21.2/lisp/font-lock.el#694:(define-minor-mode font-lock-mode
103 (rename-buffer (concat "xxx-" bname) t))
106 (rename-buffer bname)))
107 (font-lock-set-defaults))
109 (defun cheat-font-lock-fontify (&optional dummy)
110 (if (and (fboundp 'font-lock-flush) (fboundp 'font-lock-ensure))
111 (progn (font-lock-flush) (font-lock-ensure))
113 (font-lock-fontify-buffer))))
115 (provide 'cheat-font-lock)
117 ;;; cheat-font-lock.el ends here