ledger / vim-ledger

Vim plugin for Ledger
GNU General Public License v2.0
374 stars 54 forks source link

vim-ledger spews errors #143

Open l29ah opened 1 year ago

l29ah commented 1 year ago

vim 9.0 here. Todays master tells me this when i open a ledger file:

Error detected while processing /etc/vim/vimrc[92]../usr/share/vim/vim90/syntax/syntax.vim[43]..BufRead Autocommands for "*.ldg"..FileType Autocommands for "*"..Syntax Autocommands for "*"..function <SNR>3_SynSet[25]..script /usr/share/vim/vimfiles/syntax/ledger.vim:
line   15:
E121: Undefined variable: g:ledger_is_hledger
line   22:
E121: Undefined variable: b:is_hledger
line   70:
E121: Undefined variable: s:line_comment_chars
line   74:
E121: Undefined variable: b:is_hledger
line   88:
E121: Undefined variable: b:is_hledger
line  147:
E121: Undefined variable: b:is_hledger
alerque commented 1 year ago

Hm, interesting. This indicates you are loading the syntax rules without having loaded the file type plugin at all. That isn't a situation I expected when I reworked the variable usage to be per-buffer.

l29ah commented 1 year ago

Do i? I'm surprised since /usr/share/vim/vimfiles/autoload/ledger.vim is present, and other files in /usr/share/vim/vimfiles/autoload get loaded apparently.

alerque commented 1 year ago

I just checked they way things are loading for me (via :scriptnames) and then inspecting some variables. In my case I don't see any errors and ftplugin does load first, but also unexpectedly g:ledger_is_hledger which gets set in ftplugin is not readable by the syntax file that loads next. I'm poking at it trying to figure out what gives.

valankar commented 1 year ago

I'm getting similar errors:

"ledger.ledger" 1322L, 50183C
Error detected while processing /media/sdm1/valankar/.vim/pack/ledger/start/vim-ledger/syntax/ledger.vim:
line   15:
E121: Undefined variable: g:ledger_is_hledger
E15: Invalid expression: g:ledger_is_hledger
line   22:
E121: Undefined variable: b:is_hledger
E15: Invalid expression: b:is_hledger ? ';*#' : ';|*#%'
line   70:
E121: Undefined variable: s:line_comment_chars
E15: Invalid expression: 'syn match ledgerComment /^['.s:line_comment_chars.'].*$/'
line   74:
E121: Undefined variable: b:is_hledger
E15: Invalid expression: b:is_hledger
line   88:
E121: Undefined variable: b:is_hledger
E15: Invalid expression: b:is_hledger
line  147:
E121: Undefined variable: b:is_hledger
E15: Invalid expression: b:is_hledger ? 'hledger' : 'ledger'
valankar commented 1 year ago

I'm getting similar errors:

I switched from:

VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Jan 10 2022 21:05:25)

to:

VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Oct 28 2022 21:16:22)

and no longer get the errors.

alerque commented 1 year ago

Thanks for the useful information @valankar, that helps narrow this down a lot.

While I'm more than happy to see old versions of VIM supported, I'm a NeoVIM user myself (and it works there) and VIM 9 is hardly bleeding edge (having been out for a couple years); so personally I'm not very motivated to go dig up the problem here. I might at some point, but it is low on the urgency scale for me.

That being said I would love too facilitate a PR if somebody else has the time and motivation to dig into what happened that we lost VIM 8 support (and presumably earlier). It probably isn't a hard fix, it just needs somebody with an old VIM to poke around and try it.

cript0nauta commented 1 year ago

Hi! I'm using vim 9.0.0609 (VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Jan 01 1980 00:00:00)) in a NixOS system, and still have the same issues reported here. I'll investigate the issue during this week, but it looks like just upgrading to Vim 9 isn't enough to solve this problem.

yehoshuapw commented 1 year ago

I have the same issue too, (Gentoo-9.0.1157), a workaround which works is (the idea is from https://github.com/python-mode/python-mode/issues/47 )

adding (those specific values might not be the best choices)

let g:ledger_is_hledger=1
let b:is_hledger=1
let s:line_comment_chars=";"

before the plugin is loaded

(that issue is old, so unlikely to be that same issue. the idea of just sticking the definitions in vimrc is from there)

stevehemingway commented 1 year ago

I have the same issue. I am running on Vim 9.0. When I add the lines above to define the undefined variables, the plugin seems to work fine.

phylor commented 1 year ago

Using pathogen, you need to enable the filetype plugin before loading the plugins.

filetype plugin indent on

execute pathogen#infect()
call pathogen#helptags()

Using version VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Apr 06 2023 14:24:38). I got the same errors when the filetype line above was placed after the execute pathogen.


Alternatively, setting the variables @yehoshuapw mentioned before the execute pathogen also works.

Scholars-Mate commented 1 year ago

I am on Vim 9.0 and was also experiencing this issue. Enabling syntax after the filetype plugin fixed the issue for me:

filetype plugin indent on
syntax on
cript0nauta commented 1 year ago

After bisecting the repo, it looks like the issue is caused by commit 6990fa243b684d91bd7386af3f378cdf6ed7c536.

I fixed the issue locally by adding the following in my vimrc:

let g:ledger_is_hledger=v:false

(since i use ledger instead of hledger)

kirtr commented 1 year ago

This bug had me stumped for several attempts for a fix. I've finally gotten it working on Ubuntu and I think I have a set of best practices for other Debian / Ubuntu users to use. I've forked the repository and have modified the README.md. I'm not sure how to create a pull request in this project in order to update the documentation. Here's a link to my updated README.md. https://github.com/kirtr/vim-ledger/blob/master/README.md

tkapias commented 8 months ago

After bisecting the repo, it looks like the issue is caused by commit 6990fa2.

I fixed the issue locally by adding the following in my vimrc:

let g:ledger_is_hledger=v:false

(since i use ledger instead of hledger)

I had this issue with hledger on Vim 9.0 (Compiled latest from july 2023).

@cript0nauta answer solved it for me:

let g:ledger_is_hledger=v:true
chreekat commented 6 months ago

I suspect the reason some people get this issue and others don't is due to differences in vim startup files that different OS distributions use. That is, /usr/share/vim/.../vimrc has different contents. On NixOS, it's

set nocompatible
syntax on

function! NixosPluginPath()
  let seen = {}
  for p in reverse(split($NIX_PROFILES))
    for d in split(glob(p . '/share/vim-plugins/*'))
      let pluginname = substitute(d, ".*/", "", "")
      if !has_key(seen, pluginname)
        exec 'set runtimepath^='.d
        let after = d."/after"
        if isdirectory(after)
          exec 'set runtimepath^='.after
        endif
        let seen[pluginname] = 1
      endif
    endfor
  endfor
endfunction

execute NixosPluginPath()

if filereadable("/etc/vimrc")
  source /etc/vimrc
elseif filereadable("/etc/vim/vimrc")
  source /etc/vim/vimrc
endif

So on my system, syntax on is executed very early.

alerque commented 4 months ago

I just bumped into something like this myself. In my case I am using packer, and in my setup for vim-ledger I add some completion stuff to nvim-cmp. I mistakenly set the loader for vim-ledger to after = { "nvim-cmp" } without/instead of having set requires = { "nvim-cmp" }. That mistake made it spew errors, not exactly the ones in this issue but about invalid automcommand stuff related to vim-ledger. Correcting the load order was all it took to git back to sanity.

The more I look at it the more I think this isn't so much an issue as a collection of issues depending on how people setup their plugin loaders and all order related. We might have some variables we can check for before attempting to use (and I'm happy to facilitate PRs along these lines if anybody figures them out), but the real answer is probable just "make sure you do things in the right order".

larsks commented 1 week ago

I load vim-ledger using lazy vim, and I get the same set of errors:

Error detected while processing BufReadPost Autocommands for "*"..Syntax Autocommands for "*"..function <SNR>30_SynSet[26]..script /home/lars/
.local/share/nvim/lazy/vim-ledger/syntax/ledger.vim:
line   15:
E121: Undefined variable: g:ledger_is_hledger
line   22:
E121: Undefined variable: b:is_hledger
line   70:
E121: Undefined variable: s:line_comment_chars
line   74:
E121: Undefined variable: b:is_hledger
line   88:
E121: Undefined variable: b:is_hledger
line  147:
E121: Undefined variable: b:is_hledger
Press ENTER or type command to continue

Setting g:ledger_is_hledger does resolve the problem; I'm not sure about the "right" place to set this, so I set it before loading lazyvim. My init.lua looks like:

-- work around https://github.com/ledger/vim-ledger/issues/143
vim.g.ledger_is_hledger = true

-- bootstrap lazy.nvim, LazyVim and your plugins
require("config.lazy")