config

Personal configuration.
git clone git://code.dwrz.net/config
Log | Files | Refs

vertico-unobtrusive.el (2757B)


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