Vim syntastic is not showing warning messages - vim

This is my current syntastic configuration:
let g:syntastic_check_on_open=1
let g:syntastic_quiet_messages = { "level": [] }
let g:syntastic_aggregate_errors = 1
let g:syntastic_javascript_checkers = ['jshint', 'jslint']
let g:syntastic_warning_symbol = 'WW'
let g:syntastic_error_symbol = 'EE'
The problem that I have is that, it shows only error messages in my javascript files:
For example:
% jslint web/js/app.js
web/js/app.js
#1 'define' was used before it was defined.
define([ // Line 1, Pos 1
#2 Expected exactly one space between 'function' and '('.
RestangularProvider.setResponseExtractor(function(response, operation) { // Line 73, Pos 58
but when I open the file in vim i see only the message #1 'define' was used before it was defined., not the second one.
What should I do to enable warnings to be shown too?

Syntastic uses the following command line options to jslint by default:
--white --nomen --regexp --plusplus --bitwise --newcap --sloppy --vars
(see syntastic/syntax_checkers/javascript/jslint.vim).
You can set your own options via
let g:syntastic_javscript_jslint_args = "--foo --bar --baz"
The --white from the defaults is what suppresses your second warning

Related

Neovim config error: '<eof>' expected near 'local'

I'm setting up Neovim like this guy in this video: https://www.youtube.com/watch?v=vdn_pKJUda8&t=145s&ab_channel=JoseanMartinez
I'm using WSL - Windows subsystem for Linux.
And I have this error in ~/.config/nvim/lua/suleiman/plugins-setup.lua file:
Error detected while processing /home/suleiman/.config/nvim/init.lua:
E5113: Error while calling lua chunk: vim/_init_packages.lua:0:
/home/suleiman/.config/nvim/lua/suleiman/plugins-setup.lua:24: '<eof>' expected near 'local'
stack traceback:
[C]: in function 'error'
vim/_init_packages.lua: in function <vim/_init_packages.lua:0>
[C]: in function 'require'
/home/suleiman/.config/nvim/init.lua:1: in main chunk
And here is the file itself:
vim.cmd([[
augroup packer_user_config
autocmd!
autocmd BufWritePost plugins.lua source <afile> | PackerCompile
augroup end
]])
local status, packer = pcall(require, 'packer')
if not status then
return
end
return packer.startup(function(use)
use('wbthomason/packer.nvim')
use('bluz71/vim-nightfly-guicolors')
if packer_bootstrap then
require('packer').sync()
end
end)
local ensure_packer = function() // This is the line:24
local fn = vim.fn
local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
if fn.empty(fn.glob(install_path)) > 0 then
fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
vim.cmd [[packadd packer.nvim]]
return true
end
return false
end
local packer_bootstrap = ensure_packer()
return require('packer').startup(function(use)
use 'wbthomason/packer.nvim'
-- My plugins here
-- use 'foo1/bar1.nvim'
-- use 'foo2/bar2.nvim'
-- Automatically set up your configuration after cloning packer.nvim
-- Put this at the end after all plugins
if packer_bootstrap then
require('packer').sync()
end
end)
plugins-setup.lua
And this is here is the ~/.config/nvim/init.lua file where I require that file:
require('suleiman.plugins-setup')
require('suleiman.core.options')
require('suleiman.core.keymaps')
require('suleiman.core.colorscheme')
I searched on this error, I didn't find the solution.
There isn't supposed to be an error at all I think, because I copied what that guy on that video did.

Trying to write to VIM from Genero using 4gl

I would like to open a .4gl file in VI terminal and write to it, this is the code I have currently:
let p_command = "test -f ", MTGENDIR CLIPPED,"/",p_prog clipped,".4gl"
run p_command returning p_status
let p_command = "vi ",p_prog clipped,".4gl"
--let p_command = "w ",p_prog clipped,".4gl"
--let p_command = ":w ",p_prog clipped,".4gl"
run p_command
This is the error I get in the debugger once it gets to the step vi and then it hangs:
(fgldb) next
376 let p_command = "vi ",p_prog clipped,".4gl"
(fgldb) next
377 run p_command
(fgldb) next
Vim: Warning: Output is not to a terminal
Vim: Warning: Input is not from a terminal
if i try writing with the commented code above (w or :w) it crashes and display this error:
The DVM process crashed. Please contact FourJs support.
DVM has encountered a problem. Execution of 'mt_gen' stopped
Is there any other way i can write to .4gl file in Genero?
To answer the very last sentence "Is there any other way I can write to .4gl file in Genero?" then you can use base.Channel class to write to a file ...
MAIN
DEFINE ch base.Channel
LET ch = base.Channel.create()
CALL ch.openFile("example.4gl","w")
CALL ch.writeLine("MAIN")
CALL ch.writeLine(" DISPLAY 'Hello World'")
CALL ch.writeLine("END MAIN")
CALL ch.close()
END MAIN
... the key bit being the use of base.Channel.openFile and w (or a) as the opening mode http://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_ClassChannel_openFile.html
Alternatively you can build up the file inside a STRING or base.StringBuffer variable and use the TEXT writeFile method http://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_datatypes_TEXT_writeFile.html ...
MAIN
DEFINE s STRING
DEFINE t TEXT
LET s =
"MAIN", ASCII(13),
" DISPLAY 'Hello World'", ASCII(13),
"END MAIN"
LOCATE t IN MEMORY
LET t = s
CALL t.writeFile("example2.4gl")
END MAIN
I'm not sure why you think you need vi/vim in your solution to write to a .4gl file.

Setting vimwiki_list in a lua.init file

I am using neovim and am trying to use lua for my settings.
I have installed vimwiki and following the instructions to set
let g:vimwiki_list = [{'path': '~/vimwiki/',
\ 'syntax': 'markdown', 'ext': '.md'}]
I have tried doing this in lua with
vim.api.nvim_set_var('vimwiki_list', {path = "~/mywiki/"})
This results in the error
Error detected while processing function vimwiki#vars#init[2]..<SNR>31_populate_wikilocal_options:
line 49:
E714: List required
Error detected while processing function <SNR>30_vimwiki_get_known_extensions:
line 3:
E727: Start past end
E714: List required
Error detected while processing /home/me/.local/share/nvim/site/pack/packer/start/vimwiki/plugin/vimwiki.vim:
line 303:
E714: List required
line 315:
E712: Argument of map() must be a List or Dictionary
E714: List required
Error detected while processing function <SNR>30_build_menu:
line 2:
E727: Start past end
E714: List required
How do I correctly set these type of options, specifically for vimwiki, and more generally for other cases?
I did;
vim.g.vimwiki_list = {{path = '~/Docs/Mywiki', syntax = 'markdown', ext = '.md'}}
which resolved the error and set the options

How to make vim’s vimgrep command keep indentations?

I’m trying to use vim’s quick fix (or local) list to get some information extracted from a file. For example, I want to get all the method names of a python module (the idea was borrowed from pycharm). What I want to get in vim’s “local list” is just something like the following:
class Foo:
def one():
def two():
def three():
def bar():
def bazz():
To achieve that, I do approximately the following steps:
:" OK, the current buffer is being used.
:let file_name = expand('%:p')
:" The heart of the process is one of vim’s grep-like command.
:execute 'lvimgrep /\v^\s*(class|def)/ '.file_name
:" I open the results with the “lopen” command because “llist”
:" doesn’t allow me to use concealing.
:lopen
:" Since I’m working with one file, I don’t need information
:" about file name, line number etc.
:setlocal conceallevel=3
:syntax match NonText /\v^.+col \d+([:]|[|])/ transparent conceal
:" Please note, I‘m still able to jump to a line
:" with the “ll” command.
But unfortunately I get:
class Foo:
def one():
def two():
def three():
def bar():
def bazz():
All the indents are swallowed! The result is quite useless… I can’t differentiate which of the functions belong to a class, which of them are stand-alone.
Please note, the concealing doesn’t have a meaningful influence on the result. If I took away the two last commands (conceal-related), nothing significant would change, only the file name and line/column numbers would be shown but the text in the lines would be still without indents anyway.
So, my questions are:
Is it possible to make lvimgrep (or an analogue) keep the lines untouched in order to save indentation? Is there a magic command or option to do that? Or should I program my own implementation of lvimgrep?
P.S. I’d like to use vim’s regular expressions. But if it’s impossible, I could switch to the external “grep” command (I’m a linux guy) and use the BRE or ERE syntax as well.
No, currently, it is impossible to make lvimgrep (or even similar commands) keep leading whitespace characters in the quickfix (location) list entries, since space and tab characters are unconditionally skipped from the beginning, if the text length is greater than 3.
The only way to achieve the desired behavior (at least, using *vimgrep commands) is to modify the source code. For example, you might add an option as demonstrated in the following patch:
diff --git a/runtime/optwin.vim b/runtime/optwin.vim
index 7d3a8804d..caac55cf2 100644
--- a/runtime/optwin.vim
+++ b/runtime/optwin.vim
## -1299,6 +1299,7 ## call <SID>OptionG("ve", &ve)
call append("$", "eventignore\tlist of autocommand events which are to be ignored")
call <SID>OptionG("ei", &ei)
call append("$", "loadplugins\tload plugin scripts when starting up")
+call append("$", "locws\tenables whitespace characters for entries in the location window")
call <SID>BinOptionG("lpl", &lpl)
call append("$", "exrc\tenable reading .vimrc/.exrc/.gvimrc in the current directory")
call <SID>BinOptionG("ex", &ex)
diff --git a/src/option.c b/src/option.c
index aabfc7f53..4ba280806 100644
--- a/src/option.c
+++ b/src/option.c
## -1791,6 +1791,9 ## static struct vimoption options[] =
{"loadplugins", "lpl", P_BOOL|P_VI_DEF,
(char_u *)&p_lpl, PV_NONE,
{(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
+ {"locws", NULL, P_BOOL|P_VI_DEF,
+ (char_u *)&p_locws, PV_NONE,
+ {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
{"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
#if defined(DYNAMIC_LUA)
(char_u *)&p_luadll, PV_NONE,
diff --git a/src/option.h b/src/option.h
index c1a25b342..5e17c459e 100644
--- a/src/option.h
+++ b/src/option.h
## -602,6 +602,7 ## EXTERN char_u *p_lcs; // 'listchars'
EXTERN int p_lz; // 'lazyredraw'
EXTERN int p_lpl; // 'loadplugins'
+EXTERN int p_locws; // 'locws'
#if defined(DYNAMIC_LUA)
EXTERN char_u *p_luadll; // 'luadll'
#endif
diff --git a/src/quickfix.c b/src/quickfix.c
index 136c472e1..8e206ddd7 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
## -4417,8 +4417,9 ## qf_update_buffer(qf_info_T *qi, qfline_T *old_last)
static int
qf_buf_add_line(buf_T *buf, linenr_T lnum, qfline_T *qfp, char_u *dirname)
{
- int len;
- buf_T *errbuf;
+ int len;
+ buf_T *errbuf;
+ long lval;
if (qfp->qf_module != NULL)
{
## -4472,10 +4473,12 ## qf_buf_add_line(buf_T *buf, linenr_T lnum, qfline_T *qfp, char_u *dirname)
IObuff[len++] = '|';
IObuff[len++] = ' ';
- // Remove newlines and leading whitespace from the text.
+ // Remove newlines and leading whitespace from the text,
+ // if the user not enabled whitespaces explicitly via locws option.
// For an unrecognized line keep the indent, the compiler may
// mark a word with ^^^^.
- qf_fmt_text(len > 3 ? skipwhite(qfp->qf_text) : qfp->qf_text,
+ get_option_value((char_u *)"locws", &lval, NULL, 0);
+ qf_fmt_text(len > 3 ? (lval ? qfp->qf_text : skipwhite(qfp->qf_text)) : qfp->qf_text,
IObuff + len, IOSIZE - len);
if (ml_append_buf(buf, lnum, IObuff,
With locws option, you could enable whitespace characters in the quickfix/location entries as follows:
:set locws
Alternative Option
As an alternative, you could just list out the results via :# an :global
:g/\v^\s*(class|def)/#
This will print out the relevant lines with their associated line numbers.
A slightly fancier mapping:
nnoremap <leader>f :keeppatterns g/\v^\s*(class|def)/#<cr>:
With this mapping you can just type the line number and press enter to jump to a line after executing the mapping.
For more help see:
:h :g
:h :#
:h :keeppatterns
:h :range
Using Quickfix List
In order to use the quickfix list you will need to "mangle" your indent text with another character, e.g. >.
command! PyLocations call <SID>py_locations()
function! s:py_locations()
let lst = []
let bufnr = bufnr('%')
let pat = repeat(' ', shiftwidth())
let Fn = {l -> substitute(matchstr(l, '^\s*'), pat, '▶', 'g') . matchstr(l, '\S.*')}
keeppatterns g/\v^\s*(class|def)>/call add(lst, {'bufnr': bufnr, 'lnum': line('.'), 'text': call(Fn, [getline('.')])})
call setqflist(lst, ' ')
cwindow
endfunction
I’ve done it! But it took more than “half an hour” as I supposed early.
During the research, I found that vim’s local list (and I‘m sure quick fix list too) keeps the indentation of a line when it’s unable to recognize the line as a valid “goto information”, when the line format doesn’t correspond to errorformat. (See :help quickfix-valid) So, to get a nice looking list it must be rendered manually. But in order to have the possibility of jumping to the items of a search result, a quickfix or local list must be created as well.
I’ve split the task into two functions: the fist one retrieves the data, the second one shows it.
function! s:grep_buffer(pattern)
let file_name = expand("%")
let b:grepped = [] |" It will store the search results.
lexpr! [] |" The local list will give the possibility of jumping.
for line_number in range(1, line('$'))
let line_content = getline(line_number)
if line_content =~ '\V'.a:pattern
call add(b:grepped, line_content)
laddexpr file_name.':'.line_number.':'.line_content
endif
endfor
endfunction
function! s:show_result()
if exists('b:grepped')
let grepped = b:grepped |" After creation a new window it’ll be lost.
vnew
call append(0, grepped)
setlocal buftype=nofile |" Don’t make vim save the content.
setlocal noswapfile
setlocal nomodifiable
nn <silent> <buffer> <CR> :exe line(".").'ll'<CR>
wincmd l |" Now the old window is on the right.
hide
endif
endfunction
Of course, a convenient key mapping must be designed. (There is a trailing space in the second line.)
command! -nargs=1 GrepBuffer call <SID>grep_buffer(<f-args>)
nn <leader>g :GrepBuffer
nn <silent> <leader>s :call <SID>show_result()<CR>
It’s super convenient! When I want to overview the search results again, I call the show_result function which replaces the current window with the search results. I can use all the usual navigation tools to move the cursor through the search results. And all I need to jump to an interesting place is just to hit the enter key!
Thanks for all! The problem is solved, vim is the greatest editor.

Get filename and line number that called vim autoload function

I'm trying to populate the quickfix list using an autoload function, i.e.:
function! myplugin#myfunc(msg)
" this doesn't work from *inside* an autoload function
let filename = fnamemodify(resolve(expand('<sfile>:p')))
" not sure if it's possible to get the line number from where
" a function was called
let linenum = '?#'
" create qf dict object
" set filename, line number, bufnr, text, etc
" add dict to qflist
" setqflist(qfdictlist)
endfunction!
The problem I've run into is I can't figure out a way to get the filename and line number from the code that called the autoload function. Any suggestions?
Out of the box. This is not possible.
However, depending on the exact scenario, here are a few leads.
I've attempted to write a function that decodes the callstack from v:throwpoint when an exception is caught. It's still experimental. See https://github.com/LucHermitte/lh-vim-lib/blob/master/autoload/lh/exception.vim
From my test unit framework, I know precisely which test-file/line is failing. To do so, I had to parse the UT file in order to inject the line number of the caller into the :Assert* commands.
As you see, none of these solutions is very good. But there are none other right now. The callstack isn't available, except from v:throwpoint in an exception context. The only other solution is to have callers inject their references (~__FILE__ + ~__LINE__) when calling. And the only way to automate this is to compile the caller script into another script that automatically injects the missing information.
By right now, understand there had been a proposal on vim-dev mailing list this last month in order to permit to have access to the call stack, but alas, only during debugging sessions: https://github.com/vim/vim/pull/433
If this is accepted, may be it could be extended later to offer a viml function that'll export this information.
EDIT: Your question inspired me to write a simplistic logging facility for vim:
" Function: lh#log#new(where, kind) {{{3
" - where: "vert"/""/...
" - kind: "qf"/"loc" for loclist
" NOTE: In order to obtain the name of the calling function, an exception is
" thrown and the backtrace is analysed.
" In order to work, this trick requires:
" - a reasonable callstack size (past a point, vim shortens the names returned
" by v:throwpoint
" - named functions ; i.e. functions defined on dictionaries (and not attached
" to them) will have their names mangled (actually it'll be a number) and
" lh#exception#callstack() won't be able to decode them.
" i.e.
" function s:foo() dict abort
" logger.log("here I am");
" endfunction
" let dict.foo = function('s:foo')
" will work correctly fill the quicklist/loclist, but
" function dict.foo() abort
" logger.log("here I am");
" endfunction
" won't
" TODO: add verbose levels
function! lh#log#new(where, kind) abort
let log = { 'winnr': bufwinnr('%'), 'kind': a:kind, 'where': a:where}
" open loc/qf window {{{4
function! s:open() abort dict
try
let buf = bufnr('%')
exe 'silent! '.(self.where). ' '.(self.kind == 'loc' ? 'l' : 'c').'open'
finally
call lh#buffer#find(buf)
endtry
endfunction
" add {{{4
function! s:add_loc(msg) abort dict
call setloclist(self.winnr, [a:msg], 'a')
endfunction
function! s:add_qf(msg) abort dict
call setqflist([a:msg], 'a')
endfunction
" clear {{{4
function! s:clear_loc() abort dict
call setloclist(self.winnr, [])
endfunction
function! s:clear_qf() abort dict
call setqflist([])
endfunction
" log {{{4
function! s:log(msg) abort dict
let data = { 'text': a:msg }
try
throw "dummy"
catch /.*/
let bt = lh#exception#callstack(v:throwpoint)
if len(bt) > 1
let data.filename = bt[1].script
let data.lnum = bt[1].pos
endif
endtry
call self._add(data)
endfunction
" reset {{{4
function! s:reset() dict abort
call self.clear()
call self.open()
return self
endfunction
" register methods {{{4
let log.open = function('s:open')
let log._add = function('s:add_'.a:kind)
let log.clear = function('s:clear_'.a:kind)
let log.log = function('s:log')
let log.reset = function('s:reset')
" open the window {{{4
call log.reset()
return log
endfunction
Which use this other function of mine that decodes the callstack.
Well, if you can't get the file and line from inside the autoload function, you have to pass that into your function.
Your autoloaded function is invoked somehow, either by a custom mapping, command, or on an :autocmd event. From there, you can resolve the current file (expand('%') and line number ('line('.')) and pass that in.
But why do you need that?! For normal editing tasks, I can't imagine why. If you're writting a custom Vim debugging plugin, okay, that might be useful. But debugging via Vimscript is difficult (as you've found out), the callstack isn't exposed. Better stick with the built-in :debug and :breakadd; I've so far found them sufficient.

Resources