Menu

#1910 JavaMacros plugin

None
open
None
5
2020-05-26
2020-05-24
ruanjiaxing
No

Said plugin's document is very poor. They said the Java doc will contains more information about how to write macro using Java and compiled to class bytecode and run this .class as JEdit macro. But the Jar file JavaMacros.jar contains no Java doc at all. I have no idea how to use it and it seemed the plugin is no longer updated. Please consider updating it or just remove it and clearly state that bytecode .class file currently can't be run as JEdit macro and you can't write JEdit macro in Java so other people know that it is currently impossible and they would have a look to implement an actual working solution. Thanks.

Discussion

  • Dale Anson

    Dale Anson - 2020-05-24

    Well, you're right, the documentation is poor. However, the plugin does work as advertised, but it's a little unusual. Here's a working example, more or less from the JavaMacro code itself, which would have been in the javadoc if the javadoc had actually been included with the plugin:

    package macros;
    
    
    import javamacros.*;
    
    import org.gjt.sp.jedit.*;
    import org.gjt.sp.jedit.textarea.JEditTextArea;
    
    
    public class Hello_World implements MacroClass {
    
        public void run( Buffer buffer, View view, Macros.Macro macro, JEditTextArea textArea ) throws Exception {
            Macros.message( view, "Hello World!" );
        }
    }
    

    Put this in a directory named "macros". Compile it like this:

    javac -cp /path/to/JavaMacros.jar:/path/to/jedit.jar:. macros/Hello_World.java
    

    Copy the resulting .class file to your jEdit settings directory/macros.

    Now the unusual part, the JavaMacros.jar file needs to be added to the classpath that you use to start jEdit. I start jEdit from a shell script, so my start up line looks like this:

    java -Xmx620m -Xms512m ${ANTIALIAS_ALL}  "-Djedit.home=$JEDIT_HOME" -cp ~/.jedit/jars/JavaMacros.jar -jar "$JEDIT_HOME/jedit.jar" -reuseview "$@"
    

    So restart jEdit with the JavaMacros.jar in the classpath, and you should see "Hello World" in the Macros menu, and clicking it show a message box saying "Hello World".

    The plugin code does need some updating, the build file doesn't work out of the box anymore and as you mentioned, the documentation is poor and the javadoc is missing altogether. I'll see if I can find time to fix those issues. I'd like to see if there is a way so that the JavaMacros.jar doesn't have to be included in jEdit's start up classpath for the macros to work, that's a significant barrier to user adoption of this plugin.

     
    • ruanjiaxing

      ruanjiaxing - 2020-05-25

      Thank you. Your example worked. Could you extend the plugin so it would run a jar file and not just a .class file? I found .class file is a bit inconvenient. I also don't understand why the author didn't start with jar file from the beginning but chose .class file instead.

       
      • Dale Anson

        Dale Anson - 2020-05-25

        Probably not. The idea of a macro is something small, quick, and not very complicated. If you need more than that, as in multiple classes in a jar file, then you probably need a plugin, which is packaged in a jar file.

         
        • ruanjiaxing

          ruanjiaxing - 2020-05-26

          Thanks. I got it.

           
  • Dale Anson

    Dale Anson - 2020-05-24
    • assigned_to: Dale Anson
    • Group: -->
     

Log in to post a comment.