From: Van Z. J. <jr...@mi...> - 2015-05-11 19:37:15
|
I have noticed a small problem in the recognition of comments. I can use M-; to insert a comment on the current line. I should be able to use the same command to move point to an existing comment on the current line, with the side effect of moving that comment to the preferred start column. Actually that does work if the comment starts with "% ", but fails if the percent is followed by something other than a space. Suppose I am editing this file with point anywhere on the third line: function foo a = 3; b = 4; %first comment c = 5; d = 6; e = 7; % second comment f = 8; If I press M-; I get: function foo a = 3; b = 4; %first comment c = 5; d = 6; e = 7; % second comment f = 8; With point on any other line, I get the expected result. I expect this could be fixed by adjusting a regular expression, but I could not follow the logic well enough to find it. - Jim Van Zandt |
From: Eric L. <Eri...@ma...> - 2015-06-07 20:05:19
|
Hi Jim, Here is a tweaked version of the Matlab-comment function that should fix the problem you found. If it works for you let me know and I can update it. Enjoy Eric (defun matlab-comment () "Add a comment to the current line." (interactive) (cond ((matlab-ltype-empty) ; empty line (matlab-comm-from-prev) (if (matlab-lattr-comm) (skip-chars-forward " \t%") (insert matlab-comment-line-s) (matlab-indent-line))) ((matlab-ltype-comm) ; comment line (matlab-comm-from-prev) (skip-chars-forward " \t%")) ((matlab-lattr-comm) ; code line w/ comment (beginning-of-line) (re-search-forward "[^%]%") (forward-char -1) (if (> (current-column) comment-column) (delete-horizontal-space)) (if (< (current-column) comment-column) (indent-to comment-column)) (skip-chars-forward "% \t")) (t ; code line w/o comment (end-of-line) (re-search-backward "[^ \t\n^]" 0 t) (forward-char) (delete-horizontal-space) (if (< (current-column) comment-column) (indent-to comment-column) (insert " ")) (insert matlab-comment-on-line-s)))) From: Van Zandt, Jim [mailto:jr...@mi...] Sent: Monday, May 11, 2015 3:37 PM To: mat...@li... Subject: [Matlab-emacs-discuss] recognizing comments I have noticed a small problem in the recognition of comments. I can use M-; to insert a comment on the current line. I should be able to use the same command to move point to an existing comment on the current line, with the side effect of moving that comment to the preferred start column. Actually that does work if the comment starts with "% ", but fails if the percent is followed by something other than a space. Suppose I am editing this file with point anywhere on the third line: function foo a = 3; b = 4; %first comment c = 5; d = 6; e = 7; % second comment f = 8; If I press M-; I get: function foo a = 3; b = 4; %first comment c = 5; d = 6; e = 7; % second comment f = 8; With point on any other line, I get the expected result. I expect this could be fixed by adjusting a regular expression, but I could not follow the logic well enough to find it. - Jim Van Zandt |
From: Van Z. J. <jr...@mi...> - 2015-06-08 12:17:00
|
Works great, thanks! I suggest one additional change. If point is anywhere on a code line with a comment, then matlab-comment moves point to the beginning of the comment. If it's on a comment line, then point gets moved to the beginning of the comment only if it starts after that point. Otherwise it's left unchanged. I suggest an additional "beginning-of-line" for this case. I don't think this interferes with matlab-comm-from-prev. - Jim Van Zandt (defun matlab-comment () "Add a comment to the current line." (interactive) (cond ((matlab-ltype-empty) ; empty line (matlab-comm-from-prev) (if (matlab-lattr-comm) (skip-chars-forward " \t%") (insert matlab-comment-line-s) (matlab-indent-line))) ((matlab-ltype-comm) ; comment line (matlab-comm-from-prev) (beginning-of-line) (skip-chars-forward " \t%")) ((matlab-lattr-comm) ; code line w/ comment (beginning-of-line) (re-search-forward "[^%]%") (forward-char -1) (if (> (current-column) comment-column) (delete-horizontal-space)) (if (< (current-column) comment-column) (indent-to comment-column)) (skip-chars-forward "% \t")) (t ; code line w/o comment (end-of-line) (re-search-backward "[^ \t\n^]" 0 t) (forward-char) (delete-horizontal-space) (if (< (current-column) comment-column) (indent-to comment-column) (insert " ")) (insert matlab-comment-on-line-s)))) From: Eric Ludlam <Eri...@ma...<mailto:Eri...@ma...>> Date: Sunday, June 7, 2015 at 3:47 PM To: Jim Van Zandt <jr...@mi...<mailto:jr...@mi...>>, "mat...@li...<mailto:mat...@li...>" <mat...@li...<mailto:mat...@li...>> Subject: RE: recognizing comments (defun matlab-comment () "Add a comment to the current line." (interactive) (cond ((matlab-ltype-empty) ; empty line (matlab-comm-from-prev) (if (matlab-lattr-comm) (skip-chars-forward " \t%") (insert matlab-comment-line-s) (matlab-indent-line))) ((matlab-ltype-comm) ; comment line (matlab-comm-from-prev) (skip-chars-forward " \t%")) ((matlab-lattr-comm) ; code line w/ comment (beginning-of-line) (re-search-forward "[^%]%") (forward-char -1) (if (> (current-column) comment-column) (delete-horizontal-space)) (if (< (current-column) comment-column) (indent-to comment-column)) (skip-chars-forward "% \t")) (t ; code line w/o comment (end-of-line) (re-search-backward "[^ \t\n^]" 0 t) (forward-char) (delete-horizontal-space) (if (< (current-column) comment-column) (indent-to comment-column) (insert " ")) (insert matlab-comment-on-line-s)))) |