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.

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