Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

3089 řádky
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. ;; C-x B: Add bookmark
  1184. ;; C-x b: List bookmarks
  1185. (set-variable 'bookmark-default-file
  1186. (expand-file-name (concat user-emacs-directory
  1187. "bmk")))
  1188. (set-variable 'bookmark-sort-flag nil)
  1189. (defun my-bookmark-set ()
  1190. "My `bookmark-set'."
  1191. (interactive)
  1192. (cl-assert (or buffer-file-name
  1193. default-directory))
  1194. (let ((name (file-name-nondirectory (or buffer-file-name
  1195. (directory-file-name default-directory))))
  1196. (linenum (count-lines (point-min)
  1197. (point)))
  1198. (linetext (buffer-substring-no-properties (point-at-bol)
  1199. (point-at-eol))))
  1200. (bookmark-set (format "%s:%d:%s"
  1201. name linenum linetext)
  1202. nil)))
  1203. ;; Done by advice instead
  1204. ;; (set-variable 'bookmark-save-flag
  1205. ;; 1)
  1206. (with-eval-after-load 'recentf
  1207. (defvar recentf-exclude)
  1208. (defvar bookmark-default-file)
  1209. (add-to-list 'recentf-exclude
  1210. (regexp-quote bookmark-default-file)))
  1211. (defvar bookmark-default-file)
  1212. (defun my-bookmark-set--advice (orig-func &rest args)
  1213. "Function for `bookmark-set-internal'.
  1214. ORIG-FUNC is the target function, and ARGS is the argument when it is called."
  1215. (bookmark-load bookmark-default-file)
  1216. (apply orig-func args)
  1217. (bookmark-save nil bookmark-default-file))
  1218. (with-eval-after-load 'bookmark
  1219. (advice-add 'bookmark-set-internal
  1220. :around
  1221. 'my-bookmark-set--advice)
  1222. (unless (file-readable-p bookmark-default-file)
  1223. (bookmark-save nil bookmark-default-file)))
  1224. (define-key ctl-x-map "b" 'list-bookmarks)
  1225. (when (fboundp 'counsel-bookmark)
  1226. (define-key ctl-x-map "b" 'counsel-bookmark))
  1227. (define-key ctl-x-map "B" 'my-bookmark-set)
  1228. ;; vc
  1229. (set-variable 'vc-handled-backends '(RCS))
  1230. (set-variable 'vc-rcs-register-switches "-l")
  1231. (set-variable 'vc-rcs-checkin-switches "-l")
  1232. (set-variable 'vc-command-messages t)
  1233. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1234. ;; share clipboard with x
  1235. ;; this page describes this in details, but only these sexps seem to be needed
  1236. ;; http://garin.jp/doc/Linux/xwindow_clipboard
  1237. (and nil
  1238. (not window-system)
  1239. (not (eq window-system 'mac))
  1240. (getenv "DISPLAY")
  1241. (not (equal (getenv "DISPLAY") ""))
  1242. (executable-find "xclip")
  1243. ;; (< emacs-major-version 24)
  1244. '(require 'xclip nil t)
  1245. nil
  1246. (turn-on-xclip))
  1247. (declare-function turn-on-pasteboard "pasteboard")
  1248. (and (eq system-type 'darwin)
  1249. (require 'pasteboard nil t)
  1250. (turn-on-pasteboard))
  1251. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1252. ;; some modes and hooks
  1253. ;; Include some extra modes
  1254. (require 'generic-x)
  1255. ;; Derived from https://github.com/ensime/ensime-emacs/issues/591#issuecomment-291916753
  1256. (defun my-scalafmt ()
  1257. (interactive)
  1258. (cl-assert buffer-file-name)
  1259. (cl-assert (not (buffer-modified-p)))
  1260. (let* ((configdir (locate-dominating-file default-directory ".scalafmt.conf"))
  1261. (configoption (if configdir
  1262. (concat " --config "
  1263. (shell-quote-argument (expand-file-name configdir))
  1264. ".scalafmt.conf"
  1265. )
  1266. ""))
  1267. (str (concat "scalafmt -f "
  1268. (shell-quote-argument buffer-file-name)
  1269. configoption
  1270. " -i --exclude ensime")))
  1271. (message str)
  1272. (shell-command-to-string str))
  1273. (message "scalafmt done")
  1274. (revert-buffer nil t))
  1275. (when (fboundp 'web-mode)
  1276. (add-to-list 'auto-mode-alist
  1277. '("\\.html\\.j2\\'" . web-mode))
  1278. (add-to-list 'auto-mode-alist
  1279. ;; Django Template Language
  1280. '("\\.dtl\\'" . web-mode))
  1281. )
  1282. (when (locate-library "wgrep")
  1283. (set-variable 'wgrep-auto-save-buffer t)
  1284. (with-eval-after-load 'grep
  1285. (defvar grep-mode-map)
  1286. (define-key grep-mode-map
  1287. "e"
  1288. 'wgrep-change-to-wgrep-mode)))
  1289. (when (fboundp 'grep-context-mode)
  1290. (add-hook 'compilation-mode-hook #'grep-context-mode))
  1291. (with-eval-after-load 'remember
  1292. (defvar remember-mode-map)
  1293. (define-key remember-mode-map (kbd "C-x C-s") 'ignore))
  1294. (set-variable 'remember-notes-initial-major-mode
  1295. 'change-log-mode)
  1296. (set-variable 'magit-define-global-key-bindings nil)
  1297. (with-eval-after-load 'magit-section
  1298. (set-face-background 'magit-section-highlight
  1299. nil))
  1300. ;; Sane colors
  1301. (with-eval-after-load 'magit-diff
  1302. (set-face-background 'magit-diff-context nil)
  1303. (set-face-background 'magit-diff-context-highlight nil)
  1304. (set-face-foreground 'magit-diff-hunk-heading nil)
  1305. (set-face-background 'magit-diff-hunk-heading nil)
  1306. (set-face-foreground 'magit-diff-hunk-heading-highlight nil)
  1307. (set-face-background 'magit-diff-hunk-heading-highlight nil)
  1308. ;; https://blog.shibayu36.org/entry/2016/03/27/220552
  1309. (set-face-foreground 'magit-diff-added "green")
  1310. (set-face-background 'magit-diff-added nil)
  1311. (set-face-foreground 'magit-diff-added-highlight "green")
  1312. (set-face-background 'magit-diff-added-highlight nil)
  1313. (set-face-foreground 'magit-diff-removed "red")
  1314. (set-face-background 'magit-diff-removed nil)
  1315. (set-face-foreground 'magit-diff-removed-highlight "red")
  1316. (set-face-background 'magit-diff-removed-highlight nil)
  1317. (set-face-background 'magit-diff-lines-boundary "blue")
  1318. )
  1319. (declare-function magit-show-commit "magit")
  1320. (defun my-magit-messenger (file line)
  1321. "Magit messenger."
  1322. (interactive (list buffer-file-name
  1323. (line-number-at-pos)))
  1324. (cl-assert file)
  1325. (cl-assert line)
  1326. (let* ((blame-args '("-w"))
  1327. (id (with-temp-buffer
  1328. (let ((exit (apply 'call-process
  1329. "git" ;; PROGRAM
  1330. nil ;; INFILE
  1331. t ;; DESTINATION
  1332. nil ;; DISPLAY
  1333. "--no-pager" ;; ARGS
  1334. "blame"
  1335. "-L"
  1336. (format "%d,+1" line)
  1337. "--porcelain"
  1338. file
  1339. blame-args
  1340. )))
  1341. (goto-char (point-min))
  1342. (cl-assert (eq exit 0)
  1343. "Failed: %s" (buffer-substring (point)
  1344. (point-at-eol)))
  1345. (save-match-data
  1346. (re-search-forward (rx buffer-start
  1347. (one-or-more hex-digit)))
  1348. (match-string 0))))))
  1349. (magit-show-commit id)))
  1350. (when (boundp 'git-rebase-filename-regexp)
  1351. (add-to-list 'auto-mode-alist
  1352. `(,git-rebase-filename-regexp . text-mode)))
  1353. (when (fboundp 'ggtags-mode)
  1354. (add-hook 'c-mode-common-hook
  1355. 'ggtags-mode)
  1356. (add-hook 'python-mode-hook
  1357. 'ggtags-mode)
  1358. (add-hook 'js-mode-hook
  1359. 'ggtags-mode)
  1360. (add-hook 'scheme-mode-hook
  1361. 'ggtags-mode)
  1362. )
  1363. (when (fboundp 'imenu-list-minor-mode)
  1364. (defvar imenu-list-buffer-name)
  1365. (defun my-imenu-list-toggle ()
  1366. "My 'imenu-list` toggle."
  1367. (interactive)
  1368. (require 'imenu-list)
  1369. (if (eq (window-buffer)
  1370. (get-buffer imenu-list-buffer-name))
  1371. (imenu-list-minor-mode -1)
  1372. (imenu-list-minor-mode 1)))
  1373. ;; (set-variable 'imenu-list-auto-resize t)
  1374. (set-variable 'imenu-list-focus-after-activation t)
  1375. ;; (define-key ctl-x-map (kbd "C-l") 'my-imenu-list-toggle)
  1376. (define-key ctl-x-map (kbd "C-l") 'imenu-list-smart-toggle)
  1377. )
  1378. (add-hook 'emacs-lisp-mode-hook
  1379. (lambda ()
  1380. (setq imenu-generic-expression
  1381. `(("Sections" ";;;\+\n;; \\(.*\\)\n" 1)
  1382. ,@imenu-generic-expression))))
  1383. ;; TODO: Try paraedit http://daregada.blogspot.com/2012/03/paredit.html
  1384. (with-eval-after-load 'compile
  1385. (defvar compilation-filter-start)
  1386. (defvar compilation-error-regexp-alist)
  1387. (eval-and-compile (require 'ansi-color))
  1388. (add-hook 'compilation-filter-hook
  1389. (lambda ()
  1390. (let ((inhibit-read-only t))
  1391. (ansi-color-apply-on-region compilation-filter-start
  1392. (point)))))
  1393. (add-to-list 'compilation-error-regexp-alist
  1394. ;; ansible-lint
  1395. '("^\\([^ \n]+\\):\\([0-9]+\\)$" 1 2))
  1396. (add-to-list 'compilation-error-regexp-alist
  1397. ;; pydocstyle
  1398. '("^\\([^ \n]+\\):\\([0-9]+\\) " 1 2))
  1399. )
  1400. (declare-function company-cancel "company")
  1401. (when (fboundp 'global-company-mode)
  1402. (add-hook 'after-first-visit-hook
  1403. 'global-company-mode))
  1404. ;; http://qiita.com/sune2/items/b73037f9e85962f5afb7
  1405. ;; https://qiita.com/yuze/items/a145b1e3edb6d0c24cbf
  1406. (set-variable 'company-idle-delay nil)
  1407. (set-variable 'company-minimum-prefix-length 2)
  1408. (set-variable 'company-selection-wrap-around t)
  1409. (set-variable 'company-global-modes '(not term-char-mode
  1410. term-line-mode))
  1411. (declare-function company-manual-begin "company")
  1412. (with-eval-after-load 'company
  1413. (defvar company-mode-map)
  1414. (define-key company-mode-map (kbd "C-i") 'company-indent-or-complete-common)
  1415. ;; (with-eval-after-load 'python
  1416. ;; (defvar python-indent-trigger-commands)
  1417. ;; ;; TODO: This disables completion in python?
  1418. ;; (add-to-list 'python-indent-trigger-commands
  1419. ;; 'company-indent-or-complete-common))
  1420. (define-key ctl-x-map (kbd "C-i") 'company-complete) ; Originally `indent-rigidly'
  1421. (defvar company-active-map)
  1422. (define-key company-active-map (kbd "C-n") 'company-select-next)
  1423. (define-key company-active-map (kbd "C-p") 'company-select-previous)
  1424. (define-key company-active-map (kbd "C-s") 'company-filter-candidates)
  1425. (define-key company-active-map (kbd "C-i") 'company-complete-selection)
  1426. (define-key company-active-map (kbd "C-f") 'company-complete-selection)
  1427. (defvar company-mode)
  1428. (defvar company-candidates)
  1429. (defvar company-candidates-length)
  1430. ;; (popup-tip "Hello, World!")
  1431. (defun my-company-lighter-current-length ()
  1432. "Get current candidate length."
  1433. (interactive)
  1434. (let ((l nil)
  1435. (inhibit-message t))
  1436. (when (and company-mode
  1437. (not (minibufferp))
  1438. ;; Do nothing when already in company completion
  1439. (not company-candidates))
  1440. ;; FIXME: Somehow it cannto catch errors from ggtags
  1441. (ignore-errors
  1442. ;; (company-auto-begin)
  1443. (company-manual-begin)
  1444. (setq l company-candidates-length)
  1445. (company-cancel)))
  1446. (if l
  1447. (format "[%d]" l)
  1448. "")))
  1449. (defvar company-lighter)
  1450. (set-variable 'company-lighter-base "Cmp")
  1451. ;; (add-to-list 'company-lighter
  1452. ;; '(:eval (my-company-lighter-current-length))
  1453. ;; t)
  1454. ;; This breaks japanese text input
  1455. ;; (set-variable 'my-company-length-popup-tip-timer
  1456. ;; (run-with-idle-timer 0.2 t
  1457. ;; 'my-company-length-popup-tip))
  1458. ;; (current-active-maps)
  1459. ;; (lookup-key)
  1460. '(mapcar (lambda (map)
  1461. (lookup-key map (kbd "C-i")))
  1462. (current-active-maps))
  1463. ;; https://qiita.com/syohex/items/8d21d7422f14e9b53b17
  1464. (set-face-attribute 'company-tooltip nil
  1465. :foreground "black" :background "lightgrey")
  1466. (set-face-attribute 'company-tooltip-common nil
  1467. :foreground "black" :background "lightgrey")
  1468. (set-face-attribute 'company-tooltip-common-selection nil
  1469. :foreground "white" :background "steelblue")
  1470. (set-face-attribute 'company-tooltip-selection nil
  1471. :foreground "black" :background "steelblue")
  1472. (set-face-attribute 'company-preview-common nil
  1473. :background nil :foreground "lightgrey" :underline t)
  1474. (set-face-attribute 'company-scrollbar-fg nil
  1475. :background "orange")
  1476. (set-face-attribute 'company-scrollbar-bg nil
  1477. :background "gray40")
  1478. )
  1479. ;; https://github.com/lunaryorn/flycheck
  1480. ;; TODO: Any way to disable auto check?
  1481. ;; Update flycheck-hooks-alist?
  1482. (when (fboundp 'global-flycheck-mode)
  1483. (add-hook 'after-first-visit-hook
  1484. 'global-flycheck-mode))
  1485. ;; (set-variable 'flycheck-display-errors-delay 2.0)
  1486. ;; (fset 'flycheck-display-error-at-point-soon 'ignore)
  1487. ;; (with-eval-after-load 'flycheck
  1488. ;; (when (fboundp 'flycheck-black-check-setup)
  1489. ;; (flycheck-black-check-setup)))
  1490. ;; (when (fboundp 'ilookup-open-word)
  1491. ;; (define-key ctl-x-map "d" 'ilookup-open-word)
  1492. ;; )
  1493. (set-variable 'ac-ignore-case nil)
  1494. (when (fboundp 'term-run-shell-command)
  1495. (define-key ctl-x-map "t" 'term-run-shell-command))
  1496. (add-to-list 'safe-local-variable-values
  1497. '(encoding utf-8))
  1498. (setq enable-local-variables :safe)
  1499. ;; Detect file type from shebang and set major-mode.
  1500. (add-to-list 'interpreter-mode-alist
  1501. '("python3" . python-mode))
  1502. (add-to-list 'interpreter-mode-alist
  1503. '("python2" . python-mode))
  1504. (with-eval-after-load 'python
  1505. (defvar python-mode-map (make-sparse-keymap))
  1506. (define-key python-mode-map (kbd "C-m") 'newline-and-indent))
  1507. ;; I want to use this, but this breaks normal self-insert-command
  1508. ;; (set-variable 'py-indent-list-style
  1509. ;; 'one-level-to-beginning-of-statement)
  1510. (set-variable 'pydoc-command
  1511. "python3 -m pydoc")
  1512. (declare-function with-venv-advice-add "with-venv")
  1513. (with-eval-after-load 'pydoc
  1514. ;; pydoc depends on python-shell-interpreter but it does not load this
  1515. (require 'python)
  1516. (when (require 'with-venv nil t)
  1517. (with-venv-advice-add 'pydoc)
  1518. ;; Used in interactive function of pydoc
  1519. (with-venv-advice-add 'pydoc-all-modules)))
  1520. (defvar my-cousel-pydoc-history nil "History of `my-counsel-pydoc'.")
  1521. (defun my-counsel-pydoc ()
  1522. "Counsel `pydoc'."
  1523. (interactive)
  1524. (eval-and-compile (require 'pydoc nil t))
  1525. (ivy-read "Recently: " (pydoc-all-modules)
  1526. :require-match t
  1527. :history 'my-cousel-pydoc-history
  1528. :action (lambda (x) (pydoc x))
  1529. :caller 'my-counsel-pydoc))
  1530. (set-variable 'flycheck-python-mypy-config '("mypy.ini" ".mypy.ini" "setup.cfg"))
  1531. (set-variable 'flycheck-flake8rc '("setup.cfg" "tox.ini" ".flake8rc"))
  1532. (set-variable 'flycheck-python-pylint-executable "python3")
  1533. (set-variable 'flycheck-python-pycompile-executable "python3")
  1534. (set-variable 'python-indent-guess-indent-offset nil)
  1535. (with-eval-after-load 'blacken
  1536. (when (require 'with-venv nil t)
  1537. (with-venv-advice-add 'blacken-buffer)))
  1538. (with-eval-after-load 'ansible-doc
  1539. (when (require 'with-venv nil t)
  1540. (with-venv-advice-add 'ansible-doc)))
  1541. ;; `isortify-buffer' breaks buffer when it contains japanese text
  1542. (defun my-isortify ()
  1543. (interactive)
  1544. (cl-assert buffer-file-name)
  1545. (cl-assert (not (buffer-modified-p)))
  1546. (call-process "python" ;; PROGRAM
  1547. nil ;; INFILE
  1548. nil ;; DESTINATION
  1549. nil ;; DISPLAY
  1550. "-m" "isort" buffer-file-name)
  1551. (message "isortify done")
  1552. (revert-buffer nil t))
  1553. (when (fboundp 'with-venv-advice-add)
  1554. ;; TODO: Lazy load with-venv
  1555. (with-venv-advice-add 'my-isortify))
  1556. ;; https://github.com/lunaryorn/old-emacs-configuration/blob/master/lisp/flycheck-virtualenv.el
  1557. (defun my-set-venv-flycheck-executable-find ()
  1558. "Set flycheck executabie find."
  1559. (interactive)
  1560. (when (fboundp 'with-venv)
  1561. (set-variable 'flycheck-executable-find
  1562. '(lambda (e)
  1563. (with-venv
  1564. (executable-find e)))
  1565. t)))
  1566. (defun my-update-flycheck-flake8-error-level-alist ()
  1567. "Update `flycheck-flake8-error-level-alist'."
  1568. (defvar flycheck-flake8-error-level-alist)
  1569. ;; (add-to-list 'flycheck-flake8-error-level-alist
  1570. ;; '("^D.*$" . warning))
  1571. (set-variable 'flycheck-flake8-error-level-alist
  1572. nil)
  1573. )
  1574. (add-hook 'python-mode-hook
  1575. 'my-set-venv-flycheck-executable-find)
  1576. (add-hook 'python-mode-hook
  1577. 'my-update-flycheck-flake8-error-level-alist)
  1578. (when (fboundp 'with-venv-info-mode)
  1579. (add-hook 'python-mode-hook
  1580. 'with-venv-info-mode))
  1581. ;; Run multiple chekcers
  1582. ;; https://github.com/flycheck/flycheck/issues/186
  1583. (add-hook 'python-mode-hook
  1584. (lambda ()
  1585. ;; Currently on python-mode eldoc-mode sometimes print
  1586. ;; wired message on "from" keyword:
  1587. ;;var from = require("./from")
  1588. (eldoc-mode -1)))
  1589. ;; http://fukuyama.co/foreign-regexp
  1590. '(and (require 'foreign-regexp nil t)
  1591. (progn
  1592. (setq foreign-regexp/regexp-type 'perl)
  1593. '(setq reb-re-syntax 'foreign-regexp)
  1594. ))
  1595. (with-eval-after-load 'sql
  1596. (require 'sql-indent nil t))
  1597. (set-variable 'sqlind-basic-offset 4)
  1598. (add-to-list 'auto-mode-alist
  1599. '("\\.hql\\'" . sql-mode))
  1600. (set-variable 'sql-product 'postgres)
  1601. (set-variable 'sqlformat-command 'pgformatter)
  1602. (when (fboundp 'git-command)
  1603. (define-key ctl-x-map "g" 'git-command))
  1604. (when (fboundp 'gited-list)
  1605. (defalias 'gited 'gited-list))
  1606. (when (and (eval-and-compile (require 'git-commit nil t))
  1607. (fboundp 'global-git-commit-mode))
  1608. ;; git-commit is defined badly and breaks the convention that only loading a
  1609. ;; library should not change the Emacs behavior:
  1610. ;; anyway I enable this manually here.
  1611. (global-git-commit-mode 1))
  1612. (with-eval-after-load 'git-commit
  1613. (add-hook 'git-commit-setup-hook
  1614. 'turn-off-auto-fill t))
  1615. (with-eval-after-load 'rst
  1616. (defvar rst-mode-map)
  1617. (define-key rst-mode-map (kbd "C-m") 'newline-and-indent))
  1618. (with-eval-after-load 'jdee
  1619. (add-hook 'jdee-mode-hook
  1620. (lambda ()
  1621. (make-local-variable 'global-mode-string)
  1622. (add-to-list 'global-mode-string
  1623. mode-line-position))))
  1624. ;; Cannot enable error thrown. Why???
  1625. ;; https://github.com/m0smith/malabar-mode#Installation
  1626. ;; (when (require 'malabar-mode nil t)
  1627. ;; (add-to-list 'load-path
  1628. ;; (expand-file-name (concat user-emacs-directory "/cedet")))
  1629. ;; (require 'cedet-devel-load nil t)
  1630. ;; (eval-after-init (activate-malabar-mode)))
  1631. (with-eval-after-load 'make-mode
  1632. (defvar makefile-mode-map (make-sparse-keymap))
  1633. (define-key makefile-mode-map (kbd "C-m") 'newline-and-indent)
  1634. ;; this functions is set in write-file-functions, i cannot find any
  1635. ;; good way to remove this.
  1636. (fset 'makefile-warn-suspicious-lines 'ignore))
  1637. (with-eval-after-load 'verilog-mode
  1638. (defvar verilog-mode-map (make-sparse-keymap))
  1639. (define-key verilog-mode-map ";" 'self-insert-command))
  1640. (setq diff-switches "-u")
  1641. (autoload 'diff-goto-source "diff-mode" nil t)
  1642. (with-eval-after-load 'diff-mode
  1643. ;; (when (and (eq major-mode
  1644. ;; 'diff-mode)
  1645. ;; (not buffer-file-name))
  1646. ;; ;; do not pass when major-mode is derived mode of diff-mode
  1647. ;; (view-mode 1))
  1648. (set-face-attribute 'diff-header nil
  1649. :foreground nil
  1650. :background nil
  1651. :weight 'bold)
  1652. (set-face-attribute 'diff-file-header nil
  1653. :foreground nil
  1654. :background nil
  1655. :weight 'bold)
  1656. (set-face-foreground 'diff-index "blue")
  1657. (set-face-attribute 'diff-hunk-header nil
  1658. :foreground "cyan"
  1659. :weight 'normal)
  1660. (set-face-attribute 'diff-context nil
  1661. ;; :foreground "white"
  1662. :foreground nil
  1663. :weight 'normal)
  1664. (set-face-foreground 'diff-removed "red")
  1665. (set-face-foreground 'diff-added "green")
  1666. (set-face-background 'diff-removed nil)
  1667. (set-face-background 'diff-added nil)
  1668. (set-face-attribute 'diff-changed nil
  1669. :foreground "magenta"
  1670. :weight 'normal)
  1671. (set-face-attribute 'diff-refine-changed nil
  1672. :foreground nil
  1673. :background nil
  1674. :weight 'bold
  1675. :inverse-video t)
  1676. ;; Annoying !
  1677. ;;(diff-auto-refine-mode)
  1678. (set-variable 'diff-refine nil)
  1679. )
  1680. ;; (ffap-bindings)
  1681. (with-eval-after-load 'browse-url
  1682. (set-variable 'browse-url-browser-function
  1683. 'eww-browse-url))
  1684. (set-variable 'sh-here-document-word "__EOC__")
  1685. (with-eval-after-load 'adoc-mode
  1686. (defvar adoc-mode-map)
  1687. (define-key adoc-mode-map (kbd "C-m") 'newline))
  1688. (when (fboundp 'adoc-mode)
  1689. (setq auto-mode-alist
  1690. `(("\\.adoc\\'" . adoc-mode)
  1691. ("\\.asciidoc\\'" . adoc-mode)
  1692. ,@auto-mode-alist)))
  1693. (with-eval-after-load 'markup-faces
  1694. ;; Is this too match ?
  1695. (set-face-foreground 'markup-meta-face
  1696. "color-245")
  1697. (set-face-foreground 'markup-meta-hide-face
  1698. "color-245")
  1699. )
  1700. ;; TODO: check if this is required
  1701. (with-eval-after-load 'groovy-mode
  1702. (defvar groovy-mode-map)
  1703. (define-key groovy-mode-map "(" 'self-insert-command)
  1704. (define-key groovy-mode-map ")" 'self-insert-command)
  1705. (define-key groovy-mode-map (kbd "C-m") 'newline-and-indent)
  1706. )
  1707. (when (fboundp 'groovy-mode)
  1708. (add-to-list 'auto-mode-alist
  1709. '("build\\.gradle\\'" . groovy-mode)))
  1710. (add-to-list 'auto-mode-alist
  1711. '("\\.gawk\\'" . awk-mode))
  1712. (with-eval-after-load 'yaml-mode
  1713. (defvar yaml-mode-map (make-sparse-keymap))
  1714. (define-key yaml-mode-map (kbd "C-m") 'newline))
  1715. (with-eval-after-load 'html-mode
  1716. (defvar html-mode-map (make-sparse-keymap))
  1717. (define-key html-mode-map (kbd "C-m") 'reindent-then-newline-and-indent))
  1718. (with-eval-after-load 'text-mode
  1719. (define-key text-mode-map (kbd "C-m") 'newline))
  1720. (with-eval-after-load 'info
  1721. (defvar Info-additional-directory-list)
  1722. (dolist (dir (directory-files (concat user-emacs-directory
  1723. "info")
  1724. t
  1725. "^[^.].*"))
  1726. (when (file-directory-p dir)
  1727. (add-to-list 'Info-additional-directory-list
  1728. dir)))
  1729. (let ((dir (expand-file-name "~/.brew/share/info")))
  1730. (when (file-directory-p dir)
  1731. (add-to-list 'Info-additional-directory-list
  1732. dir))))
  1733. (with-eval-after-load 'apropos
  1734. (defvar apropos-mode-map (make-sparse-keymap))
  1735. (define-key apropos-mode-map "n" 'next-line)
  1736. (define-key apropos-mode-map "p" 'previous-line))
  1737. ;; `isearch' library does not call `provide' so cannot use with-eval-after-load
  1738. ;; (define-key isearch-mode-map
  1739. ;; (kbd "C-j") 'isearch-other-control-char)
  1740. ;; (define-key isearch-mode-map
  1741. ;; (kbd "C-k") 'isearch-other-control-char)
  1742. ;; (define-key isearch-mode-map
  1743. ;; (kbd "C-h") 'isearch-other-control-char)
  1744. (define-key isearch-mode-map (kbd "C-h") 'isearch-del-char)
  1745. (define-key isearch-mode-map (kbd "M-r")
  1746. 'isearch-query-replace-regexp)
  1747. ;; do not cleanup isearch highlight: use `lazy-highlight-cleanup' to remove
  1748. (setq lazy-highlight-cleanup nil)
  1749. ;; face for isearch highlighting
  1750. (set-face-attribute 'lazy-highlight
  1751. nil
  1752. :foreground `unspecified
  1753. :background `unspecified
  1754. :underline t
  1755. ;; :weight `bold
  1756. )
  1757. (add-hook 'outline-mode-hook
  1758. (lambda ()
  1759. (when (string-match "\\.md\\'" buffer-file-name)
  1760. (setq-local outline-regexp "#+ "))))
  1761. (add-hook 'outline-mode-hook
  1762. 'outline-show-all)
  1763. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  1764. (with-eval-after-load 'markdown-mode
  1765. (defvar gfm-mode-map)
  1766. (define-key gfm-mode-map (kbd "C-m") 'electric-indent-just-newline)
  1767. (define-key gfm-mode-map "`" nil) ;; markdown-electric-backquote
  1768. )
  1769. (when (fboundp 'gfm-mode)
  1770. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'gfm-mode))
  1771. (add-hook 'markdown-mode-hook
  1772. 'outline-minor-mode)
  1773. (add-hook 'markdown-mode-hook
  1774. (lambda ()
  1775. (setq-local comment-start ";")))
  1776. )
  1777. ;; http://keisanbutsuriya.hateblo.jp/entry/2015/02/10/152543
  1778. ;; M-$ to ispell word
  1779. ;; M-x flyspell-buffer to highlight all suspicious words
  1780. (when (executable-find "aspell")
  1781. (set-variable 'ispell-program-name "aspell")
  1782. (set-variable 'ispell-extra-args '("--lang=en_US")))
  1783. (with-eval-after-load 'ispell
  1784. (add-to-list 'ispell-skip-region-alist '("[^\000-\377]+")))
  1785. (when (fboundp 'flyspell-mode)
  1786. (add-hook 'text-mode-hook
  1787. 'flyspell-mode))
  1788. (when (fboundp 'flyspell-prog-mode)
  1789. (add-hook 'prog-mode-hook
  1790. 'flyspell-prog-mode))
  1791. ;; c-mode
  1792. ;; http://www.emacswiki.org/emacs/IndentingC
  1793. ;; http://en.wikipedia.org/wiki/Indent_style
  1794. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  1795. ;; http://seesaawiki.jp/whiteflare503/d/Emacs%20%a5%a4%a5%f3%a5%c7%a5%f3%a5%c8
  1796. (with-eval-after-load 'cc-vars
  1797. (defvar c-default-style nil)
  1798. (add-to-list 'c-default-style
  1799. '(c-mode . "k&r"))
  1800. (add-to-list 'c-default-style
  1801. '(c++-mode . "k&r")))
  1802. (add-to-list 'auto-mode-alist
  1803. '("\\.gs\\'" . js-mode))
  1804. (with-eval-after-load 'js2-mode
  1805. ;; currently do not use js2-mode
  1806. ;; (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  1807. ;; (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode))
  1808. ;; (defvar js2-mode-map (make-sparse-keymap))
  1809. ;; (define-key js2-mode-map (kbd "C-m") (lambda ()
  1810. ;; (interactive)
  1811. ;; (js2-enter-key)
  1812. ;; (indent-for-tab-command)))
  1813. ;; (add-hook (kill-local-variable 'before-save-hook)
  1814. ;; 'js2-before-save)
  1815. ;; (add-hook 'before-save-hook
  1816. ;; 'my-indent-buffer
  1817. ;; nil
  1818. ;; t)
  1819. )
  1820. (add-to-list 'interpreter-mode-alist
  1821. '("node" . js-mode))
  1822. (add-hook 'js-mode-hook
  1823. (lambda ()
  1824. ;; Stop current line highlighting
  1825. (set-variable 'js-indent-level 2 t)
  1826. ))
  1827. (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
  1828. (with-eval-after-load 'uniquify
  1829. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  1830. (setq uniquify-ignore-buffers-re "*[^*]+*")
  1831. (setq uniquify-min-dir-content 1))
  1832. (with-eval-after-load 'view
  1833. (defvar view-mode-map (make-sparse-keymap))
  1834. (define-key view-mode-map "j" 'scroll-up-line)
  1835. (define-key view-mode-map "k" 'scroll-down-line)
  1836. (define-key view-mode-map "v" 'toggle-read-only)
  1837. (define-key view-mode-map "q" 'bury-buffer)
  1838. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  1839. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  1840. ;; (define-key view-mode-map
  1841. ;; "n" 'nonincremental-repeat-search-forward)
  1842. ;; (define-key view-mode-map
  1843. ;; "N" 'nonincremental-repeat-search-backward)
  1844. ;; N conflicts with git-walktree
  1845. ;; (define-key view-mode-map "/" 'isearch-forward-regexp)
  1846. ;; (define-key view-mode-map "?" 'isearch-backward-regexp)
  1847. ;; (define-key view-mode-map "n" 'isearch-repeat-forward)
  1848. ;; (define-key view-mode-map "N" 'isearch-repeat-backward)
  1849. (define-key view-mode-map (kbd "C-m") 'my-rgrep-symbol-at-point))
  1850. (global-set-key "\M-r" 'view-mode)
  1851. ;; (setq view-read-only t)
  1852. (with-eval-after-load 'term
  1853. (defvar term-raw-map (make-sparse-keymap))
  1854. (define-key term-raw-map (kbd "C-x")
  1855. (lookup-key (current-global-map)
  1856. (kbd "C-x"))))
  1857. (add-hook 'term-mode-hook
  1858. (lambda ()
  1859. ;; Stop current line highlighting
  1860. (set-variable 'hl-line-range-function (lambda () '(0 . 0)) t)
  1861. (set-variable 'scroll-margin 0 t)
  1862. ))
  1863. (set-variable 'term-buffer-maximum-size 20480)
  1864. (set-variable 'term-suppress-hard-newline t)
  1865. (add-hook 'Man-mode-hook
  1866. (lambda ()
  1867. (view-mode 1)
  1868. (setq truncate-lines nil)))
  1869. (set-variable 'Man-notify-method (if window-system
  1870. 'newframe
  1871. 'aggressive))
  1872. (set-variable 'woman-cache-filename (expand-file-name (concat user-emacs-directory
  1873. "woman_cache.el")))
  1874. ;; not work because man.el will be loaded when man called
  1875. (defalias 'man 'woman)
  1876. (add-to-list 'auto-mode-alist
  1877. '("/tox\\.ini\\'" . conf-unix-mode))
  1878. (add-to-list 'auto-mode-alist
  1879. '("/setup\\.cfg\\'" . conf-unix-mode))
  1880. (when (fboundp 'toml-mode)
  1881. (add-to-list 'auto-mode-alist
  1882. '("/tox\\.ini\\'" . toml-mode))
  1883. (add-to-list 'auto-mode-alist
  1884. '("/setup\\.cfg\\'" . toml-mode))
  1885. (add-to-list 'auto-mode-alist
  1886. '("/Pipfile\\'" . toml-mode))
  1887. (add-to-list 'auto-mode-alist
  1888. '("/poetry\\.lock\\'" . toml-mode))
  1889. )
  1890. (when (fboundp 'json-mode)
  1891. (add-to-list 'auto-mode-alist
  1892. '("/Pipfile\\.lock\\'" . json-mode)))
  1893. (add-hook 'json-mode-hook
  1894. (lambda ()
  1895. ;; Stop current line highlighting
  1896. (set-variable 'js-indent-level 2 t)
  1897. ))
  1898. (add-hook 'go-mode-hook
  1899. (lambda()
  1900. (defvar go-mode-map)
  1901. (add-hook 'before-save-hook 'gofmt-before-save nil t)
  1902. (define-key go-mode-map (kbd "M-.") 'godef-jump)))
  1903. (when (fboundp 'k8s-mode)
  1904. (add-to-list 'auto-mode-alist
  1905. '("\\.k8s\\'" . k8s-mode)))
  1906. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1907. ;; buffers
  1908. (defvar bs-configurations)
  1909. (declare-function bs-set-configuration "bs")
  1910. (declare-function bs-refresh "bs")
  1911. (declare-function bs-message-without-log "bs")
  1912. (declare-function bs--current-config-message "bs")
  1913. (with-eval-after-load 'bs
  1914. (add-to-list 'bs-configurations
  1915. '("specials" "^\\*" nil ".*" nil nil))
  1916. (add-to-list 'bs-configurations
  1917. '("files-and-specials" "^\\*" buffer-file-name ".*" nil nil))
  1918. (defvar bs-mode-map)
  1919. (defvar bs-current-configuration)
  1920. (define-key bs-mode-map (kbd "t")
  1921. ;; TODO: fix toggle feature
  1922. (lambda ()
  1923. (interactive)
  1924. (if (string= "specials"
  1925. bs-current-configuration)
  1926. (bs-set-configuration "files")
  1927. (bs-set-configuration "specials"))
  1928. (bs-refresh)
  1929. (bs-message-without-log "%s"
  1930. (bs--current-config-message))))
  1931. ;; (setq bs-configurations (list
  1932. ;; '("processes" nil get-buffer-process ".*" nil nil)
  1933. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
  1934. ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
  1935. )
  1936. (when (fboundp 'bs-show)
  1937. (defalias 'list-buffers 'bs-show)
  1938. (set-variable 'bs-default-configuration "files-and-specials")
  1939. (set-variable 'bs-default-sort-name "by nothing")
  1940. (add-hook 'bs-mode-hook
  1941. (lambda ()
  1942. (setq-local scroll-margin 0)
  1943. (setq-local header-line-format nil)
  1944. (setq-local mode-line-format nil)
  1945. )))
  1946. ;;(iswitchb-mode 1)
  1947. (icomplete-mode)
  1948. (defun iswitchb-buffer-display-other-window ()
  1949. "Do iswitchb in other window."
  1950. (interactive)
  1951. (let ((iswitchb-default-method 'display))
  1952. (call-interactively 'iswitchb-buffer)))
  1953. ;; buffer killing
  1954. ;; (defun my-delete-window-killing-buffer () nil)
  1955. (defun my-query-kill-current-buffer ()
  1956. "Interactively kill current buffer."
  1957. (interactive)
  1958. (if (y-or-n-p (concat "kill current buffer? :"))
  1959. (kill-buffer (current-buffer))))
  1960. (defun my-force-query-kill-current-buffer ()
  1961. "Interactively kill current buffer."
  1962. (interactive)
  1963. (when (y-or-n-p (concat "kill current buffer? :"))
  1964. (let ((kill-buffer-hook nil)
  1965. (kill-buffer-query-functions nil))
  1966. (kill-buffer (current-buffer)))))
  1967. ;;(global-set-key "\C-xk" 'my-query-kill-current-buffer)
  1968. ;; Originally C-x C-k -> kmacro-keymap
  1969. ;; (global-set-key "\C-x\C-k" 'kmacro-keymap)
  1970. (global-set-key (kbd "C-x C-k") 'my-query-kill-current-buffer)
  1971. (substitute-key-definition 'kill-buffer
  1972. 'my-query-kill-current-buffer
  1973. global-map)
  1974. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1975. ;; dired
  1976. (defun my-file-head (filename &optional n)
  1977. "Return list of first N lines of file FILENAME."
  1978. ;; TODO: Fix for janapese text
  1979. ;; TODO: Fix for short text
  1980. (let ((num (or n 10))
  1981. (size 100)
  1982. (beg 0)
  1983. (end 0)
  1984. (result '())
  1985. (read -1))
  1986. (with-temp-buffer
  1987. (erase-buffer)
  1988. (while (or (<= (count-lines (point-min)
  1989. (point-max))
  1990. num)
  1991. (eq read 0))
  1992. (setq end (+ beg size))
  1993. (setq read (nth 1 (insert-file-contents-literally filename
  1994. nil
  1995. beg
  1996. end)))
  1997. (goto-char (point-max))
  1998. (setq beg (+ beg size)))
  1999. (goto-char (point-min))
  2000. (while (< (length result) num)
  2001. (let ((start (point)))
  2002. (forward-line 1)
  2003. (setq result
  2004. `(,@result ,(buffer-substring-no-properties start
  2005. (point))))))
  2006. result
  2007. ;; (buffer-substring-no-properties (point-min)
  2008. ;; (progn
  2009. ;; (forward-line num)
  2010. ;; (point)))
  2011. )))
  2012. ;; (apply 'concat (my-file-head "./shrc" 10)
  2013. (declare-function dired-get-filename "dired" t)
  2014. (defun my-dired-echo-file-head (arg)
  2015. "Echo head of current file.
  2016. ARG is num to show, or defaults to 7."
  2017. (interactive "P")
  2018. (let ((f (dired-get-filename)))
  2019. (message "%s"
  2020. (apply 'concat
  2021. (my-file-head f
  2022. 7)))))
  2023. (declare-function dired-get-marked-files "dired")
  2024. (defun my-dired-diff ()
  2025. "Show diff of marked file and file of current line."
  2026. (interactive)
  2027. (let ((files (dired-get-marked-files nil nil nil t)))
  2028. (if (eq (car files)
  2029. t)
  2030. (diff (cadr files) (dired-get-filename))
  2031. (message "One file must be marked!"))))
  2032. (defun dired-get-file-info ()
  2033. "Print information of current line file."
  2034. (interactive)
  2035. (let* ((file (dired-get-filename t))
  2036. (quoted (shell-quote-argument file)))
  2037. (if (file-directory-p file)
  2038. (progn
  2039. (message "Calculating disk usage...")
  2040. (let ((du (or (executable-find "gdu")
  2041. (executable-find "du")
  2042. (error "du not found"))))
  2043. (shell-command (concat du
  2044. " -hsD "
  2045. quoted))))
  2046. (shell-command (concat "file "
  2047. quoted)))))
  2048. (defun my-dired-scroll-up ()
  2049. "Scroll up."
  2050. (interactive)
  2051. (my-dired-previous-line (- (window-height) 1)))
  2052. (defun my-dired-scroll-down ()
  2053. "Scroll down."
  2054. (interactive)
  2055. (my-dired-next-line (- (window-height) 1)))
  2056. ;; (defun my-dired-forward-line (arg)
  2057. ;; ""
  2058. ;; (interactive "p"))
  2059. (declare-function dired-get-subdir "dired")
  2060. (declare-function dired-move-to-filename "dired")
  2061. (defun my-dired-previous-line (arg)
  2062. "Move ARG lines up."
  2063. (interactive "p")
  2064. (if (> arg 0)
  2065. (progn
  2066. (if (eq (line-number-at-pos)
  2067. 1)
  2068. (goto-char (point-max))
  2069. (forward-line -1))
  2070. (my-dired-previous-line (if (or (dired-get-filename nil t)
  2071. (dired-get-subdir))
  2072. (- arg 1)
  2073. arg)))
  2074. (dired-move-to-filename)))
  2075. (defun my-dired-next-line (arg)
  2076. "Move ARG lines down."
  2077. (interactive "p")
  2078. (if (> arg 0)
  2079. (progn
  2080. (if (eq (point)
  2081. (point-max))
  2082. (goto-char (point-min))
  2083. (forward-line 1))
  2084. (my-dired-next-line (if (or (dired-get-filename nil t)
  2085. (dired-get-subdir))
  2086. (- arg 1)
  2087. arg)))
  2088. (dired-move-to-filename)))
  2089. (defun my-tramp-remote-find-file (f)
  2090. "Open F."
  2091. (interactive (list (read-file-name "My Find File Tramp: "
  2092. "/scp:"
  2093. nil ;; "/scp:"
  2094. (confirm-nonexistent-file-or-buffer))))
  2095. (find-file f))
  2096. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  2097. (if (eq window-system 'mac)
  2098. (setq dired-listing-switches "-lhFA")
  2099. (setq dired-listing-switches "-lhFA --time-style=long-iso")
  2100. )
  2101. (setq dired-listing-switches "-lhFA")
  2102. ;; when using dired-find-alternate-file
  2103. ;; reuse current dired buffer for the file to open
  2104. ;; (put 'dired-find-alternate-file 'disabled nil)
  2105. (set-variable 'dired-ls-F-marks-symlinks t)
  2106. (set-variable 'ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
  2107. (set-variable 'ls-lisp-dirs-first t)
  2108. (set-variable 'ls-lisp-use-localized-time-format t)
  2109. (set-variable 'ls-lisp-format-time-list
  2110. '("%Y-%m-%d %H:%M"
  2111. "%Y-%m-%d "))
  2112. (set-variable 'dired-dwim-target t)
  2113. (set-variable 'dired-isearch-filenames t)
  2114. (set-variable 'dired-hide-details-hide-symlink-targets nil)
  2115. (set-variable 'dired-hide-details-hide-information-lines nil)
  2116. (set-variable 'dired-deletion-confirmer 'y-or-n-p)
  2117. (set-variable 'dired-recursive-deletes 'always)
  2118. ;; (add-hook 'dired-after-readin-hook
  2119. ;; 'my-replace-nasi-none)
  2120. (with-eval-after-load 'dired
  2121. (require 'ls-lisp nil t)
  2122. (defvar dired-mode-map (make-sparse-keymap))
  2123. ;; dired-do-chgrp sometimes cause system hung
  2124. (define-key dired-mode-map "G" 'ignore)
  2125. (define-key dired-mode-map "e" 'wdired-change-to-wdired-mode)
  2126. (define-key dired-mode-map "i" 'dired-get-file-info)
  2127. ;; (define-key dired-mode-map "f" 'find-file)
  2128. (define-key dired-mode-map "f" 'my-fuzzy-finder-or-find-file)
  2129. (define-key dired-mode-map "!" 'shell-command)
  2130. (define-key dired-mode-map "&" 'async-shell-command)
  2131. (define-key dired-mode-map "X" 'dired-do-async-shell-command)
  2132. (define-key dired-mode-map "=" 'my-dired-diff)
  2133. (define-key dired-mode-map "B" 'gtkbm-add-current-dir)
  2134. (define-key dired-mode-map "b" 'gtkbm)
  2135. (define-key dired-mode-map "h" 'my-dired-echo-file-head)
  2136. (define-key dired-mode-map (kbd "TAB") 'other-window)
  2137. ;; (define-key dired-mode-map "P" 'my-dired-do-pack-or-unpack)
  2138. (define-key dired-mode-map "/" 'dired-isearch-filenames)
  2139. (define-key dired-mode-map (kbd "DEL") 'dired-up-directory)
  2140. (define-key dired-mode-map (kbd "C-h") 'dired-up-directory)
  2141. (substitute-key-definition 'dired-next-line
  2142. 'my-dired-next-line
  2143. dired-mode-map)
  2144. (substitute-key-definition 'dired-previous-line
  2145. 'my-dired-previous-line
  2146. dired-mode-map)
  2147. ;; (define-key dired-mode-map (kbd "C-p") 'my-dired-previous-line)
  2148. ;; (define-key dired-mode-map (kbd "p") 'my-dired-previous-line)
  2149. ;; (define-key dired-mode-map (kbd "C-n") 'my-dired-next-line)
  2150. ;; (define-key dired-mode-map (kbd "n") 'my-dired-next-line)
  2151. (define-key dired-mode-map (kbd "<left>") 'my-dired-scroll-up)
  2152. (define-key dired-mode-map (kbd "<right>") 'my-dired-scroll-down)
  2153. (define-key dired-mode-map (kbd "ESC p") 'my-dired-scroll-up)
  2154. (define-key dired-mode-map (kbd "ESC n") 'my-dired-scroll-down)
  2155. (add-hook 'dired-mode-hook
  2156. (lambda ()
  2157. (when (fboundp 'dired-hide-details-mode)
  2158. (dired-hide-details-mode t)
  2159. (local-set-key "l" 'dired-hide-details-mode))
  2160. (when (fboundp 'dired-omit-mode)
  2161. (dired-omit-mode 1)
  2162. (local-set-key "a" 'dired-omit-mode))
  2163. (let ((file "._Icon\015"))
  2164. (when nil
  2165. '(file-readable-p file)
  2166. (delete-file file)))))
  2167. (when (fboundp 'pack-dired-dwim)
  2168. (with-eval-after-load 'dired
  2169. (define-key dired-mode-map "P" 'pack-dired-dwim)))
  2170. ;; https://emacs.stackexchange.com/questions/68585/dired-mode-toggle-show-hidden-files-folders-by-keyboard-shortcut
  2171. (set-variable 'dired-omit-files
  2172. (rx (or (regexp "\\`[.]?#\\|\\`[.][.]?\\'")
  2173. (seq bos "." (not (any "."))))))
  2174. ;; (string-match-p dired-omit-files ".abc")
  2175. (when (fboundp 'dired-omit-mode)
  2176. (with-eval-after-load 'dired
  2177. ))
  2178. )
  2179. (when (fboundp 'dired-filter-mode)
  2180. (add-hook 'dired-mode-hook
  2181. 'dired-filter-mode))
  2182. (set-variable 'dired-filter-stack nil)
  2183. ;; Currently disabled in favor of dired-from-git-ls-files
  2184. ;; (define-key ctl-x-map "f" 'find-dired)
  2185. (defvar my-dired-git-ls-files-history
  2186. "History for `my-dired-git-ls-files'." nil)
  2187. (defun my-dired-git-ls-files (arg)
  2188. "Dired from git ls-files."
  2189. (interactive (list
  2190. (read-shell-command "git ls-files: "
  2191. "git ls-files -z ")))
  2192. (pop-to-buffer-same-window
  2193. (dired-noselect `(,default-directory
  2194. ,@(split-string (shell-command-to-string arg)
  2195. "\0" t))
  2196. ""))
  2197. )
  2198. (define-key ctl-x-map (kbd "G") 'my-dired-git-ls-files)
  2199. (with-eval-after-load 'dired
  2200. (defvar dired-mode-map (make-sparse-keymap))
  2201. (define-key dired-mode-map "G" 'my-dired-git-ls-files))
  2202. (with-eval-after-load 'pack
  2203. (set-variable 'pack-silence
  2204. t)
  2205. (defvar pack-program-alist)
  2206. (add-to-list 'pack-program-alist
  2207. '("\\.txz\\'" :pack "tar -cJf" :unpack "tar -xf"))
  2208. (when (executable-find "aunpack")
  2209. (add-to-list 'pack-program-alist
  2210. ' ("\\.zip\\'"
  2211. :pack ("zip" "-r" archive sources)
  2212. :pack-append ("zip" "-r" archive sources)
  2213. :unpack ("aunpack" archive))))
  2214. )
  2215. ;; dired-k
  2216. (declare-function dired-k-no-revert "dired-k")
  2217. (when (fboundp 'dired-k)
  2218. (set-variable 'dired-k-style 'git)
  2219. ;; What is the best way of doing this?
  2220. (with-eval-after-load 'dired-k
  2221. (fset 'dired-k--highlight-by-file-attribyte 'ignore))
  2222. ;; (set-variable 'dired-k-size-colors
  2223. ;; `((,most-positive-fixnum)))
  2224. ;; (set-variable 'dired-k-date-colors
  2225. ;; `((,most-positive-fixnum)))
  2226. (add-hook 'dired-after-readin-hook #'dired-k-no-revert)
  2227. )
  2228. ;; (when (eval-and-compile (require 'dired-rainbow nil t))
  2229. ;; (dired-rainbow-define gtags "brightblack" "GTAGS"))
  2230. (with-eval-after-load 'diredfl
  2231. (set-face-foreground 'diredfl-file-name nil)
  2232. )
  2233. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2234. ;; misc funcs
  2235. (define-key ctl-x-map "T" 'git-worktree)
  2236. (define-key ctl-x-map "W" 'git-walktree)
  2237. (defun mkcdd ()
  2238. "Make date directory and open it with dired."
  2239. (interactive)
  2240. (let ((d (format-time-string "%Y%m%d-%H%M%S")))
  2241. (make-directory d)
  2242. (find-file d)))
  2243. (when (fboundp 'browse-url-default-macosx-browser)
  2244. (defalias 'browse-osx 'browse-url-default-macosx-browser))
  2245. (defalias 'qcalc 'quick-calc)
  2246. (defun memo (&optional dir)
  2247. "Open memo.txt in DIR."
  2248. (interactive)
  2249. (pop-to-buffer (find-file-noselect (concat (if dir
  2250. (file-name-as-directory dir)
  2251. "")
  2252. "memo.txt"))))
  2253. ;; TODO: remember-projectile
  2254. (set (defvar my-privnotes-path nil
  2255. "My privnotes repository path.")
  2256. (expand-file-name "~/my/privnotes"))
  2257. (defun my-privnotes-readme (dir)
  2258. "Open my privnotes DIR."
  2259. (interactive (list
  2260. (read-file-name "Privnotes: "
  2261. (expand-file-name (format-time-string "%Y%m%d_")
  2262. my-privnotes-path))))
  2263. (let ((path (expand-file-name "README.md" dir)))
  2264. (with-current-buffer (find-file path)
  2265. (unless (file-exists-p path)
  2266. (insert (file-name-base dir)
  2267. "\n"
  2268. "=======\n"
  2269. "\n\n")))))
  2270. (define-key ctl-x-map "p" 'my-privnotes-readme)
  2271. (set (defvar my-rgrep-alist nil
  2272. "Alist of rgrep command.
  2273. Each element is in the form like (NAME SEXP COMMAND), where SEXP returns the
  2274. condition to choose COMMAND when evaluated.")
  2275. `(
  2276. ;; ripgrep
  2277. ("rg"
  2278. (executable-find "rg")
  2279. "rg -nH --no-heading --hidden --no-ignore-parent --glob '!.git/' --smart-case -M 1280 ")
  2280. ;; git grep
  2281. ("gitgrep"
  2282. (eq 0
  2283. (shell-command "git rev-parse --git-dir"))
  2284. "git --no-pager grep -nH -e ")
  2285. ;; sift
  2286. ("sift"
  2287. (executable-find "sift")
  2288. ("sift --binary-skip --filename --line-number --git --smart-case "))
  2289. ;; the silver searcher
  2290. ("ag"
  2291. (executable-find "ag")
  2292. "ag --nogroup --nopager --filename ")
  2293. ;; ack
  2294. ("ack"
  2295. (executable-find "ack")
  2296. "ack --nogroup --nopager --with-filename ")
  2297. ;; gnu global
  2298. ("global"
  2299. (and (require 'ggtags nil t)
  2300. (executable-find "global")
  2301. (ggtags-current-project-root))
  2302. "global --result grep ")
  2303. ;; grep
  2304. ("grep"
  2305. t
  2306. ,(concat "find . "
  2307. "-path '*/.git' -prune -o "
  2308. "-path '*/.svn' -prune -o "
  2309. "-type f -print0 | "
  2310. "xargs -0 grep -nH -e "))
  2311. )
  2312. )
  2313. (defvar my-rgrep-default nil
  2314. "Default command name for my-rgrep.")
  2315. (defun my-rgrep-grep-command (&optional name alist)
  2316. "Return recursive grep command for current directory or nil.
  2317. If NAME is given, use that without testing.
  2318. Commands are searched from ALIST."
  2319. (if alist
  2320. (if name
  2321. ;; if name is given search that from alist and return the command
  2322. (nth 2 (assoc name
  2323. alist))
  2324. ;; if name is not given try test in 1th elem
  2325. (let ((car (car alist))
  2326. (cdr (cdr alist)))
  2327. (if (eval (nth 1 car))
  2328. ;; if the condition is true return the command
  2329. (nth 2 car)
  2330. ;; try next one
  2331. (and cdr
  2332. (my-rgrep-grep-command name cdr)))))
  2333. ;; if alist is not given set default value
  2334. (my-rgrep-grep-command name my-rgrep-alist)))
  2335. (declare-function projectile-project-p "projectile")
  2336. (declare-function projectile-with-default-dir "projectile")
  2337. (declare-function projectile-project-root "projectile")
  2338. (defun my-rgrep (command-args)
  2339. "My recursive grep. Run COMMAND-ARGS.
  2340. If prefix argument is given, use current symbol as default search target
  2341. and search from projectile root (if projectile is available)."
  2342. (interactive (let ((cmd (my-rgrep-grep-command my-rgrep-default
  2343. nil)))
  2344. (if cmd
  2345. (list (read-shell-command "grep command: "
  2346. (concat cmd
  2347. (if current-prefix-arg
  2348. (thing-at-point 'symbol t)
  2349. ""))
  2350. 'grep-find-history))
  2351. (error "My-Rgrep: Command for rgrep not found")
  2352. )))
  2353. (if (and current-prefix-arg
  2354. (eval-and-compile (require 'projectile nil t))
  2355. (projectile-project-p))
  2356. (projectile-with-default-dir (projectile-project-root)
  2357. (compilation-start command-args
  2358. 'grep-mode))
  2359. (compilation-start command-args
  2360. 'grep-mode)))
  2361. (defun my-rgrep-thing-at-point-projectile-root ()
  2362. "My recursive grep to find thing at point from project root."
  2363. (interactive)
  2364. (let* ((cmd (my-rgrep-grep-command my-rgrep-default
  2365. nil))
  2366. (command-args
  2367. (if cmd
  2368. (concat cmd
  2369. (or (thing-at-point 'symbol t)
  2370. (error "No symbol at point")))
  2371. (error "My-Rgrep: Command for rgrep not found"))))
  2372. (if (eval-and-compile (require 'projectile nil t))
  2373. (with-temp-buffer
  2374. (cd (or (projectile-project-root)
  2375. default-directory))
  2376. (compilation-start command-args
  2377. 'grep-mode))
  2378. (compilation-start command-args
  2379. 'grep-mode))))
  2380. (defmacro define-my-rgrep (name)
  2381. "Define rgrep for NAME."
  2382. `(defun ,(intern (concat "my-rgrep-"
  2383. name)) ()
  2384. ,(format "My recursive grep by %s."
  2385. name)
  2386. (interactive)
  2387. (let ((my-rgrep-default ,name))
  2388. (if (called-interactively-p 'any)
  2389. (call-interactively 'my-rgrep)
  2390. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  2391. )
  2392. (define-my-rgrep "ack")
  2393. (define-my-rgrep "ag")
  2394. (define-my-rgrep "rg")
  2395. (define-my-rgrep "sift")
  2396. (define-my-rgrep "gitgrep")
  2397. (define-my-rgrep "grep")
  2398. (define-my-rgrep "global")
  2399. (define-key ctl-x-map "s" 'my-rgrep)
  2400. (define-key ctl-x-map "." 'my-rgrep-thing-at-point-projectile-root)
  2401. (defun my-occur (regexp &optional region)
  2402. "My occur command to search REGEXP to search REGION."
  2403. (interactive (list (read-string "List lines matching regexp: "
  2404. (thing-at-point 'symbol t))))
  2405. (occur regexp nil region))
  2406. (define-key ctl-x-map (kbd "C-o") 'my-occur)
  2407. (set-variable 'dumb-jump-prefer-searcher 'rg)
  2408. (defalias 'make 'compile)
  2409. (define-key ctl-x-map "c" 'compile)
  2410. (autoload 'pb/push-item "pushbullet")
  2411. (defun my-pushbullet-note (text &optional title)
  2412. "Push TEXT with optional TITLE."
  2413. (interactive "sText to Push: ")
  2414. (pb/push-item '("") text "note" (or title "")))
  2415. ;;;;;;;;;;;;;;;;;;;
  2416. ;; peek-file-mode
  2417. (defvar peek-file-buffers
  2418. ()
  2419. "Peek buffers.")
  2420. (defun peek-file (file)
  2421. "Peek FILE."
  2422. (interactive "fFile to peek: ")
  2423. (with-current-buffer (find-file file)
  2424. (peek-file-mode)))
  2425. (define-minor-mode peek-file-mode
  2426. "Peek file mode."
  2427. :lighter "PK"
  2428. (view-mode peek-file-mode)
  2429. (add-to-list 'peek-file-buffers
  2430. (current-buffer))
  2431. (add-hook 'switch-buffer-functions
  2432. 'peek-file-remove-buffers))
  2433. (defun peek-file-remove-buffers (&args _)
  2434. "Remove peek file buffers."
  2435. (cl-dolist (buf (cl-copy-list peek-file-buffers))
  2436. (unless (get-buffer-window buf t)
  2437. (setq peek-file-buffers
  2438. (delq buf
  2439. peek-file-buffers))
  2440. (with-current-buffer buf
  2441. (when peek-file-mode
  2442. (kill-buffer))))))
  2443. (declare-function dired-get-file-for-visit "dired")
  2444. (with-eval-after-load 'dired
  2445. (defun dired-peek-file (&rest files)
  2446. "Dired `peak-file' FILES."
  2447. (interactive (list (dired-get-file-for-visit)))
  2448. (message "AAA %S" files)
  2449. (dolist (file files)
  2450. (peek-file file)))
  2451. (defvar dired-mode-map (make-sparse-keymap))
  2452. (define-key dired-mode-map "v" 'dired-peek-file))
  2453. ;;;;;;;;;;;;;;;;;;;;
  2454. ;; remember-projectile
  2455. ;; TODO: Add global-minor-mode
  2456. (defvar remember-data-file)
  2457. (defun my-set-remember-data-file-buffer-local ()
  2458. "Set `remember-data-file'."
  2459. (when (require 'projectile nil t)
  2460. (setq-local remember-data-file
  2461. (expand-file-name ".remember.notes"
  2462. (projectile-project-root)))))
  2463. (add-hook 'after-change-major-mode-hook
  2464. 'my-set-remember-data-file-buffer-local)
  2465. (define-key ctl-x-map "R" 'remember)
  2466. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2467. ;; ivy
  2468. (set-variable 'ivy-format-functions-alist
  2469. '((t . (lambda (cands) (ivy--format-function-generic
  2470. (lambda (str)
  2471. (concat "+> "
  2472. (ivy--add-face str 'ivy-current-match)
  2473. ))
  2474. (lambda (str)
  2475. (concat "| " str))
  2476. cands
  2477. "\n")))))
  2478. (set-variable 'ivy-wrap t)
  2479. (set-variable 'ivy-sort-max-size 500)
  2480. (when (fboundp 'ivy-rich-mode)
  2481. (ivy-rich-mode 1))
  2482. (with-eval-after-load 'ivy
  2483. (defvar ivy-minibuffer-map)
  2484. (define-key ivy-minibuffer-map (kbd "C-u")
  2485. (lambda () (interactive) (delete-region (point-at-bol) (point))))
  2486. (defvar ivy-sort-matches-functions-alist)
  2487. ;; (add-to-list 'ivy-sort-matches-functions-alist
  2488. ;; '(counsel-M-x . ivy--shorter-matches-first))
  2489. )
  2490. (set-variable 'ivy-on-del-error-function 'ignore)
  2491. (when (fboundp 'counsel-M-x)
  2492. (define-key esc-map "x" 'counsel-M-x)
  2493. )
  2494. (declare-function ivy-thing-at-point "ivy")
  2495. (when (and (fboundp 'ivy-read)
  2496. (locate-library "counsel"))
  2497. (defvar counsel-describe-map)
  2498. (defun my-counsel-describe-symbol ()
  2499. "Forwaord to `describe-symbol'."
  2500. (interactive)
  2501. (cl-assert (eval-and-compile (require 'help-mode nil t))) ;; describe-symbol-backends
  2502. (cl-assert (eval-and-compile (require 'counsel nil t)))
  2503. (ivy-read "Describe symbol: " obarray
  2504. ;; From describe-symbol definition
  2505. :predicate (lambda (vv)
  2506. (cl-some (lambda (x) (funcall (nth 1 x) vv))
  2507. describe-symbol-backends))
  2508. :require-match t
  2509. :history 'counsel-describe-symbol-history
  2510. :keymap counsel-describe-map
  2511. :preselect (ivy-thing-at-point)
  2512. :action (lambda (x)
  2513. (describe-symbol (intern x)))
  2514. :caller 'my-counsel-describe-symbol))
  2515. (define-key help-map "o" 'my-counsel-describe-symbol)
  2516. )
  2517. (declare-function ivy-configure "ivy")
  2518. (with-eval-after-load 'counsel ;; Hook to counsel, not ivy
  2519. ;; (ivy-configure 'my-counsel-describe-symbol
  2520. ;; :sort-fn 'my-ivy-length)
  2521. ;; (ivy-configure 'counsel-M-x
  2522. ;; ;; :initial-input ""
  2523. ;; :sort-fn 'ivy-string<
  2524. ;; )
  2525. )
  2526. (when (fboundp 'counsel-imenu)
  2527. (define-key ctl-x-map "l" 'counsel-imenu))
  2528. (when (fboundp 'swiper)
  2529. (define-key esc-map (kbd "C-s") 'swiper))
  2530. (with-eval-after-load 'ivy
  2531. ;; ivy-prescient requires counsel already loaded
  2532. (require 'counsel nil t)
  2533. (when (fboundp 'ivy-prescient-mode)
  2534. ;; (set-variable 'prescient-sort-length-enable t)
  2535. ;; (set-variable 'prescient-sort-full-matches-first t)
  2536. ;; (set-variable 'ivy-prescient-enable-filtering t)
  2537. ;; (set-variable 'ivy-prescient-enable-sorting nil)
  2538. ;; (set-variable 'ivy-prescient-sort-commands t)
  2539. (set-variable 'prescient-filter-method
  2540. '(literal prefix literal-prefix regexp initialism fuzzy))
  2541. (when (fboundp 'prescient-persist-mode)
  2542. (prescient-persist-mode t))
  2543. (ivy-prescient-mode 1)
  2544. ;; (set-variable 'ivy-sort-functions-alist
  2545. ;; '((t . ivy-string<)))
  2546. ))
  2547. ;; ?
  2548. (define-key input-decode-map "\e[1;5C" [C-right])
  2549. (define-key input-decode-map "\e[1;5D" [C-left])
  2550. ;;;;;;;;;;;;;;;;;;;;;;;;
  2551. ;; mozc
  2552. (global-set-key (kbd "C-c m e") 'ignore)
  2553. (global-set-key (kbd "C-c m d") 'ignore)
  2554. ;; mozc
  2555. (when (locate-library "mozc")
  2556. ;; https://tottoto.net/mac-emacs-karabiner-elements-japanese-input-method-config/
  2557. (with-eval-after-load 'mozc
  2558. ;; (define-key mozc-mode-map (kbd "C-h") 'backward-delete-char)
  2559. ;; (define-key mozc-mode-map (kbd "C-p") (kbd "<up>"))
  2560. ;; (define-key mozc-mode-map (kbd "C-n") (kbd "SPC"))
  2561. )
  2562. (setq default-input-method "japanese-mozc")
  2563. (custom-set-variables '(mozc-leim-title "あ"))
  2564. (defun turn-on-input-method ()
  2565. (interactive)
  2566. (activate-input-method default-input-method))
  2567. (defun turn-off-input-method ()
  2568. (interactive)
  2569. (deactivate-input-method))
  2570. ;; (setq mozc-candidate-style 'echo-area)
  2571. (global-set-key (kbd "C-c m e") 'turn-on-input-method)
  2572. (global-set-key (kbd "C-c m d") 'turn-off-input-method)
  2573. (global-set-key (kbd "<f7>") 'turn-off-input-method)
  2574. (global-set-key (kbd "<f8>") 'turn-on-input-method)
  2575. (require 'mozc-popup)
  2576. (set-variable 'mozc-candidate-style 'popup)
  2577. ;; これいる?
  2578. (when (require 'mozc-im nil t)
  2579. (setq default-input-method "japanese-mozc-im")
  2580. ;; (global-set-key (kbd "C-j") 'toggle-input-method)
  2581. )
  2582. )
  2583. (defun browse-url-macosx-vivaldi-browser (url &rest args)
  2584. "Invoke the macOS Vlvaldi Web browser with URL.
  2585. ARGS are not used."
  2586. (interactive (browse-url-interactive-arg "URL: "))
  2587. (start-process (concat "vivaldi " url)
  2588. nil
  2589. "/Applications/Vivaldi.app/Contents/MacOS/Vivaldi"
  2590. url))
  2591. (declare-function vterm "vterm")
  2592. ;; 前の実行結果を残したまま次のコマンドを実行する方法はあるだろうか
  2593. (defun my-vterm-cmd (command)
  2594. "Start arbitrary command in vterm buffer."
  2595. (interactive "sCommand: ")
  2596. (let ((vterm-shell command)
  2597. (vterm-buffer-name "*vterm-cmd*")
  2598. (vterm-kill-buffer-on-exit nil))
  2599. (when (get-buffer vterm-buffer-name)
  2600. (kill-buffer (get-buffer vterm-buffer-name)))
  2601. (vterm)))
  2602. ;; (setq vterm-shell "bash -l")
  2603. ;; (setq vterm-kill-buffer-on-exit nil)
  2604. ;; ;; (setq vterm-term-environment-variable "screen-256color")
  2605. ;; これいつ動くの?
  2606. ;; 自動で project を switch させる方法はある?
  2607. (add-hook 'projectile-after-switch-project-hook
  2608. (lambda ()
  2609. (message "Projecttile switched to: %s"
  2610. (projectile-project-root))))
  2611. (when (fboundp 'projectile-mode)
  2612. (projectile-mode 1))
  2613. ;; (with-eval-after-load 'eglot
  2614. ;; (when (fboundp 'with-venv-advice-add)
  2615. ;; (with-venv-advice-add 'eglot--executable-find))
  2616. ;; (set-variable 'eldoc-echo-area-use-multiline-p nil)
  2617. ;; (set-variable 'eglot-extend-to-xref t))
  2618. (set-variable 'lsp-python-ms-auto-install-server t)
  2619. (set-variable 'lsp-python-ms-parse-dot-env-enabled t)
  2620. (set-variable 'lsp-python-ms-python-executable-cmd "python3")
  2621. ;; (add-hook 'python-mode-hook #'my-lsp-python-setup)
  2622. (defun my-lsp-python-setup ()
  2623. "Setup python ms."
  2624. (when (and (fboundp 'lsp)
  2625. (require 'lsp-python-ms nil t))
  2626. (lsp)))
  2627. (set-variable 'awk-preview-default-program
  2628. "# C-c C-l: Update preview C-c C-c: Commit and exit
  2629. # C-c C-r: Resest to original C-c C-k: Abort
  2630. BEGIN {
  2631. # FS = \",\"
  2632. }
  2633. {
  2634. # Replace string
  2635. # gsub(BEFORE, AFTER, $0)
  2636. print NR, $0
  2637. }
  2638. ")
  2639. (message "Emacs started at %s"
  2640. (current-time-string))
  2641. (run-with-idle-timer (* 3 60 60) ;; 3 hours
  2642. t
  2643. (lambda ()
  2644. (message "Emacs does nothing for 3 hours: %s"
  2645. (current-time-string))))
  2646. ;; https://emacs-jp.github.io/tips/startup-optimization
  2647. ;; Restore to original value
  2648. (setq gc-cons-threshold my-orig-gc-cons-threshold)
  2649. (setq file-name-handler-alist my-orig-file-name-handler-alist)
  2650. (when (getenv "_EMACS_EL_PROFILE")
  2651. (profiler-report)
  2652. (profiler-stop))
  2653. ;; Local Variables:
  2654. ;; flycheck-disabled-checkers: (emacs-lisp-checkdoc)
  2655. ;; flycheck-checker: emacs-lisp
  2656. ;; End:
  2657. ;;; emancs.el ends here