Commit | Line | Data |
---|---|---|
6594deb0 ER |
1 | ;;; ledit.el --- Emacs side of ledit interface |
2 | ||
a2535589 JA |
3 | ;; Copyright (C) 1985 Free Software Foundation, Inc. |
4 | ||
5 | ;; This file is part of GNU Emacs. | |
6 | ||
7 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
8 | ;; it under the terms of the GNU General Public License as published by | |
9 | ;; the Free Software Foundation; either version 1, or (at your option) | |
10 | ;; any later version. | |
11 | ||
12 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | ;; GNU General Public License for more details. | |
16 | ||
17 | ;; You should have received a copy of the GNU General Public License | |
18 | ;; along with GNU Emacs; see the file COPYING. If not, write to | |
19 | ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
20 | ||
21 | ||
22 | ;;; To do: | |
23 | ;;; o lisp -> emacs side of things (grind-definition and find-definition) | |
24 | ||
25 | (defvar ledit-mode-map nil) | |
26 | ||
27 | (defconst ledit-zap-file (concat "/tmp/" (user-login-name) ".l1") | |
28 | "File name for data sent to Lisp by Ledit.") | |
29 | (defconst ledit-read-file (concat "/tmp/" (user-login-name) ".l2") | |
30 | "File name for data sent to Ledit by Lisp.") | |
31 | (defconst ledit-compile-file | |
32 | (concat "/tmp/" (user-login-name) ".l4") | |
33 | "File name for data sent to Lisp compiler by Ledit.") | |
34 | (defconst ledit-buffer "*LEDIT*" | |
35 | "Name of buffer in which Ledit accumulates data to send to Lisp.") | |
7229064d | 36 | |
6503cec3 JB |
37 | ;;;###autoload |
38 | (defconst ledit-save-files t "\ | |
39 | *Non-nil means Ledit should save files before transferring to Lisp.") | |
40 | ;;;###autoload | |
41 | (defconst ledit-go-to-lisp-string "%?lisp" "\ | |
42 | *Shell commands to execute to resume Lisp job.") | |
43 | ;;;###autoload | |
44 | (defconst ledit-go-to-liszt-string "%?liszt" "\ | |
45 | *Shell commands to execute to resume Lisp compiler job.") | |
a2535589 JA |
46 | |
47 | (defun ledit-save-defun () | |
48 | "Save the current defun in the ledit buffer" | |
49 | (interactive) | |
50 | (save-excursion | |
51 | (end-of-defun) | |
52 | (let ((end (point))) | |
53 | (beginning-of-defun) | |
54 | (append-to-buffer ledit-buffer (point) end)) | |
55 | (message "Current defun saved for Lisp"))) | |
56 | ||
57 | (defun ledit-save-region (beg end) | |
58 | "Save the current region in the ledit buffer" | |
59 | (interactive "r") | |
60 | (append-to-buffer ledit-buffer beg end) | |
61 | (message "Region saved for Lisp")) | |
62 | ||
63 | (defun ledit-zap-defun-to-lisp () | |
f30ff39f | 64 | "Carry the current defun to Lisp." |
a2535589 JA |
65 | (interactive) |
66 | (ledit-save-defun) | |
67 | (ledit-go-to-lisp)) | |
68 | ||
69 | (defun ledit-zap-defun-to-liszt () | |
f30ff39f | 70 | "Carry the current defun to liszt." |
a2535589 JA |
71 | (interactive) |
72 | (ledit-save-defun) | |
73 | (ledit-go-to-liszt)) | |
74 | ||
75 | (defun ledit-zap-region-to-lisp (beg end) | |
f30ff39f | 76 | "Carry the current region to Lisp." |
a2535589 JA |
77 | (interactive "r") |
78 | (ledit-save-region beg end) | |
79 | (ledit-go-to-lisp)) | |
80 | ||
81 | (defun ledit-go-to-lisp () | |
82 | "Suspend Emacs and restart a waiting Lisp job." | |
83 | (interactive) | |
84 | (if ledit-save-files | |
85 | (save-some-buffers)) | |
86 | (if (get-buffer ledit-buffer) | |
87 | (save-excursion | |
88 | (set-buffer ledit-buffer) | |
89 | (goto-char (point-min)) | |
90 | (write-region (point-min) (point-max) ledit-zap-file) | |
91 | (erase-buffer))) | |
92 | (suspend-emacs ledit-go-to-lisp-string) | |
93 | (load ledit-read-file t t)) | |
94 | ||
95 | (defun ledit-go-to-liszt () | |
96 | "Suspend Emacs and restart a waiting Liszt job." | |
97 | (interactive) | |
98 | (if ledit-save-files | |
99 | (save-some-buffers)) | |
100 | (if (get-buffer ledit-buffer) | |
101 | (save-excursion | |
102 | (set-buffer ledit-buffer) | |
103 | (goto-char (point-min)) | |
104 | (insert "(declare (macros t))\n") | |
105 | (write-region (point-min) (point-max) ledit-compile-file) | |
106 | (erase-buffer))) | |
107 | (suspend-emacs ledit-go-to-liszt-string) | |
108 | (load ledit-read-file t t)) | |
109 | ||
110 | (defun ledit-setup () | |
f30ff39f | 111 | "Set up key bindings for the Lisp/Emacs interface." |
a2535589 JA |
112 | (if (not ledit-mode-map) |
113 | (progn (setq ledit-mode-map (make-sparse-keymap)) | |
114 | (lisp-mode-commands ledit-mode-map))) | |
115 | (define-key ledit-mode-map "\e\^d" 'ledit-save-defun) | |
116 | (define-key ledit-mode-map "\e\^r" 'ledit-save-region) | |
117 | (define-key ledit-mode-map "\^xz" 'ledit-go-to-lisp) | |
118 | (define-key ledit-mode-map "\e\^c" 'ledit-go-to-liszt)) | |
119 | ||
120 | (ledit-setup) | |
121 | ||
7229064d | 122 | ;;;###autoload |
a2535589 | 123 | (defun ledit-mode () |
f30ff39f | 124 | "\\<ledit-mode-map>Major mode for editing text and stuffing it to a Lisp job. |
a2535589 | 125 | Like Lisp mode, plus these special commands: |
f30ff39f | 126 | \\[ledit-save-defun] -- record defun at or after point |
a2535589 | 127 | for later transmission to Lisp job. |
f30ff39f BP |
128 | \\[ledit-save-region] -- record region for later transmission to Lisp job. |
129 | \\[ledit-go-to-lisp] -- transfer to Lisp job and transmit saved text. | |
130 | \\[ledit-go-to-liszt] -- transfer to Liszt (Lisp compiler) job | |
a2535589 JA |
131 | and transmit saved text. |
132 | \\{ledit-mode-map} | |
133 | To make Lisp mode automatically change to Ledit mode, | |
134 | do (setq lisp-mode-hook 'ledit-from-lisp-mode)" | |
135 | (interactive) | |
136 | (lisp-mode) | |
137 | (ledit-from-lisp-mode)) | |
138 | ||
7229064d | 139 | ;;;###autoload |
a2535589 JA |
140 | (defun ledit-from-lisp-mode () |
141 | (use-local-map ledit-mode-map) | |
142 | (setq mode-name "Ledit") | |
143 | (setq major-mode 'ledit-mode) | |
144 | (run-hooks 'ledit-mode-hook)) | |
6594deb0 ER |
145 | |
146 | ;;; ledit.el ends here |