Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I am looking for a setup configuration file in order to use Emacs and Clojure.
Something similar to this:
https://github.com/flyingmachine/emacs-for-clojure/archive/book1.zip
I suggest that you steer clear of the Clojure for the Brave and True customization file. I am new to Clojure and used that file. It uses extremely old versions of Cider, and when I attempted to fix a bug by updating, nothing would work. Eventually, I had to use
Locate emacs
in terminal to find every specific location of an emacs related file. To make the story short, my emacs never worked again, I eventually lost control of Nautilus file browser and I thought my computer was going to explode. Anyways.
Instead of a configuration file, I suggest you try Spacemacs. It is easy to install, and easy to configure. Here are initial setup instructions for Clojure, and an brief introduction manual.
Here are some fragments from my Emacs config. Just put it into you home directory.
Setting up package sources:
;; packages
(setq package-archives
'(("gnu" . "http://elpa.gnu.org/packages/")
("marmalade" . "http://marmalade-repo.org/packages/")
("melpa" . "http://melpa.org/packages/")))
(require 'package)
(package-initialize)
List of packages (truncated):
(setq my-packages
'(auto-complete
cider
clojure-mode
paredit))
Installing the packages:
(dolist (pkg my-packages)
(unless (package-installed-p pkg)
(package-install pkg)))
Clojure(Script) configuration:
;; clojure
(add-hook 'cider-mode-hook (lambda () (show-paren-mode 1)))
(add-hook 'cider-mode-hook #'eldoc-mode)
(add-hook 'cider-mode-hook #'paredit-mode)
(add-hook 'cider-mode-hook #'imenu-add-menubar-index)
(setq cider-font-lock-dynamically nil)
(setq cider-repl-use-pretty-printing t)
;; clojurescript mode
(add-hook 'clojurescript-mode #'paredit-mode)
(add-hook 'clojurescript-mode #'paredit-mode)
Setting up code line numbers:
;; Line numbers
(line-number-mode t)
(global-linum-mode t)
(column-number-mode t)
(setq linum-format " %d")
Related
I know that Emacs has the polymode package that allows coding in RMarkdown. However, it seems that Spacemacs is still missing the equivalent of a polymode layer.
I have been trying to install it directly into Spacemacs, with no success. Therefore my question: is there a way to edit RMarkdown files in Spacemacs (not plain Emacs).
you can add packages to spacemacs by adding them to dotspacemacs-additional-packages in your .spacemacs:
dotspacemacs-additional-packages '(polymode poly-R poly-noweb poly-markdown)
after a restart the packages should get installed automatically, you probably want to set some other options in dotspacemacs/user-config () e.g. something like:
(add-to-list 'auto-mode-alist '("\\.md" . poly-markdown-mode))
(add-to-list 'auto-mode-alist '("\\.Snw" . poly-noweb+r-mode))
(add-to-list 'auto-mode-alist '("\\.Rnw" . poly-noweb+r-mode))
(add-to-list 'auto-mode-alist '("\\.Rmd" . poly-markdown+r-mode))
Edit:
polymode got a rework.
There's no official polymode layer for Spacemacs, but I've found a couple of implementations in random configs on GitHub. Here's one that works for me:
;;; packages.el --- polymode layer packages file for Spacemacs.
;;
;; Copyright (c) 2012-2016 Sylvain Benner & Contributors
;;
;; Author: Walmes Zeviani & Fernando Mayer
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; Layer retrieved from here:
;; https://github.com/MilesMcBain/spacemacs_cfg/blob/master/private/polymode/packages.el
;;
;;; Code:
(defconst polymode-packages
'(polymode
poly-R
poly-markdown))
(defun polymode/init-poly-R ())
(defun polymode/init-poly-markdown ())
(defun polymode/init-polymode ()
(use-package polymode
:mode (("\\.Rmd" . Rmd-mode))
:init
(progn
(defun Rmd-mode ()
"ESS Markdown mode for Rmd files"
(interactive)
(require 'poly-R)
(require 'poly-markdown)
(R-mode)
(poly-markdown+r-mode))
))
)
;;; packages.el ends here
There are a few ways to work with private custom layers like this, but one straightforward and easy way is to...
Save the code above as a file named packages.el in ~/.emacs.d/layers/private/polymode/.
Add polymode to your list of dotspacemacs/layers, e.g.
(defun dotspacemacs/layers ()
ess
polymode
python
...
Restart Emacs and the polymode package should install.
Using this, you shouldn't have to use (add-to-list 'auto-mode-alist... to declare the particular mode that .Rmd files should use since it's defined in the layer. I retrieved this particular layer from here. I tried one or two others as well, but they didn't work for me.
I'm trying to install icicles in Emacs because I've read it makes for a more clear emacs experience. The problem is, even though I'm loading the Melpa repositories, and Checked melpa for if the package was available (it was) If I try package-install on it, it returns [no match].
I've tried package-refresh-contents to na avail. Please help with this, I could do it manually, but AUGH!
Just for context, here's the contents on my .emacs:
;; packages
(require 'package)
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
("org" . "http://orgmode.org/elpa/")
("marmalade" . "https://marmalade-repo.org/packages/")
("melpa" . "https://melpa.org/packages/")))
(add-to-list 'load-path "~/.emacs.d/elisp")
(defun require-package (package)
(setq-default highlight-tabs t)
"Install given PACKAGE."
(unless (package-installed-p package)
(unless (assoc package package-archive-contents)
(package-refresh-contents))
(package-install package)))
(package-initialize)
(load-theme 'zenburn t)
(require 'php-mode)
(eval-after-load 'php-mode
'(require 'php-ext))
(add-to-list 'auto-mode-alist '("\\.json$" . js-mode))
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(custom-safe-themes (quote ("f5eb916f6bd4e743206913e6f28051249de8ccfd070eae47b5bde31ee813d55f" default))))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;;
Thanks in advance, all help is very much appreciated
Icicles is no longer distributed on ELPA or MELPA:
NOTE:
Icicles, as well as my other libraries that are on EmacsWiki, used to be obtainable also from MELPA. You may still find some of them there, but they are likely not up-to-date.
As of 2017-10, MELPA has decided to no longer accept Lisp libraries from EmacsWiki. This includes my libraries, even though these libraries are read-only (administrator lock on the wiki pages). Too bad. This means that you must download Icicles and my other libraries only from Emacs Wiki. Sorry about that. I upload Icicles files only to the wiki.
https://www.emacswiki.org/emacs/Icicles_-_Libraries
Solved the problem by doing M-x eval-buffer on my .emacs.
SLIME
I'm pretty new to both Clojure & emacs and I've been trying to set up SLIME for Clojure. The official documentation implicitly assumes you know what your doing with emacs. There isn't just a bunch of code you can stick into your configuration files. Since I am interested in Clojure for Data Analysis, I don't really want to deal with Leiningen if at all possible, but I want the dynamic environment that slime provides.
I have installed Clojure from git in /opt/clojure/ and clojure-contrib in /opt/clojure-contrib and I can get a repl. I installed swank-clojure, clojure-mode, and slime from github in `~/.bin following this tutorial. I changed a few things around when this wasn't working by adding some stuff from the comments section of the official documentation.
When I start slime with M-x slime I get a continuous Polling "/tmp/slime.14113".. (Abort with 'M-x slime-abort-connection'.).
Here is my init-clj.el:
;; clojure-mode
(add-to-list 'load-path "~/.bin/clojure-mode")
;; swank-clojure
(add-to-list 'load-path "~/.bin/swank-clojure")
(setq swank-clojure-jar-path "/opt/clojure/clojure.jar"
swank-clojure-extra-classpaths (list
"~/.bin/swank-clojure/src/swank"
"/opt/clojure/clojure-contrib/target/clojure-contrib-1.2.0-SNAPSHOT.jar"))
(require 'swank-clojure)
;; slime
(eval-after-load "slime"
'(progn (slime-setup '(slime-repl))))
(add-to-list 'load-path "~/.bin/slime")
(require 'slime)
(eval-after-load 'slime '(setq slime-protocol-version 'ignore))
(slime-setup '(slime-repl))
(require 'clojure-mode)
(require 'clojure-test-mode)
Here is the error I get when I call it when ants.clj is open:
(progn (load "/home/kca/.bin/slime/swank-loader.lisp" :verbose t) (funcall (read- from-string "swank-loader:init")) (funcall (read-from-string "swank:start-server") "/tmp/slime.14113" :coding-system "iso-latin-1-unix"))
Clojure 1.2.0-master-SNAPSHOT
user=> java.lang.Exception: Unable to resolve symbol: progn in this context (NO_SOURCE_FILE:1)
Inferior Lisp
I made a script in .bin/ called clj-repl that holds the java command to start a repl. I then M-x set-variable inferior-lisp-program /home/wdkrnls/.bin/clj-repl. Emacs complains its the wrong type.
The best way to use Clojure is to start by installing Leiningen.
Then install Swank Clojure as a Leiningen plugin.
Next, I'd recommend stripping your current custom Clojure setup from .emacs, and installing ELPA, and then setting up the following initialization code in your .emacs file:
;; Find this line, added by ELPA:
(require 'package)
;; and add the following expression:
(add-to-list 'package-archives
'("marmalade" .
"http://marmalade-repo.org/packages/") t)
;; ... and the rest of the ELPA init code
(package-initialize)
Then, run package-list-packages and install clojure-mode and slime (and paredit for good measure), and anything else you might want.
This should have you all set up and ready to use SLIME in (Leiningen) Clojure projects. And despite the seemingly complex procedure here, you can create a single "uberjar" from your projects to deploy on other servers with absolutely no dependency hassle.
Try the method detailed here. It takes a couple of minutes to set everything up from scratch on a clean unix or mac box:
http://www.learningclojure.com/2010/08/clojure-emacs-swank-slime-maven-maven.html
I followed the instructions as best I could for installing terminal SLIME on Mac OS X, but when I press M-x it does not prompt me.
I installed emacs and Lisp using the following two sudo commands:
sudo port install emacs +carbon
sudo port install sbcl slime
I got the following instructions:
(add-to-list 'load-path "/opt/local/share/emacs/site-lisp/slime")
(require 'slime-autoloads)
(setq slime-lisp-implementations
`((sbcl ("/opt/local/bin/sbcl"))
(abcl ("/opt/local/bin/abcl"))
(clisp ("/opt/local/bin/clisp"))))
(add-hook 'lisp-mode-hook
(lambda ()
(cond ((not (featurep 'slime))
(require 'slime)
(normal-mode)))))
(eval-after-load "slime"
'(slime-setup '(slime-fancy slime-banner)))
Populate the initialization list in SLIME-LISP-IMPLEMENTATIONS with
the correct paths to the Common Lisp exectuables you wish to use.
I'm not sure what that last bit means...
Anyways, I've never used Lisp or emacs before, most literal n00b directed instructions would be best. Just the bare minimum to write and execute common lisp with emacs.
Thanks!
Looks like you're on the right track already. Since you've only installed sbcl, and not the other lisps, just cut your initialization code down to this:
(add-to-list 'load-path "/opt/local/share/emacs/site-lisp/slime")
(require 'slime-autoloads)
(setq slime-lisp-implementations `((sbcl ("/opt/local/bin/sbcl")))
(add-hook 'lisp-mode-hook
(lambda () (cond ((not (featurep 'slime)) (require 'slime) (normal-mode)))))
(eval-after-load "slime" '(slime-setup '(slime-fancy slime-banner)))
After that, use M-x slime, and you should be good to go.
I set up emacs for both clojure and common lisp, but I want also (slime-setup '(slime-fancy)) for common lisp. If I add that line to init.el, clojure won't work: it gives me repl, but it hangs after I run any code.
My configuration
For clojure:
I set up clojure-mode, slime, slime-repl via ELPA
I run $ lein swank in project directory
Then M-x slime-connect to hack clojure
For common lisp I place this after ELPA code in init.el:
(add-to-list 'load-path "~/.elisp/slime")
(require 'slime)
(add-to-list 'slime-lisp-implementations '(sbcl ("/opt/local/bin/sbcl") :coding-system utf-8-unix))
;; (slime-setup '(slime-fancy))
So if I uncomment the last line, clojure will be broken. But slime-fancy a very important meta package for hacking common lisp.
Is there a way to set them both up to work without changing configuration and restarting when I need to switch languages?
Update
I found that slime-autodoc loaded with slime-fancy is the cause of hangs.
(slime-setup '(slime-fancy))
(setq slime-use-autodoc-mode nil)
This configuration lets run both common lisp and clojure SLIMEs. Even simultaneously. But without slime-autodoc.
I also found I'm using the CVS version of SLIME since I manually do (add-to-list 'load-path "~/.elisp/slime") after ELPA code. That does not solve the problem. Maybe there is a version from some magic date which works with clojure? Here a guy says CVS version works for him: http://www.youtube.com/watch?v=lf_xI3fZdIg&feature=player_detailpage#t=221s
Here is a solution. (using hooks)
That is ugly but quite convenient.
(add-hook 'slime-connected-hook
(lambda ()
(if (string= (slime-lisp-implementation-type) "Clojure")
(setq slime-use-autodoc-mode nil)
(setq slime-use-autodoc-mode t))
))
(add-hook 'slime-mode-hook
(lambda ()
(if (eq major-mode 'clojure-mode)
(slime-autodoc-mode 0)
(slime-autodoc-mode 1))))
Update
If the problem still exists on the slime-repl buffer, try the following code:
(add-hook 'slime-repl-mode-hook
(lambda ()
(if (string= (slime-lisp-implementation-type) "Clojure")
(progn (setq slime-use-autodoc-mode nil)
(slime-autodoc-mode 0))
(progn (setq slime-use-autodoc-mode t)
(slime-autodoc-mode 1)))))
I've been contemplating on the same problem recently. The issue is that the SLIME in ELPA is trimmed down and is next to useless for Common Lisp. One way you can circumvent the problem is to check out SLIME from CVS from the same date as the checkout was done for the ELPA package and add manually the missing stuff. Someone on #clojure told me he did that and the solution worked.
I personally find such a solution pretty ugly, but until someone manages to get the Clojure support into upstream SLIME there won't be a better one.
Alternatively you can add features to the slime-setup one by one and see what feature exactly is causing the problem with the Clojure evaluation - after all slime-fancy is simply a metafeature that just loads the most popular contrib features.
Btw you don't need the lines
(add-to-list 'load-path "~/.elisp/slime/contrib")
(setq slime-backend "~/.elisp/slime/swank-loader.lisp")
(require 'slime)
The contrib dir will be added automatically to the load path, the back-end is the default and if you're using 'slime-autoloads you should require slime before that, since this defeats the purpose of the autoload.
I use sbcl, clozure, and clojure: Getting Emacs, Slime, Common Lisp (SBCL, Clozure), and Clojure to Work Together