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.
 
 
 
 
 
 

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