Code snippets and auto indent

652 views
Skip to first unread message

kl...@artraktiv.com

unread,
Mar 5, 2014, 6:18:05 AM3/5/14
to zed-...@googlegroups.com
Hey there!


First of all: I really really like Zed so far. 

Two of the things I was wondering wether you could add an auto code indent feature and wether there is an easy way to add more code snippets?


Regards

Zef Hemel

unread,
Mar 5, 2014, 8:34:35 AM3/5/14
to kl...@artraktiv.com, zed-...@googlegroups.com
Hi,

First of all: thanks for using Zed.

Regarding auto indent: what do you mean exactly? For most languages, indentation should be automatic while writing code, e.g. in a C-like language, the editor indents after pressing Return after a {. If you're referring to code formatting/beautification (reformatting the entire file), that's currently only supported for HTML, XML, CSS, JSON and JavaScript and can be triggered using the Tools:Beautify command (Command-Shift-B on Mac, Ctrl-Shift-B on other OSes).

Regarding an easy way to add snippets: you can add snippets, but whether it's "easy" is subjective. It's not super easy, but here how you do it. Let's assume you want to add a snippet for JavaScript files.

Open the Configuration project and find the language mode .json file for your language (Javascript's located in /default/mode/javascript.json). There, under commands and "Tools:Complete:Snippets" you see default snippets listed. Now, javascript.json is a read-only file so you can't modify it. Instead what we'll do is mirror the structure of this file in our /user.json file and extend it that way from the outside. The nicest way to do this is to split the editor in two (Command-2/Ctrl-2) and open /user.json in the other screen. In this file, recreate the structure of the javascript file as follows and add a new snippet:

{
    "modes": {
        "javascript": {
            "commands": {
                "Tools:Complete:Snippet": {
                    "mynewsnippet": "this ${1:is} a ${2:snippet}"
                }
            }
        }
    }
}

This will create a snippet name "mynewsnippet" for just the JS mode, that expands to "this is a snippet" with two place holders.

I realize telling you this that this is not exactly "easy" so we can definitely look into ways to make this simpler, maybe there should be some dedicated UI to do this. Any suggestions are welcome.

-- Zef


--
You received this message because you are subscribed to the Google Groups "Zed user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zed-user+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Michael Klein

unread,
Mar 5, 2014, 9:04:22 AM3/5/14
to zed-...@googlegroups.com, kl...@artraktiv.com, z...@zef.me
Thanks a lot!
I realize I somehow got my terms mixed up. Found it now and it works like a charm!

I suppose a dedicated UI for snippets might be a good idea. I feel like you could do so much with that.

Regards

Zef Hemel

unread,
Mar 5, 2014, 9:06:10 AM3/5/14
to Michael Klein, zed-...@googlegroups.com
I just made an issue for it: https://github.com/zedapp/zed/issues/105

-- Zef
Reply all
Reply to author
Forward
0 new messages