Merge from lexical-binding branch.
authorStefan Monnier <monnier@iro.umontreal.ca>
Fri, 1 Apr 2011 17:19:52 +0000 (13:19 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Fri, 1 Apr 2011 17:19:52 +0000 (13:19 -0400)
* doc/lispref/eval.texi (Eval): Discourage the use of `eval'.
Document its new `lexical' argument.

* doc/lispref/variables.texi (Defining Variables): Mention the new meaning of `defvar'.
(Lexical Binding): New sub-section.

* lisp/Makefile.in (BIG_STACK_DEPTH, BIG_STACK_OPTS, BYTE_COMPILE_FLAGS):
New variables.
(compile-onefile, .el.elc, compile-calc, recompile): Use them.
(COMPILE_FIRST): Add macroexp and cconv.
* lisp/makefile.w32-in: Mirror changes in Makefile.in.

* lisp/vc/cvs-status.el:
* lisp/vc/diff-mode.el:
* lisp/vc/log-edit.el:
* lisp/vc/log-view.el:
* lisp/vc/smerge-mode.el:
* lisp/textmodes/bibtex-style.el:
* textmodes/css.el:
* lisp/startup.el:
* lisp/uniquify.el:
* lisp/minibuffer.el:
* lisp/newcomment.el:
* lisp/reveal.el:
* lisp/server.el:
* lisp/mpc.el:
* lisp/emacs-lisp/smie.el:
* lisp/doc-view.el:
* lisp/dired.el:
* lisp/abbrev.el: Use lexical binding.

* lisp/custom.el (custom-initialize-default, custom-declare-variable):
Use `defvar'.

* lisp/files.el (lexical-binding): Declare safe.

* lisp/help-fns.el (help-split-fundoc): Return nil if there's nothing else
than the arglist.
(help-add-fundoc-usage): Don't add `Not documented'.
(help-function-arglist): Handle closures, subroutines, and new
byte-code-functions.
(help-make-usage): Remove leading underscores.
(describe-function-1): Handle closures.
(describe-variable): Use special-variable-p for completion.

* lisp/simple.el (with-wrapper-hook, apply-partially): Move to subr.el.

* lisp/subr.el (apply-partially): Use new closures rather than CL.
(--dolist-tail--, --dotimes-limit--): Don't declare dynamic.
(dolist, dotimes): Use slightly different expansion for lexical code.
(functionp): Move to C.
(letrec): New macro.
(with-wrapper-hook): Use it and apply-partially instead of CL.
(eval-after-load): Preserve lexical-binding.
(save-window-excursion, with-output-to-temp-buffer): Turn them
into macros.

* lisp/emacs-lisp/advice.el (ad-arglist): Use help-function-arglist.

* lisp/emacs-lisp/autoload.el (make-autoload): Don't burp on trivial macros.

* lisp/emacs-lisp/byte-opt.el: Use lexical binding.
(byte-inline-lapcode): Remove (to bytecomp).
(byte-compile-inline-expand): Pay attention to inlining to/from
lexically bound code.
(byte-compile-unfold-lambda): Don't handle byte-code-functions
any more.
(byte-optimize-form-code-walker): Don't handle save-window-excursion
any more and don't call compiler-macros.
(byte-compile-splice-in-already-compiled-code): Remove.
(byte-code): Don't inline any more.
(disassemble-offset): Receive `bytes' as argument rather than via
dynamic scoping.
(byte-compile-tag-number): Declare before first use.
(byte-decompile-bytecode-1): Handle new byte-codes, don't change
`return' even if make-spliceable.
(byte-compile-side-effect-and-error-free-ops): Add stack-ref, remove
obsolete interactive-p.
(byte-optimize-lapcode): Optimize new lap-codes.
Don't trip up on new form of `byte-constant' lap code.

* lisp/emacs-lisp/byte-run.el (make-obsolete): Don't set the `byte-compile'
handler any more.

* lisp/emacs-lisp/bytecomp.el: Use lexical binding instead of
a "bytecomp-" prefix.  Macroexpand everything as a separate phase.
(byte-compile-initial-macro-environment):
Handle declare-function here.
(byte-compile--lexical-environment): New var.
(byte-stack-ref, byte-stack-set, byte-discardN)
(byte-discardN-preserve-tos): New lap codes.
(byte-interactive-p): Don't use any more.
(byte-compile-push-bytecodes, byte-compile-push-bytecode-const2):
New macros.
(byte-compile-lapcode): Use them and handle new lap codes.
(byte-compile-obsolete): Remove.
(byte-compile-arglist-signature): Handle new byte-code arg"lists".
(byte-compile-arglist-warn): Check late def of inlinable funs.
(byte-compile-cl-warn): Don't silence warnings for compiler-macros
since they should have been expanded by now.
(byte-compile--outbuffer): Rename from bytecomp-outbuffer.
(byte-compile-from-buffer): Remove unused second arg.
(byte-compile-preprocess): New function.
(byte-compile-toplevel-file-form): New function to distinguish
file-form calls from outside from file-form calls from hunk-handlers.
(byte-compile-file-form): Simplify.
(byte-compile-file-form-defsubst): Remove.
(byte-compile-file-form-defmumble): Simplify now that
byte-compile-lambda always returns a byte-code-function.
(byte-compile): Preprocess.
(byte-compile-byte-code-maker, byte-compile-byte-code-unmake):
Remove, not used any more.
(byte-compile-arglist-vars, byte-compile-make-lambda-lexenv)
(byte-compile-make-args-desc): New funs.
(byte-compile-lambda): Handle lexical functions.  Always return
a byte-code-function.
(byte-compile-reserved-constants): New var, to make up room for
closed-over variables.
(byte-compile-constants-vector): Obey it.
(byte-compile-top-level): New args `lexenv' and `reserved-csts'.
(byte-compile-macroexpand-declare-function): New function.
(byte-compile-form): Call byte-compile-unfold-bcf to inline immediate
byte-code-functions.
(byte-compile-form): Check obsolescence here.
(byte-compile-inline-lapcode, byte-compile-unfold-bcf): New functions.
(byte-compile-variable-ref): Remove.
(byte-compile-dynamic-variable-op): New fun.
(byte-compile-dynamic-variable-bind, byte-compile-variable-ref)
(byte-compile-variable-set): New funs.
(byte-compile-discard): Add 2 args.
(byte-compile-stack-ref, byte-compile-stack-set)
(byte-compile-make-closure, byte-compile-get-closed-var): New funs.
(byte-compile-funarg, byte-compile-funarg-2): Remove, handled in
macroexpand-all instead.
(byte-compile-quote-form): Remove.
(byte-compile-push-binding-init, byte-compile-not-lexical-var-p)
(byte-compile-bind, byte-compile-unbind): New funs.
(byte-compile-let): Handle let* and lexical binding.
(byte-compile-let*): Remove.
(byte-compile-catch, byte-compile-unwind-protect)
(byte-compile-track-mouse, byte-compile-condition-case):
Handle a new :fun-body form, used for lexical scoping.
(byte-compile-save-window-excursion)
(byte-compile-with-output-to-temp-buffer): Remove.
(byte-compile-defun): Simplify.
(byte-compile-stack-adjustment): New fun.
(byte-compile-out): Use it.
(byte-compile-refresh-preloaded): Don't reload byte-compiler files.

* lisp/emacs-lisp/cconv.el: New file.

* lisp/emacs-lisp/cl-extra.el (cl-macroexpand-all): Properly quote CL
closures.

* lisp/emacs-lisp/cl-macs.el (cl-byte-compile-block)
(cl-byte-compile-throw): Remove.
(cl-block-wrapper, cl-block-throw): Use compiler-macros instead.

* lisp/emacs-lisp/cl.el (pushnew): Silence warning.

* lisp/emacs-lisp/disass.el (disassemble-internal): Handle new
`closure' objects.
(disassemble-1): Handle new byte codes.

* lisp/emacs-lisp/edebug.el (edebug-eval-defun)
(edebug-eval-top-level-form): Use eval-sexp-add-defvars.
(edebug-toggle): Avoid `eval'.

* lisp/emacs-lisp/eieio-comp.el: Remove.

* lisp/emacs-lisp/eieio.el (byte-compile-file-form-defmethod):
Don't autoload.
(eieio-defgeneric-form-primary-only-one): Use `byte-compile' rather
than the internal `byte-compile-lambda'.
(defmethod): Don't hide code under quotes.
(eieio-defmethod): New `code' argument.

* lisp/emacs-lisp/float-sup.el (pi): Don't declare as dynamically bound.

* lisp/emacs-lisp/lisp-mode.el (eval-last-sexp-1):
Use eval-sexp-add-defvars.
(eval-sexp-add-defvars): New fun.

* lisp/emacs-lisp/macroexp.el: Use lexical binding.
(macroexpand-all-1): Check obsolete macros.  Expand compiler-macros.
Don't convert ' to #' without checking that it's indeed quoting
a lambda.

* lisp/emacs-lisp/pcase.el: Don't use destructuring-bind.
(pcase--memoize): Rename from pcase-memoize.  Change weakness.
(pcase): Add `let' pattern.
Change memoization so it actually works.
(pcase-mutually-exclusive-predicates): Add byte-code-function-p.
(pcase--u1) <guard, pred>: Fix possible shadowing problem.
<let>: New case.

* src/alloc.c (Fmake_symbol): Init new `declared_special' field.

* src/buffer.c (defvar_per_buffer): Set new `declared_special' field.

* src/bytecode.c (Bstack_ref, Bstack_set, Bstack_set2, BdiscardN):
New byte-codes.
(exec_byte_code): New function extracted from Fbyte_code to handle new
calling convention for byte-code-functions.  Add new byte-codes.

* src/callint.c (Fcall_interactively): Preserve lexical-binding mode for
interactive spec.

* src/doc.c (Fdocumentation, store_function_docstring):
* src/data.c (Finteractive_form): Handle closures.

* src/eval.c (Fsetq): Handle lexical vars.
(Fdefun, Fdefmacro, Ffunction): Make closures when needed.
(Fdefconst, Fdefvaralias, Fdefvar): Mark as dynamic.
(FletX, Flet): Obey lexical binding.
(Fcommandp): Handle closures.
(Feval): New `lexical' arg.
(eval_sub): New function extracted from Feval.  Use it almost
everywhere where Feval was used.  Look up vars in lexical env.
Handle closures.
(Ffunctionp): Move from subr.el.
(Ffuncall): Handle closures.
(apply_lambda): Remove `eval_flags'.
(funcall_lambda): Handle closures and new byte-code-functions.
(Fspecial_variable_p): New function.
(syms_of_eval): Initialize the Vinternal_interpreter_environment var,
but without exporting it to Lisp.

* src/fns.c (concat, mapcar1): Accept byte-code-functions.

* src/image.c (parse_image_spec): Use Ffunctionp.

* src/keyboard.c (eval_dyn): New fun.
(menu_item_eval_property): Use it.

* src/lisp.h (struct Lisp_Symbol): New field `declared_special'.

* src/lread.c (lisp_file_lexically_bound_p): New function.
(Fload): Bind Qlexical_binding.
(readevalloop): Remove `evalfun' arg.
Bind Qinternal_interpreter_environment.
(Feval_buffer): Bind Qlexical_binding.
(defvar_int, defvar_bool, defvar_lisp_nopro, defvar_kboard):
Mark as dynamic.
(syms_of_lread): Declare `lexical-binding'.

* src/window.c (Ftemp_output_buffer_show): New fun.
(Fsave_window_excursion):
* src/print.c (Fwith_output_to_temp_buffer): Move to subr.el.

1  2 
doc/lispref/ChangeLog
etc/NEWS
lisp/ChangeLog
lisp/emacs-lisp/bytecomp.el
lisp/minibuffer.el
src/ChangeLog
src/eval.c
src/window.c

@@@ -1,6 -1,6 +1,14 @@@
++2011-04-01  Stefan Monnier  <monnier@iro.umontreal.ca>
++
++      * variables.texi (Defining Variables): Mention the new meaning of `defvar'.
++      (Lexical Binding): New sub-section.
++
++      * eval.texi (Eval): Discourage the use of `eval'.
++      Document its new `lexical' argument.
++
  2011-03-28  Stefan Monnier  <monnier@iro.umontreal.ca>
  
--      * commands.texi (Command Overview): post-command-hook is not reset to
++      * commands.texi (Command Overview): `post-command-hook' is not reset to
        nil any more.
  
  2011-03-19  Stefan Monnier  <monnier@iro.umontreal.ca>
diff --cc etc/NEWS
+++ b/etc/NEWS
@@@ -773,6 -748,6 +773,22 @@@ sc.el, x-menu.el, rnews.el, rnewspost.e
  \f
  * Lisp changes in Emacs 24.1
  
++** Code can now use lexical scoping by default instead of dynamic scoping.
++The `lexical-binding' variable lets code use lexical scoping for local
++variables.  It is typically set via file-local variables, in which case it
++applies to all the code in that file.
++
++*** `eval' takes a new optional argument `lexical' to choose the new lexical
++binding instead of the old dynamic binding mode.
++
++*** Lexically scoped interpreted functions are represented with a new form
++of function value which looks like (closure ENV ARGS &rest BODY).
++
++*** New macro `letrec' to define recursive local functions.
++
++*** New function `special-variable-p' to check whether a variable is
++declared as dynamically bound.
++
  ** pre/post-command-hook are not reset to nil upon error.
  Instead, the offending function is removed.
  
diff --cc lisp/ChangeLog
@@@ -1,51 -1,3 +1,245 @@@
++2011-04-01  Stefan Monnier  <monnier@iro.umontreal.ca>
++
++      Add lexical binding.
++
++      * subr.el (apply-partially): Use new closures rather than CL.
++      (--dolist-tail--, --dotimes-limit--): Don't declare dynamic.
++      (dolist, dotimes): Use slightly different expansion for lexical code.
++      (functionp): Move to C.
++      (letrec): New macro.
++      (with-wrapper-hook): Use it and apply-partially instead of CL.
++      (eval-after-load): Preserve lexical-binding.
++      (save-window-excursion, with-output-to-temp-buffer): Turn them
++      into macros.
++
++      * simple.el (with-wrapper-hook, apply-partially): Move to subr.el.
++
++      * help-fns.el (help-split-fundoc): Return nil if there's nothing else
++      than the arglist.
++      (help-add-fundoc-usage): Don't add `Not documented'.
++      (help-function-arglist): Handle closures, subroutines, and new
++      byte-code-functions.
++      (help-make-usage): Remove leading underscores.
++      (describe-function-1): Handle closures.
++      (describe-variable): Use special-variable-p for completion.
++
++      * files.el (lexical-binding): Declare safe.
++
++      * emacs-lisp/pcase.el: Don't use destructuring-bind.
++      (pcase--memoize): Rename from pcase-memoize.  Change weakness.
++      (pcase): Add `let' pattern.
++      Change memoization so it actually works.
++      (pcase-mutually-exclusive-predicates): Add byte-code-function-p.
++      (pcase--u1) <guard, pred>: Fix possible shadowing problem.
++      <let>: New case.
++
++      * emacs-lisp/macroexp.el: Use lexical binding.
++      (macroexpand-all-1): Check obsolete macros.  Expand compiler-macros.
++      Don't convert ' to #' without checking that it's indeed quoting
++      a lambda.
++
++      * emacs-lisp/lisp-mode.el (eval-last-sexp-1):
++      Use eval-sexp-add-defvars.
++      (eval-sexp-add-defvars): New fun.
++
++      * emacs-lisp/float-sup.el (pi): Don't declare as dynamically bound.
++
++      * emacs-lisp/eieio.el (byte-compile-file-form-defmethod):
++      Don't autoload.
++      (eieio-defgeneric-form-primary-only-one): Use `byte-compile' rather
++      than the internal `byte-compile-lambda'.
++      (defmethod): Don't hide code under quotes.
++      (eieio-defmethod): New `code' argument.
++
++      * emacs-lisp/eieio-comp.el: Remove.
++
++      * emacs-lisp/edebug.el (edebug-eval-defun)
++      (edebug-eval-top-level-form): Use eval-sexp-add-defvars.
++      (edebug-toggle): Avoid `eval'.
++
++      * emacs-lisp/disass.el (disassemble-internal): Handle new
++      `closure' objects.
++      (disassemble-1): Handle new byte codes.
++
++      * emacs-lisp/cl.el (pushnew): Silence warning.
++
++      * emacs-lisp/cl-macs.el (cl-byte-compile-block)
++      (cl-byte-compile-throw): Remove.
++      (cl-block-wrapper, cl-block-throw): Use compiler-macros instead.
++
++      * emacs-lisp/cl-extra.el (cl-macroexpand-all): Properly quote CL
++      closures.
++
++      * emacs-lisp/cconv.el: New file.
++
++      * emacs-lisp/bytecomp.el: Use lexical binding instead of
++      a "bytecomp-" prefix.  Macroexpand everything as a separate phase.
++      (byte-compile-initial-macro-environment):
++      Handle declare-function here.
++      (byte-compile--lexical-environment): New var.
++      (byte-stack-ref, byte-stack-set, byte-discardN)
++      (byte-discardN-preserve-tos): New lap codes.
++      (byte-interactive-p): Don't use any more.
++      (byte-compile-push-bytecodes, byte-compile-push-bytecode-const2):
++      New macros.
++      (byte-compile-lapcode): Use them and handle new lap codes.
++      (byte-compile-obsolete): Remove.
++      (byte-compile-arglist-signature): Handle new byte-code arg"lists".
++      (byte-compile-arglist-warn): Check late def of inlinable funs.
++      (byte-compile-cl-warn): Don't silence warnings for compiler-macros
++      since they should have been expanded by now.
++      (byte-compile--outbuffer): Rename from bytecomp-outbuffer.
++      (byte-compile-from-buffer): Remove unused second arg.
++      (byte-compile-preprocess): New function.
++      (byte-compile-toplevel-file-form): New function to distinguish
++      file-form calls from outside from file-form calls from hunk-handlers.
++      (byte-compile-file-form): Simplify.
++      (byte-compile-file-form-defsubst): Remove.
++      (byte-compile-file-form-defmumble): Simplify now that
++      byte-compile-lambda always returns a byte-code-function.
++      (byte-compile): Preprocess.
++      (byte-compile-byte-code-maker, byte-compile-byte-code-unmake):
++      Remove, not used any more.
++      (byte-compile-arglist-vars, byte-compile-make-lambda-lexenv)
++      (byte-compile-make-args-desc): New funs.
++      (byte-compile-lambda): Handle lexical functions.  Always return
++      a byte-code-function.
++      (byte-compile-reserved-constants): New var, to make up room for
++      closed-over variables.
++      (byte-compile-constants-vector): Obey it.
++      (byte-compile-top-level): New args `lexenv' and `reserved-csts'.
++      (byte-compile-macroexpand-declare-function): New function.
++      (byte-compile-form): Call byte-compile-unfold-bcf to inline immediate
++      byte-code-functions.
++      (byte-compile-form): Check obsolescence here.
++      (byte-compile-inline-lapcode, byte-compile-unfold-bcf): New functions.
++      (byte-compile-variable-ref): Remove.
++      (byte-compile-dynamic-variable-op): New fun.
++      (byte-compile-dynamic-variable-bind, byte-compile-variable-ref)
++      (byte-compile-variable-set): New funs.
++      (byte-compile-discard): Add 2 args.
++      (byte-compile-stack-ref, byte-compile-stack-set)
++      (byte-compile-make-closure, byte-compile-get-closed-var): New funs.
++      (byte-compile-funarg, byte-compile-funarg-2): Remove, handled in
++      macroexpand-all instead.
++      (byte-compile-quote-form): Remove.
++      (byte-compile-push-binding-init, byte-compile-not-lexical-var-p)
++      (byte-compile-bind, byte-compile-unbind): New funs.
++      (byte-compile-let): Handle let* and lexical binding.
++      (byte-compile-let*): Remove.
++      (byte-compile-catch, byte-compile-unwind-protect)
++      (byte-compile-track-mouse, byte-compile-condition-case):
++      Handle a new :fun-body form, used for lexical scoping.
++      (byte-compile-save-window-excursion)
++      (byte-compile-with-output-to-temp-buffer): Remove.
++      (byte-compile-defun): Simplify.
++      (byte-compile-stack-adjustment): New fun.
++      (byte-compile-out): Use it.
++      (byte-compile-refresh-preloaded): Don't reload byte-compiler files.
++
++      * emacs-lisp/byte-run.el (make-obsolete): Don't set the `byte-compile'
++      handler any more.
++
++      * emacs-lisp/byte-opt.el: Use lexical binding.
++      (byte-inline-lapcode): Remove (to bytecomp).
++      (byte-compile-inline-expand): Pay attention to inlining to/from
++      lexically bound code.
++      (byte-compile-unfold-lambda): Don't handle byte-code-functions
++      any more.
++      (byte-optimize-form-code-walker): Don't handle save-window-excursion
++      any more and don't call compiler-macros.
++      (byte-compile-splice-in-already-compiled-code): Remove.
++      (byte-code): Don't inline any more.
++      (disassemble-offset): Receive `bytes' as argument rather than via
++      dynamic scoping.
++      (byte-compile-tag-number): Declare before first use.
++      (byte-decompile-bytecode-1): Handle new byte-codes, don't change
++      `return' even if make-spliceable.
++      (byte-compile-side-effect-and-error-free-ops): Add stack-ref, remove
++      obsolete interactive-p.
++      (byte-optimize-lapcode): Optimize new lap-codes.
++      Don't trip up on new form of `byte-constant' lap code.
++
++      * emacs-lisp/autoload.el (make-autoload): Don't burp on trivial macros.
++
++      * emacs-lisp/advice.el (ad-arglist): Use help-function-arglist.
++
++      * custom.el (custom-initialize-default, custom-declare-variable):
++      Use `defvar'.
++
++      * Makefile.in (BIG_STACK_DEPTH, BIG_STACK_OPTS, BYTE_COMPILE_FLAGS):
++      New variables.
++      (compile-onefile, .el.elc, compile-calc, recompile): Use them.
++      (COMPILE_FIRST): Add macroexp and cconv.
++      * makefile.w32-in: Mirror changes in Makefile.in.
++
++      * vc/cvs-status.el:
++      * vc/diff-mode.el:
++      * vc/log-edit.el:
++      * vc/log-view.el:
++      * vc/smerge-mode.el:
++      * textmodes/bibtex-style.el:
++      * textmodes/css.el:
++      * startup.el:
++      * uniquify.el:
++      * minibuffer.el: 
++      * newcomment.el: 
++      * reveal.el: 
++      * server.el: 
++      * mpc.el: 
++      * emacs-lisp/smie.el: 
++      * doc-view.el: 
++      * dired.el: 
++      * abbrev.el: Use lexical binding.
++
 +2011-04-01  Eli Zaretskii  <eliz@gnu.org>
 +
 +      * info.el (info-display-manual): New function.
 +
 +2011-03-31  Stefan Monnier  <monnier@iro.umontreal.ca>
 +
 +      * loadup.el: Load minibuffer after loaddefs, to use define-minor-mode.
 +
 +2011-03-31  Tassilo Horn  <tassilo@member.fsf.org>
 +
 +      * net/rcirc.el (rcirc-handler-001): Only authenticate, if there's
 +      an entry for that server in rcirc-authinfo. (Bug#8385)
 +
 +2011-03-31  Glenn Morris  <rgm@gnu.org>
 +
 +      * progmodes/f90.el (f90-find-tag-default): Handle multiple `%'.
 +
 +      * generic-x.el (etc-fstab-generic-mode): Add ext4, sysfs keywords.
 +
 +2011-03-30  Christoph Scholtes  <cschol2112@googlemail.com>
 +
 +      * progmodes/python.el (python-default-interpreter)
 +      (python-python-command-args, python-jython-command-args)
 +      (python-which-shell, python-which-args, python-which-bufname)
 +      (python-file-queue, python-comint-output-filter-function)
 +      (python-toggle-shells, python-shell): Remove obsolete defcustoms,
 +      variables and functions.
 +
 +2011-03-30  Stefan Monnier  <monnier@iro.umontreal.ca>
 +
 +      * minibuffer.el (completion-table-dynamic): Optimize `boundaries'.
 +      (completion-in-region-mode): New minor mode.
 +      (completion-in-region): Use it.
 +      (completion-in-region--data, completion-in-region-mode-map): New vars.
 +      (completion-in-region--postch): New function.
 +      (completion--capf-misbehave-funs, completion--capf-safe-funs):
 +      New vars.
 +      (completion--capf-wrapper): New function.
 +      (completion-at-point): Use it to track well-behavedness of
 +      hook functions.
 +      (completion-help-at-point): New command.
 +
 +2011-03-30  Jason Merrill  <jason@redhat.com>  (tiny change)
 +
 +      * vc/add-log.el (add-change-log-entry): Don't use whitespace
 +      syntax class to search for whitespace on a single line
 +      (Message-ID: <4D938140.4030905@redhat.com>).
 +
  2011-03-30  Leo Liu  <sdl.web@gmail.com>
  
        * abbrev.el (abbrev-edit-save-to-file, abbrev-edit-save-buffer):
  
  2011-03-28  Brian T. Sniffen  <bsniffen@akamai.com>  (tiny change)
  
--      * net/imap.el (imap-shell-open, imap-process-connection-type): Use
--      imap-process-connection-type for 'shell' streams as well as
++      * net/imap.el (imap-shell-open, imap-process-connection-type):
++      Use imap-process-connection-type for 'shell' streams as well as
        Kerberos, SSL, other subprocesses.
  
  2011-03-28  Leo Liu  <sdl.web@gmail.com>
@@@ -2804,67 -2848,82 +2848,81 @@@ If FORM is a lambda or a macro, byte-co
  ;; expression.
  ;; If for-effect is non-nil, byte-compile-form will output a byte-discard
  ;; before terminating (ie no value will be left on the stack).
- ;; A byte-compile handler may, when for-effect is non-nil, choose output code
- ;; which does not leave a value on the stack, and then set for-effect to nil
- ;; (to prevent byte-compile-form from outputting the byte-discard).
+ ;; A byte-compile handler may, when byte-compile--for-effect is non-nil, choose
+ ;; output code which does not leave a value on the stack, and then set
+ ;; byte-compile--for-effect to nil (to prevent byte-compile-form from
+ ;; outputting the byte-discard).
  ;; If a handler wants to call another handler, it should do so via
- ;; byte-compile-form, or take extreme care to handle for-effect correctly.
- ;; (Use byte-compile-form-do-effect to reset the for-effect flag too.)
+ ;; byte-compile-form, or take extreme care to handle byte-compile--for-effect
+ ;; correctly.  (Use byte-compile-form-do-effect to reset the
+ ;; byte-compile--for-effect flag too.)
  ;;
  (defun byte-compile-form (form &optional for-effect)
-   (setq form (macroexpand form byte-compile-macro-environment))
-   (cond ((not (consp form))
-        (cond ((or (not (symbolp form)) (byte-compile-const-symbol-p form))
-               (when (symbolp form)
-                 (byte-compile-set-symbol-position form))
-               (byte-compile-constant form))
-              ((and for-effect byte-compile-delete-errors)
-               (when (symbolp form)
-                 (byte-compile-set-symbol-position form))
-               (setq for-effect nil))
-              (t (byte-compile-variable-ref 'byte-varref form))))
-       ((symbolp (car form))
-        (let* ((bytecomp-fn (car form))
-               (bytecomp-handler (get bytecomp-fn 'byte-compile)))
-          (when (byte-compile-const-symbol-p bytecomp-fn)
-            (byte-compile-warn "`%s' called as a function" bytecomp-fn))
-          (and (byte-compile-warning-enabled-p 'interactive-only)
-               (memq bytecomp-fn byte-compile-interactive-only-functions)
-               (byte-compile-warn "`%s' used from Lisp code\n\
- That command is designed for interactive use only" bytecomp-fn))
-          (when (byte-compile-warning-enabled-p 'callargs)
-            (if (memq bytecomp-fn
-                      '(custom-declare-group custom-declare-variable
-                                             custom-declare-face))
-                  (byte-compile-nogroup-warn form))
-            (byte-compile-callargs-warn form))
-          (if (and bytecomp-handler
-                     ;; Make sure that function exists.  This is important
-                     ;; for CL compiler macros since the symbol may be
-                     ;; `cl-byte-compile-compiler-macro' but if CL isn't
-                     ;; loaded, this function doesn't exist.
-                     (or (not (memq bytecomp-handler
-                                  '(cl-byte-compile-compiler-macro)))
-                         (functionp bytecomp-handler)))
-                (funcall bytecomp-handler form)
-            (byte-compile-normal-call form))
-          (if (byte-compile-warning-enabled-p 'cl-functions)
-              (byte-compile-cl-warn form))))
-       ((and (or (byte-code-function-p (car form))
-                 (eq (car-safe (car form)) 'lambda))
-             ;; if the form comes out the same way it went in, that's
-             ;; because it was malformed, and we couldn't unfold it.
-             (not (eq form (setq form (byte-compile-unfold-lambda form)))))
-        (byte-compile-form form for-effect)
-        (setq for-effect nil))
-       ((byte-compile-normal-call form)))
-   (if for-effect
-       (byte-compile-discard)))
+   (let ((byte-compile--for-effect for-effect))
+     (cond
+      ((not (consp form))
+       (cond ((or (not (symbolp form)) (byte-compile-const-symbol-p form))
+              (when (symbolp form)
+                (byte-compile-set-symbol-position form))
+              (byte-compile-constant form))
+             ((and byte-compile--for-effect byte-compile-delete-errors)
+              (when (symbolp form)
+                (byte-compile-set-symbol-position form))
+              (setq byte-compile--for-effect nil))
+             (t
+              (byte-compile-variable-ref form))))
+      ((symbolp (car form))
+       (let* ((fn (car form))
+              (handler (get fn 'byte-compile)))
+         (when (byte-compile-const-symbol-p fn)
+           (byte-compile-warn "`%s' called as a function" fn))
+         (and (byte-compile-warning-enabled-p 'interactive-only)
+              (memq fn byte-compile-interactive-only-functions)
+              (byte-compile-warn "`%s' used from Lisp code\n\
+ That command is designed for interactive use only" fn))
+         (if (and (fboundp (car form))
+                  (eq (car-safe (symbol-function (car form))) 'macro))
+             (byte-compile-report-error
+              (format "Forgot to expand macro %s" (car form))))
+         (if (and handler
+                  ;; Make sure that function exists.  This is important
+                  ;; for CL compiler macros since the symbol may be
+                  ;; `cl-byte-compile-compiler-macro' but if CL isn't
+                  ;; loaded, this function doesn't exist.
+                  (and (not (eq handler
+                                ;; Already handled by macroexpand-all.
+                                'cl-byte-compile-compiler-macro))
+                       (functionp handler)))
+             (funcall handler form)
+           (byte-compile-normal-call form))
+         (if (byte-compile-warning-enabled-p 'cl-functions)
+             (byte-compile-cl-warn form))))
+      ((and (byte-code-function-p (car form))
+            (memq byte-optimize '(t lap)))
+       (byte-compile-unfold-bcf form))
+      ((and (eq (car-safe (car form)) 'lambda)
+            ;; if the form comes out the same way it went in, that's
+            ;; because it was malformed, and we couldn't unfold it.
+            (not (eq form (setq form (byte-compile-unfold-lambda form)))))
+       (byte-compile-form form byte-compile--for-effect)
+       (setq byte-compile--for-effect nil))
+      ((byte-compile-normal-call form)))
+     (if byte-compile--for-effect
+         (byte-compile-discard))))
  
  (defun byte-compile-normal-call (form)
 -              '(custom-declare-group
 -                ;; custom-declare-variable custom-declare-face
 -                ))
+   (when (and (byte-compile-warning-enabled-p 'callargs)
+              (symbolp (car form)))
+     (if (memq (car form)
++              '(custom-declare-group custom-declare-variable
++                                     custom-declare-face))
+         (byte-compile-nogroup-warn form))
+     (when (get (car form) 'byte-obsolete-info)
+       (byte-compile-warn-obsolete (car form)))
+     (byte-compile-callargs-warn form))
    (if byte-compile-generate-call-tree
        (byte-compile-annotate-call-tree form))
-   (when (and for-effect (eq (car form) 'mapcar)
+   (when (and byte-compile--for-effect (eq (car form) 'mapcar)
               (byte-compile-warning-enabled-p 'mapcar))
      (byte-compile-set-symbol-position 'mapcar)
      (byte-compile-warn
@@@ -3137,12 -3294,68 +3293,66 @@@ If it is nil, then the handler is \"byt
          ((= len 4) (byte-compile-three-args form))
          (t (byte-compile-subr-wrong-args form "2-3")))))
  
- (defun byte-compile-noop (form)
+ (defun byte-compile-noop (_form)
    (byte-compile-constant nil))
  
- (defun byte-compile-discard ()
-   (byte-compile-out 'byte-discard 0))
+ (defun byte-compile-discard (&optional num preserve-tos)
+   "Output byte codes to discard the NUM entries at the top of the stack.
+ NUM defaults to 1.
+ If PRESERVE-TOS is non-nil, preserve the top-of-stack value, as if it were
+ popped before discarding the num values, and then pushed back again after
+ discarding."
+   (if (and (null num) (not preserve-tos))
+       ;; common case
+       (byte-compile-out 'byte-discard)
+     ;; general case
+     (unless num
+       (setq num 1))
+     (when (and preserve-tos (> num 0))
+       ;; Preserve the top-of-stack value by writing it directly to the stack
+       ;; location which will be at the top-of-stack after popping.
+       (byte-compile-stack-set (1- (- byte-compile-depth num)))
+       ;; Now we actually discard one less value, since we want to keep
+       ;; the eventual TOS
+       (setq num (1- num)))
+     (while (> num 0)
+       (byte-compile-out 'byte-discard)
+       (setq num (1- num)))))
+ (defun byte-compile-stack-ref (stack-pos)
+   "Output byte codes to push the value at stack position STACK-POS."
+   (let ((dist (- byte-compile-depth (1+ stack-pos))))
+     (if (zerop dist)
+         ;; A simple optimization
+         (byte-compile-out 'byte-dup)
+       ;; normal case
+       (byte-compile-out 'byte-stack-ref dist))))
+ (defun byte-compile-stack-set (stack-pos)
+   "Output byte codes to store the TOS value at stack position STACK-POS."
+   (byte-compile-out 'byte-stack-set (- byte-compile-depth (1+ stack-pos))))
+ (byte-defop-compiler-1 internal-make-closure byte-compile-make-closure)
+ (byte-defop-compiler-1 internal-get-closed-var byte-compile-get-closed-var)
 -(defconst byte-compile--env-var (make-symbol "env"))
 -
+ (defun byte-compile-make-closure (form)
+   "Byte-compile the special `internal-make-closure' form."
+   (if byte-compile--for-effect (setq byte-compile--for-effect nil)
+     (let* ((vars (nth 1 form))
+            (env (nth 2 form))
+            (body (nthcdr 3 form))
+            (fun
+             (byte-compile-lambda `(lambda ,vars . ,body) nil (length env))))
+       (assert (byte-code-function-p fun))
+       (byte-compile-form `(make-byte-code
+                            ',(aref fun 0) ',(aref fun 1)
+                            (vconcat (vector . ,env) ',(aref fun 2))
+                            ,@(nthcdr 3 (mapcar (lambda (x) `',x) fun)))))))
+ (defun byte-compile-get-closed-var (form)
+   "Byte-compile the special `internal-get-closed-var' form."
+   (if byte-compile--for-effect (setq byte-compile--for-effect nil)
+     (byte-compile-out 'byte-constant (nth 1 form))))
  
  ;; Compile a function that accepts one or more args and is right-associative.
  ;; We do it by left-associativity so that the operations
@@@ -171,16 -171,11 +171,15 @@@ FUN will be called in the buffer from w
  The result of the `completion-table-dynamic' form is a function
  that can be used as the COLLECTION argument to `try-completion' and
  `all-completions'.  See Info node `(elisp)Programmed Completion'."
-   (lexical-let ((fun fun))
-     (lambda (string pred action)
-       (if (eq (car-safe action) 'boundaries)
-           ;; `fun' is not supposed to return another function but a plain old
-           ;; completion table, whose boundaries are always trivial.
-           nil
-         (with-current-buffer (let ((win (minibuffer-selected-window)))
-                                (if (window-live-p win) (window-buffer win)
-                                  (current-buffer)))
-           (complete-with-action action (funcall fun string) string pred))))))
+   (lambda (string pred action)
 -    (with-current-buffer (let ((win (minibuffer-selected-window)))
 -                           (if (window-live-p win) (window-buffer win)
 -                             (current-buffer)))
 -      (complete-with-action action (funcall fun string) string pred))))
++    (if (eq (car-safe action) 'boundaries)
++        ;; `fun' is not supposed to return another function but a plain old
++        ;; completion table, whose boundaries are always trivial.
++        nil
++      (with-current-buffer (let ((win (minibuffer-selected-window)))
++                             (if (window-live-p win) (window-buffer win)
++                               (current-buffer)))
++        (complete-with-action action (funcall fun string) string pred)))))
  
  (defmacro lazy-completion-table (var fun)
    "Initialize variable VAR as a lazy completion table.
@@@ -672,16 -658,16 +666,16 @@@ scroll the window of possible completio
      (setq minibuffer-scroll-window nil))
  
    (cond
--    ;; If there's a fresh completion window with a live buffer,
--    ;; and this command is repeated, scroll that window.
++   ;; If there's a fresh completion window with a live buffer,
++   ;; and this command is repeated, scroll that window.
     ((window-live-p minibuffer-scroll-window)
      (let ((window minibuffer-scroll-window))
--        (with-current-buffer (window-buffer window)
--          (if (pos-visible-in-window-p (point-max) window)
--            ;; If end is in view, scroll up to the beginning.
--            (set-window-start window (point-min) nil)
--          ;; Else scroll down one screen.
--          (scroll-other-window))
++      (with-current-buffer (window-buffer window)
++        (if (pos-visible-in-window-p (point-max) window)
++            ;; If end is in view, scroll up to the beginning.
++            (set-window-start window (point-min) nil)
++          ;; Else scroll down one screen.
++          (scroll-other-window))
          nil)))
     ;; If we're cycling, keep on cycling.
     ((and completion-cycling completion-all-sorted-completions)
@@@ -1029,7 -1013,7 +1023,7 @@@ It also eliminates runs of equal string
                                   'mouse-face 'highlight)
                (add-text-properties (point) (progn (insert (cadr str)) (point))
                                     '(mouse-face nil
--                                              face completions-annotations)))
++                                     face completions-annotations)))
            (cond
             ((eq completions-format 'vertical)
              ;; Vertical format
@@@ -1482,20 -1348,20 +1476,20 @@@ same as `substitute-in-file-name'.
          ;; other table handle the test-completion case.
          nil)
         ((eq (car-safe action) 'boundaries)
--          ;; Only return boundaries if there's something to complete,
--          ;; since otherwise when we're used in
--          ;; completion-table-in-turn, we could return boundaries and
--          ;; let some subsequent table return a list of completions.
--          ;; FIXME: Maybe it should rather be fixed in
--          ;; completion-table-in-turn instead, but it's difficult to
--          ;; do it efficiently there.
++        ;; Only return boundaries if there's something to complete,
++        ;; since otherwise when we're used in
++        ;; completion-table-in-turn, we could return boundaries and
++        ;; let some subsequent table return a list of completions.
++        ;; FIXME: Maybe it should rather be fixed in
++        ;; completion-table-in-turn instead, but it's difficult to
++        ;; do it efficiently there.
          (when (try-completion (substring string beg) table nil)
--            ;; Compute the boundaries of the subfield to which this
--            ;; completion applies.
--            (let ((suffix (cdr action)))
--              (list* 'boundaries
--                     (or (match-beginning 2) (match-beginning 1))
--                     (when (string-match "[^[:alnum:]_]" suffix)
++          ;; Compute the boundaries of the subfield to which this
++          ;; completion applies.
++          (let ((suffix (cdr action)))
++            (list* 'boundaries
++                   (or (match-beginning 2) (match-beginning 1))
++                   (when (string-match "[^[:alnum:]_]" suffix)
                       (match-beginning 0))))))
         (t
          (if (eq (aref string (1- beg)) ?{)
  (defun completion-file-name-table (string pred action)
    "Completion table for file names."
    (ignore-errors
--  (cond
--   ((eq (car-safe action) 'boundaries)
--    (let ((start (length (file-name-directory string)))
--          (end (string-match-p "/" (cdr action))))
--      (list* 'boundaries
--             ;; if `string' is "C:" in w32, (file-name-directory string)
--             ;; returns "C:/", so `start' is 3 rather than 2.
--             ;; Not quite sure what is The Right Fix, but clipping it
--             ;; back to 2 will work for this particular case.  We'll
--             ;; see if we can come up with a better fix when we bump
--             ;; into more such problematic cases.
--             (min start (length string)) end)))
--
--   ((eq action 'lambda)
--    (if (zerop (length string))
--        nil    ;Not sure why it's here, but it probably doesn't harm.
--      (funcall (or pred 'file-exists-p) string)))
++    (cond
++     ((eq (car-safe action) 'boundaries)
++      (let ((start (length (file-name-directory string)))
++            (end (string-match-p "/" (cdr action))))
++        (list* 'boundaries
++               ;; if `string' is "C:" in w32, (file-name-directory string)
++               ;; returns "C:/", so `start' is 3 rather than 2.
++               ;; Not quite sure what is The Right Fix, but clipping it
++               ;; back to 2 will work for this particular case.  We'll
++               ;; see if we can come up with a better fix when we bump
++               ;; into more such problematic cases.
++               (min start (length string)) end)))
++
++     ((eq action 'lambda)
++      (if (zerop (length string))
++          nil    ;Not sure why it's here, but it probably doesn't harm.
++        (funcall (or pred 'file-exists-p) string)))
  
--   (t
++     (t
        (let* ((name (file-name-nondirectory string))
               (specdir (file-name-directory string))
               (realdir (or specdir default-directory)))
  
--      (cond
--       ((null action)
++        (cond
++         ((null action)
            (let ((comp (file-name-completion name realdir pred)))
              (if (stringp comp)
                  (concat specdir comp)
                comp)))
  
--       ((eq action t)
--        (let ((all (file-name-all-completions name realdir)))
++         ((eq action t)
++          (let ((all (file-name-all-completions name realdir)))
  
--          ;; Check the predicate, if necessary.
++            ;; Check the predicate, if necessary.
              (unless (memq pred '(nil file-exists-p))
--            (let ((comp ())
--                  (pred
++              (let ((comp ())
++                    (pred
                       (if (eq pred 'file-directory-p)
--                       ;; Brute-force speed up for directory checking:
--                       ;; Discard strings which don't end in a slash.
--                       (lambda (s)
--                         (let ((len (length s)))
--                           (and (> len 0) (eq (aref s (1- len)) ?/))))
--                     ;; Must do it the hard (and slow) way.
++                         ;; Brute-force speed up for directory checking:
++                         ;; Discard strings which don't end in a slash.
++                         (lambda (s)
++                           (let ((len (length s)))
++                             (and (> len 0) (eq (aref s (1- len)) ?/))))
++                       ;; Must do it the hard (and slow) way.
                         pred)))
                  (let ((default-directory (expand-file-name realdir)))
--                (dolist (tem all)
--                  (if (funcall pred tem) (push tem comp))))
--              (setq all (nreverse comp))))
++                  (dolist (tem all)
++                    (if (funcall pred tem) (push tem comp))))
++                (setq all (nreverse comp))))
  
              all))))))))
  
@@@ -1755,115 -1621,115 +1749,115 @@@ See `read-file-name' for the meaning o
                      (minibuffer--double-dollars dir)))
                   (initial (cons (minibuffer--double-dollars initial) 0)))))
  
--      (let ((completion-ignore-case read-file-name-completion-ignore-case)
--            (minibuffer-completing-file-name t)
--            (pred (or predicate 'file-exists-p))
--            (add-to-history nil))
--
--        (let* ((val
--                (if (or (not (next-read-file-uses-dialog-p))
--                      ;; Graphical file dialogs can't handle remote
--                      ;; files (Bug#99).
--                      (file-remote-p dir))
--                    ;; We used to pass `dir' to `read-file-name-internal' by
--                    ;; abusing the `predicate' argument.  It's better to
--                    ;; just use `default-directory', but in order to avoid
--                    ;; changing `default-directory' in the current buffer,
--                    ;; we don't let-bind it.
-                     (lexical-let ((dir (file-name-as-directory
-                                         (expand-file-name dir))))
 -                    (let ((dir (file-name-as-directory
 -                                (expand-file-name dir))))
--                      (minibuffer-with-setup-hook
--                          (lambda ()
--                          (setq default-directory dir)
--                          ;; When the first default in `minibuffer-default'
--                          ;; duplicates initial input `insdef',
--                          ;; reset `minibuffer-default' to nil.
--                          (when (equal (or (car-safe insdef) insdef)
--                                       (or (car-safe minibuffer-default)
--                                           minibuffer-default))
--                            (setq minibuffer-default
--                                  (cdr-safe minibuffer-default)))
--                          ;; On the first request on `M-n' fill
--                          ;; `minibuffer-default' with a list of defaults
--                          ;; relevant for file-name reading.
--                          (set (make-local-variable 'minibuffer-default-add-function)
--                               (lambda ()
--                                 (with-current-buffer
--                                     (window-buffer (minibuffer-selected-window))
++    (let ((completion-ignore-case read-file-name-completion-ignore-case)
++          (minibuffer-completing-file-name t)
++          (pred (or predicate 'file-exists-p))
++          (add-to-history nil))
++
++      (let* ((val
++              (if (or (not (next-read-file-uses-dialog-p))
++                      ;; Graphical file dialogs can't handle remote
++                      ;; files (Bug#99).
++                      (file-remote-p dir))
++                  ;; We used to pass `dir' to `read-file-name-internal' by
++                  ;; abusing the `predicate' argument.  It's better to
++                  ;; just use `default-directory', but in order to avoid
++                  ;; changing `default-directory' in the current buffer,
++                  ;; we don't let-bind it.
++                  (let ((dir (file-name-as-directory
++                              (expand-file-name dir))))
++                    (minibuffer-with-setup-hook
++                        (lambda ()
++                          (setq default-directory dir)
++                          ;; When the first default in `minibuffer-default'
++                          ;; duplicates initial input `insdef',
++                          ;; reset `minibuffer-default' to nil.
++                          (when (equal (or (car-safe insdef) insdef)
++                                       (or (car-safe minibuffer-default)
++                                           minibuffer-default))
++                            (setq minibuffer-default
++                                  (cdr-safe minibuffer-default)))
++                          ;; On the first request on `M-n' fill
++                          ;; `minibuffer-default' with a list of defaults
++                          ;; relevant for file-name reading.
++                          (set (make-local-variable 'minibuffer-default-add-function)
++                               (lambda ()
++                                 (with-current-buffer
++                                     (window-buffer (minibuffer-selected-window))
                                   (read-file-name--defaults dir initial)))))
--                        (completing-read prompt 'read-file-name-internal
--                                         pred mustmatch insdef
--                                         'file-name-history default-filename)))
--                  ;; If DEFAULT-FILENAME not supplied and DIR contains
--                  ;; a file name, split it.
--                  (let ((file (file-name-nondirectory dir))
--                      ;; When using a dialog, revert to nil and non-nil
--                      ;; interpretation of mustmatch. confirm options
--                      ;; need to be interpreted as nil, otherwise
--                      ;; it is impossible to create new files using
--                      ;; dialogs with the default settings.
--                      (dialog-mustmatch
--                         (not (memq mustmatch
--                                    '(nil confirm confirm-after-completion)))))
--                    (when (and (not default-filename)
--                             (not (zerop (length file))))
--                      (setq default-filename file)
--                      (setq dir (file-name-directory dir)))
--                    (when default-filename
--                    (setq default-filename
--                          (expand-file-name (if (consp default-filename)
--                                                (car default-filename)
--                                              default-filename)
--                                            dir)))
--                    (setq add-to-history t)
--                    (x-file-dialog prompt dir default-filename
--                                 dialog-mustmatch
--                                   (eq predicate 'file-directory-p)))))
--
--               (replace-in-history (eq (car-safe file-name-history) val)))
--          ;; If completing-read returned the inserted default string itself
--          ;; (rather than a new string with the same contents),
--          ;; it has to mean that the user typed RET with the minibuffer empty.
--          ;; In that case, we really want to return ""
--          ;; so that commands such as set-visited-file-name can distinguish.
--        (when (consp default-filename)
--          (setq default-filename (car default-filename)))
--          (when (eq val default-filename)
--            ;; In this case, completing-read has not added an element
--            ;; to the history.  Maybe we should.
--            (if (not replace-in-history)
--                (setq add-to-history t))
--            (setq val ""))
--          (unless val (error "No file name specified"))
--
--          (if (and default-filename
--                   (string-equal val (if (consp insdef) (car insdef) insdef)))
--              (setq val default-filename))
--          (setq val (substitute-in-file-name val))
--
--          (if replace-in-history
--              ;; Replace what Fcompleting_read added to the history
--              ;; with what we will actually return.  As an exception,
--              ;; if that's the same as the second item in
--              ;; file-name-history, it's really a repeat (Bug#4657).
++                      (completing-read prompt 'read-file-name-internal
++                                       pred mustmatch insdef
++                                       'file-name-history default-filename)))
++                ;; If DEFAULT-FILENAME not supplied and DIR contains
++                ;; a file name, split it.
++                (let ((file (file-name-nondirectory dir))
++                      ;; When using a dialog, revert to nil and non-nil
++                      ;; interpretation of mustmatch. confirm options
++                      ;; need to be interpreted as nil, otherwise
++                      ;; it is impossible to create new files using
++                      ;; dialogs with the default settings.
++                      (dialog-mustmatch
++                       (not (memq mustmatch
++                                  '(nil confirm confirm-after-completion)))))
++                  (when (and (not default-filename)
++                             (not (zerop (length file))))
++                    (setq default-filename file)
++                    (setq dir (file-name-directory dir)))
++                  (when default-filename
++                    (setq default-filename
++                          (expand-file-name (if (consp default-filename)
++                                                (car default-filename)
++                                              default-filename)
++                                            dir)))
++                  (setq add-to-history t)
++                  (x-file-dialog prompt dir default-filename
++                                 dialog-mustmatch
++                                 (eq predicate 'file-directory-p)))))
++
++             (replace-in-history (eq (car-safe file-name-history) val)))
++        ;; If completing-read returned the inserted default string itself
++        ;; (rather than a new string with the same contents),
++        ;; it has to mean that the user typed RET with the minibuffer empty.
++        ;; In that case, we really want to return ""
++        ;; so that commands such as set-visited-file-name can distinguish.
++        (when (consp default-filename)
++          (setq default-filename (car default-filename)))
++        (when (eq val default-filename)
++          ;; In this case, completing-read has not added an element
++          ;; to the history.  Maybe we should.
++          (if (not replace-in-history)
++              (setq add-to-history t))
++          (setq val ""))
++        (unless val (error "No file name specified"))
++
++        (if (and default-filename
++                 (string-equal val (if (consp insdef) (car insdef) insdef)))
++            (setq val default-filename))
++        (setq val (substitute-in-file-name val))
++
++        (if replace-in-history
++            ;; Replace what Fcompleting_read added to the history
++            ;; with what we will actually return.  As an exception,
++            ;; if that's the same as the second item in
++            ;; file-name-history, it's really a repeat (Bug#4657).
++            (let ((val1 (minibuffer--double-dollars val)))
++              (if history-delete-duplicates
++                  (setcdr file-name-history
++                          (delete val1 (cdr file-name-history))))
++              (if (string= val1 (cadr file-name-history))
++                  (pop file-name-history)
++                (setcar file-name-history val1)))
++          (if add-to-history
++              ;; Add the value to the history--but not if it matches
++              ;; the last value already there.
                (let ((val1 (minibuffer--double-dollars val)))
--                (if history-delete-duplicates
--                    (setcdr file-name-history
--                            (delete val1 (cdr file-name-history))))
--              (if (string= val1 (cadr file-name-history))
--                  (pop file-name-history)
--                (setcar file-name-history val1)))
--            (if add-to-history
--                ;; Add the value to the history--but not if it matches
--                ;; the last value already there.
--                (let ((val1 (minibuffer--double-dollars val)))
--                  (unless (and (consp file-name-history)
--                               (equal (car file-name-history) val1))
--                    (setq file-name-history
--                          (cons val1
--                                (if history-delete-duplicates
--                                    (delete val1 file-name-history)
--                                  file-name-history)))))))
++                (unless (and (consp file-name-history)
++                             (equal (car file-name-history) val1))
++                  (setq file-name-history
++                        (cons val1
++                              (if history-delete-duplicates
++                                  (delete val1 file-name-history)
++                                file-name-history)))))))
        val))))
  
  (defun internal-complete-buffer-except (&optional buffer)
@@@ -2323,9 -2185,9 +2313,9 @@@ filter out additional entries (because 
  
  (defun completion-pcm--pattern->string (pattern)
    (mapconcat (lambda (x) (cond
--                     ((stringp x) x)
--                     ((eq x 'star) "*")
--                     (t "")))           ;any, point, prefix.
++                          ((stringp x) x)
++                          ((eq x 'star) "*")
++                          (t "")))           ;any, point, prefix.
               pattern
               ""))
  
  ;; second alternative.
  (defun completion-pcm--filename-try-filter (all)
    "Filter to adjust `all' file completion to the behavior of `try'."
--    (when all
++  (when all
      (let ((try ())
            (re (concat "\\(?:\\`\\.\\.?/\\|"
                        (regexp-opt completion-ignored-extensions)
           (equal (completion-pcm--pattern->string pattern) (car all)))
      t)
     (t
--      (let* ((mergedpat (completion-pcm--merge-completions all pattern))
--             ;; `mergedpat' is in reverse order.  Place new point (by
--           ;; order of preference) either at the old point, or at
--           ;; the last place where there's something to choose, or
--           ;; at the very end.
--             (pointpat (or (memq 'point mergedpat)
--                           (memq 'any   mergedpat)
--                           (memq 'star  mergedpat)
--                           ;; Not `prefix'.
--                         mergedpat))
--             ;; New pos from the start.
--             (newpos (length (completion-pcm--pattern->string pointpat)))
--           ;; Do it afterwards because it changes `pointpat' by sideeffect.
--             (merged (completion-pcm--pattern->string (nreverse mergedpat))))
++    (let* ((mergedpat (completion-pcm--merge-completions all pattern))
++           ;; `mergedpat' is in reverse order.  Place new point (by
++           ;; order of preference) either at the old point, or at
++           ;; the last place where there's something to choose, or
++           ;; at the very end.
++           (pointpat (or (memq 'point mergedpat)
++                         (memq 'any   mergedpat)
++                         (memq 'star  mergedpat)
++                         ;; Not `prefix'.
++                         mergedpat))
++           ;; New pos from the start.
++           (newpos (length (completion-pcm--pattern->string pointpat)))
++           ;; Do it afterwards because it changes `pointpat' by sideeffect.
++           (merged (completion-pcm--pattern->string (nreverse mergedpat))))
  
        (setq suffix (completion--merge-suffix merged newpos suffix))
--        (cons (concat prefix merged suffix) (+ newpos (length prefix)))))))
++      (cons (concat prefix merged suffix) (+ newpos (length prefix)))))))
  
  (defun completion-pcm-try-completion (string table pred point)
    (destructuring-bind (pattern all prefix suffix)
diff --cc src/ChangeLog
@@@ -1,42 -1,3 +1,100 @@@
++2011-04-01  Stefan Monnier  <monnier@iro.umontreal.ca>
++
++      Add lexical binding.
++
++      * window.c (Ftemp_output_buffer_show): New fun.
++      (Fsave_window_excursion):
++      * print.c (Fwith_output_to_temp_buffer): Move to subr.el.
++
++      * lread.c (lisp_file_lexically_bound_p): New function.
++      (Fload): Bind Qlexical_binding.
++      (readevalloop): Remove `evalfun' arg.
++      Bind Qinternal_interpreter_environment.
++      (Feval_buffer): Bind Qlexical_binding.
++      (defvar_int, defvar_bool, defvar_lisp_nopro, defvar_kboard):
++      Mark as dynamic.
++      (syms_of_lread): Declare `lexical-binding'.
++
++      * lisp.h (struct Lisp_Symbol): New field `declared_special'.
++
++      * keyboard.c (eval_dyn): New fun.
++      (menu_item_eval_property): Use it.
++
++      * image.c (parse_image_spec): Use Ffunctionp.
++
++      * fns.c (concat, mapcar1): Accept byte-code-functions.
++
++      * eval.c (Fsetq): Handle lexical vars.
++      (Fdefun, Fdefmacro, Ffunction): Make closures when needed.
++      (Fdefconst, Fdefvaralias, Fdefvar): Mark as dynamic.
++      (FletX, Flet): Obey lexical binding.
++      (Fcommandp): Handle closures.
++      (Feval): New `lexical' arg.
++      (eval_sub): New function extracted from Feval.  Use it almost
++      everywhere where Feval was used.  Look up vars in lexical env.
++      Handle closures.
++      (Ffunctionp): Move from subr.el.
++      (Ffuncall): Handle closures.
++      (apply_lambda): Remove `eval_flags'.
++      (funcall_lambda): Handle closures and new byte-code-functions.
++      (Fspecial_variable_p): New function.
++      (syms_of_eval): Initialize the Vinternal_interpreter_environment var,
++      but without exporting it to Lisp.
++
++      * doc.c (Fdocumentation, store_function_docstring):
++      * data.c (Finteractive_form): Handle closures.
++
++      * callint.c (Fcall_interactively): Preserve lexical-binding mode for
++      interactive spec.
++
++      * bytecode.c (Bstack_ref, Bstack_set, Bstack_set2, BdiscardN): New
++      byte-codes.
++      (exec_byte_code): New function extracted from Fbyte_code to handle new
++      calling convention for byte-code-functions.  Add new byte-codes.
++
++      * buffer.c (defvar_per_buffer): Set new `declared_special' field.
++
++      * alloc.c (Fmake_symbol): Init new `declared_special' field.
++
 +2011-03-31  Juanma Barranquero  <lekktu@gmail.com>
 +
 +      * xdisp.c (redisplay_internal): Fix prototype.
 +
 +2011-03-31  Eli Zaretskii  <eliz@gnu.org>
 +
 +      * xdisp.c (SCROLL_LIMIT): New macro.
 +      (try_scrolling): Use it when setting scroll_limit.  Limit
 +      scrolling to 100 screen lines.
 +      (redisplay_window): Even when falling back on "recentering",
 +      position point in the window according to scroll-conservatively,
 +      scroll-margin, and scroll-*-aggressively variables.  (Bug#6671)
 +
 +      (try_scrolling): When point is above the window, allow searching
 +      as far as scroll_max, or one screenful, to compute vertical
 +      distance from PT to the scroll margin position.  This prevents
 +      try_scrolling from unnecessarily failing when
 +      scroll-conservatively is set to a value slightly larger than the
 +      window height.  Clean up the case of PT below the margin at bottom
 +      of window: scroll_max can no longer be INT_MAX.  When aggressive
 +      scrolling is in use, don't let point enter the opposite scroll
 +      margin as result of the scroll.
 +      (syms_of_xdisp) <scroll-conservatively>: Document the
 +      threshold of 100 lines for never-recentering scrolling.
 +
 +2011-03-31  Juanma Barranquero  <lekktu@gmail.com>
 +
 +      * dispextern.h (move_it_by_lines):
 +      * xdisp.c (move_it_by_lines): Remove parameter `need_y_p', unused
 +      since 2000-12-29T14:24:09Z!gerd@gnu.org.  All callers changed.
 +      (message_log_check_duplicate): Remove parameters `prev_bol' and
 +      `this_bol', unused since 1998-01-01T02:27:27Z!rms@gnu.org.  All callers changed.
 +      (redisplay_internal): Remove parameter `preserve_echo_area',
 +      unused since 1999-07-21T21:43:52Z!gerd@gnu.org.  All callers changed.
 +
 +      * indent.c (Fvertical_motion):
 +      * window.c (window_scroll_pixel_based, Frecenter):
 +      Don't pass `need_y_p' to `move_it_by_lines'.
 +
  2011-03-30  Stefan Monnier  <monnier@iro.umontreal.ca>
  
        * eval.c (struct backtrace): Don't cheat with negative numbers, but do
diff --cc src/eval.c
@@@ -3297,6 -3485,19 +3485,17 @@@ unbind_to (int count, Lisp_Object value
    UNGCPRO;
    return value;
  }
 -\f
 -
+ DEFUN ("special-variable-p", Fspecial_variable_p, Sspecial_variable_p, 1, 1, 0,
+        doc: /* Return non-nil if SYMBOL's global binding has been declared special.
+ A special variable is one that will be bound dynamically, even in a
+ context where binding is lexical by default.  */)
+   (Lisp_Object symbol)
+ {
+    CHECK_SYMBOL (symbol);
+    return XSYMBOL (symbol)->declared_special ? Qt : Qnil;
+ }
  \f
  DEFUN ("backtrace-debug", Fbacktrace_debug, Sbacktrace_debug, 2, 2, 0,
         doc: /* Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
diff --cc src/window.c
Simple merge