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.

229 lines
6.3 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. ** Magit
  105. #+BEGIN_SRC emacs-lisp
  106. (use-package magit
  107. :bind (("C-x g" . magit-status))
  108. :config
  109. (use-package git-commit
  110. :hook (git-commit-setup . git-commit-turn-on-flyspell)))
  111. #+END_SRC
  112. ** Python
  113. *** Platform specific
  114. #+BEGIN_SRC emacs-lisp
  115. (cond
  116. ((string-equal system-type "gnu/linux")
  117. "python3")
  118. ((string-equal system-type "windows-nt")
  119. "python.exe"))
  120. #+END_SRC
  121. *** custom feature
  122. *** bindings/settings
  123. #+begin_src emacs-lisp
  124. (use-package python
  125. :config
  126. (use-package elpy
  127. :bind (("C-=" . elpy-goto-assignment))
  128. :config (when (require 'flycheck nil t)
  129. (setq elpy-modules (delq 'elpy-module-flymake elpy-modules))))
  130. (elpy-enable)
  131. (blacken-mode))
  132. #+END_SRC
  133. ** SSH config mode
  134. #+BEGIN_SRC emacs-lisp
  135. (use-package ssh-config-mode
  136. :mode "~/.ssh/config\\'")
  137. #+END_SRC
  138. ** Tramp
  139. ** Webmode
  140. ** YAML
  141. #+BEGIN_SRC emacs-lisp
  142. (use-package yaml-mode
  143. :mode "\\.yml\\'")
  144. #+END_SRC
  145. * Minor modes/misc
  146. ** Kill the things
  147. *** Buffer
  148. #+BEGIN_SRC emacs-lisp
  149. (global-set-key (kbd "C-x k") 'kill-this-buffer)
  150. #+END_SRC
  151. *** Emacs
  152. #+BEGIN_SRC emacs-lisp
  153. (global-set-key (kbd "C-x C-k C-x C-k") 'kill-emacs)
  154. #+END_SRC
  155. ** Lispy
  156. #+BEGIN_SRC emacs-lisp
  157. (use-package lispy
  158. :hook ((emacs-lisp-mode) . lispy-mode))
  159. #+END_SRC
  160. * Navigation/autocompletion
  161. ** Ace window
  162. #+BEGIN_SRC emacs-lisp
  163. (use-package ace-window
  164. :bind (("M-Q" . ace-window)))
  165. #+END_SRC
  166. ** Hippie expand
  167. #+BEGIN_SRC emacs-lisp
  168. (use-package hippie-exp
  169. :bind ("M-/" . hippie-expand))
  170. #+END_SRC
  171. ** IBuffer mode
  172. #+BEGIN_SRC emacs-lisp
  173. (use-package ibbufer-vc
  174. :hook ((ibuffer-mode . ibuffer-vc-set-filter-groups-by-vc-root)))
  175. (use-package ibuffer
  176. :bind (("C-x C-b" . ibuffer))
  177. :config
  178. (define-ibuffer-column size-h
  179. ;; Use human readable Size column instead of original one
  180. (:name "Size" :inline t)
  181. (cond ((> (buffer-size) 1000000)
  182. (format "%7.1fM" (/ (buffer-size) 1000000.0)))
  183. ((> (buffer-size) 100000)
  184. (format "%7.0fk" (/ (buffer-size) 1000.0)))
  185. ((> (buffer-size) 1000)
  186. (format "%7.1fk" (/ (buffer-size) 1000.0)))
  187. (t
  188. (format "%8d" (buffer-size))))))
  189. #+END_SRC
  190. ** Ivy
  191. #+BEGIN_SRC emacs-lisp
  192. (use-package ivy
  193. :config
  194. (use-package swiper
  195. :bind ("C-s" . swiper))
  196. (ivy-mode))
  197. #+END_SRC
  198. * Look and feel
  199. ** Line numbers
  200. #+BEGIN_SRC emacs-lisp
  201. (global-display-line-numbers-mode)
  202. #+END_SRC
  203. ** Mode line bell
  204. #+BEGIN_SRC emacs-lisp
  205. (use-package mode-line-bell
  206. :config
  207. (mode-line-bell-mode))
  208. #+END_SRC
  209. ** Spaceline
  210. #+BEGIN_SRC emacs-lisp
  211. (use-package spaceline-config
  212. :config
  213. (use-package winum
  214. :init
  215. (setq winum-keymap
  216. (let ((map (make-sparse-keymap)))
  217. (define-key map (kbd "M-0") 'winum-select-window-0-or-10)
  218. (define-key map (kbd "M-1") 'winum-select-window-1)
  219. (define-key map (kbd "M-2") 'winum-select-window-2)
  220. (define-key map (kbd "M-3") 'winum-select-window-3)
  221. (define-key map (kbd "M-4") 'winum-select-window-4)
  222. (define-key map (kbd "M-5") 'winum-select-window-5)
  223. (define-key map (kbd "M-6") 'winum-select-window-6)
  224. (define-key map (kbd "M-7") 'winum-select-window-7)
  225. (define-key map (kbd "M-8") 'winum-select-window-8)
  226. map)))
  227. (spaceline-spacemacs-theme)
  228. (winum-mode))
  229. #+END_SRC