Skip to content

Commit 8497976

Browse files
committed
Support multiple return
1 parent aa2f2eb commit 8497976

File tree

2 files changed

+45
-19
lines changed

2 files changed

+45
-19
lines changed

docstr-key.el

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
;;; Code:
2929

3030
(require 'cl-lib)
31+
(require 's)
3132

3233
(defcustom docstr-key-support nil
3334
"If non-nil, use key support to fulfill document string triggerations' conditions."
@@ -55,6 +56,19 @@
5556
(insert (docstr-get-prefix))
5657
(indent-for-tab-command))
5758

59+
(defun docstr-key-single-line-prefix-insertion ()
60+
"Insertion for single line comment."
61+
(let* ((prev-line-text (save-excursion (forward-line -1) (thing-at-point 'line)))
62+
(prev-line-doc-symbol (docstr-util-comment-line-symbol -1))
63+
(current-line-doc-symbol (docstr-util-comment-line-symbol))
64+
(next-line-doc-symbol (docstr-util-comment-line-symbol 1))
65+
(prev-line-content (string-trim (s-replace prev-line-doc-symbol "" prev-line-text))))
66+
(when (or (string= prev-line-doc-symbol next-line-doc-symbol)
67+
(and (not (string-empty-p prev-line-content))
68+
(string= current-line-doc-symbol next-line-doc-symbol)))
69+
(insert (concat prev-line-doc-symbol " "))
70+
(indent-for-tab-command))))
71+
5872
(defun docstr-key-javadoc-asterik (fnc &rest args)
5973
"Asterik key for Javadoc like document string.
6074
@@ -75,8 +89,9 @@ document string."
7589
(if (not (docstr-util-comment-block-p)) (apply fnc args)
7690
(let ((new-doc-p (docstr-util-between-pair-p "/*" "*/")))
7791
(apply fnc args)
78-
(when (docstr-util-multiline-comment-p)
79-
(docstr-key-insert-prefix))
92+
(if (docstr-util-multiline-comment-p)
93+
(docstr-key-insert-prefix)
94+
(docstr-key-single-line-prefix-insertion))
8095
(when new-doc-p
8196
;; We can't use `newline-and-indent' here, or else the space will be gone.
8297
(progn (insert "\n") (indent-for-tab-command))

docstr-util.el

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -180,29 +180,40 @@ and GREEDY."
180180

181181
(defun docstr-util-start-comment-symbol (&optional pt)
182182
"Return the starting comment symbol form the given PT."
183-
(let (start-pt)
184-
(save-excursion
185-
(when pt (goto-char pt))
186-
(docstr-util--goto-start-comment)
187-
(setq start-pt (point))
188-
(re-search-forward "[ \t\r\n]" (1+ (line-end-position)) t)
189-
(if (= start-pt (point)) nil
190-
(string-trim (buffer-substring start-pt (point)))))))
183+
(when (docstr-util-comment-block-p)
184+
(let (start-pt)
185+
(save-excursion
186+
(when pt (goto-char pt))
187+
(docstr-util--goto-start-comment)
188+
(progn ; Make sure to go outside of symbol
189+
(re-search-backward "[ \t\r\n]" nil t)
190+
(forward-char 1))
191+
(setq start-pt (point))
192+
(re-search-forward "[ \t\r\n]" (1+ (line-end-position)) t)
193+
(if (= start-pt (point)) nil
194+
(string-trim (buffer-substring start-pt (point))))))))
191195

192196
(defun docstr-util-end-comment-symbol (&optional pt)
193197
"Return the ending comment symbol form the given PT."
194-
(let (end-pt)
195-
(save-excursion
196-
(when pt (goto-char pt))
197-
(docstr-util--goto-end-comment)
198-
(setq end-pt (point))
199-
(re-search-backward "[ \t\r\n]" (1- (line-beginning-position)) t)
200-
(if (= end-pt (point)) nil
201-
(string-trim (buffer-substring (point) end-pt))))))
198+
(when (docstr-util-comment-block-p)
199+
(let (end-pt)
200+
(save-excursion
201+
(when pt (goto-char pt))
202+
(docstr-util--goto-end-comment)
203+
(setq end-pt (point))
204+
(re-search-backward "[ \t\r\n]" (1- (line-beginning-position)) t)
205+
(if (= end-pt (point)) nil
206+
(string-trim (buffer-substring (point) end-pt)))))))
202207

203208
(defun docstr-util-multiline-comment-p ()
204209
"Return non-nil, if current point inside multi-line comment block."
205-
(string-match-p "/[*]" (docstr-util-start-comment-symbol)))
210+
(ignore-errors (string-match-p "/[*]" (docstr-util-start-comment-symbol))))
211+
212+
(defun docstr-util-comment-line-symbol (&optional n)
213+
"Forward N line and return starting comment symbol."
214+
(save-excursion
215+
(when n (forward-line n)) (end-of-line)
216+
(docstr-util-start-comment-symbol)))
206217

207218
;;
208219
;; (@* "Key" )

0 commit comments

Comments
 (0)