Skip to content

Commit

Permalink
[Fix #523][Fix #835] Fix TRAMP issues (#1129)
Browse files Browse the repository at this point in the history
It fixes the behavior where Emacs hangs because of projectile when you open a file over TRAMP. When Emacs hangs, very often the only solution is to kill emacs from another terminal.

The fix can be summarized as follow:

"**Stop trying to find information about files for which it's not possible to get informations from.**"

Here is what currently happens:

1. Open a file
2. An empty buffer is created (and TRAMP starts connecting)
3. Projectile want to display project name and asks questions about the file (way too soon)
4. TRAMP is confused and hangs

Here is what my fix changes:

1. Open a file
2. An empty buffer is created (and TRAMP starts connecting)
3. Projectile want to display project name (and gets told that no project root exists)
4. TRAMP eventually connects
5. File is displayed
6. Projectile want to display project name (now that it is connected it gets the right answer)
  • Loading branch information
Silex authored and bbatsov committed Apr 7, 2017
1 parent 0c307c8 commit 323fb84
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

### Changes

* [#1129](https://github.com/bbatsov/projectile/pull/1129): Fix TRAMP issues.
* Add R DESCRIPTION file to `projectile-project-root-files`.
* Ignore backup files in `projectile-get-other-files`.
* Ignore Ensime cache directory, `.ensime_cache`.
Expand Down
32 changes: 18 additions & 14 deletions projectile.el
Original file line number Diff line number Diff line change
Expand Up @@ -863,17 +863,23 @@ topmost sequence of matched directories. Nil otherwise."
(defun projectile-project-root ()
"Retrieves the root directory of a project if available.
The current directory is assumed to be the project's root otherwise."
(let ((dir default-directory))
(or (cl-some
(lambda (func)
(let* ((cache-key (format "%s-%s" func dir))
(cache-value (gethash cache-key projectile-project-root-cache)))
(if (and cache-value (file-exists-p cache-value))
cache-value
(let ((value (funcall func (file-truename dir))))
(puthash cache-key value projectile-project-root-cache)
value))))
projectile-project-root-files-functions)
;; The `is-local' and `is-connected' variables are used to fix the behavior where Emacs hangs
;; because of Projectile when you open a file over TRAMP. It basically prevents Projectile from trying
;; to find information about files for which it's not possible to get that information right now.
(let* ((dir default-directory)
(is-local (not (file-remote-p dir))) ;; `true' if the file is local
(is-connected (file-remote-p dir nil t))) ;; `true' if the file is remote AND we are connected to the remote
(or (when (or is-local is-connected)
(cl-some
(lambda (func)
(let* ((cache-key (format "%s-%s" func dir))
(cache-value (gethash cache-key projectile-project-root-cache)))
(if (and cache-value (file-exists-p cache-value))
cache-value
(let ((value (funcall func (file-truename dir))))
(puthash cache-key value projectile-project-root-cache)
value))))
projectile-project-root-files-functions))
(if projectile-require-project-root
(error "You're not in a project")
default-directory))))
Expand Down Expand Up @@ -3475,9 +3481,7 @@ is chosen."

;;;###autoload
(defcustom projectile-mode-line
'(:eval (if (file-remote-p default-directory)
" Projectile"
(format " Projectile[%s]" (projectile-project-name))))
'(:eval (format " Projectile[%s]" (projectile-project-name)))
"Mode line lighter for Projectile.
The value of this variable is a mode line template as in
Expand Down

0 comments on commit 323fb84

Please sign in to comment.