;;; org-server.el --- A server mode for Emacs Org-mode ;; Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc. ;; ;; Author: Torsten Wagner ;; 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 . ;;; 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)))))