[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/embark 21a56fccdf 1/2: Refactor code duplicated in mini
From: |
ELPA Syncer |
Subject: |
[elpa] externals/embark 21a56fccdf 1/2: Refactor code duplicated in minimal and verbose indicators |
Date: |
Sat, 15 Jan 2022 14:57:25 -0500 (EST) |
branch: externals/embark
commit 21a56fccdfabdb1a3ddade0d21c957b19b0d3572
Author: Omar Antolín <omar.antolin@gmail.com>
Commit: Omar Antolín <omar.antolin@gmail.com>
Refactor code duplicated in minimal and verbose indicators
---
embark.el | 116 +++++++++++++++++++++++++++-----------------------------------
1 file changed, 51 insertions(+), 65 deletions(-)
diff --git a/embark.el b/embark.el
index 978d4bd53e..0bb49595b9 100644
--- a/embark.el
+++ b/embark.el
@@ -1003,14 +1003,48 @@ If CYCLE is non-nil bind `embark-cycle'."
(concat (car (split-string target "\n" 'omit-nulls "\\s-*")) "…")
target))
-(defun embark--act-label (rep multi)
- "Return highlighted Act/Rep indicator label given REP and MULTI."
- (propertize
- (cond
- (multi "∀ct")
- (rep "Rep")
- (t "Act"))
- 'face 'highlight))
+(defun embark--format-targets (target shadowed-targets rep)
+ "Return a formatted string indicating the TARGET of an action.
+
+This is used internally by the minimal indicator and for the
+targets section of the verbose indicator. The string will also
+mention any SHADOWED-TARGETS. A non-nil REP indicates we are in
+a repeating sequence of actions."
+ (let ((act (propertize
+ (cond
+ ((plist-get target :multi) "∀ct")
+ (rep "Rep")
+ (t "Act"))
+ 'face 'highlight)))
+ (cond
+ ((eq (plist-get target :type) 'embark-become)
+ (propertize "Become" 'face 'highlight))
+ ((and (minibufferp)
+ (not (eq 'embark-keybinding
+ (completion-metadata-get
+ (embark--metadata)
+ 'category))))
+ ;; we are in a minibuffer but not from the
+ ;; completing-read prompter, use just "Act"
+ act)
+ ((plist-get target :multi)
+ (format "%s on %s %ss"
+ act
+ (plist-get target :multi)
+ (plist-get target :type)))
+ (t (format
+ "%s on %s%s '%s'"
+ act
+ (plist-get target :type)
+ (if shadowed-targets
+ (format (propertize "(%s)" 'face 'shadow)
+ (string-join
+ (mapcar (lambda (x)
+ (symbol-name (plist-get x :type)))
+ shadowed-targets)
+ ", "))
+ "")
+ (embark--truncate-target (plist-get target :target)))))))
(defun embark-minimal-indicator ()
"Minimal indicator, appearing in the minibuffer prompt or echo area.
@@ -1023,42 +1057,9 @@ the minibuffer is open, the message is added to the
prompt."
(if (null keymap)
(when indicator-overlay
(delete-overlay indicator-overlay))
- (let* ((target (car targets))
- (act (embark--act-label
- (eq (lookup-key keymap [13]) #'embark-done)
- (plist-get target :multi)))
- (shadowed-targets (cdr targets))
- (indicator
- (cond
- ;; TODO code duplication with
embark--verbose-indicator-section-target
- ((eq (plist-get target :type) 'embark-become)
- (propertize "Become" 'face 'highlight))
- ((and (minibufferp)
- (not (eq 'embark-keybinding
- (completion-metadata-get
- (embark--metadata)
- 'category))))
- ;; we are in a minibuffer but not from the
- ;; completing-read prompter, use just "Act"
- act)
- ((plist-get target :multi)
- (format "%s on %s %ss"
- act
- (plist-get target :multi)
- (plist-get target :type)))
- (t (format
- "%s on %s%s '%s'"
- act
- (plist-get target :type)
- (if shadowed-targets
- (format (propertize "(%s)" 'face 'shadow)
- (string-join
- (mapcar (lambda (x)
- (symbol-name (plist-get x :type)))
- shadowed-targets)
- ", "))
- "")
- (embark--truncate-target (plist-get target :target)))))))
+ (let ((indicator (embark--format-targets
+ (car targets) (cdr targets)
+ (eq (lookup-key keymap [13]) #'embark-done))))
(if (not (minibufferp))
(message "%s" indicator)
(unless indicator-overlay
@@ -1409,25 +1410,10 @@ of all full key sequences bound in the keymap."
(&key targets bindings &allow-other-keys)
"Format the TARGETS section for the indicator buffer.
BINDINGS is the formatted list of keybindings."
- (let* ((target (plist-get (car targets) :target))
- (kind (plist-get (car targets) :type))
- (result (cond
- ;; TODO code duplication with embark-minimal-indicator
- ((eq kind 'embark-become)
- (concat (propertize "Become" 'face 'highlight)))
- ((plist-get (car targets) :multi)
- (format "%s on %s %ss"
- (embark--act-label nil t)
- (plist-get (car targets) :multi)
- kind))
- (t
- (format "%s on %s '%s'"
- (embark--act-label
- (seq-find (lambda (b) (eq (caddr b) #'embark-done))
- bindings)
- nil)
- kind
- (embark--truncate-target target))))))
+ (let ((result (embark--format-targets
+ (car targets)
+ nil ; the shadowed targets section deals with these
+ (cl-find 'embark-done bindings :key #'caddr :test #'eq))))
(add-face-text-property 0 (length result)
'embark-verbose-indicator-title
'append
@@ -1439,8 +1425,8 @@ BINDINGS is the formatted list of keybindings."
"Format the CYCLE key section for the indicator buffer.
SHADOWED-TARGETS is the list of other targets."
(concat
- (and cycle(propertize (format "(%s to cycle)" cycle)
- 'face 'embark-verbose-indicator-shadowed))
+ (and cycle (propertize (format "(%s to cycle)" cycle)
+ 'face 'embark-verbose-indicator-shadowed))
(and shadowed-targets "\n")))
(cl-defun embark--verbose-indicator-section-shadowed-targets