branch: externals/vertico commit f0a2577ea221cb3adb3bc48de4205030700fc738 Author: Daniel Mendler <m...@daniel-mendler.de> Commit: Daniel Mendler <m...@daniel-mendler.de>
Add horizontico extension --- README.org | 14 ++++---- extensions/horizontico.el | 82 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 7 deletions(-) diff --git a/README.org b/README.org index 5f3edf6..3c17959 100644 --- a/README.org +++ b/README.org @@ -152,6 +152,7 @@ We maintain a few small extension packages to Vertico in this repository in the subdirectory [[https://github.com/minad/vertico/tree/main/extensions][extensions/]]. Currently these extensions are available: + - [[https://github.com/minad/vertico/blob/main/extensions/horizontico.el][horizontico.el]]: HORIZONTal Interactive COmpletion - [[https://github.com/minad/vertico/blob/main/extensions/vertico-buffer.el][vertico-buffer.el]]: Offers =vertico-buffer-mode= to display Vertico in a separate buffer - [[https://github.com/minad/vertico/blob/main/extensions/vertico-ido.el][vertico-ido.el]]: Commands for Ido-like directory navigation - [[https://github.com/minad/vertico/blob/main/extensions/vertico-repeat.el][vertico-repeat.el]]: The command =vertico-repeate= repeats the last completion session @@ -212,13 +213,12 @@ with Emacs. There are at least two other interactive completion UIs, which follow a similar philosophy: - - [[https://github.com/raxod502/selectrum][Selectrum]]: Selectrum has a similar UI as Vertico. Vertico additionally has - the ability to cycle over candidates and offers more commands for grouping - support. On the other hand, Selectrum supports Avy-style quick keys and a - horizontal display. Furthermore Selectrum is significantly more complex and - not fully compatible with every Emacs completion command ([[https://github.com/raxod502/selectrum/issues/481][Issue #481]]), since - it uses its own filtering infrastructure, which deviates from the standard - Emacs completion facilities. + - [[https://github.com/raxod502/selectrum][Selectrum]]: Selectrum has a similar UI as Vertico. Selectrum is significantly + more complex and not fully compatible with every Emacs completion command + ([[https://github.com/raxod502/selectrum/issues/481][Issue #481]]), since it uses its own filtering infrastructure, which deviates + from the standard Emacs completion facilities. Selectrum supports additional + Avy-style quick keys. Vertico additionally has the ability to cycle over + candidates and offers more commands for grouping support. - [[https://github.com/oantolin/icomplete-vertical][Icomplete-vertical]]: This package enhances the Emacs builtin Icomplete with a vertical display. In contrast to Vertico, the candidates are rotated such that the current candidate always appears at the top. From my perspective, diff --git a/extensions/horizontico.el b/extensions/horizontico.el new file mode 100644 index 0000000..856d186 --- /dev/null +++ b/extensions/horizontico.el @@ -0,0 +1,82 @@ +;;; horizontico.el --- HORIZONTal Interactive COmpletion -*- lexical-binding: t -*- + +;; Copyright (C) 2021 Free Software Foundation, Inc. + +;; Version: 0.1 + +;; This file is part of GNU Emacs. + +;; This program is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <http://www.gnu.org/licenses/>. + +;;; Commentary: + +;; This package is a Vertico extension providing a horizontal display. + +;;; Code: + +(require 'vertico) + +(defvar horizontico--orig-group-format nil) +(defvar horizontico--orig-count nil) + +(defun horizontico--display (candidates) + "Display CANDIDATES horizontally." + (move-overlay vertico--candidates-ov (point-max) (point-max)) + (when (>= vertico--index 0) + (setq candidates + (seq-drop-while (lambda (cand) + (let ((face (get-text-property 0 'face cand))) + (not (if (listp face) + (memq 'vertico-current face) + (eq 'vertico-current face))))) + candidates))) + (setq candidates + (seq-map-indexed (lambda (cand idx) + (replace-regexp-in-string + "\\` +" "" + (replace-regexp-in-string + "[ \t]+" (if (= idx 0) #(" " 0 1 (face vertico-current)) " ") + (substring cand 0 -1)))) + candidates)) + (overlay-put + vertico--candidates-ov 'after-string + (concat #(" " 0 1 (cursor t)) + (if candidates + (concat "{" (string-join candidates " | ") "}") + "[No match]")))) + +(defun horizontico--disable-annotations (_ candidates) + "Return CANDIDATES without adding annotations." + candidates) + +;;;###autoload +(define-minor-mode horizontico-mode + "HORIZONTal Interactive COmpletion." + :global t + (cond + (horizontico-mode + (setq horizontico--orig-group-format vertico-group-format + horizontico--orig-count vertico-count + vertico-group-format nil + vertico-count 20) + (advice-add #'vertico--affixate :override #'horizontico--disable-annotations) + (advice-add #'vertico--display-candidates :override #'horizontico--display)) + (t + (setq vertico-group-format horizontico--orig-group-format + vertico-count horizontico--orig-count) + (advice-remove #'vertico--affixate #'horizontico--disable-annotations) + (advice-remove #'vertico--display-candidates #'horizontico--display)))) + +(provide 'horizontico) +;;; horizontico.el ends here