changeset 69161:70d5fa701ff8

(jka-compr-compression-info-list) (jka-compr-mode-alist-additions, jka-compr-load-suffixes): Give :set functions to provide automatic updating. Update docstring. Give compiler defvars early in the file and move the defcustoms to a later spot where all called functions are defined. (jka-compr-file-name-handler-entry): Doc fix. (jka-compr-compression-info-list--internal) (jka-compr-mode-alist-additions--internal) (jka-compr-load-suffixes--internal): New variables. (jka-compr-install): Set the three above variables. Update `load-file-rep-suffixes' instead of `load-suffixes'. (jka-compr-update, jka-compr-set): New functions. (auto-compression-mode): Doc fix. These changes are installed in two steps to provide better diffs. The present revision makes no sense without the next one.
author Luc Teirlinck <teirllm@auburn.edu>
date Mon, 27 Feb 2006 01:47:56 +0000
parents 21adf79dfc57
children ada9af8312a6
files lisp/jka-cmpr-hook.el
diffstat 1 files changed, 80 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/jka-cmpr-hook.el	Mon Feb 27 01:44:20 2006 +0000
+++ b/lisp/jka-cmpr-hook.el	Mon Feb 27 01:47:56 2006 +0000
@@ -26,7 +26,7 @@
 
 ;;; Commentary:
 
-;; This file contains the  code to enable and disable Auto-Compression mode.
+;; This file contains the code to enable and disable Auto-Compression mode.
 ;; It is preloaded.  The guts of this mode are in jka-compr.el, which
 ;; is loaded only when you really try to uncompress something.
 
@@ -113,7 +113,12 @@
 
 Because of the way `call-process' is defined, discarding the stderr output of
 a program adds the overhead of starting a shell each time the program is
-invoked."
+invoked.
+
+If you set this outside Custom while Auto Compression mode is
+already enabled \(as it is by default), you have to call
+`jka-compr-update' after setting it to properly update other
+variables.  Setting this through Custom does that automatically."
   :type '(repeat (vector regexp
 			 (choice :tag "Compress Message"
 				 (string :format "%v")
@@ -132,17 +137,35 @@
 			 (boolean :tag "Append")
 			 (boolean :tag "Strip Extension")
 			 (string :tag "Magic Bytes")))
+  :set 'jka-compr-set
   :group 'jka-compr)
 
 (defcustom jka-compr-mode-alist-additions
   (list (cons "\\.tgz\\'" 'tar-mode) (cons "\\.tbz\\'" 'tar-mode))
-  "A list of pairs to add to `auto-mode-alist' when jka-compr is installed."
+  "List of pairs added to `auto-mode-alist' when installing jka-compr.
+Uninstalling jka-compr removes all pairs from `auto-mode-alist' that
+installing added.
+
+If you set this outside Custom while Auto Compression mode is
+already enabled \(as it is by default), you have to call
+`jka-compr-update' after setting it to properly update other
+variables.  Setting this through Custom does that automatically."
   :type '(repeat (cons string symbol))
+  :set 'jka-compr-set
   :group 'jka-compr)
 
 (defcustom jka-compr-load-suffixes '(".gz")
-  "List of suffixes to try when loading files."
+  "List of compression related suffixes to try when loading files.
+Enabling Auto Compression mode appends this list to `load-file-rep-suffixes',
+which see.  Disabling Auto Compression mode removes all suffixes
+from `load-file-rep-suffixes' that enabling added.
+
+If you set this outside Custom while Auto Compression mode is
+already enabled \(as it is by default), you have to call
+`jka-compr-update' after setting it to properly update other
+variables.  Setting this through Custom does that automatically."
   :type '(repeat string)
+  :set 'jka-compr-set
   :group 'jka-compr)
 
 ;; List of all the elements we actually added to file-coding-system-alist.
@@ -150,7 +173,32 @@
 
 (defvar jka-compr-file-name-handler-entry
   nil
-  "The entry in `file-name-handler-alist' used by the jka-compr I/O functions.")
+  "`file-name-handler-alist' entry used by jka-compr I/O functions.")
+
+;; Compiler defvars.  These three variables will be defined later with
+;; `defcustom' when everything used in the :set functions is defined.
+(defvar jka-compr-compression-info-list)
+(defvar jka-compr-mode-alist-additions)
+(defvar jka-compr-load-suffixes)
+
+(defvar jka-compr-compression-info-list--internal nil
+  "Stored value of `jka-compr-compression-info-list'.
+If Auto Compression mode is enabled, this is the value of
+`jka-compr-compression-info-list' when `jka-compr-install' was last called.
+Otherwise, it is nil.")
+
+(defvar jka-compr-mode-alist-additions--internal nil
+  "Stored value of `jka-compr-mode-alist-additions'.
+If Auto Compression mode is enabled, this is the value of
+`jka-compr-mode-alist-additions' when `jka-compr-install' was last called.
+Otherwise, it is nil.")
+
+(defvar jka-compr-load-suffixes--internal nil
+  "Stored value of `jka-compr-load-suffixes'.
+If Auto Compression mode is enabled, this is the value of
+`jka-compr-load-suffixes' when `jka-compr-install' was last called.
+Otherwise, it is nil.")
+
 
 (defun jka-compr-build-file-regexp ()
   (mapconcat
@@ -194,6 +242,13 @@
 
   (push jka-compr-file-name-handler-entry file-name-handler-alist)
 
+  (setq jka-compr-compression-info-list--internal
+	jka-compr-compression-info-list
+	jka-compr-mode-alist-additions--internal
+	jka-compr-mode-alist-additions
+	jka-compr-load-suffixes--internal
+	jka-compr-load-suffixes)
+
   (dolist (x jka-compr-compression-info-list)
     ;; Don't do multibyte encoding on the compressed files.
     (let ((elt (cons (jka-compr-info-regexp x)
@@ -216,15 +271,8 @@
 	(append auto-mode-alist jka-compr-mode-alist-additions))
 
   ;; Make sure that (load "foo") will find /bla/foo.el.gz.
-  (setq load-suffixes
-	(apply 'append
-	       (append (mapcar (lambda (suffix)
-                               (cons suffix
-                                     (mapcar (lambda (ext) (concat suffix ext))
-                                             jka-compr-load-suffixes)))
-                             load-suffixes)
-                       (list jka-compr-load-suffixes)))))
-
+  (setq load-file-rep-suffixes
+	(append load-file-rep-suffixes jka-compr-load-suffixes nil)))
 
 (defun jka-compr-installed-p ()
   "Return non-nil if jka-compr is installed.
@@ -240,10 +288,27 @@
 
     installed))
 
+(defun jka-compr-update ()
+  "Update Auto Compression mode for changes in option values.
+If you change the options `jka-compr-compression-info-list',
+`jka-compr-mode-alist-additions' or `jka-compr-load-suffixes'
+outside Custom, while Auto Compression mode is already enabled
+\(as it is by default), then you have to call this function
+afterward to properly update other variables.  Setting these
+options through Custom does this automatically."
+  (when (jka-compr-installed-p)
+    (jka-compr-uninstall)
+    (jka-compr-install)))
+
+(defun jka-compr-set (variable value)
+  "Internal Custom :set function."
+  (set-default variable value)
+  (jka-compr-update))
+
 (define-minor-mode auto-compression-mode
   "Toggle automatic file compression and uncompression.
 With prefix argument ARG, turn auto compression on if positive, else off.
-Returns the new status of auto compression (non-nil means on)."
+Return the new status of auto compression (non-nil means on)."
   :global t :init-value t :group 'jka-compr :version "22.1"
   (let* ((installed (jka-compr-installed-p))
 	 (flag auto-compression-mode))