clojure.contrib with slime and inferior-lisp-program question - emacs

I have the following from the slime repl (no clojure.contib functions found):
M-X slime
user=> (:require 'clojure.contrib.string)
nil
user=> (doc clojure.contrib.string/blank?)
java.lang.Exception: Unable to resolve var: clojure.contrib.string/blank? in this context (NO_SOURCE_FILE:10)
And the following when starting clojure from console (but here everything is being found OK):
adr#~/clojure/cloj-1.2$ java -cp /home/adr/clojure/cloj-1.2/clojure.jar:/home/adr/clojure/cloj-1.2/clojure-contrib.jar -server clojure.main
user=> (:require 'clojure.contrib.string)
nil
user=> (doc clojure.contrib.string/blank?)
-------------------------
clojure.contrib.string/blank?
([s])
True if s is nil, empty, or contains only whitespace.
nil
In my .emacs I have the following:
(setq inferior-lisp-program "java -cp /home/adr/clojure/cloj-1.2/clojure.jar:/home/adr/clojure/cloj-1.2/clojure-contrib.jar -server clojure.main")
My clojure jars (1.2) are at '/home/adr/clojure/cloj-1.2'.
I;m a newbie with emacs, been following some tutorials. For some time I've been trying to use the clojure.contrib library from Emacs, but "M-X slime" finds no clojure.contrib. Please, help
Edit: if that would help, now i saw that when using M-X slime there is a message:
(progn (load "/home/adr/.emacs.d/elpa/slime-20100404/swank-loader.lisp" :verbose t) (funcall (read-from-string "swank-loader:init")) (funcall (read-from-string "swank:start-server") "/tmp/slime.4493" :coding-system "iso-latin-1-unix"))
Clojure 1.2.0
user=> java.lang.Exception: Unable to resolve symbol: progn in this context (NO_SOURCE_FILE:1)
Edit2: But there is no such error message if I use M-X slime-connect after having started a "lein swank" in a directory (though even starting with "M-X slime-connect" there are no clojure-contrib libraries found in the REPL (though they are downloaded by leiningen as dependency)).

This line:
(progn (load "/home/adr/.emacs.d/elpa/slime-20100404/swank-loader.lisp" :verbose t) (funcall (read-from-string "swank-loader:init")) (funcall (read-from-string "swank:start-server") "/tmp/slime.4493" :coding-system "iso-latin-1-unix"))
is Common Lisp, not Clojure, but since you set inferior-lisp-program to Clojure, slime can't start a swank server.
See the following sections in swank-clojure project:
Connecting with SLIME
Embedding
swank-clojure.el
The functionality you want is probably in swank-clojure.el, but it is not recommended anymore.
As you're already using ELPA:
add-to-list 'package-archives
'("technomancy" . "http://repo.technomancy.us/emacs/") t)
M-x package-install ;(slime-repl)
M-x slime-connect

It seems to me that I was using the wrong way to "require" libraries in the REPL (due to my inexperience with clojure); when using a syntax such as:
user=> (require 'clojure.contrib.string)
nil
user=> (clojure.contrib.string/blank? "asd")
false
all the libraries are being found OK (no matter if using "M-X slime" for a non-swank REPL or "M-X slime-connect" for a swank server). So it was entirely my mistake (I have found hints about my mistake at this stackoverflow answer: Why do I get an error when I run (use 'clojure.contrib.repl-utils)?)

Related

Calling (require ...) on a MELPA installed package gives FlyCheck error "Cannot open load file"

I want to require some packages installed through MELPA so that i can access their variables and functions without getting "free variable" or "undefined function" warnings.
However, when I try to load a package it isn't found by Flycheck and i get a "Cannot open load file" error. It seems that the bytecode compiler doesn't read into the directory with the files installed by MELPA, but I don't know how to solve this.
I'm using Emacs 26.3 with Purcell's config that includes Flymake-Flycheck. This snippet covers the relevant parts of the init-elpa.el custom files where you can see the at the end that even if I install and then (require ...) a package it still is marked with an error by Flycheck.
;;; init-elpa.el --- Settings and helpers for package.el -*- lexical-binding: t -*-
(require 'package)
(require 'cl-lib)
;;; Install into separate package dirs for each Emacs version, to prevent bytecode incompatibility
(setq package-user-dir
(expand-file-name (format "elpa-%s.%s" emacs-major-version emacs-minor-version)
user-emacs-directory))
;;; Standard package repositories
(add-to-list 'package-archives '( "melpa" . "https://melpa.org/packages/") t)
(defun require-package (package &optional min-version no-refresh)
"Install given PACKAGE, optionally requiring MIN-VERSION.
If NO-REFRESH is non-nil, the available package lists will not be
re-downloaded in order to locate PACKAGE."
...)
(defun maybe-require-package (package &optional min-version no-refresh)
"Try to install PACKAGE, and return non-nil if successful.
In the event of failure, return nil and print a warning message.
Optionally require MIN-VERSION. If NO-REFRESH is non-nil, the
available package lists will not be re-downloaded in order to
locate PACKAGE."
...)
;;; Fire up package.el
(setq package-enable-at-startup nil)
(package-initialize)
(defvar sanityinc/required-packages nil)
(defun sanityinc/note-selected-package (oldfun package &rest args)
"If OLDFUN reports PACKAGE was successfully installed, note that fact.
The package name is noted by adding it to
`sanityinc/required-packages'. This function is used as an
advice for `require-package', to which ARGS are passed."
...)
(advice-add 'require-package :around 'sanityinc/note-selected-package)
(when (fboundp 'package--save-selected-packages)
(require-package 'seq)
(add-hook 'after-init-hook
(lambda ()
(package--save-selected-packages
(seq-uniq (append sanityinc/required-packages package-selected-packages))))))
;; READ HERE: now i try to install and require some packages.
(require-package 'fullframe)
(require-package 'evil)
(require 'fullframe) ;; Flycheck gives an ERROR: cannot open load file, files or directory does not exist
(require 'evil) ;; same as above
(require 'python) ;;this gives no error, since it's built-in i guess.
(provide 'init-elpa)
;;; init-elpa.el ends here
You can see that (package-initialize) is called so the load-path should be set. Also, I have flycheck-emacs-lisp-load-path set to 'inherit, which should mean that the bytecode compiler reads the same dirs as a normal emacs instance.
What should I do in order to make the bytecode compiler recognize my ELPA directory?
Check out flycheck-emacs-lisp-load-path variable
flycheck-emacs-lisp-load-path is a variable defined in ‘flycheck.el’.
... When set to ‘inherit’, use the ‘load-path’ of the current Emacs
session during syntax checking.
E.g you could do:
(use-package flycheck
:diminish ""
:custom
(flycheck-emacs-lisp-load-path 'inherit)
...

Package EXT does not exist

I am currently working through the Land of Lisp examples and have run into a compile exception: package EXT does not exist
from this line I suspect:
(ext:shell (concatenate 'string "dot -Tpng -O" fname))
I am running my repl inside emacs with slime and am unsure as to how to remedy this after some googling of the error.
Any help would be much appreciated.
It was in fact that SBCL was set as the default lisp program in emacs.
By replacing:
(setq inferior-lisp-program "/usr/bin/sbcl")
To:
(setq inferior-lisp-program "/usr/bin/clisp")
in my emacs configuration file fixed the issue. (On a Unix system at least)

Org-Babel Clojure Cider NRepl broken?

I followed the instructions here and wrote the following org-mode file:
#+BEGIN_SRC emacs-lisp
(princ (concat (format "Emacs version:\n%s\n" (emacs-version))
(format "\norg version: %s\n" (org-version))))
#+END_SRC
#+RESULTS:
: Emacs version:
: GNU Emacs 25.1.1 (x86_64-apple-darwin13.4.0, NS appkit-1265.21 Version 10.9.5 (Build 13F1911))
: of 2016-09-17
:
: org version: 9.0.5
#+BEGIN_SRC clojure :results value
(* 6 7)
#+END_SRC
#+RESULTS:
* COMMENT org babel settings
Local variables:
org-confirm-babel-evaluate: nil
End:
As you can see, the evaluation of the emacs-lisp block works and produces the
expected output. Incidentally, it also reports the versions of things I'm using. However, the clojure source block, when evaluated, leaves
Code block returned no value.
I tried many different Clojure expressions in the code block, such as printlns and more. Nothing shows up in the NREPL window, and the results in org mode are always the same: the message above in the minibuffer.
in the emacs minibuffer. Here are the specific steps I took:
$ lein new clojure-example
$ cd clojure-example
$ emacs clojure.example.org
keyboarded in the file above
run emacs command cider-jack-in
That produces a repl window with the following version info:
;; Connected to nREPL server - nrepl://localhost:52695
;; CIDER 0.15.0snapshot (package: 20170403.402), nREPL 0.2.12
;; Clojure 1.8.0, Java 1.8.0_121
etc.
put emacs cursor inside each block and type C-c C-c, which is bound to
org-babel-execute-src-block
Prior to that, I inserted the following code in my emacs initialization file:
(require 'org)
(require 'ob-clojure)
(org-babel-do-load-languages
'org-babel-load-languages
'( (clojure . t)
(emacs-lisp . t)
))
(setq org-babel-clojure-backend 'cider)
(require 'cider)
According to the cited instructions.
I'd be grateful for any help.
Yes, in the current stable release (9.0.5), the org-mode clojure backend is broken and does not work. I submitted a patch which has been applied and I expect will be in the next release.
See https://emacs.stackexchange.com/questions/30857/clojure-code-evaluation-in-org-mode-produces-no-output/31169#31169

Running cider-jack-in in emacs

I would like to learn some Clojure, and I'm trying to run REPL from Emacs, but I cannot get it to work.
I have created a basic project with lein. I open the generated file core.clj in Emacs, and when I try to run the REPL from it (by running the cider-jack-in), I just get the message:
Symbol's function definition is void: nil
I have toggled the debug-on-error, and the backtrace (several last lines) is:
Debugger entered--Lisp error: (void-function nil)
nil(#<buffer core.clj>)
#[257 " !\203\207\300\207" [exclude predicate] 3 "\n\n(fn ELT)"](#<buffer core.clj>)
seq-map(#[257 " !\203\207\300\207" [exclude predicate] 3 "\n\n(fn ELT)"] (#<buffer core.clj> #<buffer *Minibuf-1*> #<buffer *Warnings*> #<buffer *GNU Emacs*> #<buffer *scratch*> #<buffer *Minibuf-0*> #<buffer *Messages*> #<buffer *code-conversion-work*> #<buffer *Echo Area 0*> #<buffer *Echo Area 1*>))
seq-filter(#[257 "r\211q\210\300\301!)\207" [derived-mode-p cider-repl-mode] 3 "\n\n(fn BUFFER)"] (#<buffer core.clj> #<buffer *Minibuf-1*> #<buffer *Warnings*> #<buffer *GNU Emacs*> #<buffer *scratch*> #<buffer *Minibuf-0*> #<buffer *Messages*> #<buffer *code-conversion-work*> #<buffer *Echo Area 0*> #<buffer *Echo Area 1*>))
cider-repl-buffers()
cider-find-reusable-repl-buffer(nil "~/Development/languages/clojure/playground/test1/")
cider-jack-in(nil)
When I run lein run in the terminal, the code runs properly.
Also, when I run lein repl in the terminal, the REPL runs properly with the following info:
nREPL server started on port 62741 on host 127.0.0.1 - nrepl://127.0.0.1:62741
REPL-y 0.3.7, nREPL 0.2.12
Clojure 1.8.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_45-b14
Lein has Cider version 0.14.0, while Emacs has downloaded version 0.15.0.
Could anyone help me figure out which part of the setup I'm missing, or what I'm doing wrong?
Thanks for the help!
EDIT: Bellow is the contents of Emacs init file, with comments removed:
(require 'package)
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/") t)
(add-to-list 'package-archives
'("tromey" . "http://tromey.com/elpa/") t)
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/") t)
(package-initialize)
(when (not package-archive-contents)
(package-refresh-contents))
(defvar ido-cur-item nil)
(defvar ido-default-item nil)
(defvar ido-cur-list nil)
(defvar predicate nil)
(defvar inherit-input-method nil)
(defvar my-packages
'(paredit
clojure-mode
clojure-mode-extra-font-locking
cider
ido-ubiquitous
smex
projectile
rainbow-delimiters
tagedit
magit))
(if (eq system-type 'darwin)
(add-to-list 'my-packages 'exec-path-from-shell))
(dolist (p my-packages)
(when (not (package-installed-p p))
(package-install p)))
(add-to-list 'load-path "~/.emacs.d/vendor")
(add-to-list 'load-path "~/.emacs.d/customizations")
(load "shell-integration.el")
(load "navigation.el")
(load "ui.el")
(load "editing.el")
(load "misc.el")
(load "elisp-editing.el")
(load "setup-clojure.el")
(load "setup-js.el")
here's my lein debugging checklist:
remove any meniton of cider-nrepl from ~/.lein/profiles.clj
run lein repl from a terminal, then cider-connect to localhost from emacs
run lein upgrade
upgrade to the latest version of the cider emacs package
ask in the cider channel on clojure slack before submitting bug reports.
It used to be required to add cider's nrepl middleware to your lein profile to get it included on the classpath when lein start up. Now cider does this automatically and chooses the matching version on it's own. Many people are following instructions from when this was a manual process and run into problems like this, so check that first.
Remove your ~/.emacs.d directory and install spacemacs instead
git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d
Once you run Emacs with the new spacemacs ~/.emacs.d directory, you can simply open up a Clojure file and spacemacs will load in the Clojure layer for you.
More details can be found at spacemacs.org and in this tutorial on clojure development with spacemacs https://practicalli.github.io/spacemacs/
So the error appears to be in cider-client.el at line 102 https://github.com/clojure-emacs/cider/blob/master/cider-client.el#L99. I've got the whole defun posted below:
(defun cider-repl-buffers ()
"Return the list of REPL buffers."
(seq-filter
(lambda (buffer)
(with-current-buffer buffer (derived-mode-p 'cider-repl-mode)))
(buffer-list)))
Can you visit this file in your CIDER copy and ensure that this definition looks like this. This code is just looking for repl buffers and is filtering the buffers that emacs knows about.

swank-clojure and slime no longer co-operating in emacs

I made the mistake of updating my existing ports with MacPorts -- now slime and swank-clojure no longer work. I get the following message when I invoke clojure-jack-in within emacs:
Versions differ: 2011-04-16 (slime) vs. 20100404 (swank). Continue? (y or n)
Entering y will bring up the slime REPL, but then when I try to evaluate an expression in the REPL, I get another message:
Not connected. Use `M-x slime' to start a Lisp.
What is going on here?
Here are the relevant portions of my init.el file:
;; slime
(setq inferior-lisp-program "/opt/local/bin/sbcl")
(add-to-list 'load-path
"/opt/local/share/emacs/site-lisp/slime"
"/opt/local/share/emacs/site-lisp/slime/contrib")
(add-hook 'slime-repl-mode-hook
(defun clojure-mode-slime-font-lock()
(require 'clojure-mode)
(let (font-lock-mode)
(clojure-mode-font-lock-setup))))
(require 'slime)
(slime-setup '(slime-repl))
(eval-after-load "slime" '(slime-setup '(slime-fancy slime-banner)))
;; clojure
(add-to-list 'load-path
"~/.emacs.d/elpa/clojure-mode-el"
"~/.emacs.d/elpa/paredit-22")
(require 'clojure-mode)
(defun turn-on-paredit () (paredit-mode 1))
(add-hook 'clojure-mode-hook 'turn-on-paredit)
swank-clojure only works with slime version 20100404:
https://github.com/technomancy/swank-clojure/issues/120#issuecomment-4862556
only option at this point is to downgrade version of slime.