branch: externals/vertico commit 407b9c11ffc697aab985865d411b1d345ea7950e Author: Daniel Mendler <m...@daniel-mendler.de> Commit: Daniel Mendler <m...@daniel-mendler.de>
Require the compat library --- extensions/vertico-flat.el | 12 +++++------- extensions/vertico-grid.el | 16 +++++++--------- extensions/vertico-quick.el | 2 +- extensions/vertico-reverse.el | 28 +++++++++++++-------------- vertico.el | 44 +++++++++++++++++++++---------------------- 5 files changed, 48 insertions(+), 54 deletions(-) diff --git a/extensions/vertico-flat.el b/extensions/vertico-flat.el index 86303032cb..fa483a60d1 100644 --- a/extensions/vertico-flat.el +++ b/extensions/vertico-flat.el @@ -61,12 +61,10 @@ :type 'plist :group 'vertico) -(defvar vertico-flat-map - (let ((map (make-sparse-keymap))) - (define-key map [remap left-char] #'vertico-previous) - (define-key map [remap right-char] #'vertico-next) - map) - "Additional keymap activated in flat mode.") +(defvar-keymap vertico-flat-map + :doc "Additional keymap activated in flat mode." + "<remap> <left-char>" #'vertico-previous + "<remap> <right-char>" #'vertico-next) (defun vertico-flat--display-candidates (candidates) "Display CANDIDATES horizontally." @@ -99,7 +97,7 @@ (> width 0) (> count 0)) (let ((cand (car candidates))) (setq cand (car (funcall vertico--highlight (list cand)))) - (when (string-match-p "\n" cand) + (when (string-search "\n" cand) (setq cand (vertico--truncate-multiline cand width))) (setq cand (string-trim (replace-regexp-in-string diff --git a/extensions/vertico-grid.el b/extensions/vertico-grid.el index 1e79e0cf02..6497410036 100644 --- a/extensions/vertico-grid.el +++ b/extensions/vertico-grid.el @@ -66,14 +66,12 @@ When scrolling beyond this limit, candidates may be truncated." :type 'integer :group 'vertico) -(defvar vertico-grid-map - (let ((map (make-sparse-keymap))) - (define-key map [remap left-char] #'vertico-grid-left) - (define-key map [remap right-char] #'vertico-grid-right) - (define-key map [remap scroll-down-command] #'vertico-grid-scroll-down) - (define-key map [remap scroll-up-command] #'vertico-grid-scroll-up) - map) - "Additional keymap activated in grid mode.") +(defvar-keymap vertico-grid-map + :doc "Additional keymap activated in grid mode." + "<remap> <left-char>" #'vertico-grid-left + "<remap> <right-char>" #'vertico-grid-right + "<remap> <scroll-down-command>" #'vertico-grid-scroll-down + "<remap> <scroll-up-command>" #'vertico-grid-scroll-up) (defvar-local vertico-grid--columns vertico-grid-min-columns "Current number of grid columns.") @@ -96,7 +94,7 @@ When scrolling beyond this limit, candidates may be truncated." (cands (seq-map-indexed (lambda (cand index) (cl-incf index start) - (when (string-match-p "\n" cand) + (when (string-search "\n" cand) (setq cand (vertico--truncate-multiline cand width))) (truncate-string-to-width (string-trim diff --git a/extensions/vertico-quick.el b/extensions/vertico-quick.el index 6a0f95723f..173eec842b 100644 --- a/extensions/vertico-quick.el +++ b/extensions/vertico-quick.el @@ -109,7 +109,7 @@ TWO is non-nil if two keys should be displayed." (pcase-let ((`(,keys . ,events) (vertico-quick--keys first index start))) (setq list (nconc events list)) (if (bound-and-true-p vertico-flat-mode) - (setq keys (replace-regexp-in-string " " "" keys) + (setq keys (string-replace " " "" keys) cand (string-trim cand) cand (substring cand (min (length cand) (length keys)))) (setq keys (concat keys (make-string (max 1 (- (length prefix) 2)) ?\s)))) diff --git a/extensions/vertico-reverse.el b/extensions/vertico-reverse.el index 51cd73959b..d9ccca594b 100644 --- a/extensions/vertico-reverse.el +++ b/extensions/vertico-reverse.el @@ -38,21 +38,19 @@ (require 'vertico) -(defvar vertico-reverse-map - (let ((map (make-sparse-keymap))) - (define-key map [remap beginning-of-buffer] #'vertico-last) - (define-key map [remap minibuffer-beginning-of-buffer] #'vertico-last) - (define-key map [remap end-of-buffer] #'vertico-first) - (define-key map [remap scroll-down-command] #'vertico-scroll-up) - (define-key map [remap scroll-up-command] #'vertico-scroll-down) - (define-key map [remap next-line] #'vertico-previous) - (define-key map [remap previous-line] #'vertico-next) - (define-key map [remap next-line-or-history-element] #'vertico-previous) - (define-key map [remap previous-line-or-history-element] #'vertico-next) - (define-key map [remap backward-paragraph] #'vertico-next-group) - (define-key map [remap forward-paragraph] #'vertico-previous-group) - map) - "Additional keymap activated in reverse mode.") +(defvar-keymap vertico-reverse-map + :doc "Additional keymap activated in reverse mode." + "<remap> <beginning-of-buffer>" #'vertico-last + "<remap> <minibuffer-beginning-of-buffer>" #'vertico-last + "<remap> <end-of-buffer>" #'vertico-first + "<remap> <scroll-down-command>" #'vertico-scroll-up + "<remap> <scroll-up-command>" #'vertico-scroll-down + "<remap> <next-line>" #'vertico-previous + "<remap> <previous-line>" #'vertico-next + "<remap> <next-line-or-history-element>" #'vertico-previous + "<remap> <previous-line-or-history-element>" #'vertico-next + "<remap> <backward-paragraph>" #'vertico-next-group + "<remap> <forward-paragraph>" #'vertico-previous-group) (defun vertico-reverse--display-candidates (lines) "Display LINES in reverse." diff --git a/vertico.el b/vertico.el index d15e2a279a..addb244000 100644 --- a/vertico.el +++ b/vertico.el @@ -6,7 +6,7 @@ ;; Maintainer: Daniel Mendler <m...@daniel-mendler.de> ;; Created: 2021 ;; Version: 1.0 -;; Package-Requires: ((emacs "27.1")) +;; Package-Requires: ((emacs "27.1") (compat "29.1.1.0")) ;; Homepage: https://github.com/minad/vertico ;; This file is part of GNU Emacs. @@ -33,6 +33,7 @@ ;;; Code: +(require 'compat) (require 'seq) (eval-when-compile (require 'cl-lib) @@ -117,25 +118,24 @@ The value should lie between 0 and vertico-count/2." (defface vertico-current '((t :inherit highlight :extend t)) "Face used to highlight the currently selected candidate.") -(defvar vertico-map - (let ((map (make-composed-keymap nil minibuffer-local-map))) - (define-key map [remap beginning-of-buffer] #'vertico-first) - (define-key map [remap minibuffer-beginning-of-buffer] #'vertico-first) - (define-key map [remap end-of-buffer] #'vertico-last) - (define-key map [remap scroll-down-command] #'vertico-scroll-down) - (define-key map [remap scroll-up-command] #'vertico-scroll-up) - (define-key map [remap next-line] #'vertico-next) - (define-key map [remap previous-line] #'vertico-previous) - (define-key map [remap next-line-or-history-element] #'vertico-next) - (define-key map [remap previous-line-or-history-element] #'vertico-previous) - (define-key map [remap backward-paragraph] #'vertico-previous-group) - (define-key map [remap forward-paragraph] #'vertico-next-group) - (define-key map [remap exit-minibuffer] #'vertico-exit) - (define-key map [remap kill-ring-save] #'vertico-save) - (define-key map "\M-\r" #'vertico-exit-input) - (define-key map "\t" #'vertico-insert) - map) - "Vertico minibuffer keymap derived from `minibuffer-local-map'.") +(defvar-keymap vertico-map + :doc "Vertico minibuffer keymap derived from `minibuffer-local-map'." + :parent minibuffer-local-map + "<remap> <beginning-of-buffer>" #'vertico-first + "<remap> <minibuffer-beginning-of-buffer>" #'vertico-first + "<remap> <end-of-buffer>" #'vertico-last + "<remap> <scroll-down-command>" #'vertico-scroll-down + "<remap> <scroll-up-command>" #'vertico-scroll-up + "<remap> <next-line>" #'vertico-next + "<remap> <previous-line>" #'vertico-previous + "<remap> <next-line-or-history-element>" #'vertico-next + "<remap> <previous-line-or-history-element>" #'vertico-previous + "<remap> <backward-paragraph>" #'vertico-previous-group + "<remap> <forward-paragraph>" #'vertico-next-group + "<remap> <exit-minibuffer>" #'vertico-exit + "<remap> <kill-ring-save>" #'vertico-save + "M-RET" #'vertico-exit-input + "TAB" #'vertico-insert) (defvar-local vertico--highlight #'identity "Deferred candidate highlighting function.") @@ -198,7 +198,7 @@ The value should lie between 0 and vertico-count/2." (and (>= (length elem) base-size) (eq t (compare-strings base 0 base-size elem 0 base-size)))) (let ((file-sep (and (eq minibuffer-history-variable 'file-name-history) - (string-match-p "/" elem base-size)))) + (string-search "/" elem base-size)))) ;; Drop base string from history elements & special file handling. (when (or (> base-size 0) file-sep) (setq elem (substring elem base-size (and file-sep (1+ file-sep))))) @@ -532,7 +532,7 @@ The function is configured by BY, BSIZE, BINDEX, BPRED and PRED." (pcase (car line) (`(,index ,cand ,prefix ,suffix) (setq start (or start index)) - (when (string-match-p "\n" cand) + (when (string-search "\n" cand) (setq cand (vertico--truncate-multiline cand max-width))) (setcar line (vertico--format-candidate cand prefix suffix index start)))))) lines))