Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

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