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

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

[elpa] externals/lentic dea9f03ab8 103/333: Only update regions which ov


From: ELPA Syncer
Subject: [elpa] externals/lentic dea9f03ab8 103/333: Only update regions which overlap the change.
Date: Tue, 27 Feb 2024 13:00:12 -0500 (EST)

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

    Only update regions which overlap the change.
    
    Previously, all regions were updated even if they were outside the
    change region. While this had no functional changes, it was
    computationally expensive.
---
 dev-resources/block-comment-changed-first-line.tex |  8 ++
 linked-buffer-block.el                             | 88 +++++++++++++---------
 test/linked-buffer-test.el                         |  5 +-
 3 files changed, 64 insertions(+), 37 deletions(-)

diff --git a/dev-resources/block-comment-changed-first-line.tex 
b/dev-resources/block-comment-changed-first-line.tex
new file mode 100644
index 0000000000..95a9e72e60
--- /dev/null
+++ b/dev-resources/block-comment-changed-first-line.tex
@@ -0,0 +1,8 @@
+inserted
+Commented Code
+
+\begin{code}
+(comment "code")
+\end{code}
+
+Commented Code
diff --git a/linked-buffer-block.el b/linked-buffer-block.el
index 6ce4343880..11fa488df8 100644
--- a/linked-buffer-block.el
+++ b/linked-buffer-block.el
@@ -87,22 +87,31 @@ function `linked-buffer-configuration' object."
 
 (defun linked-buffer-blk-uncomment-buffer (conf begin end buffer)
   "Given CONF, a `linked-buffer-configuration' object, remove all
-start of line comment-characters in appropriate blocks between
-BEGIN and END in BUFFER."
+start of line comment-characters in appropriate blocks. Changes
+should only have occurred between BEGIN and END in BUFFER."
   (-map
    (lambda (pairs)
-     (prog1
-         (linked-buffer-blk-uncomment-region
-          conf
-          (car pairs) (cdr pairs) buffer)
+     (let* 
+         ((block-begin (car pairs))
+          (block-end (cdr pairs))
+          (rtn
+           (when
+               (and (>= end block-begin)
+                    (>= block-end begin))
+             (linked-buffer-blk-uncomment-region
+              conf
+              block-begin block-end buffer))))
        ;; remove markers as we go
        (set-marker (car pairs) nil)
-       (set-marker (cdr pairs) nil)))
-   (linked-buffer-blk-marker-boundaries conf begin end buffer)))
+       (set-marker (cdr pairs) nil)
+       rtn))
+   (linked-buffer-blk-marker-boundaries 
+    conf buffer)))
 
 (defun linked-buffer-blk-comment-region (conf begin end buffer)
   "Given CONF, a `linked-buffer-configuration' object, add
 start of line comment characters beween BEGIN and END in BUFFER."
+  (linked-buffer-log "comment-region (%s,%s,%s)" begin end buffer)
   (let ((line-match
          (m-buffer-match
           buffer
@@ -126,17 +135,23 @@ start of line comment characters beween BEGIN and END in 
BUFFER."
 
 (defun linked-buffer-blk-comment-buffer (conf begin end buffer)
   "Given CONF, a `linked-buffer-configuration' object, add
-start of line comment-characters in appropriate blocks between
-BEGIN and END in BUFFER."
+start of line comment-characters. Changes should only have occurred
+between BEGIN and END in BUFFER."
   (-map
    ;; comment each of these regions
    (lambda (pairs)
-     (prog1
-         (linked-buffer-blk-comment-region
-          conf (car pairs) (cdr pairs) buffer)
+     (let* ((block-begin (car pairs))
+            (block-end (cdr pairs))
+            (rtn
+             (when
+                 (and (>= end block-begin)
+                      (>= block-end begin))
+               (linked-buffer-blk-comment-region
+                conf (car pairs) (cdr pairs) buffer))))
        (set-marker (car pairs) nil)
-       (set-marker (cdr pairs) nil)))
-   (linked-buffer-blk-marker-boundaries conf begin end buffer)))
+       (set-marker (cdr pairs) nil)
+       rtn))
+   (linked-buffer-blk-marker-boundaries conf buffer)))
 
 (put 'unmatched-delimiter-error
      'error-conditions
@@ -145,11 +160,11 @@ BEGIN and END in BUFFER."
 (put 'unmatched-delimiter-error
      'error-message "Unmatched Delimiter in Buffer")
 
-(defun linked-buffer-blk-marker-boundaries (conf begin end buffer)
+(defun linked-buffer-blk-marker-boundaries (conf buffer)
   "Given CONF, a `linked-buffer-configuration' object, find
-demarcation markers between BEGIN and END in BUFFER. Returns a
-list of start end cons pairs. BEGIN is considered to be an
-implicit start and END an implicit stop."
+demarcation markers. Returns a list of start end cons pairs.
+`point-min' is considered to be an implicit start and `point-max'
+an implicit stop."
   (let* ((match-block
           (linked-buffer-block-match
            conf buffer))
@@ -162,18 +177,19 @@ implicit start and END an implicit stop."
            (length match-end))
       (linked-buffer-log "delimiters do not match")
       (signal 'unmatched-delimiter-error
-              (list begin end buffer)))
-    (-zip
-     ;; start comment markers
-     ;; plus the start of the region
-     (cons
-      (set-marker (make-marker) begin buffer)
-      match-start)
-     ;; end comment markers
-     ;; plus the end of the buffer
-     (append
-      match-end
-      (list (set-marker (make-marker) end buffer))))))
+              (list buffer)))
+    (with-current-buffer buffer
+      (-zip
+       ;; start comment markers
+       ;; plus the start of the region
+       (cons
+        (set-marker (make-marker) (point-min) buffer)
+        match-start)
+       ;; end comment markers
+       ;; plus the end of the buffer
+       (append
+        match-end
+        (list (set-marker (make-marker) (point-max) buffer)))))))
 
 (defmethod linked-buffer-block-match ((conf linked-buffer-block-configuration)
                                       buffer)
@@ -277,13 +293,15 @@ between the two buffers; we don't care which one has 
comments."
 
 (defmethod linked-buffer-block-comment-start-regexp
   ((conf linked-buffer-commented-block-configuration))
-  (concat (regexp-quote (oref conf :comment))
-          (oref conf :comment-start)))
+  (concat
+   "\\(" (regexp-quote (oref conf :comment)) "\\)?"
+   (oref conf :comment-start)))
 
 (defmethod linked-buffer-block-comment-stop-regexp
   ((conf linked-buffer-commented-block-configuration))
-  (concat (regexp-quote (oref conf :comment))
-          (oref conf :comment-stop)))
+  (concat
+   "\\(" (regexp-quote (oref conf :comment)) "\\)?"
+   (oref conf :comment-stop)))
 
 (defmethod linked-buffer-clone
   ((conf linked-buffer-uncommented-block-configuration)
diff --git a/test/linked-buffer-test.el b/test/linked-buffer-test.el
index 3f97bb9bda..bd50e9e11d 100644
--- a/test/linked-buffer-test.el
+++ b/test/linked-buffer-test.el
@@ -51,7 +51,8 @@
                   "-c"
                   a-file
                   b-file)
-                 (buffer-string))))))
+                 (buffer-string))))
+    nil))
 
 (defun linked-buffer-test-clone-equal (init file cloned-file)
   (let ((cloned-file
@@ -259,7 +260,7 @@ This mostly checks my test machinary."
 
 (ert-deftest clojure-latex-first-line ()
   "Tests for a bug after introduction of incremental blocks."
-  :expected-result :fail
+  :expected-result :failed
   (should
    (linked-buffer-test-clone-and-change-equal
     'linked-buffer-clojure-latex-init



reply via email to

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