vim-orgmode icon indicating copy to clipboard operation
vim-orgmode copied to clipboard

E117: Unknown function: <SNR>69_ReadTodoKeywords

Open athanassis opened this issue 3 years ago • 1 comments

Hi, I have installed vim-orgmode with pathogen and python 3.10.7. I get this message for the unknown function ReadTodoKeywords. The function seems to be used or defined in these files:

thanos@win10-ubuntu:/mnt/c/Users/adamis/vimfiles $ grep -ril ReadTodoKeywords * bundle/vim-orgmode/syntax/org.vim bundle/vim-orgmode/syntax/orgagenda.vim bundle/vim-orgmode/syntax/orgtodo.vim pack/git-plugins/start/vim-orgmode/syntax/org.vim pack/git-plugins/start/vim-orgmode/syntax/orgagenda.vim pack/git-plugins/start/vim-orgmode/syntax/orgtodo.vim

Any pointers what could be the problem?

athanassis avatar Sep 19 '22 14:09 athanassis

Ran into the same issue multiple times and just now decided to dig a little deeper.

My environment is:

  • Arch Linux
  • vim 9.1
  • plugin manager: vim-plug
  • installed plugins and their git-describe:
    • NrrwRgn e027db9
    • ale 699c0db
    • calendar-vim 2083a41
    • nerdtree 7.1.3
    • tabular 12437cd
    • tagbar 8de7694
    • taglist 97b001b
    • utl.vim 3.0a-ALPHA
    • vim-SyntaxRange 78004d2
    • vim-colors-solarized 528a59f
    • vim-markdown 8f6cb3a
    • vim-orgmode 8398234
    • vim-repeat 6584602
    • vim-speeddating c17eb01

I found that the global variable g:loaded_org_syntax seems to be the culprit. It is nowhere else referenced than in syntax/org.vim, so I removed it alongside with the exists() check:

diff --git a/syntax/org.vim b/syntax/org.vim
index f295f8f..18c8d20 100644
--- a/syntax/org.vim
+++ b/syntax/org.vim
@@ -110,122 +110,118 @@ while s:i <= g:org_heading_highlight_levels
 endwhile
 unlet! s:i

-if !exists('g:loaded_org_syntax')
-	let g:loaded_org_syntax = 1
-
-	function! OrgExtendHighlightingGroup(base_group, new_group, settings)
-		let l:base_hi = ''
-		redir => l:base_hi
-		silent execute 'highlight ' . a:base_group
-		redir END
-		let l:group_hi = substitute(split(l:base_hi, '\n')[0], '^' . a:base_group . '\s\+xxx', '', '')
-		execute 'highlight ' . a:new_group . l:group_hi . ' ' . a:settings
-	endfunction
-
-	function! OrgInterpretFaces(faces)
-		let l:res_faces = ''
-		if type(a:faces) == 3
-			let l:style = []
-			for l:f in a:faces
-				let l:_f = [l:f]
-				if type(l:f) == 3
-					let l:_f = l:f
-				endif
-				for l:g in l:_f
-					if type(l:g) == 1 && l:g =~ '^:'
-						if l:g !~ '[\t ]'
-							continue
-						endif
-						let l:k_v = split(l:g)
-						if l:k_v[0] == ':foreground'
-							let l:gui_color = ''
-							let l:found_gui_color = 0
-							for l:color in split(l:k_v[1], ',')
-								if l:color =~ '^#'
-									let l:found_gui_color = 1
-									let l:res_faces = l:res_faces . ' guifg=' . l:color
-								elseif l:color != ''
-									let l:gui_color = l:color
-									let l:res_faces = l:res_faces . ' ctermfg=' . l:color
-								endif
-							endfor
-							if ! l:found_gui_color && l:gui_color != ''
-								let l:res_faces = l:res_faces . ' guifg=' . l:gui_color
-							endif
-						elseif l:k_v[0] == ':background'
-							let l:gui_color = ''
-							let l:found_gui_color = 0
-							for l:color in split(l:k_v[1], ',')
-								if l:color =~ '^#'
-									let l:found_gui_color = 1
-									let l:res_faces = l:res_faces . ' guibg=' . l:color
-								elseif l:color != ''
-									let l:gui_color = l:color
-									let l:res_faces = l:res_faces . ' ctermbg=' . l:color
-								endif
-							endfor
-							if ! l:found_gui_color && l:gui_color != ''
-								let l:res_faces = l:res_faces . ' guibg=' . l:gui_color
+function! OrgExtendHighlightingGroup(base_group, new_group, settings)
+	let l:base_hi = ''
+	redir => l:base_hi
+	silent execute 'highlight ' . a:base_group
+	redir END
+	let l:group_hi = substitute(split(l:base_hi, '\n')[0], '^' . a:base_group . '\s\+xxx', '', '')
+	execute 'highlight ' . a:new_group . l:group_hi . ' ' . a:settings
+endfunction
+
+function! OrgInterpretFaces(faces)
+	let l:res_faces = ''
+	if type(a:faces) == 3
+		let l:style = []
+		for l:f in a:faces
+			let l:_f = [l:f]
+			if type(l:f) == 3
+				let l:_f = l:f
+			endif
+			for l:g in l:_f
+				if type(l:g) == 1 && l:g =~ '^:'
+					if l:g !~ '[\t ]'
+						continue
+					endif
+					let l:k_v = split(l:g)
+					if l:k_v[0] == ':foreground'
+						let l:gui_color = ''
+						let l:found_gui_color = 0
+						for l:color in split(l:k_v[1], ',')
+							if l:color =~ '^#'
+								let l:found_gui_color = 1
+								let l:res_faces = l:res_faces . ' guifg=' . l:color
+							elseif l:color != ''
+								let l:gui_color = l:color
+								let l:res_faces = l:res_faces . ' ctermfg=' . l:color
 							endif
-						elseif l:k_v[0] == ':weight' || l:k_v[0] == ':slant' || l:k_v[0] == ':decoration'
-							if index(l:style, l:k_v[1]) == -1
-								call add(l:style, l:k_v[1])
+						endfor
+						if ! l:found_gui_color && l:gui_color != ''
+							let l:res_faces = l:res_faces . ' guifg=' . l:gui_color
+						endif
+					elseif l:k_v[0] == ':background'
+						let l:gui_color = ''
+						let l:found_gui_color = 0
+						for l:color in split(l:k_v[1], ',')
+							if l:color =~ '^#'
+								let l:found_gui_color = 1
+								let l:res_faces = l:res_faces . ' guibg=' . l:color
+							elseif l:color != ''
+								let l:gui_color = l:color
+								let l:res_faces = l:res_faces . ' ctermbg=' . l:color
 							endif
+						endfor
+						if ! l:found_gui_color && l:gui_color != ''
+							let l:res_faces = l:res_faces . ' guibg=' . l:gui_color
+						endif
+					elseif l:k_v[0] == ':weight' || l:k_v[0] == ':slant' || l:k_v[0] == ':decoration'
+						if index(l:style, l:k_v[1]) == -1
+							call add(l:style, l:k_v[1])
 						endif
-					elseif type(l:g) == 1
-						" TODO emacs interprets the color and automatically determines
-						" whether it should be set as foreground or background color
-						let l:res_faces = l:res_faces . ' ctermfg=' . l:k_v[1] . ' guifg=' . l:k_v[1]
 					endif
-				endfor
-			endfor
-			let l:s = ''
-			for l:i in l:style
-				if l:s == ''
-					let l:s = l:i
-				else
-					let l:s = l:s . ','. l:i
+				elseif type(l:g) == 1
+					" TODO emacs interprets the color and automatically determines
+					" whether it should be set as foreground or background color
+					let l:res_faces = l:res_faces . ' ctermfg=' . l:k_v[1] . ' guifg=' . l:k_v[1]
 				endif
 			endfor
-			if l:s != ''
-				let l:res_faces = l:res_faces . ' term=' . l:s . ' cterm=' . l:s . ' gui=' . l:s
+		endfor
+		let l:s = ''
+		for l:i in l:style
+			if l:s == ''
+				let l:s = l:i
+			else
+				let l:s = l:s . ','. l:i
 			endif
-		elseif type(a:faces) == 1
-			" TODO emacs interprets the color and automatically determines
-			" whether it should be set as foreground or background color
-			let l:res_faces = l:res_faces . ' ctermfg=' . a:faces . ' guifg=' . a:faces
+		endfor
+		if l:s != ''
+			let l:res_faces = l:res_faces . ' term=' . l:s . ' cterm=' . l:s . ' gui=' . l:s
 		endif
-		return l:res_faces
-	endfunction
-
-	function! s:ReadTodoKeywords(keywords, todo_headings)
-		let l:default_group = 'Todo'
-		for l:i in a:keywords
-			if type(l:i) == 3
-				call s:ReadTodoKeywords(l:i, a:todo_headings)
-				continue
-			endif
-			if l:i == '|'
-				let l:default_group = 'Question'
-				continue
+	elseif type(a:faces) == 1
+		" TODO emacs interprets the color and automatically determines
+		" whether it should be set as foreground or background color
+		let l:res_faces = l:res_faces . ' ctermfg=' . a:faces . ' guifg=' . a:faces
+	endif
+	return l:res_faces
+endfunction
+
+function! s:ReadTodoKeywords(keywords, todo_headings)
+	let l:default_group = 'Todo'
+	for l:i in a:keywords
+		if type(l:i) == 3
+			call s:ReadTodoKeywords(l:i, a:todo_headings)
+			continue
+		endif
+		if l:i == '|'
+			let l:default_group = 'Question'
+			continue
+		endif
+		" strip access key
+		let l:_i = substitute(l:i, "\(.*$", "", "")
+		let l:safename = substitute(l:_i, "\\W", "\\=('u' . char2nr(submatch(0)))", "g")
+
+		let l:group = l:default_group
+		for l:j in g:org_todo_keyword_faces
+			if l:j[0] == l:_i
+				let l:group = 'org_todo_keyword_face_' . l:safename
+				call OrgExtendHighlightingGroup(l:default_group, l:group, OrgInterpretFaces(l:j[1]))
+				break
 			endif
-			" strip access key
-			let l:_i = substitute(l:i, "\(.*$", "", "")
-			let l:safename = substitute(l:_i, "\\W", "\\=('u' . char2nr(submatch(0)))", "g")
-
-			let l:group = l:default_group
-			for l:j in g:org_todo_keyword_faces
-				if l:j[0] == l:_i
-					let l:group = 'org_todo_keyword_face_' . l:safename
-					call OrgExtendHighlightingGroup(l:default_group, l:group, OrgInterpretFaces(l:j[1]))
-					break
-				endif
-			endfor
-			silent! exec 'syntax match org_todo_keyword_' . l:safename . ' /\*\{1,\}\s\{1,\}\zs' . l:_i .'\(\s\|$\)/ ' . a:todo_headings . ' contains=@NoSpell'
-			silent! exec 'hi def link org_todo_keyword_' . l:safename . ' ' . l:group
 		endfor
-	endfunction
-endif
+		silent! exec 'syntax match org_todo_keyword_' . l:safename . ' /\*\{1,\}\s\{1,\}\zs' . l:_i .'\(\s\|$\)/ ' . a:todo_headings . ' contains=@NoSpell'
+		silent! exec 'hi def link org_todo_keyword_' . l:safename . ' ' . l:group
+	endfor
+endfunction

 call s:ReadTodoKeywords(g:org_todo_keywords, s:todo_headings)
 unlet! s:todo_headings

This seems to do the trick. However: I have no idea whether or not somebody else would rely on g:loaded_org_syntax.

@jceb, could you comment on that? How bad of an idea would this be?

hoedur avatar Feb 21 '25 12:02 hoedur