Trouble with enabling clojure-mode-extra-font-locking mode in emacs - emacs

I am currently trying to enable clojure-mode-extra-font-locking in emacs. Currently it's in
~/.emacs.d/bootleg/clojure-mode-extra-font-locking/clojure-mode-extra-font-locking.el
.
I have the following code:
(require 'clojure-mode)
(add-to-list 'load-path "~/.emacs.d/bootleg/clojure-mode-extra-font-locking/")
(require 'clojure-mode-extra-font-locking)
But when I open a .clj file I get this in the minibuffer:
File mode specification error: (void-function enable)
What am I doing wrong? Thank you!
edit:
This is what I get with
M-x toggle-debug-on-error
Debugger entered--Lisp error: (void-function enable)
enable()
run-hooks(change-major-mode-after-body-hook prog-mode-hook clojure-mode-hook)
apply(run-hooks (change-major-mode-after-body-hook prog-mode-hook clojure-mode-hook))
run-mode-hooks(clojure-mode-hook)
clojure-mode()
set-auto-mode-0(clojure-mode nil)
set-auto-mode()
normal-mode(t)
after-find-file(nil t)
find-file-noselect-1(#<buffer test.clj> "~/src/clojure/test.clj" nil nil "~/src/clojure/test.clj" (16260320 2069))
find-file-noselect("/home/n/src/clojure/test.clj" nil nil nil)
find-file("/home/n/src/clojure/test.clj")
#[257 "\304\305!!r\306\307\310\311\312\313!\314\"\315\316%DC\216\317#\320\"\210 \205$\321\n!?\205)\322\323\n\"!+\207" [ivy-last counsel-find-file-speedup-remote ivy--directory find-file-hook internal--before-with-selected-window ivy--get-window funcall make-byte-code 0 "\301\300!\207" vconcat vector [internal--after-with-selected-window] 2 "\n\n(fn)" select-window norecord file-remote-p find-file expand-file-name] 9 "\n\n(fn X)"]("/home/k/src/clojure/test.clj")
ivy-call()
ivy-read("Find file: " read-file-name-internal :matcher counsel--find-file-matcher :initial-input nil :action #[257 "\304\305!!r\306\307\310\311\312\313!\314\"\315\316%DC\216\317#\320\"\210 \205$\321\n!?\205)\322\323\n\"!+\207" [ivy-last counsel-find-file-speedup-remote ivy--directory find-file-hook internal--before-with-selected-window ivy--get-window funcall make-byte-code 0 "\301\300!\207" vconcat vector [internal--after-with-selected-window] 2 "\n\n(fn)" select-window norecord file-remote-p find-file expand-file-name] 9 "\n\n(fn X)"] :preselect nil :require-match confirm-after-completion :history file-name-history :keymap (keymap (C-backspace . counsel-up-directory) (67108991 . counsel-up-directory)) :caller counsel-find-file)
counsel-find-file()
call-interactively(counsel-find-file nil nil)
command-execute(counsel-find-file)

Are you sure you really need/want this package?
When I saw your question, my first response was going to be "Don't bother with
it." This was mainly because the last time I looked, the package was fairly out
of date and a while ago, cider had added functionality to provide enhanced
font-locking anyway. However, I then checked and saw that the extra font lock
package has recently been updated and remembered that while cider is fantastic,
there are some who prefer to use inf-clojure rather than cider (especially in
some node based environments where you don't have an nRepl and don't want to go
the piggieback middleware route to fake one).
the first thing you should do is change your setup to get clojure-mode and
clojure-mode-extra-font-lock from the MELPA archive. The clojure-mode and cider
packages are fast moving targets with new packages released pretty much every
week. This is great, but it does make keeping additional packages like the extra
font lock package in sync a little harder. Getting them from the package
archives will likely help ensure things are all in sync.
If your new to clojure, I really wouldn't worry about the additional
font-locking stuff. Far better to concentrate on just clojure-mode, cider and
clj-refactor. IMO these are the much more important parts and the ones which
will enhance the environment and your workflow. Once you have those packages all
working well and your comfortable with them, then go back and look at adding the
extra font locking. There is a high chance you will find it unnecessary.
I also highly recommend using the use-package package to manage your elpa
packages. It makes your init file easier to maintain and can dramatically speed
up emacs startup time.

Related

emacs scratch not interactive mode

I updated a lot of packages that I had directly from github to the MELPA packages. Nonetheless something really weird happened to my *scratch* buffer. The default message is not appearing (the buffer is completely empty), and also the interactive elisp mode is not set (let's say I write (+ 2 2) and then hit C-j and it tells me invalid function). I have no idea why. I don't even know how to debug it to check where the error is. Any ideas?
Finally the problem was generated by flycheck-add-next-checker, for some reason, using the MELPA repositories is generating this error. I just commented the following part of my configuration file.
(eval-after-load 'flycheck
'(progn
;; Add Google C++ Style checker.
;; In default, syntax checked by Clang and Cppcheck.
(flycheck-add-next-checker 'c/c++-clang
'(warnings-only . c/c++-googlelint))))

org mode with clojure - can't get export to work

EDIT I've also asked this question on emacs.stackexchange
I'm a relative emacs newbie and have set up my emacs (24.4.1) to work with clojure as described here.
The gist of it is that I am now using the latest org-mode from git and loading it in my init.el (I am using prelude btw) as below:
(add-to-list 'load-path "~/repos/org-mode/lisp")
(require 'org)
(require 'ob-clojure)
I am trying to use org to write a literate clojure program that I can export to markdown. Clojure and babel now work well, evaluation works etc, but when I try to export my org file I get an error.
load-with-code-conversion: Symbol's value as variable is void: p
The stack trace when I set toggle-debug-on-error is:
Debugger entered--Lisp error: (void-variable p)
eval-buffer(#<buffer *load*> nil
"/Users/krisfoster/repos/org-mode/lisp/ox.el" nil t)
; Reading at buffer position 229233
load-with-code-conversion("/Users/krisfoster/repos/org-mode/lisp/ox.el"
"/Users/krisfoster/repos/org-mode/lisp/ox.el" nil t)
autoload-do-load((autoload "ox" "Export dispatcher for Org mode.\n
\nIt provides an access to common export related tasks in a
buffer.\nIts interface comes in two flavors: standard and
expert.\n\nWhile both share the same set of bindings, only the
former\ndisplays the valid keys associations in a dedicated
buffer.\nScrolling (resp. line-wise motion) in this buffer is done
with\nSPC and DEL (resp. C-n and C-p) keys.\n\nSet variable `org-
export-dispatch-use-expert-ui' to switch to one\nflavor or the
other.\n\nWhen ARG is \\[universal-argument], repeat the last
export action, with the same set\nof options used back then, on
the current buffer.\n\nWhen ARG is \\[universal-argument] \\
[universal-argument], display the asynchronous export
stack.\n\n(fn &optional ARG)" t nil) org-export-dispatch)
command-execute(org-export-dispatch)
I tried to resolve this by (require-ing the various org export packages, the ones in the clone of the org git repo that is, from within my init.el. But no dice - in fact that generated yet more issues. I have tried debugging but can't figure out what is wrong. I am suspecting I need to be requiring something but don't know what.
I have my init.el here - init.el gist
Any-one have any ideas what I am doing wrong?
Thanks in advance.
There was a bug in org-mode around the time you made this post, so the problem may be resolved. However, I noticed a few issues with your init file. Some things which might help
Use the lisp package manager to install your packages (ELPA). This will make your life much easier. The org guys maintain an ELPA repository which is updated regularly and will likely be a little more stable than just pulling in the repo. They have a version called org-plus-contrib which I use and find quite good. Just add
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/"))
You state that your running prelude, but I can't see anything in your init which is loading prelude (only a call to a function which turns off the guru-mode). Prelude is pretty good and quite popular, but if your going to use it, you need to 'drink the cool aid' that is, do things in the prelude way. For example, prelude comes with org-mode and uses ELPA to install it. You need to be careful your not get a blend of org versions. Another alternative to prelude which I found very good is Steve Purcell's emacs.d. I found it a little easier to work with YMMV, but it may be worth checking out as it has good support for the mac. See emacs.d
It is a really good idea to break up your emacs init script into separate files. This makes it easy to comment out lots of stuff when your trying to track down a problem and allows you to just focus on the key bits your trying to get working. I maintain my init.el file as an org file and use babel to generate all the lisp code. You can have a look at it on github. I originally started with Purcell's emacs.d and then borrowed with pride (stole) much of it to go into my own config. It isn't a fine example of how to configure emacs, but might help with your setup
I notice your attempting to use cider as the backend 'evaluator' for clojure code. Note that you only need to do this if you want to have blocks of clojure in your org file which you want to evaluate and then use the result. You don't need to do this if all you want to do is generate *.clj files from your org code. Instead, you just want to 'tangle' your org file, which will generate the updated clj source files, which you can then work on. This keeps things a lot simpler and avoids problems arising when you try to do things with your org file that attempt to evaluate the clojure code and fail. Note also that I expect you would need to do a bit more than just set cider as the backend evaluator - cide is just an interface to a repl. You would need a repl as well.

ac-auto-start (auto-complete mode) would not get set no matter what

I'm facing a very bizarre behaviour. No matter how I set ac-auto-start, be it through customization, by evaluating (setq ac-auto-start 2), (setq-default ac-auto-start 2) or (setq-local ac-auto-start 2) immediately after I do it, the variable is set to nil.
I've looked through the source of auto-complete mode and the ac-slime in my case, but none of these does nothing to this variable. I am at a loss as to how to deal with this.
The effective consequences of this malfunction is that completion combobox doesn't appear on its own, unless I force it to by doing M-x auto-complete. This behaviour is consistent in all modes where auto-complete minor mode is enabled.
EDIT
This seems to be an issue with latest Emacs. Now it fails to modify variables values, no matter what variable it is. So, say, after running it with -Q I've now discovered that I can't evaluate the code that uses (setq ...) forms as it has no effect. :/ So, please, hold on, I'll try to investigate this...
This was due to the typo, but the original problem is still there.
Emacs version is 24.3.50.1 pulled from trunk about a week ago.
auto-complete is version 1.4 installed from MELPA.
I'm setting the variable by moving the point to the REPL buffer, then M-:. I check its value in the same way.
EDIT2
OK, I finally found the reason: I had enzyme package installed, and it had an earlier version of auto-complete inside of it, for some reason parts of the auto-complete code were loaded from there and other parts from the one installed from MELPA. After disabling enzyme it all works well now.
EDIT3
This still happens after I run (auto-complete-mode 1) in the REPL buffer. The variable will become impossible to set. I've searched through various autocomplete timers that may be setting something, but no luck so far.
There is indeed something strange going on with the setting of auto-complete-mode.
(I'm using the ELPA version in a GNU Emacs 24.3.1)
This is set up by customize-group RET auto-complete :
'(ac-auto-show-menu t)
'(ac-auto-start t)
At this point if you M-x auto-complete-mode you get a [no match] right in the minibuffer. Only after you try to M-x auto-complete, yelding a "auto-complete-mode is not enabled" weird error, will you be able to M-x auto-complete-mode (but without command completion... Hm) and then be in the mode.
If you put this in your init file (.emacs)
(require 'auto-complete)
(auto-complete-mode t)
It will be effective only if you re-eval it after startup (?!?).
The same with something like
(if (auto-complete)
(auto-complete-mode t))
The only way that I found to get auto-complete-mode to load at startup is to :
(eval-and-compile
(require 'auto-complete nil 'noerror))
(The above customize options are now effective)

Emacs Init File Line Numbering

I am trying to display line numbers in emacs on the left hand side. I know it is the linum-mode. When I do M-x linum-mode, my emacs can't find linum-mode. It only finds line-numbers-mode which displays it on the mode bar at the bottom. Why does it not have linum-mode?
Also, when I put (menu-bar-mode t) or even (menu-bar-mode 1), the menu bar does not start at start-up.
When I put (global-linum-mode t) I get the following init error (using --debug-init):
Debugger entered--Lisp error: (void-function global-linum-mode)
(global-linum-mode t)
eval-buffer(#<buffer *load*> nil "/Users/nayef/.emacs.d/init.el" nil t) ; Reading at buffer position 68
load-with-code-conversion("/Users/nayef/.emacs.d/init.el" "/Users/nayef/.emacs.d/init.el" t t)
load("/Users/nayef/.emacs.d/init" t t)
This is extremely extremely frustrating. It works on one computer over SSH but when I do it on my laptop it does not work. I am starting to understand that even though Emacs is more powerful than VIM, VIM is at least 10 times easier to use, less keystrokes and requires WAY less modifications.
Which version of Emacs do you have? linum-mode is included with Emacs 23 and Emacs 24. If you can, you should probably upgrade to those version. If you can't upgrade and you have Emacs 22, you'll need to do the following steps:
Download linum.el on your system (let's say it's in /home/nayefc/).
Add the line (add-to-list 'load-path "/home/nayefc/") to your .emacs
Add the line (require 'linum) to your .emacs
Restart Emacs, and you should be able to call M-x linum-mode. Good luck.
Vincent.
You're having problems because linum-mode is not a standard part of any Emacs distribution; it has to be installed. You can get it here.

A gentle tutorial to Emacs/Swank/Paredit for Clojure

I am moving to Emacs to work on Clojure/Lisp.
What is all the information I need to setup on Emacs to be able to do the following?
automatic matching/generation of corresponding closing brackets
autoindent Lisp/Clojure style, not C++/Java style
Syntax highlighting
Invoking REPL
To be able to load a part of code from file into the REPL and evaluate it.
It would be great if I could also get the list of commands to get these things after setting things up on Emacs.
[Edit from non-author: this is from 2010, and the process has been significantly simplified since May 2011. I'll add a post to this answer with my setup notes as of Feb 2012.]
You'll need to put together a few pieces: Emacs, SLIME (which works perfectly well with Clojure -- see swank-clojure), swank-clojure (the Clojure implementation of SLIME's server counterpart), clojure-mode, Paredit and, of course, the Clojure jar for a start, then perhaps some extras among which Leiningen would perhaps be the most notable. Once you do set it all up, you'll have -- within Emacs -- all the workflow / editing features you mention in the question.
Basic setup:
The following are to great tutorials which describe how to set all of this up; there's more on the Web, but some of the others are quite outdated, whereas these two seem to be ok for now:
in which are found tricks of the trade concerning clojure authorship post on Phil Hagelberg's blog; Phil maintains swank-clojure and clojure-mode, as well as a package called the Emacs Starter Kit which is something any newcomer to the Emacs world would be well-advised to have a look at. These instructions seem to have been brought up to date with recent changes to the infrastructure; in case of doubt, look for additional information on Clojure's Google group.
Setting up Clojure, Incanter, Emacs, Slime, Swank, and Paredit post on the blog of the Incanter project. Incanter is a fascinating package providing an R-like DSL for statistical computations embedded right into Clojure. This post will be useful even if you don't plan on using -- or even installing -- Incanter.
Putting it all to work:
Once you set up all of this stuff, you could try and start using it right away, but I would strongly advise you to do the following:
Have a look at SLIME's manual -- it's included in the sources and is actually very readable. Also, there's absolutely no reason why you should read the whole 50-page monster manual; just have a look around to see what features are available.
Note: the autodoc feature of SLIME as found in the latest upstream sources is incompatible with swank-clojure -- this problem won't come up if you follow Phil Hagelberg's recommendation to use the ELPA version (see his aforementioned blog post for an explanation) or simply leave autodoc off (which is the default state of things). The latter option has some added appeal in that you can still use the latest SLIME with Common Lisp, in case you use that as well.
Have a look at the docs for paredit. There are two ways to go about this: (1) look at the source -- there's a huge amount of comments at the top of the file which contain all the information you're likely to need; (2) type C-h m in Emacs while paredit-mode is active -- a buffer will pop up with information on the current major mode followed by information on all active minor modes (paredit is one of those).
Update: I've just found this cool set of notes on Paredit by Phil Hagelberg... That's a link to a text file, I remember seeing a nice set of slides with this information somewhere, but can't seem to find it now. Anyway, it is a nice summary of how it works. Definitely take a look at it, I can't live without Paredit now and this file should make it very easy to start using it, I believe. :-)
In fact, the C-h m combination will tell you about all keybindings active at the SLIME REPL, in clojure-mode (you'll want to remember C-c C-k for sending the current buffer off for compilation) and indeed in any Emacs buffer.
As for loading the code from a file and then experimenting with it at the REPL: use the aforementioned C-c C-k combination to compile the current buffer, then use or require its namespace at the REPL. Next, experiment away.
Final notes:
Be prepared to have to tweak things for a while before it all clicks. There's a lot of tools involved and their interactions are mostly fairly smooth, but not to the point where it would be safe to assume you won't have to make some adjustments initially.
Finally, here's a bit of code I keep in .emacs which you won't find elsewhere (although it's based on a cool function by Phil Hagelberg). I alternate between starting my swank instances with lein swank (one of the cooler features of Leiningen) and using the clojure-project function as found below to start the whole thing from within Emacs. I've done my best to make the latter produce an environment closely matching that provided by lein swank. Oh, and if you just want a REPL in Emacs for a quick and dirty experiment, then with the correct setup you should be able to use M-x slime directly.
(setq clojure-project-extra-classpaths
'(
; "deps/"
"src/"
"classes/"
"test/"
))
(setq clojure-project-jar-classpaths
'(
; "deps/"
"lib/"
))
(defun find-clojure-project-jars (path)
(apply #'append
(mapcar (lambda (d)
(loop for jar in (remove-if (lambda (f) (member f '("." "..")))
(directory-files d t))
collect jar into jars
finally return jars))
(remove-if-not #'file-exists-p
clojure-project-jar-classpaths))))
(defun find-clojure-jar (jars)
(let ((candidates
(remove-if-not
(lambda (jar)
(string-match-p "clojure\\([0-9.-]+\\(SNAPSHOT|MASTER\\)?\\)?\\.jar$" jar))
jars)))
(if candidates
(car candidates)
(expand-file-name "~/.clojure/clojure.jar"))))
(defun find-clojure-contrib-jar (jars)
(let ((candidates
(remove-if-not
(lambda (jar)
(string-match-p "clojure-contrib\\([0-9.-]+\\(SNAPSHOT|MASTER\\)?\\)?\\.jar$" jar))
jars)))
(if candidates
(car candidates)
(expand-file-name "~/.clojure/clojure-contrib.jar"))))
;;; original due to Phil Hagelberg
;;; (see `Best practices for Slime with Clojure' thread on Clojure Google Group)
(defun clojure-project (path)
"Sets up classpaths for a clojure project and starts a new SLIME session.
Kills existing SLIME session, if any."
(interactive (list (ido-read-directory-name
"Project root:"
(locate-dominating-file default-directory "pom.xml"))))
(when (get-buffer "*inferior-lisp*")
(kill-buffer "*inferior-lisp*"))
(cd path)
;; I'm not sure if I want to mkdir; doing that would be a problem
;; if I wanted to open e.g. clojure or clojure-contrib as a project
;; (both lack "deps/")
; (mapcar (lambda (d) (mkdir d t)) '("deps" "src" "classes" "test"))
(let* ((jars (find-clojure-project-jars path))
(clojure-jar (find-clojure-jar jars))
(clojure-contrib-jar (find-clojure-contrib-jar jars)))
(setq swank-clojure-binary nil
;; swank-clojure-jar-path (expand-file-name "~/.clojure/clojure.jar")
swank-clojure-jar-path clojure-jar
swank-clojure-extra-classpaths
(cons clojure-contrib-jar
(append (mapcar (lambda (d) (expand-file-name d path))
clojure-project-extra-classpaths)
(find-clojure-project-jars path)))
swank-clojure-extra-vm-args
(list (format "-Dclojure.compile.path=%s"
(expand-file-name "classes/" path)))
slime-lisp-implementations
(cons `(clojure ,(swank-clojure-cmd) :init swank-clojure-init)
(remove-if #'(lambda (x) (eq (car x) 'clojure))
slime-lisp-implementations))))
(slime))
There is one more excelent tutorial:
http://www.braveclojure.com/basic-emacs/ (1st part)
http://www.braveclojure.com/using-emacs-with-clojure/ (2nd part)
In 30 to 45 minutes one can have everything setup from scratch.
The tutorial does not assumes any prior knowladge of Emacs (and Clojure too - in earlier posts there is a nice intro to Clojure).
The Emacs Starter kit has gotten great reviews for getting started with Clojure:
To answer only the swank part of your question:
Leiningen is a really easy way of setting up swank with the correct classpath and get it connected to Emacs.
A great video is here: http://vimeo.com/channels/fulldisclojure#8934942
Here is an example of a project.clj file that
(defproject project "0.1"
:dependencies [[org.clojure/clojure
"1.1.0-master-SNAPSHOT"]
[org.clojure/clojure-contrib
"1.0-SNAPSHOT"]]
:dev-dependencies [[leiningen/lein-swank "1.1.0"]]
:main my.project.main)
then run:
lein swank
and from Emacs:
alt-x slime-connect
Clojure with Emacs on Clojure Documentation can be useful too.
CIDER (Clojure Interactive
Development Environment) must be mentioned here.
It’ll cover most of what you’re looking for. It includes:
interactive REPL
debugging
test running
code navigation
documentation lookup
lots more
In addition to CIDER, there are some other essential and nice-to-have
add-ons for clojure development, which I’ll try to group respectively
(and subjectively):
Essentials
smartparens – parentheses
pairing, manipulation, navigation (or
parinfer if you prefer)
clj-refactor –-
has a couple amazing features, like auto-adding/compiling namepaces
(it may be incorporated into CIDER soon)
clojure-mode –
font-lock, indentation, navigation
company – text completion
framework (or choose another auto-completer)
rainbow delimeters –
highlights/colorizes delimiters such as parentheses, brackets or
braces according to their depth
flycheck – on-the-fly syntax
checking extension
flycheck-clj-kondo –
integration for clj-kondo
Niceties
clojure-snippets –
tab-expandable shortcuts to longer code chunks
dumb-jump – jump to
definitions
which-key – displays
available keybindings in popup
highlight parentheses –
highlight surrounding parentheses
crux – a Collection of
Ridiculously Useful eXtensions for Emacs
comment-dwim-2 –
replacement for Emacs’ built-in comment-dwim
General Essentials (for any language)
magit – git porcelain inside Emacs
projectile – project mgmt
for finding files, searching, etc
helm – incremental completion
and selection narrowing framework (or
swiper)
Other Resources
If you’re looking for a setup that already has done most/all of this
work for you, a couple options are:
prelude
spacemacs