aboutsummaryrefslogtreecommitdiff
path: root/sx-compose.el
diff options
context:
space:
mode:
Diffstat (limited to 'sx-compose.el')
-rw-r--r--sx-compose.el40
1 files changed, 28 insertions, 12 deletions
diff --git a/sx-compose.el b/sx-compose.el
index a25ee50..1b3101a 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'.")
@@ -201,19 +204,32 @@ respectively added locally to `sx-compose-before-send-hook' and
(add-hook 'sx-compose-before-send-hook #'sx-compose--check-tags 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'.