diff options
Diffstat (limited to 'lisp/textmodes/emacs-authors-mode.el')
| -rw-r--r-- | lisp/textmodes/emacs-authors-mode.el | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/lisp/textmodes/emacs-authors-mode.el b/lisp/textmodes/emacs-authors-mode.el new file mode 100644 index 00000000000..af78ab605e9 --- /dev/null +++ b/lisp/textmodes/emacs-authors-mode.el | |||
| @@ -0,0 +1,145 @@ | |||
| 1 | ;;; emacs-authors-mode.el --- font-locking for etc/AUTHORS -*- lexical-binding: t -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2021-2022 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Stefan Kangas <stefan@marxist.se> | ||
| 6 | ;; Keywords: internal | ||
| 7 | |||
| 8 | ;; This file is part of GNU Emacs. | ||
| 9 | |||
| 10 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 11 | ;; it under the terms of the GNU General Public License as published by | ||
| 12 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 13 | ;; (at your option) any later version. | ||
| 14 | |||
| 15 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 18 | ;; GNU General Public License for more details. | ||
| 19 | |||
| 20 | ;; You should have received a copy of the GNU General Public License | ||
| 21 | ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. | ||
| 22 | |||
| 23 | ;;; Commentary: | ||
| 24 | |||
| 25 | ;; Major mode to display the etc/AUTHORS file from the Emacs | ||
| 26 | ;; distribution. Provides some basic font locking and not much else. | ||
| 27 | |||
| 28 | ;;; Code: | ||
| 29 | |||
| 30 | (require 'subr-x) ; `emacs-etc--hide-local-variables' | ||
| 31 | |||
| 32 | (defgroup emacs-authors-mode nil | ||
| 33 | "Display the \"etc/AUTHORS\" file from the Emacs distribution." | ||
| 34 | :version "29.1" | ||
| 35 | :group 'internal) | ||
| 36 | |||
| 37 | (defface emacs-authors-default | ||
| 38 | '((t :inherit variable-pitch)) | ||
| 39 | "Default face used to display the \"etc/AUTHORS\" file. | ||
| 40 | See also `emacs-authors-mode'." | ||
| 41 | :version "29.1") | ||
| 42 | |||
| 43 | (defface emacs-authors-author | ||
| 44 | '((((class color) (min-colors 88) (background light)) | ||
| 45 | :foreground "midnight blue" | ||
| 46 | :weight bold :height 1.05 | ||
| 47 | :inherit variable-pitch) | ||
| 48 | (((class color) (min-colors 88) (background dark)) | ||
| 49 | :foreground "cyan" | ||
| 50 | :weight bold :height 1.05 | ||
| 51 | :inherit variable-pitch) | ||
| 52 | (((supports :weight bold) (supports :height 1.05)) | ||
| 53 | :weight bold :height 1.05 | ||
| 54 | :inherit variable-pitch) | ||
| 55 | (((supports :weight bold)) | ||
| 56 | :weight bold :inherit variable-pitch) | ||
| 57 | (t :inherit variable-pitch)) | ||
| 58 | "Face used for the author in the \"etc/AUTHORS\" file. | ||
| 59 | See also `emacs-authors-mode'." | ||
| 60 | :version "29.1") | ||
| 61 | |||
| 62 | (defface emacs-authors-descriptor | ||
| 63 | '((((class color) (min-colors 88) (background light)) | ||
| 64 | :foreground "sienna" :inherit variable-pitch) | ||
| 65 | (((class color) (min-colors 88) (background dark)) | ||
| 66 | :foreground "peru" :inherit variable-pitch) | ||
| 67 | (t :inherit variable-pitch)) | ||
| 68 | "Face used for the description text in the \"etc/AUTHORS\" file. | ||
| 69 | See also `emacs-authors-mode'." | ||
| 70 | :version "29.1") | ||
| 71 | |||
| 72 | (defface emacs-authors-other-files | ||
| 73 | '((t :inherit emacs-authors-descriptor)) | ||
| 74 | "Face used for the \"other files\" text in the \"etc/AUTHORS\" file. | ||
| 75 | See also `emacs-authors-mode'." | ||
| 76 | :version "29.1") | ||
| 77 | |||
| 78 | (defconst emacs-authors--author-re | ||
| 79 | (rx bol (group (not (any blank "\n")) (+? (not (any ":" "\n")))) ":") | ||
| 80 | "Regexp matching an author in \"etc/AUTHORS\".") | ||
| 81 | |||
| 82 | (defvar emacs-authors-mode-font-lock-keywords | ||
| 83 | `((,emacs-authors--author-re | ||
| 84 | 1 'emacs-authors-author) | ||
| 85 | (,(rx (or "wrote" | ||
| 86 | (seq (? "and ") (or "co-wrote" "changed")))) | ||
| 87 | 0 'emacs-authors-descriptor) | ||
| 88 | (,(rx "and " (+ digit) " other files") | ||
| 89 | 0 'emacs-authors-other-files) | ||
| 90 | (,(rx bol (not space) (+ not-newline) eol) | ||
| 91 | 0 'emacs-authors-default))) | ||
| 92 | |||
| 93 | (defun emacs-authors-next-author (&optional arg) | ||
| 94 | "Move point to the next author in \"etc/AUTHORS\". | ||
| 95 | With a prefix arg ARG, move point that many authors forward." | ||
| 96 | (interactive "p" emacs-authors-mode) | ||
| 97 | (if (< 0 arg) | ||
| 98 | (progn | ||
| 99 | (when (looking-at emacs-authors--author-re) | ||
| 100 | (forward-line 1)) | ||
| 101 | (re-search-forward emacs-authors--author-re nil t arg)) | ||
| 102 | (when (looking-at emacs-authors--author-re) | ||
| 103 | (forward-line -1)) | ||
| 104 | (re-search-backward emacs-authors--author-re nil t (abs arg))) | ||
| 105 | (goto-char (line-beginning-position))) | ||
| 106 | |||
| 107 | (defun emacs-authors-prev-author (&optional arg) | ||
| 108 | "Move point to the previous author in \"etc/AUTHORS\". | ||
| 109 | With a prefix arg ARG, move point that many authors backward." | ||
| 110 | (interactive "p" emacs-authors-mode) | ||
| 111 | (emacs-authors-next-author (- arg))) | ||
| 112 | |||
| 113 | (defvar emacs-authors-imenu-generic-expression | ||
| 114 | `((nil ,(rx bol (group (+ (not ":"))) ": " | ||
| 115 | (or "wrote" "co-wrote" "changed") | ||
| 116 | " ") | ||
| 117 | 1))) | ||
| 118 | |||
| 119 | (define-obsolete-variable-alias 'etc-authors-mode-map 'emacs-authors-mode-map "29.1") | ||
| 120 | (defvar-keymap emacs-authors-mode-map | ||
| 121 | :doc "Keymap for `emacs-authors-mode'." | ||
| 122 | "n" #'emacs-authors-next-author | ||
| 123 | "p" #'emacs-authors-prev-author) | ||
| 124 | |||
| 125 | ;;;###autoload | ||
| 126 | (define-derived-mode emacs-authors-mode special-mode "Authors View" | ||
| 127 | "Major mode for viewing \"etc/AUTHORS\" from the Emacs distribution. | ||
| 128 | Provides some basic font locking and not much else." | ||
| 129 | (setq-local font-lock-defaults | ||
| 130 | '(emacs-authors-mode-font-lock-keywords nil nil ((?_ . "w")))) | ||
| 131 | (setq font-lock-multiline nil) | ||
| 132 | (setq imenu-generic-expression emacs-authors-imenu-generic-expression) | ||
| 133 | (emacs-etc--hide-local-variables)) | ||
| 134 | |||
| 135 | (define-obsolete-face-alias 'etc-authors-default 'emacs-authors-default "29.1") | ||
| 136 | (define-obsolete-face-alias 'etc-authors-author 'emacs-authors-author "29.1") | ||
| 137 | (define-obsolete-face-alias 'etc-authors-descriptor 'emacs-authors-descriptor "29.1") | ||
| 138 | (define-obsolete-face-alias 'etc-authors-other-files 'emacs-authors-other-files "29.1") | ||
| 139 | (define-obsolete-function-alias 'etc-authors-next-author #'emacs-authors-next-author "29.1") | ||
| 140 | (define-obsolete-function-alias 'etc-authors-prev-author #'emacs-authors-prev-author "29.1") | ||
| 141 | ;;;###autoload | ||
| 142 | (define-obsolete-function-alias 'etc-authors-mode #'emacs-authors-mode "29.1") | ||
| 143 | |||
| 144 | (provide 'emacs-authors-mode) | ||
| 145 | ;;; emacs-authors-mode.el ends here | ||