Files
cappuccino/Tools/Editors/TextMate/JavaScript Objective-J.tmbundle/Commands/Show Obj-J Documentation for Word.tmCommand
T

215 lines
6.9 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>command</key>
<string>[[ -z $OBJJ_HOME ]] &amp;&amp; echo "OBJJ_HOME wasn't set!" &amp;&amp; exit 206
[[ ! -d "$OBJJ_HOME/Documentation" ]] &amp;&amp; echo "Please copy the folder Documentation to $OBJJ_HOME" &amp;&amp; exit 206
function showUpClassPage {
cat &lt;&lt;-HTM
&lt;body onload='javascript:window.location.href="tm-file://$OBJJ_HOME/Documentation/class$1"'&gt;
&lt;/body&gt;
HTM
exit 205
}
function showUpPage {
cat &lt;&lt;-HTM
&lt;body onload='javascript:window.location.href="tm-file://$1"'&gt;
&lt;/body&gt;
HTM
exit 205
}
DOCHEAD=$(perl -e '
#$line_nr = defined($ENV{"TM_INPUT_START_LINE"}) ? $ENV{"TM_INPUT_START_LINE"} : 1;
$line_nr = 1;
$cur_line_nr = $ENV{"TM_LINE_NUMBER"};
$header = "";
while($cur_line_nr--&gt;$line_nr) {$header.=&lt;&gt;;}
$tail = &lt;&gt;;
$header .= substr($tail,0,$ENV{"TM_LINE_INDEX"});
print $header;
')
# caret is inside of a class name
if [ `echo $TM_SCOPE | grep -c 'support.class.cappuccino'` -gt 0 ]; then
n=$(echo $TM_CURRENT_WORD | perl -pe 's/(.)(.)(.*)/_$1_$2_$3/;s/(?&lt;!_)([A-Z])(?!_)/_$1/g;s/_{2,}/_/g')
showUpClassPage "$n.html"
fi
# caret is inside of a foundation class name
if [ `echo $TM_SCOPE | grep -c 'support.variable.cappuccino.foundation'` -gt 0 ]; then
[[ "$TM_CURRENT_WORD" == "CPApp" ]] &amp;&amp; showUpClassPage "_C_P_Application.html"
fi
# caret is inside of a objj function
if [ `echo $TM_SCOPE | grep -c 'support.function.cappuccino'` -gt 0 ]; then
FILE=$(ruby -e '
require File.join(ENV["TM_SUPPORT_PATH"], "lib/ui.rb")
require File.join(ENV["TM_SUPPORT_PATH"], "lib/exit_codes.rb")
cur_word = ""
cur_word &lt;&lt; ENV["TM_CURRENT_WORD"]
cur_word.sub!("CG", "C[GP]") if cur_word[0..1] == "CG" or cur_word[0..1] == "CP"
lg = %x{egrep -rl "C[GP]RectMake" '$OBJJ_HOME/Documentation'}
urls = lg.split(/\n/).sort
if urls.length == 1
print urls.first
else
display = urls.map{|x| x.split("/").last.sub!(".html","")}
index=TextMate::UI.menu(display)
if index != nil
print urls[index]
else
TextMate.exit_discard()
end
end
')
FUNC=$(echo -en $TM_CURRENT_WORD | perl -pe 's/^(C[PG])(.*)/C[PG]$2/')
ANKER=`cat "$FILE" | egrep -o "\"#$FUNC.*?\"" | sed -e 's/^"//;s/".*//' | head -n 1`
[[ ! -z "$ANKER" ]] &amp;&amp; showUpPage "$FILE$ANKER"
[[ ! -z $FILE ]] &amp;&amp; showUpPage "$FILE" &amp;&amp; exit 206
fi
# caret is inside of a constant
if [ `echo $TM_SCOPE | grep -c 'support.constant.cappuccino'` -gt 0 ]; then
FILE=$(ruby -e '
require File.join(ENV["TM_SUPPORT_PATH"], "lib/ui.rb")
require File.join(ENV["TM_SUPPORT_PATH"], "lib/exit_codes.rb")
lg = %x{egrep -rl #{ENV["TM_CURRENT_WORD"]} '$OBJJ_HOME/Documentation'}
urls = lg.split(/\n/).sort
if urls.length == 1
print urls.first
else
display = urls.map{|x| x.split("/").last.sub!(".html","")}
index=TextMate::UI.menu(display)
if index != nil
print urls[index]
else
TextMate.exit_discard()
end
end
')
[[ ! -z $FILE ]] &amp;&amp; showUpPage "$FILE" &amp;&amp; exit 206
fi
# caret is inside of [method]
if [ `echo $TM_SCOPE | grep -c 'meta.bracketed.js.objj'` -gt 0 ]; then
# find []
DECL=$(echo -en "$DOCHEAD" | perl -e '
undef $/;
$header = &lt;&gt;;
$header=~s/\n/ /g;
@arr=split(//,$header);$c=0;
for($i=$#arr;$i&gt;-1;$i--){$c-- if($arr[$i] eq "]");$c++ if($arr[$i] eq "[");last if $c&gt;0;}
if($i==-1) {
print "";
} else {
print substr($header,$i+1);
}
')
# find the class for a method
CLASS=$(echo -en "$DECL" | perl -e '
undef $/;
$header = &lt;&gt;;
substr($header,0) =~ m/^\s*(\w+).*/;
$f = $1;
if (defined($f)) {
if($f=~m/CPApp/) {
print "CPApplication";
} else {
print $f;
}
} else {
substr($header,1) =~ m/^\s*(\w+).*/;
$f = $1;
if(defined($f)) {
if($f=~m/CPApp/) {
print "CPApplication";
} else {
print $f;
}
}
}
')
if [ ! -e "$OBJJ_HOME/Documentation/classes/$CLASS.html" ]; then
CLASS=$(echo -en "$DOCHEAD" | ruby -e '
require File.join(ENV["TM_SUPPORT_PATH"], "lib/ui.rb")
require File.join(ENV["TM_SUPPORT_PATH"], "lib/exit_codes.rb")
known_classes = []
classes = []
lg = %x{cd '$OBJJ_HOME/Documentation/classes'; egrep -rl #{ENV["TM_CURRENT_WORD"]} .}
known_classes = lg.split(/\n/).map{|x| x.sub("\.html","").sub("./","") }.sort
if known_classes.empty?
lg = %x{ls '$OBJJ_HOME/Documentation/classes'}
known_classes = lg.split(/\n/).map{|x| x.sub("\.html","").sub("./","") }.sort
end
STDIN.read().scan(/\b[_]{0,2}[NC][APS]\w+(?=[^\.])\b/) {|c| classes &lt;&lt; c if ! classes.include?(c) &amp;&amp; known_classes.include?(c)}
classes.sort!
if classes != known_classes
classes &lt;&lt; "--"
classes += known_classes
end
if classes.length == 1
if classes.first != "--"
print classes.first
else
TextMate.exit_discard()
end
else
index=TextMate::UI.menu(classes)
if index != nil
print classes[index]
else
TextMate.exit_discard()
end
end
')
fi
[[ -z $CLASS ]] &amp;&amp; exit 200
[[ ! -e "$OBJJ_HOME/Documentation/classes/$CLASS.html" ]] &amp;&amp; echo "Nothing for '$CLASS'!" &amp;&amp; exit 206
# tries to find only the first method for 'method1: method2: etc'
FIRSTMETHOD=$(echo -en "$DECL" | perl -e '
undef $/;$d = &lt;&gt;;
$d=~m/\s*(\w+):/m;
print $1;
')
METHOD=${FIRSTMETHOD:-$TM_CURRENT_WORD}
# find the correct anker within CLASS.html
ANKER=`cat "$OBJJ_HOME/Documentation/classes/$CLASS.html" | egrep -o "\"#$METHOD.*?\"" | sed -e 's/^"//;s/".*//' | head -n 1`
[[ ! -z "$ANKER" ]] &amp;&amp; showUpClassPage "$CLASS.html$ANKER"
# check for inherited methods
ANKER=`cat "$OBJJ_HOME/Documentation/classes/$CLASS.html" | egrep -o "[^#\"]+?html#$METHOD" | head -n 1`
# echo $CLASS; echo $METHOD; echo $ANKER; exit 206
CLASS=$(echo -en "$ANKER" | perl -pe 's/(.*?)\.html.*/$1/;')
# find the correct anker within the new CLASS.html
ANKER=`cat "$OBJJ_HOME/Documentation/classes/$CLASS.html" | egrep -o "\"#$METHOD.*?\"" | sed -e 's/^"//;s/".*//' | head -n 1`
[[ ! -z "$ANKER" ]] &amp;&amp; showUpClassPage "$CLASS.html$ANKER"
# [[ ! -z "$ANKER" ]] &amp;&amp; showUpClassPage "$ANKER"
fi
exit 205</string>
<key>input</key>
<string>selection</string>
<key>keyEquivalent</key>
<string>^h</string>
<key>name</key>
<string>Documentation for Word</string>
<key>output</key>
<string>replaceSelectedText</string>
<key>scope</key>
<string>support.class.cappuccino, support.variable.cappuccino.foundation, meta.bracketed.js.objj, support.function.cappuccino</string>
<key>uuid</key>
<string>2D05A28A-2ED7-4A9A-9A5C-8625466BC77C</string>
</dict>
</plist>