I have emacs configured to refrain from inserting tabs for indentation purposes already. But this does not have any effect when I paste text containing a tab (from an external application, Google Chrome). How can I ensure that tabs are always replaced with spaces in pasted text?
As suggested in Qudit's answer, this can be done by advising
mouse-yank-primary (see section 12.3 of emacs manual):
(defun remove-tabs-in-region (string) (subst-char-in-region (point) (mark) ?\t 32)) (advice-add 'clipboard-yank :after #'remove-tabs-in-region) (advice-add 'mouse-yank-primary :after #'remove-tabs-in-region)
This does not try to be smart, each tab is simply replaced by a space. Maybe
indent-region could also be called in the advice?
You can do this by advising the yank commands:
(region-end) to get the region and then call
query-replace to change the tabs to the appropriate numbers of spaces.