Sublime Forum

[SOLVED] Possible to launch custom AutoComplete on_modified OR include word separators on_query_completions?

#22

 

My convention is pretty specific:
 

Class: title case
Person, HumanBeing

Variables: camel case + ( ( underscore + TitleCase ) * x )
item_Property_SubProperty, name, firstName, firstName_Vowel_Count

Functions: same as variables, but with a verb as the first word
verb_Description, get_FirstName
 

I only use camel case initially to differentiate between classes and [ variables | functions ], but find that title case offers the ability to minimize underscores while maintaining readability and also more clarity than strict camel case.

EG:
          lastWord_FirstSegment_Vowel_Count
vs      lastWordFirstSegmentVowelCount
vs      lastword_firstsegment_vowel_count
vs      last_word_first_segment_vowel_count

Although I will agree that this is my own take on “what is readable or not”, as you mentioned.
 

 
PEP8 shows mixed LISP and K&R style @ Indentation.

 

 
True.  I guess for in-line context, whitespace maybe detracts from code relationships.  I write more for macro-level scanning so I can find what I’m looking for quickly, and then utilize ST’s native bracket highlighting if I need to precisely interpret a particular line.  Also, I tend to over-declare variables as to avoid that issue entirely, so I can read complex nestings as if they were text rather than having to decipher functions in-line.

EG: I spread my rocks out so I can find them easily, and if I need to inspect one I’ll pick it up & stare at it.  :stuck_out_tongue:
 

 
Meh, I feel like it’s unavoidable since there are so many languages ( some of which have particular convention limitations ), potential styles, and personal preferences.

I know I’m not always going to dig everyone’s code preferences, but I can always use a tool to format their code or run a RegEx replace or something.  If I’m contributing to a repo I just try to adapt & use it as an exercise in versatility.

 

Have you used CoolFormat by any chance?  I find it super useful for quickly altering code that’s not in my preferred format.  Just wish it had a few more language options…  Know of any similar options that may be more universal?

Also, out of curiosity since you mentioned you review a lot of code - what kind of stuff do you work on outside of ST?

0 Likes

#23

Your conventions seems very arbitrary from my point of view, although “consistent” in that sense. Whatever floats your boat.

I didn’t know of CoolFormat, but I also don’t use a lot of the languages it supports.

Well, I generally find myself reading at least as much code as I’m writing when I’m primarily being productive, even if just to get familiar with either the code base or what I am going to use from a third party. While maintaining the package_control_channel repo, I scan all Packages for typical offenders like leaking file handles, bad ST2-3 compatibility specifications or just how they function in general. In addition to that, I’ve worked on a couple open source packages where you obviously need to grasp the code first before making the changes you want to.

Outside of ST I just script myself script some things. Whatever I need. And work on stuff related to my studies.


Please reply to this post in a PM if there is more to talk about. It really defeats the purpose of this thread.

1 Like

#24

@FichteFoll

 
YUSSS!  :smile:

 
I managed to get YAML working by mirroring my JSON format.

First level completions can optionally have a string value to replicate snippet functionality.  All nested completions use dictionaries only, where final nested values are just empty dictionaries.

This allows me to easily query the entire structure as a simple dictionary without the need for additional processing.

 
EG:  My code pulls completions by:

completionSets[ "TestCompletion" ][ "PrimaryA" ][ "SubA1" ][ "Nested1" ]

 

And now I have nice, simple custom-completions files that are much smaller & easier to [ read | write ].
( and infinite nesting )

completionTrigger: "."

fileContext_Mode: "All" # "All" | "Syntaxes" | "FileExtensions" | "Scopes"
fileContexts: []

locationContext_Mode: "All" # "All" | "Paths_StartWith" | "Paths_EndWith" | "ProjectNames"
locationContext_RegEx_Enabled: false
locationContexts: []


completionSets:
	
	TestString1: "THIS IS A STRING"
        TestString2:

	TestCompletion:
		PrimaryA:
			SubA1:
				Nested1:
				Nested2:
			SubA2:
		PrimaryB:
			SubB1:
			SubB2:

 

Thanks again for your input, the YAML implementation is perfect.  :grin:

1 Like

WebGL Completions and Tooltips
Is there any way to trigger autocompletion on non-word characters?
#25

Hi Fico,
I am a newbie in sublime plugin development This post is really useful to me and I am trying to develop something really similar. Would you mind kindly explain why here

"auto_complete_triggers": [ {"selector": "text.html", "characters": "<"}, {"selector": "source.python", "characters": "."} ],

make this solution work?

Looks like this setting means only trigger the on_query_completitons when the file syntax is python and when there is a “.” ahead of the word . I am trying to replicate the process like you did but it does not work…

Thank you so much for your kind reply!

0 Likes

#26

The auto_complete_triggers setting controls additional situations in which the AC panel opens automatically; the setting here says that it opens when you press < while in an HTML file (in which case you will get HTML tag completions) and when you press . in a Python file, in which case you get… whatever the plugin would generate for AC entries in that case.

In either case it is up to the on_query_completions handler to use to context clues it’s given (like the location in the buffer) to examine what the buffer looks like to know what it’s supposed to suggest.

0 Likes