~damien/jedit-hello-from-clojure

9146ffa2ba9ea657d6879eabbd168d660ad1c4a6 — Damien Radtke 9 months ago main
Initial commit
6 files changed, 98 insertions(+), 0 deletions(-)

A .gitignore
A Makefile
A README.md
A ivy.xml
A resources/HelloFromClojure.props
A src/hellofromclojure/plugin.clj
A  => .gitignore +3 -0
@@ 1,3 @@
/classes
/.cpcache
*.jar

A  => Makefile +30 -0
@@ 1,30 @@
JEDIT_JAR := $(HOME)/jEdit/5.6.0/jedit.jar
JARS := $(HOME)/Library/jEdit/jars/

CLOJURE_VERSION := 1.11.1
SPEC_ALPHA_VERSION := 0.3.218
CORE_SPECS_ALPHA_VERSION := 0.2.62

DEPS_HOME := $(HOME)/.m2/repository
CLOJURE_PATH := $(DEPS_HOME)/org/clojure/clojure/$(CLOJURE_VERSION)/clojure-$(CLOJURE_VERSION).jar
SPEC_ALPHA_PATH := $(DEPS_HOME)/org/clojure/spec.alpha/$(SPEC_ALPHA_VERSION)/spec.alpha-$(SPEC_ALPHA_VERSION).jar
CORE_SPECS_ALPHA_PATH := $(DEPS_HOME)/org/clojure/core.specs.alpha/$(CORE_SPECS_ALPHA_VERSION)/core.specs.alpha-$(CORE_SPECS_ALPHA_VERSION).jar

default: deps build

deps:
	ivy

build:
	mkdir -p classes
	java -cp $(CLOJURE_PATH):$(SPEC_ALPHA_PATH):$(CORE_SPECS_ALPHA_PATH):$(JEDIT_JAR):src:classes \
		clojure.main --eval "(compile 'hellofromclojure.plugin)" \
		&& jar --create --file HelloFromClojure.jar -C classes . -C resources .

install:
	cp $(CLOJURE_PATH) $(SPEC_ALPHA_PATH) HelloFromClojure.jar $(JARS)

uninstall:
	rm $(JARS)/clojure-$(CLOJURE_VERSION).jar $(JARS)/spec.alpha-$(SPEC_ALPHA_VERSION).jar $(JARS)/HelloFromClojure.jar

all: deps build install

A  => README.md +14 -0
@@ 1,14 @@
This plugin demonstrates how you can write a jEdit plugin with Clojure.

To build it, you just need to have the following installed:

1. jEdit
2. Apache Ivy
3. Make

Then you can run

```sh
$ make         # To download Clojure and build the plugin
$ make install # To copy the built jar and its dependencies to the jars folder
```

A  => ivy.xml +6 -0
@@ 1,6 @@
<ivy-module version="2.0">
	<info organisation="jedit-plugins" module="HelloFromClojure"/>
    <dependencies>
        <dependency org="org.clojure" name="clojure" rev="1.11.1"/>
    </dependencies>
</ivy-module>

A  => resources/HelloFromClojure.props +10 -0
@@ 1,10 @@
plugin.hellofromclojure.HelloFromClojurePlugin.activate=startup

plugin.hellofromclojure.HelloFromClojurePlugin.name=Hello From Clojure
plugin.hellofromclojure.HelloFromClojurePlugin.version=0.1
plugin.hellofromclojure.HelloFromClojurePlugin.author=Damien Radtke
plugin.hellofromclojure.HelloFromClojurePlugin.description=This plugin demonstrates a technique for building jEdit plugins in Clojure, rather than Java.
plugin.hellofromclojure.HelloFromClojurePlugin.jars=clojure-1.11.1.jar spec.alpha-0.3.218.jar

plugin.hellofromclojure.HelloFromClojurePlugin.depend.0=jdk 11
plugin.hellofromclojure.HelloFromClojurePlugin.depend.1=jedit 05.05.99.00

A  => src/hellofromclojure/plugin.clj +35 -0
@@ 1,35 @@
(ns hellofromclojure.plugin
  (:gen-class
    :name hellofromclojure.HelloFromClojurePlugin
    :extends org.gjt.sp.jedit.EditPlugin
    :exposes-methods {createBrowserMenuItems superCreateBrowserMenuItems
                      createMenuItems superCreateMenuItems
                      getClassName superGetClassName
                      getPluginHome superGetPluginHome
                      getPluginJAR superGetPluginJAR})
  (:import
    [org.gjt.sp.util Log]))

(defn -start [this]
  (Log/log Log/DEBUG this "Hello from Clojure!"))

(defn -stop [this]
  (Log/log Log/DEBUG this "Goodbye from Clojure!"))

; The following methods simply invoke the superclass definition.
; Clojure interop doesn't seem to let you do this automatically.

(defn -createBrowserMenuItems [this]
  (. this superCreateBrowserMenuItems))

(defn -createMenuItems [this]
  (. this superCreateMenuItems))

(defn -getClassName [this]
  (. this superGetClassName))

(defn -getPluginHome [this]
  (. this superGetPluginHome))

(defn -getPluginJAR [this]
  (. this superGetPluginJAR))