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.

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