Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

3084 wiersze
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 'sqlformat-command 'pgformatter)
  1597. (when (fboundp 'git-command)
  1598. (define-key ctl-x-map "g" 'git-command))
  1599. (when (fboundp 'gited-list)
  1600. (defalias 'gited 'gited-list))
  1601. (when (and (eval-and-compile (require 'git-commit nil t))
  1602. (fboundp 'global-git-commit-mode))
  1603. ;; git-commit is defined badly and breaks the convention that only loading a
  1604. ;; library should not change the Emacs behavior:
  1605. ;; anyway I enable this manually here.
  1606. (global-git-commit-mode 1))
  1607. (with-eval-after-load 'git-commit
  1608. (add-hook 'git-commit-setup-hook
  1609. 'turn-off-auto-fill t))
  1610. (with-eval-after-load 'rst
  1611. (defvar rst-mode-map)
  1612. (define-key rst-mode-map (kbd "C-m") 'newline-and-indent))
  1613. (with-eval-after-load 'jdee
  1614. (add-hook 'jdee-mode-hook
  1615. (lambda ()
  1616. (make-local-variable 'global-mode-string)
  1617. (add-to-list 'global-mode-string
  1618. mode-line-position))))
  1619. ;; Cannot enable error thrown. Why???
  1620. ;; https://github.com/m0smith/malabar-mode#Installation
  1621. ;; (when (require 'malabar-mode nil t)
  1622. ;; (add-to-list 'load-path
  1623. ;; (expand-file-name (concat user-emacs-directory "/cedet")))
  1624. ;; (require 'cedet-devel-load nil t)
  1625. ;; (eval-after-init (activate-malabar-mode)))
  1626. (with-eval-after-load 'make-mode
  1627. (defvar makefile-mode-map (make-sparse-keymap))
  1628. (define-key makefile-mode-map (kbd "C-m") 'newline-and-indent)
  1629. ;; this functions is set in write-file-functions, i cannot find any
  1630. ;; good way to remove this.
  1631. (fset 'makefile-warn-suspicious-lines 'ignore))
  1632. (with-eval-after-load 'verilog-mode
  1633. (defvar verilog-mode-map (make-sparse-keymap))
  1634. (define-key verilog-mode-map ";" 'self-insert-command))
  1635. (setq diff-switches "-u")
  1636. (autoload 'diff-goto-source "diff-mode" nil t)
  1637. (with-eval-after-load 'diff-mode
  1638. ;; (when (and (eq major-mode
  1639. ;; 'diff-mode)
  1640. ;; (not buffer-file-name))
  1641. ;; ;; do not pass when major-mode is derived mode of diff-mode
  1642. ;; (view-mode 1))
  1643. (set-face-attribute 'diff-header nil
  1644. :foreground nil
  1645. :background nil
  1646. :weight 'bold)
  1647. (set-face-attribute 'diff-file-header nil
  1648. :foreground nil
  1649. :background nil
  1650. :weight 'bold)
  1651. (set-face-foreground 'diff-index "blue")
  1652. (set-face-attribute 'diff-hunk-header nil
  1653. :foreground "cyan"
  1654. :weight 'normal)
  1655. (set-face-attribute 'diff-context nil
  1656. ;; :foreground "white"
  1657. :foreground nil
  1658. :weight 'normal)
  1659. (set-face-foreground 'diff-removed "red")
  1660. (set-face-foreground 'diff-added "green")
  1661. (set-face-background 'diff-removed nil)
  1662. (set-face-background 'diff-added nil)
  1663. (set-face-attribute 'diff-changed nil
  1664. :foreground "magenta"
  1665. :weight 'normal)
  1666. (set-face-attribute 'diff-refine-changed nil
  1667. :foreground nil
  1668. :background nil
  1669. :weight 'bold
  1670. :inverse-video t)
  1671. ;; Annoying !
  1672. ;;(diff-auto-refine-mode)
  1673. (set-variable 'diff-refine nil)
  1674. )
  1675. ;; (ffap-bindings)
  1676. (with-eval-after-load 'browse-url
  1677. (set-variable 'browse-url-browser-function
  1678. 'eww-browse-url))
  1679. (set-variable 'sh-here-document-word "__EOC__")
  1680. (with-eval-after-load 'adoc-mode
  1681. (defvar adoc-mode-map)
  1682. (define-key adoc-mode-map (kbd "C-m") 'newline))
  1683. (when (fboundp 'adoc-mode)
  1684. (setq auto-mode-alist
  1685. `(("\\.adoc\\'" . adoc-mode)
  1686. ("\\.asciidoc\\'" . adoc-mode)
  1687. ,@auto-mode-alist)))
  1688. (with-eval-after-load 'markup-faces
  1689. ;; Is this too match ?
  1690. (set-face-foreground 'markup-meta-face
  1691. "color-245")
  1692. (set-face-foreground 'markup-meta-hide-face
  1693. "color-245")
  1694. )
  1695. ;; TODO: check if this is required
  1696. (with-eval-after-load 'groovy-mode
  1697. (defvar groovy-mode-map)
  1698. (define-key groovy-mode-map "(" 'self-insert-command)
  1699. (define-key groovy-mode-map ")" 'self-insert-command)
  1700. (define-key groovy-mode-map (kbd "C-m") 'newline-and-indent)
  1701. )
  1702. (when (fboundp 'groovy-mode)
  1703. (add-to-list 'auto-mode-alist
  1704. '("build\\.gradle\\'" . groovy-mode)))
  1705. (add-to-list 'auto-mode-alist
  1706. '("\\.gawk\\'" . awk-mode))
  1707. (with-eval-after-load 'yaml-mode
  1708. (defvar yaml-mode-map (make-sparse-keymap))
  1709. (define-key yaml-mode-map (kbd "C-m") 'newline))
  1710. (with-eval-after-load 'html-mode
  1711. (defvar html-mode-map (make-sparse-keymap))
  1712. (define-key html-mode-map (kbd "C-m") 'reindent-then-newline-and-indent))
  1713. (with-eval-after-load 'text-mode
  1714. (define-key text-mode-map (kbd "C-m") 'newline))
  1715. (with-eval-after-load 'info
  1716. (defvar Info-additional-directory-list)
  1717. (dolist (dir (directory-files (concat user-emacs-directory
  1718. "info")
  1719. t
  1720. "^[^.].*"))
  1721. (when (file-directory-p dir)
  1722. (add-to-list 'Info-additional-directory-list
  1723. dir)))
  1724. (let ((dir (expand-file-name "~/.brew/share/info")))
  1725. (when (file-directory-p dir)
  1726. (add-to-list 'Info-additional-directory-list
  1727. dir))))
  1728. (with-eval-after-load 'apropos
  1729. (defvar apropos-mode-map (make-sparse-keymap))
  1730. (define-key apropos-mode-map "n" 'next-line)
  1731. (define-key apropos-mode-map "p" 'previous-line))
  1732. ;; `isearch' library does not call `provide' so cannot use with-eval-after-load
  1733. ;; (define-key isearch-mode-map
  1734. ;; (kbd "C-j") 'isearch-other-control-char)
  1735. ;; (define-key isearch-mode-map
  1736. ;; (kbd "C-k") 'isearch-other-control-char)
  1737. ;; (define-key isearch-mode-map
  1738. ;; (kbd "C-h") 'isearch-other-control-char)
  1739. (define-key isearch-mode-map (kbd "C-h") 'isearch-del-char)
  1740. (define-key isearch-mode-map (kbd "M-r")
  1741. 'isearch-query-replace-regexp)
  1742. ;; do not cleanup isearch highlight: use `lazy-highlight-cleanup' to remove
  1743. (setq lazy-highlight-cleanup nil)
  1744. ;; face for isearch highlighting
  1745. (set-face-attribute 'lazy-highlight
  1746. nil
  1747. :foreground `unspecified
  1748. :background `unspecified
  1749. :underline t
  1750. ;; :weight `bold
  1751. )
  1752. (add-hook 'outline-mode-hook
  1753. (lambda ()
  1754. (when (string-match "\\.md\\'" buffer-file-name)
  1755. (setq-local outline-regexp "#+ "))))
  1756. (add-hook 'outline-mode-hook
  1757. 'outline-show-all)
  1758. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  1759. (with-eval-after-load 'markdown-mode
  1760. (defvar gfm-mode-map)
  1761. (define-key gfm-mode-map (kbd "C-m") 'electric-indent-just-newline)
  1762. (define-key gfm-mode-map "`" nil) ;; markdown-electric-backquote
  1763. )
  1764. (when (fboundp 'gfm-mode)
  1765. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'gfm-mode))
  1766. (add-hook 'markdown-mode-hook
  1767. 'outline-minor-mode)
  1768. (add-hook 'markdown-mode-hook
  1769. (lambda ()
  1770. (setq-local comment-start ";")))
  1771. )
  1772. ;; http://keisanbutsuriya.hateblo.jp/entry/2015/02/10/152543
  1773. ;; M-$ to ispell word
  1774. ;; M-x flyspell-buffer to highlight all suspicious words
  1775. (when (executable-find "aspell")
  1776. (set-variable 'ispell-program-name "aspell")
  1777. (set-variable 'ispell-extra-args '("--lang=en_US")))
  1778. (with-eval-after-load 'ispell
  1779. (add-to-list 'ispell-skip-region-alist '("[^\000-\377]+")))
  1780. (when (fboundp 'flyspell-mode)
  1781. (add-hook 'text-mode-hook
  1782. 'flyspell-mode))
  1783. (when (fboundp 'flyspell-prog-mode)
  1784. (add-hook 'prog-mode-hook
  1785. 'flyspell-prog-mode))
  1786. ;; c-mode
  1787. ;; http://www.emacswiki.org/emacs/IndentingC
  1788. ;; http://en.wikipedia.org/wiki/Indent_style
  1789. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  1790. ;; http://seesaawiki.jp/whiteflare503/d/Emacs%20%a5%a4%a5%f3%a5%c7%a5%f3%a5%c8
  1791. (with-eval-after-load 'cc-vars
  1792. (defvar c-default-style nil)
  1793. (add-to-list 'c-default-style
  1794. '(c-mode . "k&r"))
  1795. (add-to-list 'c-default-style
  1796. '(c++-mode . "k&r")))
  1797. (add-to-list 'auto-mode-alist
  1798. '("\\.gs\\'" . js-mode))
  1799. (with-eval-after-load 'js2-mode
  1800. ;; currently do not use js2-mode
  1801. ;; (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  1802. ;; (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode))
  1803. ;; (defvar js2-mode-map (make-sparse-keymap))
  1804. ;; (define-key js2-mode-map (kbd "C-m") (lambda ()
  1805. ;; (interactive)
  1806. ;; (js2-enter-key)
  1807. ;; (indent-for-tab-command)))
  1808. ;; (add-hook (kill-local-variable 'before-save-hook)
  1809. ;; 'js2-before-save)
  1810. ;; (add-hook 'before-save-hook
  1811. ;; 'my-indent-buffer
  1812. ;; nil
  1813. ;; t)
  1814. )
  1815. (add-to-list 'interpreter-mode-alist
  1816. '("node" . js-mode))
  1817. (add-hook 'js-mode-hook
  1818. (lambda ()
  1819. ;; Stop current line highlighting
  1820. (set-variable 'js-indent-level 2 t)
  1821. ))
  1822. (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
  1823. (with-eval-after-load 'uniquify
  1824. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  1825. (setq uniquify-ignore-buffers-re "*[^*]+*")
  1826. (setq uniquify-min-dir-content 1))
  1827. (with-eval-after-load 'view
  1828. (defvar view-mode-map (make-sparse-keymap))
  1829. (define-key view-mode-map "j" 'scroll-up-line)
  1830. (define-key view-mode-map "k" 'scroll-down-line)
  1831. (define-key view-mode-map "v" 'toggle-read-only)
  1832. (define-key view-mode-map "q" 'bury-buffer)
  1833. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  1834. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  1835. ;; (define-key view-mode-map
  1836. ;; "n" 'nonincremental-repeat-search-forward)
  1837. ;; (define-key view-mode-map
  1838. ;; "N" 'nonincremental-repeat-search-backward)
  1839. ;; N conflicts with git-walktree
  1840. ;; (define-key view-mode-map "/" 'isearch-forward-regexp)
  1841. ;; (define-key view-mode-map "?" 'isearch-backward-regexp)
  1842. ;; (define-key view-mode-map "n" 'isearch-repeat-forward)
  1843. ;; (define-key view-mode-map "N" 'isearch-repeat-backward)
  1844. (define-key view-mode-map (kbd "C-m") 'my-rgrep-symbol-at-point))
  1845. (global-set-key "\M-r" 'view-mode)
  1846. ;; (setq view-read-only t)
  1847. (with-eval-after-load 'term
  1848. (defvar term-raw-map (make-sparse-keymap))
  1849. (define-key term-raw-map (kbd "C-x")
  1850. (lookup-key (current-global-map)
  1851. (kbd "C-x"))))
  1852. (add-hook 'term-mode-hook
  1853. (lambda ()
  1854. ;; Stop current line highlighting
  1855. (set-variable 'hl-line-range-function (lambda () '(0 . 0)) t)
  1856. (set-variable 'scroll-margin 0 t)
  1857. ))
  1858. (set-variable 'term-buffer-maximum-size 20480)
  1859. (set-variable 'term-suppress-hard-newline t)
  1860. (add-hook 'Man-mode-hook
  1861. (lambda ()
  1862. (view-mode 1)
  1863. (setq truncate-lines nil)))
  1864. (set-variable 'Man-notify-method (if window-system
  1865. 'newframe
  1866. 'aggressive))
  1867. (set-variable 'woman-cache-filename (expand-file-name (concat user-emacs-directory
  1868. "woman_cache.el")))
  1869. ;; not work because man.el will be loaded when man called
  1870. (defalias 'man 'woman)
  1871. (add-to-list 'auto-mode-alist
  1872. '("/tox\\.ini\\'" . conf-unix-mode))
  1873. (add-to-list 'auto-mode-alist
  1874. '("/setup\\.cfg\\'" . conf-unix-mode))
  1875. (when (fboundp 'toml-mode)
  1876. (add-to-list 'auto-mode-alist
  1877. '("/tox\\.ini\\'" . toml-mode))
  1878. (add-to-list 'auto-mode-alist
  1879. '("/setup\\.cfg\\'" . toml-mode))
  1880. (add-to-list 'auto-mode-alist
  1881. '("/Pipfile\\'" . toml-mode))
  1882. (add-to-list 'auto-mode-alist
  1883. '("/poetry\\.lock\\'" . toml-mode))
  1884. )
  1885. (when (fboundp 'json-mode)
  1886. (add-to-list 'auto-mode-alist
  1887. '("/Pipfile\\.lock\\'" . json-mode)))
  1888. (add-hook 'json-mode-hook
  1889. (lambda ()
  1890. ;; Stop current line highlighting
  1891. (set-variable 'js-indent-level 2 t)
  1892. ))
  1893. (add-hook 'go-mode-hook
  1894. (lambda()
  1895. (defvar go-mode-map)
  1896. (add-hook 'before-save-hook 'gofmt-before-save nil t)
  1897. (define-key go-mode-map (kbd "M-.") 'godef-jump)))
  1898. (when (fboundp 'k8s-mode)
  1899. (add-to-list 'auto-mode-alist
  1900. '("\\.k8s\\'" . k8s-mode)))
  1901. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1902. ;; buffers
  1903. (defvar bs-configurations)
  1904. (declare-function bs-set-configuration "bs")
  1905. (declare-function bs-refresh "bs")
  1906. (declare-function bs-message-without-log "bs")
  1907. (declare-function bs--current-config-message "bs")
  1908. (with-eval-after-load 'bs
  1909. (add-to-list 'bs-configurations
  1910. '("specials" "^\\*" nil ".*" nil nil))
  1911. (add-to-list 'bs-configurations
  1912. '("files-and-specials" "^\\*" buffer-file-name ".*" nil nil))
  1913. (defvar bs-mode-map)
  1914. (defvar bs-current-configuration)
  1915. (define-key bs-mode-map (kbd "t")
  1916. ;; TODO: fix toggle feature
  1917. (lambda ()
  1918. (interactive)
  1919. (if (string= "specials"
  1920. bs-current-configuration)
  1921. (bs-set-configuration "files")
  1922. (bs-set-configuration "specials"))
  1923. (bs-refresh)
  1924. (bs-message-without-log "%s"
  1925. (bs--current-config-message))))
  1926. ;; (setq bs-configurations (list
  1927. ;; '("processes" nil get-buffer-process ".*" nil nil)
  1928. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
  1929. ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
  1930. )
  1931. (when (fboundp 'bs-show)
  1932. (defalias 'list-buffers 'bs-show)
  1933. (set-variable 'bs-default-configuration "files-and-specials")
  1934. (set-variable 'bs-default-sort-name "by nothing")
  1935. (add-hook 'bs-mode-hook
  1936. (lambda ()
  1937. (setq-local scroll-margin 0)
  1938. (setq-local header-line-format nil)
  1939. (setq-local mode-line-format nil)
  1940. )))
  1941. ;;(iswitchb-mode 1)
  1942. (icomplete-mode)
  1943. (defun iswitchb-buffer-display-other-window ()
  1944. "Do iswitchb in other window."
  1945. (interactive)
  1946. (let ((iswitchb-default-method 'display))
  1947. (call-interactively 'iswitchb-buffer)))
  1948. ;; buffer killing
  1949. ;; (defun my-delete-window-killing-buffer () nil)
  1950. (defun my-query-kill-current-buffer ()
  1951. "Interactively kill current buffer."
  1952. (interactive)
  1953. (if (y-or-n-p (concat "kill current buffer? :"))
  1954. (kill-buffer (current-buffer))))
  1955. (defun my-force-query-kill-current-buffer ()
  1956. "Interactively kill current buffer."
  1957. (interactive)
  1958. (when (y-or-n-p (concat "kill current buffer? :"))
  1959. (let ((kill-buffer-hook nil)
  1960. (kill-buffer-query-functions nil))
  1961. (kill-buffer (current-buffer)))))
  1962. ;;(global-set-key "\C-xk" 'my-query-kill-current-buffer)
  1963. ;; Originally C-x C-k -> kmacro-keymap
  1964. ;; (global-set-key "\C-x\C-k" 'kmacro-keymap)
  1965. (global-set-key (kbd "C-x C-k") 'my-query-kill-current-buffer)
  1966. (substitute-key-definition 'kill-buffer
  1967. 'my-query-kill-current-buffer
  1968. global-map)
  1969. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1970. ;; dired
  1971. (defun my-file-head (filename &optional n)
  1972. "Return list of first N lines of file FILENAME."
  1973. ;; TODO: Fix for janapese text
  1974. ;; TODO: Fix for short text
  1975. (let ((num (or n 10))
  1976. (size 100)
  1977. (beg 0)
  1978. (end 0)
  1979. (result '())
  1980. (read -1))
  1981. (with-temp-buffer
  1982. (erase-buffer)
  1983. (while (or (<= (count-lines (point-min)
  1984. (point-max))
  1985. num)
  1986. (eq read 0))
  1987. (setq end (+ beg size))
  1988. (setq read (nth 1 (insert-file-contents-literally filename
  1989. nil
  1990. beg
  1991. end)))
  1992. (goto-char (point-max))
  1993. (setq beg (+ beg size)))
  1994. (goto-char (point-min))
  1995. (while (< (length result) num)
  1996. (let ((start (point)))
  1997. (forward-line 1)
  1998. (setq result
  1999. `(,@result ,(buffer-substring-no-properties start
  2000. (point))))))
  2001. result
  2002. ;; (buffer-substring-no-properties (point-min)
  2003. ;; (progn
  2004. ;; (forward-line num)
  2005. ;; (point)))
  2006. )))
  2007. ;; (apply 'concat (my-file-head "./shrc" 10)
  2008. (declare-function dired-get-filename "dired" t)
  2009. (defun my-dired-echo-file-head (arg)
  2010. "Echo head of current file.
  2011. ARG is num to show, or defaults to 7."
  2012. (interactive "P")
  2013. (let ((f (dired-get-filename)))
  2014. (message "%s"
  2015. (apply 'concat
  2016. (my-file-head f
  2017. 7)))))
  2018. (declare-function dired-get-marked-files "dired")
  2019. (defun my-dired-diff ()
  2020. "Show diff of marked file and file of current line."
  2021. (interactive)
  2022. (let ((files (dired-get-marked-files nil nil nil t)))
  2023. (if (eq (car files)
  2024. t)
  2025. (diff (cadr files) (dired-get-filename))
  2026. (message "One file must be marked!"))))
  2027. (defun dired-get-file-info ()
  2028. "Print information of current line file."
  2029. (interactive)
  2030. (let* ((file (dired-get-filename t))
  2031. (quoted (shell-quote-argument file)))
  2032. (if (file-directory-p file)
  2033. (progn
  2034. (message "Calculating disk usage...")
  2035. (let ((du (or (executable-find "gdu")
  2036. (executable-find "du")
  2037. (error "du not found"))))
  2038. (shell-command (concat du
  2039. " -hsD "
  2040. quoted))))
  2041. (shell-command (concat "file "
  2042. quoted)))))
  2043. (defun my-dired-scroll-up ()
  2044. "Scroll up."
  2045. (interactive)
  2046. (my-dired-previous-line (- (window-height) 1)))
  2047. (defun my-dired-scroll-down ()
  2048. "Scroll down."
  2049. (interactive)
  2050. (my-dired-next-line (- (window-height) 1)))
  2051. ;; (defun my-dired-forward-line (arg)
  2052. ;; ""
  2053. ;; (interactive "p"))
  2054. (declare-function dired-get-subdir "dired")
  2055. (declare-function dired-move-to-filename "dired")
  2056. (defun my-dired-previous-line (arg)
  2057. "Move ARG lines up."
  2058. (interactive "p")
  2059. (if (> arg 0)
  2060. (progn
  2061. (if (eq (line-number-at-pos)
  2062. 1)
  2063. (goto-char (point-max))
  2064. (forward-line -1))
  2065. (my-dired-previous-line (if (or (dired-get-filename nil t)
  2066. (dired-get-subdir))
  2067. (- arg 1)
  2068. arg)))
  2069. (dired-move-to-filename)))
  2070. (defun my-dired-next-line (arg)
  2071. "Move ARG lines down."
  2072. (interactive "p")
  2073. (if (> arg 0)
  2074. (progn
  2075. (if (eq (point)
  2076. (point-max))
  2077. (goto-char (point-min))
  2078. (forward-line 1))
  2079. (my-dired-next-line (if (or (dired-get-filename nil t)
  2080. (dired-get-subdir))
  2081. (- arg 1)
  2082. arg)))
  2083. (dired-move-to-filename)))
  2084. (defun my-tramp-remote-find-file (f)
  2085. "Open F."
  2086. (interactive (list (read-file-name "My Find File Tramp: "
  2087. "/scp:"
  2088. nil ;; "/scp:"
  2089. (confirm-nonexistent-file-or-buffer))))
  2090. (find-file f))
  2091. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  2092. (if (eq window-system 'mac)
  2093. (setq dired-listing-switches "-lhFA")
  2094. (setq dired-listing-switches "-lhFA --time-style=long-iso")
  2095. )
  2096. (setq dired-listing-switches "-lhFA")
  2097. ;; when using dired-find-alternate-file
  2098. ;; reuse current dired buffer for the file to open
  2099. ;; (put 'dired-find-alternate-file 'disabled nil)
  2100. (set-variable 'dired-ls-F-marks-symlinks t)
  2101. (set-variable 'ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
  2102. (set-variable 'ls-lisp-dirs-first t)
  2103. (set-variable 'ls-lisp-use-localized-time-format t)
  2104. (set-variable 'ls-lisp-format-time-list
  2105. '("%Y-%m-%d %H:%M"
  2106. "%Y-%m-%d "))
  2107. (set-variable 'dired-dwim-target t)
  2108. (set-variable 'dired-isearch-filenames t)
  2109. (set-variable 'dired-hide-details-hide-symlink-targets nil)
  2110. (set-variable 'dired-hide-details-hide-information-lines nil)
  2111. (set-variable 'dired-deletion-confirmer 'y-or-n-p)
  2112. (set-variable 'dired-recursive-deletes 'always)
  2113. ;; (add-hook 'dired-after-readin-hook
  2114. ;; 'my-replace-nasi-none)
  2115. (with-eval-after-load 'dired
  2116. (require 'ls-lisp nil t)
  2117. (defvar dired-mode-map (make-sparse-keymap))
  2118. ;; dired-do-chgrp sometimes cause system hung
  2119. (define-key dired-mode-map "G" 'ignore)
  2120. (define-key dired-mode-map "e" 'wdired-change-to-wdired-mode)
  2121. (define-key dired-mode-map "i" 'dired-get-file-info)
  2122. ;; (define-key dired-mode-map "f" 'find-file)
  2123. (define-key dired-mode-map "f" 'my-fuzzy-finder-or-find-file)
  2124. (define-key dired-mode-map "!" 'shell-command)
  2125. (define-key dired-mode-map "&" 'async-shell-command)
  2126. (define-key dired-mode-map "X" 'dired-do-async-shell-command)
  2127. (define-key dired-mode-map "=" 'my-dired-diff)
  2128. (define-key dired-mode-map "B" 'gtkbm-add-current-dir)
  2129. (define-key dired-mode-map "b" 'gtkbm)
  2130. (define-key dired-mode-map "h" 'my-dired-echo-file-head)
  2131. (define-key dired-mode-map (kbd "TAB") 'other-window)
  2132. ;; (define-key dired-mode-map "P" 'my-dired-do-pack-or-unpack)
  2133. (define-key dired-mode-map "/" 'dired-isearch-filenames)
  2134. (define-key dired-mode-map (kbd "DEL") 'dired-up-directory)
  2135. (define-key dired-mode-map (kbd "C-h") 'dired-up-directory)
  2136. (substitute-key-definition 'dired-next-line
  2137. 'my-dired-next-line
  2138. dired-mode-map)
  2139. (substitute-key-definition 'dired-previous-line
  2140. 'my-dired-previous-line
  2141. dired-mode-map)
  2142. ;; (define-key dired-mode-map (kbd "C-p") 'my-dired-previous-line)
  2143. ;; (define-key dired-mode-map (kbd "p") 'my-dired-previous-line)
  2144. ;; (define-key dired-mode-map (kbd "C-n") 'my-dired-next-line)
  2145. ;; (define-key dired-mode-map (kbd "n") 'my-dired-next-line)
  2146. (define-key dired-mode-map (kbd "<left>") 'my-dired-scroll-up)
  2147. (define-key dired-mode-map (kbd "<right>") 'my-dired-scroll-down)
  2148. (define-key dired-mode-map (kbd "ESC p") 'my-dired-scroll-up)
  2149. (define-key dired-mode-map (kbd "ESC n") 'my-dired-scroll-down)
  2150. (add-hook 'dired-mode-hook
  2151. (lambda ()
  2152. (when (fboundp 'dired-hide-details-mode)
  2153. (dired-hide-details-mode t)
  2154. (local-set-key "l" 'dired-hide-details-mode))
  2155. (when (fboundp 'dired-omit-mode)
  2156. (dired-omit-mode 1)
  2157. (local-set-key "a" 'dired-omit-mode))
  2158. (let ((file "._Icon\015"))
  2159. (when nil
  2160. '(file-readable-p file)
  2161. (delete-file file)))))
  2162. (when (fboundp 'pack-dired-dwim)
  2163. (with-eval-after-load 'dired
  2164. (define-key dired-mode-map "P" 'pack-dired-dwim)))
  2165. ;; https://emacs.stackexchange.com/questions/68585/dired-mode-toggle-show-hidden-files-folders-by-keyboard-shortcut
  2166. (set-variable 'dired-omit-files
  2167. (rx (or (regexp "\\`[.]?#\\|\\`[.][.]?\\'")
  2168. (seq bos "." (not (any "."))))))
  2169. ;; (string-match-p dired-omit-files ".abc")
  2170. (when (fboundp 'dired-omit-mode)
  2171. (with-eval-after-load 'dired
  2172. ))
  2173. )
  2174. (when (fboundp 'dired-filter-mode)
  2175. (add-hook 'dired-mode-hook
  2176. 'dired-filter-mode))
  2177. (set-variable 'dired-filter-stack nil)
  2178. ;; Currently disabled in favor of dired-from-git-ls-files
  2179. ;; (define-key ctl-x-map "f" 'find-dired)
  2180. (defvar my-dired-git-ls-files-history
  2181. "History for `my-dired-git-ls-files'." nil)
  2182. (defun my-dired-git-ls-files (arg)
  2183. "Dired from git ls-files."
  2184. (interactive (list
  2185. (read-shell-command "git ls-files: "
  2186. "git ls-files -z ")))
  2187. (pop-to-buffer-same-window
  2188. (dired-noselect `(,default-directory
  2189. ,@(split-string (shell-command-to-string arg)
  2190. "\0" t))
  2191. ""))
  2192. )
  2193. (define-key ctl-x-map (kbd "G") 'my-dired-git-ls-files)
  2194. (with-eval-after-load 'dired
  2195. (defvar dired-mode-map (make-sparse-keymap))
  2196. (define-key dired-mode-map "G" 'my-dired-git-ls-files))
  2197. (with-eval-after-load 'pack
  2198. (set-variable 'pack-silence
  2199. t)
  2200. (defvar pack-program-alist)
  2201. (add-to-list 'pack-program-alist
  2202. '("\\.txz\\'" :pack "tar -cJf" :unpack "tar -xf"))
  2203. (when (executable-find "aunpack")
  2204. (add-to-list 'pack-program-alist
  2205. ' ("\\.zip\\'"
  2206. :pack ("zip" "-r" archive sources)
  2207. :pack-append ("zip" "-r" archive sources)
  2208. :unpack ("aunpack" archive))))
  2209. )
  2210. ;; dired-k
  2211. (declare-function dired-k-no-revert "dired-k")
  2212. (when (fboundp 'dired-k)
  2213. (set-variable 'dired-k-style 'git)
  2214. ;; What is the best way of doing this?
  2215. (with-eval-after-load 'dired-k
  2216. (fset 'dired-k--highlight-by-file-attribyte 'ignore))
  2217. ;; (set-variable 'dired-k-size-colors
  2218. ;; `((,most-positive-fixnum)))
  2219. ;; (set-variable 'dired-k-date-colors
  2220. ;; `((,most-positive-fixnum)))
  2221. (add-hook 'dired-after-readin-hook #'dired-k-no-revert)
  2222. )
  2223. ;; (when (eval-and-compile (require 'dired-rainbow nil t))
  2224. ;; (dired-rainbow-define gtags "brightblack" "GTAGS"))
  2225. (with-eval-after-load 'diredfl
  2226. (set-face-foreground 'diredfl-file-name nil)
  2227. )
  2228. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2229. ;; misc funcs
  2230. (define-key ctl-x-map "T" 'git-worktree)
  2231. (define-key ctl-x-map "W" 'git-walktree)
  2232. (defun mkcdd ()
  2233. "Make date directory and open it with dired."
  2234. (interactive)
  2235. (let ((d (format-time-string "%Y%m%d-%H%M%S")))
  2236. (make-directory d)
  2237. (find-file d)))
  2238. (when (fboundp 'browse-url-default-macosx-browser)
  2239. (defalias 'browse-osx 'browse-url-default-macosx-browser))
  2240. (defalias 'qcalc 'quick-calc)
  2241. (defun memo (&optional dir)
  2242. "Open memo.txt in DIR."
  2243. (interactive)
  2244. (pop-to-buffer (find-file-noselect (concat (if dir
  2245. (file-name-as-directory dir)
  2246. "")
  2247. "memo.txt"))))
  2248. ;; TODO: remember-projectile
  2249. (set (defvar my-privnotes-path nil
  2250. "My privnotes repository path.")
  2251. (expand-file-name "~/my/privnotes"))
  2252. (defun my-privnotes-readme (dir)
  2253. "Open my privnotes DIR."
  2254. (interactive (list
  2255. (read-file-name "Privnotes: "
  2256. (expand-file-name (format-time-string "%Y%m%d_")
  2257. my-privnotes-path))))
  2258. (let ((path (expand-file-name "README.md" dir)))
  2259. (with-current-buffer (find-file path)
  2260. (unless (file-exists-p path)
  2261. (insert (file-name-base dir)
  2262. "\n"
  2263. "=======\n"
  2264. "\n\n")))))
  2265. (define-key ctl-x-map "p" 'my-privnotes-readme)
  2266. (set (defvar my-rgrep-alist nil
  2267. "Alist of rgrep command.
  2268. Each element is in the form like (NAME SEXP COMMAND), where SEXP returns the
  2269. condition to choose COMMAND when evaluated.")
  2270. `(
  2271. ;; ripgrep
  2272. ("rg"
  2273. (executable-find "rg")
  2274. "rg -nH --no-heading --hidden --no-ignore-parent --glob '!.git/' --smart-case -M 1280 ")
  2275. ;; git grep
  2276. ("gitgrep"
  2277. (eq 0
  2278. (shell-command "git rev-parse --git-dir"))
  2279. "git --no-pager grep -nH -e ")
  2280. ;; sift
  2281. ("sift"
  2282. (executable-find "sift")
  2283. ("sift --binary-skip --filename --line-number --git --smart-case "))
  2284. ;; the silver searcher
  2285. ("ag"
  2286. (executable-find "ag")
  2287. "ag --nogroup --nopager --filename ")
  2288. ;; ack
  2289. ("ack"
  2290. (executable-find "ack")
  2291. "ack --nogroup --nopager --with-filename ")
  2292. ;; gnu global
  2293. ("global"
  2294. (and (require 'ggtags nil t)
  2295. (executable-find "global")
  2296. (ggtags-current-project-root))
  2297. "global --result grep ")
  2298. ;; grep
  2299. ("grep"
  2300. t
  2301. ,(concat "find . "
  2302. "-path '*/.git' -prune -o "
  2303. "-path '*/.svn' -prune -o "
  2304. "-type f -print0 | "
  2305. "xargs -0 grep -nH -e "))
  2306. )
  2307. )
  2308. (defvar my-rgrep-default nil
  2309. "Default command name for my-rgrep.")
  2310. (defun my-rgrep-grep-command (&optional name alist)
  2311. "Return recursive grep command for current directory or nil.
  2312. If NAME is given, use that without testing.
  2313. Commands are searched from ALIST."
  2314. (if alist
  2315. (if name
  2316. ;; if name is given search that from alist and return the command
  2317. (nth 2 (assoc name
  2318. alist))
  2319. ;; if name is not given try test in 1th elem
  2320. (let ((car (car alist))
  2321. (cdr (cdr alist)))
  2322. (if (eval (nth 1 car))
  2323. ;; if the condition is true return the command
  2324. (nth 2 car)
  2325. ;; try next one
  2326. (and cdr
  2327. (my-rgrep-grep-command name cdr)))))
  2328. ;; if alist is not given set default value
  2329. (my-rgrep-grep-command name my-rgrep-alist)))
  2330. (declare-function projectile-project-p "projectile")
  2331. (declare-function projectile-with-default-dir "projectile")
  2332. (declare-function projectile-project-root "projectile")
  2333. (defun my-rgrep (command-args)
  2334. "My recursive grep. Run COMMAND-ARGS.
  2335. If prefix argument is given, use current symbol as default search target
  2336. and search from projectile root (if projectile is available)."
  2337. (interactive (let ((cmd (my-rgrep-grep-command my-rgrep-default
  2338. nil)))
  2339. (if cmd
  2340. (list (read-shell-command "grep command: "
  2341. (concat cmd
  2342. (if current-prefix-arg
  2343. (thing-at-point 'symbol t)
  2344. ""))
  2345. 'grep-find-history))
  2346. (error "My-Rgrep: Command for rgrep not found")
  2347. )))
  2348. (if (and current-prefix-arg
  2349. (eval-and-compile (require 'projectile nil t))
  2350. (projectile-project-p))
  2351. (projectile-with-default-dir (projectile-project-root)
  2352. (compilation-start command-args
  2353. 'grep-mode))
  2354. (compilation-start command-args
  2355. 'grep-mode)))
  2356. (defun my-rgrep-thing-at-point-projectile-root ()
  2357. "My recursive grep to find thing at point from project root."
  2358. (interactive)
  2359. (let* ((cmd (my-rgrep-grep-command my-rgrep-default
  2360. nil))
  2361. (command-args
  2362. (if cmd
  2363. (concat cmd
  2364. (or (thing-at-point 'symbol t)
  2365. (error "No symbol at point")))
  2366. (error "My-Rgrep: Command for rgrep not found"))))
  2367. (if (eval-and-compile (require 'projectile nil t))
  2368. (with-temp-buffer
  2369. (cd (or (projectile-project-root)
  2370. default-directory))
  2371. (compilation-start command-args
  2372. 'grep-mode))
  2373. (compilation-start command-args
  2374. 'grep-mode))))
  2375. (defmacro define-my-rgrep (name)
  2376. "Define rgrep for NAME."
  2377. `(defun ,(intern (concat "my-rgrep-"
  2378. name)) ()
  2379. ,(format "My recursive grep by %s."
  2380. name)
  2381. (interactive)
  2382. (let ((my-rgrep-default ,name))
  2383. (if (called-interactively-p 'any)
  2384. (call-interactively 'my-rgrep)
  2385. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  2386. )
  2387. (define-my-rgrep "ack")
  2388. (define-my-rgrep "ag")
  2389. (define-my-rgrep "rg")
  2390. (define-my-rgrep "sift")
  2391. (define-my-rgrep "gitgrep")
  2392. (define-my-rgrep "grep")
  2393. (define-my-rgrep "global")
  2394. (define-key ctl-x-map "s" 'my-rgrep)
  2395. (define-key ctl-x-map "." 'my-rgrep-thing-at-point-projectile-root)
  2396. (defun my-occur (regexp &optional region)
  2397. "My occur command to search REGEXP to search REGION."
  2398. (interactive (list (read-string "List lines matching regexp: "
  2399. (thing-at-point 'symbol t))))
  2400. (occur regexp nil region))
  2401. (define-key ctl-x-map (kbd "C-o") 'my-occur)
  2402. (set-variable 'dumb-jump-prefer-searcher 'rg)
  2403. (defalias 'make 'compile)
  2404. (define-key ctl-x-map "c" 'compile)
  2405. (autoload 'pb/push-item "pushbullet")
  2406. (defun my-pushbullet-note (text &optional title)
  2407. "Push TEXT with optional TITLE."
  2408. (interactive "sText to Push: ")
  2409. (pb/push-item '("") text "note" (or title "")))
  2410. ;;;;;;;;;;;;;;;;;;;
  2411. ;; peek-file-mode
  2412. (defvar peek-file-buffers
  2413. ()
  2414. "Peek buffers.")
  2415. (defun peek-file (file)
  2416. "Peek FILE."
  2417. (interactive "fFile to peek: ")
  2418. (with-current-buffer (find-file file)
  2419. (peek-file-mode)))
  2420. (define-minor-mode peek-file-mode
  2421. "Peek file mode."
  2422. :lighter "PK"
  2423. (view-mode peek-file-mode)
  2424. (add-to-list 'peek-file-buffers
  2425. (current-buffer))
  2426. (add-hook 'switch-buffer-functions
  2427. 'peek-file-remove-buffers))
  2428. (defun peek-file-remove-buffers (&args _)
  2429. "Remove peek file buffers."
  2430. (cl-dolist (buf (cl-copy-list peek-file-buffers))
  2431. (unless (get-buffer-window buf t)
  2432. (setq peek-file-buffers
  2433. (delq buf
  2434. peek-file-buffers))
  2435. (with-current-buffer buf
  2436. (when peek-file-mode
  2437. (kill-buffer))))))
  2438. (declare-function dired-get-file-for-visit "dired")
  2439. (with-eval-after-load 'dired
  2440. (defun dired-peek-file (&rest files)
  2441. "Dired `peak-file' FILES."
  2442. (interactive (list (dired-get-file-for-visit)))
  2443. (message "AAA %S" files)
  2444. (dolist (file files)
  2445. (peek-file file)))
  2446. (defvar dired-mode-map (make-sparse-keymap))
  2447. (define-key dired-mode-map "v" 'dired-peek-file))
  2448. ;;;;;;;;;;;;;;;;;;;;
  2449. ;; remember-projectile
  2450. ;; TODO: Add global-minor-mode
  2451. (defvar remember-data-file)
  2452. (defun my-set-remember-data-file-buffer-local ()
  2453. "Set `remember-data-file'."
  2454. (when (require 'projectile nil t)
  2455. (setq-local remember-data-file
  2456. (expand-file-name ".remember.notes"
  2457. (projectile-project-root)))))
  2458. (add-hook 'after-change-major-mode-hook
  2459. 'my-set-remember-data-file-buffer-local)
  2460. (define-key ctl-x-map "R" 'remember)
  2461. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2462. ;; ivy
  2463. (set-variable 'ivy-format-functions-alist
  2464. '((t . (lambda (cands) (ivy--format-function-generic
  2465. (lambda (str)
  2466. (concat "+> "
  2467. (ivy--add-face str 'ivy-current-match)
  2468. ))
  2469. (lambda (str)
  2470. (concat "| " str))
  2471. cands
  2472. "\n")))))
  2473. (set-variable 'ivy-wrap t)
  2474. (set-variable 'ivy-sort-max-size 500)
  2475. (when (fboundp 'ivy-rich-mode)
  2476. (ivy-rich-mode 1))
  2477. (with-eval-after-load 'ivy
  2478. (defvar ivy-minibuffer-map)
  2479. (define-key ivy-minibuffer-map (kbd "C-u")
  2480. (lambda () (interactive) (delete-region (point-at-bol) (point))))
  2481. (defvar ivy-sort-matches-functions-alist)
  2482. (add-to-list 'ivy-sort-matches-functions-alist
  2483. '(counsel-M-x . ivy--shorter-matches-first))
  2484. )
  2485. (set-variable 'ivy-on-del-error-function 'ignore)
  2486. (when (fboundp 'counsel-M-x)
  2487. (define-key esc-map "x" 'counsel-M-x)
  2488. )
  2489. (declare-function ivy-thing-at-point "ivy")
  2490. (when (and (fboundp 'ivy-read)
  2491. (locate-library "counsel"))
  2492. (defvar counsel-describe-map)
  2493. (defun my-counsel-describe-symbol ()
  2494. "Forwaord to `describe-symbol'."
  2495. (interactive)
  2496. (cl-assert (eval-and-compile (require 'help-mode nil t))) ;; describe-symbol-backends
  2497. (cl-assert (eval-and-compile (require 'counsel nil t)))
  2498. (ivy-read "Describe symbol: " obarray
  2499. ;; From describe-symbol definition
  2500. :predicate (lambda (vv)
  2501. (cl-some (lambda (x) (funcall (nth 1 x) vv))
  2502. describe-symbol-backends))
  2503. :require-match t
  2504. :history 'counsel-describe-symbol-history
  2505. :keymap counsel-describe-map
  2506. :preselect (ivy-thing-at-point)
  2507. :action (lambda (x)
  2508. (describe-symbol (intern x)))
  2509. :caller 'my-counsel-describe-symbol))
  2510. (define-key help-map "o" 'my-counsel-describe-symbol)
  2511. )
  2512. (declare-function ivy-configure "ivy")
  2513. (with-eval-after-load 'counsel ;; Hook to counsel, not ivy
  2514. ;; (ivy-configure 'my-counsel-describe-symbol
  2515. ;; :sort-fn 'my-ivy-length)
  2516. (ivy-configure 'counsel-M-x
  2517. ;; :initial-input ""
  2518. :sort-fn 'ivy-string<
  2519. )
  2520. )
  2521. (when (fboundp 'counsel-imenu)
  2522. (define-key ctl-x-map "l" 'counsel-imenu))
  2523. (when (fboundp 'swiper)
  2524. (define-key esc-map (kbd "C-s") 'swiper))
  2525. (with-eval-after-load 'ivy
  2526. ;; ivy-prescient requires counsel already loaded
  2527. (require 'counsel nil t)
  2528. (when (fboundp 'ivy-prescient-mode)
  2529. (set-variable 'prescient-sort-length-enable t)
  2530. (set-variable 'prescient-sort-full-matches-first t)
  2531. (set-variable 'ivy-prescient-enable-filtering t)
  2532. (set-variable 'ivy-prescient-enable-sorting nil)
  2533. ;; (set-variable 'ivy-prescient-sort-commands t)
  2534. (set-variable 'prescient-filter-method
  2535. '(literal prefix literal-prefix regexp initialism fuzzy))
  2536. (when (fboundp 'prescient-persist-mode)
  2537. (prescient-persist-mode t))
  2538. (ivy-prescient-mode 1)
  2539. ;; (set-variable 'ivy-sort-functions-alist
  2540. ;; '((t . ivy-string<)))
  2541. ))
  2542. ;; ?
  2543. (define-key input-decode-map "\e[1;5C" [C-right])
  2544. (define-key input-decode-map "\e[1;5D" [C-left])
  2545. ;;;;;;;;;;;;;;;;;;;;;;;;
  2546. ;; mozc
  2547. (global-set-key (kbd "C-c m e") 'ignore)
  2548. (global-set-key (kbd "C-c m d") 'ignore)
  2549. ;; mozc
  2550. (when (locate-library "mozc")
  2551. ;; https://tottoto.net/mac-emacs-karabiner-elements-japanese-input-method-config/
  2552. (with-eval-after-load 'mozc
  2553. ;; (define-key mozc-mode-map (kbd "C-h") 'backward-delete-char)
  2554. ;; (define-key mozc-mode-map (kbd "C-p") (kbd "<up>"))
  2555. ;; (define-key mozc-mode-map (kbd "C-n") (kbd "SPC"))
  2556. )
  2557. (setq default-input-method "japanese-mozc")
  2558. (custom-set-variables '(mozc-leim-title "あ"))
  2559. (defun turn-on-input-method ()
  2560. (interactive)
  2561. (activate-input-method default-input-method))
  2562. (defun turn-off-input-method ()
  2563. (interactive)
  2564. (deactivate-input-method))
  2565. ;; (setq mozc-candidate-style 'echo-area)
  2566. (global-set-key (kbd "C-c m e") 'turn-on-input-method)
  2567. (global-set-key (kbd "C-c m d") 'turn-off-input-method)
  2568. (global-set-key (kbd "<f7>") 'turn-off-input-method)
  2569. (global-set-key (kbd "<f8>") 'turn-on-input-method)
  2570. (require 'mozc-popup)
  2571. (set-variable 'mozc-candidate-style 'popup)
  2572. ;; これいる?
  2573. (when (require 'mozc-im nil t)
  2574. (setq default-input-method "japanese-mozc-im")
  2575. ;; (global-set-key (kbd "C-j") 'toggle-input-method)
  2576. )
  2577. )
  2578. (defun browse-url-macosx-vivaldi-browser (url &rest args)
  2579. "Invoke the macOS Vlvaldi Web browser with URL.
  2580. ARGS are not used."
  2581. (interactive (browse-url-interactive-arg "URL: "))
  2582. (start-process (concat "vivaldi " url)
  2583. nil
  2584. "/Applications/Vivaldi.app/Contents/MacOS/Vivaldi"
  2585. url))
  2586. (declare-function vterm "vterm")
  2587. ;; 前の実行結果を残したまま次のコマンドを実行する方法はあるだろうか
  2588. (defun my-vterm-cmd (command)
  2589. "Start arbitrary command in vterm buffer."
  2590. (interactive "sCommand: ")
  2591. (let ((vterm-shell command)
  2592. (vterm-buffer-name "*vterm-cmd*")
  2593. (vterm-kill-buffer-on-exit nil))
  2594. (when (get-buffer vterm-buffer-name)
  2595. (kill-buffer (get-buffer vterm-buffer-name)))
  2596. (vterm)))
  2597. ;; (setq vterm-shell "bash -l")
  2598. ;; (setq vterm-kill-buffer-on-exit nil)
  2599. ;; ;; (setq vterm-term-environment-variable "screen-256color")
  2600. ;; これいつ動くの?
  2601. ;; 自動で project を switch させる方法はある?
  2602. (add-hook 'projectile-after-switch-project-hook
  2603. (lambda ()
  2604. (message "Projecttile switched to: %s"
  2605. (projectile-project-root))))
  2606. (when (fboundp 'projectile-mode)
  2607. (projectile-mode 1))
  2608. ;; (with-eval-after-load 'eglot
  2609. ;; (when (fboundp 'with-venv-advice-add)
  2610. ;; (with-venv-advice-add 'eglot--executable-find))
  2611. ;; (set-variable 'eldoc-echo-area-use-multiline-p nil)
  2612. ;; (set-variable 'eglot-extend-to-xref t))
  2613. (set-variable 'lsp-python-ms-auto-install-server t)
  2614. (set-variable 'lsp-python-ms-parse-dot-env-enabled t)
  2615. (set-variable 'lsp-python-ms-python-executable-cmd "python3")
  2616. ;; (add-hook 'python-mode-hook #'my-lsp-python-setup)
  2617. (defun my-lsp-python-setup ()
  2618. "Setup python ms."
  2619. (when (and (fboundp 'lsp)
  2620. (require 'lsp-python-ms nil t))
  2621. (lsp)))
  2622. (set-variable 'awk-preview-default-program
  2623. "# C-c C-l: Update preview C-c C-c: Commit and exit
  2624. # C-c C-r: Resest to original C-c C-k: Abort
  2625. BEGIN {
  2626. # FS = \",\"
  2627. }
  2628. {
  2629. # Replace string
  2630. # gsub(BEFORE, AFTER, $0)
  2631. print NR, $0
  2632. }
  2633. ")
  2634. (message "Emacs started at %s"
  2635. (current-time-string))
  2636. (run-with-idle-timer (* 3 60 60) ;; 3 hours
  2637. t
  2638. (lambda ()
  2639. (message "Emacs does nothing for 3 hours: %s"
  2640. (current-time-string))))
  2641. ;; https://emacs-jp.github.io/tips/startup-optimization
  2642. ;; Restore to original value
  2643. (setq gc-cons-threshold my-orig-gc-cons-threshold)
  2644. (setq file-name-handler-alist my-orig-file-name-handler-alist)
  2645. (when (getenv "_EMACS_EL_PROFILE")
  2646. (profiler-report)
  2647. (profiler-stop))
  2648. ;; Local Variables:
  2649. ;; flycheck-disabled-checkers: (emacs-lisp-checkdoc)
  2650. ;; flycheck-checker: emacs-lisp
  2651. ;; End:
  2652. ;;; emancs.el ends here