🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.help
Article #189477

Re: Recenter-definition (request)

#189477
From: Sebastian Kremer
Date: Fri, 18 Jan 1991 17:38
54 lines
3020 bytes
>>> On 16 Jan 91 08:41:17 GMT, mernst@theory.lcs.mit.edu (Michael Ernst) said:

Michael> Has anyone implemented recenter-definition?  This function,
Michael> which was bound to M-C-r in ZMACS, scrolled the window so
Michael> that the current definition (and possibly preceding comments)
Michael> was fully visible.  This was a great boon when trying to see
Michael> all of a function's definition at once -- one keystroke, not
Michael> a bunch of fiddling with scrolling and C-l, did the trick.

I have a version of recenter bound to C-l that cycles point through
the three interesting positions in the window: top, bottom and middle.
So at most two C-l's take point where you want it.

It it is less smart, but more general than the function you wanted.  I
use it a lot and find it more useful than the standard C-l behaviour.

-- cut here --

(defun current-line () ; this function from the elisp manual
  "Return the vertical position of point in the selected window.  
Top line is 0.  Counts each text line only once, even if it wraps."
  (+ (count-lines (window-start) (point))
     (if (= (current-column) 0) 1 0)
     -1))

(global-set-key "\C-l" 'smart-recenter)
(defun smart-recenter (&optional arg)
  "Recenter window, trying to be smart about it.
If on last line of window, make this line to the middle window line.
  If on first line, make it the last.  Anything else, make it the first.
Thus invoking this command repeatedly will cycle you through the
  top, last and middle position.
With one \\[universal-argument], just refresh display without moving.
With a specific ARG, make current line the ARG'th window line.

Bug: does not know about wrapped lines."
  (interactive "P")
  (let* ((ht (window-height (selected-window)))
	 (ht-half (/ ht 2)) 
	 (line (current-line)))
    (if (equal arg '(4))
	;; (redraw-display) bombs in Epoch 3.1.
	(progn (recenter) (recenter line))
      (recenter (cond (arg (prefix-numeric-value arg))
		      ;; testing (= line ht-half) fails for even-sized
		      ;; windows
		      ((equal line (- ht 2)) ht-half)
		      ((equal line 0) -1)
		      (t 0))))))
-- cut here --
--

Sebastian Kremer <sk@thp.Uni-Koeln.DE>
Institute of Theoretical Physics, University of Cologne, F. R. of Germany
Technical Details
Message-ID: <SK.91Jan18173803@sun0.thp.uni-koeln.de>
Path: arc1-ca.pugleaf.net!gmdzi!unido!uni-koeln!aix370.rrz.uni-koeln.de!sk
References: <MERNST.91Jan16004117@emu.lcs.mit.edu>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 103b8b,4bd0029937a7c494
X-Google-Attributes: gid103b8b,public
X-Google-ArrivalTime: 1991-01-21 16:48:52 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!uni-koeln!aix370.rrz.uni-koeln.de!sk
From: sk@thp.uni-koeln.de (Sebastian Kremer)
Newsgroups: gnu.emacs.help
Subject: Re: Recenter-definition (request)
Message-ID: <SK.91Jan18173803@sun0.thp.uni-koeln.de>
Date: 18 Jan 91 17:38:03 GMT
References: <MERNST.91Jan16004117@emu.lcs.mit.edu>
Sender: news@rrz.uni-koeln.de (Usenet News System)
Distribution: gnu
Organization: Institute of Theoretical Physics, University of Cologne, F. R.
 Germany
Lines: 54
In-Reply-To: mernst@theory.lcs.mit.edu's message of 16 Jan 91 08:41:17 GMT