0

Using spacemacs I usually open new files for editing with C-s C-f (for find-file), since that is recommended by this answer.

However I have an issue when the file I wish to open is both new (doesn't yet exist), and is a substring of an existing file. For example: I want to open project/src/Types/List.hs for editing, but there already exists project/src/Types/InfiniteList.hs. So when I type the name of the file I wish to edit it selects the existing file from the list.

I tried also using neo-tree to create the file but it seems like it uses find-file to implement its file creation so the problem continues.

My current solution is to go to my terminal and touch the desired file before opening, but this is pretty annoying to do. Is there some way to do this from within spacemacs? Is there some alternative to find-file that I should be using here?

  • That isn’t the default Emacs behavior, so either you or Spacemacs have enabled something like `ido-mode` or similar. – db48x Jun 06 '21 at 11:41
  • @db48x It's definitely not `ido-mode`. Turning ido mode on switches to `ido-find-file` which works quite differently (but still does the annoying behavior). I'm working with a fresh spacemacs installation out of the box, so it is possible it is cause by something else but I don't know what. It certainly is default *spacemacs* behavior. – Éamonn Olive Jun 06 '21 at 12:05
  • `ido-mode` is just one that I could remember off the top of my head; there are a number of other popular packages that improve Emacs along these lines. You’ll have to dive into the Spacemacs documentation and find out what it is doing. – db48x Jun 06 '21 at 12:28
  • I believe this is ivy, also called swiper behavior. If so, you might try the keys C-M-j (ivy-immediate-done) – Lyn Headley Jun 06 '21 at 12:38
  • @LynHeadley `C-M-j` drops me into the dired by name mode in the current directory. I'm not sure what it is supposed to do, but that's what happens when I try it. – Éamonn Olive Jun 06 '21 at 13:02
  • Please incorporate any relevant info from comments into the question itself (including updating tags, if appropriate). Comments can be deleted at any time. Thx. – Drew Jun 06 '21 at 15:47
  • @Drew What information are you thinking of specifically? – Éamonn Olive Jun 06 '21 at 16:52
  • Not thinking of anything specifically. Got the impression that comments were perhaps beginning to specify the question further. – Drew Jun 06 '21 at 19:29
  • 1
    @LynHeadley I had this annoyance too and never bothered to look into it until now. I'm using normal Emacs though with `counsel-find-file` to find files. The `C-M-j` works for me on your exact example. I have a directory with `InfiniteList.hs` I launch `counsel-find-file` (with `SPC f f` for me), type `List.hs`. It autocomplete to `InfiniteList.hs`, but pressing `C-M-j` ignores the completion and creates `List.hs`. You should check what function your key binding is bound to. It might not be an ivy function, but a helm one instead (or something else). – willbush Jun 09 '21 at 06:16
  • @willbush Ah I see. This actually solves my problem. `C-M-j` does indeed work. Since I didn't know what it was supposed to do I didn't realize that I had to type the entire file name before `C-M-j`. It makes perfect sense it dropped me into dired mode. – Éamonn Olive Jun 09 '21 at 07:20

0 Answers0