Add file-specific words to Sublime Text spell checking - sublimetext

If I use a certain (made-up) word only in a particular file. Is there a way to add it to the dictionary of just that particular file with Sublime Text?

Updated 23 Jan 23
Unfortunately not. You can use the added_words setting to include your special word in the dictionary:
{
// ...
"added_words": [
"Bandersnatch"
]
}
But this is an application-wide setting, and it's not consulted in the project or user setting scopes.
But if you put that in your user settings, it will apply in all files. To be more precise, you can use Projects. Create a project file, then make sure you open your project using the Projects > Open Project… menu item. In there, you can put the added_words setting in the settings object:
{
"folders":
[
{
"path": "."
}
],
"settings":
{
"added_words": ["Bandersnatch"]
},
}
This will apply the setting to just a single window, but it will be all files in that window. You can tailor the project (using the folders key) so that it only displays the one file, but that may be too restrictive.
Depending on the different file types you edit, it may be possible to tailor the spelling_selector to uniquely identify this one file. In fact, if you wrote a syntax which applied a scope (which you could inherit from the real scope) to any file with the exact name your file has, then you'd be able to apply spelling only to that file using spelling_selector. However, I think this would turn off spelling for all other files, which is probably not what you want either.

Related

Syntax highlighting for .js.erb won't stay as JavaScript [duplicate]

Is there a way to make Sublime Text use a different syntax hilighting plugin for files inside a specific directory tree?
E.g. By default I want to use the default Javascript file type for .js files, but for files under ~/Unity/ folder I want to use Unity3d-Javascript file type.
Check out the ApplySyntax package. This is a very powerful plugin that allows you to apply arbitrary regexes to several different aspects of a file (file name, contents, first line, suffix, etc.) and then assign a syntax based on them. Once installed, open Preferences -> Package Settings -> ApplySyntax -> Settings-Default to read all the notes and see how the regexes are set up. Then, open ... -> Settings-User and add your custom regexes. I haven't tested this, but something along these lines should work:
{
"name": "Unity3D/UnityJavaScript",
"rules": [
{"file_name": ".*/Unity/.js$"}
]
}
Good luck!

How to maintain Interface and Implementation in separate files simultaneously in Xcode

I have several lines of code of a written class with Interface written in testclass.h and implementation written in testclass.m in Xcode. I wish when I update an entry in testclass.m, its counterpart in testclass.h can be updated automatically.
For example, I have an interface for following function in both testclass.h and testclass.m:
-(void)testfunction
And I modified its name to a different one due to some reason in testclass.m to:
-(void)another_test_function
If I want this code to run I need to manually change the entry in the header. Although I'm very new to programming but I can imagine it could be really frustrating if you are trying to modify something in a big program with a lot of different files invoking some modified entry name. I wish Xcode can auto-detect this change and modify the entry in the header file to -(void)another_test_function automatically.
Is there any way I can do that? All I know by searching the internet is that you can use a shortcut to "edit all in scope" but this only affect all the occurrence in the same file, not header file.
Right-click the method name you would like to change (in either the header or the implementation file) and then select Refactor > Rename. You can then change the name of the method, and Xcode will show you what it will change.
If that looks good, you can accept the changes and you're done.

Sublime Text different syntax for files under a specific subdirectory

Is there a way to make Sublime Text use a different syntax hilighting plugin for files inside a specific directory tree?
E.g. By default I want to use the default Javascript file type for .js files, but for files under ~/Unity/ folder I want to use Unity3d-Javascript file type.
Check out the ApplySyntax package. This is a very powerful plugin that allows you to apply arbitrary regexes to several different aspects of a file (file name, contents, first line, suffix, etc.) and then assign a syntax based on them. Once installed, open Preferences -> Package Settings -> ApplySyntax -> Settings-Default to read all the notes and see how the regexes are set up. Then, open ... -> Settings-User and add your custom regexes. I haven't tested this, but something along these lines should work:
{
"name": "Unity3D/UnityJavaScript",
"rules": [
{"file_name": ".*/Unity/.js$"}
]
}
Good luck!

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.

Xcode 4: How can I reference project variables/macros in a file template?

Ok, so, I've got a relatively complex project template hierarchy that defines code style related macros and variables (curlies on same or new line, indentation, etc). My code style template will probably give more context
Works great when generating a project.
However, I'm not seeing a clear path to reusing these macros/variables when generating new files after the project has been built. Findings so far:
macros and variables defined at the project level are not substituted when referenced in a file template
popup option definitions in file templates do not seem to support complex definitions (e.g. defining a macro when the drop down is in a given state)
project variables do appear to become defaults for options of the same name in the file template wizard
file templates don't appear to be able to define other templates as ancestors
Any ideas?
Enter the following line:
defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{ "ORGANIZATIONNAME" = "Your Company Name" ; }'
into a Terminal window, replacing "Your Company Name" with whatever you choose.
You can also open the file at ~/Library/Preferences/com.apple.Xcode in "Property List Editor" and insert your company name as a string value for the key "ORGANIZATIONNAME" under the dictionary "PBXCustomTemplateMacroDefinitions". You may need to create "PBXCustomTemplateMacroDefinitions" at the top level if it doesn't already exist.

Resources