aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sx-question-list.el76
-rw-r--r--sx-question-mode.el82
-rw-r--r--sx.el33
3 files changed, 105 insertions, 86 deletions
diff --git a/sx-question-list.el b/sx-question-list.el
index 32bc140..4f298a3 100644
--- a/sx-question-list.el
+++ b/sx-question-list.el
@@ -210,19 +210,39 @@ and thus not displayed in the list of questions.
This is ignored if `sx-question-list--refresh-function' is set.")
(make-variable-buffer-local 'sx-question-list--dataset)
+(defconst sx-question-list--key-definitions
+ '(
+ ;; S-down and S-up would collide with `windmove'.
+ ("<down>" sx-question-list-next)
+ ("<up>" sx-question-list-previous)
+ ("RET" sx-display "Display")
+ ("n" sx-question-list-next "Navigate")
+ ("p" sx-question-list-previous "Navigate")
+ ("j" sx-question-list-view-next "Navigate")
+ ("k" sx-question-list-view-previous "Navigate")
+ ("N" sx-question-list-next-far)
+ ("P" sx-question-list-previous-far)
+ ("J" sx-question-list-next-far)
+ ("K" sx-question-list-previous-far)
+ ("g" sx-question-list-refresh)
+ ("t" sx-tab-switch "tab")
+ ("a" sx-ask "ask")
+ ("S" sx-search "Search")
+ ("s" sx-switchto-map "switch-to")
+ ("v" sx-visit-externally "visit")
+ ("u" sx-upvote)
+ ("d" sx-downvote)
+ ("h" sx-question-list-hide "hide")
+ ("m" sx-question-list-mark-read "mark-read")
+ ("*" sx-favorite)
+ )
+ "List of key definitions for `sx-question-list-mode'.
+This list must follow the form described in
+`sx--key-definitions-to-header-line'.")
+
(defconst sx-question-list--header-line
- '(" "
- (:propertize "n p j k" face mode-line-buffer-id)
- ": Navigate"
- " "
- (:propertize "RET" face mode-line-buffer-id)
- ": View question"
- " "
- (:propertize "v" face mode-line-buffer-id)
- ": Visit externally"
- " "
- (:propertize "q" face mode-line-buffer-id)
- ": Quit")
+ (sx--key-definitions-to-header-line
+ sx-question-list--key-definitions)
"Header-line used on the question list.")
(defconst sx-question-list--order-methods
@@ -332,34 +352,10 @@ into consideration. The same holds for `sx-question-list--order'.
;;; Keybinds
-(mapc
- (lambda (x) (define-key sx-question-list-mode-map
- (car x) (cadr x)))
- '(
- ;; S-down and S-up would collide with `windmove'.
- ([down] sx-question-list-next)
- ([up] sx-question-list-previous)
- ("n" sx-question-list-next)
- ("p" sx-question-list-previous)
- ("j" sx-question-list-view-next)
- ("k" sx-question-list-view-previous)
- ("N" sx-question-list-next-far)
- ("P" sx-question-list-previous-far)
- ("J" sx-question-list-next-far)
- ("K" sx-question-list-previous-far)
- ("g" sx-question-list-refresh)
- ("t" sx-tab-switch)
- ("a" sx-ask)
- ("S" sx-search)
- ("s" sx-switchto-map)
- ("v" sx-visit-externally)
- ("u" sx-upvote)
- ("d" sx-downvote)
- ("h" sx-question-list-hide)
- ("m" sx-question-list-mark-read)
- ("*" sx-favorite)
- ([?\r] sx-display)
- ))
+;; We need this quote+eval combo because `kbd' was a macro in 24.2.
+(mapc (lambda (x) (eval `(define-key sx-question-list-mode-map
+ (kbd ,(car x)) #',(cadr x))))
+ sx-question-list--key-definitions)
(defun sx-question-list-hide (data)
"Hide question under point.
diff --git a/sx-question-mode.el b/sx-question-mode.el
index 820c5b4..cb19a0b 100644
--- a/sx-question-mode.el
+++ b/sx-question-mode.el
@@ -163,28 +163,41 @@ property."
pos 'sx-question-mode--section-content nil)))
-;;; Major-mode
+;;; Major-mode constants
+(defconst sx-question-mode--key-definitions
+ '(
+ ("<down>" sx-question-mode-next-section)
+ ("<up>" sx-question-mode-previous-section)
+ ("n" sx-question-mode-next-section "Navigate")
+ ("p" sx-question-mode-previous-section "Navigate")
+ ("g" sx-question-mode-refresh)
+ ("v" sx-visit-externally)
+ ("u" sx-upvote "upvote")
+ ("d" sx-downvote "downvote")
+ ("q" quit-window)
+ ("SPC" scroll-up-command)
+ ("e" sx-edit "edit")
+ ("S" sx-search "Search")
+ ("s" sx-switchto-map "switch-to")
+ ("*" sx-favorite "star")
+ ("O" sx-question-mode-order-by "Order")
+ ("c" sx-comment "comment")
+ ("a" sx-answer "answer")
+ ("TAB" forward-button "Navigate")
+ ("<S-iso-lefttab>" backward-button)
+ ("<S-tab>" backward-button)
+ ("<backtab>" backward-button))
+ "List of key definitions for `sx-question-mode'.
+This list must follow the form described in
+`sx--key-definitions-to-header-line'.")
+
(defconst sx-question-mode--header-line
- '(" "
- (:propertize "n p TAB" face mode-line-buffer-id)
- ": Navigate"
- " "
- (:propertize "u d" face mode-line-buffer-id)
- ": Up/Down Vote"
- " "
- (:propertize "c" face mode-line-buffer-id)
- ": Comment"
- " "
- (:propertize "a" face mode-line-buffer-id)
- ": Answer"
- " "
- (:propertize "e" face mode-line-buffer-id)
- ": Edit"
- " "
- (:propertize "q" face mode-line-buffer-id)
- ": Quit")
+ (sx--key-definitions-to-header-line
+ sx-question-mode--key-definitions)
"Header-line used on the question list.")
+
+;;; Major-mode definition
(defconst sx-question-mode--mode-line
'(" "
;; `sx-question-mode--data' is guaranteed to have through
@@ -237,33 +250,10 @@ on the current buffer use
(remove-hook 'window-configuration-change-hook
'markdown-fontify-buffer-wiki-links t))
-(mapc
- (lambda (x) (define-key sx-question-mode-map
- (car x) (cadr x)))
- `(
- ([down] sx-question-mode-next-section)
- ([up] sx-question-mode-previous-section)
- ("n" sx-question-mode-next-section)
- ("p" sx-question-mode-previous-section)
- ("g" sx-question-mode-refresh)
- ("c" sx-comment)
- ("v" sx-visit-externally)
- ("u" sx-upvote)
- ("d" sx-downvote)
- ("O" sx-question-mode-order-by)
- ("q" quit-window)
- (" " scroll-up-command)
- ("a" sx-answer)
- ("e" sx-edit)
- ("S" sx-search)
- ("s" sx-switchto-map)
- ("*" sx-favorite)
- (,(kbd "S-SPC") scroll-down-command)
- ([backspace] scroll-down-command)
- ([tab] forward-button)
- (,(kbd "<S-iso-lefttab>") backward-button)
- (,(kbd "<S-tab>") backward-button)
- (,(kbd "<backtab>") backward-button)))
+;; We need this quote+eval combo because `kbd' was a macro in 24.2.
+(mapc (lambda (x) (eval `(define-key sx-question-mode-map
+ (kbd ,(car x)) #',(cadr x))))
+ sx-question-mode--key-definitions)
(defun sx-question-mode-refresh (&optional no-update)
"Refresh currently displayed question.
diff --git a/sx.el b/sx.el
index e5e9c3e..3bc6768 100644
--- a/sx.el
+++ b/sx.el
@@ -436,6 +436,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'."