OSDN Git Service

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