PageRenderTime 61ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/dot.emacs.d/site-lisp/howm/cheat-font-lock.el

https://github.com/dot/dotfiles.old
Emacs Lisp | 111 lines | 42 code | 11 blank | 58 comment | 0 complexity | 50233f119f7ba7db37c9e12bb013d75b MD5 | raw file
Possible License(s): GPL-3.0
  1. ;;; cheat-font-lock.el --- modify font-lock-keywords
  2. ;;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
  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. ;; depends on internal implementation of font-lock.el
  22. ;; renamed from howm-font-lock.el [2003-12-12]
  23. (require 'font-lock)
  24. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  25. ;; This code is canceled because it caused a bug on howm-1.2.2rc5.
  26. ;; cheat-font-lock-merge-keywords must support compiled keywords for current
  27. ;; implementation of riffle-contents-mode. [2005-04-28]
  28. ;; See below.
  29. ;; snap:///~/elisp/howm/howm-view.el#223:(define-derived-mode howm-view-contents-mode riffle-contents-mode "HowmC"
  30. ;; snap:///~/elisp/howm/howm-view.el#256:(cheat-font-lock-merge-keywords howm-view-contents-font-lock-keywords
  31. ;;
  32. ;; (if (and (fboundp 'font-lock-add-keywords) (>= emacs-major-version 21))
  33. ;; (progn
  34. ;; (defun cheat-font-lock-merge-keywords (&rest keywords-list)
  35. ;; ;; compiled keywords are not supported in keywords-list.
  36. ;; (font-lock-add-keywords nil (apply #'append keywords-list) 'set))
  37. ;; (defun cheat-font-lock-append-keywords (entries)
  38. ;; (font-lock-add-keywords nil entries 'append))
  39. ;; (defun cheat-font-lock-prepend-keywords (entries)
  40. ;; (font-lock-add-keywords nil entries))
  41. ;; ;; inhibit warning. sigh...
  42. ;; (defun cheat-font-lock-20040624-format-p () nil)
  43. ;; (defun cheat-font-lock-compiled-p (keywords) nil)
  44. ;; (defun cheat-font-lock-compiled-body (keywords) nil)
  45. ;; )
  46. ;; (progn
  47. ;; ;; for xemacs and emacs20
  48. ;; ))
  49. (defun cheat-font-lock-20040624-format-p ()
  50. ;; need to call font-lock-set-defaults before font-lock-compile-keywords.
  51. ;; see http://lists.gnu.org/archive/html/emacs-diffs/2005-12/msg00961.html
  52. (font-lock-set-defaults)
  53. (>= (length (font-lock-compile-keywords '(("dummy" . 'dummy)))) 3)) ;; dirty
  54. (defun cheat-font-lock-compiled-p (keywords)
  55. (eq (car-safe keywords) t))
  56. (if (cheat-font-lock-20040624-format-p)
  57. (defun cheat-font-lock-compiled-body (keywords)
  58. (cddr keywords))
  59. (defun cheat-font-lock-compiled-body (keywords)
  60. (cdr keywords)))
  61. (defun cheat-font-lock-keywords (keywords)
  62. (if (cheat-font-lock-compiled-p keywords)
  63. (cheat-font-lock-compiled-body keywords)
  64. keywords))
  65. (defun cheat-font-lock-merge-keywords (&rest keywords-list)
  66. (let ((bodies-list (mapcar #'cheat-font-lock-keywords keywords-list)))
  67. (setq font-lock-keywords
  68. (apply #'append bodies-list))))
  69. (defun cheat-font-lock-append-keywords (entries)
  70. (cheat-font-lock-merge-keywords font-lock-keywords entries))
  71. (defun cheat-font-lock-prepend-keywords (entries)
  72. (cheat-font-lock-merge-keywords entries font-lock-keywords))
  73. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  74. (defun cheat-font-lock-mode (&optional silent)
  75. "Enable font-lock-mode without calling fontify-buffer."
  76. ;; For xemacs. But this seems to have no effect. ;_; [2004-01-14]
  77. (when silent
  78. (set (make-local-variable 'font-lock-verbose) nil))
  79. ;; Keywords are not highlighted on the fly in emacs-21.3.50.1
  80. ;; when font-lock-defaults is nil. I don't understand this. [2003-11-28]
  81. (when (null font-lock-defaults)
  82. (set (make-local-variable 'font-lock-defaults) '(nil)))
  83. ;; Without the next line, global value is changed to t. [2003-12-30]
  84. ;; (emacs-20.7.2 on Vine Linux 2.6)
  85. (make-local-variable 'font-lock-fontified)
  86. (let* ((font-lock-fontified t) ;; adjourn fontify-buffer
  87. (bname (buffer-name))
  88. (need-rename (eq (aref (buffer-name) 0) ?\ )))
  89. ;; Rename invisible buffer in order to force font-lock-mode.
  90. ;; cf. snap:///usr/share/emacs/21.2/lisp/font-lock.el#694:(define-minor-mode font-lock-mode
  91. (when need-rename
  92. (rename-buffer (concat "xxx-" bname) t))
  93. (font-lock-mode 1)
  94. (when need-rename
  95. (rename-buffer bname)))
  96. (font-lock-set-defaults))
  97. (defun cheat-font-lock-fontify (&optional dummy)
  98. (font-lock-fontify-buffer))
  99. (provide 'cheat-font-lock)
  100. ;;; cheat-font-lock.el ends here