Okay, I lied. It is trivial, but not very efficient, and it probably won't
work on Windows.
By adding the following redefinition of jka-compr-get-compression-info it will
check that it starts with the magic bytes before trying to uncompress. It
starts a whole new process though for every file whose name matches something
in jka-compr-compression-info-list so it _will_ be a performance hit, but since
opening compressed files is generally slow anyway it might not be noticeable.
Unfortunately there isn't really any good way to do this in an advice, so if
the definition changes this will have to be updated manually.
-Ivan
(defun jka-compr-get-compression-info (filename)
"Return information about the compression scheme of FILENAME.
The determination as to which compression scheme, if any, to use is
based on the filename itself and `jka-compr-compression-info-list'."
(catch 'compression-info
(let ((case-fold-search nil))
(dolist (x jka-compr-compression-info-list)
(and (string-match (jka-compr-info-regexp x) filename)
(if (not (jka-compr-info-file-magic-bytes x))
t ;; No bytes to check so assume it's compressed
(string= (jka-compr-info-file-magic-bytes x)
(shell-command-to-string
(format "head -c %s %s"
(length (jka-compr-info-file-magic-bytes x))
(shell-quote-argument filename)))))
(throw 'compression-info x)))
nil)))
On Nov 15, 2011, at 8:50 AM, Ivan Andrus wrote:
> I thought that was what it did, but just adding the magic number leaves it
> broken for non-compressed spkg's (I checked). The magic number is only used
> (as near as I can tell from looking at the emacs source) to decide if the
> file is already compressed or if it needs to be compressed when it's saving
> the file.
>
> Honestly, the whole thing seems like an emacs bug, but I'm not sure the
> maintainers will agree. It wasn't completely trivial to fix it last night,
> so I didn't. :-) If you want I can file a bug report (I would like to be
> CC'ed if you send one).
>
> -Ivan
>
> On Nov 15, 2011, at 1:47 AM, Bill Janssen wrote:
>
>> I see that in John's formulation, there's also a space for a "magic
>> number" for the file. Maybe that could be used to switch between
>> bunzip2 and tar, versus just tar.
>>
>> On Nov 12, 6:20 pm, Michael Orlitzky <[email protected]> wrote:
>>> On 11/12/2011 08:47 PM, Bill Janssen wrote:
>>>
>>>> You can visit a .tar.bz2 file with GNU Emacs 23, and it works. If I
>>>> rename the .spkg file to .tar.bz2, it works. But I don't see how to
>>>> tell Emacs that .spkg == .tar.bz2...
>>>
>>> John beat me to it, but this works in your .emacs file.
>>>
>>> ;; We have to disable auto-compression-mode first,
>>> ;; don't ask me why.
>>> (auto-compression-mode 0)
>>>
>>> ;; Add the "spkg" extension to the list of stuff we want to
>>> ;; decompress automatically (with bzip2).
>>> (add-to-list 'jka-compr-compression-info-list
>>> ["\\.spkg$"
>>> "zipping" "bzip2" ()
>>> "unzipping" "bzip2" ("-d")
>>> nil t])
>>>
>>> ;; Re-enable auto-compression mode.
>>> (auto-compression-mode 1)
>>>
>>> ;; Auto-compression will bunzip2 the spkg file, but then Emacs
>>> ;; needs to know that it should use tar-mode on what bunzip2 spits
>>> ;; out.
>>> (setq auto-mode-alist
>>> (append
>>> (list
>>> '("\\.spkg$" . tar-mode)
>>> )
>>>
>>> auto-mode-alist))
>
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org