Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically decompress a custom compressed file when opened in emacs?

Tags:

unix

emacs

elisp

I know Emacs automatically opens compressed files like .tar.gz. I'm trying to figure how to achieve this with my own compression script rather than the standard ones. Following this link, I added the following to my Emacs init file

(if (fboundp 'auto-compression-mode)
    (auto-compression-mode 0)
  (require 'jka-compr)) 
(add-to-list 'jka-compr-compression-info-list 
             ["\\.customcom\\'"
              "custom compressing"  "customcom" (-c)
              "custom decompressing" "customcom" (-d)
              nil t])
(auto-compression-mode 1) 

Ideally, i want to run the command customcom -d foo.customcom when the file is opened but with the above addition, its running customcom -d < foo.cusotmcom and giving an error. How can I modify the above to nullify the input redirection so that it takes the filename only rather than the contents of the file or is there a different way of approaching this problem?

like image 989
BobLoblaw Avatar asked Oct 02 '22 21:10

BobLoblaw


1 Answers

Maybe, the following code is helpful. By the way, it is interesting that the author of jka-compr did not take the evaluation of the program arguments into consideration and did not provide filename as one of the possible evaluable arguments.

I do not know your compression/uncompression program. Therefore, I just used cat for files ending with .cat instead for testing.

(defadvice jka-compr-info-compress-args (around eval-args activate)
  "Evaluate program arguments"
  (setq ad-return-value (mapcar 'eval (aref info 3))))

(defadvice jka-compr-info-uncompress-args (around eval-args activate)
  "Evaluate program arguments"
  (setq ad-return-value (mapcar 'eval (aref info 6))))


(add-to-list 'jka-compr-compression-info-list ["\\.cat\\'" "cat" "cat" ("-")
                           "cat uncompress" "cat" (filename) nil t ""])

(add-to-list 'auto-mode-alist '("\\.cat\\'" nil jka-compr))

(add-to-list 'file-name-handler-alist '("\\.cat\\'" . jka-compr-handler))

Corresponding enhancement-request:

http://debbugs.gnu.org/cgi/bugreport.cgi?msg=5;att=1;bug=16454

like image 134
Tobias Avatar answered Oct 05 '22 12:10

Tobias