Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error opening .class in Windows, no 'file' command (workaround) #4

Open
Quezion opened this issue May 11, 2023 · 0 comments
Open

Error opening .class in Windows, no 'file' command (workaround) #4

Quezion opened this issue May 11, 2023 · 0 comments

Comments

@Quezion
Copy link

Quezion commented May 11, 2023

You can install & configure this module on Windows, but opening Java .class files will raise a runtime error about missing program 'file'. This occurs because find is Mac/Linux specific & doesn't exist on Windows, but the jdecomp--jar-p implementation assumes it's an inbuilt program.

This is the current jdecomp--jar-p source:

(defun jdecomp--jar-p (file)
  "Return t if FILE is a JAR."
  (ignore-errors
    (let ((type-output (with-output-to-string
                         (process-file "file" nil standard-output nil
                                       "-bL" "--mime-type"
                                       (expand-file-name file)))))
      (member (string-trim type-output) jdecomp--jar-mime-types))))

On Emacs 24+, we can override this implementation with a simple file-exists-p on Windows. This is the configuration from my user.el:

(jdecomp-mode 1)
(customize-set-variable 'jdecomp-decompiler-type 'cfr)
(customize-set-variable 'jdecomp-decompiler-paths
                        '((cfr . "~/Downloads/cfr-0.152.jar")))

(advice-add 'jdecomp--jar-p :override
            (lambda (file) (file-exists-p file)))

Then jdecomp works automatically as expected when opening .class files.

(Appreciate the library -- saved me from installing Eclipse 🙂)

EDIT: The above code snippet only works if you manually EVAL it after init. It'll then work as long as your Emacs stays launched. It's probably possible to fix this by including the advice-add in a post-init hook, but I haven't done this yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant