Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

3034 rindas
101 KiB

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