Hi Uwe,

Eric fixed the issue, see attached patches which apply against the current 
source forge tip, 3048e9. I also tested it and have deployed it internally 
within MathWorks. Can you try the patches and if they are good, update source 
forge?

Thanks,
John
________________________________
From: Uwe Brauer <o...@mat.ucm.es>
Sent: Tuesday, April 25, 2023 5:53 AM
To: matlab-emacs-discuss@lists.sourceforge.net 
<matlab-emacs-discuss@lists.sourceforge.net>
Subject: [Matlab-emacs-discuss] another bug with the filling alorithm



Hi

Given the following example


while diff > TOL && k <= nmax % por una parte se condiciona al while con un 
valor de tolerancia para el error diff, error de una iteración de la iteración 
simple, y, por otra parte, se toma un numero máximo de iteraciones porque puede 
perfectamente el error de iteración no ser menor que la tolerancia, provocando 
un bucle infinito


matlab-fill-region returns the following errors

Who wrote this filling algorithm? According to git-hg blame, it was Eric
and the code is well quite old.

I have no idea how to debug this.

Any comments?

Regards

Uwe

--
Warning: Content may be disturbing to some audiences
I strongly condemn Putin's war of aggression against the Ukraine.
I support to deliver weapons to Ukraine's military.
I support the ban of Russia from SWIFT.
I support the EU membership of the Ukraine.
https://addons.thunderbird.net/en-US/thunderbird/addon/gmail-conversation-view/<https://addons.thunderbird.net/en-US/thunderbird/addon/gmail-conversation-view>
--- /mathworks/hub/share/sbtools/apps/emacs-add-ons/src/matlab-emacs/matlab-emacs/matlab.el	2023-04-25 14:30:34.743571388 -0400
+++ matlab.el	2023-05-08 08:56:32.582984029 -0400
@@ -1708,7 +1708,7 @@
 (defun matlab-beginning-of-command ()
   "Go to the beginning of an M command.
 Travels across continuations."
-  (interactive "P")
+  (interactive)
   (matlab-scan-beginning-of-command))
 
 (defun matlab-end-of-command ()
@@ -2400,19 +2400,28 @@
 (defun matlab-set-comm-fill-prefix ()
   "Set the `fill-prefix' for the current (comment) line."
   (interactive)
-  (if (matlab-line-comment-p (matlab-compute-line-context 1))
-      (setq fill-prefix
-            (save-excursion
-              (beginning-of-line)
-              (let ((e (matlab-point-at-eol))
-                    (pf nil))
-                (while (and (re-search-forward "%+[ \t]*\\($$$ \\|\\* \\)?" e t)
-                            (matlab-cursor-in-string)))
-                (setq pf (match-string 0))
-                (when (string-match "%\\s-*\\* " pf)
-                  (setq pf (concat "%" (make-string (1- (length pf)) ?  ))))
-                (concat (make-string (- (current-column) (length pf)) ? )
-                        pf))))))
+  (let ((ctxt (matlab-compute-line-context 1)))
+    (if (matlab-line-comment-p ctxt)
+        (setq fill-prefix
+              (save-excursion
+                (beginning-of-line)
+                (let ((e (matlab-point-at-eol))
+                      (pf nil))
+                  (while (and (re-search-forward "%+[ \t]*\\($$$ \\|\\* \\)?" e t)
+                              (matlab-cursor-in-string)))
+                  (setq pf (match-string 0))
+                  (when (string-match "%\\s-*\\* " pf)
+                    (setq pf (concat "%" (make-string (1- (length pf)) ?  ))))
+                  (concat (make-string (- (current-column) (length pf)) ? )
+                          pf))))
+      ;; Not a comment line, but maybe a comment at end of a line?  If
+      ;; so make next comment line up with the end of line comment
+      ;; column the way aoto fill does.
+      (let ((cstart (matlab-line-end-comment-column ctxt)))
+        (if cstart
+            (setq fill-prefix
+                  (concat (make-string cstart ? ) "% "))
+          )) )))
 
 (defun matlab-set-comm-fill-prefix-post-code ()
   "Set the `fill-prefix' for the current post-code comment line."
@@ -2564,7 +2573,7 @@
          ((or (matlab-line-comment-p lvl1)
               (and (save-excursion (move-to-column fill-column)
                                    (matlab-cursor-in-comment))
-                   (matlab-line-comment-p lvl1)))
+                   (matlab-line-end-comment-column lvl1)))
           ;; If the whole line is a comment, do this.
           (matlab-set-comm-fill-prefix) (do-auto-fill)
           (matlab-reset-fill-prefix))
@@ -2672,35 +2681,9 @@
   "Fill the current comment line.
 With optional argument, JUSTIFY the comment as well."
   (interactive)
-  (if (not (matlab-comment-on-line))
-      (error "No comment to fill"))
-  (beginning-of-line)
-  ;; First, find the beginning of this comment...
-  (while (and (looking-at matlab-cline-start-skip)
-              (not (bobp)))
-    (forward-line -1)
-    (beginning-of-line))
-  (if (not (looking-at matlab-cline-start-skip))
-      (forward-line 1))
-  ;; Now scan to the end of this comment so we have our outer bounds,
-  ;; and narrow to that region.
-  (save-restriction
-    (narrow-to-region (point)
-                      (save-excursion
-                        (while (and (looking-at matlab-cline-start-skip)
-                                    (not (save-excursion (end-of-line) (eobp))))
-                          (forward-line 1)
-                          (beginning-of-line))
-                        (if (not (looking-at matlab-cline-start-skip))
-                            (forward-line -1))
-                        (end-of-line)
-                        (point)))
-    ;; Find the fill prefix...
-    (matlab-comment-on-line)
-    (looking-at "%[ \t]*")
-    (let ((fill-prefix (concat (make-string (current-column) ? )
-                               (match-string 0))))
-      (fill-region (point-min) (point-max) justify))))
+  ;; Set the fill prefix
+  (matlab-set-comm-fill-prefix)
+  (fill-paragraph justify))
 
 (defun matlab-justify-line ()
   "Delete space on end of line and justify."
@@ -2724,7 +2707,7 @@
          (let ((paragraph-separate "%%\\|%[a-zA-Z]\\|%[ \t]*$\\|[ \t]*$")
                (paragraph-start "%[a-zA-Z]\\|%[ \t]*$\\|[ \t]*$\\|%\\s-*\\*")
                (paragraph-ignore-fill-prefix nil)
-               (start (save-excursion (matlab-scan-beginning-of-command)
+               (start (save-excursion (matlab-beginning-of-string-or-comment t)
                                       (if (looking-at "%%")
                                           (progn (end-of-line)
                                                  (forward-char 1)))
--- matlab-syntax.el_orig	2022-03-16 21:21:45.648400003 -0400
+++ matlab-syntax.el	2023-05-07 07:54:40.316705480 -0400
@@ -451,7 +451,10 @@
 	  (goto-char (nth 8 pps))
 	  
 	  t)
-      (when all-comments (forward-comment -100000)))))
+      (when all-comments
+	(prog1
+	    (forward-comment -100000)
+	  (skip-chars-forward " \t\n\r"))))))
 
 (defun matlab-end-of-string-or-comment (&optional all-comments)
   "If the cursor is in a string or comment, move to the end.
_______________________________________________
Matlab-emacs-discuss mailing list
Matlab-emacs-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matlab-emacs-discuss

Reply via email to