Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

3058 rader
101 KiB

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