view.run_command("example") not working - sublimetext2

I created first plugin for sublime text 3 with name relative:
import sublime, sublime_plugin
class ExampleCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.insert(edit, 0, "Hello, World!")
Then save it to path
/pathToSublime3/Packages/relative/relative.py
Then try to test it in command window (cntrl + `):
view.run_command('example')
I expected to see Hello, World! in the beginning of current opened file, but fail. What I do wrong?

If your experience was like mine, you may have copied several super basic plugins to try to find one that worked. I think the failure of the others was affecting the Hello World one. For what it's worth, here are the things I did that seem to have worked.
I'm using ST3 on Win7, so maybe there are differences in plugin development between that and ST2.
Note that as I tried many different permutations of these, I don't exactly know which ones are the real fix. But if these get you working, then maybe you can start making incremental changes and see when it breaks.
Moved all *.py files that were my plugins into "Packages" folder. (I read many posts that said that plugin files in the "Packages\User" or "Packages\NameOfPlugin" folder should be read, but I haven't tried them yet. I put it in "Packages" to make sure that finding the files wasn't a problem.)
Restart Sublime after every change. (The docs say you don't have to, but if you have errors in your plugins, it seems that the auto-reload feature doesn't work. Which kinda makes sense. Once I got the errors out of all my plugins, the auto-reload feature started working correctly.)
A few of the simple/tutorial plugins I copied off the web (even some from sublimetext.com!) referenced/imported "sublimePlugin" which errorred on my ST3 Win7 instance. Apparently the correct library to import is "sublime_plugin". The two places this is used, in basic plugins, are 1) at the very top in the import section, as well as 2) in the class line, which I'll illustrate below...
# didn't work for me...
class ExampleCommand(sublimePlugin.TextCommand):
# DID work for me...
class ExampleCommand(sublime_plugin.TextCommand):

'Ctrl+N' create a new file, then try it again. Don't run it in the old file.

All I need is close sublime text 3 and open it again. Now Hello World works fine

The console doesn't open with Ctrl + ` For Sublime Text 2, but this example is written in the v2 documentation.
Using that command opens up a popup starting with # which is to open another file.
The console opens by doing Ctrl + F1. After that, you can write that code in there, and the text will be added into your current view (in any view, in fact).

Be sure to read the "Where to Store Plugins", I made the mistake of creating a folder (package) when the hello_world.py is simply a plugin. Also keep in mind from the documentation window commands and text commands, cause in this case since it is a text command you must execute it in the "view" that you want it to place the text (which can't be the plugin definition file that you created.
Hope that helps anyone in the future as that was a few things I came across

Related

nothing happens when I click configure build task in VSCODE saying no build task found

When I Ctrl+shift+B I get this. I click it and it goes no-where. I wait thinking my computer is thinking but nothing. Tried to create a folder .vscode and place a tasks.json in it. VScode acts like it doesn't even see it. I expect VScode to bring the menus up that I see in all the other posts when they click it. Mine just is not going anywhere when I click it. Thanks
since i am not allowed to answer for some picky reason. we shall see if this survives. To help the poor guy that spent too long looking. I created a new folder and put scripts in with no .vscode. then ctrl+shift+p searched for tasks.auto clicked on whatever auto it came up with. It built a new settings.json. I copied the tasks.json from the other folder over and was able to build. finally. found this work around here https://techoverflow.net/2020/01/24/how-to-fix-platform-io-no-tasks-to-run-found-configure-tasks/
configureBuildTask
Follow this tutorial:
https://code.visualstudio.com/docs/cpp/config-linux
I had the same issue, then followed the tutorial. Afterwards the issue was gone.

Goland showing Unresolved type (Instance, in GCE library specifically), but core/tests run fine ("invalidate and restart" solution not working here)

I'm using the GCE library in Go, along with go modules.
I'm finding that, while it happily compiles and runs unit tests, it's not resolving those types (e.g. compute.Instance) in the Goland IDE. I'm using 2020.2.
I first added this dependency by hand-coding (adding "google.golang.org/api/compute/v1" to my imports, and letting the module handler load whatever it needs). It added google.golang.org/api v0.50.0 to my go.mod file.
I've tried the old "Invalidate and Restart" approach, and it didn't do anything. I have another project where a different version of that module happens to be loaded, and it works fine on that one.
I've even tried a more nuclear version (Invalidate (no restart), close project, close IDE, delete the .idea directory, and delete the contents of ~/.cache/JetBrains). Still no dice.
FWIW my go module's version is go 1.15
You can navigate to the package sources by pressing Command/CTRL+Click on the import statement (or via External Libraries menu in Project View) and find compute-gen.go file and size limit warning. The IDE behaves as expected.
As a workaround, you can invoke Help | Edit Custom Properties... and add the following line idea.max.intellisense.filesize=8500000 (depends on the original file size), restart GoLand. Please, keep in mind that the IDE can be slow when dealing with large files even if they are not open in the editor.
You can read more about the idea.properties file here.

VS Code - How to stop it deleting whitespaces?

I am using Microsoft's VS Code to edit css, html and ts files that are shared by my team on a VSTS Git repo. However, my VS Code keeps removing empty/whitespaces that my colleagues added when I save any change (Image below) and this screws up the whole Git Diff part, as almost every single line of code shows as a diff.
I tried to disable every single config setup but nothings works:
At the end, what was causing my problem was the extension: EditorConfig for VS Code
This plugin attempts to override user/workspace settings with settings
found in .editorconfig files. No additional or vscode-specific files
are required. As with any EditorConfig plugin, if root=true is not
specified, EditorConfig will continue to look for an .editorconfig
file outside of the project.
I believe, it was overriding the options I selected inside of VS Code (such as files.trimTrailingWhitespace: false). So, no setup change I was making was actually being applied.
It seems you have trailing whitespace enabled in User Preferences too.
I'd suggest opening your configuration file of VSCode using
CtrlShiftP or
CmdShiftP in Mac and then go to Open User Settings.
I'm sure the next line is around there somewhere, delete it or change it to false.
files.trimTrailingWhitespace": true
In my case, the JS-CSS-HTML Formatter extension from lonefy
caused the problem.
Editor › Comments: Ignore Empty Lines
——>choose :false

How to make a buffer have a read-only in Sublime Text 2

This is not about those files that have their read-only flag set at the OS level, but about every file that users don't intend to modify.
I want Sublime Text to ignore any changes and prevent saving anything to such files. One example for this scenario is when the user is reading source code that shouldn't be altered in anyway.
"Just be really careful, and don't press any buttons" is undoubtedly a good advice, but if I were to "accidentally" delete that octothorpe in front of a comment, or add new lines to a file that is sensitive to such things (some config files in Linux) and then accidently hit save....
I found "toggle-readonly" at GitHub, but it is actually toggling the file permissions ("Read Only", "Write"), which is not quite what I wanted.
Yes, this is possible, but you'll have to write a plugin (which actually isn't that hard, especially if you know Python). The API call is view.set_read_only(flag) in the sublime module, where Flag is a boolean. Here's a quick example which checks if a newly-opened file has a certain suffix, and if so sets it to read-only.
import sublime
import sublime_plugin
class MakeViewReadOnlyCommand(sublime_plugin.TextCommand):
def run(self, edit):
if self.view.file_name().endswith(".cfg"):
self.view.set_read_only(True)
class ConfigFileListener(sublime_plugin.EventListener):
def on_load(self, view):
view.run_command("make_view_read_only")
Open a new file with Python syntax, copy the code into it, alter it as needed, then save it in your Packages/User directory as make_view_read_only.py. Restart Sublime to load it, and you should be all set. To test if a certain view is read-only, open the console and enter
view.is_read_only()
The plugin "Toggle the View Read-Only" will do it. It basically does what MattDMo said: when you set the view as read-only, the file can still be changed by another program (or another user), and Sublime Text will pick up those changes. It also has the context menu item you asked for. I like the "Readonly" indicator in status bar.
I didn't test it on Sublime Text 2, but in Sublime Text 3 it works great, and it claims to work on Sublime Text 2 as well.

Set syntax for a specific file name in Sublime Text 2/3

I have a program that uses a file called user.cfg to get its user defined configuration settings. The odd thing is that they chose the syntax for this file to be Tcl (it's not odd that it is Tcl, it's odd they chose the .cfg extension instead of .tcl). So, when I open this file in Sublime Text, it doesn't know what syntax highlighting scheme to choose.
What I would like to do is set the syntax highlighting for user.cfg to Tcl, but not all .cfg files to Tcl.
I have seen this question which is very similar to mine, except in that case the special file name had no extension so Sublime Text knew to assign Ruby highlighting to only that one file. Unfortunately, I have an extension so the solution given there will not work for me.
Is there any known way to get Sublime Text base a highlighting scheme on the full filename?
Take a look at the ApplySyntax plugin.
The previous answer is completely true; however, I thought it would be better to have it here all in one place rather than going on another webpage to find the list of procedure to apply it
Sublime text 3
This is found here
Ensure Package Control is installed. Instructions are found here.
In Sublime Text, press Ctrl+Shift+P (Win, Linux) or Cmd+Shift+P (macOS) to bring up the quick panel and start typing Package Control: Install Package.
Select the command and it will show a list of installable plugins.
Start typing ApplySyntax; when you see it, select it.
Restart to be sure everything is loaded proper.
Enjoy!