diff options
| author | Stefan Monnier | 2020-04-11 13:55:52 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2020-04-11 13:56:03 -0400 |
| commit | 38166443c06b23a6d260c7d443077fe843dfce92 (patch) | |
| tree | 6aa8a1155959b3325371d029d688f851ae20d2c2 | |
| parent | 5084fdb83e2421516f161daff37ea67d1cb63402 (diff) | |
| download | emacs-38166443c06b23a6d260c7d443077fe843dfce92.tar.gz emacs-38166443c06b23a6d260c7d443077fe843dfce92.zip | |
* lisp/progmodes/cl-font-lock.el: Fix header and make it a minor mode
Change copyright to FSF and licence to GPLv3+.
Tweak Commentary (the code doesn't seem to provide the lambda
prettification mentioned).
(cl-font-lock-add-regexes): Remove macro.
(cl-font-lock-built-in-keywords): New variable.
(cl-font-lock-built-in-mode): New minor mode.
| -rw-r--r-- | lisp/progmodes/cl-font-lock.el | 109 |
1 files changed, 57 insertions, 52 deletions
diff --git a/lisp/progmodes/cl-font-lock.el b/lisp/progmodes/cl-font-lock.el index 6d6992e11c1..7ef43fd4490 100644 --- a/lisp/progmodes/cl-font-lock.el +++ b/lisp/progmodes/cl-font-lock.el | |||
| @@ -1,52 +1,59 @@ | |||
| 1 | ;;; cl-font-lock.el --- Pretty Common Lisp font locking -*- lexical-binding: t; -*- | 1 | ;;; cl-font-lock.el --- Pretty Common Lisp font locking -*- lexical-binding: t; -*- |
| 2 | ;; Copyright (C) 2019 Yue Daian | 2 | ;; Copyright (C) 2019-2020 Free Software Foundation, Inc. |
| 3 | ;; Author: Yue Daian | 3 | |
| 4 | ;; Author: Yue Daian <sheepduke@gmail.com> | ||
| 4 | ;; Maintainer: Spenser Truex <web@spensertruex.com> | 5 | ;; Maintainer: Spenser Truex <web@spensertruex.com> |
| 5 | ;; Created: 2019-06-16 | 6 | ;; Created: 2019-06-16 |
| 6 | ;; Version: 0.3.0 | 7 | ;; Old-Version: 0.3.0 |
| 7 | ;; Package-Requires: ((emacs "24.5")) | 8 | ;; Package-Requires: ((emacs "24.5")) |
| 8 | ;; Keywords: lisp wp files convenience | 9 | ;; Keywords: lisp wp files convenience |
| 9 | ;; URL: https://github.com/cl-font-lock/cl-font-lock | 10 | ;; URL: https://github.com/cl-font-lock/cl-font-lock |
| 10 | ;; Homepage: https://github.com/cl-font-lock/cl-font-lock | 11 | ;; Homepage: https://github.com/cl-font-lock/cl-font-lock |
| 11 | ;; This file is not part of GNU Emacs, but you want to use GNU Emacs to run it. | ||
| 12 | ;; This file is very free software. | ||
| 13 | |||
| 14 | ;; This is free and unencumbered software released into the public domain. | ||
| 15 | |||
| 16 | ;; Anyone is free to copy, modify, publish, use, compile, sell, or | ||
| 17 | ;; distribute this software, either in source code form or as a compiled | ||
| 18 | ;; binary, for any purpose, commercial or non-commercial, and by any | ||
| 19 | ;; means. | ||
| 20 | 12 | ||
| 21 | ;; In jurisdictions that recognize copyright laws, the author or authors | 13 | ;; This file is part of GNU Emacs |
| 22 | ;; of this software dedicate any and all copyright interest in the | ||
| 23 | ;; software to the public domain. We make this dedication for the benefit | ||
| 24 | ;; of the public at large and to the detriment of our heirs and | ||
| 25 | ;; successors. We intend this dedication to be an overt act of | ||
| 26 | ;; relinquishment in perpetuity of all present and future rights to this | ||
| 27 | ;; software under copyright law. | ||
| 28 | 14 | ||
| 29 | ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | 15 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
| 30 | ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | 16 | ;; it under the terms of the GNU General Public License as published by |
| 31 | ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | 17 | ;; the Free Software Foundation, either version 3 of the License, or |
| 32 | ;; IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | 18 | ;; (at your option) any later version. |
| 33 | ;; OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
| 34 | ;; ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
| 35 | ;; OTHER DEALINGS IN THE SOFTWARE. | ||
| 36 | 19 | ||
| 37 | ;; For more information, please refer to <http://unlicense.org/>. | 20 | ;; GNU Emacs is distributed in the hope that it will be useful, |
| 21 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 22 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 23 | ;; GNU General Public License for more details. | ||
| 38 | 24 | ||
| 25 | ;; You should have received a copy of the GNU General Public License | ||
| 26 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | ||
| 39 | 27 | ||
| 40 | ;;; Commentary: | 28 | ;;; Commentary: |
| 41 | 29 | ||
| 42 | ;; Highlight all the symbols in the Common Lisp ANSI Standard, and prettify | 30 | ;; Highlight all the symbols in the Common Lisp ANSI Standard. |
| 43 | ;; lambda to display the greek letter. | ||
| 44 | ;; | ||
| 45 | ;; Adds font-lock regexes to lisp-mode. | 31 | ;; Adds font-lock regexes to lisp-mode. |
| 46 | 32 | ||
| 33 | ;;;; Todo: | ||
| 34 | |||
| 35 | ;; - Integrate better into `lisp-mode' (e.g. enable it by default). | ||
| 36 | ;; - Distinguish functions from macros like `pushnew'. | ||
| 37 | |||
| 47 | ;;; Code: | 38 | ;;; Code: |
| 48 | 39 | ||
| 49 | (require 'cl-lib) | 40 | ;; The list of built-in functions and variables was actually not |
| 41 | ;; extracted from the standard, but from SBCL with the following | ||
| 42 | ;; (Common Lisp) code: | ||
| 43 | |||
| 44 | ;; (defvar *functions* nil) | ||
| 45 | ;; (defvar *symbols* nil) | ||
| 46 | ;; (defvar *types* nil) | ||
| 47 | |||
| 48 | ;; (let ((pack (find-package :common-lisp))) | ||
| 49 | ;; (do-all-symbols (sym) | ||
| 50 | ;; (cond | ||
| 51 | ;; ((not (eql pack (symbol-package sym))) nil) | ||
| 52 | ;; ((fboundp sym) (pushnew sym *functions*)) | ||
| 53 | ;; ((find-class sym nil) (pushnew sym *types*)) | ||
| 54 | ;; (t (pushnew sym *symbols*))))) | ||
| 55 | |||
| 56 | |||
| 50 | (defvar cl-font-lock-built-in--functions | 57 | (defvar cl-font-lock-built-in--functions |
| 51 | '("+" "-" "/" "/=" "<" "<=" "=" ">" ">=" "*" "1-" "1+" "abs" "acons" "acos" | 58 | '("+" "-" "/" "/=" "<" "<=" "=" ">" ">=" "*" "1-" "1+" "abs" "acons" "acos" |
| 52 | "acosh" "add-method" "adjoin" "adjustable-array-p" "adjust-array" | 59 | "acosh" "add-method" "adjoin" "adjustable-array-p" "adjust-array" |
| @@ -256,28 +263,26 @@ | |||
| 256 | (defvar cl-font-lock--character-names | 263 | (defvar cl-font-lock--character-names |
| 257 | '("newline" "space" "rubout" "page" "tab" "backspace" "return" "linefeed")) | 264 | '("newline" "space" "rubout" "page" "tab" "backspace" "return" "linefeed")) |
| 258 | 265 | ||
| 259 | (defmacro cl-font-lock-add-regexes (fn mode &rest symbol-face) | 266 | (defvar cl-font-lock-built-in-keywords |
| 260 | "Expand to more than one call to font-lock. | 267 | (mapcar (lambda (s) |
| 261 | Argument FN is the function used to send off the regex. Commonly | 268 | `(,(regexp-opt (symbol-value (car s)) 'symbols) |
| 262 | `font-lock-add-keywords' or `font-lock-remove-keywords'. Argument | 269 | . ,(cdr s))) |
| 263 | MODE is the mode where the regexes are sent. | 270 | '((cl-font-lock-built-in--functions . font-lock-function-name-face) |
| 264 | Optional argument SYMBOL-FACE dotted-pair of (regex-var . font-face)." | 271 | (cl-font-lock-built-in--variables . font-lock-variable-name-face) |
| 265 | `(progn | 272 | (cl-font-lock-built-in--types . font-lock-type-face) |
| 266 | ,@(cl-loop for s in symbol-face | 273 | (cl-font-lock-built-in--symbols . font-lock-builtin-face) |
| 267 | collect | 274 | (cl-font-lock--character-names . font-lock-variable-name-face)))) |
| 268 | `(,fn | ||
| 269 | ',mode | ||
| 270 | `((,(regexp-opt ,(car s) 'symbols) | ||
| 271 | . ,(cdr ',s))))))) | ||
| 272 | 275 | ||
| 273 | (cl-font-lock-add-regexes | 276 | ;;;###autoload |
| 274 | font-lock-add-keywords | 277 | (define-minor-mode cl-font-lock-built-in-mode |
| 275 | lisp-mode | 278 | "Highlight built-in functions, variables, and types in `lisp-mode'." |
| 276 | (cl-font-lock-built-in--functions . font-lock-function-name-face) | 279 | :global t |
| 277 | (cl-font-lock-built-in--variables . font-lock-variable-name-face) | 280 | (funcall |
| 278 | (cl-font-lock-built-in--types . font-lock-type-face) | 281 | (if cl-font-lock-built-in-mode |
| 279 | (cl-font-lock-built-in--symbols . font-lock-builtin-face) | 282 | #'font-lock-add-keywords |
| 280 | (cl-font-lock--character-names . font-lock-variable-name-face)) | 283 | #'font-lock-remove-keywords) |
| 284 | 'lisp-mode | ||
| 285 | cl-font-lock-built-in-keywords)) | ||
| 281 | 286 | ||
| 282 | (provide 'cl-font-lock) | 287 | (provide 'cl-font-lock) |
| 283 | 288 | ||