branch: elpa/paredit
commit 7e3b3f0c7af3c67f9c9c3c6b901559ce8cf2824b
Author: Taylor R Campbell <[email protected]>
Commit: Taylor R Campbell <[email protected]>
In `paredit-recenter-on-sexp', handle S-expressions larger than screen.
Ignore-this: 617dee9b848d79adfb69c7c8ad53e3f6
New command `paredit-recenter-on-defun'.
Thanks to Eitan Postavsky for the report.
darcs-hash:20110323002413-00fcc-1b422d9a7c39f930a862f8917cec8a868fa066b0
---
paredit.el | 33 ++++++++++++++++++++++++++-------
1 file changed, 26 insertions(+), 7 deletions(-)
diff --git a/paredit.el b/paredit.el
index 2e2fb28..b851a67 100644
--- a/paredit.el
+++ b/paredit.el
@@ -1750,7 +1750,7 @@ If that text is unbalanced, signal an error instead."
(if end-char-quote "" "not ")
phrase)))))
-;;;; Cursor and Screen Movement
+;;;; Point Motion
(eval-and-compile
(defmacro defun-saving-mark (name bvl doc &rest body)
@@ -1792,6 +1792,8 @@ With ARG, do this that many times.
A negative argument means move forward but still descend a level."
(interactive "p")
(down-list (- (or arg 1))))
+
+;;;; Window Positioning
(defalias 'paredit-recentre-on-sexp 'paredit-recenter-on-sexp)
@@ -1799,13 +1801,30 @@ A negative argument means move forward but still
descend a level."
"Recenter the screen on the S-expression following the point.
With a prefix argument N, encompass all N S-expressions forward."
(interactive "P")
- (save-excursion
- (forward-sexp n)
- (let ((end-point (point)))
- (backward-sexp n)
- (let ((start-point (point)))
+ (let* ((p (point))
+ (end-point (progn (forward-sexp n) (point)))
+ (start-point (progn (goto-char end-point) (backward-sexp n) (point))))
+ ;; Point is at beginning of first S-expression.
+ (let ((p-visible nil) (start-visible nil))
+ (save-excursion
(forward-line (/ (count-lines start-point end-point) 2))
- (recenter)))))
+ (recenter)
+ (setq p-visible (pos-visible-in-window-p p))
+ (setq start-visible (pos-visible-in-window-p start-point)))
+ (cond ((not start-visible)
+ ;; Implies (not p-visible). Put the start at the top of
+ ;; the screen.
+ (recenter 0))
+ (p-visible
+ ;; Go back to p if we can.
+ (goto-char p))))))
+
+(defun paredit-recenter-on-defun ()
+ "Recenter the screen on the definition at point."
+ (interactive)
+ (save-excursion
+ (beginning-of-defun)
+ (paredit-recenter-on-sexp)))
(defun paredit-focus-on-defun ()
"Moves display to the top of the definition at point."