Sublime Forum

2 new plugins: Bound Keys and Find Selected

#1

Only discovered ST a couple of weeks ago and I’m already in love. Previously I used ultraedit which is a great editor but ST has all that it does, is just as fast and is so much more extensible and pretty.

The thing I missed the most was being able to press F3 to search for whatever text was selected. If nothing is selected it searches for whatever you last searched for in the find panel. I’ve put together a really simple plugin to match this functionality and it’s up here: github.com/CodeEffect/FindSelected My python is a little rusty as it’s been a while so your comments /feature requests / bugs / suggestions would be very much appreciated. Here’s the bumf:

[quote]Two additional search methods are available:

find_selected_next - If some text is selected then it is searched for and the cursor highlights the next occurrence of the text. If no text is selected then depending on the passed argument we either search for the last Find search term (“last_search”) or the clipboard (“clipboard”).

find_selected_previous - As above but we search backwards

This package doesn’t really add much in the way of new functionality, it just makes available existing functionality under one method or keypress. Previously to search for the last search term you would call the “find_next” method or to search for selected text you would call the “find_under” method. Now you can just call the “find_selected” method and depending on whether text is selected or not the appropriate built-in method is called for you. It’s a somewhat trivial change in behaviour but one I found that I missed greatly when migrating from UltraEdit. There is also the added ability to search for whatever is on the clipboard in one keypress.[/quote]

I can’t believe that the second plugin doesn’t exist in one form or another as it seemed like such an obvious requirement but I was unable to find anything after a quick google search (cue links to 10 other similar plugins :smile:). Bound Keys github.com/CodeEffect/BoundKeys lists all key combinations from installed plugins (that aren’t ignored) from your platform. It presents the data in a sort of table and lists key combination, command, arguments and clashes with other key combinations including whether or not it’s been overridden and if so by which file. Again, any feedback / comments etc is very much appreciated. My next task will be to give it a bit of colour so if anyone has suggestions on the best route to accomplish that I’d be grateful for any advice.

The bumf again:

[quote]A plugin to list the contents of keymap files and indicate any clashes / overrides. Sublime Text 2 (sublimetext.com/2).

The plugin lists the contents of all installed sublime-keymap files from active plugins along with the user and default files. The last column of the table lists clashes of key combinations whilst he prescence of asterisks indicate that the combination is overridden by the other file.

The presented columns of data are: Key combination, command called, arguments to command and clashes.[/quote]

Both only tested on ST2 in windows but when I get round to sorting my broken RAID I’ll be able to test on nix too.

I really enjoyed putting those two together so if anyone has any ideas on a plugin they’d like built either post here or bung me a PM. If I’ve got the time and it’s not too much of a beast I’ll (probably!) have a go at putting it together.

Thanks for such a great app, will be buying a license shortly :smile:

0 Likes

#2

As for BoundKeys, I wrote FindKeyConflicts to do something similar. :smile: I think many users just do “sublime.log_commands(True)” when something isn’t behaving properly, then track it down that way. To color it, you would need to define your own color scheme, then apply it to the generated output file. I’ll take a closer look at yours when I have some extra time. Welcome to the ST community.

0 Likes

#3

Another one added: github.com/CodeEffect/AlarmClock

Pretty much does what it says on the tin:

[quote]Need to be able to get your head down and bury yourself in your code without missing that important meeting? This really simple plugin allows you to quickly set alarms either a number of hours / minutes into the future or at a particular time. Includes that all important snooze functionality in case you’re not quite done yet.

At present the audible beep only works on windows. Beeping for linux / mac will be added shortly.[/quote]

Not quite working fully in ST2 at the moment (I think it’s only the beep but I’ve not yet had the time to look into it).

Also, as noted the beep doesn’t work in anything other than windows on ST3. I’ll get Linux up and running shortly but if anyone has suggestions on how best to beep on a mac I’d love to hear. I suspect I may have to call an external program but that’s a bit shitty so I’d really rather not.

0 Likes

#4

What about just print(’\a’)? Works over here.

0 Likes

#5

Was the first thing I tried but it didn’t work from inside ST (or the console), it just printed a bell character.

Could I ask what platform you’re using please - and whether you’ve tried it in the console / as a plugin please? If it works on mac / *nix then jobs a good 'un :smiley:

0 Likes

#6

Hah! no, it doesn’t work… I only checked in the terminal, not in Sublime Text’s console.

0 Likes

#7

On OS X you can do this:
from os import system
system(‘say time up!’)

0 Likes

#8

What about instead of getting the beep out of python directly, you just call the system?

For OSX (not a hardware beep, but still sufficient)

from subprocess import call


call("osascript",  "-e",  "beep 1"])

Also, just for kicks and giggles on mac, you could make it talk:

[code]from subprocess import call

call(“say”, “i’m afraid i can’t do that dave”])
[/code]

Both work from within sublime on ST3 at least, but I imagine they would work on ST2 as well.

I imagine you could take a similar approach on linux. Call the command line from python to perform an operation to create your alarm instead of relying on python to do it for you.

Anyways, just some ideas.

EDIT: Looks like adzenith had the same idea.

0 Likes

#9

I smell some config settings :smiley: Cheers guys, I’ll get what I can test working then post for mac beta testers :smile:

0 Likes

#10

Having a weird issue on ST2 with threads. I’ve got a solution to make beeps on windows on ST2 using a batch file and a vbscript which all works kind of nicely. The issue is that I launch a thread to beep away in the background then fire up an ok_cancel_dialog to allow the user to snooze or turn off the alarm. This worked fine on ST3 but on ST2 the ok_cancel_dialog seems to halt execution of all code including the thread that I’ve just fired off.

So this:

# Code to beep fired off in its own thread
def beep(arg, stop_event):
    os.chdir(os.path.dirname(os.path.abspath(__file__)))
    while(not stop_event.is_set()):
        subprocess.call("wscript ./hidebat.vbs")
        stop_event.wait(0.9)

# Code to fire off the thread
    self.t_stop = threading.Event()
    t = threading.Thread(target=beep, args=(1, self.t_stop))
    t.start()
    if sublime.ok_cancel_dialog("Alarm time up", "Snooze"):

Just beeps once and stops. When I click OK or cancel it sometimes beeps again then stops (as it should do). If I remove the ok_cancel_dialog() it beeps continually as you might expect it would always do. I’ve tried a sleep before I open my ok_cancel_dialog in case it needed a bit of a run up before the thread would start working but that just means it beeps a bit more to start but as soon as the dialog opens it stops as before. I’ve stuck in some basic debugging with print statements and they support the above: opening the dialog halts execution of all code.

I’m scratching my head on this one now, am I doing something stupid? What am I missing?

0 Likes

#11

One option is to use the input panel as a confirmation dialog. Insert “Y” or “N”. I have done this myself in my HexViewer plugin (before sublime ever added okay_cancel dialogs; you could also use the quick panel and popup up the snooze option in the list or cancel). Or you could just allow a command to snooze it. The user can bind the snooze command to a shortcut or access it from the menu or command palette. In the latter case of just having a snooze command, there would be no dialog, the user would just need to execute the snooze command (this would be in the documentation).

0 Likes

#12

I assume from what you’ve said that it’s expected behaviour?

That’s a shame, the OK / Cancel is perfect as it flashes the task bar if you’ve not got ST in view and it’s impossible to ignore (accidentally or otherwise) if you have it in view. Never mind, it’ll have to be an option for ST2 users

0 Likes

#13

Keep in mind that the core code of ST3 got a big overhaul in relation to synchronous and asynchronous stuff. That is some of the “improvements” to ST3.

0 Likes

#14

Updated with a tiny local wav file for the alarm now as it was just the easiest way all around + everything works as it should.

It uses afplay on OSX, aplay on Linux (requires ALSA) and a tiny (4KB) exe on windows (source code included) to play the alarm file. If anyone is on OSX and can test I’d be really grateful: github.com/CodeEffect/AlarmClock :smiley:

Also, if this setup doesn’t work for anyone (no alsa, OSX older than 10.5 etc etc) could they let me know and if at all possible advise an alternative please?

0 Likes

#15

Another one added: github.com/CodeEffect/FooLime

More of a hobby project this one, something for me to tinker with. Just putting it out there in case anyone else finds it of use.

EDIT: Still looking for someone to test the OSX alarm clock if you’ve got 5 mins and a mac :smiley:

0 Likes