r180933 - Basic clang-format integration for BBEdit.
Daniel Jasper
djasper at google.com
Thu May 2 10:37:37 PDT 2013
Author: djasper
Date: Thu May 2 12:37:36 2013
New Revision: 180933
URL: http://llvm.org/viewvc/llvm-project?rev=180933&view=rev
Log:
Basic clang-format integration for BBEdit.
Thanks to Avi Drissman!
Added:
cfe/trunk/tools/clang-format/clang-format-bbedit.applescript
Modified:
cfe/trunk/docs/ClangFormat.rst
Modified: cfe/trunk/docs/ClangFormat.rst
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormat.rst?rev=180933&r1=180932&r2=180933&view=diff
==============================================================================
--- cfe/trunk/docs/ClangFormat.rst (original)
+++ cfe/trunk/docs/ClangFormat.rst Thu May 2 12:37:36 2013
@@ -81,6 +81,21 @@ This binds the function `clang-format-re
current line or selected region.
+BBEdit Integration
+==================
+
+:program:`clang-format` cannot be used as a text filter with BBEdit, but works
+well via a script. The AppleScript to do this integration can be found at
+`clang/tools/clang-format/clang-format-bbedit.applescript`; place a copy in
+`~/Library/Application Support/BBEdit/Scripts`, and edit the path within it to
+point to your local copy of :program:`clang-format`.
+
+With this integration you can select the script from the Script menu and
+:program:`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.
+
+
Script for patch reformatting
=============================
Added: cfe/trunk/tools/clang-format/clang-format-bbedit.applescript
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/clang-format-bbedit.applescript?rev=180933&view=auto
==============================================================================
--- cfe/trunk/tools/clang-format/clang-format-bbedit.applescript (added)
+++ cfe/trunk/tools/clang-format/clang-format-bbedit.applescript Thu May 2 12:37:36 2013
@@ -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
More information about the cfe-commits
mailing list