An Updated version is now available at Sublime Plugins – Perforce
Trying to do my part, I did a small Perforce integration plugin. Right now it takes for granted that you have an open ticket with your Perforce server, otherwise the actions will simply fail. The plugin is still work in progress but I try to work on it daily to add features here and there.
Getting Sublime Text 2
At the time of writing, Sublime Text 2 is “free” (a pop up will appear every now and then to suggest you buy a license) or available for pretty cheap, 59$. For such a great editor, I highly recommend buying it to support the developer. Download
Getting Perforce Plugin
My plugin is available in a couple of ways, but here’s my recommendations:
- Download and install Package Control for Sublime Text 2
- Open the command window (ctrl+shift+p in the default install)
- Select Package Control: Install Package
- Type “perforce”, press enter
- Browse to GitHub for my Sublime Text 2 Perforce Plugin repository
- Download the Zip File
- Locate your “roaming app data” folder, on Vista (old laptop, I know…) it’s located here: C:\Users\*your username*\AppData\Roaming
- Browse to Sublime Text 2\Packages
- Create a Perforce folder
- Copy the content of the folder ericmartel-Sublime-Text-2-Perforce-Plugin-?????? in the newly created Perforce folder so that Perforce.py resides in the root of Sublime Text2\Packages\Perforce
The plugin has two commands that react to events related to saving files.
When the plugin detects that you’re trying to save a new file (didn’t exist pre-save, exists post-save) and the file resides within your client root, it will automatically mark it for add.
You can disable this feature by changing the value of perforce_auto_add to false.
When the plugin detects that you’re modifying (perforce_auto_checkout_on_modified set to true) or you’re trying to save an existing file (exists pre-save – perforce_auto_checkout_on_save set to true) and the file resides within your client root, it will automatically try to checkout the file. For the moment there’s no handling of exclusive checkout or other conditions that could make the checkout fail.
You can disable this feature by changing the value of perforce_auto_checkout to false.
The text commands are all available through the command window (ctrl+shift+p in the default install). By typing perforce you can filter only the commands related to this plugin:
As you can see, you will even see the keyboard shortcuts assigned to these commands, as an example I assigned “ctrl+alt+x” to the Graphical Diff with Depot. Triggering the command from this window, from the Console (ctrl+`), from a menu item or from a keyboard shortcut will all result to the same thing.
These commands all redirect the p4 output to the Console window (ctrl+`) and a warning in some cases where the file in the view is not in the client root, if the perforce_warnings_enabled setting is set to true.
This command will attempt to checkout the file in the current view. Not much error handling is made. Use this command to manually control your checkout, if the perforce_auto_checkout setting is set to false.
This command will attempt to add the file in the current view. This is useful if the file was not created directly through Sublime Text 2 or if the perforce_auto_add setting is set to false.
This command will prompt you for a new name for the file in the current view.
This command will delete the file in the current view from Perforce.
This command will attempt to revert the changes made to the file in the current view.
This command outputs directly the result of a call to p4 diff with the file in view to the Console (ctrl+`). Recommended to more advanced users as the output is not really user-friendly.
This command calls p4diff and compares the local version of the current file with the version in the depot. I wish I could extend this to support Araxis Merge, but unfortunately I’m on sick leave for a couple of months and don’t feel like buying a license for my personal needs. Feel free to donate one and I’ll make the plugin configurable
This command will create an empty changelist and prompt the user for a single line description.
This command lists all the available changelists and then lets the user type a line to be added to the description.
This command lists all the available changelists, adding “New” to the list. By selecting a changelist, the file will be moved to this changelist. If new is selected, the user is prompted to enter a description for the new changelist.
This command lists all the files that are currently checked out sorted by changelist with part of the changelist description.
Here’s my current listing for a small web project I’m working on. Under the black square is the rest of the local path, but I didn’t want to make public the name of my project yet!
All the commands are easily available through the Tools menu (screenshot not updated):
Please make suggestions. The plugin does what I need for now, I might polish it or update it depending on my usage but if you’d like something added, feel free to ask!
How you can contribute
I will gladly accept bug reports on GitHub and suggestions by email (or use the contact form on this page if you can’t find my email address – with all the spam I keep receiving recently it shouldn’t be hard to find).
I keep a changelog in the main file of this plugin so you will be credited for your contribution!
Also, please buy Sublime Text 2 to support its developer!