Skip to content

Ability to use "Documentation for Word" on selected text #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tiennou opened this issue Feb 11, 2014 · 5 comments
Closed

Ability to use "Documentation for Word" on selected text #45

tiennou opened this issue Feb 11, 2014 · 5 comments

Comments

@tiennou
Copy link

tiennou commented Feb 11, 2014

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 ?

@sorbits
Copy link
Member

sorbits commented Feb 11, 2014

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

@tiennou
Copy link
Author

tiennou commented Feb 11, 2014

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 ;-).

@sorbits
Copy link
Member

sorbits commented Feb 11, 2014

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)

@tiennou
Copy link
Author

tiennou commented Jun 29, 2015

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

@tiennou tiennou closed this as completed Jun 29, 2015
@tiennou
Copy link
Author

tiennou commented Jun 29, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants