You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

3063 lines
101 KiB

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