1
0
mirror of https://github.com/amix/vimrc synced 2025-06-16 09:35:01 +08:00

Updated plugins

This commit is contained in:
Amir Salihefendic
2019-11-16 16:28:42 +01:00
parent 96e10ed101
commit 72bdaba47e
204 changed files with 5936 additions and 1666 deletions

View File

@ -11,6 +11,12 @@ priority -60
##############
global !p
from vimsnippets import foldmarker, make_box, get_comment_format
LOREM = """
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod \
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At \
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, \
no sea takimata sanctus est Lorem ipsum dolor sit amet.
"""
endglobal
snippet box "A nice box with the current comment symbol" b
@ -56,11 +62,8 @@ endsnippet
##########################
# LOREM IPSUM GENERATORS #
##########################
snippet lorem "Lorem Ipsum - 50 Words" b
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
no sea takimata sanctus est Lorem ipsum dolor sit amet.
snippet "lorem(([1-4])?[0-9])?" "Lorem Ipsum" r
`!p snip.rv = " ".join(LOREM.split()[:int(match.group(1))]) if match.group(1) else LOREM`
endsnippet
##########################
@ -104,7 +107,7 @@ endsnippet
# Misc #
##########
snippet uuid "Random UUID" w
`!p if not snip.c: import uuid; snip.rv = uuid.uuid4()`
`!p if not snip.c: import uuid; snip.rv = str(uuid.uuid4())`
endsnippet
# vim:ft=snippets:

View File

@ -1,25 +1,55 @@
priority -50
global !p
# A overkill(dirty) table with automatic alignment feature
def create_table(snip):
# retrieving single line from current string and treat it like tabstops count
placeholders_string = snip.buffer[snip.line].strip()[2:].split("x",1)
rows_amount = int(placeholders_string[0])
columns_amount = int(placeholders_string[1])
# 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])
# erase current line
snip.buffer[snip.line] = ''
prefix_str = "from vimsnippets import display_width;"
# create anonymous snippet with expected content and number of tabstops
anon_snippet_title = ' | '.join(['$' + str(col) for col in range(1,columns_amount+1)]) + "\n"
anon_snippet_delimiter = ':-|' * (columns_amount-1) + ":-\n"
anon_snippet_body = ""
for row in range(1,rows_amount+1):
anon_snippet_body += ' | '.join(['$' + str(row*columns_amount+col) for col in range(1,columns_amount+1)]) + "\n"
anon_snippet_table = anon_snippet_title + anon_snippet_delimiter + anon_snippet_body
# erase current line
snip.buffer[snip.line] = ""
# expand anonymous snippet
snip.expand_anon(anon_snippet_table)
# 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)
endglobal
###########################
@ -101,8 +131,9 @@ snippet fnt "Footnote"
[^$1]:${2:Text}
endsnippet
pre_expand "create_table(snip)"
snippet "tb(\d+x\d+)" "Customizable table" br
post_jump "create_table(snip)"
snippet "tb([1-9][1-9])" "Fancy table" br
`!p snip.rv = match.group(1)`
endsnippet
# vim:ft=snippets:

View File

@ -497,8 +497,8 @@ def __coerce__(self, other):
${25:pass}
endsnippet
snippet deff
def ${1:fname}(`!p snip.rv = vim.eval('indent(".") ? "self" : ""')`$2):
snippet deff "function or class method"
def ${1:fname}(`!p snip.rv = "self, " if snip.indent else ""`$2):
$0
endsnippet

View File

@ -6,53 +6,43 @@ priority -50
# General Stuff #
###########################################################################
global !p
import vim
from os import path as ospath
from string import Template
import re
from collections import Counter
from vimsnippets import complete, has_cjk, display_width
from vimsnippets import complete
#http://docutils.sourceforge.net/docs/ref/rst/roles.html
TEXT_ROLES = ['emphasis','literal','code','math',
'pep-reference','rfc-reference',
'strong','subscript','superscript',
'title-reference','raw']
# http://docutils.sourceforge.net/docs/ref/rst/roles.html
TEXT_ROLES = ['emphasis', 'literal', 'code', 'math',
'pep-reference', 'rfc-reference',
'strong', 'subscript', 'superscript',
'title-reference', 'raw']
TEXT_ROLES_REGEX = r'\.\.\srole::?\s(w+)'
#http://docutils.sourceforge.net/docs/ref/rst/directives.html#specific-admonitions
# http://docutils.sourceforge.net/docs/ref/rst/directives.html#specific-admonitions
SPECIFIC_ADMONITIONS = ["attention", "caution", "danger",
"error", "hint", "important", "note",
"tip", "warning"]
#http://docutils.sourceforge.net/docs/ref/rst/directives.html
DIRECTIVES = ['topic','sidebar','math','epigraph',
'parsed-literal','code','highlights',
'pull-quote','compound','container','table','csv-table',
'list-table','class','sectnum',
'role','default-role','unicode',
'raw']
# http://docutils.sourceforge.net/docs/ref/rst/directives.html
DIRECTIVES = ['code', 'contents', 'admonition', 'table', 'csv-table', 'list-table',
'class', 'container', 'sidebar', 'topic', 'title',
'role', 'default-role', 'raw']
NONE_CONTENT_DIRECTIVES = ['rubric', 'contents', 'header',
'footer', 'date', 'include', 'title']
# DIRECTIVES_WITHOUT_TITLE means directive arguments equal None
DIRECTIVES_WITHOUT_TITLE = ['math', 'meta', 'parsed-literal', 'line-block',
'header', 'compound', 'highlights', 'pull-quote',
'footer', 'epigraph', 'rubric', 'sectnum']
INCLUDABLE_DIRECTIVES = ['image', 'figure', 'include']
# CJK chars
# http://stackoverflow.com/questions/2718196/find-all-chinese-text-in-a-string-using-python-and-regex
CJK_RE = re.compile(u'[⺀-⺙⺛-⻳⼀-⿕々〇〡-〩〸-〺〻㐀-䶵一-鿃豈-鶴侮-頻並-龎]', re.UNICODE)
#http://www.pygal.org/en/stable/documentation/types/index.html
# Directives for Subsubsection Definition
DIRECTIVES_FOR_SUBSTITUTION = ['replace', 'unicode', 'date']
# http://www.pygal.org/en/stable/documentation/types/index.html
CHART_TYPES = ["Line", "StackedLine", "HorizontalLine", "Bar", "StackedBar", "HorizontalBar", "Histogram", "XY", "DateLine", "TimeLine", "TimeDeltaLine", "DateTimeLine", "Pie", "Radar", "Box", "Dot", "Funnel", "Gauge", "SolidGauge", "Pyramid", "Treemap"]
def has_cjk(s):
"""Detect if s contains CJK characters."""
return CJK_RE.search(s) is not None
def real_filename(filename):
"""pealeextension name off if possible
# i.e. "foo.bar.png will return "foo.bar"
"""
return ospath.splitext(filename)[0]
return os.path.splitext(filename)[0]
def check_file_exist(rst_path, relative_path):
"""
@ -62,23 +52,10 @@ def check_file_exist(rst_path, relative_path):
:param relative_path: path related to rst file
:return: relative file's absolute path if file exist
"""
abs_path = ospath.join(ospath.dirname(rst_path), relative_path)
if ospath.isfile(abs_path):
abs_path = os.path.join(os.path.dirname(rst_path), relative_path)
if os.path.isfile(abs_path):
return abs_path
try:
rst_char_len = vim.strwidth # Requires Vim 7.3+
except AttributeError:
from unicodedata import east_asian_width
def rst_char_len(s):
"""Return the required over-/underline length for s."""
result = 0
for c in s:
result += 2 if east_asian_width(c) in ('W', 'F') else 1
return result
def make_items(times, leading='+'):
"""
make lines with leading char multitimes
@ -130,45 +107,45 @@ def get_popular_code_type():
endglobal
snippet part "Part" b
`!p snip.rv = rst_char_len(t[1])*'#'`
`!p snip.rv = display_width(t[1])*'#'`
${1:${VISUAL:Part name}}
`!p snip.rv = rst_char_len(t[1])*'#'`
`!p snip.rv = display_width(t[1])*'#'`
$0
endsnippet
snippet chap "Chapter" b
`!p snip.rv = rst_char_len(t[1])*'*'`
`!p snip.rv = display_width(t[1])*'*'`
${1:${VISUAL:Chapter name}}
`!p snip.rv = rst_char_len(t[1])*'*'`
`!p snip.rv = display_width(t[1])*'*'`
$0
endsnippet
snippet sec "Section" b
${1:${VISUAL:Section name}}
`!p snip.rv = rst_char_len(t[1])*'='`
`!p snip.rv = display_width(t[1])*'='`
$0
endsnippet
snippet ssec "Subsection" b
${1:${VISUAL:Subsection name}}
`!p snip.rv = rst_char_len(t[1])*'-'`
`!p snip.rv = display_width(t[1])*'-'`
$0
endsnippet
snippet sssec "Subsubsection" b
${1:${VISUAL:Subsubsection name}}
`!p snip.rv = rst_char_len(t[1])*'^'`
`!p snip.rv = display_width(t[1])*'^'`
$0
endsnippet
snippet para "Paragraph" b
${1:${VISUAL:Paragraph name}}
`!p snip.rv = rst_char_len(t[1])*'"'`
`!p snip.rv = display_width(t[1])*'"'`
$0
endsnippet
@ -228,7 +205,7 @@ endsnippet
# img, inc, fig
snippet id "Includable Directives" b
`!p
real_name=real_filename(ospath.basename(t[2]))
real_name=real_filename(os.path.basename(t[2]))
di=t[1][:2]
link=""
@ -264,23 +241,30 @@ snippet di "Directives" b
$0
endsnippet
snippet nd "None Content Directives" b
.. $1`!p snip.rv=complete(t[1], NONE_CONTENT_DIRECTIVES)`:: $2
snippet dt "Directives without title" b
.. $1`!p snip.rv=complete(t[1], DIRECTIVES_WITHOUT_TITLE)`::
${2:${VISUAL:Content}}
$0
endsnippet
snippet ds "Directives for subscription" b
.. |$1| $2`!p snip.rv=complete(t[2], DIRECTIVES_FOR_SUBSTITUTION)`:: ${3:Content}
$0
endsnippet
snippet sa "Specific Admonitions" b
.. $1`!p snip.rv =complete(t[1], SPECIFIC_ADMONITIONS)`::
.. $1`!p snip.rv =complete(t[1], SPECIFIC_ADMONITIONS)`:: $2
${2:${VISUAL:Content}}
${3:${VISUAL:Content}}
$0
endsnippet
#it will be trigger at start of line or after a word
# it will be trigger at start of line or after a word
snippet ro "Text Roles" w
\ :$1`!p snip.rv=complete(t[1],
TEXT_ROLES+look_up_directives(TEXT_ROLES_REGEX,
TEXT_ROLES+look_up_directives(TEXT_ROLES_REGEX,
path))`:\`$2\`\
endsnippet
@ -306,7 +290,7 @@ snippet chart "Pygal chart for Nikola" b
.. chart:: $1`!p snip.rv=complete(t[1], CHART_TYPES)`
:title: '${2:Browser usage evolution (in %)}'
:x_labels: [${3:"2002", "2003", "2004", "2005", "2006", "2007"}]
'Firefox', [None, None, 0, 16.6, 25, 31]
'Chrome', [None, None, None, None, None, None]
'IE', [85.8, 84.6, 84.7, 74.5, 66, 58.6]
@ -323,4 +307,5 @@ snippet sid "SideBar" b
${2:${VISUAL:SideBar Content}}
endsnippet
# vim:ft=snippets:
# vim:set list noet sts=0 sw=4 ts=4: