emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

recenter-ratio (was: Re: Toolbars on MacOSX)


From: Juri Linkov
Subject: recenter-ratio (was: Re: Toolbars on MacOSX)
Date: Thu, 13 May 2004 07:33:33 +0300
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (gnu/linux)

YAMAMOTO Mitsuharu <address@hidden> writes:
>   
> http://developer.apple.com/documentation/UserExperience/Conceptual/OSXHIGuidelines/XHIGWindows/chapter_16_section_3.html#//apple_ref/doc/uid/20000961/BABIFCFJ

I must say that Apple human interface guidelines define very
well-researched principles of implementing the good user interfaces.
I will not discuss its usefulness for Emacs design now, but one
chapter reminded me about an improvement I wanted to propose for
addition to Emacs.  The chapter at

http://developer.apple.com/documentation/UserExperience/Conceptual/OSXHIGuidelines/XHIGWindows/chapter_16_section_4.html#//apple_ref/doc/uid/20000961-BACFHDHE

defines a concept of "visually centered placement", where the distance
from the bottom to the center should be approximately twice the
distance as that from the center to the top.  This applies to the
window positioning, but the same principle makes sense also for the
cursor positioning in Emacs.  Currently by default the cursor is
always placed exactly in the center of the window (i.e. on the window
line equal to the window height divided by the constant 2).  I use
a special key to scroll the window to adjust the place with the cursor
to more convenient vertical position (which is about 1/3 of the window
height).  Unfortunately, currently it is not possible to change the
hard-coded default cursor position.

The following patch introduces a new variable with the default value 2.
Its value defines a ratio at which the cursor is placed by default
from the top of the window relative to the window height.  It even
can be set to the Golden Ratio if one wishes so:

(setq recenter-ratio (expt (/ (1+ (sqrt 5)) 2) 2))

Index: emacs/src/window.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/window.c,v
retrieving revision 1.465
diff -u -r1.465 window.c
--- emacs/src/window.c  7 May 2004 00:43:49 -0000       1.465
+++ emacs/src/window.c  13 May 2004 04:34:11 -0000
@@ -120,6 +120,10 @@
 
 Lisp_Object Vother_window_scroll_buffer;
 
+Lisp_Object Vrecenter_ratio;
+
 /* Non-nil means it's function to call to display temp buffers.  */
 
 Lisp_Object Vtemp_buffer_show_function;
@@ -5172,7 +5221,7 @@
       int ht = window_internal_height (w);
 
       if (center_p)
-       arg = make_number (ht / 2);
+       arg = make_number (ht / XFLOATINT (Vrecenter_ratio));
       else if (XINT (arg) < 0)
        arg = make_number (XINT (arg) + ht);
 
@@ -5241,7 +5290,7 @@
 
   lines = displayed_window_lines (w);
   if (NILP (arg))
-    XSETFASTINT (arg, lines / 2);
+    XSETFASTINT (arg, lines / XFLOATINT (Vrecenter_ratio));
   else
     {
       arg = Fprefix_numeric_value (arg);
@@ -6474,6 +6523,10 @@
               doc: /* If non-nil, this is a buffer and \\[scroll-other-window] 
should scroll its window.  */);
   Vother_window_scroll_buffer = Qnil;
 
+  DEFVAR_LISP ("recenter-ratio", &Vrecenter_ratio,
+              doc: /* Ratio to recenter cursor.  */);
+  Vrecenter_ratio = 2;
+
   DEFVAR_BOOL ("pop-up-frames", &pop_up_frames,
               doc: /* *Non-nil means `display-buffer' should make a separate 
frame.  */);
   pop_up_frames = 0;

Index: emacs/src/xdisp.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/xdisp.c,v
retrieving revision 1.888
diff -u -r1.888 xdisp.c
--- emacs/src/xdisp.c   10 May 2004 11:16:37 -0000      1.888
+++ emacs/src/xdisp.c   13 May 2004 03:34:29 -0000
@@ -229,6 +229,8 @@
 extern Lisp_Object Qwhen;
 extern Lisp_Object Qhelp_echo;
 
+extern Lisp_Object Vrecenter_ratio;
+
 Lisp_Object Qoverriding_local_map, Qoverriding_terminal_local_map;
 Lisp_Object Qwindow_scroll_functions, Vwindow_scroll_functions;
 Lisp_Object Qredisplay_end_trigger_functions;
@@ -11722,7 +11724,7 @@
          /* If point does not appear, try to move point so it does
             appear. The desired matrix has been built above, so we
             can use it here.  */
-         new_vpos = window_box_height (w) / 2;
+         new_vpos = window_box_height (w) / XFLOATINT (Vrecenter_ratio);
        }
 
       if (!make_cursor_line_fully_visible (w, 0))
@@ -11922,7 +11924,7 @@
   /* Finally, just choose place to start which centers point */
 
  recenter:
-  centering_position = window_box_height (w) / 2;
+  centering_position = window_box_height (w) / XFLOATINT (Vrecenter_ratio);
 
  point_at_top:
   /* Jump here with centering_position already set to 0.  */

-- 
Juri Linkov
http://www.jurta.org/emacs/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]