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.
 
 
 
 
 
 

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