2014-03-11 16:10:50 -04:00
|
|
|
priority -50
|
2012-08-16 23:41:25 -04:00
|
|
|
|
2016-07-16 14:30:35 -04:00
|
|
|
global !p
|
2019-11-16 10:28:42 -05:00
|
|
|
# A overkill(dirty) table with automatic alignment feature
|
2016-07-16 14:30:35 -04:00
|
|
|
def create_table(snip):
|
2019-11-16 10:28:42 -05:00
|
|
|
# retrieving single line from current string and treat it like tabstops count
|
|
|
|
placeholders_string = snip.buffer[snip.line].strip()
|
|
|
|
rows_amount = int(placeholders_string[0])
|
|
|
|
columns_amount = int(placeholders_string[1])
|
|
|
|
|
|
|
|
prefix_str = "from vimsnippets import display_width;"
|
|
|
|
|
|
|
|
# erase current line
|
|
|
|
snip.buffer[snip.line] = ""
|
|
|
|
|
|
|
|
# create anonymous snippet with expected content and number of tabstops
|
|
|
|
anon_snippet_title = "| "
|
|
|
|
anon_snippet_delimiter = "|"
|
|
|
|
for col in range(1, columns_amount+1):
|
|
|
|
sync_rows = [x*columns_amount+col for x in range(rows_amount+1)]
|
|
|
|
sync_str = ",".join(["t[{0}]".format(x) for x in sync_rows])
|
|
|
|
max_width_str = "max(list(map(display_width, [" + sync_str + "])))"
|
|
|
|
cur_width_str = "display_width(t[" + str(col) + "])"
|
|
|
|
rv_val = "(" + max_width_str + "-" + cur_width_str + ")*' '"
|
|
|
|
anon_snippet_title += "${" + str(col) + ":head" + str(col)\
|
|
|
|
+ "}`!p " + prefix_str + "snip.rv=" + rv_val + "` | "
|
|
|
|
anon_snippet_delimiter += ":`!p " + prefix_str + "snip.rv = "\
|
|
|
|
+ max_width_str + "*'-'" + "`-|"
|
|
|
|
|
|
|
|
anon_snippet_title += "\n"
|
|
|
|
|
|
|
|
anon_snippet_delimiter += "\n"
|
|
|
|
anon_snippet_body = ""
|
|
|
|
for row in range(1, rows_amount+1):
|
|
|
|
body_row = "| "
|
|
|
|
for col in range(1, columns_amount+1):
|
|
|
|
sync_rows = [x*columns_amount+col for x in range(rows_amount+1)]
|
|
|
|
sync_str = ",".join(["t[{0}]".format(x) for x in sync_rows])
|
|
|
|
max_width_str = "max(list(map(display_width, [" + sync_str + "])))"
|
|
|
|
cur_width_str = "display_width(t[" + str(row*columns_amount+col) + "])"
|
|
|
|
rv_val = "(" + max_width_str + "-" + cur_width_str + ")*' '"
|
|
|
|
placeholder = "R{0}C{1}".format(row, col)
|
|
|
|
body_row += "${" + str(row*columns_amount+col) + ":" + placeholder\
|
|
|
|
+ "}`!p " + prefix_str + "snip.rv=" + rv_val + "` | "
|
|
|
|
|
|
|
|
body_row += "\n"
|
|
|
|
anon_snippet_body += body_row
|
|
|
|
|
|
|
|
anon_snippet_table = anon_snippet_title + anon_snippet_delimiter + anon_snippet_body
|
|
|
|
|
|
|
|
# expand anonymous snippet
|
|
|
|
snip.expand_anon(anon_snippet_table)
|
2016-07-16 14:30:35 -04:00
|
|
|
endglobal
|
|
|
|
|
2012-08-16 23:41:25 -04:00
|
|
|
###########################
|
|
|
|
# Sections and Paragraphs #
|
|
|
|
###########################
|
|
|
|
snippet sec "Section" b
|
|
|
|
# ${1:Section Name} #
|
|
|
|
$0
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet ssec "Sub Section" b
|
|
|
|
## ${1:Section Name} ##
|
|
|
|
$0
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet sssec "SubSub Section" b
|
|
|
|
### ${1:Section Name} ###
|
|
|
|
$0
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet par "Paragraph" b
|
|
|
|
#### ${1:Paragraph Name} ####
|
|
|
|
$0
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet spar "Paragraph" b
|
|
|
|
##### ${1:Paragraph Name} #####
|
|
|
|
$0
|
|
|
|
endsnippet
|
|
|
|
|
2018-07-19 08:52:53 -04:00
|
|
|
###################
|
|
|
|
# Text formatting #
|
|
|
|
###################
|
|
|
|
|
|
|
|
snippet * "italics"
|
|
|
|
*${1:${VISUAL}}*$0
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet ** "bold"
|
|
|
|
**${1:${VISUAL}}**$0
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet *** "bold italics"
|
|
|
|
***${1:${VISUAL}}***$0
|
|
|
|
endsnippet
|
|
|
|
|
2020-04-25 21:56:16 -04:00
|
|
|
snippet /* "Comment"
|
|
|
|
<!-- ${1:${VISUAL}} -->$0
|
|
|
|
endsnippet
|
2018-07-19 08:52:53 -04:00
|
|
|
|
2012-08-16 23:41:25 -04:00
|
|
|
################
|
|
|
|
# Common stuff #
|
|
|
|
################
|
2013-04-13 13:45:21 -04:00
|
|
|
snippet link "Link to something"
|
2020-12-04 16:15:32 -05:00
|
|
|
[${1:${VISUAL:Text}}](${3:https://${2:www.url.com}})$0
|
2012-08-16 23:41:25 -04:00
|
|
|
endsnippet
|
|
|
|
|
2013-04-13 13:45:21 -04:00
|
|
|
snippet img "Image"
|
2012-08-16 23:41:25 -04:00
|
|
|
![${1:pic alt}](${2:path}${3/.+/ "/}${3:opt title}${3/.+/"/})$0
|
|
|
|
endsnippet
|
|
|
|
|
2014-07-02 07:18:18 -04:00
|
|
|
snippet ilc "Inline Code" i
|
2021-10-11 05:30:43 -04:00
|
|
|
\`${1:${VISUAL}}\`$0
|
2014-07-02 07:18:18 -04:00
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet cbl "Codeblock" b
|
2021-10-11 05:30:43 -04:00
|
|
|
\`\`\`$1
|
|
|
|
${2:${VISUAL}}
|
2014-07-02 07:18:18 -04:00
|
|
|
\`\`\`
|
|
|
|
$0
|
|
|
|
endsnippet
|
|
|
|
|
2016-07-16 14:30:35 -04:00
|
|
|
snippet refl "Reference Link"
|
|
|
|
[${1:${VISUAL:Text}}][${2:id}]$0
|
|
|
|
|
2020-12-04 16:15:32 -05:00
|
|
|
[$2]:${4:https://${3:www.url.com}} "${5:$4}"
|
2016-07-16 14:30:35 -04:00
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet fnt "Footnote"
|
|
|
|
[^${1:${VISUAL:Footnote}}]$0
|
|
|
|
|
|
|
|
[^$1]:${2:Text}
|
|
|
|
endsnippet
|
|
|
|
|
2020-04-25 21:56:16 -04:00
|
|
|
snippet detail "Disclosure"
|
|
|
|
<details${3: open=""}>
|
2020-06-21 11:50:44 -04:00
|
|
|
${1:<summary>${2}</summary>}$0
|
2020-04-25 21:56:16 -04:00
|
|
|
</details>
|
|
|
|
endsnippet
|
|
|
|
|
2019-11-16 10:28:42 -05:00
|
|
|
post_jump "create_table(snip)"
|
|
|
|
snippet "tb([1-9][1-9])" "Fancy table" br
|
|
|
|
`!p snip.rv = match.group(1)`
|
2016-07-16 14:30:35 -04:00
|
|
|
endsnippet
|
|
|
|
|
2012-08-16 23:41:25 -04:00
|
|
|
# vim:ft=snippets:
|