[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: splitting a window at point
From: |
Tomas Nordin |
Subject: |
Re: splitting a window at point |
Date: |
Thu, 19 Apr 2018 20:13:01 +0200 |
"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