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.

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