summaryrefslogtreecommitdiff
path: root/tools/clang-format/clang-format-bbedit.applescript
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-05-02 17:37:36 +0000
committerDaniel Jasper <djasper@google.com>2013-05-02 17:37:36 +0000
commit82e3b47276f175a4b51772525da5314f0f48df9c (patch)
treea178dcea6bbcb043009d3b6e28feb32b57504dc3 /tools/clang-format/clang-format-bbedit.applescript
parentfa6b079b1231366696f6a497c6a084c73a35c85d (diff)
downloadclang-82e3b47276f175a4b51772525da5314f0f48df9c.tar.gz
clang-82e3b47276f175a4b51772525da5314f0f48df9c.tar.bz2
clang-82e3b47276f175a4b51772525da5314f0f48df9c.tar.xz
Basic clang-format integration for BBEdit.
Thanks to Avi Drissman! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180933 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/clang-format/clang-format-bbedit.applescript')
-rw-r--r--tools/clang-format/clang-format-bbedit.applescript27
1 files changed, 27 insertions, 0 deletions
diff --git a/tools/clang-format/clang-format-bbedit.applescript b/tools/clang-format/clang-format-bbedit.applescript
new file mode 100644
index 0000000000..fa88fe9004
--- /dev/null
+++ b/tools/clang-format/clang-format-bbedit.applescript
@@ -0,0 +1,27 @@
+-- In this file, change "/path/to/" to the path where you installed clang-format
+-- and save it to ~/Library/Application Support/BBEdit/Scripts. You can then
+-- select the script from the Script menu and clang-format will format the
+-- selection. Note that you can rename the menu item by renaming the script, and
+-- can assign the menu item a keyboard shortcut in the BBEdit preferences, under
+-- Menus & Shortcuts.
+on urlToPOSIXPath(theURL)
+ return do shell script "python -c \"import urllib, urlparse, sys; print urllib.unquote(urlparse.urlparse(sys.argv[1])[2])\" " & quoted form of theURL
+end urlToPOSIXPath
+
+tell application "BBEdit"
+ set selectionOffset to characterOffset of selection
+ set selectionLength to length of selection
+ set fileURL to URL of text document 1
+end tell
+
+set filePath to urlToPOSIXPath(fileURL)
+set newContents to do shell script "/path/to/clang-format -offset=" & selectionOffset & " -length=" & selectionLength & " " & quoted form of filePath
+
+tell application "BBEdit"
+ -- "set contents of text document 1 to newContents" scrolls to the bottom while
+ -- replacing a selection flashes a bit but doesn't affect the scroll position.
+ set currentLength to length of contents of text document 1
+ select characters 1 thru currentLength of text document 1
+ set text of selection to newContents
+ select characters selectionOffset thru (selectionOffset + selectionLength - 1) of text document 1
+end tell