From 7344cc325f0ee1afdb0ad7a3e2c5db591bfdb053 Mon Sep 17 00:00:00 2001 From: Denis Zheleztsov Date: Thu, 9 Aug 2018 22:53:49 +0300 Subject: [PATCH] Initial quotes support --- idec-answers.el | 28 +++++++++++++++++++++++++++- idec.el | 20 ++++++++++++++------ 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/idec-answers.el b/idec-answers.el index b2a65b0..a5e7d5e 100644 --- a/idec-answers.el +++ b/idec-answers.el @@ -191,7 +191,6 @@ (defun edit-answer-without-quote (id msg-hash) "Answer to message with ID MSG-HASH." - msg-hash (let (answer-hash p) (setq answer-hash (get-answers-hash id msg-hash)) (switch-to-buffer (get-buffer-create (concat "*IDEC: answer to " id "*"))) @@ -208,6 +207,33 @@ (goto-char p) (idec))) +(defun idec-answers-edit-answer-with-quote (id msg-hash) + "Answer to message with quoted body with ID, MSG-HASH and BODY." + (let (answer-hash p) + (setq answer-hash (get-answers-hash id msg-hash)) + (switch-to-buffer (get-buffer-create (concat "*IDEC: answer to " id "*"))) + + (insert (make-answer-header id msg-hash)) + (forward-line) + (add-text-properties (point) (point-min) 'read-only) + (setq p (point)) + + (defun insert-quote (head tail) + "Insert quote with HEAD and TAIL." + (insert "> ") (insert head) (insert "\n") + (when (> (length tail) 0) + (message "%S" tail) + (insert-quote (car tail) (cdr tail)))) + + (insert-quote (car (get-message-field (gethash "content" msg-hash) "body")) + (cdr (get-message-field (gethash "content" msg-hash) "body"))) + (insert "\n") + (insert-text-button "[Send]" + 'action (lambda (x) (send-reply-message (button-get x 'msg))) + 'msg answer-hash) + (goto-char p)) + (idec)) + ;; END OF ANSWERS ;; NEW MESSAGE diff --git a/idec.el b/idec.el index 678ab9a..452429f 100644 --- a/idec.el +++ b/idec.el @@ -109,10 +109,15 @@ put cursor to CHECKPOINT." (insert-button "Answer" 'action (lambda (x) (edit-answer-without-quote (button-get x 'id) (button-get x 'msg-hash))) 'id (gethash "id" msg) - 'msg-hash answer-hash)) + 'msg-hash answer-hash) (princ "]") (princ "\t [") - (insert-button "Quote answer") + (insert-button "Quoted answer" + 'action (lambda (x) (idec-answers-edit-answer-with-quote + (button-get x 'id) + (button-get x 'msg-hash))) + 'id (gethash "id" msg) + 'msg-hash answer-hash)) (princ "]") (add-text-properties start (point) 'read-only)) (idec)) @@ -151,14 +156,17 @@ put cursor to CHECKPOINT." (insert-button "Answer" 'action (lambda (x) (edit-answer-without-quote (button-get x 'id) (button-get x 'msg-hash))) 'id (gethash "id" msg) - 'msg-hash answer-hash)) + 'msg-hash answer-hash) (princ "]") - (princ (concat (make-string 6 ? ) "[")) - (insert-button "Quote answer") + (princ (concat (make-string 9 ? ) "[")) + (insert-button "Quoted answer" + 'action (lambda (x) (idec-answers-edit-answer-with-quote (button-get x 'id) (button-get x 'msg-hash))) + 'id (gethash "id" msg) + 'msg-hash answer-hash)) (princ "]") (add-text-properties (point-min) (point-max) 'read-only)) (point-max) - (idec-mode)) + (idec)) (defun display-new-messages () "Display new fetched messages from `new-messages-list'."