annotate etc/ledit.l @ 41636:1edf7025cd57

*** empty log message ***
author Jason Rumney <jasonr@gnu.org>
date Wed, 28 Nov 2001 19:22:50 +0000
parents bd1d7d04426c
children 19880a4faa73
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25928
Dave Love <fx@gnu.org>
parents:
diff changeset
1 ;;; -*- Mode: lisp -*-
Dave Love <fx@gnu.org>
parents:
diff changeset
2
Dave Love <fx@gnu.org>
parents:
diff changeset
3 ; load in the c functions
Dave Love <fx@gnu.org>
parents:
diff changeset
4
Dave Love <fx@gnu.org>
parents:
diff changeset
5 (removeaddress '_signal)
Dave Love <fx@gnu.org>
parents:
diff changeset
6 (removeaddress '_switch_to_proc)
Dave Love <fx@gnu.org>
parents:
diff changeset
7 (removeaddress '_set_proc_str)
Dave Love <fx@gnu.org>
parents:
diff changeset
8
Dave Love <fx@gnu.org>
parents:
diff changeset
9 (cfasl "/src/mdc/ledit/leditcfns.o" '_switch_to_proc 'emacs)
Dave Love <fx@gnu.org>
parents:
diff changeset
10
Dave Love <fx@gnu.org>
parents:
diff changeset
11 (getaddress '_set_proc_str 'set_proc_str)
Dave Love <fx@gnu.org>
parents:
diff changeset
12
Dave Love <fx@gnu.org>
parents:
diff changeset
13 (declare (special *ledit-infile* ; emacs->lisp tempfile
Dave Love <fx@gnu.org>
parents:
diff changeset
14 *ledit-outfile* ; lisp->emacs tempfile
Dave Love <fx@gnu.org>
parents:
diff changeset
15 *ledit-ppfile* ; pp->emacs tempfile
Dave Love <fx@gnu.org>
parents:
diff changeset
16 *ledit-lisztfile* ; compiler input
Dave Love <fx@gnu.org>
parents:
diff changeset
17 *ledit-objfile* ; compiler output
Dave Love <fx@gnu.org>
parents:
diff changeset
18 *ledit-initialized*) ; flag
Dave Love <fx@gnu.org>
parents:
diff changeset
19 )
Dave Love <fx@gnu.org>
parents:
diff changeset
20
Dave Love <fx@gnu.org>
parents:
diff changeset
21 (setq *ledit-initialized* nil)
Dave Love <fx@gnu.org>
parents:
diff changeset
22
Dave Love <fx@gnu.org>
parents:
diff changeset
23 ;;; INIT-LEDIT
Dave Love <fx@gnu.org>
parents:
diff changeset
24
Dave Love <fx@gnu.org>
parents:
diff changeset
25 (defun init-ledit ()
Dave Love <fx@gnu.org>
parents:
diff changeset
26 (let ((user (getenv '|USER|))) ;USER must be uppercase
Dave Love <fx@gnu.org>
parents:
diff changeset
27 (setq
Dave Love <fx@gnu.org>
parents:
diff changeset
28 *ledit-outfile* (concat "/tmp/" user ".l2") ; lisp -> emacs
Dave Love <fx@gnu.org>
parents:
diff changeset
29 *ledit-infile* (concat "/tmp/" user ".l1") ; emacs -> lisp
Dave Love <fx@gnu.org>
parents:
diff changeset
30 *ledit-ppfile* (concat "/tmp/" user ".l3") ; pp output to emacs.
Dave Love <fx@gnu.org>
parents:
diff changeset
31 *ledit-lisztfile* (concat "/tmp/" user ".l4")
Dave Love <fx@gnu.org>
parents:
diff changeset
32 *ledit-objfile* (concat "/tmp/" user ".o")
Dave Love <fx@gnu.org>
parents:
diff changeset
33 *ledit-initialized* t)))
Dave Love <fx@gnu.org>
parents:
diff changeset
34
Dave Love <fx@gnu.org>
parents:
diff changeset
35 ;;; LEDIT
Dave Love <fx@gnu.org>
parents:
diff changeset
36 ; if 1 arg, arg is taken as a tag name to pass to emacs.
Dave Love <fx@gnu.org>
parents:
diff changeset
37 ; if 2 args, second arg is a keyword. If 2nd arg is pp,
Dave Love <fx@gnu.org>
parents:
diff changeset
38 ; pp is applied to first arg, and result is sent to emacs
Dave Love <fx@gnu.org>
parents:
diff changeset
39 ; to put in a buffer called LEDIT (which is first erased.)
Dave Love <fx@gnu.org>
parents:
diff changeset
40
Dave Love <fx@gnu.org>
parents:
diff changeset
41 (defun ledit fexpr (args)
Dave Love <fx@gnu.org>
parents:
diff changeset
42 (apply #'ledit* args))
Dave Love <fx@gnu.org>
parents:
diff changeset
43
Dave Love <fx@gnu.org>
parents:
diff changeset
44 ;;; LEDIT*
Dave Love <fx@gnu.org>
parents:
diff changeset
45
Dave Love <fx@gnu.org>
parents:
diff changeset
46 (defun ledit* n
Dave Love <fx@gnu.org>
parents:
diff changeset
47 (if (not *ledit-initialized*) (init-ledit))
Dave Love <fx@gnu.org>
parents:
diff changeset
48 (ledit-output (listify n))
Dave Love <fx@gnu.org>
parents:
diff changeset
49 (syscall 10. *ledit-infile*) ; syscall 10 is "delete"
Dave Love <fx@gnu.org>
parents:
diff changeset
50 (syscall 10. *ledit-lisztfile*)
Dave Love <fx@gnu.org>
parents:
diff changeset
51 (emacs)
Dave Love <fx@gnu.org>
parents:
diff changeset
52 (ledit-input)
Dave Love <fx@gnu.org>
parents:
diff changeset
53 (syscall 10. *ledit-outfile*)
Dave Love <fx@gnu.org>
parents:
diff changeset
54 (syscall 10. *ledit-ppfile*)
Dave Love <fx@gnu.org>
parents:
diff changeset
55 t)
Dave Love <fx@gnu.org>
parents:
diff changeset
56
Dave Love <fx@gnu.org>
parents:
diff changeset
57 ;;; LEDIT-OUTPUT
Dave Love <fx@gnu.org>
parents:
diff changeset
58 ;;; Egad, what a mess! Doesn't work for XEMACS yet.
Dave Love <fx@gnu.org>
parents:
diff changeset
59 ;;; Here's an example from Mocklisp:
Dave Love <fx@gnu.org>
parents:
diff changeset
60 ;;; -> (defun bar (nothing) (bar nothing))
Dave Love <fx@gnu.org>
parents:
diff changeset
61 ;;; bar
Dave Love <fx@gnu.org>
parents:
diff changeset
62 ;;; -> (ledit bar)
Dave Love <fx@gnu.org>
parents:
diff changeset
63 ;;; should produce...
Dave Love <fx@gnu.org>
parents:
diff changeset
64 ;;; (progn) (progn tag (setq tag "bar") (&goto-tag))
Dave Love <fx@gnu.org>
parents:
diff changeset
65 ;;; and
Dave Love <fx@gnu.org>
parents:
diff changeset
66 ;;; -> (ledit bar pp)
Dave Love <fx@gnu.org>
parents:
diff changeset
67 ;;; should stuff this to emacs...
Dave Love <fx@gnu.org>
parents:
diff changeset
68 ;;; (progn) (switch-to-buffer "LEDIT") (erase-buffer)
Dave Love <fx@gnu.org>
parents:
diff changeset
69 ;;; (insert-file "/tmp/walter.l3") (lisp-mode)
Dave Love <fx@gnu.org>
parents:
diff changeset
70 ;;; and this...
Dave Love <fx@gnu.org>
parents:
diff changeset
71 ;;; (def bar
Dave Love <fx@gnu.org>
parents:
diff changeset
72 ;;; (lambda (x)
Dave Love <fx@gnu.org>
parents:
diff changeset
73 ;;; (bar nothing)))
Dave Love <fx@gnu.org>
parents:
diff changeset
74 ;;; into *LEDIT*
Dave Love <fx@gnu.org>
parents:
diff changeset
75
Dave Love <fx@gnu.org>
parents:
diff changeset
76 (defun ledit-output (args)
Dave Love <fx@gnu.org>
parents:
diff changeset
77 (if args
Dave Love <fx@gnu.org>
parents:
diff changeset
78 (let ((ofile (outfile *ledit-outfile*)))
Dave Love <fx@gnu.org>
parents:
diff changeset
79 (format ofile "(progn)") ; this is necessary.
Dave Love <fx@gnu.org>
parents:
diff changeset
80
Dave Love <fx@gnu.org>
parents:
diff changeset
81 (cond ((null (cdr args)) ; no keyword -> arg is a tag.
Dave Love <fx@gnu.org>
parents:
diff changeset
82 (format ofile "(progn tag (setq tag \"~A\"~
Dave Love <fx@gnu.org>
parents:
diff changeset
83 (&goto-tag))"
Dave Love <fx@gnu.org>
parents:
diff changeset
84 (car args)))
Dave Love <fx@gnu.org>
parents:
diff changeset
85 ((eq (cadr args) 'pp) ; pp-> pp first arg to emacs
Dave Love <fx@gnu.org>
parents:
diff changeset
86 (apply 'pp `((|F| ,*ledit-ppfile*) ,(car args)))
Dave Love <fx@gnu.org>
parents:
diff changeset
87 (format ofile "(switch-to-buffer \"LEDIT\")~
Dave Love <fx@gnu.org>
parents:
diff changeset
88 (erase-buffer)")
Dave Love <fx@gnu.org>
parents:
diff changeset
89 (format ofile "(insert-file \"~A\")"
Dave Love <fx@gnu.org>
parents:
diff changeset
90 *ledit-ppfile*)
Dave Love <fx@gnu.org>
parents:
diff changeset
91 (format ofile "(lisp-mode)"))
Dave Love <fx@gnu.org>
parents:
diff changeset
92
Dave Love <fx@gnu.org>
parents:
diff changeset
93 (t (format t "~&~A -- unknown option~%" (cdr args))))
Dave Love <fx@gnu.org>
parents:
diff changeset
94 (close ofile))))
Dave Love <fx@gnu.org>
parents:
diff changeset
95
Dave Love <fx@gnu.org>
parents:
diff changeset
96 ;;; LISZT*
Dave Love <fx@gnu.org>
parents:
diff changeset
97 ;;; Need this guy to do compile-input.
Dave Love <fx@gnu.org>
parents:
diff changeset
98 ;;; Liszt returns 0 if all was well.
Dave Love <fx@gnu.org>
parents:
diff changeset
99 ;;; Note that in ordinary use the user will have to get used to looking
Dave Love <fx@gnu.org>
parents:
diff changeset
100 ;;; at "%Warning: ... Compiler declared *foo* special" messages, since
Dave Love <fx@gnu.org>
parents:
diff changeset
101 ;;; you don't usually want to hunt around in your file, zap in the the
Dave Love <fx@gnu.org>
parents:
diff changeset
102 ;;; declarations, then go back to what you were doing.
Dave Love <fx@gnu.org>
parents:
diff changeset
103 ;;; Fortunately this doesn't cause the compiler to bomb.
Dave Love <fx@gnu.org>
parents:
diff changeset
104 ;;; Some sleepless night I will think of a way to get around this.
Dave Love <fx@gnu.org>
parents:
diff changeset
105
Dave Love <fx@gnu.org>
parents:
diff changeset
106 (defun liszt* (&rest args)
Dave Love <fx@gnu.org>
parents:
diff changeset
107 (apply #'liszt args))
Dave Love <fx@gnu.org>
parents:
diff changeset
108
Dave Love <fx@gnu.org>
parents:
diff changeset
109 ;;; LEDIT-INPUT
Dave Love <fx@gnu.org>
parents:
diff changeset
110 ;;; Although there are two cases here, in practice
Dave Love <fx@gnu.org>
parents:
diff changeset
111 ;;; it is never the case that there is both input to be
Dave Love <fx@gnu.org>
parents:
diff changeset
112 ;;; interpreted and input to be compiled.
Dave Love <fx@gnu.org>
parents:
diff changeset
113
Dave Love <fx@gnu.org>
parents:
diff changeset
114 (defun ledit-input ()
Dave Love <fx@gnu.org>
parents:
diff changeset
115 (if (probef *ledit-lisztfile*)
Dave Love <fx@gnu.org>
parents:
diff changeset
116 (cond ((getd #'liszt)
Dave Love <fx@gnu.org>
parents:
diff changeset
117 (format t ";Compiling LEDIT:")
Dave Love <fx@gnu.org>
parents:
diff changeset
118 (and (zerop (liszt* *ledit-lisztfile* '-o *ledit-objfile*))
Dave Love <fx@gnu.org>
parents:
diff changeset
119 (load *ledit-objfile*)))
Dave Love <fx@gnu.org>
parents:
diff changeset
120 (t (format t ";Can't compile LEDIT: No liszt.~%;Reading instead:")
Dave Love <fx@gnu.org>
parents:
diff changeset
121 (let ((ifile (infile *ledit-lisztfile*)))
Dave Love <fx@gnu.org>
parents:
diff changeset
122 (ledit-load ifile)
Dave Love <fx@gnu.org>
parents:
diff changeset
123 (close ifile)))))
Dave Love <fx@gnu.org>
parents:
diff changeset
124
Dave Love <fx@gnu.org>
parents:
diff changeset
125 (if (probef *ledit-infile*)
Dave Love <fx@gnu.org>
parents:
diff changeset
126 (let ((ifile (infile *ledit-infile*)))
Dave Love <fx@gnu.org>
parents:
diff changeset
127 (format t ";Reading from LEDIT:~%")
Dave Love <fx@gnu.org>
parents:
diff changeset
128 (ledit-load ifile)
Dave Love <fx@gnu.org>
parents:
diff changeset
129 (close ifile))))
Dave Love <fx@gnu.org>
parents:
diff changeset
130
Dave Love <fx@gnu.org>
parents:
diff changeset
131 ;;; LEDIT-LOAD
Dave Love <fx@gnu.org>
parents:
diff changeset
132 ;;; A generally useful form of load
Dave Love <fx@gnu.org>
parents:
diff changeset
133
Dave Love <fx@gnu.org>
parents:
diff changeset
134 (defun ledit-load (ifile)
Dave Love <fx@gnu.org>
parents:
diff changeset
135 (let ((eof-form (list 'eof-form)))
Dave Love <fx@gnu.org>
parents:
diff changeset
136 (do ((form (read ifile eof-form) (read ifile eof-form)))
Dave Love <fx@gnu.org>
parents:
diff changeset
137 ((eq form eof-form))
Dave Love <fx@gnu.org>
parents:
diff changeset
138 (format t "; ~A~%" (eval form)))))
Dave Love <fx@gnu.org>
parents:
diff changeset
139
Dave Love <fx@gnu.org>
parents:
diff changeset
140 (setsyntax #/ 'macro 'ledit) ; make ^E = (ledit)<return>
Dave Love <fx@gnu.org>
parents:
diff changeset
141
Dave Love <fx@gnu.org>
parents:
diff changeset
142 ;; more robust version of the c function set_proc_str. Does argument checking.
Dave Love <fx@gnu.org>
parents:
diff changeset
143 ;; set_proc_str sets the string that is stuffed to the tty after franz pauses
Dave Love <fx@gnu.org>
parents:
diff changeset
144 ;; and the csh wakes up. It is usually "%emacs" or "%vemacs" or "%?emacs"
Dave Love <fx@gnu.org>
parents:
diff changeset
145 (defun set-proc-str (arg)
Dave Love <fx@gnu.org>
parents:
diff changeset
146 (if (stringp arg)
Dave Love <fx@gnu.org>
parents:
diff changeset
147 (set_proc_str arg)
Dave Love <fx@gnu.org>
parents:
diff changeset
148 (if (symbolp arg)
Dave Love <fx@gnu.org>
parents:
diff changeset
149 (set_proc_str (get-pname arg))
Dave Love <fx@gnu.org>
parents:
diff changeset
150 (error arg " is illegal argument to set-proc-str"))))