EMACS integration with the JVM.
As of October 21, 2016, malabar mode is uniting with https://github.com/jdee-emacs/jdee. No more work will be done on malabar and all the useful functionality has been or will be moved to JDEE. I recommend using JDEE instead of malabar (I have).
If there is malabar functionality missing from JDEE, please create an issue at https://github.com/jdee-emacs/jdee/issues with "from malabar" in the title specifying the missing functionality.
I will leave this project up for reference but no issues are being worked and no updates will be made. My efforts will go to improving JDEE.
malabar-mode is a monir-mode with hooks into Maven that makes it easy to compile files on the fly and execute Maven build commands.
NOTE: The java/groovy code has been moved to https://github.com/m0smith/malabar-mode-jar
This is based on a fork of buzztaiki's fork of espenhw's malabar-mode which has been merged back into the master branch. Development of malabar-mode has restarted. This is an attempt to keep it up to date and develop at a modest pace.
You may want to skip to Installation.
Since malabar-mode can be used from both java-mode and groovy-mode, we get some things for free:
-
Syntax highlighting
-
Movement commands (
C-M-f/-b
is a winner; so isM-f/-b
, especially withc-subword-mode
turned on) -
Electric punctuation
There's lots more; and since this is Emacs, you can turn off or modify anything you don't like.
-
Tight integration with Maven. If you're not using Maven, you should not consider malabar-mode for now. Adding gradle support is pending.
-
A Groovy console for rapid prototyping and exploratory programming
-
JUnit integration, both for running tests standalone and through Maven
-
Debugger integration with EMACS built in GUD
-
Import help; import one class or all needed classes in the buffer (with prompting if the class name is ambiguous)
-
Extend class / implement interface / override method helpers
-
Simplistic refactorings
-
See the Cheat Sheet
and more.
# InstallationThere has been a lot of work to rewrite malabar-mode to make it easier to maintain, install and develop. It is currently in a beta stage. Once it has some time to mature, it will be put back into MELPA. Until then, the installation is manual:
-
Install groovy (2.3.7 or later). Ubunutu has a real old version. Use GVM to install http://gvmtool.net/
-
Install gradle
git clone https://github.com/alexott/cedet.git
cd cedet
make all
-
Install malabar-mode from melpa
-
Install emacs package groovy-mode. Do not use marmalade version as it is old.
-
Add to .emacs:
(load-file "~/projects/cedet/cedet-devel-load.el")
(add-hook 'after-init-hook (lambda ()
(message "activate-malabar-mode")
(activate-malabar-mode)))
(add-hook 'malabar-java-mode-hook 'flycheck-mode)
(add-hook 'malabar-groovy-mode-hook 'flycheck-mode)
- in emacs (malabar-run-groovy) or C-u M-x run-groovy - you may need to enter the path to groovysh, especially on Windows
- Edit a java/groovy file in a maven2 project
NOTE 1.x is no longer supported and no more development will happen on this branch
The malabar-mode package is now part of
MELPA thanks to this
issue. Make sure you
have the MELPA package archive enabled in your init.el or .emacs and
your package contents are up to date (use M-x package-refresh-contents
if you can’t find the malabar-mode package and
you’ve added MELPA to your package archives.
Version 2.3.7 or beyond
malabar-mode was originally developed on Emacs 23, but development now targets Emacs 24.
-
(optional) If you want to mimic the IDEish compile-on-save behaviour, add the following as well::
(add-hook 'malabar-mode-hook (lambda () (add-hook 'after-save-hook 'malabar-http-compile-file-silently nil t)))
Update: malabar-mode now has a menu. Yay!
-
flycheck integration is working except for the few edge cases where the groovy parser differs from th ejava parser
-
cedet integration for java, not working for groovy yet
-
unit testing a class or method
The malabar minor mode has three different integrations: an interactive groovy shell (repl), a malabar HTTP server (http), and the external project manager like maven or gradle (pm). Each of the integrations is managed seperately. That is, compiling a file using the service will not load that class into the repl. As such, the functions will be named so it is obvious which integration is used: malabar-repl-
, malabar-http-
, or malabar-pm-
Here is a list of available interactive commands by integration, with default keybindings where applicable:
Unit Test
- malabar-http-run-test (C-c C-v t)
- Runs the unit tests in the current class. With a prefix args, ask for a method name and only run that test
- semantic-ia-describe-class (C-c C-v i)
- Show the public variables and methods on a class
- malabar-semantic-heirarchy (C-c C-v h)
- Show super classes and interfaces implemented by a class
- malabar-fully-qualified-class-name-kill-ring-save (C-c C-v *)
- Copy the fully qualifed classname of the current buffer to the kill ring
- malabar-which (C-c C-v w)
- Returns the jar containing the speficied class
- malabar-import-all (C-c C-v z)
- Adds import statements for all unqualified classes in the buffer, as
if by performing
malabar-import-one-class
on each. - malabar-import-one-class (C-c C-v C-z)
Adds an import statement for a single unqualified class (defaults to the symbol at point). If more than one class matches the unqualified name you will be asked which class to import.
The variable
malabar-import-excluded-classes-regexp-list
contains a list of regular expressions; if one of these matches the qualified class name, the class will be excluded from import. The default value excludes classes fromjava.lang
, JRE internal classes and inner classes.- ede-edit-file-target (C-c C-v C-p)
- Visit the project file, that is the closest file named
pom.xml
searching upwards in the directory structure. - malabar-repl-send-buffer (C-c C-v C-k)
- Send the contents of the current buffer to the running groovy instance. If the buffer is a class rather than a script, prefer
malabar-repl-mode-load-class
- malabar-stack-trace-buffer (C-c C-v C-#)
- Create a new stack trace buffer and optional copy the current region into it. A stack trace buffer parses the stack trace and allows jumping directly to the error in the source file. The stack trace buffer will parse whatever stack trace is pasted into it
- malabar-repl-send-classpath-of-buffer (C-c C-v s)
- For use with
malabar-repl-send-buffer
andmalabar-repl-mode-load-class
, it loads the classpath of the current project into the running groovy buffer. This allows for code in the current project to be used interactively. - malabar-repl-send-classpath-element (C-c C-v s)
- Add a jar, zip or directory to the running groovy buffer
- malabar-jdb (C-c C-v J)
- Start the JDB debugger on the current class.
- malabar-update-package
- Updates the package statement of the current buffer to match its place in the source directory.
- malabar-implement-interface (C-c C-v C-i)
- Prompts for an interface, adds stub implementations of all that interface's methods and adds the interface to the class's implements clause.
- malabar-jump-to-thing (C-c C-v C-y)
- Jumps to the definition of the 'thing' at point. More technically,
uses
semantic-analyze-current-context
output to identify an origin for the code at point, taking type membership into account. This function is much likesemantic-ia-fast-jump
, only a little smarter.
In addition, standard Semantic code completion is available; trigger
this however you wish. By default, semantic-ia-complete-symbol
is
bound to C-c C-v C-.
and semantic-ia-complete-symbol-menu
is
bound to C-c C-v .
.
The following are either not in 2.0 yet or are only partially working. If you use any of these regularly, please use the issue tracker to let me know. Those missing features that have issues added will be given higher priority. Otherwise, they will be added back in random order.
- malabar-http-compile-file (C-c C-v C-c)
- Compiles the current file.
- malabar-clear-typecache
- Clears the type cache (used for code completion) if it gets confused. If you have to use this often, please file a bug.
- malabar-extend-class (C-c C-v C-e)
- Prompts for a class, adds stub implementations of all that class's abstract methods and accessible constructors and inserts the appropriate extends clause.
- malabar-repl-start
- Start the Groovy console, or pop to it if it is running.
- malabar-repl-stop
- Kill the Groovy console process.
- malabar-run-maven-command
- Prompts for and executes an (almost) arbitrary Maven command line.
Honors profile activation, property definitions and lifecycle
phases/goals. E.g.:
-DskipTests=true -Pdev-mode install
will run the install lifecycle with the dev-mode profile active, skipping tests. - malabar-install-project (C-c C-v C-b)
- Runs
mvn install
on your project. With prefix argument (C-u), cleans the project first (mvn clean install
). - malabar-override-method (C-c C-v C-o)
- Prompts for an eligible method from the superclass of the class at
point and adds a stub implementation of that method. If the chosen
method is one of
Object.equals` or `Object.hashCode
, override both of them. - malabar-run-all-tests (C-c C-v M-t)
- Runs
mvn test
on your project. With prefix argument (C-u), cleans the project first (mvn clean test
). - malabar-run-junit-test-no-maven (C-c C-v C-t)
- Compiles the current file, performs
malabar-visit-corresponding-test
, compiles that file (if not the same as where we started) and runs the now-current buffer as a standalone JUnit test. - malabar-http-run-test (C-c C-v t)
- Runs the corresponding test to this buffer using Maven (
mvn test -Dtest=classname
) - malabar-visit-corresponding-test
Visits the corresponding test class; that is, the file in the parallel src/test/java hierarchy that matches the class in the current buffer (with
malabar-test-class-suffix
appended).E.g.,
M-x malabar-visit-corresponding-test
in a buffer visitingsrc/main/java/org/grumblesmurf/malabar/MvnServer.java
will visit the filesrc/test/java/org/grumblesmurf/malabar/MvnServerTest.java
with the default value ofmalabar-test-class-suffix
.If the current buffer looks like a test class, this command does nothing.
- malabar-refactor-extract-constant (C-c C-v C-r C-c)
- Extracts the thing at point as a named constant. The scope of the
constant will default to
malabar-refactor-extract-constant-default-scope
, but with a prefix arg will prompt for the scope.
Some default abbrevs are set up, see the variable
malabar-case-fixed-abbrevs
for the current list.
Note the presence of the #Test
abbrev; this expands to::
@Test
public void |() throws Exception {
fail("Unfinished test");
}
With point left at the position marked with |
.
In addition to the electric insertion offered by CC-mode, malabar-mode
offers an expansion that simulates the Elvis operator, although the
generated code is not as efficient as a language-provided Elvis
operator would be. This expansion is controlled by the variable
malabar-electric-elvis-p
.
Github has excellent support for forking! Just hit the fork button at the top, code and go. For everyone's convenience, you should probably rebase to m0smith/malabar-mode/master every now and then. :)
If you don't want to go that far, git is, after all, a distributed VCS. Just commit to your local repository and then use git-format-patch to extract patches in a useful format.
To the issue tracker (see the next section).
Good for you. Create a ticket in the issue tracker and stuff will happen.
Hint #1: Tell me what you did, what you expected to happen and what
actually happened. Include any error messages (Emacs backtraces,
output in the buffers named starting with *Malabar
, interesting
stuff from *Messages*
etc.).
Hint #2: Bugs with patches tend to be fixed faster (see the previous section).
Yes, it probably would! Either describe the feature that you want in the issue tracker, or (even better) fork, code, and ask me to pull.
And of course, if I nix your feature request, you're free to maintain your own local patch branch if you wish (or, for that matter, a complete fork). malabar-mode is Open Source, after all.
This fork of malabar-mode uses git-flow to manage branching in development. As such, branches are:
- develop
- tracks the latest state of development (that isn't occurring in an isolated branch)
- master
- tracks the latest stable snapshot
Feature, release, feature, hotfix, and support branches won't
usually be shared. If they are pushed to github, they shouldn't
be rebased but may disappear after they are merged with
develop
or master
.
Your Emacs environment can be configured to use a "live" version of malabar-mode with the following steps:
-
Add the following to your
.emacs
:(setq malabar-repl-lib-dir "
/src/malabar-mode/target/lib") (setq malabar-repl-extra-classpath '("/src/malabar-mode/target/classes")) (add-to-list 'load-path "~/src/malabar-mode/src/main/lisp/") -
Run
mvn package -P devel
to extract libraries intotarget/lib
.
With this configuration, you can rebuild malabar-mode's JVM
component with mvn compile
, which will compile classes into
target/classes
. To apply these changes, restart malabar-mode
in Emacs with M-x malabar-repl-restart
.
After editing elisp files, eval them to apply changes immediately.
Try
(setq malabar-util-path-separator ";")
(setq malabar-util-path-filter 'cygwin-convert-file-name-to-windows)
(setq malabar-util-groovy-file-filter 'malabar-util-reverse-slash)
- JDEE for being a source of frustration and inspiration (and sometimes of code)
- Nikolaj Schumacher for fringe-helper and elk-test
- espenhw for getting the whole thing rolling
- nflath, stepb and bbatsov for caring enough to help
- Everybody else for caring enough read this and report bugs
malabar-mode is copyright (c) 2009-2014 Matthew O. Smith [email protected]
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
For the full text of the GPL, see http://www.gnu.org/licenses/gpl2.txt.