25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

3068 satır
102 KiB

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