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.

755 lines
24 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. :mode (rx "docker-compose.yml" eos)
  261. :hook
  262. (docker-compose-mode . company-mode))
  263. #+END_SRC
  264. ** Java
  265. *** Meghanada
  266. #+BEGIN_SRC emacs-lisp
  267. (use-package autodisass-java-bytecode
  268. :defer t)
  269. (use-package meghanada
  270. :if (rlbr/high-mem (* 512 1024))
  271. :defer t
  272. :init
  273. (add-hook 'java-mode-hook
  274. (lambda ()
  275. (meghanada-mode t)
  276. (flycheck-mode +1)
  277. (add-hook 'before-save-hook 'meghanada-code-beautify-before-save)))
  278. :config
  279. (setq indent-tabs-mode nil)
  280. (setq meghanada-server-remote-debug t)
  281. (setq meghanada-javac-xlint "-Xlint:all,-processing")
  282. (advice-add 'meghanada-code-beautify :around (lambda (old)
  283. (interactive)
  284. (let ((p (line-number-at-pos)))
  285. (apply old nil)
  286. (goto-line p)
  287. (reposition-window))))
  288. (defhydra hydra-meghanada (:hint nil :exit t)
  289. "
  290. ^Edit^ ^Tast or Task^
  291. ^^^^^^-------------------------------------------------------
  292. _f_: meghanada-compile-file _m_: meghanada-restart
  293. _c_: meghanada-compile-project _t_: meghanada-run-task
  294. _o_: meghanada-optimize-import _j_: meghanada-run-junit-test-case
  295. _s_: meghanada-switch-test-case _J_: meghanada-run-junit-class
  296. _v_: meghanada-local-variable _R_: meghanada-run-junit-recent
  297. _i_: meghanada-import-all _r_: meghanada-reference
  298. _g_: magit-status _T_: meghanada-typeinfo
  299. _q_: exit
  300. "
  301. ("f" meghanada-compile-file)
  302. ("m" meghanada-restart)
  303. ("c" meghanada-compile-project)
  304. ("o" meghanada-optimize-import)
  305. ("s" meghanada-switch-test-case)
  306. ("v" meghanada-local-variable)
  307. ("i" meghanada-import-all)
  308. ("g" magit-status)
  309. ("t" meghanada-run-task)
  310. ("T" meghanada-typeinfo)
  311. ("j" meghanada-run-junit-test-case)
  312. ("J" meghanada-run-junit-class)
  313. ("R" meghanada-run-junit-recent)
  314. ("r" meghanada-reference)
  315. ("q" exit)
  316. ("z" nil "leave"))
  317. :bind
  318. (:map meghanada-mode-map
  319. ("C-S-t" . meghanada-switch-testcase)
  320. ("M-RET" . meghanada-local-variable)
  321. ("M-r" . meghanada-reference)
  322. ("M-t" . meghanada-typeinfo)
  323. ("C-z" . hydra-meghanada/body))
  324. :commands
  325. (meghanada-mode))
  326. #+END_SRC
  327. ** JavaScript
  328. #+BEGIN_SRC emacs-lisp
  329. (use-package js2-mode
  330. :mode "\\.js\\'"
  331. :hook ((js2-mode . js2-imenu-extras-mode)
  332. (js2-mode . (lambda () (add-hook 'xref-backend-functions #'xref-js2-xref-backend nil t))))
  333. :config
  334. (use-package js2-refactor
  335. :hook (js2-mode . js2-refactor-mode)
  336. :bind
  337. (:map js2-mode-map
  338. ("C-k" . js2r-kill))
  339. :config
  340. (js2r-add-keybindings-with-prefix "C-c C-r"))
  341. (use-package xref-js2
  342. :demand t)
  343. (define-key js-mode-map (kbd "M-.") nil)
  344. (defun rlbr/jump-to-definition ()
  345. "Jump to a definition."
  346. (interactive)
  347. (condition-case-unless-debug nil
  348. (js2-jump-to-definition)
  349. (error
  350. (progn
  351. (ignore-errors
  352. (xref-pop-marker-stack))
  353. (xref-find-definitions (xref-backend-identifier-at-point (xref-find-backend)))))))
  354. (define-key js-mode-map (kbd "M-.") #'rlbr/jump-to-definition))
  355. #+END_SRC
  356. ** JSON
  357. #+BEGIN_SRC emacs-lisp
  358. (use-package json
  359. :config
  360. (use-package json-mode
  361. :bind (:map json-mode-map
  362. ("C-c p p" . json-pretty-print-buffer-ordered)))
  363. (use-package json-reformat
  364. :config
  365. (setq json-encoding-default-indentation (make-string json-reformat:indent-width ? ))))
  366. #+END_SRC
  367. ** Lisp
  368. *** Emacs lisp
  369. #+BEGIN_SRC emacs-lisp
  370. (use-package elisp-mode
  371. :hook (emacs-lisp-mode . company-mode))
  372. #+END_SRC
  373. ** Magit
  374. #+BEGIN_SRC emacs-lisp
  375. (use-package magit
  376. :bind (("C-x g" . magit-status))
  377. :config
  378. (use-package git-commit
  379. :hook (git-commit-setup . git-commit-turn-on-flyspell)))
  380. #+END_SRC
  381. ** Python
  382. *** Platform specific
  383. Set python command
  384. #+BEGIN_SRC emacs-lisp
  385. (setq elpy-rpc-python-command
  386. (cond
  387. ((string-equal system-type "gnu/linux")
  388. "python3")
  389. ((string-equal system-type "windows-nt")
  390. "pythonw.exe")))
  391. #+END_SRC
  392. put executables in elpy-rpc-venv in path
  393. #+BEGIN_SRC emacs-lisp
  394. (defun rlbr/elpy-append-to-path ()
  395. (setenv "PATH" (string-join (list (getenv "PATH")
  396. (let ((default-directory (elpy-rpc-get-or-create-virtualenv))
  397. (path-entry)
  398. (elpy-binpath))
  399. (if (string-equal system-type "windows-nt")
  400. (progn (setq elpy-binpath (expand-file-name "Scripts"))
  401. (setq path-entry (replace-regexp-in-string (regexp-quote "/")
  402. (regexp-quote "\\")
  403. elpy-binpath)))
  404. (setq elpy-binpath (expand-file-name "bin"))
  405. (setq path-entry elpy-binpath))
  406. (nconc exec-path (list elpy-binpath))
  407. elpy-binpath))
  408. path-separator)))
  409. #+END_SRC
  410. #+BEGIN_SRC emacs-lisp
  411. (defun rlbr/fix-for-android ()
  412. (unless (= 0 (call-process elpy-rpc-python-command nil nil nil "-c" "import multiprocessing;multiprocessing.Pool()"))
  413. (setq python-check-command
  414. (string-join `(,python-check-command "--jobs=1") " "))))
  415. #+END_SRC
  416. *** Custom feature
  417. #+BEGIN_SRC emacs-lisp
  418. (defun rlbr/join-venv-with-number (number-name)
  419. "Join a list with a name and a number"
  420. (let
  421. ((number (car number-name))
  422. (name (cdr number-name)))
  423. (if (= number 0)
  424. name
  425. (string-join (list name (number-to-string number))
  426. "~"))))
  427. (defun rlbr/split-venv-with-number (name-number)
  428. "Split a virtualenv name with either a ~ seperating the name and the number, or nothing"
  429. (let ((split-result (split-string name-number (regexp-quote "~")))
  430. (ret))
  431. (if (= 1 (length split-result))
  432. (progn
  433. (setq ret (car split-result))
  434. (push 0 ret))
  435. (progn
  436. (setq ret
  437. (string-join
  438. (butlast split-result)
  439. "~"))
  440. (push
  441. (string-to-number
  442. (car (last split-result)))
  443. ret)))
  444. ret))
  445. (defun rlbr/get-venv-name (&optional library-root)
  446. "Generate venv name based off of the base-name of the library root"
  447. (file-name-base
  448. (directory-file-name
  449. (if library-root
  450. library-root
  451. (elpy-library-root)))))
  452. (defun rlbr/handle-name-conflicts (venv-name)
  453. "Deal with potential name conflicts in venv"
  454. (let ((venv-conflicts)
  455. (venv-partition-name))
  456. (setq venv-partition-name (rlbr/split-venv-with-number venv-name))
  457. (setq venv-conflicts
  458. (seq-filter
  459. (lambda (item)
  460. (string-equal (cdr item)
  461. venv-name))
  462. (mapcar #'rlbr/split-venv-with-number (pyvenv-virtualenv-list))))
  463. (when venv-conflicts
  464. (setcar venv-partition-name (1+ (apply 'max (mapcar #'car venv-conflicts)))))
  465. (rlbr/join-venv-with-number venv-partition-name)))
  466. (require 'vc)
  467. (defun rlbr/setup-python-venv-dirlocals (&optional library-root venv-name)
  468. "Setup .dir-locals file in library root and tell vc system to ignore .dir-locals file"
  469. (let* ((library-root (if library-root
  470. library-root
  471. (elpy-library-root)))
  472. (venv-name (if venv-name venv-name (rlbr/get-venv-name library-root)))
  473. (default-directory library-root)
  474. (dir-locals-path (expand-file-name
  475. ".dir-locals.el")))
  476. (rlbr/save-buffer-func-to-file dir-locals-path 'add-dir-local-variable
  477. `(python-mode pyvenv-workon ,venv-name))
  478. (let ((vc-root (vc-find-root dir-locals-path ".git")))
  479. (when vc-root
  480. ;; If the directory is under version control
  481. (let ((vc-ignore-file (vc-call-backend 'Git 'find-ignore-file vc-root)))
  482. (if (apply 'string-equal (mapcar 'directory-file-name (mapcar 'file-truename (list vc-root library-root))))
  483. ;; If the vc-root is the same as the library root, don't ask any questions
  484. (vc-ignore ".dir-locals.el")
  485. ;; Otherwise prompt to ignore
  486. (when (y-or-n-p (format "Ignore .dir-locals.el in repo '%s' ?" vc-root))
  487. (vc-ignore ".dir-locals.el"))))))))
  488. (defun rlbr/get-python-executable ()
  489. (read-file-name "Python interpreter to use: " (file-name-directory (executable-find "python"))
  490. nil nil "python"))
  491. (defun emacs-default-venv ()
  492. (unless (member "emacs-default-venv" (pyvenv-virtualenv-list))
  493. (pyvenv-create "emacs-default-venv" (rlbr/get-python-executable)))
  494. "emacs-default-venv")
  495. (defun rlbr/init-python-venv-in-library-root (&optional library-root)
  496. "Prompt to either create one or use default" (let ((venv-name (rlbr/get-venv-name))
  497. (library-root (if library-root library-root (elpy-library-root))))
  498. (let ((workon-home (pyvenv-workon-home)))
  499. (unless (file-exists-p workon-home)
  500. (make-directory workon-home t)))
  501. (setq venv-name (rlbr/handle-name-conflicts venv-name))
  502. (if (y-or-n-p (format "Create venv '%s'?" venv-name))
  503. (pyvenv-create venv-name (rlbr/get-python-executable))
  504. (progn
  505. (setq venv-name (emacs-default-venv))))
  506. (rlbr/setup-python-venv-dirlocals library-root venv-name)
  507. venv-name))
  508. (require 'dash)
  509. (defun rlbr/init-venv ()
  510. (when (eq major-mode 'python-mode)
  511. (cond ((file-remote-p buffer-file-name)
  512. ;; If the file is remote, don't try and do anything fancy
  513. (setq-local pyvenv-workon (emacs-default-venv)))
  514. ((let ((buffer-file-name (file-truename buffer-file-name)))
  515. ;; Don't change anything if entering a file in a python install's lib (ie for a file located with xref)
  516. (string-match-p (rx bos (or
  517. ;; Windows
  518. (and letter ":/" (one-or-more not-newline)
  519. "/Lib")
  520. ;; Rest of the sane world
  521. (and (or
  522. ;; In the home directory
  523. (and (zero-or-more not-newline)
  524. "/home/" (zero-or-more not-newline)
  525. (or
  526. ;; System python user installed package
  527. "/.local"
  528. ;; In a virtualenv
  529. (and "/.virtualenvs/" (one-or-more (not (any "/"))))
  530. ;; Elpy-rpc venv
  531. (and "/.emacs.d/elpy/rpc-venv")
  532. ;; Using Pyenv
  533. (and "/.pyenv/versions/"
  534. (one-or-more (not (any "/"))))))
  535. ;; System python
  536. (and (zero-or-more not-newline)
  537. "/usr"
  538. (opt "/local")))
  539. ;; Standard */lib/python3.7/ etc
  540. (or
  541. ;; Standard python
  542. (and "/lib/python" (one-or-more (any digit ".")))
  543. ;; PyPy
  544. (and (or "/lib-python" "/lib_pypy")))))
  545. (zero-or-more not-newline))
  546. buffer-file-name))
  547. nil)
  548. (t
  549. ;; Upon failing all conditions, prompt to create virtual environment if it doesn't exist
  550. (cond ((and pyvenv-workon (not (member pyvenv-workon (pyvenv-virtualenv-list))))
  551. ;; If there is a virtualenv specified and it doesn't exist, prompt to create it or set to default virtual environment
  552. (if (y-or-n-p (format "Venv '%s' is specified but does not exist. Create it?" pyvenv-workon))
  553. (progn (pyvenv-create pyvenv-workon (rlbr/get-python-executable))
  554. (pyvenv-workon pyvenv-workon))
  555. (rlbr/save-buffer-func-to-file (let ((default-directory (elpy-library-root)))
  556. (expand-file-name ".dir-locals.el"))
  557. 'add-dir-local-variable '(python-mode pyvenv-workon (emacs-default-venv)))
  558. (setq-local pyvenv-workon (emacs-default-venv))))
  559. ((not pyvenv-workon)
  560. ;; If nothing has already set pyvenv-workon, create venv
  561. (setq-local pyvenv-workon (rlbr/init-python-venv-in-library-root))))))
  562. (pyvenv-workon pyvenv-workon)))
  563. #+END_SRC
  564. *** Bindings/settings
  565. #+BEGIN_SRC emacs-lisp
  566. (use-package python
  567. :hook
  568. ((python-mode . pyvenv-mode)
  569. (python-mode . flycheck-mode)
  570. (python-mode . (lambda () (add-hook 'before-save-hook 'elpy-black-fix-code nil 'local))))
  571. :bind
  572. (:map python-mode-map
  573. (("C-<" . flycheck-previous-error)
  574. ("C->" . flycheck-next-error)))
  575. :config
  576. (use-package elpy
  577. :hook (hack-local-variables . rlbr/init-venv)
  578. :bind (:map python-mode-map
  579. (("C-=" . elpy-goto-assignment)
  580. ("M-." . elpy-goto-definition)))
  581. :config
  582. (when (require 'flycheck nil t)
  583. (setq elpy-modules (delq 'elpy-module-flymake elpy-modules)))
  584. (rlbr/prefix-arg-overload 'elpy-goto-definition 'elpy-goto-definition-other-window)
  585. (rlbr/prefix-arg-overload 'elpy-goto-assignment 'elpy-goto-assignment-other-window)
  586. (rlbr/elpy-append-to-path)
  587. (rlbr/fix-for-android)
  588. (pyvenv-tracking-mode))
  589. (use-package realgud
  590. :bind (:map python-mode-map
  591. (("C-c d b" . realgud:pdb))))
  592. (elpy-enable))
  593. #+END_SRC
  594. ** SSH config mode
  595. #+BEGIN_SRC emacs-lisp
  596. (use-package ssh-config-mode
  597. :mode "~/.ssh/config\\'")
  598. #+END_SRC
  599. ** Tramp
  600. ** Webmode
  601. #+BEGIN_SRC emacs-lisp
  602. (use-package web-mode
  603. :mode
  604. (("\\.phtml\\'" . web-mode)
  605. ("\\.tpl\\.php\\'" . web-mode)
  606. ("\\.[agj]sp\\'" . web-mode)
  607. ("\\.as[cp]x\\'" . web-mode)
  608. ("\\.erb\\'" . web-mode)
  609. ("\\.mustache\\'" . web-mode)
  610. ("\\.djhtml\\'" . web-mode)
  611. ("\\.html?\\'" . web-mode)))
  612. #+END_SRC
  613. ** YAML
  614. #+BEGIN_SRC emacs-lisp
  615. (use-package yaml-mode
  616. :mode "\\.yml\\'")
  617. #+END_SRC
  618. * Minor modes/misc
  619. ** Better shell
  620. #+BEGIN_SRC emacs-lisp
  621. (use-package better-shell
  622. :bind
  623. (("M-V l" . better-shell-shell)
  624. ("M-V r" . better-shell-remote-open)
  625. ("M-V s" . better-shell-sudo-here)))
  626. #+END_SRC
  627. ** Custom custom
  628. #+BEGIN_SRC emacs-lisp
  629. (advice-add 'custom-save-faces :after (lambda () (rlbr/multiline-sexp-with-symbol "custom-set-faces")))
  630. (advice-add 'custom-save-variables :after (lambda () (rlbr/multiline-sexp-with-symbol "custom-set-variables")))
  631. #+END_SRC
  632. ** Elmacro
  633. #+BEGIN_SRC emacs-lisp
  634. (use-package elmacro
  635. :diminish
  636. :demand
  637. :config
  638. (elmacro-mode +1))
  639. #+END_SRC
  640. ** Kill the things
  641. *** Buffer
  642. #+BEGIN_SRC emacs-lisp
  643. (global-set-key (kbd "C-x k") 'rlbr/kill-this-buffer)
  644. #+END_SRC
  645. *** Emacs
  646. #+BEGIN_SRC emacs-lisp
  647. (global-set-key (kbd "C-x C-k C-x C-k") 'save-buffers-kill-emacs)
  648. #+END_SRC
  649. ** Lispy
  650. #+BEGIN_SRC emacs-lisp
  651. (use-package lispy
  652. :hook ((emacs-lisp-mode) . lispy-mode))
  653. #+END_SRC
  654. * Navigation/auto-completion
  655. ** Ace window
  656. #+BEGIN_SRC emacs-lisp
  657. (use-package ace-window
  658. :bind (("M-Q" . ace-window)))
  659. #+END_SRC
  660. ** Disable Ido
  661. #+BEGIN_SRC emacs-lisp
  662. (use-package ido
  663. :config
  664. (ido-mode -1))
  665. #+END_SRC
  666. ** Hippie expand
  667. #+BEGIN_SRC emacs-lisp
  668. (use-package hippie-exp
  669. :bind ("M-/" . hippie-expand))
  670. #+END_SRC
  671. ** IBuffer mode
  672. #+BEGIN_SRC emacs-lisp
  673. (use-package ibbufer-vc
  674. :hook
  675. ((ibuffer-mode . ibuffer-vc-set-filter-groups-by-vc-root)))
  676. ;; Use human readable Size column instead of original one
  677. (use-package ibuffer :bind (("C-x C-b" . ibuffer))
  678. :bind (:map ibuffer-mode-map
  679. (("C-c t" . ibuffer-tramp-set-filter-groups-by-tramp-connection)
  680. ("C-c g" . ibuffer-vc-set-filter-groups-by-vc-root)))
  681. :config (define-ibuffer-column size-h (:name "Size" :inline t)
  682. (cond ((> (buffer-size)
  683. 1000000)
  684. (format "%7.1fM" (/ (buffer-size)
  685. 1000000.0)))
  686. ((> (buffer-size)
  687. 100000)
  688. (format "%7.0fk" (/ (buffer-size)
  689. 1000.0)))
  690. ((> (buffer-size)
  691. 1000)
  692. (format "%7.1fk" (/ (buffer-size)
  693. 1000.0)))
  694. (t (format "%8d" (buffer-size))))))
  695. #+END_SRC
  696. ** Ivy
  697. #+BEGIN_SRC emacs-lisp
  698. (use-package ivy
  699. :diminish
  700. :config
  701. (use-package counsel
  702. :diminish)
  703. (use-package swiper
  704. :bind ("C-s" . swiper))
  705. (ivy-mode)
  706. (counsel-mode))
  707. #+END_SRC
  708. * Look and feel
  709. ** Line numbers
  710. #+BEGIN_SRC emacs-lisp
  711. (global-display-line-numbers-mode)
  712. #+END_SRC
  713. ** Mode line bell
  714. #+BEGIN_SRC emacs-lisp
  715. (use-package mode-line-bell
  716. :config
  717. (mode-line-bell-mode))
  718. #+END_SRC
  719. ** Smart mode line
  720. #+BEGIN_SRC emacs-lisp
  721. (use-package smart-mode-line
  722. :init
  723. (winum-mode 1)
  724. :config
  725. (sml/setup))
  726. #+END_SRC
  727. ** Theme
  728. #+BEGIN_SRC emacs-lisp
  729. (use-package dracula-theme
  730. :config
  731. (load-theme 'dracula t))
  732. #+END_SRC
  733. ** Winum-mode
  734. #+BEGIN_SRC emacs-lisp
  735. (use-package winum
  736. :bind
  737. (:map winum-keymap
  738. (("M-0" . winum-select-window-0-or-10)
  739. ("M-1" . winum-select-window-1)
  740. ("M-2" . winum-select-window-2)
  741. ("M-3" . winum-select-window-3)
  742. ("M-4" . winum-select-window-4)
  743. ("M-5" . winum-select-window-5)
  744. ("M-6" . winum-select-window-6)
  745. ("M-7" . winum-select-window-7)
  746. ("M-8" . winum-select-window-8))))
  747. #+END_SRC
  748. * Clipboard manager
  749. ** Clipmon settings
  750. #+BEGIN_SRC emacs-lisp
  751. (use-package clipmon
  752. :if (or (eq system-type 'windows-nt) (member "X11" (split-string system-configuration-features " ")))
  753. :hook ((after-init . clipmon-mode-start)
  754. (after-init . clipmon-persist)))
  755. #+END_SRC