mirrored 16 minutes ago
0
Your Namefix type error, fix custom challenge b90d114
import vimgolf.vimgolf
import os
import tempfile
import atexit

_VIMGOLF_VIMRC_FILEPATH = os.path.join(
    os.path.dirname(vimgolf.vimgolf.__file__), "vimgolf.vimrc"
)

_CYBERGOD_VIMGOLF_CONFIG_TMPDIR = tempfile.TemporaryDirectory()
atexit.register(_CYBERGOD_VIMGOLF_CONFIG_TMPDIR.cleanup)


def _prepare_vimrc_content_with_buffer_file(buffer_file: str):
    buffer_file = os.path.abspath(buffer_file)
    ret = f"""
" http://vimdoc.sourceforge.net/htmldoc/starting.html#vimrc

set nocompatible        " use vim defaults
set scrolloff=3         " keep 3 lines when scrolling
set ai                  " set auto-indenting on for programming

set showcmd             " display incomplete commands
set nobackup            " do not keep a backup file
set number              " show line numbers
set ruler               " show the current row and column

set hlsearch            " highlight searches
set incsearch           " do incremental searching
set showmatch           " jump to matches when entering regexp
set ignorecase          " ignore case when searching
set smartcase           " no ignorecase if Uppercase char present

set visualbell t_vb=    " turn off error beep/flash
set novisualbell        " turn off visual bell

set backspace=indent,eol,start  " make that backspace key work the way it should
set runtimepath=$VIMRUNTIME     " turn off user scripts
                                " https://github.com/igrigorik/vimgolf/issues/129

syntax on               " turn syntax highlighting on by default
filetype on             " detect type of file
filetype indent on      " load indent file for specific file type

set t_RV=               " http://bugs.debian.org/608242
                        " http://groups.google.com/group/vim_dev/browse_thread/
                        "        thread/9770ea844cec3282

autocmd TextChanged,TextChangedI * write! {buffer_file}
                        "use write! instead of write for overwriting
"""
    return ret


_CYBERGOD_VIMGOLF_VIMRC_FILEPATH = os.path.join(
    _CYBERGOD_VIMGOLF_CONFIG_TMPDIR.name, "cybergod_vimgolf.vimrc"
)


def _prepare_cybergod_vimrc_with_buffer_file(buffer_file: str):
    content = _prepare_vimrc_content_with_buffer_file(buffer_file)

    with open(_CYBERGOD_VIMGOLF_VIMRC_FILEPATH, "w+") as f:
        f.write(content)


__all__ = [
    "_CYBERGOD_VIMGOLF_VIMRC_FILEPATH",
    "_prepare_cybergod_vimrc_with_buffer_file",
    "_VIMGOLF_VIMRC_FILEPATH",
]