From 8aa9bcb7d5fd80592868a6eebedc40bb0c775ef7 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Sat, 22 Jun 2013 00:05:33 +0200 Subject: Add editing-scrumelo-story macro This macro makes it easier to define some actions to edit a scrumelo story and then saving that buffer. --- scrumelo.el | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/scrumelo.el b/scrumelo.el index 19e1439..1adf0f5 100644 --- a/scrumelo.el +++ b/scrumelo.el @@ -14,6 +14,9 @@ (require 'esxml) (require 'org) +(eval-when-compile + (require 'cl-macs)) + ;;; Code: (defvar scrumelo-project-file "~/projects/scrumelo/aeos.org" @@ -49,6 +52,20 @@ "http://cdnjs.cloudflare.com/ajax/libs/react/0.3.2/JSXTransformer.js" "The location of the JSX Transformer JS file.") +(defmacro editing-scrumelo-story (id after &rest body) + "Edit the story with ID. + +Goto the story with ID and execute AFTER after executing BODY and +saving the buffer." + (declare (indent 2)) + (let ((entry-var (cl-gensym))) + `(with-scrumelo-buffer + (let ((,entry-var (cdr (org-id-find ,id)))) + (goto-char ,entry-var) + ,@body + (save-buffer) + ,after)))) + (defmacro with-scrumelo-http-params (params httpcon &rest body) "Bind parameters PARAMS from HTTPCON and execute BODY." (declare (indent 2)) @@ -121,14 +138,10 @@ (elnode-method httpcon (POST (with-scrumelo-http-params (id) httpcon - (with-scrumelo-buffer - (let ((entry (cdr (org-id-find id)))) - (goto-char entry) - (org-todo) - (save-buffer) + (editing-scrumelo-story id (scrumelo--send-json - httpcon - (list (cons :state (org-entry-get (point) "TODO")))))))))) + httpcon `((:state . ,(org-entry-get (point) "TODO")))) + (org-todo)))))) (defun scrumelo-move-story (dir) "Create a function to move a story in direction DIR." @@ -137,14 +150,9 @@ (elnode-method httpcon (POST (with-scrumelo-http-params (id) httpcon - (with-scrumelo-buffer - (let ((entry (cdr (org-id-find id)))) - (goto-char entry) - (funcall func) - (save-buffer) - (scrumelo--send-json - httpcon - (list (cons :status "OK"))))))))))) + (editing-scrumelo-story id + (scrumelo--send-json httpcon '((:status . "OK"))) + (funcall func)))))))) (defun scrumelo--send-json (httpcon obj) "Respond to HTTPCON with OBJ converted to a json structure." -- cgit v1.2.3-54-g00ecf