justinmk / vim-dirvish

Directory viewer for Vim :zap:
Other
1.18k stars 64 forks source link

x could toggle items in the arg list #139

Closed arecarn closed 5 years ago

arecarn commented 5 years ago

Just a thought, but x could toggle items in the argslist. I created a modfied s:set_args() function that seems to do the right thing to toggle the item in or out of the args list.

I modified the fnamemodify() call to use ':." instead of ':p' since it seems like the args list keeps track of the absolute path of file in the args list internally and provides them relative to the pwd.

The only thing that doesn't seem to work is the removal of the highlighting of deselected files.

function! s:set_args(args) abort
  if exists('*arglistid') && arglistid() == 0
    arglocal
  endif
  let normalized_argv = map(argv(), 'fnamemodify(v:val, ":p")')
  for f in a:args
    if -1 == index(normalized_argv, f)
      exe '$argadd '.fnameescape(fnamemodify(f, ':.')) " modified
    else                                               " added
      exe '$argadd '.fnameescape(fnamemodify(f, ':.')) " added
    endif
  endfor
  echo 'arglist: '.argc().' files'

  " Define (again) DirvishArg syntax group.
  exe 'source '.fnameescape(s:srcdir.'/syntax/dirvish.vim')
endfunction
justinmk commented 5 years ago

Thanks for the patch! Is dax not good enough?

I modified the fnamemodify() call to use ':." instead of ':p' since it seems like the args list keeps track of the absolute path of file in the args list internally and provides them relative to the pwd.

IIRC the absolute path is required for highlighting and to avoid other indeterminism.

If highlighting can't be reliable then it's not really worth adding such a feature. Please do send a PR if you can get it reliable without adding lots of complicated code :)

justinmk commented 5 years ago

Implemented.

Note: {visual}x does not toggle, because it isn't useful. Use {visual}x to choose a block of items, then use x to remove individual items.

modified the fnamemodify() call to use ':." instead of ':p'

Also trying this out. I think the old absolute path approach isn't needed since normalized_argv was added.

arecarn commented 5 years ago

Might want to witch back to using ':p'. noticed when trying to select the pwd while from it's parent fnameescape(fnamemodify(f, ':.') == ''

e.g. pwd = /home/user/dotfiles if you are in a dirvish buffer for /home/user and select dotfiles with x it can be repeatedly added because "" in not in the args list. And what gets added isn't "dotfiles" it's "/home/user"