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.

213 lines
6.6 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. **** linum
  113. #+BEGIN_SRC emacs-lisp
  114. (global-display-line-numbers-mode)
  115. #+END_SRC
  116. *** dired
  117. #+begin_src emacs-lisp
  118. (setq ls-lisp-use-insert-directory-program t)
  119. #+end_src
  120. #+begin_src emacs-lisp
  121. (setq dired-listing-switches "-alh")
  122. #+end_src
  123. * Tramp configuration
  124. #+begin_src emacs-lisp
  125. (add-to-list 'tramp-remote-path 'tramp-own-remote-path)
  126. (add-to-list 'tramp-remote-path "/system/xbin")
  127. (add-to-list 'tramp-remote-path "/data/data/com.termux/file/usr/bin")
  128. #+end_src
  129. * Web things
  130. ** javascript stuff
  131. #+begin_src emacs-lisp
  132. (require 'js2-mode)
  133. (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  134. (add-hook 'js2-mode-hook #'js2-imenu-extras-mode)
  135. (require 'js2-refactor)
  136. (require 'xref-js2)
  137. (add-hook 'js2-mode-hook #'js2-refactor-mode)
  138. (js2r-add-keybindings-with-prefix "C-c C-r")
  139. (define-key js2-mode-map (kbd "C-k") #'js2r-kill)
  140. (define-key js-mode-map (kbd "M-.") nil)
  141. (add-hook 'js2-mode-hook (lambda ()
  142. (add-hook 'xref-backend-functions #'xref-js2-xref-backend nil t)))
  143. (define-key js2-mode-map (kbd "C-k") #'js2r-kill)
  144. #+end_src
  145. ** web mode
  146. #+begin_src emacs-lisp
  147. (require 'web-mode)
  148. (add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode))
  149. (add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode))
  150. (add-to-list 'auto-mode-alist '("\\.[agj]sp\\'" . web-mode))
  151. (add-to-list 'auto-mode-alist '("\\.as[cp]x\\'" . web-mode))
  152. (add-to-list 'auto-mode-alist '("\\.erb\\'" . web-mode))
  153. (add-to-list 'auto-mode-alist '("\\.mustache\\'" . web-mode))
  154. (add-to-list 'auto-mode-alist '("\\.djhtml\\'" . web-mode))
  155. (add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
  156. #+end_src
  157. * Platform Specific
  158. #+begin_src emacs-lisp
  159. (cond
  160. #+end_src
  161. ** Windows
  162. #+begin_src emacs-lisp
  163. ((string-equal system-type "windows-nt")
  164. (progn
  165. (defun quote-exe (path)
  166. (w32-short-file-name path))
  167. (defun start-external-shell ()
  168. (interactive)
  169. (start-process-shell-command (format "cmd(%s)" default-directory) nil "start default.bat"))
  170. (global-set-key (kbd "C-S-C") 'start-external-shell)
  171. (setq insert-directory-program "C:/Program Files/git/usr/bin/ls.exe")
  172. (setq find-program (quote-exe "C:/Program Files/git/usr/bin/find.exe"))
  173. (setq grep-program (quote-exe "C:/Program Files/git/usr/bin/grep.exe"))
  174. (setq python-shell-interpreter (quote-exe (executable-find "python")))
  175. (setq python-check-command (quote-exe (executable-find "flake8")))
  176. (setq delete-by-moving-to-trash t)
  177. (defun python-shell-interpreter-refresh ()
  178. (interactive)
  179. (setq python-shell-interpreter (quote-exe (executable-find "python"))))
  180. (add-hook 'python-django-project-root-hook 'python-shell-interpreter-refresh)
  181. ))
  182. #+end_src
  183. ** Linux
  184. #+begin_src emacs-lisp
  185. ((string-equal system-type "gnu/linux")
  186. (progn
  187. (setq python-shell-interpreter "python3")
  188. (setq elpy-rpc-python-command python-shell-interpreter)
  189. (defun get-elpa-package-install-directory (pkg)
  190. "Return the install directory of elpa PKG. Return nil if it is not found."
  191. (let ((elpa-dir package-user-dir))
  192. (when (file-exists-p elpa-dir)
  193. (let* ((pkg-match (concat "\\`" (symbol-name pkg) "-[0-9]+"))
  194. (dir (car (directory-files elpa-dir 'full pkg-match))))
  195. (when dir (file-name-as-directory dir))))))
  196. (setq vr/command-python
  197. (format "python3 %s" (expand-file-name "regexp.py" (get-elpa-package-install-directory 'visual-regexp-steroids))))
  198. )))
  199. #+end_src
  200. * Python
  201. #+begin_src emacs-lisp
  202. (elpy-enable)
  203. (when (require 'flycheck nil t)
  204. (setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
  205. (add-hook 'elpy-mode-hook 'flycheck-mode))
  206. (require 'blacken)
  207. (defun python-mode-keys ()
  208. "Modify python-mode local key map"
  209. (local-set-key (kbd "C-=") 'elpy-goto-assignment))
  210. (add-hook 'python-mode-hook 'python-mode-keys)
  211. (add-hook 'elpy-mode-hook 'blacken-mode)
  212. (setq elpy-syntax-check-command python-check-command)
  213. #+end_src