aboutsummaryrefslogtreecommitdiffstats
path: root/admin/admin.el
diff options
context:
space:
mode:
authorStefan Kangas2022-09-16 14:17:14 +0200
committerStefan Kangas2022-09-16 16:19:29 +0200
commitf232d989fd90dc35b647da9db152d70b421f35a9 (patch)
tree39565d253c924ed081795369f3a6f9d30e90241c /admin/admin.el
parent397890ba77465f71c4ccd38314f30907b78193b8 (diff)
downloademacs-f232d989fd90dc35b647da9db152d70b421f35a9.tar.gz
emacs-f232d989fd90dc35b647da9db152d70b421f35a9.zip
Improve HTML export of NEWS file
* admin/admin.el (admin--org-export-headers-format) (admin--org-html-postamble): New variables. (admin--require-external-package): New function. (make-news-html-file): Improve HTML export.
Diffstat (limited to 'admin/admin.el')
-rw-r--r--admin/admin.el211
1 files changed, 130 insertions, 81 deletions
diff --git a/admin/admin.el b/admin/admin.el
index 12e6fcb7f8c..60b043a3516 100644
--- a/admin/admin.el
+++ b/admin/admin.el
@@ -770,69 +770,13 @@ Optional argument TYPE is type of output (nil means all)."
770 (if (member type (list nil m)) 770 (if (member type (list nil m))
771 (make-manuals-dist--1 root m)))) 771 (make-manuals-dist--1 root m))))
772 772
773(defun make-news-html-file (root version) 773(defvar admin--org-export-headers-format "\
774 "Convert the NEWS file into an HTML file."
775 (interactive (let ((root
776 (if noninteractive
777 (or (pop command-line-args-left)
778 default-directory)
779 (read-directory-name "Emacs root directory: "
780 source-directory nil t))))
781 (list root
782 (read-string "Version number: " emacs-version))))
783 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
784 (user-error "%s doesn't seem to be the root of an Emacs source tree" root))
785 (let* ((dir (make-temp-file "emacs-news-file" t))
786 (orig (expand-file-name "etc/NEWS" root))
787 (new (expand-file-name (format "NEWS.%s.org" version) dir))
788 (html-file (format "%s.html" (file-name-base new)))
789 (copyright-years (format-time-string "%Y")))
790 (unwind-protect
791 (progn
792 (copy-file orig new)
793 (find-file new)
794
795 ;; Find the copyright range:
796 (goto-char (point-min))
797 (re-search-forward "^Copyright (C) \\([0-9-]+\\) Free Software Foundation, Inc.")
798 (setq copyright-years (match-string 1))
799
800 ;; Get rid of some unnecessary stuff:
801 (replace-regexp-in-region "^---$" "" (point-min) (point-max))
802 (replace-regexp-in-region "^\\+\\+\\+$" "" (point-min) (point-max))
803 (dolist (str '(" \n"
804 "GNU Emacs NEWS -- history of user-visible changes."
805 "Temporary note:"
806 "+++ indicates that all relevant manuals in doc/ have been updated."
807 "--- means no change in the manuals is needed."
808 "When you add a new item, use the appropriate mark if you are sure it"
809 "applies, and please also update docstrings as needed."
810 "You can narrow news to a specific version by calling 'view-emacs-news'"
811 "with a prefix argument or by typing 'C-u C-h C-n'."))
812 (replace-string-in-region str "" (point-min) (point-max)))
813
814 ;; Use Org-mode markers for <code>.
815 (replace-regexp-in-region
816 ;; This could probably be improved quite a bit...
817 (rx "'" (group (+ (not (any "'\n")))) "'")
818 "~\\1~" (point-min) (point-max))
819
820 ;; Format Emacs Lisp.
821 (while (re-search-forward "^ " nil t)
822 (backward-paragraph)
823 (insert "\n#+begin_src emacs-lisp")
824 (forward-paragraph)
825 (insert "#+end_src\n"))
826
827 ;; Insert Org-mode export headers.
828 (goto-char (point-min))
829 (insert (format
830 "\
831#+title: GNU Emacs %s NEWS -- history of user-visible changes 774#+title: GNU Emacs %s NEWS -- history of user-visible changes
832#+author: 775#+author:
833#+options: author:nil creator:nil toc:1 num:2 *:nil \\n:nil 776#+options: author:nil creator:nil toc:1 num:2 *:nil \\n:t ^:nil tex:nil
834#+language: en 777#+language: en
835#+HTML_LINK_HOME: https://www.gnu.org/software/emacs 778#+HTML_LINK_HOME: /software/emacs
779#+HTML_LINK_UP: /software/emacs
836#+html_head_extra: <link rel=\"stylesheet\" type=\"text/css\" href=\"/mini.css\" media=\"handheld\" /> 780#+html_head_extra: <link rel=\"stylesheet\" type=\"text/css\" href=\"/mini.css\" media=\"handheld\" />
837#+html_head_extra: <link rel=\"stylesheet\" type=\"text/css\" href=\"/layout.min.css\" media=\"screen\" /> 781#+html_head_extra: <link rel=\"stylesheet\" type=\"text/css\" href=\"/layout.min.css\" media=\"screen\" />
838#+html_head_extra: <link rel=\"stylesheet\" type=\"text/css\" href=\"/print.min.css\" media=\"print\" /> 782#+html_head_extra: <link rel=\"stylesheet\" type=\"text/css\" href=\"/print.min.css\" media=\"print\" />
@@ -844,12 +788,9 @@ Optional argument TYPE is type of output (nil means all)."
844of a GNU] \" width=\"129\" height=\"122\"/> 788of a GNU] \" width=\"129\" height=\"122\"/>
845</a> 789</a>
846</div> 790</div>
847#+END_EXPORT\n\n" 791#+END_EXPORT\n\n")
848 version)) 792
849 (org-mode) 793(defvar admin--org-html-postamble "
850 (let ((org-html-postamble
851 (format
852 "
853<p> 794<p>
854Return to the <a href=\"/software/emacs/emacs.html\">GNU Emacs home page</a>. 795Return to the <a href=\"/software/emacs/emacs.html\">GNU Emacs home page</a>.
855</p> 796</p>
@@ -884,21 +825,129 @@ $Date: %s $
884<!-- timestamp end --> 825<!-- timestamp end -->
885</p> 826</p>
886</div> 827</div>
887</div>" 828</div>")
888 copyright-years 829
889 ;; e.g. "2022/09/13 09:13:13" 830(defun admin--require-external-package (pkg)
890 (format-time-string "%Y/%M/%y %H:%m:%S")))) 831 (package-initialize)
891 ;; Actually export. 832 (require pkg nil t)
892 (org-html-export-to-html) 833 (unless (featurep pkg)
893 ;; Kill the .org buffer. 834 (when (yes-or-no-p (format "Package \"%s\" is missing. Install now?" pkg))
894 (kill-buffer (current-buffer)) 835 (package-install pkg)
895 ;; Move file into place. 836 (require pkg nil t))))
896 (let ((old (expand-file-name html-file dir)) 837
897 (new (expand-file-name html-file (expand-file-name "etc" root)))) 838(defvar org-html-postamble)
898 (delete-file new) 839(defvar org-html-mathjax-template)
899 (copy-file old new) 840(defun make-news-html-file (root version)
900 (find-file new)))) 841 "Convert the NEWS file into an HTML file."
901 (delete-directory dir t)))) 842 (interactive (let ((root
843 (if noninteractive
844 (or (pop command-line-args-left)
845 default-directory)
846 (read-directory-name "Emacs root directory: "
847 source-directory nil t))))
848 (list root
849 (read-string "Major version number: "
850 (number-to-string emacs-major-version)))))
851 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
852 (user-error "%s doesn't seem to be the root of an Emacs source tree" root))
853 (admin--require-external-package 'htmlize)
854 (let* ((orig (expand-file-name "etc/NEWS" root))
855 (new (expand-file-name (format "etc/NEWS.%s.org" version) root))
856 (html-file (format "%s.html" (file-name-base new)))
857 (copyright-years (format-time-string "%Y")))
858 (copy-file orig new t)
859 (find-file new)
860
861 ;; Find the copyright range.
862 (goto-char (point-min))
863 (re-search-forward "^Copyright (C) \\([0-9-]+\\) Free Software Foundation, Inc.")
864 (setq copyright-years (match-string 1))
865
866 ;; Delete some unnecessary stuff.
867 (replace-regexp-in-region "^---$" "" (point-min) (point-max))
868 (replace-regexp-in-region "^\\+\\+\\+$" "" (point-min) (point-max))
869 (dolist (str '(" \n"
870 "GNU Emacs NEWS -- history of user-visible changes."
871 "Temporary note:"
872 "+++ indicates that all relevant manuals in doc/ have been updated."
873 "--- means no change in the manuals is needed."
874 "When you add a new item, use the appropriate mark if you are sure it"
875 "applies, and please also update docstrings as needed."
876 "You can narrow news to a specific version by calling 'view-emacs-news'"
877 "with a prefix argument or by typing 'C-u C-h C-n'."))
878 (replace-string-in-region str "" (point-min) (point-max)))
879
880 ;; Escape some characters.
881 (replace-regexp-in-region (rx "$") "@@html:&dollar;@@" (point-min) (point-max))
882
883 ;; Use Org-mode markers for 'symbols', 'C-x k', etc.
884 (replace-regexp-in-region
885 (rx-let ((key (seq
886 ;; Modifier (optional)
887 (? (any "ACHMSs") "-")
888 (or
889 ;; single key
890 (not (any " \n"))
891 ;; "<return>" and "<remap> <foo>"
892 (seq "<"
893 (+ (any "A-Za-z-"))
894 (+ (seq " " (+ (any "A-Za-z-"))))
895 ">")
896 "NUL" "RET" "LFD" "TAB"
897 "ESC" "SPC" "DEL")))
898 (email (seq (+ (not (any " @\n")))
899 "@"
900 (+ (not (any " @\n")))))
901 (lisp-symbol (regexp lisp-mode-symbol-regexp)))
902 (rx "'" (group
903 (or lisp-symbol
904 email
905 (seq "M-x " lisp-symbol)
906 (seq key (+ " " key))))
907 "'"))
908 "~\\1~" (point-min) (point-max))
909
910 ;; Format code blocks.
911 (while (re-search-forward "^ " nil t)
912 (let ((elisp-block (looking-at "(")))
913 (backward-paragraph)
914 (insert (if elisp-block
915 "\n#+BEGIN_SRC emacs-lisp"
916 "\n#+BEGIN_EXAMPLE"))
917 (forward-paragraph)
918 (insert (if elisp-block
919 "#+END_SRC\n"
920 "#+END_EXAMPLE\n"))))
921
922 ;; Delete buffer local variables.
923 (goto-char (point-max))
924 (when (re-search-backward "Local variables:")
925 (forward-line -1)
926 (delete-region (point) (point-max)))
927
928 ;; Insert Org-mode export headers.
929 (goto-char (point-min))
930 (insert (format admin--org-export-headers-format version))
931 (org-mode)
932 (save-buffer)
933
934 ;; Make the HTML export.
935 (let* ((org-html-postamble
936 (format admin--org-html-postamble
937 copyright-years
938 ;; e.g. "2022/09/13 09:13:13"
939 (format-time-string "%Y/%M/%y %H:%m:%S")))
940 (org-html-mathjax-template "")
941 (htmlize-output-type 'css))
942 (org-html-export-as-html))
943
944 ;; Write HTML to file.
945 (let ((new (expand-file-name html-file (expand-file-name "etc" root))))
946 (write-file new)
947 (unless noninteractive
948 (find-file new)
949 (html-mode))
950 (message "Successfully exported HTML to %s" new))))
902 951
903 952
904;; Stuff to check new `defcustom's got :version tags. 953;; Stuff to check new `defcustom's got :version tags.