aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtur Malabarba <bruce.connor.am@gmail.com>2014-11-29 20:53:52 +0000
committerArtur Malabarba <bruce.connor.am@gmail.com>2014-11-29 20:59:59 +0000
commiteca252dfddba3b18d4da74bee1b802c8d59e0c4a (patch)
tree34f4ae1dfb71707dd36ec0357425c0e22e05f379
parent8d38a7bfe808f6af9c95ca7a490a7a822ea59e73 (diff)
New "Add a Comment" button
-rw-r--r--sx-button.el8
-rw-r--r--sx-interaction.el9
-rw-r--r--sx-question-print.el7
3 files changed, 20 insertions, 4 deletions
diff --git a/sx-button.el b/sx-button.el
index ed94558..afc1cf7 100644
--- a/sx-button.el
+++ b/sx-button.el
@@ -25,6 +25,7 @@
(require 'sx)
(require 'sx-question)
+(require 'sx-interaction)
;;; Command definitions
@@ -92,6 +93,13 @@ This is usually a link's URL, or the content of a code block."
'action #'sx-button-follow-link
:supertype 'sx-button)
+(define-button-type 'sx-button-comment
+ 'help-echo (concat "mouse-1, RET"
+ (propertize ": write a comment"
+ 'face 'minibuffer-prompt))
+ 'action #'sx-comment
+ :supertype 'sx-button)
+
(provide 'sx-button)
;;; sx-button.el ends here
diff --git a/sx-interaction.el b/sx-interaction.el
index 5f3ece6..92b062b 100644
--- a/sx-interaction.el
+++ b/sx-interaction.el
@@ -117,15 +117,18 @@ changes."
;;; Commenting
-(defun sx-comment (data text)
+(defun sx-comment (data &optional text)
"Post a comment on DATA given by TEXT.
DATA can be a question, an answer, or a comment. Interactively,
it is guessed from context at point.
If DATA is a comment, the comment is posted as a reply to it.
TEXT is a string. Interactively, it is read from the minibufer."
- (interactive
- (list (sx--data-here) 'query))
+ (interactive (list (sx--data-here) 'query))
+ ;; When clicking the "Add a Comment" button, first arg is a marker.
+ (when (markerp data)
+ (setq data (sx--data-here))
+ (setq text 'query))
(sx-assoc-let data
;; Get the comment text
(when (eq text 'query)
diff --git a/sx-question-print.el b/sx-question-print.el
index b8fc633..22f857c 100644
--- a/sx-question-print.el
+++ b/sx-question-print.el
@@ -237,7 +237,12 @@ DATA can represent a question or an answer."
.body_markdown)
"\n"
(propertize sx-question-mode-separator
- 'face 'sx-question-mode-header)))))
+ 'face 'sx-question-mode-header))))
+ ;; This is where the "add a comment" button is printed.
+ (insert " ")
+ (insert-text-button "Add a Comment"
+ :type 'sx-button-comment)
+ (insert "\n"))
;; Comments have their own `sx--data-here' property (so they can
;; be upvoted too).
(when .comments