2

I get this error when I am trying to swtch buffer and a folder of an open buffer is deleted outside emacs:

Error in post-command-hook (evil-mode-check-buffers): (file-error "Setting current directory" "directory not found")

I think it would be better to just close the buffer or offer the user to save open files elsewhere instead of giving error and block all other commands.

Is there a way to avoid the blockage?

2

1 Answer 1

1

You could override the post-command-hook function to check for the folder, then if it doesn't exist, do something else or just kill the buffer.

This article has some insight on how to do that.

Basically overriding the function is redefining the function locally, so you can change it's behavior. This allows you to alter the functionality without having to delve into Emacs source code, recompiling, etc.

Probably the easiest (at least in my opinion) is to C-h f <function-name> RET, then should show you what elisp file contains that function, so you can get to the source code easily. Once you do that, you should be able to add a command or function call to do what you wish (i.e. close a buffer or save elsewhere). I don't have evil installed, but this is an example of looking at C-h f load-theme RET:

load-theme is an interactive compiled Lisp function in 'custom.el'

So now you know that the function you're looking for is in custom.el (in my example.)

Here is the GNU page on hooks, which is what you're effectively creating.

0

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.