-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
227 lines (209 loc) · 8.42 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
;; trivial setting
(progn
(setq inhibit-startup-message t)
(setq inhibit-splash-screen t)
;; (tool-bar-mode 0)
(menu-bar-mode -1)
(progn
(setq visible-bell t)
(setq ring-bell-function 'ignore))
(progn
(setq scroll-conservatively 1);C-n C-p
(setq next-screen-context-lines 0);C-v M-v
)
(progn
(setq backup-inhibited t);do not create backup files
(setq delete-auto-save-files t);delete auto save files when emacs is closed
)
(progn
(show-paren-mode 1);hilight a set of ()
(setq show-paren-delay 0) ;the delay until a set of () is highlighted
)
(setq-default indent-tabs-mode nil);use space instead of tab
(setq-default transient-mark-mode t);hilight a selection
(setq-default show-trailing-whitespace t)
(global-auto-revert-mode 1) ;See http://maruta.be/emacs/12
(setq-default bidi-display-reordering nil
bidi-paragraph-direction (quote left-to-right))
(progn ;cua mode enable
(cua-mode t)
(setq cua-enable-cua-keys nil))
(load-theme 'wheatgrass)
)
;; about elisp
(progn
;; See http://d.hatena.ne.jp/m-hiyama/20081128/1227855376
(when (require 'package nil t)
(defvar package-archives)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/"))
(package-initialize) ;call this function before use elpa el such as tabbar
(defvar my/favorite-packages
'(
auto-async-byte-compile
auto-complete
helm
helm-descbinds
markdown-mode
multi-term
popup
popwin
tabbar
wgrep
yaml-mode
cmake-mode
flycheck-pyflakes
))
(let (f)
(dolist (package my/favorite-packages)
(unless (package-installed-p package)
(if (null f)
(progn
(package-refresh-contents)
(setq f t)))
(package-install package))))
)
(when (require 'tabbar nil t)
(tabbar-mode)
(setq tabbar-buffer-list-function
#'(lambda ()
(delq nil
(mapcar #'(lambda (b)
(cond
((eq (current-buffer) b) b)
((buffer-file-name b) b)
((char-equal ?\ (aref (buffer-name b) 0)) nil)
((equal "*scratch*" (buffer-name b)) b)
((string-match "*shell" (buffer-name b)) b)
((string-match "*terminal" (buffer-name b)) b)
((char-equal ?* (aref (buffer-name b) 0)) nil)
((buffer-live-p b) b)))
(buffer-list)))))
;; (global-set-key [(C M f)] 'tabbar-forward)
;; (global-set-key [(C M b)] 'tabbar-backward)
(global-set-key [(M right)] 'tabbar-forward)
(global-set-key [(M left)] 'tabbar-backward)
(tabbar-mwheel-mode nil)
(setq tabbar-buffer-groups-function nil)
(setq tabbar-separator '(1.5))
(dolist (btn '(tabbar-buffer-home-button tabbar-scroll-left-button tabbar-scroll-right-button))
(set btn (cons (cons "" nil)
(cons "" nil))))
)
;; helm
(when (require 'helm-descbinds nil t) (helm-descbinds-mode))
;; (when (require 'auto-complete nil t)
;; (global-auto-complete-mode t)
;; ;; (setq ac-modes (cons 'lisp-mode ac-modes))
;; )
;; Load the library and start it up
(if (getenv "ROS_DISTRO")
(progn
(add-to-list 'load-path (format "/opt/ros/%s/share/emacs/site-lisp" (getenv "ROS_DISTRO")))
(require 'rosemacs-config nil t)))
(when (require 'auto-async-byte-compile nil t)
;(setq auto-async-byte-compile-exclude-files-regexp "init.el")
(add-hook 'emacs-lisp-mode-hook 'enable-auto-async-byte-compile-mode))
(when (require 'uniquify nil t) (setq uniquify-buffer-name-style 'post-forward-angle-brackets))
(when (require 'multi-term nil t) (setq multi-term-program "/bin/bash"))
(when (require 'flycheck-pyflakes nil t)
(flycheck-add-next-checker 'python-pyflakes 'python-flake8)
(flycheck-add-next-checker 'python-pyflakes 'python-pycompile)
(add-hook 'python-mode-hook
#'(lambda ()
(flycheck-mode)
(add-to-list 'flycheck-disabled-checkers 'python-mypy)))
)
)
;; about mode
(progn
;; example : *hoge* +hoge+
(font-lock-add-keywords
'lisp-mode (list
(list "\\(\\*\\w\+\\*\\)\\>" '(1 font-lock-constant-face nil t))
(list "\\(\\+\\w\+\\+\\)\\>" '(1 font-lock-constant-face nil t))))
;; an AssociationList that associates MajorModes with a pattern to match a buffer filename when it is first opened
(add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.html\\'" . html-mode))
(add-to-list 'auto-mode-alist '("\\.ino" . c++-mode))
;; shell mode
(progn
(set-terminal-coding-system 'utf-8)
(set-buffer-file-coding-system 'utf-8)
(setq explicit-shell-file-name shell-file-name)
(setq shell-command-option "-c")
(setq system-uses-terminfo nil)
(setq shell-file-name-chars "~/A-Za-z0-9_^$!#%&{}@`'.,:()-")
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
(add-hook 'shell-mode-hook #'(lambda () (set-buffer-process-coding-system 'utf-8-unix 'utf-8-unix))))
(when (locate-library "vrml-mode")
(autoload 'vrml-mode "vrml-mode" nil t)
(add-to-list 'auto-mode-alist '("\\.wrl\\'" . vrml-mode))
)
;; (add-hook 'c-mode-common-hook
;; #'(lambda ()
;; (define-key c++-mode-map "/" 'self-insert-command)
;; (setq comment-style 'extra-line)
;; (setq comment-continue " * ")
;; (setq comment-start "/* ")
;; (setq comment-end " */")))
(add-hook 'c-mode-common-hook
#'(lambda ()
(c-set-style "cc-mode")
(c-set-offset 'statement-cont 'c-lineup-math)
(c-set-offset 'member-init-cont '/)
)
)
)
;;; Global Setting Key
;; See http://d.hatena.ne.jp/tomoya/20090415/1239809615
(progn
(global-set-key [(C h)] 'backward-delete-char)
(global-set-key [(M g)] 'goto-line)
(global-set-key [(C x) (C b)] 'bs-show)
;; Timestamp
;; See http://stackoverflow.com/questions/1250846/wrong-type-argument-commandp-error-when-binding-a-lambda-to-a-key
(global-set-key [(C c) (C d)] #'(lambda () (interactive) (insert (current-time-string))))
(global-set-key [(M p)] #'(lambda (n) (interactive "p") (forward-line (* -1 n)) (scroll-down n)))
(global-set-key [(M n)] #'(lambda (n) (interactive "p") (forward-line n) (scroll-up n)))
(global-set-key [(C q)] #'(lambda (n) (interactive "p") (cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1)) ((looking-at "\\s\)") (forward-char 1) (backward-list 1)))))
(global-set-key [(C x) (b)] 'helm-for-files)
;; (global-set-key [(C x) (C f)] 'helm-find-files)
(global-set-key [(M y)] 'helm-show-kill-ring)
(global-set-key [(C o)] 'dabbrev-expand)
)
;; fix emacs bag
(defadvice terminal-init-xterm (after fix-some-keys activate)
(define-key input-decode-map "\e[1;2A" [S-up])
(define-key input-decode-map "\e[4~" [end]))
;; for *scratch*
(progn
(defun my-make-scratch (&optional arg)
(interactive)
(progn
(set-buffer (get-buffer-create "*scratch*"))
(funcall initial-major-mode)
(erase-buffer)
(when (and initial-scratch-message (not inhibit-startup-message))
(insert initial-scratch-message))
(or arg (progn (setq arg 0)
(switch-to-buffer "*scratch*")))
(cond ((= arg 0) (message "*scratch* is cleared up."))
((= arg 1) (message "another *scratch* is created")))))
(add-hook 'kill-buffer-query-functions
#'(lambda ()
(if (string= "*scratch*" (buffer-name))
(progn (my-make-scratch 0) nil)
t)))
(add-hook 'after-save-hook
#'(lambda ()
(unless (member (get-buffer "*scratch*") (buffer-list))
(my-make-scratch 1))))
)
;; UTF-8 : put these lines at the end of init.el
(progn
(prefer-coding-system 'utf-8)
(set-file-name-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8))