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

possible autochdir workaround #36

Closed
Konfekt opened this issue Jun 11, 2014 · 8 comments
Closed

possible autochdir workaround #36

Konfekt opened this issue Jun 11, 2014 · 8 comments

Comments

@Konfekt
Copy link
Collaborator

Konfekt commented Jun 11, 2014

Hello,

Just found the following lines in the documentation to CtrlP.vim, and they seem to behave well with respect to ctrlspace, better than set autochdir or the workaround proposed here. The autocmd sets the cwd to the current project root, similar to what ctrlspace does when opening it first time.

  " A standalone function to set the working directory to the project's root, or
  " to the parent directory of the current file if a root can't be found:
  function! s:setcwd()
    let cph = expand('%:p:h', 1)
    if cph =~ '^.\+://' | retu | en
    for mkr in ['.git/', '.hg/', '.svn/', '.bzr/', '_darcs/', '.vimprojects']
      let wd = call('find'.(mkr =~ '/$' ? 'dir' : 'file'), [mkr, cph.';'])
      if wd != '' | let &acd = 0 | brea | en
    endfo
    exe 'lc!' fnameescape(wd == '' ? cph : substitute(wd, mkr.'$', '.', ''))
  endfunction

  autocmd BufEnter * call s:setcwd()
@szw
Copy link
Collaborator

szw commented Jun 14, 2014

Looks scary ;) but yeah, CtrlP is a truly storehouse of knowledge. Do you think should we refer to this in the docs? Any pull requests will be appreciated :)

@Konfekt
Copy link
Collaborator Author

Konfekt commented Jun 22, 2014

I think so. I could merge it in there.

This resolves the problem with the doubling of file paths when loading CtrlSpace Workspace described in my earlier posts (you should check this yourself with autocmd BufEnter * silent! lcd %:p:h), but keeps a autochdir functionality.

The problem now only reoccurs, naturally, when the project root set by CtrlSpace is one specified by the user, without any VCS markers.

@szw
Copy link
Collaborator

szw commented Jun 22, 2014

Yeah, that would be great :).

@szw szw closed this as completed in b54dca8 Jul 15, 2014
@szw
Copy link
Collaborator

szw commented Jul 15, 2014

Ok, autochdir should be working from now. Let me know if more issues occur.

@Konfekt
Copy link
Collaborator Author

Konfekt commented Jul 16, 2014

Perfeito. I stick to my CtrlP RootDir autochdir function and let you know of any irregularities, perhaps others will report if other autochdir functionalities go along as well.

As a sidenote: there is a check for swapped files missing when loading a workspace. If there is a swap file, the work space simply won't load and you have to cancel by Control-C.

1 similar comment
@Konfekt
Copy link
Collaborator Author

Konfekt commented Jul 16, 2014

Perfeito. I stick to my CtrlP RootDir autochdir function and let you know of any irregularities, perhaps others will report if other autochdir functionalities go along as well.

As a sidenote: there is a check for swapped files missing when loading a workspace. If there is a swap file, the work space simply won't load and you have to cancel by Control-C.

@szw
Copy link
Collaborator

szw commented Jul 16, 2014

This should be fixed too (#16). :)

@Konfekt
Copy link
Collaborator Author

Konfekt commented Jul 17, 2014

Oh, just in time. Already cloned your new master.

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

2 participants