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.

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