I want all changes in Sublime Text Editor 3 show in real time on a website. I would like to write a plugin that sends only the changes to an API.
Can the EventListener on_modified I somehow tell what has changed? With view.change_count () I will not get only the number of the change.
import sublime, sublime_plugin
class KeyBindingListener(sublime_plugin.EventListener):
def on_modified_async(self, view):
print("The on_modified event fired!"+str(view.change_count()));
Related
I am trying to write a Python script that accesses a webpage (http://www.yeastgenome.org/locus/S000001142/overview) and downloads a (DNA sequence, fasta) file. The file is automatically downloaded once one clicks on a dropdown menu.
This is the dropdown menu:
Download (.fsa)
and one of the options would for example be:
Genomic DNA +/- 1kb
Could someone please point me in the right direction, how to do this?
The Selenium modules?
Thanks a bunch!!
You basically want to navigate to the page, click on the dropdown to open it, and then click on the selection you want. You will need a couple waits... one to wait for the bottom of the page to load and show the dropdown and another short pause to wait for the dropdown to open.
from selenium.webdriver.support import expected_conditions as EC
driver.get("http://www.yeastgenome.org/locus/S000001142/overview")
wait = WebDriverWait(driver, 4)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"a.dropdown"))).click()
option = "Protein" // change to the desired option in the dropdown... must be EXACT text
wait.until(EC.element_to_be_clickable((By.XPATH,"//ul[contains(#class,'open')]/li/a[text()='" + option + "']"))).click()
I want to mimic the behavior of Chrome's ctrl+9 shortcut.
It goes to the tab of highest index.
Sublime has a command select_by_index.
Is there a way to get the max index so I can make a key binding?
I was able to make a simple sublime plugin (Tools > New Plugin...)
Packages/User/last_view.py
import sublime, sublime_plugin
class LastViewCommand(sublime_plugin.WindowCommand):
def run(self):
self.window.focus_view(self.window.views()[-1])
Packages/User/Default (OSX).sublime-keymap
[
{ "keys": ["super+9"], "command": "last_view" }
]
If you know how many tabs are open, you could use ALT-[NUM] to jump to the last open tab. [NUM] must be substituded by the Number of the last tab.
Is there a way to import all Sublime Text code snippets into PhpStorm?
Everything from switch expanding on Tab press to:
switch (variable) {
case 'value':
# code...
break;
default:
# code...
break;
}
I know you can add them manually with Live Templates but doing all of that would be an awful lot of work.
In Sublime it works along with code completion, if I start typing first 2 letters of class and code completion dialog pop-up on Tab key press it will expand to full class block with intelligent cursor positioning and I can press Tab again to switch from doc block to class name.
When I press Ctrl+Tab, Ctrl+Shift+Tab or Ctrl+W the tab I get switched to is not the one just near the one I was on (as I would like to) but to some else. When I press Ctl+N the new tab is created right near the tab I am at while I always want it to be created at the end of the tabs list. How to configure it to achieve the behaviour I desire?
To achieve the Ctrl+Tab and Ctrl+Shift+Tab behavior you can add the following lines to your sublime-keymap:
{ "keys": ["ctrl+tab"], "command": "next_view" },
{ "keys": ["ctrl+shift+tab"], "command": "prev_view" }
To open sublime-keymap:
click "Preferences"
click "Key Bindings"
You will see two settings file, select a file that named "User"
This is a visual example on how it should look.
With the default key bindings, ControlPage Up and ControlPage Down will allow you to move right and left among your open tabs, respectively, in their visual order. (The keybinding solution replicates this functionality using your preferred keys.)
Because the package installer is now included with Sublime Text, it's also straightforward to add the MoveTab extension, which adds the shortcuts ShiftControlPage Up and ShiftControlPage Down to move the current tab within that visual order.
To access the package installer in Sublime Text 3 (in Windows, anyway), type ShiftControlp, then Package Control: Install Package.
You can use a plugin to get the new file behavior you want.
import sublime_plugin
class MyNewFile(sublime_plugin.WindowCommand):
def run(self):
window = self.window
view = window.new_file()
active_group = window.active_group()
views_in_group = window.views_in_group(active_group)
window.set_view_index(view, active_group, len(views_in_group) - 1)
Save the above in Packages/User as <somename>.py. Then use the command my_new_file in your key binding for ctrl+n I wouldn't be surprised if there was aplugin to do this already, but it's pretty simple, so easier to write it yourself, than to search package control :) You can likely lose a plugin to do what you want for ctrl+w also, but you didn't describe the behavior you wanted.
I got problem with jQuery Snippet that i installed throughout package control. After installation I do not have popup with jQuery code hints and intalisance. Look at this video:
http://code.tutsplus.com/courses/perfect-workflow-in-sublime-text-2/lessons/adding-snippets-through-package-control
On 0:50 after typing . he got popup with code hints - I don't have this one. I have to type . on and then press Tab to display popup with snippet...
And yes, I'm in JavaScript file and I got default settings.
And after . he also got all jQuery functions like add or addClass. I do not have this one even if I press Ctrl+Space.
If you hit CTRL-SPACE you'll get the dropdown of available completions for what you've just typed.
http://www.sublimetext.com/docs/2/tab_completion.html
If you want the autocomplete dropdown to appear as you type then add this line to your User Preferences.sublime-settings file:
{
"auto_complete_selector": "source, text"
}
That should do what you're looking for :-)
Consider changing User Settings to the following:
{
// By default, auto complete will commit the current completion on enter.
// This setting can be used to make it complete on tab instead.
// Completing on tab is generally a superior option, as it removes
// ambiguity between committing the completion and inserting a newline.
"auto_complete_commit_on_tab": true,
// Controls if auto complete is shown when snippet fields are active.
// Only relevant if auto_complete_commit_on_tab is true.
"auto_complete_with_fields": true,
// As Richard Jordan suggested, this item
// controls what scopes auto complete will be triggered in
"auto_complete_selector": "source, text"
}
Open your User Settings by pressing Cmd+, on Mac or Ctrl+, on Windows
And if you want to fully grasp Sublime Text 2, I do recommend this course: Perfect Workflow in Sublime Text. It used to be free by the time I first posted this answer. I still recommend it anyways.
Which OS are you using? I'm guessing Windows.
The problem here seems to be that the jQuery snippets in the available plugins have <tabTrigger> attributes that start either with a $ or a ., which causes trouble.
Try the following: Find the jQuery package that contains those snippets (Under Preferences -> Browse Packages) and open the .sublime-snippet file of a snippet that doesn't work properly. The one you named in your post would be defined in the file event-on.sublime-snippet.
Find the line
<tabTrigger>.on</tabTrigger>
and remove the . as follows
<tabTrigger>on</tabTrigger>
Save and return to your .js file. Now see if the snippet shows up when you type o. This works for me.
I guess this is a bug in Sublime Text 2 for Windows (maybe Linux, too?), since it obviously works fine on OS X as we see in the video course you've linked.
There was an issue created on GitHub on this specific package and I now commented this info. I guess the only way to get this working is to have snippets that do not start with special characters.
I also filed a bug for Sublime Text on Userecho.
The creator of the video is using SublimeCodeIntel. What you see at 00:50 isn't Sublime Text 2's autocompletion popup, it's SublimeCodeIntel's import autocompletion popup:
Imports autocomplete - Shows autocomplete with the available modules/symbols in real time.
See the Github page for more information.