* hooking jode to emacs
@ 2003-12-19 21:49 kgold
2003-12-19 23:38 ` Kevin Rodgers
0 siblings, 1 reply; 10+ messages in thread
From: kgold @ 2003-12-19 21:49 UTC (permalink / raw)
I'd like to use jode to decompile when editing a class file. I found
the below elisp. However jode is a bit too smart, and adds .class
to the end of it's argument. So it tries to look for
filename.class.class
I need to pass the file name without the extension. It seems like
file-name-sans-extension is what I want, but I just don't know the
syntax. Could someone modify this elisp to do that?
; Use this once jad is downloaded
(defvar class-file-decompile-command "jode "
"The shell command run by `decompile-class-file'.")
(defun decompile-class-file (&optional file)
"Run `class-file-decompile-command' on FILE, but only if it's a .class file.
If FILE is nil, run it on `buffer-file-name'."
(interactive "fFile: ")
(or file (setq file buffer-file-name))
(and (equal (file-name-extension file) "class")
(shell-command (concat class-file-decompile-command " " file))))
(add-hook 'find-file-hooks 'decompile-class-file)
--
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: hooking jode to emacs
2003-12-19 21:49 hooking jode to emacs kgold
@ 2003-12-19 23:38 ` Kevin Rodgers
2003-12-22 14:47 ` kgold
0 siblings, 1 reply; 10+ messages in thread
From: Kevin Rodgers @ 2003-12-19 23:38 UTC (permalink / raw)
kgold wrote:
> I'd like to use jode to decompile when editing a class file. I found
> the below elisp. However jode is a bit too smart, and adds .class
> to the end of it's argument. So it tries to look for
>
> filename.class.class
>
> I need to pass the file name without the extension. It seems like
> file-name-sans-extension is what I want, but I just don't know the
> syntax. Could someone modify this elisp to do that?
It works the same way as file-name-extension, which you use. What happens if
you just replace the reference to file in (shell-command ...) with
(file-name-sans-extension file)?
--
Kevin Rodgers
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: hooking jode to emacs
2003-12-19 23:38 ` Kevin Rodgers
@ 2003-12-22 14:47 ` kgold
2003-12-22 16:13 ` Kai Grossjohann
0 siblings, 1 reply; 10+ messages in thread
From: kgold @ 2003-12-22 14:47 UTC (permalink / raw)
Kevin Rodgers <ihs_4664@yahoo.com> writes:
>
> It works the same way as file-name-extension, which you use. What happens if
> you just replace the reference to file in (shell-command ...) with
> (file-name-sans-extension file)?
Thanks. The below worked. It turns out that jode also wants the file
name without the directory path.
Two more (since emacs can do anything)
- How can I automatically set the resulting *Shell Command Output*
buffer to java-mode. M-x java-mode works interactively.
My attempts at variations of this didn't work.
(execute-extended-command 'java-mode)
- The author of jode sends two lines (his name and email address, and
the name of the class file) to stdout. How can I trim these two
lines out of the buffer?
~~~~~~~~~~~~~~~~~~
(defun decompile-class-file (&optional file)
"Run `class-file-decompile-command' on FILE, but only if it's a .class file.
If FILE is nil, run it on `buffer-file-name'."
(interactive "fFile: ")
(or file (setq file buffer-file-name))
(and (equal (file-name-extension file) "class")
(shell-command (concat class-file-decompile-command " "
(file-name-nondirectory (file-name-sans-extension file))))))
--
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: hooking jode to emacs
2003-12-22 14:47 ` kgold
@ 2003-12-22 16:13 ` Kai Grossjohann
2003-12-22 19:40 ` kgold
0 siblings, 1 reply; 10+ messages in thread
From: Kai Grossjohann @ 2003-12-22 16:13 UTC (permalink / raw)
kgold@watson.ibm.com (kgold) writes:
> (defun decompile-class-file (&optional file)
> "Run `class-file-decompile-command' on FILE, but only if it's a .class file.
> If FILE is nil, run it on `buffer-file-name'."
> (interactive "fFile: ")
> (or file (setq file buffer-file-name))
> (and (equal (file-name-extension file) "class")
> (shell-command (concat class-file-decompile-command " "
> (file-name-nondirectory (file-name-sans-extension file))))))
Maybe it's better to use call-process instead of shell-command. Hm.
Oh, no it's not necessary, you can specify a buffer for the output of
the shell command.
Maybe like this:
(set-buffer (create-file-buffer (concat (file-name-sans-extension file)
".java")))
(shell-command (concat class-file-decompile-command " "
(file-name-nondirectory (file-name-sans-extension file)))
t ; output to current buffer
nil) ; stderr goes to same buffer as stdout
(java-mode)
What do you think?
Regarding the two extra lines, maybe you're lucky and the output goes
to stderr, so you can just specify a buffer instead of nil for the two
extra lines. If not, you can always do (goto-char (point-min))
followed by (kill-line 2) to delete the first two lines.
Kai
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: hooking jode to emacs
2003-12-22 16:13 ` Kai Grossjohann
@ 2003-12-22 19:40 ` kgold
2003-12-22 21:16 ` Kai Grossjohann
0 siblings, 1 reply; 10+ messages in thread
From: kgold @ 2003-12-22 19:40 UTC (permalink / raw)
Kai Grossjohann <kai@emptydomain.de> writes:
> [great suggestions]
This version puts the output in a .class.java buffer and eliminates
the two extra jode lines.
It works for classes that aren't in a package.
For classes in a package, passing the file name without the directory
is wrong. Rather, one must discard only from the current working
directory up toward the root, and then create a relative path by
replacing the Unix "/" directory separator with the Java separator
".".
Anyone have too much free time? :-)
(defun decompile-class-file (&optional file)
"Run `class-file-decompile-command' on FILE, but only if it's a .class file.
If FILE is nil, run it on `buffer-file-name'."
(interactive "fFile: ")
(or file (setq file buffer-file-name))
(and (equal (file-name-extension file) "class")
(set-buffer (create-file-buffer (concat (file-name-sans-extension file)
".class.java")))
(shell-command (concat class-file-decompile-command " "
(file-name-nondirectory (file-name-sans-extension file)))
t ; output to current buffer
nil) ; stderr goes to same buffer as stdout
(java-mode)
(goto-char (point-min))
(kill-line 2)
)
)
--
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: hooking jode to emacs
2003-12-22 19:40 ` kgold
@ 2003-12-22 21:16 ` Kai Grossjohann
2003-12-23 17:59 ` Kevin Rodgers
0 siblings, 1 reply; 10+ messages in thread
From: Kai Grossjohann @ 2003-12-22 21:16 UTC (permalink / raw)
kgold@watson.ibm.com (kgold) writes:
> For classes in a package, passing the file name without the directory
> is wrong. Rather, one must discard only from the current working
> directory up toward the root, and then create a relative path by
> replacing the Unix "/" directory separator with the Java separator
> ".".
Sounds as if the argument should be a fully qualified class name; but
then you don't know how many elements to include in the name. Hm.
Kai
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: hooking jode to emacs
2003-12-22 21:16 ` Kai Grossjohann
@ 2003-12-23 17:59 ` Kevin Rodgers
2003-12-23 20:22 ` Kevin Rodgers
2003-12-25 16:28 ` Kai Grossjohann
0 siblings, 2 replies; 10+ messages in thread
From: Kevin Rodgers @ 2003-12-23 17:59 UTC (permalink / raw)
Kai Grossjohann wrote:
> kgold@watson.ibm.com (kgold) writes:
>>For classes in a package, passing the file name without the directory
>>is wrong. Rather, one must discard only from the current working
>>directory up toward the root, and then create a relative path by
>>replacing the Unix "/" directory separator with the Java separator
>>".".
>
> Sounds as if the argument should be a fully qualified class name; but
> then you don't know how many elements to include in the name. Hm.
The package-qualified class name corresponds to a directory-qualified file
name, but that is relative to some project root directory, right? So Ken
should be able to do something like
(subst-char-in-string ?. ?/ (file-relative-name buffer-file-name
project-directory))
--
Kevin Rodgers
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: hooking jode to emacs
2003-12-23 17:59 ` Kevin Rodgers
@ 2003-12-23 20:22 ` Kevin Rodgers
2003-12-25 16:28 ` Kai Grossjohann
1 sibling, 0 replies; 10+ messages in thread
From: Kevin Rodgers @ 2003-12-23 20:22 UTC (permalink / raw)
Kevin Rodgers wrote:
> The package-qualified class name corresponds to a directory-qualified file
> name, but that is relative to some project root directory, right? So Ken
> should be able to do something like
>
> (subst-char-in-string ?. ?/ (file-relative-name buffer-file-name
> project-directory))
Oops, I got the FROMCHAR and TOCHAR arguments backward.
--
Kevin Rodgers
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: hooking jode to emacs
2003-12-23 17:59 ` Kevin Rodgers
2003-12-23 20:22 ` Kevin Rodgers
@ 2003-12-25 16:28 ` Kai Grossjohann
2003-12-29 21:38 ` Kevin Rodgers
1 sibling, 1 reply; 10+ messages in thread
From: Kai Grossjohann @ 2003-12-25 16:28 UTC (permalink / raw)
Kevin Rodgers <ihs_4664@yahoo.com> writes:
> The package-qualified class name corresponds to a directory-qualified file
> name, but that is relative to some project root directory, right?
My unspoken assumption was that it is difficult to find out what's the
project root directory.
Merry Christmas,
Kai
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: hooking jode to emacs
2003-12-25 16:28 ` Kai Grossjohann
@ 2003-12-29 21:38 ` Kevin Rodgers
0 siblings, 0 replies; 10+ messages in thread
From: Kevin Rodgers @ 2003-12-29 21:38 UTC (permalink / raw)
Kai Grossjohann wrote:
> Kevin Rodgers <ihs_4664@yahoo.com> writes:
>>The package-qualified class name corresponds to a directory-qualified file
>>name, but that is relative to some project root directory, right?
>
> My unspoken assumption was that it is difficult to find out what's the
> project root directory.
In general, yes. But it'd be easy to store it in an environment variable or
a .project file.
--
Kevin Rodgers
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2003-12-29 21:38 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-12-19 21:49 hooking jode to emacs kgold
2003-12-19 23:38 ` Kevin Rodgers
2003-12-22 14:47 ` kgold
2003-12-22 16:13 ` Kai Grossjohann
2003-12-22 19:40 ` kgold
2003-12-22 21:16 ` Kai Grossjohann
2003-12-23 17:59 ` Kevin Rodgers
2003-12-23 20:22 ` Kevin Rodgers
2003-12-25 16:28 ` Kai Grossjohann
2003-12-29 21:38 ` Kevin Rodgers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).