Selaa lähdekoodia

Switched to being called org-capture-server

Samuel W. Flint 7 vuotta sitten
vanhempi
commit
0711d4e798
1 muutettua tiedostoa jossa 238 lisäystä ja 237 poistoa
  1. 238 237
      server/edit-server.el

+ 238 - 237
server/edit-server.el

@@ -1,7 +1,8 @@
-;;; edit-server.el --- server that responds to edit requests from Chrome
+;;; org-capture-server.el --- server that responds to edit requests from Chrome
 
 
 ;; Copyright (C) 2009-2013  Alex Bennée
 ;; Copyright (C) 2009-2013  Alex Bennée
 ;; Copyright (C) 2010-2011  Riccardo Murri
 ;; Copyright (C) 2010-2011  Riccardo Murri
+;; Copyright (C) 2017 Samuel W. Flint
 
 
 ;; Author: Alex Bennée <alex@bennee.com>
 ;; Author: Alex Bennée <alex@bennee.com>
 ;; Maintainer: Alex Bennée <alex@bennee.com>
 ;; Maintainer: Alex Bennée <alex@bennee.com>
@@ -38,28 +39,28 @@
 ;; To open pages for editing in new buffers in your existing Emacs
 ;; To open pages for editing in new buffers in your existing Emacs
 ;; instance:
 ;; instance:
 ;;
 ;;
-;;   (when (require 'edit-server nil t)
-;;     (setq edit-server-new-frame nil)
-;;     (edit-server-start))
+;;   (when (require 'org-capture-server nil t)
+;;     (setq org-capture-server-new-frame nil)
+;;     (org-capture-server-start))
 ;;
 ;;
 ;; To open pages for editing in new frames using a running emacs
 ;; To open pages for editing in new frames using a running emacs
 ;; started in --daemon mode:
 ;; started in --daemon mode:
 ;;
 ;;
-;;   (when (and (require 'edit-server nil t) (daemonp))
-;;     (edit-server-start))
+;;   (when (and (require 'org-capture-server nil t) (daemonp))
+;;     (org-capture-server-start))
 ;;
 ;;
 ;; Buffers are edited in `text-mode' by default; to use a different
 ;; Buffers are edited in `text-mode' by default; to use a different
-;; major mode, change `edit-server-default-major-mode' or customize
-;; `edit-server-url-major-mode-alist' to specify major modes based
+;; major mode, change `org-capture-server-default-major-mode' or customize
+;; `org-capture-server-url-major-mode-alist' to specify major modes based
 ;; on the remote URL:
 ;; on the remote URL:
 ;;
 ;;
-;;   (setq edit-server-url-major-mode-alist
+;;   (setq org-capture-server-url-major-mode-alist
 ;;         '(("github\\.com" . markdown-mode)))
 ;;         '(("github\\.com" . markdown-mode)))
 ;;
 ;;
-;; Alternatively, set the mode in `edit-server-start-hook'.  For
+;; Alternatively, set the mode in `org-capture-server-start-hook'.  For
 ;; example:
 ;; example:
 ;;
 ;;
-;; (add-hook 'edit-server-start-hook
+;; (add-hook 'org-capture-server-start-hook
 ;;           (lambda ()
 ;;           (lambda ()
 ;;             (when (string-match "github.com" (buffer-name))
 ;;             (when (string-match "github.com" (buffer-name))
 ;;               (markdown-mode))))
 ;;               (markdown-mode))))
@@ -76,52 +77,52 @@
 
 
 ;;; Customization
 ;;; Customization
 
 
-(defcustom edit-server-port 9292
+(defcustom org-capture-server-port 9292
   "Local port the edit server listens to."
   "Local port the edit server listens to."
-  :group 'edit-server
+  :group 'org-capture-server
   :type 'integer)
   :type 'integer)
 
 
-(defcustom edit-server-host nil
+(defcustom org-capture-server-host nil
   "If not nil, accept connections from HOST address rather than just
   "If not nil, accept connections from HOST address rather than just
 localhost. This may present a security issue."
 localhost. This may present a security issue."
-  :group 'edit-server
+  :group 'org-capture-server
   :type 'boolean)
   :type 'boolean)
 
 
-(defcustom edit-server-verbose nil
+(defcustom org-capture-server-verbose nil
   "If not nil, log connections and progress also to the echo area."
   "If not nil, log connections and progress also to the echo area."
-  :group 'edit-server
+  :group 'org-capture-server
   :type 'boolean)
   :type 'boolean)
 
 
-(defcustom edit-server-done-hook nil
-  "Hook run when done editing a buffer for the Emacs HTTP edit-server.
+(defcustom org-capture-server-done-hook nil
+  "Hook run when done editing a buffer for the Emacs HTTP org-capture-server.
 Current buffer holds the text that is about to be sent back to the client."
 Current buffer holds the text that is about to be sent back to the client."
-  :group 'edit-server
+  :group 'org-capture-server
   :type 'hook)
   :type 'hook)
 
 
-(defcustom edit-server-start-hook nil
+(defcustom org-capture-server-start-hook nil
   "Hook run when starting a editing buffer.  Current buffer is
   "Hook run when starting a editing buffer.  Current buffer is
 the fully prepared editing buffer.  Use this hook to enable
 the fully prepared editing buffer.  Use this hook to enable
 buffer-specific modes or add key bindings."
 buffer-specific modes or add key bindings."
-  :group 'edit-server
+  :group 'org-capture-server
   :type 'hook)
   :type 'hook)
 
 
-(defcustom edit-server-edit-mode-hook nil
-  "Hook run when we enter edit-server-edit-mode.  This is the final step of
+(defcustom org-capture-server-edit-mode-hook nil
+  "Hook run when we enter org-capture-server-edit-mode.  This is the final step of
 an edit session and is called when all frames and displays have been
 an edit session and is called when all frames and displays have been
 set-up.  You should not set any additional major modes here though as they
 set-up.  You should not set any additional major modes here though as they
-may conflict with the edit-server-edit-mode, use the
-edit-server-start-hook instead."
-  :group 'edit-server
+may conflict with the org-capture-server-edit-mode, use the
+org-capture-server-start-hook instead."
+  :group 'org-capture-server
   :type 'hook)
   :type 'hook)
 
 
 ;; frame options
 ;; frame options
 
 
-(defcustom edit-server-new-frame t
+(defcustom org-capture-server-new-frame t
   "If not nil, edit each buffer in a new frame (and raise it)."
   "If not nil, edit each buffer in a new frame (and raise it)."
-  :group 'edit-server
+  :group 'org-capture-server
   :type 'boolean)
   :type 'boolean)
 
 
-(defcustom edit-server-new-frame-alist
+(defcustom org-capture-server-new-frame-alist
   '((name . "Edit with Emacs FRAME")
   '((name . "Edit with Emacs FRAME")
     (width . 80)
     (width . 80)
     (height . 25)
     (height . 25)
@@ -129,46 +130,46 @@ edit-server-start-hook instead."
     (menu-bar-lines . t))
     (menu-bar-lines . t))
   "Frame parameters for new frames.  See `default-frame-alist' for examples.
   "Frame parameters for new frames.  See `default-frame-alist' for examples.
 If nil, the new frame will use the existing `default-frame-alist' values."
 If nil, the new frame will use the existing `default-frame-alist' values."
-  :group 'edit-server
+  :group 'org-capture-server
   :type '(repeat (cons :format "%v"
   :type '(repeat (cons :format "%v"
 		       (symbol :tag "Parameter")
 		       (symbol :tag "Parameter")
 		       (sexp :tag "Value"))))
 		       (sexp :tag "Value"))))
 
 
-(defcustom edit-server-default-major-mode
+(defcustom org-capture-server-default-major-mode
   'text-mode
   'text-mode
   "The default major mode to use in editing buffers, if no other
   "The default major mode to use in editing buffers, if no other
-mode is selected by `edit-server-url-major-mode-alist'."
-  :group 'edit-server
+mode is selected by `org-capture-server-url-major-mode-alist'."
+  :group 'org-capture-server
   :type 'function)
   :type 'function)
 
 
-(defcustom edit-server-url-major-mode-alist
+(defcustom org-capture-server-url-major-mode-alist
   nil
   nil
   "A-list of patterns and corresponding functions; when the first
   "A-list of patterns and corresponding functions; when the first
-pattern is encountered which matches `edit-server-url', the
+pattern is encountered which matches `org-capture-server-url', the
 corresponding function will be called in order to set the desired
 corresponding function will be called in order to set the desired
 major mode. If no pattern matches,
 major mode. If no pattern matches,
-`edit-server-default-major-mode' will be used."
-  :group 'edit-server
+`org-capture-server-default-major-mode' will be used."
+  :group 'org-capture-server
   :type '(alist :key-type (string :tag "Regexp")
   :type '(alist :key-type (string :tag "Regexp")
 		:value-type (function :tag "Major mode function")))
 		:value-type (function :tag "Major mode function")))
 
 
-(defcustom edit-server-new-frame-mode-line t
+(defcustom org-capture-server-new-frame-mode-line t
   "Show the emacs frame's mode-line if set to t; hide if nil."
   "Show the emacs frame's mode-line if set to t; hide if nil."
-  :group 'edit-server
+  :group 'org-capture-server
   :type 'boolean)
   :type 'boolean)
 
 
 ;;; Variables
 ;;; Variables
 
 
-(defconst edit-server-process-buffer-name " *edit-server*"
-  "Template name of the edit-server process buffers.")
+(defconst org-capture-server-process-buffer-name " *org-capture-server*"
+  "Template name of the org-capture-server process buffers.")
 
 
-(defconst edit-server-log-buffer-name "*edit-server-log*"
-  "Name of the edit-server process buffers.")
+(defconst org-capture-server-log-buffer-name "*org-capture-server-log*"
+  "Name of the org-capture-server process buffers.")
 
 
-(defconst edit-server-edit-buffer-name "TEXTAREA"
-  "Template name of the edit-server text editing buffers.")
+(defconst org-capture-server-edit-buffer-name "TEXTAREA"
+  "Template name of the org-capture-server text editing buffers.")
 
 
-(defvar edit-server-clients ()
+(defvar org-capture-server-clients ()
   "List of all client processes associated with the server process.")
   "List of all client processes associated with the server process.")
 
 
 ;; Buffer local variables
 ;; Buffer local variables
@@ -178,71 +179,71 @@ major mode. If no pattern matches,
 ;; back when ready. They are `permanent-local` to avoid being reset if
 ;; back when ready. They are `permanent-local` to avoid being reset if
 ;; the buffer changes major modes.
 ;; the buffer changes major modes.
 
 
-(defvar edit-server-proc nil
+(defvar org-capture-server-proc nil
   "Network process associated with the current edit.")
   "Network process associated with the current edit.")
-(make-variable-buffer-local 'edit-server-proc)
-(put 'edit-server-proc 'permanent-local t)
+(make-variable-buffer-local 'org-capture-server-proc)
+(put 'org-capture-server-proc 'permanent-local t)
 
 
-(defvar edit-server-frame nil
-  "The frame created for a new edit-server process.")
-(make-variable-buffer-local 'edit-server-frame)
-(put 'edit-server-frame 'permanent-local t)
+(defvar org-capture-server-frame nil
+  "The frame created for a new org-capture-server process.")
+(make-variable-buffer-local 'org-capture-server-frame)
+(put 'org-capture-server-frame 'permanent-local t)
 
 
-(defvar edit-server-phase nil
+(defvar org-capture-server-phase nil
   "Symbol indicating the state of the HTTP request parsing.")
   "Symbol indicating the state of the HTTP request parsing.")
-(make-variable-buffer-local 'edit-server-phase)
-(put 'edit-server-phase 'permanent-local t)
+(make-variable-buffer-local 'org-capture-server-phase)
+(put 'org-capture-server-phase 'permanent-local t)
 
 
-(defvar edit-server-received nil
+(defvar org-capture-server-received nil
   "Number of bytes received so far in the client buffer.
   "Number of bytes received so far in the client buffer.
 Depending on the character encoding, may be different from the buffer length.")
 Depending on the character encoding, may be different from the buffer length.")
-(make-variable-buffer-local 'edit-server-received)
-(put 'edit-server-received 'permanent-local t)
+(make-variable-buffer-local 'org-capture-server-received)
+(put 'org-capture-server-received 'permanent-local t)
 
 
-(defvar edit-server-request nil
+(defvar org-capture-server-request nil
   "The HTTP request (GET, HEAD, POST) received.")
   "The HTTP request (GET, HEAD, POST) received.")
-(make-variable-buffer-local 'edit-server-request)
-(put 'edit-server-request 'permanent-local t)
+(make-variable-buffer-local 'org-capture-server-request)
+(put 'org-capture-server-request 'permanent-local t)
 
 
-(defvar edit-server-request-url nil
+(defvar org-capture-server-request-url nil
   "The HTTP request URL received.")
   "The HTTP request URL received.")
-(make-variable-buffer-local 'edit-server-request-url)
-(put 'edit-server-request-url 'permanent-local t)
+(make-variable-buffer-local 'org-capture-server-request-url)
+(put 'org-capture-server-request-url 'permanent-local t)
 
 
-(defvar edit-server-content-length nil
+(defvar org-capture-server-content-length nil
   "The value gotten from the HTTP `Content-Length' header.")
   "The value gotten from the HTTP `Content-Length' header.")
-(make-variable-buffer-local 'edit-server-content-length)
-(put 'edit-server-content-length 'permanent-local t)
+(make-variable-buffer-local 'org-capture-server-content-length)
+(put 'org-capture-server-content-length 'permanent-local t)
 
 
-(defvar edit-server-url nil
+(defvar org-capture-server-url nil
   "The value gotten from the HTTP `x-url' header.")
   "The value gotten from the HTTP `x-url' header.")
-(make-variable-buffer-local 'edit-server-url)
-(put 'edit-server-url 'permanent-local t)
+(make-variable-buffer-local 'org-capture-server-url)
+(put 'org-capture-server-url 'permanent-local t)
 
 
-(defvar edit-server-file nil
+(defvar org-capture-server-file nil
   "The value gotten from the HTTP `x-file' header.")
   "The value gotten from the HTTP `x-file' header.")
-(make-variable-buffer-local 'edit-server-file)
-(put 'edit-server-file 'permanent-local t)
+(make-variable-buffer-local 'org-capture-server-file)
+(put 'org-capture-server-file 'permanent-local t)
 
 
 ;;; Mode magic
 ;;; Mode magic
 ;;
 ;;
-;; We want to re-map some of the keys to trigger edit-server-done
+;; We want to re-map some of the keys to trigger org-capture-server-done
 ;; instead of the usual emacs like behaviour. However using
 ;; instead of the usual emacs like behaviour. However using
 ;; local-set-key will affect all buffers of the same mode, hence we
 ;; local-set-key will affect all buffers of the same mode, hence we
 ;; define a special (derived) mode for handling editing of text areas.
 ;; define a special (derived) mode for handling editing of text areas.
 
 
 
 
-(defvar edit-server-edit-mode-map
+(defvar org-capture-server-edit-mode-map
   (let ((map (make-sparse-keymap)))
   (let ((map (make-sparse-keymap)))
-    (define-key map (kbd "C-x C-s") 'edit-server-save)
-    (define-key map (kbd "C-x #")   'edit-server-done)
-    (define-key map (kbd "C-c C-c") 'edit-server-done)
-    (define-key map (kbd "C-x C-c") 'edit-server-abort)
+    (define-key map (kbd "C-x C-s") 'org-capture-server-save)
+    (define-key map (kbd "C-x #")   'org-capture-server-done)
+    (define-key map (kbd "C-c C-c") 'org-capture-server-done)
+    (define-key map (kbd "C-x C-c") 'org-capture-server-abort)
     map)
     map)
-  "Keymap for minor mode `edit-server-edit-mode'.
+  "Keymap for minor mode `org-capture-server-edit-mode'.
 
 
 Redefine a few common Emacs keystrokes to functions that can
 Redefine a few common Emacs keystrokes to functions that can
-deal with the response to the edit-server request.
+deal with the response to the org-capture-server request.
 
 
 Any of the following keys will close the buffer and send the text
 Any of the following keys will close the buffer and send the text
 to the HTTP client: C-x #, C-c C-c.
 to the HTTP client: C-x #, C-c C-c.
@@ -252,35 +253,35 @@ Pressing C-x C-s will save the current state to the kill-ring.
 If any of the above isused with a prefix argument, the
 If any of the above isused with a prefix argument, the
 unmodified text is sent back instead.")
 unmodified text is sent back instead.")
 
 
-(define-minor-mode edit-server-edit-mode
-  "Minor mode enabled on buffers opened by `edit-server-accept'.
+(define-minor-mode org-capture-server-edit-mode
+  "Minor mode enabled on buffers opened by `org-capture-server-accept'.
 
 
 Its sole purpose is currently to enable
 Its sole purpose is currently to enable
-`edit-server-edit-mode-map', which overrides common keystrokes to
+`org-capture-server-edit-mode-map', which overrides common keystrokes to
 send a response back to the client."
 send a response back to the client."
-  :group 'edit-server
+  :group 'org-capture-server
   :lighter " EditSrv"
   :lighter " EditSrv"
   :init-value nil
   :init-value nil
-  :keymap edit-server-edit-mode-map
+  :keymap org-capture-server-edit-mode-map
   (when (and
   (when (and
          (numberp arg)
          (numberp arg)
          (> arg 0))
          (> arg 0))
-    (run-hooks 'edit-server-edit-mode-hook)))
+    (run-hooks 'org-capture-server-edit-mode-hook)))
 
 
-(defun turn-on-edit-server-edit-mode-if-server ()
-  "Turn on `edit-server-edit-mode' if in an edit-server buffer."
-  (when edit-server-proc
-    (edit-server-edit-mode t)))
+(defun turn-on-org-capture-server-edit-mode-if-server ()
+  "Turn on `org-capture-server-edit-mode' if in an org-capture-server buffer."
+  (when org-capture-server-proc
+    (org-capture-server-edit-mode t)))
 
 
-(define-globalized-minor-mode global-edit-server-edit-mode
-  edit-server-edit-mode turn-on-edit-server-edit-mode-if-server)
-(global-edit-server-edit-mode t)
+(define-globalized-minor-mode global-org-capture-server-edit-mode
+  org-capture-server-edit-mode turn-on-org-capture-server-edit-mode-if-server)
+(global-org-capture-server-edit-mode t)
 
 
 
 
 ;; Edit Server socket code
 ;; Edit Server socket code
 
 
 ;; Avoid an unnecessary prompt about active processes when exiting
 ;; Avoid an unnecessary prompt about active processes when exiting
-;; emacs with no active edit-server clients
+;; emacs with no active org-capture-server clients
 ;; https://github.com/stsquad/emacs_chrome/issues/67
 ;; https://github.com/stsquad/emacs_chrome/issues/67
 ;;
 ;;
 ;; According to http://emacswiki.org/emacs/AdviceVsHooks advice is a
 ;; According to http://emacswiki.org/emacs/AdviceVsHooks advice is a
@@ -288,69 +289,69 @@ send a response back to the client."
 ;; only hooks run by save-buffers-kill-emacs are defined by
 ;; only hooks run by save-buffers-kill-emacs are defined by
 ;; kill-emacs-query-functions and run *after* the check for active
 ;; kill-emacs-query-functions and run *after* the check for active
 ;; processes which results in precisely the interactive prompt we want
 ;; processes which results in precisely the interactive prompt we want
-;; to avoid when edit-server has no active clients.  So it seems that
+;; to avoid when org-capture-server has no active clients.  So it seems that
 ;; advice is the only solution until save-buffers-kill-emacs offers an
 ;; advice is the only solution until save-buffers-kill-emacs offers an
 ;; earlier hook.
 ;; earlier hook.
 (defadvice save-buffers-kill-emacs
 (defadvice save-buffers-kill-emacs
-      (before edit-server-stop-before-kill-emacs)
-      "Call `edit-server-stop' if there are no active clients, to
-avoid the user being prompted to kill the edit-server process."
-      (or edit-server-clients (edit-server-stop)))
+      (before org-capture-server-stop-before-kill-emacs)
+      "Call `org-capture-server-stop' if there are no active clients, to
+avoid the user being prompted to kill the org-capture-server process."
+      (or org-capture-server-clients (org-capture-server-stop)))
 
 
 ;;;###autoload
 ;;;###autoload
-(defun edit-server-start (&optional verbose)
+(defun org-capture-server-start (&optional verbose)
   "Start the edit server.
   "Start the edit server.
 
 
 If argument VERBOSE is non-nil, logs all server activity to buffer
 If argument VERBOSE is non-nil, logs all server activity to buffer
-`*edit-server-log*'.  When called interactivity, a prefix argument
+`*org-capture-server-log*'.  When called interactivity, a prefix argument
 will cause it to be verbose."
 will cause it to be verbose."
   (interactive "P")
   (interactive "P")
-  (if (or (process-status "edit-server")
+  (if (or (process-status "org-capture-server")
 	  (null (condition-case err
 	  (null (condition-case err
                     (let ((proc (make-network-process
                     (let ((proc (make-network-process
-                                 :name "edit-server"
-                                 :buffer edit-server-process-buffer-name
+                                 :name "org-capture-server"
+                                 :buffer org-capture-server-process-buffer-name
                                  :family 'ipv4
                                  :family 'ipv4
-                                 :host (or edit-server-host 'local)
-                                 :service edit-server-port
-                                 :log 'edit-server-accept
+                                 :host (or org-capture-server-host 'local)
+                                 :service org-capture-server-port
+                                 :log 'org-capture-server-accept
                                  :server t
                                  :server t
                                  :noquery t)))
                                  :noquery t)))
                       (set-process-coding-system proc 'utf-8 'utf-8)
                       (set-process-coding-system proc 'utf-8 'utf-8)
                       proc)
                       proc)
 		  (file-error nil))))
 		  (file-error nil))))
-      (message "An edit-server process is already running")
+      (message "An org-capture-server process is already running")
     (ad-activate 'save-buffers-kill-emacs)
     (ad-activate 'save-buffers-kill-emacs)
-    (setq edit-server-clients '())
-    (when verbose (get-buffer-create edit-server-log-buffer-name))
-    (edit-server-log nil "Created a new edit-server process")))
+    (setq org-capture-server-clients '())
+    (when verbose (get-buffer-create org-capture-server-log-buffer-name))
+    (org-capture-server-log nil "Created a new org-capture-server process")))
 
 
-(defun edit-server-stop nil
+(defun org-capture-server-stop nil
   "Stop the edit server"
   "Stop the edit server"
   (interactive)
   (interactive)
-  (while edit-server-clients
-    (edit-server-kill-client (car edit-server-clients))
-    (setq edit-server-clients (cdr edit-server-clients)))
-  (if (process-status "edit-server")
-      (delete-process "edit-server")
+  (while org-capture-server-clients
+    (org-capture-server-kill-client (car org-capture-server-clients))
+    (setq org-capture-server-clients (cdr org-capture-server-clients)))
+  (if (process-status "org-capture-server")
+      (delete-process "org-capture-server")
     (message "No edit server running"))
     (message "No edit server running"))
-  (when (get-buffer edit-server-process-buffer-name)
-    (kill-buffer edit-server-process-buffer-name))
+  (when (get-buffer org-capture-server-process-buffer-name)
+    (kill-buffer org-capture-server-process-buffer-name))
   (ad-disable-advice 'save-buffers-kill-emacs
   (ad-disable-advice 'save-buffers-kill-emacs
-                     'before 'edit-server-stop-before-kill-emacs)
+                     'before 'org-capture-server-stop-before-kill-emacs)
   ;; Disabling advice doesn't take effect until you (re-)activate
   ;; Disabling advice doesn't take effect until you (re-)activate
   ;; all advice for the function.
   ;; all advice for the function.
   (ad-activate 'save-buffers-kill-emacs))
   (ad-activate 'save-buffers-kill-emacs))
 
 
-(defun edit-server-log (proc fmt &rest args)
-  "If a `*edit-server-log*' buffer exists, write STRING to it.
-This is done for logging purposes.  If `edit-server-verbose' is
+(defun org-capture-server-log (proc fmt &rest args)
+  "If a `*org-capture-server-log*' buffer exists, write STRING to it.
+This is done for logging purposes.  If `org-capture-server-verbose' is
 non-nil, then STRING is also echoed to the message line."
 non-nil, then STRING is also echoed to the message line."
   (let ((string (apply 'format fmt args)))
   (let ((string (apply 'format fmt args)))
-    (when edit-server-verbose
+    (when org-capture-server-verbose
       (message string))
       (message string))
-    (when (get-buffer edit-server-log-buffer-name)
-      (with-current-buffer edit-server-log-buffer-name
+    (when (get-buffer org-capture-server-log-buffer-name)
+      (with-current-buffer org-capture-server-log-buffer-name
 	(goto-char (point-max))
 	(goto-char (point-max))
 	(insert (current-time-string)
 	(insert (current-time-string)
 		" "
 		" "
@@ -362,26 +363,26 @@ non-nil, then STRING is also echoed to the message line."
 		string)
 		string)
 	(or (bolp) (newline))))))
 	(or (bolp) (newline))))))
 
 
-(defun edit-server-accept (server client msg)
+(defun org-capture-server-accept (server client msg)
   "Accept a new client connection."
   "Accept a new client connection."
-  (let ((buffer (generate-new-buffer edit-server-process-buffer-name)))
+  (let ((buffer (generate-new-buffer org-capture-server-process-buffer-name)))
     (buffer-disable-undo buffer)
     (buffer-disable-undo buffer)
     (set-process-buffer client buffer)
     (set-process-buffer client buffer)
-    (set-process-filter client 'edit-server-filter)
+    (set-process-filter client 'org-capture-server-filter)
     ;; kill-buffer kills the associated process
     ;; kill-buffer kills the associated process
     (set-process-query-on-exit-flag client nil)
     (set-process-query-on-exit-flag client nil)
     (with-current-buffer buffer
     (with-current-buffer buffer
-      (setq edit-server-phase 'wait
-	    edit-server-received 0
-	    edit-server-request nil
-	    edit-server-request-url nil))
-    (setq edit-server-content-length nil
-	  edit-server-url nil
-	  edit-server-file nil))
-  (add-to-list 'edit-server-clients client)
-  (edit-server-log client msg))
-
-(defun edit-server-filter (proc string)
+      (setq org-capture-server-phase 'wait
+	    org-capture-server-received 0
+	    org-capture-server-request nil
+	    org-capture-server-request-url nil))
+    (setq org-capture-server-content-length nil
+	  org-capture-server-url nil
+	  org-capture-server-file nil))
+  (add-to-list 'org-capture-server-clients client)
+  (org-capture-server-log client msg))
+
+(defun org-capture-server-filter (proc string)
   "Process data received from the client."
   "Process data received from the client."
   ;; there is no guarantee that data belonging to the same client
   ;; there is no guarantee that data belonging to the same client
   ;; request will arrive all in one go; therefore, we must accumulate
   ;; request will arrive all in one go; therefore, we must accumulate
@@ -389,109 +390,109 @@ non-nil, then STRING is also echoed to the message line."
   ;; requires us to keep track of the processing state.
   ;; requires us to keep track of the processing state.
   (with-current-buffer (process-buffer proc)
   (with-current-buffer (process-buffer proc)
     (insert string)
     (insert string)
-    (setq edit-server-received
-	  (+ edit-server-received (string-bytes string)))
-    (when (eq edit-server-phase 'wait)
+    (setq org-capture-server-received
+	  (+ org-capture-server-received (string-bytes string)))
+    (when (eq org-capture-server-phase 'wait)
       ;; look for a complete HTTP request string
       ;; look for a complete HTTP request string
       (save-excursion
       (save-excursion
 	(goto-char (point-min))
 	(goto-char (point-min))
 	(when (re-search-forward
 	(when (re-search-forward
 	       "^\\([A-Z]+\\)\\s-+\\(\\S-+\\)\\s-+\\(HTTP/[0-9\.]+\\)\r?\n"
 	       "^\\([A-Z]+\\)\\s-+\\(\\S-+\\)\\s-+\\(HTTP/[0-9\.]+\\)\r?\n"
 	       nil t)
 	       nil t)
-	  (setq edit-server-request (match-string 1)
-		edit-server-request-url (match-string 2)
-		edit-server-content-length nil
-		edit-server-phase 'head)
-	  (edit-server-log
+	  (setq org-capture-server-request (match-string 1)
+		org-capture-server-request-url (match-string 2)
+		org-capture-server-content-length nil
+		org-capture-server-phase 'head)
+	  (org-capture-server-log
 	   proc "Got HTTP `%s' request of url `%s', processing in buffer `%s'..."
 	   proc "Got HTTP `%s' request of url `%s', processing in buffer `%s'..."
-	   edit-server-request edit-server-request-url (current-buffer)))))
+	   org-capture-server-request org-capture-server-request-url (current-buffer)))))
 
 
-    (when (eq edit-server-phase 'head)
+    (when (eq org-capture-server-phase 'head)
       ;; look for "Content-length" header
       ;; look for "Content-length" header
       (save-excursion
       (save-excursion
 	(goto-char (point-min))
 	(goto-char (point-min))
 	(when (re-search-forward "^Content-Length:\\s-+\\([0-9]+\\)" nil t)
 	(when (re-search-forward "^Content-Length:\\s-+\\([0-9]+\\)" nil t)
-	  (setq edit-server-content-length
+	  (setq org-capture-server-content-length
 		(string-to-number (match-string 1)))))
 		(string-to-number (match-string 1)))))
       ;; look for "x-url" header
       ;; look for "x-url" header
       (save-excursion
       (save-excursion
 	(goto-char (point-min))
 	(goto-char (point-min))
 	(when (re-search-forward "^x-url: .*/\\{2,3\\}\\([^\r\n]+\\)" nil t)
 	(when (re-search-forward "^x-url: .*/\\{2,3\\}\\([^\r\n]+\\)" nil t)
-	  (setq edit-server-url (match-string 1))))
+	  (setq org-capture-server-url (match-string 1))))
       ;; look for "x-file" header
       ;; look for "x-file" header
       (save-excursion
       (save-excursion
 	(goto-char (point-min))
 	(goto-char (point-min))
 	(when (re-search-forward "^x-file: \\([^\r\n]+\\)" nil t)
 	(when (re-search-forward "^x-file: \\([^\r\n]+\\)" nil t)
-	  (edit-server-log proc "Found x-file: %s" (match-string 1))
-	  (setq edit-server-file (match-string 1))))
+	  (org-capture-server-log proc "Found x-file: %s" (match-string 1))
+	  (setq org-capture-server-file (match-string 1))))
       ;; look for head/body separator
       ;; look for head/body separator
       (save-excursion
       (save-excursion
 	(goto-char (point-min))
 	(goto-char (point-min))
 	(when (re-search-forward "\\(\r?\n\\)\\{2\\}" nil t)
 	(when (re-search-forward "\\(\r?\n\\)\\{2\\}" nil t)
 	  ;; HTTP headers are pure ASCII (1 char = 1 byte), so we can subtract
 	  ;; HTTP headers are pure ASCII (1 char = 1 byte), so we can subtract
 	  ;; the buffer position from the count of received bytes
 	  ;; the buffer position from the count of received bytes
-	  (setq edit-server-received
-		(- edit-server-received (- (match-end 0) (point-min))))
+	  (setq org-capture-server-received
+		(- org-capture-server-received (- (match-end 0) (point-min))))
 	  ;; discard headers - keep only HTTP content in buffer
 	  ;; discard headers - keep only HTTP content in buffer
 	  (delete-region (point-min) (match-end 0))
 	  (delete-region (point-min) (match-end 0))
-	  (edit-server-log proc
+	  (org-capture-server-log proc
 			   "Processed headers, length: %s, url: %s, file: %s"
 			   "Processed headers, length: %s, url: %s, file: %s"
-			   edit-server-content-length edit-server-url edit-server-file)
-	  (setq edit-server-phase 'body))))
+			   org-capture-server-content-length org-capture-server-url org-capture-server-file)
+	  (setq org-capture-server-phase 'body))))
 
 
-    (when (eq edit-server-phase 'body)
-      (if (and edit-server-content-length
-	       (> edit-server-content-length edit-server-received))
-	  (edit-server-log proc
+    (when (eq org-capture-server-phase 'body)
+      (if (and org-capture-server-content-length
+	       (> org-capture-server-content-length org-capture-server-received))
+	  (org-capture-server-log proc
 			   "Received %d bytes of %d ..."
 			   "Received %d bytes of %d ..."
-			   edit-server-received edit-server-content-length)
+			   org-capture-server-received org-capture-server-content-length)
 	;; all content transferred - process request now
 	;; all content transferred - process request now
 	(cond
 	(cond
-	 ((string-match "foreground" edit-server-request-url)
-	  (edit-server-foreground-request (current-buffer))
-	  (edit-server-send-response proc "edit-server received foreground request.\n")
-	  (edit-server-kill-client proc))
-	 ((string= edit-server-request "POST")
+	 ((string-match "foreground" org-capture-server-request-url)
+	  (org-capture-server-foreground-request (current-buffer))
+	  (org-capture-server-send-response proc "org-capture-server received foreground request.\n")
+	  (org-capture-server-kill-client proc))
+	 ((string= org-capture-server-request "POST")
 	  ;; create editing buffer, and move content to it
 	  ;; create editing buffer, and move content to it
-	  (edit-server-find-or-create-edit-buffer proc edit-server-file))
+	  (org-capture-server-find-or-create-edit-buffer proc org-capture-server-file))
 	 (t
 	 (t
 	  ;; send 200 OK response to any other request
 	  ;; send 200 OK response to any other request
-	  (edit-server-send-response proc "edit-server is running.\n")
-	  (edit-server-kill-client proc)))
+	  (org-capture-server-send-response proc "org-capture-server is running.\n")
+	  (org-capture-server-kill-client proc)))
 	;; wait for another connection to arrive
 	;; wait for another connection to arrive
-	(setq edit-server-received 0)
-	(setq edit-server-phase 'wait)))))
+	(setq org-capture-server-received 0)
+	(setq org-capture-server-phase 'wait)))))
 
 
-(defun edit-server-foreground-request (buffer)
+(defun org-capture-server-foreground-request (buffer)
   "Bring Emacs into the foreground after a request from Chrome.
   "Bring Emacs into the foreground after a request from Chrome.
 `buffer' is the process buffer which contains any potential contents
 `buffer' is the process buffer which contains any potential contents
 to be passed into the kill ring.
 to be passed into the kill ring.
 
 
 The new frame will have a specific frame parameter of
 The new frame will have a specific frame parameter of
-  `edit-server-forground-frame' set to 't"
+  `org-capture-server-forground-frame' set to 't"
   (when (bufferp buffer)
   (when (bufferp buffer)
     (with-current-buffer buffer
     (with-current-buffer buffer
       (kill-ring-save (point-min) (point-max))))
       (kill-ring-save (point-min) (point-max))))
   
   
-  (when edit-server-new-frame
+  (when org-capture-server-new-frame
     (set-frame-parameter
     (set-frame-parameter
      (make-frame-on-display (getenv "DISPLAY")
      (make-frame-on-display (getenv "DISPLAY")
-                            edit-server-new-frame-alist)
-     'edit-server-forground-frame 't)))
+                            org-capture-server-new-frame-alist)
+     'org-capture-server-forground-frame 't)))
 
 
-(defun edit-server-show-edit-buffer (buffer)
+(defun org-capture-server-show-edit-buffer (buffer)
   "Show edit `BUFFER' by creating a frame or raising the selected
   "Show edit `BUFFER' by creating a frame or raising the selected
 frame. If a frame was created it returns `FRAME'."
 frame. If a frame was created it returns `FRAME'."
   (let ((edit-frame nil))
   (let ((edit-frame nil))
-    (when edit-server-new-frame
+    (when org-capture-server-new-frame
       (setq edit-frame
       (setq edit-frame
             (if (memq window-system '(ns mac nil))
             (if (memq window-system '(ns mac nil))
                 ;; Aquamacs, Emacs NS, Emacs (experimental) Mac port, termcap.
                 ;; Aquamacs, Emacs NS, Emacs (experimental) Mac port, termcap.
                 ;; matching (nil) avoids use of DISPLAY from TTY environments.
                 ;; matching (nil) avoids use of DISPLAY from TTY environments.
-                (make-frame edit-server-new-frame-alist)
+                (make-frame org-capture-server-new-frame-alist)
               (make-frame-on-display (getenv "DISPLAY")
               (make-frame-on-display (getenv "DISPLAY")
-                                     edit-server-new-frame-alist)))
-      (unless edit-server-new-frame-mode-line
+                                     org-capture-server-new-frame-alist)))
+      (unless org-capture-server-new-frame-mode-line
         (setq mode-line-format nil))
         (setq mode-line-format nil))
       (select-frame edit-frame)
       (select-frame edit-frame)
       (when (and (eq window-system 'x)
       (when (and (eq window-system 'x)
@@ -504,24 +505,24 @@ frame. If a frame was created it returns `FRAME'."
     (select-frame-set-input-focus (window-frame (selected-window)))
     (select-frame-set-input-focus (window-frame (selected-window)))
     edit-frame))
     edit-frame))
 
 
-(defun edit-server-choose-major-mode ()
-  "Use `edit-server-url-major-mode-alist' to choose a major mode
-initialization function based on `edit-server-url', or fall back
-to `edit-server-default-major-mode'"
-  (funcall (or (assoc-default edit-server-url
-                              edit-server-url-major-mode-alist 'string-match)
-               edit-server-default-major-mode)))
+(defun org-capture-server-choose-major-mode ()
+  "Use `org-capture-server-url-major-mode-alist' to choose a major mode
+initialization function based on `org-capture-server-url', or fall back
+to `org-capture-server-default-major-mode'"
+  (funcall (or (assoc-default org-capture-server-url
+                              org-capture-server-url-major-mode-alist 'string-match)
+               org-capture-server-default-major-mode)))
 
 
-(defun edit-server-find-or-create-edit-buffer (proc &optional existing)
+(defun org-capture-server-find-or-create-edit-buffer (proc &optional existing)
   "Find and existing or create an new edit buffer, place content in it
   "Find and existing or create an new edit buffer, place content in it
 and save the network process for the final call back"
 and save the network process for the final call back"
   ;; FIXME: `existing' is useless: see issue #104.
   ;; FIXME: `existing' is useless: see issue #104.
   (let* ((existing-buffer (and (stringp existing) (get-buffer existing)))
   (let* ((existing-buffer (and (stringp existing) (get-buffer existing)))
 	 (buffer (or existing-buffer (generate-new-buffer
 	 (buffer (or existing-buffer (generate-new-buffer
-				      (or edit-server-url
-					  edit-server-edit-buffer-name)))))
+				      (or org-capture-server-url
+					  org-capture-server-edit-buffer-name)))))
 
 
-    (edit-server-log proc
+    (org-capture-server-log proc
 		     "using buffer %s for edit (existing-buffer is %s)"
 		     "using buffer %s for edit (existing-buffer is %s)"
 		     buffer existing-buffer)
 		     buffer existing-buffer)
 
 
@@ -539,25 +540,25 @@ and save the network process for the final call back"
     (when existing-buffer
     (when existing-buffer
       (kill-ring-save (point-min) (point-max)))
       (kill-ring-save (point-min) (point-max)))
 
 
-    (edit-server-log proc "copying new data into buffer")
+    (org-capture-server-log proc "copying new data into buffer")
     (copy-to-buffer buffer (point-min) (point-max))
     (copy-to-buffer buffer (point-min) (point-max))
     
     
     (with-current-buffer buffer
     (with-current-buffer buffer
-      (setq edit-server-url (with-current-buffer (process-buffer proc) edit-server-url))
-      (edit-server-choose-major-mode)
-      ;; Allow `edit-server-start-hook' to override the major mode.
+      (setq org-capture-server-url (with-current-buffer (process-buffer proc) org-capture-server-url))
+      (org-capture-server-choose-major-mode)
+      ;; Allow `org-capture-server-start-hook' to override the major mode.
       ;; (re)setting the minor mode seems to clear the buffer-local
       ;; (re)setting the minor mode seems to clear the buffer-local
       ;; variables that we depend upon for the response, so call the
       ;; variables that we depend upon for the response, so call the
       ;; hooks early on
       ;; hooks early on
-      (run-hooks 'edit-server-start-hook)
+      (run-hooks 'org-capture-server-start-hook)
       (set-buffer-modified-p 'nil)
       (set-buffer-modified-p 'nil)
-      (add-hook 'kill-buffer-hook 'edit-server-abort* nil t)
+      (add-hook 'kill-buffer-hook 'org-capture-server-abort* nil t)
       (buffer-enable-undo)
       (buffer-enable-undo)
-      (setq edit-server-proc proc
-	    edit-server-frame (edit-server-show-edit-buffer buffer))
-      (edit-server-edit-mode))))
+      (setq org-capture-server-proc proc
+	    org-capture-server-frame (org-capture-server-show-edit-buffer buffer))
+      (org-capture-server-edit-mode))))
 
 
-(defun edit-server-send-response (proc &optional body progress)
+(defun org-capture-server-send-response (proc &optional body progress)
   "Send an HTTP 200 OK response back to process PROC.
   "Send an HTTP 200 OK response back to process PROC.
 Optional second argument BODY specifies the response content:
 Optional second argument BODY specifies the response content:
     - If nil, the HTTP response will have null content.
     - If nil, the HTTP response will have null content.
@@ -567,7 +568,7 @@ Optional second argument BODY specifies the response content:
 If optional third argument progress is non-nil, then the response
 If optional third argument progress is non-nil, then the response
 will include x-file and x-open headers to allow continuation of editing."
 will include x-file and x-open headers to allow continuation of editing."
   (interactive)
   (interactive)
-  (edit-server-log proc "sending edit-server response")
+  (org-capture-server-log proc "sending org-capture-server response")
   (if (processp proc)
   (if (processp proc)
       (let ((response-header (concat
       (let ((response-header (concat
 			      "HTTP/1.0 200 OK\n"
 			      "HTTP/1.0 200 OK\n"
@@ -588,18 +589,18 @@ will include x-file and x-open headers to allow continuation of editing."
 	  (encode-coding-region (point-min) (point-max) 'utf-8)
 	  (encode-coding-region (point-min) (point-max) 'utf-8)
 	  (process-send-region proc (point-min) (point-max))))
 	  (process-send-region proc (point-min) (point-max))))
 	(process-send-eof proc)
 	(process-send-eof proc)
-	(edit-server-log proc "Editing done, sent HTTP OK response."))
-    (message "edit-server-send-response: invalid proc (bug?)")))
+	(org-capture-server-log proc "Editing done, sent HTTP OK response."))
+    (message "org-capture-server-send-response: invalid proc (bug?)")))
 
 
-(defun edit-server-kill-client (proc)
+(defun org-capture-server-kill-client (proc)
   "Kill client process PROC and remove it from the list."
   "Kill client process PROC and remove it from the list."
   (let ((procbuf (process-buffer proc)))
   (let ((procbuf (process-buffer proc)))
     (delete-process proc)
     (delete-process proc)
     (when (buffer-live-p procbuf)
     (when (buffer-live-p procbuf)
       (kill-buffer procbuf))
       (kill-buffer procbuf))
-    (setq edit-server-clients (delq proc edit-server-clients))))
+    (setq org-capture-server-clients (delq proc org-capture-server-clients))))
 
 
-(defun edit-server-done (&optional abort nokill)
+(defun org-capture-server-done (&optional abort nokill)
   "Finish editing: send HTTP response back, close client and editing buffers.
   "Finish editing: send HTTP response back, close client and editing buffers.
 
 
 The current contents of the buffer are sent back to the HTTP
 The current contents of the buffer are sent back to the HTTP
@@ -611,17 +612,17 @@ buffer is not killed and the buffer name is passed to calling process.
 When called interactively, use prefix arg to abort editing."
 When called interactively, use prefix arg to abort editing."
   (interactive "P")
   (interactive "P")
   ;; Do nothing if the connection is closed by the browser (tab killed, etc.)
   ;; Do nothing if the connection is closed by the browser (tab killed, etc.)
-  (unless (eq (process-status edit-server-proc) 'closed)
+  (unless (eq (process-status org-capture-server-proc) 'closed)
     (let ((buffer (current-buffer))
     (let ((buffer (current-buffer))
-	  (proc edit-server-proc)
-	  (procbuf (process-buffer edit-server-proc)))
-      ;; edit-server-* vars are buffer-local,
+	  (proc org-capture-server-proc)
+	  (procbuf (process-buffer org-capture-server-proc)))
+      ;; org-capture-server-* vars are buffer-local,
       ;; so they must be used before issuing kill-buffer
       ;; so they must be used before issuing kill-buffer
       (if abort
       (if abort
 	  ;; send back original content
 	  ;; send back original content
 	  (with-current-buffer procbuf
 	  (with-current-buffer procbuf
-	    (run-hooks 'edit-server-done-hook)
-	    (edit-server-send-response proc t))
+	    (run-hooks 'org-capture-server-done-hook)
+	    (org-capture-server-send-response proc t))
 	;; send back edited content
 	;; send back edited content
 	(save-restriction
 	(save-restriction
 	  (widen)
 	  (widen)
@@ -630,40 +631,40 @@ When called interactively, use prefix arg to abort editing."
 	  (dolist (format buffer-file-format)
 	  (dolist (format buffer-file-format)
 	    (format-encode-region (point-min) (point-max) format))
 	    (format-encode-region (point-min) (point-max) format))
 	  ;; send back
 	  ;; send back
-	  (run-hooks 'edit-server-done-hook)
-	  (edit-server-send-response proc t nokill)
-	  (edit-server-log proc "sent response to browser")))
-      (when edit-server-frame
-	(delete-frame edit-server-frame))
+	  (run-hooks 'org-capture-server-done-hook)
+	  (org-capture-server-send-response proc t nokill)
+	  (org-capture-server-log proc "sent response to browser")))
+      (when org-capture-server-frame
+	(delete-frame org-capture-server-frame))
       ;; delete-frame may change the current buffer
       ;; delete-frame may change the current buffer
       (unless nokill
       (unless nokill
         ;; don't run abort twice in a row.
         ;; don't run abort twice in a row.
-        (remove-hook 'kill-buffer-hook 'edit-server-abort*)
+        (remove-hook 'kill-buffer-hook 'org-capture-server-abort*)
 	(kill-buffer buffer))
 	(kill-buffer buffer))
-      (edit-server-kill-client proc))))
+      (org-capture-server-kill-client proc))))
 
 
-;; edit-server-save uses the iterative edit-server option (send a
+;; org-capture-server-save uses the iterative org-capture-server option (send a
 ;; buffer back to the client which then returns new request to
 ;; buffer back to the client which then returns new request to
-;; continue the session). The edit-server then switches back to the
+;; continue the session). The org-capture-server then switches back to the
 ;; buffer referenced by the x-file header.
 ;; buffer referenced by the x-file header.
 ;;
 ;;
 
 
-(defun edit-server-save ()
+(defun org-capture-server-save ()
   "Save the current state of the edit buffer but don't close it."
   "Save the current state of the edit buffer but don't close it."
   (interactive)
   (interactive)
-  (edit-server-done nil t))
+  (org-capture-server-done nil t))
 
 
-(defun edit-server-abort ()
+(defun org-capture-server-abort ()
   "Discard editing and send the original text back to the browser."
   "Discard editing and send the original text back to the browser."
   (interactive)
   (interactive)
-  (edit-server-done t))
+  (org-capture-server-done t))
 
 
-(defun edit-server-abort* ()
+(defun org-capture-server-abort* ()
   "Discard editing and send the original text back to the browser,
   "Discard editing and send the original text back to the browser,
 but don't kill the editing buffer."
 but don't kill the editing buffer."
   (interactive)
   (interactive)
-  (edit-server-done t t))
+  (org-capture-server-done t t))
 
 
-(provide 'edit-server)
+(provide 'org-capture-server)
 
 
-;;; edit-server.el ends here
+;;; org-capture-server.el ends here