[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/vertico eb5d617 47/48: Improve candidate sanitization
From: |
Stefan Monnier |
Subject: |
[elpa] externals/vertico eb5d617 47/48: Improve candidate sanitization |
Date: |
Mon, 5 Apr 2021 10:54:48 -0400 (EDT) |
branch: externals/vertico
commit eb5d61764b19d1b137aedc9102455752e06c6b07
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Improve candidate sanitization
---
vertico.el | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/vertico.el b/vertico.el
index d36b5ea..e380f48 100644
--- a/vertico.el
+++ b/vertico.el
@@ -64,10 +64,10 @@
"Maximal number of candidates to show."
:type 'integer)
-(defcustom vertico-truncation
- (cons #("⤶" 0 1 (face vertico-truncation))
- #("…" 0 1 (face vertico-truncation)))
- "Truncation replacement strings."
+(defcustom vertico-multiline
+ (cons #("⤶" 0 1 (face vertico-multiline))
+ #("…" 0 1 (face vertico-multiline)))
+ "Replacements for multiline strings."
:type '(cons string string))
(defgroup vertico-faces nil
@@ -75,8 +75,8 @@
:group 'vertico
:group 'faces)
-(defface vertico-truncation '((t :inherit shadow))
- "Face used to highlight truncation characters.")
+(defface vertico-multiline '((t :inherit shadow))
+ "Face used to highlight multiline replacement characters.")
(defface vertico-group-title '((t :inherit shadow :slant italic))
"Face used for the title text of the candidate group headlines.")
@@ -280,13 +280,13 @@
vertico--total total
vertico--candidates candidates))))
-(defun vertico--flatten-prop (prop insert str)
- "Flatten STR with PROP, INSERT or remove."
+(defun vertico--flatten-string (prop str)
+ "Flatten STR with display or invisible PROP."
(let ((len (length str)) (pos 0) (chunks))
(while (/= pos len)
(let ((end (next-single-property-change pos prop str len)))
(if-let (val (get-text-property pos prop str))
- (when (and insert (stringp val))
+ (when (and (eq prop 'display) (stringp val))
(push val chunks))
(push (substring str pos end) chunks))
(setq pos end)))
@@ -326,13 +326,13 @@
(push (format vertico-group-format new-title) chunks)
(push "\n" chunks)
(setq title new-title)))
- (setq cand (thread-last cand
- (replace-regexp-in-string "[\t ]+" " ")
- (replace-regexp-in-string "[\t\n ]*\n[\t\n ]*" (car
vertico-truncation))
- (string-trim)
- (vertico--flatten-prop 'display 'insert)
- (vertico--flatten-prop 'invisible nil))
- cand (truncate-string-to-width cand max-width 0 nil (cdr
vertico-truncation))
+ (when (string-match-p "\n" cand)
+ (setq cand (thread-last cand
+ (replace-regexp-in-string "[\t ]+" " ")
+ (replace-regexp-in-string "[\t\n ]*\n[\t\n ]*" (car
vertico-multiline))
+ (replace-regexp-in-string "\\`[\t\n ]+\\|[\t\n ]+\\'"
""))
+ cand (truncate-string-to-width cand max-width 0 nil (cdr
vertico-multiline))))
+ (setq cand (vertico--flatten-string 'invisible
(vertico--flatten-string 'display cand))
cand (concat prefix cand
(if (text-property-not-all 0 (length suffix) 'face
nil suffix)
suffix
- [elpa] externals/vertico 1b75916 18/48: better orderless integration, (continued)
- [elpa] externals/vertico 1b75916 18/48: better orderless integration, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico 42823ce 25/48: Use read-char-exclusive to avoid error message, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico af41b13 24/48: fix lexical scoping, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico fa9e8dc 26/48: split functions, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico 27070bb 27/48: truncate long candidate strings, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico 94d9c4c 28/48: use literals, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico 5f64f97 22/48: update readme, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico 308670c 31/48: Fix confirmation: Use ignore-errors+read-char, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico 2cde6fd 40/48: Simplify, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico e429e06 43/48: Rename to vertico, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico eb5d617 47/48: Improve candidate sanitization,
Stefan Monnier <=
- [elpa] externals/vertico d57d390 34/48: Support partial completion for files, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico f3c0e7c 35/48: tidy shadowed file names, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico afd0abf 41/48: Always pass again through completion style for highlighting, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico 06e5dfe 02/48: improve minibuffer resizing, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico b5cfdd7 09/48: Handle completion boundaries, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico 866475c 05/48: increase threshold, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico c0606cf 39/48: Formatting, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico 7fdfd52 45/48: Formatting, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico 708f89d 46/48: Update copyright information, Stefan Monnier, 2021/04/05
- [elpa] externals/vertico cc3ba08 23/48: add screenshot, Stefan Monnier, 2021/04/05