help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: naming and/or directly addressing particular windows?


From: martin rudalics
Subject: Re: naming and/or directly addressing particular windows?
Date: Mon, 03 Dec 2012 18:42:45 +0100

> (defun writers-room-windows (width)
>   "Trying to figure out how to get a nice windows config for a writers
> room mode"
>   (interactive )
>   (global-linum-mode 0)
>   (delete-other-windows)
>   (set-window-name (selected-window) 'guide)
>   (let ((new-window (split-window-horizontally width)))
>     (set-window-name new-window 'main))
>   (select-window (window-with-name 'main))
>   (let ((new-window (split-window-horizontally (- width))))
>     (set-window-name new-window 'metadata))
>   (select-window (window-with-name 'guide))
>   )
>
> (writers-room-windows 25)

You frequently select a window for the sole purpose to apply
`split-window-horizontally' to it.  But it's better to use
`select-window' exclusively for editing its buffer.

I would recommend to rewrite this part as

  (let* ((main (split-window nil width t))
         (metadata (split-window main (- width) t)))
    (set-window-name (selected-window) "guide")
    (set-window-name main "main")
    (set-window-name metadata "metadata"))

> emacs-version reports:
> GNU Emacs 24.2.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.6.0) of
> 2012-10-09 on meitnerium, modified by Debian
>
> If you have any more hints for this next problem -- forcing an
> indirect buffer to open in a particular window -- I'd be very
> grateful.

As a start try playing around with these:

(defun display-buffer-in-foo (buffer alist)
  "Try displaying BUFFER in a window named *foo*."
  (let ((window (window-with-name "*foo*")))
    (when window
      (window--display-buffer
       buffer window 'reuse alist display-buffer-mark-dedicated))))

(let ((display-buffer-alist
       (cons
        '("\\*foo\\*" (display-buffer-in-foo))
        display-buffer-alist)))
  (pop-to-buffer (get-buffer-create "*foo*")))

martin



reply via email to

[Prev in Thread] Current Thread [Next in Thread]