blob: 2390ab1cb974f7f66039c4f1b769b42b7b8d08d3 [file] [log] [blame]
Bram Moolenaardb6ea062014-07-10 22:01:47 +02001" Vim filetype plugin file
dkearnse93afc22024-03-03 05:27:47 +11002" Language: R Markdown file
3" Maintainer: This runtime file is looking for a new maintainer.
4" Former Maintainer: Jakson Alves de Aquino <jalvesaq@gmail.com>
5" Former Repository: https://github.com/jalvesaq/R-Vim-runtime
John M Devina7229c82024-09-23 20:09:33 +02006" Last Change:
7" 2024 Feb 28 by Vim Project
8" 2024 Sep 23 by Vim Project: properly restore fex option
Bram Moolenaare4a3bcf2016-08-26 19:52:37 +02009" Original work by Alex Zvoleff (adjusted from R help for rmd by Michel Kuhlmann)
Bram Moolenaardb6ea062014-07-10 22:01:47 +020010
11" Only do this when not yet done for this buffer
12if exists("b:did_ftplugin")
13 finish
14endif
15
Bram Moolenaarfc65cab2018-08-28 22:58:02 +020016if exists('g:rmd_include_html') && g:rmd_include_html
17 runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim
Bram Moolenaare4a3bcf2016-08-26 19:52:37 +020018endif
19
Bram Moolenaarfc65cab2018-08-28 22:58:02 +020020setlocal comments=fb:*,fb:-,fb:+,n:>
21setlocal commentstring=#\ %s
Bram Moolenaardb6ea062014-07-10 22:01:47 +020022setlocal formatoptions+=tcqln
23setlocal formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\|^\\s*[-*+]\\s\\+
24setlocal iskeyword=@,48-57,_,.
25
26let s:cpo_save = &cpo
27set cpo&vim
28
Bram Moolenaar71badf92023-04-22 22:40:14 +010029function FormatRmd()
Bram Moolenaarfc65cab2018-08-28 22:58:02 +020030 if search("^[ \t]*```[ ]*{r", "bncW") > search("^[ \t]*```$", "bncW")
31 setlocal comments=:#',:###,:##,:#
32 else
33 setlocal comments=fb:*,fb:-,fb:+,n:>
34 endif
35 return 1
36endfunction
37
Jakson Alves de Aquino34745942023-09-27 13:56:02 -030038let s:last_line = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010039function SetRmdCommentStr()
Jakson Alves de Aquino34745942023-09-27 13:56:02 -030040 if line('.') == s:last_line
41 return
42 endif
43 let s:last_line = line('.')
44
45 if (search("^[ \t]*```[ ]*{r", "bncW") > search("^[ \t]*```$", "bncW")) || ((search('^---$', 'Wn') || search('^\.\.\.$', 'Wn')) && search('^---$', 'bnW'))
46 set commentstring=#\ %s
47 else
48 set commentstring=<!--\ %s\ -->
49 endif
Bram Moolenaardd60c362023-02-27 15:49:53 +000050endfunction
51
52" If you do not want both 'comments' and 'commentstring' dynamically defined,
53" put in your vimrc: let g:rmd_dynamic_comments = 0
Bram Moolenaarfc65cab2018-08-28 22:58:02 +020054if !exists("g:rmd_dynamic_comments") || (exists("g:rmd_dynamic_comments") && g:rmd_dynamic_comments == 1)
55 setlocal formatexpr=FormatRmd()
Bram Moolenaardd60c362023-02-27 15:49:53 +000056 augroup RmdCStr
57 autocmd!
58 autocmd CursorMoved <buffer> call SetRmdCommentStr()
59 augroup END
Bram Moolenaarfc65cab2018-08-28 22:58:02 +020060endif
61
Bram Moolenaardb6ea062014-07-10 22:01:47 +020062" Enables pandoc if it is installed
63unlet! b:did_ftplugin
64runtime ftplugin/pandoc.vim
65
66" Don't load another plugin for this buffer
67let b:did_ftplugin = 1
68
Bram Moolenaar11e3c5b2021-04-21 18:09:37 +020069if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
dkearnse93afc22024-03-03 05:27:47 +110070 let b:browsefilter = "R Source Files (*.R, *.Rnw, *.Rd, *.Rmd, *.Rrst, *.qmd)\t*.R;*.Rnw;*.Rd;*.Rmd;*.Rrst;*.qmd\n"
Doug Kearns93197fd2024-01-14 20:59:02 +010071 if has("win32")
72 let b:browsefilter .= "All Files (*.*)\t*\n"
73 else
74 let b:browsefilter .= "All Files (*)\t*\n"
75 endif
Bram Moolenaardb6ea062014-07-10 22:01:47 +020076endif
77
78if exists('b:undo_ftplugin')
John M Devina7229c82024-09-23 20:09:33 +020079 let b:undo_ftplugin .= " | setl cms< com< fo< flp< isk< fex< | unlet! b:browsefilter"
Bram Moolenaardb6ea062014-07-10 22:01:47 +020080else
John M Devina7229c82024-09-23 20:09:33 +020081 let b:undo_ftplugin = "setl cms< com< fo< flp< isk< fex< | unlet! b:browsefilter"
Bram Moolenaardb6ea062014-07-10 22:01:47 +020082endif
83
84let &cpo = s:cpo_save
85unlet s:cpo_save
86
87" vim: sw=2