aboutsummaryrefslogtreecommitdiff
path: root/sx.el
diff options
context:
space:
mode:
authorArtur Malabarba <bruce.connor.am@gmail.com>2015-02-21 18:22:18 -0200
committerArtur Malabarba <bruce.connor.am@gmail.com>2015-02-21 18:22:18 -0200
commit895f33c7566b3b83679e816f599945a92c2b21ae (patch)
tree1520ddf29be63e5516610c889306d7f22c9fb558 /sx.el
parent0b8a09dadb3f90303e7c77ac0e644bc393c00700 (diff)
parentf46b4c3efddf15b76fcafdd0d35969dadc2881f4 (diff)
Merge branch 'generate-header-line-from-keymap' into delete-command
Diffstat (limited to 'sx.el')
-rw-r--r--sx.el33
1 files changed, 33 insertions, 0 deletions
diff --git a/sx.el b/sx.el
index 9ad9744..fd4d79e 100644
--- a/sx.el
+++ b/sx.el
@@ -423,6 +423,39 @@ if ALIST contains a different string at the ?% entry."
(buffer-string))))
+;;; Key definitions
+(defun sx--key-definitions-to-header-line (definitions)
+ "Return a `header-line-format' from DEFINITIONS.
+DEFINITIONS is a list where each element has one of the following two forms
+ (KEY COMMAND)
+ (KEY COMMAND DESCRIPTION)
+
+The latter are used to build the return value, the former are
+ignored."
+ (let ((ptize (lambda (x) `(:propertize ,x face mode-line-buffer-id)))
+ alist out)
+ (dolist (it definitions)
+ (when (> (length it) 2)
+ (let* ((key (car it))
+ (desc (elt it 2))
+ (cell (assoc desc alist)))
+ (if cell (push key (cdr cell))
+ (push (cons desc (list key)) alist)))))
+ (dolist (it alist out)
+ (let ((desc (car it))
+ (keys (cdr it)))
+ (push (list " "
+ (cons (funcall ptize (car keys))
+ (mapcar (lambda (k) `("," ,(funcall ptize k))) (cdr keys)))
+ (let ((match
+ (and (= 1 (length keys))
+ (string-match (regexp-quote (car keys)) desc))))
+ (if (and (numberp match) (= 0 match))
+ (substring desc (length (car keys)))
+ (concat ":" desc))))
+ out)))))
+
+
(defcustom sx-init-hook nil
"Hook run when SX initializes.
Run after `sx-init--internal-hook'."