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

Make it easier to create snippets #105

Closed
zefhemel opened this Issue Mar 5, 2014 · 14 comments

Comments

Projects
None yet
5 participants
@zefhemel
Copy link
Member

zefhemel commented Mar 5, 2014

This is apparently something that people want to do and the current way to do so is non-trivial (https://groups.google.com/forum/#!topic/zed-user/2stQdP9i0uM). Any suggestions on how to make this easier are welcome.

@zefhemel zefhemel added the enhancement label Mar 5, 2014

@ghost

This comment has been minimized.

Copy link

ghost commented Mar 5, 2014

Frankly I don't see how it can be any easier. I think it just needs some better documentation. For example, I just tried to make some snippets for Python (a language that doesn't come with any). When my first attempts failed, I tried copying the exact javascript snippets into my /user.json, and then just changed javascript to python. No luck, wasn't working. Took me a few minutes of banging my head on the wall before I realized I was missing the snippet handler. Once I added that it was great.

@zefhemel

This comment has been minimized.

Copy link
Member Author

zefhemel commented Mar 6, 2014

If you know how to do it, it's not that hard. However, what I could imagine is a Snippet:Add command that pops up a window asking for a snippet name and editor for snippet code, which automatically updates user.json for you (for the current language mode).

@Wanchai

This comment has been minimized.

Copy link

Wanchai commented Mar 6, 2014

Hi guys,
I'm trying to use a snippet without success ...
I guess I didn't use the handler correctly. Where should I put it ?

{
    "imports": [
        "/default.json"
    ],
    "modes": {        
        "php": {
            "name": "PHP",
            "highlighter": "ace/mode/php",
            "extensions": ["php", "php4", "ctp"],
            "commands": {
                "Tools:Complete:Snippet": {
                    "mynewsnippet": "this ${1:is} a ${2:snippet}"
                }
            },
            "handlers": {
                "complete": ["Tools:Complete:Builtin","Tools:Complete:Snippet"]
            }
        }
    },
    "keys": {
        "Edit:Toggle Comment": {
            "win": "Ctrl-Q",
            "mac": "Command-/"
        }
    },
    "commands": {},
    "handlers": {},
    "themes": {}
}
@zefhemel

This comment has been minimized.

Copy link
Member Author

zefhemel commented Mar 6, 2014

@Wanchai if you replace the "Tools:Complete:Snippet": { ... } part with this it should work:

                "Tools:Complete:Snippet": {
                    "scriptUrl": "/default/command/snippet_completer.js",
                    "snippets": {
                        "mynewsnippet": "this ${1:is} a ${2:snippet}"
                    }
                }
@Wanchai

This comment has been minimized.

Copy link

Wanchai commented Mar 6, 2014

Works like a charm. Thanks a lot.

An other thing, as I'm working with PHP, the $ mess with the all thing. So I used a place holder as a workaround :

"snippets": {
    "viewVars": "${1:$}this->viewVars['${2:authUser}']"
}

Is there a better way to do this?

Also, I agree with robru that a documentation about it would be great. Because the setup is the hardess part. Adding new ones is easy.

@ghost

This comment has been minimized.

Copy link

ghost commented Mar 6, 2014

@zefhemel oh I see what you mean about having some UI for it. That would be ok, as long as it was smart enough to add the complete handler and the scriptUrl for languages that don't come with snippets enabled. Or maybe you should just add those things to all languages, regardless of if they actually have any snippets or not... ;-)

@zefhemel

This comment has been minimized.

Copy link
Member Author

zefhemel commented Mar 7, 2014

Yep. Auto adding is probably nicest. — Zef

Sent from my iPhone

On Thu, Mar 6, 2014 at 7:58 PM, Robert Bruce Park
notifications@github.com wrote:

@zefhemel oh I see what you mean about having some UI for it. That would be ok, as long as it was smart enough to add the complete handler and the scriptUrl for languages that don't come with snippets enabled. Or maybe you should just add those things to all languages, regardless of if they actually have any snippets or not... ;-)

Reply to this email directly or view it on GitHub:
#105 (comment)

@gwitasod

This comment has been minimized.

Copy link

gwitasod commented Mar 22, 2014

this might sound silly but how do I get the snippet on the page? i tried the code above in the user.json I entered it correctly. on my .js page when i type mynewsnippet what do I do next? I tried all shorts of combinations with the keyboard but nothing happens.

I expected I type the shortcut of the snippet "mynewsnippet", I click tab and it opens a menu and I select "mynewsnippet" (just like when I do for the function "fn" shortcut).

I cannot figure it out. when i type "mynewsnippet" and I click on the tab key, nothing happens. (when i type "fn", the shortcut for the function snippet, everything works as expected.

how do I get the snippet on the page. is there a different key combination?

@ghost

This comment has been minimized.

Copy link

ghost commented Mar 22, 2014

Yep, you should type the snippet name (or even just the first part of it),
hit tab, and then enter to choose it from the list, then it's just like
fn. If it's not working, your config is probably wrong. Can you paste the
whole config here please?

@gwitasod

This comment has been minimized.

Copy link

gwitasod commented Mar 22, 2014

I had a typo. it works like a charm

@gregorydillon

This comment has been minimized.

Copy link

gregorydillon commented Apr 28, 2014

Yes, I'm wishing this was easier, with an easy way to share snippets.

@ghost

This comment has been minimized.

Copy link

ghost commented Apr 28, 2014

@gregorydillon If you have good snippets worth sharing, why not submit pull requests here? Then all Zed users benefit.

@ijaaz

This comment has been minimized.

Copy link

ijaaz commented May 5, 2014

That does make sense

On Mon, Apr 28, 2014 at 12:34 AM, Robert Bruce Park <
notifications@github.com> wrote:

@gregorydillon https://github.com/gregorydillon If you have good
snippets worth sharing, why not submit pull requests here? Then all Zed
users benefit.


Reply to this email directly or view it on GitHubhttps://github.com//issues/105#issuecomment-41522320
.

@zefhemel

This comment has been minimized.

Copy link
Member Author

zefhemel commented Jul 11, 2014

Alright, I just created a package that implements a snippet manager in user land. I added it as a git submodule (so be sure to git submodule update). It has two commands: Snippets:List and Snippets:Add both operate on the the mode of the currently open file.

@zefhemel zefhemel closed this Jul 11, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment