Hi Uwe,
I don't think these fill-paragraph patches made it into master. Attached are
the patches that work for me. Are there any reasons to not apply them?
Thanks,
John
________________________________
From: Uwe Brauer <[email protected]>
Sent: Monday, July 31, 2023 11:57 AM
To: Eric Ludlam <[email protected]>
Cc: Matlab-emacs-discuss <[email protected]>
Subject: Re: [Matlab-emacs-discuss] the filling patch and its problems
>>> "EL" == Eric Ludlam <[email protected]> writes:
> Is anyone out there interested in the "code fill" feature?
You mean besides me 😇 I do hope so!
> It was a hairy thing to implement back in the day, and most of the
> feedback I got was "how do I turn this off?" It is likely easier to
> drop the feature than figure out how to fix it for all cases.
I cannot judge this and I don't want to cause you headaches.
However I can tell you that code that is written with the native matlab
editor (say by my students) tend to have these enormous comment lines as
in the files
fill_prob2.m
fill_prob.m
So filling these lines would help me quite a bit and I thought emacs
users sharing code with those using the native editor might face similar
problems.
The thing that puzzles me:
in commit 0f305501f26d633048c83a89b6652db169394a3f
that line filling problems seemed to be solved
But in the last two commits it throws an error.
So what changed and can't we just go back?
> Basically, it isn't hard to create a line of code it can't fill, in
> which case it throws this error. Maybe a warning is better?
Yes I think so.
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 NATO membership of the Ukraine.
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>
diff --git a/matlab-syntax.el b/matlab-syntax.el
index 18203a5..6c92adc 100644
--- a/matlab-syntax.el
+++ b/matlab-syntax.el
@@ -451,7 +451,10 @@ Returns non-nil if the cursor is in a comment."
(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.
diff --git a/matlab.el b/matlab.el
index 8ca0ee2..a0f3164 100644
--- a/matlab.el
+++ b/matlab.el
@@ -1708,7 +1708,7 @@ The name is any text after the %% and any whitespace."
(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 @@ Argument BEG and END indicate the region to uncomment."
(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 @@ filling which will automatically insert `...' and the end of a line."
((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 @@ Non-nil JUSTIFY-FLAG means justify comment lines as well."
"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 @@ ARG is passed to `fill-paragraph' and will justify the text."
(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-emacs-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matlab-emacs-discuss