all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Framework extending window functions for Follow Mode (etc.).
@ 2015-11-05 19:29 Alan Mackenzie
  2015-11-05 19:36 ` John Wiegley
                   ` (3 more replies)
  0 siblings, 4 replies; 57+ messages in thread
From: Alan Mackenzie @ 2015-11-05 19:29 UTC (permalink / raw)
  To: emacs-devel

Hello, Emacs.

Partly out of a need to nail down bug #17453, partly out of a need to
make it easier for arbitrary libraries to work with Follow Mode, partly
at the suggestion of Eli, I now propose the following.

The six functions window-start, window-end, set-window-start, recenter,
pos-visible-in-window-p, and move-to-window-line-function will acquire
an extra optional parameter GROUP.  The notion is that "this call is
interested in groups of windows, not just single ones".

Each of these functions will get an associated variable, e.g.
"window-start-function".  The function will call the value of that
variable instead of doing its normal actions, when GROUP is non-nil.
Typically, the `window-start-function' will recursively call
window-start (on some window) to perform its operation.

window-start-function, and friends, will be set by Follow Mode in its
initialisation, and unset when it is disabled.

Here is one sixth of the patch for this change (excluding changes to the
manual).  As a patch, it probably won't work because of all the
deletions.  (The whole of the patch would quickly become tedious.)



diff --git a/src/window.c b/src/window.c
index d61f586..46adda7 100644
--- a/src/window.c
+++ b/src/window.c
@@ -1655,30 +1671,39 @@ Return POS.  */)
   return pos;
 }
 
-DEFUN ("set-window-start", Fset_window_start, Sset_window_start, 2, 3, 0,
+DEFUN ("set-window-start", Fset_window_start, Sset_window_start, 2, 4, 0,
        doc: /* Make display in WINDOW start at position POS in WINDOW's buffer.
 WINDOW must be a live window and defaults to the selected one.  Return
 POS.  Optional third arg NOFORCE non-nil inhibits next redisplay from
-overriding motion of point in order to display at this exact start.  */)
-  (Lisp_Object window, Lisp_Object pos, Lisp_Object noforce)
+overriding motion of point in order to display at this exact start.
+
+If GROUP is non-nil, and `set-window-start-function' is set to a function,
+then instead of the above, that function is called with the three arguments
+WINDOW, POS, and NOFORCE, and its result returned.  */)
+  (Lisp_Object window, Lisp_Object pos, Lisp_Object noforce, Lisp_Object group)
 {
-  register struct window *w = decode_live_window (window);
+  if (!NILP (group)
+      && FUNCTIONP (Vset_window_start_function))
+    return call3 (Vset_window_start_function, window, pos, noforce);
+  {
+    register struct window *w = decode_live_window (window);
 
-  set_marker_restricted (w->start, pos, w->contents);
-  /* This is not right, but much easier than doing what is right.  */
-  w->start_at_line_beg = false;
-  if (NILP (noforce))
-    w->force_start = true;
-  w->update_mode_line = true;
-  /* Bug#15957.  */
-  w->window_end_valid = false;
-  wset_redisplay (w);
+    set_marker_restricted (w->start, pos, w->contents);
+    /* This is not right, but much easier than doing what is right.  */
+    w->start_at_line_beg = false;
+    if (NILP (noforce))
+      w->force_start = true;
+    w->update_mode_line = true;
+    /* Bug#15957.  */
+    w->window_end_valid = false;
+    wset_redisplay (w);
 
-  return pos;
+    return pos;
+  }
 }
 
 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p,
@@ -7159,7 +7212,15 @@ syms_of_window (void)
   DEFSYM (Qclone_of, "clone-of");
   DEFSYM (Qfloor, "floor");
   DEFSYM (Qceiling, "ceiling");
-
+  DEFSYM (Qwindow_start_function, "window-start-function");
+  DEFSYM (Qwindow_end_function, "window-end-function");
+  DEFSYM (Qset_window_start_function, "set-window-start-function");
+  DEFSYM (Qrecenter_function, "recenter-function");
+  DEFSYM (Qpos_visible_in_window_p_function, "pos-visible-in-window-p-function");
+  DEFSYM (Qmove_to_window_line_function, "move-to-window-line-function");
+  
   staticpro (&Vwindow_list);
 
   minibuf_selected_window = Qnil;
@@ -7330,6 +7391,70 @@ Note that this optimization can cause the portion of the buffer
+  DEFVAR_LISP ("set-window-start-function", Vset_window_start_function,
+               doc: /* The function to call for `set-window-start' when its GROUP parameter is non-nil.
+When this variable contains a function, and `set-window-start' is called
+with a non-nil GROUP parameter, the function is called instead of
+`set-window-start''s normal action.  `set-window-start' passes the function
+its three parameters WINDOW, POS, and NOFORCE.  The function may call
+`set-window-start' recursively.  */);
+  Vset_window_start_function = Qnil;
+  Fmake_variable_buffer_local (Qset_window_start_function);
+  Fput (Qset_window_start_function, Qpermanent_local, Qt);
+



-- 
Alan Mackenzie (Nuremberg, Germany).



^ permalink raw reply related	[flat|nested] 57+ messages in thread

end of thread, other threads:[~2015-12-08  0:42 UTC | newest]

Thread overview: 57+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-05 19:29 Framework extending window functions for Follow Mode (etc.) Alan Mackenzie
2015-11-05 19:36 ` John Wiegley
2015-11-05 20:00   ` Alan Mackenzie
2015-11-07 13:07 ` Alan Mackenzie
2015-11-09 22:30   ` John Wiegley
2015-11-10 11:27     ` Alan Mackenzie
2015-11-10 13:13     ` Alan Mackenzie
2015-11-10 15:20       ` John Wiegley
2015-11-10 22:29       ` John Wiegley
2015-11-11  0:30         ` Alan Mackenzie
2015-11-11  0:34           ` John Wiegley
2015-11-11 16:15             ` Alan Mackenzie
2015-11-11 16:50               ` John Wiegley
2015-11-11 17:15                 ` Comms and building Emacs. [Re: Framework extending window functions for Follow Mode (etc.).] Alan Mackenzie
2015-11-11 17:58                   ` Alan Mackenzie
2015-11-07 13:26 ` Framework extending window functions for Follow Mode (etc.) martin rudalics
2015-11-07 13:57   ` Alan Mackenzie
2015-11-07 15:18     ` martin rudalics
2015-11-07 16:12       ` Alan Mackenzie
2015-11-07 17:07         ` martin rudalics
2015-11-07 18:55           ` Alan Mackenzie
2015-11-08  9:22             ` martin rudalics
2015-11-08 12:13               ` Alan Mackenzie
2015-11-08 18:10                 ` martin rudalics
2015-11-08 19:57                   ` Alan Mackenzie
2015-11-09  8:25                     ` martin rudalics
2015-11-09 17:03                       ` Alan Mackenzie
2015-11-07 17:54 ` Artur Malabarba
2015-11-07 18:24   ` Alan Mackenzie
2015-11-07 21:58     ` Juri Linkov
2015-11-08  0:29       ` Alan Mackenzie
2015-11-08  9:23         ` martin rudalics
2015-11-09  0:50         ` Juri Linkov
2015-11-09 15:41           ` bug#17453: " Alan Mackenzie
2015-11-09 15:41           ` Alan Mackenzie
2015-11-10  0:51             ` bug#17453: " Juri Linkov
2015-11-10 11:08               ` Alan Mackenzie
2015-11-11  0:12                 ` Juri Linkov
2015-11-11 16:19                   ` Alan Mackenzie
2015-11-12  0:52                     ` Juri Linkov
2015-11-12  8:22                       ` martin rudalics
2015-11-12 20:14                         ` Juri Linkov
2015-11-17 22:55                           ` Alan Mackenzie
2015-11-18  0:38                             ` Juri Linkov
2015-11-18 17:58                               ` Alan Mackenzie
2015-11-18 21:28                                 ` Alan Mackenzie
2015-11-19  0:45                                 ` Juri Linkov
2015-11-25 19:33                                   ` Alan Mackenzie
2015-11-26 23:03                                     ` Juri Linkov
2015-11-30 20:37                                       ` Alan Mackenzie
2015-12-01  0:07                                         ` Juri Linkov
2015-12-05 16:40                                           ` Alan Mackenzie
2015-12-05 23:06                                             ` Juri Linkov
2015-12-07 19:15                                               ` Alan Mackenzie
2015-12-08  0:42                                                 ` Juri Linkov
2015-11-12 22:15                       ` Alan Mackenzie
2015-11-09  0:50         ` Juri Linkov

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.