2
* Copyright (c) 2001 by The XFree86 Project, Inc.
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the "Software"),
6
* to deal in the Software without restriction, including without limitation
7
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
* and/or sell copies of the Software, and to permit persons to whom the
9
* Software is furnished to do so, subject to the following conditions:
11
* The above copyright notice and this permission notice shall be included in
12
* all copies or substantial portions of the Software.
14
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
* THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
* Except as contained in this notice, the name of the XFree86 Project shall
23
* not be used in advertising or otherwise to promote the sale, use or other
24
* dealings in this Software without prior written authorization from the
27
* Author: Paulo César Pereira de Andrade
30
/* $XFree86: xc/programs/xedit/lisp.c,v 1.20tsi Exp $ */
33
#include "lisp/lisp.h"
34
#include "lisp/xedit.h"
39
#include <X11/Xaw/SmeBSB.h>
40
#include <X11/Xaw/SimpleMenu.h>
45
static void XeditDoLispEval(Widget);
46
static void EditModeCallback(Widget, XtPointer, XtPointer);
51
static int lisp_initialized;
52
extern Widget scratch;
53
static Widget edit_mode_menu, edit_mode_entry, edit_mode_none;
59
XeditLispInitialize(void)
61
setlocale(LC_NUMERIC, "C");
64
LispXeditInitialize();
68
XeditLispCleanUp(void)
74
XeditLispEval(Widget w, XEvent *event, String *params, Cardinal *num_params)
76
XeditDoLispEval(messwidget);
80
XeditPrintLispEval(Widget w, XEvent *event, String *params, Cardinal *num_params)
82
if (XawTextGetSource(w) == scratch) {
83
XtCallActionProc(w, "newline", event, params, *num_params);
87
XtCallActionProc(w, "newline-and-indent", event, params, *num_params);
91
XeditKeyboardReset(Widget w, XEvent *event, String *params, Cardinal *num_params)
93
XtCallActionProc(w, "keyboard-reset", event, params, *num_params);
97
SetTextProperties(xedit_flist_item *item)
99
if (lisp_initialized) {
100
Widget source = XawTextGetSource(textwindow);
101
XawTextPosition top = XawTextTopPosition(textwindow);
103
if (source != item->source)
104
XawTextSetSource(textwindow, item->source, 0);
105
XeditLispSetEditMode(item, NULL);
106
if (source != item->source)
107
XawTextSetSource(textwindow, source, top);
112
UnsetTextProperties(xedit_flist_item *item)
114
XeditLispUnsetEditMode(item);
118
XeditDoLispEval(Widget output)
122
XawTextPosition position, end;
124
/* get lisp expression */
125
src = XawTextGetSource(textwindow);
126
position = XawTextGetInsertionPoint(textwindow);
128
while (position >= 0) {
129
(void)XawTextSourceRead(src, position, &block, 1);
130
if (!isspace(block.ptr[0]))
136
if (block.ptr[0] != ')') {
137
while (position >= 0) {
138
(void)XawTextSourceRead(src, position, &block, 1);
139
if (isspace(block.ptr[0]) ||
140
block.ptr[0] == '(' ||
141
block.ptr[0] == ')' ||
142
block.ptr[0] == '"' ||
147
if (!isspace(block.ptr[0]))
151
/* XXX note that embedded '(' and ')' will confuse this code */
152
XawTextPosition last, tmp;
161
position = XawTextSourceSearch(src, last, XawsdLeft, &block);
162
if (position == XawTextSearchError) {
169
tmp = XawTextSourceSearch(src, tmp, XawsdRight, &block);
170
if (tmp == XawTextSearchError) {
176
} while (++tmp <= last);
180
/* check for extra characters */
181
while (position > 0) {
182
(void)XawTextSourceRead(src, position - 1, &block, 1);
183
if (block.length != 1 ||
184
isspace(block.ptr[0]) ||
185
block.ptr[0] == ')' ||
186
block.ptr[0] == '"' ||
193
if (position < 0 || position >= end)
196
XeditLispExecute(output, position, end);
200
CreateEditModePopup(Widget parent)
204
static char *editModes = "editModes";
206
XtVaCreateManagedWidget("modeMenuItem", smeBSBObjectClass, parent,
207
XtNmenuName, editModes, NULL);
208
edit_mode_menu = XtCreatePopupShell(editModes, simpleMenuWidgetClass,
210
XtRealizeWidget(edit_mode_menu);
212
edit_mode_none = XtCreateManagedWidget("none", smeBSBObjectClass,
213
edit_mode_menu, NULL, 0);
214
XtAddCallback(edit_mode_none, XtNcallback, EditModeCallback, NULL);
216
for (i = 0; i < num_mode_infos; i++) {
217
sme = XtVaCreateManagedWidget("mode", smeBSBObjectClass, edit_mode_menu,
218
XtNlabel, mode_infos[i].desc, NULL);
219
XtAddCallback(sme, XtNcallback, EditModeCallback,
220
(XtPointer)(mode_infos + i));
221
mode_infos[i].sme = sme;
226
SetEditModeMenu(void)
229
Widget old_entry = edit_mode_entry, new_entry = edit_mode_none;
230
xedit_flist_item *item = FindTextSource(XawTextGetSource(textwindow), NULL);
232
for (i = 0; i < num_mode_infos; i++) {
233
if (item->xldata && item->xldata->syntax &&
234
mode_infos[i].syntax == item->xldata->syntax) {
235
new_entry = mode_infos[i].sme;
240
if (old_entry != new_entry) {
242
XtVaSetValues(old_entry, XtNleftBitmap, None, NULL);
243
XtVaSetValues(new_entry, XtNleftBitmap, flist.pixmap, NULL);
244
edit_mode_entry = new_entry;
249
EditModeCallback(Widget w, XtPointer client_data, XtPointer call_data)
251
Widget source = XawTextGetSource(textwindow);
252
EditModeInfo *info = (EditModeInfo*)client_data;
253
xedit_flist_item *item = FindTextSource(source, NULL);
255
/* If no edit mode selected and selecting the plain/none mode */
257
(item->xldata == NULL || item->xldata->syntax == NULL)) ||
258
/* if selecting the current mode */
259
(info && item && item->xldata && info->syntax &&
260
info->syntax == item->xldata->syntax))
263
XawTextSourceClearEntities(source,
264
XawTextSourceScan(source, 0, XawstAll,
266
XawTextSourceScan(source, 0, XawstAll,
267
XawsdRight, 1, True));
268
XeditLispUnsetEditMode(item);
270
XeditLispSetEditMode(item, info->symbol);
272
item->properties = NULL;
273
UpdateTextProperties(1);