all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Working with buffers in frames
@ 2024-09-30 12:32 Heime
  0 siblings, 0 replies; only message in thread
From: Heime @ 2024-09-30 12:32 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor


After inserting some text, text properties and possibly some buttons in a 
named buffer, I want this to be contained in some dedicated frame that is
separate from the current working frame.

For instance, consider the following function 

(defun quest-background-colour-chart-b (hex-colours &optional bfrn)
  "Display background colors for a given list of HEX-COLOURS in a new buffer."

  (interactive)

  (let* ( (colours hex-colours)
          (bfname (or bfrn "Quest Colours"))
          (dbuffer (get-buffer-create (concat "𒆳 " bfname))))

    (with-current-buffer dbuffer

      (erase-buffer)

      ;; Set background colour for buffer
      (face-remap-add-relative 'default :background "blue")

      (insert "\n")

      (dolist (hex colours)
        (let* ( (hex-text  (format " %s " hex))
                (text      (format "Colour: %s\n" hex))
                (hex-pt    (point)) )

          (insert hex-text)
          (add-text-properties hex-pt (point)
            `(face (:foreground "white")))

          (let ( (text-pt (point)) )
            (insert text)
            (add-text-properties text-pt (point)
              `(face (:background ,hex :foreground "black"))))))

      (goto-char (point-min)))

    (switch-to-buffer dbuffer)))

Instead of the common switch-to-buffer I have begun calling 
the following, to handle the buffer in the frame quest-frame.

(select-frame-set-input-focus quest-frame)
    (set-window-buffer (frame-selected-window quest-frame) dbuffer)))

Still, one do not necessarily need to use select-frame-set-input-focus or 
set-window-buffer directly.  Because Emacs provides built-in functions like 
pop-to-buffer, display-buffer, and switch-to-buffer, which can handle displaying 
buffers in different frames. 

display-buffer is the most flexible function for displaying a buffer.  It can
be used to specify rules for how and where to display the buffer, including 
creating new frames.

The same can be said of pop-to-buffer.  But for switch-to-buffer you'd have 
to manually switch to the frame first, then use switch-to-buffer to show the 
buffer in that frame.  view-buffer is similar to switch-to-buffer, but intended 
for read-only viewing of a buffer.

I would value some practical advice, examples, and useful approaches and takeaways
if one wants to display buffers in dedicated frames. 




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-09-30 12:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-30 12:32 Working with buffers in frames Heime

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.