You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

3032 lines
100 KiB

  1. ;;; emacs.el --- 10sr emacs initialization
  2. ;;; Code:
  3. ;; SETUP_LOAD: (load "bytecomp") ;; Required for WSL environment
  4. ;; SETUP_LOAD: (let ((file "DOTFILES_DIR/emacs.el"))
  5. ;; SETUP_LOAD: (and (file-readable-p file)
  6. ;; SETUP_LOAD: (byte-recompile-file file nil 0 t)))
  7. ;; TODO: Use custom-set-variables in place of set-variable
  8. (setq debug-on-error t)
  9. ;; make directories
  10. (unless (file-directory-p (expand-file-name user-emacs-directory))
  11. (make-directory (expand-file-name user-emacs-directory)))
  12. (require 'cl-lib)
  13. (require 'simple)
  14. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15. ;; Some macros for internals
  16. (defvar after-first-visit-hook nil
  17. "Run only once at the first visit of file.")
  18. (defvar after-first-visit-hook--done nil
  19. "Non-nil when `after-first-visit-hook' has already been called.")
  20. (defun after-first-visit-hook-run ()
  21. "Run `after-first-visit-hook' and clear its config."
  22. (when (not after-first-visit-hook--done)
  23. (run-hooks 'after-first-visit-hook))
  24. (setq after-first-visit-hook--done t)
  25. (remove-hook 'find-file-hook
  26. 'after-first-visit-hook-run))
  27. (add-hook 'find-file-hook
  28. 'after-first-visit-hook-run)
  29. (defmacro eval-after-init (&rest body)
  30. "If `after-init-hook' has been run, run BODY immediately.
  31. Otherwize hook it."
  32. (declare (indent 0) (debug t))
  33. `(if after-init-time
  34. ;; Currently after-init-hook is run just after setting after-init-hook
  35. (progn
  36. ,@body)
  37. (add-hook 'after-init-hook
  38. (lambda ()
  39. ,@body))))
  40. ;; (defmacro safe-require-or-eval (feature)
  41. ;; "Require FEATURE if available.
  42. ;; At compile time the feature will be loaded immediately."
  43. ;; `(eval-and-compile
  44. ;; (message "safe-require-or-eval: Trying to require %s" ,feature)
  45. ;; (require ,feature nil t)))
  46. ;; (defmacro autoload-eval-lazily (feature &optional functions &rest body)
  47. ;; "Define autoloading FEATURE that defines FUNCTIONS.
  48. ;; FEATURE is a symbol. FUNCTIONS is a list of symbols. If FUNCTIONS is nil,
  49. ;; the function same as FEATURE is defined as autoloaded function. BODY is passed
  50. ;; to `eval-after-load'.
  51. ;; After this macro is expanded, this returns the path to library if FEATURE
  52. ;; found, otherwise returns nil."
  53. ;; (declare (indent 2) (debug t))
  54. ;; (let* ((libname (symbol-name (eval feature)))
  55. ;; (libpath (locate-library libname)))
  56. ;; `(progn
  57. ;; (when (locate-library ,libname)
  58. ;; ,@(mapcar (lambda (f)
  59. ;; `(unless (fboundp ',f)
  60. ;; (progn
  61. ;; (message "Autoloaded function `%S' defined (%s)"
  62. ;; (quote ,f)
  63. ;; ,libpath)
  64. ;; (autoload (quote ,f)
  65. ;; ,libname
  66. ;; ,(concat "Autoloaded function defined in \""
  67. ;; libpath
  68. ;; "\".")
  69. ;; t))))
  70. ;; (or (eval functions)
  71. ;; `(,(eval feature)))))
  72. ;; (eval-after-load ,feature
  73. ;; (quote (progn
  74. ;; ,@body)))
  75. ;; (locate-library ,libname))))
  76. ;; (when (autoload-eval-lazily 'tetris nil
  77. ;; (message "Tetris loaded!"))
  78. ;; (message "Tetris found!"))
  79. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  80. ;; package
  81. (set (defvar 10sr-package-list)
  82. '(
  83. vimrc-mode
  84. markdown-mode
  85. yaml-mode
  86. gnuplot-mode
  87. php-mode
  88. erlang
  89. js2-mode
  90. js-doc
  91. git-commit
  92. gitignore-mode
  93. adoc-mode
  94. go-mode
  95. ;; It seems malabar has been merged into jdee and this package
  96. ;; already removed
  97. ;; malabar-mode
  98. gosh-mode
  99. scala-mode
  100. web-mode
  101. toml-mode
  102. json-mode
  103. color-moccur
  104. ggtags
  105. flycheck
  106. auto-highlight-symbol
  107. hl-todo
  108. ;; Currently not available
  109. ;; pp-c-l
  110. xclip
  111. foreign-regexp
  112. multi-term
  113. term-run
  114. editorconfig
  115. git-ps1-mode
  116. restart-emacs
  117. fill-column-indicator
  118. pkgbuild-mode
  119. minibuffer-line
  120. which-key
  121. ;; I think this works in place of my autosave lib
  122. super-save
  123. pipenv
  124. imenu-list
  125. page-break-lines
  126. ;; aggressive-indent
  127. dired-filter
  128. wgrep
  129. magit
  130. git-gutter
  131. end-mark
  132. sl
  133. ;; TODO: Configure pony-tpl-mode
  134. pony-mode
  135. gited
  136. highlight-indentation
  137. diminish
  138. fzf
  139. fic-mode
  140. term-cursor
  141. pydoc
  142. color-identifiers-mode
  143. dired-k
  144. blacken
  145. back-button
  146. with-venv
  147. nyan-mode
  148. diredfl
  149. editorconfig
  150. editorconfig-custom-majormode
  151. git-command
  152. prompt-text
  153. ;; 10sr repository
  154. ;; 10sr-extras
  155. terminal-title
  156. dired-list-all-mode
  157. pack
  158. set-modeline-color
  159. read-only-only-mode
  160. smart-revert
  161. autosave
  162. ;;window-organizer
  163. ilookup
  164. pasteboard
  165. awk-preview
  166. recently
  167. ))
  168. (require 'package)
  169. (set-variable 'package-archives
  170. `(,@package-archives
  171. ("melpa" . "https://melpa.org/packages/")
  172. ;; Somehow fails to download via https
  173. ("10sr-el" . "http://10sr.github.io/emacs-lisp/elpa/")))
  174. (package-initialize)
  175. (defun my-auto-install-package ()
  176. "Install packages semi-automatically."
  177. (interactive)
  178. (package-refresh-contents)
  179. (mapc (lambda (pkg)
  180. (or (package-installed-p pkg)
  181. (package-install pkg)))
  182. 10sr-package-list))
  183. ;; (lazy-load-eval 'sudoku)
  184. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  185. ;; my-idle-hook
  186. (defvar my-idle-hook nil
  187. "Hook run when idle for several secs.")
  188. (defvar my-idle-hook-sec 5
  189. "Second to run `my-idle-hook'.")
  190. (run-with-idle-timer my-idle-hook-sec
  191. t
  192. (lambda ()
  193. (run-hooks 'my-idle-hook)))
  194. ;; (add-hook 'my-idle-hook
  195. ;; (lambda ()
  196. ;; (message "idle hook message")))
  197. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  198. ;; start and quit
  199. (setq inhibit-startup-message t)
  200. (setq initial-buffer-choice 'messages-buffer)
  201. (setq confirm-kill-emacs 'y-or-n-p)
  202. (setq gc-cons-threshold (* 1024 1024 16))
  203. (setq garbage-collection-messages nil)
  204. (when window-system
  205. (add-to-list 'default-frame-alist '(cursor-type . box))
  206. (add-to-list 'default-frame-alist '(background-color . "white"))
  207. (add-to-list 'default-frame-alist '(foreground-color . "gray10"))
  208. ;; (add-to-list 'default-frame-alist '(alpha . (80 100 100 100)))
  209. ;; does not work?
  210. )
  211. ;; (add-to-list 'default-frame-alist '(cursor-type . box))
  212. (menu-bar-mode 1)
  213. (define-key ctl-x-map "M" 'menu-bar-open)
  214. (defalias 'menu 'menu-bar-open)
  215. (and (fboundp 'tool-bar-mode)
  216. (tool-bar-mode 0))
  217. (and (fboundp 'set-scroll-bar-mode)
  218. (set-scroll-bar-mode nil))
  219. (eval-after-init
  220. (message "%s %s" invocation-name emacs-version)
  221. (message "Invocation directory: %s" default-directory)
  222. (message "%s was taken to initialize emacs." (emacs-init-time))
  223. ;; (view-echo-area-messages)
  224. ;; (view-emacs-news)
  225. )
  226. (with-current-buffer "*Messages*"
  227. (emacs-lock-mode 'kill))
  228. (cd ".") ; when using windows use / instead of \ in `default-directory'
  229. ;; locale
  230. (set-language-environment "Japanese")
  231. (set-default-coding-systems 'utf-8-unix)
  232. (prefer-coding-system 'utf-8-unix)
  233. (setq system-time-locale "C")
  234. ;; my prefix map
  235. (defvar my-prefix-map nil
  236. "My prefix map.")
  237. (define-prefix-command 'my-prefix-map)
  238. (global-set-key (kbd "C-^") 'my-prefix-map)
  239. ;; (define-key my-prefix-map (kbd "C-q") 'quoted-insert)
  240. ;; (define-key my-prefix-map (kbd "C-z") 'suspend-frame)
  241. ;; (comint-show-maximum-output)
  242. ;; kill scratch
  243. (eval-after-init
  244. (let ((buf (get-buffer "*scratch*")))
  245. (when buf
  246. (kill-buffer buf))))
  247. ;; modifier keys
  248. ;; (setq mac-option-modifier 'control)
  249. ;; display
  250. (setq visible-bell t)
  251. (setq ring-bell-function 'ignore)
  252. (mouse-avoidance-mode 'banish)
  253. (setq echo-keystrokes 0.1)
  254. (defun reload-init-file ()
  255. "Reload Emacs init file."
  256. (interactive)
  257. (when (and user-init-file
  258. (file-readable-p user-init-file))
  259. (load-file user-init-file)))
  260. (require 'session nil t)
  261. ;; server
  262. (set-variable 'server-name (concat "server"
  263. (number-to-string (emacs-pid))))
  264. ;; In Cygwin Environment `server-runnning-p' stops when server-use-tcp is nil
  265. ;; In Darwin environment, init fails with message like 'Service name too long'
  266. ;; when server-use-tcp is nil
  267. (when (or (eq system-type
  268. 'cygwin)
  269. (eq system-type
  270. 'darwin))
  271. (set-variable 'server-use-tcp t))
  272. ;; MSYS2 fix
  273. (when (eq system-type
  274. 'windows-nt)
  275. (setq shell-file-name
  276. (executable-find "bash"))
  277. '(setq function-key-map
  278. `(,@function-key-map ([pause] . [?\C-c])
  279. ))
  280. (define-key key-translation-map
  281. (kbd "<pause>")
  282. (kbd "C-c"))
  283. '(keyboard-translate [pause]
  284. (kbd "C-c")p)
  285. ;; TODO: move to other place later
  286. (when (not window-system)
  287. (setq interprogram-paste-function nil)
  288. (setq interprogram-cut-function nil)))
  289. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  290. ;; global keys
  291. (global-set-key (kbd "<up>") 'scroll-down-line)
  292. (global-set-key (kbd "<down>") 'scroll-up-line)
  293. (global-set-key (kbd "<left>") 'scroll-down)
  294. (global-set-key (kbd "<right>") 'scroll-up)
  295. ;; (define-key my-prefix-map (kbd "C-h") help-map)
  296. ;; (global-set-key (kbd "C-\\") help-map)
  297. (define-key ctl-x-map (kbd "DEL") help-map)
  298. (define-key ctl-x-map (kbd "C-h") help-map)
  299. ;; This is often fired mistakenly
  300. (define-key ctl-x-map "h" 'ignore) ;; Previously mark-whole-buffer
  301. (define-key help-map "a" 'apropos)
  302. ;; disable annoying keys
  303. (global-set-key [prior] 'ignore)
  304. (global-set-key (kbd "<next>") 'ignore)
  305. (global-set-key [menu] 'ignore)
  306. (global-set-key [down-mouse-1] 'ignore)
  307. (global-set-key [down-mouse-2] 'ignore)
  308. (global-set-key [down-mouse-3] 'ignore)
  309. (global-set-key [mouse-1] 'ignore)
  310. (global-set-key [mouse-2] 'ignore)
  311. (global-set-key [mouse-3] 'ignore)
  312. (global-set-key (kbd "<eisu-toggle>") 'ignore)
  313. (global-set-key (kbd "C-<eisu-toggle>") 'ignore)
  314. ;; Interactively evaluate Emacs Lisp expressions
  315. (define-key ctl-x-map "i" 'ielm)
  316. (when (fboundp 'which-key-mode)
  317. (which-key-mode))
  318. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  319. ;; editor
  320. ;; Basically it should not set globally (instead use something like file local
  321. ;; variables or editorconfig), but for most cases I just need this...
  322. (defun my-set-require-final-newline ()
  323. "Set `require-final-newline'."
  324. (set (make-local-variable 'require-final-newline)
  325. mode-require-final-newline))
  326. (add-hook 'prog-mode-hook
  327. 'my-set-require-final-newline)
  328. (add-hook 'text-mode-hook
  329. 'my-set-require-final-newline)
  330. (add-hook 'conf-mode-hook
  331. 'my-set-require-final-newline)
  332. ;; Used from term-cursor
  333. ;; hbar is too hard to find...
  334. (defun my-cursor-type-change (&rest args)
  335. "ARGS are discarded."
  336. ;; TODO: Support wdired and wgrep
  337. (if buffer-read-only
  338. (setq cursor-type 'hbar)
  339. (setq cursor-type 'box)))
  340. ;; (add-hook 'switch-buffer-functions
  341. ;; 'my-cursor-type-change)
  342. ;; (add-hook 'read-only-mode-hook
  343. ;; 'my-cursor-type-change)
  344. ;; (when (fboundp 'global-term-cursor-mode)
  345. ;; (global-term-cursor-mode 1))
  346. ;; ;; (term-cursor--eval)
  347. (setq kill-whole-line t)
  348. (setq scroll-conservatively 35
  349. scroll-margin 2)
  350. (setq-default major-mode 'text-mode)
  351. (setq next-line-add-newlines nil)
  352. (setq kill-read-only-ok t)
  353. (setq truncate-partial-width-windows nil) ; when splitted horizontally
  354. ;; (setq-default line-spacing 0.2)
  355. (setq-default indicate-empty-lines t) ; when using x indicate empty line
  356. ;; (setq-default tab-width 4)
  357. (setq-default indent-tabs-mode nil)
  358. (setq-default indent-line-function 'indent-to-left-margin)
  359. ;; (setq-default indent-line-function nil)
  360. (setq-default truncate-lines nil)
  361. ;; (pc-selection-mode 1) ; make some already defined keybind back to default
  362. (delete-selection-mode 1)
  363. (cua-mode 0)
  364. (setq line-move-visual nil)
  365. (setq create-lockfiles nil)
  366. (setq set-mark-command-repeat-pop t)
  367. (add-hook 'before-save-hook
  368. 'time-stamp)
  369. ;; Add Time-stamp: <> to insert timestamp there
  370. (set-variable 'time-stamp-format
  371. "%:y-%02m-%02d %02H:%02M:%02S %Z 10sr")
  372. ;; key bindings
  373. ;; moving around
  374. ;;(keyboard-translate ?\M-j ?\C-j)
  375. ;; (global-set-key (kbd "M-p") 'backward-paragraph)
  376. (define-key esc-map "p" 'backward-paragraph)
  377. ;; (global-set-key (kbd "M-n") 'forward-paragraph)
  378. (define-key esc-map "n" 'forward-paragraph)
  379. (global-set-key (kbd "C-<up>") 'scroll-down-line)
  380. (global-set-key (kbd "C-<down>") 'scroll-up-line)
  381. (global-set-key (kbd "C-<left>") 'scroll-down)
  382. (global-set-key (kbd "C-<right>") 'scroll-up)
  383. (global-set-key (kbd "<select>") 'ignore) ; 'previous-line-mark)
  384. (define-key ctl-x-map (kbd "ESC x") 'execute-extended-command)
  385. (define-key ctl-x-map (kbd "ESC :") 'eval-expression)
  386. ;; C-h and DEL
  387. (global-set-key (kbd "C-h") (kbd "DEL"))
  388. ;; (normal-erase-is-backspace-mode 1)
  389. ;;(global-set-key (kbd "C-m") 'reindent-then-newline-and-indent)
  390. (global-set-key (kbd "C-m") 'newline-and-indent)
  391. ;; (global-set-key (kbd "C-o") (kbd "C-e C-m"))
  392. ;; (global-set-key "\C-z" 'undo) ; undo is M-u
  393. (define-key esc-map "u" 'undo)
  394. (define-key esc-map "i" (kbd "ESC TAB"))
  395. ;; (global-set-key (kbd "C-r") 'query-replace-regexp)
  396. ;; (global-set-key (kbd "C-s") 'isearch-forward-regexp)
  397. ;; (global-set-key (kbd "C-r") 'isearch-backward-regexp)
  398. (set-variable 'search-default-mode t)
  399. ;; TODO: Do not depend on ivy function
  400. ;; (set-variable 'search-default-mode
  401. ;; (lambda (str lax)
  402. ;; (ivy--regex-fuzzy (replace-regexp-in-string (rx (one-or-more whitespace))
  403. ;; ""
  404. ;; str))))
  405. (when (fboundp 'undo-fu-only-undo)
  406. (global-set-key (kbd "C-_") 'undo-fu-only-undo))
  407. (when (fboundp 'undo-fu-only-redo)
  408. (global-set-key (kbd "C-M-_") 'undo-fu-only-redo))
  409. (require 'page-ext nil t)
  410. (when (fboundp 'global-page-break-lines-mode)
  411. (add-hook 'after-first-visit-hook
  412. 'global-page-break-lines-mode))
  413. (with-eval-after-load 'page-break-lines
  414. (set-face-foreground 'page-break-lines
  415. "cyan")
  416. )
  417. (defun my-insert-page-break ()
  418. "Insert ^L."
  419. (interactive)
  420. (insert "\^L\n"))
  421. (when (fboundp 'global-git-gutter-mode)
  422. (add-hook 'after-first-visit-hook
  423. 'global-git-gutter-mode))
  424. (with-eval-after-load 'git-gutter
  425. (declare-function global-git-gutter-mode "git-gutter")
  426. (custom-set-variables
  427. '(git-gutter:lighter " Gttr"))
  428. (custom-set-variables
  429. '(git-gutter:update-interval 2))
  430. (custom-set-variables
  431. '(git-gutter:unchanged-sign " "))
  432. (when (>= (display-color-cells)
  433. 256)
  434. (let ((c "color-233"))
  435. (set-face-background 'git-gutter:modified c)
  436. (set-face-background 'git-gutter:added c)
  437. (set-face-background 'git-gutter:deleted c)
  438. (set-face-background 'git-gutter:unchanged c)))
  439. (set-face-background 'git-gutter:modified "magenta")
  440. (set-face-background 'git-gutter:added "green")
  441. (set-face-background 'git-gutter:deleted "red")
  442. )
  443. ;; (when (fboundp 'fancy-narrow-mode)
  444. ;; (add-hook 'after-first-visit-hook
  445. ;; 'fancy-narrow-mode))
  446. ;; https://solist.work/blog/posts/mark-ring/
  447. (defun my-exchange-point-and-mark ()
  448. "`exchange-point-and-mark' without mark activation."
  449. (interactive)
  450. (exchange-point-and-mark)
  451. (deactivate-mark))
  452. (define-key ctl-x-map (kbd "C-x") 'my-exchange-point-and-mark)
  453. (when (fboundp 'counsel-mark-ring)
  454. (define-key ctl-x-map "m" 'counsel-mark-ring))
  455. (with-eval-after-load 'ivy
  456. (defvar ivy-sort-functions-alist)
  457. (add-to-list 'ivy-sort-functions-alist
  458. '(counsel-mark-ring)))
  459. (run-with-idle-timer 10 t
  460. (lambda ()
  461. (push-mark)
  462. ;; (when (fboundp 'visible-mark-move-overlays)
  463. ;; (visible-mark-move-overlays))
  464. ))
  465. (add-hook 'switch-buffer-functions
  466. (lambda (&rest _)
  467. (unless (or (mark t)
  468. (minibufferp))
  469. (push-mark))))
  470. (add-hook 'switch-buffer-functions
  471. (lambda (&rest _)
  472. (when (minibufferp)
  473. ;; Remove mark in minibuffer
  474. (set-mark nil))))
  475. (when (fboundp 'back-button-mode)
  476. (back-button-mode 1))
  477. (when (fboundp 'back-button-local-forward)
  478. (global-set-key (kbd "<right>") 'back-button-local-forward))
  479. (when (fboundp 'back-button-local-backward)
  480. (global-set-key (kbd "<left>") 'back-button-local-backward))
  481. (when (fboundp 'global-visible-mark-mode)
  482. (set-variable 'visible-mark-max 2)
  483. ;; (set-variable 'visible-mark-faces '(visible-mark-face1 visible-mark-face2))
  484. ;; http://emacs.rubikitch.com/visible-mark/
  485. ;; transient-mark-modeでC-SPC C-SPC、あるいはC-SPC C-gすると消えるバグ修正
  486. (defun visible-mark-move-overlays--avoid-disappear (&rest them)
  487. "Fix.
  488. THEM are function and its args."
  489. (let ((mark-active t)) (apply them)))
  490. (advice-add 'visible-mark-move-overlays
  491. :around
  492. 'visible-mark-move-overlays--avoid-disappear)
  493. ;; (global-visible-mark-mode 1)
  494. )
  495. ;; visible-mark-mode
  496. ;; visible-mark-overlays
  497. ;; mark-ring
  498. ;; (equal mark-ring (cl-copy-list mark-ring))
  499. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  500. ;; title and mode-line
  501. (when (fboundp 'terminal-title-mode)
  502. ;; if TERM is not screen use default value
  503. (if (getenv "TMUX")
  504. ;; if use tmux locally just basename of current dir
  505. (set-variable 'terminal-title-format
  506. '((file-name-nondirectory (directory-file-name
  507. default-directory))))
  508. (if (and (let ((tty-type (frame-parameter nil
  509. 'tty-type)))
  510. (and tty-type
  511. (equal (car (split-string tty-type
  512. "-"))
  513. "screen")))
  514. (not (getenv "SSH_CONNECTION")))
  515. (set-variable 'terminal-title-format
  516. '((file-name-nondirectory (directory-file-name
  517. default-directory))))
  518. ;; seems that TMUX is used locally and ssh to remote host
  519. (set-variable 'terminal-title-format
  520. `("em:"
  521. ,user-login-name
  522. "@"
  523. ,(car (split-string (system-name)
  524. "\\."))
  525. ":"
  526. default-directory))
  527. )
  528. )
  529. (terminal-title-mode))
  530. (setq eol-mnemonic-dos "\\r\\n")
  531. (setq eol-mnemonic-mac "\\r")
  532. (setq eol-mnemonic-unix "")
  533. (which-function-mode 1)
  534. (line-number-mode 0)
  535. (column-number-mode 0)
  536. (size-indication-mode 0)
  537. (setq mode-line-position
  538. '(:eval (format ":%%l:%%c /%d%s"
  539. (count-lines (point-max)
  540. (point-min))
  541. (if (buffer-narrowed-p)
  542. "[N]"
  543. "")
  544. )))
  545. (when (fboundp 'diminish)
  546. (eval-after-init
  547. (diminish 'recently-mode)
  548. (diminish 'editorconfig-mode)
  549. (diminish 'which-key-mode)
  550. )
  551. (with-eval-after-load 'whitespace
  552. (diminish 'global-whitespace-mode))
  553. (with-eval-after-load 'page-break-lines
  554. (diminish 'page-break-lines-mode))
  555. (with-eval-after-load 'auto-highlight-symbol
  556. (diminish 'auto-highlight-symbol-mode))
  557. (with-eval-after-load 'color-identifiers-mode
  558. (diminish 'color-identifiers-mode))
  559. (with-eval-after-load 'highlight-indentation
  560. (diminish 'highlight-indentation-mode))
  561. (with-eval-after-load 'back-button
  562. (diminish 'back-button-mode))
  563. (with-eval-after-load 'git-gutter
  564. (diminish 'git-gutter-mode))
  565. (with-eval-after-load 'autorevert
  566. (diminish 'auto-revert-mode))
  567. )
  568. (setq mode-line-front-space "")
  569. ;; (setq mode-line-end-spaces "")
  570. ;; Set current frame name to empty string
  571. (setq-default mode-line-format
  572. (let* ((l mode-line-format)
  573. (l (cl-substitute " " " "
  574. l
  575. :test 'equal))
  576. (l (cl-substitute " " " "
  577. l
  578. :test 'equal))
  579. )
  580. l))
  581. (set-frame-parameter nil 'name "")
  582. ;; See color-name-rgb-alist for available color names
  583. ;; http://www.raebear.net/computers/emacs-colors/
  584. ;; https://www.emacswiki.org/emacs/ListColors
  585. ;; (list-colors-display is not a complete list)
  586. (defconst my-mode-line-background-default
  587. (face-background 'mode-line)
  588. "Default color of mode-line at init.")
  589. (defun my-mode-line-color-update (&rest args)
  590. "ARGS are discarded"
  591. (let ((ro "skyblue")
  592. (rw my-mode-line-background-default))
  593. (if (or (not buffer-read-only)
  594. (and (eq major-mode 'wdired-mode)))
  595. (set-face-background 'mode-line
  596. rw)
  597. (set-face-background 'mode-line
  598. ro))))
  599. (add-hook 'switch-buffer-functions
  600. 'my-mode-line-color-update)
  601. (add-hook 'read-only-mode-hook
  602. 'my-mode-line-color-update)
  603. (add-hook 'wdired-mode-hook
  604. 'my-mode-line-color-update)
  605. (advice-add 'wdired-change-to-dired-mode
  606. :after
  607. 'my-mode-line-color-update)
  608. (advice-add 'wgrep-change-to-wgrep-mode
  609. :after
  610. 'my-mode-line-color-update)
  611. (advice-add 'wgrep-to-original-mode
  612. :after
  613. 'my-mode-line-color-update)
  614. (set-face-background 'header-line
  615. my-mode-line-background-default)
  616. ;; http://www.geocities.jp/simizu_daisuke/bunkei-meadow.html#frame-title
  617. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  618. ;; minibuffer
  619. (setq insert-default-directory t)
  620. (setq completion-ignore-case t
  621. read-file-name-completion-ignore-case t
  622. read-buffer-completion-ignore-case t)
  623. (setq resize-mini-windows t)
  624. (temp-buffer-resize-mode 1)
  625. (savehist-mode 1)
  626. (defvar display-time-format "%Y/%m/%d %a %H:%M")
  627. (set-variable 'help-at-pt-display-when-idle t)
  628. (fset 'yes-or-no-p 'y-or-n-p)
  629. ;; complete symbol when `eval'
  630. (define-key read-expression-map (kbd "TAB") 'completion-at-point)
  631. (define-key minibuffer-local-map (kbd "C-u")
  632. (lambda () (interactive) (delete-region (point-at-bol) (point))))
  633. ;; I dont know these bindings are good
  634. (define-key minibuffer-local-map (kbd "C-p") (kbd "ESC p"))
  635. (define-key minibuffer-local-map (kbd "C-n") (kbd "ESC n"))
  636. (with-eval-after-load 'minibuffer-line
  637. (set-face-underline 'minibuffer-line nil)
  638. )
  639. (when (fboundp 'minibuffer-line-mode)
  640. (set-variable 'minibuffer-line-refresh-interval
  641. 25)
  642. ;; Set idle timer
  643. (defvar my-minibuffer-line--idle-timer nil)
  644. (defvar minibuffer-line-mode)
  645. (add-hook 'minibuffer-line-mode-hook
  646. (lambda ()
  647. (when my-minibuffer-line--idle-timer
  648. (cancel-timer my-minibuffer-line--idle-timer)
  649. (setq my-minibuffer-line--idle-timer nil))
  650. (when minibuffer-line-mode
  651. (setq my-minibuffer-line--idle-timer
  652. (run-with-idle-timer 0.5
  653. t
  654. 'minibuffer-line--update)))))
  655. (set-variable 'minibuffer-line-format
  656. `(,(concat user-login-name
  657. "@"
  658. (car (split-string (system-name)
  659. "\\."))
  660. ":")
  661. (:eval (abbreviate-file-name (or buffer-file-name
  662. default-directory)))
  663. (:eval (and (fboundp 'git-ps1-mode-get-current)
  664. (git-ps1-mode-get-current " [GIT:%s]")))
  665. " "
  666. (:eval (format-time-string display-time-format))))
  667. (minibuffer-line-mode 1)
  668. )
  669. (when (fboundp 'prompt-text-mode)
  670. (set-variable 'prompt-text-format
  671. `(,(concat ""
  672. user-login-name
  673. "@"
  674. (car (split-string (system-name)
  675. "\\."))
  676. ":")
  677. (:eval (abbreviate-file-name (or buffer-file-name
  678. default-directory)))
  679. (:eval (and (fboundp 'git-ps1-mode-get-current)
  680. (git-ps1-mode-get-current " [GIT:%s]")))
  681. " "
  682. (:eval (format-time-string display-time-format))
  683. "\n"
  684. (:eval (symbol-name this-command))
  685. ": "))
  686. (prompt-text-mode 1))
  687. (with-eval-after-load 'helm
  688. (defvar helm-map)
  689. (define-key helm-map (kbd "C-h") (kbd "DEL")))
  690. (setq-default header-line-format
  691. '(:eval (let ((f (or (buffer-file-name)
  692. default-directory)))
  693. (when f
  694. (abbreviate-file-name f)))))
  695. (when (eval-and-compile (require 'nyan-mode nil t))
  696. (setq-default header-line-format
  697. '(
  698. ;; (:eval (file-name-nondirectory(directory-file-name (or buffer-file-name
  699. ;; default-directory))))
  700. ;; "["
  701. (:eval (progn
  702. (list (nyan-create))))
  703. ;; "]"
  704. ;; (:eval (let ((f (or (buffer-file-name)
  705. ;; default-directory)))
  706. ;; (when f
  707. ;; (abbreviate-file-name f))))
  708. ))
  709. (defun my-nyan-set-length (&rest _)
  710. "Set `nyan-mode' length to window width."
  711. (set-variable 'nyan-bar-length
  712. (- (window-size nil t) 4)
  713. t))
  714. (add-hook 'window-configuration-change-hook
  715. 'my-nyan-set-length)
  716. (add-hook 'switch-buffer-functions
  717. 'my-nyan-set-length)
  718. )
  719. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  720. ;; letters, font-lock mode and fonts
  721. (when (fboundp 'color-identifiers-mode)
  722. (add-hook 'prog-mode-hook
  723. 'color-identifiers-mode))
  724. (setq text-quoting-style 'grave)
  725. ;; (set-face-background 'vertical-border (face-foreground 'mode-line))
  726. ;; (set-window-margins (selected-window) 1 1)
  727. (unless window-system
  728. (setq frame-background-mode 'dark))
  729. (and (or (eq system-type 'Darwin)
  730. (eq system-type 'darwin))
  731. (fboundp 'mac-set-input-method-parameter)
  732. (mac-set-input-method-parameter 'japanese 'cursor-color "red")
  733. (mac-set-input-method-parameter 'roman 'cursor-color "black"))
  734. (when (and (boundp 'input-method-activate-hook) ; i dont know this is correct
  735. (boundp 'input-method-inactivate-hook))
  736. (add-hook 'input-method-activate-hook
  737. (lambda () (set-cursor-color "red")))
  738. (add-hook 'input-method-inactivate-hook
  739. (lambda () (set-cursor-color "black"))))
  740. (when (fboundp 'show-paren-mode)
  741. (add-hook 'after-first-visit-hook
  742. 'show-paren-mode))
  743. (set-variable 'show-paren-delay 0.5)
  744. (set-variable 'show-paren-style 'parenthesis) ; mixed is hard to read
  745. ;; (set-face-background 'show-paren-match
  746. ;; "black")
  747. ;; ;; (face-foreground 'default))
  748. ;; (set-face-foreground 'show-paren-match
  749. ;; "white")
  750. ;; (set-face-inverse-video-p 'show-paren-match
  751. ;; t)
  752. (transient-mark-mode 1)
  753. (global-font-lock-mode 1)
  754. (setq font-lock-global-modes
  755. '(not
  756. help-mode
  757. eshell-mode
  758. ;;term-mode
  759. Man-mode
  760. ))
  761. ;; (standard-display-ascii ?\n "$\n")
  762. ;; (defvar my-eol-face
  763. ;; '(("\n" . (0 font-lock-comment-face t nil)))
  764. ;; )
  765. ;; (defvar my-tab-face
  766. ;; '(("\t" . '(0 highlight t nil))))
  767. (defvar my-jspace-face
  768. '(("\u3000" . '(0 highlight t nil))))
  769. (add-hook 'font-lock-mode-hook
  770. (lambda ()
  771. ;; (font-lock-add-keywords nil my-eol-face)
  772. (font-lock-add-keywords nil my-jspace-face)
  773. ))
  774. (when (fboundp 'global-whitespace-mode)
  775. (add-hook 'after-first-visit-hook
  776. 'global-whitespace-mode))
  777. (add-hook 'dired-mode-hook
  778. ;; Other way to disable in dired buffers?
  779. (lambda () (set-variable 'whitespace-style nil t)))
  780. (with-eval-after-load 'whitespace
  781. (defvar whitespace-display-mappings)
  782. (defvar whitespace-mode)
  783. (add-to-list 'whitespace-display-mappings
  784. ;; We need t since last one takes precedence
  785. `(tab-mark ?\t ,(vconcat "|>\t")) t)
  786. ;; (add-to-list 'whitespace-display-mappings
  787. ;; `(newline-mark ?\n ,(vconcat "$\n")))
  788. (set-variable 'whitespace-style '(face
  789. trailing ; trailing blanks
  790. ;; tabs
  791. ;; spaces
  792. ;; lines
  793. lines-tail ; lines over 80
  794. newline ; newlines
  795. ;; empty ; empty lines at beg or end of buffer
  796. ;; big-indent
  797. ;; space-mark
  798. tab-mark
  799. newline-mark ; use display table for newline
  800. ))
  801. ;; (setq whitespace-newline 'font-lock-comment-face)
  802. ;; (setq whitespace-style (delq 'newline-mark whitespace-style))
  803. (defun my-whitesspace-mode-reload ()
  804. "Reload whitespace-mode config."
  805. (interactive)
  806. (when whitespace-mode
  807. (whitespace-mode 0)
  808. (whitespace-mode 1)))
  809. (set-variable 'whitespace-line-column nil)
  810. (if (>= (display-color-cells)
  811. 256)
  812. (set-face-foreground 'whitespace-newline "color-109")
  813. ;; (progn
  814. ;; (set-face-bold-p 'whitespace-newline
  815. ;; t))
  816. ))
  817. (and nil
  818. '(require 'fill-column-indicator nil t)
  819. (setq fill-column-indicator))
  820. (defun my-gen-hl-line-color-dark ()
  821. "Generate color for current line in black background."
  822. (let* ((candidates (mapcar 'number-to-string (number-sequence 1 6)))
  823. (limit (length candidates))
  824. (r 0) (g 0) (b 0))
  825. (while (and (<= (abs (- r g)) 1)
  826. (<= (abs (- g b)) 1)
  827. (<= (abs (- b r)) 1))
  828. (setq r (random limit))
  829. (setq g (random limit))
  830. (setq b (random limit)))
  831. (format "#%s%s%s"
  832. (nth r candidates)
  833. (nth g candidates)
  834. (nth b candidates)
  835. )))
  836. ;; (my-gen-hl-line-color-dark)
  837. ;; highlight current line
  838. ;; http://wiki.riywo.com/index.php?Meadow
  839. (face-spec-set 'hl-line
  840. `((((min-colors 256)
  841. (background dark))
  842. ;; Rotate midnightblue
  843. (:background ,(my-gen-hl-line-color-dark)))
  844. (((min-colors 256)
  845. (background light))
  846. ;; TODO: What is should be?
  847. (:background "color-234"))
  848. (t
  849. (:underline "black"))))
  850. (set-variable 'hl-line-global-modes
  851. '(not
  852. term-mode))
  853. (global-hl-line-mode 1) ;; (hl-line-mode 1)
  854. (set-face-foreground 'font-lock-regexp-grouping-backslash "#666")
  855. (set-face-foreground 'font-lock-regexp-grouping-construct "#f60")
  856. ;;(require 'set-modeline-color nil t)
  857. ;; (let ((fg (face-foreground 'default))
  858. ;; (bg (face-background 'default)))
  859. ;; (set-face-background 'mode-line-inactive
  860. ;; (if (face-inverse-video-p 'mode-line) fg bg))
  861. ;; (set-face-foreground 'mode-line-inactive
  862. ;; (if (face-inverse-video-p 'mode-line) bg fg)))
  863. ;; (set-face-underline 'mode-line-inactive
  864. ;; t)
  865. ;; (set-face-underline 'vertical-border
  866. ;; nil)
  867. ;; (when (require 'end-mark nil t)
  868. ;; (global-end-mark-mode))
  869. ;; M-x highlight-* to highlight things
  870. (global-hi-lock-mode 1)
  871. (unless (fboundp 'highlight-region-text)
  872. (defun highlight-region-text (beg end)
  873. "Highlight text between BEG and END."
  874. (interactive "r")
  875. (highlight-regexp (regexp-quote (buffer-substring-no-properties beg
  876. end)))
  877. (setq deactivate-mark t)))
  878. (when (fboundp 'auto-highlight-symbol-mode)
  879. (add-hook 'prog-mode-hook
  880. 'auto-highlight-symbol-mode))
  881. ;; Not work in combination with flyspell-mode
  882. ;; (when (fboundp 'global-auto-highlight-symbol-mode)
  883. ;; (add-hook 'after-first-visit-hook
  884. ;; 'global-auto-highlight-symbol-mode))
  885. (set-variable 'ahs-idle-interval 0.6)
  886. (when (fboundp 'highlight-indentation-mode)
  887. (dolist (hook
  888. '(
  889. prog-mode-hook
  890. text-mode-hook
  891. ))
  892. (add-hook hook
  893. 'highlight-indentation-mode)))
  894. (with-eval-after-load 'highlight-indentation
  895. (set-face-background 'highlight-indentation-face "color-236"))
  896. ;; (set-face-background 'highlight-indentation-current-column-face "#c3b3b3")
  897. (when (fboundp 'fic-mode)
  898. (add-hook 'prog-mode-hook
  899. 'fic-mode))
  900. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  901. ;; file handling
  902. (auto-insert-mode 1)
  903. ;; fzf
  904. ;; Too slow in term buffer!
  905. ;; (set-variable 'fzf/executable "sk")
  906. ;; (set-variable 'fzf/args "--color bw --print-query")
  907. ;; Modified from hardcoded default to include:
  908. ;; - directories
  909. ;; - hidden files
  910. ;; - root directory (.)
  911. ;; - parent directory (..)
  912. ;; ripgrep cannot list directories...
  913. ;; (setenv "FZF_DEFAULT_COMMAND" "rg --files --hidden --follow --glob '!.git/*' --no-ignore")
  914. (defvar my-fzf-default-command nil
  915. "My fzf FZF_DEFAULT_COMMAND.")
  916. (set-variable 'my-fzf-default-command
  917. (let ((find (or (executable-find "bfs") ;; Breadth-first find https://github.com/tavianator/bfs
  918. ;; Use gfind if available?
  919. "find"))
  920. (fd (or (executable-find "fdfind")
  921. (executable-find "fd"))))
  922. (if fd
  923. (concat "set -eu; set -o pipefail; "
  924. "echo .; "
  925. "echo ..; "
  926. "command " fd " "
  927. "--follow --hidden --no-ignore "
  928. "--color always "
  929. "2>/dev/null")
  930. (concat "set -eu; set -o pipefail; "
  931. "echo .; "
  932. "echo ..; "
  933. "command " find " -L . "
  934. "-mindepth 1 "
  935. "\\( -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune "
  936. "-o -print "
  937. "2> /dev/null "
  938. "| "
  939. "cut -b3-"))))
  940. (set-variable 'fzf/window-height 45)
  941. (set-variable 'fzf/args "--print-query --ansi --color='bg+:-1' --inline-info --cycle")
  942. ;; (set-variable 'fzf/args "--print-query --ansi --inline-info --cycle")
  943. ;; (set-variable 'fzf/args "--print-query --ansi --color=bw --inline-info --cycle")
  944. (declare-function fzf "fzf" t)
  945. (defun my-fzf-or-find-file ()
  946. "Call fzf if usable or call `find-file'."
  947. (declare (interactive-only t))
  948. (interactive)
  949. (if (and (executable-find "fzf")
  950. (fboundp 'fzf)
  951. (not (file-remote-p default-directory)))
  952. (let ((process-environment (cl-copy-list process-environment)))
  953. (setenv "FZF_DEFAULT_COMMAND" my-fzf-default-command)
  954. (fzf))
  955. (call-interactively 'find-file)))
  956. (define-key ctl-x-map "f" 'my-fzf-or-find-file)
  957. (defun my-fzf-all-lines ()
  958. "Fzf all lines."
  959. (interactive)
  960. (let ((process-environment (cl-copy-list process-environment)))
  961. (setenv "FZF_DEFAULT_COMMAND" "rg -nH --no-heading --hidden --follow --glob '!.git/*' --color=always ^")
  962. (fzf)))
  963. (define-key ctl-x-map "S" 'my-fzf-all-lines)
  964. ;; recently
  965. ;; TODO: Enable after first visit file?
  966. (with-eval-after-load 'recently
  967. (defvar recently-excludes)
  968. (add-to-list 'recently-excludes
  969. (rx-to-string (list 'and
  970. 'string-start
  971. (expand-file-name package-user-dir))
  972. t)))
  973. (when (fboundp 'recently-mode)
  974. (define-key ctl-x-map (kbd "C-r") 'recently-show)
  975. (set-variable 'recently-max 1000)
  976. (recently-mode 1))
  977. (defvar my-cousel-recently-history nil "History of `my-counsel-recently'.")
  978. (declare-function recently-list "recently" t)
  979. (when (and (require 'recently nil t)
  980. (fboundp 'ivy-read))
  981. (defun my-counsel-recently ()
  982. "Consel `recently'."
  983. (interactive)
  984. (ivy-read "Recently: " (mapcar 'abbreviate-file-name (recently-list))
  985. :require-match t
  986. :history 'my-cousel-recently-history
  987. :preselect default-directory
  988. :action (lambda (x) (find-file x))
  989. :caller 'my-counsel-recently))
  990. (define-key ctl-x-map (kbd "C-r") 'my-counsel-recently)
  991. )
  992. (when (fboundp 'editorconfig-mode)
  993. (add-hook 'after-first-visit-hook
  994. 'editorconfig-mode)
  995. (add-hook 'after-first-visit-hook
  996. 'editorconfig-mode-apply
  997. t)) ;; Do after enabling editorconfig-mode
  998. (set-variable 'editorconfig-get-properties-function
  999. 'editorconfig-core-get-properties-hash)
  1000. (set-variable 'editorconfig-mode-lighter "")
  1001. (when (fboundp 'ws-butler-mode)
  1002. (set-variable 'editorconfig-trim-whitespaces-mode
  1003. 'ws-butler-mode))
  1004. (with-eval-after-load 'org-src
  1005. ;; [*.org\[\*Org Src*\[ c \]*\]]
  1006. (add-hook 'org-src-mode-hook
  1007. 'editorconfig-mode-apply t))
  1008. (when (fboundp 'editorconfig-custom-majormode)
  1009. (add-hook 'editorconfig-after-apply-functions
  1010. 'editorconfig-custom-majormode))
  1011. ;; Add readonly=true to set read-only-mode
  1012. (add-hook 'editorconfig-after-apply-functions
  1013. (lambda (props)
  1014. (let ((r (gethash 'readonly props)))
  1015. (when (and (string= r "true")
  1016. (not buffer-read-only))
  1017. (read-only-mode 1)))))
  1018. (add-hook 'editorconfig-hack-properties-functions
  1019. '(lambda (props)
  1020. (when (derived-mode-p 'makefile-mode)
  1021. (puthash 'indent_style "tab" props))
  1022. (when (derived-mode-p 'diff-mode)
  1023. (puthash 'trim_trailing_whitespace "false" props)
  1024. (puthash 'insert_final_newline "false" props)
  1025. )
  1026. ))
  1027. (when (fboundp 'editorconfig-auto-apply-enable)
  1028. (add-hook 'editorconfig-conf-mode-hook
  1029. 'editorconfig-auto-apply-enable))
  1030. ;; (when (fboundp 'editorconfig-charset-extras)
  1031. ;; (add-hook 'editorconfig-custom-hooks
  1032. ;; 'editorconfig-charset-extras))
  1033. (setq revert-without-query '(".+"))
  1034. ;; save cursor position
  1035. (when (fboundp 'save-place-mode)
  1036. (autoload 'save-place-find-file-hook "saveplace")
  1037. (add-hook 'after-first-visit-hook
  1038. 'save-place-mode)
  1039. (add-hook 'after-first-visit-hook
  1040. 'save-place-find-file-hook
  1041. t))
  1042. (set-variable 'save-place-file (concat user-emacs-directory
  1043. "places"))
  1044. ;; http://www.bookshelf.jp/soft/meadow_24.html#SEC260
  1045. (setq make-backup-files t)
  1046. (setq vc-make-backup-files t)
  1047. ;; (make-directory (expand-file-name "~/.emacsbackup"))
  1048. (setq backup-directory-alist
  1049. (cons (cons "." (expand-file-name (concat user-emacs-directory
  1050. "backup")))
  1051. backup-directory-alist))
  1052. (setq version-control 't)
  1053. (setq delete-old-versions t)
  1054. (setq kept-new-versions 20)
  1055. (setq auto-save-list-file-prefix (expand-file-name (concat user-emacs-directory
  1056. "auto-save/")))
  1057. ;; (setq delete-auto-save-files t)
  1058. (setq auto-save-visited-interval 8)
  1059. (auto-save-visited-mode 1)
  1060. ;; (add-to-list 'auto-save-file-name-transforms
  1061. ;; `(".*" ,(concat user-emacs-directory "auto-save-dir") t))
  1062. ;; (setq auto-save-interval 3)
  1063. ;; (auto-save-mode 1)
  1064. (add-to-list 'completion-ignored-extensions ".bak")
  1065. (set-variable 'completion-cycle-threshold nil) ;; NEVER use
  1066. (setq delete-by-moving-to-trash t)
  1067. ;; trash-directory "~/.emacs.d/trash")
  1068. (add-hook 'after-save-hook
  1069. 'executable-make-buffer-file-executable-if-script-p)
  1070. (when (fboundp 'smart-revert-on)
  1071. (smart-revert-on))
  1072. ;; autosave
  1073. ;; auto-save-visited-mode can be used instead?
  1074. ;; (when (require 'autosave nil t)
  1075. ;; (autosave-set 8))
  1076. ;; bookmarks
  1077. (set-variable 'bookmark-default-file
  1078. (expand-file-name (concat user-emacs-directory
  1079. "bmk")))
  1080. (set-variable 'bookmark-sort-flag nil)
  1081. (defun my-bookmark-set ()
  1082. "My `bookmark-set'."
  1083. (interactive)
  1084. (cl-assert (or buffer-file-name
  1085. default-directory))
  1086. (let ((name (file-name-nondirectory (or buffer-file-name
  1087. (directory-file-name default-directory))))
  1088. (linenum (count-lines (point-min)
  1089. (point)))
  1090. (linetext (buffer-substring-no-properties (point-at-bol)
  1091. (point-at-eol))))
  1092. (bookmark-set (format "%s:%d:%s"
  1093. name linenum linetext)
  1094. nil)))
  1095. ;; Done by advice instead
  1096. ;; (set-variable 'bookmark-save-flag
  1097. ;; 1)
  1098. (with-eval-after-load 'recentf
  1099. (defvar recentf-exclude)
  1100. (defvar bookmark-default-file)
  1101. (add-to-list 'recentf-exclude
  1102. (regexp-quote bookmark-default-file)))
  1103. (defvar bookmark-default-file)
  1104. (defun my-bookmark-set--advice (orig-func &rest args)
  1105. "Function for `bookmark-set-internal'.
  1106. ORIG-FUNC is the target function, and ARGS is the argument when it is called."
  1107. (bookmark-load bookmark-default-file)
  1108. (apply orig-func args)
  1109. (bookmark-save))
  1110. (with-eval-after-load 'bookmark
  1111. (advice-add 'bookmark-set-internal
  1112. :around
  1113. 'my-bookmark-set--advice))
  1114. (define-key ctl-x-map "b" 'list-bookmarks)
  1115. (when (fboundp 'counsel-bookmark)
  1116. (define-key ctl-x-map "b" 'counsel-bookmark))
  1117. (define-key ctl-x-map "B" 'my-bookmark-set)
  1118. ;; vc
  1119. (set-variable 'vc-handled-backends '(RCS))
  1120. (set-variable 'vc-rcs-register-switches "-l")
  1121. (set-variable 'vc-rcs-checkin-switches "-l")
  1122. (set-variable 'vc-command-messages t)
  1123. (when (fboundp 'neotree)
  1124. (define-key ctl-x-map (kbd "C-n") 'neotree))
  1125. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1126. ;; share clipboard with x
  1127. ;; this page describes this in details, but only these sexps seem to be needed
  1128. ;; http://garin.jp/doc/Linux/xwindow_clipboard
  1129. (and nil
  1130. (not window-system)
  1131. (not (eq window-system 'mac))
  1132. (getenv "DISPLAY")
  1133. (not (equal (getenv "DISPLAY") ""))
  1134. (executable-find "xclip")
  1135. ;; (< emacs-major-version 24)
  1136. '(require 'xclip nil t)
  1137. nil
  1138. (turn-on-xclip))
  1139. (declare-function turn-on-pasteboard "pasteboard")
  1140. (and (eq system-type 'darwin)
  1141. (require 'pasteboard nil t)
  1142. (turn-on-pasteboard))
  1143. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1144. ;; some modes and hooks
  1145. ;; Include some extra modes
  1146. (require 'generic-x)
  1147. ;; Derived from https://github.com/ensime/ensime-emacs/issues/591#issuecomment-291916753
  1148. (defun my-scalafmt ()
  1149. (interactive)
  1150. (cl-assert buffer-file-name)
  1151. (cl-assert (not (buffer-modified-p)))
  1152. (let* ((configdir (locate-dominating-file default-directory ".scalafmt.conf"))
  1153. (configoption (if configdir
  1154. (concat " --config "
  1155. (shell-quote-argument (expand-file-name configdir))
  1156. ".scalafmt.conf"
  1157. )
  1158. ""))
  1159. (str (concat "scalafmt -f "
  1160. (shell-quote-argument buffer-file-name)
  1161. configoption
  1162. " -i --exclude ensime")))
  1163. (message str)
  1164. (shell-command-to-string str))
  1165. (message "scalafmt done")
  1166. (revert-buffer nil t))
  1167. (when (fboundp 'web-mode)
  1168. (add-to-list 'auto-mode-alist
  1169. '("\\.html\\.j2\\'" . web-mode))
  1170. (add-to-list 'auto-mode-alist
  1171. ;; Django Template Language
  1172. '("\\.dtl\\'" . web-mode))
  1173. )
  1174. (when (locate-library "wgrep")
  1175. (set-variable 'wgrep-auto-save-buffer t)
  1176. (with-eval-after-load 'grep
  1177. (defvar grep-mode-map)
  1178. (define-key grep-mode-map
  1179. "e"
  1180. 'wgrep-change-to-wgrep-mode)))
  1181. (when (fboundp 'grep-context-mode)
  1182. (add-hook 'compilation-mode-hook #'grep-context-mode))
  1183. (with-eval-after-load 'remember
  1184. (defvar remember-mode-map)
  1185. (define-key remember-mode-map (kbd "C-x C-s") 'ignore))
  1186. (set-variable 'remember-notes-initial-major-mode
  1187. 'change-log-mode)
  1188. (declare-function global-magit-file-mode "magit-files")
  1189. (with-eval-after-load 'magit-files
  1190. ;; `global-magit-file-mode' is enabled by default and this mode overwrites
  1191. ;; existing keybindings.
  1192. ;; Apparently it is a HARMFUL behavior and it is really awful that I have
  1193. ;; to disable thie mode here, but do anyway.
  1194. ;; See also https://github.com/magit/magit/issues/3517
  1195. (global-magit-file-mode -1))
  1196. (with-eval-after-load 'magit-section
  1197. (set-face-background 'magit-section-highlight
  1198. nil))
  1199. ;; Sane colors
  1200. (with-eval-after-load 'magit-diff
  1201. (set-face-background 'magit-diff-context nil)
  1202. (set-face-background 'magit-diff-context-highlight nil)
  1203. (set-face-foreground 'magit-diff-hunk-heading nil)
  1204. (set-face-background 'magit-diff-hunk-heading nil)
  1205. (set-face-foreground 'magit-diff-hunk-heading-highlight nil)
  1206. (set-face-background 'magit-diff-hunk-heading-highlight nil)
  1207. ;; https://blog.shibayu36.org/entry/2016/03/27/220552
  1208. (set-face-foreground 'magit-diff-added "green")
  1209. (set-face-background 'magit-diff-added nil)
  1210. (set-face-foreground 'magit-diff-added-highlight "green")
  1211. (set-face-background 'magit-diff-added-highlight nil)
  1212. (set-face-foreground 'magit-diff-removed "red")
  1213. (set-face-background 'magit-diff-removed nil)
  1214. (set-face-foreground 'magit-diff-removed-highlight "red")
  1215. (set-face-background 'magit-diff-removed-highlight nil)
  1216. (set-face-background 'magit-diff-lines-boundary "blue")
  1217. )
  1218. (declare-function magit-show-commit "magit")
  1219. (defun my-magit-messenger (file line)
  1220. "Magit messenger."
  1221. (interactive (list buffer-file-name
  1222. (line-number-at-pos)))
  1223. (cl-assert file)
  1224. (cl-assert line)
  1225. (let* ((blame-args '("-w"))
  1226. (id (with-temp-buffer
  1227. (let ((exit (apply 'call-process
  1228. "git" ;; PROGRAM
  1229. nil ;; INFILE
  1230. t ;; DESTINATION
  1231. nil ;; DISPLAY
  1232. "--no-pager" ;; ARGS
  1233. "blame"
  1234. "-L"
  1235. (format "%d,+1" line)
  1236. "--porcelain"
  1237. file
  1238. blame-args
  1239. )))
  1240. (goto-char (point-min))
  1241. (cl-assert (eq exit 0)
  1242. "Failed: %s" (buffer-substring (point)
  1243. (point-at-eol)))
  1244. (save-match-data
  1245. (re-search-forward (rx buffer-start
  1246. (one-or-more hex-digit)))
  1247. (match-string 0))))))
  1248. (magit-show-commit id)))
  1249. (when (boundp 'git-rebase-filename-regexp)
  1250. (add-to-list 'auto-mode-alist
  1251. `(,git-rebase-filename-regexp . text-mode)))
  1252. (when (fboundp 'ggtags-mode)
  1253. (add-hook 'c-mode-common-hook
  1254. 'ggtags-mode)
  1255. (add-hook 'python-mode-hook
  1256. 'ggtags-mode)
  1257. (add-hook 'js-mode-hook
  1258. 'ggtags-mode)
  1259. (add-hook 'scheme-mode-hook
  1260. 'ggtags-mode)
  1261. )
  1262. (when (fboundp 'imenu-list-minor-mode)
  1263. (defvar imenu-list-buffer-name)
  1264. (defun my-imenu-list-toggle ()
  1265. "My 'imenu-list` toggle."
  1266. (interactive)
  1267. (require 'imenu-list)
  1268. (if (eq (window-buffer)
  1269. (get-buffer imenu-list-buffer-name))
  1270. (imenu-list-minor-mode -1)
  1271. (imenu-list-minor-mode 1)))
  1272. ;; (set-variable 'imenu-list-auto-resize t)
  1273. (set-variable 'imenu-list-focus-after-activation t)
  1274. (define-key ctl-x-map (kbd "C-l") 'my-imenu-list-toggle))
  1275. (add-hook 'emacs-lisp-mode-hook
  1276. (lambda ()
  1277. (setq imenu-generic-expression
  1278. `(("Sections" ";;;\+\n;; \\(.*\\)\n" 1)
  1279. ,@imenu-generic-expression))))
  1280. ;; TODO: Try paraedit http://daregada.blogspot.com/2012/03/paredit.html
  1281. (with-eval-after-load 'compile
  1282. (defvar compilation-filter-start)
  1283. (defvar compilation-error-regexp-alist)
  1284. (eval-and-compile (require 'ansi-color))
  1285. (add-hook 'compilation-filter-hook
  1286. (lambda ()
  1287. (let ((inhibit-read-only t))
  1288. (ansi-color-apply-on-region compilation-filter-start
  1289. (point)))))
  1290. (add-to-list 'compilation-error-regexp-alist
  1291. ;; ansible-lint
  1292. '("^\\([^ \n]+\\):\\([0-9]+\\)$" 1 2))
  1293. (add-to-list 'compilation-error-regexp-alist
  1294. ;; pydocstyle
  1295. '("^\\([^ \n]+\\):\\([0-9]+\\) " 1 2))
  1296. )
  1297. (declare-function company-cancel "company")
  1298. (when (fboundp 'global-company-mode)
  1299. (add-hook 'after-first-visit-hook
  1300. 'global-company-mode))
  1301. (declare-function company-manual-begin "company")
  1302. (with-eval-after-load 'company
  1303. ;; http://qiita.com/sune2/items/b73037f9e85962f5afb7
  1304. ;; https://qiita.com/yuze/items/a145b1e3edb6d0c24cbf
  1305. (set-variable 'company-idle-delay nil)
  1306. (set-variable 'company-minimum-prefix-length 2)
  1307. (set-variable 'company-selection-wrap-around t)
  1308. (defvar company-mode-map)
  1309. (define-key company-mode-map (kbd "C-i") 'company-indent-or-complete-common)
  1310. ;; (with-eval-after-load 'python
  1311. ;; (defvar python-indent-trigger-commands)
  1312. ;; ;; TODO: This disables completion in puthon?
  1313. ;; (add-to-list 'python-indent-trigger-commands
  1314. ;; 'company-indent-or-complete-common))
  1315. (define-key ctl-x-map (kbd "C-i") 'company-complete) ; Originally `indent-rigidly'
  1316. (defvar company-active-map)
  1317. (define-key company-active-map (kbd "C-n") 'company-select-next)
  1318. (define-key company-active-map (kbd "C-p") 'company-select-previous)
  1319. (define-key company-active-map (kbd "C-s") 'company-filter-candidates)
  1320. (define-key company-active-map (kbd "C-i") 'company-complete-selection)
  1321. (define-key company-active-map (kbd "C-f") 'company-complete-selection)
  1322. (defvar company-mode)
  1323. (defvar company-candidates)
  1324. (defvar company-candidates-length)
  1325. ;; (popup-tip "Hello, World!")
  1326. (defun my-company-lighter-current-length ()
  1327. "Get current candidate length."
  1328. (interactive)
  1329. (let ((l nil)
  1330. (inhibit-message t))
  1331. (when (and company-mode
  1332. (not (minibufferp))
  1333. ;; Do nothing when already in company completion
  1334. (not company-candidates))
  1335. ;; FIXME: Somehow it cannto catch errors from ggtags
  1336. (ignore-errors
  1337. ;; (company-auto-begin)
  1338. (company-manual-begin)
  1339. (setq l company-candidates-length)
  1340. (company-cancel)))
  1341. (if l
  1342. (format "[%d]" l)
  1343. "")))
  1344. (defvar company-lighter)
  1345. (set-variable 'company-lighter-base "Cmp")
  1346. ;; (add-to-list 'company-lighter
  1347. ;; '(:eval (my-company-lighter-current-length))
  1348. ;; t)
  1349. ;; This breaks japanese text input
  1350. ;; (set-variable 'my-company-length-popup-tip-timer
  1351. ;; (run-with-idle-timer 0.2 t
  1352. ;; 'my-company-length-popup-tip))
  1353. ;; (current-active-maps)
  1354. ;; (lookup-key)
  1355. '(mapcar (lambda (map)
  1356. (lookup-key map (kbd "C-i")))
  1357. (current-active-maps))
  1358. ;; https://qiita.com/syohex/items/8d21d7422f14e9b53b17
  1359. (set-face-attribute 'company-tooltip nil
  1360. :foreground "black" :background "lightgrey")
  1361. (set-face-attribute 'company-tooltip-common nil
  1362. :foreground "black" :background "lightgrey")
  1363. (set-face-attribute 'company-tooltip-common-selection nil
  1364. :foreground "white" :background "steelblue")
  1365. (set-face-attribute 'company-tooltip-selection nil
  1366. :foreground "black" :background "steelblue")
  1367. (set-face-attribute 'company-preview-common nil
  1368. :background nil :foreground "lightgrey" :underline t)
  1369. (set-face-attribute 'company-scrollbar-fg nil
  1370. :background "orange")
  1371. (set-face-attribute 'company-scrollbar-bg nil
  1372. :background "gray40")
  1373. )
  1374. ;; https://github.com/lunaryorn/flycheck
  1375. ;; TODO: Any way to disable auto check?
  1376. ;; Update flycheck-hooks-alist?
  1377. (when (fboundp 'global-flycheck-mode)
  1378. (add-hook 'after-first-visit-hook
  1379. 'global-flycheck-mode))
  1380. ;; (set-variable 'flycheck-display-errors-delay 2.0)
  1381. ;; (fset 'flycheck-display-error-at-point-soon 'ignore)
  1382. ;; (with-eval-after-load 'flycheck
  1383. ;; (when (fboundp 'flycheck-black-check-setup)
  1384. ;; (flycheck-black-check-setup)))
  1385. (when (fboundp 'ilookup-open-word)
  1386. (define-key ctl-x-map "d" 'ilookup-open-word))
  1387. (set-variable 'ac-ignore-case nil)
  1388. (when (fboundp 'term-run-shell-command)
  1389. (define-key ctl-x-map "t" 'term-run-shell-command))
  1390. (add-to-list 'safe-local-variable-values
  1391. '(encoding utf-8))
  1392. (setq enable-local-variables :safe)
  1393. ;; Detect file type from shebang and set major-mode.
  1394. (add-to-list 'interpreter-mode-alist
  1395. '("python3" . python-mode))
  1396. (add-to-list 'interpreter-mode-alist
  1397. '("python2" . python-mode))
  1398. (with-eval-after-load 'python
  1399. (defvar python-mode-map (make-sparse-keymap))
  1400. (define-key python-mode-map (kbd "C-m") 'newline-and-indent))
  1401. ;; I want to use this, but this breaks normal self-insert-command
  1402. ;; (set-variable 'py-indent-list-style
  1403. ;; 'one-level-to-beginning-of-statement)
  1404. (set-variable 'pydoc-command
  1405. "python3 -m pydoc")
  1406. (declare-function with-venv-advice-add "with-venv")
  1407. (with-eval-after-load 'pydoc
  1408. (when (require 'with-venv nil t)
  1409. (with-venv-advice-add 'pydoc)))
  1410. (set-variable 'flycheck-python-mypy-ini ".mypy.ini")
  1411. (set-variable 'flycheck-flake8rc "setup.cfg")
  1412. (set-variable 'flycheck-python-pylint-executable "python3")
  1413. (set-variable 'flycheck-python-pycompile-executable "python3")
  1414. (set-variable 'python-indent-guess-indent-offset nil)
  1415. (with-eval-after-load 'blacken
  1416. (when (require 'with-venv nil t)
  1417. (with-venv-advice-add 'blacken-buffer)))
  1418. (with-eval-after-load 'ansible-doc
  1419. (when (require 'with-venv nil t)
  1420. (with-venv-advice-add 'ansible-doc)))
  1421. ;; `isortify-buffer' breaks buffer when it contains japanese text
  1422. (defun my-isortify ()
  1423. (interactive)
  1424. (cl-assert buffer-file-name)
  1425. (cl-assert (not (buffer-modified-p)))
  1426. (call-process "python" ;; PROGRAM
  1427. nil ;; INFILE
  1428. nil ;; DESTINATION
  1429. nil ;; DISPLAY
  1430. "-m" "isort" buffer-file-name)
  1431. (message "isortify done")
  1432. (revert-buffer nil t))
  1433. (when (fboundp 'with-venv-advice-add)
  1434. ;; TODO: Lazy load with-venv
  1435. (with-venv-advice-add 'my-isortify))
  1436. ;; https://github.com/lunaryorn/old-emacs-configuration/blob/master/lisp/flycheck-virtualenv.el
  1437. (defun my-set-venv-flycheck-executable-find ()
  1438. "Set flycheck executabie find."
  1439. (interactive)
  1440. (when (fboundp 'with-venv)
  1441. (set-variable 'flycheck-executable-find
  1442. '(lambda (e)
  1443. (with-venv
  1444. (executable-find e)))
  1445. t)))
  1446. (defun my-update-flycheck-flake8-error-level-alist ()
  1447. "Update `flycheck-flake8-error-level-alist'."
  1448. (defvar flycheck-flake8-error-level-alist)
  1449. ;; (add-to-list 'flycheck-flake8-error-level-alist
  1450. ;; '("^D.*$" . warning))
  1451. (set-variable 'flycheck-flake8-error-level-alist
  1452. nil)
  1453. )
  1454. (add-hook 'python-mode-hook
  1455. 'my-set-venv-flycheck-executable-find)
  1456. (add-hook 'python-mode-hook
  1457. 'my-update-flycheck-flake8-error-level-alist)
  1458. (when (fboundp 'with-venv-info-mode)
  1459. (add-hook 'python-mode-hook
  1460. 'with-venv-info-mode))
  1461. ;; Run multiple chekcers
  1462. ;; https://github.com/flycheck/flycheck/issues/186
  1463. (add-hook 'python-mode-hook
  1464. (lambda ()
  1465. ;; Currently on python-mode eldoc-mode sometimes print
  1466. ;; wired message on "from" keyword:
  1467. ;;var from = require("./from")
  1468. (eldoc-mode -1)))
  1469. ;; http://fukuyama.co/foreign-regexp
  1470. '(and (require 'foreign-regexp nil t)
  1471. (progn
  1472. (setq foreign-regexp/regexp-type 'perl)
  1473. '(setq reb-re-syntax 'foreign-regexp)
  1474. ))
  1475. (with-eval-after-load 'sql
  1476. (require 'sql-indent nil t))
  1477. (add-to-list 'auto-mode-alist
  1478. '("\\.hql\\'" . sql-mode))
  1479. (when (fboundp 'git-command)
  1480. (define-key ctl-x-map "g" 'git-command))
  1481. (when (fboundp 'gited-list)
  1482. (defalias 'gited 'gited-list))
  1483. (when (fboundp 'global-git-commit-mode)
  1484. (add-hook 'after-first-visit-hook
  1485. 'global-git-commit-mode)
  1486. (add-hook 'after-first-visit-hook
  1487. 'git-commit-setup-check-buffer))
  1488. (with-eval-after-load 'git-commit
  1489. (add-hook 'git-commit-setup-hook
  1490. 'turn-off-auto-fill t))
  1491. (with-eval-after-load 'rst
  1492. (defvar rst-mode-map)
  1493. (define-key rst-mode-map (kbd "C-m") 'newline-and-indent))
  1494. (with-eval-after-load 'jdee
  1495. (add-hook 'jdee-mode-hook
  1496. (lambda ()
  1497. (make-local-variable 'global-mode-string)
  1498. (add-to-list 'global-mode-string
  1499. mode-line-position))))
  1500. ;; Cannot enable error thrown. Why???
  1501. ;; https://github.com/m0smith/malabar-mode#Installation
  1502. ;; (when (require 'malabar-mode nil t)
  1503. ;; (add-to-list 'load-path
  1504. ;; (expand-file-name (concat user-emacs-directory "/cedet")))
  1505. ;; (require 'cedet-devel-load nil t)
  1506. ;; (eval-after-init (activate-malabar-mode)))
  1507. (with-eval-after-load 'make-mode
  1508. (defvar makefile-mode-map (make-sparse-keymap))
  1509. (define-key makefile-mode-map (kbd "C-m") 'newline-and-indent)
  1510. ;; this functions is set in write-file-functions, i cannot find any
  1511. ;; good way to remove this.
  1512. (fset 'makefile-warn-suspicious-lines 'ignore))
  1513. (with-eval-after-load 'verilog-mode
  1514. (defvar verilog-mode-map (make-sparse-keymap))
  1515. (define-key verilog-mode-map ";" 'self-insert-command))
  1516. (setq diff-switches "-u")
  1517. (autoload 'diff-goto-source "diff-mode" nil t)
  1518. (with-eval-after-load 'diff-mode
  1519. ;; (when (and (eq major-mode
  1520. ;; 'diff-mode)
  1521. ;; (not buffer-file-name))
  1522. ;; ;; do not pass when major-mode is derived mode of diff-mode
  1523. ;; (view-mode 1))
  1524. (set-face-attribute 'diff-header nil
  1525. :foreground nil
  1526. :background nil
  1527. :weight 'bold)
  1528. (set-face-attribute 'diff-file-header nil
  1529. :foreground nil
  1530. :background nil
  1531. :weight 'bold)
  1532. (set-face-foreground 'diff-index "blue")
  1533. (set-face-attribute 'diff-hunk-header nil
  1534. :foreground "cyan"
  1535. :weight 'normal)
  1536. (set-face-attribute 'diff-context nil
  1537. ;; :foreground "white"
  1538. :foreground nil
  1539. :weight 'normal)
  1540. (set-face-foreground 'diff-removed "red")
  1541. (set-face-foreground 'diff-added "green")
  1542. (set-face-background 'diff-removed nil)
  1543. (set-face-background 'diff-added nil)
  1544. (set-face-attribute 'diff-changed nil
  1545. :foreground "magenta"
  1546. :weight 'normal)
  1547. (set-face-attribute 'diff-refine-changed nil
  1548. :foreground nil
  1549. :background nil
  1550. :weight 'bold
  1551. :inverse-video t)
  1552. ;; Annoying !
  1553. ;;(diff-auto-refine-mode)
  1554. )
  1555. ;; (ffap-bindings)
  1556. (set-variable 'browse-url-browser-function
  1557. 'eww-browse-url)
  1558. (set-variable 'sh-here-document-word "__EOC__")
  1559. (with-eval-after-load 'adoc-mode
  1560. (defvar adoc-mode-map)
  1561. (define-key adoc-mode-map (kbd "C-m") 'newline))
  1562. (when (fboundp 'adoc-mode)
  1563. (setq auto-mode-alist
  1564. `(("\\.adoc\\'" . adoc-mode)
  1565. ("\\.asciidoc\\'" . adoc-mode)
  1566. ,@auto-mode-alist)))
  1567. (with-eval-after-load 'markup-faces
  1568. ;; Is this too match ?
  1569. (set-face-foreground 'markup-meta-face
  1570. "color-245")
  1571. (set-face-foreground 'markup-meta-hide-face
  1572. "color-245")
  1573. )
  1574. ;; TODO: check if this is required
  1575. (with-eval-after-load 'groovy-mode
  1576. (defvar groovy-mode-map)
  1577. (define-key groovy-mode-map "(" 'self-insert-command)
  1578. (define-key groovy-mode-map ")" 'self-insert-command)
  1579. (define-key groovy-mode-map (kbd "C-m") 'newline-and-indent)
  1580. )
  1581. (when (fboundp 'groovy-mode)
  1582. (add-to-list 'auto-mode-alist
  1583. '("build\\.gradle\\'" . groovy-mode)))
  1584. (add-to-list 'auto-mode-alist
  1585. '("\\.gawk\\'" . awk-mode))
  1586. (with-eval-after-load 'yaml-mode
  1587. (defvar yaml-mode-map (make-sparse-keymap))
  1588. (define-key yaml-mode-map (kbd "C-m") 'newline))
  1589. (with-eval-after-load 'html-mode
  1590. (defvar html-mode-map (make-sparse-keymap))
  1591. (define-key html-mode-map (kbd "C-m") 'reindent-then-newline-and-indent))
  1592. (with-eval-after-load 'text-mode
  1593. (define-key text-mode-map (kbd "C-m") 'newline))
  1594. (with-eval-after-load 'info
  1595. (defvar Info-additional-directory-list)
  1596. (dolist (dir (directory-files (concat user-emacs-directory
  1597. "info")
  1598. t
  1599. "^[^.].*"))
  1600. (when (file-directory-p dir)
  1601. (add-to-list 'Info-additional-directory-list
  1602. dir)))
  1603. (let ((dir (expand-file-name "~/.brew/share/info")))
  1604. (when (file-directory-p dir)
  1605. (add-to-list 'Info-additional-directory-list
  1606. dir))))
  1607. (with-eval-after-load 'apropos
  1608. (defvar apropos-mode-map (make-sparse-keymap))
  1609. (define-key apropos-mode-map "n" 'next-line)
  1610. (define-key apropos-mode-map "p" 'previous-line))
  1611. ;; `isearch' library does not call `provide' so cannot use with-eval-after-load
  1612. ;; (define-key isearch-mode-map
  1613. ;; (kbd "C-j") 'isearch-other-control-char)
  1614. ;; (define-key isearch-mode-map
  1615. ;; (kbd "C-k") 'isearch-other-control-char)
  1616. ;; (define-key isearch-mode-map
  1617. ;; (kbd "C-h") 'isearch-other-control-char)
  1618. (define-key isearch-mode-map (kbd "C-h") 'isearch-del-char)
  1619. (define-key isearch-mode-map (kbd "M-r")
  1620. 'isearch-query-replace-regexp)
  1621. ;; do not cleanup isearch highlight: use `lazy-highlight-cleanup' to remove
  1622. (setq lazy-highlight-cleanup nil)
  1623. ;; face for isearch highlighing
  1624. (set-face-attribute 'lazy-highlight
  1625. nil
  1626. :foreground `unspecified
  1627. :background `unspecified
  1628. :underline t
  1629. ;; :weight `bold
  1630. )
  1631. (add-hook 'outline-mode-hook
  1632. (lambda ()
  1633. (when (string-match "\\.md\\'" buffer-file-name)
  1634. (setq-local outline-regexp "#+ "))))
  1635. (add-hook 'outline-mode-hook
  1636. 'outline-show-all)
  1637. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  1638. (with-eval-after-load 'markdown-mode
  1639. (defvar gfm-mode-map)
  1640. (define-key gfm-mode-map (kbd "C-m") 'electric-indent-just-newline)
  1641. (define-key gfm-mode-map "`" nil) ;; markdown-electric-backquote
  1642. )
  1643. (when (fboundp 'gfm-mode)
  1644. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'gfm-mode))
  1645. (add-hook 'markdown-mode-hook
  1646. 'outline-minor-mode)
  1647. (add-hook 'markdown-mode-hook
  1648. (lambda ()
  1649. (setq-local comment-start ";")))
  1650. )
  1651. ;; http://keisanbutsuriya.hateblo.jp/entry/2015/02/10/152543
  1652. ;; M-$ to ispell word
  1653. ;; M-x flyspell-buffer to highlight all suspicious words
  1654. (when (executable-find "aspell")
  1655. (set-variable 'ispell-program-name "aspell")
  1656. (set-variable 'ispell-extra-args '("--lang=en_US")))
  1657. (with-eval-after-load 'ispell
  1658. (add-to-list 'ispell-skip-region-alist '("[^\000-\377]+")))
  1659. (when (fboundp 'flyspell-mode)
  1660. (add-hook 'text-mode-hook
  1661. 'flyspell-mode))
  1662. (when (fboundp 'flyspell-prog-mode)
  1663. (add-hook 'prog-mode-hook
  1664. 'flyspell-prog-mode))
  1665. ;; c-mode
  1666. ;; http://www.emacswiki.org/emacs/IndentingC
  1667. ;; http://en.wikipedia.org/wiki/Indent_style
  1668. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  1669. ;; http://seesaawiki.jp/whiteflare503/d/Emacs%20%a5%a4%a5%f3%a5%c7%a5%f3%a5%c8
  1670. (with-eval-after-load 'cc-vars
  1671. (defvar c-default-style nil)
  1672. (add-to-list 'c-default-style
  1673. '(c-mode . "k&r"))
  1674. (add-to-list 'c-default-style
  1675. '(c++-mode . "k&r")))
  1676. (with-eval-after-load 'js2-mode
  1677. ;; currently do not use js2-mode
  1678. ;; (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  1679. ;; (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode))
  1680. ;; (defvar js2-mode-map (make-sparse-keymap))
  1681. ;; (define-key js2-mode-map (kbd "C-m") (lambda ()
  1682. ;; (interactive)
  1683. ;; (js2-enter-key)
  1684. ;; (indent-for-tab-command)))
  1685. ;; (add-hook (kill-local-variable 'before-save-hook)
  1686. ;; 'js2-before-save)
  1687. ;; (add-hook 'before-save-hook
  1688. ;; 'my-indent-buffer
  1689. ;; nil
  1690. ;; t)
  1691. )
  1692. (add-to-list 'interpreter-mode-alist
  1693. '("node" . js-mode))
  1694. (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
  1695. (with-eval-after-load 'uniquify
  1696. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  1697. (setq uniquify-ignore-buffers-re "*[^*]+*")
  1698. (setq uniquify-min-dir-content 1))
  1699. (with-eval-after-load 'view
  1700. (defvar view-mode-map (make-sparse-keymap))
  1701. (define-key view-mode-map "j" 'scroll-up-line)
  1702. (define-key view-mode-map "k" 'scroll-down-line)
  1703. (define-key view-mode-map "v" 'toggle-read-only)
  1704. (define-key view-mode-map "q" 'bury-buffer)
  1705. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  1706. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  1707. ;; (define-key view-mode-map
  1708. ;; "n" 'nonincremental-repeat-search-forward)
  1709. ;; (define-key view-mode-map
  1710. ;; "N" 'nonincremental-repeat-search-backward)
  1711. ;; N conflicts with git-walktree
  1712. ;; (define-key view-mode-map "/" 'isearch-forward-regexp)
  1713. ;; (define-key view-mode-map "?" 'isearch-backward-regexp)
  1714. ;; (define-key view-mode-map "n" 'isearch-repeat-forward)
  1715. ;; (define-key view-mode-map "N" 'isearch-repeat-backward)
  1716. (define-key view-mode-map (kbd "C-m") 'my-rgrep-symbol-at-point))
  1717. (global-set-key "\M-r" 'view-mode)
  1718. ;; (setq view-read-only t)
  1719. (with-eval-after-load 'term
  1720. (defvar term-raw-map (make-sparse-keymap))
  1721. (define-key term-raw-map (kbd "C-x")
  1722. (lookup-key (current-global-map)
  1723. (kbd "C-x"))))
  1724. (add-hook 'term-mode-hook
  1725. (lambda ()
  1726. ;; Stop current line highlighting
  1727. (set-variable 'hl-line-range-function (lambda () '(0 . 0)) t)
  1728. (set-variable 'scroll-margin 0 t)
  1729. ))
  1730. (set-variable 'term-buffer-maximum-size 20480)
  1731. (set-variable 'term-suppress-hard-newline t)
  1732. (add-hook 'Man-mode-hook
  1733. (lambda ()
  1734. (view-mode 1)
  1735. (setq truncate-lines nil)))
  1736. (set-variable 'Man-notify-method (if window-system
  1737. 'newframe
  1738. 'aggressive))
  1739. (set-variable 'woman-cache-filename (expand-file-name (concat user-emacs-directory
  1740. "woman_cache.el")))
  1741. ;; not work because man.el will be loaded when man called
  1742. (defalias 'man 'woman)
  1743. (add-to-list 'auto-mode-alist
  1744. '("tox\\.ini\\'" . conf-unix-mode))
  1745. (when (fboundp 'toml-mode)
  1746. (add-to-list 'auto-mode-alist
  1747. '("/tox\\.ini\\'" . toml-mode))
  1748. (add-to-list 'auto-mode-alist
  1749. '("/Pipfile\\'" . toml-mode))
  1750. (add-to-list 'auto-mode-alist
  1751. '("/poetry\\.lock\\'" . toml-mode))
  1752. )
  1753. (when (fboundp 'json-mode)
  1754. (add-to-list 'auto-mode-alist
  1755. '("/Pipfile\\.lock\\'" . json-mode)))
  1756. (add-hook 'go-mode-hook
  1757. (lambda()
  1758. (defvar go-mode-map)
  1759. (add-hook 'before-save-hook' 'gofmt-before-save nil t)
  1760. (define-key go-mode-map (kbd "M-.") 'godef-jump)))
  1761. (when (fboundp 'k8s-mode)
  1762. (add-to-list 'auto-mode-alist
  1763. '("\\.k8s\\'" . k8s-mode)))
  1764. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1765. ;; buffers
  1766. (defvar bs-configurations)
  1767. (declare-function bs-set-configuration "bs")
  1768. (declare-function bs-refresh "bs")
  1769. (declare-function bs-message-without-log "bs")
  1770. (declare-function bs--current-config-message "bs")
  1771. (with-eval-after-load 'bs
  1772. (add-to-list 'bs-configurations
  1773. '("specials" "^\\*" nil ".*" nil nil))
  1774. (add-to-list 'bs-configurations
  1775. '("files-and-specials" "^\\*" buffer-file-name ".*" nil nil))
  1776. (defvar bs-mode-map)
  1777. (defvar bs-current-configuration)
  1778. (define-key bs-mode-map (kbd "t")
  1779. ;; TODO: fix toggle feature
  1780. (lambda ()
  1781. (interactive)
  1782. (if (string= "specials"
  1783. bs-current-configuration)
  1784. (bs-set-configuration "files")
  1785. (bs-set-configuration "specials"))
  1786. (bs-refresh)
  1787. (bs-message-without-log "%s"
  1788. (bs--current-config-message))))
  1789. ;; (setq bs-configurations (list
  1790. ;; '("processes" nil get-buffer-process ".*" nil nil)
  1791. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
  1792. ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
  1793. )
  1794. (when (fboundp 'bs-show)
  1795. (defalias 'list-buffers 'bs-show)
  1796. (set-variable 'bs-default-configuration "files-and-specials")
  1797. (set-variable 'bs-default-sort-name "by nothing")
  1798. (add-hook 'bs-mode-hook
  1799. (lambda ()
  1800. (setq-local scroll-margin 0)
  1801. (setq-local header-line-format nil)
  1802. (setq-local mode-line-format nil)
  1803. )))
  1804. ;;(iswitchb-mode 1)
  1805. (icomplete-mode)
  1806. (defun iswitchb-buffer-display-other-window ()
  1807. "Do iswitchb in other window."
  1808. (interactive)
  1809. (let ((iswitchb-default-method 'display))
  1810. (call-interactively 'iswitchb-buffer)))
  1811. ;; buffer killing
  1812. ;; (defun my-delete-window-killing-buffer () nil)
  1813. (defun my-query-kill-current-buffer ()
  1814. "Interactively kill current buffer."
  1815. (interactive)
  1816. (if (y-or-n-p (concat "kill current buffer? :"))
  1817. (kill-buffer (current-buffer))))
  1818. (defun my-force-query-kill-current-buffer ()
  1819. "Interactively kill current buffer."
  1820. (interactive)
  1821. (when (y-or-n-p (concat "kill current buffer? :"))
  1822. (let ((kill-buffer-hook nil)
  1823. (kill-buffer-query-functions nil))
  1824. (kill-buffer (current-buffer)))))
  1825. ;;(global-set-key "\C-xk" 'my-query-kill-current-buffer)
  1826. ;; Originally C-x C-k -> kmacro-keymap
  1827. ;; (global-set-key "\C-x\C-k" 'kmacro-keymap)
  1828. (global-set-key (kbd "C-x C-k") 'my-query-kill-current-buffer)
  1829. (substitute-key-definition 'kill-buffer
  1830. 'my-query-kill-current-buffer
  1831. global-map)
  1832. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1833. ;; dired
  1834. (defun my-file-head (filename &optional n)
  1835. "Return list of first N lines of file FILENAME."
  1836. ;; TODO: Fix for janapese text
  1837. ;; TODO: Fix for short text
  1838. (let ((num (or n 10))
  1839. (size 100)
  1840. (beg 0)
  1841. (end 0)
  1842. (result '())
  1843. (read -1))
  1844. (with-temp-buffer
  1845. (erase-buffer)
  1846. (while (or (<= (count-lines (point-min)
  1847. (point-max))
  1848. num)
  1849. (eq read 0))
  1850. (setq end (+ beg size))
  1851. (setq read (nth 1 (insert-file-contents-literally filename
  1852. nil
  1853. beg
  1854. end)))
  1855. (goto-char (point-max))
  1856. (setq beg (+ beg size)))
  1857. (goto-char (point-min))
  1858. (while (< (length result) num)
  1859. (let ((start (point)))
  1860. (forward-line 1)
  1861. (setq result
  1862. `(,@result ,(buffer-substring-no-properties start
  1863. (point))))))
  1864. result
  1865. ;; (buffer-substring-no-properties (point-min)
  1866. ;; (progn
  1867. ;; (forward-line num)
  1868. ;; (point)))
  1869. )))
  1870. ;; (apply 'concat (my-file-head "./shrc" 10)
  1871. (declare-function dired-get-filename "dired" t)
  1872. (defun my-dired-echo-file-head (arg)
  1873. "Echo head of current file.
  1874. ARG is num to show, or defaults to 7."
  1875. (interactive "P")
  1876. (let ((f (dired-get-filename)))
  1877. (message "%s"
  1878. (apply 'concat
  1879. (my-file-head f
  1880. 7)))))
  1881. (declare-function dired-get-marked-files "dired")
  1882. (defun my-dired-diff ()
  1883. "Show diff of marked file and file of current line."
  1884. (interactive)
  1885. (let ((files (dired-get-marked-files nil nil nil t)))
  1886. (if (eq (car files)
  1887. t)
  1888. (diff (cadr files) (dired-get-filename))
  1889. (message "One file must be marked!"))))
  1890. (defun dired-get-file-info ()
  1891. "Print information of current line file."
  1892. (interactive)
  1893. (let* ((file (dired-get-filename t))
  1894. (quoted (shell-quote-argument file)))
  1895. (if (file-directory-p file)
  1896. (progn
  1897. (message "Calculating disk usage...")
  1898. (let ((du (or (executable-find "gdu")
  1899. (executable-find "du")
  1900. (error "du not found"))))
  1901. (shell-command (concat du
  1902. " -hsD "
  1903. quoted))))
  1904. (shell-command (concat "file "
  1905. quoted)))))
  1906. (defun my-dired-scroll-up ()
  1907. "Scroll up."
  1908. (interactive)
  1909. (my-dired-previous-line (- (window-height) 1)))
  1910. (defun my-dired-scroll-down ()
  1911. "Scroll down."
  1912. (interactive)
  1913. (my-dired-next-line (- (window-height) 1)))
  1914. ;; (defun my-dired-forward-line (arg)
  1915. ;; ""
  1916. ;; (interactive "p"))
  1917. (declare-function dired-get-subdir "dired")
  1918. (declare-function dired-move-to-filename "dired")
  1919. (defun my-dired-previous-line (arg)
  1920. "Move ARG lines up."
  1921. (interactive "p")
  1922. (if (> arg 0)
  1923. (progn
  1924. (if (eq (line-number-at-pos)
  1925. 1)
  1926. (goto-char (point-max))
  1927. (forward-line -1))
  1928. (my-dired-previous-line (if (or (dired-get-filename nil t)
  1929. (dired-get-subdir))
  1930. (- arg 1)
  1931. arg)))
  1932. (dired-move-to-filename)))
  1933. (defun my-dired-next-line (arg)
  1934. "Move ARG lines down."
  1935. (interactive "p")
  1936. (if (> arg 0)
  1937. (progn
  1938. (if (eq (point)
  1939. (point-max))
  1940. (goto-char (point-min))
  1941. (forward-line 1))
  1942. (my-dired-next-line (if (or (dired-get-filename nil t)
  1943. (dired-get-subdir))
  1944. (- arg 1)
  1945. arg)))
  1946. (dired-move-to-filename)))
  1947. (defun my-tramp-remote-find-file (f)
  1948. "Open F."
  1949. (interactive (list (read-file-name "My Find File Tramp: "
  1950. "/scp:"
  1951. nil ;; "/scp:"
  1952. (confirm-nonexistent-file-or-buffer))))
  1953. (find-file f))
  1954. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  1955. (if (eq window-system 'mac)
  1956. (setq dired-listing-switches "-lhF")
  1957. (setq dired-listing-switches "-lhF --time-style=long-iso")
  1958. )
  1959. (setq dired-listing-switches "-lhF")
  1960. ;; when using dired-find-alternate-file
  1961. ;; reuse current dired buffer for the file to open
  1962. ;; (put 'dired-find-alternate-file 'disabled nil)
  1963. (set-variable 'dired-ls-F-marks-symlinks t)
  1964. (set-variable 'ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
  1965. (set-variable 'ls-lisp-dirs-first t)
  1966. (set-variable 'ls-lisp-use-localized-time-format t)
  1967. (set-variable 'ls-lisp-format-time-list
  1968. '("%Y-%m-%d %H:%M"
  1969. "%Y-%m-%d "))
  1970. (set-variable 'dired-dwim-target t)
  1971. (set-variable 'dired-isearch-filenames t)
  1972. (set-variable 'dired-hide-details-hide-symlink-targets nil)
  1973. (set-variable 'dired-hide-details-hide-information-lines nil)
  1974. (set-variable 'dired-deletion-confirmer 'y-or-n-p)
  1975. (set-variable 'dired-recursive-deletes 'always)
  1976. ;; (add-hook 'dired-after-readin-hook
  1977. ;; 'my-replace-nasi-none)
  1978. (with-eval-after-load 'dired
  1979. (require 'ls-lisp nil t)
  1980. (defvar dired-mode-map (make-sparse-keymap))
  1981. ;; dired-do-chgrp sometimes cause system hung
  1982. (define-key dired-mode-map "G" 'ignore)
  1983. (define-key dired-mode-map "e" 'wdired-change-to-wdired-mode)
  1984. (define-key dired-mode-map "i" 'dired-get-file-info)
  1985. ;; (define-key dired-mode-map "f" 'find-file)
  1986. (define-key dired-mode-map "f" 'my-fzf-or-find-file)
  1987. (define-key dired-mode-map "z" 'fzf)
  1988. (define-key dired-mode-map "!" 'shell-command)
  1989. (define-key dired-mode-map "&" 'async-shell-command)
  1990. (define-key dired-mode-map "X" 'dired-do-async-shell-command)
  1991. (define-key dired-mode-map "=" 'my-dired-diff)
  1992. (define-key dired-mode-map "B" 'gtkbm-add-current-dir)
  1993. (define-key dired-mode-map "b" 'gtkbm)
  1994. (define-key dired-mode-map "h" 'my-dired-echo-file-head)
  1995. (define-key dired-mode-map (kbd "TAB") 'other-window)
  1996. ;; (define-key dired-mode-map "P" 'my-dired-do-pack-or-unpack)
  1997. (define-key dired-mode-map "/" 'dired-isearch-filenames)
  1998. (define-key dired-mode-map (kbd "DEL") 'dired-up-directory)
  1999. (define-key dired-mode-map (kbd "C-h") 'dired-up-directory)
  2000. (substitute-key-definition 'dired-next-line
  2001. 'my-dired-next-line
  2002. dired-mode-map)
  2003. (substitute-key-definition 'dired-previous-line
  2004. 'my-dired-previous-line
  2005. dired-mode-map)
  2006. ;; (define-key dired-mode-map (kbd "C-p") 'my-dired-previous-line)
  2007. ;; (define-key dired-mode-map (kbd "p") 'my-dired-previous-line)
  2008. ;; (define-key dired-mode-map (kbd "C-n") 'my-dired-next-line)
  2009. ;; (define-key dired-mode-map (kbd "n") 'my-dired-next-line)
  2010. (define-key dired-mode-map (kbd "<left>") 'my-dired-scroll-up)
  2011. (define-key dired-mode-map (kbd "<right>") 'my-dired-scroll-down)
  2012. (define-key dired-mode-map (kbd "ESC p") 'my-dired-scroll-up)
  2013. (define-key dired-mode-map (kbd "ESC n") 'my-dired-scroll-down)
  2014. (add-hook 'dired-mode-hook
  2015. (lambda ()
  2016. (when (fboundp 'dired-hide-details-mode)
  2017. (dired-hide-details-mode t)
  2018. (local-set-key "l" 'dired-hide-details-mode))
  2019. (let ((file "._Icon\015"))
  2020. (when nil
  2021. '(file-readable-p file)
  2022. (delete-file file)))))
  2023. (when (fboundp 'pack-dired-dwim)
  2024. (with-eval-after-load 'dired
  2025. (define-key dired-mode-map "P" 'pack-dired-dwim)))
  2026. (when (fboundp 'dired-list-all-mode)
  2027. (setq dired-listing-switches "-lhF")
  2028. (with-eval-after-load 'dired
  2029. (define-key dired-mode-map "a" 'dired-list-all-mode))))
  2030. (when (fboundp 'dired-filter-mode)
  2031. (add-hook 'dired-mode-hook
  2032. 'dired-filter-mode))
  2033. (set-variable 'dired-filter-stack nil)
  2034. ;; Currently disabled in favor of dired-from-git-ls-files
  2035. ;; (define-key ctl-x-map "f" 'find-dired)
  2036. (defvar my-dired-git-ls-files-history
  2037. "History for `my-dired-git-ls-files'." nil)
  2038. (defun my-dired-git-ls-files (arg)
  2039. "Dired from git ls-files."
  2040. (interactive (list
  2041. (read-shell-command "git ls-files: "
  2042. "git ls-files -z ")))
  2043. (pop-to-buffer-same-window
  2044. (dired-noselect `(,default-directory
  2045. ,@(split-string (shell-command-to-string arg)
  2046. "\0" t))
  2047. ""))
  2048. )
  2049. (define-key ctl-x-map (kbd "G") 'my-dired-git-ls-files)
  2050. (with-eval-after-load 'dired
  2051. (defvar dired-mode-map (make-sparse-keymap))
  2052. (define-key dired-mode-map "G" 'my-dired-git-ls-files))
  2053. (with-eval-after-load 'pack
  2054. (set-variable 'pack-silence
  2055. t)
  2056. (defvar pack-program-alist)
  2057. (add-to-list 'pack-program-alist
  2058. '("\\.txz\\'" :pack "tar -cJf" :unpack "tar -xf"))
  2059. (when (executable-find "aunpack")
  2060. (add-to-list 'pack-program-alist
  2061. ' ("\\.zip\\'"
  2062. :pack ("zip" "-r" archive sources)
  2063. :pack-append ("zip" "-r" archive sources)
  2064. :unpack ("aunpack" archive))))
  2065. )
  2066. ;; dired-k
  2067. ;; Current HEAD of original repo is broken
  2068. ;; https://github.com/syohex/emacs-dired-k/issues/45
  2069. (declare-function dired-k-no-revert "dired-k")
  2070. (when (fboundp 'dired-k)
  2071. (set-variable 'dired-k-style 'git)
  2072. ;; What is the best way of doing this?
  2073. (with-eval-after-load 'dired-k
  2074. (fset 'dired-k--highlight-by-file-attribyte 'ignore))
  2075. ;; (set-variable 'dired-k-size-colors
  2076. ;; `((,most-positive-fixnum)))
  2077. ;; (set-variable 'dired-k-date-colors
  2078. ;; `((,most-positive-fixnum)))
  2079. (let* ((pkg (cadr (assq 'dired-k
  2080. package-alist)))
  2081. (version-str (package-version-join (package-desc-version pkg))))
  2082. ;; Currently dired-k HEAD of original repository is broken so do not use that
  2083. (when (string= version-str
  2084. "20171017.1228")
  2085. ;; always execute dired-k when dired buffer is opened and reverted
  2086. (add-hook 'dired-after-readin-hook #'dired-k-no-revert)
  2087. ;; This still create index.lock files...........................
  2088. ;; (add-hook 'switch-buffer-functions
  2089. ;; (lambda (prev cur)
  2090. ;; (when (derived-mode-p 'dired-mode)
  2091. ;; (dired-k-no-revert))))
  2092. )))
  2093. ;; (when (eval-and-compile (require 'dired-rainbow nil t))
  2094. ;; (dired-rainbow-define gtags "brightblack" "GTAGS"))
  2095. ;; ?
  2096. ;; (set-variable 'dired-omit-files
  2097. ;; (rx (or (regexp "^\\.?#")
  2098. ;; (regexp "^\\.$")
  2099. ;; (regexp "^\\.\\.$")
  2100. ;; (regexp "^GPATH$")
  2101. ;; (regexp "^GRTAGS$")
  2102. ;; (regexp "^GTAGS$")
  2103. ;; )))
  2104. (with-eval-after-load 'diredfl
  2105. (set-face-foreground 'diredfl-file-name nil)
  2106. )
  2107. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2108. ;; misc funcs
  2109. (define-key ctl-x-map "T" 'git-worktree)
  2110. (define-key ctl-x-map "W" 'git-walktree)
  2111. (when (fboundp 'browse-url-default-macosx-browser)
  2112. (defalias 'browse-osx 'browse-url-default-macosx-browser))
  2113. (defalias 'qcalc 'quick-calc)
  2114. (defun memo (&optional dir)
  2115. "Open memo.txt in DIR."
  2116. (interactive)
  2117. (pop-to-buffer (find-file-noselect (concat (if dir
  2118. (file-name-as-directory dir)
  2119. "")
  2120. "memo.txt"))))
  2121. ;; TODO: remember-projectile
  2122. (set (defvar my-privnotes-path nil
  2123. "My privnotes repository path.")
  2124. (expand-file-name "~/my/privnotes"))
  2125. (defun my-privnotes-readme (dir)
  2126. "Open my privnotes DIR."
  2127. (interactive (list
  2128. (read-file-name "Privnotes: "
  2129. (expand-file-name (format-time-string "%Y%m%d_")
  2130. my-privnotes-path))))
  2131. (let ((path (expand-file-name "README.md" dir)))
  2132. (with-current-buffer (find-file path)
  2133. (unless (file-exists-p path)
  2134. (insert (file-name-base dir)
  2135. "\n"
  2136. "=======\n"
  2137. "\n\n")))))
  2138. (define-key ctl-x-map "p" 'my-privnotes-readme)
  2139. (set (defvar my-rgrep-alist nil
  2140. "Alist of rgrep command.
  2141. Each element is in the form like (NAME SEXP COMMAND), where SEXP returns the
  2142. condition to choose COMMAND when evaluated.")
  2143. `(
  2144. ;; ripgrep
  2145. ("rg"
  2146. (executable-find "rg")
  2147. "rg -nH --no-heading --hidden --glob '!.git/' --smart-case -M 1280 ")
  2148. ;; git grep
  2149. ("gitgrep"
  2150. (eq 0
  2151. (shell-command "git rev-parse --git-dir"))
  2152. "git --no-pager grep -nH -e ")
  2153. ;; sift
  2154. ("sift"
  2155. (executable-find "sift")
  2156. ("sift --binary-skip --filename --line-number --git --smart-case "))
  2157. ;; the silver searcher
  2158. ("ag"
  2159. (executable-find "ag")
  2160. "ag --nogroup --nopager --filename ")
  2161. ;; ack
  2162. ("ack"
  2163. (executable-find "ack")
  2164. "ack --nogroup --nopager --with-filename ")
  2165. ;; gnu global
  2166. ("global"
  2167. (and (require 'ggtags nil t)
  2168. (executable-find "global")
  2169. (ggtags-current-project-root))
  2170. "global --result grep ")
  2171. ;; grep
  2172. ("grep"
  2173. t
  2174. ,(concat "find . "
  2175. "-path '*/.git' -prune -o "
  2176. "-path '*/.svn' -prune -o "
  2177. "-type f -print0 | "
  2178. "xargs -0 grep -nH -e "))
  2179. )
  2180. )
  2181. (defvar my-rgrep-default nil
  2182. "Default command name for my-rgrep.")
  2183. (defun my-rgrep-grep-command (&optional name alist)
  2184. "Return recursive grep command for current directory or nil.
  2185. If NAME is given, use that without testing.
  2186. Commands are searched from ALIST."
  2187. (if alist
  2188. (if name
  2189. ;; if name is given search that from alist and return the command
  2190. (nth 2 (assoc name
  2191. alist))
  2192. ;; if name is not given try test in 1th elem
  2193. (let ((car (car alist))
  2194. (cdr (cdr alist)))
  2195. (if (eval (nth 1 car))
  2196. ;; if the condition is true return the command
  2197. (nth 2 car)
  2198. ;; try next one
  2199. (and cdr
  2200. (my-rgrep-grep-command name cdr)))))
  2201. ;; if alist is not given set default value
  2202. (my-rgrep-grep-command name my-rgrep-alist)))
  2203. (declare-function projectile-project-p "projectile")
  2204. (declare-function projectile-with-default-dir "projectile")
  2205. (declare-function projectile-project-root "projectile")
  2206. (defun my-rgrep (command-args)
  2207. "My recursive grep. Run COMMAND-ARGS.
  2208. If prefix argument is given, use current symbol as default search target
  2209. and search from projectile root (if projectile is available)."
  2210. (interactive (let ((cmd (my-rgrep-grep-command my-rgrep-default
  2211. nil)))
  2212. (if cmd
  2213. (list (read-shell-command "grep command: "
  2214. (concat cmd
  2215. (if current-prefix-arg
  2216. (thing-at-point 'symbol t)
  2217. ""))
  2218. 'grep-find-history))
  2219. (error "My-Rgrep: Command for rgrep not found")
  2220. )))
  2221. (if (and current-prefix-arg
  2222. (eval-and-compile (require 'projectile nil t))
  2223. (projectile-project-p))
  2224. (projectile-with-default-dir (projectile-project-root)
  2225. (compilation-start command-args
  2226. 'grep-mode))
  2227. (compilation-start command-args
  2228. 'grep-mode)))
  2229. (defun my-rgrep-thing-at-point-projectile-root ()
  2230. "My recursive grep to find thing at point from project root."
  2231. (interactive)
  2232. (let* ((cmd (my-rgrep-grep-command my-rgrep-default
  2233. nil))
  2234. (command-args
  2235. (if cmd
  2236. (concat cmd
  2237. (or (thing-at-point 'symbol t)
  2238. (error "No symbol at point")))
  2239. (error "My-Rgrep: Command for rgrep not found"))))
  2240. (if (eval-and-compile (require 'projectile nil t))
  2241. (projectile-with-default-dir (or (projectile-project-root)
  2242. default-directory)
  2243. (compilation-start command-args
  2244. 'grep-mode))
  2245. (compilation-start command-args
  2246. 'grep-mode))))
  2247. (defmacro define-my-rgrep (name)
  2248. "Define rgrep for NAME."
  2249. `(defun ,(intern (concat "my-rgrep-"
  2250. name)) ()
  2251. ,(format "My recursive grep by %s."
  2252. name)
  2253. (interactive)
  2254. (let ((my-rgrep-default ,name))
  2255. (if (called-interactively-p 'any)
  2256. (call-interactively 'my-rgrep)
  2257. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  2258. )
  2259. (define-my-rgrep "ack")
  2260. (define-my-rgrep "ag")
  2261. (define-my-rgrep "rg")
  2262. (define-my-rgrep "sift")
  2263. (define-my-rgrep "gitgrep")
  2264. (define-my-rgrep "grep")
  2265. (define-my-rgrep "global")
  2266. (define-key ctl-x-map "s" 'my-rgrep)
  2267. (define-key ctl-x-map "." 'my-rgrep-thing-at-point-projectile-root)
  2268. (defun my-occur (regexp &optional region)
  2269. "My occur command to search REGEXP to search REGION."
  2270. (interactive (list (read-string "List lines matching regexp: "
  2271. (thing-at-point 'symbol t))))
  2272. (occur regexp nil region))
  2273. (define-key ctl-x-map (kbd "C-o") 'my-occur)
  2274. (set-variable 'dumb-jump-prefer-searcher 'rg)
  2275. (defalias 'make 'compile)
  2276. (define-key ctl-x-map "c" 'compile)
  2277. (autoload 'pb/push-item "pushbullet")
  2278. (defun my-pushbullet-note (text &optional title)
  2279. "Push TEXT with optional TITLE."
  2280. (interactive "sText to Push: ")
  2281. (pb/push-item '("") text "note" (or title "")))
  2282. ;;;;;;;;;;;;;;;;;;;;;
  2283. ;; git-bug
  2284. (defconst git-bug-ls-regexp
  2285. (eval-when-compile
  2286. (rx bol
  2287. (submatch (one-or-more alphanumeric)) ; id
  2288. ;; (one-or-more any)
  2289. (one-or-more space)
  2290. (submatch (or "open" "close")) ; status
  2291. (one-or-more space)
  2292. (submatch (maximal-match (zero-or-more print))) ; title
  2293. "\t"
  2294. (submatch (one-or-more alphanumeric)) ; user
  2295. (one-or-more space)
  2296. "C:"
  2297. (submatch (one-or-more digit)) ; Comment num
  2298. (one-or-more space)
  2299. "L:"
  2300. (submatch (one-or-more digit)) ; Label num
  2301. eol
  2302. ))
  2303. "Regexp to parse line of output of git-bug ls.
  2304. Used by `git-bug-ls'.")
  2305. (declare-function string-trim "subr-x")
  2306. (defun git-bug-bugs ()
  2307. "Get list of git-bug bugs."
  2308. (with-temp-buffer
  2309. (git-bug--call-process "bug" "ls")
  2310. (goto-char (point-min))
  2311. (let ((bugs nil))
  2312. (while (not (eq (point) (point-max)))
  2313. (save-match-data
  2314. (when (re-search-forward git-bug-ls-regexp (point-at-eol) t)
  2315. (setq bugs `(,@bugs
  2316. ,(list
  2317. :id (match-string 1)
  2318. :status (match-string 2)
  2319. :title (string-trim (match-string 3))
  2320. :user (match-string 4)
  2321. :comment-num (match-string 5)
  2322. :label-num (match-string 6)
  2323. )))))
  2324. (forward-line 1)
  2325. (goto-char (point-at-bol)))
  2326. bugs)))
  2327. (defun git-bug-ls ()
  2328. "Open and select git bug list buffer."
  2329. (interactive)
  2330. (pop-to-buffer (git-bug-ls-noselect)))
  2331. (defun git-bug-ls--set-tabulated-list-mode-variables ()
  2332. "Not implemented.")
  2333. (defun git-bug-ls-mode ()
  2334. "Not implemented.")
  2335. (defun git-bug-ls-noselect (&optional directory)
  2336. "Open git bug list buffer.
  2337. If optional arg DIRECTORY is given change current directory to there before
  2338. initializing."
  2339. (setq directory (expand-file-name (or directory
  2340. default-directory)))
  2341. (cl-assert (file-directory-p directory))
  2342. (let* ((root (git-bug--get-repository-root directory))
  2343. (name (file-name-nondirectory root))
  2344. (bname (format "*GitBug<%s>*" name)))
  2345. (with-current-buffer (get-buffer-create bname)
  2346. (cd root)
  2347. (git-bug-ls--set-tabulated-list-mode-variables)
  2348. (git-bug-ls-mode)
  2349. (current-buffer))))
  2350. (defun git-bug--get-repository-root (dir)
  2351. "Resolve repository root of DIR.
  2352. If DIR is not inside of any git repository, signal an error."
  2353. (cl-assert (file-directory-p dir))
  2354. (with-temp-buffer
  2355. (cd dir)
  2356. (git-bug--call-process "rev-parse" "--show-toplevel")
  2357. (goto-char (point-min))
  2358. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
  2359. (defun git-bug--call-process (&rest args)
  2360. "Start git process synchronously with ARGS.
  2361. Raise error when git process ends with non-zero status.
  2362. Any output will be written to current buffer."
  2363. (let ((status (apply 'call-process
  2364. "git"
  2365. nil
  2366. t
  2367. nil
  2368. args)))
  2369. (cl-assert (eq status 0)
  2370. nil
  2371. (buffer-substring-no-properties (point-min) (point-max)))))
  2372. ;;;;;;;;;;;;;;;;;;;
  2373. ;; peek-file-mode
  2374. (defvar peek-file-buffers
  2375. ()
  2376. "Peek buffers.")
  2377. (defun peek-file (file)
  2378. "Peek FILE."
  2379. (interactive "fFile to peek: ")
  2380. (with-current-buffer (find-file file)
  2381. (peek-file-mode)))
  2382. (define-minor-mode peek-file-mode
  2383. "Peek file mode."
  2384. :lighter "PK"
  2385. (view-mode peek-file-mode)
  2386. (add-to-list 'peek-file-buffers
  2387. (current-buffer))
  2388. (add-hook 'switch-buffer-functions
  2389. 'peek-file-remove-buffers))
  2390. (defun peek-file-remove-buffers (&args _)
  2391. "Remove peek file buffers."
  2392. (cl-dolist (buf (cl-copy-list peek-file-buffers))
  2393. (unless (get-buffer-window buf t)
  2394. (setq peek-file-buffers
  2395. (delq buf
  2396. peek-file-buffers))
  2397. (with-current-buffer buf
  2398. (when peek-file-mode
  2399. (kill-buffer))))))
  2400. ;;;;;;;;;;;;;;;;;;;;
  2401. ;; remember-projectile
  2402. ;; TODO: Add global-minor-mode
  2403. (defvar remember-data-file)
  2404. (defun my-set-remember-data-file-buffer-local ()
  2405. "Set `remember-data-file'."
  2406. (when (require 'projectile nil t)
  2407. (setq-local remember-data-file
  2408. (expand-file-name ".remember.notes"
  2409. (projectile-project-root)))))
  2410. (add-hook 'after-change-major-mode-hook
  2411. 'my-set-remember-data-file-buffer-local)
  2412. (define-key ctl-x-map "R" 'remember)
  2413. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2414. ;; ivy
  2415. ;; (set-variable 'enable-recursive-minibuffers t)
  2416. ;; (minibuffer-depth-indicate-mode 1)
  2417. (declare-function ivy--regex-ignore-order "ivy")
  2418. (declare-function ivy--regex-fuzzy "ivy")
  2419. (defun my--ivy-regex-fuzzy-ignore-order (str)
  2420. "Re-build regex from STR for ignore-order fuzzy match."
  2421. (let ((re-list (ivy--regex-ignore-order str)))
  2422. (if (listp re-list)
  2423. (mapcar (lambda (e)
  2424. (let ((head (car e))
  2425. (tail (cdr e)))
  2426. (if tail
  2427. (cons (ivy--regex-fuzzy head)
  2428. tail)
  2429. (cons head tail))))
  2430. re-list)
  2431. (ivy--regex-fuzzy re-list))))
  2432. ;; (my--ivy-regex-fuzzy-ignore-order "ab bc !cee")
  2433. ;; (ivy--regex-fuzzy "ab")
  2434. ;; (ivy--regex-ignore-order "a b")
  2435. (set-variable 'ivy-re-builders-alist
  2436. '((t . my--ivy-regex-fuzzy-ignore-order)))
  2437. ;; (set-variable 'ivy-format-functions-alist
  2438. ;; '((t . ivy-format-function-arrow)))
  2439. (set-variable 'ivy-format-functions-alist
  2440. '((t . (lambda (cands) (ivy--format-function-generic
  2441. (lambda (str)
  2442. (concat "+> "
  2443. (ivy--add-face str 'ivy-current-match)
  2444. ))
  2445. (lambda (str)
  2446. (concat "| " str))
  2447. cands
  2448. "\n")))))
  2449. (set-variable 'ivy-wrap t)
  2450. (set-variable 'ivy-sort-max-size 500)
  2451. (when (fboundp 'ivy-rich-mode)
  2452. (ivy-rich-mode 1))
  2453. (with-eval-after-load 'ivy
  2454. (defvar ivy-minibuffer-map)
  2455. (define-key ivy-minibuffer-map (kbd "C-u")
  2456. (lambda () (interactive) (delete-region (point-at-bol) (point)))))
  2457. (set-variable 'ivy-on-del-error-function 'ignore)
  2458. (when (fboundp 'counsel-M-x)
  2459. (define-key esc-map "x" 'counsel-M-x)
  2460. ;; (counsel-mode 1)
  2461. ;; counsel-fzf executes fzf -f QUERY for each input
  2462. ;; (define-key ctl-x-map "f"
  2463. ;; (lambda ()
  2464. ;; (interactive
  2465. ;; (let ((process-environment (cl-copy-list process-environment)))
  2466. ;; (setenv "FZF_DEFAULT_COMMAND" nil)
  2467. ;; (counsel-fzf)))))
  2468. )
  2469. ;; (when (fboundp 'counsel-switch-buffer)
  2470. ;; (define-key ctl-x-map (kbd "C-b") 'counsel-switch-buffer))
  2471. (declare-function ivy-thing-at-point "ivy")
  2472. (when (and (fboundp 'ivy-read)
  2473. (locate-library "counsel"))
  2474. (defvar counsel-describe-map)
  2475. (defun my-counsel-describe-symbol ()
  2476. "Forwaord to `describe-symbol'."
  2477. (interactive)
  2478. (cl-assert (eval-and-compile (require 'help-mode nil t))) ;; describe-symbol-backends
  2479. (cl-assert (eval-and-compile (require 'counsel nil t)))
  2480. (ivy-read "Describe symbol: " obarray
  2481. ;; From describe-symbol definition
  2482. :predicate (lambda (vv)
  2483. (cl-some (lambda (x) (funcall (nth 1 x) vv))
  2484. describe-symbol-backends))
  2485. :require-match t
  2486. :history 'counsel-describe-symbol-history
  2487. :keymap counsel-describe-map
  2488. :preselect (ivy-thing-at-point)
  2489. :action (lambda (x)
  2490. (describe-symbol (intern x)))
  2491. :caller 'my-counsel-describe-symbol))
  2492. (define-key help-map "o" 'my-counsel-describe-symbol)
  2493. )
  2494. ;; (defun my-ivy-length (x y)
  2495. ;; "Ivy sort to order by string length."
  2496. ;; (<= (length (if (consp x) (car x) x))
  2497. ;; (length (if (consp y) (car y) y))))
  2498. ;; (my-ivy-length "a" (cons "bc" t))
  2499. ;; (my-ivy-length "a" (cons "c" t))
  2500. (declare-function ivy-configure "ivy")
  2501. (with-eval-after-load 'counsel ;; Hook to counsel, not ivy
  2502. ;; (ivy-configure 'my-counsel-describe-symbol
  2503. ;; :sort-fn 'my-ivy-length)
  2504. (ivy-configure 'counsel-M-x
  2505. :initial-input ""
  2506. ;; :sort-fn 'my-ivy-length
  2507. )
  2508. (defvar ivy-sort-matches-functions-alist)
  2509. (add-to-list 'ivy-sort-matches-functions-alist
  2510. '(my-counsel-describe-symbol . ivy--shorter-matches-first))
  2511. (add-to-list 'ivy-sort-matches-functions-alist
  2512. '(counsel-M-x . ivy--shorter-matches-first))
  2513. )
  2514. (when (fboundp 'counsel-imenu)
  2515. (define-key ctl-x-map "l" 'counsel-imenu))
  2516. (when (fboundp 'swiper)
  2517. (define-key esc-map (kbd "C-s") 'swiper))
  2518. ;; ?
  2519. (define-key input-decode-map "\e[1;5C" [C-right])
  2520. (define-key input-decode-map "\e[1;5D" [C-left])
  2521. ;;;;;;;;;;;;;;;;;;;;;;;;
  2522. ;; mozc
  2523. (global-set-key (kbd "C-c m e") 'ignore)
  2524. (global-set-key (kbd "C-c m d") 'ignore)
  2525. ;; mozc
  2526. (when (locate-library "mozc")
  2527. ;; https://tottoto.net/mac-emacs-karabiner-elements-japanese-input-method-config/
  2528. (with-eval-after-load 'mozc
  2529. ;; (define-key mozc-mode-map (kbd "C-h") 'backward-delete-char)
  2530. ;; (define-key mozc-mode-map (kbd "C-p") (kbd "<up>"))
  2531. ;; (define-key mozc-mode-map (kbd "C-n") (kbd "SPC"))
  2532. )
  2533. (setq default-input-method "japanese-mozc")
  2534. (custom-set-variables '(mozc-leim-title "あ"))
  2535. (defun turn-on-input-method ()
  2536. (interactive)
  2537. (activate-input-method default-input-method))
  2538. (defun turn-off-input-method ()
  2539. (interactive)
  2540. (deactivate-input-method))
  2541. ;; (setq mozc-candidate-style 'echo-area)
  2542. (global-set-key (kbd "C-c m e") 'turn-on-input-method)
  2543. (global-set-key (kbd "C-c m d") 'turn-off-input-method)
  2544. (global-set-key (kbd "<f7>") 'turn-off-input-method)
  2545. (global-set-key (kbd "<f8>") 'turn-on-input-method)
  2546. (require 'mozc-popup)
  2547. (set-variable 'mozc-candidate-style 'popup)
  2548. ;; これいる?
  2549. (when (require 'mozc-im nil t)
  2550. (setq default-input-method "japanese-mozc-im")
  2551. ;; (global-set-key (kbd "C-j") 'toggle-input-method)
  2552. )
  2553. )
  2554. ;;;;;;;;;;;;;;
  2555. ;; mmv
  2556. ;; https://www.emacswiki.org/emacs/MakingMarkVisible
  2557. ;;;; Make the mark visible, and the visibility toggleable. ('mmv' means 'make
  2558. ;;;; mark visible'.) By Patrick Gundlach, Teemu Leisti, and Stefan.
  2559. (defgroup mmv nil
  2560. "Make mark visible."
  2561. :group 'tools)
  2562. (defvar mmv-face-foreground
  2563. (face-foreground 'hi-yellow)
  2564. "Foreground color for `mmv-face'.")
  2565. (defvar mmv-face-background
  2566. (face-background 'hi-yellow)
  2567. "Background color for `mmv-face'.")
  2568. (defface mmv-face
  2569. `((t :background ,mmv-face-background :foreground ,mmv-face-foreground))
  2570. "Face used for showing the mark's position."
  2571. :group 'mmv)
  2572. (defvar-local mmv-mark-overlay nil
  2573. "The overlay for showing the mark's position.")
  2574. (defvar-local mmv-is-mark-visible t
  2575. "The overlay is visible only when this variable's value is t.")
  2576. (defun mmv-draw-mark (&rest _)
  2577. "Make the mark's position stand out by means of a one-character-long overlay.
  2578. If the value of variable `mmv-is-mark-visible' is nil, the mark will be
  2579. invisible."
  2580. (unless mmv-mark-overlay
  2581. (setq mmv-mark-overlay (make-overlay 0 0 nil t))
  2582. (overlay-put mmv-mark-overlay 'face 'mmv-face)
  2583. (overlay-put mmv-mark-overlay 'priority 10)) ;; bigger than highlight-indentation-current-column-overlay-priority
  2584. (let ((mark-position (mark t)))
  2585. (cond
  2586. ((null mark-position) (delete-overlay mmv-mark-overlay))
  2587. ((and (< mark-position (point-max))
  2588. (not (eq ?\n (char-after mark-position))))
  2589. (overlay-put mmv-mark-overlay 'after-string nil)
  2590. (move-overlay mmv-mark-overlay mark-position (1+ mark-position)))
  2591. (t
  2592. ;; This branch is called when the mark is at the end of a line or at the
  2593. ;; end of the buffer. We use a bit of trickery to avoid the higlight
  2594. ;; extending from the mark all the way to the right end of the frame.
  2595. (overlay-put mmv-mark-overlay 'after-string
  2596. (propertize " " 'face (overlay-get mmv-mark-overlay 'face)))
  2597. (move-overlay mmv-mark-overlay mark-position mark-position)))))
  2598. (add-hook 'pre-redisplay-functions #'mmv-draw-mark)
  2599. (defun mmv-toggle-mark-visibility ()
  2600. "Toggles the mark's visiblity and redraws it (whether invisible or visible)."
  2601. (interactive)
  2602. (setq mmv-is-mark-visible (not mmv-is-mark-visible))
  2603. (if mmv-is-mark-visible
  2604. (set-face-attribute 'mmv-face nil :background mmv-face-background :foreground mmv-face-foreground)
  2605. (set-face-attribute 'mmv-face nil :background 'unspecified :foreground 'unspecified))
  2606. (mmv-draw-mark))
  2607. ;; Local Variables:
  2608. ;; flycheck-disabled-checkers: (emacs-lisp-checkdoc)
  2609. ;; flycheck-checker: emacs-lisp
  2610. ;; End:
  2611. ;;; emancs.el ends here