-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-main.el
374 lines (324 loc) · 11.7 KB
/
init-main.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
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
;;; init-main.el -*- lexical-binding: t -*-
(defmacro append-to-list (to lst &optional last)
`(set ,to ,(if last
`(append (symbol-value ,to) ,lst)
`(append ,lst (symbol-value ,to)))))
;;; 新規フレームのデフォルト設定
(when (boundp 'window-system)
(append-to-list 'default-frame-alist
'((width . 120) ; フレーム幅(文字数)
(height . 50)) ; フレーム高(文字数)
)
(if (eq window-system 'mac)
(append-to-list 'default-frame-alist
'((top . 0)
(left . 0))))
(if (eq window-system 'w32)
(setf (alist-get 'height default-frame-alist) 45)))
(defconst my/bootstrap-packages
(if (< emacs-major-version 29)
'(use-package diminish)
'(diminish)))
(defvar my/packages
`(company
auto-compile
editorconfig
ddskk
rg
wgrep
,(if (< emacs-major-version 26) 'nlinum)
yaml-mode
markdown-mode))
(append-to-list 'my/packages
(if (eq system-type 'windows-nt)
'(tr-ime)
`(flycheck
,(unless (display-graphic-p) 'flycheck-tip)
flycheck-pos-tip
magit
multi-term)))
(add-to-list 'my/packages
(cond
((eq window-system 'w32) 'twilight-theme)
(t 'solarized-theme))
t)
(require 'cl-lib)
(if (let ((cask-el "~/.cask/cask.el"))
(or (and (file-exists-p cask-el)
(require 'cask cask-el))
(require 'cask nil 'noerror)))
(progn
(cask-initialize)
(require 'pallet))
;; setup package.el
(when (require 'package nil 'noerror)
(setq package-user-dir "~/.emacs.d/elisp/elpa"
package-enable-at-startup nil
package--init-file-ensured t)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
(let ((packages (cl-remove-if #'package-installed-p
(append my/bootstrap-packages (delete 'nil my/packages)))))
(when packages
(package-refresh-contents)
(dolist (pkg packages)
(package-install pkg))))
;; リストをStatus降順でソートする
(defun my/package-menu-sort-status-desc ()
(setq tabulated-list-sort-key (cons "Status" t)))
(add-hook 'package-menu-mode-hook #'my/package-menu-sort-status-desc)))
(eval-when-compile
(require 'use-package))
(require 'bind-key)
(require 'diminish)
(let ((theme-dir (expand-file-name "~/.emacs.d/elisp/solarized-emacs/")))
(if (file-accessible-directory-p theme-dir)
(add-to-list 'custom-theme-load-path theme-dir)))
(or (ignore-errors (load-theme 'solarized-dark t)) ; 'solarized-theme'
(ignore-errors (load-theme 'twilight t))) ; 'twilight-theme'
(use-package my-nlinum
:if (and (fboundp 'nlinum-mode)
(< emacs-major-version 26))
:commands my/global-nlinum-mode
:custom (nlinum-format "%3d")
:hook (after-init . my/global-nlinum-mode))
(use-package display-line-numbers
:defer t
:if (>= emacs-major-version 26)
:hook (after-init . global-display-line-numbers-mode)
:init
(defun my/display-line-numbers--turn-on ()
"Turn on `display-line-numbers-mode'."
(unless (or (minibufferp)
(member major-mode '(shell-mode eshell-mode))
(let ((name (buffer-name)))
(or (string-match "*" name)
(string-match "vterm" name)))
(> (buffer-size) 3000000)
;; taken from linum.el
(and (daemonp) (null (frame-parameter nil 'client))))
(display-line-numbers-mode)))
:config
(fset 'display-line-numbers--turn-on 'my/display-line-numbers--turn-on))
;; company-mode
(use-package company
:defer t
:if (fboundp 'global-company-mode)
:bind (:map company-active-map
("[tab]" . 'company-complete-common-or-cycle))
:hook (after-init . global-company-mode)
:diminish company-mode
:config
(unless (eq system-type 'darwin)
(setopt company-backends (delete 'company-clang company-backends))))
;; flycheck
(use-package flycheck
:defer t
:if (fboundp 'global-flycheck-mode)
:functions (error-tip-delete-popup error-tip-popup-error-message)
:hook (after-init . global-flycheck-mode)
:bind (:map flycheck-mode-map
("C-c C-n" . flycheck-next-error)
("C-c C-p" . flycheck-previous-error))
:init
(unless (eq system-type 'darwin)
(setopt flycheck-disabled-checkers '(c/c++-clang)))
:config
(defun flycheck-cc-mode-checker-setup ()
(cond
((derived-mode-p 'c-mode 'c++-mode)
(cond
((executable-find "cppcheck")
(flycheck-select-checker 'c/c++-cppcheck))
;; (setq flycheck-clang-include-path
;; (list "/usr/local/Cellar/wxmac/3.0.2/lib/wx/include/osx_cocoa-unicode-3.0"
;; "/usr/local/Cellar/wxmac/3.0.2/include/wx-3.0"))
(t
nil)))
((derived-mode-p 'python-mode)
(flycheck-select-checker 'python-pylint))))
(add-hook 'flycheck-before-syntax-check-hook #'flycheck-cc-mode-checker-setup)
(flycheck-pos-tip-mode)
(when (and (not (display-graphic-p))
(require 'error-tip nil 'noerror))
(defun flycheck-pos-tip-tty-popup (errors)
(when errors
(error-tip-delete-popup)
(let ((msgs (mapcar #'flycheck-error-format-message-and-id errors)))
(error-tip-popup-error-message msgs))))
(setopt flycheck-pos-tip-display-errors-tty-function #'flycheck-pos-tip-tty-popup)))
(use-package typescript-mode
:defer t
:if (fboundp 'tide-setup)
:init
(add-hook 'typescript-mode-hook #'tide-setup)
(add-hook 'typescript-mode-hook #'eldoc-mode))
(use-package whitespace
:defer t
:diminish (whitespace-mode
global-whitespace-mode
whitespace-newline-mode)
:init
(add-hook 'after-init-hook #'global-whitespace-mode)
:config
(setq whitespace-style '(face ; faceで可視化
trailing ; 行末
tabs ; タブ
spaces ; スペース
empty ; 先頭/末尾の空行
space-mark ; 表示のマッピング
;;; tab-mark
))
(setq whitespace-display-mappings
'((space-mark ?\u3000 [?\u25a1])
;; WARNING: the mapping below has a problem.
;; When a TAB occupies exactly one column, it will display the
;; character ?\xBB at that column followed by a TAB which goes to
;; the next TAB column.
;; If this is a problem for you, please, comment the line below.
(tab-mark ?\t [?\u00BB ?\t] [?\\ ?\t])))
;; スペースは全角のみを可視化
(setq whitespace-space-regexp "\\(\u3000+\\)")
;; 保存前に自動でクリーンアップ
;;(setq whitespace-action '(auto-cleanup))
;;(setq whitespace-style '(trailing space-before-tab indentation empty space-after-tab)) ;; only show bad whitespace
(defvar my/bg-color "#232323")
(set-face-attribute 'whitespace-trailing nil
:background my/bg-color
:foreground "DeepPink"
:underline t)
(set-face-attribute 'whitespace-tab nil
:background my/bg-color
:foreground "LightSkyBlue"
:underline t)
(set-face-attribute 'whitespace-space nil
:background my/bg-color
:foreground "GreenYellow"
:weight 'bold)
(set-face-attribute 'whitespace-empty nil
:background my/bg-color))
;; git-commit-mode
(use-package git-commit
:defer t
:if (fboundp 'magit-version)
:commands global-git-commit-mode
:hook (after-init . global-git-commit-mode)
:config
(defun my/set-commit-log-encoding ()
(if (string-match-p "^undecided" (symbol-name buffer-file-coding-system))
(set-buffer-file-coding-system 'utf-8-unix)))
(add-hook 'git-commit-setup-hook #'my/set-commit-log-encoding))
(use-package magit-process
:if (fboundp 'magit-version)
:commands magit-process-file)
;; ag
(use-package ag
:defer t
:defines (ag-highlight-search ag-reuse-buffers)
:config
(setq ag-highlight-search t)
(setq ag-reuse-buffers t))
(defvar dropbox-path
(cond
((eq system-type 'windows-nt)
(let ((userfolder (concat (getenv "USERPROFILE") "/Dropbox"))
(json-path (concat (getenv "LOCALAPPDATA") "/Dropbox/info.json")))
(cond
((file-accessible-directory-p userfolder)
userfolder)
((file-exists-p json-path)
(require 'json)
(cdr (assoc 'path (assoc 'personal (json-read-file json-path)))))
(t nil))))
((eq system-type 'darwin)
(expand-file-name "~/Dropbox"))
(t nil)))
;; SKK
(use-package skk
:defer t
:init
(custom-set-variables '(skk-isearch-mode-enable t))
(bind-keys*
("C-x C-j" . skk-mode)
("C-x j" . skk-auto-fill-mode))
;;("C-x t" . skk-tutorial)
;; Macの場合はAquaSKK内蔵のskkservを使う
(when (eq window-system 'mac)
(setq skk-server-host "127.0.0.1")
(setq skk-server-portnum 1178))
(setq skk-jisyo-code 'utf-8-unix)
(if dropbox-path
(setq skk-jisyo (concat dropbox-path "/skk-jisyo.utf8")))
(unless (boundp 'skk-server-host)
(let* ((large-jisyo (expand-file-name "~/.emacs.d/etc/skk/SKK-JISYO.L"))
(cdb (concat large-jisyo ".cdb")))
(if (file-exists-p cdb)
(defvar skk-cdb-large-jisyo cdb)
(defvar skk-large-jisyo large-jisyo))))
:config
;; from skk-setup
;; Isearch setting.
(defun skk-isearch-setup-maybe ()
(when (or (eq skk-isearch-mode-enable 'always)
(and (boundp 'skk-mode)
skk-mode
skk-isearch-mode-enable))
(skk-isearch-mode-setup)))
(defun skk-isearch-cleanup-maybe ()
(when (and (featurep 'skk-isearch)
skk-isearch-mode-enable)
(skk-isearch-mode-cleanup)))
(add-hook 'isearch-mode-hook #'skk-isearch-setup-maybe)
(add-hook 'isearch-mode-end-hook #'skk-isearch-cleanup-maybe))
;; coffee-script mode
(use-package coffee-mode
:defer t
:config
(custom-set-variables '(coffee-tab-width 2)))
;; auto-compile-mode
(use-package auto-compile
:defer t
:if (fboundp 'auto-compile-on-save-mode)
:init
(add-hook 'after-init-hook #'auto-compile-on-save-mode))
(use-package editorconfig
:defer t
:if (fboundp 'editorconfig-mode)
:diminish editorconfig-mode
:init
(add-hook 'after-init-hook #'editorconfig-mode))
(use-package wgrep
:defer t
:config
(setq wgrep-auto-save-buffer t))
(setq backup-enable-predicate
(lambda (name)
(and (normal-backup-enable-predicate name)
(not
(let ((method (file-remote-p name 'method)))
(when (stringp method)
(member method '("su" "sudo"))))))))
(defun my/buffer-menu-adv (args)
(or (and (car args)
args)
'(1)))
(advice-add 'list-buffers :filter-args #'my/buffer-menu-adv)
(defun my/ignoring-dotfiles-f-n-completion (func &rest args)
(let ((x (apply func args)))
(if (and (listp x) (stringp (car x))
(cdr x))
(let ((result (cl-remove-if (lambda (f) (string-prefix-p "." f)) x)))
(if (and (listp result) (cdr result))
result
x))
x)))
(advice-add 'completion-file-name-table :around #'my/ignoring-dotfiles-f-n-completion)
(unless (daemonp)
(require 'server)
(unless (server-running-p)
(server-start)))
;;; Local Variables:
;;; coding: utf-8-unix
;;; mode: emacs-lisp
;;; End: