I will join the hoards of Emacs people and put up my Emacs init.el file here. This should be compatible with the tutorial I posted. Even though I was first exposed to Emacs over 20 years ago, I didn’t really start using it until about last year. So I truly still consider myself a newbie. Everything I learned here is basically just recapping stuff I found online. There is nothing original here. My goal is to try to present something that would have helped me when I started out learning Clojure with Emacs. This is cobbled together and modified from the main home (or github) page of each package, and here:
http://clojure.jr0cket.co.uk/perfect-environment/2—configure-emacs-for-clojure
http://ergoemacs.org/emacs/emacs_useful_user_keybinding.html
http://stackoverflow.com/questions/88399/how-do-i-duplicate-a-whole-line-in-emacs
Also, I apologize for the syntax highlighting. I’m not sure how to get elisp syntax highlighting to work in WordPress. I’m currently using SyntaxHighlighter Evolved V3.17.
;; Add Marmalade package archive for Emacs starter kit and other Emacs packages ;; This allows ALT-x package-list-packages to return a big list of useful packages (require 'package) (add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/") ) (package-initialize) ;; Add Clojure and other supporting packages to the Emacs environment ;; Packages are installed if they are not already present ;; The list includes packages for the starter kit, Clojure and markdown files (used by github) ;; This can be avoided if you have manually installed the packages eg via ;; ALT-x package-list-packages (when (not package-archive-contents) (package-refresh-contents)) (defvar my-packages '(clojure-mode ;; the major mode for clojure clojure-test-mode ;; not sure -- I still haven't learned how to write test code paredit ;; keeps parentheses balanced nrepl ;; IDE and REPL for clojure fuzzy ;; needed for nrepl popup ;; popup tooltips auto-complete ;; used for ac-nrepl ac-nrepl ;; autocomplete for nrepl eldoc ;; shows argument completion in the echo area for elisp rainbow-delimiters ;; colors parentheses, etc. undo-tree ;; undo/redo sanity restored tabbar ;; tabs at top of window linum)) ;; Line numbers in the border (dolist (p my-packages) (when (not (package-installed-p p)) (package-install p))) (add-hook 'nrepl-interaction-mode-hook 'nrepl-turn-on-eldoc-mode ) ;enables eldoc when in nrepl (not sure why this is needed) (add-hook 'clojure-mode-hook 'turn-on-eldoc-mode) ;enables eldoc when writing clojure (not sure why this is needed) (add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode) ;enables eldoc when writing elisp (add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode) ;enables eldoc for scratch buffer ;; Enable paredit mode for clojure, elisp, and nrepl (add-hook 'clojure-mode-hook 'paredit-mode) (add-hook 'emacs-lisp-mode-hook 'paredit-mode) (add-hook 'nrepl-repl-mode-hook 'paredit-mode) (require 'auto-complete-config) (ac-config-default) (define-key ac-completing-map "M-/" 'ac-stop) ; use ALT-/ to stop completion ;; Enable ac-nrepl -- this looks like a mess and doesn't quite work right ;; Not sure how this relates to popup (require 'auto-complete) (require 'ac-nrepl) (global-auto-complete-mode t) (add-hook 'nrepl-mode-hook 'ac-nrepl-setup) (add-hook 'nrepl-interaction-mode-hook 'ac-nrepl-setup) (add-hook 'clojure-nrepl-mode-hook 'ac-nrepl-setup) (eval-after-load "auto-complete" '(add-to-list 'ac-modes 'nrepl-mode)) ;; This doesn't look like http://blog.worldcognition.com/2012/07/setting-up-emacs-for-clojure-programming.html ;; colors nearest parentheses (require 'highlight-parentheses) (define-globalized-minor-mode global-highlight-parentheses-mode highlight-parentheses-mode (lambda () (highlight-parentheses-mode t))) (global-highlight-parentheses-mode t) ;; enable rainbow delimiters (require 'rainbow-delimiters) (global-rainbow-delimiters-mode) ;; These allow me to move cursor around using the keys that ;; are naturally under my right hand, while using Dvorak keyboard (global-set-key (kbd "M-h") 'backward-char) ;; sets ALT-h to left arrow, replaces emacs mail help (global-set-key (kbd "M-t") 'next-line) ;; sets ALT-t to down arrow, replaces emacs transpose (global-set-key (kbd "M-n") 'forward-char) ;; sets ALT-n to right arrow, replaces down in minibuffer history (global-set-key (kbd "M-c") 'previous-line) ;; sets ALT-c to up arrow, replaces nothing ;; buffer and tab management (require 'tabbar) (tabbar-mode 1) ;; shows tabs at the top (global-set-key [C-tab] 'next-buffer) ;; CTRL-tab goes to next buffer (global-set-key [C-S-tab] 'previous-buffer) ;; CTRL-SHIFT-tab goes to previous buffer ;; Duplicate line function ;; From http://stackoverflow.com/questions/88399/how-do-i-duplicate-a-whole-line-in-emacs (defun duplicate-line-or-region (&optional n) "Duplicate current line, or region if active. With argument N, make N copies. With negative N, comment out original line and use the absolute value." (interactive "*p") (let ((use-region (use-region-p))) (save-excursion (let ((text (if use-region ;Get region if active, otherwise line (buffer-substring (region-beginning) (region-end)) (prog1 (thing-at-point 'line) (end-of-line) (if (< 0 (forward-line 1)) ;Go to beginning of next line, or make a new one (newline)))))) (dotimes (i (abs (or n 1))) ;Insert N times, or once if not specified (insert text)))) (if use-region nil ;Only if we're working with a line (not a region) (let ((pos (- (point) (line-beginning-position)))) ;Save column (if (> 0 n) ;Comment out original with negative arg (comment-region (line-beginning-position) (line-end-position))) (forward-line 1) (forward-char pos))))) ;; Set duplicate line to CTRL-c d (global-set-key (kbd "C-c d") 'duplicate-line-or-region) ;; Other stuff (electric-indent-mode 1) ;; enables auto indentation (show-paren-mode 1) ;; shows paren matching cursor location (setq show-paren-delay 0) ;; ... with zero delay (global-linum-mode 1) ;; shows line numbers (column-number-mode 1) ;; shows cursor row,col at bottom of window (global-set-key (kbd "C-z") 'undo) ;; Sets CTRL-z to undo (global-set-key [f9] 'nrepl-jack-in) ;; Sets F9 to start nrepl (setq inhibit-startup-message t) ;; No splash screen (setq initial-scratch-message nil) ;; No scratch message (load-theme 'solarized-dark t) ;; Change colors (setq solarized-contrast 'low) ;; Change contrast