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

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