Emacs 24 and Clojure


So there’s been a while since I last dabbled in Clojure and a lot has happened.

Leiningen for instance has changed a lot. I now use version 2+. I’ve also had to install version 24 of Emacs (couldn’t get nrepl.l to work otherwise) and I’m happy to say the whole packaging thing works much more smoothly now, the setup that took hours to get going in the prior version now took a few minutes. To get Emacs I had to add the cassou repository to my repositories (lucid main), add-apt-repository ppa:cassou/emacs. At first it wouldn’t start, was complaining that some file wasn’t named in a certain way so I simply renamed that file and voila!

Marmalade was down when I did this but I was able to get everything installed through melpa that I’ve grown used to (see prior articles in this series for more details). Everything except cedet which happily worked when simply copied from my old emacs.d folder to the new one.

So with everything up and running I can simply do C-c M-j to open up an nrepl buffer and then C-c C-k to run any file I’m currently editing.

Seems like a lot has happened in Clojure web dev land as well. At the moment I’m looking into sqlkorma and noir. I ran into a couple of gotchas when setting up the connection to MySQL, first of all I had to use the jdbc driver which didn’t require anything more than [mysql/mysql-connector-java “5.1.24″] in my dependencies in the project.clj file.

Secondly the connection settings need a few tweaks, here is mine:

(defdb prod {:classname   "com.mysql.jdbc.Driver"
             :subprotocol "mysql"
             :subname     "//"
             :user        "root"
             :password    "1234"
             :delimiters  "`"})

Note zeroDateTimeBehavior=convertToNull and ` as delimiter, important stuff…

Here is my new init.l:

(add-to-list 'load-path "/home/henrik/.emacs.d/henrik")

(require 'package)
(add-to-list 'package-archives
             '("melpa" . "http://melpa.milkbox.net/packages/") t)

(defvar my-packages '(starter-kit starter-kit-lisp starter-kit-bindings clojure-mode nrepl paredit zenburn-theme ecb auto-complete exec-path-from-shell)
  "A list of packages to ensure are installed at launch.")

(dolist (p my-packages)
  (when (not (package-installed-p p))
    (package-install p)))

(add-hook 'clojure-mode-hook 'paredit-mode)

(load-theme 'zenburn t)

(setq stack-trace-on-error t)

(defun iwb ()
  "indent whole buffer"
  (indent-region (point-min) (point-max) nil)
  (untabify (point-min) (point-max)))
(defun rc () (slime-repl-clear-buffer) ) 
(defun browser-jump (base-url)
  (let (myword myurl)
    (setq myword
          (if (and transient-mark-mode mark-active)
              (buffer-substring-no-properties (region-beginning) (region-end))
            (thing-at-point 'symbol)))
    (setq myurl (concat base-url myword))
    (browse-url myurl)))

(defun clojure-jump () (interactive) (browser-jump "http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/"))

(defun picolisp-jump ()
  (let (myword myurl)
    (setq myword
          (if (and transient-mark-mode mark-active)
              (buffer-substring-no-properties (region-beginning) (region-end))
            (thing-at-point 'symbol)))
    (setq myurl (concat "http://localhost/documents/picolisp/ref" (upcase (substring myword 0 1)) ".html#" myword))
    (browse-url myurl)))

(fset 'sqbracket-wrap
      (lambda (&optional arg) "Keyboard macro." (interactive "p") (kmacro-exec-ring-item (quote ("\213[" 0 "%d")) arg)))

(fset 'curlybrace-wrap
      (lambda (&optional arg) "Keyboard macro." (interactive "p") (kmacro-exec-ring-item (quote ("\213{" 0 "%d")) arg)))

(defun lisp-enable-paredit-hook () (paredit-mode 1))
(add-hook 'picolisp-mode-hook 'lisp-enable-paredit-hook)

(setq kill-whole-line t)

(defun refresh-file ()
  (revert-buffer t t t))

(load-file "/home/henrik/.emacs.d/henrik/cedet/common/cedet.el")

(global-ede-mode 1)
(setq ecb-tree-buffer-style 'ascii-guides)
(global-set-key [f12] 'ecb-activate)
(setq ecb-tip-of-the-day nil)

; left7 left14 left-dir-plus-speedbar
(setq ecb-layout-name "left15")
(setq ecb-layout-window-sizes (quote (("left15" (0.14285714285714285 . 0.49206349206349204) (0.14285714285714285 . 0.49206349206349204)))))
(setq my-projects '("/opt/clojure" "/opt/picolisp" "/home/henrik/rails_projects" "/home/henrik/.emacs.d"))
(setq tags-table-list '("/opt/picolisp"))
(setq ecb-source-path my-projects)

(require 'auto-complete-config)
(setq ac-auto-start 3)
(add-to-list 'ac-modes 'picolisp-mode)
(setq ac-ignore-case t)
(setq ac-auto-start nil)
(global-set-key (kbd "C-<tab>") 'auto-complete)

(add-to-list 'auto-mode-alist '("\\.l\\'" . picolisp-mode))

(add-hook 'inferior-picolisp-load-hook (lambda () (tsm-mode 1)))

(delete-selection-mode t)


(setq nrepl-hide-special-buffers t)
(add-hook 'nrepl-interaction-mode-hook 'nrepl-turn-on-eldoc-mode)
;(add-hook 'clojure-mode-hook 'nrepl)

(add-hook 'clojure-mode-hook 'rainbow-delimiters-mode)
(add-hook 'picolisp-mode-hook 'rainbow-delimiters-mode)

(global-linum-mode 1)
(setq column-number-mode t)

(defun switch-full-screen ()
  (shell-command "wmctrl -r :ACTIVE: -btoggle,fullscreen"))

(global-set-key [f11] 'switch-full-screen)
(global-set-key (kbd "C-c C-s") 'find-grep-dired)
(global-set-key [f5] 'refresh-file)
(global-set-key (kbd "C-z") 'undo)
(global-set-key (kbd "C-M-m") 'mark-sexp)
(global-set-key (kbd "M-[") 'sqbracket-wrap)
(global-set-key [f1] 'menu-bar-mode)
(global-set-key [f6] 'split-window-horizontally)
(global-set-key [f7] 'split-window-vertically)
(global-set-key [f8] 'delete-window)
(global-set-key (kbd "C-c c")        'comment-region)
(global-set-key (kbd "C-c C-u c")    'uncomment-region)

(eval-after-load 'clojure-mode
	'(define-key clojure-mode-map (kbd "M-{") 'curlybrace-wrap))

(eval-after-load 'clojure-mode
	'(define-key clojure-mode-map (kbd "C-M-r") 'clojure-jump))

(eval-after-load 'picolisp-mode
	'(define-key picolisp-mode-map (kbd "C-M-r") 'picolisp-jump))

Related Posts

Tags: , ,