def make_diary( nvim: Nvim, options: PluginOptions, gcal_service: SimpleNvimGoogleCal, github_service: SimpleNvimGithub, auto_command: bool = False, ) -> None: """make_diary Make the actual diary markdown file. This includes the following steps: * Open the file if it already exists. * If not, put the default template in and save. """ # If the buffer is not empty, don't continue. Issue an error if manually # called, don't issue an error for an autocommand. if not is_buffer_empty(nvim): if not auto_command: nvim.err_write("Buffer is not empty, can't create diary.\n") return # If options is none, then everything else probably wasn't setup either. if options is None: nvim.err_write("Options weren't initialised, aborting.\n") return full_markdown: List[str] = [] diary_date: str = get_diary_date(nvim) diary_metadata: Dict[str, str] = {"Date": diary_date} full_markdown.extend(generate_markdown_metadata(diary_metadata)) set_buffer_contents(nvim, full_markdown) for heading in options.daily_headings: full_markdown.append(f"## {heading}") full_markdown.append("") set_buffer_contents(nvim, full_markdown) # Add in issues section issues: List[GitHubIssue] = [] if options.use_github_repo and github_service and github_service.active: issues = github_service.active_issues issue_markdown: List[str] = produce_issue_markdown(options, issues) full_markdown.extend(issue_markdown) set_buffer_contents(nvim, full_markdown) # Add in the calendar entries days_events: List[CalendarEvent] = [] if options.use_google_calendar and gcal_service and gcal_service.active: date_today_object: date = parser.parse(diary_date).date() if date_today_object == date.today(): days_events = gcal_service.active_events else: days_events = gcal_service.get_events_for_date(date_today_object) schedule_markdown: List[str] = produce_schedule_markdown(days_events) full_markdown.extend(schedule_markdown) # Set the buffer contents and save the file. set_buffer_contents(nvim, full_markdown) nvim.command(":w") if options.auto_generate_diary_index: generate_diary_index(options)
def error(vim: Nvim, expr): string = (expr if isinstance(expr, str) else str(expr)) vim.call('denite#util#print_error', string)
def clear_cmdline(vim: Nvim): vim.command('redraw | echo')
def echo(vim: Nvim, color, string): vim.call('denite#util#echo', color, string)
def debug(vim: Nvim, expr): if hasattr(vim, 'out_write'): string = (expr if isinstance(expr, str) else str(expr)) return vim.out_write('[denite] ' + string + '\n') else: print(expr)
def confirm(vim: Nvim, question: str) -> bool: """ Confirm action """ option: int = vim.call('confirm', question, '&Yes\n&No\n&Cancel') return option == 1
def path2project(vim: Nvim, path: str, root_markers: typing.List[str]) -> str: return str( vim.call('denite#project#path2project_directory', path, root_markers))
def path2project(vim: Nvim, path, root_markers): return vim.call('denite#project#path2project_directory', path, root_markers)
def abspath(vim: Nvim, path): return normpath(join(vim.call('getcwd'), expand(path)))
def debug(vim: Nvim, expr: typing.Any) -> None: if hasattr(vim, 'out_write'): string = (expr if isinstance(expr, str) else str(expr)) vim.out_write('[denite] ' + string + '\n') else: print(expr)
def test_get_all_windows(vim: Nvim) -> None: vim.command("edit text1") vim.command("split text2") vim.command("split text3") vim.command("split text4") vim.command("tabnew") vim.command("edit text5") vim.command("split text6") vim.command("split text7") vim.command("split text8") vim.command("tabnext") w = Window(vim) for c in [ { "no_current": False, "expected": [ [ "text4", "1: [1/4] % text4", 1, 1, ], [ "text3", "1: [2/4] # text3", 1, 2, ], [ "text2", "1: [3/4] text2", 1, 3, ], [ "text1", "1: [4/4] $ text1", 1, 4, ], [ "text8", "2: [1/4] text8", 2, 1, ], [ "text7", "2: [2/4] text7", 2, 2, ], [ "text6", "2: [3/4] text6", 2, 3, ], [ "text5", "2: [4/4] text5", 2, 4, ], ], }, { "no_current": True, "expected": [ [ "text3", "1: [2/4] # text3", 1, 2, ], [ "text2", "1: [3/4] text2", 1, 3, ], [ "text1", "1: [4/4] $ text1", 1, 4, ], [ "text8", "2: [1/4] text8", 2, 1, ], [ "text7", "2: [2/4] text7", 2, 2, ], [ "text6", "2: [3/4] text6", 2, 3, ], [ "text5", "2: [4/4] text5", 2, 4, ], ], }, ]: expected = [{ "word": x[0], "abbr": x[1], "action__tabnr": x[2], "action__winnr": x[3] } for x in cast(List[Any], c["expected"])] assert expected == w.get_all_windows(c["no_current"])
def echo(vim: Nvim, color: str, string: str) -> None: vim.call('denite#util#echo', color, string)
def set_default(vim: Nvim, var: str, val: typing.Any) -> typing.Any: return vim.call('denite#util#set_default', var, val)
def relpath(vim: Nvim, path: str) -> str: return str(normpath(vim.call('fnamemodify', expand(path), ':~:.')))
def cd(vim: Nvim, path: str) -> None: vim.call('defx#util#cd', path)
def relpath(vim: Nvim, path): return normpath(vim.call('fnamemodify', expand(path), ':~:.'))
def error(vim: Nvim, expr: typing.Any) -> None: """ Prints the error messages to Vim/Nvim's :messages buffer. """ vim.call('defx#util#print_error', expr)
def set_default(vim: Nvim, var, val): return vim.call('denite#util#set_default', var, val)
def _bigger_preview(nvim: Nvim, stack: Stack, args: Tuple[str, Sequence[str]]) -> None: syntax, lines = args nvim.command("stopinsert") set_preview(nvim, syntax=syntax, preview=lines)
def strwidth(vim: Nvim, word: str) -> int: return (int(vim.call('strwidth', word)) if len(word) != len(bytes(word, 'utf-8', 'surrogatepass')) else len(word))