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

Allow NERDTreeIgnore to use paths. #737

Closed
aemonge opened this issue Aug 29, 2017 · 11 comments
Closed

Allow NERDTreeIgnore to use paths. #737

aemonge opened this issue Aug 29, 2017 · 11 comments

Comments

@aemonge
Copy link

aemonge commented Aug 29, 2017

So I know let NERDTreeIgnore=['[^pre].*[[dir]]'] will hide all the directories that don't start with pre as a prefix. But I would like to apply that rule only to directories under bower_components directory.

Ideally something like these two options:

  • let NERDTreeIgnore=['bower_components\/[^pre].*[[dir]]']
  • let NERDTreeIgnore=['bower_components\/[^pre].*[[path]]']
@lifecrisis
Copy link
Contributor

This may require a new option, or an expansion of the meaning of the g:NERDTreeIgnore option. I'm hesitant to do this.

@PhilRunninger
Copy link
Member

@aemonge Disregarding your feature request for a moment, can you confirm your setting is working properly? The way I read it, NERDTree will hide all directories that contain any other character that is not p, r, or e. In other words, it would hide just about everything. To do what you want

... hide all the directories that don't start with pre as a prefix.

involves some uncommon regex complexity. Using this StackOverflow thread and :h /\@! as starting points, you could try this:

:let NERDTreeIgnore=['^\(pre\)\@!.*$']

Of course this doesn't address your feature request, and outside of the bower_components directory, all directories disappear. To get them back, you need to toggle the file filters with the f key, so I understand your request.

I had fun discovering this lesser known capability in regular expressions. Thanks for the question.

@aemonge
Copy link
Author

aemonge commented Aug 31, 2017

@PhilRunninger, thanks a lot for the correction of the RegExp, endeed the final version would have to use your fixed version with @lifecrisis new feature for path 👍

@juanibiapina
Copy link
Contributor

Why not use NERDTreeAddPathFilter ?

@aemonge
Copy link
Author

aemonge commented Sep 29, 2017

@juanibiapina could you provide the function that would work ? I'm not really used to vimscript so I don't really know how to do it. So far I've got until here:

call NERDTreeAddPathFilter('FilterNonPre')

function! FilterNonPre(params)
  " echo a:params['path']
  " echo params.AbsolutePathFor()
  " echo a:params.AbsolutePathFor()
  let bu=join(a:params['path']['pathSegments'], '/')
  let w:ja=matchstr(bu, '\c bower_components\/pre')
  if empty(ja)
    echo 'Noooooooooooooooooooooooooooooooooooooooooo'
    echo bu
    return 1
  endif
  " let bu='buu'
  echo bu
  echo '^^^^^ siiiiiiiiiiiii'
  return 1
  " echo a:params['path'].AbsolutePathFor()
endfunction

Trying to get a regex to filter the result. Also I would like to get relative path, or PWD

@aemonge
Copy link
Author

aemonge commented Oct 2, 2017

I've progressed a little bit, but I finally got stucked with the regex. My updated code is as follows:

call NERDTreeAddPathFilter('FilterNonPre')

function! FilterNonPre(params)
  let pwd=expand('%:p:h')
  let fullPath=join([''] + a:params['path']['pathSegments'], '/')
  let relativePath=substitute(fullPath, pwd, '', '')
  let hasHidableMatch=matchstr(relativePath, '^\bower_components/pre\\@!.*$')

  " echo '============='
  echo relativePath
  echo hasHidableMatch
  " return 0

  if empty(hasHidableMatch)
    return 0
  endif
  return 1
endfunction

My intension is to hide all folder inside (./bower_components) that have not a pre

@juanibiapina
Copy link
Contributor

juanibiapina commented Oct 2, 2017

You can use path.str() to get a full path representation, should make it easier.

For a relative path, check the documentation of path.str() also. I think strForEdit should be relative.

And if you're having trouble with the regexp, do it in two steps, it's more readable anyway. Check if it matches bower_components and then your next thing.

@aemonge
Copy link
Author

aemonge commented Oct 3, 2017

Ohhh !!! Yes!!! I got complicated without need, OFC ! thanks!

@aemonge
Copy link
Author

aemonge commented Oct 3, 2017

Finall working result:

call NERDTreeAddPathFilter('FilterNonPre')

function! FilterNonPre(params)
  let pwd=expand('%:p:h')
  let fullPath=join([''] + a:params['path']['pathSegments'], '/')
  let relativePath=substitute(fullPath, pwd, '', '')
  let inBower=matchstr(relativePath, '/bower_components/')

  if !empty(inBower)
    let hasPre=matchstr(relativePath, 'bower_components/pre')
    if empty(hasPre)
      return 1 " ignore
    endif
  endif
  return 0
endfunction

@lifecrisis
Copy link
Contributor

Hey @aemonge, thanks for working through this. Also, @juanibiapina, thanks for helping out.

@aemonge, are you satisfied enough to close the issue?

@aemonge
Copy link
Author

aemonge commented Oct 4, 2017

Yes !

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

No branches or pull requests

4 participants