* Re: naming and/or directly addressing particular windows?
@ 2012-12-02 17:46 martin rudalics
2012-12-03 12:38 ` Matt Price
0 siblings, 1 reply; 11+ messages in thread
From: martin rudalics @ 2012-12-02 17:46 UTC (permalink / raw)
To: moptop99; +Cc: help-gnu-emacs
> I'm slowly starting to understand. I now have this primitive code,
> which at least sets up the windows the way I want them:
>
> (defun my-windows-function ()
> "Trying to figure out how to get a nice windows config for writers-room-mode"
...
> (split-window-horizontally)
> (windmove-right)
> (fix-window-horizontal-size 35)
> (add-to-list 'my-winlist
> (cons 'metadata (selected-window))
> )
...
> (select-window(cdr(assoc 'guide my-winlist)) )
> )
I'm not sure why you need names at all but with Emacs 24 it's simpler to
use window parameters as
(defun set-window-name (window name)
(set-window-parameter window 'name name))
(defun window-with-name (name)
(window-with-parameter 'name name))
which also relieves you from the task to recycle dead windows from
`my-winlist', and rewrite your code as
(let ((new-window (split-window-horizontally -35)))
(set-window-name new-window 'metadata))
...
(select-window (window-with-name 'guide))
> I'm not having an easy time figuring out how that function decides
> which window to use when creating and focussing on the new indirect
> buffer. I can see (and the documentation states) that a choice is
> first made between using a new or dedicated frame, or the same frame
> with either the original or another window. But the code to put the
> buffer in another window in the same frame is quite simple:
>
> ((eq org-indirect-buffer-display 'other-window)
> (pop-to-buffer ibuf))
>
>
> I've been chasing the code down to native emacs functions --
> pop-to-buffer ends up relying on display-buffer -- but I haven't yet
> found a place where I an specify a particular window for the new
> buffer. Does anyone else know a way?
Depends (also) on the version of your Emacs.
martin
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: naming and/or directly addressing particular windows?
2012-12-02 17:46 naming and/or directly addressing particular windows? martin rudalics
@ 2012-12-03 12:38 ` Matt Price
2012-12-03 17:42 ` martin rudalics
0 siblings, 1 reply; 11+ messages in thread
From: Matt Price @ 2012-12-03 12:38 UTC (permalink / raw)
To: martin rudalics; +Cc: help-gnu-emacs
On Sun, Dec 2, 2012 at 12:46 PM, martin rudalics <rudalics@gmx.at> wrote:
>
> I'm not sure why you need names at all but with Emacs 24 it's simpler to
> use window parameters as
>
> (defun set-window-name (window name)
> (set-window-parameter window 'name name))
>
> (defun window-with-name (name)
> (window-with-parameter 'name name))
>
> which also relieves you from the task to recycle dead windows from
> `my-winlist', and rewrite your code as
>
> (let ((new-window (split-window-horizontally -35)))
> (set-window-name new-window 'metadata))
>
> ...
>
> (select-window (window-with-name 'guide))
>
that is so very helpful, thank you. I may not really need names but
for someone like me who has a hard time even reading lisp, I think
they will be a helpful mneumonic. (probably it would be just as good
to assign a variable the value of '(selected-window)' at various
points in the function). I've rewritten my code like this, which
seems to be much clearer than the original:
(defun set-window-name (window name)
(set-window-parameter window 'name name))
(defun window-with-name (name)
(window-with-parameter 'name name))
(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)
>
>> I'm not having an easy time figuring out how that function decides
>> which window to use when creating and focussing on the new indirect
>> buffer. I can see (and the documentation states) that a choice is
>> first made between using a new or dedicated frame, or the same frame
>> with either the original or another window. But the code to put the
>> buffer in another window in the same frame is quite simple:
>>
>> ((eq org-indirect-buffer-display 'other-window)
>> (pop-to-buffer ibuf))
>>
>>
>> I've been chasing the code down to native emacs functions --
>> pop-to-buffer ends up relying on display-buffer -- but I haven't yet
>> found a place where I an specify a particular window for the new
>> buffer. Does anyone else know a way?
>
> Depends (also) on the version of your Emacs.
>
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.
Thanks so much,
Matt
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: naming and/or directly addressing particular windows?
2012-12-03 12:38 ` Matt Price
@ 2012-12-03 17:42 ` martin rudalics
2012-12-03 19:58 ` Matt Price
0 siblings, 1 reply; 11+ messages in thread
From: martin rudalics @ 2012-12-03 17:42 UTC (permalink / raw)
To: Matt Price; +Cc: help-gnu-emacs
> (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
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: naming and/or directly addressing particular windows?
2012-12-03 17:42 ` martin rudalics
@ 2012-12-03 19:58 ` Matt Price
2012-12-03 20:58 ` Jambunathan K
2012-12-04 9:01 ` martin rudalics
0 siblings, 2 replies; 11+ messages in thread
From: Matt Price @ 2012-12-03 19:58 UTC (permalink / raw)
To: martin rudalics; +Cc: help-gnu-emacs
On Mon, Dec 3, 2012 at 12:42 PM, martin rudalics <rudalics@gmx.at> wrote:
>
> 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"))
>
wow, that's so much cleaner. again. thanks.
>> 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*")))
in the 'let' expression above, how would I replace \\*foo\\* and *foo*
with a regular expression that will match, say,
(concat (buffer-name) "-" [:digit:])
? I'm not quite clear on using regexes in emacs. thanks again so
much! I know I'm asking a lot of questions, I *am* trying things in
between but am getting stymied pretty quickly each time.
Matt
>
> martin
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: naming and/or directly addressing particular windows?
2012-12-03 19:58 ` Matt Price
@ 2012-12-03 20:58 ` Jambunathan K
2012-12-04 13:52 ` Matt Price
2012-12-04 9:01 ` martin rudalics
1 sibling, 1 reply; 11+ messages in thread
From: Jambunathan K @ 2012-12-03 20:58 UTC (permalink / raw)
To: Matt Price; +Cc: help-gnu-emacs
Matt Price <moptop99@gmail.com> writes:
> with a regular expression that will match, say,
>
> (concat (buffer-name) "-" [:digit:])
M-x ielm RET
,----
| *** Welcome to IELM *** Type (describe-mode) for help.
| ELISP> (rx-to-string `(and ,(buffer-name) (zero-or-more digit)))
| "\\(?:\\*ielm\\*[[:digit:]]*\\)"
| ELISP> *ielm*1
`----
M-x re-builder RET
Copy, paste the string returned by `rx-to-string' in the resulting
re-builder buffer. You will see that it matches the second line.
C-f rx RET
--
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: naming and/or directly addressing particular windows?
2012-12-03 19:58 ` Matt Price
2012-12-03 20:58 ` Jambunathan K
@ 2012-12-04 9:01 ` martin rudalics
2012-12-05 16:11 ` Matt Price
1 sibling, 1 reply; 11+ messages in thread
From: martin rudalics @ 2012-12-04 9:01 UTC (permalink / raw)
To: Matt Price; +Cc: help-gnu-emacs
> in the 'let' expression above, how would I replace \\*foo\\* and *foo*
> with a regular expression that will match, say,
>
> (concat (buffer-name) "-" [:digit:])
Try ".+-[0-9]$" instead of "\\*foo\\*" and "foo-1" instead of "*foo*".
Note that if the purpose of your functions is to display buffers always
approximately at the same location within an Emacs frame, then side
windows (see the function `display-buffer-in-side-window' and the
variables `window-sides-vertical' and `window-sides-slots') might be
more appropriate.
In your case there would be a centered "main window", the "guide window"
at the left and the "metadata window" at the bottom of the frame.
In any case be always aware of two issues:
(1) A user may delete any window at any time (with a few restrictions).
So be prepared that you may have to re-create your windows and give
them a name for showing the buffer of your choice.
(2) Emacs and other applications might reuse or split a window at any
time, for example, to display information like a warning or a
backtrace.
You can fix some of these by making windows dedicated and/or fixing
their sizes but doing that is not entirely trivial.
martin
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: naming and/or directly addressing particular windows?
2012-12-04 9:01 ` martin rudalics
@ 2012-12-05 16:11 ` Matt Price
0 siblings, 0 replies; 11+ messages in thread
From: Matt Price @ 2012-12-05 16:11 UTC (permalink / raw)
To: martin rudalics; +Cc: help-gnu-emacs
On Tue, Dec 4, 2012 at 4:01 AM, martin rudalics <rudalics@gmx.at> wrote:
>> in the 'let' expression above, how would I replace \\*foo\\* and *foo*
>> with a regular expression that will match, say,
>>
>> (concat (buffer-name) "-" [:digit:])
>
> Try ".+-[0-9]$" instead of "\\*foo\\*" and "foo-1" instead of "*foo*".
ah, that works, though I was ble to get something slightly more
restrictive working instead:
(let ((display-buffer-alist
(cons
`( ,(rx-to-string `(and ,(buffer-name) "-" (zero-or-more
digit))) (display-buffer-in-main))
display-buffer-alist)))
(org-tree-to-indirect-buffer))
>
> Note that if the purpose of your functions is to display buffers always
> approximately at the same location within an Emacs frame, then side
> windows (see the function `display-buffer-in-side-window' and the
> variables `window-sides-vertical' and `window-sides-slots') might be
> more appropriate.
>
> In your case there would be a centered "main window", the "guide window"
> at the left and the "metadata window" at the bottom of the frame.
I can see that would be better. I seem to have some code working so
leaving it as-is for now but will hopefully return to this question
later.
>
> In any case be always aware of two issues:
>
> (1) A user may delete any window at any time (with a few restrictions).
> So be prepared that you may have to re-create your windows and give
> them a name for showing the buffer of your choice.
>
> (2) Emacs and other applications might reuse or split a window at any
> time, for example, to display information like a warning or a
> backtrace.
>
> You can fix some of these by making windows dedicated and/or fixing
> their sizes but doing that is not entirely trivial.
Yes, my code is rather fragile as it stands, and is going to need to
protect against those kind of disturbances somehow. I'll have to
figure these issues out.
for now, I've put my fragile and incomplete code on github so org-mode
users can think about the interface design & make
suggestions/contributions:
https://github.com/titaniumbones/org-writers-room
I really appreciate all your help & hope that something useful comes
out of this! Thanks again,
Matt
^ permalink raw reply [flat|nested] 11+ messages in thread
* naming and/or directly addressing particular windows?
@ 2012-12-01 15:22 Matt Price
2012-12-01 15:59 ` Drew Adams
0 siblings, 1 reply; 11+ messages in thread
From: Matt Price @ 2012-12-01 15:22 UTC (permalink / raw)
To: Bastien; +Cc: drain, Help-gnu-emacs, Org Mode
Hi,
After the recent conversation about Scrivener (on help-gnu-emacs) I
thought the very first step would be to write a simple function that
would create a window layout and populate the windows with a set of
buffers, then set mjor and minor modes for some of hte buffers.
(After that I guess I will have to figure out how to write some very
simple minor modes, or at least some functions that allow e.g. direct
editing of org-mode properties on a selected node.)
So, what I have so far is quite trivial but doesn't seem to work
exactly as I expected:
(delete-other-windows)
(split-window-horizontally)
(windmove-right)
(split-window-horizontally)
(enlarge-window-horizontally 20)
(windmove-right)
(split-window-vertically)
Anyway presumably I'll fiddle with this and eventually it will work,
but something better would be
(set-window-name "outline")
(split-named-window-horizontally-and-name-the-other-window "outline" "main")
(split-named-window-horizontally-and-name-the-other-window "main" "metadata")
(set-width-named-window "main" 60)
and then write a function, bound to say Ctrl-Enter,
open-node-as-indirect-buffer-in-named-window
Anyway: is it possible to give/get a name for a window that persists
long enough to be called in functions?
Thanks,
Matt
^ permalink raw reply [flat|nested] 11+ messages in thread
* RE: naming and/or directly addressing particular windows?
2012-12-01 15:22 Matt Price
@ 2012-12-01 15:59 ` Drew Adams
2012-12-02 5:31 ` Matt Price
0 siblings, 1 reply; 11+ messages in thread
From: Drew Adams @ 2012-12-01 15:59 UTC (permalink / raw)
To: 'Matt Price', 'Bastien'
Cc: 'drain', Help-gnu-emacs, 'Org Mode'
> Anyway: is it possible to give/get a name for a window that persists
> long enough to be called in functions?
This might help:
(defun icicle-make-window-alist (&optional all-p)
"Return an alist of entries (WNAME . WINDOW), where WNAME names WINDOW.
The name of the buffer in a window is used as its name, unless there
is more than one window displaying the same buffer. In that case,
WNAME includes a suffix [NUMBER], to make it a unique name. The
NUMBER order among window names that differ only by their [NUMBER] is
arbitrary.
Non-nil argument ALL-P means use windows from all visible frames.
Otherwise, use only windows from the selected frame."
(lexical-let ((win-alist ())
(count 2)
wname new-name)
(walk-windows (lambda (w)
(setq wname (buffer-name (window-buffer w)))
(if (not (assoc wname win-alist))
(push (cons wname w) win-alist)
(setq new-name wname)
(while (assoc new-name win-alist)
(setq new-name (format "%s[%d]" wname count)
count (1+ count)))
(push (cons new-name w) win-alist))
(setq count 2))
'no-mini
(if all-p 'visible 'this-frame))
win-alist))
(This is used in command `icicle-select-window-by-name', which in turn is the
action function for multi-command `icicle-select-window'. Code here:
http://www.emacswiki.org/emacs-en/download/icicles-cmd1.el.)
I'm guessing that there are other, similar functions available on Emacs Wiki -
start here, perhaps: http://www.emacswiki.org/emacs/CategoryWindows
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: naming and/or directly addressing particular windows?
2012-12-01 15:59 ` Drew Adams
@ 2012-12-02 5:31 ` Matt Price
0 siblings, 0 replies; 11+ messages in thread
From: Matt Price @ 2012-12-02 5:31 UTC (permalink / raw)
To: Drew Adams; +Cc: Bastien, Help-gnu-emacs, Org Mode, drain
On Sat, Dec 1, 2012 at 10:59 AM, Drew Adams <drew.adams@oracle.com> wrote:
>> Anyway: is it possible to give/get a name for a window that persists
>> long enough to be called in functions?
>
> This might help:
>
> (defun icicle-make-window-alist (&optional all-p)
> "Return an alist of entries (WNAME . WINDOW), where WNAME names WINDOW.
> The name of the buffer in a window is used as its name, unless there
> is more than one window displaying the same buffer. In that case,
> WNAME includes a suffix [NUMBER], to make it a unique name. The
> NUMBER order among window names that differ only by their [NUMBER] is
> arbitrary.
>
> Non-nil argument ALL-P means use windows from all visible frames.
> Otherwise, use only windows from the selected frame."
> (lexical-let ((win-alist ())
> (count 2)
> wname new-name)
> (walk-windows (lambda (w)
> (setq wname (buffer-name (window-buffer w)))
> (if (not (assoc wname win-alist))
> (push (cons wname w) win-alist)
> (setq new-name wname)
> (while (assoc new-name win-alist)
> (setq new-name (format "%s[%d]" wname count)
> count (1+ count)))
> (push (cons new-name w) win-alist))
> (setq count 2))
> 'no-mini
> (if all-p 'visible 'this-frame))
> win-alist))
>
> (This is used in command `icicle-select-window-by-name', which in turn is the
> action function for multi-command `icicle-select-window'. Code here:
> http://www.emacswiki.org/emacs-en/download/icicles-cmd1.el.)
>
> I'm guessing that there are other, similar functions available on Emacs Wiki -
> start here, perhaps: http://www.emacswiki.org/emacs/CategoryWindows
>
I'm slowly starting to understand. I now have this primitive code,
which at least sets up the windows the way I want them:
(defun my-windows-function ()
"Trying to figure out how to get a nice windows config for writers-room-mode"
(interactive )
(global-linum-mode 0)
(delete-other-windows)
(setq my-this-win (selected-window))
(setq my-winlist '())
(add-to-list 'my-winlist
(cons 'guide (selected-window))
)
(split-window-horizontally)
(fix-window-horizontal-size 35)
(windmove-right)
(add-to-list 'my-winlist
(cons 'main (selected-window))
)
(split-window-horizontally)
(windmove-right)
(fix-window-horizontal-size 35)
(add-to-list 'my-winlist
(cons 'metadata (selected-window))
)
(split-window-vertically)
(windmove-down)
(add-to-list 'my-winlist
(cons 'not-sure-what-this-is-for (selected-window))
)
(select-window(cdr(assoc 'guide my-winlist)) )
)
The final select-window ommand demonstrates that I can now address the
windows by name (yay!).
The next step for me is to rewrite the existing
org-tree-to-indirect-buffer function so that it reliably sends org
subtree indirect buffers to the "main" window (in the middle column of
the frame). The function starts at line 7091 of org.el:
http://orgmode.org/w/org-mode.git/blob/lisp/org.el
I'm not having an easy time figuring out how that function decides
which window to use when creating and focussing on the new indirect
buffer. I can see (and the documentation states) that a choice is
first made between using a new or dedicated frame, or the same frame
with either the original or another window. But the code to put the
buffer in another window in the same frame is quite simple:
((eq org-indirect-buffer-display 'other-window)
(pop-to-buffer ibuf))
I've been chasing the code down to native emacs functions --
pop-to-buffer ends up relying on display-buffer -- but I haven't yet
found a place where I an specify a particular window for the new
buffer. Does anyone else know a way?
Thanks again,
Matt
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2012-12-05 16:11 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-02 17:46 naming and/or directly addressing particular windows? martin rudalics
2012-12-03 12:38 ` Matt Price
2012-12-03 17:42 ` martin rudalics
2012-12-03 19:58 ` Matt Price
2012-12-03 20:58 ` Jambunathan K
2012-12-04 13:52 ` Matt Price
2012-12-04 9:01 ` martin rudalics
2012-12-05 16:11 ` Matt Price
-- strict thread matches above, loose matches on Subject: below --
2012-12-01 15:22 Matt Price
2012-12-01 15:59 ` Drew Adams
2012-12-02 5:31 ` Matt Price
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).