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.

194 lines
6.7 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. (setq backup-directory-alist
  99. `((".*" . ,temporary-file-directory)))
  100. (setq auto-save-file-name-transforms
  101. `((".*" ,temporary-file-directory t)))
  102. (cond
  103. ;; Windows fixes
  104. ((string-equal system-type "windows-nt")
  105. (progn
  106. (defun quote-exe (path)
  107. (w32-short-file-name path))
  108. (defun start-external-shell ()
  109. (interactive)
  110. (start-process-shell-command (format "cmd(%s)" default-directory) nil "start default.bat"))
  111. (global-set-key (kbd "C-S-C") 'start-external-shell)
  112. (setq insert-directory-program "C:/Program Files/git/usr/bin/ls.exe")
  113. (setq find-program (quote-exe "C:/Program Files/git/usr/bin/find.exe"))
  114. (setq grep-program (quote-exe "C:/Program Files/git/usr/bin/grep.exe"))
  115. (setq python-shell-interpreter (quote-exe (executable-find "python")))
  116. (setq python-check-command (quote-exe (executable-find "flake8")))
  117. (setq delete-by-moving-to-trash t)
  118. ))
  119. ;; Linux-specific
  120. ((string-equal system-type "gnu/linux")
  121. (progn
  122. (setq python-shell-interpreter "python3")
  123. (setq elpy-rpc-python-command python-shell-interpreter)
  124. (defun get-elpa-package-install-directory (pkg)
  125. "Return the install directory of elpa PKG. Return nil if it is not found."
  126. (let ((elpa-dir package-user-dir))
  127. (when (file-exists-p elpa-dir)
  128. (let* ((pkg-match (concat "\\`" (symbol-name pkg) "-[0-9]+"))
  129. (dir (car (directory-files elpa-dir 'full pkg-match))))
  130. (when dir (file-name-as-directory dir))))))
  131. (setq vr/command-python
  132. (format "python3 %s" (expand-file-name "regexp.py" (get-elpa-package-install-directory 'visual-regexp-steroids))))
  133. )))
  134. (add-hook 'git-commit-setup-hook 'git-commit-turn-on-flyspell)
  135. (add-hook 'before-save-hook 'delete-trailing-whitespace)
  136. ;; --------------------------------------
  137. (load-theme 'dracula t)
  138. (global-linum-mode t) ;; enable line numbers globally
  139. ;; PYTHON CONFIGURATION
  140. ;; --------------------------------------
  141. (elpy-enable)
  142. ;;(debug-on-variable-change 'python-check-command)
  143. ;; (elpy-use-ipython)
  144. ;; use flycheck not flymake with elpy
  145. (when (require 'flycheck nil t)
  146. (setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
  147. (add-hook 'elpy-mode-hook 'flycheck-mode))
  148. ;; enable py-autopep8 formatting on save
  149. (require 'py-autopep8)
  150. (defun python-mode-keys ()
  151. "Modify python-mode local key map"
  152. (local-set-key (kbd "C-c C-p") 'py-autopep8))
  153. (add-hook 'python-mode-hook 'python-mode-keys)
  154. (add-hook 'elpy-mode-hook 'py-autopep8-enable-on-save)
  155. (setq elpy-syntax-check-command python-check-command)
  156. ;; init.el ends here
  157. (custom-set-variables
  158. ;; custom-set-variables was added by Custom.
  159. ;; If you edit it by hand, you could mess it up, so be careful.
  160. ;; Your init file should contain only one such instance.
  161. ;; If there is more than one, they won't work right.
  162. '(custom-safe-themes
  163. (quote
  164. ("274fa62b00d732d093fc3f120aca1b31a6bb484492f31081c1814a858e25c72e" default)))
  165. '(package-selected-packages
  166. (quote
  167. (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))))
  168. (custom-set-faces
  169. ;; custom-set-faces was added by Custom.
  170. ;; If you edit it by hand, you could mess it up, so be careful.
  171. ;; Your init file should contain only one such instance.
  172. ;; If there is more than one, they won't work right.
  173. '(default ((t (:family "Roboto Mono" :foundry "outline" :slant normal :weight normal :height 113 :width normal)))))