├── README.org └── fic-mode.el /README.org: -------------------------------------------------------------------------------- 1 | * This is a fork of [[http://www.emacswiki.org/emacs/download/fic-ext-mode.el][fic-ext-mod.el]] 2 | 3 | I've decided to rename it back to the canonical fic-mode.el. 4 | 5 | * Other changes 6 | ** remove lighter 7 | I would normally use `diminish', but it is really silly to have any 8 | highlighter for this mode. 9 | ** call font-lock-fontify-buffer in init 10 | * WHY U NO PROVIDE JUMP-TO functionality??? 11 | 12 | Because you should use occur or anything-regexp. 13 | -------------------------------------------------------------------------------- /fic-mode.el: -------------------------------------------------------------------------------- 1 | ;;; fic-mode.el --- Show FIXME/TODO/BUG(...) in special face only in comments and strings 2 | ;;-------------------------------------------------------------------- 3 | ;; 4 | ;; Copyright (C) 2010, Trey Jackson 5 | ;; Copyright (C) 2010, Ivan Korotkov 6 | ;; Copyright (C) 2012, Le Wang 7 | ;; 8 | ;; Homepage: https://github.com/lewang/fic-mode 9 | ;; 10 | ;; This file is NOT part of Emacs. 11 | ;; 12 | ;; This program is free software; you can redistribute it and/or 13 | ;; modify it under the terms of the GNU General Public License as 14 | ;; published by the Free Software Foundation; either version 2 of 15 | ;; the License, or (at your option) any later version. 16 | ;; 17 | ;; This program is distributed in the hope that it will be 18 | ;; useful, but WITHOUT ANY WARRANTY; without even the implied 19 | ;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 20 | ;; PURPOSE. See the GNU General Public License for more details. 21 | ;; 22 | ;; You should have received a copy of the GNU General Public 23 | ;; License along with this program; if not, write to the Free 24 | ;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 25 | ;; MA 02111-1307 USA 26 | ;; 27 | ;; To use, save fic-mode.el to a directory in your load-path. 28 | ;; 29 | ;; (require 'fic-mode) 30 | ;; 31 | ;; ;;; emacs 24 32 | ;; (add-hook 'prog-mode-hook 'fic-mode) 33 | ;; 34 | ;; ;;; emacs 23 needs to add this to all programming modes you want this to be 35 | ;; ;;; enabled for. 36 | ;; ;;; 37 | ;; ;;; e.g. 38 | ;; (add-hook 'c++-mode-hook 'fic-mode) 39 | ;; (add-hook 'emacs-lisp-mode-hook 'fic-mode) 40 | ;; 41 | ;; or 42 | ;; 43 | ;; M-x fic-mode 44 | 45 | (defgroup fic-mode nil 46 | "Highlight FIXME/TODO(...) in comments" 47 | :tag "FIC" 48 | :group 'tools 49 | :group 'font-lock 50 | :group 'faces) 51 | 52 | (defcustom fic-highlighted-words '("FIXME" "TODO" "BUG") 53 | "Words to highlight." 54 | :group 'fic-mode) 55 | 56 | (defcustom fic-author-name-regexp "[-a-zA-Z0-9_.]+" 57 | "Regexp describing FIXME/TODO author name" 58 | :group 'fic-mode) 59 | 60 | (defcustom fic-activated-faces 61 | '(font-lock-doc-face font-lock-string-face font-lock-comment-face) 62 | "Faces to look for to highlight words." 63 | :group 'fic-mode) 64 | 65 | (defface fic-face 66 | '((((class color)) 67 | (:background "white" :foreground "red" :weight bold)) 68 | (t (:weight bold))) 69 | "Face to fontify FIXME/TODO words" 70 | :group 'fic-mode) 71 | 72 | (defface fic-author-face 73 | '((((class color)) 74 | (:background "white" :foreground "orangered" :underline t)) 75 | (t (:underline t))) 76 | "Face to fontify author/assignee of FIXME/TODO" 77 | :group 'fic-mode) 78 | 79 | (defvar fic-mode-font-lock-keywords '((fic-search-for-keyword 80 | (1 'fic-face t) 81 | (2 'fic-author-face t t))) 82 | "Font Lock keywords for fic-mode") 83 | 84 | (defvar fic-saved-hash nil 85 | "(`fic-highlighted-words' . `fic-author-name-regexp')") 86 | (defvar fic-saved-regexp nil 87 | "Regexp cache for `fic-saved-hash'") 88 | 89 | (defun fic-search-re () 90 | "Regexp to search for." 91 | (let ((hash (cons fic-highlighted-words fic-author-name-regexp))) 92 | (if (and fic-saved-hash 93 | (equal fic-saved-hash hash)) 94 | fic-saved-regexp 95 | (let ((fic-words-re (concat "\\<" 96 | (regexp-opt fic-highlighted-words t) 97 | "\\>"))) 98 | (setq fic-saved-hash hash 99 | fic-saved-regexp (concat fic-words-re "\\(?:(\\(" fic-author-name-regexp "\\))\\)?")) 100 | fic-saved-regexp)))) 101 | 102 | (defun fic-in-doc/comment-region (pos) 103 | (memq (get-char-property pos 'face) 104 | fic-activated-faces)) 105 | 106 | (defun fic-search-for-keyword (limit) 107 | (let (match-data-to-set) 108 | (save-match-data 109 | (while (and (null match-data-to-set) 110 | (re-search-forward (fic-search-re) limit t)) 111 | (if (and (fic-in-doc/comment-region (match-beginning 0)) 112 | (fic-in-doc/comment-region (match-end 0))) 113 | (setq match-data-to-set (match-data))))) 114 | (when match-data-to-set 115 | (set-match-data match-data-to-set) 116 | (goto-char (match-end 0)) 117 | t))) 118 | 119 | ;;;###autoload 120 | (define-minor-mode fic-mode 121 | "Fic mode -- minor mode for highlighting FIXME/TODO in comments" 122 | :lighter "" 123 | :group 'fic-mode 124 | (let ((kwlist fic-mode-font-lock-keywords)) 125 | (if fic-mode 126 | (font-lock-add-keywords nil kwlist 'append) 127 | (font-lock-remove-keywords nil kwlist)) 128 | (font-lock-fontify-buffer))) 129 | 130 | (provide 'fic-mode) 131 | ;;; fic-mode.el ends here 132 | --------------------------------------------------------------------------------