0

When I try to use the function ff-find-other-file on a C file, and the header file does not exist, I expect emacs to create a header file at the current location.

Since I started using helm, something else happens:

$ mkdir /tmp/helm-other-file
$ cd /tmp/helm-other-file
$ emacs a.c

M-x ff-find-other-file opens a helm buffer with two entries:

/tmp/helm-other-file/.
/tmp/helm-other-file/..

I expected that selecting the first would mean to create the buffer at that location: /tmp/helm-other-file/a.h.

Instead, the following is created: /tmp/helm-other-file/a.h/a.h. That's one (new) directory too deep.

If I select the .. version, to compensate for "too deep", I get /tmp/a.h. That's not deep enough.

If I go up a level with C-l after ff-find-other-file, then select helm-other-file/, I go back to this: /tmp/helm-other-file/a.h/a.h.

How can I fix ff-find-other-file so that unfound header file is created at the same location as the C file, with helm? I'm aware that helm-projectile might fix this, but I don't want to bring in the whole package only for that function.

1 Answer 1

1

It seems you've helm-mode enabled, the minor mode overwrites Emacs' built-in completing behavior, the thing you want is the default (it comes from completing-read's DEF argument) value, you can either C-RET (helm-cr-empty-string) to apply the default value or M-n (next-history-element) to insert the default value then RET.

You can also blacklist ff-find-other-file from helm-mode, next time helm-mode won't be involved in ff-find-other-file:

(add-to-list 'helm-completing-read-handlers-alist
             '(ff-find-other-file . nil))
2
  • C-RET did the trick, thanks! When does the behavior I'm observing make sense?
    – Gauthier
    Commented May 22, 2020 at 13:38
  • @Gauthier ff-find-other-file's use of read-directory-name is suspicious, it supplies a filename such as a.h as DEFAULT-DIRNAME, though it works fine with vanilla Emacs as it simply returns a.h, but with helm-mode, when you select the current directory, read-directory-name returns $PWD/a.h/.
    – xuchunyang
    Commented May 22, 2020 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.