emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Torsten Wagner <torsten.wagner@gmail.com>
To: Org Mode Mailing List <emacs-orgmode@gnu.org>
Subject: Announce first mockup for org-server
Date: Thu, 17 Feb 2011 14:41:42 +0900	[thread overview]
Message-ID: <4D5CB516.7080706@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 3747 bytes --]

Dear all,

based on the discussions of a google calendar sync
http://thread.gmane.org/gmane.emacs.orgmode/36517/focus=36754
and about Taskwarrior a command line org-mode like program
http://thread.gmane.org/gmane.emacs.orgmode/37020/focus=37076

a discussion started why not running emacs as an org-mode server and to 
define a command interface to directly communicate with org-mode.


A well defined API for such an server would have several benefits:

* External programs like orgmobile for Android and Iphone would not need 
to emulate well tested org-mode functions. They could simply order the 
server to execute them and send back the results (e.g. compile agenda).

* Mobile devices might save resources and battery power by not running 
emacs natively. This would work on devices without emacs.

* People could design different user-interfaces for different needs 
(e.g., mobile, web, widgets, command line) still using a full featured 
regular org-mode.

* Integration with other programs might be much easier (third party 
programs e.g., Taskwarrior just need to follow the API to communicate 
with org-mode)

* A server approach does not exclude running emacs natively on the 
device, instead of a full server address, 'localhost' could be used. 
Thus, it would be very easy to get a "offline" version for devices which 
can run emacs natively. Furthermore, emacs itself would be still one 
(the main) interface to org-mode.

* This is much different usage scenario then the org-export options, 
which basically transform org-mode files into another format. org-server 
should help to interactively communicate with org-mode.


Thinking about this for some time, I looked around and found the 
possibility of emacs (starting from emacs 22) to operate as server 
listing to certain ports.
I started a bit testing to see how server-communication in emacs looks 
like and ended up with a very very basic communication.
Even totally practically unusable (there is no functionality yet)  I 
thought that even at this early state it does not make much sense to 
keep it away from you. An API definition to communicate requires deep 
integration into org-mode and well thoughts how such a API might look 
like. This is something which requires intensive discussion and a good 
overview of org-mode internals (which I don't have).

Please find attached a first mock-up which demonstrates org-server 
communication.

Usage:
1. Copy org-server.el somewhere
2. Open in emacs and evaluate the buffer (or use another method to 
evaluate the file)
3. M-x org-server-start starts the org-server
4. Use a command line or a GUI based telnet client
5. Connect to localhost (127.0.0.1) and port 8051 (you can change the 
port in org-server.el if you need to use a different port)
6. Type something, press enter
7. To stop the server type M-x org-server-stop

If the command is recognized to be one of those
org-next-agenda org-search-header org-tag-search org-add-note 
org-add-tag org-remove-tag org-todo-sets
(all just made up without real functionality)
a message will be printed. If not the command will be rejected with a 
error message.

Again there is no function yet. It should simply demonstrate the 
possibility to receive and send commands to org-mode via a network 
connection. 99% of the code is copied from
http://www.emacswiki.org/emacs/EmacsEchoServer
I would like to express my thanks to the original author.

I would like to hear your ideas or even better your reports by playing 
around with it. I still have not much of an idea of elisp and org-mode 
internals and if many people here like the idea, maybe someone more 
capable would like to join or takeover to make all this happen...

All the best

With best regards

Torsten
					

[-- Attachment #2: org-server.el --]
[-- Type: text/plain, Size: 3938 bytes --]

;;; org-server.el --- A server mode for Emacs Org-mode

;; Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
;;
;; Author: Torsten Wagner <torsten dot wagner at gmail dot com>
;; Keywords: server, mobile, web, network
;; Homepage: http://orgmode.org
;; Version: 7.4
;;
;; This file is part of GNU Emacs.
;;
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; 2002/02/17 NO RELEASE YET !!!! This is just a very early mockup (even not alpha)
;;            with no functionallity purely created for discussions on orgmode
;;            mailing list. The code is 99% plain copied from 
;;            http://www.emacswiki.org/emacs/EmacsEchoServer
;;            Kudos to the original author.


(defvar org-server-port 8051
    "port of the org server")
  
(defvar org-server-clients '() 
    "a list where KEY is a client process and VALUE is the string")

(defvar org-server-commands '(org-next-agenda org-search-header org-tag-search org-add-note org-add-tag org-remove-tag org-todo-sets)
  "a list of possiple commands which can be executed by org-server")

(defun org-server-start nil
    "starts an emacs org server"
    (interactive)
    (unless (process-status "org-server")
      (make-network-process :name "org-server" :buffer "*org-server*" :family 'ipv4 :service org-server-port :sentinel 'org-server-sentinel :filter 'org-server-filter :server 't) 
      (setq org-server-clients '())
      )
    )
  
(defun org-server-stop nil
  "stop an emacs org server"
  (interactive)
  (while  org-server-clients
    (delete-process (car (car org-server-clients)))
    (setq org-server-clients (cdr org-server-clients)))
  (delete-process "org-server")
  )
  
(defun org-server-filter (proc string)   
  (let ((pending (assoc proc org-server-clients))
        message
        index
	cmd)
      ;;create entry if required
    (unless pending
      (setq org-server-clients (cons (cons proc "") org-server-clients))
      (setq pending  (assoc proc org-server-clients)))
    (setq message (concat (cdr pending) string))
    (while (setq index (string-match "\n" message))
      (setq index (1+ index))
      ;;test if the received message is a legal org-command (sanity check)
      (if (setq cmd (car (member (substring message 0 (- index 2)) (mapcar #'symbol-name org-server-commands))))
      (progn
	;demo mode just output it would be ok
       (process-send-string proc (concat (substring message 0 (- index 2)) " command would be avaiable\nMagically things would happen and wise results and answers would be send back\n"))
       (org-server-log (substring message 0 index) proc)
      )
      (progn
	;demo mode just output it is not ok
	(process-send-string proc "command not avaiable\n")
	(org-server-log (substring message 0 index) proc)
      ))
      (setq message (substring message index))
    )
    (setcdr pending message))
  )
  
(defun org-server-sentinel (proc msg)
  (delq proc org-server-clients)
  (org-server-log (format "client %s has quit" proc)))
  
;;from server.el
(defun org-server-log (string &optional client)
  "If a *org-server* buffer exists, write STRING to it for logging purposes."
  (if (get-buffer "*org-server*")
      (with-current-buffer "*org-server*"
	(goto-char (point-max))
	(insert (current-time-string)
		(if client (format " %s:" client) " ")
		string)
	(or (bolp) (newline)))))

[-- Attachment #3: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

                 reply	other threads:[~2011-02-17  5:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4D5CB516.7080706@gmail.com \
    --to=torsten.wagner@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).