]> code.delx.au - gnu-emacs/blob - lisp/emacs-parallel/parallel-remote.el
merge from trunk
[gnu-emacs] / lisp / emacs-parallel / parallel-remote.el
1 ;; -*- mode: emacs-lisp; lexical-binding: t; -*-
2 ;;; parallel-remote.el ---
3
4 ;; Copyright (C) 2013 Grégoire Jadi
5
6 ;; Author: Grégoire Jadi <gregoire.jadi@gmail.com>
7
8 ;; This program is free software: you can redistribute it and/or
9 ;; modify it under the terms of the GNU General Public License as
10 ;; published by the Free Software Foundation, either version 3 of
11 ;; the License, or (at your option) any later version.
12
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
20
21 ;;; Commentary:
22
23 ;;; Code:
24
25 (defvar parallel-service nil)
26 (defvar parallel-task-id nil)
27 (defvar parallel-client nil)
28 (defvar parallel--executed nil)
29
30 (defun parallel-send (data)
31 (process-send-string parallel-client
32 (format "%S " (cons parallel-task-id data))))
33
34 (defun parallel-remote--init ()
35 (setq parallel-client (make-network-process :name "emacs-parallel"
36 :buffer nil
37 :server nil
38 :service parallel-service
39 :host "localhost"
40 :family 'ipv4))
41 (set-process-filter parallel-client #'parallel-remote--filter)
42 (parallel-send 'code)
43 (when noninteractive ; Batch Mode
44 ;; The evaluation is done in the `parallel--filter' but in Batch
45 ;; Mode, Emacs doesn't wait for the input, it stops as soon as
46 ;; `parallel--init' has been executed.
47 (while (null parallel--executed)
48 (sleep-for 10)))) ; arbitrary chosen
49
50 (defun parallel-remote--filter (_proc output)
51 (parallel-send
52 (if (or noninteractive
53 (not debug-on-error))
54 (condition-case err
55 (eval (read output))
56 (error err))
57 (eval (read output))))
58 (setq parallel--executed t)
59 (kill-emacs))
60
61 (provide 'parallel-remote)
62
63 ;;; parallel-remote.el ends here