What is the option that makes Sublime Text add whitespace at the left of wrapped lines? - sublimetext

I want Sublime to treat my text files like they are source code files and show whitespace at the left of wrapped lines, like so:
beginning of long line blah blah blah, now it wraps
and it keeps going after an automatic indent
I tried opening the console and setting the option manually:
view.settings().set('indent_subsequent_lines', True)
but nothing changes, any ideas?

Well, that was fun. There's no easily accessible setting for this. But as you indicate, ST decides whether to add an extra indent when soft wrapping, from whether the syntax is considered code-like or plain text-like.
Being one or the other is up to the package defining the syntax to specify. So lacking a global setting from ST, you need to change your text packages. As an example, let's take Text. That contains Plain text.tmLanguage. In that you change
<key>scopeName</key>
<string>text.plain</string>
to
<key>scopeName</key>
<string>source.plain</string>
I'm unsure of whether there'll be ill effects from not keeping .plain.
One easy way to do this is to get the PackageResourceViewerpackage.
After install, do:
cmdshiftp
Type: Open Resource
return
Type: Text
return
Type: Plain text.tmLanguage
Make your edit and save.
PackageResourceViewer will save the modified Text package to your Packages directory. And sublime will display files considered to have Plain text-syntax, like they are code.
The caveat is that you need to do this for every text-syntax you want to be considered code.

As #AdamAL said, it's dependent on both the 'indent_subsequent_lines' setting as well as whether it's considered a "source" or a "text" language ... by default, "markup" languages (such as HTML, CSS, etc.) and plain text, etc., are considered "text", and programming languages such as C++, Java, PHP, etc., are considered "source".
"Source" languages will indent subsequent soft-wrapped lines (if the indent_subsequent_lines is true), whereas "text" languages will only indent up to the same level as the current line.
For each one you want to change, you'll need to edit the settings of the given language. #AdamAL's answer provides a great way to do this using the PackageResourceViewer package:
After install, do:
[Ctrl/Cmd]+[shift]+p, "Open Resource"
Find the name of the language you want to change, and find either the .sublime-syntax file or the .tmLanguage file. .sublime-syntax is supported from build 3084 of ST 3 and appears that it may trump values in the .tmLanguage file in supported versions, if present (when editing the definition of TaskPaper files provided by the "PlainTasks" package, my change didn't take when just editing the PlainTasks.tmLanguage, I had to edit the PlainTasks.sublime-syntax before it took).
In .sublime-syntax (which are YAML files) look for the first scope: line, where the main scope name of the language is identified (there will be lots of other scope: entries further down under contexts:).
In .tmLanguage (which are XML .plist files) look for the <string> following the <key>scopeName</key>.
Sublime Text Syntax Definition Documentation Reference:
scopeName
Name of the topmost scope for this syntax definition. Either source.<lang> or text.<lang>. Use source for programming languages and text for markup and everything else.
The <lang> (without brackets) is just an identifier string for the given syntax/language definition.
I noted that it seems that (in ST 3, anyway), no restart of Sublime Text is needed to get the changes to apply, if the edit is in the right place.
And also note that there may be other effects of changing this in more complex packages -- For example, in PlainTasks, the additional keybindings that it defines depended on it looking for a context that included text.todo, which I changed to source.todo in several places. So in order for the keybindings to work properly again, I also had to update my .sublime-keymap for that package. (This could also be because I changed it in a place besides the .sublime-syntax that I didn't need to. Just sayin' -- YMMV.)

Related

A new language, how to auto-complete in windows vim?

I'm using Gvim in windows.
Normally, when we type some character then press Ctrl-n, vim will show some tag, but those tags just includes words which have been pre-typed in the current file.
Now, I need it working in a new language, and show the tag which has been defined in other files.
So, I create a new \\.ctags for this new language, and generate tags file by exuberant-ctags.
I can choose a function in current file, then press Ctrl-] to jump to the function definition, but this function was define in the other files. It is working very well.
I don't know how to make it show the tags which are generated by ctags when I type some character.
Please help me. Thanks very much.
My English is poor, I hope you can understand what I said.
CTRL-N is just the default completion (which completes from a variety of sources, including the open buffers and also the tags database). There are many more specialized completions (all starting with CTRL-X), among them tags completion, triggered via CTRL-X CTRL-], see :help i_CTRL-X_CTRL-]. If you've correctly configured the 'tags' option (so your tags database is found) and tags jumps do work, just start using that.
Some languages / filetypes also define a language-specific completion (for language keywords etc.), usually via the 'omnifunc' option and triggered by CTRL-X CTRL-O. You could write such yourself, too.

How to create this sublime text syntax?

I am trying to create a simple sublime syntax where when the first word of a line is "DONE" the whole line turns to a different color.
For example:
- do this
DONE - do that // this line turns green
- but also do this
My two questions are:
- How does one go about creating a ST syntax
- How would I create the above simple syntax.
The most you could highlight is the region containing text. I don't know if that's what you are looking for. To do this would require defining a tmLanguage file and modifying you tmTheme file. The tmLanguage file describes a set of regular expressions for which a scope is applied to the text within ST. The tmTheme file takes the scopes applied, and applies some coloring. I'm not an expert on writing either of these files, so you may need to do some experimentation on your own.
For information on writing syntax files, see here and here. The theme files are much simpler, in terms of defining them. Those guides recommend using AAAPackageDev, which is not necessary (and not compatible with ST3 last I checked). The language files are all XML, which you can work with, but I find working in JSON or YAML easier. If you feel the same way, you can start with the below snippet and use SerializedDataConverter to convert between XML and PLIST/JSON.
{
"name": "Syntax Name",
"scopeName": "source.syntax_name",
"fileTypes": [""],
"patterns": [
],
"uuid": "ca03e751-04ef-4330-9a6b-9b99aae1c418"
}
I can't recall the location of any references, but I'm sure they're out there. Though, simply viewing some existing theme files may be enough for you. TO view these, you can use PackageResourceViewer. Isn't really necessary if you are working in ST2, but makes things much easier in ST3. To begin working on your own custom theme, I'd copy the contents of the theme file you are currently to a new file, and save it in your Packages/User directory. That way, you always have something to revert to, in case you mess something up.

Does a syntax highlighter in an IDE scan the whole file every time a letter is typed?

Assuming a syntax highlighter uses a lexer to do the background work: when typing in an IDE with live syntax highlighting, does the lexer have to re-tokenize the entire file (in whatever language, ex. Java, C++, Python, etc), does the lexer only have to re-read and tokenize the current line, or does it only keep itself occupied with a single character/word at a time?
I'm asking because in a lot of editors/IDEs, most code remains the same as the programmer is typing, however, in some cases there's stuff like starting a string literal, which re-highlights the rest of the line, and in other cases like starting a multi-line comment, the whole text file becomes re-highlighted from the point where I start the multi-line comment, to the end of the file.
If the lexical analysis has to be done for the entire file for every single letter typed, wouldn't that make it slow, especially for larger (100.000+ lines) text files?
There is a syntax highlight and semantic highlight.
Syntax highlight is when editor only decorates based on language syntax - e.g. identifiers are black, keywords are pink and comments are green. Syntax highlight does not necessarily reparses (or, rather, tokenizes) the whole file - it can only tokenize "damaged region" (e.g. tokens around edit location). Of course, editor developer may opt to tokenize the whole input - as it is really fast, error-proof and easier to implement.
Semantic highlight (one that, for instance, can highlight global and local identifiers differently) usually require complete reparse - e.g. in Java adding "static" to function declaration would require you to invalidate function references both above and below the cursor. In some cases caching may be implemented (e.g. cache include files parse result as user edit does not change it that much). Semantic highlight is slow so it is usually combined with syntax highligh (you may see in Eclipse that the keywords are highlighted instantly - while member variable changes the color from the black after some small delay).
I didn't look this up, but I am pretty sure that it depends what is being highlighted. That is, comparing the local area you are typing in with basic syntax; versus, say an open comment that until closed highlights from that point until the end of the file.

Syntax Highlighting in Sublime Text 2

So I have been trying to figure out how to add syntax highlighting for the name of typedef's in c++ files, in sublime text.
For example, if I have typedef long long integer; I want integer to be highlighted (preferably the same color as the other types: int, bool, etc.). I went looked at the C.tmLanuage file, and tried to add the following regex code ^typedef.*?\s(\w+)\s*; to storage.type.c (line 49), but it didn't work. If I add the word string, it will highlight all instances of the word string. I tried going in the C++.tmLanguage file, and adding the regex code to storage.type.c++, but it still did not work.
Does anybody know how to get typedef's highlighted in sublime text?
Also, is there a way to get syntax highlighting for class name? Let's say I declare a string or vector, I would like either string or vector to be highlighted.
That regex would work (I believe) if you had something along the lines of typedef foo; To get the behavior you want, you will have to create a slightly more complex pattern entry in the tmLanguage file. As the language file is based on TextMates, you will want to have this as a reference (http://manual.macromates.com/en/language_grammars#language_grammars). I would also recommend using PlistJsonConverter (working in JSON is easier for me than working in XML). You will probably need to define begin and end patterns (begin will probably be typedef end will probably be ;). You can then apply whatever patterns you want to that group.
As for the class name highlighting, I would look to see what, if any scopes are being applied. If none are, you will have to come up with a regex to apply the scope to those. You can then add a color entry, or use a defined one from the color scheme.
Edit:
Actually they don't appear to be JSON. I see () rather than []. JSON is pretty simple to understand. You can look for something more in depth, but wikipedia is a good place to start. What you would probably be interested in are the things under the "Rule Keys" section. I did some searching (because I knew there were some better examples out there), and came across http://docs.sublimetext.info/en/latest/extensibility/syntaxdefs.html . It goes over syntax definitions from scratch, but the most relevant section is probably http://docs.sublimetext.info/en/latest/extensibility/syntaxdefs.html#analyzing-patterns. I don't have a regex to find class names, so you would have to come up with one yourself. If you haven't already though, you may want to search around to see if someone else has implemented a language file in a way that works for you.
You will want to start with the built in tmLanguage file and convert that from a Plist to json. You can then edit that file and move it back.

Custom syntax highlighting in Geany

I am trying to create custom syntax highlighting for Kivy '.kv' files in the Geany editor. Although the specific filetype seems irrelavant to the issue I'm having, as any efforts I make at getting syntax highlighting to work for a custom filetype results in a completely non-highlighted file. I believe I have done my homework on this, and nothing seems to work.
I have added the following to ~/.config/geany/filetype_extensions.conf
Kivy=*.kv;
I also have a custom type definition file named 'filetypes.Kivy.conf' in ~/.config/geany/filedefs/. I have tried basing this file off several of the stock type definition files in /usr/share/geany/ and the file never gets any syntax highlighting applied in Geany. Right now, just for experimentation's sake, my 'filetypes.Kivy.conf' file looks like this:
# For complete documentation of this file, please see Geany's main documentation
[settings]
# default extension used when saving files
extension=kv
# single comments, like # in this file
comment_single=#
[keywords]
# all items must be in one line
primary=size canvas
secondary=pos size
[indentation]
width=4
# 0 is spaces, 1 is tabs, 2 is tab & spaces
type=0
This is very loosly based on the stock XML definition file, but like I said I've tried many other stock files. In many cases I only changed the 'extension=' value to kv and still no highlighting was applied, even though going to Document>Set Filetype in Geany and choosing virtually any random filetype (besides my custom entry) would yeild some sort of highlighting within my .kv file. This is even the case when using the unmodified contents of a stock definition which otherwise works fine on my .kv file when specifically selected in Geany!
Also, the Kivy filetype is listed and selected by default in Document>Set Filetype within Geany, so I must be doing something right here!
I realize this similar question has been asked, but the solutions seem irrelavent to my case, as I've tried every related topic on this and many other sites. My Geany version is 1.22 and I'm running Arch Linux. This is driving me nuts - any suggestions?
Thank you!
Set lexer_filetype= property in the [settings] section of your filetype file. Working highlighting requires that there is a lexer that could be used for highlighting the .kv-files.
For more info see http://www.geany.org/manual/#lexer-filetype
There are three important things to obey:
the configuration file should be placed in "~/.config/geany/filedefs"
the configuration file must have the extension ".conf" - otherwise it won't show up at all (the files in "/usr/share/geany/filesdefs", where I copied my base file from, do not have a ".conf" extension!)
you must set the "lexer_filetype" to an existing (presumably builtin) configuration; e.g. "lexer_filetype=Python"

Resources