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.

233 lines
6.4 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/select-replace)
  40. (define-key global-map (kbd "C-c q") 'vr/select-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. (global-set-key (kbd "C-<tab>") 'recentf-open-files)
  68. #+end_src
  69. **** backup
  70. #+begin_src emacs-lisp
  71. (let ((backup-dir (concat user-emacs-directory "backup"))
  72. (auto-save-dir (concat user-emacs-directory "autosave"))
  73. )
  74. (if (not (file-directory-p backup-dir))
  75. (make-directory backup-dir))
  76. (if (not(file-directory-p auto-save-dir))
  77. (make-directory auto-save-dir)
  78. )
  79. (setq backup-directory-alist
  80. `((".*" . , backup-dir)))
  81. (setq auto-save-file-name-transforms
  82. `((".*" , (concat auto-save-dir "/") t))))
  83. #+end_src
  84. **** kill buffer option
  85. #+begin_src emacs-lisp
  86. (global-set-key (kbd "C-x k") 'kill-this-buffer)
  87. #+end_src
  88. **** inhibit start screen
  89. #+begin_src emacs-lisp
  90. (setq inhibit-startup-screen t)
  91. #+end_src
  92. **** save options
  93. #+begin_src emacs-lisp
  94. (add-hook 'before-save-hook 'delete-trailing-whitespace)
  95. #+end_src
  96. **** theming
  97. #+begin_src emacs-lisp
  98. (load-theme 'dracula t)
  99. #+end_src
  100. **** line numbers globally
  101. #+begin_src emacs-lisp
  102. (global-linum-mode t)
  103. #+end_src
  104. *** dired
  105. #+begin_src emacs-lisp
  106. (setq ls-lisp-use-insert-directory-program t)
  107. #+end_src
  108. #+begin_src emacs-lisp
  109. (setq dired-listing-switches "-alh")
  110. #+end_src
  111. * Tramp configuration
  112. #+begin_src emacs-lisp
  113. (add-to-list 'tramp-remote-path 'tramp-own-remote-path)
  114. (add-to-list 'tramp-remote-path "/system/xbin")
  115. (add-to-list 'tramp-remote-path "/data/data/com.termux/file/usr/bin")
  116. #+end_src
  117. * Web things
  118. ** javascript stuff
  119. #+begin_src emacs-lisp
  120. (require 'js2-mode)
  121. (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  122. (add-hook 'js2-mode-hook #'js2-imenu-extras-mode)
  123. (require 'js2-refactor)
  124. (require 'xref-js2)
  125. (add-hook 'js2-mode-hook #'js2-refactor-mode)
  126. (js2r-add-keybindings-with-prefix "C-c C-r")
  127. (define-key js2-mode-map (kbd "C-k") #'js2r-kill)
  128. (define-key js-mode-map (kbd "M-.") nil)
  129. (add-hook 'js2-mode-hook (lambda ()
  130. (add-hook 'xref-backend-functions #'xref-js2-xref-backend nil t)))
  131. (define-key js2-mode-map (kbd "C-k") #'js2r-kill)
  132. #+end_src
  133. ** web mode
  134. #+begin_src emacs-lisp
  135. (require 'web-mode)
  136. (add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode))
  137. (add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode))
  138. (add-to-list 'auto-mode-alist '("\\.[agj]sp\\'" . web-mode))
  139. (add-to-list 'auto-mode-alist '("\\.as[cp]x\\'" . web-mode))
  140. (add-to-list 'auto-mode-alist '("\\.erb\\'" . web-mode))
  141. (add-to-list 'auto-mode-alist '("\\.mustache\\'" . web-mode))
  142. (add-to-list 'auto-mode-alist '("\\.djhtml\\'" . web-mode))
  143. (add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
  144. #+end_src
  145. * Platform Specific
  146. #+begin_src emacs-lisp
  147. (cond
  148. #+end_src
  149. ** Windows
  150. #+begin_src emacs-lisp
  151. ((string-equal system-type "windows-nt")
  152. (progn
  153. (defun quote-exe (path)
  154. (w32-short-file-name path))
  155. (defun start-external-shell ()
  156. (interactive)
  157. (start-process-shell-command (format "cmd(%s)" default-directory) nil "start default.bat"))
  158. (global-set-key (kbd "C-S-C") 'start-external-shell)
  159. (setq insert-directory-program "C:/Program Files/git/usr/bin/ls.exe")
  160. (setq find-program (quote-exe "C:/Program Files/git/usr/bin/find.exe"))
  161. (setq grep-program (quote-exe "C:/Program Files/git/usr/bin/grep.exe"))
  162. (setq python-shell-interpreter (quote-exe (executable-find "python")))
  163. (setq python-check-command (quote-exe (executable-find "flake8")))
  164. (setq delete-by-moving-to-trash t)
  165. (defun python-shell-interpreter-refresh ()
  166. (interactive)
  167. (setq python-shell-interpreter (quote-exe (executable-find "python"))))
  168. (add-hook 'python-django-project-root-hook 'python-shell-interpreter-refresh)
  169. ))
  170. #+end_src
  171. ** Linux
  172. #+begin_src emacs-lisp
  173. ((string-equal system-type "gnu/linux")
  174. (progn
  175. (setq python-shell-interpreter "python3")
  176. (setq elpy-rpc-python-command python-shell-interpreter)
  177. (defun get-elpa-package-install-directory (pkg)
  178. "Return the install directory of elpa PKG. Return nil if it is not found."
  179. (let ((elpa-dir package-user-dir))
  180. (when (file-exists-p elpa-dir)
  181. (let* ((pkg-match (concat "\\`" (symbol-name pkg) "-[0-9]+"))
  182. (dir (car (directory-files elpa-dir 'full pkg-match))))
  183. (when dir (file-name-as-directory dir))))))
  184. (setq vr/command-python
  185. (format "python3 %s" (expand-file-name "regexp.py" (get-elpa-package-install-directory 'visual-regexp-steroids))))
  186. )))
  187. #+end_src
  188. * Python
  189. #+begin_src emacs-lisp
  190. (elpy-enable)
  191. (when (require 'flycheck nil t)
  192. (setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
  193. (add-hook 'elpy-mode-hook 'flycheck-mode))
  194. (require 'blacken)
  195. (defun python-mode-keys ()
  196. "Modify python-mode local key map"
  197. (local-set-key (kbd "C-=") 'elpy-goto-assignment))
  198. (add-hook 'python-mode-hook 'python-mode-keys)
  199. (add-hook 'elpy-mode-hook 'blacken-mode)
  200. (setq elpy-syntax-check-command python-check-command)
  201. #+end_src