aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2011-02-19 00:10:33 -0500
committerStefan Monnier2011-02-19 00:10:33 -0500
commite0f57e65692ed73a86926f737388b60faec92767 (patch)
treecd119f7a6f2a04673f304fbf8cfaf8fc7c0896f2
parent9a05edc4fcf1eff8966ac327e479bb8f9ca219a9 (diff)
downloademacs-e0f57e65692ed73a86926f737388b60faec92767.tar.gz
emacs-e0f57e65692ed73a86926f737388b60faec92767.zip
* lisp/subr.el (save-window-excursion): New macro, moved from C.
* lisp/emacs-lisp/lisp-mode.el (save-window-excursion): Don't touch. * lisp/emacs-lisp/cconv.el (cconv-closure-convert-rec, cconv-analyse-form): Don't handle save-window-excursion any more. * lisp/emacs-lisp/bytecomp.el (interactive-p, save-window-excursion): Don't use the byte-code any more. (byte-compile-form): Check macro expansion was done. (byte-compile-save-window-excursion): Remove. * lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker): Ignore save-window-excursion. Don't macroepand any more. * src/window.c (Fsave_window_excursion): Remove. Moved to Lisp. (syms_of_window): Don't defsubr it. * src/window.h (Fsave_window_excursion): Don't declare it. * src/bytecode.c (exec_byte_code): Inline Fsave_window_excursion.
-rw-r--r--lisp/ChangeLog13
-rw-r--r--lisp/emacs-lisp/byte-opt.el21
-rw-r--r--lisp/emacs-lisp/bytecomp.el18
-rw-r--r--lisp/emacs-lisp/cconv.el6
-rw-r--r--lisp/emacs-lisp/lisp-mode.el1
-rw-r--r--lisp/subr.el19
-rw-r--r--src/ChangeLog7
-rw-r--r--src/bytecode.c32
-rw-r--r--src/window.c23
-rw-r--r--src/window.h1
10 files changed, 67 insertions, 74 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 6b6555ab7e3..ae91513937c 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,16 @@
12011-02-19 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * subr.el (save-window-excursion): New macro, moved from C.
4 * emacs-lisp/lisp-mode.el (save-window-excursion): Don't touch.
5 * emacs-lisp/cconv.el (cconv-closure-convert-rec, cconv-analyse-form):
6 Don't handle save-window-excursion any more.
7 * emacs-lisp/bytecomp.el (interactive-p, save-window-excursion):
8 Don't use the byte-code any more.
9 (byte-compile-form): Check macro expansion was done.
10 (byte-compile-save-window-excursion): Remove.
11 * emacs-lisp/byte-opt.el (byte-optimize-form-code-walker):
12 Ignore save-window-excursion. Don't macroepand any more.
13
12011-02-18 Stefan Monnier <monnier@iro.umontreal.ca> 142011-02-18 Stefan Monnier <monnier@iro.umontreal.ca>
2 15
3 * emacs-lisp/pcase.el (pcase--expand, pcase--u, pcase--u1, pcase--q1): 16 * emacs-lisp/pcase.el (pcase--expand, pcase--u, pcase--u1, pcase--q1):
diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el
index 12df3251267..038db292350 100644
--- a/lisp/emacs-lisp/byte-opt.el
+++ b/lisp/emacs-lisp/byte-opt.el
@@ -498,8 +498,7 @@
498 (prin1-to-string form)) 498 (prin1-to-string form))
499 nil) 499 nil)
500 500
501 ((memq fn '(defun defmacro function 501 ((memq fn '(defun defmacro function condition-case))
502 condition-case save-window-excursion))
503 ;; These forms are compiled as constants or by breaking out 502 ;; These forms are compiled as constants or by breaking out
504 ;; all the subexpressions and compiling them separately. 503 ;; all the subexpressions and compiling them separately.
505 form) 504 form)
@@ -530,24 +529,6 @@
530 ;; However, don't actually bother calling `ignore'. 529 ;; However, don't actually bother calling `ignore'.
531 `(prog1 nil . ,(mapcar 'byte-optimize-form (cdr form)))) 530 `(prog1 nil . ,(mapcar 'byte-optimize-form (cdr form))))
532 531
533 ;; If optimization is on, this is the only place that macros are
534 ;; expanded. If optimization is off, then macroexpansion happens
535 ;; in byte-compile-form. Otherwise, the macros are already expanded
536 ;; by the time that is reached.
537 ((not (eq form
538 (setq form (macroexpand form
539 byte-compile-macro-environment))))
540 (byte-optimize-form form for-effect))
541
542 ;; Support compiler macros as in cl.el.
543 ((and (fboundp 'compiler-macroexpand)
544 (symbolp (car-safe form))
545 (get (car-safe form) 'cl-compiler-macro)
546 (not (eq form
547 (with-no-warnings
548 (setq form (compiler-macroexpand form))))))
549 (byte-optimize-form form for-effect))
550
551 ((not (symbolp fn)) 532 ((not (symbolp fn))
552 (byte-compile-warn "`%s' is a malformed function" 533 (byte-compile-warn "`%s' is a malformed function"
553 (prin1-to-string fn)) 534 (prin1-to-string fn))
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index d3ac50a671a..54a1912169a 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -586,7 +586,6 @@ Each element is (INDEX . VALUE)")
586(byte-defop 114 0 byte-save-current-buffer 586(byte-defop 114 0 byte-save-current-buffer
587 "To make a binding to record the current buffer") 587 "To make a binding to record the current buffer")
588(byte-defop 115 0 byte-set-mark-OBSOLETE) 588(byte-defop 115 0 byte-set-mark-OBSOLETE)
589(byte-defop 116 1 byte-interactive-p)
590 589
591;; These ops are new to v19 590;; These ops are new to v19
592(byte-defop 117 0 byte-forward-char) 591(byte-defop 117 0 byte-forward-char)
@@ -622,8 +621,6 @@ otherwise pop it")
622 621
623(byte-defop 138 0 byte-save-excursion 622(byte-defop 138 0 byte-save-excursion
624 "to make a binding to record the buffer, point and mark") 623 "to make a binding to record the buffer, point and mark")
625(byte-defop 139 0 byte-save-window-excursion
626 "to make a binding to record entire window configuration")
627(byte-defop 140 0 byte-save-restriction 624(byte-defop 140 0 byte-save-restriction
628 "to make a binding to record the current buffer clipping restrictions") 625 "to make a binding to record the current buffer clipping restrictions")
629(byte-defop 141 -1 byte-catch 626(byte-defop 141 -1 byte-catch
@@ -2955,6 +2952,10 @@ That command is designed for interactive use only" bytecomp-fn))
2955 custom-declare-face)) 2952 custom-declare-face))
2956 (byte-compile-nogroup-warn form)) 2953 (byte-compile-nogroup-warn form))
2957 (byte-compile-callargs-warn form)) 2954 (byte-compile-callargs-warn form))
2955 (if (and (fboundp (car form))
2956 (eq (car-safe (indirect-function (car form))) 'macro))
2957 (byte-compile-report-error
2958 (format "Forgot to expand macro %s" (car form))))
2958 (if (and bytecomp-handler 2959 (if (and bytecomp-handler
2959 ;; Make sure that function exists. This is important 2960 ;; Make sure that function exists. This is important
2960 ;; for CL compiler macros since the symbol may be 2961 ;; for CL compiler macros since the symbol may be
@@ -3167,7 +3168,6 @@ If it is nil, then the handler is \"byte-compile-SYMBOL.\""
3167(byte-defop-compiler bobp 0) 3168(byte-defop-compiler bobp 0)
3168(byte-defop-compiler current-buffer 0) 3169(byte-defop-compiler current-buffer 0)
3169;;(byte-defop-compiler read-char 0) ;; obsolete 3170;;(byte-defop-compiler read-char 0) ;; obsolete
3170(byte-defop-compiler interactive-p 0)
3171(byte-defop-compiler widen 0) 3171(byte-defop-compiler widen 0)
3172(byte-defop-compiler end-of-line 0-1) 3172(byte-defop-compiler end-of-line 0-1)
3173(byte-defop-compiler forward-char 0-1) 3173(byte-defop-compiler forward-char 0-1)
@@ -3946,7 +3946,6 @@ binding slots have been popped."
3946(byte-defop-compiler-1 save-excursion) 3946(byte-defop-compiler-1 save-excursion)
3947(byte-defop-compiler-1 save-current-buffer) 3947(byte-defop-compiler-1 save-current-buffer)
3948(byte-defop-compiler-1 save-restriction) 3948(byte-defop-compiler-1 save-restriction)
3949(byte-defop-compiler-1 save-window-excursion)
3950(byte-defop-compiler-1 with-output-to-temp-buffer) 3949(byte-defop-compiler-1 with-output-to-temp-buffer)
3951(byte-defop-compiler-1 track-mouse) 3950(byte-defop-compiler-1 track-mouse)
3952 3951
@@ -4047,15 +4046,6 @@ binding slots have been popped."
4047 (byte-compile-body-do-effect (cdr form)) 4046 (byte-compile-body-do-effect (cdr form))
4048 (byte-compile-out 'byte-unbind 1)) 4047 (byte-compile-out 'byte-unbind 1))
4049 4048
4050(defun byte-compile-save-window-excursion (form)
4051 (pcase (cdr form)
4052 (`(:fun-body ,f)
4053 (byte-compile-form `(list (list 'funcall ,f))))
4054 (body
4055 (byte-compile-push-constant
4056 (byte-compile-top-level-body body for-effect))))
4057 (byte-compile-out 'byte-save-window-excursion 0))
4058
4059(defun byte-compile-with-output-to-temp-buffer (form) 4049(defun byte-compile-with-output-to-temp-buffer (form)
4060 (byte-compile-form (car (cdr form))) 4050 (byte-compile-form (car (cdr form)))
4061 (byte-compile-out 'byte-temp-output-buffer-setup 0) 4051 (byte-compile-out 'byte-temp-output-buffer-setup 0)
diff --git a/lisp/emacs-lisp/cconv.el b/lisp/emacs-lisp/cconv.el
index d8f5a7da44d..4e42e9f3c1d 100644
--- a/lisp/emacs-lisp/cconv.el
+++ b/lisp/emacs-lisp/cconv.el
@@ -635,8 +635,8 @@ Returns a form where all lambdas don't have any free variables."
635 ,(cconv-closure-convert-rec `(function (lambda () ,@body)) 635 ,(cconv-closure-convert-rec `(function (lambda () ,@body))
636 emvrs fvrs envs lmenvs))) 636 emvrs fvrs envs lmenvs)))
637 637
638 (`(,(and head (or `save-window-excursion `track-mouse)) . ,body) 638 (`(track-mouse . ,body)
639 `(,head 639 `(track-mouse
640 :fun-body 640 :fun-body
641 ,(cconv-closure-convert-rec `(function (lambda () ,@body)) 641 ,(cconv-closure-convert-rec `(function (lambda () ,@body))
642 emvrs fvrs envs lmenvs))) 642 emvrs fvrs envs lmenvs)))
@@ -827,7 +827,7 @@ lambdas if they are suitable for lambda lifting.
827 827
828 ;; FIXME: The bytecode for save-window-excursion and the lack of 828 ;; FIXME: The bytecode for save-window-excursion and the lack of
829 ;; bytecode for track-mouse forces us to wrap the body. 829 ;; bytecode for track-mouse forces us to wrap the body.
830 (`(,(or `save-window-excursion `track-mouse) . ,body) 830 (`(track-mouse . ,body)
831 (setq inclosure (1+ inclosure)) 831 (setq inclosure (1+ inclosure))
832 (dolist (form body) 832 (dolist (form body)
833 (cconv-analyse-form form env inclosure))) 833 (cconv-analyse-form form env inclosure)))
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el
index 37a86b7135d..85717408121 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -1209,7 +1209,6 @@ This function also returns nil meaning don't specify the indentation."
1209(put 'prog1 'lisp-indent-function 1) 1209(put 'prog1 'lisp-indent-function 1)
1210(put 'prog2 'lisp-indent-function 2) 1210(put 'prog2 'lisp-indent-function 2)
1211(put 'save-excursion 'lisp-indent-function 0) 1211(put 'save-excursion 'lisp-indent-function 0)
1212(put 'save-window-excursion 'lisp-indent-function 0)
1213(put 'save-restriction 'lisp-indent-function 0) 1212(put 'save-restriction 'lisp-indent-function 0)
1214(put 'save-match-data 'lisp-indent-function 0) 1213(put 'save-match-data 'lisp-indent-function 0)
1215(put 'save-current-buffer 'lisp-indent-function 0) 1214(put 'save-current-buffer 'lisp-indent-function 0)
diff --git a/lisp/subr.el b/lisp/subr.el
index c72752eb8f2..626128c62b3 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2767,6 +2767,25 @@ nor the buffer list."
2767 (when (buffer-live-p ,old-buffer) 2767 (when (buffer-live-p ,old-buffer)
2768 (set-buffer ,old-buffer)))))) 2768 (set-buffer ,old-buffer))))))
2769 2769
2770(defmacro save-window-excursion (&rest body)
2771 "Execute BODY, preserving window sizes and contents.
2772Return the value of the last form in BODY.
2773Restore which buffer appears in which window, where display starts,
2774and the value of point and mark for each window.
2775Also restore the choice of selected window.
2776Also restore which buffer is current.
2777Does not restore the value of point in current buffer.
2778
2779BEWARE: Most uses of this macro introduce bugs.
2780E.g. it should not be used to try and prevent some code from opening
2781a new window, since that window may sometimes appear in another frame,
2782in which case `save-window-excursion' cannot help."
2783 (declare (indent 0) (debug t))
2784 (let ((c (make-symbol "wconfig")))
2785 `(let ((,c (current-window-configuration)))
2786 (unwind-protect (progn ,@body)
2787 (set-window-configuration ,c)))))
2788
2770(defmacro with-temp-file (file &rest body) 2789(defmacro with-temp-file (file &rest body)
2771 "Create a new buffer, evaluate BODY there, and write the buffer to FILE. 2790 "Create a new buffer, evaluate BODY there, and write the buffer to FILE.
2772The value returned is the value of the last form in BODY. 2791The value returned is the value of the last form in BODY.
diff --git a/src/ChangeLog b/src/ChangeLog
index 0b2ee8550ca..6bebce0abaa 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,10 @@
12011-02-19 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * window.c (Fsave_window_excursion): Remove. Moved to Lisp.
4 (syms_of_window): Don't defsubr it.
5 * window.h (Fsave_window_excursion): Don't declare it.
6 * bytecode.c (exec_byte_code): Inline Fsave_window_excursion.
7
12011-02-17 Stefan Monnier <monnier@iro.umontreal.ca> 82011-02-17 Stefan Monnier <monnier@iro.umontreal.ca>
2 9
3 * eval.c (Vinternal_interpreter_environment): Remove. 10 * eval.c (Vinternal_interpreter_environment): Remove.
diff --git a/src/bytecode.c b/src/bytecode.c
index 1ad01aaf8f7..ad2f7d18ade 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -138,7 +138,7 @@ extern Lisp_Object Qand_optional, Qand_rest;
138 138
139#define Bpoint 0140 139#define Bpoint 0140
140/* Was Bmark in v17. */ 140/* Was Bmark in v17. */
141#define Bsave_current_buffer 0141 141#define Bsave_current_buffer 0141 /* Obsolete. */
142#define Bgoto_char 0142 142#define Bgoto_char 0142
143#define Binsert 0143 143#define Binsert 0143
144#define Bpoint_max 0144 144#define Bpoint_max 0144
@@ -158,7 +158,7 @@ extern Lisp_Object Qand_optional, Qand_rest;
158#define Bsave_current_buffer_1 0162 /* Replacing Bsave_current_buffer. */ 158#define Bsave_current_buffer_1 0162 /* Replacing Bsave_current_buffer. */
159#define Bread_char 0162 /* No longer generated as of v19 */ 159#define Bread_char 0162 /* No longer generated as of v19 */
160#define Bset_mark 0163 /* this loser is no longer generated as of v18 */ 160#define Bset_mark 0163 /* this loser is no longer generated as of v18 */
161#define Binteractive_p 0164 /* Needed since interactive-p takes unevalled args */ 161#define Binteractive_p 0164 /* Obsolete. */
162 162
163#define Bforward_char 0165 163#define Bforward_char 0165
164#define Bforward_word 0166 164#define Bforward_word 0166
@@ -183,7 +183,7 @@ extern Lisp_Object Qand_optional, Qand_rest;
183#define Bdup 0211 183#define Bdup 0211
184 184
185#define Bsave_excursion 0212 185#define Bsave_excursion 0212
186#define Bsave_window_excursion 0213 186#define Bsave_window_excursion 0213 /* Obsolete. */
187#define Bsave_restriction 0214 187#define Bsave_restriction 0214
188#define Bcatch 0215 188#define Bcatch 0215
189 189
@@ -192,7 +192,7 @@ extern Lisp_Object Qand_optional, Qand_rest;
192#define Btemp_output_buffer_setup 0220 192#define Btemp_output_buffer_setup 0220
193#define Btemp_output_buffer_show 0221 193#define Btemp_output_buffer_show 0221
194 194
195#define Bunbind_all 0222 195#define Bunbind_all 0222 /* Obsolete. */
196 196
197#define Bset_marker 0223 197#define Bset_marker 0223
198#define Bmatch_beginning 0224 198#define Bmatch_beginning 0224
@@ -763,7 +763,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
763 AFTER_POTENTIAL_GC (); 763 AFTER_POTENTIAL_GC ();
764 break; 764 break;
765 765
766 case Bunbind_all: 766 case Bunbind_all: /* Obsolete. */
767 /* To unbind back to the beginning of this frame. Not used yet, 767 /* To unbind back to the beginning of this frame. Not used yet,
768 but will be needed for tail-recursion elimination. */ 768 but will be needed for tail-recursion elimination. */
769 BEFORE_POTENTIAL_GC (); 769 BEFORE_POTENTIAL_GC ();
@@ -891,16 +891,24 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
891 save_excursion_save ()); 891 save_excursion_save ());
892 break; 892 break;
893 893
894 case Bsave_current_buffer: 894 case Bsave_current_buffer: /* Obsolete. */
895 case Bsave_current_buffer_1: 895 case Bsave_current_buffer_1:
896 record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ()); 896 record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ());
897 break; 897 break;
898 898
899 case Bsave_window_excursion: 899 case Bsave_window_excursion: /* Obsolete. */
900 BEFORE_POTENTIAL_GC (); 900 {
901 TOP = Fsave_window_excursion (TOP); /* FIXME: lexbind */ 901 register Lisp_Object val;
902 AFTER_POTENTIAL_GC (); 902 register int count = SPECPDL_INDEX ();
903 break; 903
904 record_unwind_protect (Fset_window_configuration,
905 Fcurrent_window_configuration (Qnil));
906 BEFORE_POTENTIAL_GC ();
907 TOP = Fprogn (TOP);
908 unbind_to (count, TOP);
909 AFTER_POTENTIAL_GC ();
910 break;
911 }
904 912
905 case Bsave_restriction: 913 case Bsave_restriction:
906 record_unwind_protect (save_restriction_restore, 914 record_unwind_protect (save_restriction_restore,
@@ -1412,7 +1420,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
1412 AFTER_POTENTIAL_GC (); 1420 AFTER_POTENTIAL_GC ();
1413 break; 1421 break;
1414 1422
1415 case Binteractive_p: 1423 case Binteractive_p: /* Obsolete. */
1416 PUSH (Finteractive_p ()); 1424 PUSH (Finteractive_p ());
1417 break; 1425 break;
1418 1426
diff --git a/src/window.c b/src/window.c
index abf01758c3f..c90cc268a92 100644
--- a/src/window.c
+++ b/src/window.c
@@ -6400,28 +6400,6 @@ redirection (see `redirect-frame-focus'). */)
6400 return (tem); 6400 return (tem);
6401} 6401}
6402 6402
6403DEFUN ("save-window-excursion", Fsave_window_excursion, Ssave_window_excursion,
6404 0, UNEVALLED, 0,
6405 doc: /* Execute BODY, preserving window sizes and contents.
6406Return the value of the last form in BODY.
6407Restore which buffer appears in which window, where display starts,
6408and the value of point and mark for each window.
6409Also restore the choice of selected window.
6410Also restore which buffer is current.
6411Does not restore the value of point in current buffer.
6412usage: (save-window-excursion BODY...) */)
6413 (Lisp_Object args)
6414{
6415 register Lisp_Object val;
6416 register int count = SPECPDL_INDEX ();
6417
6418 record_unwind_protect (Fset_window_configuration,
6419 Fcurrent_window_configuration (Qnil));
6420 val = Fprogn (args);
6421 return unbind_to (count, val);
6422}
6423
6424
6425 6403
6426/*********************************************************************** 6404/***********************************************************************
6427 Window Split Tree 6405 Window Split Tree
@@ -7195,7 +7173,6 @@ frame to be redrawn only if it is a tty frame. */);
7195 defsubr (&Swindow_configuration_frame); 7173 defsubr (&Swindow_configuration_frame);
7196 defsubr (&Sset_window_configuration); 7174 defsubr (&Sset_window_configuration);
7197 defsubr (&Scurrent_window_configuration); 7175 defsubr (&Scurrent_window_configuration);
7198 defsubr (&Ssave_window_excursion);
7199 defsubr (&Swindow_tree); 7176 defsubr (&Swindow_tree);
7200 defsubr (&Sset_window_margins); 7177 defsubr (&Sset_window_margins);
7201 defsubr (&Swindow_margins); 7178 defsubr (&Swindow_margins);
diff --git a/src/window.h b/src/window.h
index 491ffa30bd1..473a43bbc3c 100644
--- a/src/window.h
+++ b/src/window.h
@@ -860,7 +860,6 @@ EXFUN (Fwindow_minibuffer_p, 1);
860EXFUN (Fdelete_window, 1); 860EXFUN (Fdelete_window, 1);
861EXFUN (Fwindow_buffer, 1); 861EXFUN (Fwindow_buffer, 1);
862EXFUN (Fget_buffer_window, 2); 862EXFUN (Fget_buffer_window, 2);
863EXFUN (Fsave_window_excursion, UNEVALLED);
864EXFUN (Fset_window_configuration, 1); 863EXFUN (Fset_window_configuration, 1);
865EXFUN (Fcurrent_window_configuration, 1); 864EXFUN (Fcurrent_window_configuration, 1);
866extern int compare_window_configurations (Lisp_Object, Lisp_Object, int); 865extern int compare_window_configurations (Lisp_Object, Lisp_Object, int);