Hi,
I'm developing a new bundle for a scripting language. For the "Run" command I'd like to make usage of TM's TextMate::Executor library. Fine.
But I was confronted with two subjects for a discussion:
1) TextMate.save_if_untitled
In order to use TextMate::Executor one should execute "TextMate.save_if_untitled('foo')" in beforehand. But I'd like to allow to the user that s/he runs either the entire document or only a selection. With the current implementation this doesn't work, so I suggest the following change (adding of the first 6 lines of code and a new argument):
save_current_document.rb line: 33ff
def save_if_untitled(temp_ext='tmp', ignore_selection=true) if not ignore_selection and not ENV['TM_SELECTED_TEXT'].nil? ENV['TM_FILEPATH'] = nil if not ENV['TM_SELECTED_TEXT'].nil? ENV['TM_DISPLAYNAME'] += ' (Selection)' end end return unless ENV['TM_FILEPATH'].nil?
ENV['TM_FILEPATH'] = TextMate::IO.tempfile(temp_ext).path ENV['TM_FILENAME'] = File.basename(ENV['TM_FILEPATH']) ENV['TM_FILE_IS_UNTITLED'] = 'true'
begin ......
This approach does't break the default behaviour. Only if the developer would like to add that functionality s/he has only set the second argument to "false". By adding "(Selection)" or whatever to TM_DISPLAYNAME the user will be notified additionally.
2) TextMate::Executor.run -> version
The interpreter I'm working with is an "hybrid". If you start it without arguments or with arguments which can't be interpreted as a file name the interpreter starts in the GUI mode, i.e. a real application with windows etc. pops up. Otherwise, if you pass as first argument a valid file path plus optional arguments, the interpreter works like Perl, Python, etc. in a command line mode.
The current TextMate::Executor.run implementation has a nice feature, you can get the current version number from the current installed interpreter or compiler as default BUT you are NOT able to avoid it.
In my case the interpreter doesn't catch these kind of querying, in other words I can set the ":version_*"-options to whatever the GUI is popping up and tells me stories about errors. Finally I ended up to write a special script which returns the version number and I call it via:
:version_args => ENV["TM_BUNDLE_SUPPORT"] + "/bin/version.praat"
but I believe one could solve this kind of problem quite easily, namely if the developer sets explicitly ":version_args => nil" the version querying won't be executed. To achieve that one has to change one single line:
executor.rb line: 99
version = (not options[:version_args].nil?) ? parse_version(args[0], options) : ''
Did I miss something?
Kind regards, Hans
On 29 Sep 2014, at 18:07, Hans-Jörg Bibiko wrote:
[…] In order to use TextMate::Executor one should execute "TextMate.save_if_untitled('foo')" in beforehand. But I'd like to allow to the user that s/he runs either the entire document or only a selection […]
I don’t understand your proposed semantics as we go from two to four cases:
1. Document is untitled, we have a selection 2. Document is untitled, no selection 3. Document has filename, we have a selection 4. Document has filename, no selection
For example for #3, would you change TM_FILENAME to a temporary file and then save selection to this temporary file? If so, I think this is better handled by your command, e.g.:
if ENV.has_key?('TM_SELECTION') # setup temporary TM_FILENAME and save selection else TextMate.save_if_untitled end
- TextMate::Executor.run -> version
[…] I believe one could solve this kind of problem quite easily, namely if the developer sets explicitly ":version_args => nil" the version querying won't be executed. To achieve that one has to change one single line:
executor.rb line: 99
version = (not options[:version_args].nil?) ?
parse_version(args[0], options) : ''
This makes sense, and I’ve run into this myself (inability to disable the version check for “interpreters” where it didn’t really make sense).
Will you submit a PR for this? If so, I’d suggest avoiding the “not” operator.