Subject: [PATCH] Compress past NEWS files during installation

From: [email-masked]
Date: Wed, 26 Dec 2018 13:49:28 -0600

This shaves off just over a MB off of the installation using gzip -9.
While I was at it, I put in the compression of etc/refcards/*.ps, which
covers part of a TODO.

I wanted to compress etc/refcards/*.tex as well, but I noticed that it
would affect the Makefile that is also installed. It appears to be the
only Makefile that's installed; if there's little or no reason for it,
would it be okay to remove it during installation and compress the *.tex
files as well?

>From 40bd26ccbbae7c486dc2be39fe21147694889af4 Mon Sep 17 00:00:00 2001
From: Alexander Gramiak <[email-masked]>
Date: Mon, 24 Dec 2018 18:06:30 -0600
Subject: [PATCH] Compress past NEWS files and etc/refcards/*.ps

Do not compress NEWS or ORG-NEWS as those are actively updated and
shouldn't rely on decompression support to be viewed.

* Makefile.in (install-arch-indep): Do it.

* lisp/help.el (view-emacs-news): Refactor slightly, and support
compressed NEWS files when `auto-compression-mode' is enabled.
---
 Makefile.in  |  9 ++++++---
 etc/NEWS     |  3 +++
 lisp/help.el | 28 +++++++++++++++++-----------
 3 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index f0b2b66c88..bbb028a74a 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -541,8 +541,7 @@ set_installuser=
 ## install-etcdoc installs the relevant DOC.
 
 ## Note that we install etc/refcards/*.ps if present.
-## TODO we should compress these if GZIP_PROG is set.
-## It would be simpler to have a separate install rule for etc/refcards
+## TODO It would be simpler to have a separate install rule for etc/refcards
 ## (maybe move it to doc/refcards?).
 
 ## Note that the Makefiles in the etc directory are potentially useful
@@ -616,7 +615,11 @@ install-arch-indep:
 	  for f in `find . -name "*.elc" -print | sed 's/.elc$$/.el/'`; do \
 	    ${GZIP_PROG} -9n "$$f"; \
 	  done; \
-	  ${GZIP_PROG} -9n "../etc/publicsuffix.txt"; \
+	  cd "$(DESTDIR)${etcdir}" && \
+	  for f in `find . -maxdepth 1 -name "*NEWS*" -not -name NEWS \
+	-not -name ORG-NEWS` `find refcards -name "*.ps"` "publicsuffix.txt"; do \
+	    ${GZIP_PROG} -9n "$$f"; \
+	  done; \
 	}
 	-chmod -R a+r "$(DESTDIR)${datadir}/emacs/${version}" ${COPYDESTS}
 
diff --git a/etc/NEWS b/etc/NEWS
index e427e84780..586e7065d1 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -37,6 +37,9 @@ functions 'json-serialize', 'json-insert', 'json-parse-string', and
 'json-parse-buffer' are typically much faster than their Lisp
 counterparts from json.el.
 
+** NEWS files for past Emacs versions and packages are now compressed
+by default.
+
 ** The etags program now uses the C library's regular expression matcher
 when possible, and a compatible regex substitute otherwise.  This will
 let developers maintain Emacs's own regex code without having to also
diff --git a/lisp/help.el b/lisp/help.el
index ad782f74ca..e0738da485 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -350,16 +350,18 @@ view-emacs-news
 	      (mapc
 	       (lambda (file)
 		 (with-temp-buffer
-		   (insert-file-contents
-		    (expand-file-name file data-directory))
-		   (while (re-search-forward
-			   (if (member file '("NEWS.18" "NEWS.1-17"))
-			       "Changes in \\(?:Emacs\\|version\\)?[ \t]*\\([0-9]+\\(?:\\.[0-9]+\\)?\\)"
-			     "^\\* [^0-9\n]*\\([0-9]+\\.[0-9]+\\)") nil t)
-		     (setq res (cons (match-string-no-properties 1) res)))))
-	       (cons "NEWS"
-		     (directory-files data-directory nil
-				      "^NEWS\\.[0-9][-0-9]*$" nil)))
+		   (insert-file-contents file)
+                   (let ((section (if (string-match "\\`NEWS\\.\\(1-17\\|18\\)"
+                                                    (file-name-nondirectory file))
+                                      "Changes in \\(?:Emacs\\|version\\)?[ \t]*\\([0-9]+\\(?:\\.[0-9]+\\)?\\)"
+			            "^\\* [^0-9\n]*\\([0-9]+\\.[0-9]+\\)")))
+                     (while (re-search-forward section nil t)
+                       (setq res (cons (match-string-no-properties 1) res))))))
+	       (cons (expand-file-name "NEWS" data-directory)
+		     (directory-files data-directory
+                                      t
+				      (format "^NEWS\\.[0-9][-0-9]*%s\\'"
+                                              (regexp-opt load-file-rep-suffixes)))))
 	      (sort (delete-dups res) #'string>)))
 	   (current (car all-versions)))
       (setq version (completing-read
@@ -385,7 +387,11 @@ view-emacs-news
 		((< vn 18) "NEWS.1-17")
 		(t (format "NEWS.%d" vn))))
 	 res)
-    (view-file (expand-file-name file data-directory))
+    (view-file (or (locate-file file
+                                (list data-directory)
+                                load-file-rep-suffixes)
+                   (error "Requested NEWS file is compressed; please enable \
+`auto-compression-mode' and try again")))
     (widen)
     (goto-char (point-min))
     (when (stringp version)
-- 
2.20.1