Sublime Forum

Dev Build 2030

#25

PHP.sublime-completions accepts the full snippet syntax in the contents field, so you can put in “$array_walk(${1:array}, ${0:funcname})”, for example.

0 Likes

#26

Thanks for all your hard work jps, this is definitely looking impressive!

Since we’re on the subject of snippets etc, is there currently a UI available - or planned to be implemented - for me to view available snippets within a given snippet directory?

i.e. When I’m working inside PHP tags, I’d like a quick reference panel (perhaps located underneath the minimap?) where I can see a preview of PHP snippets and their associated trigger. I can then double click an item to insert, or enter the tab trigger, even right click for a context menu that allows me to edit the snippet contents, change the tab trigger, or remove the snippet completely. Being able to switch between snippet views quickly and painlessly would be nice, even dynamically updating the snippet panel when moving between different code sections within the same file (e.g. PHP <-> HTML / Javascript <-> HTML)

0 Likes

#27

While not exactly what you’re after, pressing ctrl+space without typing anything (i.e., with only whitespace or punctuation to the left of the cursor) will show a list with of valid snippets at that point.

0 Likes

#28

[quote=“skaet”]Thanks for all your hard work jps, this is definitely looking impressive!

Since we’re on the subject of snippets etc, is there currently a UI available - or planned to be implemented - for me to view available snippets within a given snippet directory?

i.e. When I’m working inside PHP tags, I’d like a quick reference panel (perhaps located underneath the minimap?) where I can see a preview of PHP snippets and their associated trigger. I can then double click an item to insert, or enter the tab trigger, even right click for a context menu that allows me to edit the snippet contents, change the tab trigger, or remove the snippet completely. Being able to switch between snippet views quickly and painlessly would be nice, even dynamically updating the snippet panel when moving between different code sections within the same file (e.g. PHP <-> HTML / Javascript <-> HTML)[/quote]

I think the zen coding method of pressing F1 to bring up a find panel style list of all possible snippets in the current syntax would be better. Rather than having a panel always on screen.

0 Likes

#29

This snippet window doesn’t seem to constrain itself to my screen: the bottom easily gets cut off.

0 Likes

#30

I’ve made a file for CSS completions based on this properties list meiert.com/en/indices/css-properties/. It’s just a basic start for all the properties I haven’t added variations of each property with completed values. I’ve commented out the CSS3 elements I don’t think any browser supports yet but I could be wrong on a few (voice perhaps). Feel free to include it in Sublime and change or modify it.

Btw, the fuzzy completions are great! It’s like zen coding but i can make up the completion snippet based on what makes sense :smile: Great stuff.
CSS-completions.zip (2.65 KB)

0 Likes

#31

So with the new auto completions is there a possibility of a “Display auto completion as you type” setting?

0 Likes

#32

Jon,

have you given thought to conditional completions? E.g. in C only allow certain completions if an #include <…> for that part is present. I can see that I need to provide C_completions.py for the parsing and such, but does the completions file allow for any demarking of the appropriate sections?

0 Likes

#33

Not sure if it has been reported in this thread yet, just skimmed through it quickly and it seems kinda crazy to make a separate thread for it so just posting a bug I found here. I tested it in PHP and it didn’t occur so I think it’s only an HTML issue but for some reason in HTML the following occurs.

[code]

Some text.


A test.

[cursor here] [/code]

Now if the cursor is where it’s shown above and you hold shift then up then end to delete the second paragraph, ST2 unindents the first paragraph for some reason. On Linux if it’s platform specific for some reason.

[code]

Some text.

[/code]
0 Likes

#34

You can make multiple .sublime-completions files, each targeting a different scope. For example, you could save this as Packages/C++/Headers.sublime-completions:

{
	"scope": "string.quoted.other.lt-gt.include.c meta.preprocessor.c.include source.c++",

	"completions":
	
		"vector",
		"numeric",
		"funcional"
	]
}

If you want to do a similar thing via the completion API, then you’re given the locations the auto complete is triggered at, so you can run view.match_selector(point)

0 Likes

#35

Here is the full PHP function list with snippets for every function:

bitbucket.org/vostok4/sublimeph … ompletions

0 Likes

#36

[quote=“ilya”]New completion system is very cool!

But wrapping selection with html tags is not working?[/quote]

Yes. I miss that very much :frowning:

Edit:

Umm, I cant even trigger paragraph, p->tab gives me (v2032) :astonished:

0 Likes

#37

Jon, I cannot get what you wrote to work.

I created a Headers ©.sublime-completions with (shortened) the following contents:

[code]
{
“scope”: “string.quoted.other.lt-gt.include.c meta.preprocessor.c.include source.c”,

"completions":

	"assert.h",
	"complex.h"
]

}[/code]
I cannot get this to work. If I take out the parts in scope before “source.c” then I can get it to complete. I have set the syntax explicitly to C in the View menu. So what obvious thing am I doing wrong here? It should be similar to your C++ example. I’ve tried “meta.preprocessor.c.include source.c” as well as “string.quoted.other.lt-gt.include.c source.c” as well, but they also failed.

Also, my question before was actually different. Since I communicated the idea across badly, let me try again. Within the scope of the source file if you would allow all completion tokens it would be incredibly bloated. So depending on which #include files are included at the top I would like to limit the tokens. E.g. if #include <stdio.h> is included I want fclose() to be available in autocompletion, but if #include <stdio.h> is not present, I don’t want to offer the possibility.

0 Likes

#38

I think a plugin could be what you want here. Using Jon’s example plugin as a starting point:

[code]import sublime
import sublime_plugin

class C_Completions(sublime_plugin.EventListener):
all_completions = {“string.h”:
(“sl”, “strlen($1)”),
],
“stdio.h”:
(“pf”, “printf($1)”),
]}

def on_query_completions(self, view, prefix, locations):
if not view.match_selector(locations[0], “source.c”):
return ]
filenames = ]
regions = view.find_all(r"#include +"<](.+)">]", 0, “$1”, filenames)
completions = ]
for f,r in zip(filenames, regions):
if (f in self.all_completions and
view.syntax_name(r.begin()).strip().endswith(“preprocessor.c.include source.c”)):
completions += self.all_completions[f]
return completions[/code]

0 Likes

#39

Is there a way to get the scope name in a plugin

I tried

view.run_command('show_scope_name')

and theres view.scope_name() but I can’t tell what args it takes or even if it does what i need (grab the the file source type eg: source.css.less) so i can check against it.

We really really need some api docs for ST2.

0 Likes

#40

I believe view.syntax_name and view.scope_name are identical. They both take a text_point as an argument and return a string containing the name of the scope at the text point.
If a function exists in both ST1 and ST2, it tends to take the same arguments and have the same effect, so the API docs for ST1 are actually pretty helpful.

0 Likes

#41

adzenith thanks for the quick reply.

this seems to work

view.scope_name(view.text_point(0,0)).split(' ')-2]
0 Likes

#42

[quote=“atomi”]adzenith thanks for the quick reply.

this seems to work

view.scope_name(view.text_point(0,0)).split(' ')-2] [/quote]

view.text_point(0,0) will always just be 0, I believe.
You can also call view.settings().get(“syntax”) in order to figure out which syntax file is being used.

0 Likes

#43

I don’t understand… “will always just be 0”
Sorry.

Are you talking about the return value?
I’m getting as the return value fwiw punctuation.definition…

0 Likes

#44

view.text_point() returns a a text_point, which is really just an integer index of the indicated character in the buffer. Because the character at row 0, col 0 is always the character at buffer index 0, view.text_point(0,0) will always return 0.
Let me know if I’m not making any sense.

0 Likes