Function: zone--build-zone-buffer

zone--build-zone-buffer is a byte-compiled function defined in zone.el.gz.

Signature

(zone--build-zone-buffer WIN BUF)

Documentation

Construct the *zone* buffer in window WIN, based on buffer BUF.

Remove other windows if zone-delete-other-windows is non-nil. The selected buffer is then placed in the window. If only a portion of the buffer is visible, try to recenter it to expose more.

Source Code

;; Defined in /usr/src/emacs/lisp/play/zone.el.gz
;;;; Prepare the *zone* buffer with a copy of the source buffer

(defun zone--build-zone-buffer (win buf)
  "Construct the *zone* buffer in window WIN, based on buffer BUF.
Remove other windows if `zone-delete-other-windows' is non-nil.  The
selected buffer is then placed in the window.  If only a portion of the
buffer is visible, try to recenter it to expose more."
  ;; Make us single window if desired
  (when zone-delete-other-windows
    (delete-other-windows win))
  ;; Switch in the source buffer into the window
  (unless (eq (current-buffer) buf)
    (set-window-buffer win buf nil))
  ;; Try to scroll the buffer into the window
  (unless (< (window-end) (point-max))
    (let ((scroll-margin 0))
      (recenter -1)))
  (redisplay)
  ;; Create the zone buffer and populate it
  (let* ((win-end (window-end win t))
         (win-beg (window-start))
         (win-pt  (window-point))
         (new-pt  (1+ (- win-pt win-beg)))
         (win-ht  (line-pixel-height)))
    (with-current-buffer (get-buffer-create zone-buffer-name)
      (put 'zone 'orig-buffer buf)
      (erase-buffer)
      (setq-local mode-name "Zone"
                  buffer-undo-list t
                  truncate-lines t
                  scroll-margin 0
                  scroll-conservatively 1000
                  scroll-up-aggressively 0
                  scroll-down-aggressively 0
                  show-trailing-whitespace nil
                  tab-width (buffer-local-value 'tab-width buf)
                  line-spacing (buffer-local-value 'line-spacing buf))
      ;; Grab the visible portion of the source buffer
      (insert-buffer-substring buf win-beg win-end)
      ;; Remove read-only property so zone can play with all of it
      (let ((inhibit-read-only t)
            (beg (point-min))
            (end (point-max)))
        (remove-text-properties beg end '(read-only nil))
        ;; Adjust line height with the settings from the original buffer
        (add-text-properties beg end `(line-height ,win-ht))
        ;; Get rid of tab characters and position the window
        (untabify beg end)))
    ;; Move the zone buffer to the window
    (set-window-buffer win zone-buffer-name nil)
    ;; Position the zone buffer in the window
    ;;   Position point and then fix the top.
    ;;   These with scroll settings above fix
    ;;   the content boundaries in the window
    (set-window-point win new-pt)
    (set-window-start win (point-min))
    (redisplay)))