From 435a7d910ea930aa9055b9e91c121cc339f0e980 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 21 Feb 2015 17:29:51 -0200 Subject: Define and use sx-question-mode--key-definitions --- sx-question-mode.el | 80 +++++++++++++++++++++++------------------------------ 1 file changed, 35 insertions(+), 45 deletions(-) (limited to 'sx-question-mode.el') 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 + '( + ("" sx-question-mode-next-section) + ("" 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") + ("" backward-button) + ("" backward-button) + ("" 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 "") backward-button) - (,(kbd "") backward-button) - (,(kbd "") 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. -- cgit v1.2.3 From d13f4115beeda50a598f2161100a16fa21455e62 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 21 Feb 2015 18:23:03 -0200 Subject: Bind delete to K --- sx-question-mode.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'sx-question-mode.el') diff --git a/sx-question-mode.el b/sx-question-mode.el index dd231bc..fd7f026 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -177,9 +177,10 @@ property." ("c" sx-comment "comment") ("a" sx-answer "answer") ("e" sx-edit "edit") - ("S" sx-search "Search") - ("s" sx-switchto-map "switch-to") + ("S" sx-search) ("*" sx-favorite "star") + ("K" sx-delete "Delete") + ("s" sx-switchto-map "switch-to") ("TAB" forward-button "Navigate") ("" backward-button) ("" backward-button) -- cgit v1.2.3