[COMMIT] If the position of a window's cached point is deleted, use buffer point instead

Aidan Kehoe <[email protected]>
Newsgroups gmane.emacs.xemacs.beta,gmane.emacs.xemacs.patches
Message-ID <[email protected]>
APPROVE COMMIT

NOTE: Ths patch has been committed.

 Ar an seachtú lá déag de mí Meitheamh, scríobh Michael Heinrich: 

 > I tested it with 21.5.34 and it works for me.  Cursor-position stays at
 > the right place in dired buffer after editing a file.  Thank you.

Great!

# HG changeset patch
# User Aidan Kehoe <[email protected]>
# Date 1403034945 -3600
#      Tue Jun 17 20:55:45 2014 +0100
# Node ID a1808d52a34a15175e99534534b4a3668135bbda
# Parent  acf1c26e3019f3e8171b591c5b9e120f87187012
If the position of a window's cached point is deleted, use buffer point instead

src/ChangeLog addition:

2014-06-17  Aidan Kehoe  <[email protected]>

	* extents.h:
	* window.c:
	* window.c (unshow_buffer):
	* window.c (Fset_window_buffer):
	Use extents, rather than markers, for the window buffer point
	cache, so that when the text containing that window buffer point
	is deleted, the window display code uses the buffer's actual point
	instead of the position that the marker had been moved to.
	Fixes Michael Heinrich's problem of
	http://mid.gmane.org/[email protected] ,
	introduced by Ben's patch of
	https://bitbucket.org/xemacs/xemacs/commits/047d37eb70d70f43803 .

diff -r acf1c26e3019 -r a1808d52a34a src/ChangeLog
--- a/src/ChangeLog	Thu May 15 12:25:25 2014 -0600
+++ b/src/ChangeLog	Tue Jun 17 20:55:45 2014 +0100
@@ -1,3 +1,18 @@
+2014-06-17  Aidan Kehoe  <[email protected]>
+
+	* extents.h:
+	* window.c:
+	* window.c (unshow_buffer):
+	* window.c (Fset_window_buffer):
+	Use extents, rather than markers, for the window buffer point
+	cache, so that when the text containing that window buffer point
+	is deleted, the window display code uses the buffer's actual point
+	instead of the position that the marker had been moved to.
+	Fixes Michael Heinrich's problem of
+	http://mid.gmane.org/[email protected] ,
+	introduced by Ben's patch of
+	https://bitbucket.org/xemacs/xemacs/commits/047d37eb70d70f43803 . 
+
 2014-05-08  Jerry James  <[email protected]>
 
 	* print.c (struct debug_bindings): Add print_circle field.
diff -r acf1c26e3019 -r a1808d52a34a src/extents.h
--- a/src/extents.h	Thu May 15 12:25:25 2014 -0600
+++ b/src/extents.h	Tue Jun 17 20:55:45 2014 +0100
@@ -132,6 +132,7 @@
 EXFUN (Fextent_property, 3);
 EXFUN (Fput_text_property, 5);
 
+EXFUN (Fextent_detached_p, 1);
 EXFUN (Fdetach_extent, 1);
 EXFUN (Fextent_end_position, 1);
 EXFUN (Fextent_object, 1);
diff -r acf1c26e3019 -r a1808d52a34a src/window.c
--- a/src/window.c	Thu May 15 12:25:25 2014 -0600
+++ b/src/window.c	Tue Jun 17 20:55:45 2014 +0100
@@ -41,6 +41,7 @@
 #include "commands.h"
 #include "device-impl.h"
 #include "elhash.h"
+#include "extents.h"
 #include "faces.h"
 #include "frame-impl.h"
 #include "glyphs.h"
@@ -2047,17 +2048,29 @@
 		 BUF_ZV (b)));
 
   {
-    Lisp_Object marker = Fgethash (buf, w->saved_point_cache, Qnil);
+    Lisp_Object marker;
+    Lisp_Object saved_point = Fgethash (buf, w->saved_point_cache, Qnil);
     int selected = EQ (wrap_window (w), Fselected_window (Qnil));
 
-    if (NILP (marker))
+    if (NILP (saved_point))
       {
-	marker = Fmake_marker ();
-	Fputhash (buf, marker, w->saved_point_cache);
+	saved_point = Fmake_extent (Qnil, Qnil, buf);
+        Fset_extent_property (saved_point, Qstart_open, Qt);
+	Fputhash (buf, saved_point, w->saved_point_cache);
       }
-    Fset_marker (marker,
-		 selected ? make_fixnum (BUF_PT (b)) : w->pointm[CURRENT_DISP],
-		 buf);
+
+    if (selected)
+      {
+        set_extent_endpoints (XEXTENT (saved_point),
+                              BYTE_BUF_PT (b), BYTE_BUF_PT (b), buf);
+      }
+    else
+      {
+        set_extent_endpoints (XEXTENT (saved_point),
+                              byte_marker_position (w->pointm[CURRENT_DISP]),
+                              byte_marker_position (w->pointm[CURRENT_DISP]),
+                              buf);
+      }
 
     marker = Fgethash (buf, w->saved_last_window_start_cache, Qnil);
 
@@ -3710,10 +3723,12 @@
 			 buffer);
 #else
   {
-    Lisp_Object marker = Fgethash (buffer, w->saved_point_cache, Qnil);
+    Lisp_Object saved_point = Fgethash (buffer, w->saved_point_cache, Qnil);
     Lisp_Object newpoint =
-      !NILP (marker) ? make_fixnum (marker_position (marker)) :
-      make_fixnum (BUF_PT (XBUFFER (buffer)));
+      (EXTENTP (saved_point) && !NILP (Fextent_detached_p (saved_point)))
+      ? Fextent_start_position (saved_point)
+: make_fixnum (BUF_PT (XBUFFER (buffer)));
+    Lisp_Object marker;
     /* Previously, we had in here set-window-point, which did one of the
        following two, but not both.  However, that could result in pointm
        being in a different buffer from the window's buffer!  Probably



-- 
‘Liston operated so fast that he once accidentally amputated an assistant’s
fingers along with a patient’s leg, […] The patient and the assistant both
died of sepsis, and a spectator reportedly died of shock, resulting in the
only known procedure with a 300% mortality.’ (Atul Gawande, NEJM, 2012)

_______________________________________________
XEmacs-Beta mailing list
[email protected]
http://lists.xemacs.org/mailman/listinfo/xemacs-beta
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.