Kill Sexp or Directory07 Apr 2015, by Artur Malabarba.
Cluttered as our keyboards are with key-binds, it's always nice when we can combine two disjoint functionalities in the same key. I have M-k and C-M-k bound to killing the next and previous sexp, respectively, but that is never something I need inside a string or when typing a file name in the minibuffer. Then these keys become utterly useless!
The solution to this conundrum is, of course, to find another use for them in these cases. Something that comes up regularly inside strings (or file-name prompts) is killing an entire directory name.
The code below, binds M-k to a command that automatically decides whether to kill a sexp or a directory name. The decision making is a little tricky, but it has yet to let me down.