25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

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