Can I use Xcode as an IDE for Perl scripts? - xcode

I am using OS X 10.9 (Mavericks) and need to work on a Perl project. I enjoy using TextMate, Atom, and BBEdit, but would like to try using Xcode instead, as it has good integration with git, a clean look, and I am already intimately familiar with the UI and syntax highlighting colour scheme.
Is it possible to use Xcode as an IDE to develop and run Perl scripts, in a way that puts it on par, or ahead of, existing text editors?
Update
I used Xcode 5 as an IDE for Perl for more than a month, and found it an excellent alternative to regular text editors like Atom and TextMate. However, like pure text editors, Xcode lacks support for debugging in Perl. I have since discovered Komodo IDE, a really nice IDE for Perl (and similar languages) that supports graphical Perl debugging, plus remote Perl debugging. I have since switched from using Xcode for Perl development to using Komodo IDE.

After some experimentation, it seems that Xcode makes for a fairly decent environment for developing Perl. Here is a screenshot of Xcode showing some Perl, project navigator, Git integration, and command-line output from a Perl script, as run by Xcode.
Xcode 5's built-in syntax highlighting works fine with Perl (.pl and .pm) files, right out of the box. But to use Xcode to write Perl more efficiently, you'll want to set up a new Xcode project:
Create a new Xcode workspace (File > New > Workspace) and select the folder you want to use for the Perl project.
Enable the Xcode navigator, so you can see the files in your project (View > Navigators > Show Navigators). Notice that Xcode does not show you a list of files in the workspace folder by default. If you're reading this, you're probably already an Xcode user, already knew that.
Manually add any files, or folders (groups, in Xcode parlance), that you want to see in the project (right-click on the Project Navigator pane and select Add files to "Project Name). Create groups to mirror your folder structure and add any files in subfolders to the groups. This can be a bit of work, depending on the size of your Perl project, but once you're set up it should not change much.
Click on your files in the Project Navigator to view the code. If you are using a Git or Subversion, Xcode will generate diffs as normal in the Xcode version editor.
To get your Perl script running when you hit Cmd-R:
Create a new scheme (Product > Scheme > New Scheme), configure Target to None and assign a name like Run Perl.
After creating the scheme, hit Edit Scheme.
In the Run perl scheme, set the Executable to /usr/bin/perl (select Other then press Shift-Cmd-G, enter /usr/bin/perl, and press Choose).
Go to the Arguments tab and ensure that your main script is the first argument. Add more arguments and environment variables as necessary.
Go to the Options tab and set Use custom working directory to your project folder. Deselect XPC services and any other options related to iOS or OS X development.
Press OK and when you press Cmd-R in Xcode, Xcode will call Perl, run your script, and show you the output.
To get Perl snippets and templates in Xcode, see How to create project templates in Xcode 4.
Extra tips:
If you are working with files that have extensions for an language that Xcode does not recognise, such as .sql files, you may be able to use the generic syntax highlighting. Go to Editor > Syntax Highlighting > Generic.

Related

How to associate types of files in Mac Finder to be opened by IntelliJ IDEA in "LightEdit" mode if I am a JetBrains Toolbox user?

IntelliJ IDEA 2020 can (finally!) simply open a file to be edited, without a project being involved. This is called LightEdit mode.
At this point in a JetBrains video, we see the host platform's file manager app opening a file via IntelliJ while noting that all such files should be opened using that same tool.
No "IntelliJ" application to choose
The problem for me is that I am a happy user of JetBrains Toolbox app to automatically install, upgrade, and open IntelliJ. So in my "Applications" folder on macOS, I have no "IntelliJ" application to choose in the Mac Finder when trying to open a file.
Is there some other way or trick to getting the Finder to know to open files with IntelliJ? And preferably with the latest version, as I believe Toolbox may keep around the older versions.
Basically, I am asking the same as this Question, How to make available “open this project in IntelliJ IDEA” option in Windows context menu, if IntelliJ IDEA has been installed via JetBrains Toolbox?, but for macOS instead of MS Windows. The Answer on that other Question is Windows-specific.
As a Toolbox user you still have access to the "generated shell scripts" (/usr/local/bin/idea, or things like /usr/local/bin/phpstorm, /usr/local/bin/pycharm, etc for individual applications).
But, these are shell scripts, and cannot be used for this because they lack the application identifiers needed by the OS for launching apps.
What you can do is wrap any of this with an Automator application. By wrapping the shell script directly, it should remain updated (since the shell script is itself a Toolbox generated wrapper that points to the latest installed version).
To do so:
Open Automator and click on the "new document" button.
Select "Application".
Add a "Run shell script" action from the library:
Change the "pass input" dropdown from "to stdin" to "as arguments".
Create a script similar to this this (replace phpstorm with idea or whatever IDE you have installed):
for file in "$#"
do
/usr/local/bin/phpstorm -e "$file"
done
Save the application somwhere, with a descriptive name:
Once that one is saved, you'll be able to use it to launch files from Finder, or even set it as default for a file type:
Use the app's menu: IntelliJ IDEA -> Preferences -> Editor -> File Types
Then press the Associate File Types with IntelliJ IDEA button.
A window will open with file groups you could choose from, and then press the OK button, then Apply and another OK.
After this, a MacOS restart is required.

How to open Visual Studio Code (0.5.0 - 0.7.0) from Unity on OSX

Visual Studio Code (0.3.0 - 0.7.0) defaults to opening files in a new window, so if you double-click a file in the project view in Unity, or any log in the console, it will open a new window rather than opening the file in an existing window you already have open.
Visual Studio Code (0.5.0 - 0.7.0) will open a file in an existing window if you pass it the command line arg -r, however Unity will not let you customize command line arguments on OSX, it's a Windows-only feature.
Is there a way to open files from Unity into an existing window in Visual Studio Code (0.3.0 - 0.7.0)?
There is a way, but it's a pain. Create a shell script that calls Visual Studio Code and passes it the file path that Unity provides:
"/Applications/Visual Studio Code.app/Contents/MacOS/Electron" -r -g $1
exit 0
Then you need to make an .app from that shell script. I used a program called Platypus to make the .app. If you use Platypus make sure to check the 'Accepts Dropped Items` checkbox, it didn't work for me until I used this option.
Once you have the .app created you need to set that app as your External Editor in Unity.
Hopefully in the future Unity will allow custom arguments to be sent for OSX, not just Windows. Also it would be nice if Unity passed the line and column numbers to custom external editors, currently those details are only passed to certain Unity-recognized editors. There is really no reason I can think of that why they could not pass that information as additional arguments. Because that information isn't being passed that means you cannot configure this script to open up the file to line that an error might be on, which is a bummer.
Also, this entire answer would be unnecessary if the Visual Studio Code team would just add an option in the preferences to default to opening files in the existing window instead of defaulting to a new one. There are a couple of feature requests listed on their site for this currently, here's one: http://visualstudio.uservoice.com/forums/293070-visual-studio-code/suggestions/8740771-persistant-option-to-open-files-in-existing-window
Hi you can get full debugging support in VSCode for Unity using this plugin
https://github.com/dotBunny/VSCode
VS Code in Unity
This plugin works on both MacOS and Windows and gives you the following capabilities:
•An option to enable VS Code integration (Editor –> Assets –> Enable Integration), this updates your solution files and (more importantly) keeps them in sync. This also sets the preferred external tool editor in the Unity preferences.
*Note, the old “Sync MonoDevelop” option is now gone in the Unity editor from V5.2
•It writes out the necessary (and sometimes hard to find) VS Code configuration files, including the ability to hide “non-code” files in the editor (hides things like .sln, .csproj and the ever present unity .meta files)
There are a couple of other settings in there to help speed up the integration.
•Automatically launches VS Code direct to your project folder, EVERY-TIME. no longer do you have to worry about keeping that window open, or switching around if you work on multiple projects
One thing to be aware of, once you enable the VSCode integration, changing your preferred code editor in the External Tools preferences will have no effect as the plugin takes over opening code files.

Xcode 5 diff files that aren't in versioning system

Xcode 5 has a nice diff system. But for the life of me, I cannot get it to diff two files that aren't in a repository. I just want to use it to compare any two arbitrary files, but when I open one file, and go to the version editor button, the two half windows say: "no editor"
Any thoughts?
Choose Xcode > Open Developer Tool > FileMerge from the menu bar and you'll get an app that can show you a comparison view much like the one in the Xcode version editor.

XCode Local Changes Indicator like other IDEs

I'm new to XCode and Objective-C programming. I have used WebStorm, IntelliJ, Netbeans, and Eclipse. They all support something like this:
Notice the colors on the left that indicate what's changed locally. Clicking on those will show me what it was before and allow me to reset the local copy to what it was before. Very useful and I do it all the time.
Obviously, with iOS programming, I want to use XCode, but I really want to have those indicators. All I see with XCode is this:
Notice that there's no indicator at all...
Note: I am not talking about being able to open a git diff tool, even if it's built into XCode. I am looking for the simplicity that all the other IDEs give me...
The closest thing in Xcode is the version editor. Choose View > Version Editor > Show Version Editor to show the version editor. The version editor shows your local copy and the last committed version of the file side by side and highlights the changes between the two versions.

A way to automatically organize #imports in Xcode

I love the "Organize Imports" command in Eclipse to implicitly add and remove classes imported into a source file (as in Java or ActionScript).
Is there a command in Xcode to update the #import directives at the top of.m Objective-C files based on the classes referenced within the file?
You can do this by creating an Automator action and use that in Xcode as well as everywhere in Mac OS X. To do that, do the following:
Start Automator -> New
Choose "Quick Action" (or "Service" on older MacOS/Automator versions)
add a "run shell script" action
use sort | uniq as the script and check the "output replaces selected text" checkbox
save and give it a name (e.g. "sort & unique")
check "Output replaces selected text"
After you saved it, you can just select your imports in Xcode, right click and choose your "sort & unique" action to organize your imports.
This is not as good as the organize import actions in Eclipse or IntelliJ, because it doesn't removes unused stuff etc. but it's better than nothing.
PS: Got that from WWDC 2012 Sessions - Session 402 Working Effeciently with Xcode (starting at 6:15)
EDIT
I started using AppCode, the Objective-C IDE from JetBrains, and it has features like "organise imports". You should check it out: http://www.jetbrains.com/objc/.
I'm resolving this as not currently a feature of Xcode :(
I've found Cedar Shortcuts to at least be usable. It's not as good as Eclipse's import feature (it doesn't organize imports), but it can keep you from having to go to the top of a class file and typing an import statement. With this plugin you just place the cursor on the class that needs imported and press Ctrl + Option + I. Here's the github project. https://github.com/cppforlife/CedarShortcuts
I made a small Xcode plugin to sort the headers and remove duplicates of the file with a shortcut, you can check it out! - https://github.com/insanoid/CleanHeaders-Xcode
AppCode from Jetbrains can do this.
Yup. Like in Eclipse, this would be an awesome feature since developing in XCode (Cocoa Touch) does require quite a bit of class imports which are not easy to remember and Android development in Eclipse sorts this out with a simple keystroke combination that saves so much time ! Hope there is a way to do this in XCode soon !
WordService (freeware) from Devon Technologies, provides a service that can be used in any Cocoa app that can (amongst others) sort lines.
Alternatively, you can use an Xcode Extension, such as Imp
Swiftlint has an opt-in rule which if opted, will automatically sort the imports alphabetically.
Add - sorted_imports to your .swiftlint.yml file under opt_in_rules.
Run swiftlint autocorrect terminal command on project root directory (same where swiftlint.yml is stored).

Resources