Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clever-f conflicts with wordcount function #31

Closed
eater opened this issue Feb 22, 2017 · 11 comments
Closed

Clever-f conflicts with wordcount function #31

eater opened this issue Feb 22, 2017 · 11 comments

Comments

@eater
Copy link

eater commented Feb 22, 2017

I use this function to keep a live wordcount in the statusline: https://gist.github.com/cormacrelf/d0bee254f5630b0e93c3

When I try to use Clever-f, I get an error

Error detected while processing function clever_f#find_with[12]..WordCount:
E523: Not allowed here

Is there an easy way to resolve the conflict?

@rhysd
Copy link
Owner

rhysd commented Feb 23, 2017

Do you know which line causes the error? I could not find the code related to clever-f.vim in your gist.

At least it looks that you should use normal! instead of normal.

@eater
Copy link
Author

eater commented Feb 23, 2017

No, I'm not sure where the conflict is! I didn't write the function, I just found the gist. Changing it to normal! is a good idea but doesn't fix the error.

Here's a simplified version of the function that still conflicts:

function! WordCount()
  if line('$') == 1 && getline(1) == '' 
    return 
  elseif mode() == "i"  || mode() == "n"
    let s:old_status = v:statusmsg
    exe "silent normal! g\<c-g>"
    let b:word_count = str2nr(split(v:statusmsg)[11])
    let v:statusmsg = s:old_status
  endif
  return b:word_count
endfunction

@rhysd
Copy link
Owner

rhysd commented Feb 23, 2017

Thank you for reducing code. But I can still not identify the cause of this bug... Could you show me your status line configuration? I need to reproduce.

@eater
Copy link
Author

eater commented Feb 25, 2017

From .vimrc:

let mystatusline = ""
let mystatusline .= "\ %n\ %*" |                                        " buffer number
let mystatusline .= "\ %<%F%*" |                                        " full path
let mystatusline .= "\ %y%*" |                                          " file type
let mystatusline .= " \%M" |                                            " modified flag
let mystatusline .= "\ %#vimWarn#\%{(&key==\"\"?\"\":\"ENCR\")}%*" |    " encrypted?
let mystatusline .= "\ \[%{v:register}\]" |                             " current register
let mystatusline .= "\ %{getcwd()} "                                   " current working dir
let &statusline = mystatusline
autocmd FileType txt if &statusline !~ "WC: " | setlocal statusline+=\ \ WC:\ %{WordCount()}\ 

@rhysd
Copy link
Owner

rhysd commented Feb 25, 2017

Thanks. I'll try it.

@rhysd
Copy link
Owner

rhysd commented Feb 25, 2017

I could not see the error as below (it seems that it breaks cursor position when entering insert mode, but it looks not related to this issue)

tmp

@eater
Copy link
Author

eater commented Mar 5, 2017

Here's a longer set of error messages.

Error detected while processing function clever_f#find_with[12]..WordCount:
line   11:
E523: Not allowed here
Error detected while processing function clever_f#find_with[12]..WordCount:
line   17:
E684: list index out of range: 11
Error detected while processing function clever_f#find_with[12]..WordCount:
line   17:
E116: Invalid arguments for function str2nr(s:split_wc[11])
Error detected while processing function clever_f#find_with[12]..WordCount:
line   17:
E15: Invalid expression: str2nr(s:split_wc[11])
Error detected while processing function clever_f#find_with[12]..WordCount:
line   11:
E523: Not allowed here
Error detected while processing function clever_f#find_with[12]..WordCount:
line   17:
E684: list index out of range: 11
Error detected while processing function clever_f#find_with[12]..WordCount:
line   17:
E116: Invalid arguments for function str2nr(s:split_wc[11])
Error detected while processing function clever_f#find_with[12]..WordCount:
line   17:
E15: Invalid expression: str2nr(s:split_wc[11])

@chrisbra
Copy link

instead of using a selfmade wordcount function, you can use the builtin wordcount() function, which has been included in Vim 7.4.1042

@eater
Copy link
Author

eater commented Aug 31, 2017

Amazing! Thanks, @chrisbra.

@rhysd
Copy link
Owner

rhysd commented Aug 31, 2017

Thank you @chrisbra. @eater, did it solve this issue?

@rhysd
Copy link
Owner

rhysd commented Sep 8, 2017

It looks it is a problem of implementation of the function WordCount(). It seems to be called while clever-f.vim's f is used because of status line update, but not related to this plugin directly. Closing this.

@rhysd rhysd closed this as completed Sep 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants