Skip to content

Commit

Permalink
Deprecated in favor of Espresso-native support for placeholder variables
Browse files Browse the repository at this point in the history
  • Loading branch information
onecrayon committed Dec 20, 2009
1 parent 3b8a9e8 commit 2ac4348
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 28 deletions.
4 changes: 3 additions & 1 deletion src/Support/Library/tea_actions.py
Expand Up @@ -546,14 +546,16 @@ def sanitize_for_snippet(text):
text = text.replace('}', '\}')
return text.replace('`', '\`')

def construct_snippet(text, snippet):
def construct_snippet(text, snippet, parse_new_vars=False):
'''
Constructs a simple snippet by replacing $SELECTED_TEXT with
sanitized text
'''
if text is None:
text = ''
text = sanitize_for_snippet(text)
if parse_new_vars:
snippet = snippet.replace('$EDITOR_SELECTION', text)
return snippet.replace('$SELECTED_TEXT', text)

def indent_snippet(context, snippet, range):
Expand Down
2 changes: 2 additions & 0 deletions src/Support/Scripts/goto.py
Expand Up @@ -62,7 +62,9 @@ def act(context, target=None, source=None, trim=False, discard_indent=False,

if target is not None and text:
if search_string is not None:
# DEPRECATED: Please use $EDITOR_SELECTION instead
search = search_string.replace('$SELECTED_TEXT', text)
search = search_string.replace('$EDITOR_SELECTION', text)
else:
search = text
# Find the start and end points of the substring
Expand Down
2 changes: 1 addition & 1 deletion src/Support/Scripts/insert_snippet.py
Expand Up @@ -22,4 +22,4 @@ def act(context, default=None, undo_name=None, **syntaxes):
# Construct the snippet
snippet = tea.construct_snippet(text, snippet)
# Insert that snippet!
return tea.insert_snippet_over_range(context, snippet, range, undo_name)
return tea.insert_snippet(context, snippet)
2 changes: 1 addition & 1 deletion src/Support/Scripts/insert_url_snippet.py
Expand Up @@ -51,4 +51,4 @@ def act(context, default=None, fallback_url='', undo_name=None, **syntaxes):
snippet = tea.select_from_zones(context, range, default, **syntaxes)
snippet = tea.construct_snippet(text, snippet)
snippet = snippet.replace('$URL', tea.sanitize_for_snippet(url))
return tea.insert_snippet_over_range(context, snippet, range, undo_name, False)
return tea.insert_snippet(context, snippet)
4 changes: 2 additions & 2 deletions src/Support/Scripts/selected_lines_to_snippets.py
Expand Up @@ -33,9 +33,9 @@ def act(context, first_snippet='', following_snippet='',
# Only wrap the line if there's some content
if content.group(2) != '':
if count == 1:
segment = tea.construct_snippet(content.group(2), first)
segment = tea.construct_snippet(content.group(2), first, True)
else:
segment = tea.construct_snippet(content.group(2), following)
segment = tea.construct_snippet(content.group(2), following, True)
snippet += content.group(1) + segment + content.group(3)
count += 1
else:
Expand Down
2 changes: 1 addition & 1 deletion src/Support/Scripts/selections_to_snippets.py
Expand Up @@ -23,4 +23,4 @@ def act(context, first_snippet='', following_snippet='',
else:
indent = True
snippet = tea.construct_snippet(text, first_snippet + final_append)
return tea.insert_snippet_over_range(context, snippet, range, undo_name, indent)
return tea.insert_snippet(context, snippet, indent)
11 changes: 6 additions & 5 deletions src/Support/Scripts/selections_to_text.py
Expand Up @@ -23,21 +23,22 @@ def act(context, default=None, undo_name=None, **syntaxes):
# Make sure the range is actually a selection
if range.length > 0:
text = tea.get_selection(context, range)
snippet = '${1:' + insertion.replace('$SELECTED_TEXT',
'${2:$SELECTED_TEXT}') + '}$0'
snippet = '${1:' + insertion.replace('$EDITOR_SELECTION',
'${2:$EDITOR_SELECTION}') + '}$0'
else:
# Not a selection, just wrap the cursor
text = ''
snippet = insertion.replace('$SELECTED_TEXT', '$1') + '$0'
snippet = insertion.replace('$EDITOR_SELECTION', '$1') + '$0'
snippet = tea.construct_snippet(text, snippet)
return tea.insert_snippet_over_range(context, snippet, range,
undo_name)
return tea.insert_snippet(context, snippet)
# Since we're here, it must not have been a single selection
insertions = tea.new_recipe()
for range in ranges:
insertion = tea.select_from_zones(context, range, default, **syntaxes)
text = tea.get_selection(context, range)
# DEPRECATED: $SELECTED_TEXT will go away in future; don't use it
text = insertion.replace('$SELECTED_TEXT', text)
text = insertion.replace('$EDITOR_SELECTION', text)
insertions.addReplacementString_forRange_(text, range)
if undo_name is not None:
insertions.setUndoActionName_(undo_name)
Expand Down
2 changes: 2 additions & 0 deletions src/Support/Scripts/visit_url.py
Expand Up @@ -33,7 +33,9 @@ def act(context, input=None, default=None, **syntaxes):
text = urllib.quote_plus(text)
url = tea.select_from_zones(context, range, default, **syntaxes)
# Got the URL, let's run the URL
# DEPRECATED: please use $EDITOR_SELECTION instead
url = url.replace('$SELECTED_TEXT', text)
url = url.replace('$EDITOR_SELECTION', text)
NSWorkspace.sharedWorkspace().openURL_(NSURL.URLWithString_(url))
# Because this gets passed through to Obj-C, using int prevents beeping
return True
16 changes: 8 additions & 8 deletions src/TextActions/FormattingActions.xml
Expand Up @@ -12,12 +12,12 @@
<dict>
<key>default</key>
<string><![CDATA[
${1:$SELECTED_TEXT}$0
${1:$EDITOR_SELECTION}$0
]]></string>

<key>python, python *</key>
<string><![CDATA[
${1:$SELECTED_TEXT}$0]]></string>
${1:$EDITOR_SELECTION}$0]]></string>

<key>undo_name</key>
<string>Insert Indented Line</string>
Expand Down Expand Up @@ -86,17 +86,17 @@
<options>
<dict>
<key>default</key>
<string>&lt;em>$SELECTED_TEXT&lt;/em></string>
<string>&lt;em>$EDITOR_SELECTION&lt;/em></string>

<key>undo_name</key>
<string>Emphasize</string>

<!-- Syntax-specific overrides -->
<key>markdown, markdown structural, markdown stylistic</key>
<string>*$SELECTED_TEXT*</string>
<string>*$EDITOR_SELECTION*</string>

<key>textile</key>
<string>_$SELECTED_TEXT_</string>
<string>_$EDITOR_SELECTION_</string>
</dict>
</options>
</setup>
Expand All @@ -111,17 +111,17 @@
<options>
<dict>
<key>default</key>
<string>&lt;strong>$SELECTED_TEXT&lt;/strong></string>
<string>&lt;strong>$EDITOR_SELECTION&lt;/strong></string>

<key>undo_name</key>
<string>Strong</string>

<!-- Syntax-specific overrides -->
<key>markdown, markdown structural, markdown stylistic</key>
<string>**$SELECTED_TEXT**</string>
<string>**$EDITOR_SELECTION**</string>

<key>textile</key>
<string>*$SELECTED_TEXT*</string>
<string>*$EDITOR_SELECTION*</string>
</dict>
</options>
</setup>
Expand Down
18 changes: 9 additions & 9 deletions src/TextActions/HTMLActions.xml
Expand Up @@ -134,7 +134,7 @@
<options>
<dict>
<key>default</key>
<string>&lt;$SELECTED_TEXT>$1&lt;/$WORD>$0</string>
<string>&lt;$EDITOR_SELECTION>$1&lt;/$WORD>$0</string>

<key>extra_characters</key>
<string>_-#.>+*:$!@</string>
Expand Down Expand Up @@ -194,7 +194,7 @@
<options>
<dict>
<key>first_snippet</key>
<string>&lt;${1:p}>$SELECTED_TEXT&lt;/${1/\s.*//}>$0</string>
<string>&lt;${1:p}>$EDITOR_SELECTION&lt;/${1/\s.*//}>$0</string>
</dict>
</options>
</setup>
Expand All @@ -210,10 +210,10 @@
<options>
<dict>
<key>first_snippet</key>
<string>&lt;${1:li}>$SELECTED_TEXT&lt;/${1/\s.*//}></string>
<string>&lt;${1:li}>$EDITOR_SELECTION&lt;/${1/\s.*//}></string>

<key>following_snippet</key>
<string>&lt;$1>$SELECTED_TEXT&lt;/${1/\s.*//}></string>
<string>&lt;$1>$EDITOR_SELECTION&lt;/${1/\s.*//}></string>

<key>final_append</key>
<string>$0</string>
Expand All @@ -235,7 +235,7 @@
<options>
<dict>
<key>default</key>
<string>&lt;a href="${1:$URL}"${2: title="$3"}>$SELECTED_TEXT&lt;/a>$0</string>
<string>&lt;a href="${1:$URL}"${2: title="$3"}>$EDITOR_SELECTION&lt;/a>$0</string>

<key>fallback_url</key>
<string>http://</string>
Expand All @@ -245,10 +245,10 @@

<!-- Syntax-specific overrides -->
<key>markdown, markdown structural, markdown stylistic</key>
<string>[$SELECTED_TEXT](${1:$URL})$0</string>
<string>[$EDITOR_SELECTION](${1:$URL})$0</string>

<key>textile</key>
<string>"$SELECTED_TEXT":${1:$URL}$0</string>
<string>"$EDITOR_SELECTION":${1:$URL}$0</string>
</dict>
</options>
</setup>
Expand All @@ -269,11 +269,11 @@
<string>word</string>

<key>default</key>
<string><![CDATA[http://google.com/search?q=$SELECTED_TEXT+site%3Ahttp%3A%2F%2Fhtmlhelp.com%2Freference%2Fhtml40%2F]]></string>
<string><![CDATA[http://google.com/search?q=$EDITOR_SELECTION+site%3Ahttp%3A%2F%2Fhtmlhelp.com%2Freference%2Fhtml40%2F]]></string>


<key>entity.name</key>
<string><![CDATA[http://google.com/search?q=$SELECTED_TEXT+site%3Ahttp%3A%2F%2Fhtmlhelp.com%2Freference%2Fhtml40%2F&btnI=745]]></string>
<string><![CDATA[http://google.com/search?q=$EDITOR_SELECTION+site%3Ahttp%3A%2F%2Fhtmlhelp.com%2Freference%2Fhtml40%2F&btnI=745]]></string>
</dict>
</options>
</setup>
Expand Down

0 comments on commit 2ac4348

Please sign in to comment.