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.

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