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)))))
(re-search-forward "[^[:ascii:]]" nil 1)
with (describe-char-display (1- (point)) (char-before))
.
Robert Pluim proposed already a solution.
The credit for describe-char-display
belongs to him.
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 "")))))
buffer-display-table
to display those characters with another character that is supported, such as an ascii ☺ in lieu of01F 91C
and ☻ for01F 91B
as depicted in the photo.char-displayable-p
help here?Return non-nil if we should be able to display CHAR. On a multi-font display, the test is only whether there is an appropriate font from the selected frame’s fontset to display CHAR’s charset in general. Since fonts may be specified on a per-character basis, this may not be accurate.
char-displayable-p
doesn't seem to do the right thing for this case.(char-displayable-p #x1f91c)
returnsunicode
, even when my font can't display that character.