選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

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