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 <[email protected]<mailto:[email protected]>>
Date: Sunday, June 7, 2015 at 3:47 PM
To: Jim Van Zandt <[email protected]<mailto:[email protected]>>,
"[email protected]<mailto:[email protected]>"
<[email protected]<mailto:[email protected]>>
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))))
------------------------------------------------------------------------------
_______________________________________________
Matlab-emacs-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matlab-emacs-discuss