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.

296 lines
8.6 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
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 dependent
  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 satisfies output-matches-p when fed args and return the full-path"
  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. * Tramp configuration
  102. ** Tramp append plist to connection properties
  103. #+BEGIN_SRC emacs-lisp
  104. (use-package kv
  105. :config
  106. (defun rlbr/add-config-to-tramp (matches-regexp config-plist)
  107. (let ((config-alist (kvplist->alist config-plist)))
  108. (dolist (pair config-alist)
  109. (let ((config (list
  110. matches-regexp
  111. (car pair)
  112. (cdr pair))))
  113. (add-to-list
  114. 'tramp-connection-properties
  115. config))))))
  116. #+END_SRC
  117. ** Android
  118. #+BEGIN_SRC emacs-lisp
  119. (use-package tramp
  120. :config
  121. (let ((android-config (let ((default-directory "/data/data/com.termux/files"))
  122. (list "tmpdir" (expand-file-name "home/temp/")
  123. "remote-shell" (expand-file-name "usr/bin/sh")
  124. "remote-process-environment" (append (list (concat "PREFIX=" default-directory "usr")) tramp-remote-process-environment)
  125. "remote-path" (append (mapcar 'expand-file-name '("home/.local/bin" "usr/bin" "usr/bin/applets")) '("/sbin" "/vendor/bin" "/system/sbin" "/system/bin" "/system/xbin"))))))
  126. (rlbr/add-config-to-tramp "/ssh:termux.*:" android-config)))
  127. #+END_SRC
  128. * Major modes
  129. ** Java
  130. ** JavaScript
  131. #+BEGIN_SRC emacs-lisp
  132. (use-package js2-mode
  133. :mode "\\.js\\'"
  134. :hook ((js2-mode . js2-imenu-extras-mode)
  135. (js2-mode . (lambda () (add-hook 'xref-backend-functions #'xref-js2-xref-backend nil t))))
  136. :config
  137. (use-package js2-refactor
  138. :hook (js2-mode . js2-refactor-mode)
  139. :bind
  140. (:map js2-mode-map
  141. ("C-k" . js2r-kill))
  142. :config
  143. (js2r-add-keybindings-with-prefix "C-c C-r"))
  144. (use-package xref-js2
  145. :demand t)
  146. (define-key js-mode-map (kbd "M-.") nil)
  147. (defun rlbr/jump-to-definition ()
  148. "Jump to a definition."
  149. (interactive)
  150. (condition-case-unless-debug nil
  151. (js2-jump-to-definition)
  152. (error
  153. (progn
  154. (ignore-errors
  155. (xref-pop-marker-stack))
  156. (xref-find-definitions (xref-backend-identifier-at-point (xref-find-backend)))))))
  157. (define-key js-mode-map (kbd "M-.") #'rlbr/jump-to-definition))
  158. #+END_SRC
  159. ** Magit
  160. #+BEGIN_SRC emacs-lisp
  161. (use-package magit
  162. :bind (("C-x g" . magit-status))
  163. :config
  164. (use-package git-commit
  165. :hook (git-commit-setup . git-commit-turn-on-flyspell)))
  166. #+END_SRC
  167. ** Python
  168. *** Platform specific
  169. #+BEGIN_SRC emacs-lisp
  170. (cond
  171. ((string-equal system-type "gnu/linux")
  172. "python3")
  173. ((string-equal system-type "windows-nt")
  174. "python.exe"))
  175. #+END_SRC
  176. *** custom feature
  177. *** bindings/settings
  178. #+BEGIN_SRC emacs-lisp
  179. (use-package python
  180. :config
  181. (use-package elpy
  182. :bind (("C-=" . elpy-goto-assignment))
  183. :config (when (require 'flycheck nil t)
  184. (setq elpy-modules (delq 'elpy-module-flymake elpy-modules))))
  185. (elpy-enable)
  186. (blacken-mode))
  187. #+END_SRC
  188. ** SSH config mode
  189. #+BEGIN_SRC emacs-lisp
  190. (use-package ssh-config-mode
  191. :mode "~/.ssh/config\\'")
  192. #+END_SRC
  193. ** Tramp
  194. ** Webmode
  195. #+BEGIN_SRC emacs-lisp
  196. (use-package web-mode
  197. :mode
  198. (("\\.phtml\\'" . web-mode)
  199. ("\\.tpl\\.php\\'" . web-mode)
  200. ("\\.[agj]sp\\'" . web-mode)
  201. ("\\.as[cp]x\\'" . web-mode)
  202. ("\\.erb\\'" . web-mode)
  203. ("\\.mustache\\'" . web-mode)
  204. ("\\.djhtml\\'" . web-mode)
  205. ("\\.html?\\'" . web-mode)))
  206. #+END_SRC
  207. ** YAML
  208. #+BEGIN_SRC emacs-lisp
  209. (use-package yaml-mode
  210. :mode "\\.yml\\'")
  211. #+END_SRC
  212. * Minor modes/misc
  213. ** Kill the things
  214. *** Buffer
  215. #+BEGIN_SRC emacs-lisp
  216. (global-set-key (kbd "C-x k") 'kill-this-buffer)
  217. #+END_SRC
  218. *** Emacs
  219. #+BEGIN_SRC emacs-lisp
  220. (global-set-key (kbd "C-x C-k C-x C-k") 'kill-emacs)
  221. #+END_SRC
  222. ** Lispy
  223. #+BEGIN_SRC emacs-lisp
  224. (use-package lispy
  225. :hook ((emacs-lisp-mode) . lispy-mode))
  226. #+END_SRC
  227. * Navigation/auto-completion
  228. ** Ace window
  229. #+BEGIN_SRC emacs-lisp
  230. (use-package ace-window
  231. :bind (("M-Q" . ace-window)))
  232. #+END_SRC
  233. ** Hippie expand
  234. #+BEGIN_SRC emacs-lisp
  235. (use-package hippie-exp
  236. :bind ("M-/" . hippie-expand))
  237. #+END_SRC
  238. ** IBuffer mode
  239. #+BEGIN_SRC emacs-lisp
  240. (use-package ibbufer-vc
  241. :hook ((ibuffer-mode . ibuffer-vc-set-filter-groups-by-vc-root)))
  242. (use-package ibuffer
  243. :bind (("C-x C-b" . ibuffer))
  244. :config
  245. (define-ibuffer-column size-h
  246. ;; Use human readable Size column instead of original one
  247. (:name "Size" :inline t)
  248. (cond ((> (buffer-size) 1000000)
  249. (format "%7.1fM" (/ (buffer-size) 1000000.0)))
  250. ((> (buffer-size) 100000)
  251. (format "%7.0fk" (/ (buffer-size) 1000.0)))
  252. ((> (buffer-size) 1000)
  253. (format "%7.1fk" (/ (buffer-size) 1000.0)))
  254. (t
  255. (format "%8d" (buffer-size))))))
  256. #+END_SRC
  257. ** Ivy
  258. #+BEGIN_SRC emacs-lisp
  259. (use-package ivy
  260. :config
  261. (use-package swiper
  262. :bind ("C-s" . swiper))
  263. (ivy-mode))
  264. #+END_SRC
  265. * Look and feel
  266. ** Line numbers
  267. #+BEGIN_SRC emacs-lisp
  268. (global-display-line-numbers-mode)
  269. #+END_SRC
  270. ** Mode line bell
  271. #+BEGIN_SRC emacs-lisp
  272. (use-package mode-line-bell
  273. :config
  274. (mode-line-bell-mode))
  275. #+END_SRC
  276. ** Spaceline
  277. #+BEGIN_SRC emacs-lisp
  278. (use-package spaceline-config
  279. :config
  280. (use-package winum
  281. :init
  282. (setq winum-keymap
  283. (let ((map (make-sparse-keymap)))
  284. (define-key map (kbd "M-0") 'winum-select-window-0-or-10)
  285. (define-key map (kbd "M-1") 'winum-select-window-1)
  286. (define-key map (kbd "M-2") 'winum-select-window-2)
  287. (define-key map (kbd "M-3") 'winum-select-window-3)
  288. (define-key map (kbd "M-4") 'winum-select-window-4)
  289. (define-key map (kbd "M-5") 'winum-select-window-5)
  290. (define-key map (kbd "M-6") 'winum-select-window-6)
  291. (define-key map (kbd "M-7") 'winum-select-window-7)
  292. (define-key map (kbd "M-8") 'winum-select-window-8)
  293. map)))
  294. (spaceline-spacemacs-theme)
  295. (winum-mode))
  296. #+END_SRC