From: Stefan Kangas Date: Wed, 14 Sep 2022 14:22:59 +0000 (+0200) Subject: Automate exporting etc/NEWS to HTML X-Git-Tag: emacs-28.3-rc1~91 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=5543aea1b2b8c68481ae0ce2bb501d8484ef7f7c;p=emacs.git Automate exporting etc/NEWS to HTML * admin/admin.el (make-news-html-file): New function. * .gitignore: Ignore generated "etc/NEWS*.html" file. --- diff --git a/.gitignore b/.gitignore index 2254b8a9c8e..e48e3594269 100644 --- a/.gitignore +++ b/.gitignore @@ -263,6 +263,7 @@ doc/misc/cc-mode.ss doc/misc/modus-themes.texi doc/misc/org.texi etc/DOC +etc/NEWS*.html etc/refcards/emacsver.tex gnustmp* /info/ diff --git a/admin/admin.el b/admin/admin.el index 67cbf85a32a..12e6fcb7f8c 100644 --- a/admin/admin.el +++ b/admin/admin.el @@ -770,6 +770,136 @@ Optional argument TYPE is type of output (nil means all)." (if (member type (list nil m)) (make-manuals-dist--1 root m)))) +(defun make-news-html-file (root version) + "Convert the NEWS file into an HTML file." + (interactive (let ((root + (if noninteractive + (or (pop command-line-args-left) + default-directory) + (read-directory-name "Emacs root directory: " + source-directory nil t)))) + (list root + (read-string "Version number: " emacs-version)))) + (unless (file-exists-p (expand-file-name "src/emacs.c" root)) + (user-error "%s doesn't seem to be the root of an Emacs source tree" root)) + (let* ((dir (make-temp-file "emacs-news-file" t)) + (orig (expand-file-name "etc/NEWS" root)) + (new (expand-file-name (format "NEWS.%s.org" version) dir)) + (html-file (format "%s.html" (file-name-base new))) + (copyright-years (format-time-string "%Y"))) + (unwind-protect + (progn + (copy-file orig new) + (find-file new) + + ;; Find the copyright range: + (goto-char (point-min)) + (re-search-forward "^Copyright (C) \\([0-9-]+\\) Free Software Foundation, Inc.") + (setq copyright-years (match-string 1)) + + ;; Get rid of some unnecessary stuff: + (replace-regexp-in-region "^---$" "" (point-min) (point-max)) + (replace-regexp-in-region "^\\+\\+\\+$" "" (point-min) (point-max)) + (dolist (str '(" \n" + "GNU Emacs NEWS -- history of user-visible changes." + "Temporary note:" + "+++ indicates that all relevant manuals in doc/ have been updated." + "--- means no change in the manuals is needed." + "When you add a new item, use the appropriate mark if you are sure it" + "applies, and please also update docstrings as needed." + "You can narrow news to a specific version by calling 'view-emacs-news'" + "with a prefix argument or by typing 'C-u C-h C-n'.")) + (replace-string-in-region str "" (point-min) (point-max))) + + ;; Use Org-mode markers for . + (replace-regexp-in-region + ;; This could probably be improved quite a bit... + (rx "'" (group (+ (not (any "'\n")))) "'") + "~\\1~" (point-min) (point-max)) + + ;; Format Emacs Lisp. + (while (re-search-forward "^ " nil t) + (backward-paragraph) + (insert "\n#+begin_src emacs-lisp") + (forward-paragraph) + (insert "#+end_src\n")) + + ;; Insert Org-mode export headers. + (goto-char (point-min)) + (insert (format + "\ +#+title: GNU Emacs %s NEWS -- history of user-visible changes +#+author: +#+options: author:nil creator:nil toc:1 num:2 *:nil \\n:nil +#+language: en +#+HTML_LINK_HOME: https://www.gnu.org/software/emacs +#+html_head_extra: +#+html_head_extra: +#+html_head_extra: + +#+BEGIN_EXPORT html +
+ +\" + +
+#+END_EXPORT\n\n" + version)) + (org-mode) + (let ((org-html-postamble + (format + " +

+Return to the GNU Emacs home page. +

+ +
+
+ +

+Please send FSF & GNU inquiries to +<gnu@gnu.org>. +There are also other ways to contact +the FSF. +Broken links and other corrections or suggestions can be sent to +<bug-gnu-emacs@gnu.org>. +

+
+ +

+ Copyright © %s Free Software Foundation, Inc. +

+ +

This page is licensed under +a CC-BY-SA +license.

+ + + +

+Updated: + +$Date: %s $ + +

+
+" + copyright-years + ;; e.g. "2022/09/13 09:13:13" + (format-time-string "%Y/%M/%y %H:%m:%S")))) + ;; Actually export. + (org-html-export-to-html) + ;; Kill the .org buffer. + (kill-buffer (current-buffer)) + ;; Move file into place. + (let ((old (expand-file-name html-file dir)) + (new (expand-file-name html-file (expand-file-name "etc" root)))) + (delete-file new) + (copy-file old new) + (find-file new)))) + (delete-directory dir t)))) + ;; Stuff to check new `defcustom's got :version tags. ;; Adapted from check-declare.el.