Hi

Just to resume the discussion. I insert below the emails discussing the
two problems I found 

I applied the two patches, I attach below and then I run into a problem:

* First problem
Take one of these awful long comment line

    ev = 0;                                                       % el número 
de evaluaciones al inicio es cero, pues no ha habido ninguna iteración

this after running matlab-fill-comment-line to

    ev = 0; % el número de evaluaciones al inicio es cero, pues no ha
                                                                  % habido
                                                                  % ninguna
                                                                  % iteración

Which does not look correct to me, shouldn't it be

    ev = 0; % el número de evaluaciones al inicio es cero, pues no ha
            % habido ninguna iteración
Or do I miss here something


* Second problem.
I tried just to run
matlab-indent-region
on
#+begin_src
    ev = 0; % el número de evaluaciones al inicio es cero, pues no ha
                                                                  % habido
                                                                  % ninguna
                                                                  % iteración
#+end_src

and I obtained an error I attach, something is not right here




--- 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.
--- /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)))
Debugger entered--Lisp error: (wrong-number-of-arguments #f(compiled-function 
(start end &optional column noprogress) (interactive nil) #<bytecode 
0xbf403742a90dff7>) 0)
  matlab-indent-region()
  funcall-interactively(matlab-indent-region)
  call-interactively(matlab-indent-region record nil)
  command-execute(matlab-indent-region record)
  execute-extended-command(nil "matlab-indent-region" "matlab-indent-re")
  funcall-interactively(execute-extended-command nil "matlab-indent-region" 
"matlab-indent-re")
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)
-- 
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 NATO membership of the Ukraine.
I support the EU membership of the Ukraine. 
https://addons.thunderbird.net/en-US/thunderbird/addon/gmail-conversation-view/



Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
Matlab-emacs-discuss mailing list
Matlab-emacs-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matlab-emacs-discuss

Reply via email to