Skip to content

Commit

Permalink
Support multiple return
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Jan 28, 2021
1 parent aa2f2eb commit 8497976
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 19 deletions.
19 changes: 17 additions & 2 deletions docstr-key.el
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
;;; Code:

(require 'cl-lib)
(require 's)

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

(defun docstr-key-single-line-prefix-insertion ()
"Insertion for single line comment."
(let* ((prev-line-text (save-excursion (forward-line -1) (thing-at-point 'line)))
(prev-line-doc-symbol (docstr-util-comment-line-symbol -1))
(current-line-doc-symbol (docstr-util-comment-line-symbol))
(next-line-doc-symbol (docstr-util-comment-line-symbol 1))
(prev-line-content (string-trim (s-replace prev-line-doc-symbol "" prev-line-text))))
(when (or (string= prev-line-doc-symbol next-line-doc-symbol)
(and (not (string-empty-p prev-line-content))
(string= current-line-doc-symbol next-line-doc-symbol)))
(insert (concat prev-line-doc-symbol " "))
(indent-for-tab-command))))

(defun docstr-key-javadoc-asterik (fnc &rest args)
"Asterik key for Javadoc like document string.
Expand All @@ -75,8 +89,9 @@ document string."
(if (not (docstr-util-comment-block-p)) (apply fnc args)
(let ((new-doc-p (docstr-util-between-pair-p "/*" "*/")))
(apply fnc args)
(when (docstr-util-multiline-comment-p)
(docstr-key-insert-prefix))
(if (docstr-util-multiline-comment-p)
(docstr-key-insert-prefix)
(docstr-key-single-line-prefix-insertion))
(when new-doc-p
;; We can't use `newline-and-indent' here, or else the space will be gone.
(progn (insert "\n") (indent-for-tab-command))
Expand Down
45 changes: 28 additions & 17 deletions docstr-util.el
Original file line number Diff line number Diff line change
Expand Up @@ -180,29 +180,40 @@ and GREEDY."

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

(defun docstr-util-end-comment-symbol (&optional pt)
"Return the ending comment symbol form the given PT."
(let (end-pt)
(save-excursion
(when pt (goto-char pt))
(docstr-util--goto-end-comment)
(setq end-pt (point))
(re-search-backward "[ \t\r\n]" (1- (line-beginning-position)) t)
(if (= end-pt (point)) nil
(string-trim (buffer-substring (point) end-pt))))))
(when (docstr-util-comment-block-p)
(let (end-pt)
(save-excursion
(when pt (goto-char pt))
(docstr-util--goto-end-comment)
(setq end-pt (point))
(re-search-backward "[ \t\r\n]" (1- (line-beginning-position)) t)
(if (= end-pt (point)) nil
(string-trim (buffer-substring (point) end-pt)))))))

(defun docstr-util-multiline-comment-p ()
"Return non-nil, if current point inside multi-line comment block."
(string-match-p "/[*]" (docstr-util-start-comment-symbol)))
(ignore-errors (string-match-p "/[*]" (docstr-util-start-comment-symbol))))

(defun docstr-util-comment-line-symbol (&optional n)
"Forward N line and return starting comment symbol."
(save-excursion
(when n (forward-line n)) (end-of-line)
(docstr-util-start-comment-symbol)))

;;
;; (@* "Key" )
Expand Down

0 comments on commit 8497976

Please sign in to comment.