From a0cf898ca52409a1073a4d3cf97d9650eb39eb82 Mon Sep 17 00:00:00 2001 From: cannorin Date: Fri, 1 Nov 2024 11:32:31 +0900 Subject: [PATCH 1/2] Use the OS-specific newline when passing code to FSI --- autoload/fsharp.vim | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/autoload/fsharp.vim b/autoload/fsharp.vim index 275e8e3..500bf20 100644 --- a/autoload/fsharp.vim +++ b/autoload/fsharp.vim @@ -25,6 +25,16 @@ function! s:prompt(msg) let &cmdheight = height endfunction +function! s:get_newline() + if &fileformat == 'dos' + return "\r\n" + elseif &fileformat == 'mac' + return "\r" + else + return "\n" + endif +endfunction +let s:newline = s:get_newline() " FSAC payload interfaces @@ -661,7 +671,7 @@ function! fsharp#sendFsi(text) if fsharp#openFsi(!g:fsharp#fsi_focus_on_send) > 0 " Neovim if has('nvim') - call chansend(s:fsi_job, a:text . "\n" . ";;". "\n") + call chansend(s:fsi_job, a:text . s:newline . ";;". s:newline) " Vim 8 else call term_sendkeys(s:fsi_buffer, a:text . "\" . ";;" . "\") @@ -684,13 +694,13 @@ function! s:get_visual_selection() endfunction function! s:get_complete_buffer() - return join(getline(1, '$'), "\n") + return join(getline(1, '$'), s:newline) endfunction function! fsharp#sendSelectionToFsi() range let lines = s:get_visual_selection() exec 'normal' len(lines) . 'j' - let text = join(lines, "\n") + let text = join(lines, s:newline) return fsharp#sendFsi(text) endfunction From a9eda69541946c7909b1c3500576781dbb2dc66f Mon Sep 17 00:00:00 2001 From: cannorin Date: Sun, 3 Nov 2024 14:49:26 +0900 Subject: [PATCH 2/2] Use the OS-specific newline when passing code to FSI (2) Use `has('win32')` to counter the case where a Windows user is editing UNIX text files --- autoload/fsharp.vim | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/autoload/fsharp.vim b/autoload/fsharp.vim index 500bf20..c166897 100644 --- a/autoload/fsharp.vim +++ b/autoload/fsharp.vim @@ -26,10 +26,8 @@ function! s:prompt(msg) endfunction function! s:get_newline() - if &fileformat == 'dos' + if has('win32') || &fileformat == 'dos' return "\r\n" - elseif &fileformat == 'mac' - return "\r" else return "\n" endif