-
Notifications
You must be signed in to change notification settings - Fork 19
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
Conversation
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.
Using Mac10.9 + Emacs 25.0.95, with js2-mode enabled, the point is inside 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. |
Actually I think it's a simple bug. I'll take a look at it, thanks for trying it and reporting this. |
Did jsdoc previously work with that Immediately Invoked Function Expression (IIFE)? Just to be sure. |
5bafd49
to
f97d9f8
Compare
@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. |
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.
f97d9f8
to
db96b0c
Compare
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.
Great! Thx for the contribution. |
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: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.