From 2100025167d571e94e39ff7101f92de87fa32f5a Mon Sep 17 00:00:00 2001 From: Joseph Benden Date: Sun, 31 Jan 2016 16:54:56 -0700 Subject: [PATCH] Fix nil file name for buffer when projectile-cache-current-file When opening a file from the terminal, it is possible for the file to be a project and have the `switch-to-buffer` hook run, with a new buffer that has no associated file. --- CHANGELOG.md | 1 + projectile.el | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e62814c5..d5ef3b808 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ * [#955](https://github.com/bbatsov/projectile/issues/955): Error while toggling between test and source file. * [#952](https://github.com/bbatsov/projectile/issues/952): VCS submodules brought in even thought not descendent of project root. * [#576](https://github.com/bbatsov/projectile/issues/576): `projectile-replace` stomps regular expressions. +* [#957](https://github.com/bbatsov/projectile/pull/957): When opening a specified file from the terminal, do not error inside of `projectile-cache-current-file`. ## 0.13.0 (10/21/2015) diff --git a/projectile.el b/projectile.el index 31b99bf9e..324f2530f 100644 --- a/projectile.el +++ b/projectile.el @@ -666,8 +666,8 @@ The cache is created both in memory and on the hard drive." "Add the currently visited file to the cache." (interactive) (let ((current-project (projectile-project-root))) - (when (gethash (projectile-project-root) projectile-projects-cache) - (let* ((abs-current-file (file-truename (buffer-file-name (current-buffer)))) + (when (and (buffer-file-name) (gethash (projectile-project-root) projectile-projects-cache)) + (let* ((abs-current-file (file-truename (buffer-file-name))) (current-file (file-relative-name abs-current-file current-project))) (unless (or (projectile-file-cached-p current-file current-project) (projectile-ignored-directory-p (file-name-directory abs-current-file))