aemoncannon/ensime — Issue #204: Interactively finding .ensime breaks on Emacs 24
Author: aemoncannon
Created: 2011-11-18 15:41:03+00:00
State: open
Labels: bug

Hi Aemon,

apologies for the delay in following this up...

On 10/11/2011, at 4:42 AM, Aemon Cannon wrote:

> The function ensime-config-find-file does the work of actually finding the .ensime file, given a path denoting the project directory, or any file, subdirectory within the project directory.
>
> On my machine, all these will correctly evaluate to the same .ensime file.
> (ensime-config-find-file "~/projects/ensime/")
> (ensime-config-find-file "~/projects/ensime/src/main")
> (ensime-config-find-file "~/projects/ensime/src/main/scala")
> (ensime-config-find-file "~/projects/ensime/src/main/scala/")
> (ensime-config-find-file "~/projects/ensime/.ensime")

Here's what happens -- which is completely reproducible here ;-)

Scenario #1, Using ECB:
a) open ~/path/to/src/main/scala/foo/Foo.scala file
b) M-x ensime
c) minibuffer prompt is: "ENSIME Project file: " ~/path/to/.ensime
d) hit return, ensime immediately states: Could not find an ENSIME project file. Would you like to generate one?

Scenario #2, Using ECB:
a) open ~/path/to/src/main/scala/foo/Foo.scala file
b) M-x ensime
c) minibuffer prompt is: "ENSIME Project file: " ~/path/to/.ensime
d) change to ~/path/to/ then hit enter
e) ensime starts

Scenario #3, Using ECB:
a) open ~/path/to/src/main/scala/foo/Foo.scala file
b) change dir to ~/path/to with cursor in ECB directory buffer
c) M-x ensime
c) minibuffer prompt is: "ENSIME Project file: " ~/path/to/
d) hit return, ensime starts

I've just done some debugging of the `ensime-config-find-and-load` function, copying it to my scratch buffer.
The arguments to `read-file-name` -- at least with emacs 24 -- appear to be causing it to return nil for scenario #1.

So if I M-:
(read-file-name "Foo: " (file-name-directory "~/path/to/.ensime") "~/path/to/.ensime" nil (file-name-nondirectory "~/path/to/.ensime"))
Minibuffer: Foo: ~/path/to/.ensime
--> ""

The docs for read-file-name suggest [1] "Please note: we recommend using default rather than initial in most cases."

http://www.gnu.org/software/emacs/elisp/html_node/Reading-File-Names.html