From aaab6e57e0b1ebe297d66a22299edbab909fd0c8 Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@justemail.net>
Date: Fri, 6 May 2016 21:57:25 +0200
Subject: [PATCH] screen: when using positionlog, show as much of the file as
 possible

When opening a file that was edited before, and the remembered position
is near the end of the file, then don't center the target line but show
the last line of the file on the bottom line of the screen, thus showing
as much of the file content as possible.

This addresses https://savannah.gnu.org/bugs/?46243.
---
 src/search.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/search.c b/src/search.c
index dd75f6ce..622f1588 100644
--- a/src/search.c
+++ b/src/search.c
@@ -955,13 +955,22 @@ void do_gotolinecolumn(ssize_t line, ssize_t column, bool use_answer,
     openfile->current_x = actual_x(openfile->current->data, column - 1);
     openfile->placewewant = column - 1;
 
-    /* Put the top line of the edit window in range of the current line. */
-    edit_update(CENTERING);
-
-    /* When in interactive mode, update the screen. */
+    /* When the position was manually given, center the target line. */
     if (interactive) {
+	edit_update(CENTERING);
 	edit_refresh();
 	display_main_list();
+    } else {
+	/* If the target line is close to the tail of the file, put the last
+	 * line of the file on the bottom line of the screen; otherwise, just
+	 * center the target line. */
+	if (openfile->filebot->lineno - openfile->current->lineno <
+							editwinrows / 2) {
+	    openfile->current_y = editwinrows - openfile->filebot->lineno +
+					openfile->current->lineno - 1;
+	    edit_update(STATIONARY);
+	} else
+	    edit_update(CENTERING);
     }
 }
 
-- 
GitLab