-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathElispBackend.py
155 lines (118 loc) · 4.19 KB
/
ElispBackend.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# ElispBackend.py
#
# Copyright (c) 2001 Alex Schroeder
# Released under the GNU General Public Licence
#
# Elisp backend for Parrot
# This is a backend for Emacs Lisp. It generates a defun
# which will then use widgets to implement the window
# specified in parrot.
# Last altered: 2001-10-14
# History:
# 2001-10-14 Alex Schroeder: created
from inrep import *
from backend import *
#===========================================================
##### Elisp backend ######################################
#===========================================================
class Elisp_GLOBAL(Backend_GLOBAL):
def getStartCode(self):
return """;;; autogenerated by Parrot's ElispBackend module
(require 'widget)
(eval-when-compile
(require 'wid-edit))
"""
def getCodeBetweenComponents(self): return '\n'
def getEndCode(self):
s = "\n"
for v in self.varList:
s = s + ("!! variable: %s !!\n" % v)
s = s + "\n;;; end of Parrot code\n"
return s
def getBackendSignature(self): return 'Elisp'
def produceCode(self):
self.varList = []
return self.getCode()
# The Elisp backend produces files with an .el extension
def fileExtension(self): return '.el'
# return list of container types understood by this backend:
def getContainerTypes(self):
return ('window',)
# return ('window', 'colLayout', 'rowLayout', 'table', 'tr', 'td',
# 'menuBar', 'menu')
# return list of components which aren't containers
def getNonContainerTypes(self):
return ('button', 'label', 'textField')
# return ('menuItem', 'button', 'label', 'textField', 'checkBox',
# 'radioButton')
#===========================================================
# containers
#===========================================================
#class Elisp_container(Backend_container): pass
class Elisp_window(Backend_container):
def getAttrDoc(self):
return {'id': 'the name of the function',
'text': 'the buffer name used for the dialog',
'doc': 'the doc string for the function'}
def getStartCode(self):
doc_string = ''
if self.attr.has_key('doc'):
doc_string = "\n \"%s\"" % (self.attr['doc'])
return """
(defun %s ()%s
(interactive)
(switch-to-buffer "*%s*")
(kill-all-local-variables)
(let ((inhibit-read-only t))
(erase-buffer))
""" %(self.getId(), doc_string, self.getText())
def getCodeBetweenComponents(self): return ''
def getEndCode(self):
return """
(use-local-map widget-keymap)
(widget-setup))
"""
#===========================================================
# non-container components
#===========================================================
class Elisp_component(Backend_component):
# append (self)'s Id as a variable name,
# to the list of variable names
# in the Elisp_GLOBAL
def appendMe(self):
myGlobal = self.getGlobal()
myGlobal.varList.append(self.getId())
class Elisp_button(Elisp_component):
def getAttrDoc(self):
return {'id': 'the function to call',
'text': "the button's text"}
def getCode(self):
self.appendMe()
return """ (widget-create
'push-button
:notify (lambda (&rest ignore) %s)
"%s")""" % (self.getId(), self.getText())
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class Elisp_label(Elisp_component):
def getAttrDoc(self):
return {'text': "the label's text"}
def getCode(self):
return " (widget-insert \"%s\")\n" % (self.getText())
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class Elisp_textField(Elisp_component):
def getAttrDoc(self):
return {'id': 'the variable used for the value of the field',
'text': 'text that goes in the textfield at startup',
'type':
'type according to "Atomic Sexp Widgets" in the widget manual'}
def getCode(self):
self.appendMe()
type = 'string'
if self.attr.has_key('type'):
type = self.attr['type']
return " (setq %s (widget-create '%s \"%s\"))\n" % (
self.getId(),
type,
self.getText())
#===========================================================
#end