aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/jka-cmpr-hook.el95
1 files changed, 80 insertions, 15 deletions
diff --git a/lisp/jka-cmpr-hook.el b/lisp/jka-cmpr-hook.el
index 3de3b7daccc..94cffad9d9a 100644
--- a/lisp/jka-cmpr-hook.el
+++ b/lisp/jka-cmpr-hook.el
@@ -26,7 +26,7 @@
26 26
27;;; Commentary: 27;;; Commentary:
28 28
29;; This file contains the code to enable and disable Auto-Compression mode. 29;; This file contains the code to enable and disable Auto-Compression mode.
30;; It is preloaded. The guts of this mode are in jka-compr.el, which 30;; It is preloaded. The guts of this mode are in jka-compr.el, which
31;; is loaded only when you really try to uncompress something. 31;; is loaded only when you really try to uncompress something.
32 32
@@ -113,7 +113,12 @@ APPEND-FLAG STRIP-EXTENSION-FLAG FILE-MAGIC-CHARS], where:
113 113
114Because of the way `call-process' is defined, discarding the stderr output of 114Because of the way `call-process' is defined, discarding the stderr output of
115a program adds the overhead of starting a shell each time the program is 115a program adds the overhead of starting a shell each time the program is
116invoked." 116invoked.
117
118If you set this outside Custom while Auto Compression mode is
119already enabled \(as it is by default), you have to call
120`jka-compr-update' after setting it to properly update other
121variables. Setting this through Custom does that automatically."
117 :type '(repeat (vector regexp 122 :type '(repeat (vector regexp
118 (choice :tag "Compress Message" 123 (choice :tag "Compress Message"
119 (string :format "%v") 124 (string :format "%v")
@@ -132,17 +137,35 @@ invoked."
132 (boolean :tag "Append") 137 (boolean :tag "Append")
133 (boolean :tag "Strip Extension") 138 (boolean :tag "Strip Extension")
134 (string :tag "Magic Bytes"))) 139 (string :tag "Magic Bytes")))
140 :set 'jka-compr-set
135 :group 'jka-compr) 141 :group 'jka-compr)
136 142
137(defcustom jka-compr-mode-alist-additions 143(defcustom jka-compr-mode-alist-additions
138 (list (cons "\\.tgz\\'" 'tar-mode) (cons "\\.tbz\\'" 'tar-mode)) 144 (list (cons "\\.tgz\\'" 'tar-mode) (cons "\\.tbz\\'" 'tar-mode))
139 "A list of pairs to add to `auto-mode-alist' when jka-compr is installed." 145 "List of pairs added to `auto-mode-alist' when installing jka-compr.
146Uninstalling jka-compr removes all pairs from `auto-mode-alist' that
147installing added.
148
149If you set this outside Custom while Auto Compression mode is
150already enabled \(as it is by default), you have to call
151`jka-compr-update' after setting it to properly update other
152variables. Setting this through Custom does that automatically."
140 :type '(repeat (cons string symbol)) 153 :type '(repeat (cons string symbol))
154 :set 'jka-compr-set
141 :group 'jka-compr) 155 :group 'jka-compr)
142 156
143(defcustom jka-compr-load-suffixes '(".gz") 157(defcustom jka-compr-load-suffixes '(".gz")
144 "List of suffixes to try when loading files." 158 "List of compression related suffixes to try when loading files.
159Enabling Auto Compression mode appends this list to `load-file-rep-suffixes',
160which see. Disabling Auto Compression mode removes all suffixes
161from `load-file-rep-suffixes' that enabling added.
162
163If you set this outside Custom while Auto Compression mode is
164already enabled \(as it is by default), you have to call
165`jka-compr-update' after setting it to properly update other
166variables. Setting this through Custom does that automatically."
145 :type '(repeat string) 167 :type '(repeat string)
168 :set 'jka-compr-set
146 :group 'jka-compr) 169 :group 'jka-compr)
147 170
148;; List of all the elements we actually added to file-coding-system-alist. 171;; List of all the elements we actually added to file-coding-system-alist.
@@ -150,7 +173,32 @@ invoked."
150 173
151(defvar jka-compr-file-name-handler-entry 174(defvar jka-compr-file-name-handler-entry
152 nil 175 nil
153 "The entry in `file-name-handler-alist' used by the jka-compr I/O functions.") 176 "`file-name-handler-alist' entry used by jka-compr I/O functions.")
177
178;; Compiler defvars. These three variables will be defined later with
179;; `defcustom' when everything used in the :set functions is defined.
180(defvar jka-compr-compression-info-list)
181(defvar jka-compr-mode-alist-additions)
182(defvar jka-compr-load-suffixes)
183
184(defvar jka-compr-compression-info-list--internal nil
185 "Stored value of `jka-compr-compression-info-list'.
186If Auto Compression mode is enabled, this is the value of
187`jka-compr-compression-info-list' when `jka-compr-install' was last called.
188Otherwise, it is nil.")
189
190(defvar jka-compr-mode-alist-additions--internal nil
191 "Stored value of `jka-compr-mode-alist-additions'.
192If Auto Compression mode is enabled, this is the value of
193`jka-compr-mode-alist-additions' when `jka-compr-install' was last called.
194Otherwise, it is nil.")
195
196(defvar jka-compr-load-suffixes--internal nil
197 "Stored value of `jka-compr-load-suffixes'.
198If Auto Compression mode is enabled, this is the value of
199`jka-compr-load-suffixes' when `jka-compr-install' was last called.
200Otherwise, it is nil.")
201
154 202
155(defun jka-compr-build-file-regexp () 203(defun jka-compr-build-file-regexp ()
156 (mapconcat 204 (mapconcat
@@ -194,6 +242,13 @@ and `inhibit-first-line-modes-suffixes'."
194 242
195 (push jka-compr-file-name-handler-entry file-name-handler-alist) 243 (push jka-compr-file-name-handler-entry file-name-handler-alist)
196 244
245 (setq jka-compr-compression-info-list--internal
246 jka-compr-compression-info-list
247 jka-compr-mode-alist-additions--internal
248 jka-compr-mode-alist-additions
249 jka-compr-load-suffixes--internal
250 jka-compr-load-suffixes)
251
197 (dolist (x jka-compr-compression-info-list) 252 (dolist (x jka-compr-compression-info-list)
198 ;; Don't do multibyte encoding on the compressed files. 253 ;; Don't do multibyte encoding on the compressed files.
199 (let ((elt (cons (jka-compr-info-regexp x) 254 (let ((elt (cons (jka-compr-info-regexp x)
@@ -216,15 +271,8 @@ and `inhibit-first-line-modes-suffixes'."
216 (append auto-mode-alist jka-compr-mode-alist-additions)) 271 (append auto-mode-alist jka-compr-mode-alist-additions))
217 272
218 ;; Make sure that (load "foo") will find /bla/foo.el.gz. 273 ;; Make sure that (load "foo") will find /bla/foo.el.gz.
219 (setq load-suffixes 274 (setq load-file-rep-suffixes
220 (apply 'append 275 (append load-file-rep-suffixes jka-compr-load-suffixes nil)))
221 (append (mapcar (lambda (suffix)
222 (cons suffix
223 (mapcar (lambda (ext) (concat suffix ext))
224 jka-compr-load-suffixes)))
225 load-suffixes)
226 (list jka-compr-load-suffixes)))))
227
228 276
229(defun jka-compr-installed-p () 277(defun jka-compr-installed-p ()
230 "Return non-nil if jka-compr is installed. 278 "Return non-nil if jka-compr is installed.
@@ -240,10 +288,27 @@ The return value is the entry in `file-name-handler-alist' for jka-compr."
240 288
241 installed)) 289 installed))
242 290
291(defun jka-compr-update ()
292 "Update Auto Compression mode for changes in option values.
293If you change the options `jka-compr-compression-info-list',
294`jka-compr-mode-alist-additions' or `jka-compr-load-suffixes'
295outside Custom, while Auto Compression mode is already enabled
296\(as it is by default), then you have to call this function
297afterward to properly update other variables. Setting these
298options through Custom does this automatically."
299 (when (jka-compr-installed-p)
300 (jka-compr-uninstall)
301 (jka-compr-install)))
302
303(defun jka-compr-set (variable value)
304 "Internal Custom :set function."
305 (set-default variable value)
306 (jka-compr-update))
307
243(define-minor-mode auto-compression-mode 308(define-minor-mode auto-compression-mode
244 "Toggle automatic file compression and uncompression. 309 "Toggle automatic file compression and uncompression.
245With prefix argument ARG, turn auto compression on if positive, else off. 310With prefix argument ARG, turn auto compression on if positive, else off.
246Returns the new status of auto compression (non-nil means on)." 311Return the new status of auto compression (non-nil means on)."
247 :global t :init-value t :group 'jka-compr :version "22.1" 312 :global t :init-value t :group 'jka-compr :version "22.1"
248 (let* ((installed (jka-compr-installed-p)) 313 (let* ((installed (jka-compr-installed-p))
249 (flag auto-compression-mode)) 314 (flag auto-compression-mode))