aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtur Malabarba <bruce.connor.am@gmail.com>2014-12-05 18:01:35 +0000
committerArtur Malabarba <bruce.connor.am@gmail.com>2014-12-05 18:01:35 +0000
commit307895c5533636c9e1380dd55b38309f8dba702f (patch)
treecc69aab7cc8e1e7f32246568a9f0d07eb5fb0f57
parenta9dc66a6fc3a9d6e8cbf2a15601aea3510052679 (diff)
Fix bug when editing questions
-rw-r--r--sx-compose.el40
1 files changed, 28 insertions, 12 deletions
diff --git a/sx-compose.el b/sx-compose.el
index 4560c15..d8f3b23 100644
--- a/sx-compose.el
+++ b/sx-compose.el
@@ -70,12 +70,15 @@ Is invoked between `sx-compose-before-send-hook' and
(defvar sx-compose--question-headers
(concat
#("Title: " 0 7 (intangible t read-only t rear-nonsticky t))
+ "%s"
#("\n" 0 1 (read-only t))
#("Tags : " 0 7 (read-only t intangible t rear-nonsticky t))
+ "%s"
#("\n" 0 1 (read-only t rear-nonsticky t))
- #("________________________________________\n\n"
- 0 42 (read-only t rear-nonsticky t intangible t
- sx-compose-separator t)))
+ #("________________________________________\n"
+ 0 41 (read-only t rear-nonsticky t intangible t
+ sx-compose-separator t))
+ "\n")
"Headers inserted when composing a new question.
Used by `sx-compose-create'.")
@@ -172,19 +175,32 @@ respectively added locally to `sx-compose-before-send-hook' and
(add-hook 'sx-compose-after-send-functions it nil t))
;; If the buffer is empty, the draft didn't exist. So prepare the
;; question.
- (when (and is-question (string= (buffer-string) ""))
- (let ((inhibit-point-motion-hooks))
- (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? "))
+ (when (or (string= (buffer-string) "")
+ (y-or-n-p "Draft buffer exists. Reset it? "))
+ (let ((inhibit-point-motion-hooks t)
+ (inhibit-read-only t))
(erase-buffer)
- (insert (cdr (assoc 'body_markdown parent)))))
+ (when (consp parent)
+ (insert (cdr (assoc 'body_markdown parent))))
+ (when is-question
+ (sx-compose--print-question-headers
+ (when (consp parent) parent))
+ (unless (consp parent)
+ (goto-char (point-min))
+ (goto-char (line-end-position))))))
;; Return the buffer
(current-buffer))))
+(defun sx-compose--print-question-headers (question)
+ "Print question headers for the compose buffer.
+If QUESTION is non-nil, fill the headers with the data from
+QUESTION."
+ (sx-assoc-let question
+ (goto-char (point-min))
+ (insert
+ (format sx-compose--question-headers
+ (or .title "") (mapconcat #'identity .tags " ")))))
+
(defun sx-compose--generate-keywords (is-question)
"Reading current buffer, generate a keywords alist.
Keywords meant to be used in `sx-method-call'.