all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Heime <heimeborgia@protonmail.com>
To: Heime via Users list for the GNU Emacs text editor
	<help-gnu-emacs@gnu.org>
Subject: Working with buffers in frames
Date: Mon, 30 Sep 2024 12:32:44 +0000	[thread overview]
Message-ID: <ZkvtfOj7K5MQr1sVd0Oy_wFQak3U2_yIkiWyAFiQmHQkUiICrSIL9jqKtmGi_tu7TP0OHRJHYnxLFB_NQ8CP96zCFLGEj75XZTZdj0da8lI=@protonmail.com> (raw)


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. 




                 reply	other threads:[~2024-09-30 12:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='ZkvtfOj7K5MQr1sVd0Oy_wFQak3U2_yIkiWyAFiQmHQkUiICrSIL9jqKtmGi_tu7TP0OHRJHYnxLFB_NQ8CP96zCFLGEj75XZTZdj0da8lI=@protonmail.com' \
    --to=heimeborgia@protonmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.