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.

209 lines
6.5 KiB

  1. * Global
  2. ** Add features/modes
  3. *** undo-tree
  4. #+begin_src emacs-lisp
  5. (require 'undo-tree)
  6. (global-undo-tree-mode)
  7. #+end_src
  8. *** ssh-config-mode
  9. #+begin_src emacs-lisp
  10. (require 'ssh-config-mode)
  11. (add-to-list 'auto-mode-alist '("~/.ssh/config\\'" . ssh-config-mode))
  12. #+end_src
  13. *** yaml-mode
  14. #+begin_src emacs-lisp
  15. (require 'yaml-mode)
  16. (add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode))
  17. #+end_src
  18. *** elpy move line up and down globally
  19. #+begin_src emacs-lisp
  20. (require 'elpy)
  21. (global-set-key (kbd "M-<up>") 'elpy-nav-move-line-or-region-up)
  22. (global-set-key (kbd "M-<down>") 'elpy-nav-move-line-or-region-down)
  23. (global-set-key (kbd "C-c <left>") 'windmove-left)
  24. (global-set-key (kbd "C-c <right>") 'windmove-right)
  25. (global-set-key (kbd "C-c <up>") 'windmove-up)
  26. (global-set-key (kbd "C-c <down>") 'windmove-down)
  27. #+end_src
  28. *** iedit-mode
  29. #+begin_src emacs-lisp
  30. (global-set-key (kbd "C-;") 'iedit-mode)
  31. #+end_src
  32. *** spellcheck entire buffer
  33. #+begin_src emacs-lisp
  34. (global-set-key (kbd "C-!") 'ispell-buffer)
  35. #+end_src
  36. *** find/replace
  37. #+begin_src emacs-lisp
  38. (require 'visual-regexp-steroids)
  39. (define-key global-map (kbd "C-c r") 'vr/replace)
  40. (define-key global-map (kbd "C-c q") 'vr/query-replace)
  41. #+end_src
  42. *** duplicate line function
  43. #+begin_src emacs-lisp
  44. (defun duplicate-line()
  45. (interactive)
  46. (move-beginning-of-line 1)
  47. (kill-line)
  48. (yank)
  49. (open-line 1)
  50. (next-line 1)
  51. (yank))
  52. (global-set-key (kbd "C-c d") 'duplicate-line)
  53. #+end_src
  54. *** magit
  55. #+begin_src emacs-lisp
  56. (global-set-key (kbd "C-x g") 'magit-status)
  57. #+end_src
  58. #+begin_src emacs-lisp
  59. (add-hook 'git-commit-setup-hook 'git-commit-turn-on-flyspell)
  60. #+end_src
  61. ** options
  62. *** global
  63. **** recent files
  64. #+begin_src emacs-lisp
  65. (require 'recentf)
  66. (recentf-mode 1)
  67. #+end_src
  68. **** backup
  69. #+begin_src emacs-lisp
  70. (let ((backup-dir (concat user-emacs-directory "backup"))
  71. (auto-save-dir (concat user-emacs-directory "autosave"))
  72. )
  73. (if (not (file-directory-p backup-dir))
  74. (make-directory backup-dir))
  75. (if (not(file-directory-p auto-save-dir))
  76. (make-directory auto-save-dir)
  77. )
  78. (setq backup-directory-alist
  79. `((".*" . , backup-dir)))
  80. (setq auto-save-file-name-transforms
  81. `((".*" , (concat auto-save-dir "/") t))))
  82. #+end_src
  83. **** kill buffer option
  84. #+begin_src emacs-lisp
  85. (global-set-key (kbd "C-x k") 'kill-this-buffer)
  86. #+end_src
  87. **** inhibit start screen
  88. #+begin_src emacs-lisp
  89. (setq inhibit-startup-screen t)
  90. #+end_src
  91. **** save options
  92. #+begin_src emacs-lisp
  93. (add-hook 'before-save-hook 'delete-trailing-whitespace)
  94. #+end_src
  95. **** theming
  96. #+begin_src emacs-lisp
  97. (load-theme 'dracula t)
  98. #+end_src
  99. **** bell
  100. #+BEGIN_SRC emacs-lisp
  101. (mode-line-bell-mode)
  102. #+END_SRC
  103. **** ivy
  104. #+BEGIN_SRC emacs-lisp
  105. (ivy-mode)
  106. (global-set-key (kbd "C-s") 'swiper)
  107. #+END_SRC
  108. **** kill-emacs key
  109. #+BEGIN_SRC emacs-lisp
  110. (global-set-key (kbd "C-x C-k C-x C-k") 'kill-emacs)
  111. #+END_SRC
  112. *** dired
  113. #+begin_src emacs-lisp
  114. (setq ls-lisp-use-insert-directory-program t)
  115. #+end_src
  116. #+begin_src emacs-lisp
  117. (setq dired-listing-switches "-alh")
  118. #+end_src
  119. * Tramp configuration
  120. #+begin_src emacs-lisp
  121. (add-to-list 'tramp-remote-path 'tramp-own-remote-path)
  122. (add-to-list 'tramp-remote-path "/system/xbin")
  123. (add-to-list 'tramp-remote-path "/data/data/com.termux/file/usr/bin")
  124. #+end_src
  125. * Web things
  126. ** javascript stuff
  127. #+begin_src emacs-lisp
  128. (require 'js2-mode)
  129. (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  130. (add-hook 'js2-mode-hook #'js2-imenu-extras-mode)
  131. (require 'js2-refactor)
  132. (require 'xref-js2)
  133. (add-hook 'js2-mode-hook #'js2-refactor-mode)
  134. (js2r-add-keybindings-with-prefix "C-c C-r")
  135. (define-key js2-mode-map (kbd "C-k") #'js2r-kill)
  136. (define-key js-mode-map (kbd "M-.") nil)
  137. (add-hook 'js2-mode-hook (lambda ()
  138. (add-hook 'xref-backend-functions #'xref-js2-xref-backend nil t)))
  139. (define-key js2-mode-map (kbd "C-k") #'js2r-kill)
  140. #+end_src
  141. ** web mode
  142. #+begin_src emacs-lisp
  143. (require 'web-mode)
  144. (add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode))
  145. (add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode))
  146. (add-to-list 'auto-mode-alist '("\\.[agj]sp\\'" . web-mode))
  147. (add-to-list 'auto-mode-alist '("\\.as[cp]x\\'" . web-mode))
  148. (add-to-list 'auto-mode-alist '("\\.erb\\'" . web-mode))
  149. (add-to-list 'auto-mode-alist '("\\.mustache\\'" . web-mode))
  150. (add-to-list 'auto-mode-alist '("\\.djhtml\\'" . web-mode))
  151. (add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
  152. #+end_src
  153. * Platform Specific
  154. #+begin_src emacs-lisp
  155. (cond
  156. #+end_src
  157. ** Windows
  158. #+begin_src emacs-lisp
  159. ((string-equal system-type "windows-nt")
  160. (progn
  161. (defun quote-exe (path)
  162. (w32-short-file-name path))
  163. (defun start-external-shell ()
  164. (interactive)
  165. (start-process-shell-command (format "cmd(%s)" default-directory) nil "start default.bat"))
  166. (global-set-key (kbd "C-S-C") 'start-external-shell)
  167. (setq insert-directory-program "C:/Program Files/git/usr/bin/ls.exe")
  168. (setq find-program (quote-exe "C:/Program Files/git/usr/bin/find.exe"))
  169. (setq grep-program (quote-exe "C:/Program Files/git/usr/bin/grep.exe"))
  170. (setq python-shell-interpreter (quote-exe (executable-find "python")))
  171. (setq python-check-command (quote-exe (executable-find "flake8")))
  172. (setq delete-by-moving-to-trash t)
  173. (defun python-shell-interpreter-refresh ()
  174. (interactive)
  175. (setq python-shell-interpreter (quote-exe (executable-find "python"))))
  176. (add-hook 'python-django-project-root-hook 'python-shell-interpreter-refresh)
  177. ))
  178. #+end_src
  179. ** Linux
  180. #+begin_src emacs-lisp
  181. ((string-equal system-type "gnu/linux")
  182. (progn
  183. (setq python-shell-interpreter "python3")
  184. (setq elpy-rpc-python-command python-shell-interpreter)
  185. (defun get-elpa-package-install-directory (pkg)
  186. "Return the install directory of elpa PKG. Return nil if it is not found."
  187. (let ((elpa-dir package-user-dir))
  188. (when (file-exists-p elpa-dir)
  189. (let* ((pkg-match (concat "\\`" (symbol-name pkg) "-[0-9]+"))
  190. (dir (car (directory-files elpa-dir 'full pkg-match))))
  191. (when dir (file-name-as-directory dir))))))
  192. (setq vr/command-python
  193. (format "python3 %s" (expand-file-name "regexp.py" (get-elpa-package-install-directory 'visual-regexp-steroids))))
  194. )))
  195. #+end_src
  196. * Python
  197. #+begin_src emacs-lisp
  198. (elpy-enable)
  199. (when (require 'flycheck nil t)
  200. (setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
  201. (add-hook 'elpy-mode-hook 'flycheck-mode))
  202. (require 'blacken)
  203. (defun python-mode-keys ()
  204. "Modify python-mode local key map"
  205. (local-set-key (kbd "C-=") 'elpy-goto-assignment))
  206. (add-hook 'python-mode-hook 'python-mode-keys)
  207. (add-hook 'elpy-mode-hook 'blacken-mode)
  208. (setq elpy-syntax-check-command python-check-command)
  209. #+end_src