forked from technomancy/emacs-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjames.el
268 lines (214 loc) · 8.44 KB
/
james.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
;; DESCRIPTION: jstr settings (heavily based upon topfunky settings)
;; Manually set PATH for use by eshell, rspec-mode, etc.
(let ((path))
(setq path (concat "/opt/ruby-enterprise/bin:"
"~/bin:"
"~/src/homebrew/bin:"
"/usr/local/bin:"
"/usr/bin:"
"/bin"))
(setenv "PATH" path))
(add-to-list 'load-path (concat dotfiles-dir "/vendor"))
;; Save backups in one place
;; Put autosave files (ie #foo#) in one place, *not*
;; scattered all over the file system!
(defvar autosave-dir
(concat "/tmp/emacs_autosaves/" (user-login-name) "/"))
(make-directory autosave-dir t)
(defun auto-save-file-name-p (filename)
(string-match "^#.*#$" (file-name-nondirectory filename)))
(defun make-auto-save-file-name ()
(concat autosave-dir
(if buffer-file-name
(concat "#" (file-name-nondirectory buffer-file-name) "#")
(expand-file-name
(concat "#%" (buffer-name) "#")))))
;; Put backup files (ie foo~) in one place too. (The backup-directory-alist
;; list contains regexp=>directory mappings; filenames matching a regexp are
;; backed up in the corresponding directory. Emacs will mkdir it if necessary.)
(defvar backup-dir (concat "/tmp/emacs_backups/" (user-login-name) "/"))
(setq backup-directory-alist (list (cons "." backup-dir)))
;;(add-hook 'before-save-hook 'delete-trailing-whitespace)
(setq default-tab-width 4)
(setq-default tab-stop-list (list 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100 104 108))
(setq tab-width 4)
;; Custom frame width
(add-to-list 'default-frame-alist '(width . 180))
(add-to-list 'default-frame-alist '(height . 50))
;; Open current file in TextMate.
(defun textmate-open-buffer ()
(interactive)
(shell-command-to-string (concat "mate " buffer-file-name)))
;; Plain Text
;;; Stefan Monnier <foo at acm.org>. It is the opposite of
;;; fill-paragraph. Takes a multi-line paragraph and makes
;;; it into a single line of text.
(defun unfill-paragraph ()
(interactive)
(let ((fill-column (point-max)))
(fill-paragraph nil)))
(defun refresh-file ()
(interactive)
(revert-buffer t t t))
(global-set-key [f5] 'refresh-file)
;; Snippets
(add-to-list 'load-path (concat dotfiles-dir "/vendor/yasnippet.el"))
(require 'yasnippet)
(yas/initialize)
(yas/load-directory (concat dotfiles-dir "/vendor/yasnippet.el/snippets"))
;; Commands
(require 'unbound)
;; Minor Modes
(add-to-list 'load-path (concat dotfiles-dir "/vendor/textmate.el"))
(require 'textmate)
(textmate-mode)
(require 'whitespace)
;; Centered cursor mode support
(load (concat dotfiles-dir "vendor/centered-cursor-mode.el"))
(require 'centered-cursor-mode)
(global-centered-cursor-mode +1)
;; Major Modes
;; Enable javascript-mode
(autoload 'javascript-mode "javascript-mode.el"
"Major mode for editing JavaScript files" t)
(add-to-list 'auto-mode-alist '("\\.js\\'" . javascript-mode))
;; Enable nav mode
(add-to-list 'load-path (concat dotfiles-dir "vendor/nav"))
(require 'nav)
(add-to-list 'load-path (concat dotfiles-dir "/vendor/rspec-mode"))
(require 'rspec-mode)
(require 'textile-mode)
(add-to-list 'auto-mode-alist '("\\.textile\\'" . textile-mode))
(autoload 'markdown-mode "markdown-mode.el"
"Major mode for editing Markdown files" t)
(add-to-list 'auto-mode-alist '("\\.mdown\\'" . markdown-mode))
(require 'haml-mode)
(add-to-list 'auto-mode-alist '("\\.haml$" . haml-mode))
(require 'sass-mode)
(add-to-list 'auto-mode-alist '("\\.sass$" . sass-mode))
(add-to-list 'auto-mode-alist '("\\.sake\\'" . ruby-mode))
(require 'php-mode)
(add-to-list 'auto-mode-alist '("\\.php$" . php-mode))
;; gist
(require 'gist)
;; Color Themes
(add-to-list 'load-path (concat dotfiles-dir "/vendor/color-theme"))
(require 'color-theme)
(color-theme-initialize)
;; Functions
(require 'line-num)
;; Full screen toggle
;; Doesn't appear to work in Cocoa Emacs.
;; (defun toggle-fullscreen ()
;; (interactive)
;; (set-frame-parameter nil 'fullscreen (if (frame-parameter nil 'fullscreen)
;; nil
;; 'fullboth)))
;; (global-set-key (kbd "M-n") 'toggle-fullscreen)
;; Outdent
;; TODO: Fix issue: does not function with tab width in document
;; (e.g. ruby files) does not ==
;; default-tab-width/tab-width. Investigate further.
(defun outdent ()
(interactive)
(move-beginning-of-line nil)
(push-mark)
(move-end-of-line nil)
(indent-rigidly (region-beginning) (region-end) (* -1 (symbol-value 'tab-width)))
(pop-mark))
(global-set-key (kbd "S-<tab>") 'outdent)
;; Keyboard
;; Some Mac-friendly key counterparts
(global-set-key (kbd "M-s") 'save-buffer)
(global-set-key (kbd "M-z") 'undo)
;; Custom tab formatting stuff..
(global-set-key (kbd "C-c n") 'nav)
;; Custom key bindings for other-window
(global-set-key (kbd "C-`") 'other-window)
(global-set-key (kbd "s-`") 'other-window)
;; Custom key binding for ido-imenu
(global-set-key (kbd "C-.") 'ido-imenu)
;; Custom key binding for comment or uncomment
(global-set-key (kbd "C-/") 'comment-or-uncomment-region-or-line)
;; Custom key binding for goto-line
(global-set-key (kbd "C-c g") 'goto-line)
;; Kill current buffer without prompting
(global-set-key (kbd "C-c k") 'kill-buffer-now)
(defun kill-buffer-now ()
"Kill current buffer without prompting."
(interactive)
(kill-buffer (current-buffer)))
;; Refresh ctags for current project.
(defun reload-tags ()
"Rebuild gtags and visit tags table"
(interactive)
(shell-command "/usr/local/bin/ctags-create")
(visit-tags-table "TAGS"))
(global-set-key [(tab)] 'smart-tab)
(defun smart-tab ()
"This smart tab is minibuffer compliant: it acts as usual in
the minibuffer. Else, if mark is active, indents region. Else if
point is at the end of a symbol, expands it. Else indents the
current line."
(interactive)
(if (minibufferp)
;; Perform the default behaviour. Do not do dabbrev-expand
(minibuffer-complete)
(if (eq (symbol-value 'major-mode) 'shell-mode)
(unless (shell-dynamic-complete-command)
(shell-dynamic-complete-filename))
(if mark-active
(indent-region (region-beginning)
(region-end))
(if (looking-at "\\_>")
(dabbrev-expand nil)
(indent-for-tab-command))))))
;; Duplicate line
(defun duplicate-line ()
"EASY"
(interactive)
(save-excursion
(let ((line-text (buffer-substring-no-properties
(line-beginning-position)
(line-end-position))))
(move-end-of-line 1)
(newline)
(insert line-text))))
(global-set-key "\C-cd" 'duplicate-line)
;; Select current line and move cursor to end of line
(defun select-line ()
"Selects the current line."
(interactive)
(end-of-line)
(push-mark nil t t)
(back-to-indentation))
(global-set-key (kbd "C-c s") 'select-line)
;; Other
(prefer-coding-system 'utf-8)
(server-start)
;; Activate theme
(load (concat dotfiles-dir "color-theme-github.el"))
(color-theme-github)
;; Use pretty-greek mode. Code from http://www.emacswiki.org/emacs/PrettyGreek.
(defun pretty-greek ()
(interactive)
(let ((greek '("alpha" "beta" "gamma" "delta" "epsilon" "zeta" "eta" "theta" "iota" "kappa" "lambda" "mu" "nu" "xi" "omicron" "pi" "rho" "sigma_final" "sigma" "tau" "upsilon" "phi" "chi" "psi" "omega")))
(loop for word in greek
for code = 97 then (+ 1 code)
do (let ((greek-char (make-char 'greek-iso8859-7 code)))
(font-lock-add-keywords nil
`((,(concatenate 'string "\\(^\\|[^a-zA-Z0-9]\\)\\(" word "\\)[a-zA-Z]")
(0 (progn (decompose-region (match-beginning 2) (match-end 2))
nil)))))
(font-lock-add-keywords nil
`((,(concatenate 'string "\\(^\\|[^a-zA-Z0-9]\\)\\(" word "\\)[^a-zA-Z]")
(0 (progn (compose-region (match-beginning 2) (match-end 2)
,greek-char)
nil)))))))))
;; Use pretty-greek only in appropriate modes..
(add-hook 'org-mode-hook 'pretty-greek)
(add-hook 'text-mode 'pretty-greek)
;; Use clean view mode in org-mode..
(add-hook 'org-mode-hook 'org-indent-mode)
;; Global store an org link to current logication
(global-set-key "\C-cl" 'org-store-link)