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.

202 lines
7.0 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. ;; init.el --- Emacs configuration
  2. ;; INSTALL PACKAGES
  3. ;; --------------------------------------
  4. (require 'package)
  5. (add-to-list 'package-archives
  6. '("melpa" . "https://melpa.org/packages/") t)
  7. (package-initialize)
  8. (when (not package-archive-contents)
  9. (package-refresh-contents))
  10. (defvar myPackages
  11. '(better-defaults
  12. ein
  13. iedit
  14. elpy
  15. flycheck
  16. magit
  17. ssh-config-mode
  18. web-mode
  19. dracula-theme
  20. yaml-mode
  21. py-autopep8
  22. apache-mode
  23. js2-mode
  24. js2-refactor
  25. xref-js2
  26. visual-regexp-steroids))
  27. (mapc #'(lambda (package)
  28. (unless (package-installed-p package)
  29. (package-install package)))
  30. myPackages)
  31. ;; BASIC
  32. (require 'ssh-config-mode)
  33. (add-to-list 'auto-mode-alist '("~/.ssh/config\\'" . ssh-config-mode))
  34. (require 'yaml-mode)
  35. (add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode))
  36. (require 'elpy)
  37. (global-set-key (kbd "M-<up>") 'elpy-nav-move-line-or-region-up)
  38. (global-set-key (kbd "M-<down>") 'elpy-nav-move-line-or-region-down)
  39. ;; Window movement
  40. (global-set-key (kbd "C-c <left>") 'windmove-left)
  41. (global-set-key (kbd "C-c <right>") 'windmove-right)
  42. (global-set-key (kbd "C-c <up>") 'windmove-up)
  43. (global-set-key (kbd "C-c <down>") 'windmove-down)
  44. (global-set-key (kbd "C-;") 'iedit-mode)
  45. ;; Tramp
  46. (add-to-list 'tramp-remote-path 'tramp-own-remote-path)
  47. (add-to-list 'tramp-remote-path "/system/xbin")
  48. (add-to-list 'tramp-remote-path "/data/data/com.termux/file/usr/bin")
  49. ;; JavaScript
  50. (require 'js2-mode)
  51. (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  52. ;; Better imenu
  53. (add-hook 'js2-mode-hook #'js2-imenu-extras-mode)
  54. (require 'js2-refactor)
  55. (require 'xref-js2)
  56. (add-hook 'js2-mode-hook #'js2-refactor-mode)
  57. (js2r-add-keybindings-with-prefix "C-c C-r")
  58. (define-key js2-mode-map (kbd "C-k") #'js2r-kill)
  59. ;; js-mode (which js2 is based on) binds "M-." which conflicts with xref, so
  60. ;; unbind it.
  61. (define-key js-mode-map (kbd "M-.") nil)
  62. (add-hook 'js2-mode-hook (lambda ()
  63. (add-hook 'xref-backend-functions #'xref-js2-xref-backend nil t)))
  64. (define-key js2-mode-map (kbd "C-k") #'js2r-kill)
  65. ;; Web-mode
  66. (require 'web-mode)
  67. (add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode))
  68. (add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode))
  69. (add-to-list 'auto-mode-alist '("\\.[agj]sp\\'" . web-mode))
  70. (add-to-list 'auto-mode-alist '("\\.as[cp]x\\'" . web-mode))
  71. (add-to-list 'auto-mode-alist '("\\.erb\\'" . web-mode))
  72. (add-to-list 'auto-mode-alist '("\\.mustache\\'" . web-mode))
  73. (add-to-list 'auto-mode-alist '("\\.djhtml\\'" . web-mode))
  74. (add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
  75. ;; visual-regexp-steroids
  76. (require 'visual-regexp-steroids)
  77. (define-key global-map (kbd "C-c r") 'vr/select-replace)
  78. (define-key global-map (kbd "C-c q") 'vr/select-query-replace)
  79. ;; Custom
  80. (setq dired-listing-switches "-alh")
  81. (defun duplicate-line()
  82. (interactive)
  83. (move-beginning-of-line 1)
  84. (kill-line)
  85. (yank)
  86. (open-line 1)
  87. (next-line 1)
  88. (yank))
  89. (global-set-key (kbd "C-c d") 'duplicate-line)
  90. (require 'recentf)
  91. (recentf-mode 1)
  92. (global-set-key (kbd "C-<tab>") 'recentf-open-files)
  93. (global-set-key (kbd "C-x g") 'magit-status)
  94. (setq inhibit-startup-screen t)
  95. ;; (setq vc-handled-backends nil)
  96. ;; use external ls
  97. (setq ls-lisp-use-insert-directory-program t)
  98. (let ((backup-dir (concat user-emacs-directory "backup"))
  99. (auto-save-dir (concat user-emacs-directory "autosave"))
  100. )
  101. (if (not (file-directory-p backup-dir))
  102. (make-directory backup-dir))
  103. (if (not(file-directory-p auto-save-dir))
  104. (make-directory auto-save-dir)
  105. )
  106. (setq backup-directory-alist
  107. `((".*" . , backup-dir)))
  108. (setq auto-save-file-name-transforms
  109. `((".*" , (concat auto-save-dir "/") t))))
  110. (cond
  111. ;; Windows fixes
  112. ((string-equal system-type "windows-nt")
  113. (progn
  114. (defun quote-exe (path)
  115. (w32-short-file-name path))
  116. (defun start-external-shell ()
  117. (interactive)
  118. (start-process-shell-command (format "cmd(%s)" default-directory) nil "start default.bat"))
  119. (global-set-key (kbd "C-S-C") 'start-external-shell)
  120. (setq insert-directory-program "C:/Program Files/git/usr/bin/ls.exe")
  121. (setq find-program (quote-exe "C:/Program Files/git/usr/bin/find.exe"))
  122. (setq grep-program (quote-exe "C:/Program Files/git/usr/bin/grep.exe"))
  123. (setq python-shell-interpreter (quote-exe (executable-find "python")))
  124. (setq python-check-command (quote-exe (executable-find "flake8")))
  125. (setq delete-by-moving-to-trash t)
  126. ))
  127. ;; Linux-specific
  128. ((string-equal system-type "gnu/linux")
  129. (progn
  130. (setq python-shell-interpreter "python3")
  131. (setq elpy-rpc-python-command python-shell-interpreter)
  132. (defun get-elpa-package-install-directory (pkg)
  133. "Return the install directory of elpa PKG. Return nil if it is not found."
  134. (let ((elpa-dir package-user-dir))
  135. (when (file-exists-p elpa-dir)
  136. (let* ((pkg-match (concat "\\`" (symbol-name pkg) "-[0-9]+"))
  137. (dir (car (directory-files elpa-dir 'full pkg-match))))
  138. (when dir (file-name-as-directory dir))))))
  139. (setq vr/command-python
  140. (format "python3 %s" (expand-file-name "regexp.py" (get-elpa-package-install-directory 'visual-regexp-steroids))))
  141. )))
  142. (add-hook 'git-commit-setup-hook 'git-commit-turn-on-flyspell)
  143. (add-hook 'before-save-hook 'delete-trailing-whitespace)
  144. ;; --------------------------------------
  145. (load-theme 'dracula t)
  146. (global-linum-mode t) ;; enable line numbers globally
  147. ;; PYTHON CONFIGURATION
  148. ;; --------------------------------------
  149. (elpy-enable)
  150. ;;(debug-on-variable-change 'python-check-command)
  151. ;; (elpy-use-ipython)
  152. ;; use flycheck not flymake with elpy
  153. (when (require 'flycheck nil t)
  154. (setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
  155. (add-hook 'elpy-mode-hook 'flycheck-mode))
  156. ;; enable py-autopep8 formatting on save
  157. (require 'py-autopep8)
  158. (defun python-mode-keys ()
  159. "Modify python-mode local key map"
  160. (local-set-key (kbd "C-c C-p") 'py-autopep8))
  161. (add-hook 'python-mode-hook 'python-mode-keys)
  162. (add-hook 'elpy-mode-hook 'py-autopep8-enable-on-save)
  163. (setq elpy-syntax-check-command python-check-command)
  164. ;; init.el ends here
  165. (custom-set-variables
  166. ;; custom-set-variables was added by Custom.
  167. ;; If you edit it by hand, you could mess it up, so be careful.
  168. ;; Your init file should contain only one such instance.
  169. ;; If there is more than one, they won't work right.
  170. '(custom-safe-themes
  171. (quote
  172. ("274fa62b00d732d093fc3f120aca1b31a6bb484492f31081c1814a858e25c72e" default)))
  173. '(package-selected-packages
  174. (quote
  175. (js2-mode js2-refactor xref-js2 python-django django-mode visual-regexp-steroids pcre2el vimrc-mode iedit transient magit dracula-theme py-autopep8 flycheck elpy ein better-defaults ssh-config-mode yaml-mode apache-mode web-mode))))
  176. (custom-set-faces
  177. ;; custom-set-faces was added by Custom.
  178. ;; If you edit it by hand, you could mess it up, so be careful.
  179. ;; Your init file should contain only one such instance.
  180. ;; If there is more than one, they won't work right.
  181. '(default ((t (:family "Roboto Mono" :foundry "outline" :slant normal :weight normal :height 113 :width normal)))))