]> code.delx.au - gnu-emacs/commitdiff
xdisp fix
authorJoakim Verona <joakim@verona.se>
Mon, 8 Apr 2013 22:21:04 +0000 (00:21 +0200)
committerJoakim Verona <joakim@verona.se>
Mon, 8 Apr 2013 22:21:04 +0000 (00:21 +0200)
1  2 
configure.ac
lisp/emacs-lisp/edebug.el
src/Makefile.in
src/dispextern.h
src/dispnew.c
src/keyboard.c
src/lisp.h
src/print.c
src/window.c
src/xdisp.c

diff --combined configure.ac
index 4a27099ab4ac8f7ae95e4657f30685fca1656d71,2d8c4c3473d65168f11ea95d510301d863f0d04b..b5dc05120df04da6eee59953ca4c477788c66324
@@@ -203,8 -203,6 +203,8 @@@ OPTION_DEFAULT_ON([acl],[don't compile 
  OPTION_DEFAULT_ON([gnutls],[don't use -lgnutls for SSL/TLS support])
  OPTION_DEFAULT_ON([inotify],[don't compile with inotify (file-watch) support])
  
 +OPTION_DEFAULT_OFF([xwidgets],[enable use of some gtk widgets it Emacs buffers])
 +
  ## For the times when you want to build Emacs but don't have
  ## a suitable makeinfo, and can live without the manuals.
  dnl http://lists.gnu.org/archive/html/emacs-devel/2008-04/msg01844.html
@@@ -2023,65 -2021,6 +2023,65 @@@ if test "${HAVE_GTK}" = "yes"; the
   term_header=gtkutil.h
  fi
  
 +
 +HAVE_XWIDGETS=no
 +HAVE_WEBKIT=no
 +HAVE_GOOCANVAS=no
 +HAVE_CLUTTER=no
 +HAVE_GIR=no
 +
 +if test "${with_xwidgets}" != "no"; then
 +   echo "xwidgets enabled, checking webkit, and others"
 +   HAVE_XWIDGETS=yes
 +   AC_DEFINE(HAVE_XWIDGETS, 1, [Define to 1 if you have xwidgets support.])        
 +#xwidgets
 +#TODO
 +# - enable only if gtk/gtk3 enabled
 +# - webkit, goocanvas, clutter
 +# - only webkit_osr is good so remove plain webkit laterish
 +
 +#webkit version for gtk3. 
 +  WEBKIT_REQUIRED=1.4.0
 +  WEBKIT_MODULES="webkitgtk-3.0 >= $WEBKIT_REQUIRED"
 +
 +  if test "${with_gtk3}" = "yes"; then
 +    PKG_CHECK_MODULES(WEBKIT, $WEBKIT_MODULES, HAVE_WEBKIT=yes, HAVE_WEBKIT=no)
 +    if test $HAVE_WEBKIT = yes; then
 +        AC_DEFINE(HAVE_WEBKIT_OSR, 1, [Define to 1 if you have webkit_osr support.])     
 +    fi
 +  fi
 +
 +  if test "${with_xwdemo}"  = "yes"; then
 +#clutter and goocanvas are just proof of concept so disable for now  
 +  CLUTTER_REQUIRED=1.0.0   
 +  CLUTTER_MODULES="clutter-gtk-1.0 >= $CLUTTER_REQUIRED"
 +
 +  PKG_CHECK_MODULES(CLUTTER, $CLUTTER_MODULES, HAVE_CLUTTER=yes, HAVE_CLUTTER=no)
 +  if test $HAVE_CLUTTER = yes;  then
 +     AC_DEFINE(HAVE_CLUTTER, 1, [Define to 1 if you have clutter support.])
 +  fi
 +
 +
 +  GOOCANVAS_REQUIRED=1.4.0
 +  GOOCANVAS_MODULES="goocanvasgtk-3.0 >= $GOOCANVAS_REQUIRED"
 +
 +  PKG_CHECK_MODULES(GOOCANVAS, $GOOCANVAS_MODULES, HAVE_GOOCANVAS=yes, HAVE_GOOCANVAS=no)
 +  if test $HAVE_GOOCANVAS = yes; then
 +     AC_DEFINE(HAVE_GOOCANVAS, 1, [Define to 1 if you have goocanvas support.])
 +  fi
 +  fi
 +
 +  GIR_REQUIRED=1.32.1
 +  GIR_MODULES="gobject-introspection-1.0 >= $GIR_REQUIRED"
 +  PKG_CHECK_MODULES(GIR, $GIR_MODULES, HAVE_GIR=yes, HAVE_GIR=no)
 +  if test $HAVE_GIR = yes; then
 +     AC_DEFINE(HAVE_GIR, 1, [Define to 1 if you have GIR support.])
 +  fi
 +
 +  
 +fi
 +
 +
  dnl D-Bus has been tested under GNU/Linux only.  Must be adapted for
  dnl other platforms.
  HAVE_DBUS=no
@@@ -4100,7 -4039,7 +4100,7 @@@ TOOLKIT_LIBW
  case "$USE_X_TOOLKIT" in
    MOTIF) TOOLKIT_LIBW="$MOTIF_LIBW" ;;
    LUCID) TOOLKIT_LIBW="$LUCID_LIBW" ;;
 -  none) test "x$HAVE_GTK" = "xyes" && TOOLKIT_LIBW="$GTK_LIBS" ;;
 +  none) test "x$HAVE_GTK" = "xyes" && TOOLKIT_LIBW="$GTK_LIBS -lXcomposite" ;;
  esac
  AC_SUBST(TOOLKIT_LIBW)
  
@@@ -4246,6 -4185,13 +4246,13 @@@ case "$opsys" i
    *) LD_SWITCH_SYSTEM_TEMACS= ;;
  esac
  
+ if test x$ac_enable_profiling != x ; then
+   case $opsys in
+     *freebsd | gnu-linux) ;;
+     *) LD_SWITCH_SYSTEM_TEMACS="$LD_SWITCH_SYSTEM_TEMACS -pg" ;;
+   esac
+ fi
  AC_SUBST(LD_SWITCH_SYSTEM_TEMACS)
  
  ## Common for all window systems
@@@ -4348,12 -4294,6 +4355,12 @@@ echo "  Does Emacs use -lotf
  echo "  Does Emacs use -lxft?                                   ${HAVE_XFT}"
  
  echo "  Does Emacs use toolkit scroll bars?                     ${USE_TOOLKIT_SCROLL_BARS}"
 +
 +echo "  Does Emacs support Xwidgets?                            ${HAVE_XWIDGETS}"
 +echo "       Does xwidgets support webkit(requires gtk3)?       ${HAVE_WEBKIT}"
 +echo "       Does xwidgets support gobject introspection?       ${HAVE_GIR}"
 +echo "       Does xwidgets support clutter(demo code)?          ${HAVE_CLUTTER}"
 +echo "       Does xwidgets support goocanvas(demo code)?        ${HAVE_GOOCANVAS}"
  echo
  
  if test -n "${EMACSDATA}"; then
index 41b02da82fe20b0e1d6128b5c076b9f5807558ce,867f079ce5f609459eb8094348cd9109fe1b9d0c..e91e0408481be8e01e5a7ad03093517dab037f5a
@@@ -1,4 -1,4 +1,4 @@@
 -;;; edebug.el --- a source-level debugger for Emacs Lisp  -*- lexical-binding: t -*-
 +;;; edebug.el --- a source-level debugger for Emacs Lisp
  
  ;; Copyright (C) 1988-1995, 1997, 1999-2013 Free Software Foundation,
  ;; Inc.
  ;;; Code:
  
  (require 'macroexp)
- ;;; Bug reporting
- (defalias 'edebug-submit-bug-report 'report-emacs-bug)
+ (eval-when-compile (require 'cl-lib))
+ (eval-when-compile (require 'pcase))
  
  ;;; Options
  
@@@ -238,7 -236,7 +236,7 @@@ If the result is non-nil, then break.  
  
  (defun get-edebug-spec (symbol)
    ;; Get the spec of symbol resolving all indirection.
 -  (let ((spec nil)
 +  (let ((edebug-form-spec nil)
        (indirect symbol))
      (while
          (progn
                 (setq indirect
                       (function-get indirect 'edebug-form-spec 'macro))))
        ;; (edebug-trace "indirection: %s" edebug-form-spec)
 -      (setq spec indirect))
 -    spec))
 +      (setq edebug-form-spec indirect))
 +    edebug-form-spec
 +    ))
  
  ;;;###autoload
  (defun edebug-basic-spec (spec)
@@@ -338,9 -335,7 +336,9 @@@ A lambda list keyword is a symbol that 
               (lambda (e1 e2)
                 (funcall function (car e1) (car e2))))))
  
 -;; Not used.
 +;;(def-edebug-spec edebug-save-restriction t)
 +
 +;; Not used.  If it is used, def-edebug-spec must be defined before use.
  '(defmacro edebug-save-restriction (&rest body)
    "Evaluate BODY while saving the current buffers restriction.
  BODY may change buffer outside of current restriction, unlike
@@@ -348,6 -343,7 +346,6 @@@ save-restriction.  BODY may change the 
  and the restriction will be restored to the original buffer,
  and the current buffer remains current.
  Return the result of the last expression in BODY."
 -  (declare (debug t))
    `(let ((edebug:s-r-beg (point-min-marker))
         (edebug:s-r-end (point-max-marker)))
       (unwind-protect
    ;; Select WINDOW if it is provided and still exists.  Otherwise,
    ;; if buffer is currently shown in several windows, choose one.
    ;; Otherwise, find a new window, possibly splitting one.
 -  ;; FIXME: We should probably just be using `pop-to-buffer'.
    (setq window
        (cond
         ((and (edebug-window-live-p window)
         ((eq (window-buffer (selected-window)) buffer)
          ;; Selected window already displays BUFFER.
          (selected-window))
 -       ((get-buffer-window buffer 0))
 +       ((edebug-get-buffer-window buffer))
         ((one-window-p 'nomini)
          ;; When there's one window only, split it.
          (split-window (minibuffer-selected-window)))
              window-info)
      (set-window-configuration window-info)))
  
 +(defalias 'edebug-get-buffer-window 'get-buffer-window)
 +(defalias 'edebug-sit-for 'sit-for)
 +(defalias 'edebug-input-pending-p 'input-pending-p)
 +
 +
  ;;; Redefine read and eval functions
  ;; read is redefined to maybe instrument forms.
  ;; eval-defun is redefined to check edebug-all-forms and edebug-all-defs.
  
  ;; Save the original read function
 -(defalias 'edebug-original-read
 -  (symbol-function (if (fboundp 'edebug-original-read)
 -                       'edebug-original-read 'read)))
 +(or (fboundp 'edebug-original-read)
 +    (defalias 'edebug-original-read  (symbol-function 'read)))
  
  (defun edebug-read (&optional stream)
    "Read one Lisp expression as text from STREAM, return as Lisp object.
@@@ -619,36 -612,29 +617,36 @@@ already is one.)
  ;; The internal data that is needed for edebugging is kept in the
  ;; buffer-local variable `edebug-form-data'.
  
 -(defvar-local edebug-form-data nil
 -  "A list of entries associating symbols with buffer regions.
 -Each entry is an `edebug--form-data' struct with fields:
 -SYMBOL, BEGIN-MARKER, and END-MARKER.  The markers
 -are at the beginning and end of an entry level form and SYMBOL is
 -a symbol that holds all edebug related information for the form on its
 -property list.
 -
 -In the future (haha!), the symbol will be irrelevant and edebug data will
 -be stored in the definitions themselves rather than in the property
 -list of a symbol.")
 -
 -(cl-defstruct (edebug--form-data
 -               ;; Some callers expect accessors to return nil when passed nil.
 -               (:type list)
 -               (:constructor edebug--make-form-data-entry (name begin end))
 -               (:predicate nil) (:constructor nil) (:copier nil))
 -  name begin end)
 +(make-variable-buffer-local 'edebug-form-data)
 +
 +(defvar edebug-form-data nil)
 +;; A list of entries associating symbols with buffer regions.
 +;; This is an automatic buffer local variable.  Each entry looks like:
 +;; @code{(@var{symbol} @var{begin-marker} @var{end-marker}).  The markers
 +;; are at the beginning and end of an entry level form and @var{symbol} is
 +;; a symbol that holds all edebug related information for the form on its
 +;; property list.
 +
 +;; In the future, the symbol will be irrelevant and edebug data will
 +;; be stored in the definitions themselves rather than in the property
 +;; list of a symbol.
 +
 +(defun edebug-make-form-data-entry (symbol begin end)
 +  (list symbol begin end))
 +
 +(defsubst edebug-form-data-name (entry)
 +  (car entry))
 +
 +(defsubst edebug-form-data-begin (entry)
 +  (nth 1 entry))
 +
 +(defsubst edebug-form-data-end (entry)
 +  (nth 2 entry))
  
  (defsubst edebug-set-form-data-entry (entry name begin end)
 -  (setf (edebug--form-data-name entry) name) ;; In case name is changed.
 -  (set-marker (edebug--form-data-begin entry) begin)
 -  (set-marker (edebug--form-data-end entry) end))
 +  (setcar entry name);; in case name is changed
 +  (set-marker (nth 1 entry) begin)
 +  (set-marker (nth 2 entry) end))
  
  (defun edebug-get-form-data-entry (pnt &optional end-point)
    ;; Find the edebug form data entry which is closest to PNT.
    ;; Return `nil' if none found.
    (let ((rest edebug-form-data)
        closest-entry
 -      (closest-dist 999999))  ;; Need maxint here.
 +      (closest-dist 999999))  ;; need maxint here
      (while (and rest (< 0 closest-dist))
        (let* ((entry (car rest))
 -           (begin (edebug--form-data-begin entry))
 +           (begin (edebug-form-data-begin entry))
             (dist (- pnt begin)))
        (setq rest (cdr rest))
        (if (and (<= 0 dist)
                 (< dist closest-dist)
                 (or (not end-point)
 -                   (= end-point (edebug--form-data-end entry)))
 -               (<= pnt (edebug--form-data-end entry)))
 +                   (= end-point (edebug-form-data-end entry)))
 +               (<= pnt (edebug-form-data-end entry)))
            (setq closest-dist dist
                  closest-entry entry))))
      closest-entry))
  ;; and find an entry given a symbol, which should be just assq.
  
  (defun edebug-form-data-symbol ()
 -  "Return the edebug data symbol of the form where point is in.
 -If point is not inside a edebuggable form, cause error."
 -  (or (edebug--form-data-name (edebug-get-form-data-entry (point)))
 +;; Return the edebug data symbol of the form where point is in.
 +;; If point is not inside a edebuggable form, cause error.
 +  (or (edebug-form-data-name (edebug-get-form-data-entry (point)))
        (error "Not inside instrumented form")))
  
  (defun edebug-make-top-form-data-entry (new-entry)
    ;; Make NEW-ENTRY the first element in the `edebug-form-data' list.
    (edebug-clear-form-data-entry new-entry)
 -  (push new-entry edebug-form-data))
 +  (setq edebug-form-data (cons new-entry edebug-form-data)))
  
  (defun edebug-clear-form-data-entry (entry)
 -  "If non-nil, clear ENTRY out of the form data.
 -Maybe clear the markers and delete the symbol's edebug property?"
 +;; If non-nil, clear ENTRY out of the form data.
 +;; Maybe clear the markers and delete the symbol's edebug property?
    (if entry
        (progn
        ;; Instead of this, we could just find all contained forms.
    ;; If it gets an error, make it nil.
    (let ((temp-hook edebug-setup-hook))
      (setq edebug-setup-hook nil)
 -    (if (functionp temp-hook) (funcall temp-hook)
 -      (mapc #'funcall temp-hook)))
 +    (run-hooks 'temp-hook))
  
    (let (result
        edebug-top-window-data
  (defvar edebug-offset-list) ; the list of offset positions.
  
  (defun edebug-inc-offset (offset)
 -  ;; Modifies edebug-offset-index and edebug-offset-list
 -  ;; accesses edebug-func-marc and buffer point.
 +  ;; modifies edebug-offset-index and edebug-offset-list
 +  ;; accesses edebug-func-marc and buffer point
    (prog1
        edebug-offset-index
      (setq edebug-offset-list (cons (- offset edebug-form-begin-marker)
    ;; given FORM.  Looks like:
    ;; (edebug-after (edebug-before BEFORE-INDEX) AFTER-INDEX FORM)
    ;; Also increment the offset index for subsequent use.
 -  `(edebug-after (edebug-before ,before-index) ,after-index ,form))
 +  (list 'edebug-after
 +      (list 'edebug-before before-index)
 +      after-index form))
  
  (defun edebug-make-after-form (form after-index)
    ;; Like edebug-make-before-and-after-form, but only after.
 -  `(edebug-after 0 ,after-index ,form))
 +  (list 'edebug-after 0 after-index form))
  
  
  (defun edebug-unwrap (sexp)
@@@ -1286,7 -1271,7 +1284,7 @@@ expressions; a `progn' form will be ret
         ;; Set this marker before parsing.
         (edebug-form-begin-marker
          (if form-data-entry
 -            (edebug--form-data-begin form-data-entry)
 +            (edebug-form-data-begin form-data-entry)
            ;; Buffer must be current-buffer for this to work:
            (set-marker (make-marker) form-begin))))
  
          ;; For definitions.
          ;; (edebug-containing-def-name edebug-def-name)
          ;; Get name from form-data, if any.
 -        (edebug-old-def-name (edebug--form-data-name form-data-entry))
 +        (edebug-old-def-name (edebug-form-data-name form-data-entry))
          edebug-def-name
          edebug-def-args
          edebug-def-interactive
        ;; In the latter case, pointers to the entry remain eq.
        (if (not form-data-entry)
          (setq form-data-entry
 -              (edebug--make-form-data-entry
 +              (edebug-make-form-data-entry
                 edebug-def-name
                 edebug-form-begin-marker
                 ;; Buffer must be current-buffer.
  ;; Otherwise it signals an error.  The place of the error is found
  ;; with the two before- and after-offset functions.
  
 -(defun edebug-no-match (cursor &rest args)
 +(defun edebug-no-match (cursor &rest edebug-args)
    ;; Throw a no-match, or signal an error immediately if gate is active.
    ;; Remember this point in case we need to report this error.
    (setq edebug-error-point (or edebug-error-point
                               (edebug-before-offset cursor))
 -      edebug-best-error (or edebug-best-error args))
 +      edebug-best-error (or edebug-best-error edebug-args))
    (if (and edebug-gate (not edebug-&optional))
        (progn
        (if edebug-error-point
            (goto-char edebug-error-point))
 -      (apply 'edebug-syntax-error args))
 -    (throw 'no-match args)))
 +      (apply 'edebug-syntax-error edebug-args))
 +    (funcall 'throw 'no-match edebug-args)))
  
  
  (defun edebug-match (cursor specs)
                 specs))))
  
  
 -(defun edebug-match-gate (_cursor)
 +(defun edebug-match-gate (cursor)
    ;; Simply set the gate to prevent backtracking at this level.
    (setq edebug-gate t)
    nil)
      nil))
  
  
 -(defun edebug-match-function (_cursor)
 +(defun edebug-match-function (cursor)
    (error "Use function-form instead of function in edebug spec"))
  
  (defun edebug-match-&define (cursor specs)
      (edebug-move-cursor cursor)
      (list name)))
  
 -(defun edebug-match-colon-name (_cursor spec)
 +(defun edebug-match-colon-name (cursor spec)
    ;; Set the edebug-def-name to the spec.
    (setq edebug-def-name
        (if edebug-def-name
           def-body))
  ;; FIXME? Isn't this missing the doc-string?  Cf defun.
  (def-edebug-spec defmacro
 -  ;; FIXME: Improve `declare' so we can Edebug gv-expander and
 -  ;; gv-setter declarations.
    (&define name lambda-list [&optional ("declare" &rest sexp)] def-body))
  
  (def-edebug-spec arglist lambda-list)  ;; deprecated - use lambda-list.
  ;; (def-edebug-spec anonymous-form ((&or ["lambda" lambda] ["macro" macro])))
  
  ;; Standard functions that take function-forms arguments.
 +(def-edebug-spec mapcar (function-form form))
 +(def-edebug-spec mapconcat (function-form form form))
 +(def-edebug-spec mapatoms (function-form &optional form))
 +(def-edebug-spec apply (function-form &rest form))
 +(def-edebug-spec funcall (function-form &rest form))
  
  ;; FIXME?  The manual uses this form (maybe that's just for illustration?):
  ;; (def-edebug-spec let
                     &or ("quote" edebug-\`) def-form))
  
  ;; New byte compiler.
 +(def-edebug-spec defsubst defun)
 +(def-edebug-spec dont-compile t)
 +(def-edebug-spec eval-when-compile t)
 +(def-edebug-spec eval-and-compile t)
  
  (def-edebug-spec save-selected-window t)
  (def-edebug-spec save-current-buffer t)
 +(def-edebug-spec delay-mode-hooks t)
 +(def-edebug-spec with-temp-file t)
 +(def-edebug-spec with-temp-message t)
 +(def-edebug-spec with-syntax-table t)
 +(def-edebug-spec push (form sexp))
 +(def-edebug-spec pop (sexp))
 +
 +(def-edebug-spec 1value (form))
 +(def-edebug-spec noreturn (form))
 +
  
  ;; Anything else?
  
 +
 +;; Some miscellaneous specs for macros in public packages.
 +;; Send me yours.
 +
 +;; advice.el by Hans Chalupsky (hans@cs.buffalo.edu)
 +
 +(def-edebug-spec ad-dolist ((symbolp form &optional form) body))
 +(def-edebug-spec defadvice
 +  (&define name   ;; thing being advised.
 +         (name  ;; class is [&or "before" "around" "after"
 +                ;;               "activation" "deactivation"]
 +          name  ;; name of advice
 +          &rest sexp  ;; optional position and flags
 +          )
 +         [&optional stringp]
 +         [&optional ("interactive" interactive)]
 +         def-body))
 +
 +(def-edebug-spec easy-menu-define (symbolp body))
 +
 +(def-edebug-spec with-custom-print body)
 +
 +
  ;;; The debugger itself
  
  (defvar edebug-active nil)  ;; Non-nil when edebug is active
  
- ;;; add minor-mode-alist entry
- (or (assq 'edebug-active minor-mode-alist)
-     (setq minor-mode-alist (cons (list 'edebug-active " *Debugging*")
-                                minor-mode-alist)))
  (defvar edebug-stack nil)
  ;; Stack of active functions evaluated via edebug.
  ;; Should be nil at the top level.
  
  ;; Dynamically bound variables, declared globally but left unbound.
  (defvar edebug-function) ; the function being executed. change name!!
 +(defvar edebug-args) ; the arguments of the function
  (defvar edebug-data) ; the edebug data for the function
 +(defvar edebug-value) ; the result of the expression
 +(defvar edebug-after-index)
  (defvar edebug-def-mark) ; the mark for the definition
  (defvar edebug-freq-count) ; the count of expression visits.
  (defvar edebug-coverage) ; the coverage results of each expression of function.
  (defvar edebug-outside-debug-on-error) ; the value of debug-on-error outside
  (defvar edebug-outside-debug-on-quit) ; the value of debug-on-quit outside
  
 +(defvar edebug-outside-overriding-local-map)
 +(defvar edebug-outside-overriding-terminal-local-map)
  
  (defvar edebug-outside-pre-command-hook)
  (defvar edebug-outside-post-command-hook)
  
  ;;; Handling signals
  
 -(defun edebug-signal (signal-name signal-data)
 +(defun edebug-signal (edebug-signal-name edebug-signal-data)
    "Signal an error.  Args are SIGNAL-NAME, and associated DATA.
  A signal name is a symbol with an `error-conditions' property
  that is a list of condition names.
@@@ -2203,19 -2138,18 +2196,19 @@@ See `condition-case'
  This is the Edebug replacement for the standard `signal'.  It should
  only be active while Edebug is.  It checks `debug-on-error' to see
  whether it should call the debugger.  When execution is resumed, the
 -error is signaled again."
 -  (if (and (listp debug-on-error) (memq signal-name debug-on-error))
 -      (edebug 'error (cons signal-name signal-data)))
 +error is signaled again.
 +\n(fn SIGNAL-NAME DATA)"
 +  (if (and (listp debug-on-error) (memq edebug-signal-name debug-on-error))
 +      (edebug 'error (cons edebug-signal-name edebug-signal-data)))
    ;; If we reach here without another non-local exit, then send signal again.
    ;; i.e. the signal is not continuable, yet.
    ;; Avoid infinite recursion.
    (let ((signal-hook-function nil))
 -    (signal signal-name signal-data)))
 +    (signal edebug-signal-name edebug-signal-data)))
  
  ;;; Entering Edebug
  
 -(defun edebug-enter (function args body)
 +(defun edebug-enter (edebug-function edebug-args edebug-body)
    ;; Entering FUNC.  The arguments are ARGS, and the body is BODY.
    ;; Setup edebug variables and evaluate BODY.  This function is called
    ;; when a function evaluated with edebug-eval-top-level-form is entered.
    ;; Is this the first time we are entering edebug since
    ;; lower-level recursive-edit command?
    ;; More precisely, this tests whether Edebug is currently active.
 -  (let ((edebug-function function))
 -    (if (not edebug-entered)
 -        (let ((edebug-entered t)
 -              ;; Binding max-lisp-eval-depth here is OK,
 -              ;; but not inside an unwind-protect.
 -              ;; Doing it here also keeps it from growing too large.
 -              (max-lisp-eval-depth (+ 100 max-lisp-eval-depth)) ; too much??
 -              (max-specpdl-size (+ 200 max-specpdl-size))
 -
 -              (debugger edebug-debugger) ; only while edebug is active.
 -              (edebug-outside-debug-on-error debug-on-error)
 -              (edebug-outside-debug-on-quit debug-on-quit)
 -              ;; Binding these may not be the right thing to do.
 -              ;; We want to allow the global values to be changed.
 -              (debug-on-error (or debug-on-error edebug-on-error))
 -              (debug-on-quit edebug-on-quit)
 -
 -              ;; Lexical bindings must be uncompiled for this to work.
 -              (cl-lexical-debug t))
 -          (unwind-protect
 -              (let ((signal-hook-function 'edebug-signal))
 -                (setq edebug-execution-mode (or edebug-next-execution-mode
 -                                                edebug-initial-mode
 -                                                edebug-execution-mode)
 -                      edebug-next-execution-mode nil)
 -                (edebug-enter function args body))))
 -
 -      (let* ((edebug-data (get function 'edebug))
 -             (edebug-def-mark (car edebug-data)) ; mark at def start
 -             (edebug-freq-count (get function 'edebug-freq-count))
 -             (edebug-coverage (get function 'edebug-coverage))
 -             (edebug-buffer (marker-buffer edebug-def-mark))
 -
 -             (edebug-stack (cons function edebug-stack))
 -             (edebug-offset-indices (cons 0 edebug-offset-indices))
 -             )
 -        (if (get function 'edebug-on-entry)
 -            (progn
 -              (setq edebug-execution-mode 'step)
 -              (if (eq (get function 'edebug-on-entry) 'temp)
 -                  (put function 'edebug-on-entry nil))))
 -        (if edebug-trace
 -            (edebug--enter-trace function args body)
 -          (funcall body))
 -        ))))
 +  (if (not edebug-entered)
 +      (let ((edebug-entered t)
 +          ;; Binding max-lisp-eval-depth here is OK,
 +          ;; but not inside an unwind-protect.
 +          ;; Doing it here also keeps it from growing too large.
 +          (max-lisp-eval-depth (+ 100 max-lisp-eval-depth)) ; too much??
 +          (max-specpdl-size (+ 200 max-specpdl-size))
 +
 +          (debugger edebug-debugger)  ; only while edebug is active.
 +          (edebug-outside-debug-on-error debug-on-error)
 +          (edebug-outside-debug-on-quit debug-on-quit)
 +          ;; Binding these may not be the right thing to do.
 +          ;; We want to allow the global values to be changed.
 +          (debug-on-error (or debug-on-error edebug-on-error))
 +          (debug-on-quit edebug-on-quit)
 +
 +          ;; Lexical bindings must be uncompiled for this to work.
 +          (cl-lexical-debug t))
 +      (unwind-protect
 +          (let ((signal-hook-function 'edebug-signal))
 +            (setq edebug-execution-mode (or edebug-next-execution-mode
 +                                            edebug-initial-mode
 +                                            edebug-execution-mode)
 +                  edebug-next-execution-mode nil)
 +            (edebug-enter edebug-function edebug-args edebug-body))))
 +
 +    (let* ((edebug-data (get edebug-function 'edebug))
 +         (edebug-def-mark (car edebug-data)) ; mark at def start
 +         (edebug-freq-count (get edebug-function 'edebug-freq-count))
 +         (edebug-coverage (get edebug-function 'edebug-coverage))
 +         (edebug-buffer (marker-buffer edebug-def-mark))
 +
 +         (edebug-stack (cons edebug-function edebug-stack))
 +         (edebug-offset-indices (cons 0 edebug-offset-indices))
 +         )
 +      (if (get edebug-function 'edebug-on-entry)
 +        (progn
 +          (setq edebug-execution-mode 'step)
 +          (if (eq (get edebug-function 'edebug-on-entry) 'temp)
 +              (put edebug-function 'edebug-on-entry nil))))
 +      (if edebug-trace
 +        (edebug-enter-trace edebug-body)
 +      (funcall edebug-body))
 +      )))
  
  (defun edebug-var-status (var)
    "Return a cons cell describing the status of VAR's current binding.
@@@ -2294,14 -2229,14 +2287,14 @@@ STATUS should be a list returned by `ed
          (t
           (set var value)))))
  
 -(defun edebug--enter-trace (function args body)
 +(defun edebug-enter-trace (edebug-body)
    (let ((edebug-stack-depth (1+ edebug-stack-depth))
        edebug-result)
      (edebug-print-trace-before
 -     (format "%s args: %s" function args))
 -    (prog1 (setq edebug-result (funcall body))
 +     (format "%s args: %s" edebug-function edebug-args))
 +    (prog1 (setq edebug-result (funcall edebug-body))
        (edebug-print-trace-after
 -       (format "%s result: %s" function edebug-result)))))
 +       (format "%s result: %s" edebug-function edebug-result)))))
  
  (def-edebug-spec edebug-tracing (form body))
  
@@@ -2329,49 -2264,49 +2322,49 @@@ MSG is printed after `::::} '.
  
  
  
 -(defun edebug-slow-before (before-index)
 +(defun edebug-slow-before (edebug-before-index)
    (unless edebug-active
      ;; Debug current function given BEFORE position.
      ;; Called from functions compiled with edebug-eval-top-level-form.
      ;; Return the before index.
 -    (setcar edebug-offset-indices before-index)
 +    (setcar edebug-offset-indices edebug-before-index)
  
      ;; Increment frequency count
 -    (aset edebug-freq-count before-index
 -        (1+ (aref edebug-freq-count before-index)))
 +    (aset edebug-freq-count edebug-before-index
 +        (1+ (aref edebug-freq-count edebug-before-index)))
  
      (if (or (not (memq edebug-execution-mode '(Go-nonstop next)))
 -          (input-pending-p))
 -      (edebug-debugger before-index 'before nil)))
 -  before-index)
 +          (edebug-input-pending-p))
 +      (edebug-debugger edebug-before-index 'before nil)))
 +  edebug-before-index)
  
 -(defun edebug-fast-before (_before-index)
 +(defun edebug-fast-before (edebug-before-index)
    ;; Do nothing.
    )
  
 -(defun edebug-slow-after (_before-index after-index value)
 +(defun edebug-slow-after (edebug-before-index edebug-after-index edebug-value)
    (if edebug-active
 -      value
 +      edebug-value
      ;; Debug current function given AFTER position and VALUE.
      ;; Called from functions compiled with edebug-eval-top-level-form.
      ;; Return VALUE.
 -    (setcar edebug-offset-indices after-index)
 +    (setcar edebug-offset-indices edebug-after-index)
  
      ;; Increment frequency count
 -    (aset edebug-freq-count after-index
 -        (1+ (aref edebug-freq-count after-index)))
 -    (if edebug-test-coverage (edebug--update-coverage after-index value))
 +    (aset edebug-freq-count edebug-after-index
 +        (1+ (aref edebug-freq-count edebug-after-index)))
 +    (if edebug-test-coverage (edebug-update-coverage))
  
      (if (and (eq edebug-execution-mode 'Go-nonstop)
 -           (not (input-pending-p)))
 +           (not (edebug-input-pending-p)))
        ;; Just return result.
 -      value
 -      (edebug-debugger after-index 'after value)
 +      edebug-value
 +      (edebug-debugger edebug-after-index 'after edebug-value)
        )))
  
 -(defun edebug-fast-after (_before-index _after-index value)
 +(defun edebug-fast-after (edebug-before-index edebug-after-index edebug-value)
    ;; Do nothing but return the value.
 -  value)
 +  edebug-value)
  
  (defun edebug-run-slow ()
    (defalias 'edebug-before 'edebug-slow-before)
  (edebug-run-slow)
  
  
 -(defun edebug--update-coverage (after-index value)
 -  (let ((old-result (aref edebug-coverage after-index)))
 +(defun edebug-update-coverage ()
 +  (let ((old-result (aref edebug-coverage edebug-after-index)))
      (cond
       ((eq 'ok-coverage old-result))
       ((eq 'unknown old-result)
 -      (aset edebug-coverage after-index value))
 +      (aset edebug-coverage edebug-after-index edebug-value))
       ;; Test if a different result.
 -     ((not (eq value old-result))
 -      (aset edebug-coverage after-index 'ok-coverage)))))
 +     ((not (eq edebug-value old-result))
 +      (aset edebug-coverage edebug-after-index 'ok-coverage)))))
  
  
  ;; Dynamically declared unbound variables.
 +(defvar edebug-arg-mode)  ; the mode, either before, after, or error
  (defvar edebug-breakpoints)
  (defvar edebug-break-data) ; break data for current function.
  (defvar edebug-break) ; whether a break occurred.
  (defvar edebug-global-break-result nil)
  
  
 -(defun edebug-debugger (offset-index arg-mode value)
 +(defun edebug-debugger (edebug-offset-index edebug-arg-mode edebug-value)
    (if inhibit-redisplay
        ;; Don't really try to enter edebug within an eval from redisplay.
 -      value
 +      edebug-value
      ;; Check breakpoints and pending input.
 -    ;; If edebug display should be updated, call edebug--display.
 -    ;; Return value.
 +    ;; If edebug display should be updated, call edebug-display.
 +    ;; Return edebug-value.
      (let* ( ;; This needs to be here since breakpoints may be changed.
           (edebug-breakpoints (car (cdr edebug-data))) ; list of breakpoints
 -         (edebug-break-data (assq offset-index edebug-breakpoints))
 +         (edebug-break-data (assq edebug-offset-index edebug-breakpoints))
           (edebug-break-condition (car (cdr edebug-break-data)))
           (edebug-global-break
            (if edebug-global-break-condition
                  (error nil))))
           (edebug-break))
  
 -      ;;(edebug-trace "exp: %s" value)
 +;;;    (edebug-trace "exp: %s" edebug-value)
        ;; Test whether we should break.
        (setq edebug-break
            (or edebug-global-break
        ;; or break, or input is pending,
        (if (or (not (memq edebug-execution-mode '(go continue Continue-fast)))
              edebug-break
 -            (input-pending-p))
 -        (edebug--display value offset-index arg-mode)) ; <---------- display
 +            (edebug-input-pending-p))
 +        (edebug-display))             ; <--------------- display
  
 -      value)))
 +      edebug-value
 +      )))
  
  
  ;; window-start now stored with each function.
  ;; Emacs 19 adds an arg to mark and mark-marker.
  (defalias 'edebug-mark-marker 'mark-marker)
  
 -(defvar edebug-outside-unread-command-events)
  
 -(defun edebug--display (value offset-index arg-mode)
 +(defun edebug-display ()
    (unless (marker-position edebug-def-mark)
      ;; The buffer holding the source has been killed.
      ;; Let's at least show a backtrace so the user can figure out
    ;; Setup windows for edebug, determine mode, maybe enter recursive-edit.
    ;; Uses local variables of edebug-enter, edebug-before, edebug-after
    ;; and edebug-debugger.
 -  (let ((edebug-active t)             ; For minor mode alist.
 +  (let ((edebug-active t)             ; for minor mode alist
        (edebug-with-timeout-suspend (with-timeout-suspend))
 -      edebug-stop                     ; Should we enter recursive-edit?
 +      edebug-stop                     ; should we enter recursive-edit
        (edebug-point (+ edebug-def-mark
 -                       (aref (nth 2 edebug-data) offset-index)))
 +                       (aref (nth 2 edebug-data) edebug-offset-index)))
        edebug-buffer-outside-point     ; current point in edebug-buffer
        ;; window displaying edebug-buffer
        (edebug-window-data (nth 3 edebug-data))
        (edebug-outside-point (point))
        (edebug-outside-mark (edebug-mark))
        (edebug-outside-unread-command-events unread-command-events)
 -      edebug-outside-windows          ; Window or screen configuration.
 +      edebug-outside-windows          ; window or screen configuration
        edebug-buffer-points
  
 -      edebug-eval-buffer             ; Declared here so we can kill it below.
 -      (eval-result-list (and edebug-eval-list
 -                               (edebug-eval-result-list)))
 +      edebug-eval-buffer              ; declared here so we can kill it below
 +      (edebug-eval-result-list (and edebug-eval-list
 +                                    (edebug-eval-result-list)))
        edebug-trace-window
        edebug-trace-window-start
  
        (let ((overlay-arrow-position overlay-arrow-position)
              (overlay-arrow-string overlay-arrow-string)
              (cursor-in-echo-area nil)
 -            (unread-command-events nil)
 +            (unread-command-events unread-command-events)
              ;; any others??
              )
            (setq-default cursor-in-non-selected-windows t)
              (let ((debug-on-error nil))
                (error "Buffer defining %s not found" edebug-function)))
  
 -        (if (eq 'after arg-mode)
 +        (if (eq 'after edebug-arg-mode)
              ;; Compute result string now before windows are modified.
 -            (edebug-compute-previous-result value))
 +            (edebug-compute-previous-result edebug-value))
  
          (if edebug-save-windows
              ;; Save windows now before we modify them.
          ;; Now display eval list, if any.
          ;; This is done after the pop to edebug-buffer
          ;; so that buffer-window correspondence is correct after quitting.
 -        (edebug-eval-display eval-result-list)
 +        (edebug-eval-display edebug-eval-result-list)
          ;; The evaluation list better not have deleted edebug-window-data.
          (select-window (car edebug-window-data))
          (set-buffer edebug-buffer)
          (setq edebug-buffer-outside-point (point))
          (goto-char edebug-point)
  
 -        (if (eq 'before arg-mode)
 +        (if (eq 'before edebug-arg-mode)
              ;; Check whether positions are up-to-date.
              ;; This assumes point is never before symbol.
              (if (not (memq (following-char) '(?\( ?\# ?\` )))
                  (edebug-adjust-window (cdr edebug-window-data)))
  
          ;; Test if there is input, not including keyboard macros.
 -        (if (input-pending-p)
 +        (if (edebug-input-pending-p)
              (progn
                (setq edebug-execution-mode 'step
                      edebug-stop t)
          (edebug-overlay-arrow)
  
          (cond
 -         ((eq 'error arg-mode)
 +         ((eq 'error edebug-arg-mode)
            ;; Display error message
            (setq edebug-execution-mode 'step)
            (edebug-overlay-arrow)
            (beep)
 -          (if (eq 'quit (car value))
 +          (if (eq 'quit (car edebug-value))
                (message "Quit")
 -            (edebug-report-error value)))
 +            (edebug-report-error edebug-value)))
           (edebug-break
            (cond
             (edebug-global-break
  
           (t (message "")))
  
 -        (if (eq 'after arg-mode)
 +        (setq unread-command-events nil)
 +        (if (eq 'after edebug-arg-mode)
              (progn
                ;; Display result of previous evaluation.
                (if (and edebug-break
                         (not (eq edebug-execution-mode 'Continue-fast)))
 -                    (sit-for edebug-sit-for-seconds)) ; Show message.
 +                    (edebug-sit-for edebug-sit-for-seconds)) ; Show message.
                (edebug-previous-result)))
  
          (cond
           (edebug-break
            (cond
             ((eq edebug-execution-mode 'continue)
 -              (sit-for edebug-sit-for-seconds))
 -           ((eq edebug-execution-mode 'Continue-fast) (sit-for 0))
 +              (edebug-sit-for edebug-sit-for-seconds))
 +           ((eq edebug-execution-mode 'Continue-fast) (edebug-sit-for 0))
             (t (setq edebug-stop t))))
           ;; not edebug-break
           ((eq edebug-execution-mode 'trace)
 -          (sit-for edebug-sit-for-seconds)) ; Force update and pause.
 +          (edebug-sit-for edebug-sit-for-seconds)) ; Force update and pause.
           ((eq edebug-execution-mode 'Trace-fast)
 -          (sit-for 0)))               ; Force update and continue.
 +          (edebug-sit-for 0)))                ; Force update and continue.
  
          (unwind-protect
              (if (or edebug-stop
                      (memq edebug-execution-mode '(step next))
 -                    (eq arg-mode 'error))
 +                    (eq edebug-arg-mode 'error))
                  (progn
                    ;; (setq edebug-execution-mode 'step)
                    ;; (edebug-overlay-arrow)   ; This doesn't always show up.
 -                  (edebug--recursive-edit arg-mode))) ; <----- Recursive edit
 +                  (edebug-recursive-edit))) ; <---------- Recursive edit
  
            ;; Reset the edebug-window-data to whatever it is now.
            (let ((window (if (eq (window-buffer) edebug-buffer)
                              (selected-window)
 -                          (get-buffer-window edebug-buffer))))
 +                          (edebug-get-buffer-window edebug-buffer))))
              ;; Remember window-start for edebug-buffer, if still displayed.
              (if window
                  (progn
            (goto-char edebug-buffer-outside-point))
          ;; ... nothing more.
          )
 -      ;; Could be an option to keep eval display up.
 -      (if edebug-eval-buffer (kill-buffer edebug-eval-buffer))
        (with-timeout-unsuspend edebug-with-timeout-suspend)
        ;; Reset global variables to outside values in case they were changed.
        (setq
  
  ;; Emacs 19.
  (defvar edebug-outside-last-command-event)
 +(defvar edebug-outside-unread-command-events)
  (defvar edebug-outside-last-input-event)
  (defvar edebug-outside-last-event-frame)
  (defvar edebug-outside-last-nonmenu-event)
  (defvar edebug-outside-track-mouse)
  
 -(defun edebug--recursive-edit (arg-mode)
 +(defun edebug-recursive-edit ()
    ;; Start up a recursive edit inside of edebug.
    ;; The current buffer is the edebug-buffer, which is put into edebug-mode.
    ;; Assume that none of the variables below are buffer-local.
-   (let ((edebug-buffer-read-only buffer-read-only)
-       ;; match-data must be done in the outside buffer
+   (let (;; match-data must be done in the outside buffer
        (edebug-outside-match-data
         (with-current-buffer edebug-outside-buffer ; in case match buffer different
           (match-data)))
        ;; during a recursive-edit
        edebug-inside-windows
  
-       (edebug-outside-map (current-local-map))
-         (edebug-outside-overriding-local-map overriding-local-map)
-         (edebug-outside-overriding-terminal-local-map
-          overriding-terminal-local-map)
          ;; Save the outside value of executing macro.  (here??)
          (edebug-outside-executing-macro executing-kbd-macro)
          (edebug-outside-pre-command-hook
              (last-nonmenu-event nil)
              (track-mouse nil)
  
 -              (standard-output t)
 -              (standard-input t)
 -
              ;; Don't keep reading from an executing kbd macro
                ;; within edebug unless edebug-continue-kbd-macro is
                ;; non-nil.  Again, local binding may not be best.
              )
  
          (if (and (eq edebug-execution-mode 'go)
 -                 (not (memq arg-mode '(after error))))
 +                 (not (memq edebug-arg-mode '(after error))))
              (message "Break"))
  
-         (setq buffer-read-only t)
          (setq signal-hook-function nil)
  
-         (edebug-mode)
+         (edebug-mode 1)
          (unwind-protect
              (recursive-edit)          ;  <<<<<<<<<< Recursive edit
  
            (setq signal-hook-function 'edebug-signal)
            (if edebug-backtrace-buffer
                (kill-buffer edebug-backtrace-buffer))
 +          ;; Could be an option to keep eval display up.
 +          (if edebug-eval-buffer (kill-buffer edebug-eval-buffer))
  
            ;; Remember selected-window after recursive-edit.
            ;;      (setq edebug-inside-window (selected-window))
                  (set-buffer edebug-buffer)
                  (if (memq edebug-execution-mode '(go Go-nonstop))
                      (edebug-overlay-arrow))
-                 (setq buffer-read-only edebug-buffer-read-only)
-                 (use-local-map edebug-outside-map)
-                 (remove-hook 'kill-buffer-hook 'edebug-kill-buffer t)
-                 )
+                   (edebug-mode -1))
              ;; gotta have a buffer to let its buffer local variables be set
              (get-buffer-create " bogus edebug buffer"))
            ));; inner let
  
  (defun edebug-adjust-window (old-start)
    ;; If pos is not visible, adjust current window to fit following context.
 -  ;; (message "window: %s old-start: %s window-start: %s pos: %s"
 -  ;;          (selected-window) old-start (window-start) (point)) (sit-for 5)
 +;;;  (message "window: %s old-start: %s window-start: %s pos: %s"
 +;;;      (selected-window) old-start (window-start) (point)) (sit-for 5)
    (if (not (pos-visible-in-window-p))
        (progn
        ;; First try old-start
            (set-window-start (selected-window) old-start))
        (if (not (pos-visible-in-window-p))
            (progn
 -      ;; (message "resetting window start") (sit-for 2)
 +;;    (message "resetting window start") (sit-for 2)
        (set-window-start
         (selected-window)
         (save-excursion
@@@ -3075,12 -2999,12 +3057,12 @@@ before returning.  The default is one s
               (current-buffer) (point)
               (if (marker-buffer (edebug-mark-marker))
                   (marker-position (edebug-mark-marker)) "<not set>"))
 -      (sit-for arg)
 +      (edebug-sit-for arg)
        (edebug-pop-to-buffer edebug-buffer (car edebug-window-data)))))
  
  
  ;; Joe Wells, here is a start at your idea of adding a buffer to the internal
 -;; display list.  Still need to use this list in edebug--display.
 +;; display list.  Still need to use this list in edebug-display.
  
  '(defvar edebug-display-buffer-list nil
    "List of buffers that edebug will display when it is active.")
@@@ -3402,7 -3326,7 +3384,7 @@@ function or macro is called, Edebug wil
           (save-excursion
             (down-list 1)
             (if (looking-at "\(")
 -               (edebug--form-data-name
 +               (edebug-form-data-name
                  (edebug-get-form-data-entry (point)))
               (edebug-original-read (current-buffer))))))
        (edebug-instrument-function func))))
@@@ -3515,11 -3439,10 +3497,11 @@@ edebug-mode.
  
  ;;; Evaluation of expressions
  
 +(def-edebug-spec edebug-outside-excursion t)
 +
  (defmacro edebug-outside-excursion (&rest body)
    "Evaluate an expression list in the outside context.
  Return the result of the last expression."
 -  (declare (debug t))
    `(save-excursion                    ; of current-buffer
       (if edebug-save-windows
         (progn
           (pre-command-hook (cdr edebug-outside-pre-command-hook))
           (post-command-hook (cdr edebug-outside-post-command-hook))
  
 -         ;; See edebug-display.
 +         ;; See edebug-display
           (overlay-arrow-position edebug-outside-o-a-p)
           (overlay-arrow-string edebug-outside-o-a-s)
           (cursor-in-echo-area edebug-outside-c-i-e-a)
  
  (defvar cl-debug-env)  ; defined in cl; non-nil when lexical env used.
  
 -(defun edebug-eval (expr)
 +(defun edebug-eval (edebug-expr)
    ;; Are there cl lexical variables active?
 -  (eval (if (and (bound-and-true-p cl-debug-env)
 -                 (fboundp 'cl-macroexpand-all))
 -            (cl-macroexpand-all expr cl-debug-env)
 -          expr)
 +  (eval (if (bound-and-true-p cl-debug-env)
 +            (cl-macroexpand-all edebug-expr cl-debug-env)
 +          edebug-expr)
          lexical-binding))
  
 -(defun edebug-safe-eval (expr)
 +(defun edebug-safe-eval (edebug-expr)
    ;; Evaluate EXPR safely.
    ;; If there is an error, a string is returned describing the error.
    (condition-case edebug-err
 -      (edebug-eval expr)
 +      (edebug-eval edebug-expr)
      (error (edebug-format "%s: %s"  ;; could
                          (get (car edebug-err) 'error-message)
                          (car (cdr edebug-err))))))
  ;;; Printing
  
  
 -(defun edebug-report-error (value)
 +(defun edebug-report-error (edebug-value)
    ;; Print an error message like command level does.
    ;; This also prints the error name if it has no error-message.
    (message "%s: %s"
 -         (or (get (car value) 'error-message)
 -             (format "peculiar error (%s)" (car value)))
 +         (or (get (car edebug-value) 'error-message)
 +             (format "peculiar error (%s)" (car edebug-value)))
           (mapconcat (function (lambda (edebug-arg)
                                  ;; continuing after an error may
                                  ;; complain about edebug-arg. why??
                                  (prin1-to-string edebug-arg)))
 -                    (cdr value) ", ")))
 +                    (cdr edebug-value) ", ")))
  
  (defvar print-readably) ; defined by lemacs
  ;; Alternatively, we could change the definition of
        (edebug-prin1-to-string value)
        (error "#Apparently circular structure#"))))
  
 -(defun edebug-compute-previous-result (previous-value)
 +(defun edebug-compute-previous-result (edebug-previous-value)
    (if edebug-unwrap-results
 -      (setq previous-value
 -          (edebug-unwrap* previous-value)))
 +      (setq edebug-previous-value
 +          (edebug-unwrap* edebug-previous-value)))
    (setq edebug-previous-result
        (concat "Result: "
 -              (edebug-safe-prin1-to-string previous-value)
 -              (eval-expression-print-format previous-value))))
 +              (edebug-safe-prin1-to-string edebug-previous-value)
 +              (eval-expression-print-format edebug-previous-value))))
  
  (defun edebug-previous-result ()
    "Print the previous result."
  (defalias 'edebug-format 'format)
  (defalias 'edebug-message 'message)
  
 -(defun edebug-eval-expression (expr)
 +(defun edebug-eval-expression (edebug-expr)
    "Evaluate an expression in the outside environment.
  If interactive, prompt for the expression.
  Print result in minibuffer."
                      'read-expression-history)))
    (princ
     (edebug-outside-excursion
 -    (setq values (cons (edebug-eval expr) values))
 +    (setq values (cons (edebug-eval edebug-expr) values))
      (concat (edebug-safe-prin1-to-string (car values))
              (eval-expression-print-format (car values))))))
  
@@@ -3697,14 -3621,14 +3679,14 @@@ Print value in minibuffer.
    "Evaluate sexp before point in outside environment; insert value.
  This prints the value into current buffer."
    (interactive)
 -  (let* ((form (edebug-last-sexp))
 -       (result-string
 +  (let* ((edebug-form (edebug-last-sexp))
 +       (edebug-result-string
          (edebug-outside-excursion
 -         (edebug-safe-prin1-to-string (edebug-safe-eval form))))
 +         (edebug-safe-prin1-to-string (edebug-safe-eval edebug-form))))
         (standard-output (current-buffer)))
      (princ "\n")
      ;; princ the string to get rid of quotes.
 -    (princ result-string)
 +    (princ edebug-result-string)
      (princ "\n")
      ))
  
@@@ -3838,7 -3762,9 +3820,9 @@@ be installed in `emacs-lisp-mode-map'."
    (interactive)
    (describe-function 'edebug-mode))
  
- (defun edebug-mode ()
+ (defvar edebug--mode-saved-vars nil)
+ (define-minor-mode edebug-mode
    "Mode for Emacs Lisp buffers while in Edebug.
  
  In addition to all Emacs Lisp commands (except those that modify the
@@@ -3872,20 -3798,32 +3856,32 @@@ Options
  `edebug-on-signal'
  `edebug-unwrap-results'
  `edebug-global-break-condition'"
+   :lighter " *Debugging*"
+   :keymap edebug-mode-map
    ;; If the user kills the buffer in which edebug is currently active,
    ;; exit to top level, because the edebug command loop can't usefully
    ;; continue running in such a case.
    ;;
-   ;; Append `edebug-kill-buffer' to the hook to avoid interfering with
-   ;; other entries that are ungarded against deleted buffer.
-   (add-hook 'kill-buffer-hook 'edebug-kill-buffer t t)
-   (use-local-map edebug-mode-map))
+   (if (not edebug-mode)
+       (progn
+         (while edebug--mode-saved-vars
+           (let ((setting (pop edebug--mode-saved-vars)))
+             (if (consp setting)
+                 (set (car setting) (cdr setting))
+               (kill-local-variable setting))))
+         (remove-hook 'kill-buffer-hook 'edebug-kill-buffer t))
+     (pcase-dolist (`(,var . ,val) '((buffer-read-only . t)))
+       (push
+        (if (local-variable-p var) (cons var (symbol-value var)) var)
+        edebug--mode-saved-vars)
+       (set (make-local-variable var) val))
+     ;; Append `edebug-kill-buffer' to the hook to avoid interfering with
+     ;; other entries that are unguarded against deleted buffer.
+     (add-hook 'kill-buffer-hook 'edebug-kill-buffer t t)))
  
  (defun edebug-kill-buffer ()
    "Used on `kill-buffer-hook' when Edebug is operating in a buffer of Lisp code."
-   (let (kill-buffer-hook)
-     (kill-buffer (current-buffer)))
-   (top-level))
+   (run-with-timer 0 nil #'top-level))
  
  ;;; edebug eval list mode
  
        (edebug-trace nil))
      (mapcar 'edebug-safe-eval edebug-eval-list)))
  
 -(defun edebug-eval-display-list (eval-result-list)
 +(defun edebug-eval-display-list (edebug-eval-result-list)
    ;; Assumes edebug-eval-buffer exists.
 -  (let ((standard-output edebug-eval-buffer)
 +  (let ((edebug-eval-list-temp edebug-eval-list)
 +      (standard-output edebug-eval-buffer)
        (edebug-comment-line
         (format ";%s\n" (make-string (- (window-width) 2) ?-))))
      (set-buffer edebug-eval-buffer)
      (erase-buffer)
 -    (dolist (exp edebug-eval-list)
 -      (prin1 exp) (terpri)
 -      (prin1 (pop eval-result-list)) (terpri)
 -      (princ edebug-comment-line))
 +    (while edebug-eval-list-temp
 +      (prin1 (car edebug-eval-list-temp)) (terpri)
 +      (prin1 (car edebug-eval-result-list)) (terpri)
 +      (princ edebug-comment-line)
 +      (setq edebug-eval-list-temp (cdr edebug-eval-list-temp))
 +      (setq edebug-eval-result-list (cdr edebug-eval-result-list)))
      (edebug-pop-to-buffer edebug-eval-buffer)
      ))
  
  (defun edebug-create-eval-buffer ()
 -  (unless (and edebug-eval-buffer (buffer-name edebug-eval-buffer))
 -    (set-buffer (setq edebug-eval-buffer (get-buffer-create "*edebug*")))
 -    (edebug-eval-mode)))
 +  (if (not (and edebug-eval-buffer (buffer-name edebug-eval-buffer)))
 +      (progn
 +      (set-buffer (setq edebug-eval-buffer (get-buffer-create "*edebug*")))
 +      (edebug-eval-mode))))
  
  ;; Should generalize this to be callable outside of edebug
  ;; with calls in user functions, e.g. (edebug-eval-display)
  
 -(defun edebug-eval-display (eval-result-list)
 -  "Display expressions and evaluations in EVAL-RESULT-LIST.
 +(defun edebug-eval-display (edebug-eval-result-list)
 +  "Display expressions and evaluations in EDEBUG-EVAL-RESULT-LIST.
  It modifies the context by popping up the eval display."
 -  (when eval-result-list
 -    (edebug-create-eval-buffer)
 -    (edebug-eval-display-list eval-result-list)))
 +  (if edebug-eval-result-list
 +      (progn
 +      (edebug-create-eval-buffer)
 +      (edebug-eval-display-list edebug-eval-result-list)
 +      )))
  
  (defun edebug-eval-redisplay ()
    "Redisplay eval list in outside environment.
 -May only be called from within `edebug--recursive-edit'."
 +May only be called from within `edebug-recursive-edit'."
    (edebug-create-eval-buffer)
    (edebug-outside-excursion
     (edebug-eval-display-list (edebug-eval-result-list))
      (if (not (eobp))
        (progn
          (forward-sexp 1)
 -        (push (edebug-last-sexp) new-list)))
 +        (setq new-list (cons (edebug-last-sexp) new-list))))
  
      (while (re-search-forward "^;" nil t)
        (forward-line 1)
               (not (eobp)))
          (progn
            (forward-sexp 1)
 -          (push (edebug-last-sexp) new-list))))
 +          (setq new-list (cons (edebug-last-sexp) new-list)))))
  
      (setq edebug-eval-list (nreverse new-list))
      (edebug-eval-redisplay)
      (define-key map "\C-c\C-u" 'edebug-update-eval-list)
      (define-key map "\C-x\C-e" 'edebug-eval-last-sexp)
      (define-key map "\C-j" 'edebug-eval-print-last-sexp)
 -    map)
 -  "Keymap for Edebug Eval mode.  Superset of Lisp Interaction mode.")
 +  map)
 +"Keymap for Edebug Eval mode.  Superset of Lisp Interaction mode.")
  
  (put 'edebug-eval-mode 'mode-class 'special)
  
@@@ -4026,32 -3958,32 +4022,32 @@@ Global commands prefixed by `global-ede
  ;; since they depend on the backtrace looking a certain way.  But
  ;; edebug is not dependent on this, yet.
  
 -(defun edebug (&optional arg-mode &rest args)
 +(defun edebug (&optional edebug-arg-mode &rest debugger-args)
    "Replacement for `debug'.
  If we are running an edebugged function, show where we last were.
  Otherwise call `debug' normally."
 -  ;;(message "entered: %s  depth: %s  edebug-recursion-depth: %s"
 -  ;;  edebug-entered (recursion-depth) edebug-recursion-depth) (sit-for 1)
 +;;  (message "entered: %s  depth: %s  edebug-recursion-depth: %s"
 +;;       edebug-entered (recursion-depth) edebug-recursion-depth) (sit-for 1)
    (if (and edebug-entered  ; anything active?
           (eq (recursion-depth) edebug-recursion-depth))
        (let (;; Where were we before the error occurred?
 -          (offset-index (car edebug-offset-indices))
 -          (value (car args))
 -          ;; Bind variables required by edebug--display.
 +          (edebug-offset-index (car edebug-offset-indices))
 +          ;; Bind variables required by edebug-display
 +          (edebug-value (car debugger-args))
            edebug-breakpoints
            edebug-break-data
            edebug-break-condition
            edebug-global-break
 -          (edebug-break (null arg-mode)) ;; If called explicitly.
 +          (edebug-break (null edebug-arg-mode)) ;; if called explicitly
            )
 -      (edebug--display value offset-index arg-mode)
 -      (if (eq arg-mode 'error)
 +      (edebug-display)
 +      (if (eq edebug-arg-mode 'error)
            nil
 -        value))
 +        edebug-value))
  
      ;; Otherwise call debug normally.
      ;; Still need to remove extraneous edebug calls from stack.
 -    (apply 'debug arg-mode args)
 +    (apply 'debug edebug-arg-mode debugger-args)
      ))
  
  
          (null (buffer-name edebug-backtrace-buffer)))
        (setq edebug-backtrace-buffer
            (generate-new-buffer "*Backtrace*"))
 -    ;; Else, could just display edebug-backtrace-buffer.
 +    ;; else, could just display edebug-backtrace-buffer
      )
    (with-output-to-temp-buffer (buffer-name edebug-backtrace-buffer)
      (setq edebug-backtrace-buffer standard-output)
        (beginning-of-line)
        (cond
         ((looking-at "^  \(edebug-after")
 -        ;; Previous lines may contain code, so just delete this line.
 +        ;; Previous lines may contain code, so just delete this line
          (setq last-ok-point (point))
          (forward-line 1)
          (delete-region last-ok-point (point)))
    "In buffer BUF-NAME, display FMT and ARGS at the end and make it visible.
  The buffer is created if it does not exist.
  You must include newlines in FMT to break lines, but one newline is appended."
 -  ;; e.g.
 -  ;; (edebug-trace-display "*trace-point*"
 -  ;;                       "saving: point = %s  window-start = %s"
 -  ;;                       (point) (window-start))
 +;; e.g.
 +;;     (edebug-trace-display "*trace-point*"
 +;;      "saving: point = %s  window-start = %s"
 +;;      (point) (window-start))
    (let* ((oldbuf (current-buffer))
         (selected-window (selected-window))
         (buffer (get-buffer-create buf-name))
         buf-window)
 -    ;; (message "before pop-to-buffer") (sit-for 1)
 +;;    (message "before pop-to-buffer") (sit-for 1)
      (edebug-pop-to-buffer buffer)
      (setq truncate-lines t)
      (setq buf-window (selected-window))
      (vertical-motion (- 1 (window-height)))
      (set-window-start buf-window (point))
      (goto-char (point-max))
 -    ;; (set-window-point buf-window (point))
 -    ;; (sit-for 0)
 +;;    (set-window-point buf-window (point))
 +;;    (edebug-sit-for 0)
      (bury-buffer buffer)
      (select-window selected-window)
      (set-buffer oldbuf))
@@@ -4184,8 -4116,8 +4180,8 @@@ reinstrument it.
        ;; Insert all the indices for this line.
        (forward-line 1)
        (setq start-of-count-line (point)
 -            first-index i   ; Really, last index for line above this one.
 -            last-count -1)  ; Cause first count to always appear.
 +            first-index i   ; really last index for line above this one.
 +            last-count -1)  ; cause first count to always appear.
        (insert ";#")
        ;; i == first-index still
        (while (<= (setq i (1+ i)) last-index)
  It is removed when you hit any char."
    ;; This seems not to work with Emacs 18.59. It undoes too far.
    (interactive)
-   (let ((buffer-read-only nil))
+   (let ((inhibit-read-only t))
      (undo-boundary)
      (edebug-display-freq-count)
 -    (setq unread-command-events
 -          (append unread-command-events (list (read-event))))
 +    (setq unread-command-events (append unread-command-events (read-event)))
      ;; Yuck!  This doesn't seem to work at all for me.
      (undo)))
  
@@@ -4328,80 -4261,6 +4324,80 @@@ With prefix argument, make it a tempora
    (edebug-modify-breakpoint t condition arg))
  
  (easy-menu-define edebug-menu edebug-mode-map "Edebug menus" edebug-mode-menus)
 +\f
 +;;; Byte-compiler
 +
 +;; Extension for bytecomp to resolve undefined function references.
 +;; Requires new byte compiler.
 +
 +(eval-when-compile
 +  ;; The body of eval-when-compile seems to get evaluated with eval-defun.
 +  ;; We only want to evaluate when actually byte compiling.
 +  ;; But it is OK to evaluate as long as byte-compiler has been loaded.
 +  (if (featurep 'byte-compile) (progn
 +
 +  (defun byte-compile-resolve-functions (funcs)
 +    "Say it is OK for the named functions to be unresolved."
 +    (mapc
 +     (function
 +      (lambda (func)
 +      (setq byte-compile-unresolved-functions
 +            (delq (assq func byte-compile-unresolved-functions)
 +                  byte-compile-unresolved-functions))))
 +     funcs)
 +    nil)
 +
 +  '(defun byte-compile-resolve-free-references (vars)
 +     "Say it is OK for the named variables to be referenced."
 +     (mapcar
 +      (function
 +       (lambda (var)
 +       (setq byte-compile-free-references
 +             (delq var byte-compile-free-references))))
 +      vars)
 +     nil)
 +
 +  '(defun byte-compile-resolve-free-assignments (vars)
 +     "Say it is OK for the named variables to be assigned."
 +     (mapcar
 +      (function
 +       (lambda (var)
 +       (setq byte-compile-free-assignments
 +             (delq var byte-compile-free-assignments))))
 +      vars)
 +     nil)
 +
 +  (byte-compile-resolve-functions
 +   '(reporter-submit-bug-report
 +     edebug-gensym ;; also in cl.el
 +     ;; Interfaces to standard functions.
 +     edebug-original-eval-defun
 +     edebug-original-read
 +     edebug-get-buffer-window
 +     edebug-mark
 +     edebug-mark-marker
 +     edebug-input-pending-p
 +     edebug-sit-for
 +     edebug-prin1-to-string
 +     edebug-format
 +     ;; lemacs
 +     zmacs-deactivate-region
 +     popup-menu
 +     ;; CL
 +     cl-macroexpand-all
 +     ;; And believe it or not, the byte compiler doesn't know about:
 +     byte-compile-resolve-functions
 +     ))
 +
 +  '(byte-compile-resolve-free-references
 +    '(read-expression-history
 +      read-expression-map))
 +
 +  '(byte-compile-resolve-free-assignments
 +    '(read-expression-history))
 +
 +  )))
 +
  \f
  ;;; Autoloading of Edebug accessories
  
diff --combined src/Makefile.in
index 93d65867fa782fb8d96e592b3d1ab12058b5b52b,c6a067a1ade8bf8004bc12374dd7f6ec15899a3c..ac09d41858d0bd25b2e99b2bdd9ad13b48c9b537
@@@ -226,15 -226,6 +226,15 @@@ CFLAGS_SOUND= @CFLAGS_SOUND
  RSVG_LIBS= @RSVG_LIBS@
  RSVG_CFLAGS= @RSVG_CFLAGS@
  
 +CLUTTER_LIBS= @CLUTTER_LIBS@
 +CLUTTER_CFLAGS= @CLUTTER_CFLAGS@
 +
 +WEBKIT_LIBS= @WEBKIT_LIBS@
 +WEBKIT_CFLAGS= @WEBKIT_CFLAGS@
 +
 +GIR_LIBS= @GIR_LIBS@
 +GIR_CFLAGS= @GIR_CFLAGS@
 +
  IMAGEMAGICK_LIBS= @IMAGEMAGICK_LIBS@
  IMAGEMAGICK_CFLAGS= @IMAGEMAGICK_CFLAGS@
  
@@@ -325,9 -316,8 +325,9 @@@ ALL_CFLAGS=-Demacs $(MYCPPFLAGS) -I. -I
    $(C_SWITCH_MACHINE) $(C_SWITCH_SYSTEM) $(C_SWITCH_X_SITE) \
    $(GNUSTEP_CFLAGS) $(CFLAGS_SOUND) $(RSVG_CFLAGS) $(IMAGEMAGICK_CFLAGS) \
    $(LIBXML2_CFLAGS) $(DBUS_CFLAGS) \
 +  $(WEBKIT_CFLAGS) $(CLUTTER_CFLAGS) $(GIR_CFLAGS) \
    $(SETTINGS_CFLAGS) $(FREETYPE_CFLAGS) $(FONTCONFIG_CFLAGS) \
-   $(LIBOTF_CFLAGS) $(M17N_FLT_CFLAGS) $(DEPFLAGS) $(PROFILING_CFLAGS) \
+   $(LIBOTF_CFLAGS) $(M17N_FLT_CFLAGS) $(DEPFLAGS) \
    $(LIBGNUTLS_CFLAGS) \
    $(WARN_CFLAGS) $(WERROR_CFLAGS) $(CFLAGS)
  ALL_OBJC_CFLAGS=$(ALL_CFLAGS) $(GNU_OBJC_CFLAGS)
  .SUFFIXES: .m
  .c.o:
        @$(MKDEPDIR)
-       $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<
+       $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $(PROFILING_CFLAGS) $<
  .m.o:
        @$(MKDEPDIR)
-       $(CC) -c $(CPPFLAGS) $(ALL_OBJC_CFLAGS) $<
+       $(CC) -c $(CPPFLAGS) $(ALL_OBJC_CFLAGS) $(PROFILING_CFLAGS) $<
  
  ## lastfile must follow all files whose initialized data areas should
  ## be dumped as pure by dump-emacs.
@@@ -355,13 -345,11 +355,13 @@@ base_obj = dispnew.o frame.o scroll.o x
        process.o gnutls.o callproc.o \
        region-cache.o sound.o atimer.o \
        doprnt.o intervals.o textprop.o composite.o xml.o inotify.o \
 +      xwidget.o \
        profiler.o \
        $(MSDOS_OBJ) $(MSDOS_X_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_OBJ) \
        $(W32_OBJ) $(WINDOW_SYSTEM_OBJ)
  obj = $(base_obj) $(NS_OBJC_OBJ)
  
 +xwidget.o: xwidget.c xwidget.h
  ## Object files used on some machine or other.
  ## These go in the DOC file on all machines in case they are needed.
  ## Some of them have no DOC entries, but it does no harm to have them
@@@ -404,7 -392,6 +404,7 @@@ ALLOBJS = $(VMLIMIT_OBJ) $(obj) $(other
  LIBES = $(LIBS) $(W32_LIBS) $(LIBS_GNUSTEP) $(LIBX_BASE) $(LIBIMAGE) \
     $(LIBX_OTHER) $(LIBSOUND) \
     $(RSVG_LIBS) $(IMAGEMAGICK_LIBS) $(LIB_CLOCK_GETTIME) \
 +   $(WEBKIT_LIBS) $(CLUTTER_LIBS) $(GIR_LIBS) \
     $(LIB_EACCESS) $(LIB_FDATASYNC) $(LIB_TIMER_TIME) $(DBUS_LIBS) \
     $(LIB_EXECINFO) \
     $(LIBXML2_LIBS) $(LIBGPM) $(LIBRESOLV) $(LIBS_SYSTEM) \
diff --combined src/dispextern.h
index 9a03abf6766b6a8d603b77bad182f76dd4ca6ec7,cb2e944d1cc2eef57d95a104e4cc405182fa220e..0c35aff82851ea56ac53b7137116af233397433e
@@@ -288,11 -288,7 +288,11 @@@ enum glyph_typ
    IMAGE_GLYPH,
  
    /* Glyph is a space of fractional width and/or height.  */
 -  STRETCH_GLYPH
 +  STRETCH_GLYPH,
 +#ifdef HAVE_XWIDGETS
 +  /* Glyph is an external widget drawn by the GUI toolkit.   */
 +  XWIDGET_GLYPH
 +#endif  
  };
  
  
@@@ -440,9 -436,6 +440,9 @@@ struct glyp
      /* Image ID for image glyphs (type == IMAGE_GLYPH).  */
      int img_id;
  
 +#ifdef HAVE_XWIDGETS
 +    struct xwidget* xwidget;
 +#endif    
      /* Sub-structure for type == STRETCH_GLYPH.  */
      struct
      {
@@@ -1309,9 -1302,6 +1309,9 @@@ struct glyph_strin
    /* Image, if any.  */
    struct image *img;
  
 +#ifdef HAVE_XWIDGETS  
 +  struct xwidget* xwidget;
 +#endif
    /* Slice */
    struct glyph_slice slice;
  
  
  /* Value is non-zero if window W wants a mode line.  */
  
- #define WINDOW_WANTS_MODELINE_P(W)                                    \
-      (!MINI_WINDOW_P ((W))                                            \
-       && !(W)->pseudo_window_p                                                \
-       && FRAME_WANTS_MODELINE_P (XFRAME (WINDOW_FRAME ((W))))         \
-       && BUFFERP (W->buffer)                                  \
-       && !NILP (BVAR (XBUFFER (W->buffer), mode_line_format)) \
-       && WINDOW_TOTAL_LINES (W) > 1)
+ #define WINDOW_WANTS_MODELINE_P(W)                            \
+   (!MINI_WINDOW_P ((W))                                               \
+    && !(W)->pseudo_window_p                                   \
+    && FRAME_WANTS_MODELINE_P (XFRAME (WINDOW_FRAME ((W))))    \
+    && BUFFERP (W->contents)                                   \
+    && !NILP (BVAR (XBUFFER (W->contents), mode_line_format))  \
+    && WINDOW_TOTAL_LINES (W) > 1)
  
  /* Value is true if window W wants a header line.  */
  
- #define WINDOW_WANTS_HEADER_LINE_P(W)                                 \
-      (!MINI_WINDOW_P ((W))                                            \
-       && !(W)->pseudo_window_p                                                \
-       && FRAME_WANTS_MODELINE_P (XFRAME (WINDOW_FRAME ((W))))         \
-       && BUFFERP (W->buffer)                                  \
-       && !NILP (BVAR (XBUFFER (W->buffer), header_line_format))       \
-       && WINDOW_TOTAL_LINES (W) > 1                                   \
-       + !NILP (BVAR (XBUFFER (W->buffer), mode_line_format)))
+ #define WINDOW_WANTS_HEADER_LINE_P(W)                         \
+   (!MINI_WINDOW_P ((W))                                               \
+    && !(W)->pseudo_window_p                                   \
+    && FRAME_WANTS_MODELINE_P (XFRAME (WINDOW_FRAME ((W))))    \
+    && BUFFERP (W->contents)                                   \
+    && !NILP (BVAR (XBUFFER (W->contents), header_line_format))        \
+    && WINDOW_TOTAL_LINES (W) > 1                              \
+    + !NILP (BVAR (XBUFFER (W->contents), mode_line_format)))
  
  /* Return proper value to be used as baseline offset of font that has
     ASCENT and DESCENT to draw characters by the font at the vertical
@@@ -2005,11 -1994,7 +2004,11 @@@ enum display_element_typ
    IT_TRUNCATION,
  
    /* Continuation glyphs.  See the comment for IT_TRUNCATION.  */
 -  IT_CONTINUATION
 +  IT_CONTINUATION,
 +
 +#ifdef HAVE_XWIDGETS  
 +  IT_XWIDGET
 +#endif
  };
  
  
@@@ -2073,9 -2058,6 +2072,9 @@@ enum it_method 
    GET_FROM_C_STRING,
    GET_FROM_IMAGE,
    GET_FROM_STRETCH,
 +#ifdef HAVE_XWIDGETS
 +  GET_FROM_XWIDGET,
 +#endif  
    NUM_IT_METHODS
  };
  
@@@ -2299,13 -2281,6 +2298,13 @@@ struct i
        struct {
        Lisp_Object object;
        } stretch;
 +#ifdef HAVE_XWIDGETS
 +      /* method == GET_FROM_XWIDGET */
 +      struct {
 +      Lisp_Object object;
 +        struct xwidget* xwidget;
 +      } xwidget;
 +#endif
      } u;
  
      /* current text and display positions.  */
    /* If what == IT_IMAGE, the id of the image to display.  */
    ptrdiff_t image_id;
  
 +#ifdef HAVE_XWIDGETS  
 +  /* If what == IT_XWIDGET*/
 +  struct xwidget* xwidget;
 +#endif
    /* Values from `slice' property.  */
    struct it_slice slice;
  
diff --combined src/dispnew.c
index de1ca47ef60ac31f4e70f01d8f75aa3c20912550,b4ca654a8f7d5b6acff027a8426b565fe93d78bd..ab73b6403ee3129f6075f3d295183d0adf12acfb
@@@ -17,6 -17,7 +17,6 @@@ GNU General Public License for more det
  
  You should have received a copy of the GNU General Public License
  along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 -
  #include <config.h>
  
  #define DISPEXTERN_INLINE EXTERN_INLINE
  #include TERM_HEADER
  #endif /* HAVE_WINDOW_SYSTEM */
  
 +#ifdef HAVE_XWIDGETS
 +#include "xwidget.h"
 +#endif
 +
  /* Include systime.h after xterm.h to avoid double inclusion of time.h.  */
  
  #include "systime.h"
@@@ -226,9 -223,9 +226,9 @@@ add_window_display_history (struct wind
            "%"pMu": window %p (`%s')%s\n%s",
            history_tick++,
            w,
-           ((BUFFERP (w->buffer)
-             && STRINGP (BVAR (XBUFFER (w->buffer), name)))
-            ? SSDATA (BVAR (XBUFFER (w->buffer), name))
+           ((BUFFERP (w->contents)
+             && STRINGP (BVAR (XBUFFER (w->contents), name)))
+            ? SSDATA (BVAR (XBUFFER (w->contents), name))
             : "???"),
            paused_p ? " ***paused***" : "",
            msg);
     PAUSED_P means that the update has been interrupted for
     pending input.  */
  
 -static void
 -add_frame_display_history (struct frame *f, bool paused_p)
 +static void add_frame_display_history (struct frame *f, int paused_p)
  {
    char *buf;
  
@@@ -844,16 -842,8 +844,8 @@@ clear_window_matrices (struct window *w
  {
    while (w)
      {
-       if (!NILP (w->hchild))
-       {
-         eassert (WINDOWP (w->hchild));
-         clear_window_matrices (XWINDOW (w->hchild), desired_p);
-       }
-       else if (!NILP (w->vchild))
-       {
-         eassert (WINDOWP (w->vchild));
-         clear_window_matrices (XWINDOW (w->vchild), desired_p);
-       }
+       if (WINDOWP (w->contents))
+       clear_window_matrices (XWINDOW (w->contents), desired_p);
        else
        {
          if (desired_p)
@@@ -1474,7 -1464,7 +1466,7 @@@ check_matrix_invariants (struct window 
    struct glyph_row *row = matrix->rows;
    struct glyph_row *last_text_row = NULL;
    struct buffer *saved = current_buffer;
-   struct buffer *buffer = XBUFFER (w->buffer);
+   struct buffer *buffer = XBUFFER (w->contents);
    int c;
  
    /* This can sometimes happen for a fresh window.  */
@@@ -1638,7 -1628,7 +1630,7 @@@ allocate_matrices_for_frame_redisplay (
       vertically below other windows.  */
    in_horz_combination_p
      = (!NILP (XWINDOW (window)->parent)
-        && !NILP (XWINDOW (XWINDOW (window)->parent)->hchild));
+        && WINDOW_HORIZONTAL_COMBINATION_P (XWINDOW (XWINDOW (window)->parent)));
  
    /* For WINDOW and all windows on the same level.  */
    do
  
        /* Get the dimension of the window sub-matrix for W, depending
         on whether this is a combination or a leaf window.  */
-       if (!NILP (w->hchild))
-       dim = allocate_matrices_for_frame_redisplay (w->hchild, x, y,
-                                                    dim_only_p,
-                                                    window_change_flags);
-       else if (!NILP (w->vchild))
-       dim = allocate_matrices_for_frame_redisplay (w->vchild, x, y,
+       if (WINDOWP (w->contents))
+       dim = allocate_matrices_for_frame_redisplay (w->contents, x, y,
                                                     dim_only_p,
                                                     window_change_flags);
        else
@@@ -1794,10 -1780,8 +1782,8 @@@ allocate_matrices_for_window_redisplay 
  {
    while (w)
      {
-       if (!NILP (w->vchild))
-       allocate_matrices_for_window_redisplay (XWINDOW (w->vchild));
-       else if (!NILP (w->hchild))
-       allocate_matrices_for_window_redisplay (XWINDOW (w->hchild));
+       if (WINDOWP (w->contents))
+       allocate_matrices_for_window_redisplay (XWINDOW (w->contents));
        else
        {
          /* W is a leaf window.  */
@@@ -1869,18 -1853,12 +1855,12 @@@ showing_window_margins_p (struct windo
  {
    while (w)
      {
-       if (!NILP (w->hchild))
+       if (WINDOWP (w->contents))
        {
-         if (showing_window_margins_p (XWINDOW (w->hchild)))
+         if (showing_window_margins_p (XWINDOW (w->contents)))
            return 1;
        }
-       else if (!NILP (w->vchild))
-       {
-         if (showing_window_margins_p (XWINDOW (w->vchild)))
-           return 1;
-       }
-       else if (!NILP (w->left_margin_cols)
-              || !NILP (w->right_margin_cols))
+       else if (!NILP (w->left_margin_cols) || !NILP (w->right_margin_cols))
        return 1;
  
        w = NILP (w->next) ? 0 : XWINDOW (w->next);
@@@ -1901,10 -1879,8 +1881,8 @@@ fake_current_matrices (Lisp_Object wind
      {
        w = XWINDOW (window);
  
-       if (!NILP (w->hchild))
-       fake_current_matrices (w->hchild);
-       else if (!NILP (w->vchild))
-       fake_current_matrices (w->vchild);
+       if (WINDOWP (w->contents))
+       fake_current_matrices (w->contents);
        else
        {
          int i;
@@@ -2244,10 -2220,8 +2222,8 @@@ free_window_matrices (struct window *w
  {
    while (w)
      {
-       if (!NILP (w->hchild))
-       free_window_matrices (XWINDOW (w->hchild));
-       else if (!NILP (w->vchild))
-       free_window_matrices (XWINDOW (w->vchild));
+       if (WINDOWP (w->contents))
+       free_window_matrices (XWINDOW (w->contents));
        else
        {
          /* This is a leaf window.  Free its memory and reset fields
@@@ -2380,10 -2354,8 +2356,8 @@@ build_frame_matrix_from_window_tree (st
  {
    while (w)
      {
-       if (!NILP (w->hchild))
-       build_frame_matrix_from_window_tree (matrix, XWINDOW (w->hchild));
-       else if (!NILP (w->vchild))
-       build_frame_matrix_from_window_tree (matrix, XWINDOW (w->vchild));
+       if (WINDOWP (w->contents))
+       build_frame_matrix_from_window_tree (matrix, XWINDOW (w->contents));
        else
        build_frame_matrix_from_leaf_window (matrix, w);
  
@@@ -2647,10 -2619,8 +2621,8 @@@ mirror_make_current (struct window *w, 
  {
    while (w)
      {
-       if (!NILP (w->hchild))
-       mirror_make_current (XWINDOW (w->hchild), frame_row);
-       else if (!NILP (w->vchild))
-       mirror_make_current (XWINDOW (w->vchild), frame_row);
+       if (WINDOWP (w->contents))
+       mirror_make_current (XWINDOW (w->contents), frame_row);
        else
        {
          /* Row relative to window W.  Don't use FRAME_TO_WINDOW_VPOS
@@@ -2746,8 -2716,8 +2718,8 @@@ sync_window_with_frame_matrix_rows (str
    struct glyph_row *window_row, *window_row_end, *frame_row;
    int left, right, x, width;
  
-   /* Preconditions: W must be a leaf window on a tty frame.  */
-   eassert (NILP (w->hchild) && NILP (w->vchild));
+   /* Preconditions: W must be a live window on a tty frame.  */
+   eassert (BUFFERP (w->contents));
    eassert (!FRAME_WINDOW_P (f));
  
    left = margin_glyphs_to_reserve (w, 1, w->left_margin_cols);
@@@ -2783,10 -2753,8 +2755,8 @@@ frame_row_to_window (struct window *w, 
  
    while (w && !found)
      {
-       if (!NILP (w->hchild))
-       found = frame_row_to_window (XWINDOW (w->hchild), row);
-       else if (!NILP (w->vchild))
-       found = frame_row_to_window (XWINDOW (w->vchild), row);
+       if (WINDOWP (w->contents))
+       found = frame_row_to_window (XWINDOW (w->contents), row);
        else if (row >= WINDOW_TOP_EDGE_LINE (w)
               && row < WINDOW_BOTTOM_EDGE_LINE (w))
        found = w;
@@@ -2814,11 -2782,8 +2784,8 @@@ mirror_line_dance (struct window *w, in
  {
    while (w)
      {
-       if (!NILP (w->hchild))
-       mirror_line_dance (XWINDOW (w->hchild), unchanged_at_top,
-                          nlines, copy_from, retained_p);
-       else if (!NILP (w->vchild))
-       mirror_line_dance (XWINDOW (w->vchild), unchanged_at_top,
+       if (WINDOWP (w->contents))
+       mirror_line_dance (XWINDOW (w->contents), unchanged_at_top,
                           nlines, copy_from, retained_p);
        else
        {
@@@ -2927,10 -2892,8 +2894,8 @@@ check_window_matrix_pointers (struct wi
  {
    while (w)
      {
-       if (!NILP (w->hchild))
-       check_window_matrix_pointers (XWINDOW (w->hchild));
-       else if (!NILP (w->vchild))
-       check_window_matrix_pointers (XWINDOW (w->vchild));
+       if (WINDOWP (w->contents))
+       check_window_matrix_pointers (XWINDOW (w->contents));
        else
        {
          struct frame *f = XFRAME (w->frame);
@@@ -3196,10 -3159,8 +3161,8 @@@ update_window_tree (struct window *w, b
  
    while (w && !paused_p)
      {
-       if (!NILP (w->hchild))
-       paused_p |= update_window_tree (XWINDOW (w->hchild), force_p);
-       else if (!NILP (w->vchild))
-       paused_p |= update_window_tree (XWINDOW (w->vchild), force_p);
+       if (WINDOWP (w->contents))
+       paused_p |= update_window_tree (XWINDOW (w->contents), force_p);
        else if (w->must_be_updated_p)
        paused_p |= update_window (w, force_p);
  
@@@ -3538,9 -3499,6 +3501,9 @@@ update_window (struct window *w, bool f
    add_window_display_history (w, w->current_matrix->method, paused_p);
  #endif
  
 +#ifdef HAVE_XWIDGETS
 +  xwidget_end_redisplay(w, w->current_matrix);
 +#endif
    clear_glyph_matrix (desired_matrix);
  
    return paused_p;
@@@ -3980,10 -3938,8 +3943,8 @@@ set_window_update_flags (struct window 
  {
    while (w)
      {
-       if (!NILP (w->hchild))
-       set_window_update_flags (XWINDOW (w->hchild), on_p);
-       else if (!NILP (w->vchild))
-       set_window_update_flags (XWINDOW (w->vchild), on_p);
+       if (WINDOWP (w->contents))
+       set_window_update_flags (XWINDOW (w->contents), on_p);
        else
        w->must_be_updated_p = on_p;
  
@@@ -4138,12 -4094,6 +4099,12 @@@ scrolling_window (struct window *w, boo
        break;
      }
  
 +#ifdef HAVE_XWIDGETS
 + //currently this is needed to detect xwidget movement reliably. or probably not.
 +  //printf("scrolling_window\n");
 +    return 0;
 +#endif
 +  
    /* Give up if some rows in the desired matrix are not enabled.  */
    if (!MATRIX_ROW (desired_matrix, i)->enabled_p)
      return -1;
@@@ -4556,7 -4506,7 +4517,7 @@@ update_frame_1 (struct frame *f, bool f
        }
      }
  
-   lint_assume (FRAME_LINES (f) >= 0);
+   lint_assume (0 <= FRAME_LINES (f));
    pause_p = 0 < i && i < FRAME_LINES (f) - 1;
  
    /* Now just clean up termcap drivers and set cursor, etc.  */
@@@ -5136,7 -5086,7 +5097,7 @@@ buffer_posn_from_coords (struct window 
  
    /* We used to set current_buffer directly here, but that does the
       wrong thing with `face-remapping-alist' (bug#2044).  */
-   Fset_buffer (w->buffer);
+   Fset_buffer (w->contents);
    itdata = bidi_shelve_cache ();
    SET_TEXT_POS_FROM_MARKER (startp, w->start);
    CHARPOS (startp) = min (ZV, max (BEGV, CHARPOS (startp)));
    *dx = x0 + it.first_visible_x - it.current_x;
    *dy = *y - it.current_y;
  
-   string =  w->buffer;
+   string = w->contents;
    if (STRINGP (it.string))
      string = it.string;
    *pos = it.current;
        if (STRINGP (it.string))
        BYTEPOS (pos->pos) = string_char_to_byte (string, CHARPOS (pos->pos));
        else
-       BYTEPOS (pos->pos) = buf_charpos_to_bytepos (XBUFFER (w->buffer),
+       BYTEPOS (pos->pos) = buf_charpos_to_bytepos (XBUFFER (w->contents),
                                                     CHARPOS (pos->pos));
      }
  
@@@ -5822,7 -5772,7 +5783,7 @@@ sit_for (Lisp_Object timeout, bool read
    else if (FLOATP (timeout))
      {
        double seconds = XFLOAT_DATA (timeout);
-       if (seconds <= 0)
+       if (! (0 < seconds))
        return Qt;
        else
        {
diff --combined src/keyboard.c
index d373935f3e41697a54f81ee594fb6188bf91d87c,beba3025887c2a2a323a34ad6e43ce2e9d611e5e..eb9f93a4c7d5aad28d9857f268155978d1032d5c
@@@ -210,12 -210,6 +210,6 @@@ static EMACS_INT last_auto_save
  /* The value of point when the last command was started.  */
  static ptrdiff_t last_point_position;
  
- /* The buffer that was current when the last command was started.  */
- static Lisp_Object last_point_position_buffer;
- /* The window that was selected when the last command was started.  */
- static Lisp_Object last_point_position_window;
  /* The frame in which the last input event occurred, or Qmacro if the
     last event came from a macro.  We use this to determine when to
     generate switch-frame events.  This may be cleared by functions
@@@ -323,9 -317,6 +317,9 @@@ static Lisp_Object Qsave_session
  #ifdef HAVE_DBUS
  static Lisp_Object Qdbus_event;
  #endif
 +#ifdef HAVE_XWIDGETS
 +Lisp_Object Qxwidget_event;
 +#endif
  #ifdef HAVE_INOTIFY
  static Lisp_Object Qfile_inotify;
  #endif /* HAVE_INOTIFY */
@@@ -836,7 -827,7 +830,7 @@@ This function is called by the editor i
    update_mode_lines = 1;
  
    if (command_loop_level
-       && current_buffer != XBUFFER (XWINDOW (selected_window)->buffer))
+       && current_buffer != XBUFFER (XWINDOW (selected_window)->contents))
      buffer = Fcurrent_buffer ();
    else
      buffer = Qnil;
@@@ -1398,7 -1389,7 +1392,7 @@@ command_loop_1 (void
        Fkill_emacs (Qnil);
  
        /* Make sure the current window's buffer is selected.  */
-       set_buffer_internal (XBUFFER (XWINDOW (selected_window)->buffer));
+       set_buffer_internal (XBUFFER (XWINDOW (selected_window)->contents));
  
        /* Display any malloc warning that just came out.  Use while because
         displaying one warning can cause another.  */
        /* A filter may have run while we were reading the input.  */
        if (! FRAME_LIVE_P (XFRAME (selected_frame)))
        Fkill_emacs (Qnil);
-       set_buffer_internal (XBUFFER (XWINDOW (selected_window)->buffer));
+       set_buffer_internal (XBUFFER (XWINDOW (selected_window)->contents));
  
        ++num_input_keys;
  
        {
          struct buffer *b;
          XWINDOW (selected_window)->force_start = 0;
-         b = XBUFFER (XWINDOW (selected_window)->buffer);
+         b = XBUFFER (XWINDOW (selected_window)->contents);
          BUF_BEG_UNCHANGED (b) = BUF_END_UNCHANGED (b) = 0;
        }
  
        prev_buffer = current_buffer;
        prev_modiff = MODIFF;
        last_point_position = PT;
-       last_point_position_window = selected_window;
-       XSETBUFFER (last_point_position_buffer, prev_buffer);
  
        /* By default, we adjust point to a boundary of a region that
           has such a property that should be treated intangible
@@@ -3987,13 -3976,6 +3979,13 @@@ kbd_buffer_get_event (KBOARD **kbp
          kbd_fetch_ptr = event + 1;
        }
  #endif
 +#ifdef HAVE_XWIDGETS      
 +      else if (event->kind == XWIDGET_EVENT)
 +      {
 +        obj = make_lispy_event (event);
 +        kbd_fetch_ptr = event + 1;
 +      }
 +#endif      
  #ifdef HAVE_INOTIFY
        else if (event->kind == FILE_NOTIFY_EVENT)
          {
@@@ -5152,7 -5134,7 +5144,7 @@@ make_lispy_position (struct frame *f, L
          if (STRINGP (string))
            string_info = Fcons (string, make_number (charpos));
          textpos = (w == XWINDOW (selected_window)
-                    && current_buffer == XBUFFER (w->buffer))
+                    && current_buffer == XBUFFER (w->contents))
            ? PT : marker_position (w->pointm);
  
          xret = wx;
@@@ -5914,15 -5896,6 +5906,15 @@@ make_lispy_event (struct input_event *e
        }
  #endif /* HAVE_DBUS */
  
 +#ifdef HAVE_XWIDGETS
 +    case XWIDGET_EVENT:
 +      {
 +        printf("cool, an xwidget event arrived in make_lispy_event!\n");
 +        return  Fcons (Qxwidget_event,event->arg);
 +      }
 +#endif /* HAVE_XWIDGETS */
 +
 +
  #ifdef HAVE_INOTIFY
      case FILE_NOTIFY_EVENT:
        {
@@@ -9164,9 -9137,9 +9156,9 @@@ read_key_sequence (Lisp_Object *keybuf
                {
                  if (! FRAME_LIVE_P (XFRAME (selected_frame)))
                    Fkill_emacs (Qnil);
-                 if (XBUFFER (XWINDOW (selected_window)->buffer)
+                 if (XBUFFER (XWINDOW (selected_window)->contents)
                      != current_buffer)
-                   Fset_buffer (XWINDOW (selected_window)->buffer);
+                   Fset_buffer (XWINDOW (selected_window)->contents);
                }
  
              goto replay_sequence;
                 special-event-map, ...) might have switched the current buffer
                 or the selected window from under us in the mean time.  */
              if (fix_current_buffer
-                 && (XBUFFER (XWINDOW (selected_window)->buffer)
+                 && (XBUFFER (XWINDOW (selected_window)->contents)
                      != current_buffer))
-               Fset_buffer (XWINDOW (selected_window)->buffer);
+               Fset_buffer (XWINDOW (selected_window)->contents);
              current_binding = active_maps (first_event);
            }
  
                     not the current buffer.  If we're at the
                     beginning of a key sequence, switch buffers.  */
                  if (WINDOWP (window)
-                     && BUFFERP (XWINDOW (window)->buffer)
-                     && XBUFFER (XWINDOW (window)->buffer) != current_buffer)
+                     && BUFFERP (XWINDOW (window)->contents)
+                     && XBUFFER (XWINDOW (window)->contents) != current_buffer)
                    {
                      ASET (raw_keybuf, raw_keybuf_count, key);
                      raw_keybuf_count++;
  
                      if (! FRAME_LIVE_P (XFRAME (selected_frame)))
                        Fkill_emacs (Qnil);
-                     set_buffer_internal (XBUFFER (XWINDOW (window)->buffer));
+                     set_buffer_internal (XBUFFER (XWINDOW (window)->contents));
                      goto replay_sequence;
                    }
                }
@@@ -11009,10 -10982,6 +11001,10 @@@ syms_of_keyboard (void
    DEFSYM (Qdbus_event, "dbus-event");
  #endif
  
 +#ifdef HAVE_XWIDGETS
 +  Qxwidget_event = intern ("xwidget-event");
 +  staticpro (&Qxwidget_event);
 +#endif /* HAVE_XWIDGETS */
  #ifdef HAVE_INOTIFY
    DEFSYM (Qfile_inotify, "file-inotify");
  #endif /* HAVE_INOTIFY */
    Fset (Qinput_method_exit_on_first_char, Qnil);
    Fset (Qinput_method_use_echo_area, Qnil);
  
-   last_point_position_buffer = Qnil;
-   last_point_position_window = Qnil;
    {
      int i;
      int len = sizeof (head_table) / sizeof (head_table[0]);
diff --combined src/lisp.h
index 8187f7da99328718d7cf3e009b741d45137e081d,bcb866b4cc4401626f5f9a82157e05444ec06a34..175ec828c974bd8ce5300ab4d6b3b3e4f528fa7d
@@@ -417,11 -417,6 +417,11 @@@ enum pvec_typ
    PVEC_WINDOW_CONFIGURATION,
    PVEC_SUBR,
    PVEC_OTHER,
 +#ifdef HAVE_XWIDGETS
 +  PVEC_XWIDGET,
 +  PVEC_XWIDGET_VIEW,
 +#endif
 +
    /* These should be last, check internal_equal to see why.  */
    PVEC_COMPILED,
    PVEC_CHAR_TABLE,
@@@ -548,7 -543,7 +548,7 @@@ static EMACS_INT const VALMAS
     type or if I is a NaN.  */
  
  #define FIXNUM_OVERFLOW_P(i) \
-   (! (((i) >= 0 || (i) >= MOST_NEGATIVE_FIXNUM) && (i) <= MOST_POSITIVE_FIXNUM))
+   (! ((0 <= (i) || MOST_NEGATIVE_FIXNUM <= (i)) && (i) <= MOST_POSITIVE_FIXNUM))
  
  LISP_INLINE ptrdiff_t
  clip_to_bounds (ptrdiff_t lower, EMACS_INT num, ptrdiff_t upper)
  }
  
  \f
- /* Forward declarations.  */
- LISP_INLINE bool SAVE_VALUEP (Lisp_Object);
- LISP_INLINE struct Lisp_Save_Value *XSAVE_VALUE (Lisp_Object);
  /* Extract a value or address from a Lisp_Object.  */
  
  #define XCONS(a)   (eassert (CONSP (a)), \
@@@ -1492,53 -1482,6 +1487,6 @@@ struct Lisp_Save_Valu
      } data[SAVE_VALUE_SLOTS];
    };
  
- /* Return the type of V's Nth saved value.  */
- LISP_INLINE int
- save_type (struct Lisp_Save_Value *v, int n)
- {
-   eassert (0 <= n && n < SAVE_VALUE_SLOTS);
-   return (v->save_type >> (SAVE_SLOT_BITS * n) & ((1 << SAVE_SLOT_BITS) - 1));
- }
- /* Get and set the Nth saved pointer.  */
- LISP_INLINE void *
- XSAVE_POINTER (Lisp_Object obj, int n)
- {
-   eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_POINTER);
-   return XSAVE_VALUE (obj)->data[n].pointer;;
- }
- LISP_INLINE void
- set_save_pointer (Lisp_Object obj, int n, void *val)
- {
-   eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_POINTER);
-   XSAVE_VALUE (obj)->data[n].pointer = val;
- }
- /* Likewise for the saved integer.  */
- LISP_INLINE ptrdiff_t
- XSAVE_INTEGER (Lisp_Object obj, int n)
- {
-   eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_INTEGER);
-   return XSAVE_VALUE (obj)->data[n].integer;
- }
- LISP_INLINE void
- set_save_integer (Lisp_Object obj, int n, ptrdiff_t val)
- {
-   eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_INTEGER);
-   XSAVE_VALUE (obj)->data[n].integer = val;
- }
- /* Extract Nth saved object.  */
- LISP_INLINE Lisp_Object
- XSAVE_OBJECT (Lisp_Object obj, int n)
- {
-   eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_OBJECT);
-   return XSAVE_VALUE (obj)->data[n].object;
- }
  /* A miscellaneous object, when it's on the free list.  */
  struct Lisp_Free
    {
@@@ -1560,13 -1503,6 +1508,6 @@@ union Lisp_Mis
      struct Lisp_Save_Value u_save_value;
    };
  
- LISP_INLINE struct Lisp_Save_Value *
- XSAVE_VALUE (Lisp_Object a)
- {
-   eassert (SAVE_VALUEP (a));
-   return & XMISC (a)->u_save_value;
- }
  /* Forwarding pointer to an int variable.
     This is allowed only in the value cell of a symbol,
     and it means that the symbol's value really lives in the
@@@ -1859,6 -1795,60 +1800,60 @@@ SAVE_VALUEP (Lisp_Object x
    return MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Save_Value;
  }
  
+ LISP_INLINE struct Lisp_Save_Value *
+ XSAVE_VALUE (Lisp_Object a)
+ {
+   eassert (SAVE_VALUEP (a));
+   return & XMISC (a)->u_save_value;
+ }
+ /* Return the type of V's Nth saved value.  */
+ LISP_INLINE int
+ save_type (struct Lisp_Save_Value *v, int n)
+ {
+   eassert (0 <= n && n < SAVE_VALUE_SLOTS);
+   return (v->save_type >> (SAVE_SLOT_BITS * n) & ((1 << SAVE_SLOT_BITS) - 1));
+ }
+ /* Get and set the Nth saved pointer.  */
+ LISP_INLINE void *
+ XSAVE_POINTER (Lisp_Object obj, int n)
+ {
+   eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_POINTER);
+   return XSAVE_VALUE (obj)->data[n].pointer;;
+ }
+ LISP_INLINE void
+ set_save_pointer (Lisp_Object obj, int n, void *val)
+ {
+   eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_POINTER);
+   XSAVE_VALUE (obj)->data[n].pointer = val;
+ }
+ /* Likewise for the saved integer.  */
+ LISP_INLINE ptrdiff_t
+ XSAVE_INTEGER (Lisp_Object obj, int n)
+ {
+   eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_INTEGER);
+   return XSAVE_VALUE (obj)->data[n].integer;
+ }
+ LISP_INLINE void
+ set_save_integer (Lisp_Object obj, int n, ptrdiff_t val)
+ {
+   eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_INTEGER);
+   XSAVE_VALUE (obj)->data[n].integer = val;
+ }
+ /* Extract Nth saved object.  */
+ LISP_INLINE Lisp_Object
+ XSAVE_OBJECT (Lisp_Object obj, int n)
+ {
+   eassert (save_type (XSAVE_VALUE (obj), n) == SAVE_OBJECT);
+   return XSAVE_VALUE (obj)->data[n].object;
+ }
  #define AUTOLOADP(x) (CONSP (x) && EQ (Qautoload, XCAR (x)))
  
  #define INTFWDP(x) (XFWDTYPE (x) == Lisp_Fwd_Int)
@@@ -2570,7 -2560,7 +2565,7 @@@ gc_aset (Lisp_Object array, ptrdiff_t i
  LISP_INLINE void
  vcopy (Lisp_Object v, ptrdiff_t offset, Lisp_Object *args, ptrdiff_t count)
  {
-   eassert (offset >= 0 && count >= 0 && offset + count <= ASIZE (v));
+   eassert (0 <= offset && 0 <= count && offset + count <= ASIZE (v));
    memcpy (XVECTOR (v)->contents + offset, args, count * sizeof *args);
  }
  
@@@ -3781,11 -3771,6 +3776,6 @@@ extern void syms_of_xml (void)
  extern void xml_cleanup_parser (void);
  #endif
  
- #ifdef HAVE_MENUS
- /* Defined in (x|w32)fns.c, nsfns.m...  */
- extern int have_menus_p (void);
- #endif
  #ifdef HAVE_DBUS
  /* Defined in dbusbind.c.  */
  void syms_of_dbusbind (void);
diff --combined src/print.c
index 8498a758a21a2e5594078a9c7ab6c96947336926,811ab5011ced6633afc336693945050182460d58..eb1f9cba82dc86e89e07ed318be8d0b9e456d992
@@@ -36,9 -36,7 +36,9 @@@ along with GNU Emacs.  If not, see <htt
  #include "blockinput.h"
  #include "termhooks.h"                /* For struct terminal.  */
  #include "font.h"
 -
 +#ifdef HAVE_XWIDGETS
 +#include "xwidget.h"
 +#endif
  Lisp_Object Qstandard_output;
  
  static Lisp_Object Qtemp_buffer_setup_hook;
@@@ -1765,23 -1763,16 +1765,23 @@@ print_object (Lisp_Object obj, Lisp_Obj
          strout (XSUBR (obj)->symbol_name, -1, -1, printcharfun);
          PRINTCHAR ('>');
        }
 +#ifdef HAVE_XWIDGETS
 +      else if (XXWIDGETP (obj))
 +      {
 +        strout ("#<xwidget ", -1, -1, printcharfun);
 +        PRINTCHAR ('>');
 +      }
 +#endif      
        else if (WINDOWP (obj))
        {
          int len;
          strout ("#<window ", -1, -1, printcharfun);
          len = sprintf (buf, "%p", XWINDOW (obj));
          strout (buf, len, len, printcharfun);
-         if (!NILP (XWINDOW (obj)->buffer))
+         if (BUFFERP (XWINDOW (obj)->contents))
            {
              strout (" on ", -1, -1, printcharfun);
-             print_string (BVAR (XBUFFER (XWINDOW (obj)->buffer), name),
+             print_string (BVAR (XBUFFER (XWINDOW (obj)->contents), name),
                            printcharfun);
            }
          PRINTCHAR ('>');
diff --combined src/window.c
index a2e6a5a0602a6af0053e18465d9ba5d8435e3e74,feb5f7b5cc7be8369bfc774a72b293b755dbd35c..77604f4ee1960973fd52e1a659d9694ef59765ef
@@@ -52,10 -52,9 +52,10 @@@ along with GNU Emacs.  If not, see <htt
  #ifdef HAVE_NS
  #include "nsterm.h"
  #endif
 -
 -Lisp_Object Qwindowp, Qwindow_live_p;
 -static Lisp_Object Qwindow_valid_p;
 +#ifdef HAVE_XWIDGETS
 +#include "xwidget.h"
 +#endif
 +Lisp_Object Qwindowp, Qwindow_live_p, Qwindow_valid_p;
  static Lisp_Object Qwindow_configuration_p, Qrecord_window_buffer;
  static Lisp_Object Qwindow_deletable_p, Qdelete_window, Qdisplay_buffer;
  static Lisp_Object Qreplace_buffer_in_windows, Qget_mru_window;
@@@ -148,11 -147,6 +148,6 @@@ wset_display_table (struct window *w, L
    w->display_table = val;
  }
  static void
- wset_hchild (struct window *w, Lisp_Object val)
- {
-   w->hchild = val;
- }
- static void
  wset_left_fringe_width (struct window *w, Lisp_Object val)
  {
    w->left_fringe_width = val;
@@@ -218,11 -212,6 +213,6 @@@ wset_temslot (struct window *w, Lisp_Ob
    w->temslot = val;
  }
  static void
- wset_vchild (struct window *w, Lisp_Object val)
- {
-   w->vchild = val;
- }
- static void
  wset_vertical_scroll_bar_type (struct window *w, Lisp_Object val)
  {
    w->vertical_scroll_bar_type = val;
@@@ -232,6 -221,18 +222,18 @@@ wset_window_parameters (struct window *
  {
    w->window_parameters = val;
  }
+ static void
+ wset_combination (struct window *w, bool horflag, Lisp_Object val)
+ {
+   /* Since leaf windows never becomes non-leaf, there should
+      be no buffer and markers in start and pointm fields of W.  */
+   eassert (!BUFFERP (w->contents) && NILP (w->start) && NILP (w->pointm));
+   w->contents = val;
+   /* When an internal window is deleted and VAL is nil, HORFLAG
+      is meaningless.  */
+   if (!NILP (val))
+     w->horizontal = horflag;
+ }
  
  struct window *
  decode_live_window (register Lisp_Object window)
@@@ -276,9 -277,9 +278,9 @@@ static voi
  adjust_window_count (struct window *w, int arg)
  {
    eassert (eabs (arg) == 1);
-   if (BUFFERP (w->buffer))
+   if (BUFFERP (w->contents))
      {
-       struct buffer *b = XBUFFER (w->buffer);
+       struct buffer *b = XBUFFER (w->contents);
  
        if (b->base_buffer)
        b = b->base_buffer;
@@@ -297,7 -298,11 +299,11 @@@ voi
  wset_buffer (struct window *w, Lisp_Object val)
  {
    adjust_window_count (w, -1);
-   w->buffer = val;
+   if (BUFFERP (val))
+     /* Make sure that we do not assign the buffer
+        to an internal window.  */
+     eassert (MARKERP (w->start) && MARKERP (w->pointm));
+   w->contents = val;
    adjust_window_count (w, 1);
  }
  
@@@ -395,15 -400,8 +401,8 @@@ the first window of that frame.  */
        window = XFRAME (frame_or_window)->root_window;
      }
  
-   while (NILP (XWINDOW (window)->buffer))
-     {
-       if (! NILP (XWINDOW (window)->hchild))
-       window = XWINDOW (window)->hchild;
-       else if (! NILP (XWINDOW (window)->vchild))
-       window = XWINDOW (window)->vchild;
-       else
-       emacs_abort ();
-     }
+   while (WINDOWP (XWINDOW (window)->contents))
+     window = XWINDOW (window)->contents;
  
    return window;
  }
@@@ -490,11 -488,11 +489,11 @@@ select_window (Lisp_Object window, Lisp
    if (NILP (norecord))
      {
        w->use_time = ++window_select_count;
-       record_buffer (w->buffer);
+       record_buffer (w->contents);
      }
  
    /* Make the selected window's buffer current.  */
-   Fset_buffer (w->buffer);
+   Fset_buffer (w->contents);
  
    if (EQ (window, selected_window) && !inhibit_point_swap)
      return window;
  
    select_window_1 (window, inhibit_point_swap);
  
-   bset_last_selected_window (XBUFFER (w->buffer), window);
+   bset_last_selected_window (XBUFFER (w->contents), window);
    windows_or_buffers_changed++;
    return window;
  }
@@@ -534,10 -532,10 +533,10 @@@ select_window_1 (Lisp_Object window, bo
    if (!inhibit_point_swap)
      {
        struct window *ow = XWINDOW (selected_window);
-       if (! NILP (ow->buffer))
-       set_marker_both (ow->pointm, ow->buffer,
-                        BUF_PT (XBUFFER (ow->buffer)),
-                        BUF_PT_BYTE (XBUFFER (ow->buffer)));
+       if (BUFFERP (ow->contents))
+       set_marker_both (ow->pointm, ow->contents,
+                        BUF_PT (XBUFFER (ow->contents)),
+                        BUF_PT_BYTE (XBUFFER (ow->contents)));
      }
  
    selected_window = window;
@@@ -582,7 -580,8 +581,8 @@@ If WINDOW is omitted or nil, it default
  Return nil for an internal window or a deleted window.  */)
    (Lisp_Object window)
  {
-   return decode_any_window (window)->buffer;
+   struct window *w = decode_any_window (window);
+   return WINDOW_LEAF_P (w) ? w->contents : Qnil;
  }
  
  DEFUN ("window-parent", Fwindow_parent, Swindow_parent, 0, 1, 0,
@@@ -602,7 -601,8 +602,8 @@@ Return nil if WINDOW is an internal win
  horizontal combination.  */)
    (Lisp_Object window)
  {
-   return decode_valid_window (window)->vchild;
+   struct window *w = decode_valid_window (window);
+   return WINDOW_VERTICAL_COMBINATION_P (w) ? w->contents : Qnil;
  }
  
  DEFUN ("window-left-child", Fwindow_left_child, Swindow_left_child, 0, 1, 0,
@@@ -613,7 -613,8 +614,8 @@@ Return nil if WINDOW is an internal win
  vertical combination.  */)
    (Lisp_Object window)
  {
-   return decode_valid_window (window)->hchild;
+   struct window *w = decode_valid_window (window);
+   return WINDOW_HORIZONTAL_COMBINATION_P (w) ? w->contents : Qnil;
  }
  
  DEFUN ("window-next-sibling", Fwindow_next_sibling, Swindow_next_sibling, 0, 1, 0,
@@@ -646,9 -647,9 +648,9 @@@ WINDOW are never \(re-)combined with WI
  
    CHECK_VALID_WINDOW (window);
    w = XWINDOW (window);
-   if (!NILP (w->buffer))
+   if (WINDOW_LEAF_P (w))
      error ("Combination limit is meaningful for internal windows only");
-   return XWINDOW (window)->combination_limit;
+   return w->combination_limit;
  }
  
  DEFUN ("set-window-combination-limit", Fset_window_combination_limit, Sset_window_combination_limit, 2, 2, 0,
@@@ -664,7 -665,7 +666,7 @@@ future use.  */
  
    CHECK_VALID_WINDOW (window);
    w = XWINDOW (window);
-   if (!NILP (w->buffer))
+   if (WINDOW_LEAF_P (w))
      error ("Combination limit is meaningful for internal windows only");
    wset_combination_limit (w, limit);
    return limit;
@@@ -861,7 -862,7 +863,7 @@@ set_window_hscroll (struct window *w, E
  
    /* Prevent redisplay shortcuts when changing the hscroll.  */
    if (w->hscroll != new_hscroll)
-     XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
+     XBUFFER (w->contents)->prevent_redisplay_optimizations_p = 1;
  
    w->hscroll = new_hscroll;
    return make_number (new_hscroll);
@@@ -1442,7 -1443,7 +1444,7 @@@ correct to return the top-level value o
    register struct window *w = decode_live_window (window);
  
    if (w == XWINDOW (selected_window))
-     return make_number (BUF_PT (XBUFFER (w->buffer)));
+     return make_number (BUF_PT (XBUFFER (w->contents)));
    else
      return Fmarker_position (w->pointm);
  }
@@@ -1484,7 -1485,7 +1486,7 @@@ if it isn't already recorded.  */
    Lisp_Object buf;
    struct buffer *b;
  
-   buf = w->buffer;
+   buf = w->contents;
    CHECK_BUFFER (buf);
    b = XBUFFER (buf);
  
@@@ -1547,7 -1548,7 +1549,7 @@@ Return POS.  */
  
    if (w == XWINDOW (selected_window))
      {
-       if (XBUFFER (w->buffer) == current_buffer)
+       if (XBUFFER (w->contents) == current_buffer)
        Fgoto_char (pos);
        else
        {
  
          /* ... but here we want to catch type error before buffer change.  */
          CHECK_NUMBER_COERCE_MARKER (pos);
-         set_buffer_internal (XBUFFER (w->buffer));
+         set_buffer_internal (XBUFFER (w->contents));
          Fgoto_char (pos);
          set_buffer_internal (old_buffer);
        }
      }
    else
      {
-       set_marker_restricted (w->pointm, pos, w->buffer);
+       set_marker_restricted (w->pointm, pos, w->contents);
        /* We have to make sure that redisplay updates the window to show
         the new value of point.  */
        ++windows_or_buffers_changed;
@@@ -1580,7 -1581,7 +1582,7 @@@ overriding motion of point in order to 
  {
    register struct window *w = decode_live_window (window);
  
-   set_marker_restricted (w->start, pos, w->buffer);
+   set_marker_restricted (w->start, pos, w->contents);
    /* This is not right, but much easier than doing what is right.  */
    w->start_at_line_beg = 0;
    if (NILP (noforce))
@@@ -1624,7 -1625,7 +1626,7 @@@ display row, and VPOS is the row numbe
    int x, y;
  
    w = decode_live_window (window);
-   buf = XBUFFER (w->buffer);
+   buf = XBUFFER (w->contents);
    SET_TEXT_POS_FROM_MARKER (top, w->start);
  
    if (EQ (pos, Qt))
@@@ -1693,8 -1694,8 +1695,8 @@@ Return nil if window display is not up-
    if (noninteractive || w->pseudo_window_p)
      return Qnil;
  
-   CHECK_BUFFER (w->buffer);
-   b = XBUFFER (w->buffer);
+   CHECK_BUFFER (w->contents);
+   b = XBUFFER (w->contents);
  
    /* Fail if current matrix is not up-to-date.  */
    if (!w->window_end_valid
@@@ -1920,9 -1921,9 +1922,9 @@@ window_display_table (struct window *w
  
    if (DISP_TABLE_P (w->display_table))
      dp = XCHAR_TABLE (w->display_table);
-   else if (BUFFERP (w->buffer))
+   else if (BUFFERP (w->contents))
      {
-       struct buffer *b = XBUFFER (w->buffer);
+       struct buffer *b = XBUFFER (w->contents);
  
        if (DISP_TABLE_P (BVAR (b, display_table)))
        dp = XCHAR_TABLE (BVAR (b, display_table));
@@@ -1947,17 -1948,14 +1949,14 @@@ WINDOW must be a live window and defaul
  static void
  unshow_buffer (register struct window *w)
  {
-   Lisp_Object buf;
-   struct buffer *b;
+   Lisp_Object buf = w->contents;
+   struct buffer *b = XBUFFER (buf);
  
-   buf = w->buffer;
-   b = XBUFFER (buf);
-   if (b != XMARKER (w->pointm)->buffer)
-     emacs_abort ();
+   eassert (b == XMARKER (w->pointm)->buffer);
  
  #if 0
    if (w == XWINDOW (selected_window)
-       || ! EQ (buf, XWINDOW (selected_window)->buffer))
+       || ! EQ (buf, XWINDOW (selected_window)->contents))
      /* Do this except when the selected window's buffer
         is being removed from some other window.  */
  #endif
    /* Point in the selected window's buffer
       is actually stored in that buffer, and the window's pointm isn't used.
       So don't clobber point in that buffer.  */
-   if (! EQ (buf, XWINDOW (selected_window)->buffer)
+   if (! EQ (buf, XWINDOW (selected_window)->contents)
        /* Don't clobber point in current buffer either (this could be
         useful in connection with bug#12208).
        && XBUFFER (buf) != current_buffer  */
        /* This line helps to fix Horsley's testbug.el bug.  */
        && !(WINDOWP (BVAR (b, last_selected_window))
           && w != XWINDOW (BVAR (b, last_selected_window))
-          && EQ (buf, XWINDOW (BVAR (b, last_selected_window))->buffer)))
+          && EQ (buf, XWINDOW (BVAR (b, last_selected_window))->contents)))
      temp_set_point_both (b,
                         clip_to_bounds (BUF_BEGV (b),
                                         marker_position (w->pointm),
@@@ -2045,13 -2043,8 +2044,8 @@@ replace_window (Lisp_Object old, Lisp_O
  
    tem = o->parent;
    wset_parent (n, tem);
-   if (!NILP (tem))
-     {
-       if (EQ (XWINDOW (tem)->vchild, old))
-       wset_vchild (XWINDOW (tem), new);
-       if (EQ (XWINDOW (tem)->hchild, old))
-       wset_hchild (XWINDOW (tem), new);
-     }
+   if (!NILP (tem) && EQ (XWINDOW (tem)->contents, old))
+     wset_combination (XWINDOW (tem), XWINDOW (tem)->horizontal, new);
  }
  
  /* If window WINDOW and its parent window are iso-combined, merge
@@@ -2070,22 -2063,19 +2064,19 @@@ recombine_windows (Lisp_Object window
    if (!NILP (parent) && NILP (w->combination_limit))
      {
        p = XWINDOW (parent);
-       if (((!NILP (p->vchild) && !NILP (w->vchild))
-          || (!NILP (p->hchild) && !NILP (w->hchild))))
+       if (WINDOWP (p->contents) && WINDOWP (w->contents)
+         && p->horizontal == w->horizontal)
        /* WINDOW and PARENT are both either a vertical or a horizontal
           combination.  */
        {
-         horflag = NILP (w->vchild);
-         child = horflag ? w->hchild : w->vchild;
+         horflag = WINDOW_HORIZONTAL_COMBINATION_P (w);
+         child = w->contents;
          c = XWINDOW (child);
  
          /* Splice WINDOW's children into its parent's children and
             assign new normal sizes.  */
          if (NILP (w->prev))
-           if (horflag)
-             wset_hchild (p, child);
-           else
-             wset_vchild (p, child);
+           wset_combination (p, horflag, child);
          else
            {
              wset_prev (c, w->prev);
            }
  
          /* WINDOW can be deleted now.  */
-         wset_vchild (w, Qnil);
-         wset_hchild (w, Qnil);
+         wset_combination (w, 0, Qnil);
        }
      }
  }
@@@ -2210,7 -2199,7 +2200,7 @@@ candidate_window_p (Lisp_Object window
    struct frame *f = XFRAME (w->frame);
    int candidate_p = 1;
  
-   if (!BUFFERP (w->buffer))
+   if (!BUFFERP (w->contents))
      candidate_p = 0;
    else if (MINI_WINDOW_P (w)
             && (EQ (minibuf, Qlambda)
@@@ -2550,7 -2539,7 +2540,7 @@@ enum window_loo
    GET_BUFFER_WINDOW,              /* Arg is buffer */
    REPLACE_BUFFER_IN_WINDOWS_SAFELY, /* Arg is buffer */
    REDISPLAY_BUFFER_WINDOWS,       /* Arg is buffer */
-   CHECK_ALL_WINDOWS
+   CHECK_ALL_WINDOWS                 /* Arg is ignored */
  };
  
  static Lisp_Object
@@@ -2614,7 -2603,7 +2604,7 @@@ window_loop (enum window_loop type, Lis
        switch (type)
          {
          case GET_BUFFER_WINDOW:
-           if (EQ (w->buffer, obj)
+           if (EQ (w->contents, obj)
                /* Don't find any minibuffer window except the one that
                   is currently in use.  */
                && (MINI_WINDOW_P (w) ? EQ (window, minibuf_window) : 1))
          case REPLACE_BUFFER_IN_WINDOWS_SAFELY:
            /* We could simply check whether the buffer shown by window
               is live, and show another buffer in case it isn't.  */
-           if (EQ (w->buffer, obj))
+           if (EQ (w->contents, obj))
              {
                /* Undedicate WINDOW.  */
                wset_dedicated (w, Qnil);
                /* Make WINDOW show the buffer returned by
                   other_buffer_safely, don't run any hooks.  */
                set_window_buffer
-                 (window, other_buffer_safely (w->buffer), 0, 0);
+                 (window, other_buffer_safely (w->contents), 0, 0);
                /* If WINDOW is the selected window, make its buffer
                   current.  But do so only if the window shows the
                   current buffer (Bug#6454).  */
                if (EQ (window, selected_window)
-                   && XBUFFER (w->buffer) == current_buffer)
-                 Fset_buffer (w->buffer);
+                   && XBUFFER (w->contents) == current_buffer)
+                 Fset_buffer (w->contents);
              }
            break;
  
          case REDISPLAY_BUFFER_WINDOWS:
-           if (EQ (w->buffer, obj))
+           if (EQ (w->contents, obj))
              {
                mark_window_display_accurate (window, 0);
                w->update_mode_line = 1;
              }
            break;
  
-           /* Check for a window that has a killed buffer.  */
+           /* Check for a leaf window that has a killed buffer
+              or broken markers.  */
          case CHECK_ALL_WINDOWS:
-           if (! NILP (w->buffer)
-               && !BUFFER_LIVE_P (XBUFFER (w->buffer)))
-             emacs_abort ();
+           if (BUFFERP (w->contents))
+             {
+               struct buffer *b = XBUFFER (w->contents);
+               if (!BUFFER_LIVE_P (b))
+                 emacs_abort ();
+               if (!MARKERP (w->start) || XMARKER (w->start)->buffer != b)
+                 emacs_abort ();
+               if (!MARKERP (w->pointm) || XMARKER (w->pointm)->buffer != b)
+                 emacs_abort ();
+             }
            break;
  
          case WINDOW_LOOP_UNUSED:
@@@ -2787,7 -2785,7 +2786,7 @@@ window-start value is reasonable when t
    else if (MINI_WINDOW_P (w)) /* && top > 0) */
      error ("Can't expand minibuffer to full frame");
  
-   if (!NILP (w->buffer))
+   if (BUFFERP (w->contents))
      {
        startpos = marker_position (w->start);
        startbyte = marker_byte_position (w->start);
    FRAME_WINDOW_SIZES_CHANGED (f) = 1;
    resize_failed = 0;
  
-   if (NILP (w->buffer))
+   if (!WINDOW_LEAF_P (w))
      {
        /* Resize child windows vertically.  */
        XSETINT (delta, r->total_lines - w->total_lines);
        sibling = w->next;
        s = XWINDOW (sibling);
        wset_prev (s, Qnil);
-       if (!NILP (XWINDOW (w->parent)->vchild))
-       wset_vchild (XWINDOW (w->parent), sibling);
-       else
-       wset_hchild (XWINDOW (w->parent), sibling);
+       wset_combination (XWINDOW (w->parent),
+                       XWINDOW (w->parent)->horizontal, sibling);
      }
  
    /* Delete ROOT and all child windows of ROOT.  */
-   if (!NILP (r->vchild))
+   if (WINDOWP (r->contents))
      {
-       delete_all_child_windows (r->vchild);
-       wset_vchild (r, Qnil);
-     }
-   else if (!NILP (r->hchild))
-     {
-       delete_all_child_windows (r->hchild);
-       wset_hchild (r, Qnil);
+       delete_all_child_windows (r->contents);
+       wset_combination (r, 0, Qnil);
      }
  
    replace_window (root, window, 1);
  
    /* This must become SWINDOW anyway ....... */
-   if (!NILP (w->buffer) && !resize_failed)
+   if (BUFFERP (w->contents) && !resize_failed)
      {
        /* Try to minimize scrolling, by setting the window start to the
         point will cause the text at the old window start to be at the
         when the display is not current, due to typeahead).  */
        new_top = WINDOW_TOP_EDGE_LINE (w) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w)));
        if (new_top != top
-         && startpos >= BUF_BEGV (XBUFFER (w->buffer))
-         && startpos <= BUF_ZV (XBUFFER (w->buffer)))
+         && startpos >= BUF_BEGV (XBUFFER (w->contents))
+         && startpos <= BUF_ZV (XBUFFER (w->contents)))
        {
          struct position pos;
          struct buffer *obuf = current_buffer;
  
-         Fset_buffer (w->buffer);
+         Fset_buffer (w->contents);
          /* This computation used to temporarily move point, but that
             can have unwanted side effects due to text properties.  */
          pos = *vmotion (startpos, startbyte, -top, w);
  
-         set_marker_both (w->start, w->buffer, pos.bufpos, pos.bytepos);
+         set_marker_both (w->start, w->contents, pos.bufpos, pos.bytepos);
          w->window_end_valid = 0;
          w->start_at_line_beg = (pos.bytepos == BEGV_BYTE
                                    || FETCH_BYTE (pos.bytepos - 1) == '\n');
@@@ -3159,7 -3150,7 +3151,7 @@@ set_window_buffer (Lisp_Object window, 
    struct window *w = XWINDOW (window);
    struct buffer *b = XBUFFER (buffer);
    ptrdiff_t count = SPECPDL_INDEX ();
-   int samebuf = EQ (buffer, w->buffer);
+   int samebuf = EQ (buffer, w->contents);
  
    wset_buffer (w, buffer);
  
@@@ -3278,7 -3269,7 +3270,7 @@@ This function runs `window-scroll-funct
    if (!BUFFER_LIVE_P (XBUFFER (buffer)))
      error ("Attempt to display deleted buffer");
  
-   tem = w->buffer;
+   tem = w->contents;
    if (NILP (tem))
      error ("Window is deleted");
    else
@@@ -3331,8 -3322,8 +3323,8 @@@ displaying that buffer.  */
        struct window *w = XWINDOW (object);
        mark_window_display_accurate (object, 0);
        w->update_mode_line = 1;
-       if (BUFFERP (w->buffer))
-       XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
+       if (BUFFERP (w->contents))
+       XBUFFER (w->contents)->prevent_redisplay_optimizations_p = 1;
        ++update_mode_lines;
        return Qt;
      }
@@@ -3401,7 -3392,7 +3393,7 @@@ temp_output_buffer_show (register Lisp_
          record_unwind_protect (Fset_buffer, prev_buffer);
          record_unwind_protect (select_window_norecord, prev_window);
          Fselect_window (window, Qt);
-         Fset_buffer (w->buffer);
+         Fset_buffer (w->contents);
          Frun_hooks (1, &Qtemp_buffer_show_hook);
          unbind_to (count, Qnil);
        }
@@@ -3422,7 -3413,7 +3414,7 @@@ make_parent_window (Lisp_Object window
    memcpy ((char *) p + sizeof (struct vectorlike_header),
          (char *) o + sizeof (struct vectorlike_header),
          word_size * VECSIZE (struct window));
-   /* P's buffer slot may change from nil to a buffer.  */
+   /* P's buffer slot may change from nil to a buffer...  */
    adjust_window_count (p, 1);
    XSETWINDOW (parent, p);
  
    wset_next (o, Qnil);
    wset_prev (o, Qnil);
    wset_parent (o, parent);
-   wset_hchild (p, horflag ? window : Qnil);
-   wset_vchild (p, horflag ? Qnil : window);
+   /* ...but now P becomes an internal window.  */
    wset_start (p, Qnil);
    wset_pointm (p, Qnil);
    wset_buffer (p, Qnil);
+   wset_combination (p, horflag, window);
    wset_combination_limit (p, Qnil);
    wset_window_parameters (p, Qnil);
  }
@@@ -3525,10 -3515,10 +3516,10 @@@ window_resize_check (struct window *w, 
  {
    struct window *c;
  
-   if (!NILP (w->vchild))
+   if (WINDOW_VERTICAL_COMBINATION_P (w))
      /* W is a vertical combination.  */
      {
-       c = XWINDOW (w->vchild);
+       c = XWINDOW (w->contents);
        if (horflag)
        /* All child windows of W must have the same width as W.  */
        {
          return (sum_of_sizes == XINT (w->new_total));
        }
      }
-   else if (!NILP (w->hchild))
+   else if (WINDOW_HORIZONTAL_COMBINATION_P (w))
      /* W is a horizontal combination.  */
      {
-       c = XWINDOW (w->hchild);
+       c = XWINDOW (w->contents);
        if (horflag)
        /* The sum of the widths of the child windows of W must equal W's
           width.  */
@@@ -3626,10 -3616,10 +3617,10 @@@ window_resize_apply (struct window *w, 
        pos = w->top_line;
      }
  
-   if (!NILP (w->vchild))
+   if (WINDOW_VERTICAL_COMBINATION_P (w))
      /* W is a vertical combination.  */
      {
-       c = XWINDOW (w->vchild);
+       c = XWINDOW (w->contents);
        while (c)
        {
          if (horflag)
          c = NILP (c->next) ? 0 : XWINDOW (c->next);
        }
      }
-   else if (!NILP (w->hchild))
+   else if (WINDOW_HORIZONTAL_COMBINATION_P (w))
      /* W is a horizontal combination.  */
      {
-       c = XWINDOW (w->hchild);
+       c = XWINDOW (w->contents);
        while (c)
        {
          if (horflag)
@@@ -3728,7 -3718,7 +3719,7 @@@ resize_frame_windows (struct frame *f, 
                        ? 1 : 0)));
  
    r->top_line = FRAME_TOP_MARGIN (f);
-   if (NILP (r->vchild) && NILP (r->hchild))
+   if (WINDOW_LEAF_P (r))
      /* For a leaf root window just set the size.  */
      if (horflag)
        r->total_cols = new_size;
@@@ -3843,9 -3833,9 +3834,9 @@@ set correctly.  See the code of `split-
    combination_limit =
      EQ (Vwindow_combination_limit, Qt)
      || NILP (o->parent)
-     || NILP (horflag
-            ? (XWINDOW (o->parent)->hchild)
-            : (XWINDOW (o->parent)->vchild));
+     || (horflag
+       ? WINDOW_VERTICAL_COMBINATION_P (XWINDOW (o->parent))
+       : WINDOW_HORIZONTAL_COMBINATION_P (XWINDOW (o->parent)));
  
    /* We need a live reference window to initialize some parameters.  */
    if (WINDOW_LIVE_P (old))
    n = XWINDOW (new);
    wset_frame (n, frame);
    wset_parent (n, o->parent);
-   wset_vchild (n, Qnil);
-   wset_hchild (n, Qnil);
  
    if (EQ (side, Qabove) || EQ (side, Qleft))
      {
        wset_prev (n, o->prev);
        if (NILP (n->prev))
-       if (horflag)
-         wset_hchild (p, new);
-       else
-         wset_vchild (p, new);
+       wset_combination (p, horflag, new);
        else
        wset_next (XWINDOW (n->prev), new);
        wset_next (n, old);
    adjust_glyphs (f);
    /* Set buffer of NEW to buffer of reference window.  Don't run
       any hooks.  */
-   set_window_buffer (new, r->buffer, 0, 1);
+   set_window_buffer (new, r->contents, 0, 1);
    unblock_input ();
  
    /* Maybe we should run the scroll functions in Elisp (which already
@@@ -3996,13 -3981,11 +3982,11 @@@ Signal an error when WINDOW is the onl
    register Lisp_Object parent, sibling, frame, root;
    struct window *w, *p, *s, *r;
    struct frame *f;
-   bool horflag;
-   int before_sibling = 0;
+   bool horflag, before_sibling = 0;
  
    w = decode_any_window (window);
    XSETWINDOW (window, w);
-   if (NILP (w->buffer)
-       && NILP (w->hchild) && NILP (w->vchild))
+   if (NILP (w->contents))
      /* It's a no-op to delete an already deleted window.  */
      return Qnil;
  
      error ("Attempt to delete sole window of parent");
  
    p = XWINDOW (parent);
-   horflag = NILP (p->vchild);
+   horflag = WINDOW_HORIZONTAL_COMBINATION_P (p);
  
    frame = WINDOW_FRAME (w);
    f = XFRAME (frame);
        sibling = w->next;
        s = XWINDOW (sibling);
        wset_prev (s, Qnil);
-       if (horflag)
-       wset_hchild (p, sibling);
-       else
-       wset_vchild (p, sibling);
+       wset_combination (p, horflag, sibling);
      }
    else
      /* Get SIBLING above (on the left of) WINDOW.  */
  
        /* Block input.  */
        block_input ();
 +#ifdef HAVE_XWIDGETS
 +      xwidget_view_delete_all_in_window(w);
 +#endif
        window_resize_apply (p, horflag);
  
        /* If this window is referred to by the dpyinfo's mouse
        wset_next (w, Qnil);  /* Don't delete w->next too.  */
        free_window_matrices (w);
  
-       if (!NILP (w->vchild))
+       if (WINDOWP (w->contents))
        {
-         delete_all_child_windows (w->vchild);
-         wset_vchild (w, Qnil);
+         delete_all_child_windows (w->contents);
+         wset_combination (w, 0, Qnil);
        }
-       else if (!NILP (w->hchild))
-       {
-         delete_all_child_windows (w->hchild);
-         wset_hchild (w, Qnil);
-       }
-       else if (!NILP (w->buffer))
+       else
        {
          unshow_buffer (w);
          unchain_marker (XMARKER (w->pointm));
          wset_normal_cols (s, p->normal_cols);
          wset_normal_lines (s, p->normal_lines);
          /* Mark PARENT as deleted.  */
-         wset_vchild (p, Qnil);
-         wset_hchild (p, Qnil);
+         wset_combination (p, 0, Qnil);
          /* Try to merge SIBLING into its new parent.  */
          recombine_windows (sibling);
        }
        if (before_sibling)
        {
          wset_prev (s, window);
-         if (horflag)
-           wset_hchild (p, window);
-         else
-           wset_vchild (p, window);
+         wset_combination (p, horflag, window);
        }
        else
        {
@@@ -4303,10 -4271,8 +4275,8 @@@ mark_window_cursors_off (struct window 
  {
    while (w)
      {
-       if (!NILP (w->hchild))
-       mark_window_cursors_off (XWINDOW (w->hchild));
-       else if (!NILP (w->vchild))
-       mark_window_cursors_off (XWINDOW (w->vchild));
+       if (WINDOWP (w->contents))
+       mark_window_cursors_off (XWINDOW (w->contents));
        else
        w->phys_cursor_on_p = 0;
  
@@@ -4325,8 -4291,7 +4295,7 @@@ window_internal_height (struct window *
    if (!MINI_WINDOW_P (w))
      {
        if (!NILP (w->parent)
-         || !NILP (w->vchild)
-         || !NILP (w->hchild)
+         || WINDOWP (w->contents)
          || !NILP (w->next)
          || !NILP (w->prev)
          || WINDOW_WANTS_MODELINE_P (w))
@@@ -4465,7 -4430,7 +4434,7 @@@ window_scroll_pixel_based (Lisp_Object 
                  else
                    spos = min (XINT (Fline_end_position (Qnil)) + 1, ZV);
                  set_marker_restricted (w->start, make_number (spos),
-                                        w->buffer);
+                                        w->contents);
                  w->start_at_line_beg = 1;
                  w->update_mode_line = 1;
                  w->last_modified = 0;
  
        /* If control gets here, then we vscrolled.  */
  
-       XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
+       XBUFFER (w->contents)->prevent_redisplay_optimizations_p = 1;
  
        /* Don't try to change the window start below.  */
        vscrolled = 1;
        }
  
        /* Set the window start, and set up the window for redisplay.  */
-       set_marker_restricted_both (w->start, w->buffer, IT_CHARPOS (it),
+       set_marker_restricted_both (w->start, w->contents, IT_CHARPOS (it),
                                  IT_BYTEPOS (it));
        bytepos = marker_byte_position (w->start);
        w->start_at_line_beg = (pos == BEGV || FETCH_BYTE (bytepos - 1) == '\n');
@@@ -4809,7 -4774,7 +4778,7 @@@ window_scroll_line_based (Lisp_Object w
        int this_scroll_margin =
        max (0, min (scroll_margin, w->total_lines / 4));
  
-       set_marker_restricted_both (w->start, w->buffer, pos, pos_byte);
+       set_marker_restricted_both (w->start, w->contents, pos, pos_byte);
        w->start_at_line_beg = !NILP (bolp);
        w->update_mode_line = 1;
        w->last_modified = 0;
@@@ -4903,10 -4868,10 +4872,10 @@@ scroll_command (Lisp_Object n, int dire
  
    /* If selected window's buffer isn't current, make it current for
       the moment.  But don't screw up if window_scroll gets an error.  */
-   if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer)
+   if (XBUFFER (XWINDOW (selected_window)->contents) != current_buffer)
      {
        record_unwind_protect (save_excursion_restore, save_excursion_save ());
-       Fset_buffer (XWINDOW (selected_window)->buffer);
+       Fset_buffer (XWINDOW (selected_window)->contents);
  
        /* Make redisplay consider other windows than just selected_window.  */
        ++windows_or_buffers_changed;
@@@ -5021,7 -4986,7 +4990,7 @@@ specifies the window to scroll.  This t
    record_unwind_protect (save_excursion_restore, save_excursion_save ());
    ++windows_or_buffers_changed;
  
-   Fset_buffer (w->buffer);
+   Fset_buffer (w->contents);
    SET_PT_BOTH (marker_position (w->pointm), marker_byte_position (w->pointm));
  
    if (NILP (arg))
@@@ -5115,10 -5080,10 +5084,10 @@@ displayed_window_lines (struct window *
    int bottom_y;
    void *itdata = NULL;
  
-   if (XBUFFER (w->buffer) != current_buffer)
+   if (XBUFFER (w->contents) != current_buffer)
      {
        old_buffer = current_buffer;
-       set_buffer_internal (XBUFFER (w->buffer));
+       set_buffer_internal (XBUFFER (w->contents));
      }
    else
      old_buffer = NULL;
@@@ -5180,7 -5145,7 +5149,7 @@@ and redisplay normally--don't erase an
    (register Lisp_Object arg)
  {
    struct window *w = XWINDOW (selected_window);
-   struct buffer *buf = XBUFFER (w->buffer);
+   struct buffer *buf = XBUFFER (w->contents);
    struct buffer *obuf = current_buffer;
    int center_p = 0;
    ptrdiff_t charpos, bytepos;
      }
  
    /* Set the new window start.  */
-   set_marker_both (w->start, w->buffer, charpos, bytepos);
+   set_marker_both (w->start, w->contents, charpos, bytepos);
    w->window_end_valid = 0;
  
    w->optional_new_start = 1;
@@@ -5390,9 -5355,8 +5359,8 @@@ zero means top of window, negative mean
    int this_scroll_margin;
  #endif
  
-   if (!(BUFFERP (w->buffer)
-       && XBUFFER (w->buffer) == current_buffer))
-     /* This test is needed to make sure PT/PT_BYTE make sense in w->buffer
+   if (!(BUFFERP (w->contents) && XBUFFER (w->contents) == current_buffer))
+     /* This test is needed to make sure PT/PT_BYTE make sense in w->contents
         when passed below to set_marker_both.  */
      error ("move-to-window-line called from unrelated buffer");
  
      {
        int height = window_internal_height (w);
        Fvertical_motion (make_number (- (height / 2)), window);
-       set_marker_both (w->start, w->buffer, PT, PT_BYTE);
+       set_marker_both (w->start, w->contents, PT, PT_BYTE);
        w->start_at_line_beg = !NILP (Fbolp ());
        w->force_start = 1;
      }
@@@ -5552,9 -5516,9 +5520,9 @@@ the return value is nil.  Otherwise th
           window-point of the final-selected-window to the window-point of
           the current-selected-window.  So we have to be careful which
           point of the current-buffer we copy into old_point.  */
-       if (EQ (XWINDOW (data->current_window)->buffer, new_current_buffer)
+       if (EQ (XWINDOW (data->current_window)->contents, new_current_buffer)
            && WINDOWP (selected_window)
-           && EQ (XWINDOW (selected_window)->buffer, new_current_buffer)
+           && EQ (XWINDOW (selected_window)->contents, new_current_buffer)
            && !EQ (selected_window, data->current_window))
          old_point = marker_position (XWINDOW (data->current_window)->pointm);
        else
           So if possible we want this arbitrary choice of "which point" to
           be the one from the to-be-selected-window so as to prevent this
           window's cursor from being copied from another window.  */
-       if (EQ (XWINDOW (data->current_window)->buffer, new_current_buffer)
+       if (EQ (XWINDOW (data->current_window)->contents, new_current_buffer)
            /* If current_window = selected_window, its point is in BUF_PT.  */
            && !EQ (selected_window, data->current_window))
          old_point = marker_position (XWINDOW (data->current_window)->pointm);
          p = SAVED_WINDOW_N (saved_windows, k);
          window = p->window;
          w = XWINDOW (window);
-         if (!NILP (w->buffer)
-             && !EQ (w->buffer, p->buffer)
+         if (BUFFERP (w->contents)
+             && !EQ (w->contents, p->buffer)
              && BUFFER_LIVE_P (XBUFFER (p->buffer)))
            /* If a window we restore gets another buffer, record the
               window's old buffer.  */
         window holds garbage.)  We do this now, before
         restoring the window contents, and prevent it from
         being done later on when we select a new window.  */
-       if (! NILP (XWINDOW (selected_window)->buffer))
+       if (! NILP (XWINDOW (selected_window)->contents))
        {
          w = XWINDOW (selected_window);
          set_marker_both (w->pointm,
-                          w->buffer,
-                          BUF_PT (XBUFFER (w->buffer)),
-                          BUF_PT_BYTE (XBUFFER (w->buffer)));
+                          w->contents,
+                          BUF_PT (XBUFFER (w->contents)),
+                          BUF_PT_BYTE (XBUFFER (w->contents)));
        }
  
        windows_or_buffers_changed++;
            {
              wset_prev (w, Qnil);
              if (!NILP (w->parent))
-               {
-                 if (XINT (p->total_cols) == XWINDOW (w->parent)->total_cols)
-                   {
-                     wset_vchild (XWINDOW (w->parent), p->window);
-                     wset_hchild (XWINDOW (w->parent), Qnil);
-                   }
-                 else
-                   {
-                     wset_hchild (XWINDOW (w->parent), p->window);
-                     wset_vchild (XWINDOW (w->parent), Qnil);
-                   }
-               }
+               wset_combination (XWINDOW (w->parent),
+                                 (XINT (p->total_cols)
+                                  != XWINDOW (w->parent)->total_cols),
+                                 p->window);
            }
  
          /* If we squirreled away the buffer, restore it now.  */
          w->last_modified = 0;
          w->last_overlay_modified = 0;
  
-         /* Reinstall the saved buffer and pointers into it.  */
-         if (NILP (p->buffer))
-           /* An internal window.  */
-           wset_buffer (w, p->buffer);
-         else if (BUFFER_LIVE_P (XBUFFER (p->buffer)))
+         if (BUFFERP (p->buffer) && BUFFER_LIVE_P (XBUFFER (p->buffer)))
            /* If saved buffer is alive, install it.  */
            {
              wset_buffer (w, p->buffer);
              w->start_at_line_beg = !NILP (p->start_at_line_beg);
-             set_marker_restricted (w->start, p->start, w->buffer);
+             set_marker_restricted (w->start, p->start, w->contents);
              set_marker_restricted (w->pointm, p->pointm,
-                                    w->buffer);
-             Fset_marker (BVAR (XBUFFER (w->buffer), mark),
-                          p->mark, w->buffer);
+                                    w->contents);
+             Fset_marker (BVAR (XBUFFER (w->contents), mark),
+                          p->mark, w->contents);
  
              /* As documented in Fcurrent_window_configuration, don't
                 restore the location of point in the buffer which was
                  && XBUFFER (p->buffer) == current_buffer)
                Fgoto_char (w->pointm);
             }
-          else if (!NILP (w->buffer)
-                   && BUFFER_LIVE_P (XBUFFER (w->buffer)))
-            /* Keep window's old buffer; make sure the markers are
-               real.  */
-            {
-              /* Set window markers at start of visible range.  */
-              if (XMARKER (w->start)->buffer == 0)
-                set_marker_restricted_both (w->start, w->buffer, 0, 0);
-              if (XMARKER (w->pointm)->buffer == 0)
-                set_marker_restricted_both
-                  (w->pointm, w->buffer,
-                   BUF_PT (XBUFFER (w->buffer)),
-                   BUF_PT_BYTE (XBUFFER (w->buffer)));
-              w->start_at_line_beg = 1;
-            }
-         else
-           /* Window has no live buffer, get one.  */
+         else if (BUFFERP (w->contents) && BUFFER_LIVE_P (XBUFFER (w->contents)))
+           /* Keep window's old buffer; make sure the markers are real.  */
+           {
+             /* Set window markers at start of visible range.  */
+             if (XMARKER (w->start)->buffer == 0)
+               set_marker_restricted_both (w->start, w->contents, 0, 0);
+             if (XMARKER (w->pointm)->buffer == 0)
+               set_marker_restricted_both
+                 (w->pointm, w->contents,
+                  BUF_PT (XBUFFER (w->contents)),
+                  BUF_PT_BYTE (XBUFFER (w->contents)));
+             w->start_at_line_beg = 1;
+           }
+         else if (!NILP (w->start))
+           /* Leaf window has no live buffer, get one.  */
            {
              /* Get the buffer via other_buffer_safely in order to
              avoid showing an unimportant buffer and, if necessary, to
              wset_buffer (w, other_buffer_safely (Fcurrent_buffer ()));
              /* This will set the markers to beginning of visible
                 range.  */
-             set_marker_restricted_both (w->start, w->buffer, 0, 0);
-             set_marker_restricted_both (w->pointm, w->buffer, 0, 0);
+             set_marker_restricted_both (w->start, w->contents, 0, 0);
+             set_marker_restricted_both (w->pointm, w->contents, 0, 0);
              w->start_at_line_beg = 1;
              if (!NILP (w->dedicated))
                /* Record this window as dead.  */
        fset_root_window (f, data->root_window);
        /* Arrange *not* to restore point in the buffer that was
         current when the window configuration was saved.  */
-       if (EQ (XWINDOW (data->current_window)->buffer, new_current_buffer))
+       if (EQ (XWINDOW (data->current_window)->contents, new_current_buffer))
        set_marker_restricted (XWINDOW (data->current_window)->pointm,
                               make_number (old_point),
-                              XWINDOW (data->current_window)->buffer);
+                              XWINDOW (data->current_window)->contents);
  
        /* In the following call to `select-window', prevent "swapping out
         point" in the old selected window using the buffer that has
         been restored into it.  We already swapped out that point from
         that window's old buffer.  */
        select_window (data->current_window, Qnil, 1);
-       BVAR (XBUFFER (XWINDOW (selected_window)->buffer), last_selected_window)
+       BVAR (XBUFFER (XWINDOW (selected_window)->contents), last_selected_window)
        = selected_window;
  
        if (NILP (data->focus_frame)
        /* Now, free glyph matrices in windows that were not reused.  */
        for (i = n = 0; i < n_leaf_windows; ++i)
        {
-         if (NILP (leaf_windows[i]->buffer))
-           {
-             /* Assert it's not reused as a combination.  */
-             eassert (NILP (leaf_windows[i]->hchild)
-                      && NILP (leaf_windows[i]->vchild));
-             free_window_matrices (leaf_windows[i]);
-           }
-         else if (EQ (leaf_windows[i]->buffer, new_current_buffer))
+         if (NILP (leaf_windows[i]->contents))
+           free_window_matrices (leaf_windows[i]);
+         else if (EQ (leaf_windows[i]->contents, new_current_buffer))
            ++n;
        }
  
        Fset_buffer (new_current_buffer);
        /* If the new current buffer doesn't appear in the selected
         window, go to its old point (see bug#12208).  */
-       if (!EQ (XWINDOW (data->current_window)->buffer, new_current_buffer))
+       if (!EQ (XWINDOW (data->current_window)->contents, new_current_buffer))
        Fgoto_char (make_number (old_point));
      }
  
  }
  
  
- /* Recursively delete all child windows reachable via the next, vchild,
-    and hchild slots of WINDOW.  */
+ /* If WINDOW is an internal window, recursively delete all child windows
+    reachable via the next and contents slots of WINDOW.  Otherwise setup
+    WINDOW to not show any buffer.  */
  void
  delete_all_child_windows (Lisp_Object window)
  {
      /* Delete WINDOW's siblings (we traverse postorderly).  */
      delete_all_child_windows (w->next);
  
-   if (!NILP (w->vchild))
-     {
-       delete_all_child_windows (w->vchild);
-       wset_vchild (w, Qnil);
-     }
-   else if (!NILP (w->hchild))
+   if (WINDOWP (w->contents))
      {
-       delete_all_child_windows (w->hchild);
-       wset_hchild (w, Qnil);
+       delete_all_child_windows (w->contents);
+       wset_combination (w, 0, Qnil);
      }
-   else if (!NILP (w->buffer))
+   else if (BUFFERP (w->contents))
      {
        unshow_buffer (w);
        unchain_marker (XMARKER (w->pointm));
        /* Since combination limit makes sense for an internal windows
         only, we use this slot to save the buffer for the sake of
         possible resurrection in Fset_window_configuration.  */
-       wset_combination_limit (w, w->buffer);
+       wset_combination_limit (w, w->contents);
        wset_buffer (w, Qnil);
      }
  
@@@ -5948,10 -5890,8 +5894,8 @@@ count_windows (register struct window *
    register int count = 1;
    if (!NILP (window->next))
      count += count_windows (XWINDOW (window->next));
-   if (!NILP (window->vchild))
-     count += count_windows (XWINDOW (window->vchild));
-   if (!NILP (window->hchild))
-     count += count_windows (XWINDOW (window->hchild));
+   if (WINDOWP (window->contents))
+     count += count_windows (XWINDOW (window->contents));
    return count;
  }
  
@@@ -5963,10 -5903,8 +5907,8 @@@ get_leaf_windows (struct window *w, str
  {
    while (w)
      {
-       if (!NILP (w->hchild))
-       i = get_leaf_windows (XWINDOW (w->hchild), flat, i);
-       else if (!NILP (w->vchild))
-       i = get_leaf_windows (XWINDOW (w->vchild), flat, i);
+       if (WINDOWP (w->contents))
+       i = get_leaf_windows (XWINDOW (w->contents), flat, i);
        else
        flat[i++] = w;
  
@@@ -6006,7 -5944,7 +5948,7 @@@ get_phys_cursor_glyph (struct window *w
        hpos = row->used[TEXT_AREA] - 1;
      }
  
-   if (hpos >= 0 && hpos < row->used[TEXT_AREA])
+   if (0 <= hpos && hpos < row->used[TEXT_AREA])
      glyph = row->glyphs[TEXT_AREA] + hpos;
    else
      glyph = NULL;
@@@ -6022,14 -5960,14 +5964,14 @@@ save_window_save (Lisp_Object window, s
    register struct window *w;
    register Lisp_Object tem, pers, par;
  
-   for (;!NILP (window); window = w->next)
+   for (; !NILP (window); window = w->next)
      {
        p = SAVED_WINDOW_N (vector, i);
        w = XWINDOW (window);
  
        wset_temslot (w, make_number (i)); i++;
        p->window = window;
-       p->buffer = w->buffer;
+       p->buffer = (WINDOW_LEAF_P (w) ? w->contents : Qnil);
        p->left_col = make_number (w->left_col);
        p->top_line = make_number (w->top_line);
        p->total_cols = make_number (w->total_cols);
            }
        }
  
-       if (!NILP (w->buffer))
+       if (BUFFERP (w->contents))
        {
          /* Save w's value of point in the window configuration.  If w
             is the selected window, then get the value of point from
             the buffer; pointm is garbage in the selected window.  */
          if (EQ (window, selected_window))
-           p->pointm = build_marker (XBUFFER (w->buffer),
-                                     BUF_PT (XBUFFER (w->buffer)),
-                                     BUF_PT_BYTE (XBUFFER (w->buffer)));
+           p->pointm = build_marker (XBUFFER (w->contents),
+                                     BUF_PT (XBUFFER (w->contents)),
+                                     BUF_PT_BYTE (XBUFFER (w->contents)));
          else
            p->pointm = Fcopy_marker (w->pointm, Qnil);
          XMARKER (p->pointm)->insertion_type
          p->start = Fcopy_marker (w->start, Qnil);
          p->start_at_line_beg = w->start_at_line_beg ? Qt : Qnil;
  
-         tem = BVAR (XBUFFER (w->buffer), mark);
+         tem = BVAR (XBUFFER (w->contents), mark);
          p->mark = Fcopy_marker (tem, Qnil);
        }
        else
        else
        p->prev = XWINDOW (w->prev)->temslot;
  
-       if (!NILP (w->vchild))
-       i = save_window_save (w->vchild, vector, i);
-       if (!NILP (w->hchild))
-       i = save_window_save (w->hchild, vector, i);
+       if (WINDOWP (w->contents))
+       i = save_window_save (w->contents, vector, i);
      }
  
    return i;
@@@ -6454,7 -6390,7 +6394,7 @@@ If PIXELS-P is non-nil, the return valu
            adjust_glyphs (f);
  
          /* Prevent redisplay shortcuts.  */
-         XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
+         XBUFFER (w->contents)->prevent_redisplay_optimizations_p = 1;
        }
      }
  
@@@ -6488,10 -6424,8 +6428,8 @@@ foreach_window_1 (struct window *w, in
  
    for (cont = 1; w && cont;)
      {
-       if (!NILP (w->hchild))
-       cont = foreach_window_1 (XWINDOW (w->hchild), fn, user_data);
-       else if (!NILP (w->vchild))
-       cont = foreach_window_1 (XWINDOW (w->vchild), fn, user_data);
+       if (WINDOWP (w->contents))
+       cont = foreach_window_1 (XWINDOW (w->contents), fn, user_data);
        else
        cont = fn (w, user_data);
  
diff --combined src/xdisp.c
index bd68b286f4e8d37913965f900e52d7fd880cb7a5,41214880a562434237c57aa84d99850dc67e6ebe..f8a9fd57dc1f698c699bff7b4b0e117cb953179e
@@@ -314,9 -314,7 +314,9 @@@ along with GNU Emacs.  If not, see <htt
  #endif
  
  #include "font.h"
 -
 +#ifdef HAVE_XWIDGETS
 +#include "xwidget.h"
 +#endif
  #ifndef FRAME_X_OUTPUT
  #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
  #endif
@@@ -582,7 -580,7 +582,7 @@@ static struct glyph scratch_glyphs[MAX_
  
  /* Ascent and height of the last line processed by move_it_to.  */
  
- static int last_max_ascent, last_height;
+ static int last_height;
  
  /* Non-zero if there's a help-echo in the echo area.  */
  
@@@ -891,9 -889,6 +891,9 @@@ static int next_element_from_c_string (
  static int next_element_from_buffer (struct it *);
  static int next_element_from_composition (struct it *);
  static int next_element_from_image (struct it *);
 +#ifdef HAVE_XWIDGETS
 +static int next_element_from_xwidget(struct it *);
 +#endif
  static int next_element_from_stretch (struct it *);
  static void load_overlay_strings (struct it *, ptrdiff_t);
  static int init_from_display_pos (struct it *, struct window *,
@@@ -1288,10 -1283,10 +1288,10 @@@ pos_visible_p (struct window *w, ptrdif
    if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w))))
      return visible_p;
  
-   if (XBUFFER (w->buffer) != current_buffer)
+   if (XBUFFER (w->contents) != current_buffer)
      {
        old_buffer = current_buffer;
-       set_buffer_internal_1 (XBUFFER (w->buffer));
+       set_buffer_internal_1 (XBUFFER (w->contents));
      }
  
    SET_TEXT_POS_FROM_MARKER (top, w->start);
@@@ -4463,7 -4458,7 +4463,7 @@@ handle_display_prop (struct it *it
       if it was a text property.  */
  
    if (!STRINGP (it->string))
-     object = it->w->buffer;
+     object = it->w->contents;
  
    display_replaced_p = handle_display_spec (it, propval, object, overlay,
                                            position, bufpos,
@@@ -4499,9 -4494,6 +4499,9 @@@ handle_display_spec (struct it *it, Lis
    if (CONSP (spec)
        /* Simple specifications.  */
        && !EQ (XCAR (spec), Qimage)
 +#ifdef HAVE_XWIDGETS
 +      && !EQ (XCAR (spec), Qxwidget)
 +#endif
        && !EQ (XCAR (spec), Qspace)
        && !EQ (XCAR (spec), Qwhen)
        && !EQ (XCAR (spec), Qslice)
@@@ -4874,7 -4866,7 +4874,7 @@@ handle_single_display_spec (struct it *
          it->what = IT_IMAGE;
          it->image_id = -1; /* no image */
          it->position = start_pos;
-         it->object = NILP (object) ? it->w->buffer : object;
+         it->object = NILP (object) ? it->w->contents : object;
          it->method = GET_FROM_IMAGE;
          it->from_overlay = Qnil;
          it->face_id = face_id;
               || ((it ? FRAME_WINDOW_P (it->f) : frame_window_p)
                 && valid_image_p (value))
  #endif /* not HAVE_WINDOW_SYSTEM */
 -             || (CONSP (value) && EQ (XCAR (value), Qspace)));
 +             || (CONSP (value) && EQ (XCAR (value), Qspace))
 +#ifdef HAVE_XWIDGETS
 +             || XWIDGETP(value)
 +#endif
 +             );
  
    if (valid_p && !display_replaced_p)
      {
          *position = it->position = start_pos;
          retval = 1 + (it->area == TEXT_AREA);
        }
-         it->object = NILP (object) ? it->w->buffer : object;
 +#ifdef HAVE_XWIDGETS
 +      else if (XWIDGETP(value))
 +      {
 +          //printf("handle_single_display_spec: im an xwidget!!\n");
 +          it->what = IT_XWIDGET;
 +          it->method = GET_FROM_XWIDGET;
 +          it->position = start_pos;
++        it->object = NILP (object) ? it->w->contents : object;
 +        *position = start_pos;
 +
 +          it->xwidget = lookup_xwidget(value);
 +      }
 +#endif      
  #ifdef HAVE_WINDOW_SYSTEM
        else
        {
          it->what = IT_IMAGE;
          it->image_id = lookup_image (it->f, value);
          it->position = start_pos;
-         it->object = NILP (object) ? it->w->buffer : object;
+         it->object = NILP (object) ? it->w->contents : object;
          it->method = GET_FROM_IMAGE;
  
          /* Say that we haven't consumed the characters with
@@@ -5764,11 -5739,6 +5764,11 @@@ push_it (struct it *it, struct text_po
      case GET_FROM_STRETCH:
        p->u.stretch.object = it->object;
        break;
 +#ifdef HAVE_XWIDGETS
 +    case GET_FROM_XWIDGET:
 +      p->u.xwidget.object = it->object;
 +      break;
 +#endif      
      }
    p->position = position ? *position : it->position;
    p->current = it->current;
@@@ -5862,16 -5832,11 +5862,16 @@@ pop_it (struct it *it
        it->object = p->u.image.object;
        it->slice = p->u.image.slice;
        break;
 +#ifdef HAVE_XWIDGETS
 +    case GET_FROM_XWIDGET:
 +      it->object = p->u.xwidget.object;
 +      break;
 +#endif
      case GET_FROM_STRETCH:
        it->object = p->u.stretch.object;
        break;
      case GET_FROM_BUFFER:
-       it->object = it->w->buffer;
+       it->object = it->w->contents;
        break;
      case GET_FROM_STRING:
        it->object = it->string;
        else
        {
          it->method = GET_FROM_BUFFER;
-         it->object = it->w->buffer;
+         it->object = it->w->contents;
        }
      }
    it->end_charpos = p->end_charpos;
@@@ -6325,7 -6290,7 +6325,7 @@@ reseat_1 (struct it *it, struct text_po
    IT_STRING_BYTEPOS (*it) = -1;
    it->string = Qnil;
    it->method = GET_FROM_BUFFER;
-   it->object = it->w->buffer;
+   it->object = it->w->contents;
    it->area = TEXT_AREA;
    it->multibyte_p = !NILP (BVAR (current_buffer, enable_multibyte_characters));
    it->sp = 0;
@@@ -6519,9 -6484,6 +6519,9 @@@ static int (* get_next_element[NUM_IT_M
    next_element_from_c_string,
    next_element_from_image,
    next_element_from_stretch
 +#ifdef HAVE_XWIDGETS
 +  ,next_element_from_xwidget
 +#endif  
  };
  
  #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
@@@ -7179,7 -7141,7 +7179,7 @@@ set_iterator_to_next (struct it *it, in
          else
            {
              it->method = GET_FROM_BUFFER;
-             it->object = it->w->buffer;
+             it->object = it->w->contents;
            }
  
          it->dpvec = NULL;
  
      case GET_FROM_IMAGE:
      case GET_FROM_STRETCH:
 +#ifdef HAVE_XWIDGETS
 +    case GET_FROM_XWIDGET:
 +
        /* The position etc with which we have to proceed are on
         the stack.  The position may be at the end of a string,
           if the `display' property takes up the whole string.  */
        if (it->method == GET_FROM_STRING)
        goto consider_string_end;
        break;
 -
 +#endif
      default:
        /* There are no other methods defined, so this should be a bug.  */
        emacs_abort ();
@@@ -7755,7 -7714,7 +7755,7 @@@ next_element_from_ellipsis (struct it *
         setting face_before_selective_p.  */
        it->saved_face_id = it->face_id;
        it->method = GET_FROM_BUFFER;
-       it->object = it->w->buffer;
+       it->object = it->w->contents;
        reseat_at_next_visible_line_start (it, 1);
        it->face_before_selective_p = 1;
      }
@@@ -7777,19 -7736,6 +7777,19 @@@ next_element_from_image (struct it *it
    return 1;
  }
  
 +#ifdef HAVE_XWIDGETS
 +/* im not sure about this FIXME JAVE*/
 +static int
 +next_element_from_xwidget (struct it *it)
 +{
 +  it->what = IT_XWIDGET;
 +  //assert_valid_xwidget_id(it->xwidget_id,"next_element_from_xwidget");
 +  //this is shaky because why do we set "what" if we dont set the other parts??
 +  //printf("xwidget_id %d: in next_element_from_xwidget: FIXME \n", it->xwidget_id);
 +  return 1;
 +}
 +#endif
 +
  
  /* Fill iterator IT with next display element from a stretch glyph
     property.  IT->object is the value of the text property.  Value is
@@@ -8032,7 -7978,7 +8032,7 @@@ next_element_from_buffer (struct it *it
  
        /* Record what we have and where it came from.  */
        it->what = IT_CHARACTER;
-       it->object = it->w->buffer;
+       it->object = it->w->contents;
        it->position = it->current.pos;
  
        /* Normally we return the character found above, except when we
@@@ -8138,7 -8084,7 +8138,7 @@@ next_element_from_composition (struct i
          return 0;
        }
        it->position = it->current.pos;
-       it->object = it->w->buffer;
+       it->object = it->w->contents;
        it->c = composition_update_it (&it->cmp_it, IT_CHARPOS (*it),
                                     IT_BYTEPOS (*it), Qnil);
      }
@@@ -8979,7 -8925,6 +8979,6 @@@ move_it_to (struct it *it, ptrdiff_t to
        it->current_y += it->max_ascent + it->max_descent;
        ++it->vpos;
        last_height = it->max_ascent + it->max_descent;
-       last_max_ascent = it->max_ascent;
        it->max_ascent = it->max_descent = 0;
      }
  
        it->current_y += it->max_ascent + it->max_descent;
        ++it->vpos;
        last_height = it->max_ascent + it->max_descent;
-       last_max_ascent = it->max_ascent;
      }
  
    if (backup_data)
@@@ -10048,7 -9992,7 +10046,7 @@@ with_echo_area_buffer_unwind_data (stru
    Vwith_echo_area_save_vector = Qnil;
  
    if (NILP (vector))
-     vector = Fmake_vector (make_number (7), Qnil);
+     vector = Fmake_vector (make_number (9), Qnil);
  
    XSETBUFFER (tmp, current_buffer); ASET (vector, i, tmp); ++i;
    ASET (vector, i, Vdeactivate_mark); ++i;
    if (w)
      {
        XSETWINDOW (tmp, w); ASET (vector, i, tmp); ++i;
-       ASET (vector, i, w->buffer); ++i;
+       ASET (vector, i, w->contents); ++i;
        ASET (vector, i, make_number (marker_position (w->pointm))); ++i;
        ASET (vector, i, make_number (marker_byte_position (w->pointm))); ++i;
+       ASET (vector, i, make_number (marker_position (w->start))); ++i;
+       ASET (vector, i, make_number (marker_byte_position (w->start))); ++i;
      }
    else
      {
-       int end = i + 4;
+       int end = i + 6;
        for (; i < end; ++i)
        ASET (vector, i, Qnil);
      }
@@@ -10086,16 -10032,18 +10086,18 @@@ unwind_with_echo_area_buffer (Lisp_Obje
    if (WINDOWP (AREF (vector, 3)))
      {
        struct window *w;
-       Lisp_Object buffer, charpos, bytepos;
+       Lisp_Object buffer;
  
        w = XWINDOW (AREF (vector, 3));
        buffer = AREF (vector, 4);
-       charpos = AREF (vector, 5);
-       bytepos = AREF (vector, 6);
  
        wset_buffer (w, buffer);
        set_marker_both (w->pointm, buffer,
-                      XFASTINT (charpos), XFASTINT (bytepos));
+                      XFASTINT (AREF (vector, 5)),
+                      XFASTINT (AREF (vector, 6)));
+       set_marker_both (w->start, buffer,
+                      XFASTINT (AREF (vector, 7)),
+                      XFASTINT (AREF (vector, 8)));
      }
  
    Vwith_echo_area_save_vector = vector;
@@@ -10309,9 -10257,9 +10311,9 @@@ resize_mini_window (struct window *w, i
    eassert (MINI_WINDOW_P (w));
  
    /* By default, start display at the beginning.  */
-   set_marker_both (w->start, w->buffer,
-                  BUF_BEGV (XBUFFER (w->buffer)),
-                  BUF_BEGV_BYTE (XBUFFER (w->buffer)));
+   set_marker_both (w->start, w->contents,
+                  BUF_BEGV (XBUFFER (w->contents)),
+                  BUF_BEGV_BYTE (XBUFFER (w->contents)));
  
    /* Don't resize windows while redisplaying a window; it would
       confuse redisplay functions when the size of the window they are
        struct text_pos start;
        struct buffer *old_current_buffer = NULL;
  
-       if (current_buffer != XBUFFER (w->buffer))
+       if (current_buffer != XBUFFER (w->contents))
        {
          old_current_buffer = current_buffer;
-         set_buffer_internal (XBUFFER (w->buffer));
+         set_buffer_internal (XBUFFER (w->contents));
        }
  
        init_iterator (&it, w, BEGV, BEGV_BYTE, NULL, DEFAULT_FACE_ID);
@@@ -10790,7 -10738,7 +10792,7 @@@ buffer_shared_and_changed (void
  
  /* Nonzero if W doesn't reflect the actual state of current buffer due
     to its text or overlays change.  FIXME: this may be called when
-    XBUFFER (w->buffer) != current_buffer, which looks suspicious.  */
+    XBUFFER (w->contents) != current_buffer, which looks suspicious.  */
  
  static int
  window_outdated (struct window *w)
  static int
  window_buffer_changed (struct window *w)
  {
-   struct buffer *b = XBUFFER (w->buffer);
+   struct buffer *b = XBUFFER (w->contents);
  
    eassert (BUFFER_LIVE_P (b));
  
@@@ -11059,7 -11007,7 +11061,7 @@@ x_consider_frame_title (Lisp_Object fra
  
        Fselect_window (f->selected_window, Qt);
        set_buffer_internal_1
-       (XBUFFER (XWINDOW (f->selected_window)->buffer));
+       (XBUFFER (XWINDOW (f->selected_window)->contents));
        fmt = FRAME_ICONIFIED_P (f) ? Vicon_title_format : Vframe_title_format;
  
        mode_line_target = MODE_LINE_TITLE;
@@@ -11178,7 -11126,7 +11180,7 @@@ prepare_menu_bars (void
            if (windows_or_buffers_changed
              && FRAME_NS_P (f))
              ns_set_doc_edited
-             (f, Fbuffer_modified_p (XWINDOW (f->selected_window)->buffer));
+             (f, Fbuffer_modified_p (XWINDOW (f->selected_window)->contents));
  #endif
          UNGCPRO;
        }
@@@ -11250,7 -11198,7 +11252,7 @@@ update_menu_bar (struct frame *f, int s
  
          specbind (Qinhibit_menubar_update, Qt);
  
-         set_buffer_internal_1 (XBUFFER (w->buffer));
+         set_buffer_internal_1 (XBUFFER (w->contents));
          if (save_match_data)
            record_unwind_save_match_data ();
          if (NILP (Voverriding_local_map_menu_flag))
@@@ -11454,7 -11402,7 +11456,7 @@@ update_tool_bar (struct frame *f, int s
          /* Set current_buffer to the buffer of the selected
             window of the frame, so that we get the right local
             keymaps.  */
-         set_buffer_internal_1 (XBUFFER (w->buffer));
+         set_buffer_internal_1 (XBUFFER (w->contents));
  
          /* Save match data, if we must.  */
          if (save_match_data)
@@@ -12321,10 -12269,8 +12323,8 @@@ hscroll_window_tree (Lisp_Object window
      {
        struct window *w = XWINDOW (window);
  
-       if (WINDOWP (w->hchild))
-       hscrolled_p |= hscroll_window_tree (w->hchild);
-       else if (WINDOWP (w->vchild))
-       hscrolled_p |= hscroll_window_tree (w->vchild);
+       if (WINDOWP (w->contents))
+       hscrolled_p |= hscroll_window_tree (w->contents);
        else if (w->cursor.vpos >= 0)
        {
          int h_margin;
          /* Scroll when cursor is inside this scroll margin.  */
          h_margin = hscroll_margin * WINDOW_FRAME_COLUMN_WIDTH (w);
  
-         if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode, w->buffer))
+         if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode, w->contents))
              /* For left-to-right rows, hscroll when cursor is either
                 (i) inside the right hscroll margin, or (ii) if it is
                 inside the left margin and the window is already
  
              /* Find point in a display of infinite width.  */
              saved_current_buffer = current_buffer;
-             current_buffer = XBUFFER (w->buffer);
+             current_buffer = XBUFFER (w->contents);
  
              if (w == XWINDOW (selected_window))
                pt = PT;
                 redisplay.  */
              if (w->hscroll != hscroll)
                {
-                 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
+                 XBUFFER (w->contents)->prevent_redisplay_optimizations_p = 1;
                  w->hscroll = hscroll;
                  hscrolled_p = 1;
                }
@@@ -12521,9 -12467,9 +12521,9 @@@ debug_method_add (struct window *w, cha
    if (trace_redisplay_p)
      fprintf (stderr, "%p (%s): %s\n",
             w,
-            ((BUFFERP (w->buffer)
-              && STRINGP (BVAR (XBUFFER (w->buffer), name)))
-             ? SSDATA (BVAR (XBUFFER (w->buffer), name))
+            ((BUFFERP (w->contents)
+              && STRINGP (BVAR (XBUFFER (w->contents), name)))
+             ? SSDATA (BVAR (XBUFFER (w->contents), name))
              : "no buffer"),
             method + len);
  }
@@@ -12587,8 -12533,8 +12587,8 @@@ text_outside_line_unchanged_p (struct w
         require to redisplay the whole paragraph.  It might be worthwhile
         to find the paragraph limits and widen the range of redisplayed
         lines to that, but for now just give up this optimization.  */
-       if (!NILP (BVAR (XBUFFER (w->buffer), bidi_display_reordering))
-         && NILP (BVAR (XBUFFER (w->buffer), bidi_paragraph_direction)))
+       if (!NILP (BVAR (XBUFFER (w->contents), bidi_display_reordering))
+         && NILP (BVAR (XBUFFER (w->contents), bidi_paragraph_direction)))
        unchanged_p = 0;
      }
  
@@@ -12811,7 -12757,7 +12811,7 @@@ reconsider_clip_changes (struct window 
       we set b->clip_changed to 1 to force updating the screen.  If
       b->clip_changed has already been set to 1, we can skip this
       check.  */
-   if (!b->clip_changed && BUFFERP (w->buffer) && w->window_end_valid)
+   if (!b->clip_changed && BUFFERP (w->contents) && w->window_end_valid)
      {
        ptrdiff_t pt;
  
        else
        pt = marker_position (w->pointm);
  
-       if ((w->current_matrix->buffer != XBUFFER (w->buffer)
+       if ((w->current_matrix->buffer != XBUFFER (w->contents)
           || pt != w->last_point)
          && check_point_in_composition (w->current_matrix->buffer,
                                         w->last_point,
-                                        XBUFFER (w->buffer), pt))
+                                        XBUFFER (w->contents), pt))
        b->clip_changed = 1;
      }
  }
@@@ -13002,8 -12948,6 +13002,6 @@@ redisplay_internal (void
  
    unbind_to (count1, Qnil);
  
-   FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w->frame)) = -1;
    consider_all_windows_p = (update_mode_lines
                            || buffer_shared_and_changed ()
                            || cursor_type_changed);
       the whole window.  The assignment to this_line_start_pos prevents
       the optimization directly below this if-statement.  */
    if (((!NILP (Vtransient_mark_mode)
-       && !NILP (BVAR (XBUFFER (w->buffer), mark_active)))
+       && !NILP (BVAR (XBUFFER (w->contents), mark_active)))
         != (w->region_showing > 0))
        || (w->region_showing
          && w->region_showing
-         != XINT (Fmarker_position (BVAR (XBUFFER (w->buffer), mark)))))
+         != XINT (Fmarker_position (BVAR (XBUFFER (w->contents), mark)))))
      CHARPOS (this_line_start_pos) = 0;
  
    /* Optimize the case that only the line containing the cursor in the
        && !FRAME_OBSCURED_P (XFRAME (w->frame))
        /* Make sure recorded data applies to current buffer, etc.  */
        && this_line_buffer == current_buffer
-       && current_buffer == XBUFFER (w->buffer)
+       && current_buffer == XBUFFER (w->contents)
        && !w->force_start
        && !w->optional_new_start
        /* Point must be on the line that we have info recorded about.  */
              *w->desired_matrix->method = 0;
              debug_method_add (w, "optimization 1");
  #endif
 +#if HAVE_XWIDGETS
 +              //debug optimization movement issue
 +              //w->desired_matrix->no_scrolling_p = 1;
 +              //*w->desired_matrix->method = 0;
 +              //debug_method_add (w, "optimization 1");
 +#endif
 +
  #ifdef HAVE_WINDOW_SYSTEM
              update_window_fringes (w, 0);
  #endif
               PT == w->last_point
               /* Make sure the cursor was last displayed
                  in this window.  Otherwise we have to reposition it.  */
-              && w->cursor.vpos >= 0
+              && 0 <= w->cursor.vpos
               && w->cursor.vpos < WINDOW_TOTAL_LINES (w))
        {
          if (!must_finish)
        Lisp_Object mini_window = FRAME_MINIBUF_WINDOW (sf);
        struct frame *mini_frame;
  
-       displayed_buffer = XBUFFER (XWINDOW (selected_window)->buffer);
+       displayed_buffer = XBUFFER (XWINDOW (selected_window)->contents);
        /* Use list_of_error, not Qerror, so that
         we catch only errors and don't run the debugger.  */
        internal_condition_case_1 (redisplay_window_1, selected_window,
@@@ -13609,7 -13546,7 +13607,7 @@@ unwind_redisplay (Lisp_Object old_frame
  static void
  mark_window_display_accurate_1 (struct window *w, int accurate_p)
  {
-   struct buffer *b = XBUFFER (w->buffer);
+   struct buffer *b = XBUFFER (w->contents);
  
    w->last_modified = accurate_p ? BUF_MODIFF (b) : 0;
    w->last_overlay_modified = accurate_p ? BUF_OVERLAY_MODIFF (b) : 0;
@@@ -13656,11 -13593,9 +13654,9 @@@ mark_window_display_accurate (Lisp_Obje
    for (; !NILP (window); window = w->next)
      {
        w = XWINDOW (window);
-       if (!NILP (w->vchild))
-       mark_window_display_accurate (w->vchild, accurate_p);
-       else if (!NILP (w->hchild))
-       mark_window_display_accurate (w->hchild, accurate_p);
-       else if (BUFFERP (w->buffer))
+       if (WINDOWP (w->contents))
+       mark_window_display_accurate (w->contents, accurate_p);
+       else
        mark_window_display_accurate_1 (w, accurate_p);
      }
  
@@@ -13717,13 -13652,11 +13713,11 @@@ redisplay_windows (Lisp_Object window
      {
        struct window *w = XWINDOW (window);
  
-       if (!NILP (w->hchild))
-       redisplay_windows (w->hchild);
-       else if (!NILP (w->vchild))
-       redisplay_windows (w->vchild);
-       else if (!NILP (w->buffer))
+       if (WINDOWP (w->contents))
+       redisplay_windows (w->contents);
+       else if (BUFFERP (w->contents))
        {
-         displayed_buffer = XBUFFER (w->buffer);
+         displayed_buffer = XBUFFER (w->contents);
          /* Use list_of_error, not Qerror, so that
             we catch only errors and don't run the debugger.  */
          internal_condition_case_1 (redisplay_window_0, window,
@@@ -14370,7 -14303,7 +14364,7 @@@ set_cursor_from_row (struct window *w, 
          && !MATRIX_ROW_CONTINUATION_LINE_P (row)
          && row->x == 0)
        {
-         this_line_buffer = XBUFFER (w->buffer);
+         this_line_buffer = XBUFFER (w->contents);
  
          CHARPOS (this_line_start_pos)
            = MATRIX_ROW_START_CHARPOS (row) + delta;
@@@ -14406,7 -14339,7 +14400,7 @@@ run_window_scroll_functions (Lisp_Objec
    struct window *w = XWINDOW (window);
    SET_MARKER_FROM_TEXT_POS (w->start, startp);
  
-   if (current_buffer != XBUFFER (w->buffer))
+   if (current_buffer != XBUFFER (w->contents))
      emacs_abort ();
  
    if (!NILP (Vwindow_scroll_functions))
                            make_number (CHARPOS (startp)));
        SET_TEXT_POS_FROM_MARKER (startp, w->start);
        /* In case the hook functions switch buffers.  */
-       set_buffer_internal (XBUFFER (w->buffer));
+       set_buffer_internal (XBUFFER (w->contents));
      }
  
    return startp;
@@@ -15066,7 -14999,7 +15060,7 @@@ try_cursor_movement (Lisp_Object window
              must_scroll = 1;
            }
          else if (rc != CURSOR_MOVEMENT_SUCCESS
-                  && !NILP (BVAR (XBUFFER (w->buffer), bidi_display_reordering)))
+                  && !NILP (BVAR (XBUFFER (w->contents), bidi_display_reordering)))
            {
              struct glyph_row *row1;
  
          else if (scroll_p)
            rc = CURSOR_MOVEMENT_MUST_SCROLL;
          else if (rc != CURSOR_MOVEMENT_SUCCESS
-                  && !NILP (BVAR (XBUFFER (w->buffer), bidi_display_reordering)))
+                  && !NILP (BVAR (XBUFFER (w->contents), bidi_display_reordering)))
            {
              /* With bidi-reordered rows, there could be more than
                 one candidate row whose start and end positions
@@@ -15236,7 -15169,7 +15230,7 @@@ set_vertical_scroll_bar (struct window 
        || (w == XWINDOW (minibuf_window)
          && NILP (echo_area_buffer[0])))
      {
-       struct buffer *buf = XBUFFER (w->buffer);
+       struct buffer *buf = XBUFFER (w->contents);
        whole = BUF_ZV (buf) - BUF_BEGV (buf);
        start = marker_position (w->start) - BUF_BEGV (buf);
        /* I don't think this is guaranteed to be right.  For the
@@@ -15270,7 -15203,7 +15264,7 @@@ redisplay_window (Lisp_Object window, i
  {
    struct window *w = XWINDOW (window);
    struct frame *f = XFRAME (w->frame);
-   struct buffer *buffer = XBUFFER (w->buffer);
+   struct buffer *buffer = XBUFFER (w->contents);
    struct buffer *old = current_buffer;
    struct text_pos lpoint, opoint, startp;
    int update_mode_line;
    SET_TEXT_POS (lpoint, PT, PT_BYTE);
    opoint = lpoint;
  
-   /* W must be a leaf window here.  */
-   eassert (!NILP (w->buffer));
  #ifdef GLYPH_DEBUG
    *w->desired_matrix->method = 0;
  #endif
  
+   /* Make sure that both W's markers are valid.  */
+   eassert (XMARKER (w->start)->buffer == buffer);
+   eassert (XMARKER (w->pointm)->buffer == buffer);
   restart:
    reconsider_clip_changes (w, buffer);
  
        else if ((w != XWINDOW (minibuf_window)
                || minibuf_level == 0)
               /* When buffer is nonempty, redisplay window normally. */
-              && BUF_Z (XBUFFER (w->buffer)) == BUF_BEG (XBUFFER (w->buffer))
+              && BUF_Z (XBUFFER (w->contents)) == BUF_BEG (XBUFFER (w->contents))
               /* Quail displays non-mini buffers in minibuffer window.
                  In that case, redisplay the window normally.  */
-              && !NILP (Fmemq (w->buffer, Vminibuffer_list)))
+              && !NILP (Fmemq (w->contents, Vminibuffer_list)))
        {
          /* W is a mini-buffer window, but it's not active, so clear
             it.  */
       value.  */
    /* Really select the buffer, for the sake of buffer-local
       variables.  */
-   set_buffer_internal_1 (XBUFFER (w->buffer));
+   set_buffer_internal_1 (XBUFFER (w->contents));
  
    current_matrix_up_to_date_p
      = (w->window_end_valid
@@@ -16171,8 -16106,6 +16167,8 @@@ try_window (Lisp_Object window, struct 
    /* Initialize iterator and info to start at POS.  */
    start_display (&it, w, pos);
  
 +
 +  
    /* Display all lines of W.  */
    while (it.current_y < it.last_visible_y)
      {
        if (fonts_changed_p && !(flags & TRY_WINDOW_IGNORE_FONTS_CHANGE))
        return 0;
      }
 +#ifdef HAVE_XWIDGETS_xxx
 + //currently this is needed to detect xwidget movement reliably. or probably not.
 +  printf("try_window\n");
 +    return 0;
 +#endif
  
    /* Don't let the cursor end in the scroll margins.  */
    if ((flags & TRY_WINDOW_CHECK_MARGINS)
@@@ -16280,13 -16208,6 +16276,13 @@@ try_window_reusing_current_matrix (stru
      return 0;
  #endif
  
 +#ifdef HAVE_XWIDGETS_xxx
 + //currently this is needed to detect xwidget movement reliably. or probably not.
 +  printf("try_window_reusing_current_matrix\n");
 +    return 0;
 +#endif
 +
 +
    if (/* This function doesn't handle terminal frames.  */
        !FRAME_WINDOW_P (f)
        /* Don't try to reuse the display if windows have been split
                 bidi-reordered glyph rows.  Let set_cursor_from_row
                 figure out where to put the cursor, and if it fails,
                 give up.  */
-             if (!NILP (BVAR (XBUFFER (w->buffer), bidi_display_reordering)))
+             if (!NILP (BVAR (XBUFFER (w->contents), bidi_display_reordering)))
                {
                  if (!set_cursor_from_row (w, row, w->current_matrix,
                                            0, 0, 0, 0))
@@@ -16904,7 -16825,7 +16900,7 @@@ sync_frame_with_window_matrix_rows (str
  
    /* Preconditions: W must be a leaf window and full-width.  Its frame
       must have a frame matrix.  */
-   eassert (NILP (w->hchild) && NILP (w->vchild));
+   eassert (BUFFERP (w->contents));
    eassert (WINDOW_FULL_WIDTH_P (w));
    eassert (!FRAME_WINDOW_P (f));
  
@@@ -16946,7 -16867,7 +16942,7 @@@ row_containing_pos (struct window *w, p
  {
    struct glyph_row *row = start;
    struct glyph_row *best_row = NULL;
-   ptrdiff_t mindif = BUF_ZV (XBUFFER (w->buffer)) + 1;
+   ptrdiff_t mindif = BUF_ZV (XBUFFER (w->contents)) + 1;
    int last_y;
  
    /* If we happen to start on a header-line, skip that.  */
        {
          struct glyph *g;
  
-         if (NILP (BVAR (XBUFFER (w->buffer), bidi_display_reordering))
+         if (NILP (BVAR (XBUFFER (w->contents), bidi_display_reordering))
              || (!best_row && !row->continued_p))
            return row;
          /* In bidi-reordered rows, there could be several rows
@@@ -17074,13 -16995,6 +17070,13 @@@ try_window_id (struct window *w
      return 0;
  #endif
  
 +#ifdef HAVE_XWIDGETS_xxx
 +  //maybe needed for proper xwidget movement
 +    printf("try_window_id\n");
 +    return -1;
 +#endif
 +
 +  
    /* This is handy for debugging.  */
  #if 0
  #define GIVE_UP(X)                                            \
       wrapped line can change the wrap position, altering the line
       above it.  It might be worthwhile to handle this more
       intelligently, but for now just redisplay from scratch.  */
-   if (!NILP (BVAR (XBUFFER (w->buffer), word_wrap)))
+   if (!NILP (BVAR (XBUFFER (w->contents), word_wrap)))
      GIVE_UP (21);
  
    /* Under bidi reordering, adding or deleting a character in the
       to find the paragraph limits and widen the range of redisplayed
       lines to that, but for now just give up this optimization and
       redisplay from scratch.  */
-   if (!NILP (BVAR (XBUFFER (w->buffer), bidi_display_reordering))
-       && NILP (BVAR (XBUFFER (w->buffer), bidi_paragraph_direction)))
+   if (!NILP (BVAR (XBUFFER (w->contents), bidi_display_reordering))
+       && NILP (BVAR (XBUFFER (w->contents), bidi_paragraph_direction)))
      GIVE_UP (22);
  
    /* Make sure beg_unchanged and end_unchanged are up to date.  Do it
@@@ -17915,29 -17829,6 +17911,29 @@@ dump_glyph (struct glyph_row *row, stru
               glyph->left_box_line_p,
               glyph->right_box_line_p);
      }
 +#ifdef HAVE_XWIDGETS  
 +  else if (glyph->type == XWIDGET_GLYPH)
 +    {
 +      fprintf (stderr,
 +             "  %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
 +             glyph - row->glyphs[TEXT_AREA],
 +             'X',
 +             glyph->charpos,
 +             (BUFFERP (glyph->object)
 +              ? 'B'
 +              : (STRINGP (glyph->object)
 +                 ? 'S'
 +                 : '-')),
 +             glyph->pixel_width,
 +             glyph->u.xwidget,
 +             '.',
 +             glyph->face_id,
 +             glyph->left_box_line_p,
 +             glyph->right_box_line_p);
 +
 +      //      printf("dump xwidget glyph\n");
 +    }
 +#endif  
  }
  
  
@@@ -18055,7 -17946,7 +18051,7 @@@ glyphs in short form, otherwise show gl
    (Lisp_Object glyphs)
  {
    struct window *w = XWINDOW (selected_window);
-   struct buffer *buffer = XBUFFER (w->buffer);
+   struct buffer *buffer = XBUFFER (w->contents);
  
    fprintf (stderr, "PT = %"pI"d, BEGV = %"pI"d. ZV = %"pI"d\n",
           BUF_PT (buffer), BUF_BEGV (buffer), BUF_ZV (buffer));
@@@ -18161,7 -18052,7 +18157,7 @@@ static struct glyph_row 
  get_overlay_arrow_glyph_row (struct window *w, Lisp_Object overlay_arrow_string)
  {
    struct frame *f = XFRAME (WINDOW_FRAME (w));
-   struct buffer *buffer = XBUFFER (w->buffer);
+   struct buffer *buffer = XBUFFER (w->contents);
    struct buffer *old = current_buffer;
    const unsigned char *arrow_string = SDATA (overlay_arrow_string);
    int arrow_len = SCHARS (overlay_arrow_string);
@@@ -19368,7 -19259,7 +19364,7 @@@ display_line (struct it *it
              row->glyphs[TEXT_AREA]->charpos = -1;
              row->displays_text_p = 0;
  
-             if (!NILP (BVAR (XBUFFER (it->w->buffer), indicate_empty_lines))
+             if (!NILP (BVAR (XBUFFER (it->w->contents), indicate_empty_lines))
                  && (!MINI_WINDOW_P (it->w)
                      || (minibuf_level && EQ (it->window, minibuf_window))))
                row->indicate_empty_line_p = 1;
@@@ -20183,10 -20074,8 +20179,8 @@@ redisplay_mode_lines (Lisp_Object windo
      {
        struct window *w = XWINDOW (window);
  
-       if (WINDOWP (w->hchild))
-       nwindows += redisplay_mode_lines (w->hchild, force);
-       else if (WINDOWP (w->vchild))
-       nwindows += redisplay_mode_lines (w->vchild, force);
+       if (WINDOWP (w->contents))
+       nwindows += redisplay_mode_lines (w->contents, force);
        else if (force
               || FRAME_GARBAGED_P (XFRAME (w->frame))
               || !MATRIX_MODE_LINE_ROW (w->current_matrix)->enabled_p)
  
          /* Set the window's buffer for the mode line display.  */
          SET_TEXT_POS (lpoint, PT, PT_BYTE);
-         set_buffer_internal_1 (XBUFFER (w->buffer));
+         set_buffer_internal_1 (XBUFFER (w->contents));
  
          /* Point refers normally to the selected window.  For any
             other window, set up appropriate value.  */
@@@ -20978,7 -20867,7 +20972,7 @@@ are the selected window and the WINDOW'
    XSETWINDOW (window, w);
  
    if (NILP (buffer))
-     buffer = w->buffer;
+     buffer = w->contents;
    CHECK_BUFFER (buffer);
  
    /* Make formatting the modeline a non-op when noninteractive, otherwise
@@@ -22284,7 -22173,7 +22278,7 @@@ calc_pixel_width_or_height (double *res
            return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it->w));
        }
  
-       prop = buffer_local_value_1 (prop, it->w->buffer);
+       prop = buffer_local_value_1 (prop, it->w->contents);
        if (EQ (prop, Qunbound))
        prop = Qnil;
      }
  
              return OK_PIXELS (width_p ? img->width : img->height);
            }
 +#ifdef HAVE_XWIDGETS
 +        if (FRAME_WINDOW_P (it->f) && valid_xwidget_p (prop))
 +          {
 +              printf("calc_pixel_width_or_height: return dummy size FIXME\n");
 +              return OK_PIXELS (width_p ? 100 : 100);
 +            }
 +#endif          
  #endif
          if (EQ (car, Qplus) || EQ (car, Qminus))
            {
              return OK_PIXELS (pixels);
            }
  
-         car = buffer_local_value_1 (car, it->w->buffer);
+         car = buffer_local_value_1 (car, it->w->contents);
          if (EQ (car, Qunbound))
            car = Qnil;
        }
@@@ -22823,20 -22705,7 +22817,20 @@@ fill_image_glyph_string (struct glyph_s
    s->ybase += s->first_glyph->voffset;
  }
  
 -
 +#ifdef HAVE_XWIDGETS
 +static void
 +fill_xwidget_glyph_string (struct glyph_string *s)
 +{
 +  eassert (s->first_glyph->type == XWIDGET_GLYPH);
 +  printf("fill_xwidget_glyph_string: width:%d \n",s->first_glyph->pixel_width);
 +  s->face = FACE_FROM_ID (s->f, s->first_glyph->face_id);
 +  s->font = s->face->font;
 +  s->width = s->first_glyph->pixel_width;
 +  s->ybase += s->first_glyph->voffset;
 +  s->xwidget = s->first_glyph->u.xwidget;
 +  //assert_valid_xwidget_id ( s->xwidget, "fill_xwidget_glyph_string");
 +}
 +#endif
  /* Fill glyph string S from a sequence of stretch glyphs.
  
     START is the index of the first glyph to consider,
@@@ -23173,21 -23042,6 +23167,21 @@@ compute_overhangs_and_x (struct glyph_s
         }                                                              \
       while (0)
  
 +#ifdef HAVE_XWIDGETS
 +#define BUILD_XWIDGET_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
 +     do                                                                       \
 +       { \
 +         printf("BUILD_XWIDGET_GLYPH_STRING\n");                                                      \
 +       s = (struct glyph_string *) alloca (sizeof *s);                \
 +       INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL);          \
 +       fill_xwidget_glyph_string (s);                                 \
 +       append_glyph_string (&HEAD, &TAIL, s);                         \
 +       ++START;                                                       \
 +         s->x = (X);                                                  \
 +       }                                                              \
 +     while (0)
 +#endif
 +
  
  /* Add a glyph string for a sequence of character glyphs to the list
     of strings between HEAD and TAIL.  START is the index of the first
     to allocate glyph strings (because draw_glyphs can be called
     asynchronously).  */
  
 -#define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X)    \
 +#define BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X)  \
    do                                                                  \
      {                                                                 \
        HEAD = TAIL = NULL;                                             \
            case IMAGE_GLYPH:                                           \
              BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL,         \
                                        HL, X, LAST_X);                 \
 -            break;                                                    \
 -                                                                      \
 +            break;
 +              
 +#define BUILD_GLYPH_STRINGS_XW(START, END, HEAD, TAIL, HL, X, LAST_X) \
 +            case XWIDGET_GLYPH:                                         \
 +              BUILD_XWIDGET_GLYPH_STRING (START, END, HEAD, TAIL,       \
 +                                          HL, X, LAST_X);               \
 +              break;
 +
 +#define BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X)  \
            case GLYPHLESS_GLYPH:                                       \
              BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL,     \
                                            HL, X, LAST_X);             \
      } while (0)
  
  
 +#ifdef HAVE_XWIDGETS
 +#define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X)    \
 +BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X)  \
 +BUILD_GLYPH_STRINGS_XW(START, END, HEAD, TAIL, HL, X, LAST_X) \
 +BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X)
 +#else
 +#define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X)    \
 +BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X)  \
 +BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X)
 +#endif 
 +
 +        
  /* Draw glyphs between START and END in AREA of ROW on window W,
     starting at x-position X.  X is relative to AREA in W.  HL is a
     face-override with the following meaning:
@@@ -24002,89 -23837,6 +23996,89 @@@ produce_image_glyph (struct it *it
      }
  }
  
 +#ifdef HAVE_XWIDGETS
 +static void
 +produce_xwidget_glyph (struct it *it)
 +{
 +  struct xwidget* xw;
 +  struct face *face;
 +  int glyph_ascent, crop;
 +  printf("produce_xwidget_glyph:\n");
 +  eassert (it->what == IT_XWIDGET);
 +
 +  face = FACE_FROM_ID (it->f, it->face_id);
 +  eassert (face);
 +  /* Make sure X resources of the face is loaded.  */
 +  PREPARE_FACE_FOR_DISPLAY (it->f, face);
 +
 +  xw = it->xwidget;
 +  it->ascent = it->phys_ascent = glyph_ascent = xw->height/2;
 +  it->descent = xw->height/2;
 +  it->phys_descent = it->descent;
 +  it->pixel_width = xw->width;
 +  /* It's quite possible for images to have an ascent greater than
 +     their height, so don't get confused in that case.  */
 +  if (it->descent < 0)
 +    it->descent = 0;
 +
 +  it->nglyphs = 1;
 +
 +  if (face->box != FACE_NO_BOX)
 +    {
 +      if (face->box_line_width > 0)
 +      {
 +          it->ascent += face->box_line_width;
 +          it->descent += face->box_line_width;
 +      }
 +
 +      if (it->start_of_box_run_p)
 +      it->pixel_width += eabs (face->box_line_width);
 +      it->pixel_width += eabs (face->box_line_width);
 +    }
 +
 +  take_vertical_position_into_account (it);
 +
 +  /* Automatically crop wide image glyphs at right edge so we can
 +     draw the cursor on same display row.  */
 +  if ((crop = it->pixel_width - (it->last_visible_x - it->current_x), crop > 0)
 +      && (it->hpos == 0 || it->pixel_width > it->last_visible_x / 4))
 +    {
 +      it->pixel_width -= crop;
 +    }
 +
 +  if (it->glyph_row)
 +    {
 +      struct glyph *glyph;
 +      enum glyph_row_area area = it->area;
 +
 +      glyph = it->glyph_row->glyphs[area] + it->glyph_row->used[area];
 +      if (glyph < it->glyph_row->glyphs[area + 1])
 +      {
 +        glyph->charpos = CHARPOS (it->position);
 +        glyph->object = it->object;
 +        glyph->pixel_width = it->pixel_width;
 +        glyph->ascent = glyph_ascent;
 +        glyph->descent = it->descent;
 +        glyph->voffset = it->voffset;
 +        glyph->type = XWIDGET_GLYPH;
 +
 +        glyph->multibyte_p = it->multibyte_p;
 +        glyph->left_box_line_p = it->start_of_box_run_p;
 +        glyph->right_box_line_p = it->end_of_box_run_p;
 +        glyph->overlaps_vertically_p = 0;
 +          glyph->padding_p = 0;
 +        glyph->glyph_not_available_p = 0;
 +        glyph->face_id = it->face_id;
 +          glyph->u.xwidget = it->xwidget;
 +          //assert_valid_xwidget_id(glyph->u.xwidget_id,"produce_xwidget_glyph");
 +        glyph->font_type = FONT_TYPE_UNKNOWN;
 +        ++it->glyph_row->used[area];
 +      }
 +      else
 +      IT_EXPAND_MATRIX_WIDTH (it, area);
 +    }
 +}
 +#endif
  
  /* Append a stretch glyph to IT->glyph_row.  OBJECT is the source
     of the glyph, WIDTH and HEIGHT are the width and height of the
@@@ -24325,7 -24077,7 +24319,7 @@@ produce_stretch_glyph (struct it *it
        int n = width;
  
        if (!STRINGP (object))
-       object = it->w->buffer;
+       object = it->w->contents;
  #ifdef HAVE_WINDOW_SYSTEM
        if (FRAME_WINDOW_P (it->f))
        append_stretch_glyph (it, object, width, height, ascent);
@@@ -25424,10 -25176,7 +25418,10 @@@ x_produce_glyphs (struct it *it
      produce_image_glyph (it);
    else if (it->what == IT_STRETCH)
      produce_stretch_glyph (it);
 -
 +#ifdef HAVE_XWIDGETS
 +  else if (it->what == IT_XWIDGET)
 +    produce_xwidget_glyph (it);
 +#endif
   done:
    /* Accumulate dimensions.  Note: can't assume that it->descent > 0
       because this isn't true for images with `:ascent 100'.  */
@@@ -25724,7 -25473,7 +25718,7 @@@ get_window_cursor_type (struct window *
                        int *active_cursor)
  {
    struct frame *f = XFRAME (w->frame);
-   struct buffer *b = XBUFFER (w->buffer);
+   struct buffer *b = XBUFFER (w->contents);
    int cursor_type = DEFAULT_CURSOR;
    Lisp_Object alt_cursor;
    int non_selected = 0;
    /* Use normal cursor if not blinked off.  */
    if (!w->cursor_off_p)
      {
 +
 +#ifdef HAVE_XWIDGETS      
 +      if (glyph != NULL && glyph->type == XWIDGET_GLYPH){
 +        //printf("attempt xwidget cursor avoidance in get_window_cursor_type\n");
 +        return NO_CURSOR;
 +      }
 +#endif      
        if (glyph != NULL && glyph->type == IMAGE_GLYPH)
        {
          if (cursor_type == FILLED_BOX_CURSOR)
@@@ -26282,10 -26024,8 +26276,8 @@@ update_cursor_in_window_tree (struct wi
  {
    while (w)
      {
-       if (!NILP (w->hchild))
-       update_cursor_in_window_tree (XWINDOW (w->hchild), on_p);
-       else if (!NILP (w->vchild))
-       update_cursor_in_window_tree (XWINDOW (w->vchild), on_p);
+       if (WINDOWP (w->contents))
+       update_cursor_in_window_tree (XWINDOW (w->contents), on_p);
        else
        update_window_cursor (w, on_p);
  
@@@ -27531,7 -27271,7 +27523,7 @@@ note_mode_line_or_margin_highlight (Lis
                {
                  help_echo_string = help;
                  XSETWINDOW (help_echo_window, w);
-                 help_echo_object = w->buffer;
+                 help_echo_object = w->contents;
                  help_echo_pos = charpos;
                }
            }
            {
              Lisp_Object default_help
                = buffer_local_value_1 (Qmode_line_default_help_echo,
-                                       w->buffer);
+                                       w->contents);
  
              if (STRINGP (default_help))
                {
@@@ -27842,7 -27582,7 +27834,7 @@@ note_mouse_highlight (struct frame *f, 
  
    /* Are we in a window whose display is up to date?
       And verify the buffer's text has not changed.  */
-   b = XBUFFER (w->buffer);
+   b = XBUFFER (w->contents);
    if (part == ON_TEXT
        && w->window_end_valid
        && w->last_modified == BUF_MODIFF (b)
                  if (pos > 0)
                    {
                      mouse_face = get_char_property_and_overlay
-                       (make_number (pos), Qmouse_face, w->buffer, &overlay);
-                     buffer = w->buffer;
+                       (make_number (pos), Qmouse_face, w->contents, &overlay);
+                     buffer = w->contents;
                      disp_string = object;
                    }
                }
                    if (p > 0)
                      {
                        help = Fget_char_property (make_number (p),
-                                                  Qhelp_echo, w->buffer);
+                                                  Qhelp_echo, w->contents);
                        if (!NILP (help))
                          {
                            charpos = p;
-                           obj = w->buffer;
+                           obj = w->contents;
                          }
                      }
                  }
                      ptrdiff_t p = string_buffer_position (obj, start);
                      if (p > 0)
                        pointer = Fget_char_property (make_number (p),
-                                                     Qpointer, w->buffer);
+                                                     Qpointer, w->contents);
                    }
                }
              else if (BUFFERP (obj)
@@@ -28663,12 -28403,9 +28655,9 @@@ expose_window_tree (struct window *w, X
  
    while (w && !FRAME_GARBAGED_P (f))
      {
-       if (!NILP (w->hchild))
-       mouse_face_overwritten_p
-         |= expose_window_tree (XWINDOW (w->hchild), r);
-       else if (!NILP (w->vchild))
+       if (WINDOWP (w->contents))
        mouse_face_overwritten_p
-         |= expose_window_tree (XWINDOW (w->vchild), r);
+         |= expose_window_tree (XWINDOW (w->contents), r);
        else
        mouse_face_overwritten_p |= expose_window (w, r);