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.

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