Permalink
Browse files

Updated Maketags script for BBEdit 10

  • Loading branch information...
Andrew Carter
Andrew Carter committed Sep 7, 2011
1 parent d35ad18 commit 127ad067ef213f236d1b8a95b940ab01cd44dddb
Showing with 91 additions and 43 deletions.
  1. +0 −43 Scripts/Make ctags for project.applescript
  2. +91 −0 Scripts/Maketags.applescript
@@ -1,43 +0,0 @@
--- Build tags file for current BBEdit project
-
-set _theFile to missing value
-
-tell application "BBEdit"
- if (count of text windows) > 0 then
- -- Get the first text window. This will return any window that can
- -- contain a text document (standalone window, project window, etc.)
- -- and skips over Find windows, Scratchpads, and whatnot
- set _firstTextWindow to text window 1
-
- if (class of _firstTextWindow is project window) then
- set _projectDocument to project document of _firstTextWindow
- if (on disk of _projectDocument) then
- set _theProjectDir to file of _projectDocument
-
- tell application "Finder"
- set _theFile to container of _theProjectDir
- end tell
- else
- -- Shipping versions of BBEdit don't provide direct access
- -- to the Instaproject root, so fake it by asking for
- -- the first node from the project list
- set _theFile to item 1 of _projectDocument
- end if
- else if (class of _firstTextWindow is text window) then
- if (on disk of document of _firstTextWindow) then
- set _theFile to file of document of _firstTextWindow
- end if
- end if
- end if
-end tell
-
-if _theFile is equal to missing value then
- -- No base file found for reference
- -- Signal error by beep and end
- beep
-else
- -- Run the maketags script
- set _thePath to POSIX path of _theFile
- set cmd to "cd " & _thePath & "; /usr/local/bin/bbedit --maketags"
- do shell script cmd
-end if
@@ -0,0 +1,91 @@
+-- Maketags
+--
+-- Builds ctags file for currently active project
+--
+-- Installation:
+--
+-- Copy script to either location:
+-- ~/Library/Application Support/BBEdit/Scripts
+-- ~/Dropbox/Application Support/BBEdit/Scripts
+--
+-- To add a shortcut key:
+--
+-- Window -> Palettes -> Scripts
+-- Select PeepOpen and click Set Key ...
+-- Enter a shortcut key combination (recommend Command + Option + T)
+--
+-- Author: Andrew Carter <ascarter@gmail.com>
+-- Version: 0.1
+--
+-- Copyright (c) 2011 Andrew Carter
+--
+-- Permission is hereby granted, free of charge, to any person obtaining a copy
+-- of this software and associated documentation files (the "Software"), to deal
+-- in the Software without restriction, including without limitation the rights
+-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+-- copies of the Software, and to permit persons to whom the Software is
+-- furnished to do so, subject to the following conditions:
+--
+-- The above copyright notice and this permission notice shall be included in
+-- all copies or substantial portions of the Software.
+--
+-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+-- THE SOFTWARE.
+--
+
+on makeTags()
+ set theFile to missing value
+
+ tell application "BBEdit"
+ set activeWindow to front window
+
+ if (class of activeWindow is project window) then
+ set projectDocument to project document of activeWindow
+
+ if ((count of items of projectDocument) > 0) then
+ set firstFileItem to item 1 of projectDocument as alias
+ else
+ set firstFileItem to file of document of activeWindow as alias
+ end if
+
+ if (on disk of projectDocument) then
+ set theProjectFile to file of projectDocument as alias
+
+ tell application "Finder"
+ set theProjectDir to container of theProjectFile
+ set firstFileDir to container of firstFileItem
+ end tell
+
+ if (firstFileDir is equal to theProjectDir) then
+ -- Use project file
+ set theFile to theProjectDir as alias
+ else
+ -- External project file -> use first item to set context
+ set theFile to firstFileItem
+ end if
+ else
+ -- BBEdit doesn't provide direct access to the Instaproject root
+ -- Use the first node from the project list
+ set theFile to firstFileItem
+ end if
+ end if
+ end tell
+
+ if theFile is equal to missing value then
+ -- No base file found for reference
+ -- Signal error by beep and end
+ beep
+ else
+ -- Run the maketags script
+ set thePath to POSIX path of theFile
+ set cmd to "cd " & thePath & "; /usr/local/bin/bbedit --maketags"
+ do shell script cmd
+ end if
+end makeTags
+
+makeTags()

0 comments on commit 127ad06

Please sign in to comment.