-
Notifications
You must be signed in to change notification settings - Fork 1
/
adam.el
238 lines (198 loc) · 8.78 KB
/
adam.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
(defun my-coding-hook ()
(make-local-variable 'column-number-mode)
(column-number-mode t)
(if window-system (hl-line-mode t))
(idle-highlight-mode t)
(subword-mode t)
;; TODO: re-enable
;; (define-key js2-mode-map (kbd "C-,") (sp-restrict-to-pairs-interactive "{" 'sp-down-sexp))
;; (define-key js2-mode-map (kbd "C-.") (sp-restrict-to-pairs-interactive "{" 'sp-up-sexp))
)
(add-hook 'emacs-lisp-mode-hook 'my-coding-hook)
(add-hook 'ruby-mode-hook 'my-coding-hook)
;; (require 'rubocop)
(add-hook 'ruby-mode-hook #'rubocop-mode)
;; TODO: move this to JS2 setup
;; BEGIN JS2 MODE
(add-hook 'js2-mode-hook 'my-coding-hook)
(setq js-indent-level 2)
(eval-after-load 'js2-mode
`(progn
;; BUG: self is not a browser extern, just a convention that needs checking
(setq js2-browser-externs (delete "self" js2-browser-externs))
;; Consider the chai 'expect()' statement to have side-effects, so we don't warn about it
(defun js2-add-strict-warning (msg-id &optional msg-arg beg end)
(if (and js2-compiler-strict-mode
(not (and (string= msg-id "msg.no.side.effects")
(string= (buffer-substring-no-properties beg (+ beg 7)) "expect("))))
(js2-report-warning msg-id msg-arg beg
(and beg end (- end beg)))))))
;; Add support for some mocha testing externs
(setq-default js2-additional-externs
(mapcar 'symbol-name
'(after afterEach before beforeEach describe it)))
;; Prevent JS2 from complaining about the following keywords
(setq-default js2-global-externs '("module" "require" "buster" "sinon" "assert" "refute" "setTimeout" "clearTimeout" "setInterval" "clearInterval" "location" "__dirname" "console" "JSON" "process" "exports" "context"))
;; END JS2 MODE
; enable tramp to open files using sudo on a remote machine by
; doing C-x C-f /sudo:root@host[#port]:/path/to/file
(set-default 'tramp-default-proxies-alist (quote ((".*" "\\`root\\'" "/ssh:%h:"))))
;; increase minibuffer size when ido completion is active
(add-hook 'ido-minibuffer-setup-hook
(function
(lambda ()
(make-local-variable 'resize-minibuffer-window-max-height)
(setq resize-minibuffer-window-max-height 1))))
;; Put autosave files (ie #foo#) in one place, *not*
;; scattered all over the file system!
(defvar autosave-dir "~/tmp/emacs_autosaves/")
(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) "#")))))
;; SLIME
(setq inferior-lisp-program (executable-find "sbcl"))
(setq slime-contribs '(slime-fancy slime-repl slime-js))
(autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
(defun xacohen-save-current-directory ()
"Save the current directory to the file ~/.emacs.d/acohen/current-directory"
(interactive)
(let ((dir default-directory))
(with-current-buffer (find-file-noselect "~/.emacs.d/acohen/current-directory")
(delete-region (point-min) (point-max))
(insert (concat dir "\n"))
(save-buffer)
(kill-buffer (current-buffer)))))
(global-set-key [(super f10)] 'xacohen-save-current-directory)
(defun clear-shell ()
(interactive)
(let ((comint-buffer-maximum-size 0))
(comint-truncate-buffer)))
;; reclaim some binding used by shell mode and shell-command.
;; the shell mode and associated mode and commands use keys in comint-mode-map.
(add-hook 'shell-mode-hook
(lambda ()
(define-key shell-mode-map (kbd "C-c C-f") 'find-file-at-point)
(define-key shell-mode-map [f1] 'clear-shell)
(setq global-hl-line-mode nil)
))
;; might be called sql-interactive-mode-hook
(add-hook 'sql-interactive-mode-hook
'(lambda ()
(define-key sql-interactive-mode-map [f1] 'clear-shell)
(define-key sql-interactive-mode-map (kbd "M-R") 'comint-history-isearch-backward-regexp)
(setq global-hl-line-mode nil)
))
;; remove P (ibuffer-do-print) in ibuffer mode, since it's
;; way too easy to print a shitload of buffers!
(add-hook 'ibuffer-mode-hook
(lambda ()
(define-key ibuffer-mode-map (kbd "P") 'ibuffer-backward-line)
))
;; Remove completion buffer when done
(add-hook 'minibuffer-exit-hook
'(lambda ()
(let ((buffer "*Completions*"))
(and (get-buffer buffer)
(kill-buffer buffer)))))
(defun wrap-html-tag (tagName)
"Add a tag to beginning and ending of current word or text selection."
(interactive "sEnter tag name: ")
(let (p1 p2 inputText)
(if (use-region-p)
(progn
(setq p1 (region-beginning) )
(setq p2 (region-end) )
)
(let ((bds (bounds-of-thing-at-point 'symbol)))
(setq p1 (car bds) )
(setq p2 (cdr bds) ) ) )
(goto-char p2)
(insert "</" tagName ">")
(goto-char p1)
(insert "<" tagName ">")
))
(defun my-tag-lines (b e tag)
"'tag' every line in the region with a tag"
(interactive "r\nMTag for line: ")
(save-restriction
(narrow-to-region b e)
(save-excursion
(goto-char (point-min))
(while (< (point) (point-max))
(beginning-of-line)
(insert (format "<%s>" tag))
(end-of-line)
(insert (format "</%s>" tag))
(forward-line 1)))))
;; Display ido results vertically, rather than horizontally
(setq ido-decorations (quote ("\n-> " "" "\n " "\n ..." "[" "]" " [No match]" " [Matched]" " [Not readable]" " [Too big]" " [Confirm]")))
(defun ido-disable-line-trucation () (set (make-local-variable 'truncate-lines) nil))
(add-hook 'ido-minibuffer-setup-hook 'ido-disable-line-trucation)
(defvar my-local-shells
'("*shell0*" "*shell1*" "*shell2*" "*shell3*"))
(defvar my-shells (append my-local-shells))
;; truncate buffers continuously
(add-hook 'comint-output-filter-functions 'comint-truncate-buffer)
(defun make-my-shell-output-read-only (text)
"Add to comint-output-filter-functions to make stdout read only in my shells."
(if (member (buffer-name) my-shells)
(let ((inhibit-read-only t)
(output-end (process-mark (get-buffer-process (current-buffer)))))
(put-text-property comint-last-output-start output-end 'read-only t))))
(add-hook 'comint-output-filter-functions 'make-my-shell-output-read-only)
(defun my-dirtrack-mode ()
"Add to shell-mode-hook to use dirtrack mode in my shell buffers."
(when (member (buffer-name) my-shells)
(shell-dirtrack-mode 0)
(set-variable 'dirtrack-list '("^.*[^ ]+:\\(.*\\)>" 1 nil))
(dirtrack-mode 1)))
(add-hook 'shell-mode-hook 'my-dirtrack-mode)
; interpret and use ansi color codes in shell output windows
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
(defun set-scroll-conservatively ()
"Add to shell-mode-hook to prevent jump-scrolling on newlines in shell buffers."
(set (make-local-variable 'scroll-conservatively) 10))
(add-hook 'shell-mode-hook 'set-scroll-conservatively)
(defun enter-again-if-enter ()
"Make the return key select the current item in minibuf and shell history isearch.
An alternate approach would be after-advice on isearch-other-meta-char."
(when (and (not isearch-mode-end-hook-quit)
(equal (this-command-keys-vector) [13])) ; == return
(cond ((active-minibuffer-window) (minibuffer-complete-and-exit))
((member (buffer-name) my-shells) (comint-send-input)))))
(add-hook 'isearch-mode-end-hook 'enter-again-if-enter)
(defadvice comint-previous-matching-input
(around suppress-history-item-messages activate)
"Suppress the annoying 'History item : NNN' messages from shell history isearch.
If this isn't enough, try the same thing with
comint-replace-by-expanded-history-before-point."
(let ((old-message (symbol-function 'message)))
(unwind-protect
(progn (fset 'message 'ignore) ad-do-it)
(fset 'message old-message))))
(defadvice comint-send-input (around go-to-end-of-multiline activate)
"When I press enter, jump to the end of the *buffer*, instead of the end of
the line, to capture multiline input. (This only has effect if
`comint-eol-on-send' is non-nil."
(cl-flet ((end-of-line () (end-of-buffer)))
ad-do-it))
(require 'dired-x)
(require 'wdired)
(setq wdired-allow-to-change-permissions 'advanced)
(define-key dired-mode-map (kbd "r") 'wdired-change-to-wdired-mode)
;;; to fix "void function inf-ruby-keys" error
(defalias 'inf-ruby-keys 'inf-ruby-setup-keybindings)
;; Projectile mode
(projectile-global-mode)
(add-hook 'projectile-mode-hook 'projectile-rails-on)
(setq projectile-enable-caching t)
;; Projectile mode
;;; load my custom yas snippets
;;(yas/load-directory (concat dotfiles-dir "snippets/"))