They are both zip file actually. I can preview jar file directly from dired, but not for jmod files.
I can view jar files like this after opening jar files from dired.
I tried adding jmod
to dired-compress-file-suffixes
, not working.
(add-to-list 'dired-compress-file-suffixes '("\\.jmod\\'" "" "unzip -o -d %o %i"))
by the way, jar
is not in dired-compress-file-suffixes
too.
Edit: After more discussion (see comments), we've established:
*.jmod
files are a (slightly) different file format to *.jar
files, in that the magic characters at the beginning are JM
vs the PK
used in jar files (and in zip files more generally).
Were it not for that, the suggested config changes below would actually be unnecessary, as the zip file detection in magic-fallback-mode-alist
would handle them.
As it is, it's necessary to not only tell Emacs that these are archives, but additionally to modify the archive-find-type
function to recognise what kind of archive they are, as this function currently only recognises the PK
-based zip file format.
For files starting with JM^C^D
(as rendered by Emacs), the following change to archive-find-type
should do the trick (but I don't know whether that's sufficient):
@@ -772,6 +772,7 @@
;; as an archive by other software.
(let (case-fold-search)
(cond ((looking-at "\\(PK00\\)?[P]K\003\004") 'zip)
+ ((looking-at "JM\003\004") 'zip)
((looking-at "..-l[hz][0-9ds]-") 'lzh)
((looking-at "....................[\334]\247\304\375") 'zoo)
((and (looking-at "\C-z") ; signature too simple, IMHO
Original answer follows...
The default auto-mode-alist
contains the following entry for archive-mode
, with a regexp that matches .jar
files:
("\\.\\(arc\\|zip\\|lzh\\|lha\\|zoo\\|[jew]ar\\|xpi\\|rar\\|cbr\\|7z\\|squashfs\\|ARC\\|ZIP\\|LZH\\|LHA\\|ZOO\\|[JEW]AR\\|XPI\\|RAR\\|CBR\\|7Z\\|SQUASHFS\\)\\'"
. archive-mode)
The docstring for that variable also says:
The extensions whose FUNCTION is `archive-mode' should also
appear in `auto-coding-alist' with `no-conversion' coding system.
Hence this should do the trick:
(add-to-list 'auto-mode-alist '("\\.jmod\\'" . archive-mode))
(add-to-list 'auto-coding-alist '("\\.jmod\\'" . no-conversion))