aboutsummaryrefslogtreecommitdiff
path: root/sx-question-mode.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-question-mode.el
parent0b8a09dadb3f90303e7c77ac0e644bc393c00700 (diff)
parentf46b4c3efddf15b76fcafdd0d35969dadc2881f4 (diff)
Merge branch 'generate-header-line-from-keymap' into delete-command
Diffstat (limited to 'sx-question-mode.el')
-rw-r--r--sx-question-mode.el80
1 files changed, 35 insertions, 45 deletions
diff --git a/sx-question-mode.el b/sx-question-mode.el
index 6125416..dd231bc 100644
--- a/sx-question-mode.el
+++ b/sx-question-mode.el
@@ -161,28 +161,40 @@ 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)
+ ("c" sx-comment "comment")
+ ("a" sx-answer "answer")
+ ("e" sx-edit "edit")
+ ("S" sx-search "Search")
+ ("s" sx-switchto-map "switch-to")
+ ("*" sx-favorite "star")
+ ("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
(define-derived-mode sx-question-mode special-mode "Question"
"Major mode to display and navigate a question and its answers.
Letters do not insert themselves; instead, they are commands.
@@ -201,32 +213,10 @@ Letters do not insert themselves; instead, they are commands.
(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)
- ("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.