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.

186 lines
6.3 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
  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. ))
  106. ;; Linux-specific
  107. ((string-equal system-type "gnu/linux")
  108. (progn
  109. (setq python-shell-interpreter "python3")
  110. (setq elpy-rpc-python-command python-shell-interpreter)
  111. )))
  112. (add-hook 'git-commit-setup-hook 'git-commit-turn-on-flyspell)
  113. (add-hook 'before-save-hook 'delete-trailing-whitespace)
  114. ;; --------------------------------------
  115. ; (setq inhibit-startup-message t) ;; hide the startup message
  116. ; (load-theme 'material t) ;; load material theme
  117. (load-theme 'dracula t)
  118. (global-linum-mode t) ;; enable line numbers globally
  119. ;; PYTHON CONFIGURATION
  120. ;; --------------------------------------
  121. (elpy-enable)
  122. ;(debug-on-variable-change 'python-check-command)
  123. ; (elpy-use-ipython)
  124. ;; use flycheck not flymake with elpy
  125. (when (require 'flycheck nil t)
  126. (setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
  127. (add-hook 'elpy-mode-hook 'flycheck-mode))
  128. ;; enable py-autopep8 formatting on save
  129. (require 'py-autopep8)
  130. (defun python-mode-keys ()
  131. "Modify python-mode local key map"
  132. (local-set-key (kbd "C-c C-p") 'py-autopep8))
  133. (add-hook 'python-mode-hook 'python-mode-keys)
  134. (add-hook 'elpy-mode-hook 'py-autopep8-enable-on-save)
  135. ;(setq python-flymake-command "\"c:/Program Files/Python37/Scripts/flake8.exe\"")
  136. ;(setq python-check-command "\"c:/Program Files/Python37/Scripts/flake8.exe\"")
  137. ; (setq elpy-rpc-python-command "\"c:/Program Files/Python37/pythonw.exe\" ")
  138. (setq elpy-syntax-check-command python-check-command)
  139. ;; init.el ends here
  140. (custom-set-variables
  141. ;; custom-set-variables was added by Custom.
  142. ;; If you edit it by hand, you could mess it up, so be careful.
  143. ;; Your init file should contain only one such instance.
  144. ;; If there is more than one, they won't work right.
  145. '(custom-safe-themes
  146. (quote
  147. ("274fa62b00d732d093fc3f120aca1b31a6bb484492f31081c1814a858e25c72e" default)))
  148. '(package-selected-packages
  149. (quote
  150. (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))))
  151. (custom-set-faces
  152. ;; custom-set-faces was added by Custom.
  153. ;; If you edit it by hand, you could mess it up, so be careful.
  154. ;; Your init file should contain only one such instance.
  155. ;; If there is more than one, they won't work right.
  156. '(default ((t (:family "Roboto Mono" :foundry "outline" :slant normal :weight normal :height 113 :width normal)))))
  157. ;; Monkey patch
  158. ;(defun quote-exe (path)
  159. ; (if (string-match-p (regexp-quote " ") path)
  160. ; (shell-quote-argument path)
  161. ; path))
  162. ;(defun quote-exe (path)
  163. ; (replace-regexp-in-string " " "\\ " path)
  164. ;
  165. ;(advice-add 'executable-find :filter-return #'quote-exe)