Got a vimwiki function:

function! vimwiki#base#is_diary_file(filename, ...) abort
  echo a:filename
  let l:diary_file_paths = a:0 > 0 ? a:1 : vimwiki#diary#get_diary_files()
  let l:normalised_file_paths =
        \ map(l:diary_file_paths, 'vimwiki#path#normalize(v:val)')
  echo l:normalised_file_paths
  let l:matching_files =
        \ filter(l:normalised_file_paths, 'v:val =~# a:filename')
"  return len(l:matching_files) > 0 " filename is a diary file if match is found

Throws this error:

line    6:
E874: (NFA) Could not pop the stack!

a:filename is equal to /Users/me/Library/Mobile Documents/com~apple~CloudDocs/Documents/vimwiki/webnotes/Politics.md

l:normalised_file_path is:

['/Users/me/Library/Mobile Documents/com~apple~CloudDocs/Documents/vimwiki/webnotes//2020-07-13.md', '/Users/me/Library/Mobile Documents/com~apple~CloudDocs/Documents/vimwiki/webnotes//2020-07-14.md', '/Users/me/Library/Mobile Documents/com~apple~CloudDocs/Documents/vimwiki/webnotes//2020-07-15.md', '/Users/me/Library/Mobile Documents/com~apple~CloudDocs/Documents/vimwiki/webnotes//2020-07-16.md', '/Users/me/Library/Mobile Documents/com~apple~CloudDocs/Documents/vimwiki/webnotes//2020-07-17.md', '/Users/me/Library/Mobile Documents/com~apple~CloudDocs/Documents/vimwiki/webnotes//2020-07-18.md', '/Users/me/Library/Mobile Documents/com~apple~CloudDocs/Documents/vimwiki/webnotes//2020-07-19.md', '/Users/me/Library/Mobile Documents/com~apple~CloudDocs/Documents/vimwiki/webnotes//2020-07-20.md', '/Users/me/Library/Mobile Documents/com~apple~CloudDocs/Documents/vimwiki/webnotes//2020-07-21.md', '/Users/me/Library/Mobile Documents/com~apple~CloudDocs/Documents/vimwiki/webnotes//2020-07-22.md', '/Users/me/Library/Mobile Documents/com~apple~CloudDocs/Documents/vimwiki/webnotes//2020-07-23.md', '/Users/me/Library/Mobile Documents/com~apple~CloudDocs/Documents/vimwiki/webnotes//2020-07-24.md', '/Users/me/Library/Mobile Documents/com~apple~CloudDocs/Documents/vimwiki/webnotes//2020-07-25.md', '/Users/me/Library/Mobile Documents/com~apple~CloudDocs/Documents/vimwiki/webnotes//2020-07-26.md', '/Users/me/Library/Mobile Documents/com~apple~CloudDocs/Documents/vimwiki/webnotes//2020-07-27.md', '/Users/me/Library/Mobile Documents/com~apple~CloudDocs/Documents/vimwiki/webnotes//2020-07-28.md', '/Users/me/Library/Mobile Documents/com~apple~CloudDocs/Documents/vimwiki/webnotes//2020-07-29.md', '/Users/me/Library/Mobile Documents/com~apple~CloudDocs/Documents/vimwiki/webnotes//2020-08-17.md', '/Users/me/Library/Mobile Documents/com~apple~CloudDocs/Documents/vimwiki/webnotes//2020-08-18.md', '/Users/me/Library/Mobile Documents/com~apple~CloudDocs/Documents/vimwiki/webnotes//2020-08-19.md', '/Users/me/Library/Mobile Documents/com~apple~CloudDocs/Documents/vimwiki/webnotes//2020-08-23.md', '/Users/me/Library/Mobile Documents/com~apple~CloudDocs/Documents/vimwiki/webnotes//2020-08-24.md', '/Users/me/Library/Mobile Documents/com~apple~CloudDocs/Documents/vimwiki/webnotes//2020-08-25.md', '/Users/me/Library/Mobile Documents/com~apple~CloudDocs/Documents/vimwiki/webnotes//2020-08-26.md', '/Users/me/Library/Mobile Documents/com~apple~CloudDocs/Documents/vimwiki/webnotes//2020-08-27.md']

Any idea why I might be getting that error?


That code is using operator =~ in the 'v:val =~# a:filename' expression and =~ is trying to evaluate a:filename as a pattern (regex) to match it against the values in the list. See :help expr-=~.

On the other hand, your a:filename includes the character ~ (twice) and that character is special in a Vim regex: it references the last replacement string used in a :s substitute command. See :help /~.

If you don't have a last substitute command (so no previous replacement), Vim will complain about it, unfortunately using the cryptic message you're seeing: E874: (NFA) Could not pop the stack!. BTW, often you'll find more context about a Vim error with :help E874 (though in this case it doesn't seem to help much.) Also, "NFA" is an acronym for "nondeterministic finite automata" and it's one of the two regex engines available in Vim, the newest one.

In any case, the problem here seems to be that the code is using a:filename as a regex, when in fact it doesn't really seem to be one (or directly usable as one...) Perhaps this was meant to be a substring match and =~ worked in the majority of cases... Perhaps all this needs is to include '\V' before a:filename to invoke "very nomagic" mode for regexes, where only \ is special, possibly combining it with escape() to take care of the \s.

A possible workaround is to move your Vimwiki to a directory that doesn't contain ~ characters in its name.

This code seems to be part of the upstream Vimwiki, so please consider filing an issue upstream, to have it fixed.

  • 1
    Thanks so much for the thorough explanation. I learned something. This error started happening after getting a new iMac and I think my path to iCloud changed, somehow. I put this new path in my vimrc file and that solved the problem. – StevieD Sep 15 '20 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.