From c44794e4132f297e2f1061d15e6d1a91d430ad84 Mon Sep 17 00:00:00 2001 From: luiznux Date: Sun, 3 Mar 2024 23:35:54 -0300 Subject: [PATCH] [Completion] Use vertico instead of ivy 1. Replaces all ivy features/packages with vertico. Vertico is more lightweight than ivy and require less configuration, also it is modern completion program. --- init.el | 2 +- lisp/code/init-elisp.el | 6 - lisp/code/init-lsp.el | 54 --- lisp/code/init-prog.el | 11 +- lisp/code/init-vcs.el | 1 - lisp/code/init-web.el | 10 +- lisp/init-functions.el | 6 +- lisp/interface/init-centaur-tabs.el | 1 - lisp/interface/init-completion.el | 301 ++++++++++++++++ lisp/interface/init-highlight.el | 19 +- lisp/interface/init-ibuffer.el | 14 +- lisp/interface/init-interface.el | 28 +- lisp/interface/init-ivy.el | 531 ---------------------------- lisp/interface/init-window.el | 1 - lisp/org-config/init-org.el | 3 - 15 files changed, 334 insertions(+), 654 deletions(-) create mode 100644 lisp/interface/init-completion.el delete mode 100644 lisp/interface/init-ivy.el diff --git a/init.el b/init.el index 4c487cb..4b8adcd 100644 --- a/init.el +++ b/init.el @@ -80,7 +80,7 @@ (require 'init-interface) (require 'init-edit) (require 'init-evil) -(require 'init-ivy) +(require 'init-completion) (require 'init-company) (require 'init-corfu) diff --git a/lisp/code/init-elisp.el b/lisp/code/init-elisp.el index b58d962..5f798de 100644 --- a/lisp/code/init-elisp.el +++ b/lisp/code/init-elisp.el @@ -224,12 +224,6 @@ Lisp function does not specify a special indentation." :hook (helpful-mode . cursor-sensor-mode) ; for remove-advice button :init (with-no-warnings - (with-eval-after-load 'counsel - (setq counsel-describe-function-function #'helpful-callable - counsel-describe-variable-function #'helpful-variable - counsel-describe-symbol-function #'helpful-symbol - counsel-descbinds-function #'helpful-callable)) - (with-eval-after-load 'apropos ;; patch apropos buttons to call helpful instead of help (dolist (fun-bt '(apropos-function apropos-macro apropos-command)) diff --git a/lisp/code/init-lsp.el b/lisp/code/init-lsp.el index aa328a8..f73ed1b 100644 --- a/lisp/code/init-lsp.el +++ b/lisp/code/init-lsp.el @@ -298,60 +298,6 @@ ;; `C-g'to close doc (advice-add #'keyboard-quit :before #'lsp-ui-doc-hide)) - -(use-package lsp-ivy - :after lsp-mode - :bind (:map lsp-mode-map - ([remap xref-find-apropos] . lsp-ivy-workspace-symbol) - ("C-s-." . lsp-ivy-global-workspace-symbol)) - :config - (with-no-warnings - (when (icons-displayable-p) - (defconst lsp-ivy-symbol-kind-icons - `(,(nerd-icons-codicon "nf-cod-symbol_namespace") ; Unknown - 0 - ,(nerd-icons-codicon "nf-cod-symbol_file") ; File - 1 - ,(nerd-icons-codicon "nf-cod-symbol_namespace" :face 'nerd-icons-lblue) ; Module - 2 - ,(nerd-icons-codicon "nf-cod-symbol_namespace" :face 'nerd-icons-lblue) ; Namespace - 3 - ,(nerd-icons-codicon "nf-cod-package") ; Package - 4 - ,(nerd-icons-codicon "nf-cod-symbol_class" :face 'nerd-icons-orange) ; Class - 5 - ,(nerd-icons-codicon "nf-cod-symbol_method" :face 'nerd-icons-purple) ; Method - 6 - ,(nerd-icons-codicon "nf-cod-symbol_property") ; Property - 7 - ,(nerd-icons-codicon "nf-cod-symbol_field" :face 'nerd-icons-lblue) ; Field - 8 - ,(nerd-icons-codicon "nf-cod-symbol_method" :face 'nerd-icons-lpurple) ; Constructor - 9 - ,(nerd-icons-codicon "nf-cod-symbol_enum" :face 'nerd-icons-orange) ; Enum - 10 - ,(nerd-icons-codicon "nf-cod-symbol_interface" :face 'nerd-icons-lblue) ; Interface - 11 - ,(nerd-icons-codicon "nf-cod-symbol_method" :face 'nerd-icons-purple) ; Function - 12 - ,(nerd-icons-codicon "nf-cod-symbol_variable" :face 'nerd-icons-lblue) ; Variable - 13 - ,(nerd-icons-codicon "nf-cod-symbol_constant") ; Constant - 14 - ,(nerd-icons-codicon "nf-cod-symbol_string") ; String - 15 - ,(nerd-icons-codicon "nf-cod-symbol_numeric") ; Number - 16 - ,(nerd-icons-codicon "nf-cod-symbol_boolean" :face 'nerd-icons-lblue) ; Boolean - 17 - ,(nerd-icons-codicon "nf-cod-symbol_array") ; Array - 18 - ,(nerd-icons-codicon "nf-cod-symbol_class" :face 'nerd-icons-blue) ; Object - 19 - ,(nerd-icons-codicon "nf-cod-symbol_key") ; Key - 20 - ,(nerd-icons-codicon "nf-cod-symbol_numeric" :face 'nerd-icons-dsilver) ; Null - 21 - ,(nerd-icons-codicon "nf-cod-symbol_enum_member" :face 'nerd-icons-lblue) ; EnumMember - 22 - ,(nerd-icons-codicon "nf-cod-symbol_structure" :face 'nerd-icons-orange) ; Struct - 23 - ,(nerd-icons-codicon "nf-cod-symbol_event" :face 'nerd-icons-orange) ; Event - 24 - ,(nerd-icons-codicon "nf-cod-symbol_operator") ; Operator - 25 - ,(nerd-icons-codicon "nf-cod-symbol_class") ; TypeParameter - 26 - )) - - (lsp-defun my-lsp-ivy--format-symbol-match - ((sym &as &SymbolInformation :kind :location (&Location :uri)) - project-root) - "Convert the match returned by `lsp-mode` into a candidate string." - (let* ((sanitized-kind (if (length> lsp-ivy-symbol-kind-icons kind) kind 0)) - (type (elt lsp-ivy-symbol-kind-icons sanitized-kind)) - (typestr (if lsp-ivy-show-symbol-kind (format "%s " type) "")) - (pathstr (if lsp-ivy-show-symbol-filename - (propertize (format " · %s" (file-relative-name (lsp--uri-to-path uri) project-root)) - 'face font-lock-comment-face) - ""))) - (concat typestr (lsp-render-symbol-information sym ".") pathstr))) - (advice-add #'lsp-ivy--format-symbol-match :override #'my-lsp-ivy--format-symbol-match)))) - - ;; Debug (use-package dap-mode :defines dap-python-executable diff --git a/lisp/code/init-prog.el b/lisp/code/init-prog.el index c1519f3..3645184 100644 --- a/lisp/code/init-prog.el +++ b/lisp/code/init-prog.el @@ -76,12 +76,7 @@ (t 'grep))) ;; Select from xref candidates in minibuffer (setq xref-show-definitions-function #'xref-show-definitions-completing-read - xref-show-xrefs-function #'xref-show-definitions-completing-read) - ;; Select from xref candidates with Ivy - (use-package ivy-xref - :after ivy - :init - (setq xref-show-xrefs-function #'ivy-xref-show-xrefs)))) + xref-show-xrefs-function #'xref-show-definitions-completing-read))) ;; Jump to definition (use-package dumb-jump @@ -100,8 +95,8 @@ ("b" dumb-jump-back "Back")))) :bind ("C-M-j" . dumb-jump-hydra/body) :init - (add-hook 'xref-backend-functions #'dumb-jump-xref-activate) ; use M-. to go to definition - (setq dumb-jump-selector 'ivy)) + ;; use M-. to go to definition + (add-hook 'xref-backend-functions #'dumb-jump-xref-activate)) ;; Code styles (use-package editorconfig diff --git a/lisp/code/init-vcs.el b/lisp/code/init-vcs.el index 1d07325..94d1790 100644 --- a/lisp/code/init-vcs.el +++ b/lisp/code/init-vcs.el @@ -48,7 +48,6 @@ (use-package magit-todos :defines magit-todos-nice :commands magit-todos-mode magit-todos--scan-with-git-grep - :bind ("C-c C-t" . ivy-magit-todos) :init (setq magit-todos-nice (if (executable-find "nice") t nil)) (setq magit-todos-scanner #'magit-todos--scan-with-git-grep) diff --git a/lisp/code/init-web.el b/lisp/code/init-web.el index c89effc..8a532aa 100644 --- a/lisp/code/init-web.el +++ b/lisp/code/init-web.el @@ -56,15 +56,7 @@ ("v" xwwp-follow-link "follow link" :exit t) ("w" xwidget-webkit-current-url-message-kill "copy url" :exit t) ("?" describe-mode "help" :exit t) - ("Q" quit-window "quit" :exit t)))) - :init - ;; Link navigation - (use-package xwwp-follow-link-ivy - :after ivy - :bind (("C-c C-z x" . xwwp) - :map xwidget-webkit-mode-map - ("v" . xwwp-follow-link)) - :init (setq xwwp-follow-link-completion-system 'ivy))) + ("Q" quit-window "quit" :exit t))))) ;; CSS (use-package css-mode diff --git a/lisp/init-functions.el b/lisp/init-functions.el index fb886db..fa9c4b9 100644 --- a/lisp/init-functions.el +++ b/lisp/init-functions.el @@ -33,7 +33,6 @@ (declare-function nerd-icons-install-fonts "ext:nerd-icons") (declare-function xwidget-webkit-current-session "xwidget") (declare-function xwidget-buffer "xwidget") -(declare-function ivy-read "ivy") ;; UI @@ -416,9 +415,8 @@ Save to option `custom-file' if NO-SAVE is nil." (interactive (list (intern - (ivy-read "Select package archives: " - (mapcar #'car luiznux-package-archives-alist) - :preselect (symbol-name luiznux-package-archives))))) + (completing-read "Select package archives: " + (mapcar #'car luiznux-package-archives-alist))))) ;; Set option (custom-set-variable 'luiznux-package-archives archives no-save) diff --git a/lisp/interface/init-centaur-tabs.el b/lisp/interface/init-centaur-tabs.el index 4415df6..5078059 100644 --- a/lisp/interface/init-centaur-tabs.el +++ b/lisp/interface/init-centaur-tabs.el @@ -35,7 +35,6 @@ ("C-" . centaur-tabs-forward) ("C-S-" . centaur-tabs-move-current-tab-to-left) ("C-S-" . centaur-tabs-move-current-tab-to-right) - ("C-c t t" . centaur-tabs-counsel-switch-group) (:map evil-normal-state-map ("g t" . centaur-tabs-forward) ("g T" . centaur-tabs-backward))) diff --git a/lisp/interface/init-completion.el b/lisp/interface/init-completion.el new file mode 100644 index 0000000..a602adb --- /dev/null +++ b/lisp/interface/init-completion.el @@ -0,0 +1,301 @@ +;;; init-completion.el --- Initialize completion configurations. -*- lexical-binding: t -*- +;; +;; Author: Luiz Tagliaferro +;; URL: https://luiznux.com +;; This file is free software :) +;; +;;; Commentary: +;; +;; ██████╗ ██████╗ ███╗ ███╗██████╗ ██╗ ███████╗████████╗██╗ ██████╗ ███╗ ██╗ +;; ██╔════╝██╔═══██╗████╗ ████║██╔══██╗██║ ██╔════╝╚══██╔══╝██║██╔═══██╗████╗ ██║ +;; ██║ ██║ ██║██╔████╔██║██████╔╝██║ █████╗ ██║ ██║██║ ██║██╔██╗ ██║ +;; ██║ ██║ ██║██║╚██╔╝██║██╔═══╝ ██║ ██╔══╝ ██║ ██║██║ ██║██║╚██╗██║ +;; ╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ███████╗███████╗ ██║ ██║╚██████╔╝██║ ╚████║ +;; ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ +;; +;; +;;; Code: + +;; fuzzy completion style +(use-package hotfuzz + :init (setq completion-styles '(hotfuzz))) + +(use-package vertico + :defines vertico-mouse-mode + :custom-face + (vertico-current ((t (:nherit hilight :background "#2257A0" :extend t)))) + :bind (:map vertico-map + ("RET" . vertico-directory-enter) + ("DEL" . vertico-directory-delete-char) + ("M-q" . vertico-directory-delete-word) + ("M-j" . vertico-next) + ("M-k" . vertico-previous) + ("M-d" . vertico-scroll-up) + ("M-u" . vertico-scroll-down) + ("M-<" . vertico-first) + ("M->" . vertico-last)) + :hook ((after-init . vertico-mode) + (rfn-eshadow-update-overlay . vertico-directory-tidy)) + :init + (setq vertico-mouse-mode t + vertico-resize 'grow-only + vertico-count 12)) + +(use-package nerd-icons-completion + :when (icons-displayable-p) + :hook (vertico-mode . nerd-icons-completion-mode)) + +(use-package marginalia + :hook (after-init . marginalia-mode)) + +(use-package consult + :commands consult-narrow-help + :bind (;; C-c bindings in `mode-specific-map' + ("C-c M-x" . consult-mode-command) + ("C-c h" . consult-history) + ("C-c m" . consult-man) + ("C-c i" . consult-imenu) + ("C-c I" . consult-info) + ("C-c r" . consult-recent-file) + + ("C-c c e" . consult-colors-emacs) + ("C-c c w" . consult-colors-web) + ("C-c c k" . consult-kmacro) + ("C-c c r" . consult-ripgrep) + ("C-c c t" . consult-theme) + ("C-c c F" . describe-face) + + ([remap Info-search] . consult-info) + ([remap isearch-forward] . consult-line) + ([remap recentf-open-files] . consult-recent-file) + + ;; C-x bindings in `ctl-x-map' + ("C-x M-:" . consult-complex-command) ;; orig. repeat-complex-command + ("C-x b" . consult-buffer) ;; orig. switch-to-buffer + ("C-x 4 b" . consult-buffer-other-window) ;; orig. switch-to-buffer-other-window + ("C-x 5 b" . consult-buffer-other-frame) ;; orig. switch-to-buffer-other-frame + ("C-x r b" . consult-bookmark) ;; orig. bookmark-jump + ("C-x p b" . consult-project-buffer) ;; orig. project-switch-to-buffer + + ;; Custom M-# bindings for fast register access + ("M-#" . consult-register-load) + ("M-'" . consult-register-store) ;; orig. abbrev-prefix-mark (unrelated) + ("C-M-#" . consult-register) + + ;; Other custom bindings + ("M-y" . consult-yank-pop) ;; orig. yank-pop + + ;; M-g bindings in `goto-map' + ("M-g e" . consult-compile-error) + ("M-g f" . consult-flymake) ;; Alternative: consult-flycheck + ("M-g g" . consult-goto-line) ;; orig. goto-line + ("M-g M-g" . consult-goto-line) ;; orig. goto-line + ("M-g o" . consult-outline) ;; Alternative: consult-org-heading + ("M-g m" . consult-mark) + ("M-g k" . consult-global-mark) + ("M-g i" . consult-imenu) + ("M-g I" . consult-imenu-multi) + + ;; M-s bindings in `search-map' + ("M-s d" . consult-find) + ("M-s D" . consult-locate) + ("M-s g" . consult-grep) + ("M-s G" . consult-git-grep) + ("M-s r" . consult-ripgrep) + ("M-s l" . consult-line) + ("M-s L" . consult-line-multi) + ("M-s k" . consult-keep-lines) + ("M-s u" . consult-focus-lines) + + ;; Isearch integration + ("M-s e" . consult-isearch-history) + :map isearch-mode-map + ("M-e" . consult-isearch-history) ;; orig. isearch-edit-string + ("M-s e" . consult-isearch-history) ;; orig. isearch-edit-string + ("M-s l" . consult-line) ;; needed by consult-line to detect isearch + ("M-s L" . consult-line-multi) ;; needed by consult-line to detect isearch + + ;; Minibuffer history + :map minibuffer-local-map + ("C-s" . (lambda () + "Insert the selected region or current symbol at point." + (interactive) + (insert (with-current-buffer + (window-buffer (minibuffer-selected-window)) + (or (and transient-mark-mode mark-active (/= (point) (mark)) + (buffer-substring-no-properties (point) (mark))) + (thing-at-point 'symbol t) + ""))))) + ("M-s" . consult-history) ;; orig. next-matching-history-element + ("M-r" . consult-history)) ;; orig. previous-matching-history-element + + ;; Enable automatic preview at point in the *Completions* buffer. This is + ;; relevant when you use the default completion UI. + :hook (completion-list-mode . consult-preview-at-point-mode) + + ;; The :init configuration is always executed (Not lazy) + :init + (with-no-warnings + ;; Optionally configure the register formatting. This improves the register + ;; preview for `consult-register', `consult-register-load', + ;; `consult-register-store' and the Emacs built-ins. + (setq register-preview-delay 0.5 + register-preview-function #'consult-register-format) + + ;; Optionally tweak the register preview window. + ;; This adds thin lines, sorting and hides the mode line of the window. + (advice-add #'register-preview :override #'consult-register-window) + + ;; Use Consult to select xref locations with preview + (with-eval-after-load 'xref + (setq xref-show-xrefs-function #'consult-xref + xref-show-definitions-function #'consult-xref)) + + ;; More utils + (defvar consult-colors-history nil + "History for `consult-colors-emacs' and `consult-colors-web'.") + ;; No longer preloaded in Emacs 28. + (autoload 'list-colors-duplicates "facemenu") + ;; No preloaded in consult.el + (autoload 'consult--read "consult") + + (defun consult-colors-emacs (color) + "Show a list of all supported colors for a particular frame. + +You can insert the name (default), or insert or kill the hexadecimal or RGB +value of the selected COLOR." + (interactive + (list (consult--read (list-colors-duplicates (defined-colors)) + :prompt "Emacs color: " + :require-match t + :category 'color + :history '(:input consult-colors-history) + ))) + (insert color)) + + ;; Adapted from counsel.el to get web colors. + (defun consult-colors--web-list nil + "Return list of CSS colors for `counsult-colors-web'." + (require 'shr-color) + (sort (mapcar #'downcase (mapcar #'car shr-color-html-colors-alist)) #'string-lessp)) + + (defun consult-colors-web (color) + "Show a list of all CSS colors.\ + +You can insert the name (default), or insert or kill the hexadecimal or RGB +value of the selected COLOR." + (interactive + (list (consult--read (consult-colors--web-list) + :prompt "Color: " + :require-match t + :category 'color + :history '(:input consult-colors-history) + ))) + (insert color))) + + :config + ;; Optionally configure preview. The default value + ;; is 'any, such that any key triggers the preview. + ;; (setq consult-preview-key 'any) + ;; (setq consult-preview-key '("S-" "S-")) + (setq consult-preview-key '(:debounce 1.0 any)) + ;; For some commands and buffer sources it is useful to configure the + ;; :preview-key on a per-command basis using the `consult-customize' macro. + (consult-customize + consult-goto-line + consult-theme :preview-key '(:debounce 0.5 any)) + + ;; Optionally configure the narrowing key. + ;; Both < and C-+ work reasonably well. + (setq consult-narrow-key "<") ;; "C-+" + + ;; Optionally make narrowing help available in the minibuffer. + ;; You may want to use `embark-prefix-help-command' or which-key instead. + (define-key consult-narrow-map (vconcat consult-narrow-key "?") #'consult-narrow-help) + + ;; replece `project.el' for find regexp + (advice-add #'project-find-regexp :override #'consult-ripgrep)) + +(use-package consult-project-extra) + +(use-package consult-flyspell + :bind ("M-g s" . consult-flyspell)) + +(use-package consult-yasnippet + :bind ("M-g y" . consult-yasnippet)) + +(use-package embark + :commands embark-prefix-help-command + :bind (("C-." . embark-act) ;; pick some comfortable binding + ("C-;" . embark-dwim) ;; good alternative: M-. + ("C-h B" . embark-bindings) + ([remap describe-bindings] . embark-bindings) + :map minibuffer-local-map + ("M-." . my-embark-preview)) + :init + ;; Optionally replace the key help with a completing-read interface + (setq prefix-help-command #'embark-prefix-help-command) + :config + (with-no-warnings + ;; Manual preview for non-Consult commands using Embark + (defun my-embark-preview () + "Previews candidate in vertico buffer, unless it's a consult command." + (interactive) + (unless (bound-and-true-p consult--preview-function) + (save-selected-window + (let ((embark-quit-after-action nil)) + (embark-dwim))))) + + ;; Hide the mode line of the Embark live/completions buffers + (add-to-list 'display-buffer-alist + '("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*" + nil + (window-parameters (mode-line-format . none)))) + + (with-eval-after-load 'which-key + (defun embark-which-key-indicator () + "An embark indicator that displays keymaps using which-key. +The which-key help message will show the type and value of the +current target followed by an ellipsis if there are further +targets." + (lambda (&optional keymap targets prefix) + (if (null keymap) + (which-key--hide-popup-ignore-command) + (which-key--show-keymap + (if (eq (plist-get (car targets) :type) 'embark-become) + "Become" + (format "Act on %s '%s'%s" + (plist-get (car targets) :type) + (embark--truncate-target (plist-get (car targets) :target)) + (if (cdr targets) "…" ""))) + (if prefix + (pcase (lookup-key keymap prefix 'accept-default) + ((and (pred keymapp) km) km) + (_ (key-binding prefix 'accept-default))) + keymap) + nil nil t (lambda (binding) + (not (string-suffix-p "-argument" (cdr binding)))))))) + + (setq embark-indicators + '(embark-which-key-indicator + embark-highlight-indicator + embark-isearch-highlight-indicator)) + + (defun embark-hide-which-key-indicator (fn &rest args) + "Hide the which-key indicator immediately when using the completing-read prompter." + (which-key--hide-popup-ignore-command) + (let ((embark-indicators + (remq #'embark-which-key-indicator embark-indicators))) + (apply fn args))) + + (advice-add #'embark-completing-read-prompter + :around #'embark-hide-which-key-indicator)))) + +(use-package embark-consult + :bind (:map minibuffer-mode-map + ("C-c C-o" . embark-export)) + :hook (embark-collect-mode . consult-preview-at-point-mode)) + + +(provide 'init-completion) +;;; init-completion.el ends here. diff --git a/lisp/interface/init-highlight.el b/lisp/interface/init-highlight.el index b056577..b3b5047 100644 --- a/lisp/interface/init-highlight.el +++ b/lisp/interface/init-highlight.el @@ -101,24 +101,7 @@ (advice-add #'macrostep-collapse :after (lambda (&rest _) (when (derived-mode-p 'prog-mode 'yaml-mode) - (highlight-indent-guides-mode 1))))) - - ;; Don't display indentations in `swiper' - ;; https://github.com/DarthFennec/highlight-indent-guides/issues/40 - (with-eval-after-load 'ivy - (defun my-ivy-cleanup-indentation (str) - "Clean up indentation highlighting in ivy minibuffer." - (let ((pos 0) - (next 0) - (limit (length str)) - (prop 'highlight-indent-guides-prop)) - (while (and pos next) - (setq next (text-property-not-all pos limit prop nil str)) - (when next - (setq pos (text-property-any next limit prop nil str)) - (ignore-errors - (remove-text-properties next pos '(display nil face nil) str)))))) - (advice-add #'ivy-cleanup-string :after #'my-ivy-cleanup-indentation)))) + (highlight-indent-guides-mode 1))))))) ;; Colorize color names in buffers (use-package rainbow-mode diff --git a/lisp/interface/init-ibuffer.el b/lisp/interface/init-ibuffer.el index 6985744..5f627b2 100644 --- a/lisp/interface/init-ibuffer.el +++ b/lisp/interface/init-ibuffer.el @@ -22,19 +22,7 @@ (use-package ibuffer :ensure nil :bind ("C-x C-b" . ibuffer) - :init (setq ibuffer-filter-group-name-face '(:inherit (font-lock-string-face bold))) - :config - (with-eval-after-load 'counsel - (with-no-warnings - (defun my-ibuffer-find-file () - (interactive) - (let ((default-directory (let ((buf (ibuffer-current-buffer))) - (if (buffer-live-p buf) - (with-current-buffer buf - default-directory) - default-directory)))) - (counsel-find-file default-directory))) - (advice-add #'ibuffer-find-file :override #'my-ibuffer-find-file)))) + :init (setq ibuffer-filter-group-name-face '(:inherit (font-lock-string-face bold)))) ;; Display icons for buffers (use-package nerd-icons-ibuffer diff --git a/lisp/interface/init-interface.el b/lisp/interface/init-interface.el index 9055ce1..8300df5 100644 --- a/lisp/interface/init-interface.el +++ b/lisp/interface/init-interface.el @@ -200,10 +200,30 @@ (grip-browse-preview) (message "Not in preview")) "browse preview" :exit t) - ("z h" (counsel-set-variable 'doom-modeline-height) "set height" :exit t) - ("z w" (counsel-set-variable 'doom-modeline-bar-width) "set bar width" :exit t) - ("z g" (counsel-set-variable 'doom-modeline-github-interval) "set github interval" :exit t) - ("z n" (counsel-set-variable 'doom-modeline-gnus-timer) "set gnus interval" :exit t)))) + ("z h" (read-from-minibuffer + "Eval: " + (format "(setq %s %s)" + 'doom-modeline-height + (symbol-value 'doom-modeline-height))) + "set height" :exit t) + ("z w" (read-from-minibuffer + "Eval: " + (format "(setq %s %s)" + 'doom-modeline-bar-width + (symbol-value 'doom-modeline-bar-width))) + "set bar width" :exit t) + ("z g" (read-from-minibuffer + "Eval: " + (format "(setq %s %s)" + 'doom-modeline-github-interval + (symbol-value 'doom-modeline-github-interval))) + "set github interval" :exit t) + ("z n" (read-from-minibuffer + "Eval: " + (format "(setq %s %s)" + 'doom-modeline-gnus-timer + (symbol-value 'doom-modeline-gnus-timer))) + "set gnus interval" :exit t)))) :init (setq doom-modeline-icon emacs-icon diff --git a/lisp/interface/init-ivy.el b/lisp/interface/init-ivy.el deleted file mode 100644 index cf89c80..0000000 --- a/lisp/interface/init-ivy.el +++ /dev/null @@ -1,531 +0,0 @@ -;;; init-ivy.el --- Initialize `ivy' configurations -*- lexical-binding: t -*- -;; -;; Author: Luiz Tagliaferro -;; URL: https://luiznux.com -;; This file is free software :) -;; -;;; Commentary: -;; -;; -;; ██╗██╗ ██╗██╗ ██╗ -;; ██║██║ ██║╚██╗ ██╔╝ -;; ██║██║ ██║ ╚████╔╝ -;; ██║╚██╗ ██╔╝ ╚██╔╝ -;; ██║ ╚████╔╝ ██║ -;; ╚═╝ ╚═══╝ ╚═╝ -;; -;; More info : https://github.com/abo-abo/swiper -;; -;;; Code: - -(eval-when-compile - (require 'init-constants) - (require 'init-custom)) - -(use-package counsel - :diminish ivy-mode counsel-mode - :commands (ivy-immediate-done - ivy-alt-done - ivy-set-occur - ivy-next-line - ivy-previous-line) - :preface - (defun config-ivy-with-empty-ivy-extra-directories (f &rest args) - (let ((ivy-extra-directories nil)) - (apply f args))) - - :custom-face - (ivy-current-match ((t (:inherit ivy-current-match)))) - (ivy-minibuffer-match-face-1 ((t (:foreground "dimgray" :distant-foreground unspecified :background unspecified)))) - (ivy-minibuffer-match-face-2 ((t (:distant-foreground unspecified :background unspecified)))) - (ivy-minibuffer-match-face-3 ((t (:distant-foreground unspecified :background unspecified)))) - (ivy-minibuffer-match-face-4 ((t (:distant-foreground unspecified :background unspecified)))) - - :bind (("C-s" . swiper-isearch) - ("C-S-s" . swiper-all) - - ("C-c C-r" . ivy-resume) - ("C-c v p" . ivy-push-view) - ("C-c v o" . ivy-pop-view) - ("C-c v ." . ivy-switch-view) - - :map counsel-mode-map - ([remap swiper] . counsel-grep-or-swiper) - ([remap swiper-backward] . counsel-grep-or-swiper-backward) - ([remap dired] . counsel-dired) - ([remap set-variable] . counsel-set-variable) - ([remap insert-char] . counsel-unicode-char) - ([remap recentf-open-files] . counsel-recentf) - ([remap org-capture] . counsel-org-capture) - - ("C-x j" . counsel-mark-ring) - ("C-h F" . counsel-faces) - - ("C-c B" . counsel-bookmarked-directory) - ("C-c O" . counsel-find-file-extern) - ("C-c P" . counsel-package) - ("C-c R" . counsel-list-processes) - ("C-c U" . counsel-unicode-char) - - ("C-c f" . counsel-projectile-rg) - ("C-c g" . counsel-git) - ("C-c h" . counsel-command-history) - ("C-c i" . counsel-imenu) - ("C-c j" . counsel-git-grep) - ("C-c l" . counsel-git-log) - ("C-c o" . counsel-outline) - ("C-c r" . counsel-recentf) - ("C-c y" . counsel-yank-pop) - ("C-c z" . counsel-fzf) - - ("C-c c B" . counsel-bookmarked-directory) - ("C-c c F" . counsel-faces) - ("C-c c L" . counsel-load-library) - ("C-c c K" . counsel-ace-link) - ("C-c c O" . counsel-find-file-extern) - ("C-c c P" . counsel-package) - ("C-c c R" . counsel-list-processes) - - ("C-c c a" . counsel-apropos) - ("C-c c e" . counsel-colors-emacs) - ("C-c c f" . counsel-find-library) - ("C-c c g" . counsel-grep) - ("C-c c h" . counsel-command-history) - ("C-c c i" . counsel-git) - ("C-c c j" . counsel-git-grep) - ("C-c c l" . counsel-git-log) - ("C-c c m" . counsel-minibuffer-history) - ("C-c c o" . counsel-outline) - - ("C-c c p" . counsel-pt) - ("C-c c r" . counsel-rg) - ("C-c c s" . counsel-ag) - ("C-c c z" . counsel-fzf) - ("C-c c t" . counsel-load-theme) - ("C-c c u" . counsel-unicode-char) - ("C-c c w" . counsel-colors-web) - ("C-c c v" . counsel-set-variable) - - ;; Evil mapping for ivy-minibuffer - :map ivy-minibuffer-map - ("M-j" . 'ivy-next-line) - ("M-k" . 'ivy-previous-line) - ("M-d" . ivy-scroll-up-command) - ("M-u" . ivy-scroll-down-command) - ("M-<" . ivy-beginning-of-buffer) - ("M->" . ivy-end-of-buffer) - ("C-w" . ivy-yank-word) - ;; Use C-j for immediate termination with the current value, and RET - ;; for continuing completion for that directory. This is the ido - ;; behaviour. - ("C-j" . ivy-immediate-done) - ("RET" . ivy-alt-done) - - :map counsel-find-file-map - ("C-h" . counsel-up-directory) - - :map swiper-map - ("M-s" . swiper-isearch-toggle) - ("M-%" . swiper-query-replace) - - :map isearch-mode-map - ("M-s" . swiper-isearch-toggle)) - - :hook ((after-init . ivy-mode) - (ivy-mode . counsel-mode)) - - :init - (setq enable-recursive-minibuffers t ; Allow commands in minibuffers - ivy-height 13 - ivy-use-selectable-prompt t - ivy-use-virtual-buffers t ; Enable bookmarks and recentf - ivy-fixed-height-minibuffer t - ivy-count-format "(%d/%d) " - ivy-ignore-buffers '("\\` " "\\`\\*tramp/" "\\`\\*xref" "\\`\\*helpful .+\\*" - "\\`\\*.+-posframe-buffer\\*" "\\` ?\\*company-.+\\*" - "\\`flycheck_.+") - ivy-on-del-error-function #'ignore - ivy-initial-inputs-alist nil) - - ;; Set use `ivy--regex-fuzzy' for some counsel modes, otherwise use - ;; `ivy--regex-plus' - (setq ivy-re-builders-alist - '((counsel-M-x . ivy--regex-fuzzy) - (counsel-find-file . ivy--regex-fuzzy) - (t . ivy--regex-plus))) - - ;; Set minibuffer height for different commands - (setq ivy-height-alist '((counsel-evil-registers . 5) - (counsel-yank-pop . 8) - (counsel-git-log . 4) - (swiper . 15) - (counsel-projectile-rg . 15))) - - (setq swiper-action-recenter t) - - (setq counsel-find-file-at-point t - counsel-preselect-current-file t - counsel-yank-pop-separator "\n────────\n") - (add-hook 'counsel-grep-post-action-hook #'recenter) - - ;; Use the faster search tools - (cond - ((executable-find "ugrep") - (setq counsel-grep-base-command "ugrep --color=never -n -e '%s' '%s'")) - ((executable-find "rg") - (setq counsel-grep-base-command "rg -S --no-heading --line-number --color never '%s' '%s'"))) - - (when (executable-find "fd") - (setq counsel-fzf-cmd - "fd --type f --hidden --follow --exclude .git --color never '%s'")) - - ;; Be compatible with `gls' - (when (and sys/macp (executable-find "gls")) - (setq counsel-find-file-occur-use-find nil - counsel-find-file-occur-cmd - "gls -a | grep -i -E '%s' | tr '\\n' '\\0' | xargs -0 gls -d --group-directories-first")) - - :config - ;; ignore Dotfiles and Lockfiles files - (setq counsel-find-file-ignore-regexp - "\\(?:^[#.]\\)\\|\\(?:[#~]$\\)\\|\\(?:^Icon?\\)") - - ;; Do not show extra directories when finding files. - (setq ivy-extra-directories '(".")) - (advice-add #'counsel-find-file :around #'config-ivy-with-empty-ivy-extra-directories) - - (with-no-warnings - ;; persist views - (with-eval-after-load 'savehist - (add-to-list 'savehist-additional-variables 'ivy-views)) - - ;; Highlight the selected item - (defun my-ivy-format-function (cands) - "Transform CANDS into a string for minibuffer." - (if (display-graphic-p) - (ivy-format-function-line cands) - (ivy-format-function-arrow cands))) - (setf (alist-get 't ivy-format-functions-alist) #'my-ivy-format-function) - - ;; Pre-fill search keywords - ;; @see https://www.reddit.com/r/emacs/comments/b7g1px/withemacs_execute_commands_like_marty_mcfly/ - (defconst my-ivy-fly-commands - '(query-replace-regexp - flush-lines keep-lines ivy-read - swiper swiper-backward swiper-all - swiper-isearch swiper-isearch-backward - lsp-ivy-workspace-symbol lsp-ivy-global-workspace-symbol - counsel-grep-or-swiper counsel-grep-or-swiper-backward - counsel-grep counsel-ack counsel-ag counsel-rg counsel-pt)) - - (defconst my-ivy-fly-back-commands - '(self-insert-command - ivy-forward-char ivy-delete-char delete-forward-char kill-word kill-sexp - end-of-line mwim-end-of-line mwim-end-of-code-or-line mwim-end-of-line-or-code - yank ivy-yank-word ivy-yank-char ivy-yank-symbol counsel-yank-pop)) - - (defvar-local my-ivy-fly--travel nil) - (defun my-ivy-fly-back-to-present () - (cond ((and (memq last-command my-ivy-fly-commands) - (equal (this-command-keys-vector) (kbd "M-p"))) - ;; repeat one time to get straight to the first history item - (setq unread-command-events - (append unread-command-events - (listify-key-sequence (kbd "M-p"))))) - ((or (memq this-command my-ivy-fly-back-commands) - (equal (this-command-keys-vector) (kbd "M-n"))) - (unless my-ivy-fly--travel - (delete-region (point) (point-max)) - (when (memq this-command '(ivy-forward-char - ivy-delete-char delete-forward-char - kill-word kill-sexp - end-of-line mwim-end-of-line - mwim-end-of-code-or-line - mwim-end-of-line-or-code)) - (insert (ivy-cleanup-string ivy-text)) - (when (memq this-command '(ivy-delete-char - delete-forward-char - kill-word kill-sexp)) - (beginning-of-line))) - (setq my-ivy-fly--travel t))))) - - (defun my-ivy-fly-time-travel () - (when (memq this-command my-ivy-fly-commands) - (insert (propertize - (save-excursion - (set-buffer (window-buffer (minibuffer-selected-window))) - (ivy-thing-at-point)) - 'face 'shadow)) - (add-hook 'pre-command-hook 'my-ivy-fly-back-to-present nil t) - (beginning-of-line))) - - (add-hook 'minibuffer-setup-hook #'my-ivy-fly-time-travel) - (add-hook 'minibuffer-exit-hook - (lambda () - (remove-hook 'pre-command-hook 'my-ivy-fly-back-to-present t))) - - ;; - ;; Improve search experience of `swiper' and `counsel' - ;; - (defun my-ivy-switch-to-swiper (&rest _) - "Switch to `swiper' with the current input." - (ivy-quit-and-run (swiper ivy-text))) - - (defun my-ivy-switch-to-swiper-isearch (&rest _) - "Switch to `swiper-isearch' with the current input." - (ivy-quit-and-run (swiper-isearch ivy-text))) - - (defun my-ivy-switch-to-swiper-all (&rest _) - "Switch to `swiper-all' with the current input." - (ivy-quit-and-run (swiper-all ivy-text))) - - (defun my-ivy-switch-to-rg-dwim (&rest _) - "Switch to `rg-dwim' with the current input." - (interactive) - (ivy-exit-with-action #'rg-dwim)) - - (defun my-ivy-switch-to-counsel-rg (&rest _) - "Switch to `counsel-rg' with the current input." - (ivy-quit-and-run (counsel-rg ivy-text default-directory))) - - (defun my-ivy-switch-to-counsel-git-grep (&rest _) - "Switch to `counsel-git-grep' with the current input." - (ivy-quit-and-run (counsel-git-grep ivy-text default-directory))) - - (defun my-ivy-switch-to-counsel-find-file (&rest _) - "Switch to `counsel-find-file' with the current input." - (ivy-quit-and-run (counsel-find-file ivy-text))) - - (defun my-ivy-switch-to-counsel-fzf (&rest _) - "Switch to `counsel-fzf' with the current input." - (ivy-quit-and-run (counsel-fzf ivy-text default-directory))) - - (defun my-ivy-switch-to-counsel-git (&rest _) - "Switch to `counsel-git' with the current input." - (ivy-quit-and-run (counsel-git ivy-text))) - - (defun my-ivy-switch-to-list-bookmarks (&rest _) - "Switch to `list-bookmarks'." - (ivy-quit-and-run (call-interactively #'list-bookmarks))) - - (defun my-ivy-switch-to-list-colors (&rest _) - "Switch to `list-colors-display'." - (ivy-quit-and-run (list-colors-display))) - - (defun my-ivy-switch-to-list-packages (&rest _) - "Switch to `list-packages'." - (ivy-quit-and-run (list-packages))) - - (defun my-ivy-switch-to-list-processes (&rest _) - "Switch to `list-processes'." - (ivy-quit-and-run (list-processes))) - - (defun my-ivy-copy-library-path (lib) - "Copy the full path of LIB." - (let ((path (find-library-name lib))) - (kill-new path) - (message "Copied path: \"%s\"." path))) - - ;; @see https://emacs-china.org/t/swiper-swiper-isearch/9007/12 - (defun my-swiper-toggle-counsel-rg () - "Toggle `counsel-rg' and `swiper'/`swiper-isearch' with the current input." - (interactive) - (if (memq (ivy-state-caller ivy-last) '(swiper swiper-isearch)) - (my-ivy-switch-to-counsel-rg) - (my-ivy-switch-to-swiper-isearch))) - (bind-key "" #'my-swiper-toggle-counsel-rg swiper-map) - (bind-key "" #'my-swiper-toggle-counsel-rg counsel-ag-map) - - (with-eval-after-load 'rg - (bind-key "" #'my-ivy-switch-to-rg-dwim swiper-map) - (bind-key "" #'my-ivy-switch-to-rg-dwim counsel-ag-map)) - - (defun my-swiper-toggle-swiper-isearch () - "Toggle `swiper' and `swiper-isearch' with the current input." - (interactive) - (ivy-quit-and-run - (if (eq (ivy-state-caller ivy-last) 'swiper-isearch) - (swiper ivy-text) - (swiper-isearch ivy-text)))) - (bind-key "" #'my-swiper-toggle-swiper-isearch swiper-map) - - (defun my-counsel-find-file-toggle-fzf () - "Toggle `counsel-fzf' with the current `counsel-find-file' input." - (interactive) - (ivy-quit-and-run - (counsel-fzf (or ivy-text "") default-directory))) - (bind-key "" #'my-counsel-find-file-toggle-fzf counsel-find-file-map) - - (defun my-counsel-toggle () - "Toggle `counsel' commands and original commands." - (interactive) - (pcase (ivy-state-caller ivy-last) - ('counsel-bookmark (my-ivy-switch-to-list-bookmarks)) - ('counsel-colors-emacs (my-ivy-switch-to-list-colors)) - ('counsel-colors-web (my-ivy-switch-to-list-colors)) - ('counsel-list-processes (my-ivy-switch-to-list-processes)) - ('counsel-package (my-ivy-switch-to-list-packages)) - (_ (ignore)))) - (bind-key "" #'my-counsel-toggle ivy-minibuffer-map) - - ;; More actions - (ivy-add-actions - #'swiper-isearch - '(("r" my-ivy-switch-to-counsel-rg "rg") - ("d" my-ivy-switch-to-rg-dwim "rg dwim") - ("s" my-ivy-switch-to-swiper "swiper") - ("a" my-ivy-switch-to-swiper-all "swiper all"))) - - (ivy-add-actions - #'swiper - '(("r" my-ivy-switch-to-counsel-rg "rg") - ("d" my-ivy-switch-to-rg-dwim "rg dwim") - ("s" my-ivy-switch-to-swiper-isearch "swiper isearch") - ("a" my-ivy-switch-to-swiper-all "swiper all"))) - - (ivy-add-actions - #'swiper-all - '(("g" my-ivy-switch-to-counsel-git-grep "git grep") - ("r" my-ivy-switch-to-counsel-rg "rg") - ("d" my-ivy-switch-to-rg-dwim "rg dwim") - ("s" my-swiper-toggle-swiper-isearch "swiper isearch") - ("S" my-ivy-switch-to-swiper "swiper"))) - - (ivy-add-actions - #'counsel-rg - '(("s" my-ivy-switch-to-swiper-isearch "swiper isearch") - ("S" my-ivy-switch-to-swiper "swiper") - ("a" my-ivy-switch-to-swiper-all "swiper all") - ("d" my-ivy-switch-to-rg-dwim "rg dwim"))) - - (ivy-add-actions - #'counsel-git-grep - '(("s" my-ivy-switch-to-swiper-isearch "swiper isearch") - ("S" my-ivy-switch-to-swiper "swiper") - ("r" my-ivy-switch-to-rg-dwim "rg") - ("d" my-ivy-switch-to-rg-dwim "rg dwim") - ("a" my-ivy-switch-to-swiper-all "swiper all"))) - - (ivy-add-actions - #'counsel-find-file - '(("g" my-ivy-switch-to-counsel-git "git") - ("z" my-ivy-switch-to-counsel-fzf "fzf"))) - - (ivy-add-actions - #'counsel-git - '(("f" my-ivy-switch-to-counsel-find-file "find file") - ("z" my-ivy-switch-to-counsel-fzf "fzf"))) - - (ivy-add-actions - 'counsel-fzf - '(("f" my-ivy-switch-to-counsel-find-file "find file") - ("g" my-ivy-switch-to-counsel-git "git"))) - - (ivy-add-actions - 'counsel-find-library - '(("p" my-ivy-copy-library-path "copy path"))) - - (ivy-add-actions - 'counsel-load-library - '(("p" my-ivy-copy-library-path "copy path"))) - - (ivy-add-actions - #'counsel-bookmark - '(("l" my-ivy-switch-to-list-bookmarks "list"))) - - (ivy-add-actions - #'counsel-colors-emacs - '(("l" my-ivy-switch-to-list-colors "list"))) - - (ivy-add-actions - #'counsel-colors-web - '(("l" my-ivy-switch-to-list-colors "list"))) - - (ivy-add-actions - #'counsel-package - '(("l" my-ivy-switch-to-list-packages "list packages"))) - - (ivy-add-actions - #'counsel-list-processes - '(("l" my-ivy-switch-to-list-processes "list")))) - - - ;; Enhance M-x - (use-package amx - :init (setq amx-history-length 20)) - - ;; Avy integration - (use-package ivy-avy - :bind (:map ivy-minibuffer-map - ("C-'" . ivy-avy))) - - ;; Integrate yasnippet - (use-package ivy-yasnippet - :bind ("C-c C-y" . ivy-yasnippet)) - - ;; Quick launch apps - (cond - (sys/linux-x-p - (bind-key "s-" #'counsel-linux-app counsel-mode-map)) - (sys/macp - (use-package counsel-osx-app - :bind (:map counsel-mode-map - ("s-" . counsel-osx-app))))) - - ;; Tramp ivy interface - (use-package counsel-tramp - :bind (:map counsel-mode-map - ("C-c c T" . counsel-tramp)))) - -;; Use Ivy to open recent directories -(use-package ivy-dired-history - :demand t - :after dired - :defines (savehist-additional-variables desktop-globals-to-save) - :bind (:map dired-mode-map - ("," . dired)) - :init - (with-eval-after-load 'savehist - (add-to-list 'savehist-additional-variables 'ivy-dired-history-variable)) - (with-eval-after-load 'desktop - (add-to-list 'desktop-globals-to-save 'ivy-dired-history-variable))) - -;; `projectile' integration -(use-package counsel-projectile - :hook (counsel-mode . counsel-projectile-mode) - :init - (setq counsel-projectile-grep-initial-input '(ivy-thing-at-point)) - (when (executable-find "ugrep") - (setq counsel-projectile-grep-base-command "ugrep --color=never -rnEI %s"))) - -;; More friendly display transformer for Ivy -;; Enable before`ivy-rich-mode' for better performance -(use-package nerd-icons-ivy-rich - :hook ((ivy-mode . nerd-icons-ivy-rich-mode) - (counsel-mode . ivy-rich-mode) - (counsel-projectile-mode . ivy-rich-mode) ; MUST after `counsel-projectile' - (ivy-rich-mode . ivy-rich-project-root-cache-mode) - (ivy-rich-mode . (lambda () - "Use abbreviate in `ivy-rich-mode'." - (setq ivy-virtual-abbreviate - (or (and ivy-rich-mode 'abbreviate) 'name))))) - :init - ;; For better performance - (setq ivy-rich-parse-remote-buffer nil) - (setq nerd-icons-ivy-rich-icon emacs-icon) - :config - (plist-put nerd-icons-ivy-rich-display-transformers-list - 'centaur-load-theme - '(:columns - ((nerd-icons-ivy-rich-theme-icon) - (ivy-rich-candidate)) - :delimiter "\t")) - (nerd-icons-ivy-rich-reload)) - -;; flx is used as the fuzzy-matching indexer backend for ivy. -(use-package flx - :after ivy) - - -(provide 'init-ivy) -;;; init-ivy.el ends here diff --git a/lisp/interface/init-window.el b/lisp/interface/init-window.el index 0e88f95..a041851 100644 --- a/lisp/interface/init-window.el +++ b/lisp/interface/init-window.el @@ -74,7 +74,6 @@ gnus-article-mode devdocs-mode grep-mode occur-mode rg-mode deadgrep-mode ag-mode pt-mode - ivy-occur-mode ivy-occur-grep-mode osx-dictionary-mode "^\\*Process List\\*$" process-menu-mode diff --git a/lisp/org-config/init-org.el b/lisp/org-config/init-org.el index 02040bd..8b9d3eb 100644 --- a/lisp/org-config/init-org.el +++ b/lisp/org-config/init-org.el @@ -220,9 +220,6 @@ prepended to the element after the #+HEADER: tag." (use-package ox-gfm :init (add-to-list 'org-export-backends 'gfm)) - (with-eval-after-load 'counsel - (bind-key [remap org-set-tags-command] #'counsel-org-tag org-mode-map)) - (use-package verb :config (define-key org-mode-map (kbd "C-c C-r") verb-command-map))