-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.emacs
543 lines (474 loc) · 20.1 KB
/
.emacs
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
;; Add my emacs libs to load path
(setq load-path (cons (substitute-in-file-name "$HOME/dot/emacs") load-path))
(require 'palette)
(require 'doremi-frm)
;; default colors
;;(set-background-color "gray95")
;;(set-background-color "#fffce5") ;;light yellow
;;(set-background-color "#e5fcff") ;;light blue
;;(set-background-color "#CC6AEEEECC6A") ;;light green
(set-background-color "#404552C54045") ;;dark gray-green
;(set-foreground-color "gray20")
(set-foreground-color "snow")
(set-cursor-color "orange")
;(load-theme 'solarized-light-theme t)
;;codesearch
(require 'codesearch)
(setq codesearch-csearchindex (getenv "CSEARCHINDEX"))
;;cmake mode
(require 'cmake-mode)
;;markdown-mode (see https://jblevins.org/projects/markdown-mode/)
(require 'package)
(add-to-list 'package-archives
'("melpa-stable" . "https://stable.melpa.org/packages/"))
(package-initialize)
(autoload 'markdown-mode "markdown-mode"
"Major mode for editing Markdown files" t)
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
(autoload 'gfm-mode "markdown-mode"
"Major mode for editing GitHub Flavored Markdown files" t)
(add-to-list 'auto-mode-alist '("README\\.md\\'" . gfm-mode))
;; don't ignore (ViSUS) .idx files for completion
(setq completion-ignored-extensions (delete ".idx" completion-ignored-extensions))
;; MATLAB (OSX)
;; check OS type
(cond
((string-equal system-type "windows-nt") ; Microsoft Windows
(progn
(message "Microsoft Windows")))
((string-equal system-type "darwin") ; Mac OS X
(progn
(message "Mac OS X")
(setq load-path (cons (substitute-in-file-name "$HOME/dot/emacs/matlab") load-path))
(load-library "matlab-load")
(matlab-cedet-setup)
;;(setq matlab-shell-command-switches '("-nojvm"))
;;(setq matlab-shell-command-switches '("-nosplash"))
(global-set-key "\M-`" 'other-frame)
))
((string-equal system-type "gnu/linux") ; linux
(progn
(message "Linux"))))
;; fix drag-and-drop in osx
(define-key global-map [ns-drag-file] 'my-ns-open-files)
(defun my-ns-open-files ()
"Open files in the list `ns-input-file'."
(interactive)
(mapc 'find-file ns-input-file)
(setq ns-input-file nil))
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
(setq tab-stop-list (number-sequence 2 200 2))
(setq default-tab-width 2)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(c-offsets-alist
(quote
((arglist-intro . +)
(arglist-cont c-lineup-gcc-asm-reg 0))))
'(cc-search-directories
(quote
("." "/usr/include" "/usr/local/include/*" "../../src" "../include/*")))
'(compilation-skip-threshold 2)
'(css-indent-offset 2)
'(desktop-path (quote ("." "~/.emacs.d/" "~")))
'(desktop-restore-eager 7)
'(desktop-save-mode t)
'(display-time-mode t)
'(ediff-split-window-function (quote split-window-horizontally))
'(fill-column 80)
'(gud-gdb-command-name "gdb --annotate=1")
'(gud-tooltip-mode t)
'(icomplete-mode t)
'(indent-tabs-mode nil)
'(inhibit-startup-screen t)
'(initial-buffer-choice t)
'(initial-scratch-message nil)
'(js-indent-level 2)
'(large-file-warning-threshold nil)
'(line-move-visual nil)
'(list-command-history-max nil)
'(msb-mode t)
'(ns-alternate-modifier (quote alt))
'(ns-command-modifier (quote meta))
'(ns-right-alternate-modifier (quote super))
'(nxml-sexp-element-flag t)
'(package-selected-packages (quote (xref-js2 js2-refactor s markdown-mode)))
'(partial-completion-mode nil)
'(safe-local-variable-values
(quote
((TeX-master . "proposal")
(TeX-master . "paper")
(TeX-master . "dynamic_remote_analysis"))))
'(savehist-mode t nil (savehist))
'(scroll-down-aggressively 0.1)
'(scroll-up-aggressively 0.1)
'(set-mark-command-repeat-pop t)
'(show-paren-mode t)
'(standard-indent 2)
'(tab-always-indent (quote complete))
'(tab-width 2)
'(tool-bar-mode nil)
'(tramp-auto-save-directory "~/.emacs.d/autosave")
'(x-alt-keysym (quote ctrl) t)
'(x-ctrl-keysym (quote alt))
'(x-hyper-keysym (quote meta) t)
'(x-meta-keysym (quote ctrl) t)
'(x-super-keysym (quote meta) t))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(font-lock-builtin-face ((t (:background "purple" :foreground "white" :weight bold))))
'(font-lock-comment-delimiter-face ((t (:inherit font-lock-comment-face :weight bold))))
'(font-lock-comment-face ((t (:foreground "light cyan"))))
'(font-lock-constant-face ((t (:foreground "cyan1" :weight bold))))
'(font-lock-function-name-face ((t (:foreground "green" :weight bold))))
'(font-lock-preprocessor-face ((t (:inherit font-lock-builtin-face :foreground "white"))))
'(font-lock-string-face ((t (:foreground "light goldenrod"))))
'(font-lock-variable-name-face ((t (:foreground "yellow"))))
'(rst-level-1 ((t nil))))
(put 'scroll-left 'disabled nil)
;;; Insert current date (from http://www.emacswiki.org/emacs/InsertDate)
(defun insert-date (prefix)
"Insert the current date. With prefix-argument, use ISO format. With
two prefix arguments, write out the day and month name."
(interactive "P")
(let ((format (cond
((not prefix) "%Y.%m.%d.%H%M")
((equal prefix '(4)) "%d.%m.%Y")
((equal prefix '(16)) "%A, %B %d, %Y"))))
(insert (format-time-string format))))
(defun insert-standard-date ()
"Inserts standard date time string."
(interactive)
(insert (format-time-string "%c")))
;;; Revert the current buffer without asking first.
(defun fast-revert-buffer ()
"Revert the buffer from the original file without asking."
(interactive)
(revert-buffer t t))
;;; increase/decrease text scale in all buffers
;; (defadvice text-scale-increase (around all-buffers (arg) activate)
;; (dolist (buffer (buffer-list))
;; (with-current-buffer buffer
;; ad-do-it)))
;;; Assign shortcuts
(global-set-key (kbd "C-}") '(lambda() (interactive) (text-scale-increase 1)))
(global-set-key (kbd "C-{") '(lambda() (interactive) (text-scale-increase -1)))
(global-set-key "\C-ce" 'ediff-buffers)
(global-set-key (kbd "C-c l") 'insert-date)
(global-set-key (kbd "C-S-p") '(lambda() (interactive) (scroll-down 1)))
(global-set-key (kbd "C-S-n") '(lambda() (interactive) (scroll-up 1)))
(global-set-key "\C-x\C-b" 'electric-buffer-list)
(global-set-key "\C-cr" 'fast-revert-buffer)
(global-set-key "\C-ct" 'toggle-truncate-lines)
(global-set-key "\C-cd" 'hide-subtree)
(global-set-key "\C-cs" 'show-subtree)
(global-set-key "\C-x\M-\." 'tags-search)
(global-set-key "\C-x\M-\," 'tags-loop-continue)
(global-set-key "\C-x\M->" 'tags-query-replace)
(global-set-key "\C-c\M-q" 'align-regexp)
(global-set-key "\C-c\C-v" 'codesearch-search-at-point)
(global-set-key "\C-c\C-f" 'codesearch-search)
(global-set-key "\C-c\C-c" 'comment-region)
(global-set-key "\C-c\C-k" 'compile)
(global-set-key (kbd "C-;") 'indent-relative)
(c-add-style "VisIt" '("gnu"
(c-basic-offset . 4)
(c-offsets-alist . ((innamespace . 0)
(substatement-open 0)
(brace-list-open 0)
(access-label . -)
(case-label . 0)
(member-init-intro . +)
(topmost-intro . 0)))))
(c-add-style "ir-tools" '("gnu"
(c-basic-offset . 4)
(c-offsets-alist . ((innamespace . 0)
(substatement-open 0)
(brace-list-open 0)
(access-label . -)
(case-label . 0)
(member-init-intro . +)
(topmost-intro . 0)))))
(c-add-style "ViSUS" '("gnu"
(c-basic-offset . 2)
(tab-width . 2)
(c-require-final-newline . 'nil)
(fill-column . 95)
(c-offsets-alist . ((innamespace . 0)
(substatement-open 0)
(statement-cont 0)
(brace-list-open 0)
(access-label . -)
(case-label . 0)
(member-init-intro . +)
(case-label . +)
(statement-case-open . 0)
(inextern-lang . 0)
(topmost-intro . 0)))))
(c-add-style "SCHOOL" '("ViSUS"
(c-basic-offset . 2)))
(c-add-style "PIDX" '("ViSUS"
(c-basic-offset . 2)))
(c-add-style "UINTAH" '("ViSUS"
(c-basic-offset . 2)))
;; pick default style based on environment var 'MYPROJECT'
(setq CurrentProject (getenv "MYPROJECT"))
(setq my-c-style "ViSUS")
;;TODO: use (cond instead
(if (equal CurrentProject "VISUS")
(setq my-c-style "ViSUS")
(if (equal CurrentProject "VISIT")
(setq my-c-style "VisIt")
(if (equal CurrentProject "PIDX")
(setq my-c-style "PIDX")
(if (equal CurrentProject "UINTAH")
(setq my-c-style "UINTAH")
(if (equal CurrentProject "SCHOOL")
(setq my-c-style "SCHOOL")
(if (equal CurrentProject "RT")
(setq my-c-style "SCHOOL")
(if (equal CurrentProject "HWRT")
(setq my-c-style "SCHOOL")
(if (equal CurrentProject "IRTOOLS")
(setq my-c-style "ir-tools")
(setq my-c-style "ViSUS")))))))))
;;
;;C++ mode
;;
(add-to-list 'auto-mode-alist '("\\.h$" . c++-mode))
(add-to-list 'auto-mode-alist '("\\.hxx" . c++-mode))
(add-to-list 'auto-mode-alist '("\\.cxx" . c++-mode))
(add-to-list 'auto-mode-alist '("\\.cu" . c++-mode))
(add-to-list 'auto-mode-alist '("\\.vert" . c++-mode))
(add-to-list 'auto-mode-alist '("\\.frag" . c++-mode))
;;C++ mode hooks
;; <ctc> still need:
;; X no indent after namespace and in switch/case
;; X drag and drop should open new file, not copy contents of file into current buffer
;; o y_or_n instead of requiring yes_or_no
;; X a way to set c-basic-offset to 4 for some projects (VisIt)
;;
;;; Save c-basic-offset and c-offsets-alist in .emacs.desktop
(add-to-list 'desktop-globals-to-save 'c-basic-offset)
(add-to-list 'desktop-globals-to-save 'c-offsets-alist)
;; Discovered macros to use with:
;; (read-kbd-macro "C-c <left>")
;; You can use view-lossage to see what to put in the quotes.
(defun hs-mode-set-keys ()
(progn
(message "running hs-mode-set-keys hook...")
(local-set-key [3 right] 'hs-show-block)
(local-set-key [3 left] 'hs-hide-block)
(local-set-key [3 up] 'hs-hide-level)
(local-set-key [3 down] 'hs-show-all)
))
(add-hook 'hs-minor-mode-hook 'hs-mode-set-keys)
(add-hook 'c-mode-common-hook 'hs-minor-mode)
;;(add-hook 'c-mode-common-hook 'outline-minor-mode)
;;Find other file
(defun ff-find-other-file-set-keys()
(progn
(message "running ff-find-other-file-set-keys hook...")
(local-set-key (kbd "C-c a") 'ff-find-other-file)))
(add-hook 'c-mode-common-hook 'ff-find-other-file-set-keys)
(add-hook 'c-mode-common-hook (lambda() (local-set-key "\M-j" 'indent-for-comment)))
;; Customizations for all modes in CC Mode.
(defun my-c-mode-common-hook ()
;; set my personal style for the current buffer
(message "running my-c-mode-common-hook...")
(c-set-style my-c-style))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
;; Python Hook
(add-hook 'python-mode-hook
'my-python-customizations)
(defun my-python-customizations ()
"set up my personal customizations for python mode"
(message "setting my python customizations...")
(setq python-indent 4)
(local-unset-key (kbd "C-c C-c"))
(local-set-key "\C-c\C-c" 'comment-region)
(setq tab-width 4)
(setq indent-tabs-mode 1))
;; Latex Hook
(add-hook 'latex-mode-hook
'my-latex-customizations)
(defun my-latex-customizations ()
"set up my personal customizations for latex mode"
(local-unset-key (kbd "C-c C-c"))
(local-set-key "\C-c\C-c" 'comment-region))
;; Xml Hook
;; ...
;; xml mode sucks, nxml mode is much better
(add-to-list 'auto-mode-alist '("\\.xml\\'" . nxml-mode))
(add-to-list 'auto-mode-alist '("\\.svgz?\\'" . nxml-mode))
(add-to-list 'auto-mode-alist '("\\.config" . nxml-mode))
(add-to-list 'auto-mode-alist '("\\.[mg]idx\\'" . nxml-mode))
;;Shell scripts
(defun cam-setup-sh-mode ()
"My own personal preferences for `sh-mode'.
This is a custom function that sets up the parameters I usually
prefer for `sh-mode'. It is automatically added to
`sh-mode-hook', but is can also be called interactively."
(interactive)
(setq sh-basic-offset 2
sh-indentation 2
sh-indent-after-function 2))
(add-hook 'sh-mode-hook 'cam-setup-sh-mode)
;; vc-ediff
(require 'vc-ediff)
(defun my-vc-dir-hide-up-to-date ()
(interactive)
(vc-dir-hide-up-to-date)
(vc-dir-hide-unregistered))
(defun vc-dir-hide-unregistered ()
"Hide unregistered items from display."
(interactive)
(let ((crt (ewoc-nth vc-ewoc -1))
(first (ewoc-nth vc-ewoc 0)))
;; Go over from the last item to the first and remove the
;; unregistered files and directories with no child files.
(while (not (eq crt first))
(let* ((data (ewoc-data crt))
(dir (vc-dir-fileinfo->directory data))
(next (ewoc-next vc-ewoc crt))
(prev (ewoc-prev vc-ewoc crt))
;; ewoc-delete does not work without this...
(inhibit-read-only t))
(when (or
;; Remove directories with no child files.
(and dir
(or
;; Nothing follows this directory.
(not next)
;; Next item is a directory.
(vc-dir-fileinfo->directory (ewoc-data next))))
;; Remove files in the unregistered state.
(eq (vc-dir-fileinfo->state data) 'unregistered))
(ewoc-delete vc-ewoc crt))
(setq crt prev)))))
(defun my-ediff-revision (file rev1 &optional rev2)
"Run Ediff by comparing 'master' against the 'current'."
(find-file file)
(if (and (buffer-modified-p)
(y-or-n-p (format "Buffer %s is modified. Save buffer? "
(buffer-name))))
(save-buffer (current-buffer)))
(ediff-load-version-control)
(ediff-vc-internal rev1 rev2 nil))
(defun my-vc-diff (&optional arg)
(interactive "P")
(call-interactively
(cond (arg (lambda nil (interactive) (vc-diff nil)))
(t (lambda nil (interactive)
(my-ediff-revision (buffer-file-name)
(read-string "revision? " "HEAD" nil "HEAD")
""))))))
(add-hook 'vc-dir-mode-hook
(lambda nil
(define-key vc-dir-mode-map "x" 'my-vc-dir-hide-up-to-date)
(define-key vc-dir-mode-map "E" 'my-vc-diff)))
;;; Remove ^Ms from the entire buffer.
(defun strip-control-ms ()
"Delete all ^Ms."
(interactive)
(save-excursion
(beginning-of-buffer)
(while (and (not (eobp))
(re-search-forward "\C-m" nil t))
(delete-region (match-beginning 0) (match-end 0)))))
;;ctc - get machine name, 11 for desktop, 10 for laptop
(when (or (string-prefix-p "jupiter" (system-name)) (string-prefix-p "mercury" (system-name)))
(set-face-attribute 'default nil :font "-apple-Monaco-medium-normal-normal-*-11-*-*-*-m-0-iso10646-1")
(if (string= (system-name) "mercury.local")
(set-face-attribute 'default nil :font "-apple-Monaco-medium-normal-normal-*-12-*-*-*-m-0-iso10646-1")
(if (string= (system-name) "atlanta.sci.utah.edu")
(message "can't set system font")
;(set-face-attribute 'default nil :font "-unknown-DejaVu Sans Mono-normal-normal-normal-*-12-*-*-*-m-0-fontset-auto2")
(set-face-attribute 'default nil :font "-apple-Monaco-medium-normal-normal-*-14-*-*-*-m-0-iso10646-1"))))
(when (string-prefix-p "gunship" (system-name))
(message "configuring for gunship (swapping meta and alt keys)...")
;; with TweakUI Ctrl key "swap left alt with left ctrl" on SUSE, this has changed (first set of swaps takes care of it)
;; I GIVE UP: can't remap ctrl on linux (though you can on OSX), so I'm just undoing swap-alt-ctrl setting
(if 0
(custom-set-variables
'(x-ctrl-keysym (quote alt))
'(x-alt-keysym (quote ctrl))
'(x-super-keysym (quote meta))
'(x-meta-keysym (quote ctrl) t)
'(x-hyper-keysym (quote meta) t)
)
(custom-set-variables
'(x-meta-keysym (quote alt))
'(x-super-keysym (quote meta))
))
;;for mercury: mac-control-modifier
;;example here: http://ergoemacs.org/emacs/emacs_hyper_super_keys.html
)
(put 'upcase-region 'disabled nil)
(defun find-duplicate-lines (&optional insertp interp)
(interactive "i\np")
(let ((max-pon (line-number-at-pos (point-max)))
(gather-dups))
(while (< (line-number-at-pos) max-pon) (= (forward-line) 0)
(let ((this-line (buffer-substring-no-properties (line-beginning-position 1) (line-end-position 1)))
(next-line (buffer-substring-no-properties (line-beginning-position 2) (line-end-position 2))))
(when (equal this-line next-line) (setq gather-dups (cons this-line gather-dups)))))
(if (or insertp interp)
(save-excursion (newline) (princ gather-dups (current-buffer)))
gather-dups)))
;;dired
(defun file-info ()
(interactive)
(let ((dired-listing-switches "-alh"))
(dired-other-window buffer-file-name)))
(global-set-key (kbd "C-c i") 'file-info)
(add-hook 'dired-mode-hook
(lambda nil
(define-key dired-do-query-replace-regexp "Q" 'dired-do-query-replace-regexp)))
(require 'package)
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
(not (gnutls-available-p))))
(url (concat (if no-ssl "http" "https") "://melpa.org/packages/")))
(add-to-list 'package-archives (cons "melpa" url) t))
(when (< emacs-major-version 24)
;; For important compatibility libraries like cl-lib
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/")))
(package-initialize)
; insert date and a line underneath (since I do it all the time)
; TODO: get the text of the C-c l command, add the line to it, and insert as a single action. That way, undo will remove all of it
(fset 'dateline
[?\C-u ?\C-u ?\C-c ?l return ?\M-2 ?\M-9 ?- return])
(global-set-key (kbd "C-c k") 'dateline)
; s.el (required by dockerfile-mode)
(add-to-list 'load-path "~/emacs/s.el")
; dockerfile mode
(add-to-list 'load-path "~/emacs/dockerfile-mode/")
(require 'dockerfile-mode)
(add-to-list 'auto-mode-alist '("Dockerfile\\'" . dockerfile-mode))
; --- javascript --- (see https://emacs.cafe/emacs/javascript/setup/2017/04/23/emacs-setup-javascript.html)
; (need to install js2-mode, js2-refactor, xref-js2 using M-x package-install RET <name>)
; also: conda install -c anaconda the-silver-searcher
(require 'js2-mode)
(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
;; Better imenu
(add-hook 'js2-mode-hook #'js2-imenu-extras-mode)
;; js "tags"
(require 'js2-refactor)
(require 'xref-js2)
(add-hook 'js2-mode-hook #'js2-refactor-mode)
(js2r-add-keybindings-with-prefix "C-c C-r")
(define-key js2-mode-map (kbd "C-k") #'js2r-kill)
;; js-mode (which js2 is based on) binds "M-." which conflicts with xref, so
;; unbind it.
(define-key js-mode-map (kbd "M-.") nil)
(add-hook 'js2-mode-hook
(lambda ()
(add-hook 'xref-backend-functions #'xref-js2-xref-backend nil t)))
; --- /javascript ---