Coder Social home page Coder Social logo

Comments (13)

blueyed avatar blueyed commented on July 21, 2024 3

I would not say that this is a bug: the only item is selected (in the list), and both lnext and lprev error out with "no next/previous".

I just wanted to propose using :ll, but you've mentioned it yourself already.

After all, still not a bug with syntastic.

I could imagine fixing this through unimpaired, which provides [l and ]l to navigate the location list: it could catch the error and call :ll automatically. What do you think?
I have reported it over there already: tpope/vim-unimpaired#7

from syntastic.

lcd047 avatar lcd047 commented on July 21, 2024 3

I'd suggest something like this instead:

function! <SID>LocationPrevious()                       
  try                                                   
    lprev                                               
  catch /^Vim\%((\a\+)\)\=:E553/                        
    llast                                               
  endtry                                                
endfunction                                             

function! <SID>LocationNext()                           
  try                                                   
    lnext                                               
  catch /^Vim\%((\a\+)\)\=:E553/                        
    lfirst                                              
  endtry                                                
endfunction                                             

nnoremap <silent> <Plug>LocationPrevious    :<C-u>exe 'call <SID>LocationPrevious()'<CR>                                        
nnoremap <silent> <Plug>LocationNext        :<C-u>exe 'call <SID>LocationNext()'<CR>
nmap <silent> ,,    <Plug>LocationPrevious              
nmap <silent> ..    <Plug>LocationNext

from syntastic.

blueyed avatar blueyed commented on July 21, 2024

This does appear to work as expected, doesn't it?

What do you expect for it to happen instead?

from syntastic.

sgronblo avatar sgronblo commented on July 21, 2024

Wouldn't you expect it to jump to the single location in the location list?

from syntastic.

blueyed avatar blueyed commented on July 21, 2024

Aren't you at the first item already? (Vim jumps there by default)

Anyway, this is Vim core functionality and therefore not an issue with syntastic in particular, as far as I can see.

from syntastic.

sgronblo avatar sgronblo commented on July 21, 2024

No I can be anywhere in the code and try to use :lnext or :lprev and I only get the No more items error. Using :ll seemed to work though. I just assumed that the location list would have been in vim long enough that it wouldn't have this blatant bugs anymore so that's why I suspected there may had been something weird with syntastic.

from syntastic.

sgronblo avatar sgronblo commented on July 21, 2024

Actually now that I know that it's just some idiosyncrasy of vim and have conditioned myself to use :ll when there's only one match I am not that bothered by this any more. It just seemed illogical.

from syntastic.

scrooloose avatar scrooloose commented on July 21, 2024

Closing this issue off as it is to do with vims standard behaviour - not syntastic

from syntastic.

yegle avatar yegle commented on July 21, 2024

I'll just post my workaround in case someone came across this issue:

function LocationListNavOrJustOne(cmd)
    redir => output
    silent! exec a:cmd
    redir END
    if match(output, "E553: No more items") >= 0
        exec ':ll'
    else
        echom output
    endif
endfunction

nmap ,, :call LocationListNavOrJustOne(":lprev")<CR>
nmap .. :call LocationListNavOrJustOne(":lnext")<CR>

Pretty straightforward: this will map ,, (two comma) to :lprev and .. (two period) to :lnext. When these two command return E553: No more items, run :ll to jump to the only result.

I was hoping to make :lprev jump to the last item when it reached the first one but I'm really not an expert in vimscripting.

from syntastic.

yegle avatar yegle commented on July 21, 2024

@lcd047
Way better than mine. Thank you!

from syntastic.

HaleTom avatar HaleTom commented on July 21, 2024

Based on @lcd047's code above I made the following to not produce a ugly multi-line erorr message if there are no entries in the location list:

" Allow :lprev to work with empty location list, or at first location
function! <SID>LocationPrevious()
  try
    lprev
  catch /:E553:/
    lfirst
  catch /:E42:/
    echo "Location list empty"
  catch /.*/
    echo v:exception
  endtry
endfunction

" Allow :lnext to work with empty location list, or at last location
function! <SID>LocationNext()
  try
    lnext
  catch /:E553:/
    lfirst
  catch /:E42:/
    echo "Location list empty"
  catch /.*/
    echo v:exception
  endtry
endfunction

from syntastic.

HaleTom avatar HaleTom commented on July 21, 2024

Actually, this is an even better solution (but consider adding echo "List empty" rather than an null catch.)

from syntastic.

timblaktu avatar timblaktu commented on July 21, 2024

For those stumbling on this behavior, maybe the solutions is "don't do that" - see this workflow/workaround.

from syntastic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.