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

add variable to ignore specific projects #1916

Closed

Conversation

dradetsky
Copy link

@dradetsky dradetsky commented Oct 31, 2024

I want to add a git repo to my home directory in order to track dotfiles (I'm aware there are other approaches that don't involve creating ~/.git/, but for reasons beyond the scope of this PR, I want to do it this way). When I do this, in doom-emacs doom doctor complains

    ! Your $HOME is recognized as a project root
      Emacs will assume $HOME is the root of any project living under $HOME. If this
      isn't desired, you will need to remove ".git" from
      `projectile-project-root-files-bottom-up' (a variable), e.g.
      
        (after! projectile (setq projectile-project-root-files-bottom-up (remove ".git"
          projectile-project-root-files-bottom-up)))

Maybe I'm misunderstanding something, but it seems like the resolution here isn't something I want to do. I still want projectile to recognize dirs with .git as project roots, I just want it to not consider $HOME to be the universal project root, as threatened by doom doctor. Therefore, I need it to say that one or more named directories are not project roots, regardless of what the root-determination machinery would say otherwise.

So I add a variable to hold a list of such directories, and consult it inside projectile-locate-dominating-file.

NOTE: the PR is intentionally missing some required cleanup (like comments) in case there is something fundamentally wrong with my whole approach (I suck at elisp). That's why it's marked as a draft. AFAIK, the code itself does what it should, but I could be wrong.


Before submitting a PR make sure the following things have been done (and denote this
by checking the relevant checkboxes):

  • The commits are consistent with our contribution guidelines
  • You've added tests (if possible) to cover your change(s)
  • All tests are passing (eldev test)
  • The new code is not generating bytecode or M-x checkdoc warnings
  • You've updated the changelog (if adding/changing user-visible functionality)
  • You've updated the readme (if adding/changing user-visible functionality)

Thanks!

@bbatsov
Copy link
Owner

bbatsov commented Nov 2, 2024

The approach seems sound, although I have some small concern about how this will affect performance, as it's an extra check in a function that's used quite often. On the other hand - by default this variable will be nil, so likely the overhead then will be close to none.

One alternative approach to consider would be to use some variable marker set via .dir-locals.el, but I assume some people might not like this, as it will require them to have .dir-local.el in any folder they'd like to ignore.

@dradetsky
Copy link
Author

@bbatsov if you're concerned about the performance (I really have no idea whether you're right to be concerned or not), we could check whether projectile-non-project-roots is non-nil before we even bother to expand file & create the closure that we'd map over projectile-non-project-roots. That way, instead of some extra misc elisp stuff per call, it's just an extra compare-to-nil per call (at least for those who aren't using this variable), which I'd assume wouldn't matter (although I haven't benchmarked obviously).

I didn't do this to begin with because I was concerned about the readability of the code, so I tried to avoid getting to clever. But if you think it's worth it here I can do it.

@bbatsov
Copy link
Owner

bbatsov commented Nov 3, 2024

I don't think an explicit nil check will be much of a difference - iterating over an empty/nil list is more or less the same. Just pursue your original approach.

@dradetsky
Copy link
Author

I subsequently decided not to store dotfiles via creating a ~/.git so this is no longer relevant to my needs. You can close the PR if you want (or IDK, keep it around & finish yourself).

@bbatsov bbatsov closed this Nov 26, 2024
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

Successfully merging this pull request may close these issues.

2 participants