Home Download Buy Blog Forum Support

Tab completion questions

Tab completion questions

Postby John Hewitt on Sun May 27, 2012 9:08 pm

I am sorry to start yet another thread on autocompletion to this forum. I did consider appending my main questions to one of the others but that doesn't seem right somehow. I am a newbie on ST2, and actually just deciding whether to stick with it. I am computer literate but I don't know the python language or json text formatting and have no desire to learn either.

Nonetheless, I do like many parts of this program, otherwise I wouldn't bother posting here at all, but there are some parts I just don't like. A major one is the almost complete absence of sensible help files. I don't understand how this program can be considered to be in version 1, let alone a candidate for version 2, when its only help documentation is written like a collection of programmers' telegrams.

However, on to my problem. I have a bunch of files with .txt extensions which I want to highlight as html. (I've got that highlighting working.) I also want many tab completions to insert as HTML code but also want others to insert technical terms of my choice - maybe RNA as ribonucleic acid, that kind of stuff.

I have been trying to get ST2 to simply to autocomplete in this way and want it to draw its completions from a file or files of my choice, not from some arbitrary list drawn up by the progammer, presumably Jon Skinner. As a test, I have been trying to get br-tab to autocomplete to <br />. (By default, it completes to <br> - simple enough one might think and I can do it, but not in the way I think is needed. If I go into the default HTML/HTML.sublime-completions file and edit it I can get br-tab to complete as <br />. Similarly, I assume that to get the <br_tab to complete to <br /> I would need to edit the HTML/html_completions.py file - I haven't done that but I assume it would work.

However, I learned these things more by trial and error than via the documentation files which, as I say, seem like waste of time to me. Moreover, there still seem to be quite a few completions whose source I don't understand or have the ability to control. More importantly, I think editing those files in the default directory would be bad because any changes I make there might be overwritten by any future upgrade. What I need is to set things up so that the completions arise from files in the user directory, where they wouldn't be touched by program upgrades, and I can't get files in that folder to do anything at all.

I have tried copying the HTML default files into the user directory, but I have not succeeded in getting my changes to be recognized as the required completions. Also, I have not succeeded in switching off the completions in the default folder, which I would like to do.

I can get completions like this to work in snippets, but I don't want a separate snippet file for every trivial text replacement like that. So, now I have some questions.

1. How does one set up completions (or other preference) so that those specified in the user folder take precedence over those in the default folders? How could I turn of the default completions altogether, so that only those controlled by the user directory or drawn from active files are operational?

2. What is the precise set of files from which autocompletion data is drawn and what is the order of preference assigned to them? It would be useful to have a clear order of priority so that, without random experiments, a user could infer which file is providing any particular completion.

3. I think part of my problem comes from the "scope" syntax found at the beginning of many of these files, since I have .txt files that I want to act as html. Here is an example of the syntax I mean.
"scope": "text.html - source - meta.tag, punctuation.definition.tag.begin"
It would be useful to know what exactly this kind of thing, at the beginning of a file, means but the explanation should preferably be in English, rather than python. The scope directive seems to be sending the system to the html defaults and, if so, I want to know how to write a line that redirects it to files in the user folder or to files with a .txt ending.

4. Can a collection of snippets be assembled into a single user file? If so, how?
John Hewitt
 
Posts: 7
Joined: Sun May 27, 2012 4:52 pm

Re: Tab completion questions

Postby C0D312 on Sun May 27, 2012 9:48 pm

Hi John. I'll see what I can do to help.

John Hewitt wrote:the documentation files which, as I say, seem like waste of time to me

The official documentation is incomplete. However, you'll have better luck if you check out the Unofficial Docs: http://docs.sublimetext.info/ Guillermo volunteered his time and compiled this large database of helpful information. Searching this forum usually brings up some good info too. In any case, you should be able to find all you need right here: http://docs.sublimetext.info/en/latest/ ... tions.html

But I'll try to answer your questions specifically anyway.

1. The user file always takes precedence over the default folders. You could potentially delete all the snippet files in the default folders but I don't see the point. I'm assuming you're primarily a web designer/developer since your questions are HTML based. Could I ask what results you're getting that you don't want?

2. This question is answered almost verbatim here: http://docs.sublimetext.info/en/latest/ ... tions.html so I won't really go into detail.
- Snippets
- API-injected completions
- .sublime-completions files
- Words in buffer

3. http://docs.sublimetext.info/en/latest/ ... -selectors

4. Yes. Sublime-completion files are essentially a collection of snippets.

Let me know if that didn't answer all your questions. I'll be willing to go into more detail if you'd like.
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Tab completion questions

Postby atomi on Mon May 28, 2012 12:59 am

Just to add, there is also readthedocks.org site at http://readthedocs.org/docs/sublime-tex ... en/latest/ with good information.

Also, for your #1 question you can copy the HTML default folder into your User folder and rename it (don't use HTML). Then in your User Preferences file you can add:

"ignored_packages": ["Vintage", "HTML"]


This way the edits you make in your User folder will always take precedence.
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US

Re: Tab completion questions

Postby C0D312 on Mon May 28, 2012 1:59 am

atomi: readthedocs == docs.sublimetext.info

They link to the same thing.
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Tab completion questions

Postby atomi on Mon May 28, 2012 4:08 am

C0D312 wrote:atomi: readthedocs == docs.sublimetext.info

They link to the same thing.


I didn't notice the docs subdomain I saw sublimetext.info and just thought you linked to: http://www.sublimetext.info/docs/en/
- which is a lot of the same information but just wanted to be thorough.

I think Guillermo owns the domain (whois check doesn't say- domains by proxy).
It might be a good idea to just redirect. Although the notice up top is probably enough...
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US

Re: Tab completion questions

Postby John Hewitt on Mon May 28, 2012 9:52 am

C0D312 wrote:Hi John. ..
But I'll try to answer your questions specifically ...
1. The user file always takes precedence over the default folders.

That is not my present experience. At present, my user file are not taking precedence over the default folders. I think they need to.
You could potentially delete all the snippet files in the default folders but I don't see the point. I'm assuming you're primarily a web designer/developer since your questions are HTML based. Could I ask what results you're getting that you don't want?.

I gave you an example for the <br> tag, which I want to change to <br />, the closing slash is now the preferred syntax in HTML. Although I know no python it is easy enough to edit the completions file to achieve that result. However, so far, I have only achieved it by editing the HTML default file. I have tried copying that same file into the user folder, but edits to that file have no effect. The outcome I want is that this simple completion, and all other completions, are controlled by me, the user, by editing files that are under my control.

C0D312 wrote:2. This question is answered almost verbatim here: http://docs.sublimetext.info/en/latest/ ... tions.html so I won't really go into detail.
- Snippets
- API-injected completions
- .sublime-completions files
- Words in buffer


I had read that but I do not see how it places the user in control of what is entered into a file that he or she is developing, and that must be the final outcome.

1. In my hands, single file snippets in the user folder do seem to take priority when accessed through the menu, though not via their trigger.
2. I do not know what is meant by "- API-injected completions" but it sounds like something the user is not in control of. If so, I might see it as undesirable.
3. Right now the cache might be a nuisance. I have several times found that the system's behaviour is changed by restarting the program. For development purposes, it might be worth switching the cache off and turning it on again when the first stable release appears.
4. Whether words should be drawn from a buffer is a matter of where they come from originally. The idea of drawing words from elsewhere in an open file, or other open files, or files in a project, seems good but I think it is the user's actions that should be defining those choices, not decisions made by the programmer.

There is quite a long list of sources for these completions and, at the moment, my sense is that the user is being outvoted by the program, which should not be happening. That would be the point of turning some of these things off by default and getting the user to choose which completion syntax to make active.

I've look at that stuff but, at present, I don't understand it. I still think it may be my problem.
4. Yes. Sublime-completion files are essentially a collection of snippets.
Let me know if that didn't answer all your questions. I'll be willing to go into more detail if you'd like.

Yes, that's how it seemed to me. My problem is how to get it to actually work.
John Hewitt
 
Posts: 7
Joined: Sun May 27, 2012 4:52 pm

Re: Tab completion questions

Postby John Hewitt on Mon May 28, 2012 9:54 am

atomi wrote:Just to add, there is also readthedocks.org site at http://readthedocs.org/docs/sublime-tex ... en/latest/ with good information.

Also, for your #1 question you can copy the HTML default folder into your User folder and rename it (don't use HTML). Then in your User Preferences file you can add:

"ignored_packages": ["Vintage", "HTML"]


This way the edits you make in your User folder will always take precedence.

That seems a good suggestion, I shall try putting HTML on ignore.
John Hewitt
 
Posts: 7
Joined: Sun May 27, 2012 4:52 pm

Re: Tab completion questions

Postby iamntz on Mon May 28, 2012 1:22 pm

John, most ST users are also developers. So we don't mind to hack a little in json config. Also, i guess we prefer ( i know i do! ) that jon is focusing on new features, bug fixes and stuff like that rather than on an exhaustive documentation (for a very long time, sublime was a one man show, not sure if things are changed lately)

However, I noticed you are in a bit of confusion. <br /> (as well as other self closing tags like img, input, etc) is not preferred syntax in HTML. Unless you are writting XHTML. Which is slightly different than HTML. For this particular case, you can create a shortcut in your Default.sublime-keymap file using this snippet:
Code: Select all
   {
      "keys"   :   ["ctrl+shift+enter"],
      "command":   "insert_snippet",
      "args"   :   { "contents": "<br>" },
      "context":   [ { "key": "selector", "operator": "equal", "operand": "text.html" } ]
   }

(sure, you can use any shortcut you want).

For other quick & short snippets, you could use a completion file (which is the very first example on docs):
Code: Select all
{
  "scope": "text.html",
  "completions":
  [
    { "trigger": "rna|rn", "contents": "ribonucleic acid" },
    { "trigger": "dna|dn", "contents": "deoxyribonucleic acid" },
    // and so forth
  ]
}


You can create file called shortcuts.sublime-completions (or whatever suits you) and place it on your User folder.
iamntz
 
Posts: 816
Joined: Fri Apr 29, 2011 8:52 am
Location: Romania

Re: Tab completion questions

Postby John Hewitt on Mon May 28, 2012 4:34 pm

atomi wrote:Just to add, there is also readthedocks.org site at http://readthedocs.org/docs/sublime-tex ... en/latest/ with good information.

Also, for your #1 question you can copy the HTML default folder into your User folder and rename it (don't use HTML). Then in your User Preferences file you can add:

"ignored_packages": ["Vintage", "HTML"]


This way the edits you make in your User folder will always take precedence.


Right, I did as you suggested and the outcome is that the br_tab completion no longer works - neither do any of the other html completions. That may seem bad, at first sight, but actually I think its good. It tells me that the completions inserted into the user folder are not being read at all and that the HTML default completions are the only source from which these completions are being drawn. It gives me some power, albeit a negative form of it.

The next question has to be, is there some other syntax I could put into the preferences settings that would actively force the program to look into a user.sublime-completions file or into .sublime-completion files generally?
John Hewitt
 
Posts: 7
Joined: Sun May 27, 2012 4:52 pm

Re: Tab completion questions

Postby John Hewitt on Mon May 28, 2012 4:52 pm

iamntz wrote:John, most ST users are also developers. So we don't mind to hack a little in json config. Also, i guess we prefer ( i know i do! ) that jon is focusing on new features, bug fixes and stuff like that rather than on an exhaustive documentation (for a very long time, sublime was a one man show, not sure if things are changed lately)

I do understand that and I am not trying to get at Jon or anyone else. I think his program has some terrific ideas in it. I like that it has a spell checker that respects code, the distraction free mode, the range of desktop adjustments that are possible, the ability to shortcut typing activities, if that ever works, and the ability to put almost everything onto keys. It's a good program. For some time my preferred text editor has been NoteTab pro; I like that a lot but but think I like ST2 more, and that is a compliment.
However, I noticed you are in a bit of confusion. <br /> (as well as other self closing tags like img, input, etc) is not preferred syntax in HTML. Unless you are writting XHTML. Which is slightly different than HTML. For this particular case, you can create a shortcut in your Default.sublime-keymap file using this snippet:
Code: Select all
   {
      "keys"   :   ["ctrl+shift+enter"],
      "command":   "insert_snippet",
      "args"   :   { "contents": "<br>" },
      "context":   [ { "key": "selector", "operator": "equal", "operand": "text.html" } ]
   }

(sure, you can use any shortcut you want).

For other quick & short snippets, you could use a completion file (which is the very first example on docs):
Code: Select all
{
  "scope": "text.html",
  "completions":
  [
    { "trigger": "rna|rn", "contents": "ribonucleic acid" },
    { "trigger": "dna|dn", "contents": "deoxyribonucleic acid" },
    // and so forth
  ]
}


You can create file called shortcuts.sublime-completions (or whatever suits you) and place it on your User folder.


I'll keep those suggestions in mind but the immediate problem is to get things recognized in the user folder.
John Hewitt
 
Posts: 7
Joined: Sun May 27, 2012 4:52 pm

Next

Return to Technical Support

Who is online

Users browsing this forum: No registered users and 10 guests