all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tomas Nordin <tomasn@posteo.net>
To: "James K. Lowden" <jklowden@speakeasy.net>, help-gnu-emacs@gnu.org
Subject: Re: splitting a window at point
Date: Thu, 19 Apr 2018 20:13:01 +0200	[thread overview]
Message-ID: <87in8n6p5e.fsf@fliptop.i-did-not-set--mail-host-address--so-tickle-me> (raw)
In-Reply-To: <20180416202359.5216cf029e1ca2451a7ac5e7@speakeasy.net>

"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



  reply	other threads:[~2018-04-19 18:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-17  0:23 splitting a window at point James K. Lowden
2018-04-19 18:13 ` Tomas Nordin [this message]
     [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

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=87in8n6p5e.fsf@fliptop.i-did-not-set--mail-host-address--so-tickle-me \
    --to=tomasn@posteo.net \
    --cc=help-gnu-emacs@gnu.org \
    --cc=jklowden@speakeasy.net \
    /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.