[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Add TODO from external app?

From: Jeff Kowalski
Subject: Re: [O] Add TODO from external app?
Date: Wed, 2 Apr 2014 03:07:40 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

I use org-etml to serve pages from within emacs and use a custom capture 
handler, like this:

(defun jeff/capture-handler (request)
  "Handle REQUEST objects meant for 'org-capture'.
GET header should contain a path in form '/capture/KEY/LINK/TITLE/BODY'."
  (with-slots (process headers) request
    (let ((path (cdr (assoc :GET headers))))
      (if (string-match "/capture:?/\\(.*\\)" path)
            (org-protocol-capture (match-string 1 path))
            (ws-response-header process 200))
        (ws-send-404 process)))))

(setq jeff/org-ehtml-handler
  '(((:GET  . "/capture") . jeff/capture-handler)
    ((:GET  . ".*") . org-ehtml-file-handler)
    ((:POST . ".*") . org-ehtml-edit-handler)))

(when t
  (mapc (lambda (server)
          (if (= 3333 (port server))
              (ws-stop server)))
  (ws-start jeff/org-ehtml-handler 3333))

And the relevant org-capture looks like

("b" "entry.html" entry (file+headline (concat org-directory "toodledo.org") 
               "* TODO [#C] %:description\nSCHEDULED: %t\n%:initial\n"
               :immediate-finish t)


Then, I post from a hosted form served as entry.html via org-ehtml, like 

<!DOCTYPE html>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Org Entry</title>

    input[type=text] {
    -webkit-appearance: none; -moz-appearance: none;
    display: block;
    margin: 0;
    width: 100%; height: 40px;
    line-height: 40px; font-size: 17px;
    border: 1px solid #bbb;
    input[type=submit],select {
    -webkit-appearance: none; -moz-appearance: none;
    display: block;
    margin: 0;
    height: 40px;
    line-height: 40px; font-size: 17px;
    border: 1px solid #bbb;

  <script src="http://code.jquery.com/jquery-1.10.2.min.js";></script>

  <form id="target" action="/capture/b">
    <input id="title" width="100%" type="text" name="title" />
    <select id="context" name="context">
      <option value="@agendas">@agendas</option>
      <option value="@calls"  >@calls  </option>
      <option value="@errands">@errands</option>
      <option value="@home"   >@home   </option>
      <option value="@quicken">@quicken</option>
      <option value="@view"   >@view   </option>
      <option value="@waiting">@waiting</option>
      <option value="@work"   >@work   </option>
    <input type="submit" value="Submit" name="submit">

  <script type="text/javascript">
    $("#target").submit (function (event) {

        var link  = encodeURIComponent("LINK");
        var title = encodeURIComponent($("#title").val() + "  :" + 
$("#context").val() + ":");
        var body  = encodeURIComponent("");
        var xurl   = "/capture/b" + "/" + link + "/" + title + "/" + body;

            url: xurl
        }).success(function() {
            $("span").text("captured "+xurl).show().fadeOut(1000);
        }).fail(function(jqXHR, textStatus) {
            $("span").text("failed " + xurl + "<br>" + textStatus).show(); 


Forwarding ports from my machine running org-ehtml on emacs means I can 
access the page anywhere to add new tasks even from my cell phone.

You could easily call this emacs-webservice from a PHP page, but it's just 
as easy to simply serve the page from emacs itself.  Take a look at org-
ehtml and the companion webserver that Schulte wrote.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]