I copy text from websites and paste/yank into emacs buffers. But this text sometimes has silent hyphens in them. The behaviour when copying and pasting text with soft hyphens in it varies across applications, but for emacs (on Windows), it seems to paste the text including the soft hyphens. I want it to not include the soft hyphens.

What I've been doing right now is a manual M-x replace-string where I paste in the soft-hyphen to be replaced with nothing.

Is there a way to have emacs automatically replace soft-hyphen with nothing after a yank? Is there a hook to use?


There is a variable named interprogram-paste-function that is bound to the function that retrieves the value from the system.

You can define your own function that calls the original function and remove the hyphens, and bind it to this variable.

The package https://github.com/Lindydancer/highlight2clipboard does similar things, although it modifies things copied from Emacs to the outside world.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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