Skip to content

Commit

Permalink
fix positioning
Browse files Browse the repository at this point in the history
The insertion functions are responsible for positioning the point at the
beginning of the function by calling js-doc--beginning-of-defun, which
is necessary for js-doc--function-doc-metadata to work.

The position-compensation after the point moved around for parsing the
data that was performed with the previous implementation is no longer
necessary because the metadata parsing is done in a separate excursion
via save-excursion.
  • Loading branch information
blaenk committed Jul 13, 2016
1 parent 4309df5 commit db96b0c
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions js-doc.el
Expand Up @@ -301,7 +301,9 @@ js-doc regards current state as in JsDoc style comment"
(split-string (buffer-substring-no-properties from to) ",")))

(defun js-doc--function-doc-metadata ()
"Parse the function's metadata for use with JsDoc."
"Parse the function's metadata for use with JsDoc.
The point should be at the beginning of the function,
which is accomplished with js-doc--beginning-of-defun."
(interactive)
;; Parse function info
(let ((metadata '())
Expand All @@ -311,8 +313,6 @@ js-doc regards current state as in JsDoc style comment"
begin
end)
(save-excursion
(js-doc--beginning-of-defun)

(setq from (search-forward "(" nil t)
to (1- (search-forward ")" nil t)))

Expand Down Expand Up @@ -364,8 +364,6 @@ The comment style can be custimized via `customize-group js-doc'"
(add-to-list 'document-list
(js-doc-format-string js-doc-bottom-line) t)
;; Insert the document
(search-backward "(" nil t)
(beginning-of-line)
(setq from (point)) ; for indentation

;; put document string into document-list
Expand All @@ -389,12 +387,10 @@ The comment style can be custimized via `customize-group js-doc'"
(interactive)

(with-eval-after-load 'yasnippet
(js-doc--beginning-of-defun)

(let ((metadata (js-doc--function-doc-metadata))
(field-count 1))
(js-doc--beginning-of-defun)
(search-backward "(" nil t)
(beginning-of-line)

(yas-expand-snippet
(concat
js-doc-top-line
Expand Down

0 comments on commit db96b0c

Please sign in to comment.