Skip to content

Commit 0684800

Browse files
saccarosiumchrisbra
authored andcommitted
patch 9.1.0865: filetype: org files are not recognized
Problem: filetype: org files are not recognized Solution: detect '*.org' files as 'org' filetype, include filetype and syntax plugin (Luca Saccarola) closes: #16054 Signed-off-by: Luca Saccarola <github.e41mv@aleeas.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 4bd9b2b commit 0684800

6 files changed

Lines changed: 130 additions & 1 deletion

File tree

runtime/doc/filetype.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*filetype.txt* For Vim version 9.1. Last change: 2024 Nov 12
1+
*filetype.txt* For Vim version 9.1. Last change: 2024 Nov 14
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -843,6 +843,12 @@ To enable folding use this: >
843843
let g:markdown_recommended_style = 0
844844
845845
846+
ORG *ft-org-plugin*
847+
848+
To enable folding use this: >
849+
let g:org_folding = 1
850+
<
851+
846852
PDF *ft-pdf-plugin*
847853

848854
Two maps, <C-]> and <C-T>, are provided to simulate a tag stack for navigating

runtime/filetype.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,9 @@ au BufNewFile,BufRead *.markdown,*.mdown,*.mkd,*.mkdn,*.mdwn,*.md
14721472
\ setf markdown |
14731473
\ endif
14741474

1475+
" Org (Emacs' org-mode)
1476+
au BufNewFile,BufRead *.org setf org
1477+
14751478
" Mason (it used to include *.comp, are those Mason files?)
14761479
au BufNewFile,BufRead *.mason,*.mhtml setf mason
14771480

runtime/ftplugin/org.vim

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
" Vim filetype plugin file
2+
" Language: Org
3+
" Maintainer: Luca Saccarola <github.e41mv@aleeas.com>
4+
" Last Change: 2024 Nov 14
5+
6+
if exists("b:did_ftplugin")
7+
finish
8+
endif
9+
let b:did_ftplugin = 1
10+
11+
if exists('b:undo_ftplugin')
12+
let b:undo_ftplugin .= "|setl cms< com< fo< flp<"
13+
else
14+
let b:undo_ftplugin = "setl cms< com< fo< flp<"
15+
endif
16+
17+
setl commentstring=#\ %s
18+
setl comments=fb:*,fb:-,fb:+,b:#,b:\:
19+
20+
setl formatoptions+=nql
21+
setl formatlistpat=^\\s*\\(\\(\\d\\|\\a\\)\\+[.)]\\|[+-]\\)\\s\\+
22+
23+
function OrgFoldExpr()
24+
let l:depth = match(getline(v:lnum), '\(^\*\+\)\@<=\( .*$\)\@=')
25+
if l:depth > 0 && synIDattr(synID(v:lnum, 1, 1), 'name') =~# '\m^orgHeadline'
26+
return ">" . l:depth
27+
endif
28+
return "="
29+
endfunction
30+
31+
if has("folding") && get(g:, 'org_folding', 0)
32+
setl foldexpr=OrgFoldExpr()
33+
setl foldmethod=expr
34+
let b:undo_ftplugin .= "|setl foldexpr< foldmethod<"
35+
endif
36+
37+
" vim: ts=8 sts=2 sw=2 et

runtime/syntax/org.vim

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
" Vim syntax file
2+
" Language: Org
3+
" Maintainer: Luca Saccarola <github.e41mv@aleeas.com>
4+
" Last Change: 2024 Nov 14
5+
"
6+
" Reference Specification: Org mode manual
7+
" GNU Info: `$ info Org`
8+
" Web: <https://orgmode.org/manual/index.html>
9+
10+
" Quit when a (custom) syntax file was already loaded
11+
if exists("b:current_syntax")
12+
finish
13+
endif
14+
let b:current_syntax = 'org'
15+
16+
syn case ignore
17+
18+
" Bold
19+
syn region orgBold matchgroup=orgBoldDelimiter start="\(^\|[- '"({\]]\)\@<=\*\ze[^ ]" end="^\@!\*\([^\k\*]\|$\)\@=" keepend
20+
hi def link orgBold markdownBold
21+
hi def link orgBoldDelimiter orgBold
22+
23+
" Italic
24+
syn region orgItalic matchgroup=orgItalicDelimiter start="\(^\|[- '"({\]]\)\@<=\/\ze[^ ]" end="^\@!\/\([^\k\/]\|$\)\@=" keepend
25+
hi def link orgItalic markdownItalic
26+
hi def link orgItalicDelimiter orgItalic
27+
28+
" Strikethrogh
29+
syn region orgStrikethrough matchgroup=orgStrikethroughDelimiter start="\(^\|[ '"({\]]\)\@<=+\ze[^ ]" end="^\@!+\([^\k+]\|$\)\@=" keepend
30+
hi def link orgStrikethrough markdownStrike
31+
hi def link orgStrikethroughDelimiter orgStrikethrough
32+
33+
" Underline
34+
syn region orgUnderline matchgroup=orgUnderlineDelimiter start="\(^\|[- '"({\]]\)\@<=_\ze[^ ]" end="^\@!_\([^\k_]\|$\)\@=" keepend
35+
36+
" Headlines
37+
syn match orgHeadline "^\*\+\s\+.*$" keepend
38+
hi def link orgHeadline Title
39+
40+
" Line Comment
41+
syn match orgLineComment /^\s*#\s\+.*$/ keepend
42+
hi def link orgLineComment Comment
43+
44+
" Block Comment
45+
syn region orgBlockComment matchgroup=orgBlockCommentDelimiter start="\c^\s*#+BEGIN_COMMENT" end="\c^\s*#+END_COMMENT" keepend
46+
hi def link orgBlockComment Comment
47+
hi def link orgBlockCommentDelimiter Comment
48+
49+
" Lists
50+
syn match orgUnorderedListMarker "^\s*[-+]\s\+" keepend
51+
hi def link orgUnorderedListMarker markdownOrderedListMarker
52+
syn match orgOrderedListMarker "^\s*\(\d\|\a\)\+[.)]\s\+" keepend
53+
hi def link orgOrderedListMarker markdownOrderedListMarker
54+
"
55+
" Verbatim
56+
syn region orgVerbatimInline matchgroup=orgVerbatimInlineDelimiter start="\(^\|[- '"({\]]\)\@<==\ze[^ ]" end="^\@!=\([^\k=]\|$\)\@=" keepend
57+
hi def link orgVerbatimInline markdownCodeBlock
58+
hi def link orgVerbatimInlineDelimiter orgVerbatimInline
59+
syn region orgVerbatimBlock matchgroup=orgVerbatimBlockDelimiter start="\c^\s*#+BEGIN_.*" end="\c^\s*#+END_.*" keepend
60+
hi def link orgVerbatimBlock orgCode
61+
hi def link orgVerbatimBlockDelimiter orgVerbatimBlock
62+
63+
" Code
64+
syn region orgCodeInline matchgroup=orgCodeInlineDelimiter start="\(^\|[- '"({\]]\)\@<=\~\ze[^ ]" end="^\@!\~\([^\k\~]\|$\)\@=" keepend
65+
highlight def link orgCodeInline markdownCodeBlock
66+
highlight def link orgCodeInlineDelimiter orgCodeInline
67+
syn region orgCodeBlock matchgroup=orgCodeBlockDelimiter start="\c^\s*#+BEGIN_SRC.*" end="\c^\s*#+END_SRC" keepend
68+
highlight def link orgCodeBlock markdownCodeBlock
69+
highlight def link orgCodeBlockDelimiter orgCodeBlock
70+
71+
" vim: ts=8 sts=2 sw=2 et

src/testdir/test_filetype.vim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2724,4 +2724,14 @@ func Test_make_file()
27242724
filetype off
27252725
endfunc
27262726

2727+
func Test_org_file()
2728+
filetype on
2729+
2730+
call writefile(['* org Headline', '*some bold text*', '/some italic text/'], 'Xfile.org', 'D')
2731+
split Xfile.org
2732+
call assert_equal('org', &filetype)
2733+
2734+
filetype off
2735+
endfunc
2736+
27272737
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
865,
707709
/**/
708710
864,
709711
/**/

0 commit comments

Comments
 (0)