You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

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