Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

3047 linhas
101 KiB

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