testup-2 icon indicating copy to clipboard operation
testup-2 copied to clipboard

TextWrangler as Editor on mac

Open driven opened this issue 10 years ago • 17 comments

To open the linked error file on a line number, requires the TW bin tool 'edit'. man edit in Terminal shows the options, I used '--separate-windows' as it seems to work best for me.

In conjunction with changing the default editor in testup 'Preferences' to '/Applications/TextWrangler.app'

I edited 'editor.rb' to use TW as shown...

  def self.open_file(file, line = 0)
    editor = self.application
    if editor =~ /TextWrangler/
      command = %[edit --separate-windows "#{file}:#{line}"]
    else
      arguments = self.arguments
      arguments.gsub!('{FILE}', file)
      arguments.gsub!('{LINE}', line)
      command = %["#{editor}" #{arguments}]
    end
    system(command)
  end

for some reason #{arguments} failed to expand so I used "#{file}:#{line}".

john

driven avatar Oct 07 '14 10:10 driven

Do you have a reference to the docs for TextWrangler on how command line arguments are invoked for this application?

thomthom avatar Oct 07 '14 10:10 thomthom

So specifying edit --separate-windows as the editor in TestUp preferences doesn't work? I don't see any reason for why #{arguments} should fail - unless you didn't have the correct formatting in the TestUp preferences. Can we see a screenshot of what you entered into the Preferences dialog?

thomthom avatar Oct 07 '14 10:10 thomthom

reference to the docs is man edit, or I can attach a PDF made using pman [a useful bin script]

driven avatar Oct 07 '14 11:10 driven

specifying edit --separate-windows returns

"edit --separatewindows" "/Users/johns_iMac/Library/Application Support/SketchUp 2015/SketchUp/Plugins/testup/tests/TestUp/TC_TestErrors.rb:32"

which won't open because of the quotes, I used

2014-10-07 11 54 00 am

driven avatar Oct 07 '14 11:10 driven

this is expanding now... must have cocked it up last night

  def self.open_file(file, line = 0)
    editor = self.application
      arguments = self.arguments
      arguments.gsub!('{FILE}', file)
      arguments.gsub!('{LINE}', line)
    if editor =~ /TextWrangler/
      command = %[edit --separate-windows #{arguments}]
    else
      command = %["#{editor}" #{arguments}]
    end
    puts command
  system(command)
  end

driven avatar Oct 07 '14 11:10 driven

So if you hard coded edit --separate-windows in the RB file, why not just type in edit --separate-windows in the Application text box in Preferences?

thomthom avatar Oct 07 '14 11:10 thomthom

(P.S. it's easier to read chunks of code if you mark them up as code blocks)

thomthom avatar Oct 07 '14 11:10 thomthom

why not just type in edit --separate-windows

it returns

"edit --separate-windows"

which won't run due to the quotes...

driven avatar Oct 07 '14 11:10 driven

Ah, so maybe the quotes needs to be specified in the Preference dialog so there is enough flexibility.

thomthom avatar Oct 07 '14 11:10 thomthom

It less obscure to use the app name in Preferences and hardcode conditionals.

A lot of people use TextWrangler, but never unix tools like 'edit'

driven avatar Oct 07 '14 11:10 driven

I have been thinking of a dropdown list of editor names where the command lines has been set up in advance.

thomthom avatar Oct 07 '14 12:10 thomthom

the default on the mac is really

  system(open "`#{file}")

that will open the file depending on it's extension, in whichever app the user normally uses, if you prepend that with -a, it opens in a chosen App, so

  system(open -a "#{application}" "`#{file}")

if you want to open at the line number then you need the 'command-line' versions depending on your choice of editor, which not everyone will have...

what about an advanced tab, in preferences, that allows you to enter your own command?

driven avatar Oct 07 '14 13:10 driven

Ruby files are often associated with the Ruby interpreter - we don't want to execute the RB script.

I was thinking of simply having a drop down list with per defined editors above the Editor and Arguments text fields. This is after all just a developer tool.

thomthom avatar Oct 07 '14 13:10 thomthom

I like the idea of the drop-down, but there are a lot of editors out there... would the input app text field stay? and could it also have an editable text field for the command?

driven avatar Oct 07 '14 13:10 driven

The existing text boxes would stay, we just add a drop down list of known configs. If people want their editor listed they just make a pull request with the patch to add it.

thomthom avatar Oct 07 '14 14:10 thomthom

Here are the commands for the three common plain text editors on MacOS:

General: open "#{file}" TextMate: mate -l #{line} "#{file}" BBedit (successor to TextWrangler): bbedit "#{file}" +#{line} Sublime: subl "#{file}:#{line}"

macfreek avatar Mar 10 '18 00:03 macfreek

@macfreek awesome!

thomthom avatar Mar 12 '18 12:03 thomthom