Disable code completion inside quotes in Sublime Text 3 - sublimetext

Is there any way to disable Sublime Text 3 firing code completion, when cursor is inside single or double quotes:
This seems to be pointless behaviour and is a little bit annoying.
I'm using newest stable (3065) Sublime Text 3, with PHP Completions Kit plugin, if that matters.

So it turns out that your PHP Completions Kit plugin is probably to blame. I forked the code on Github if you'd like to follow along.
You can populate the auto-complete dropdown in Sublime by creating a JSON-formatted .sublime-completions file. Essentially, it's a long list of snippets with associated triggers, the names of which show up in the dropdown and are matched by a fuzzy search method based on what you type. The completions are all scoped so they only come up in the desired parts of your code: for example, you wouldn't want standard function names coming up when you're trying to define a class, etc.
Back to the plugin. For several of the completion files, the scope was built up using negative selectors: starting with source.php (the base scope for all PHP code), and subtracting unwanted scopes. Once analyzed by Sublime, the completions would show up anywhere except where they were explicitly denied. An example, from function.sublime-completions:
"scope": "source.php - variable.other - meta.function.arguments - support.class - entity.other.inherited-class - meta.use - meta.catch - comment.block.documentation.phpdoc"
So those were all the places the author didn't want these completions to show up. Unfortunately, in these several files, s/he forgot to include the string scope, so completions appeared when you were typing strings, clearly undesired behavior. Fortunately, the fix is easy: go through all the completions files, check the scopes for negative selectors, and add - string to the end of them. Now, they'll still work exactly the same as before, except the completions won't show up in any kind of string.
Like I said at the top, I forked the project here, and have made the necessary corrections. I've also submitted a pull request, so we'll see if/when that gets accepted into the main code base. In the mean time, feel free to clone my repo into your Packages directory:
Click on Preferences -> Browse Packages... to open up your Packages directory. Go to that directory via the command line, then run
git clone https://github.com/MattDMo/sublime-phpck.git "PHP Completions Kit"
This will clone the repo into a folder named PHP Completions Kit, overriding the one installed by Package Control. Keep an eye on the plugin's Package Control page, and when you see the Modified field change from 2014-09-05 (it's in the tooltip if you mouse over the text 3 weeks ago) to sometime more recent, check the repo to see if it was my pull request that got merged and a new version released, and then you can feel free to delete the new folder in Packages and just stick with the Package Control version, as I won't be keeping my repo up-to-date on any new modifications to the package.
Update
My pull request has been merged, and Package Control has been updated.

Related

How to unmap sublime text keybinding so standard os action happens?

The normal mac behavior for command+shift+? is to open the help menu search, which is super convenient to do menu commands without a mouse.
Unfortunately a sublime text package I have installed has mapped that key binding to the settings menu. Here's the relevant section of the package Default (OSX).sublime-keymap file
[
{ "keys": ["super+shift+/"], "command": "open_settings" }
]
Based on Related to How to unbind a key binding in Sublime Text 2?
I went ahead and overrode their keybinding in my user keybinding. Here's my user Default (OSX).sublime-keymap file.
[
{ "keys": ["super+shift+/"], "command": "noop" }
]
This stops the package from open settings when I press the key sequence. Same behavior if I use unbound for the command, excluding the command files package keybinding. However, it doesn't bubble up to the Mac layer which opens the help search menu.
I can get things to work the way I want to by modifying the package's key binding file directly, but that's going to get overwritten the next time the package upgrades.
Is there a supported way to remove a keybinding without stopping it from bubble up to the operating system?
The only way to completely remove a key binding in a way that Sublime won't react in any way is to remove it from the sublime-keymap file. This is true whether you want to fully remove a file from the Default/Default (PLATFORM).sublime-keymap (there is one for each platform) that ships with Sublime to remove a default key binding as well as any that might be added by a third party package.
As long as the key remains in a sublime-keymap anywhere, Sublime will see it and try to do something with it, even if the key is bound to a command that doesn't exist such as noop (although that is a good way to block a default key from doing anything if that's your ultimate goal).
Editing the package file
One way to solve the problem is to directly modify the packaged file itself, as you've already mentioned. In most cases that would mean unpacking the related sublime-package file (which is just a zip file), modifying the content of the file, and then repacking it.
As you've already noted, that's not a good way to go because when a package gets updated, the entire sublime-package file gets clobbered away, so your changes will also get discarded.
Overriding the package file
A safer way to do this would be to create a package override file instead. This only works if the package in question is installed as a sublime-package file, which covers all of the packages that ship with Sublime as well as most third party packages.
To do this, you would create a folder in the same name of the package in the Sublime Packages folder, which you can get at via the Preferences menu item Browse Packages.... Once that's done, extract just the file you want to override and place it into that folder, and edit it as desired.
When Sublime loads packages from a sublime-package file, as it loads each file it checks to see if any similarly named "unpacked" files exist in the Packages/PackageName/ folder. If such a file exists, the version inside of the sublime-package file is ignored and the unpacked file is used instead.
This means that even if the package gets updated, since your unpacked version is still there, it will still be used and so your change will remain in place.
The easiest way to create such a file is to use the PackageResourceViewer package. You can use it's PackageResourceViewer: Open Resource command from the command palette to find and open the offending file. If you make changes to the file and save it, PRV will automatically create the override for you.
There are a couple of caveats to this process:
If the package in question is installed already unpacked in the Packages folder, you can't create an override. In this case there's not a lot you can do other than vigilantly re-modify the file when it updates.
Most packages won't fall under this restriction because few actually need to be installed that way (only packages that contain files that need to be exposed outside of Sublime need to be installed this way).
Note also that Sublime Text 2 only installs packages as unpacked, so in that particular case you also can't do this.
When a package override exists, it's always used in place of a packed file of the same name, no matter what. This has the unfortunate side effect that if the package update actually modifies the file that you're updating in any way, those changes are masked from you without warning.
Will the full caveat/disclosure that I'm the one that wrote the package, the OverrideAudit package for Sublime can warn you when this happens by checking every time a package gets updated to see if the version of the packaged file is newer than your overridden version so that you know this is happening and can take appropriate action.
Sublime Text 2 notes
Your question is tagging Sublime Text 2 and Sublime Text 3. In the case of Sublime Text 2, the information above about needing to remove a key binding completely in order to allow the OS to see it still holds.
However as far as I'm aware Sublime Text 2 doesn't support the idea of package overrides because it always installs all packages unpacked. As such the only solution in that particular case is to modify the packaged file and keep an eye out for changes.
At this point with Sublime Text 3 officially released there are not many compelling reasons to keep using ST2. If you purchased your license for ST2 sometime mid/late 2013 or later your license should be valid for ST3.
This is particularly important in that ST2 is no longer supported and as of High Sierra when Apple removed Python 2.6, various Sublime packages will now no longer work.

How to refresh Sublime Text 3 workspace color schemes?

When you save a project, Sublime Text will create a .sublime-workspace file. In this file, there is an array of buffers, and for each buffer there is a color_scheme property. This is set to whatever color scheme was chosen when the buffers and workspace were created.
I recently changed my theme and color scheme in my user settings file. How can I refresh all of my project's workspaces so that way it uses my new color_scheme provided in my user preference file without needed to edit each project's workspace file one-by-one?
Expanding on the answer given by Tot you can do this for all views in all windows that are open by using a nested list comprehension (remember this is Python so we can be pretty flexible):
[ v.settings().erase("color_scheme") for views in [ w.views() for w in sublime.windows() ] for v in views ]
This way you don't have to run the command in each tab individually.
The only way I found to reset tabs to user's chosen color scheme is to enter this in the console :
view.settings().erase("color_scheme")
This will reset the color scheme of the selected tab - unfortunately you'll have to do it for each tab. But it's still quicker than closing and reopening the tab.
I only have this issue with Sublime Text 3 on Mac OS X.
Source : https://www.sublimetext.com/forum/viewtopic.php?f=3&t=19310
P.S. : If you've just updated your color scheme file, you'll sometimes have to execute this command twice. Just type the up arrow in the console to write the last command again.
Windows 10 AppData-related Solution
Please make sure that you are in a similar situation as me before trying this solution (see below). Steps:
Note the language and package that the Error loading colour scheme reports (my case was: markdown and MarkdownEditing).
Go to your AppData directory (type %AppData% in file explorer address bar).
Open directory Sublime Text 3, or whatever your version is.
Open the .sublime-settings file that matches the language from step 1.
Remove any lines that refer to the package you noted from step 1.
Remember that this file should be a properly formatted JSON file when you remove lines manually. Save this file and restart Sublime Text.
Background
I've decided to post here in case some of the python script solutions didn't work for you and your situation is similar to mine. I'm using GitHub to sync my Sublime Text AppData (Windows 10), in order to keep my workflow settings the same on multiple machines. Recently, I noticed that when I uninstalled a certain package on one of my machines, I accidentally merged some configuration files for that non-existent package on my other machine. This resulted in a persistent Error loading colour scheme, in particular for me when changing syntax to markdown (the package was MarkdownEditing for reference).

How to remove notations in xcode appearing after filename?

I'm getting text like A,M,? etc after filename in Xcode. This seems to appear after setting up project on SVN. How to remove this one?
They are source control markers
A = added
M = modified
? = not added
If you dont want them there dont create your project with source control on. Make sure the circled box isnt ticked.
Creating anything other than a discardable project without source control is going to make you sad one day.
Learn about Source Control and use it if you are serious about development.
These notations basically tells you about project's files current condition at SVN or server that is hosting your code repository and your local repository. For instance, if you add a new file/class/anything you will see 'A', if you do changes in a file you will see 'M'.
If you still want to remove these words in XCode go to :
file > source control > commit
a window will appear that shows the the changes you have done in files & press commit button. After that these words will be removed.
But wait, before doing anything read about "source control".
Atleast read about these things:
Revisions
Commits
Updates

Borland Starteam: How to re -check-in a file from a frozen labeled configuration to current configuration with history

Borland Starteam: How to re -check-in a file from a frozen labeled configuration to current configuration with history?
You should be able to go to that frozen labeled configuration (View->Select Configuration->Labeled Configuration) and pick that label. Then what you are seeing should be files as of that label. You could then checkout the file you wanted from that label.
Then go back to the current configuration (View->Select Configuration->Current Configuration) and check-in your file (you will have to do a Forced Check-In since it will show as Out of Date status). In the check-in comments you may want to mention that you pulled that file forwards from that label.
You will not lose any of the history between the label and your check-in.
If the file does not exist in the current configuration, you can share the file from the labeled config to current - just have the view open in two separate windows. This will retain all of the version history.
There is a hiccup in that it will not allow you to share the file into the same folder as it originally existed (as of 2008R2). Just share the file into a different folder then move it.
All history is retained. Note that the new instance is a share, so you may want to check the reference tab before branching to make sure it will do what you expect.
Based on GanYo's comment to the question -
The problem is not the fact that the file is sitting in a frozen label -
the real problem is that the file was deleted.
You cannot "bring back to life" a file that was deleted,
but you can "go back in time" to see it's history (as mentioned by Dougman).
The only solution supported by Borland is this:
Set-Configuration to a time (or label) just before the file was deleted
(this should allow you access to the latest version of the file with all its history).
Check-out all the different revisions of the file, one-by-one, keeping them in unique names
until you have the complete list of revisions.
(best is to append the revision-number to the name of each revision to the file being saved locally)
Set-Configuration back to 'Current'.
Check-in the complete history of the file, starting with the oldest version of the file,
and going forward, until you have imported all the file-revisions in the correct sequence.
(you have to rename each revision of the file to its original name before you check it in, of course)
Having said that, you really need to think if this is worth it, because:
This "restore" process does not bring back:
the comments of each revision
the CR-links that were attached to each revision
the Lables that were attached to each revision
The file's history was there all along, and is available via 'Set Configuration' - why duplicate it?
Bottom line:
It is probably best just to restore the latest version of the file,
mentioning in the comment that it was deleted accidentally and that its history can be reviewed
by doing 'Set Configuration' to ...

Trim trailing spaces in Xcode

Is there a way to force Xcode to trim trailing whitespaces when I save file?
I'm using version 3.1.3 if that matters.
Starting from Xcode 4.4 whitespaces will be trimmed automatically by default, unless the line is all whitespace. You can also activate Including whitespace-only lines to fix this, which is not active by default.
Go to Xcode > Preferences > Text Editing > While editing
I'm using the Google Toolbox For Mac Xcode Plugin, it adds a "Correct whitespace on save" parameter that trim trailing whitespace on save. I missed that a lot from emacs.
You can create a script and bind it to a keyboard shortcut:
Select Scripts Menu > Edit User Scripts...
Press the + button and select New Shell Script
Give it a name like "Strip Trailing Spaces", and give it a shortcut like ⌃⇧R.
Set Input to "Selection" and Output to "Replace Selection"
Then enter the following script:
#!/usr/bin/perl
while (<>) {
s/\s+$//;
print "$_\n";
}
I find using the new Automatically trim trailing whitespace -> Including whitespace-only lines as suggested by #MartinStolz works well while editing but I sometimes need to do Cmd + a -> Ctrl + i and save the file multiple times with the file in focus when I'm not editing.
In case you want to clean a whole project (excluding .md files) without using scripts, you can also do a Find & Replace -> Regular Expression. Since this technique removes trailing space and tabs for documentation/comments as well, you can also try a negative lookahead for blacklisted characters to filter out single-line comments.
Find all trailing whitespace:
[\t ]+$
Find trailing whitespace without touching single-line comments:
^(?!.*\\\\)[\t ]+$
Replace:
<nothing>
So linting can also be done without swiftlint autocorrect or similar third party solutions.
For Xcode 8, I installed the swimat Xcode plug-in, for formatting Swift code, which removed all trailing spaces and whitespace-only lines.
Installation Methods
Install via homebrew-cask:
brew cask install swimat
Download the App directly:
https://github.com/Jintin/Swimat/releases/download/v1.3.5/Swimat.zip
Clone extension branch and archive to Mac App.
Usage
Once installed, you can run Swimat in Xcode via Editor -> Swimat -> Format.
This is not possible in Xcode 3.2
Edit:
I answered this question so briefly because there's no way to do this properly.
Of course, since it's software, you can do anything: Starting with Input Manager hacks or other ways of code injection to system wide keyboard interception, you can alter your local system to do anything anytime. You could set up an Applescript folder action (arrgh) or use a launch demon and the FSEvents facility to watch your source code files.
You can also add a couple of scripts to Xcode (user scripts in the menu, script phases in targets, custom Actions in the organizer, there's even the very unknown possibility a startup script), but all these solutions are flawed, since it involves the user or custom setup on the user's machine.
I'm not aware of a solution which simply works after checking out a project from SCM. I believe that there's need for this and similar customization scripts, so I filed a bug (radar 7203835, "Feature: more user script triggers in Xcode workflow"). I did not receive any feedback yet.
Here's the full text of the radar entry:
It would be useful to have more places to run scripts in Xcode.
Examples:
Pre build scripts
Pre build scripts could be used to build prerequisites like *.xcconfig files or config.h headers. This is not possible with a "Run Script Build phases", since dependency tracking takes place before any build phase is triggered.
Post build scripts
Similar to above, but running after the build
finished (including code signing etc).
Useful for additional packaging,
validity checking etc.
Pre/Post SCM Commit scripts.
To check project integrity.
Pre/Post File Save Script.
To check/alter a file before saving. E.g. run cody beautifiers
Custom project actions.
I'm aware of the organizer's ability to define arbitrary actions. But this is a per user feature (not part of the project). I'd like to define actions like build or clean that show up in the build menu and that are part of a project.
See here for Xcode4: http://www.wezm.net/technical/2011/08/strip-trailing-whitespace-xcode-4/
Cool, Google toolbox for Mac now adds a "trim whitespace" option for Xcode4.
http://code.google.com/p/google-toolbox-for-mac/downloads/list
Thanks you, Google!
The best and easy way without using scripts, hacks and much more.
Just go to Find And Replace and press alt/option + space and press space button in the replace bar and then click on replace all.
It will replace the whitespaces with normal spaces and the warning/ error will be gone !!
One way not perfect but it's working is to use Find and Replace.
Find double space and replace with nothing.
And after that Command+A and Control+I.
As I said is not perfect maybe you need to fix something, but for me worked.

Resources