• Stars
    star
    200
  • Rank 195,325 (Top 4 %)
  • Language
    Emacs Lisp
  • Created over 11 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simplifies Emacs Lisp interaction with Clojure and vice versa.

License GPL 3 MELPA Melpa Stable Build Status Coverage Status

clomacs

Clomacs logo

Emacs is a Lisp. Clojure is a Lisp. Can the two be put together to form the ultimate dev environment? "Clomacs" perhaps?

  • from Emacs isn't for everyone discussion by Anonymous Cow.

Clomacs simplifies call Clojure code from Emacs lisp and vice versa. The purpose is to provide a tool for creating mixed Elisp-Clojure Emacs extensions. It provides a small wrapper under CIDER to reduce repetitive code and uses simple-httpd to call Elisp from Clojure via http requests.

Overview

There are some requirements to run mixed Elisp-Clojure code. All the Elisp-side code should be loaded, nREPL must run with all related Clojure-side code and its dependencies.

So, the user of the mixed Elisp-Clojure Emacs extension wants to simple run Elisp code from the extension.

The purpose of the clomacs-defun is to wrap Clojure function in a Elisp function, that will start CIDER if necessary or use an existing CIDER connection of certain Elisp-Clojure Emacs extension, call this Clojure function and return it's result.

To run Elisp code from Clojure, http server on Emacs side should be started first by clomacs-httpd-start function. Then you can straightforwardly pass Elisp code as string to Emacs for eval - clomacs-eval or wrap Elisp to Clojure function via clomacs-defn.

Installation

Elisp side

Add MELPA (if not yet) to your package-archives list.

Then you can install clomacs with the following command:

M-x package-install [RET] clomacs [RET]

Clojure side

To install Clomacs, add the following dependency to your project.clj file:

Clojars Project

Usage

Prerequisites

clomacs requires Clojure 1.7+.

Simple example

Call Clojure from Elisp:

;; emacs lisp:
(require 'clomacs)
(clomacs-defun get-property System/getProperty)
(message (get-property "java.version"))

Call Elisp from Clojure:

;; emacs lisp:
(require 'clomacs)
(clomacs-httpd-start)
;; clojure:
(use 'clomacs)
(clomacs-defn emacs-version emacs-version)
(println (emacs-version))

Here System/getProperty is a Clojure function and get-property is a wrapped Elisp function. emacs-version is Elisp function and after macros evaluation - is a wrapped Clojure function.

Full-fledged example

The full source code for the following example is here: cm-test.

1. Create new Clojure project in a common way:

lein new cm-test

2. Add markdown-clj dependency to the project.clj file, add src/clj folder to the classpath:

(defproject cm-test "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :source-paths ["src/clj"]                    ;; add clj folder to the classpath
  :dependencies [[org.clojure/clojure "1.9.0"] ;; Use recent version of Clojure
                 [markdown-clj "0.9.28"]       ;; markdown-clj dependency
                 [clomacs "0.0.3-SNAPSHOT"]])  ;; Most recent version of clomacs

3. Create clj folder in the src/.
4. Copy cm_test to src/clj/ folder.
5. Add some code, using markdown lib in the src/clj/cm_test/core.clj file:

(ns cm-test.core
  (:use markdown.core))

(defn my-md-to-html-string
  "Call some function from the dependency."
  [x]
  (md-to-html-string x))

6. Create elisp folder in the src/.
7. Create cm-test.el file in this foder.
8. Add to the cm-test.el the following content:

(require 'clomacs)
(clomacs-defun cm-test-md-to-html-wrapper
               cm-test.core/my-md-to-html-string
               :lib-name "cm-test"
               :namespace cm-test.core
               :doc "Convert markdown to html via Clojure lib.")

(defun cm-test-mdarkdown-to-html (beg end)
  "Add to the selected markdown text it's html representation."
  (interactive "r")
  (save-excursion
    (if (< (point) (mark))
        (exchange-point-and-mark))
    (insert
     (concat "\n" (cm-test-md-to-html-wrapper
                   (buffer-substring beg end))))))

(provide 'cm-test)

Here is the cm-test/src path tree vizualization:

  • src
    • clj
      • cm_test
        • core.clj
    • elisp
      • cm-test.el

9. So, it can be used in your .emacs via:

(add-to-list 'load-path "~/.emacs.d/cm-test/src/elisp/")
(require 'cm-test)

10. Then mark (select) this text in one of your buffers:
# This is a test
and run M-x cm-test-mdarkdown-to-html.

<h1>This is a test</h1> should occurs in the buffer under the original text.

Projects uses clomacs:

  • cm-test - Clomacs usage example.
  • ejc-sql - Emacs SQL client uses Clojure JDBC.
  • flower - Integration with Github, Gitlab, Atlassian Jira, Microsoft TFS, Microsoft Exchange and Slack.

Requirements:

License

Copyright © 2013-2023 Kostafey [email protected] and contributors

Distributed under the General Public License, version 3.

More Repositories

1

cider

The Clojure Interactive Development Environment that Rocks for Emacs
Emacs Lisp
3,539
star
2

clojure-mode

Emacs support for the Clojure(Script) programming language
Emacs Lisp
909
star
3

clj-refactor.el

A CIDER extension that provides powerful commands for refactoring Clojure code.
Emacs Lisp
771
star
4

cider-nrepl

A collection of nREPL middleware to enhance Clojure editors with common functionality like definition lookup, code completion, etc.
Clojure
673
star
5

sayid

A debugger for Clojure
Clojure
406
star
6

orchard

A fertile ground for Clojure tooling
Clojure
326
star
7

refactor-nrepl

nREPL middleware to support refactorings in an editor agnostic way
Clojure
257
star
8

inf-clojure

Basic interaction with a Clojure subprocess
Emacs Lisp
249
star
9

squiggly-clojure

Flycheck checker for Clojure, using eastwood and core.typed.
Emacs Lisp
204
star
10

clojure-cheatsheet

[DEPRECATED] The Clojure Cheatsheet for Emacs
Emacs Lisp
193
star
11

clojure-ts-mode

The next generation Clojure major mode for Emacs, powered by TreeSitter
Emacs Lisp
129
star
12

clj-suitable

ClojureScript "IntelliSense" support for JS objects and their properties/methods. Via figwheel and Emacs CIDER.
Clojure
114
star
13

ac-cider

[DEPRECATED] Emacs auto-complete backend for CIDER
Emacs Lisp
80
star
14

ac-nrepl

[DEPRECATED] Emacs auto-complete backend for nrepl completions
Emacs Lisp
74
star
15

helm-cider

Helm interface to CIDER
Emacs Lisp
66
star
16

parseclj

Clojure Parser for Emacs Lisp
Emacs Lisp
60
star
17

cljs-tooling

[DEPRECATED] Tooling support for ClojureScript
Clojure
60
star
18

parseedn

EDN parser for Emacs Lisp
Emacs Lisp
59
star
19

example-config

A sample Emacs config for Clojure development to ease your pain
Emacs Lisp
37
star
20

haystack

Let's make the most of Clojure's infamous stacktraces!
Clojure
34
star
21

enrich-classpath

Enriches Lein/deps.edn dependency trees with Java sources, JDK sources, javadocs, etc
Clojure
32
star
22

cider-decompile

An extension to CIDER which provides a decompilation command
Emacs Lisp
27
star
23

cider-hydra

Hydras for CIDER
Emacs Lisp
24
star
24

cider-eval-sexp-fu

eval-sexp-fu.el extensions for CIDER.
Emacs Lisp
12
star
25

hackingcider

HTML
10
star
26

clojuredocs-export-edn

Daily EDN exports of ClojureDocs's database.
Clojure
9
star
27

logjam

An interactive, nrepl-oriented logging backend
Clojure
1
star
28

docs.cider.mx

CIDER's documentation site
Handlebars
1
star