* splitting a window at point
@ 2018-04-17 0:23 James K. Lowden
2018-04-19 18:13 ` Tomas Nordin
[not found] ` <mailman.12737.1524161596.27995.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 5+ messages in thread
From: James K. Lowden @ 2018-04-17 0:23 UTC (permalink / raw)
To: help-gnu-emacs
It seems like an obvious function: I'd like to split a window
vertically, such that the top of the lower window is positioned where
the cursor is. If I'm on line 6, the top window will have 6 lines, and
the bottom window gets the rest. I (would) do this from time to time,
to leave a function definition in the top window while in the lower
window I operate on the code that uses it.
split-window-vertically takes an optional argument for the top (or
bottom) window size. So far, so good. C-u C-x 2 does indeed open the
top window with 4 lines.
How, then, to compute the cursor's window position?
move-to-window-line moves to the line, but there's no get-window-line.
what-cursor-position reports the buffer position, not the window
location. I could compute the cursor's window position from it if I
knew the window's buffer position, but apropos returns no function
for "window" that mentions buffer position in its description.
Do I "just" save the curent cursor position, jump to window line 1, get
its buffer position, jump back, and take the difference? I guess that
will work, but I'd rather not move the cursor just to compute its
location.
What am I overlooking?
--jkl
^ permalink raw reply [flat|nested] 5+ messages in thread
* splitting a window at point
@ 2018-04-17 6:32 martin rudalics
0 siblings, 0 replies; 5+ messages in thread
From: martin rudalics @ 2018-04-17 6:32 UTC (permalink / raw)
To: jklowden; +Cc: help-gnu-emacs
> How, then, to compute the cursor's window position?
Have a look at the specification of 'mouse-split-window-vertically'.
It should provide everything you need in this regard.
martin
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: splitting a window at point
2018-04-17 0:23 splitting a window at point James K. Lowden
@ 2018-04-19 18:13 ` Tomas Nordin
[not found] ` <mailman.12737.1524161596.27995.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 5+ messages in thread
From: Tomas Nordin @ 2018-04-19 18:13 UTC (permalink / raw)
To: James K. Lowden, help-gnu-emacs
"James K. Lowden" <jklowden@speakeasy.net> writes:
> It seems like an obvious function: I'd like to split a window
> vertically, such that the top of the lower window is positioned where
> the cursor is. If I'm on line 6, the top window will have 6 lines, and
> the bottom window gets the rest. I (would) do this from time to time,
> to leave a function definition in the top window while in the lower
> window I operate on the code that uses it.
Freely interpreting the goal and not refraining from jumping around with
point a bit, does the following do approximately what you want?
(defun tn-split-window-defun ()
"Split window at point leaving beginning of defun visible in upper window."
(interactive)
(let ((start-pos (point))
(start-line (line-number-at-pos))
defun-lines)
(beginning-of-defun)
(setq defun-lines (1+ (- start-line (line-number-at-pos))))
(split-window-below defun-lines)
(window-resize nil (- defun-lines (window-body-height)))
(recenter 0)
(other-window 1)
(goto-char start-pos)
(recenter 0)))
--
Tomas
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: splitting a window at point
[not found] ` <mailman.12737.1524161596.27995.help-gnu-emacs@gnu.org>
@ 2018-04-20 0:42 ` James K. Lowden
2018-04-20 18:07 ` Tomas Nordin
0 siblings, 1 reply; 5+ messages in thread
From: James K. Lowden @ 2018-04-20 0:42 UTC (permalink / raw)
To: help-gnu-emacs
On Thu, 19 Apr 2018 20:13:01 +0200
Tomas Nordin <tomasn@posteo.net> wrote:
> Freely interpreting the goal and not refraining from jumping around
> with point a bit, does the following do approximately what you want?
Why, yes, Tomas, it does, and rather better than I had in mind. It
complains if the function is "too big to fit" (It says the window is
too small), but otherwise it very much does what I want.
I'm going to add it to my .emacs with your name on it, and give it
closer study when the mood arises. Thanks again!
Regards,
--jkl
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: splitting a window at point
2018-04-20 0:42 ` James K. Lowden
@ 2018-04-20 18:07 ` Tomas Nordin
0 siblings, 0 replies; 5+ messages in thread
From: Tomas Nordin @ 2018-04-20 18:07 UTC (permalink / raw)
To: James K. Lowden, help-gnu-emacs
"James K. Lowden" <jklowden@speakeasy.net> writes:
> On Thu, 19 Apr 2018 20:13:01 +0200
> Tomas Nordin <tomasn@posteo.net> wrote:
>
>> Freely interpreting the goal and not refraining from jumping around
>> with point a bit, does the following do approximately what you want?
>
> Why, yes, Tomas, it does, and rather better than I had in mind. It
> complains if the function is "too big to fit" (It says the window is
> too small), but otherwise it very much does what I want.
Cool that it worked as you wanted sort of. I can see that if calling
split-window-below with a SIZE argument with a number of lines that
require more window than it can fit, it errors. But that is kind of
natural I think.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-04-20 18:07 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-17 0:23 splitting a window at point James K. Lowden
2018-04-19 18:13 ` Tomas Nordin
[not found] ` <mailman.12737.1524161596.27995.help-gnu-emacs@gnu.org>
2018-04-20 0:42 ` James K. Lowden
2018-04-20 18:07 ` Tomas Nordin
-- strict thread matches above, loose matches on Subject: below --
2018-04-17 6:32 martin rudalics
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).