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.
 
 
 
 
 
 

2517 regels
83 KiB

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