jka-compr.el 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. ;;; jka-compr.el --- reading/writing/loading compressed files
  2. ;; Copyright (C) 1993-1995, 1997, 1999-2012 Free Software Foundation, Inc.
  3. ;; Author: jka@ece.cmu.edu (Jay K. Adams)
  4. ;; Maintainer: FSF
  5. ;; Keywords: data
  6. ;; This file is part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; This package implements low-level support for reading, writing,
  19. ;; and loading compressed files. It hooks into the low-level file
  20. ;; I/O functions (including write-region and insert-file-contents) so
  21. ;; that they automatically compress or uncompress a file if the file
  22. ;; appears to need it (based on the extension of the file name).
  23. ;; Packages like Rmail, VM, GNUS, and Info should be able to work
  24. ;; with compressed files without modification.
  25. ;; INSTRUCTIONS:
  26. ;;
  27. ;; To use jka-compr, invoke the command `auto-compression-mode' (which
  28. ;; see), or customize the variable of the same name. Its operation
  29. ;; should be transparent to the user (except for messages appearing when
  30. ;; a file is being compressed or uncompressed).
  31. ;;
  32. ;; The variable, jka-compr-compression-info-list can be used to
  33. ;; customize jka-compr to work with other compression programs.
  34. ;; The default value of this variable allows jka-compr to work with
  35. ;; Unix compress and gzip.
  36. ;;
  37. ;; If you don't want messages about compressing and decompressing
  38. ;; to show up in the echo area, you can set the compress-msg and
  39. ;; decompress-msg fields of the jka-compr-compression-info-list to
  40. ;; nil.
  41. ;; APPLICATION NOTES:
  42. ;;
  43. ;; crypt++
  44. ;; jka-compr can coexist with crypt++ if you take all the decompression
  45. ;; entries out of the crypt-encoding-list. Clearly problems will arise if
  46. ;; you have two programs trying to compress/decompress files. jka-compr
  47. ;; will not "work with" crypt++ in the following sense: you won't be able to
  48. ;; decode encrypted compressed files--that is, files that have been
  49. ;; compressed then encrypted (in that order). Theoretically, crypt++ and
  50. ;; jka-compr could properly handle a file that has been encrypted then
  51. ;; compressed, but there is little point in trying to compress an encrypted
  52. ;; file.
  53. ;;
  54. ;; ACKNOWLEDGMENTS
  55. ;;
  56. ;; jka-compr is a V19 adaptation of jka-compr for V18 of Emacs. Many people
  57. ;; have made helpful suggestions, reported bugs, and even fixed bugs in
  58. ;; jka-compr. I recall the following people as being particularly helpful.
  59. ;;
  60. ;; Jean-loup Gailly
  61. ;; David Hughes
  62. ;; Richard Pieri
  63. ;; Daniel Quinlan
  64. ;; Chris P. Ross
  65. ;; Rick Sladkey
  66. ;;
  67. ;; Andy Norman's ange-ftp was the inspiration for the original jka-compr for
  68. ;; Version 18 of Emacs.
  69. ;;
  70. ;; After I had made progress on the original jka-compr for V18, I learned of a
  71. ;; package written by Kazushi Jam Marukawa, called jam-zcat, that did exactly
  72. ;; what I was trying to do. I looked over the jam-zcat source code and
  73. ;; probably got some ideas from it.
  74. ;;
  75. ;;; Code:
  76. (require 'jka-cmpr-hook)
  77. (defcustom jka-compr-shell "sh"
  78. "Shell to be used for calling compression programs.
  79. NOTE: Not used in MS-DOS and Windows systems."
  80. :type 'string
  81. :group 'jka-compr)
  82. (defvar jka-compr-use-shell
  83. (not (memq system-type '(ms-dos windows-nt))))
  84. (defvar jka-compr-really-do-compress nil
  85. "Non-nil in a buffer whose visited file was uncompressed on visiting it.
  86. This means compress the data on writing the file, even if the
  87. data appears to be compressed already.")
  88. (make-variable-buffer-local 'jka-compr-really-do-compress)
  89. (put 'jka-compr-really-do-compress 'permanent-local t)
  90. (put 'compression-error 'error-conditions '(compression-error file-error error))
  91. (defvar jka-compr-acceptable-retval-list '(0 2 141))
  92. (defun jka-compr-error (prog args infile message &optional errfile)
  93. (let ((errbuf (get-buffer-create " *jka-compr-error*")))
  94. (with-current-buffer errbuf
  95. (widen) (erase-buffer)
  96. (insert (format "Error while executing \"%s %s < %s\"\n\n"
  97. prog
  98. (mapconcat 'identity args " ")
  99. infile))
  100. (and errfile
  101. (insert-file-contents errfile)))
  102. (display-buffer errbuf))
  103. (signal 'compression-error
  104. (list "Opening input file" (format "error %s" message) infile)))
  105. (defcustom jka-compr-dd-program "/bin/dd"
  106. "How to invoke `dd'."
  107. :type 'string
  108. :group 'jka-compr)
  109. (defvar jka-compr-dd-blocksize 256)
  110. (defun jka-compr-partial-uncompress (prog message args infile beg len)
  111. "Call program PROG with ARGS args taking input from INFILE.
  112. Fourth and fifth args, BEG and LEN, specify which part of the output
  113. to keep: LEN chars starting BEG chars from the beginning."
  114. (let ((start (point))
  115. (prefix beg))
  116. (if (and jka-compr-use-shell jka-compr-dd-program)
  117. ;; Put the uncompression output through dd
  118. ;; to discard the part we don't want.
  119. (let ((skip (/ beg jka-compr-dd-blocksize))
  120. (err-file (jka-compr-make-temp-name))
  121. ;; call-process barfs if default-directory is inaccessible.
  122. (default-directory
  123. (if (and default-directory
  124. (file-accessible-directory-p default-directory))
  125. default-directory
  126. (file-name-directory infile)))
  127. count)
  128. ;; Update PREFIX based on the text that we won't read in.
  129. (setq prefix (- beg (* skip jka-compr-dd-blocksize))
  130. count (and len (1+ (/ (+ len prefix) jka-compr-dd-blocksize))))
  131. (unwind-protect
  132. (or (memq (call-process
  133. jka-compr-shell infile t nil "-c"
  134. ;; Windows shells need the program file name
  135. ;; after the pipe symbol be quoted if they use
  136. ;; forward slashes as directory separators.
  137. (format
  138. "%s %s 2> %s | \"%s\" bs=%d skip=%d %s 2> %s"
  139. prog
  140. (mapconcat 'identity args " ")
  141. err-file
  142. jka-compr-dd-program
  143. jka-compr-dd-blocksize
  144. skip
  145. ;; dd seems to be unreliable about
  146. ;; providing the last block. So, always
  147. ;; read one more than you think you need.
  148. (if count (format "count=%d" (1+ count)) "")
  149. null-device))
  150. jka-compr-acceptable-retval-list)
  151. (jka-compr-error prog args infile message err-file))
  152. (delete-file err-file)))
  153. ;; Run the uncompression program directly.
  154. ;; We get the whole file and must delete what we don't want.
  155. (jka-compr-call-process prog message infile t nil args))
  156. ;; Delete the stuff after what we want, if there is any.
  157. (and
  158. len
  159. (< (+ start prefix len) (point))
  160. (delete-region (+ start prefix len) (point)))
  161. ;; Delete the stuff before what we want.
  162. (delete-region start (+ start prefix))))
  163. (defun jka-compr-call-process (prog message infile output temp args)
  164. ;; call-process barfs if default-directory is inaccessible.
  165. (let ((default-directory
  166. (if (and default-directory
  167. (not (file-remote-p default-directory))
  168. (file-accessible-directory-p default-directory))
  169. default-directory
  170. (file-name-directory infile))))
  171. (if jka-compr-use-shell
  172. (let ((err-file (jka-compr-make-temp-name))
  173. (coding-system-for-read (or coding-system-for-read 'undecided))
  174. (coding-system-for-write 'no-conversion))
  175. (unwind-protect
  176. (or (memq
  177. (call-process jka-compr-shell infile
  178. (if (stringp output) nil output)
  179. nil
  180. "-c"
  181. (format "%s %s 2> %s %s"
  182. prog
  183. (mapconcat 'identity args " ")
  184. err-file
  185. (if (stringp output)
  186. (concat "> " output)
  187. "")))
  188. jka-compr-acceptable-retval-list)
  189. (jka-compr-error prog args infile message err-file))
  190. (delete-file err-file)))
  191. (or (eq 0
  192. (apply 'call-process
  193. prog infile (if (stringp output) temp output)
  194. nil args))
  195. (jka-compr-error prog args infile message))
  196. (and (stringp output)
  197. (with-current-buffer temp
  198. (write-region (point-min) (point-max) output)
  199. (erase-buffer))))))
  200. ;; Support for temp files. Much of this was inspired if not lifted
  201. ;; from ange-ftp.
  202. (defcustom jka-compr-temp-name-template
  203. (expand-file-name "jka-com" temporary-file-directory)
  204. "Prefix added to all temp files created by jka-compr.
  205. There should be no more than seven characters after the final `/'."
  206. :type 'string
  207. :group 'jka-compr)
  208. (defun jka-compr-make-temp-name (&optional _local-copy)
  209. "This routine will return the name of a new file."
  210. (make-temp-file jka-compr-temp-name-template))
  211. (defun jka-compr-write-region (start end file &optional append visit)
  212. (let* ((filename (expand-file-name file))
  213. (visit-file (if (stringp visit) (expand-file-name visit) filename))
  214. (info (jka-compr-get-compression-info visit-file))
  215. (magic (and info (jka-compr-info-file-magic-bytes info))))
  216. ;; If we uncompressed this file when visiting it,
  217. ;; then recompress it when writing it
  218. ;; even if the contents look compressed already.
  219. (if (and jka-compr-really-do-compress
  220. (or (null start)
  221. (= (- end start) (buffer-size))))
  222. (setq magic nil))
  223. (if (and info
  224. ;; If the contents to be written out
  225. ;; are properly compressed already,
  226. ;; don't try to compress them over again.
  227. (not (and magic
  228. (equal (if (stringp start)
  229. (substring start 0 (min (length start)
  230. (length magic)))
  231. (let* ((from (or start (point-min)))
  232. (to (min (or end (point-max))
  233. (+ from (length magic)))))
  234. (buffer-substring from to)))
  235. magic))))
  236. (let ((can-append (jka-compr-info-can-append info))
  237. (compress-program (jka-compr-info-compress-program info))
  238. (compress-message (jka-compr-info-compress-message info))
  239. (compress-args (jka-compr-info-compress-args info))
  240. (base-name (file-name-nondirectory visit-file))
  241. temp-file temp-buffer
  242. ;; we need to leave `last-coding-system-used' set to its
  243. ;; value after calling write-region the first time, so
  244. ;; that `basic-save-buffer' sees the right value.
  245. (coding-system-used last-coding-system-used))
  246. (or compress-program
  247. (error "No compression program defined"))
  248. (setq temp-buffer (get-buffer-create " *jka-compr-wr-temp*"))
  249. (with-current-buffer temp-buffer
  250. (widen) (erase-buffer))
  251. (if (and append
  252. (not can-append)
  253. (file-exists-p filename))
  254. (let* ((local-copy (file-local-copy filename))
  255. (local-file (or local-copy filename)))
  256. (setq temp-file local-file))
  257. (setq temp-file (jka-compr-make-temp-name)))
  258. (and
  259. compress-message
  260. jka-compr-verbose
  261. (message "%s %s..." compress-message base-name))
  262. (jka-compr-run-real-handler 'write-region
  263. (list start end temp-file t 'dont))
  264. ;; save value used by the real write-region
  265. (setq coding-system-used last-coding-system-used)
  266. ;; Here we must read the output of compress program as is
  267. ;; without any code conversion.
  268. (let ((coding-system-for-read 'no-conversion))
  269. (jka-compr-call-process compress-program
  270. (concat compress-message
  271. " " base-name)
  272. temp-file
  273. temp-buffer
  274. nil
  275. compress-args))
  276. (with-current-buffer temp-buffer
  277. (let ((coding-system-for-write 'no-conversion))
  278. (if (memq system-type '(ms-dos windows-nt))
  279. (setq buffer-file-type t) )
  280. (jka-compr-run-real-handler 'write-region
  281. (list (point-min) (point-max)
  282. filename
  283. (and append can-append) 'dont))
  284. (erase-buffer)) )
  285. (delete-file temp-file)
  286. (and
  287. compress-message
  288. jka-compr-verbose
  289. (message "%s %s...done" compress-message base-name))
  290. (cond
  291. ((eq visit t)
  292. (setq buffer-file-name filename)
  293. (setq jka-compr-really-do-compress t)
  294. (set-visited-file-modtime))
  295. ((stringp visit)
  296. (setq buffer-file-name visit)
  297. (let ((buffer-file-name filename))
  298. (set-visited-file-modtime))))
  299. (and (or (eq visit t)
  300. (eq visit nil)
  301. (stringp visit))
  302. (message "Wrote %s" visit-file))
  303. ;; ensure `last-coding-system-used' has an appropriate value
  304. (setq last-coding-system-used coding-system-used)
  305. nil)
  306. (jka-compr-run-real-handler 'write-region
  307. (list start end filename append visit)))))
  308. (defun jka-compr-insert-file-contents (file &optional visit beg end replace)
  309. (barf-if-buffer-read-only)
  310. (and (or beg end)
  311. visit
  312. (error "Attempt to visit less than an entire file"))
  313. (let* ((filename (expand-file-name file))
  314. (info (jka-compr-get-compression-info filename)))
  315. (if (not info)
  316. (jka-compr-run-real-handler 'insert-file-contents
  317. (list file visit beg end replace))
  318. (let ((uncompress-message (jka-compr-info-uncompress-message info))
  319. (uncompress-program (jka-compr-info-uncompress-program info))
  320. (uncompress-args (jka-compr-info-uncompress-args info))
  321. (base-name (file-name-nondirectory filename))
  322. (notfound nil)
  323. (local-copy
  324. (jka-compr-run-real-handler 'file-local-copy (list filename)))
  325. local-file
  326. size start)
  327. (setq local-file (or local-copy filename))
  328. (and
  329. visit
  330. (setq buffer-file-name filename))
  331. (unwind-protect ; to make sure local-copy gets deleted
  332. (progn
  333. (and
  334. uncompress-message
  335. jka-compr-verbose
  336. (message "%s %s..." uncompress-message base-name))
  337. (condition-case error-code
  338. (let ((coding-system-for-read 'no-conversion))
  339. (if replace
  340. (goto-char (point-min)))
  341. (setq start (point))
  342. (if (or beg end)
  343. (jka-compr-partial-uncompress uncompress-program
  344. (concat uncompress-message
  345. " " base-name)
  346. uncompress-args
  347. local-file
  348. (or beg 0)
  349. (if (and beg end)
  350. (- end beg)
  351. end))
  352. ;; If visiting, bind off buffer-file-name so that
  353. ;; file-locking will not ask whether we should
  354. ;; really edit the buffer.
  355. (let ((buffer-file-name
  356. (if visit nil buffer-file-name)))
  357. (jka-compr-call-process uncompress-program
  358. (concat uncompress-message
  359. " " base-name)
  360. local-file
  361. t
  362. nil
  363. uncompress-args)))
  364. (setq size (- (point) start))
  365. (if replace
  366. (delete-region (point) (point-max)))
  367. (goto-char start))
  368. (error
  369. ;; If the file we wanted to uncompress does not exist,
  370. ;; handle that according to VISIT as `insert-file-contents'
  371. ;; would, maybe signaling the same error it normally would.
  372. (if (and (eq (car error-code) 'file-error)
  373. (eq (nth 3 error-code) local-file))
  374. (if visit
  375. (setq notfound error-code)
  376. (signal 'file-error
  377. (cons "Opening input file"
  378. (nthcdr 2 error-code))))
  379. ;; If the uncompression program can't be found,
  380. ;; signal that as a non-file error
  381. ;; so that find-file-noselect-1 won't handle it.
  382. (if (and (eq (car error-code) 'file-error)
  383. (equal (cadr error-code) "Searching for program"))
  384. (error "Uncompression program `%s' not found"
  385. (nth 3 error-code)))
  386. (signal (car error-code) (cdr error-code))))))
  387. (and
  388. local-copy
  389. (file-exists-p local-copy)
  390. (delete-file local-copy)))
  391. (unless notfound
  392. (decode-coding-inserted-region
  393. (point) (+ (point) size)
  394. (jka-compr-byte-compiler-base-file-name file)
  395. visit beg end replace))
  396. (and
  397. visit
  398. (progn
  399. (unlock-buffer)
  400. (setq buffer-file-name filename)
  401. (setq jka-compr-really-do-compress t)
  402. (set-visited-file-modtime)))
  403. (and
  404. uncompress-message
  405. jka-compr-verbose
  406. (message "%s %s...done" uncompress-message base-name))
  407. (and
  408. visit
  409. notfound
  410. (signal 'file-error
  411. (cons "Opening input file" (nth 2 notfound))))
  412. ;; This is done in insert-file-contents after we return.
  413. ;; That is a little weird, but better to go along with it now
  414. ;; than to change it now.
  415. ;; ;; Run the functions that insert-file-contents would.
  416. ;; (let ((p after-insert-file-functions)
  417. ;; (insval size))
  418. ;; (while p
  419. ;; (setq insval (funcall (car p) size))
  420. ;; (if insval
  421. ;; (progn
  422. ;; (or (integerp insval)
  423. ;; (signal 'wrong-type-argument
  424. ;; (list 'integerp insval)))
  425. ;; (setq size insval)))
  426. ;; (setq p (cdr p))))
  427. (or (jka-compr-info-compress-program info)
  428. (message "You can't save this buffer because compression program is not defined"))
  429. (list filename size)))))
  430. (defun jka-compr-file-local-copy (file)
  431. (let* ((filename (expand-file-name file))
  432. (info (jka-compr-get-compression-info filename)))
  433. (if info
  434. (let ((uncompress-message (jka-compr-info-uncompress-message info))
  435. (uncompress-program (jka-compr-info-uncompress-program info))
  436. (uncompress-args (jka-compr-info-uncompress-args info))
  437. (base-name (file-name-nondirectory filename))
  438. (local-copy
  439. (jka-compr-run-real-handler 'file-local-copy (list filename)))
  440. (temp-file (jka-compr-make-temp-name t))
  441. (temp-buffer (get-buffer-create " *jka-compr-flc-temp*"))
  442. local-file)
  443. (setq local-file (or local-copy filename))
  444. (unwind-protect
  445. (with-current-buffer temp-buffer
  446. (and
  447. uncompress-message
  448. jka-compr-verbose
  449. (message "%s %s..." uncompress-message base-name))
  450. ;; Here we must read the output of uncompress program
  451. ;; and write it to TEMP-FILE without any code
  452. ;; conversion. An appropriate code conversion (if
  453. ;; necessary) is done by the later I/O operation
  454. ;; (e.g. load).
  455. (let ((coding-system-for-read 'no-conversion)
  456. (coding-system-for-write 'no-conversion))
  457. (jka-compr-call-process uncompress-program
  458. (concat uncompress-message
  459. " " base-name)
  460. local-file
  461. t
  462. nil
  463. uncompress-args)
  464. (and
  465. uncompress-message
  466. jka-compr-verbose
  467. (message "%s %s...done" uncompress-message base-name))
  468. (write-region
  469. (point-min) (point-max) temp-file nil 'dont)))
  470. (and
  471. local-copy
  472. (file-exists-p local-copy)
  473. (delete-file local-copy))
  474. (kill-buffer temp-buffer))
  475. temp-file)
  476. (jka-compr-run-real-handler 'file-local-copy (list filename)))))
  477. ;; Support for loading compressed files.
  478. (defun jka-compr-load (file &optional noerror nomessage _nosuffix)
  479. "Documented as original."
  480. (let* ((local-copy (jka-compr-file-local-copy file))
  481. (load-file (or local-copy file)))
  482. (unwind-protect
  483. (let (inhibit-file-name-operation
  484. inhibit-file-name-handlers)
  485. (or nomessage
  486. (message "Loading %s..." file))
  487. (let ((load-force-doc-strings t))
  488. (load load-file noerror t t))
  489. (or nomessage
  490. (message "Loading %s...done." file))
  491. ;; Fix up the load history to point at the right library.
  492. (let ((l (or (assoc load-file load-history)
  493. ;; On MS-Windows, if load-file is in
  494. ;; temporary-file-directory, it will look like
  495. ;; "c:/DOCUME~1/USER/LOCALS~1/foo", whereas
  496. ;; readevalloop will record its truename in
  497. ;; load-history. Therefore try truename if the
  498. ;; original name is not in load-history.
  499. (assoc (file-truename load-file) load-history))))
  500. ;; Remove .gz and .elc?.
  501. (while (file-name-extension file)
  502. (setq file (file-name-sans-extension file)))
  503. (setcar l file)))
  504. (delete-file local-copy))
  505. t))
  506. (defun jka-compr-byte-compiler-base-file-name (file)
  507. (let ((info (jka-compr-get-compression-info file)))
  508. (if (and info (jka-compr-info-strip-extension info))
  509. (save-match-data
  510. (substring file 0 (string-match (jka-compr-info-regexp info) file)))
  511. file)))
  512. (put 'write-region 'jka-compr 'jka-compr-write-region)
  513. (put 'insert-file-contents 'jka-compr 'jka-compr-insert-file-contents)
  514. (put 'file-local-copy 'jka-compr 'jka-compr-file-local-copy)
  515. (put 'load 'jka-compr 'jka-compr-load)
  516. (put 'byte-compiler-base-file-name 'jka-compr
  517. 'jka-compr-byte-compiler-base-file-name)
  518. ;;;###autoload
  519. (defvar jka-compr-inhibit nil
  520. "Non-nil means inhibit automatic uncompression temporarily.
  521. Lisp programs can bind this to t to do that.
  522. It is not recommended to set this variable permanently to anything but nil.")
  523. ;;;###autoload
  524. (defun jka-compr-handler (operation &rest args)
  525. (save-match-data
  526. (let ((jka-op (get operation 'jka-compr)))
  527. (if (and jka-op (not jka-compr-inhibit))
  528. (apply jka-op args)
  529. (jka-compr-run-real-handler operation args)))))
  530. ;; If we are given an operation that we don't handle,
  531. ;; call the Emacs primitive for that operation,
  532. ;; and manipulate the inhibit variables
  533. ;; to prevent the primitive from calling our handler again.
  534. (defun jka-compr-run-real-handler (operation args)
  535. (let ((inhibit-file-name-handlers
  536. (cons 'jka-compr-handler
  537. (and (eq inhibit-file-name-operation operation)
  538. inhibit-file-name-handlers)))
  539. (inhibit-file-name-operation operation))
  540. (apply operation args)))
  541. ;;;###autoload
  542. (defun jka-compr-uninstall ()
  543. "Uninstall jka-compr.
  544. This removes the entries in `file-name-handler-alist' and `auto-mode-alist'
  545. and `inhibit-local-variables-suffixes' that were added
  546. by `jka-compr-installed'."
  547. ;; Delete from inhibit-local-variables-suffixes what jka-compr-install added.
  548. (mapc
  549. (function (lambda (x)
  550. (and (jka-compr-info-strip-extension x)
  551. (setq inhibit-local-variables-suffixes
  552. (delete (jka-compr-info-regexp x)
  553. inhibit-local-variables-suffixes)))))
  554. jka-compr-compression-info-list--internal)
  555. (let* ((fnha (cons nil file-name-handler-alist))
  556. (last fnha))
  557. (while (cdr last)
  558. (if (eq (cdr (car (cdr last))) 'jka-compr-handler)
  559. (setcdr last (cdr (cdr last)))
  560. (setq last (cdr last))))
  561. (setq file-name-handler-alist (cdr fnha)))
  562. (let* ((ama (cons nil auto-mode-alist))
  563. (last ama)
  564. entry)
  565. (while (cdr last)
  566. (setq entry (car (cdr last)))
  567. (if (or (member entry jka-compr-mode-alist-additions--internal)
  568. (and (consp (cdr entry))
  569. (eq (nth 2 entry) 'jka-compr)))
  570. (setcdr last (cdr (cdr last)))
  571. (setq last (cdr last))))
  572. (setq auto-mode-alist (cdr ama)))
  573. (while jka-compr-added-to-file-coding-system-alist
  574. (setq file-coding-system-alist
  575. (delq (car (member (pop jka-compr-added-to-file-coding-system-alist)
  576. file-coding-system-alist))
  577. file-coding-system-alist)))
  578. ;; Remove the suffixes that were added by jka-compr.
  579. (dolist (suff jka-compr-load-suffixes--internal)
  580. (setq load-file-rep-suffixes (delete suff load-file-rep-suffixes)))
  581. (setq jka-compr-compression-info-list--internal nil
  582. jka-compr-mode-alist-additions--internal nil
  583. jka-compr-load-suffixes--internal nil))
  584. (provide 'jka-compr)
  585. ;;; jka-compr.el ends here