seagle0128 / doom-modeline

A fancy and fast mode-line inspired by minimalism design.

Home Page:https://seagle0128.github.io/doom-modeline/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wrong project root detection

jumper047 opened this issue · comments

Describe
When i open file in subfolder within the project, doom-modeline considering this subfolder as project root, instead of actual root.

Steps and Expected
Project with subdirectory with some source files inside this subdir.
Project's root contains .projectile file. Also this project is svn repository.
Doom modeline path truncation set to truncate-with-project
Open file "project/subfolder/some_file.py"
Expected in modeline: "project/s/some_file.py"
Actually: "subfolder/some_file.py"
Environment:

  • OS: Windows
  • Version 7
  • Package version 20190918.1510

Additional context:
I temporarily fix it on my install by changing order of root detection functions:

      (defun doom-modeline-project-root ()
	"Get the path to the root of your project.
    Return `default-directory' if no project was found."
	(or doom-modeline-project-root
	    (setq doom-modeline-project-root
		  (or 		    (and (bound-and-true-p projectile-mode)
			   (ignore-errors (projectile-project-root)))

				      (and (fboundp 'project-current)
			   (ignore-errors
			     (when-let ((project (project-current)))
			       (expand-file-name (car (project-roots project))))))
		      (and (fboundp 'ffip-get-project-root-directory)
			   (let ((inhibit-message t))
			     (ignore-errors (ffip-get-project-root-directory))))
		      default-directory))))    

I couldn't reproduce this issue with Emacs 27 on macOS. I suspect it's related to your configurations or svn repo. Please eval (project-current) in the buffer. If the output is not as the expected, check the configurations or report to project package (It's a built-in package).

BTW, your workaround should work well, unless there are symlinks in your project structure. See #209 .

I see a similar thing. I am using a projectile project with the .projectile file in the project root. This project contains git sub modules and whenever I am in a sub module the project seems to be detected to the submodule instead of the project root.
I think this comes from that project.el has higher priority than projectile and the former simply use the vc-root or something. I am not sure if this is the same issue as reported here but the solution is the same at least.

Maybe it would be a good idea to let projectile and ffip have higher priority than project.el since if those are installed, the user probably want to use them over project.el?

@dajva I see. It seems project doesn't handle sub projects well, and projectile doesn't handle symlinks of folders. I need to think over both this one and #209.

Refer to bbatsov/projectile#1387 as well.

Oh, that's an unfortunate bug. Strange that projectile is not interested in fixing it.
Anyway, I found a way to work around it that I am posting here if someone else has a problem with this.
This adds projectile as a backend for the project dir functionality in project.el:

(defun dl-project-current-projectile-adaptor (dir)
  (cons 'projectile (projectile-project-root dir)))

(push #'dl-project-current-projectile-adaptor project-find-functions)

Yeah, it's strange. According to bbatsov/projectile@e22a775, file-truename is applied to all file names, then the symlink folders are not respected.

For example: for /a/b/test.txt, and /a/b/ linked to /c/d/

  • In project, root is /a/b/.
  • In projectile, root is /c/d/. The file truename is /c/d/test.txt.

If I change all buffer-file-name to file-truename in doom-modeline, to adapt projectile. The side-effect is all names are displayed as true names. I am not sure if it's reasonable to all users. I think it's reasonable to projectile users, while not project users.

Another option is make the project root detection method customizable. But that needs the users know what they want.

Finally I decide to add new option (doom-modeline-project-detection). You can specify one from ffip, projectile, project and nil.