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.

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