diff options
author | Artur Malabarba <bruce.connor.am@gmail.com> | 2014-12-02 01:20:09 +0000 |
---|---|---|
committer | Artur Malabarba <bruce.connor.am@gmail.com> | 2014-12-02 01:20:09 +0000 |
commit | 59c49ce60fcfa1fac4827beb11a04c0ef8585b9a (patch) | |
tree | 779443bdba73197012c5c043230dc81028cc8d8e | |
parent | b8d3e61e0d02796fdd4d0c973dc4fbc9e856baa6 (diff) |
Editing implemented
Fix #11
-rw-r--r-- | sx-compose.el | 5 | ||||
-rw-r--r-- | sx-interaction.el | 31 | ||||
-rw-r--r-- | sx-question-mode.el | 1 |
3 files changed, 33 insertions, 4 deletions
diff --git a/sx-compose.el b/sx-compose.el index e09240f..dcb1bb0 100644 --- a/sx-compose.el +++ b/sx-compose.el @@ -165,6 +165,11 @@ respectively added locally to `sx-compose-before-send-hook' and (insert sx-compose--question-headers) (goto-char (point-min)) (goto-char (line-end-position)))) + (when (consp parent) + (when (or (string= (buffer-string) "") + (y-or-n-p "Draft buffer exists. Reset it? ")) + (erase-buffer) + (insert (cdr (assoc 'body_markdown parent))))) ;; Return the buffer (current-buffer)))) diff --git a/sx-interaction.el b/sx-interaction.el index 8673400..df871dd 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -200,6 +200,28 @@ OBJECT can be a question or an answer." (setcar object `(comments . [,comment]))))) +;;; Editing +(defun sx-edit (data) + "Start editing an answer or question given by DATA. +DATA is an answer or question alist. Interactively, it is guessed +from context at point." + ;; Answering doesn't really make sense from anywhere other than + ;; inside a question. So we don't need `sx--data-here' here. + (interactive (list (sx--data-here))) + ;; If we ever make an "Edit" button, first arg is a marker. + (when (markerp data) (setq data (sx--data-here))) + (sx-assoc-let data + (when .comment_id (user-error "Editing comments is not supported yet")) + (let ((buffer (current-buffer))) + (pop-to-buffer + (sx-compose--create + .site data nil + ;; After send functions + (list (lambda (_ res) + (sx--copy-data (elt res 0) data) + (sx--maybe-update-display buffer)))))))) + + ;;; Answering (defun sx-answer (data) "Start composing an answer for question given by DATA. @@ -215,10 +237,11 @@ context at point. " (pop-to-buffer (sx-compose--create .site .question_id nil - ;; After change functions - (lambda (_ res) - (sx--add-answer-to-question-object res sx-question-mode--data) - (sx--maybe-update-display buffer))))))) + ;; After send functions + (list (lambda (_ res) + (sx--add-answer-to-question-object + (elt res 0) sx-question-mode--data) + (sx--maybe-update-display buffer)))))))) (defun sx--add-answer-to-question-object (answer question) "Add alist ANSWER to alist QUESTION in the right place." diff --git a/sx-question-mode.el b/sx-question-mode.el index 24b2cfb..cc4c082 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -189,6 +189,7 @@ Letters do not insert themselves; instead, they are commands. ("q" quit-window) (" " scroll-up-command) ("a" sx-answer) + ("e" sx-edit) (,(kbd "S-SPC") scroll-down-command) ([backspace] scroll-down-command) ([tab] forward-button) |