From c6d0ee75c520041e9117422f7b8d5e86ca6cd5d4 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 2 Dec 2014 00:32:03 +0000 Subject: sx-answer to start composing from the question buffer --- sx-question-mode.el | 1 + 1 file changed, 1 insertion(+) (limited to 'sx-question-mode.el') diff --git a/sx-question-mode.el b/sx-question-mode.el index c44519c..24b2cfb 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -188,6 +188,7 @@ Letters do not insert themselves; instead, they are commands. ("d" sx-toggle-downvote) ("q" quit-window) (" " scroll-up-command) + ("a" sx-answer) (,(kbd "S-SPC") scroll-down-command) ([backspace] scroll-down-command) ([tab] forward-button) -- cgit v1.2.3 From 59c49ce60fcfa1fac4827beb11a04c0ef8585b9a Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 2 Dec 2014 01:20:09 +0000 Subject: Editing implemented Fix #11 --- sx-compose.el | 5 +++++ sx-interaction.el | 31 +++++++++++++++++++++++++++---- sx-question-mode.el | 1 + 3 files changed, 33 insertions(+), 4 deletions(-) (limited to 'sx-question-mode.el') 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 @@ -199,6 +199,28 @@ OBJECT can be a question or an answer." (setcdr object (cons (car object) (cdr object))) (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) @@ -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) -- cgit v1.2.3 From f939c9d9fd7a2e7aabe23b2a8084652d12ca5751 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 2 Dec 2014 01:20:34 +0000 Subject: Fix bug introduced by new use of overlays. --- sx-question-mode.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sx-question-mode.el') diff --git a/sx-question-mode.el b/sx-question-mode.el index cc4c082..b685ea7 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -110,7 +110,7 @@ Prefix argument N moves N sections down or up." (cl-decf count))))) (when (equal (selected-window) (get-buffer-window)) (when sx-question-mode-recenter-line - (let ((ov (car-safe (sx-question-mode--section-overlays-at (line-end-position))))) + (let ((ov (sx-question-mode--section-overlays-at (line-end-position)))) (when (and (overlayp ov) (> (overlay-end ov) (window-end))) (recenter sx-question-mode-recenter-line)))) (sx-message-help-echo))) -- cgit v1.2.3