annotate lisp/emacs-lisp/eval-reg.el @ 21633:185e8e424ee9

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