From 1d0e733f64d1dc2549bd1698c1d03b5bcff2af5f Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 20 Dec 2014 15:08:43 -0200 Subject: Hotfix switch-tab --- sx-question-list.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sx-question-list.el') diff --git a/sx-question-list.el b/sx-question-list.el index f6a82e2..62ce032 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -315,7 +315,7 @@ into consideration. ("K" sx-question-list-previous-far) ("g" sx-question-list-refresh) (":" sx-question-list-switch-site) - ("t" sx-question-list-switch-tab) + ("t" sx-tab-switch) ("a" sx-ask) ("v" sx-visit-externally) ("u" sx-toggle-upvote) -- cgit v1.2.3 From d51791fb6ae69e3b426f7d598920b4349858908f Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 22 Dec 2014 11:37:35 -0200 Subject: Refactor .site to .site_par It turns out some api objects do have a site property, except its value is not a string, it is another object. The actual string we've been referring to as .site is the .site.api_site_parameter To avoid conflicts, I've renamed all our uses of .site to .site_par, and sx-assoc-let now makes sure the object has a .site_par value, instead of a .site value (which it may or may not have now, and is the same object that the api refers to as site). --- sx-interaction.el | 18 +++++++++--------- sx-question-list.el | 2 +- sx-question-mode.el | 2 +- sx-question.el | 18 +++++++++--------- sx.el | 9 ++++++--- 5 files changed, 26 insertions(+), 23 deletions(-) (limited to 'sx-question-list.el') diff --git a/sx-interaction.el b/sx-interaction.el index 2768c8d..342ae1c 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -142,10 +142,10 @@ Element can be a question, answer, or comment." (cl-case .type (answer (sx-display-question - (sx-question-get-from-answer .site .id) 'focus)) + (sx-question-get-from-answer .site_par .id) 'focus)) (question (sx-display-question - (sx-question-get-question .site .id) 'focus)))))) + (sx-question-get-question .site_par .id) 'focus)))))) ;;; Displaying @@ -206,7 +206,7 @@ changes." :auth 'warn :url-method "POST" :filter sx-browse-filter - :site .site)))) + :site .site_par)))) ;; The api returns the new DATA. (when (> (length result) 0) (sx--copy-data (elt result 0) data) @@ -247,14 +247,14 @@ TEXT is a string. Interactively, it is read from the minibufer." :auth 'warn :url-method "POST" :filter sx-browse-filter - :site .site + :site .site_par :keywords `((body . ,text))))) ;; The api returns the new DATA. (when (> (length result) 0) (sx--add-comment-to-object (elt result 0) (if .post_id - (sx--get-post .post_type .site .post_id) + (sx--get-post .post_type .site_par .post_id) data)) ;; Display the changes in `data'. (sx--maybe-update-display))))) @@ -287,7 +287,7 @@ ID is an integer." (car (cl-member-if (lambda (x) (sx-assoc-let x (and (equal (or .answer_id .question_id) id) - (equal .site site)))) + (equal .site_par site)))) db)))) (defun sx--add-comment-to-object (comment object) @@ -320,7 +320,7 @@ from context at point." (let ((buffer (current-buffer))) (pop-to-buffer (sx-compose-create - .site data + .site_par data ;; Before send hook (when .comment_id (list #'sx--comment-valid-p)) ;; After send functions @@ -338,7 +338,7 @@ from context at point." (defun sx--interactive-site-prompt () "Query the user for a site." (let ((default (or sx-question-list--site - (sx-assoc-let sx-question-mode--data .site) + (sx-assoc-let sx-question-mode--data .site_par) sx-default-site))) (funcall (if ido-mode #'ido-completing-read #'completing-read) (format "Site (%s): " default) @@ -372,7 +372,7 @@ context at point. " (sx-assoc-let data (pop-to-buffer (sx-compose-create - .site .question_id nil + .site_par .question_id nil ;; After send functions (list (lambda (_ res) (sx--add-answer-to-question-object diff --git a/sx-question-list.el b/sx-question-list.el index 62ce032..4b6c4ef 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -127,7 +127,7 @@ elements: Also see `sx-question-list-refresh'." (sx-assoc-let question-data (let ((favorite (if (member .question_id - (assoc .site + (assoc .site_par sx-favorites--user-favorite-list)) (if (char-displayable-p ?\x2b26) "\x2b26" "*") " "))) (list diff --git a/sx-question-mode.el b/sx-question-mode.el index a60cf3a..7d61167 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -254,7 +254,7 @@ query the api." (if no-update sx-question-mode--data (sx-assoc-let sx-question-mode--data - (sx-question-get-question .site .question_id)))) + (sx-question-get-question .site_par .question_id)))) (goto-char point) (when (equal (selected-window) (get-buffer-window (current-buffer))) diff --git a/sx-question.el b/sx-question.el index 801384a..3fcc438 100644 --- a/sx-question.el +++ b/sx-question.el @@ -94,8 +94,8 @@ If no cache exists for it, initialize one with SITE." "Non-nil if QUESTION has been read since last updated. See `sx-question--user-read-list'." (sx-assoc-let question - (sx-question--ensure-read-list .site) - (let ((ql (cdr (assoc .site sx-question--user-read-list)))) + (sx-question--ensure-read-list .site_par) + (let ((ql (cdr (assoc .site_par sx-question--user-read-list)))) (and ql (>= (or (cdr (assoc .question_id ql)) 0) .last_activity_date))))) @@ -107,14 +107,14 @@ read, i.e., if it was `sx-question--read-p'. See `sx-question--user-read-list'." (prog1 (sx-assoc-let question - (sx-question--ensure-read-list .site) - (let ((site-cell (assoc .site sx-question--user-read-list)) + (sx-question--ensure-read-list .site_par) + (let ((site-cell (assoc .site_par sx-question--user-read-list)) (q-cell (cons .question_id .last_activity_date)) cell) (cond ;; First question from this site. ((null site-cell) - (push (list .site q-cell) sx-question--user-read-list)) + (push (list .site_par q-cell) sx-question--user-read-list)) ;; Question already present. ((setq cell (assoc .question_id site-cell)) ;; Current version is newer than cached version. @@ -149,18 +149,18 @@ If no cache exists for it, initialize one with SITE." (defun sx-question--hidden-p (question) "Non-nil if QUESTION has been hidden." (sx-assoc-let question - (sx-question--ensure-hidden-list .site) - (let ((ql (cdr (assoc .site sx-question--user-hidden-list)))) + (sx-question--ensure-hidden-list .site_par) + (let ((ql (cdr (assoc .site_par sx-question--user-hidden-list)))) (and ql (memq .question_id ql))))) (defun sx-question--mark-hidden (question) "Mark QUESTION as being hidden." (sx-assoc-let question - (let ((site-cell (assoc .site sx-question--user-hidden-list))) + (let ((site-cell (assoc .site_par sx-question--user-hidden-list))) ;; If question already hidden, do nothing. (unless (memq .question_id site-cell) ;; First question from this site. - (push (list .site .question_id) sx-question--user-hidden-list) + (push (list .site_par .question_id) sx-question--user-hidden-list) ;; Question wasn't present. ;; Add it in, but make sure it's sorted (just in case we need ;; it later). diff --git a/sx.el b/sx.el index cda1acd..78995a8 100644 --- a/sx.el +++ b/sx.el @@ -303,9 +303,12 @@ DATA can also be the link itself." DATA can be a question, answer, comment, or user (or any object with a `link' property)." (when data - (unless (assq 'site data) - (setcdr data (cons (cons 'site (sx--site data)) - (cdr data)))) + (let-alist data + (unless .site_par + (setcdr data (cons (cons 'site_par + (or .site.api_site_parameter + (sx--site data))) + (cdr data))))) data)) (defmacro sx-assoc-let (alist &rest body) -- cgit v1.2.3 From 293aa1850a00dfe42549b7f4b7373057aaaa21d9 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 22 Dec 2014 11:53:38 -0200 Subject: Generalize sx-display-question to sx-display --- sx-interaction.el | 20 +++++++++++++++++++- sx-question-list.el | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'sx-question-list.el') diff --git a/sx-interaction.el b/sx-interaction.el index 965a996..181632e 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -149,9 +149,27 @@ Element can be a question, answer, or comment." ;;; Displaying +(defun sx-display (&optional data) + "Display object given by DATA. +Interactively, display object under point. Object can be a +question, an answer, or an inbox_item. + +This is meant for interactive use. In lisp code, use +object-specific functions such as `sx-display-question' and the +likes." + (interactive (list (sx--data-here) t)) + (sx-assoc-let data + (cond + (.item_type (sx-open-link .link)) + (.answer_id + (sx-display-question + (sx-question-get-from-answer .site_par .id) 'focus)) + (.title + (sx-display-question data 'focus))))) + (defun sx-display-question (&optional data focus window) "Display question given by DATA, on WINDOW. -When DATA is nil, display question under point. When FOCUS is +Interactively, display question under point. When FOCUS is non-nil (the default when called interactively), also focus the relevant window. diff --git a/sx-question-list.el b/sx-question-list.el index 4b6c4ef..4f71251 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -322,7 +322,7 @@ into consideration. ("d" sx-toggle-downvote) ("h" sx-question-list-hide) ("m" sx-question-list-mark-read) - ([?\r] sx-display-question) + ([?\r] sx-display) )) (defun sx-question-list-hide (data) -- cgit v1.2.3 From c37022ffbc52b900d81eee05f3c2c3d5fe6fee01 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 27 Dec 2014 23:06:00 -0200 Subject: Initial implementation of sx-completing-read --- sx-interaction.el | 8 ++++---- sx-question-list.el | 3 +-- sx-tab.el | 8 ++++---- sx.el | 5 +++++ 4 files changed, 14 insertions(+), 10 deletions(-) (limited to 'sx-question-list.el') diff --git a/sx-interaction.el b/sx-interaction.el index 372a5b1..9ced1ab 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -340,10 +340,10 @@ from context at point." (let ((default (or sx-question-list--site (sx-assoc-let sx-question-mode--data .site) sx-default-site))) - (funcall (if ido-mode #'ido-completing-read #'completing-read) - (format "Site (%s): " default) - (sx-site-get-api-tokens) nil t nil nil - default))) + (sx-completing-read + (format "Site (%s): " default) + (sx-site-get-api-tokens) nil t nil nil + default))) ;;;###autoload (defun sx-ask (site) diff --git a/sx-question-list.el b/sx-question-list.el index 4bd6478..d84d1ea 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -559,12 +559,11 @@ This does not update `sx-question-mode--window'." (defun sx-question-list-switch-site (site) "Switch the current site to SITE and display its questions. -Use `ido-completing-read' if variable `ido-mode' is active. Retrieve completions from `sx-site-get-api-tokens'. Sets `sx-question-list--site' and then call `sx-question-list-refresh' with `redisplay'." (interactive - (list (funcall (if ido-mode #'ido-completing-read #'completing-read) + (list (sx-completing-read "Switch to site: " (sx-site-get-api-tokens) (lambda (site) (not (equal site sx-question-list--site))) t))) diff --git a/sx-tab.el b/sx-tab.el index 6c5e21e..32a7784 100644 --- a/sx-tab.el +++ b/sx-tab.el @@ -34,10 +34,10 @@ (defun sx-tab-switch (tab) "Switch to another question-list tab." (interactive - (list (funcall (if ido-mode #'ido-completing-read #'completing-read) - "Switch to tab: " sx-tab--list - (lambda (tab) (not (equal tab sx-question-list--current-tab))) - t))) + (list (sx-completing-read + "Switch to tab: " sx-tab--list + (lambda (tab) (not (equal tab sx-question-list--current-tab))) + t))) (funcall (intern (format "sx-tab-%s" (downcase tab))))) diff --git a/sx.el b/sx.el index a63c155..c2d1164 100644 --- a/sx.el +++ b/sx.el @@ -183,6 +183,11 @@ See `sx-question-get-questions' and `sx-question-get-question'.") ;;; Utility Functions +(defun sx-completing-read (&rest args) + "Like `completing-read', but possibly use ido. +All ARGS are passed to `completing-read' or `ido-completing-read'." + (apply (if ido-mode #'ido-completing-read #'completing-read) + args)) (defmacro sx-sorted-insert-skip-first (newelt list &optional predicate) "Inserted NEWELT into LIST sorted by PREDICATE. -- cgit v1.2.3 From 39116611ea99b3b0ba33545d38c2983a17db487d Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 28 Dec 2014 00:11:02 -0200 Subject: Bind sx-search to s --- sx-question-list.el | 1 + sx-question-mode.el | 1 + 2 files changed, 2 insertions(+) (limited to 'sx-question-list.el') diff --git a/sx-question-list.el b/sx-question-list.el index d84d1ea..0856e2a 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -317,6 +317,7 @@ into consideration. (":" sx-question-list-switch-site) ("t" sx-tab-switch) ("a" sx-ask) + ("s" sx-search) ("v" sx-visit-externally) ("u" sx-toggle-upvote) ("d" sx-toggle-downvote) diff --git a/sx-question-mode.el b/sx-question-mode.el index a60cf3a..05b8984 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -231,6 +231,7 @@ Letters do not insert themselves; instead, they are commands. (" " scroll-up-command) ("a" sx-answer) ("e" sx-edit) + ("s" sx-search) (,(kbd "S-SPC") scroll-down-command) ([backspace] scroll-down-command) ([tab] forward-button) -- cgit v1.2.3 From 33d0e830929ef07f0e1aee84189fb8aec8d52f62 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 4 Jan 2015 12:08:31 -0200 Subject: Bind switchto-map to "s" --- sx-question-list.el | 4 ++-- sx-question-mode.el | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'sx-question-list.el') diff --git a/sx-question-list.el b/sx-question-list.el index cf849db..c189ad8 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -314,10 +314,10 @@ into consideration. ("J" sx-question-list-next-far) ("K" sx-question-list-previous-far) ("g" sx-question-list-refresh) - (":" sx-question-list-switch-site) ("t" sx-tab-switch) ("a" sx-ask) - ("s" sx-search) + ("S" sx-search) + ("s" sx-switchto-map) ("v" sx-visit-externally) ("u" sx-toggle-upvote) ("d" sx-toggle-downvote) diff --git a/sx-question-mode.el b/sx-question-mode.el index 721f935..c618c96 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -231,7 +231,8 @@ Letters do not insert themselves; instead, they are commands. (" " scroll-up-command) ("a" sx-answer) ("e" sx-edit) - ("s" sx-search) + ("S" sx-search) + ("s" sx-switchto-map) (,(kbd "S-SPC") scroll-down-command) ([backspace] scroll-down-command) ([tab] forward-button) -- cgit v1.2.3 From 671dceecafb9cb48b739b7fb54bf2b71bbc7e32c Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 4 Jan 2015 12:54:28 -0200 Subject: Make question-list--site buffer local. Don't ask me why it wasn't already. --- sx-question-list.el | 1 + 1 file changed, 1 insertion(+) (limited to 'sx-question-list.el') diff --git a/sx-question-list.el b/sx-question-list.el index c189ad8..9e08787 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -399,6 +399,7 @@ Non-interactively, DATA is a question alist." (defvar sx-question-list--site nil "Site being displayed in the *question-list* buffer.") +(make-variable-buffer-local 'sx-question-list--site) (defun sx-question-list-refresh (&optional redisplay no-update) "Update the list of questions. -- cgit v1.2.3 From 6bb1f537a130900b44d8170e61dbb946303af9b5 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 4 Jan 2015 16:52:24 -0200 Subject: Bind favoriting to "*" --- sx-question-list.el | 1 + sx-question-mode.el | 1 + 2 files changed, 2 insertions(+) (limited to 'sx-question-list.el') diff --git a/sx-question-list.el b/sx-question-list.el index 9e08787..0a8e72c 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -323,6 +323,7 @@ into consideration. ("d" sx-toggle-downvote) ("h" sx-question-list-hide) ("m" sx-question-list-mark-read) + ("*" sx-favorite) ([?\r] sx-display) )) diff --git a/sx-question-mode.el b/sx-question-mode.el index c618c96..62bf241 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -233,6 +233,7 @@ Letters do not insert themselves; instead, they are commands. ("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) -- cgit v1.2.3 From beafd94faf6ec8c1aede9cbca66c5af26bf35d51 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 4 Jan 2015 17:50:17 -0200 Subject: Some starting comments --- sx-question-list.el | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sx-question-list.el') diff --git a/sx-question-list.el b/sx-question-list.el index 0a8e72c..ee7d6b1 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -141,12 +141,14 @@ Also see `sx-question-list-refresh'." 'sx-question-list-answers-accepted 'sx-question-list-answers)) (concat + ;; First line (propertize .title 'face (if (sx-question--read-p question-data) 'sx-question-list-read-question 'sx-question-list-unread-question)) (propertize " " 'display "\n ") + ;; Second line (propertize favorite 'face 'sx-question-list-favorite) " " (propertize (concat (sx-time-since .last_activity_date) -- cgit v1.2.3 From e8a2b48d09e22cf5dca446e70d1428ae4561fd42 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 4 Jan 2015 17:50:35 -0200 Subject: Display bounty --- sx-filter.el | 1 + sx-question-list.el | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'sx-question-list.el') diff --git a/sx-filter.el b/sx-filter.el index d484f43..1cf010f 100644 --- a/sx-filter.el +++ b/sx-filter.el @@ -106,6 +106,7 @@ return the compiled filter." (defvar sx-browse-filter (sx-filter-from-nil ((question body_markdown + bounty_amount comments answers last_editor diff --git a/sx-question-list.el b/sx-question-list.el index ee7d6b1..81e5ab0 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -104,6 +104,11 @@ "" :group 'sx-question-list-faces) +(defface sx-question-list-bounty + '((t :inherit font-lock-warning-face)) + "" + :group 'sx-question-list-faces) + ;;; Backend variables (defvar sx-question-list--print-function #'sx-question-list--print-info @@ -150,9 +155,11 @@ Also see `sx-question-list-refresh'." (propertize " " 'display "\n ") ;; Second line (propertize favorite 'face 'sx-question-list-favorite) - " " - (propertize (concat (sx-time-since .last_activity_date) - sx-question-list-ago-string) + (if (and (numberp .bounty_amount) (> .bounty_amount 0)) + (propertize (format "%4d" .bounty_amount) + 'face 'sx-question-list-bounty) + " ") + " " 'face 'sx-question-list-date) " " (propertize (mapconcat #'sx-question--tag-format .tags " ") -- cgit v1.2.3 From 63484071c93bb3b9d661ed98a77a29e587b456e7 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 4 Jan 2015 17:51:11 -0200 Subject: Fix date width --- sx-question-list.el | 3 +++ 1 file changed, 3 insertions(+) (limited to 'sx-question-list.el') diff --git a/sx-question-list.el b/sx-question-list.el index 81e5ab0..ee37fb2 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -160,6 +160,9 @@ Also see `sx-question-list-refresh'." 'face 'sx-question-list-bounty) " ") " " + (propertize (format "%3s%s" + (sx-time-since .last_activity_date) + sx-question-list-ago-string) 'face 'sx-question-list-date) " " (propertize (mapconcat #'sx-question--tag-format .tags " ") -- cgit v1.2.3 From 707cb9f97ea9ff6e6f7b135d24a0e2e7b0f99740 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 4 Jan 2015 17:51:23 -0200 Subject: Set tag max-width to 40 --- sx-question-list.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'sx-question-list.el') diff --git a/sx-question-list.el b/sx-question-list.el index ee37fb2..1342e76 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -165,7 +165,9 @@ Also see `sx-question-list-refresh'." sx-question-list-ago-string) 'face 'sx-question-list-date) " " - (propertize (mapconcat #'sx-question--tag-format .tags " ") + ;; @TODO: Make this width customizable. (Or maybe just make + ;; the whole thing customizable) + (propertize (format "%-40s" (mapconcat #'sx-question--tag-format .tags " ")) 'face 'sx-question-list-tags) (propertize " " 'display "\n"))))))) -- cgit v1.2.3 From df4a8bba9b720357008423b8f91657a8a311607a Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 4 Jan 2015 18:09:26 -0200 Subject: Display user --- sx-filter.el | 5 ++++- sx-question-list.el | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'sx-question-list.el') diff --git a/sx-filter.el b/sx-filter.el index 1cf010f..15bd8a1 100644 --- a/sx-filter.el +++ b/sx-filter.el @@ -117,7 +117,10 @@ return the compiled filter." downvoted question_id share_link) - (user display_name) + (user display_name + reputation) + (shallow_user display_name + reputation) (comment owner body_markdown body diff --git a/sx-question-list.el b/sx-question-list.el index 1342e76..40b72b9 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -109,6 +109,16 @@ "" :group 'sx-question-list-faces) +(defface sx-question-list-reputation + '((t :inherit sx-question-list-date)) + "" + :group 'sx-question-list-faces) + +(defface sx-question-list-user + '((t :inherit font-lock-builtin-face)) + "" + :group 'sx-question-list-faces) + ;;; Backend variables (defvar sx-question-list--print-function #'sx-question-list--print-info @@ -169,6 +179,12 @@ Also see `sx-question-list-refresh'." ;; the whole thing customizable) (propertize (format "%-40s" (mapconcat #'sx-question--tag-format .tags " ")) 'face 'sx-question-list-tags) + " " + (let-alist .owner + (format "%15s %5s" + (propertize .display_name 'face 'sx-question-list-user) + (propertize (number-to-string .reputation) + 'face 'sx-question-list-reputation))) (propertize " " 'display "\n"))))))) (defvar sx-question-list--pages-so-far 0 -- cgit v1.2.3 From e39f18a1a27c9d74c04141d01b176caff869b0cd Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 4 Jan 2015 17:02:43 -0200 Subject: "u" and "d" unconditionally apply votes instead of toggling. To remove votes, use C-u. --- sx-interaction.el | 26 ++++++++++++++------------ sx-question-list.el | 4 ++-- sx-question-mode.el | 4 ++-- 3 files changed, 18 insertions(+), 16 deletions(-) (limited to 'sx-question-list.el') diff --git a/sx-interaction.el b/sx-interaction.el index 80c8e5a..b85a8db 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -208,21 +208,23 @@ With the UNDO prefix argument, unfavorite the question instead." ;;; Voting -(defun sx-toggle-upvote (data) - "Apply or remove upvote from DATA. +(defun sx-upvote (data &optional undo) + "Upvote an object given by DATA. DATA can be a question, answer, or comment. Interactively, it is -guessed from context at point." - (interactive (list (sx--error-if-unread (sx--data-here)))) - (sx-assoc-let data - (sx-set-vote data "upvote" (null (eq .upvoted t))))) +guessed from context at point. +With UNDO prefix argument, remove upvote instead of applying it." + (interactive (list (sx--error-if-unread (sx--data-here)) + current-prefix-arg)) + (sx-set-vote data "upvote" (not undo))) -(defun sx-toggle-downvote (data) - "Apply or remove downvote from DATA. +(defun sx-downvote (data &optional undo) + "Downvote an object given by DATA. DATA can be a question or an answer. Interactively, it is guessed -from context at point." - (interactive (list (sx--error-if-unread (sx--data-here)))) - (sx-assoc-let data - (sx-set-vote data "downvote" (null (eq .downvoted t))))) +from context at point. +With UNDO prefix argument, remove downvote instead of applying it." + (interactive (list (sx--error-if-unread (sx--data-here)) + current-prefix-arg)) + (sx-set-vote data "downvote" (not undo))) (defun sx-set-vote (data type status) "Set the DATA's vote TYPE to STATUS. diff --git a/sx-question-list.el b/sx-question-list.el index 0a8e72c..a8b9fb3 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -319,8 +319,8 @@ into consideration. ("S" sx-search) ("s" sx-switchto-map) ("v" sx-visit-externally) - ("u" sx-toggle-upvote) - ("d" sx-toggle-downvote) + ("u" sx-upvote) + ("d" sx-downvote) ("h" sx-question-list-hide) ("m" sx-question-list-mark-read) ("*" sx-favorite) diff --git a/sx-question-mode.el b/sx-question-mode.el index 62bf241..b13caf3 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -225,8 +225,8 @@ Letters do not insert themselves; instead, they are commands. ("g" sx-question-mode-refresh) ("c" sx-comment) ("v" sx-visit-externally) - ("u" sx-toggle-upvote) - ("d" sx-toggle-downvote) + ("u" sx-upvote) + ("d" sx-downvote) ("q" quit-window) (" " scroll-up-command) ("a" sx-answer) -- cgit v1.2.3