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.

192 lines
6.4 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
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. ;; JavaScript
  46. (require 'js2-mode)
  47. (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  48. ;; Better imenu
  49. (add-hook 'js2-mode-hook #'js2-imenu-extras-mode)
  50. (require 'js2-refactor)
  51. (require 'xref-js2)
  52. (add-hook 'js2-mode-hook #'js2-refactor-mode)
  53. (js2r-add-keybindings-with-prefix "C-c C-r")
  54. (define-key js2-mode-map (kbd "C-k") #'js2r-kill)
  55. ;; js-mode (which js2 is based on) binds "M-." which conflicts with xref, so
  56. ;; unbind it.
  57. (define-key js-mode-map (kbd "M-.") nil)
  58. (add-hook 'js2-mode-hook (lambda ()
  59. (add-hook 'xref-backend-functions #'xref-js2-xref-backend nil t)))
  60. (define-key js2-mode-map (kbd "C-k") #'js2r-kill)
  61. ;; Web-mode
  62. (require 'web-mode)
  63. (add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode))
  64. (add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode))
  65. (add-to-list 'auto-mode-alist '("\\.[agj]sp\\'" . web-mode))
  66. (add-to-list 'auto-mode-alist '("\\.as[cp]x\\'" . web-mode))
  67. (add-to-list 'auto-mode-alist '("\\.erb\\'" . web-mode))
  68. (add-to-list 'auto-mode-alist '("\\.mustache\\'" . web-mode))
  69. (add-to-list 'auto-mode-alist '("\\.djhtml\\'" . web-mode))
  70. (add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
  71. ;; Custom
  72. (setq dired-listing-switches "-alh")
  73. (defun duplicate-line()
  74. (interactive)
  75. (move-beginning-of-line 1)
  76. (kill-line)
  77. (yank)
  78. (open-line 1)
  79. (next-line 1)
  80. (yank))
  81. (global-set-key (kbd "C-c C-d") 'duplicate-line)
  82. (require 'recentf)
  83. (recentf-mode 1)
  84. (global-set-key (kbd "C-<tab>") 'recentf-open-files)
  85. (global-set-key (kbd "C-x g") 'magit-status)
  86. (setq inhibit-startup-screen t)
  87. ;; (setq vc-handled-backends nil)
  88. ;; use external ls
  89. (setq ls-lisp-use-insert-directory-program t)
  90. (cond
  91. ;; Windows fixes
  92. ((string-equal system-type "windows-nt")
  93. (progn
  94. (defun quote-exe (path)
  95. (w32-short-file-name path))
  96. (defun start-external-shell ()
  97. (interactive)
  98. (start-process-shell-command (format "cmd(%s)" default-directory) nil "start default.bat"))
  99. (global-set-key (kbd "C-S-C") 'start-external-shell)
  100. (setq insert-directory-program "C:/Program Files/git/usr/bin/ls.exe")
  101. (setq find-program (quote-exe "C:/Program Files/git/usr/bin/find.exe"))
  102. (setq grep-program (quote-exe "C:/Program Files/git/usr/bin/grep.exe"))
  103. (setq python-shell-interpreter (quote-exe (executable-find "python")))
  104. (setq python-check-command (quote-exe (executable-find "flake8")))
  105. (setq backup-directory-alist
  106. `((".*" . ,temporary-file-directory)))
  107. (setq auto-save-file-name-transforms
  108. `((".*" ,temporary-file-directory t)))
  109. (setq delete-by-moving-to-trash t)
  110. ))
  111. ;; Linux-specific
  112. ((string-equal system-type "gnu/linux")
  113. (progn
  114. (setq python-shell-interpreter "python3")
  115. (setq elpy-rpc-python-command python-shell-interpreter)
  116. )))
  117. (add-hook 'git-commit-setup-hook 'git-commit-turn-on-flyspell)
  118. (add-hook 'before-save-hook 'delete-trailing-whitespace)
  119. ;; --------------------------------------
  120. ;; (setq inhibit-startup-message t) ;; hide the startup message
  121. ;; (load-theme 'material t) ;; load material theme
  122. (load-theme 'dracula t)
  123. (global-linum-mode t) ;; enable line numbers globally
  124. ;; PYTHON CONFIGURATION
  125. ;; --------------------------------------
  126. (elpy-enable)
  127. ;;(debug-on-variable-change 'python-check-command)
  128. ;; (elpy-use-ipython)
  129. ;; use flycheck not flymake with elpy
  130. (when (require 'flycheck nil t)
  131. (setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
  132. (add-hook 'elpy-mode-hook 'flycheck-mode))
  133. ;; enable py-autopep8 formatting on save
  134. (require 'py-autopep8)
  135. (defun python-mode-keys ()
  136. "Modify python-mode local key map"
  137. (local-set-key (kbd "C-c C-p") 'py-autopep8))
  138. (add-hook 'python-mode-hook 'python-mode-keys)
  139. (add-hook 'elpy-mode-hook 'py-autopep8-enable-on-save)
  140. ;;(setq python-flymake-command "\"c:/Program Files/Python37/Scripts/flake8.exe\"")
  141. ;;(setq python-check-command "\"c:/Program Files/Python37/Scripts/flake8.exe\"")
  142. ;; (setq elpy-rpc-python-command "\"c:/Program Files/Python37/pythonw.exe\" ")
  143. (setq elpy-syntax-check-command python-check-command)
  144. ;; init.el ends here
  145. (custom-set-variables
  146. ;; custom-set-variables was added by Custom.
  147. ;; If you edit it by hand, you could mess it up, so be careful.
  148. ;; Your init file should contain only one such instance.
  149. ;; If there is more than one, they won't work right.
  150. '(custom-safe-themes
  151. (quote
  152. ("274fa62b00d732d093fc3f120aca1b31a6bb484492f31081c1814a858e25c72e" default)))
  153. '(package-selected-packages
  154. (quote
  155. (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))))
  156. (custom-set-faces
  157. ;; custom-set-faces was added by Custom.
  158. ;; If you edit it by hand, you could mess it up, so be careful.
  159. ;; Your init file should contain only one such instance.
  160. ;; If there is more than one, they won't work right.
  161. '(default ((t (:family "Roboto Mono" :foundry "outline" :slant normal :weight normal :height 113 :width normal)))))
  162. ;; Monkey patch
  163. ;;(defun quote-exe (path)
  164. ;; (if (string-match-p (regexp-quote " ") path)
  165. ;; (shell-quote-argument path)
  166. ;; path))
  167. ;;(defun quote-exe (path)
  168. ;; (replace-regexp-in-string " " "\\ " path)
  169. ;;
  170. ;;(advice-add 'executable-find :filter-return #'quote-exe)