annotate lisp/=medit.el @ 334:5f0324deb0c5

*** empty log message ***
author Jim Blandy <jimb@redhat.com>
date Mon, 15 Jul 1991 22:33:41 +0000
parents 80593a7533de
children 505130d1ddf8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
226
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 ;; Lisp interface between GNU Emacs and MEDIT package. Emacs under MDL.
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2 ;; Copyright (C) 1985 Free Software Foundation, Inc.
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3 ;; Principal author K. Shane Hartman
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5 ;; This file is part of GNU Emacs.
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8 ;; it under the terms of the GNU General Public License as published by
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 ;; the Free Software Foundation; either version 1, or (at your option)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10 ;; any later version.
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 ;; GNU Emacs is distributed in the hope that it will be useful,
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15 ;; GNU General Public License for more details.
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 ;; You should have received a copy of the GNU General Public License
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 ;; along with GNU Emacs; see the file COPYING. If not, write to
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 ;; >> This package depends on two MDL packages: MEDIT and FORKS which
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23 ;; >> can be obtained from the public (network) library at mit-ajax.
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25 (require 'mim-mode)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27 (defconst medit-zap-file (concat "/tmp/" (user-login-name) ".medit.mud")
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28 "File name for data sent to MDL by Medit.")
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 (defconst medit-buffer "*MEDIT*"
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 "Name of buffer in which Medit accumulates data to send to MDL.")
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 (defconst medit-save-files t
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 "If non-nil, Medit offers to save files on return to MDL.")
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 (defun medit-save-define ()
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 "Mark the previous or surrounding toplevel object to be sent back to MDL."
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 (interactive)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 (save-excursion
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 (beginning-of-DEFINE)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 (let ((start (point)))
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 (forward-mim-object 1)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 (append-to-buffer medit-buffer start (point))
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 (goto-char start)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 (message (buffer-substring start (progn (end-of-line) (point)))))))
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 (defun medit-save-region (start end)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 "Mark the current region to be sent to back to MDL."
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 (interactive "r")
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 (append-to-buffer medit-buffer start end)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 (message "Current region saved for MDL."))
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 (defun medit-save-buffer ()
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 "Mark the current buffer to be sent back to MDL."
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 (interactive)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 (append-to-buffer medit-buffer (point-min) (point-max))
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 (message "Current buffer saved for MDL."))
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 (defun medit-zap-define-to-mdl ()
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 "Return to MDL with surrounding or previous toplevel MDL object."
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 (indetarctive)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 (medit-save-defun)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 (medit-go-to-mdl))
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 (defun medit-zap-region-mdl (start end)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 "Return to MDL with current region."
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 (interactive)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 (medit-save-region start end)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 (medit-go-to-mdl))
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 (defun medit-zap-buffer ()
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 "Return to MDL with current buffer."
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 (interactive)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 (medit-save-buffer)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73 (medit-go-to-mdl))
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 (defun medit-goto-mdl ()
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 "Return from Emacs to superior MDL, sending saved code.
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77 Optionally, offers to save changed files."
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 (interactive)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79 (let ((buffer (get-buffer medit-buffer)))
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 (if buffer
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 (save-excursion
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 (set-buffer buffer)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 (if (buffer-modified-p buffer)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 (write-region (point-min) (point-max) medit-zap-file))
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 (set-buffer-modified-p nil)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 (erase-buffer)))
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 (if medit-save-files (save-some-buffers))
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 ;; Note could handle parallel fork by giving argument "%xmdl". Then
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 ;; mdl would have to invoke with "%emacs".
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 (suspend-emacs)))
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 (defconst medit-mode-map nil)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 (if (not medit-mode-map)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 (progn
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 (setq medit-mode-map (copy-keymap mim-mode-map))
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 (define-key medit-mode-map "\e\z" 'medit-save-define)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 (define-key medit-mode-map "\e\^z" 'medit-save-buffer)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 (define-key medit-mode-map "\^xz" 'medit-goto-mdl)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 (define-key medit-mode-map "\^xs" 'medit-zap-buffer)))
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 (defconst medit-mode-hook (and (boundp 'mim-mode-hook) mim-mode-hook) "")
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 (setq mim-mode-hook '(lambda () (medit-mode)))
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 (defun medit-mode (&optional state)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 "Major mode for editing text and returning it to a superior MDL.
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 Like Mim mode, plus these special commands:
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 \\{medit-mode-map}"
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 (interactive)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 (use-local-map medit-mode-map)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 (run-hooks 'medit-mode-hook)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 (setq major-mode 'medit-mode)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 (setq mode-name "Medit"))
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 (mim-mode)
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115
80593a7533de Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116