Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Update tabstop-generation README (#1272) #1298

Merged
merged 1 commit into from Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 56 additions & 0 deletions doc/examples/tabstop-generation/README.md
Expand Up @@ -48,3 +48,59 @@ endsnippet

Snippet is declared via regular expression and will expand to any required
number of fields in row.

Now, for a more robust tabstop generation, to create placeholders within
multiple lines:

```
global !p
def create_matrix_placeholders(snip):
# Create anonymous snippet body
anon_snippet_body = ""

# Get start and end line number of expanded snippet
start = snip.snippet_start[0]
end = snip.snippet_end[0]

# Append current line into anonymous snippet
for i in range(start, end + 1):
anon_snippet_body += snip.buffer[i]
anon_snippet_body += "" if i == end else "\n"

# Delete expanded snippet line till second to last line
for i in range(start, end):
del snip.buffer[start]

# Empty last expanded snippet line while preserving the line
snip.buffer[start] = ''

# Expand anonymous snippet
snip.expand_anon(anon_snippet_body)

def create_matrix(cols, rows, sep, start, end):
res = ""
placeholder = 1
for _ in range(0, int(rows)):
res += start + f"${placeholder} "
placeholder += 1
for _ in range(0, int(cols) - 1):
res += sep + f" ${placeholder} "
placeholder += 1
res += end
return res[:-1]
endglobal

post_jump "create_matrix_placeholders(snip)"
snippet 'arr(\d+),(\d+)' "LaTeX array" br
\begin{array}{`!p
orient = ""
for _ in range(0, int(match.group(1))): orient += "l"
snip.rv = orient`}
`!p
snip.rv = create_matrix(match.group(1), match.group(2), "&", "\t", "\\\\\\\\\n")
`$0
\end{array}
endsnippet
```

![gif](demo1.gif)
Binary file added doc/examples/tabstop-generation/demo1.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.