diff options
Diffstat (limited to 'lisp/textmodes')
-rw-r--r-- | lisp/textmodes/emacs-authors-mode.el | 145 | ||||
-rw-r--r-- | lisp/textmodes/emacs-news-mode.el | 13 | ||||
-rw-r--r-- | lisp/textmodes/etc-authors-mode.el | 133 |
3 files changed, 154 insertions, 137 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 @@ +;;; emacs-authors-mode.el --- font-locking for etc/AUTHORS -*- lexical-binding: t -*- + +;; Copyright (C) 2021-2022 Free Software Foundation, Inc. + +;; Author: Stefan Kangas <stefan@marxist.se> +;; Keywords: internal + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Major mode to display the etc/AUTHORS file from the Emacs +;; distribution. Provides some basic font locking and not much else. + +;;; Code: + +(require 'subr-x) ; `emacs-etc--hide-local-variables' + +(defgroup emacs-authors-mode nil + "Display the \"etc/AUTHORS\" file from the Emacs distribution." + :version "29.1" + :group 'internal) + +(defface emacs-authors-default + '((t :inherit variable-pitch)) + "Default face used to display the \"etc/AUTHORS\" file. +See also `emacs-authors-mode'." + :version "29.1") + +(defface emacs-authors-author + '((((class color) (min-colors 88) (background light)) + :foreground "midnight blue" + :weight bold :height 1.05 + :inherit variable-pitch) + (((class color) (min-colors 88) (background dark)) + :foreground "cyan" + :weight bold :height 1.05 + :inherit variable-pitch) + (((supports :weight bold) (supports :height 1.05)) + :weight bold :height 1.05 + :inherit variable-pitch) + (((supports :weight bold)) + :weight bold :inherit variable-pitch) + (t :inherit variable-pitch)) + "Face used for the author in the \"etc/AUTHORS\" file. +See also `emacs-authors-mode'." + :version "29.1") + +(defface emacs-authors-descriptor + '((((class color) (min-colors 88) (background light)) + :foreground "sienna" :inherit variable-pitch) + (((class color) (min-colors 88) (background dark)) + :foreground "peru" :inherit variable-pitch) + (t :inherit variable-pitch)) + "Face used for the description text in the \"etc/AUTHORS\" file. +See also `emacs-authors-mode'." + :version "29.1") + +(defface emacs-authors-other-files + '((t :inherit emacs-authors-descriptor)) + "Face used for the \"other files\" text in the \"etc/AUTHORS\" file. +See also `emacs-authors-mode'." + :version "29.1") + +(defconst emacs-authors--author-re + (rx bol (group (not (any blank "\n")) (+? (not (any ":" "\n")))) ":") + "Regexp matching an author in \"etc/AUTHORS\".") + +(defvar emacs-authors-mode-font-lock-keywords + `((,emacs-authors--author-re + 1 'emacs-authors-author) + (,(rx (or "wrote" + (seq (? "and ") (or "co-wrote" "changed")))) + 0 'emacs-authors-descriptor) + (,(rx "and " (+ digit) " other files") + 0 'emacs-authors-other-files) + (,(rx bol (not space) (+ not-newline) eol) + 0 'emacs-authors-default))) + +(defun emacs-authors-next-author (&optional arg) + "Move point to the next author in \"etc/AUTHORS\". +With a prefix arg ARG, move point that many authors forward." + (interactive "p" emacs-authors-mode) + (if (< 0 arg) + (progn + (when (looking-at emacs-authors--author-re) + (forward-line 1)) + (re-search-forward emacs-authors--author-re nil t arg)) + (when (looking-at emacs-authors--author-re) + (forward-line -1)) + (re-search-backward emacs-authors--author-re nil t (abs arg))) + (goto-char (line-beginning-position))) + +(defun emacs-authors-prev-author (&optional arg) + "Move point to the previous author in \"etc/AUTHORS\". +With a prefix arg ARG, move point that many authors backward." + (interactive "p" emacs-authors-mode) + (emacs-authors-next-author (- arg))) + +(defvar emacs-authors-imenu-generic-expression + `((nil ,(rx bol (group (+ (not ":"))) ": " + (or "wrote" "co-wrote" "changed") + " ") + 1))) + +(define-obsolete-variable-alias 'etc-authors-mode-map 'emacs-authors-mode-map "29.1") +(defvar-keymap emacs-authors-mode-map + :doc "Keymap for `emacs-authors-mode'." + "n" #'emacs-authors-next-author + "p" #'emacs-authors-prev-author) + +;;;###autoload +(define-derived-mode emacs-authors-mode special-mode "Authors View" + "Major mode for viewing \"etc/AUTHORS\" from the Emacs distribution. +Provides some basic font locking and not much else." + (setq-local font-lock-defaults + '(emacs-authors-mode-font-lock-keywords nil nil ((?_ . "w")))) + (setq font-lock-multiline nil) + (setq imenu-generic-expression emacs-authors-imenu-generic-expression) + (emacs-etc--hide-local-variables)) + +(define-obsolete-face-alias 'etc-authors-default 'emacs-authors-default "29.1") +(define-obsolete-face-alias 'etc-authors-author 'emacs-authors-author "29.1") +(define-obsolete-face-alias 'etc-authors-descriptor 'emacs-authors-descriptor "29.1") +(define-obsolete-face-alias 'etc-authors-other-files 'emacs-authors-other-files "29.1") +(define-obsolete-function-alias 'etc-authors-next-author #'emacs-authors-next-author "29.1") +(define-obsolete-function-alias 'etc-authors-prev-author #'emacs-authors-prev-author "29.1") +;;;###autoload +(define-obsolete-function-alias 'etc-authors-mode #'emacs-authors-mode "29.1") + +(provide 'emacs-authors-mode) +;;; emacs-authors-mode.el ends here diff --git a/lisp/textmodes/emacs-news-mode.el b/lisp/textmodes/emacs-news-mode.el index e6e1f037284..022e17c9343 100644 --- a/lisp/textmodes/emacs-news-mode.el +++ b/lisp/textmodes/emacs-news-mode.el @@ -25,6 +25,7 @@ (eval-when-compile (require 'cl-lib)) (require 'outline) +(require 'subr-x) ; `emacs-etc--hide-local-variables' (defgroup emacs-news-mode nil "Major mode for editing and viewing the Emacs NEWS file." @@ -59,9 +60,12 @@ "C-x C-q" #'emacs-news-view-mode "<remap> <open-line>" #'emacs-news-open-line) -(defvar-keymap emacs-news-view-mode-map - :parent emacs-news-common-map - "C-x C-q" #'emacs-news-mode) +(defvar emacs-news-view-mode-map + ;; This is defined this way instead of inheriting because we're + ;; deriving the mode from `special-mode' and want the keys from there. + (let ((map (copy-keymap emacs-news-common-map))) + (keymap-set map "C-x C-q" #'emacs-news-mode) + map)) (defvar emacs-news-mode-font-lock-keywords `(("^---$" 0 'emacs-news-does-not-need-documentation) @@ -73,7 +77,8 @@ outline-minor-mode-cycle t outline-level (lambda () (length (match-string 2))) outline-minor-mode-highlight 'append) - (outline-minor-mode)) + (outline-minor-mode) + (emacs-etc--hide-local-variables)) ;;;###autoload (define-derived-mode emacs-news-mode text-mode "NEWS" diff --git a/lisp/textmodes/etc-authors-mode.el b/lisp/textmodes/etc-authors-mode.el deleted file mode 100644 index 7eabdd4c2b8..00000000000 --- a/lisp/textmodes/etc-authors-mode.el +++ /dev/null @@ -1,133 +0,0 @@ -;;; etc-authors-mode.el --- font-locking for etc/AUTHORS -*- lexical-binding: t -*- - -;; Copyright (C) 2021-2022 Free Software Foundation, Inc. - -;; Author: Stefan Kangas <stefan@marxist.se> -;; Keywords: internal - -;; This file is part of GNU Emacs. - -;; GNU Emacs is free software: you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation, either version 3 of the License, or -;; (at your option) any later version. - -;; GNU Emacs is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. - -;;; Commentary: - -;; Major mode to display the etc/AUTHORS file from the Emacs -;; distribution. Provides some basic font locking and not much else. - -;;; Code: - -(defgroup etc-authors-mode nil - "Display the \"etc/AUTHORS\" file from the Emacs distribution." - :version "28.1" - :group 'internal) - -(defface etc-authors-default '((t :inherit variable-pitch)) - "Default face used to display the \"etc/AUTHORS\" file. -See also `etc-authors-mode'." - :version "28.1") - -(defface etc-authors-author '((((class color) (min-colors 88) (background light)) - :foreground "midnight blue" - :weight bold :height 1.05 - :inherit variable-pitch) - (((class color) (min-colors 88) (background dark)) - :foreground "cyan" - :weight bold :height 1.05 - :inherit variable-pitch) - (((supports :weight bold) (supports :height 1.05)) - :weight bold :height 1.05 - :inherit variable-pitch) - (((supports :weight bold)) - :weight bold :inherit variable-pitch) - (t :inherit variable-pitch)) - "Face used for the author in the \"etc/AUTHORS\" file. -See also `etc-authors-mode'." - :version "28.1") - -(defface etc-authors-descriptor '((((class color) (min-colors 88) (background light)) - :foreground "sienna" :inherit variable-pitch) - (((class color) (min-colors 88) (background dark)) - :foreground "peru" :inherit variable-pitch) - (t :inherit variable-pitch)) - "Face used for the description text in the \"etc/AUTHORS\" file. -See also `etc-authors-mode'." - :version "28.1") - -(defface etc-authors-other-files '((t :inherit etc-authors-descriptor)) - "Face used for the \"other files\" text in the \"etc/AUTHORS\" file. -See also `etc-authors-mode'." - :version "28.1") - -(defconst etc-authors--author-re - (rx bol (group (not (any blank "\n")) (+? (not (any ":" "\n")))) ":") - "Regexp matching an author in \"etc/AUTHORS\".") - -(defvar etc-authors-mode-font-lock-keywords - `((,etc-authors--author-re - 1 'etc-authors-author) - (,(rx (or "wrote" - (seq (? "and ") (or "co-wrote" "changed")))) - 0 'etc-authors-descriptor) - (,(rx "and " (+ digit) " other files") - 0 'etc-authors-other-files) - (,(rx bol (not space) (+ not-newline) eol) - 0 'etc-authors-default))) - -(defun etc-authors-mode--hide-local-variables () - "Hide local variables in \"etc/AUTHORS\". Used by `etc-authors-mode'." - (narrow-to-region (point-min) - (save-excursion - (goto-char (point-min)) - ;; Obfuscate to avoid this being interpreted - ;; as a local variable section itself. - (if (re-search-forward "^Local\sVariables:$" nil t) - (progn (forward-line -1) (point)) - (point-max))))) - -(defun etc-authors-next-author (&optional arg) - "Move point to the next author in \"etc/AUTHORS\". -With a prefix arg ARG, move point that many authors forward." - (interactive "p" etc-authors-mode) - (if (< 0 arg) - (progn - (when (looking-at etc-authors--author-re) - (forward-line 1)) - (re-search-forward etc-authors--author-re nil t arg)) - (when (looking-at etc-authors--author-re) - (forward-line -1)) - (re-search-backward etc-authors--author-re nil t (abs arg))) - (goto-char (line-beginning-position))) - -(defun etc-authors-prev-author (&optional arg) - "Move point to the previous author in \"etc/AUTHORS\". -With a prefix arg ARG, move point that many authors backward." - (interactive "p" etc-authors-mode) - (etc-authors-next-author (- arg))) - -(defvar-keymap etc-authors-mode-map - :doc "Keymap for `etc-authors-mode'." - "n" #'etc-authors-next-author - "p" #'etc-authors-prev-author) - -;;;###autoload -(define-derived-mode etc-authors-mode special-mode "Authors View" - "Major mode for viewing \"etc/AUTHORS\" from the Emacs distribution. -Provides some basic font locking and not much else." - (setq-local font-lock-defaults - '(etc-authors-mode-font-lock-keywords nil nil ((?_ . "w")))) - (setq font-lock-multiline nil) - (etc-authors-mode--hide-local-variables)) - -(provide 'etc-authors-mode) -;;; etc-authors-mode.el ends here |