Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement js-doc-insert-function-doc-snippet #16

Merged
merged 2 commits into from
Jul 15, 2016

Conversation

blaenk
Copy link
Contributor

@blaenk blaenk commented Jul 13, 2016

This introduces js-doc-insert-function-doc-snippet.

This uses yasnippet (if it's available) to insert the jsdoc comment which enables the use of placeholder values and cycling through the various fields.

To enable this, common functionality has been factored out to separate functions, most notably js-doc--function-doc-metadata which parses the function metadata into an alist which is then used by the jsdoc insertion functions.

You can see the advantages of the new M-x js-doc-insert-function-doc-snippet with this recording:

recording

While I was at it I changed the regular js-doc-insert-function-doc to save the position of the jsdoc description line so that the point/cursor is moved to it after the jsdoc is inserted (see #13).

This supersedes #14.

This uses yasnippet to insert the jsdoc comment which enables the use of
placeholder values and cycling through the various fields.

To enable this, common functionality has been factored out to separate
functions, most notably js-doc--function-doc-metadata which parses the
function metadata into an alist which is then used by the jsdoc
insertion functions.
@futurist
Copy link

Using Mac10.9 + Emacs 25.0.95, with js2-mode enabled, the point is inside random function, the result is below:

2016-07-13 22 27 44

The tested code snippet as below:

  var reAtRule = /^\s*@/
  var reClass = /:global\s*\(\s*((?:\.[A-Za-z0-9_-]+\s*)+)\s*\)|(\.)([!A-Za-z0-9_-]+)/g

// default local prefix implement
var random = (function () {
  var count = 0
  return function () {
    count++
    return '_' + Math.floor(Math.random() * Math.pow(2, 32)).toString(36) + count + '_'
  }
})()

The Emacs 25 have many weird behavior under Mac, tomorrow I'll test in windows, maybe it's more accurate.

@blaenk
Copy link
Contributor Author

blaenk commented Jul 13, 2016

Actually I think it's a simple bug. I'll take a look at it, thanks for trying it and reporting this.

@blaenk
Copy link
Contributor Author

blaenk commented Jul 13, 2016

Did jsdoc previously work with that Immediately Invoked Function Expression (IIFE)? Just to be sure.

@blaenk blaenk force-pushed the yasnippet-integration branch from 5bafd49 to f97d9f8 Compare July 13, 2016 20:34
@blaenk
Copy link
Contributor Author

blaenk commented Jul 13, 2016

@futurist Please try the latest commit. It now works with the two functions in your sample code. If you find any other problems please let me know.

recording

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.
@blaenk blaenk force-pushed the yasnippet-integration branch from f97d9f8 to db96b0c Compare July 13, 2016 20:40
blaenk added a commit to blaenk/dots that referenced this pull request Jul 13, 2016
I avoided it at first but it seems like a very useful thing such as for
jsdoc insertion [0].

[0]: mooz/js-doc#16

I don't want it to hijack my TAB key so I unbind that and bind yasnippet
expansion to M-n, and M-N triggers company-yasnippet.

I make sure that evil-insert state is set before expanding a snippet.
@mooz mooz merged commit f0606e8 into mooz:master Jul 15, 2016
@mooz
Copy link
Owner

mooz commented Jul 15, 2016

Great! Thx for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants