Wednesday, March 5, 2014

Using malabar-mode to auto-populate a new Java file

Java has a lot of "template" code that needs to be written and most editors and IDEs understand this and help alliviate the common tasks.  One of these is the putting a skeleton into a blank file.  To do this in malabar-mode, there is the malabar-codegen-insert-class-template function that will:
  • add the class declaration based on the name of the buffer
  • add a javadoc comment skeleton
  • update the package statement
To have EMACS run this function when a new file is created, add the following to your .emacs:

;; Auto-populate an empty java file
(add-hook 'malabar-mode-hook
      '(lambda ()
         (when (= 0 (buffer-size))
           (malabar-codegen-insert-class-template))))

No comments: