init.el 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. ;;; init.el --- Emacs Configuration -*- lexical-binding: t -*-
  2. ;;; Commentary:
  3. ;; This config start here
  4. ;;; Code:
  5. (setq network-security-level 'high)
  6. (setq package-archives
  7. '(("gnu" . "http://elpa.gnu.org/packages/")
  8. ("melpa" . "http://melpa.org/packages/")
  9. ("org" . "https://orgmode.org/elpa/"))
  10. package-archive-priorities
  11. '(("melpa" . 10)
  12. ("gnu" . 5)
  13. ("org" . 0)))
  14. (setq load-prefer-newer t)
  15. (package-initialize)
  16. (when (not package-archive-contents)
  17. (package-refresh-contents))
  18. (unless (package-installed-p 'use-package)
  19. (package-install 'use-package))
  20. (eval-when-compile
  21. (require 'use-package))
  22. (use-package diminish :ensure t)
  23. (use-package bind-key :ensure t)
  24. (setq user-full-name "Edison Ibáñez"
  25. user-mail-address "arkhan@disroot.org")
  26. (tool-bar-mode -1)
  27. (scroll-bar-mode -1)
  28. (menu-bar-mode -1)
  29. (blink-cursor-mode 0)
  30. (setq inhibit-startup-screen t
  31. initial-scratch-message nil
  32. visible-bell t
  33. apropos-do-all t
  34. large-file-warning-threshold 100000000)
  35. (fset 'yes-or-no-p 'y-or-n-p)
  36. (toggle-indicate-empty-lines)
  37. (delete-selection-mode)
  38. (blink-cursor-mode -1)
  39. (defalias 'list-buffers 'ibuffer)
  40. (set-terminal-coding-system 'utf-8)
  41. (set-keyboard-coding-system 'utf-8)
  42. (set-language-environment 'utf-8)
  43. (set-selection-coding-system 'utf-8)
  44. (setq locale-coding-system 'utf-8)
  45. (prefer-coding-system 'utf-8)
  46. (set-input-method nil)
  47. (setq auto-save-default nil
  48. auto-save-list-file-prefix nil
  49. make-backup-files nil)
  50. (setq-default indent-tabs-mode nil
  51. default-tab-width 4
  52. c-basic-offset 4)
  53. (setq show-paren-delay 0)
  54. (show-paren-mode t)
  55. (global-hl-line-mode 1)
  56. (column-number-mode t)
  57. (setq size-indication-mode t)
  58. (which-function-mode 1)
  59. (setq select-enable-primary t)
  60. (global-set-key "\C-w" 'backward-kill-word)
  61. (global-set-key "\C-x\C-k" 'kill-region)
  62. (global-set-key "\C-c\C-k" 'kill-region)
  63. (add-hook 'text-mode-hook 'turn-on-auto-fill)
  64. (add-hook 'text-mode-hook
  65. '(lambda() (set-fill-column 80)))
  66. (setq browse-url-browser-function 'browse-url-generic
  67. browse-url-generic-program "firefox")
  68. (use-package flx :ensure t)
  69. (use-package smex :ensure t)
  70. (use-package ivy
  71. :ensure t
  72. :diminish ivy-mode
  73. :bind (:map ivy-mode-map
  74. ("C-'" . ivy-avy))
  75. :config
  76. (setq ivy-wrap t
  77. ivy-virtual-abbreviate 'full
  78. ivy-use-virtual-buffers t
  79. ivy-use-selectable-prompt t
  80. ivy-count-format "(%d/%d) "
  81. ivy-re-builders-alist
  82. '((read-file-name-internal . ivy--regex-fuzzy)
  83. (t . ivy--regex-plus))
  84. ivy-on-del-error-function nil
  85. ivy-initial-inputs-alist nil)
  86. (ivy-mode 1))
  87. (setq confirm-nonexistent-file-or-buffer t)
  88. (use-package swiper
  89. :bind* (("C-s" . swiper)
  90. ("C-r" . swiper)
  91. ("C-M-s" . swiper-all))
  92. :bind (:map read-expression-map
  93. ("C-r" . counsel-expression-history)))
  94. (use-package counsel
  95. :bind (("M-x" . counsel-M-x)
  96. ("C-c b" . counsel-imenu)
  97. ("C-x C-f" . counsel-find-file)
  98. ("C-x C-r" . counsel-rg)
  99. ("C-h f" . counsel-describe-function)
  100. ("C-h v" . counsel-describe-variable)
  101. ("C-h b" . counsel-descbinds)
  102. ("M-y" . counsel-yank-pop)
  103. ("M-SPC" . counsel-shell-history))
  104. :config
  105. (setq counsel-find-file-at-point t
  106. counsel-rg-base-command "rg -uuu -S --no-heading --line-number --color never %s ."))
  107. (use-package ujelly-theme
  108. :ensure t
  109. :config (load-theme 'ujelly t))
  110. (set-face-attribute 'default nil :family "DejaVu Sans Mono" :height 90)
  111. (set-fontset-font "fontset-default" nil
  112. (font-spec :size 20 :name "Symbola"))
  113. (setq line-number-mode t
  114. column-number-mode t)
  115. (use-package smart-mode-line
  116. :ensure t
  117. :config (setq sml/no-confirm-load-theme t
  118. sml/theme 'dark
  119. sml/vc-mode-show-backend t
  120. sml/mode-width 'full
  121. sml/shorten-modes t)
  122. (sml/setup))
  123. (use-package comment-dwim-2
  124. :ensure t
  125. :bind* ("M-;" . comment-dwim-2))
  126. (use-package company
  127. :ensure t
  128. :init
  129. (setq company-backends '((company-files
  130. company-keywords
  131. company-capf
  132. company-yasnippet)
  133. (company-abbrev company-dabbrev)))
  134. (setq company-auto-complete nil
  135. company-echo-delay 0
  136. company-idle-delay 0.2
  137. company-minimum-prefix-length 1
  138. company-tooltip-align-annotations t
  139. company-tooltip-limit 20
  140. company-transformers '(company-sort-by-occurrence))
  141. (global-company-mode))
  142. (defun company-mode/backend-with-yas (backend)
  143. (if (or (and (listp backend) (member 'company-yasnippet backend)))
  144. backend
  145. (append (if (consp backend) backend (list backend))
  146. '(:with company-yasnippet))))
  147. (add-hook 'company-mode-hook (lambda () (setq company-backends (mapcar #'company-mode/backend-with-yas company-backends))) t)
  148. (defun add-pcomplete-to-capf ()
  149. (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t))
  150. (add-hook 'org-mode-hook #'add-pcomplete-to-capf)
  151. (use-package company-quickhelp
  152. :ensure t
  153. :after company
  154. :config (company-quickhelp-mode 1))
  155. (use-package fill-column-indicator
  156. :ensure t
  157. :commands (fci-mode)
  158. :init (setq fci-rule-width 5
  159. fci-rule-column 79))
  160. (use-package flycheck
  161. :ensure t
  162. :bind (("C-c e n" . flycheck-next-error)
  163. ("C-c e p" . flycheck-previous-error))
  164. :config
  165. (add-hook 'after-init-hook #'global-flycheck-mode)
  166. (setq-default flycheck-disabled-checkers
  167. (append flycheck-disabled-checkers
  168. '(javascript-jshint)))
  169. (setq-default flycheck-disabled-checkers
  170. (append flycheck-disabled-checkers
  171. '(json-jsonlist))))
  172. (setq vc-follows-symlinks t
  173. find-file-visit-truename t
  174. vc-handled-backends nil)
  175. (use-package magit
  176. :ensure t
  177. :bind (("C-x g c" . magit-commit)
  178. ("C-x g e" . magit-ediff-resolve)
  179. ("C-x g g" . magit-grep)
  180. ("C-x g l" . magit-file-log)
  181. ("C-x g p" . magit-push)
  182. ("C-x g r" . magit-rebase-interactive)
  183. ("C-x g s" . magit-status)
  184. ("C-x g u" . magit-pull)
  185. ("C-x g x" . magit-checkout))
  186. :init
  187. (progn
  188. (setq magit-git-executable "tg")
  189. (delete 'Git vc-handled-backends)
  190. (defadvice magit-status (around magit-fullscreen activate)
  191. (window-configuration-to-register :magit-fullscreen)
  192. ad-do-it
  193. (delete-other-windows))
  194. (defadvice git-commit-commit (after delete-window activate)
  195. (delete-window))
  196. (defadvice git-commit-abort (after delete-window activate)
  197. (delete-window))
  198. (defun magit-commit-mode-init ()
  199. (when (looking-at "\n")
  200. (open-line 1))))
  201. :config
  202. (progn
  203. (defadvice magit-quit-window (around magit-restore-screen activate)
  204. (let ((current-mode major-mode))
  205. ad-do-it
  206. (when (eq 'magit-status-mode current-mode)
  207. (jump-to-register :magit-fullscreen))))
  208. (defun magit-maybe-commit (&optional show-options)
  209. "Runs magit-commit unless prefix is passed"
  210. (interactive "P")
  211. (if show-options
  212. (magit-key-mode-popup-committing)
  213. (magit-commit)))
  214. (define-key magit-mode-map "c" 'magit-maybe-commit)
  215. (setq magit-completing-read-function 'ivy-completing-read
  216. magit-default-tracking-name-function 'magit-default-tracking-name-branch-only
  217. magit-status-buffer-switch-function 'switch-to-buffer
  218. magit-diff-refine-hunk t
  219. magit-rewrite-inclusive 'ask
  220. magit-process-find-password-functions '(magit-process-password-auth-source)
  221. magit-save-some-buffers t
  222. magit-process-popup-time 10
  223. magit-set-upstream-on-push 'askifnotset
  224. magit-refs-show-commit-count 'all
  225. magit-log-buffer-file-locket t)))
  226. (use-package git-gutter
  227. :ensure t
  228. :defer 1
  229. :bind (("C-x C-g" . git-gutter)
  230. ("C-x v =" . git-gutter:popup-hunk)
  231. ("C-x p" . git-gutter:previous-hunk)
  232. ("C-x n" . git-gutter:next-hunk)
  233. ("C-x v s" . git-gutter:stage-hunk)
  234. ("C-x v r" . git-gutter:revert-hunk)
  235. ("C-x v SPC" . git-gutter:mark-hunk))
  236. :config
  237. (if (display-graphic-p)
  238. (use-package git-gutter-fringe
  239. :ensure t))
  240. (global-git-gutter-mode t)
  241. (setq-default fringes-outside-margins t)
  242. (setq indicate-empty-lines nil)
  243. (setq git-gutter:lighter ""
  244. git-gutter:handled-backends '(git hg bzr svn))
  245. (set-face-foreground 'git-gutter:modified "purple")
  246. (set-face-foreground 'git-gutter:added "green")
  247. (set-face-foreground 'git-gutter:deleted "red"))
  248. (use-package gitconfig-mode
  249. :ensure t
  250. :mode ("/\\.?git/?config$"
  251. "/\\.gitmodules$")
  252. :init (add-hook 'gitconfig-mode-hook 'flyspell-mode))
  253. (use-package gitignore-mode
  254. :ensure t
  255. :mode ("/\\.gitignore$"
  256. "/\\.git/info/exclude$"
  257. "/git/ignore$"))
  258. (use-package gitattributes-mode
  259. :ensure t
  260. :defer t)
  261. (use-package git-timemachine
  262. :ensure t
  263. :commands git-timemachine
  264. :bind (:map git-timemachine-mode
  265. ("c" . git-timemachine-show-current-revision)
  266. ("b" . git-timemachine-switch-branch)))
  267. (use-package smerge-mode
  268. :ensure t
  269. :config
  270. (defun enable-smerge-maybe ()
  271. (when (and buffer-file-name (vc-backend buffer-file-name))
  272. (save-excursion
  273. (goto-char (point-min))
  274. (when (re-search-forward "^<<<<<<< " nil t)
  275. (smerge-mode +1)))))
  276. (add-hook 'buffer-list-update-hook #'enable-smerge-maybe))
  277. (use-package iedit
  278. :ensure t)
  279. (electric-pair-mode 1)
  280. (use-package paren
  281. :init (show-paren-mode)
  282. :config
  283. (set-face-background 'show-paren-match (face-background 'default))
  284. (set-face-foreground 'show-paren-match "#def")
  285. (set-face-attribute 'show-paren-match nil :weight 'extra-bold))
  286. (use-package smartparens
  287. :ensure t
  288. :commands
  289. (smartparens-mode
  290. smartparens-strict-mode)
  291. :bind
  292. (:map smartparens-strict-mode-map
  293. ("C-}" . sp-forward-slurp-sexp)
  294. ("M-s" . sp-backward-unwrap-sexp)
  295. ("C-c [" . sp-select-next-thing)
  296. ("C-c ]" . sp-select-next-thing-exchange))
  297. :config
  298. (require 'smartparens-config))
  299. (use-package rainbow-delimiters
  300. :ensure t
  301. :config
  302. (add-hook 'prog-mode-hook 'rainbow-delimiters-mode))
  303. (use-package projectile
  304. :ensure t
  305. :diminish projectile-mode
  306. :config
  307. (setq projectile-file-exists-remote-cache-expire (* 10 60)
  308. projectile-indexing-method 'alien
  309. projectile-enable-caching t
  310. projectile-completion-system 'ivy)
  311. (projectile-mode))
  312. (use-package counsel-projectile
  313. :ensure t
  314. :bind ("C-x r R" . counsel-projectile-rg)
  315. :config
  316. (setq counsel-projectile-rg-options-history (list "-uuu"))
  317. (add-hook 'text-mode-hook 'counsel-projectile-mode)
  318. (add-hook 'prog-mode-hook 'counsel-projectile-mode))
  319. (use-package term-projectile
  320. :ensure t)
  321. (use-package rg
  322. :ensure t
  323. :config (setq rg-command-line-flags (list "-uuu")))
  324. (use-package rainbow-mode
  325. :ensure t
  326. :diminish rainbow-mode
  327. :config
  328. (add-hook 'prog-mode-hook 'rainbow-mode)
  329. (add-hook 'conf-mode-hook 'rainbow-mode))
  330. (use-package terminal-here
  331. :ensure t
  332. :bind (("C-<f5>" . terminal-here-launch)
  333. ("C-<f6>" . terminal-here-project-launch)))
  334. (use-package undo-tree
  335. :ensure t
  336. :diminish undo-tree-mode
  337. :init
  338. (progn
  339. (global-undo-tree-mode)
  340. (setq undo-tree-auto-save-history t
  341. undo-tree-visualizer-timestamps t
  342. undo-tree-visualizer-diff t))
  343. (add-hook 'write-file-functions #'undo-tree-save-history-hook)
  344. (add-hook 'find-file-hook #'undo-tree-load-history-hook))
  345. (use-package yasnippet
  346. :ensure t
  347. :defer 2
  348. :config (yas-global-mode))
  349. (use-package yasnippet-snippets
  350. :ensure t)
  351. (use-package elpy
  352. :ensure t
  353. :diminish elpy-mode
  354. :config
  355. (elpy-enable)
  356. (setq elpy-rpc-backend "jedi"
  357. elpy-shell-echo-input nil
  358. elpy-modules (dolist (elem
  359. '(elpy-module-sane-defaults
  360. elpy-module-company
  361. elpy-module-eldoc
  362. elpy-module-highlight-indentation
  363. elpy-module-pyvenv
  364. elpy-module-yasnippet))))
  365. (add-to-list 'company-backends 'elpy-company-backend)
  366. (require 'smartparens-python)
  367. (with-eval-after-load 'python
  368. (defun python-shell-completion-native-try ()
  369. "Return non-nil if can trigger native completion."
  370. (let ((python-shell-completion-native-enable t)
  371. (python-shell-completion-native-output-timeout
  372. python-shell-completion-native-try-output-timeout))
  373. (python-shell-completion-native-get-completions
  374. (get-buffer-process (current-buffer))
  375. nil "_"))))
  376. (when (require 'flycheck nil t)
  377. (setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
  378. (add-hook 'elpy-mode-hook 'flycheck-mode)))
  379. (defun add-breakpoint ()
  380. "Add a break point"
  381. (interactive)
  382. (newline-and-indent)
  383. (insert "import pdb; pdb.set_trace()"))
  384. (define-key elpy-mode-map (kbd "C-c C-b") 'add-breakpoint)
  385. (use-package py-isort
  386. :ensure t
  387. :config
  388. (setq py-isort-options '("--lines=100"))
  389. (add-hook 'before-save-hook 'py-isort-before-save))
  390. (use-package pyvenv
  391. :config (defalias 'workon 'pyvenv-workon))
  392. (use-package auto-virtualenv
  393. :ensure t
  394. :config
  395. (add-hook 'elpy-mode-hook 'auto-virtualenv-set-virtualenv))
  396. (use-package virtualenvwrapper
  397. :ensure t
  398. :commands (venv-workon venv-deactivate
  399. venv-initialize-interactive-shells venv-initialize-eshell)
  400. :init
  401. (venv-initialize-interactive-shells)
  402. (venv-initialize-eshell)
  403. (setq venv-location "~/.virtualenvs")
  404. :config
  405. (add-hook 'venv-postmkvirtualenv-hook
  406. (lambda () (shell-command "pip install jedi rope
  407. isort importmagic autopep8 yapf
  408. flake8 virtualenvwrapper"))))
  409. (use-package pyimport :ensure t)
  410. (use-package pippel :ensure t)
  411. (use-package pip-requirements :ensure t)