emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/lentic 10c91c51d5 110/333: Specialised beginning of lin


From: ELPA Syncer
Subject: [elpa] externals/lentic 10c91c51d5 110/333: Specialised beginning of line treatment.
Date: Tue, 27 Feb 2024 13:00:13 -0500 (EST)

branch: externals/lentic
commit 10c91c51d536326833e10176c6a9e3eda72af280
Author: Phillip Lord <phillip.lord@newcastle.ac.uk>
Commit: Phillip Lord <phillip.lord@newcastle.ac.uk>

    Specialised beginning of line treatment.
    
    The beginning of line is now treated specially to cover changes being
    made to the comment section in linked-buffer-block. Previously
    disruption to the comments would not percolate correctly.
    
    The converted start and stop values are now passed explicitly, rather
    than hidden in the conf object which makes this easier.
---
 linked-buffer-block.el     | 124 ++++++++++++++++++++++++++++++++++-----------
 linked-buffer-org.el       |  11 ++--
 linked-buffer.el           |  33 +++++++-----
 test/linked-buffer-test.el |   5 +-
 4 files changed, 124 insertions(+), 49 deletions(-)

diff --git a/linked-buffer-block.el b/linked-buffer-block.el
index 1e0cb758f8..22e0d97450 100644
--- a/linked-buffer-block.el
+++ b/linked-buffer-block.el
@@ -244,38 +244,101 @@ between the two buffers; we don't care which one has 
comments."
   ()
   "Configuration for blocked linked-buffer without comments.")
 
+(defun linked-buffer-bolp (buffer position)
+  (with-current-buffer
+      buffer
+      (save-excursion
+        (goto-char position)
+        (bolp))))
+
 (defmethod linked-buffer-clone
   ((conf linked-buffer-commented-block-configuration)
-   &optional start stop length-before)
+   &optional start stop length-before start-converted stop-converted)
   "Update the contents in the linked-buffer without comments"
   ;;(linked-buffer-log "blk-clone-uncomment (from):(%s)" conf)
-  ;; clone the buffer first
-  (call-next-method conf start stop length-before)
-  ;; remove the line comments in the to buffer
-  ;; if the delimitors are unmatched, then we can do nothing other than clone.
-  (condition-case e
-      (linked-buffer-blk-uncomment-buffer
-       conf
-       ;; the buffer at this point has been copied over, but is in an
-       ;; inconsistent state (because it may have comments that it should
-       ;; not). Still, the convertor should still work because it counts from
-       ;; the end
-       (linked-buffer-convert
-        conf
-        ;; point-min if we know nothing else
-        (or start (point-min)))
-       (linked-buffer-convert
-        conf
-        ;; if we have a stop
-        (if stop
-            ;; take stop (if we have got longer) or
-            ;; start length before (if we have got shorter)
-            (max stop
-                 (+ start length-before))
-          (point-max)))
-       (linked-buffer-that conf))
-    (unmatched-delimiter-error
-     nil)))
+  (let*
+      ;; we need to detect whether start or stop are in the comment region at
+      ;; the beginning of the file. We check this by looking at :that-buffer
+      ;; -- if we are in the magic region, then we must be at the start of
+      ;; line. In this case, we copy the entire line as it is in a hard to
+      ;; predict state. This is slightly over cautious (it also catches first
+      ;; character), but this is safe, it only causes the occasional
+      ;; unnecessary whole line copy. In normal typing "whole line" will be
+      ;; one character anyway
+      ((start-in-comment
+        (when
+            (and start
+                 (linked-buffer-bolp
+                  (oref conf :that-buffer)
+                  start-converted))
+          (m-buffer-with-current-location
+              (oref conf :this-buffer)
+              start
+            (line-beginning-position))))
+       (start (or start-in-comment start))
+       (start-converted
+        (if start-in-comment
+          (with-current-buffer
+              (oref conf :that-buffer)
+            (save-excursion
+              (goto-char start-converted)
+              (line-beginning-position)))
+          start-converted))
+       ;; likewise for stop
+       (stop-in-comment
+        (when
+            (and start
+                 (linked-buffer-bolp
+                  (oref conf :that-buffer)
+                  stop-converted))
+          (m-buffer-with-current-location
+              (oref conf :this-buffer)
+              stop
+            (line-end-position))))
+       (stop (or stop-in-comment stop))
+       (stop-converted
+        (if stop-in-comment
+            (with-current-buffer
+                (oref conf :that-buffer)
+              (save-excursion
+                (goto-char stop-converted)
+                (line-end-position)))
+          stop-converted)))
+    ;; log when we have gone long
+    (if (or start-in-comment stop-in-comment)
+        (linked-buffer-log "In comment: %s %s"
+                           (when start-in-comment
+                             "start")
+                           (when stop-in-comment
+                             "stop")))
+        ;; now clone the buffer
+    (call-next-method conf start stop length-before
+                      start-converted stop-converted)
+    ;; remove the line comments in the to buffer
+    ;; if the delimitors are unmatched, then we can do nothing other than 
clone.
+    (condition-case e
+        (linked-buffer-blk-uncomment-buffer
+         conf
+         ;; the buffer at this point has been copied over, but is in an
+         ;; inconsistent state (because it may have comments that it should
+         ;; not). Still, the convertor should still work because it counts from
+         ;; the end
+         (linked-buffer-convert
+          conf
+          ;; point-min if we know nothing else
+          (or start (point-min)))
+         (linked-buffer-convert
+          conf
+          ;; if we have a stop
+          (if stop
+              ;; take stop (if we have got longer) or
+              ;; start length before (if we have got shorter)
+              (max stop
+                   (+ start length-before))
+            (point-max)))
+         (linked-buffer-that conf))
+      (unmatched-delimiter-error
+       nil))))
 
 (defmethod linked-buffer-invert
   ((conf linked-buffer-commented-block-configuration))
@@ -301,10 +364,11 @@ between the two buffers; we don't care which one has 
comments."
 
 (defmethod linked-buffer-clone
   ((conf linked-buffer-uncommented-block-configuration)
-   &optional start stop length-before)
+   &optional start stop length-before start-converted stop-converted)
   "Update the contents in the linked-buffer with comments."
   ;;(linked-buffer-log "blk-clone-comment conf):(%s)" conf)
-  (call-next-method conf start stop length-before)
+  (call-next-method conf start stop length-before
+                    start-converted stop-converted)
   (condition-case e
       (linked-buffer-blk-comment-buffer
        conf
diff --git a/linked-buffer-org.el b/linked-buffer-org.el
index bc86fae6e6..0a05324a3b 100644
--- a/linked-buffer-org.el
+++ b/linked-buffer-org.el
@@ -211,9 +211,11 @@
 
 (defmethod linked-buffer-clone
   ((conf linked-buffer-org-to-orgel-configuration)
-   &optional start stop length-before)
+   &optional start stop length-before
+   start-converted stop-converted)
   ;; do everything else to the buffer
-  (call-next-method conf)
+  (call-next-method conf start stop length-before
+                    start-converted stop-converted)
   (m-buffer-replace-match
    (m-buffer-match
     (linked-buffer-that conf)
@@ -273,9 +275,10 @@
 
 (defmethod linked-buffer-clone
   ((conf linked-buffer-orgel-to-org-configuration)
-   &optional start stop length-before)
+   &optional start stop length-before start-converted stop-converted)
   ;; do everything else to the buffer
-  (call-next-method conf)
+  (call-next-method conf start stop length-before
+                    start-converted stop-converted)
   (m-buffer-replace-match
    (m-buffer-match
     (linked-buffer-that conf)
diff --git a/linked-buffer.el b/linked-buffer.el
index 793b40daa0..90d1a7fa73 100644
--- a/linked-buffer.el
+++ b/linked-buffer.el
@@ -154,8 +154,6 @@ of mode in the current buffer.")
 (defun linked-buffer-config-name (buffer)
   "Given BUFFER, return a name for the configuration object."
   (format "linked: %s" buffer))
-
-
 ;; #+end_src
 
 ;; ** Base Configuration
@@ -273,7 +271,8 @@ the linked-buffer."
   location)
 
 (defmethod linked-buffer-clone ((conf linked-buffer-configuration)
-                                &optional start stop length-before)
+                                &optional start stop _length-before
+                                start-converted stop-converted)
   "Updates that-buffer to reflect the contents in this-buffer.
 
 Currently, this is just a clone all method but may use regions in future."
@@ -283,19 +282,15 @@ Currently, this is just a clone all method but may use 
regions in future."
       ;;(linked-buffer-log "this-b (point,start,stop)(%s,%s,%s)" (point) start 
stop)
       (let* ((start (or start (point-min)))
              (stop (or stop (point-max)))
-             (length-before (or length-before (buffer-size that-b)))
              ;; get the start location that we converted before the change.
              ;; linked-buffer-convert is not reliable now, because the two
              ;; buffers do not share state until we have percolated it
              (converted-start
-              (or (oref conf :last-change-start-converted)
+              (or start-converted
                   (point-min)))
              (converted-stop
-              (or (oref conf :last-change-stop-converted)
+              (or stop-converted
                   (point-max))))
-        ;; used this, so dump it
-        (oset conf :last-change-start-converted nil)
-        (oset conf :last-change-stop-converted nil)
         (with-current-buffer that-b
           (delete-region (max (point-min) converted-start)
                          (min (point-max) converted-stop))
@@ -567,12 +562,26 @@ REST is currently just ignored."
   "Update the contents of that-buffer with the contents of this-buffer.
 Update mechanism depends on CONF."
   (unwind-protect
-      (progn
+      (m-buffer-with-markers
+          ((start-converted
+            (when (oref conf :last-change-start-converted)
+              (set-marker (make-marker)
+                          (oref conf :last-change-start-converted)
+                          (oref conf :that-buffer))))
+           (stop-converted
+            (when (oref conf :last-change-stop-converted)
+                (set-marker (make-marker)
+                            (oref conf :last-change-stop-converted)
+                            (oref conf :that-buffer)))))
+        ;; used these, so dump them
+        (oset conf :last-change-start-converted nil)
+        (oset conf :last-change-stop-converted nil)
         (setq inhibit-read-only t)
         ;;(linked-buffer-log
         ;;"Update config: %s" linked-buffer-config)
-        (linked-buffer-clone conf start stop length-before))
-    (setq inhibit-read-only nil)))
+        (linked-buffer-clone conf start stop length-before
+                             start-converted stop-converted)
+        (setq inhibit-read-only nil))))
 
 (defun linked-buffer-update-point (conf)
   "Update the location of point in that-buffer to reflect this-buffer.
diff --git a/test/linked-buffer-test.el b/test/linked-buffer-test.el
index cf19bb33ec..5a45cb1e89 100644
--- a/test/linked-buffer-test.el
+++ b/test/linked-buffer-test.el
@@ -263,13 +263,12 @@ This mostly checks my test machinary."
 
 (ert-deftest clojure-latex-first-line ()
   "Tests for a bug after introduction of incremental blocks."
-  :expected-result :failed
   (should
    (linked-buffer-test-clone-and-change-equal
     'linked-buffer-clojure-latex-init
     "block-comment.clj" "block-comment.tex"
     (lambda ()
-      (delete-char 0)
-      (delete-char 0)
+      (delete-char 1)
+      (delete-char 1)
       (insert ";")
       (insert ";")))))



reply via email to

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