~ubuntu-branches/ubuntu/hardy/texmacs/hardy

« back to all changes in this revision

Viewing changes to TeXmacs/progs/texmacs/plugin/plugin-cmd.scm

  • Committer: Bazaar Package Importer
  • Author(s): Ralf Treinen
  • Date: 2004-04-19 20:34:00 UTC
  • Revision ID: james.westby@ubuntu.com-20040419203400-g4e34ih0315wcn8v
Tags: upstream-1.0.3-R2
ImportĀ upstreamĀ versionĀ 1.0.3-R2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
3
;;
 
4
;; MODULE      : plugin-cmd.scm
 
5
;; DESCRIPTION : Commanding applications from TeXmacs and vice versa
 
6
;; COPYRIGHT   : (C) 1999  Joris van der Hoeven
 
7
;;
 
8
;; This software falls under the GNU general public license and comes WITHOUT
 
9
;; ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for details.
 
10
;; If you don't have this file, write to the Free Software Foundation, Inc.,
 
11
;; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
12
;;
 
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
14
 
 
15
(texmacs-module (texmacs plugin plugin-cmd)
 
16
  (:export pre-serialize verbatim-serialize generic-serialize plugin-serialize
 
17
           plugin-serializer-set! format-command plugin-commander-set!
 
18
           plugin-eval
 
19
           plugin-supports-completions-set! plugin-supports-completions?
 
20
           plugin-supports-input-done-set! plugin-supports-input-done?))
 
21
 
 
22
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
23
;; serialization
 
24
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
25
 
 
26
(define plugin-serializer (make-ahash-table))
 
27
 
 
28
(define (pre-serialize lan t)
 
29
  (cond ((func? t 'document 1) (pre-serialize lan (cadr t)))
 
30
        ((func? t 'math 1)
 
31
         (pre-serialize lan (plugin-math-input (list 'tuple lan (cadr t)))))
 
32
        (else t)))
 
33
 
 
34
(define (verbatim-serialize lan t)
 
35
  (with u (pre-serialize lan t)
 
36
    (string-append
 
37
     (escape-verbatim (texmacs->verbatim (object->tree u))) "\n")))
 
38
 
 
39
(define (generic-serialize lan t)
 
40
  (with u (pre-serialize lan t)
 
41
    (string-append (char->string #\002) "verbatim:"
 
42
                   (escape-generic (texmacs->verbatim (object->tree u)))
 
43
                   (char->string #\005))))
 
44
 
 
45
(define (plugin-serialize lan t)
 
46
  (with fun (ahash-ref plugin-serializer lan)
 
47
    (if fun
 
48
        (fun lan t)
 
49
        (verbatim-serialize lan t))))
 
50
 
 
51
(define (plugin-serializer-set! lan val)
 
52
  (ahash-set! plugin-serializer lan val))
 
53
 
 
54
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
55
;; commands
 
56
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
57
 
 
58
(define plugin-commander (make-ahash-table))
 
59
 
 
60
(define (default-format-command s)
 
61
  (string-append (char->string #\020) s "\n"))
 
62
 
 
63
(define (format-command lan s)
 
64
  (with fun (ahash-ref plugin-commander lan)
 
65
    (if fun
 
66
        (fun s)
 
67
        (default-format-command s))))
 
68
 
 
69
(define (plugin-commander-set! lan val)
 
70
  (ahash-set! plugin-commander lan val))
 
71
 
 
72
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
73
;; evaluation + simplification of documents with one paragraph
 
74
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
75
 
 
76
(define (plugin-output-simplify t)
 
77
  (cond ((func? t 'document 1) (plugin-output-simplify (cadr t)))
 
78
        ((func? t 'with) (rcons (cDr t) (plugin-output-simplify (cAr t))))
 
79
        (else t)))
 
80
 
 
81
(define (plugin-eval name session t)
 
82
  (let* ((u (connection-eval name session (object->tree t)))
 
83
         (v (plugin-output-simplify (tree->object u))))
 
84
    v))
 
85
 
 
86
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
87
;; tab completion
 
88
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
89
 
 
90
(define plugin-supports-completions (make-ahash-table))
 
91
 
 
92
(define (plugin-supports-completions-set! key)
 
93
  (ahash-set! plugin-supports-completions key #t))
 
94
 
 
95
(define (plugin-supports-completions? key)
 
96
  (ahash-ref plugin-supports-completions key))
 
97
 
 
98
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
99
;; testing whether more input is needed
 
100
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
101
 
 
102
(define plugin-supports-input-done (make-ahash-table))
 
103
 
 
104
(define (plugin-supports-input-done-set! key)
 
105
  (ahash-set! plugin-supports-input-done key #t))
 
106
 
 
107
(define (plugin-supports-input-done? key)
 
108
  (ahash-ref plugin-supports-input-done key))