vertico-unobtrusive.el (2736B)
1 ;;; vertico-unobtrusive.el --- Unobtrusive display for Vertico -*- lexical-binding: t -*- 2 3 ;; Copyright (C) 2021-2024 Free Software Foundation, Inc. 4 5 ;; Author: Daniel Mendler <mail@daniel-mendler.de> 6 ;; Maintainer: Daniel Mendler <mail@daniel-mendler.de> 7 ;; Created: 2021 8 ;; Package-Requires: ((emacs "28.1") (compat "30") (vertico "1.9")) 9 ;; URL: https://github.com/minad/vertico 10 11 ;; This file is part of GNU Emacs. 12 13 ;; This program is free software: you can redistribute it and/or modify 14 ;; it under the terms of the GNU General Public License as published by 15 ;; the Free Software Foundation, either version 3 of the License, or 16 ;; (at your option) any later version. 17 18 ;; This program is distributed in the hope that it will be useful, 19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 ;; GNU General Public License for more details. 22 23 ;; You should have received a copy of the GNU General Public License 24 ;; along with this program. If not, see <https://www.gnu.org/licenses/>. 25 26 ;;; Commentary: 27 28 ;; This package is a Vertico extension providing a unobtrusive 29 ;; display. The unobtrusive display only shows the topmost candidate 30 ;; and nothing else, it is a simple derivative of `vertico-flat-mode'. 31 ;; 32 ;; The mode can be enabled globally or via `vertico-multiform-mode' 33 ;; per command or completion category. Alternatively the unobtrusive 34 ;; display can be toggled temporarily with M-U if 35 ;; `vertico-multiform-mode' is enabled. 36 37 ;;; Code: 38 39 (require 'vertico-flat) 40 41 (defvar vertico-unobtrusive--restore nil) 42 43 ;;;###autoload 44 (define-minor-mode vertico-unobtrusive-mode 45 "Unobtrusive display for Vertico." 46 :global t :group 'vertico 47 (cond 48 ((and vertico-unobtrusive-mode (not vertico-unobtrusive--restore)) 49 (push '(vertico-current . default) (default-value 'face-remapping-alist)) 50 (setq vertico-unobtrusive--restore (cons vertico-count vertico-count-format) 51 vertico-count 1 52 vertico-count-format nil 53 vertico-flat-format `(:separator nil :ellipsis nil ,@vertico-flat-format))) 54 ((and (not vertico-unobtrusive-mode) vertico-unobtrusive--restore) 55 (cl-callf2 delete '(vertico-current . default) 56 (default-value 'face-remapping-alist)) 57 (setq vertico-count (car vertico-unobtrusive--restore) 58 vertico-count-format (cdr vertico-unobtrusive--restore) 59 vertico-flat-format (nthcdr 4 vertico-flat-format) 60 vertico-unobtrusive--restore nil))) 61 (vertico-flat-mode (if vertico-unobtrusive-mode 1 -1))) 62 63 (cl-defmethod vertico--setup :before (&context (vertico-unobtrusive-mode (eql t))) 64 (redisplay)) 65 66 (provide 'vertico-unobtrusive) 67 ;;; vertico-unobtrusive.el ends here