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.

180 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
  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 g") 'magit-status)
  83. (setq inhibit-startup-screen t)
  84. ;; (setq vc-handled-backends nil)
  85. ;; use external ls
  86. (setq ls-lisp-use-insert-directory-program t)
  87. (let ((backup-dir (concat user-emacs-directory "backup"))
  88. (auto-save-dir (concat user-emacs-directory "autosave"))
  89. )
  90. (if (not (file-directory-p backup-dir))
  91. (make-directory backup-dir))
  92. (if (not(file-directory-p auto-save-dir))
  93. (make-directory auto-save-dir)
  94. )
  95. (setq backup-directory-alist
  96. `((".*" . , backup-dir)))
  97. (setq auto-save-file-name-transforms
  98. `((".*" , (concat auto-save-dir "/") t))))
  99. (cond
  100. ;; Windows fixes
  101. ((string-equal system-type "windows-nt")
  102. (progn
  103. (defun quote-exe (path)
  104. (w32-short-file-name path))
  105. (defun start-external-shell ()
  106. (interactive)
  107. (start-process-shell-command (format "cmd(%s)" default-directory) nil "start default.bat"))
  108. (global-set-key (kbd "C-S-C") 'start-external-shell)
  109. (setq insert-directory-program "C:/Program Files/git/usr/bin/ls.exe")
  110. (setq find-program (quote-exe "C:/Program Files/git/usr/bin/find.exe"))
  111. (setq grep-program (quote-exe "C:/Program Files/git/usr/bin/grep.exe"))
  112. (setq python-shell-interpreter (quote-exe (executable-find "python")))
  113. (setq python-check-command (quote-exe (executable-find "flake8")))
  114. (setq delete-by-moving-to-trash t)
  115. (defun python-shell-interpreter-refresh ()
  116. (interactive)
  117. (setq python-shell-interpreter (quote-exe (executable-find "python"))))
  118. (add-hook 'python-django-project-root-hook 'python-shell-interpreter-refresh)
  119. ))
  120. ;; Linux-specific
  121. ((string-equal system-type "gnu/linux")
  122. (progn
  123. (setq python-shell-interpreter "python3")
  124. (setq elpy-rpc-python-command python-shell-interpreter)
  125. (defun get-elpa-package-install-directory (pkg)
  126. "Return the install directory of elpa PKG. Return nil if it is not found."
  127. (let ((elpa-dir package-user-dir))
  128. (when (file-exists-p elpa-dir)
  129. (let* ((pkg-match (concat "\\`" (symbol-name pkg) "-[0-9]+"))
  130. (dir (car (directory-files elpa-dir 'full pkg-match))))
  131. (when dir (file-name-as-directory dir))))))
  132. (setq vr/command-python
  133. (format "python3 %s" (expand-file-name "regexp.py" (get-elpa-package-install-directory 'visual-regexp-steroids))))
  134. )))
  135. (add-hook 'git-commit-setup-hook 'git-commit-turn-on-flyspell)
  136. (add-hook 'before-save-hook 'delete-trailing-whitespace)
  137. ;; --------------------------------------
  138. (load-theme 'dracula t)
  139. (global-linum-mode t) ;; enable line numbers globally
  140. ;; PYTHON CONFIGURATION
  141. ;; --------------------------------------
  142. (elpy-enable)
  143. ;;(debug-on-variable-change 'python-check-command)
  144. ;; (elpy-use-ipython)
  145. ;; use flycheck not flymake with elpy
  146. (when (require 'flycheck nil t)
  147. (setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
  148. (add-hook 'elpy-mode-hook 'flycheck-mode))
  149. (require 'blacken)
  150. (defun python-mode-keys ()
  151. "Modify python-mode local key map"
  152. (local-set-key (kbd "C-=") 'elpy-goto-assignment))
  153. (add-hook 'python-mode-hook 'python-mode-keys)
  154. (add-hook 'elpy-mode-hook 'blacken-mode)
  155. (setq elpy-syntax-check-command python-check-command)
  156. ;; init.el ends here