At 02:52 PM 1/3/01 -0500, you wrote:
>I wanted to create a new template for my test classes.
>
>I was hoping to add this to the files->JDE New menu so it would go
>Files->JDE New->Test Class
>
>so I did the following
>
>in jde.el i changed the following on lines 736-744
>(defvar jde-new-buffer-menu
> (list
> "JDE New"
> ["Class..." jde-gen-class-buffer t]
> ["Console..." jde-gen-console-buffer t]
> ["Test Class..." jde-gen-test-class-buffer t]
> ["Other..." jde-gen-buffer t]
> )
> "Menu for creating new Java buffers.")
>
>then in jde-gen.el i added the following
>(defcustom jde-gen-test-class-buffer-template
> (list
> "(funcall jde-gen-boilerplate-function) '>'n"
> "\"/**\" '>'n"
> "\" * \""
> "(file-name-nondirectory buffer-file-name) '>'n"
> "\" *\" '>'n"
> "\" *\" '>'n"
> "\" * Created: \" (current-time-string) '>'n"
> "\" *\" '>'n"
> "\" * @author <a href=\\\"mailto: \\\"\" (user-full-name) \"</a>\"'>'n"
> "\" * @version\" '>'n"
> "\" */\" '>'n'"
> "'>'n"
> "\"public class \""
> "(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
> "\" extends TestCase\""
>
> "(if jde-gen-k&r "
> "()"
> "'>'n)"
> "\"{\"'>'n'n"
>
> "\"public \""
> "(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
> "\" (String name)\""
>
> "(if jde-gen-k&r "
> "()"
> "'>'n)"
> "\"{\"'>'n"
>
>
> "\"super(name);\""
> "'>'p'n"
> "\"}\">"
> "'>'n'n"
> "\"protected void setUp() \""
> "(if jde-gen-k&r "
> "()"
> "'>'n)"
> "\"{\"'>'n"
>
> "'>'p'n"
> "\"}\">"
> "'>'n'n"
> "\"public Test suite() \""
> "(if jde-gen-k&r "
> "()"
> "'>'n)"
> "\"{\"'>'n"
> "\"return new TestSuite(\""
> "(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
> "\".class);\"'n"
> "'>'p'n"
> "\"}\">"
> "'>'n'n"
>
> "\"public static void main(String[] args) \""
> "(if jde-gen-k&r "
> "()"
> "'>'n)"
> "\"{\"'>'n"
> "\"junit.textui.TestRunner.run(suite());\"'n"
> "'>'p'n"
> "\"}\">"
> "'>'n'n"
>
>
> "\"}\">"
> "\"// \""
> "(file-name-sans-extension (file-name-nondirectory buffer-file-name))"
> "'>'n")
> "*Template for new Java class.
>Setting this variable defines a template instantiation
>command `jde-gen-test-class', as a side-effect."
> :group 'jde-gen
> :type '(repeat string)
> :set '(lambda (sym val)
> (defalias 'jde-gen-test-class
> (tempo-define-template "java-test-class-buffer-template"
> (jde-gen-read-template val)
> nil
> "Insert a generic Java class buffer skeleton."))
> (set-default sym val)))
>
>;;;###autoload
>(defun jde-gen-test-class-buffer (file)
> "Create a new Java buffer containing a class of the same name.
>This command inserts the class template generated by `jde-gen-class'.
>It then moves the point to the location to the constructor."
> (interactive "F")
> (find-file file)
> (jde-gen-test-class)
> (beginning-of-buffer)
> (search-forward "{")
> (backward-char 1)
> (c-indent-exp)
> (tempo-forward-mark))
>
>
>
>This works. However I was hoping there was a way to do this that did not
>involve changing the jde source files. This way everyone I work with can
>just edit their individual .emacs files and all will be well with the world.
>And also if we upgrade to a new version of jde then we don't have to worry
>about reintegrating our changes.
>
The JDE already provides a facility for doing this. Here's how.
Customize jde-gen-buffer-templates to include your template function as
follows.
jde-gen-buffer-templates: [Hide]
[INS] [DEL] Template:
Title: Class
Command: jde-gen-class
[INS] [DEL] Template:
Title: Console
Command: jde-gen-console
[INS] [DEL] Template:
Title: Swing App
Command: jde-gen-jfc-app
[INS] [DEL] Template:
Title: Test Class
Command: jde-gen-test-class
[INS]
[State]: you have edited the value as text, but you have not set the option.
Save the customization in your .emac file (or prj.el file if this template
applies only to a particular project. To create a new file based on the
template, select
Files->JDE New->Other...
and type Test Class at the prompt. Note that you can use completion on the
class. Simply typing a space will open a buffer showing all the "Other"
templates availabe for creating new Java source files.
>BTW I have jde-2.2.5
>
You should upgrade to 2.2.6 (replace jde-parse.el with the patched version
I posted to the list yesterday).
- Paul