Closed sid-kurias closed 7 years ago
Hi! Good idea about using company, thanks for sharing! It seems like it completes the snippet names though, and not the keywords?
Perhaps something like this would work better? Now you do not get the full snippet name as completion candidates though.
(defun company-yankpad (command &optional arg &rest ignored)
(interactive (list 'interactive))
(case command
(interactive (company-begin-backend 'company-yankpad))
(prefix (company-grab-symbol))
(candidates (delq nil (mapcar
(lambda (c)
(string-match (concat "^\\([[:word:]]+\\)"
yankpad-expand-separator)
(car c))
(let ((snippet (match-string 1 (car c))))
(when snippet
(if (string-prefix-p arg snippet t) snippet ))))
(yankpad-active-snippets))))
(post-completion (yankpad-expand))
(duplicates t)))
I see what you mean. I now show the snippet name alongside the keyword in the company drop down. Please let me know if that is what you were referring to.
Sorry did not mean to close it. Must have hit the wrong button.
Nice work! I'm not quite sure if you want to complete candidates that doesn't have a keyword though? Lets say my yankpad look like this:
* My category
** snippet1
Insert some text (no keyword)
** snippet2: Another snippet, with a keyword!
A different snippet.
Now if I'm in the My category
category, and use company-yankpad
it will complete both snippet1
and snippet2: Another snippet, with a keyword!
. When completing snippet1
, however, it will only insert the snippet name, not the content of the snippet.
Perhaps something could be done by using yankpad-insert-snippet-name
instead of yankpad-expand
, upon post completion?
yankpad-insert-snippet-name? I did not find that anywhere.
I think both names and keywords complete now. I am using yankpad-expand for keywords and yankpad-insert-from-current-category for names. If that is not optimal do let me know.
Yes, I got the name wrong :) yankpad-insert-from-current-category
is what I meant :) It seems to work great now! Would it be okay if I added it to yankpad.el
? Ofcourse I'll give you credit in the code and on the README page.
oh yes, please go ahead and use it as you please. Don't worry about credits. I really like yankpad and orgmode and emacs :-)
Your code has now been added, thanks again!
I have written a company-mode backend for yankpad. This will show yankpad snippets that use key expansion in the drop down. When a candidate is selected it will autocomplete. The repository is here https://github.com/sid-kurias/company-yankpad . You can use it as you see best