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.

759 lines
25 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. * Editing
  2. ** Enable disabled commands
  3. #+begin_src emacs-lisp
  4. (put 'set-goal-column 'disabled nil)
  5. (put 'narrow-to-region 'disabled nil)
  6. (put 'upcase-region 'disabled nil)
  7. (put 'downcase-region 'disabled nil)
  8. (put 'scroll-left 'disabled nil)
  9. (put 'erase-buffer 'disabled nil)
  10. #+end_src
  11. ** IEdit mode
  12. #+begin_src emacs-lisp
  13. (use-package iedit
  14. :bind ("C-;" . iedit-mode))
  15. #+end_src
  16. ** Imenu
  17. #+begin_src emacs-lisp
  18. (use-package imenu
  19. :bind
  20. ("C-S-s" . imenu))
  21. #+end_src
  22. ** Spellcheck
  23. #+begin_src emacs-lisp
  24. (global-set-key (kbd "C-!") 'ispell-buffer)
  25. #+end_src
  26. ** String inflection
  27. #+begin_src emacs-lisp
  28. (use-package string-inflection
  29. :bind ("C-M-," . my-string-inflection-cycle-auto)
  30. :config
  31. (defun my-string-inflection-cycle-auto ()
  32. "switching by major-mode"
  33. (interactive)
  34. (cond
  35. ;; for emacs-lisp-mode
  36. ((eq major-mode 'emacs-lisp-mode)
  37. (string-inflection-all-cycle))
  38. ;; for python
  39. ((eq major-mode 'python-mode)
  40. (string-inflection-python-style-cycle))
  41. ;; for java
  42. ((eq major-mode 'java-mode)
  43. (string-inflection-java-style-cycle))
  44. (t
  45. ;; default
  46. (string-inflection-ruby-style-cycle)))))
  47. #+end_src
  48. ** Undo tree
  49. #+begin_src emacs-lisp
  50. (use-package undo-tree
  51. :diminish
  52. :config
  53. (global-undo-tree-mode))
  54. #+end_src
  55. * Added functionality
  56. ** Kill this buffer
  57. #+begin_src emacs-lisp
  58. (defun rlbr/kill-this-buffer ()
  59. (interactive)
  60. (kill-buffer (current-buffer)))
  61. #+end_src
  62. ** Low memeory check
  63. #+begin_src emacs-lisp
  64. (defun rlbr/high-mem (&optional threshold)
  65. (let ((threshold (or threshold (expt 1024 2)))))
  66. (>= (nth 1 (memory-info))
  67. threshold))
  68. #+end_src
  69. ** Multiline sexp with symbol
  70. Jump to symbol, go up list, lispy-multiline. Great for diff-friendly custom
  71. #+begin_src emacs-lisp
  72. (require 'isearch)
  73. (require 'lispy)
  74. (defun rlbr/multiline-sexp-with-symbol (symbol-name)
  75. (save-excursion
  76. (beginning-of-buffer)
  77. (search-forward-regexp (isearch-symbol-regexp symbol-name))
  78. (backward-up-list)
  79. (lispy-alt-multiline)))
  80. #+end_src
  81. ** Output matches
  82. Run command for each matching exe and see if output-p is true when fed the command output
  83. #+begin_src emacs-lisp
  84. (defun rlbr/output-matches (output-matches-p exe args)
  85. "locate the executable whose output satisfies output-matches-p when fed args and return the full-path"
  86. (let ((exec-path exec-path)
  87. (output)
  88. (bad)
  89. (command-output)
  90. (current-exe)
  91. (failed))
  92. (while (not (or output failed))
  93. (setq current-exe
  94. (executable-find exe))
  95. (if current-exe
  96. (progn
  97. (setq command-output
  98. (shell-command-to-string (format "%s %s" (rlbr/quote-exe current-exe)
  99. args)))
  100. (if (funcall output-matches-p command-output)
  101. (setq output current-exe)
  102. (progn
  103. (setq bad
  104. (replace-regexp-in-string "/$" "" (file-name-directory current-exe)))
  105. (setq exec-path
  106. (seq-filter (lambda (item)
  107. (not (rlbr/case-insensitive-match item bad)))
  108. exec-path)))))
  109. (setq failed t)))
  110. output))
  111. #+end_src
  112. ** Prefix arg overload
  113. #+begin_src emacs-lisp
  114. (defun rlbr/prefix-arg-overload (func alt &optional alt-args)
  115. (let ((advice `(lambda (func &optional arg)
  116. (interactive "P")
  117. (if arg (apply (quote ,alt)
  118. ,alt-args)
  119. (apply func nil)))))
  120. (advice-add func :around advice)
  121. advice))
  122. #+end_src
  123. ** Save buffer-output to file
  124. This handy function is a customized ripoff of custom-save-all
  125. #+begin_src emacs-lisp
  126. (defun rlbr/save-buffer-func-to-file (visit-file func args)
  127. "Rip off of custom-save-all"
  128. (let* ((filename visit-file)
  129. (recentf-exclude (if recentf-mode (append `(,(concat "\\`" (regexp-quote (recentf-expand-file-name visit-file))
  130. "\\'")
  131. ,(concat "\\`" (regexp-quote (file-truename (recentf-expand-file-name visit-file)))
  132. "\\'"))
  133. recentf-exclude)))
  134. (old-buffer (find-buffer-visiting filename))
  135. old-buffer-name)
  136. (with-current-buffer (let ((find-file-visit-truename t))
  137. (or old-buffer (let ((delay-mode-hooks t))
  138. (find-file-noselect filename))))
  139. (when old-buffer (setq old-buffer-name (buffer-file-name))
  140. (set-visited-file-name (file-chase-links filename)))
  141. (unless (eq major-mode 'emacs-lisp-mode)
  142. (delay-mode-hooks (emacs-lisp-mode)))
  143. (let ((inhibit-read-only t)
  144. (print-length nil)
  145. (print-level nil))
  146. (apply func args))
  147. (let ((file-precious-flag t))
  148. (save-buffer))
  149. (if old-buffer (progn (set-visited-file-name old-buffer-name)
  150. (set-buffer-modified-p nil))
  151. (kill-buffer (current-buffer))))))
  152. #+end_src
  153. * Save/load
  154. ** Backup/auto-save
  155. #+begin_src emacs-lisp
  156. (let ((backup-dir "~/.emacs.d/backup")
  157. (auto-save-dir "~/.emacs.d/autosave"))
  158. (if (not (file-directory-p backup-dir))
  159. (make-directory backup-dir))
  160. (if (not (file-directory-p
  161. auto-save-dir))
  162. (make-directory auto-save-dir)))
  163. #+end_src
  164. ** On save
  165. #+begin_src emacs-lisp
  166. (add-hook 'before-save-hook 'delete-trailing-whitespace)
  167. #+end_src
  168. ** Recent files mode
  169. #+begin_src emacs-lisp
  170. (use-package recentf
  171. :config
  172. (recentf-mode 1))
  173. #+end_src
  174. * Platform dependent
  175. ** Windows
  176. #+begin_src emacs-lisp
  177. (when (string-equal system-type "windows-nt")
  178. (progn (defun rlbr/quote-exe (path)
  179. (w32-short-file-name path))
  180. (defun rlbr/high-mem (&optional threshold) t)
  181. (defun rlbr/start-external-shell ()
  182. (interactive)
  183. (start-process-shell-command (format "cmd(%s)" default-directory)
  184. nil "start default.bat"))
  185. (global-set-key (kbd "C-S-C")
  186. 'rlbr/start-external-shell)
  187. (defun rlbr/start-windows-explorer-here ()
  188. (interactive)
  189. (start-process-shell-command "explorer" nil (format "explorer %s" (replace-regexp-in-string "/" (regexp-quote "\\")
  190. (expand-file-name default-directory)))))
  191. (global-set-key (kbd "C-S-E")
  192. 'rlbr/start-windows-explorer-here)
  193. (defun rlbr/case-insensitive-match (string1 string2)
  194. (apply 'string-equal (mapcar 'downcase (list string1 string2))))
  195. (let ((find)
  196. (grep)
  197. (ls))
  198. (progn (setq find (rlbr/output-matches (lambda (output)
  199. (string-equal ".\n" output))
  200. "find" "-maxdepth 0"))
  201. (if find (setq find-program (rlbr/quote-exe find)))
  202. (setq grep (rlbr/output-matches (lambda (output)
  203. (string-match "grep (\\w+ grep)" output))
  204. "grep" "-V"))
  205. (if grep (setq grep-program (rlbr/quote-exe grep)))
  206. (setq ls (rlbr/output-matches (lambda (output)
  207. (string-match "ls: .*'\\?/': No such file or directory" output))
  208. "ls" "?/"))
  209. (if ls (setq insert-directory-program (rlbr/quote-exe ls)))))))
  210. #+end_src
  211. * Tramp configuration
  212. ** Tramp append plist to connection properties
  213. #+begin_src emacs-lisp
  214. (use-package kv
  215. :config
  216. (defun rlbr/add-config-to-tramp (matches-regexp config-plist)
  217. (let ((config-alist (kvplist->alist config-plist)))
  218. (dolist (pair config-alist)
  219. (let ((config (list matches-regexp (car pair)
  220. (cdr pair))))
  221. (add-to-list 'tramp-connection-properties config))))))
  222. #+end_src
  223. ** Android
  224. #+begin_src emacs-lisp
  225. (use-package tramp
  226. :config
  227. (let ((android-config (let ((default-directory "/data/data/com.termux/files"))
  228. (list "tmpdir" (expand-file-name "home/temp/")
  229. "remote-shell" (expand-file-name "usr/bin/sh")
  230. "remote-process-environment" (append (list (concat "PREFIX=" default-directory "usr")) tramp-remote-process-environment)
  231. "remote-path" (append (mapcar 'expand-file-name '("home/.local/bin" "usr/bin" "usr/bin/applets")) '("/sbin" "/vendor/bin" "/system/sbin" "/system/bin" "/system/xbin"))))))
  232. (rlbr/add-config-to-tramp (rx "/" (or "scp" "ssh") (zero-or-one "x") ":" "termux" (zero-or-more any) ":") android-config)))
  233. #+end_src
  234. ** Dired rysnc
  235. #+begin_src emacs-lisp
  236. (use-package dired
  237. :bind
  238. (:map dired-mode-map
  239. ("C-c C-r" . dired-rsync))
  240. :config (use-package dired-rsync))
  241. #+end_src
  242. * Major modes
  243. ** Assembly
  244. #+begin_src emacs-lisp
  245. (use-package asm-mode
  246. :mode (rx ".sim" eos))
  247. #+end_src
  248. ** C
  249. #+begin_src emacs-lisp
  250. (use-package format-all
  251. :if (executable-find "clang-format")
  252. :hook (c-mode . format-all-mode))
  253. #+end_src
  254. ** Docker
  255. *** Docker
  256. *** Dockerfile
  257. *** Docker-compose
  258. #+begin_src emacs-lisp
  259. (use-package docker-compose-mode
  260. :config
  261. ;; auto-mode hack
  262. (let
  263. ((docker-compose-mode-regex (rassq 'docker-compose-mode auto-mode-alist)))
  264. (setq auto-mode-alist (cons docker-compose-mode-regex (rassq-delete-all 'docker-compose-mode auto-mode-alist))))
  265. :hook
  266. (docker-compose-mode . company-mode))
  267. #+end_src
  268. ** Java
  269. *** Meghanada
  270. #+begin_src emacs-lisp
  271. (use-package autodisass-java-bytecode
  272. :defer t)
  273. (use-package meghanada
  274. :if (rlbr/high-mem (* 512 1024))
  275. :defer t
  276. :init
  277. (add-hook 'java-mode-hook
  278. (lambda ()
  279. (meghanada-mode t)
  280. (flycheck-mode +1)
  281. (add-hook 'before-save-hook 'meghanada-code-beautify-before-save)))
  282. :config
  283. (setq indent-tabs-mode nil)
  284. (setq meghanada-server-remote-debug t)
  285. (setq meghanada-javac-xlint "-Xlint:all,-processing")
  286. (advice-add 'meghanada-code-beautify :around (lambda (old)
  287. (interactive)
  288. (let ((p (line-number-at-pos)))
  289. (apply old nil)
  290. (goto-line p)
  291. (reposition-window))))
  292. (defhydra hydra-meghanada (:hint nil :exit t)
  293. "
  294. ^Edit^ ^Tast or Task^
  295. ^^^^^^-------------------------------------------------------
  296. _f_: meghanada-compile-file _m_: meghanada-restart
  297. _c_: meghanada-compile-project _t_: meghanada-run-task
  298. _o_: meghanada-optimize-import _j_: meghanada-run-junit-test-case
  299. _s_: meghanada-switch-test-case _J_: meghanada-run-junit-class
  300. _v_: meghanada-local-variable _R_: meghanada-run-junit-recent
  301. _i_: meghanada-import-all _r_: meghanada-reference
  302. _g_: magit-status _T_: meghanada-typeinfo
  303. _q_: exit
  304. "
  305. ("f" meghanada-compile-file)
  306. ("m" meghanada-restart)
  307. ("c" meghanada-compile-project)
  308. ("o" meghanada-optimize-import)
  309. ("s" meghanada-switch-test-case)
  310. ("v" meghanada-local-variable)
  311. ("i" meghanada-import-all)
  312. ("g" magit-status)
  313. ("t" meghanada-run-task)
  314. ("T" meghanada-typeinfo)
  315. ("j" meghanada-run-junit-test-case)
  316. ("J" meghanada-run-junit-class)
  317. ("R" meghanada-run-junit-recent)
  318. ("r" meghanada-reference)
  319. ("q" exit)
  320. ("z" nil "leave"))
  321. :bind
  322. (:map meghanada-mode-map
  323. ("C-S-t" . meghanada-switch-testcase)
  324. ("M-RET" . meghanada-local-variable)
  325. ("M-r" . meghanada-reference)
  326. ("M-t" . meghanada-typeinfo)
  327. ("C-z" . hydra-meghanada/body))
  328. :commands
  329. (meghanada-mode))
  330. #+end_src
  331. ** JavaScript
  332. #+begin_src emacs-lisp
  333. (use-package js2-mode
  334. :mode "\\.js\\'"
  335. :hook ((js2-mode . js2-imenu-extras-mode)
  336. (js2-mode . (lambda () (add-hook 'xref-backend-functions #'xref-js2-xref-backend nil t))))
  337. :config
  338. (use-package js2-refactor
  339. :hook (js2-mode . js2-refactor-mode)
  340. :bind
  341. (:map js2-mode-map
  342. ("C-k" . js2r-kill))
  343. :config
  344. (js2r-add-keybindings-with-prefix "C-c C-r"))
  345. (use-package xref-js2
  346. :demand t)
  347. (define-key js-mode-map (kbd "M-.") nil)
  348. (defun rlbr/jump-to-definition ()
  349. "Jump to a definition."
  350. (interactive)
  351. (condition-case-unless-debug nil
  352. (js2-jump-to-definition)
  353. (error
  354. (progn
  355. (ignore-errors
  356. (xref-pop-marker-stack))
  357. (xref-find-definitions (xref-backend-identifier-at-point (xref-find-backend)))))))
  358. (define-key js-mode-map (kbd "M-.") #'rlbr/jump-to-definition))
  359. #+end_src
  360. ** JSON
  361. #+begin_src emacs-lisp
  362. (use-package json
  363. :config
  364. (use-package json-mode
  365. :bind (:map json-mode-map
  366. ("C-c p p" . json-pretty-print-buffer-ordered)))
  367. (use-package json-reformat
  368. :config
  369. (setq json-encoding-default-indentation (make-string json-reformat:indent-width ? ))))
  370. #+end_src
  371. ** Lisp
  372. *** Emacs lisp
  373. #+begin_src emacs-lisp
  374. (use-package elisp-mode
  375. :hook (emacs-lisp-mode . company-mode))
  376. #+end_src
  377. ** Magit
  378. #+begin_src emacs-lisp
  379. (use-package magit
  380. :bind (("C-x g" . magit-status))
  381. :config
  382. (use-package git-commit
  383. :hook (git-commit-setup . git-commit-turn-on-flyspell)))
  384. #+end_src
  385. ** Python
  386. *** Platform specific
  387. Set python command
  388. #+begin_src emacs-lisp
  389. (setq elpy-rpc-python-command
  390. (cond
  391. ((string-equal system-type "gnu/linux")
  392. "python3")
  393. ((string-equal system-type "windows-nt")
  394. "pythonw.exe")))
  395. #+end_src
  396. put executables in elpy-rpc-venv in path
  397. #+begin_src emacs-lisp
  398. (defun rlbr/elpy-append-to-path ()
  399. (setenv "PATH" (string-join (list (getenv "PATH")
  400. (let ((default-directory (elpy-rpc-get-or-create-virtualenv))
  401. (path-entry)
  402. (elpy-binpath))
  403. (if (string-equal system-type "windows-nt")
  404. (progn (setq elpy-binpath (expand-file-name "Scripts"))
  405. (setq path-entry (replace-regexp-in-string (regexp-quote "/")
  406. (regexp-quote "\\")
  407. elpy-binpath)))
  408. (setq elpy-binpath (expand-file-name "bin"))
  409. (setq path-entry elpy-binpath))
  410. (nconc exec-path (list elpy-binpath))
  411. elpy-binpath))
  412. path-separator)))
  413. #+end_src
  414. #+begin_src emacs-lisp
  415. (defun rlbr/fix-for-android ()
  416. (unless (= 0 (call-process elpy-rpc-python-command nil nil nil "-c" "import multiprocessing;multiprocessing.Pool()"))
  417. (setq python-check-command
  418. (string-join `(,python-check-command "--jobs=1") " "))))
  419. #+end_src
  420. *** Custom feature
  421. #+begin_src emacs-lisp
  422. (defun rlbr/join-venv-with-number (number-name)
  423. "Join a list with a name and a number"
  424. (let
  425. ((number (car number-name))
  426. (name (cdr number-name)))
  427. (if (= number 0)
  428. name
  429. (string-join (list name (number-to-string number))
  430. "~"))))
  431. (defun rlbr/split-venv-with-number (name-number)
  432. "Split a virtualenv name with either a ~ seperating the name and the number, or nothing"
  433. (let ((split-result (split-string name-number (regexp-quote "~")))
  434. (ret))
  435. (if (= 1 (length split-result))
  436. (progn
  437. (setq ret (car split-result))
  438. (push 0 ret))
  439. (progn
  440. (setq ret
  441. (string-join
  442. (butlast split-result)
  443. "~"))
  444. (push
  445. (string-to-number
  446. (car (last split-result)))
  447. ret)))
  448. ret))
  449. (defun rlbr/get-venv-name (&optional library-root)
  450. "Generate venv name based off of the base-name of the library root"
  451. (file-name-base
  452. (directory-file-name
  453. (if library-root
  454. library-root
  455. (elpy-library-root)))))
  456. (defun rlbr/handle-name-conflicts (venv-name)
  457. "Deal with potential name conflicts in venv"
  458. (let ((venv-conflicts)
  459. (venv-partition-name))
  460. (setq venv-partition-name (rlbr/split-venv-with-number venv-name))
  461. (setq venv-conflicts
  462. (seq-filter
  463. (lambda (item)
  464. (string-equal (cdr item)
  465. venv-name))
  466. (mapcar #'rlbr/split-venv-with-number (pyvenv-virtualenv-list))))
  467. (when venv-conflicts
  468. (setcar venv-partition-name (1+ (apply 'max (mapcar #'car venv-conflicts)))))
  469. (rlbr/join-venv-with-number venv-partition-name)))
  470. (require 'vc)
  471. (defun rlbr/setup-python-venv-dirlocals (&optional library-root venv-name)
  472. "Setup .dir-locals file in library root and tell vc system to ignore .dir-locals file"
  473. (let* ((library-root (if library-root
  474. library-root
  475. (elpy-library-root)))
  476. (venv-name (if venv-name venv-name (rlbr/get-venv-name library-root)))
  477. (default-directory library-root)
  478. (dir-locals-path (expand-file-name
  479. ".dir-locals.el")))
  480. (rlbr/save-buffer-func-to-file dir-locals-path 'add-dir-local-variable
  481. `(python-mode pyvenv-workon ,venv-name))
  482. (let ((vc-root (vc-find-root dir-locals-path ".git")))
  483. (when vc-root
  484. ;; If the directory is under version control
  485. (let ((vc-ignore-file (vc-call-backend 'Git 'find-ignore-file vc-root)))
  486. (if (apply 'string-equal (mapcar 'directory-file-name (mapcar 'file-truename (list vc-root library-root))))
  487. ;; If the vc-root is the same as the library root, don't ask any questions
  488. (vc-ignore ".dir-locals.el")
  489. ;; Otherwise prompt to ignore
  490. (when (y-or-n-p (format "Ignore .dir-locals.el in repo '%s' ?" vc-root))
  491. (vc-ignore ".dir-locals.el"))))))))
  492. (defun rlbr/get-python-executable ()
  493. (read-file-name "Python interpreter to use: " (file-name-directory (executable-find "python"))
  494. nil nil "python"))
  495. (defun emacs-default-venv ()
  496. (unless (member "emacs-default-venv" (pyvenv-virtualenv-list))
  497. (pyvenv-create "emacs-default-venv" (rlbr/get-python-executable)))
  498. "emacs-default-venv")
  499. (defun rlbr/init-python-venv-in-library-root (&optional library-root)
  500. "Prompt to either create one or use default" (let ((venv-name (rlbr/get-venv-name))
  501. (library-root (if library-root library-root (elpy-library-root))))
  502. (let ((workon-home (pyvenv-workon-home)))
  503. (unless (file-exists-p workon-home)
  504. (make-directory workon-home t)))
  505. (setq venv-name (rlbr/handle-name-conflicts venv-name))
  506. (if (y-or-n-p (format "Create venv '%s'?" venv-name))
  507. (pyvenv-create venv-name (rlbr/get-python-executable))
  508. (progn
  509. (setq venv-name (emacs-default-venv))))
  510. (rlbr/setup-python-venv-dirlocals library-root venv-name)
  511. venv-name))
  512. (require 'dash)
  513. (defun rlbr/init-venv ()
  514. (when (eq major-mode 'python-mode)
  515. (cond ((file-remote-p buffer-file-name)
  516. ;; If the file is remote, don't try and do anything fancy
  517. (setq-local pyvenv-workon (emacs-default-venv)))
  518. ((let ((buffer-file-name (file-truename buffer-file-name)))
  519. ;; Don't change anything if entering a file in a python install's lib (ie for a file located with xref)
  520. (string-match-p (rx bos (or
  521. ;; Windows
  522. (and letter ":/" (one-or-more not-newline)
  523. "/Lib")
  524. ;; Rest of the sane world
  525. (and (or
  526. ;; In the home directory
  527. (and (zero-or-more not-newline)
  528. "/home/" (zero-or-more not-newline)
  529. (or
  530. ;; System python user installed package
  531. "/.local"
  532. ;; In a virtualenv
  533. (and "/.virtualenvs/" (one-or-more (not (any "/"))))
  534. ;; Elpy-rpc venv
  535. (and "/.emacs.d/elpy/rpc-venv")
  536. ;; Using Pyenv
  537. (and "/.pyenv/versions/"
  538. (one-or-more (not (any "/"))))))
  539. ;; System python
  540. (and (zero-or-more not-newline)
  541. "/usr"
  542. (opt "/local")))
  543. ;; Standard */lib/python3.7/ etc
  544. (or
  545. ;; Standard python
  546. (and "/lib/python" (one-or-more (any digit ".")))
  547. ;; PyPy
  548. (and (or "/lib-python" "/lib_pypy")))))
  549. (zero-or-more not-newline))
  550. buffer-file-name))
  551. nil)
  552. (t
  553. ;; Upon failing all conditions, prompt to create virtual environment if it doesn't exist
  554. (cond ((and pyvenv-workon (not (member pyvenv-workon (pyvenv-virtualenv-list))))
  555. ;; If there is a virtualenv specified and it doesn't exist, prompt to create it or set to default virtual environment
  556. (if (y-or-n-p (format "Venv '%s' is specified but does not exist. Create it?" pyvenv-workon))
  557. (progn (pyvenv-create pyvenv-workon (rlbr/get-python-executable))
  558. (pyvenv-workon pyvenv-workon))
  559. (rlbr/save-buffer-func-to-file (let ((default-directory (elpy-library-root)))
  560. (expand-file-name ".dir-locals.el"))
  561. 'add-dir-local-variable '(python-mode pyvenv-workon (emacs-default-venv)))
  562. (setq-local pyvenv-workon (emacs-default-venv))))
  563. ((not pyvenv-workon)
  564. ;; If nothing has already set pyvenv-workon, create venv
  565. (setq-local pyvenv-workon (rlbr/init-python-venv-in-library-root))))))
  566. (pyvenv-workon pyvenv-workon)))
  567. #+end_src
  568. *** Bindings/settings
  569. #+begin_src emacs-lisp
  570. (use-package python
  571. :hook
  572. ((python-mode . pyvenv-mode)
  573. (python-mode . flycheck-mode)
  574. (python-mode . (lambda () (add-hook 'before-save-hook 'elpy-black-fix-code nil 'local))))
  575. :bind
  576. (:map python-mode-map
  577. (("C-<" . flycheck-previous-error)
  578. ("C->" . flycheck-next-error)))
  579. :config
  580. (use-package elpy
  581. :hook (hack-local-variables . rlbr/init-venv)
  582. :bind (:map python-mode-map
  583. (("C-=" . elpy-goto-assignment)
  584. ("M-." . elpy-goto-definition)))
  585. :config
  586. (when (require 'flycheck nil t)
  587. (setq elpy-modules (delq 'elpy-module-flymake elpy-modules)))
  588. (rlbr/prefix-arg-overload 'elpy-goto-definition 'elpy-goto-definition-other-window)
  589. (rlbr/prefix-arg-overload 'elpy-goto-assignment 'elpy-goto-assignment-other-window)
  590. (rlbr/elpy-append-to-path)
  591. (rlbr/fix-for-android)
  592. (pyvenv-tracking-mode))
  593. (use-package realgud
  594. :bind (:map python-mode-map
  595. (("C-c d b" . realgud:pdb))))
  596. (elpy-enable))
  597. #+end_src
  598. ** SSH config mode
  599. #+begin_src emacs-lisp
  600. (use-package ssh-config-mode
  601. :mode "~/.ssh/config\\'")
  602. #+end_src
  603. ** Tramp
  604. ** Webmode
  605. #+begin_src emacs-lisp
  606. (use-package web-mode
  607. :mode
  608. (("\\.phtml\\'" . web-mode)
  609. ("\\.tpl\\.php\\'" . web-mode)
  610. ("\\.[agj]sp\\'" . web-mode)
  611. ("\\.as[cp]x\\'" . web-mode)
  612. ("\\.erb\\'" . web-mode)
  613. ("\\.mustache\\'" . web-mode)
  614. ("\\.djhtml\\'" . web-mode)
  615. ("\\.html?\\'" . web-mode)))
  616. #+end_src
  617. ** YAML
  618. #+begin_src emacs-lisp
  619. (use-package yaml-mode
  620. :mode "\\.yml\\'")
  621. #+end_src
  622. * Minor modes/misc
  623. ** Better shell
  624. #+begin_src emacs-lisp
  625. (use-package better-shell
  626. :bind
  627. (("M-V l" . better-shell-shell)
  628. ("M-V r" . better-shell-remote-open)
  629. ("M-V s" . better-shell-sudo-here)))
  630. #+end_src
  631. ** Custom custom
  632. #+begin_src emacs-lisp
  633. (advice-add 'custom-save-faces :after (lambda () (rlbr/multiline-sexp-with-symbol "custom-set-faces")))
  634. (advice-add 'custom-save-variables :after (lambda () (rlbr/multiline-sexp-with-symbol "custom-set-variables")))
  635. #+end_src
  636. ** Elmacro
  637. #+begin_src emacs-lisp
  638. (use-package elmacro
  639. :diminish
  640. :demand
  641. :config
  642. (elmacro-mode +1))
  643. #+end_src
  644. ** Kill the things
  645. *** Buffer
  646. #+begin_src emacs-lisp
  647. (global-set-key (kbd "C-x k") 'rlbr/kill-this-buffer)
  648. #+end_src
  649. *** Emacs
  650. #+begin_src emacs-lisp
  651. (global-set-key (kbd "C-x C-k C-x C-k") 'save-buffers-kill-emacs)
  652. #+end_src
  653. ** Lispy
  654. #+begin_src emacs-lisp
  655. (use-package lispy
  656. :hook ((emacs-lisp-mode) . lispy-mode))
  657. #+end_src
  658. * Navigation/auto-completion
  659. ** Ace window
  660. #+begin_src emacs-lisp
  661. (use-package ace-window
  662. :bind (("M-Q" . ace-window)))
  663. #+end_src
  664. ** Disable Ido
  665. #+begin_src emacs-lisp
  666. (use-package ido
  667. :config
  668. (ido-mode -1))
  669. #+end_src
  670. ** Hippie expand
  671. #+begin_src emacs-lisp
  672. (use-package hippie-exp
  673. :bind ("M-/" . hippie-expand))
  674. #+end_src
  675. ** IBuffer mode
  676. #+begin_src emacs-lisp
  677. (use-package ibbufer-vc
  678. :hook
  679. ((ibuffer-mode . ibuffer-vc-set-filter-groups-by-vc-root)))
  680. ;; Use human readable Size column instead of original one
  681. (use-package ibuffer :bind (("C-x C-b" . ibuffer))
  682. :bind (:map ibuffer-mode-map
  683. (("C-c t" . ibuffer-tramp-set-filter-groups-by-tramp-connection)
  684. ("C-c g" . ibuffer-vc-set-filter-groups-by-vc-root)))
  685. :config (define-ibuffer-column size-h (:name "Size" :inline t)
  686. (cond ((> (buffer-size)
  687. 1000000)
  688. (format "%7.1fM" (/ (buffer-size)
  689. 1000000.0)))
  690. ((> (buffer-size)
  691. 100000)
  692. (format "%7.0fk" (/ (buffer-size)
  693. 1000.0)))
  694. ((> (buffer-size)
  695. 1000)
  696. (format "%7.1fk" (/ (buffer-size)
  697. 1000.0)))
  698. (t (format "%8d" (buffer-size))))))
  699. #+end_src
  700. ** Ivy
  701. #+begin_src emacs-lisp
  702. (use-package ivy
  703. :diminish
  704. :config
  705. (use-package counsel
  706. :diminish)
  707. (use-package swiper
  708. :bind ("C-s" . swiper))
  709. (ivy-mode)
  710. (counsel-mode))
  711. #+end_src
  712. * Look and feel
  713. ** Line numbers
  714. #+begin_src emacs-lisp
  715. (global-display-line-numbers-mode)
  716. #+end_src
  717. ** Mode line bell
  718. #+begin_src emacs-lisp
  719. (use-package mode-line-bell
  720. :config
  721. (mode-line-bell-mode))
  722. #+end_src
  723. ** Smart mode line
  724. #+begin_src emacs-lisp
  725. (use-package smart-mode-line
  726. :init
  727. (winum-mode 1)
  728. :config
  729. (sml/setup))
  730. #+end_src
  731. ** Theme
  732. #+begin_src emacs-lisp
  733. (use-package dracula-theme
  734. :config
  735. (load-theme 'dracula t))
  736. #+end_src
  737. ** Winum-mode
  738. #+begin_src emacs-lisp
  739. (use-package winum
  740. :bind
  741. (:map winum-keymap
  742. (("M-0" . winum-select-window-0-or-10)
  743. ("M-1" . winum-select-window-1)
  744. ("M-2" . winum-select-window-2)
  745. ("M-3" . winum-select-window-3)
  746. ("M-4" . winum-select-window-4)
  747. ("M-5" . winum-select-window-5)
  748. ("M-6" . winum-select-window-6)
  749. ("M-7" . winum-select-window-7)
  750. ("M-8" . winum-select-window-8))))
  751. #+end_src
  752. * Clipboard manager
  753. ** Clipmon settings
  754. #+begin_src emacs-lisp
  755. (use-package clipmon
  756. :if (or (eq system-type 'windows-nt) (member "X11" (split-string system-configuration-features " ")))
  757. :hook ((after-init . clipmon-mode-start)
  758. (after-init . clipmon-persist)))
  759. #+end_src