annotate lisp/edebug/eval-reg.el @ 72:b9518feda344 r20-0b31

Import from CVS: tag r20-0b31
author cvs
date Mon, 13 Aug 2007 09:03:46 +0200
parents 131b0175ea99
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; eval-reg.el --- Redefine eval-region, and subrs that use it, in Lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1994 Daniel LaLiberte
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Author: Daniel LaLiberte <liberte@cs.uiuc.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
8 ;; This file is part of XEmacs.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
11 ;; under the terms of the GNU General Public License as published by
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
18 ;; General Public License for more details.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
23 ;; 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
25 ;;; Synched up with: Not in FSF
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
26
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
27 ;;; Commentary:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
29 ;; eval-region, eval-buffer, and eval-current-buffer are redefined in
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
30 ;; Lisp to allow customizations by Lisp code. eval-region calls
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
31 ;; `read', `eval', and `prin1', so Lisp replacements of these
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
32 ;; functions will affect eval-region and anything else that calls it.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
33 ;; eval-buffer and eval-current-buffer are redefined in Lisp to call
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
34 ;; eval-region on the buffer.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
36 ;; Because of dynamic binding, all local variables are protected from
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
37 ;; being seen by eval by giving them funky names. But variables in
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
38 ;; routines that call eval-region are similarly exposed.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
40 ;; Perhaps this should be one of several files in an `elisp' package
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
41 ;; that replaces Emacs Lisp subroutines with Lisp versions of the
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
42 ;; same.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
43
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
44 ;; Eval-region may be installed, after loading, by calling:
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
45 ;; (elisp-eval-region-install). Installation can be undone with:
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
46 ;; (elisp-eval-region-uninstall).
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
47
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
48 ;;; Code:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 '(defpackage "elisp-eval-region"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (:nicknames "elisp")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (:use "elisp")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (:export
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 elisp-eval-region-install
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 elisp-eval-region-uninstall
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 elisp-eval-region-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 with-elisp-eval-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 eval-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 eval-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 eval-current-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 '(in-package elisp-eval-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;; Save standard versions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (if (not (fboundp 'original-eval-region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (defalias 'original-eval-region (symbol-function 'eval-region)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (if (not (fboundp 'original-eval-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (defalias 'original-eval-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (if (fboundp 'eval-buffer) ;; only in Emacs 19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (symbol-function 'eval-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 'undefined)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (if (not (fboundp 'original-eval-current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (defalias 'original-eval-current-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (symbol-function 'eval-current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (defvar elisp-eval-region-level 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 "If the value is 0, use the original version of `elisp-eval-region'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 Callers of `elisp-eval-region' should increment `elisp-eval-region-level'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 while the Lisp version should be used. Installing `elisp-eval-region'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 increments it once, and uninstalling decrements it.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;; Installing and uninstalling should always be used in pairs,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;; or just install once and never uninstall.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (defun elisp-eval-region-install ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (defalias 'eval-region 'elisp-eval-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (defalias 'eval-buffer 'elisp-eval-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (defalias 'eval-current-buffer 'elisp-eval-current-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (setq elisp-eval-region-level (1+ elisp-eval-region-level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (defun elisp-eval-region-uninstall ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (if (> 1 elisp-eval-region-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (setq elisp-eval-region-level (1- elisp-eval-region-level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (setq elisp-eval-region-level 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (defalias 'eval-region (symbol-function 'original-eval-region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (defalias 'eval-buffer (symbol-function 'original-eval-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (defalias 'eval-current-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (symbol-function 'original-eval-current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (put 'with-elisp-eval-region 'lisp-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (put 'with-elisp-eval-region 'lisp-indent-hook 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (put 'with-elisp-eval-region 'edebug-form-spec t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (defmacro with-elisp-eval-region (flag &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 "If FLAG is nil, decrement `eval-region-level' while executing BODY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 The effect of decrementing all the way to zero is that `eval-region'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 will use the original `eval-region', which may be the Emacs subr or some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 previous redefinition. Before calling this macro, this package should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 already have been installed, using `elisp-eval-region-install', which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 increments the count once. So if another package still requires the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 Lisp version of the code, the count will still be non-zero.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 The count is not bound locally by this macro, so changes by BODY to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 its value will not be lost."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (` (let ((elisp-code (function (lambda () (,@ body)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (if (not (, flag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (setq elisp-eval-region-level (1- elisp-eval-region-level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (funcall elisp-code))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (setq elisp-eval-region-level (1+ elisp-eval-region-level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (funcall elisp-code)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (defun elisp-eval-region (elisp-start elisp-end &optional elisp-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 "Execute the region as Lisp code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 When called from programs, expects two arguments,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 giving starting and ending indices in the current buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 of the text to be executed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 Programs can pass third argument PRINTFLAG which controls printing of output:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 nil means discard it; anything else is stream for print.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 This version, from `eval-reg.el', allows Lisp customization of read,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 eval, and the printer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ;; Because this doesnt narrow to the region, one other difference
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ;; concerns inserting whitespace after the expression being evaluated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (if (= 0 elisp-eval-region-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (original-eval-region elisp-start elisp-end elisp-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (let ((elisp-pnt (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (elisp-buf (current-buffer));; Outside buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (elisp-inside-buf (current-buffer));; Buffer current while evaling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 ;; Mark the end because it may move.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (elisp-end-marker (set-marker (make-marker) elisp-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 elisp-form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 elisp-val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (goto-char elisp-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (elisp-skip-whitespace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (while (< (point) elisp-end-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (setq elisp-form (read elisp-buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (let ((elisp-current-buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 ;; Restore the inside current-buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (set-buffer elisp-inside-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (setq elisp-val (eval elisp-form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ;; Remember current buffer for next time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (setq elisp-inside-buf (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ;; Should this be protected?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (set-buffer elisp-current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (if elisp-output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (let ((standard-output (or elisp-output t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (setq values (cons elisp-val values))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (if (eq standard-output t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (prin1 elisp-val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (princ "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (prin1 elisp-val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (princ "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (goto-char (min (max elisp-end-marker (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (progn (elisp-skip-whitespace) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 ) ; while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (if elisp-output nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 ;; like save-excursion recovery, but done only if no error occurs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 ;; but mark is not restored
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (set-buffer elisp-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (goto-char elisp-pnt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (defun elisp-skip-whitespace ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 ;; Leave point before the next token, skipping white space and comments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (skip-chars-forward " \t\r\n\f")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (while (= (following-char) ?\;)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (skip-chars-forward "^\n\r") ; skip the comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (skip-chars-forward " \t\r\n\f")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (defun elisp-eval-current-buffer (&optional elisp-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 "Execute the current buffer as Lisp code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 Programs can pass argument PRINTFLAG which controls printing of output:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 nil means discard it; anything else is stream for print.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 This version calls `eval-region' on the whole buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 ;; The standard eval-current-buffer doesn't use eval-region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (eval-region (point-min) (point-max) elisp-output))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (defun elisp-eval-buffer (&optional elisp-bufname elisp-printflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 "Execute BUFFER as Lisp code. Use current buffer if BUFFER is nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 Programs can pass argument PRINTFLAG which controls printing of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 output: nil means discard it; anything else is stream for print.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 This version calls `eval-region' on the whole buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (if (null elisp-bufname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (setq elisp-bufname (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (set-buffer (or (get-buffer elisp-bufname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (error "No such buffer: %s" elisp-bufname)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (eval-region (point-min) (point-max) elisp-printflag)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (provide 'eval-reg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 ;;; eval-reg.el ends here