Home Download Buy Blog Forum Support

I want to rewrite incremental find - is that possible?

I want to rewrite incremental find - is that possible?

Postby canoeberry on Mon Feb 10, 2014 4:58 pm

I have spent a weekend hacking Sublime to give me basic emacs functionality. I know other packages already exist but they didn't really do things quite right, and in many ways Emacs got many of the basics just absolutely right. It was a successful weekend of hacking and I am still learning.

I like the incremental find that comes with Sublime, but it is missing a couple of features. The main ones for me are:

    * if I type ctrl+s immediately after the first one, it should use the same search string that I ended with last time
    * if I type ctrl+w it should append the text in front of the cursor to the current search string
    * if I search for a MixedCase item, the search automatically becomes case sensitive, otherwise case insensitive
    * when it's done I should be able to get a notification so I can set the mark at the original location
    * I'd love a way to say "find the rest in this direction without wrapping" so I can then go all multi-cursor on the ones I've selected
I realize these are all personal taste so I am happy to implement it myself, but I either need to start from scratch (is that possible?) or I need a way to get hooks into what is happening in the incremental_find panel. I am unclear on how to do either.

Here are a few observations and comments about what I think I have learned so far:

    * I think it's a regular view inside the incremental_find panel. My text command event listener seems to be invoked when I run commands there. That is excellent! At first I thought the panel was a complete special case.
    * If I put a "context" in my key binding such that it's only active if the incremental_find panel is showing and has focus, I don't seem to be getting my function called. Should that work?
    * If that does work, would the view argument be the view for the incremental find or the active view of the active window?
    * Is there a way to capture all key strokes? I want to be able to terminate my incremental search if I type some other command, like Control-A.
canoeberry
 
Posts: 10
Joined: Tue Feb 04, 2014 11:35 pm

Re: I want to rewrite incremental find - is that possible?

Postby tito on Mon Feb 10, 2014 11:36 pm

Looks very possible.

* If I put a "context" in my key binding such that it's only active if the incremental_find panel is showing and has focus, I don't seem to be getting my function called. Should that work?
Looks like.. should work, if "operand" accepts the name of your panel.

{ "keys": ["alt+enter"], "command": "find_all", "args": {"close_panel": true},
"context": [{"key": "panel", "operand": "incremental_find"}, {"key": "panel_has_focus"}]
},


* If that does work, would the view argument be the view for the incremental find or the active view of the active window?

show_input_panel(name) returns a view, you can keep a reference to the view, and also keep track if the view is shown or not, There is also an on_change listener.

* Is there a way to capture all key strokes? I want to be able to terminate my incremental search if I type some other command, like Control-A.
Probably with keybindings.

you can log inputs and commands to a console, See http://www.sublimetext.com/docs/3/api_reference.html

You need to hack hard and is complicated without testing, because some things that are supposed to work, in some very special conditions, does not work. So I can't tell with confidence.
Give APIs, let the community build the rest!
https://github.com/titoBouzout
tito
 
Posts: 855
Joined: Thu Sep 29, 2011 2:27 pm
Location: Montevideo, Uruguay

Re: I want to rewrite incremental find - is that possible?

Postby canoeberry on Sun Feb 16, 2014 11:34 pm

Ho ho! It worked! My problem with the key bindings was - oh my - specifying "content" instead of "context" in the key binding.

I have managed to get emacs-style incremental search working. What this means is:

  • As you type characters the search string grows and all the matches are highlighted.
  • If you type the search key (Control-s) again, you move to the next match.
  • If you type backspace, you go back exactly one state. That might be going back to the previous match OR going back to a search string with one less character in it.
  • If you type Control-W characters from buffer are appended to the search string.
  • If you find yourself searching for something that doesn't exist, you can type Control-G to go back to the last state your search was succeeding.
  • If you type Control-G and your search is working, you will abort the search and go back to where you started, panel hidden.
  • If you type Control-S to start a search and then type it again immediately, it uses the last search string you used.
  • If you click the mouse in the window, the search is automatically stopped.
  • And because this is part of a larger project of mine, when you are done with your search the mark is set to where you started.

I've made the following sublime text enhancements:

  • Like ST when you start a search one item is highlighted with a solid background and other matches are outlined.
  • If you type Control-S again it moves that highlighted item to the next item. (This is the same.)
  • If you press CMD-D while searching, however, it adds the current item to the set of cursors, and moves to the next item and highlights it. By "move to the next item" I mean moves forward or backward depending on the direction you were going in when you pressed CMD-D.
  • This means you can add to your resulting cursors with CMD-D or you can SKIP the current item by just searching again with Control-S. This allows you to have non-contiguous matches in your multi-cursor when you're done.
  • If you accidentally go too far and add something you don't want, you can press backspace, because backspaces restores you to your previous state, including your selected cursors.
  • When you're done you press Return and your cursors are waiting for you!
canoeberry
 
Posts: 10
Joined: Tue Feb 04, 2014 11:35 pm

Re: I want to rewrite incremental find - is that possible?

Postby ol_ol_3388 on Sat Mar 08, 2014 12:37 am

I'm very interested in what you did. Could you please share it ?
ol_ol_3388
 
Posts: 18
Joined: Mon Feb 04, 2013 3:29 pm


Return to Plugin Development

Who is online

Users browsing this forum: Google [Bot] and 11 guests