I mean these:
I'd like to remove them, so I'm looking for a function which can find all these characters in the buffer which cannot be displayed properly with the current font and therefore show up like a rectangle.
It might be better to find fonts that can be used to display those characters, but if you really want to remove them:
(defun delete-non-displayable () (interactive) (require 'descr-text) ;; for `describe-char-display' (save-excursion (goto-char (point-min)) (while (not (eobp)) (if (or (eolp) (looking-at "\t") (describe-char-display (point) (char-after))) (forward-char) (delete-char 1)))))
Here I detail what I meant in my comment to his answer.
I've got the impression that this solution is more efficient and has at least the same level of simplicity as his solution. But maybe such a statement is subjective.
(defun delete-non-displayable () "Delete characters not contained in the used fonts and therefore non-displayable." (interactive) (require 'descr-text) ;; for `describe-char-display' (save-excursion (goto-char (point-min)) (while (re-search-forward "[^[:ascii:]]" nil 1) (unless (describe-char-display (1- (point)) (char-before)) (replace-match "")))))