62107
|
1 ;;; jka-cmpr-hook.el --- preloaded code to enable jka-compr.el
|
|
2
|
74441
|
3 ;; Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000, 2002, 2003,
|
106815
|
4 ;; 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
|
62107
|
5
|
|
6 ;; Author: jka@ece.cmu.edu (Jay K. Adams)
|
|
7 ;; Maintainer: FSF
|
|
8 ;; Keywords: data
|
|
9
|
|
10 ;; This file is part of GNU Emacs.
|
|
11
|
94678
|
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
|
62107
|
13 ;; it under the terms of the GNU General Public License as published by
|
94678
|
14 ;; the Free Software Foundation, either version 3 of the License, or
|
|
15 ;; (at your option) any later version.
|
62107
|
16
|
|
17 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20 ;; GNU General Public License for more details.
|
|
21
|
|
22 ;; You should have received a copy of the GNU General Public License
|
94678
|
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
62107
|
24
|
|
25 ;;; Commentary:
|
|
26
|
69161
|
27 ;; This file contains the code to enable and disable Auto-Compression mode.
|
62107
|
28 ;; It is preloaded. The guts of this mode are in jka-compr.el, which
|
|
29 ;; is loaded only when you really try to uncompress something.
|
|
30
|
|
31 ;;; Code:
|
|
32
|
|
33 (defgroup compression nil
|
64014
29c6e26ca9a1
(compression, jka-compr): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
34 "Data compression utilities."
|
62107
|
35 :group 'data)
|
|
36
|
|
37 (defgroup jka-compr nil
|
64014
29c6e26ca9a1
(compression, jka-compr): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
38 "jka-compr customization."
|
62107
|
39 :group 'compression)
|
|
40
|
|
41 ;; List of all the elements we actually added to file-coding-system-alist.
|
|
42 (defvar jka-compr-added-to-file-coding-system-alist nil)
|
|
43
|
|
44 (defvar jka-compr-file-name-handler-entry
|
|
45 nil
|
69161
|
46 "`file-name-handler-alist' entry used by jka-compr I/O functions.")
|
|
47
|
|
48 ;; Compiler defvars. These three variables will be defined later with
|
|
49 ;; `defcustom' when everything used in the :set functions is defined.
|
|
50 (defvar jka-compr-compression-info-list)
|
|
51 (defvar jka-compr-mode-alist-additions)
|
|
52 (defvar jka-compr-load-suffixes)
|
|
53
|
|
54 (defvar jka-compr-compression-info-list--internal nil
|
|
55 "Stored value of `jka-compr-compression-info-list'.
|
|
56 If Auto Compression mode is enabled, this is the value of
|
|
57 `jka-compr-compression-info-list' when `jka-compr-install' was last called.
|
|
58 Otherwise, it is nil.")
|
|
59
|
|
60 (defvar jka-compr-mode-alist-additions--internal nil
|
|
61 "Stored value of `jka-compr-mode-alist-additions'.
|
|
62 If Auto Compression mode is enabled, this is the value of
|
|
63 `jka-compr-mode-alist-additions' when `jka-compr-install' was last called.
|
|
64 Otherwise, it is nil.")
|
|
65
|
|
66 (defvar jka-compr-load-suffixes--internal nil
|
|
67 "Stored value of `jka-compr-load-suffixes'.
|
|
68 If Auto Compression mode is enabled, this is the value of
|
|
69 `jka-compr-load-suffixes' when `jka-compr-install' was last called.
|
|
70 Otherwise, it is nil.")
|
|
71
|
62107
|
72
|
|
73 (defun jka-compr-build-file-regexp ()
|
105965
|
74 (purecopy
|
62107
|
75 (mapconcat
|
|
76 'jka-compr-info-regexp
|
|
77 jka-compr-compression-info-list
|
105965
|
78 "\\|")))
|
62107
|
79
|
66806
|
80 ;; Functions for accessing the return value of jka-compr-get-compression-info
|
62107
|
81 (defun jka-compr-info-regexp (info) (aref info 0))
|
|
82 (defun jka-compr-info-compress-message (info) (aref info 1))
|
|
83 (defun jka-compr-info-compress-program (info) (aref info 2))
|
|
84 (defun jka-compr-info-compress-args (info) (aref info 3))
|
|
85 (defun jka-compr-info-uncompress-message (info) (aref info 4))
|
|
86 (defun jka-compr-info-uncompress-program (info) (aref info 5))
|
|
87 (defun jka-compr-info-uncompress-args (info) (aref info 6))
|
|
88 (defun jka-compr-info-can-append (info) (aref info 7))
|
|
89 (defun jka-compr-info-strip-extension (info) (aref info 8))
|
|
90 (defun jka-compr-info-file-magic-bytes (info) (aref info 9))
|
|
91
|
|
92
|
|
93 (defun jka-compr-get-compression-info (filename)
|
|
94 "Return information about the compression scheme of FILENAME.
|
|
95 The determination as to which compression scheme, if any, to use is
|
|
96 based on the filename itself and `jka-compr-compression-info-list'."
|
|
97 (catch 'compression-info
|
|
98 (let ((case-fold-search nil))
|
84875
5aa8734f1e97
(jka-compr-get-compression-info): Use `mapc' rather than `mapcar'.
Juanma Barranquero <lekktu@gmail.com>
diff
changeset
|
99 (mapc
|
62107
|
100 (function (lambda (x)
|
|
101 (and (string-match (jka-compr-info-regexp x) filename)
|
|
102 (throw 'compression-info x))))
|
|
103 jka-compr-compression-info-list)
|
|
104 nil)))
|
|
105
|
|
106 (defun jka-compr-install ()
|
|
107 "Install jka-compr.
|
|
108 This adds entries to `file-name-handler-alist' and `auto-mode-alist'
|
|
109 and `inhibit-first-line-modes-suffixes'."
|
|
110
|
|
111 (setq jka-compr-file-name-handler-entry
|
|
112 (cons (jka-compr-build-file-regexp) 'jka-compr-handler))
|
|
113
|
66806
|
114 (push jka-compr-file-name-handler-entry file-name-handler-alist)
|
62107
|
115
|
69161
|
116 (setq jka-compr-compression-info-list--internal
|
|
117 jka-compr-compression-info-list
|
|
118 jka-compr-mode-alist-additions--internal
|
|
119 jka-compr-mode-alist-additions
|
|
120 jka-compr-load-suffixes--internal
|
|
121 jka-compr-load-suffixes)
|
|
122
|
66806
|
123 (dolist (x jka-compr-compression-info-list)
|
|
124 ;; Don't do multibyte encoding on the compressed files.
|
|
125 (let ((elt (cons (jka-compr-info-regexp x)
|
|
126 '(no-conversion . no-conversion))))
|
|
127 (push elt file-coding-system-alist)
|
|
128 (push elt jka-compr-added-to-file-coding-system-alist))
|
62107
|
129
|
66806
|
130 (and (jka-compr-info-strip-extension x)
|
|
131 ;; Make entries in auto-mode-alist so that modes
|
|
132 ;; are chosen right according to the file names
|
|
133 ;; sans `.gz'.
|
|
134 (push (list (jka-compr-info-regexp x) nil 'jka-compr) auto-mode-alist)
|
|
135 ;; Also add these regexps to
|
|
136 ;; inhibit-first-line-modes-suffixes, so that a
|
|
137 ;; -*- line in the first file of a compressed tar
|
|
138 ;; file doesn't override tar-mode.
|
|
139 (push (jka-compr-info-regexp x)
|
|
140 inhibit-first-line-modes-suffixes)))
|
62107
|
141 (setq auto-mode-alist
|
|
142 (append auto-mode-alist jka-compr-mode-alist-additions))
|
|
143
|
|
144 ;; Make sure that (load "foo") will find /bla/foo.el.gz.
|
69161
|
145 (setq load-file-rep-suffixes
|
|
146 (append load-file-rep-suffixes jka-compr-load-suffixes nil)))
|
62107
|
147
|
|
148 (defun jka-compr-installed-p ()
|
|
149 "Return non-nil if jka-compr is installed.
|
|
150 The return value is the entry in `file-name-handler-alist' for jka-compr."
|
|
151
|
|
152 (let ((fnha file-name-handler-alist)
|
|
153 (installed nil))
|
|
154
|
|
155 (while (and fnha (not installed))
|
|
156 (and (eq (cdr (car fnha)) 'jka-compr-handler)
|
|
157 (setq installed (car fnha)))
|
|
158 (setq fnha (cdr fnha)))
|
|
159
|
|
160 installed))
|
|
161
|
69161
|
162 (defun jka-compr-update ()
|
|
163 "Update Auto Compression mode for changes in option values.
|
|
164 If you change the options `jka-compr-compression-info-list',
|
|
165 `jka-compr-mode-alist-additions' or `jka-compr-load-suffixes'
|
|
166 outside Custom, while Auto Compression mode is already enabled
|
|
167 \(as it is by default), then you have to call this function
|
|
168 afterward to properly update other variables. Setting these
|
|
169 options through Custom does this automatically."
|
|
170 (when (jka-compr-installed-p)
|
|
171 (jka-compr-uninstall)
|
|
172 (jka-compr-install)))
|
|
173
|
|
174 (defun jka-compr-set (variable value)
|
|
175 "Internal Custom :set function."
|
|
176 (set-default variable value)
|
|
177 (jka-compr-update))
|
|
178
|
69162
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
179 ;; I have this defined so that .Z files are assumed to be in unix
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
180 ;; compress format; and .gz files, in gzip format, and .bz2 files in bzip fmt.
|
91897
|
181
|
|
182 ;; FIXME? It seems ugly that one has to add "\\(~\\|\\.~[0-9]+~\\)?" to
|
|
183 ;; all the regexps here, in order to match backup files etc.
|
|
184 ;; It's trivial to modify jka-compr-get-compression-info to match
|
|
185 ;; regexps against file-name-sans-versions, but this regexp is also
|
|
186 ;; used to build a file-name-handler-alist entry.
|
|
187 ;; find-file-name-handler does not use file-name-sans-versions.
|
|
188 ;; Perhaps it should,
|
|
189 ;; http://lists.gnu.org/archive/html/emacs-devel/2008-02/msg00812.html,
|
|
190 ;; but it's used all over the place and there are probably other ramifications.
|
|
191 ;; One could modify jka-compr-build-file-regexp to add the backup regexp,
|
|
192 ;; but jka-compr-compression-info-list is a defcustom to which
|
|
193 ;; anything could be added, so it's easiest to leave things as they are.
|
69162
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
194 (defcustom jka-compr-compression-info-list
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
195 ;;[regexp
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
196 ;; compr-message compr-prog compr-args
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
197 ;; uncomp-message uncomp-prog uncomp-args
|
82834
|
198 ;; can-append strip-extension-flag file-magic-bytes]
|
105870
|
199 (mapcar 'purecopy
|
69162
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
200 '(["\\.Z\\(~\\|\\.~[0-9]+~\\)?\\'"
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
201 "compressing" "compress" ("-c")
|
84551
|
202 ;; gzip is more common than uncompress. It can only read, not write.
|
84502
|
203 "uncompressing" "gzip" ("-c" "-q" "-d")
|
69162
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
204 nil t "\037\235"]
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
205 ;; Formerly, these had an additional arg "-c", but that fails with
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
206 ;; "Version 0.1pl2, 29-Aug-97." (RedHat 5.1 GNU/Linux) and
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
207 ;; "Version 0.9.0b, 9-Sept-98".
|
75981
8c38d88e2bf3
(jka-compr-compression-info-list): Recognize backups of bz2 compressed files.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
208 ["\\.bz2\\(~\\|\\.~[0-9]+~\\)?\\'"
|
69162
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
209 "bzip2ing" "bzip2" nil
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
210 "bunzip2ing" "bzip2" ("-d")
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
211 nil t "BZh"]
|
98477
|
212 ["\\.tbz2?\\'"
|
69162
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
213 "bzip2ing" "bzip2" nil
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
214 "bunzip2ing" "bzip2" ("-d")
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
215 nil nil "BZh"]
|
91750
|
216 ["\\.\\(?:tgz\\|svgz\\|sifz\\)\\(~\\|\\.~[0-9]+~\\)?\\'"
|
69162
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
217 "compressing" "gzip" ("-c" "-q")
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
218 "uncompressing" "gzip" ("-c" "-q" "-d")
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
219 t nil "\037\213"]
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
220 ["\\.g?z\\(~\\|\\.~[0-9]+~\\)?\\'"
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
221 "compressing" "gzip" ("-c" "-q")
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
222 "uncompressing" "gzip" ("-c" "-q" "-d")
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
223 t t "\037\213"]
|
103523
|
224 ["\\.xz\\(~\\|\\.~[0-9]+~\\)?\\'"
|
|
225 "XZ compressing" "xz" ("-c" "-q")
|
|
226 "XZ uncompressing" "xz" ("-c" "-q" "-d")
|
|
227 t t "\3757zXZ\0"]
|
69162
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
228 ;; dzip is gzip with random access. Its compression program can't
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
229 ;; read/write stdin/out, so .dz files can only be viewed without
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
230 ;; saving, having their contents decompressed with gzip.
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
231 ["\\.dz\\'"
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
232 nil nil nil
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
233 "uncompressing" "gzip" ("-c" "-q" "-d")
|
105870
|
234 nil t "\037\213"]))
|
69162
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
235
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
236 "List of vectors that describe available compression techniques.
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
237 Each element, which describes a compression technique, is a vector of
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
238 the form [REGEXP COMPRESS-MSG COMPRESS-PROGRAM COMPRESS-ARGS
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
239 UNCOMPRESS-MSG UNCOMPRESS-PROGRAM UNCOMPRESS-ARGS
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
240 APPEND-FLAG STRIP-EXTENSION-FLAG FILE-MAGIC-CHARS], where:
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
241
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
242 regexp is a regexp that matches filenames that are
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
243 compressed with this format
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
244
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
245 compress-msg is the message to issue to the user when doing this
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
246 type of compression (nil means no message)
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
247
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
248 compress-program is a program that performs this compression
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
249 (nil means visit file in read-only mode)
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
250
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
251 compress-args is a list of args to pass to the compress program
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
252
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
253 uncompress-msg is the message to issue to the user when doing this
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
254 type of uncompression (nil means no message)
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
255
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
256 uncompress-program is a program that performs this compression
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
257
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
258 uncompress-args is a list of args to pass to the uncompress program
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
259
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
260 append-flag is non-nil if this compression technique can be
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
261 appended
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
262
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
263 strip-extension-flag non-nil means strip the regexp from file names
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
264 before attempting to set the mode.
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
265
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
266 file-magic-chars is a string of characters that you would find
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
267 at the beginning of a file compressed in this way.
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
268
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
269 If you set this outside Custom while Auto Compression mode is
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
270 already enabled \(as it is by default), you have to call
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
271 `jka-compr-update' after setting it to properly update other
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
272 variables. Setting this through Custom does that automatically."
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
273 :type '(repeat (vector regexp
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
274 (choice :tag "Compress Message"
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
275 (string :format "%v")
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
276 (const :tag "No Message" nil))
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
277 (choice :tag "Compress Program"
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
278 (string)
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
279 (const :tag "None" nil))
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
280 (repeat :tag "Compress Arguments" string)
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
281 (choice :tag "Uncompress Message"
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
282 (string :format "%v")
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
283 (const :tag "No Message" nil))
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
284 (choice :tag "Uncompress Program"
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
285 (string)
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
286 (const :tag "None" nil))
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
287 (repeat :tag "Uncompress Arguments" string)
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
288 (boolean :tag "Append")
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
289 (boolean :tag "Strip Extension")
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
290 (string :tag "Magic Bytes")))
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
291 :set 'jka-compr-set
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
292 :group 'jka-compr)
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
293
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
294 (defcustom jka-compr-mode-alist-additions
|
105870
|
295 (list (cons (purecopy "\\.tgz\\'") 'tar-mode) (cons (purecopy "\\.tbz2?\\'") 'tar-mode))
|
69162
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
296 "List of pairs added to `auto-mode-alist' when installing jka-compr.
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
297 Uninstalling jka-compr removes all pairs from `auto-mode-alist' that
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
298 installing added.
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
299
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
300 If you set this outside Custom while Auto Compression mode is
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
301 already enabled \(as it is by default), you have to call
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
302 `jka-compr-update' after setting it to properly update other
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
303 variables. Setting this through Custom does that automatically."
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
304 :type '(repeat (cons string symbol))
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
305 :set 'jka-compr-set
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
306 :group 'jka-compr)
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
307
|
105870
|
308 (defcustom jka-compr-load-suffixes (list (purecopy ".gz"))
|
69162
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
309 "List of compression related suffixes to try when loading files.
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
310 Enabling Auto Compression mode appends this list to `load-file-rep-suffixes',
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
311 which see. Disabling Auto Compression mode removes all suffixes
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
312 from `load-file-rep-suffixes' that enabling added.
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
313
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
314 If you set this outside Custom while Auto Compression mode is
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
315 already enabled \(as it is by default), you have to call
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
316 `jka-compr-update' after setting it to properly update other
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
317 variables. Setting this through Custom does that automatically."
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
318 :type '(repeat string)
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
319 :set 'jka-compr-set
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
320 :group 'jka-compr)
|
ada9af8312a6
Second step of the previous changes: move all defcustoms to where they belong.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
321
|
62107
|
322 (define-minor-mode auto-compression-mode
|
|
323 "Toggle automatic file compression and uncompression.
|
|
324 With prefix argument ARG, turn auto compression on if positive, else off.
|
69161
|
325 Return the new status of auto compression (non-nil means on)."
|
66915
63bd5d2223ee
(auto-compression-mode): Add :version keyword, because default was changed.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
326 :global t :init-value t :group 'jka-compr :version "22.1"
|
62107
|
327 (let* ((installed (jka-compr-installed-p))
|
|
328 (flag auto-compression-mode))
|
|
329 (cond
|
|
330 ((and flag installed) t) ; already installed
|
|
331 ((and (not flag) (not installed)) nil) ; already not installed
|
|
332 (flag (jka-compr-install))
|
|
333 (t (jka-compr-uninstall)))))
|
|
334
|
|
335 (defmacro with-auto-compression-mode (&rest body)
|
|
336 "Evalute BODY with automatic file compression and uncompression enabled."
|
|
337 (let ((already-installed (make-symbol "already-installed")))
|
|
338 `(let ((,already-installed (jka-compr-installed-p)))
|
|
339 (unwind-protect
|
|
340 (progn
|
|
341 (unless ,already-installed
|
|
342 (jka-compr-install))
|
|
343 ,@body)
|
|
344 (unless ,already-installed
|
|
345 (jka-compr-uninstall))))))
|
|
346 (put 'with-auto-compression-mode 'lisp-indent-function 0)
|
|
347
|
|
348
|
66806
|
349 ;; This is what we need to know about jka-compr-handler
|
|
350 ;; in order to decide when to call it.
|
62107
|
351
|
|
352 (put 'jka-compr-handler 'safe-magic t)
|
65991
|
353 (put 'jka-compr-handler 'operations '(byte-compiler-base-file-name
|
62107
|
354 write-region insert-file-contents
|
|
355 file-local-copy load))
|
|
356
|
66806
|
357 ;; Turn on the mode.
|
66876
224ffce45ccb
(auto-compression-mode): Enable it in a way that works correctly for
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
358 (when auto-compression-mode (auto-compression-mode 1))
|
62107
|
359
|
|
360 (provide 'jka-cmpr-hook)
|
|
361
|
|
362 ;; arch-tag: 4bd73429-f400-45fe-a065-270a113e31a8
|
|
363 ;;; jka-cmpr-hook.el ends here
|