textmate/php.tmbundle

Ability to use "Documentation for Word" on selected text

tiennou opened this issue · 5 comments

I usually select functions instead of simply placing the caret inside of them. Since TM_CURRENT_WORD is empty when I do that, I have to drop out of my selection for it to work.

Would it be doable to use the selected text as well as the current word ?

In the command you can put something like this at the top:

 : $term=${TM_SELECTED_TEXT:-$TM_CURRENT_WORD}

Then throughout the command use $term instead of $TM_CURRENT_WORD.

You’re most welcome to submit a pull request for such change, and I
wouldn’t blame you if you want to cleanup the command, it looks a bit
messy…

On 11 Feb 2014, at 20:04, Etienne Samson wrote:

I usually select functions instead of simply placing the caret inside
of them. Since TM_CURRENT_WORD is empty when I do that, I have to drop
out of my selection for it to work.

Would it be doable to use the selected text as well as the current
word ?


Reply to this email directly or view it on GitHub:
#45

Thanks, that works nicely. I'll do a PR tonight after a bunch of testing.

For the cleanup, unless you don't mind me rewriting everything in Ruby, I'm not sure my bash skills are up to the task ;-).

No-one will object against converting the script to ruby.

If you are actually up for it, here’s something copied from the
Objective-C lookup command:

require "#{ENV['TM_SUPPORT_PATH']}/lib/exit_codes"
require "#{ENV['TM_SUPPORT_PATH']}/lib/ui"
⋮
query = ENV['TM_SELECTED_TEXT'] || ENV['TM_CURRENT_WORD']
query = $& if query.to_s =~ /\w*/

if query.to_s.empty?
    query = %x{ /usr/bin/pbpaste -pboard find }
    query = $& if query =~ /\w+/
    query = TextMate::UI.request_string :title => "Documentation Search", 

:default => query, :prompt => "Search documentation for word"
TextMate.exit_discard if query.nil?
end

What that does is to bring up a dialog if no word is found via the
selection/current-word environment variables. The default value in that
dialog is the content of the find clipboard (if the content is a word).

On 11 Feb 2014, at 20:50, Etienne Samson wrote:

Thanks, that works nicely. I'll do a PR tonight after a bunch of
testing.

For the cleanup, unless you don't mind me rewriting everything in
Ruby, I'm not sure my bash skills are up to the task ;-).


Reply to this email directly or view it on GitHub:
#45 (comment)

Closing because it works with selections now. Apologies for not tackling the rewrite though.

Just noticed it works because I have a delta. PR incoming ;-).