Personal emacs config
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.

257 lines
7.2 KiB

6 years ago
6 years ago
  1. * Editing
  2. ** IEdit mode
  3. #+BEGIN_SRC emacs-lisp
  4. (use-package iedit
  5. :bind ("C-;" . iedit-mode))
  6. #+END_SRC
  7. ** Spellcheck
  8. #+BEGIN_SRC emacs-lisp
  9. (global-set-key (kbd "C-!") 'ispell-buffer)
  10. #+END_SRC
  11. ** Undo tree
  12. #+BEGIN_SRC emacs-lisp
  13. (use-package undo-tree
  14. :config
  15. (global-undo-tree-mode))
  16. #+END_SRC
  17. * Save/load
  18. ** Backup/auto-save
  19. #+BEGIN_SRC emacs-lisp
  20. (let ((backup-dir "~/.emacs.d/backup")
  21. (auto-save-dir "~/.emacs.d/autosave"))
  22. (if (not (file-directory-p backup-dir))
  23. (make-directory backup-dir))
  24. (if (not (file-directory-p
  25. auto-save-dir))
  26. (make-directory auto-save-dir)))
  27. #+END_SRC
  28. ** On save
  29. #+BEGIN_SRC emacs-lisp
  30. (add-hook 'before-save-hook 'delete-trailing-whitespace)
  31. #+END_SRC
  32. ** Recent files mode
  33. #+BEGIN_SRC emacs-lisp
  34. (use-package recentf
  35. :config
  36. (recentf-mode 1))
  37. #+END_SRC
  38. * Platform dependant
  39. ** Windows
  40. #+BEGIN_SRC emacs-lisp
  41. (when (string-equal system-type "windows-nt")
  42. (progn
  43. (defun rlbr/quote-exe (path)
  44. (w32-short-file-name path))
  45. (defun rlbr/start-external-shell ()
  46. (interactive)
  47. (start-process-shell-command (format "cmd(%s)" default-directory) nil "start default.bat"))
  48. (global-set-key (kbd "C-S-C") 'rlbr/start-external-shell)
  49. (defun rlbr/start-windows-explorer-here ()
  50. (interactive)
  51. (start-process-shell-command "explorer" nil (format "explorer %s" (replace-regexp-in-string "/" (regexp-quote "\\") (expand-file-name default-directory)))))
  52. (global-set-key (kbd "C-S-E") 'rlbr/start-windows-explorer-here)
  53. (defun rlbr/case-insensitive-match (string1 string2)
  54. (apply 'string-equal (mapcar 'downcase (list string1 string2))))
  55. (defun rlbr/output-matches (output-matches-p exe args)
  56. "locate the executable whose output satifies output-matches-p when fed args and return the fullpath"
  57. (let ((exec-path exec-path)
  58. (output)
  59. (bad)
  60. (command-output)
  61. (current-exe)
  62. (failed))
  63. (while (not (or output failed))
  64. (setq current-exe
  65. (executable-find exe))
  66. (if current-exe
  67. (progn
  68. (setq command-output
  69. (shell-command-to-string (format "%s %s" (rlbr/quote-exe current-exe) args)))
  70. (if (funcall output-matches-p command-output)
  71. (setq output current-exe)
  72. (progn
  73. (setq bad
  74. (replace-regexp-in-string "/$" "" (file-name-directory current-exe)))
  75. (setq exec-path
  76. (seq-filter (lambda (item) (not (rlbr/case-insensitive-match item bad))) exec-path)))))
  77. (setq failed t)))
  78. output))
  79. (let ((find)
  80. (grep)
  81. (ls))
  82. (progn
  83. (setq find
  84. (rlbr/output-matches
  85. (lambda (output) (string-equal ".\n" output))
  86. "find" "-maxdepth 0"))
  87. (if find
  88. (setq find-program (rlbr/quote-exe find)))
  89. (setq grep (rlbr/output-matches
  90. (lambda (output) (string-match "grep (\\w+ grep)" output))
  91. "grep" "-V"))
  92. (if grep
  93. (setq grep-program
  94. (rlbr/quote-exe grep)))
  95. (setq ls (rlbr/output-matches
  96. (lambda (output) (string-match "ls: .*'\\?/': No such file or directory" output))
  97. "ls" "?/"))
  98. (if ls
  99. (setq insert-directory-program (rlbr/quote-exe ls)))))))
  100. #+END_SRC
  101. * Major modes
  102. ** Java
  103. ** JavaScript
  104. #+BEGIN_SRC emacs-lisp
  105. (use-package js2-mode
  106. :mode "\\.js\\'"
  107. :hook ((js2-mode . js2-imenu-extras-mode)
  108. (js2-mode . (lambda () (add-hook 'xref-backend-functions #'xref-js2-xref-backend nil t))))
  109. :config
  110. (use-package js2-refactor
  111. :hook (js2-mode . js2-refactor-mode)
  112. :bind
  113. (:map js2-mode-map
  114. ("C-k" . js2r-kill))
  115. :config
  116. (js2r-add-keybindings-with-prefix "C-c C-r"))
  117. (use-package xref-js2
  118. :demand t)
  119. (define-key js-mode-map (kbd "M-.") nil)
  120. (defun rlbr/jump-to-definition ()
  121. "Jump to a definition."
  122. (interactive)
  123. (condition-case-unless-debug nil
  124. (js2-jump-to-definition)
  125. (error
  126. (progn
  127. (ignore-errors
  128. (xref-pop-marker-stack))
  129. (xref-find-definitions (xref-backend-identifier-at-point (xref-find-backend)))))))
  130. (define-key js-mode-map (kbd "M-.") #'rlbr/jump-to-definition))
  131. #+END_SRC
  132. ** Magit
  133. #+BEGIN_SRC emacs-lisp
  134. (use-package magit
  135. :bind (("C-x g" . magit-status))
  136. :config
  137. (use-package git-commit
  138. :hook (git-commit-setup . git-commit-turn-on-flyspell)))
  139. #+END_SRC
  140. ** Python
  141. *** Platform specific
  142. #+BEGIN_SRC emacs-lisp
  143. (cond
  144. ((string-equal system-type "gnu/linux")
  145. "python3")
  146. ((string-equal system-type "windows-nt")
  147. "python.exe"))
  148. #+END_SRC
  149. *** custom feature
  150. *** bindings/settings
  151. #+begin_src emacs-lisp
  152. (use-package python
  153. :config
  154. (use-package elpy
  155. :bind (("C-=" . elpy-goto-assignment))
  156. :config (when (require 'flycheck nil t)
  157. (setq elpy-modules (delq 'elpy-module-flymake elpy-modules))))
  158. (elpy-enable)
  159. (blacken-mode))
  160. #+END_SRC
  161. ** SSH config mode
  162. #+BEGIN_SRC emacs-lisp
  163. (use-package ssh-config-mode
  164. :mode "~/.ssh/config\\'")
  165. #+END_SRC
  166. ** Tramp
  167. ** Webmode
  168. ** YAML
  169. #+BEGIN_SRC emacs-lisp
  170. (use-package yaml-mode
  171. :mode "\\.yml\\'")
  172. #+END_SRC
  173. * Minor modes/misc
  174. ** Kill the things
  175. *** Buffer
  176. #+BEGIN_SRC emacs-lisp
  177. (global-set-key (kbd "C-x k") 'kill-this-buffer)
  178. #+END_SRC
  179. *** Emacs
  180. #+BEGIN_SRC emacs-lisp
  181. (global-set-key (kbd "C-x C-k C-x C-k") 'kill-emacs)
  182. #+END_SRC
  183. ** Lispy
  184. #+BEGIN_SRC emacs-lisp
  185. (use-package lispy
  186. :hook ((emacs-lisp-mode) . lispy-mode))
  187. #+END_SRC
  188. * Navigation/autocompletion
  189. ** Ace window
  190. #+BEGIN_SRC emacs-lisp
  191. (use-package ace-window
  192. :bind (("M-Q" . ace-window)))
  193. #+END_SRC
  194. ** Hippie expand
  195. #+BEGIN_SRC emacs-lisp
  196. (use-package hippie-exp
  197. :bind ("M-/" . hippie-expand))
  198. #+END_SRC
  199. ** IBuffer mode
  200. #+BEGIN_SRC emacs-lisp
  201. (use-package ibbufer-vc
  202. :hook ((ibuffer-mode . ibuffer-vc-set-filter-groups-by-vc-root)))
  203. (use-package ibuffer
  204. :bind (("C-x C-b" . ibuffer))
  205. :config
  206. (define-ibuffer-column size-h
  207. ;; Use human readable Size column instead of original one
  208. (:name "Size" :inline t)
  209. (cond ((> (buffer-size) 1000000)
  210. (format "%7.1fM" (/ (buffer-size) 1000000.0)))
  211. ((> (buffer-size) 100000)
  212. (format "%7.0fk" (/ (buffer-size) 1000.0)))
  213. ((> (buffer-size) 1000)
  214. (format "%7.1fk" (/ (buffer-size) 1000.0)))
  215. (t
  216. (format "%8d" (buffer-size))))))
  217. #+END_SRC
  218. ** Ivy
  219. #+BEGIN_SRC emacs-lisp
  220. (use-package ivy
  221. :config
  222. (use-package swiper
  223. :bind ("C-s" . swiper))
  224. (ivy-mode))
  225. #+END_SRC
  226. * Look and feel
  227. ** Line numbers
  228. #+BEGIN_SRC emacs-lisp
  229. (global-display-line-numbers-mode)
  230. #+END_SRC
  231. ** Mode line bell
  232. #+BEGIN_SRC emacs-lisp
  233. (use-package mode-line-bell
  234. :config
  235. (mode-line-bell-mode))
  236. #+END_SRC
  237. ** Spaceline
  238. #+BEGIN_SRC emacs-lisp
  239. (use-package spaceline-config
  240. :config
  241. (use-package winum
  242. :init
  243. (setq winum-keymap
  244. (let ((map (make-sparse-keymap)))
  245. (define-key map (kbd "M-0") 'winum-select-window-0-or-10)
  246. (define-key map (kbd "M-1") 'winum-select-window-1)
  247. (define-key map (kbd "M-2") 'winum-select-window-2)
  248. (define-key map (kbd "M-3") 'winum-select-window-3)
  249. (define-key map (kbd "M-4") 'winum-select-window-4)
  250. (define-key map (kbd "M-5") 'winum-select-window-5)
  251. (define-key map (kbd "M-6") 'winum-select-window-6)
  252. (define-key map (kbd "M-7") 'winum-select-window-7)
  253. (define-key map (kbd "M-8") 'winum-select-window-8)
  254. map)))
  255. (spaceline-spacemacs-theme)
  256. (winum-mode))
  257. #+END_SRC