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

Indentation #4

Open
TomDeneire opened this issue Nov 23, 2022 · 2 comments
Open

Indentation #4

TomDeneire opened this issue Nov 23, 2022 · 2 comments
Assignees

Comments

@TomDeneire
Copy link

One possible improvement of the plugin would be to provide a Vim indentation file for MUMPS dotlevel indentation. I've tried to solve this by remapping in insert mode to a function that appends a line based on the previous one (and on what's under the cursor, ie do or quit), but didn't get it to work. Probably not even a good idea. Vim newbie here!

@dlwicksell dlwicksell self-assigned this Nov 23, 2022
@TomDeneire
Copy link
Author

Hi David,

thought I'd get back to you on the idea of remapping , because it has been working out fine for me.

My ftdetect/mumps.vim contains the following:

"functions
function! Indent()
    let wordUnderCursor = expand("<cword>")
    let current_line = getline(".")
    let indent_level = split(current_line," ")
    let indent_begin = indent_level[0]
    if (wordUnderCursor == "d") || (wordUnderCursor == "q")
        if (wordUnderCursor == "d")
            if matchstr(indent_begin, ".") == "."
                let indent = " " . indent_begin . ". "
            else
                let indent = " . "
            endif
        endif
        if (wordUnderCursor == "q")
            if indent_begin[0] == "."
                let indent_minus_one = len(indent_begin)-2
                if indent_minus_one == -1
                    let indent = " "
                else
                    let indent = " " . indent_begin[0:indent_minus_one] . " "
                endif
            else
                let indent = " "
            endif
        endif
    else
        " to do: normal linebreak!
        if indent_begin[0] == "."
            let indent = " " . indent_begin . " "
        else
            let indent = " "
        endif
    endif
    call append(line("."), indent)
    let curpos=getcurpos()
    let curpos[1] += 1
    call setpos(".", curpos)
    call feedkeys("A")
endfunction

autocmd FileType mumps inoremap <buffer> <TAB> .
autocmd FileType mumps inoremap <buffer> <CR> <ESC>:call Indent()<CR>
autocmd FileType mumps inoremap <buffer> <c-r> <CR>

You'll see this is far from perfect. It doesn't account for a midline enter, i.e. a "normal" one, hence the last remapping. Also, I have no experience in Vimscript whatsoever and I was struggling with scoping.

But I still thought I'd send you this in case you find it useful, also because I've just replaced the Vimscript version with a Lua one, since I'm using Neovim anyway.

all the best,

T.

@dlwicksell
Copy link
Owner

Thank you. I'll look at this when I get around to exploring this request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants