swank-clojure and slime no longer co-operating in emacs - 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.

Related

How to use Cider's built-in autocompletion in Clojure?

According to this:
The built-in completion logic in CIDER relies on the library clojure-complete, so you'll have to have it your classpath for completion to work. If you're connecting to an nREPL server started from lein (e.g. you invoked M-x cider-jack-in) - there's nothing for you to do.
So -- I'm using an nREPL jack in with Emacs 24.3, so I would guess that there is "nothing for me to do." However, I am not getting any autocompletion in my Clojure source files.
I uninstalled and reinstalled Cider via Elpa to be safe. Apparently it is not necessary to manually install any other autocompletion packages from what I've read, but I must admit that getting autocompletion to work seems to be quite a task, can anyone point out what I'm missing?
Here's my old config. I haven't been using Clojure for a while, but
I've checked that it still works:
(require 'ac-nrepl)
(defun clojure-auto-complete ()
(interactive)
(let ((ac-sources
`(ac-source-nrepl-ns
ac-source-nrepl-vars
ac-source-nrepl-ns-classes
ac-source-nrepl-all-classes
ac-source-nrepl-java-methods
ac-source-nrepl-static-methods
,#ac-sources)))
(auto-complete)))
(defun my-clojure-hook ()
(auto-complete-mode 1)
(define-key clojure-mode-map
(kbd "β") 'clojure-auto-complete))
(add-hook 'clojure-mode-hook 'my-clojure-hook)
I'm pretty sure that I went for the separate function instead of modifying
ac-sources for performance reasons (I have ac-delay at 0.4).
Confirmation:
abo-abo answer of Apr 23 at 6:57 works.
Just change "ac-nrepl" into "ac-cider" of course.
(GNU Emacs 24.3.1 (x86_64-pc-linux-gnu, GTK+ Version 3.10.9)
of 2014-06-06 on brownie, modified by Debian)
(require 'auto-complete-config)
(require 'clojure-mode)
(require 'cider-mode)
(require 'ac-cider)
(ac-config-default)
;(add-hook 'cider-repl-mode-hook 'ac-cider-setup)
(add-hook 'cider-mode-hook 'ac-cider-setup)
(eval-after-load "auto-complete"
'(add-to-list 'ac-modes 'cider-repl-mode))
(add-hook 'clojure-mode-hook 'paredit-mode)
;(add-hook 'clojurescript-mode-hook 'paredit-mode)
(add-hook 'clojure-mode-hook 'rainbow-delimiters-mode)
(setq cider-repl-pop-to-buffer-on-connect nil)
(require 'highlight-parentheses)
(add-hook 'clojure-mode-hook
(lambda ()
(highlight-parentheses-mode t)))
(defun set-auto-complete-as-completion-at-point-function ()
(setq completion-at-point-functions '(auto-complete)))
(add-hook 'auto-complete-mode-hook 'set-auto-complete-as-completion-at-point-function)
;(add-hook 'cider-repl-mode-hook 'set-auto-complete-as-completion-at-point-function)
(add-hook 'cider-mode-hook 'set-auto-complete-as-completion-at-point-function)
(eval-after-load "cider"
'(define-key cider-mode-map (kbd "C-c C-d") 'ac-cider-popup-doc))
My packages are:
ac-cider
auto-complete
auto-indent
cider
clojure-mode
highlight-parentheses
parendit
popup
rainbow-delimiters
I do not want to use auto-completion for repl and script so I commented them.
You may not need them all but they are all useful. If you do not want to change the init.el file, you would better go with all packages listed.
Once you're done, make a project with Lein, then add
:plugins [[cider/cider-nrepl "0.8.2"]]
to project.clj file.
Now, it is almost done.
Open a sourcefile with Emacs, then run
M-x cider-jack-in
Then you must be able to use auto-completion feature for code!

ac-math error in emacs

I installed ac-math plugin as well as auto-complete. I ac-math.el in .emacs.d/plugins/auto-complete
I put this in my .emacs
(add-to-list 'load-path "~/.emacs.d/plugins/auto-complete/.")
(add-to-list 'ac-dictionary-directories "~/.emacs.d/plugins/auto-complete/ac-dict/")
(require 'auto-complete-config)
(ac-config-default)
(require 'ac-math)
(add-to-list 'ac-modes 'latex-mode) ; make auto-complete aware of latex-mode
(defun ac-latex-mode-setup () ; add ac-sources to default ac-sources
(setq ac-sources
(append '(ac-source-math-unicode ac-source-math-latex ac-source-latex-commands)
ac-sources)))
(add-hook 'latex-mode-hook 'ac-latex-mode-setup)
But I get the error "wrong type argument: integrep nil". Any help?
As far as auto-complete-mode is concerned there is a rather out-dated homepage: http://cx4a.org/software/auto-complete/
If you install from there you propably do not have an up to date version like eg the one that can be found on github ( https://github.com/auto-complete/auto-complete ). In that repository the branch for version 1.3 (the one that is available on the homepage) was not updated in the last three years.

How to set up emacs for clojure, evil, hinting, paren highlighting?

I'm brand-new to both Emacs and Clojure and would like to set up hinting and syntax highlighting somehow similar to the video here. I have installed:
Emacs 24.x
Leiningen 2.x
Marmalade
...Then within Emacs and via Marmalade, installed the following packages:
Evil
clojure-mode
nrepl
My big-idea question is how do these major/minor modes interact and is there a "right" way to set these things up?
My smaller-idea question is how do I get the pretty syntax highlighting and code-hinting?
Thanks!
Check out Emacs Live, its a full emacs configuration created by Sam Aaron. He codes allot of Clojure so this "battery included" setup works great for Clojure coding.
https://github.com/overtone/emacs-live
Once you have cloned this and follow the instructions you are up and running with
Clojure, nrepl, git and much more.
I list my setup. Some of the stuff is redundant, since I haven't
written in Clojure for a while, but I checked and it still works.
Use clojure to start nrepl.
You might have some issue with project.clj being in the appropriate directory,
but you should figure this out.
Open a source file e.g. foo.clj.
Use C-c C-l to call nrepl-load-file
By the way, it's the canonical shortcut to load the file into inferior process.
It will work for Common Lisp, Python etc.
Use C-c C-z to switch to repl.
This again is the canonical shortcut that works for many languages.
Here's the setup code:
(require 'clojure-mode)
(defun set-syntax-parens ()
"highlight []{} etc."
(interactive)
(modify-syntax-entry ?[ "(]")
(modify-syntax-entry ?] ")[")
(modify-syntax-entry ?{ "(}")
(modify-syntax-entry ?} "){"))
(defvar clojure.jars '("clojure-1.3.0.jar"
"swank-clojure-1.4.2.jar"
"clojure-contrib-1.2.0.jar"))
(defvar clojure.jars.d (concat dropbox.d "source/clojure/lib/"))
(defvar clojure.classpath
(apply #'concat
(mapcar (lambda (jar) (concat clojure.jars.d jar path-separator))
clojure.jars)))
(setq clojure.classpath
(concat clojure.classpath
dropbox.d "source/clojure/include/"
path-separator))
;;;###autoload
(defun clojure ()
(interactive)
(nrepl-jack-in))
(defvar clojure-server-cmd
(concat "java -Xss4096k -cp " clojure.classpath " clojure.main &"))
(add-hook 'clojure-mode-hook
(lambda()
(set-syntax-parens)))
(require 'nrepl)
(add-hook 'nrepl-mode-hook
(lambda()
(define-key nrepl-mode-map (kbd "C-l") 'nrepl-clear-buffer)))
here is the operative section from my favorite emacs config:
(when (not package-archive-contents)
(package-refresh-contents))
;; Add in your own as you wish:
(defvar my-packages '(starter-kit starter-kit-lisp starter-kit-bindings clojure-mode
nrepl auto-complete ac-nrepl org rainbow-delimiters)
"A list of packages to ensure are installed at launch.")
(dolist (p my-packages)
(when (not (package-installed-p p))
(package-install p)))
(require 'ac-nrepl)
(add-hook 'nrepl-mode-hook 'ac-nrepl-setup)
(add-hook 'nrepl-interaction-mode-hook 'ac-nrepl-setup)
(eval-after-load "auto-complete"
'(add-to-list 'ac-modes 'nrepl-mode))
(defun set-auto-complete-as-completion-at-point-function ()
(setq completion-at-point-functions '(auto-complete)))
(add-hook 'auto-complete-mode-hook 'set-auto-complete-as-completion-at-point-function)
(add-hook 'nrepl-mode-hook 'set-auto-complete-as-completion-at-point-function)
(add-hook 'nrepl-interaction-mode-hook 'set-auto-complete-as-completion-at-point-function)
(define-key nrepl-interaction-mode-map (kbd "C-c C-d") 'ac-nrepl-popup-doc)
(add-hook 'prog-mode-hook 'auto-complete-mode)
(add-hook 'nrepl-interaction-mode-hook
'nrepl-turn-on-eldoc-mode)
(add-hook 'nrepl-mode-hook 'paredit-mode)
This turns on paredit-mode everywhere, which takes a bit of getting used to though it's entirely worth it because paredit and makes using Clojure much more fun. At least once you get a handle on slurping and barfing

How to make the yasnippet as the auto-complete backend?

I want to make the yasnippet as the backend of the auto-complete. However, it doesn't work. what I do after searched the internet is as follows:
get the auto-complete-yasnippet.el, add some elisp in the .emacs like this:
(add-to-list 'load-path
"~/.emacs.d/plugins/yasnippet")
(require 'yasnippet)
(yas-global-mode 1)
(yas-minor-mode nil)
(global-set-key (kbd "M-/") 'yas/expand)
;; Auto-complete settings
;; this is the code for the auto-complete
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d//ac-dict")
(ac-config-default)
;;setup for auto-complete-yasnippet
(require 'auto-complete-yasnippet)
(setq-default ac-sources
'(
;; ac-source-semantic
ac-source-yasnippet
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
;; ac-source-imenu
ac-source-files-in-current-dir
ac-source-filename
)
)
I look at the content in the ac-sources in *scratch* with C-h v, and it does have the ac-source-yasnippet. someone said that there may be something wrong with the version and upgrade of auto-complete as well as yasnippet. How can it be fixed?
My emacs version is 23.3.1 my auto-complete version is 1.3.1 and my yasnippet version is 0.8.0(beta) which is just downloaded from the github. any help?
you can easily do it by (require 'auto-complete-yasnippet)
and then you can change your auto-complete like follows:
(defun my-ac-config ()
(setq-default ac-sources '(ac-source-abbrev ac-source-dictionary ac-source-words-in-same-mode-buffers))
(add-hook 'emacs-lisp-mode-hook 'ac-emacs-lisp-mode-setup)
;; (add-hook 'c-mode-common-hook 'ac-cc-mode-setup)
(add-hook 'ruby-mode-hook 'ac-ruby-mode-setup)
(add-hook 'css-mode-hook 'ac-css-mode-setup)
(add-hook 'auto-complete-mode-hook 'ac-common-setup)
(add-hook 'octave-mode-hook 'ac-octave-mode-setup)
(global-auto-complete-mode t))
(defun my-ac-cc-mode-setup ()
(setq ac-sources (append '(ac-source-clang ac-source-yasnippet) ac-sources)))
(add-hook 'c-mode-common-hook 'my-ac-cc-mode-setup)
;; ac-source-gtags
(my-ac-config)
It works fine on my machine.
there maybe something wrong with the auto-complete-config.el when acquire the ac-yasnippet-candidates in the auto-complete-1.3.1 version:
(defun ac-yasnippet-candidates ()
(with-no-warnings
(if (fboundp 'yas/get-snippet-tables)
;; >0.6.0
(apply 'append (mapcar 'ac-yasnippet-candidate-1 (yas/get-snippet-tables major-mode)))
(let ((table
(if (fboundp 'yas/snippet-table)
;; <0.6.0
(yas/snippet-table major-mode)
;; 0.6.0
(yas/current-snippet-table))))
(if table
(ac-yasnippet-candidate-1 table))))))
the code snippet above somewhat must be changed to be compatible with the yasnippet-0.8.0version. I download the newest version of auto-complete-1.4.0 from github and it solved the problem judge the version of yasnippet and take measures accordingly. Like this:
(defun ac-yasnippet-candidates ()
(with-no-warnings
(cond (;; 0.8 onwards
(fboundp 'yas-active-keys)
(all-completions ac-prefix (yas-active-keys)))
(;; >0.6.0
(fboundp 'yas/get-snippet-tables)
(apply 'append (mapcar 'ac-yasnippet-candidate-1
(condition-case nil
(yas/get-snippet-tables major-mode)
(wrong-number-of-arguments
(yas/get-snippet-tables))))))
(t
(let ((table
(if (fboundp 'yas/snippet-table)
;; <0.6.0
(yas/snippet-table major-mode)
;; 0.6.0
(yas/current-snippet-table))))
(if table
(ac-yasnippet-candidate-1 table)))))))
I copied the auto-complete-config.el from the auto-complete-1.4.0version, byte compiled it, and replaced the same files(both auto-complete-config.el and auto-complete-config.elc) in auto-complete-1.3.1version. it just worked! I think may the config file of auto-complete should not included in the distro and maybe it should maintained separately to make it easy to compatible with its backends.
I reconfigured the yasnippet and the auto-complete like this:
;; setup for yasnippet
(add-to-list 'load-path
"~/.emacs.d/plugins/yasnippet")
;; Extension and configuration of yasnippet.
(require 'yasnippet-config)
;; If you use yasnippet from 'auto-complete', add
(yas/set-ac-modes)
(yas/enable-emacs-lisp-paren-hack)
;; before 'auto-complete' settings.
;; Auto-complete settings
;; this is the code for the auto-complete
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d//ac-dict")
(ac-config-default)

Clisp + Emacs compile-and-load-file

Starting to learn Common lisp. Instal in my debian 5.03 clisp, emacs-23.1 and slime.
Write in .emacs:
(setq inferior-lisp-program "/usr/bin/clisp") ; your Lisp system
(add-to-list 'load-path "/home/slime/") ; your SLIME directory
(require 'slime)
(slime-setup '(slime-scratch slime-editing-commands slime-repl))
(global-font-lock-mode t)
(show-paren-mode 1)
(add-hook 'lisp-mode-hook '(lambda ()
(local-set-key (kbd "RET") 'newline-and-indent)))
Then create in emacs new lisp file: test.lisp write simple lisp expression:
(defun square(x)
(* x x))
Then try to compile this code C-c C-k and see in minibuffer: Not connected
p.s. Now i try to click in eval defun in emacs main menu: and see in minibuffer: Process lisp does not exist
What's wrong?
Thank you.
What happens if you do M-x slime ?
I looks like you don't have slime started.