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.

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