From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tomas Nordin Newsgroups: gmane.emacs.help Subject: Re: splitting a window at point Date: Thu, 19 Apr 2018 20:13:01 +0200 Message-ID: <87in8n6p5e.fsf@fliptop.i-did-not-set--mail-host-address--so-tickle-me> References: <20180416202359.5216cf029e1ca2451a7ac5e7@speakeasy.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1524161498 3728 195.159.176.226 (19 Apr 2018 18:11:38 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 19 Apr 2018 18:11:38 +0000 (UTC) To: "James K. Lowden" , help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Apr 19 20:11:34 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1f9E1t-0000sG-Ra for geh-help-gnu-emacs@m.gmane.org; Thu, 19 Apr 2018 20:11:34 +0200 Original-Received: from localhost ([::1]:37600 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9E40-00086n-MI for geh-help-gnu-emacs@m.gmane.org; Thu, 19 Apr 2018 14:13:44 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57538) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9E3W-00085v-GQ for help-gnu-emacs@gnu.org; Thu, 19 Apr 2018 14:13:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f9E3S-0006Lf-Cp for help-gnu-emacs@gnu.org; Thu, 19 Apr 2018 14:13:14 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:59992) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f9E3S-0006Fp-0a for help-gnu-emacs@gnu.org; Thu, 19 Apr 2018 14:13:10 -0400 Original-Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id B396E22334 for ; Thu, 19 Apr 2018 20:13:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1524161584; bh=d8fdDszJdrjHaOfZATyQqnnGKyJ+ZZPg1D4ZSR8mZRU=; h=From:To:Subject:Date:From; b=rZG8/EuOkdth3qASSinHTLE6hlZ9LbacCGWKjDFQXq2jzasZ4pcsRqtA6CSg44CfF 6AkmWtfBAY/rIfqpPnHyRtGimVrkIeMgIqYhbDZYGmGpieQ/czV7bDRg9KaWD/+xle ICFtS/ELphQauT+G+hf2Cao2rKtYvUOU7zzpm4Z5JcwHbfoH4uUh5JLCy4l77gIULx FgMxH4eeK8qKvpX9LA2fQA7qaW2/MnRW1ggsed+49sC2h6ix71+AegOJ0ClIIB9LkP GwneGcdKhJZZY8mJHs0r3xXJKnKkBWGXnpgrYRS3njosLLJQJg/gGJpwPMDbyroKHC MSqCXWc3FSHTw== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 40RnCg47X7z9rxW; Thu, 19 Apr 2018 20:13:03 +0200 (CEST) In-Reply-To: <20180416202359.5216cf029e1ca2451a7ac5e7@speakeasy.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 185.67.36.65 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:116564 Archived-At: "James K. Lowden" 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