Subject: bug#50674: Major mode for etc/AUTHORS with basic font-locking

From: Stefan Kangas <[email-masked]>
Date: Sun, 19 Sep 2021 07:12:40 -0700

Severity: wishlist

Please find attached a small visual improvement for the splash screen,
or rather the AUTHORS file that is reachable from the splash screen.
It comes in the form of a major mode for etc/AUTHORS that has some basic
font-locking and nothing else.

The motivation for this is basically that I have clicked the "AUTHORS"
button on the splash screen and found the file thus reached to be a bit
bare-bone visually.  (It's just a text file.)  Other software tend to
have a bit more formatting, and it's nice to show off in this small way
that Emacs has such capabilities as well.

We could of course live without it, but there's not much reason to.
From 3ae76791e43b6bdd0af8934059471c5ab62c8521 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <[email-masked]>
Date: Sun, 19 Sep 2021 15:46:44 +0200
Subject: [PATCH] New major mode with font-locking for etc/AUTHORS

* lisp/textmodes/etc-authors-mode.el: New file.
* lisp/files.el (auto-mode-alist): Use 'etc-authors-mode' for the
etc/AUTHORS file.
---
 lisp/files.el                      |  3 +-
 lisp/textmodes/etc-authors-mode.el | 80 ++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+), 1 deletion(-)
 create mode 100644 lisp/textmodes/etc-authors-mode.el

diff --git a/lisp/files.el b/lisp/files.el
index b113ff32f2..171b69e01e 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -3006,7 +3006,8 @@ auto-mode-alist
      ("\\.xcf\\'" . image-mode)
      ("\\.xmp\\'" . image-mode)
      ("\\.xwd\\'" . image-mode)
-     ("\\.yuv\\'" . image-mode)))
+     ("\\.yuv\\'" . image-mode)
+     ("emacs.*/etc/AUTHORS\\'" . etc-authors-mode)))
   "Alist of file name patterns vs corresponding major mode functions.
 Each element looks like (REGEXP . FUNCTION) or (REGEXP FUNCTION NON-NIL).
 \(NON-NIL stands for anything that is not nil; the value does not matter.)
diff --git a/lisp/textmodes/etc-authors-mode.el b/lisp/textmodes/etc-authors-mode.el
new file mode 100644
index 0000000000..36312745a0
--- /dev/null
+++ b/lisp/textmodes/etc-authors-mode.el
@@ -0,0 +1,80 @@
+;;; etc-authors-mode.el --- font-locking for etc/AUTHORS  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2021 Free Software Foundation, Inc.
+
+;; Author: Stefan Kangas <[email-masked]>
+;; Keywords: internal
+
+;; This program 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.
+
+;; This program 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 this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Major mode to display the etc/AUTHORS file in the Emacs
+;; distribution.  Provides some basic font locking and not much else.
+
+;;; Code:
+
+(defgroup etc-authors-mode nil
+  "Display the etc/AUTHORS file in the Emacs distribution."
+  :version "28.1")
+
+(defface etc-authors-default '((t :inherit variable-pitch))
+  "Default face used in `etc-authors-mode'."
+  :version "28.1")
+
+(defface etc-authors-author '((t :weight bold :height 1.05
+                                   :inherit variable-pitch))
+  "Face used for the author in `etc-authors-mode'."
+  :version "28.1")
+
+(defface etc-authors-descriptor '((t :foreground "gray30" :italic nil
+                                       :inherit variable-pitch))
+  "Face used for the author in `etc-authors-mode'."
+  :version "28.1")
+
+(defface etc-authors-other-files '((t :inherit etc-authors-descriptor))
+  "Face used for other files in `etc-authors-mode'."
+  :version "28.1")
+
+(defvar etc-authors-mode-font-lock-keywords
+  `((,(rx bol (group (not (any blank "\n")) (+? (not (any ":" "\n")))) ":")
+     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\"."
+  (narrow-to-region (point-min)
+                    (save-excursion
+                      (goto-char (point-min))
+                      (if (re-search-forward "^Local Variables:$" nil t)
+                          (progn (forward-line -1) (point))
+                        (point-max)))))
+
+;;;###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
-- 
2.30.2