forked from overtone/emacs-live
/
init.el
297 lines (225 loc) · 10.1 KB
/
init.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
;; User pack init file
;;
;; User this file to initiate the pack configuration.
;; See README for more information.
;; workaround for launching emacs from the stumpwm path
;; this will permit the starting of lein (which is in /home/tony/bin)
(setenv "PATH" (concat "/home/tony/bin:" (getenv "PATH")))
;; starter-kit snippets of code imported brutally after the default one (from emacs-live's init.el)
(require 'package)
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/") t)
(package-initialize)
(when (not package-archive-contents)
(package-refresh-contents))
(defvar my-packages '(starter-kit starter-kit-lisp starter-kit-js starter-kit-ruby starter-kit-eshell clojure-mode clojure-test-mode multi-term switch-window slime slime-repl ediff org flymake-shell graphviz-dot-mode auto-complete cljdoc fold-dwim htmlize)
"A list of packages to ensure are installed at launch.")
(dolist (p my-packages)
(when (not (package-installed-p p))
(package-install p)))
;; common-lisp setup
(setq inferior-lisp-program "/usr/bin/clisp")
;; (add-to-list ’load-path "/home/tony/.emacs.d/elpa/slime-20100404.1/")
;; (require ’slime-autoloads)
;; (slime-setup)
;; some multi term tweaks
(require 'multi-term)
(global-set-key (kbd "C-c C-j") 'term-line-mode)
;; some text/font/color tweaks
(setq-default fill-column 120)
(set-face-background 'default "black")
;; auto complete
(add-to-list 'ac-dictionary-directories "~/.emacs.d/elpa/auto-complete-1.4/dict")
(require 'auto-complete-config)
(ac-config-default)
(set-language-environment "UTF-8")
;; clojure-mode setup
(require 'clojure-mode)
(add-to-list 'auto-mode-alist '("\.cljs$" . clojure-mode))
(add-hook 'clojure-mode-hook (lambda () (paredit-mode +1)))
;; slime repl setup
; add color into the repl via clojure-jack-in
(add-hook 'slime-repl-mode-hook
(defun clojure-mode-slime-font-lock ()
(let (font-lock-mode)
(clojure-mode-font-lock-setup))))
(add-hook 'slime-repl-mode-hook (lambda () (paredit-mode +1)))
(setq slime-net-coding-system 'utf-8-unix)
;; nrepl setup
(add-hook 'nrepl-mode-hook (lambda () (paredit-mode +1)))
;; some personal functions that extends the one loaded from user.el
(defun exists-session-or-spawn-it (session-name session-command)
"Given a session-name, check the existence of such a session. If it doesn't exist, spawn the session via the command session-command"
(let ((proc (get-buffer-process session-name)))
(unless (and proc (eq (process-status proc) 'run))
(funcall session-command))))
(defun switch-to-buffer-or-nothing (process-name buffer-name)
"Given a process name, switch to the corresponding buffer-name if the process is running or does nothing."
(unless (string= (buffer-name) buffer-name)
(let ((proc (get-buffer-process process-name)))
(if (and proc (eq (process-status proc) 'run))
(switch-to-buffer-other-window buffer-name)))))
;; examples
;; (switch-to-buffer-or-nothing "*swank*" "*slime-repl nil*") ;; clojure-jack-in
;; (switch-to-buffer-or-nothing "*terminal<1>*" "*terminal<1>*") ;; multi-term
(defun multi-term-once ()
"Check the existence of a terminal with multi-term.
If it doesn't exist, launch it. Then go to this buffer in another buffer."
(interactive)
(unless (exists-session-or-spawn-it "*terminal<1>*" 'multi-term)
(switch-to-buffer-or-nothing "*terminal<1>*" "*terminal<1>*")))
(defun jack-in-once ()
"Check the existence of a repl session (nrepl or slime). If it doesn't exist, launch it."
(interactive)
(exists-session-or-spawn-it "*nrepl-server*" (lambda () (nrepl-jack-in nil))))
;; (exists-session-or-spawn-it "*swank*" 'clojure-jack-in)
;; other bindings that uses personal functions
(global-set-key (kbd "C-c C-z") 'multi-term-once)
(add-hook 'clojure-mode-hook 'jack-in-once)
;; Some org-mode setup
(column-number-mode)
(setq org-directory "~/org")
(setq org-startup-indented t)
(setq org-log-done 'time)
(setq org-default-notes-file (concat org-directory "/notes.org"))
(define-key global-map "\C-cc" 'org-capture)
(setq org-tag-alist '(("howTo" . ?h)
("tech" . ?t)
("emacs" . ?e)
("orgMode" . ?o)
("faq" . ?f)
("firefox")
("conkeror")
("linux")))
(setq org-todo-keywords
'((sequence "TODO" "IN-PROGRESS" "PENDING" "|" "DONE" "FAIL" "DELEGATED" "CANCELLED")))
;; To show/hide block of code
(require 'fold-dwim)
(global-set-key (kbd "C-c j") 'fold-dwim-toggle)
(global-set-key (kbd "C-c l") 'fold-dwim-hide-all)
(global-set-key (kbd "C-c ;") 'fold-dwim-show-all)
;; C-x C-l to lower case ; C-x C-u to upper case
(put 'downcase-region 'disabled nil)
(put 'upcase-region 'disabled nil)
;; Find file in project
(eval-after-load 'find-file-in-project
'(progn
;; add 'entreprise' files patterns (cough!)
(setq ffip-patterns
(append ffip-patterns
'("*.cs*""*.htm*" "*.java" "*.js*" "*.php"
"*.properties" "*.sql" "*.xml" "*.clj*")))
;; increase the max number of files, otherwise some files will be
;; 'unfindable' on big projects
(setq ffip-limit 8192)))
;; etags
(require 'etags)
(defun ido-find-tag ()
"Find a tag using ido"
(interactive)
(tags-completion-table)
(let (tag-names)
(mapc (lambda (x)
(unless (integerp x)
(push (prin1-to-string x t) tag-names)))
tags-completion-table)
(find-tag (ido-completing-read "Tag: " tag-names))))
(defun ido-find-file-in-tag-files ()
(interactive)
(save-excursion
(let ((enable-recursive-minibuffers t))
(visit-tags-table-buffer))
(find-file
(expand-file-name
(ido-completing-read
"Project file: " (tags-table-files) nil t)))))
(global-set-key [remap find-tag] 'ido-find-tag)
(global-set-key (kbd "C-.") 'ido-find-file-in-tag-files)
;; to improve the movement in files
(defvar smart-use-extended-syntax nil
"If t the smart symbol functionality will consider extended
syntax in finding matches, if such matches exist.")
(defvar smart-last-symbol-name ""
"Contains the current symbol name.
This is only refreshed when `last-command' does not contain
either `smart-symbol-go-forward' or `smart-symbol-go-backward'")
(make-local-variable 'smart-use-extended-syntax)
(defvar smart-symbol-old-pt nil
"Contains the location of the old point")
(defun smart-symbol-goto (name direction)
"Jumps to the next NAME in DIRECTION in the current buffer.
DIRECTION must be either `forward' or `backward'; no other option
is valid."
;; if `last-command' did not contain
;; `smart-symbol-go-forward/backward' then we assume it's a
;; brand-new command and we re-set the search term.
(unless (memq last-command '(smart-symbol-go-forward
smart-symbol-go-backward))
(setq smart-last-symbol-name name))
(setq smart-symbol-old-pt (point))
(message (format "%s scan for symbol \"%s\""
(capitalize (symbol-name direction))
smart-last-symbol-name))
(unless (catch 'done
(while (funcall (cond
((eq direction 'forward) ; forward
'search-forward)
((eq direction 'backward) ; backward
'search-backward)
(t (error "Invalid direction"))) ; all others
smart-last-symbol-name nil t)
(unless (memq (syntax-ppss-context
(syntax-ppss (point))) '(string comment))
(throw 'done t))))
(goto-char smart-symbol-old-pt)))
(defun smart-symbol-go-forward ()
"Jumps forward to the next symbol at point"
(interactive)
(smart-symbol-goto (smart-symbol-at-pt 'end) 'forward))
(defun smart-symbol-go-backward ()
"Jumps backward to the previous symbol at point"
(interactive)
(smart-symbol-goto (smart-symbol-at-pt 'beginning) 'backward))
(defun smart-symbol-at-pt (&optional dir)
"Returns the symbol at point and moves point to DIR (either `beginning' or `end') of the symbol.
If `smart-use-extended-syntax' is t then that symbol is returned
instead."
(with-syntax-table (make-syntax-table)
(if smart-use-extended-syntax
(modify-syntax-entry ?. "w"))
(modify-syntax-entry ?_ "w")
(modify-syntax-entry ?- "w")
;; grab the word and return it
(let ((word (thing-at-point 'word))
(bounds (bounds-of-thing-at-point 'word)))
(if word
(progn
(cond
((eq dir 'beginning) (goto-char (car bounds)))
((eq dir 'end) (goto-char (cdr bounds)))
(t (error "Invalid direction")))
word)
(error "No symbol found")))))
(global-set-key (kbd "M-n") 'smart-symbol-go-forward)
(global-set-key (kbd "M-p") 'smart-symbol-go-backward)
;; To dynamically extend emacs via macros
(defun save-macro (name)
"save a macro. Take a name as argument and save the last
defined macro under this name at the end of your .emacs"
(interactive "SName of the macro :") ; ask for the name of the macro
(kmacro-name-last-macro name) ; use this name for the macro
(find-file user-init-file) ; open ~/.emacs or other user init file
(goto-char (point-max)) ; go to the end of the .emacs
(newline) ; insert a newline
(insert-kbd-macro name) ; copy the macro
(newline) ; insert a newline
(switch-to-buffer nil)) ; return to the initial buffer
;; Macro generated by emacs
(fset 'after-jack-in
(lambda (&optional arg)
"A macro to dispose emacs buffer as i'm used to after the clojure-jack-in is started."
(interactive "p")
(kmacro-exec-ring-item (quote ([24 48 24 50 24 111 134217848 109 117 108 116 105 return 108 101 105 110 32 109 105 100 106 101 32 45 45 108 97 122 121 116 101 115 116 return 24 51 24 111 24 98 110 114 101 112 108 return 24 98 42 110 114 101 112 108 42 return 24 111] 0 "%d")) arg)))
(global-set-key (kbd "C-c C-i") 'after-jack-in)
;; Load bindings config
(live-load-config-file "bindings.el")