├── README.md └── highlight-quoted.el /README.md: -------------------------------------------------------------------------------- 1 | # Highlight quoted minor mode for Emacs 2 | 3 | ## Activate it through a hook 4 | 5 | ``` 6 | (add-hook 'emacs-lisp-mode-hook 'highlight-quoted-mode) 7 | ``` 8 | -------------------------------------------------------------------------------- /highlight-quoted.el: -------------------------------------------------------------------------------- 1 | ;;; highlight-quoted.el --- Highlight Lisp quotes and quoted symbols -*- lexical-binding: t -*- 2 | 3 | ;; Author: Fanael Linithien 4 | ;; URL: https://github.com/Fanael/highlight-quoted 5 | ;; Version: 0.1 6 | ;; Package-Requires: ((emacs "24")) 7 | 8 | ;; This file is NOT part of GNU Emacs. 9 | 10 | ;; Copyright (c) 2014, Fanael Linithien 11 | ;; All rights reserved. 12 | ;; 13 | ;; Redistribution and use in source and binary forms, with or without 14 | ;; modification, are permitted provided that the following conditions are 15 | ;; met: 16 | ;; 17 | ;; * Redistributions of source code must retain the above copyright 18 | ;; notice, this list of conditions and the following disclaimer. 19 | ;; * Redistributions in binary form must reproduce the above copyright 20 | ;; notice, this list of conditions and the following disclaimer in the 21 | ;; documentation and/or other materials provided with the distribution. 22 | ;; 23 | ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | ;; IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 25 | ;; TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 26 | ;; PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 27 | ;; OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | ;; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | ;; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | ;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | ;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | ;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | ;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | ;;; Commentary: 36 | 37 | ;; Minor mode proving highlight of Lisp quotes and quoted symbols. 38 | 39 | ;;; Code: 40 | 41 | (defgroup highlight-quoted nil 42 | "Highlight Lisp quotes." 43 | :prefix "highlight-quoted-" 44 | :group 'faces) 45 | 46 | (defface highlight-quoted-quote 47 | '((t :inherit font-lock-keyword-face)) 48 | "Face to highlight Lisp quotes." 49 | :group 'highlight-quoted) 50 | 51 | (defface highlight-quoted-symbol 52 | '((t :inherit font-lock-constant-face)) 53 | "Face to highlight quoted Lisp symbols." 54 | :group 'highlight-quoted) 55 | 56 | (defcustom highlight-quoted-highlight-symbols t 57 | "Non-nil iff quoted symbols should be highlighted. 58 | 59 | When the value of this variable is changed, `highlight-quoted-mode' must be 60 | re-enabled." 61 | :type 'boolean 62 | :group 'highlight-quoted) 63 | 64 | (defconst highlight-quoted--quote-only-keywords 65 | `((,(rx (or "`" "'" "#'")) . 'highlight-quoted-quote))) 66 | 67 | (defconst highlight-quoted--full-keywords 68 | `((,(rx (and (group (or "`" "'" "#'")) 69 | (? (* whitespace) 70 | (group (+ (or (syntax word) 71 | (syntax symbol))))))) 72 | (1 'highlight-quoted-quote) 73 | (2 'highlight-quoted-symbol nil t)))) 74 | 75 | (defvar highlight-quoted--buffer-keywords nil) 76 | 77 | (defun highlight-quoted--turn-on () 78 | "Set up `highlight-quoted-mode'." 79 | (let ((keywords (if highlight-quoted-highlight-symbols 80 | highlight-quoted--full-keywords 81 | highlight-quoted--quote-only-keywords))) 82 | (set (make-local-variable 'highlight-quoted--buffer-keywords) keywords) 83 | (font-lock-add-keywords nil keywords 'append))) 84 | 85 | (defun highlight-quoted--turn-off () 86 | "Tear down `highlight-quoted-mode'." 87 | (when highlight-quoted--buffer-keywords 88 | (font-lock-remove-keywords nil highlight-quoted--buffer-keywords) 89 | (kill-local-variable 'highlight-quoted--buffer-keywords))) 90 | 91 | ;;;###autoload 92 | (define-minor-mode highlight-quoted-mode 93 | "Highlight Lisp quotes and quoted symbols. 94 | 95 | Toggle Highlight-Quoted mode on or off. 96 | With a prefix argument ARG, enable Highlight-Quoted mode if ARG is positive, and 97 | disable it otherwise. If called from Lisp, enable the mode if ARG is omitted or 98 | nil, and toggle it if ARG is `toggle'. 99 | \\{highlight-quoted-mode-map}" 100 | :init-value nil 101 | :lighter "" 102 | :keymap nil 103 | (highlight-quoted--turn-off) 104 | (when highlight-quoted-mode 105 | (highlight-quoted--turn-on)) 106 | (when font-lock-mode 107 | (if (fboundp 'font-lock-flush) 108 | (font-lock-flush) 109 | (with-no-warnings (font-lock-fontify-buffer))))) 110 | 111 | (provide 'highlight-quoted) 112 | ;;; highlight-quoted.el ends here 113 | --------------------------------------------------------------------------------