;;; quality-of-life.el -*- lexical-binding: t; -*- ;;; ;;; Author: Jakob L. Kreuze ;;; URL: https://git.sr.ht/~jakob/.emacs.d/ ;;; ;;; Configuration for packages which I consider to be functional improvements to ;;; the quality of my daily Emacs usage. ;;; ;;; ;;; Ivy ;;; ;; As suggested by a friend [1], I tried out `ivy' as a replacement for `ido.' ;; It was love at first sight. It's snappy, and works even better than `ido' ;; after setting `exwm-workspace-show-all-buffers' and ;; `exwm-layout-show-all-buffers'. ;; ;; [1]: https://icosahedron.website/@zge/101330910258980695 (use-package ivy ;; Configure how the =completing-read= is displayed. :init (setq ivy-height 5 ivy-count-format "") ;; Enable Ivy globally. :config (ivy-mode 1) ;; If I'm typing a file name with capitalized letters, I may be holding shift ;; when I press space. This is a pain in the ass, and I don't use the feature ;; anyway, so I unbind it. (bind-key "S-SPC" nil ivy-minibuffer-map) :config/el-patch (defun ivy-magic-read-file-env () "If reading filename, jump to environment variable location." (interactive) (if (and ivy--directory (equal ivy-text "")) (let* ((cands (cl-loop for pair in process-environment for (var val) = (split-string pair "=" t) if (and val (not (equal "" val))) if (or ;; Don't `file-exists-p' on TRAMP stuff (el-patch-add (string-suffix-p ":/" val)) (file-exists-p (if (file-name-absolute-p val) val (setq val (expand-file-name val ivy--directory))))) collect (cons var val))) (enable-recursive-minibuffers t) (x (ivy-read "Env: " cands)) (path (cdr (assoc x cands)))) (insert (if (file-accessible-directory-p path) (file-name-as-directory path) path)) (ivy--cd-maybe)) (insert last-input-event)))) ;; `counsel' is a nice Ivy-based frontend for a couple of interactive commands. (use-package counsel :demand t :bind ("C-x b" . counsel-switch-buffer)) ;; Use Swiper instead of isearch. ;; TODO: Should I re-enable this? ;; (use-package swiper ;; :bind ;; ("C-r" . swiper) ;; ("C-s" . swiper)) ;; Use a better sorting algorithm. (use-package ivy-prescient :config (ivy-prescient-mode) (prescient-persist-mode) :init (setq prescient-save-file "~/.cache/prescient-save.el")) ;;; ;;; Imenu ;;; (use-package imenu :bind ("C-c s" . imenu)) ;;; ;;; Yasnippet ;;; ;; Load all snippets when `yas-minor-mode' is enabled. (use-package yasnippet :demand t :hook (yas-minor-mode . yas-reload-all)) ;;; ;;; Avy ;;; ;; Set up keybindings for Avy. (use-package avy :bind ("M-s" . avy-goto-char-timer) :init (setq avy-timeout-seconds 0.2)) ;; Install a link-selection package for Avy, and create a binding for `org-mode'. ;; TODO: Should I re-enable this? ;; (use-package ace-link ;; :after org ;; :init (ace-link-setup-default) ;; :bind (:map org-mode-map ;; ("C-c C-o" . ace-link-org))) ;; Hack so that fill-paragraph is aware of the width of in-line LaTeX previews. (defvar standard-fill-column (symbol-function #'current-fill-column)) (defun extract-rest-of-paragraph () "Return, as a string, the region from POINT to the end of the paragraph." (save-excursion (let ((beg (point))) (forward-paragraph) (buffer-substring beg (point))))) (defun tex-aware-current-fill-column () "Fill without breaking over LaTeX previews." (interactive "d") ;; This only really applies in `org-mode', so hop out if that's not the case. (if (eq 'org-mode major-mode) ;; Extract paragraph to temporary buffer. (let ((rest (extract-rest-of-paragraph)) res) (with-temp-buffer (insert rest) (goto-char (point-min)) ;; "Flatten" out the region. (org-latex-preview) (cl-flet ((end-position () (save-excursion (end-of-paragraph-text) (point)))) (let ((char-width-read 0) last-position) (while (/= (point) (end-position)) (setq last-position (point)) (forward-sexp) (setq char-width-read (+ char-width-read (- (point) last-position) (cl-reduce #'+ (mapcar #'(lambda (ol) (car (image-size (overlay-get ol 'display)))) (overlays-in last-position (point)))))) (when (and (>= char-width-read fill-column) (not res)) (setq res char-width-read))))) (round (or res fill-column)))) (funcall standard-fill-column))) (fset 'current-fill-column #'tex-aware-current-fill-column) (fset 'current-fill-column standard-fill-column)