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.

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