9393(defun vs-comment-return--goto-start-comment ()
9494 " Go to the start of the comment."
9595 (while (and (vs-comment-return--comment-p)
96- comment-start-skip)
97- (re-search-backward comment-start-skip nil t )))
96+ (not (bobp )))
97+ (ignore-errors (forward-char -1 )))
98+ ; ; Ensure the beginning of the syntax.
99+ (when (re-search-backward " [[:space:]]" (line-beginning-position ) t )
100+ (forward-char 1 )))
98101
99102(defun vs-comment-return--goto-end-comment ()
100103 " Go to the end of the comment."
101- (when (and (vs-comment-return--comment-p)
102- (not (eobp )))
103- (ignore-errors (forward-char 1 ))
104- (vs-comment-return--goto-end-comment)))
104+ (while (and (vs-comment-return--comment-p)
105+ (not (eobp )))
106+ (ignore-errors (forward-char 1 )))
107+ ; ; Ensure the end of the syntax.
108+ (when (re-search-forward " [[:space:]]" (line-end-position ) t )
109+ (forward-char -1 )))
105110
106111(defun vs-comment-return--comment-start-point ()
107112 " Return comment start point."
114119(defun vs-comment-return--multiline-comment-p ()
115120 " Return non-nil, if current point inside multi-line comment block."
116121 (let* ((start (vs-comment-return--comment-start-point))
117- (end (vs-comment-return--comment-end-point))
122+ (end (vs-comment-return--comment-end-point))
118123 (old-major-mode major-mode)
119124 (start-point (1+ (- (point ) start)))
120125 (content (buffer-substring start end)))
126131 (ignore-errors (font-lock-ensure ))
127132 (vs-comment-return--comment-p))))
128133
134+ (defun vs-comment-return--indent ()
135+ " Indent entire comment region."
136+ (indent-region (vs-comment-return--comment-start-point)
137+ (vs-comment-return--comment-end-point)))
138+
129139(defun vs-comment-return--re-search-forward-end (regexp &optional bound )
130140 " Repeatedly search REGEXP to BOUND."
131141 (let ((repeat (1- (length regexp))))
@@ -248,7 +258,7 @@ We use PREFIX for navigation; we search it, then check what is infront."
248258 (string-empty-p (string-trim content)))))
249259
250260(defun vs-comment-return--advice-around (func &rest args )
251- " Advice bind around return."
261+ " Advice bind around return (FUNC and ARGS) ."
252262 (if (not vs-comment-return-mode)
253263 (apply func args)
254264 (vs-comment-return--do-return func args)))
@@ -271,7 +281,7 @@ We use PREFIX for navigation; we search it, then check what is infront."
271281 (t prefix2)))
272282
273283(defun vs-comment-return--do-return (func args )
274- " Do VS like comment return."
284+ " Do VS like comment return (FUNC and ARGS) ."
275285 (cond
276286 ((not (vs-comment-return--comment-p))
277287 (apply func args))
@@ -343,7 +353,7 @@ We use PREFIX for navigation; we search it, then check what is infront."
343353 (when (vs-comment-return--c-like-multiline-comment-p)
344354 (delete-region (line-beginning-position ) (point ))
345355 (vs-comment-return--comment-line " * " )
346- (indent-for-tab-command )
356+ (vs-comment-return--indent )
347357 (when (and (not vs-comment-return-keep-suffix)
348358 (save-excursion (search-forward " */" (line-end-position ) t )))
349359 (save-excursion
0 commit comments