branch: externals/matlab-mode
commit 104a9d4e4a740ffcedb8100b7e4f16fa44f9a44d
Author: John Ciolfi <[email protected]>
Commit: John Ciolfi <[email protected]>

    t-utils.el: improve t-utils-xr debug handling and mark handling
---
 tests/t-utils.el                                   |  61 +++++++---
 .../comments_basic.m                               |   4 +-
 .../comments_basic_expected.org                    | 134 ++++++++++++---------
 3 files changed, 128 insertions(+), 71 deletions(-)

diff --git a/tests/t-utils.el b/tests/t-utils.el
index dc210fe888..fe26d378d5 100644
--- a/tests/t-utils.el
+++ b/tests/t-utils.el
@@ -202,16 +202,30 @@ You can run `t-utils--diff-check' to debug"))))
 
   (t-utils--diff-strings-impl start-contents end-contents))
 
+(defun t-utils--get-point-for-display (point)
+  "Return \"<point> L<num> C<num>\" for POINT."
+  (format "%d L%d C%d"
+          point
+          (line-number-at-pos point)
+          (save-excursion (goto-char point)
+                          (current-column))))
+
 (defvar t-utils--xr-impl-result-active)
 (defvar t-utils--xr-impl-result)
 
+(defun  t-utils--use-xr-impl-result ()
+  "Send result to `t-utils--xr-impl-result'?"
+  (and (boundp 't-utils--xr-impl-result-active)
+       t-utils--xr-impl-result-active))
+
 (defun t-utils--xr-impl (commands)
   "Implementation for `t-utils-xr' that processes COMMANDS."
   (when (or (= (point) 1)
             (not (save-excursion (goto-char (1- (point))) (looking-at ")"))))
     (error "Expected point to be after a closing parenthisis, \")\""))
 
-  (let* ((buf-file (t-utils--get-buf-file))
+  (let* ((line-move-visual nil) ;; C-n moves by true lines and not the width
+         (buf-file (t-utils--get-buf-file))
          (start-line (line-number-at-pos))
          (xr-end-point (point))
          (xr-start-point
@@ -226,9 +240,16 @@ You can run `t-utils--diff-check' to debug"))))
                          (line-number-at-pos xr-start-point)
                          (save-excursion (goto-char xr-start-point)
                                          (current-column))
-                         xr-cmd)))
+                         xr-cmd))
+         (cmd-num 0))
+
+    ;; Enable "C-SPC" in `t-utils-xr' commands.  Under regular running, we are 
being invoked from
+    ;; `t-utils-xr-test' and current buffer is a temporary buffer.  In batch 
mode,
+    ;; `transient-mark-mode' is not active, thus activate it.
+    (transient-mark-mode 1)
 
     (dolist (command commands)
+      (setq cmd-num (1+ cmd-num))
       (let ((start-point (point))
             (start-contents (buffer-substring-no-properties (point-min) 
(point-max)))
             (key-command (when (eq (type-of command) 'string)
@@ -253,28 +274,40 @@ You can run `t-utils--diff-check' to debug"))))
           (eval command))
 
         (let ((end-point (point))
-              (end-contents (buffer-substring-no-properties (point-min) 
(point-max))))
+              (end-contents (buffer-substring-no-properties (point-min) 
(point-max)))
+              (debug-msg (format "%d: %S, start point %s" cmd-num command
+                                 (t-utils--get-point-for-display 
start-point))))
 
           ;; Record point movement by adding what happened to result
           (if (equal start-point end-point)
-              (setq result (concat result "  No point movement\n"))
+              (setq result (concat result "  No point movement\n")
+                    debug-msg (concat debug-msg ", no point movement"))
             (let* ((current-line (buffer-substring-no-properties 
(line-beginning-position)
                                                                  
(line-end-position)))
                    (position (format "%d:%d: " (line-number-at-pos) 
(current-column)))
                    (carrot (concat (make-string (+ (length position) 
(current-column)) ?\s) "^")))
               (setq result (concat result (format "  Moved to point: %4d\n  : 
%s%s\n  : %s\n"
-                                                  end-point position 
current-line carrot)))))
+                                                  end-point position 
current-line carrot))
+                    debug-msg (concat debug-msg
+                                      (format ", moved point to %s"
+                                              (t-utils--get-point-for-display 
(point)))))))
 
           ;; Record buffer modifications by adding what happened to result
-          (setq result (concat result
-                               (if (equal start-contents end-contents)
-                                   "  No buffer modifications\n"
-                                 (concat "  Buffer modified:\n"
-                                         "  #+begin_src diff\n"
-                                         (t-utils-diff-strings start-contents 
end-contents)
-                                         "  #+end_src diff\n")))))))
-    (if (and (boundp 't-utils--xr-impl-result-active)
-             t-utils--xr-impl-result-active)
+          (if (equal start-contents end-contents)
+              (setq result (concat result "  No buffer modifications\n")
+                    debug-msg (concat debug-msg ", no buffer modifications"))
+            (setq result (concat result
+                                 "  Buffer modified:\n"
+                                 "  #+begin_src diff\n"
+                                 (t-utils-diff-strings start-contents 
end-contents)
+                                 "  #+end_src diff\n")
+                  debug-msg (concat debug-msg ", buffer modified")))
+
+          (when (not (t-utils--use-xr-impl-result))
+            ;; Display debugging info for interactive evaluation of 
(t-utils-xr COMMANDS)
+            (read-string (concat debug-msg "\n" "Enter to continue:"))))))
+
+    (if (t-utils--use-xr-impl-result)
         (progn
           (setq t-utils--xr-impl-result result)
           nil)
diff --git a/tests/test-matlab-ts-mode-comments-files/comments_basic.m 
b/tests/test-matlab-ts-mode-comments-files/comments_basic.m
index 29c12a7788..fd2a37fd53 100644
--- a/tests/test-matlab-ts-mode-comments-files/comments_basic.m
+++ b/tests/test-matlab-ts-mode-comments-files/comments_basic.m
@@ -2,11 +2,11 @@
 function b = comments_basic(a)
 
     % Test M-; to comment then uncomment following two statements.
-    % (t-utils-xr "C-n" "C-a" "C-SPC" "C-n" "C-n" "M-;" "M-;")
+    % (t-utils-xr "C-a" "C-n" "C-SPC" "C-n" "C-n" "M-;" "M-;" 
(deactivate-mark))
     b = a * 2;
     b = b * 3;
 
     % Test M-; to add comment to end of statement, then delete it.
-    % (t-utils-xr "C-n" "C-a" "M-;" (insert "foo") "C-a" "M-;" 
(re-search-backward ";") "C-f" "C-k")
+    % (t-utils-xr "C-a" "C-n" "M-;" (insert "foo") "C-a" "M-;" 
(re-search-backward ";") "C-f" "C-k")
     b = b * 4;
 end
diff --git 
a/tests/test-matlab-ts-mode-comments-files/comments_basic_expected.org 
b/tests/test-matlab-ts-mode-comments-files/comments_basic_expected.org
index a072104241..e1fc4c017c 100644
--- a/tests/test-matlab-ts-mode-comments-files/comments_basic_expected.org
+++ b/tests/test-matlab-ts-mode-comments-files/comments_basic_expected.org
@@ -2,87 +2,111 @@
 
 * Executing commands from comments_basic.m:5:6:
 
-  (t-utils-xr "C-n" "C-a" "C-SPC" "C-n" "C-n" "M-;" "M-;")
+  (t-utils-xr "C-a" "C-n" "C-SPC" "C-n" "C-n" "M-;" "M-;" (deactivate-mark))
 
-- Invoking      : "C-n" = next-line
-  Start point   :  182
-  Moved to point:  197
-  : 6:14:     b = a * 2;
-  :                     ^
+- Invoking      : "C-a" = move-beginning-of-line
+  Start point   :  200
+  Moved to point:  120
+  : 5:0:     % (t-utils-xr "C-a" "C-n" "C-SPC" "C-n" "C-n" "M-;" "M-;" 
(deactivate-mark))
+  :      ^
   No buffer modifications
 
-- Invoking      : "C-a" = move-beginning-of-line
-  Start point   :  197
-  Moved to point:  183
+- Invoking      : "C-n" = next-line
+  Start point   :  120
+  Moved to point:  201
   : 6:0:     b = a * 2;
   :      ^
   No buffer modifications
 
 - Invoking      : "C-SPC" = set-mark-command
-  Start point   :  183
+  Start point   :  201
   No point movement
   No buffer modifications
 
 - Invoking      : "C-n" = next-line
-  Start point   :  183
-  Moved to point:  198
+  Start point   :  201
+  Moved to point:  216
   : 7:0:     b = b * 3;
   :      ^
   No buffer modifications
 
 - Invoking      : "C-n" = next-line
-  Start point   :  198
-  Moved to point:  213
+  Start point   :  216
+  Moved to point:  231
   : 8:0: 
   :      ^
   No buffer modifications
 
 - Invoking      : "M-;" = comment-dwim
-  Start point   :  213
-  Moved to point:  219
-  : 8:6:     % 
-  :            ^
+  Start point   :  231
+  Moved to point:  235
+  : 8:0: 
+  :      ^
   Buffer modified:
   #+begin_src diff
 --- start_contents
 +++ end_contents
-@@ -5,7 +5,7 @@
-     % (t-utils-xr "C-n" "C-a" "C-SPC" "C-n" "C-n" "M-;" "M-;")
-     b = a * 2;
-     b = b * 3;
--
-+    % 
+@@ -3,8 +3,8 @@
+ 
+     % Test M-; to comment then uncomment following two statements.
+     % (t-utils-xr "C-a" "C-n" "C-SPC" "C-n" "C-n" "M-;" "M-;" 
(deactivate-mark))
+-    b = a * 2;
+-    b = b * 3;
++    % b = a * 2;
++    % b = b * 3;
+ 
      % Test M-; to add comment to end of statement, then delete it.
-     % (t-utils-xr "C-n" "C-a" "M-;" (insert "foo") "C-a" "M-;" 
(re-search-backward ";") "C-f" "C-k")
-     b = b * 4;
+     % (t-utils-xr "C-a" "C-n" "M-;" (insert "foo") "C-a" "M-;" 
(re-search-backward ";") "C-f" "C-k")
   #+end_src diff
 
 - Invoking      : "M-;" = comment-dwim
-  Start point   :  219
+  Start point   :  235
+  Moved to point:  231
+  : 8:0: 
+  :      ^
+  Buffer modified:
+  #+begin_src diff
+--- start_contents
++++ end_contents
+@@ -3,8 +3,8 @@
+ 
+     % Test M-; to comment then uncomment following two statements.
+     % (t-utils-xr "C-a" "C-n" "C-SPC" "C-n" "C-n" "M-;" "M-;" 
(deactivate-mark))
+-    % b = a * 2;
+-    % b = b * 3;
++    b = a * 2;
++    b = b * 3;
+ 
+     % Test M-; to add comment to end of statement, then delete it.
+     % (t-utils-xr "C-a" "C-n" "M-;" (insert "foo") "C-a" "M-;" 
(re-search-backward ";") "C-f" "C-k")
+  #+end_src diff
+
+- Invoking      : (deactivate-mark)
+  Start point   :  231
   No point movement
   No buffer modifications
 
 * Executing commands from comments_basic.m:10:6:
 
-  (t-utils-xr "C-n" "C-a" "M-;" (insert "foo") "C-a" "M-;" (re-search-backward 
";") "C-f" "C-k")
+  (t-utils-xr "C-a" "C-n" "M-;" (insert "foo") "C-a" "M-;" (re-search-backward 
";") "C-f" "C-k")
 
-- Invoking      : "C-n" = next-line
-  Start point   :  387
-  Moved to point:  402
-  : 11:14:     b = b * 4;
-  :                      ^
+- Invoking      : "C-a" = move-beginning-of-line
+  Start point   :  399
+  Moved to point:  299
+  : 10:0:     % (t-utils-xr "C-a" "C-n" "M-;" (insert "foo") "C-a" "M-;" 
(re-search-backward ";") "C-f" "C-k")
+  :       ^
   No buffer modifications
 
-- Invoking      : "C-a" = move-beginning-of-line
-  Start point   :  402
-  Moved to point:  388
+- Invoking      : "C-n" = next-line
+  Start point   :  299
+  Moved to point:  400
   : 11:0:     b = b * 4;
   :       ^
   No buffer modifications
 
 - Invoking      : "M-;" = comment-dwim
-  Start point   :  388
-  Moved to point:  422
+  Start point   :  400
+  Moved to point:  434
   : 11:34:     b = b * 4;                  % 
   :                                          ^
   Buffer modified:
@@ -90,17 +114,17 @@
 --- start_contents
 +++ end_contents
 @@ -8,5 +8,5 @@
-     % 
+ 
      % Test M-; to add comment to end of statement, then delete it.
-     % (t-utils-xr "C-n" "C-a" "M-;" (insert "foo") "C-a" "M-;" 
(re-search-backward ";") "C-f" "C-k")
+     % (t-utils-xr "C-a" "C-n" "M-;" (insert "foo") "C-a" "M-;" 
(re-search-backward ";") "C-f" "C-k")
 -    b = b * 4;
 +    b = b * 4;                  % 
  end
   #+end_src diff
 
 - Invoking      : (insert "foo")
-  Start point   :  422
-  Moved to point:  425
+  Start point   :  434
+  Moved to point:  437
   : 11:37:     b = b * 4;                  % foo
   :                                             ^
   Buffer modified:
@@ -108,53 +132,53 @@
 --- start_contents
 +++ end_contents
 @@ -8,5 +8,5 @@
-     % 
+ 
      % Test M-; to add comment to end of statement, then delete it.
-     % (t-utils-xr "C-n" "C-a" "M-;" (insert "foo") "C-a" "M-;" 
(re-search-backward ";") "C-f" "C-k")
+     % (t-utils-xr "C-a" "C-n" "M-;" (insert "foo") "C-a" "M-;" 
(re-search-backward ";") "C-f" "C-k")
 -    b = b * 4;                  % 
 +    b = b * 4;                  % foo
  end
   #+end_src diff
 
 - Invoking      : "C-a" = move-beginning-of-line
-  Start point   :  425
-  Moved to point:  388
+  Start point   :  437
+  Moved to point:  400
   : 11:0:     b = b * 4;                  % foo
   :       ^
   No buffer modifications
 
 - Invoking      : "M-;" = comment-dwim
-  Start point   :  388
-  Moved to point:  422
+  Start point   :  400
+  Moved to point:  434
   : 11:34:     b = b * 4;                  % foo
   :                                          ^
   No buffer modifications
 
 - Invoking      : (re-search-backward ";")
-  Start point   :  422
-  Moved to point:  401
+  Start point   :  434
+  Moved to point:  413
   : 11:13:     b = b * 4;                  % foo
   :                     ^
   No buffer modifications
 
 - Invoking      : "C-f" = forward-char
-  Start point   :  401
-  Moved to point:  402
+  Start point   :  413
+  Moved to point:  414
   : 11:14:     b = b * 4;                  % foo
   :                      ^
   No buffer modifications
 
 - Invoking      : "C-k" = kill-line
-  Start point   :  402
+  Start point   :  414
   No point movement
   Buffer modified:
   #+begin_src diff
 --- start_contents
 +++ end_contents
 @@ -8,5 +8,5 @@
-     % 
+ 
      % Test M-; to add comment to end of statement, then delete it.
-     % (t-utils-xr "C-n" "C-a" "M-;" (insert "foo") "C-a" "M-;" 
(re-search-backward ";") "C-f" "C-k")
+     % (t-utils-xr "C-a" "C-n" "M-;" (insert "foo") "C-a" "M-;" 
(re-search-backward ";") "C-f" "C-k")
 -    b = b * 4;                  % foo
 +    b = b * 4;
  end

Reply via email to