It's pretty easy: such "prettified symbols" have start/end of their region stored in text properties. So you basically just query that and if it's non-nil, then you know you're dealing with "pretty symbol".
Then solution involves adding an around-advice over delete-backward-char
which would query the aforementioned properties, and remove the region if they're there otherwise call the original delete-backward-char
.
;; an advice around delete-backward-char
(defun delete-backward-pretty-symbol-advice (orig-func n killflag)
"Remove \"pretty-symbol\" if it's prior to caret, otherwise call
`delete-backward-char'"
(if-let*
((prev-point (when (> (point) (point-min))
(- (point) 1)))
(pretty-start (get-text-property prev-point 'prettify-symbols-start))
(pretty-past-end (get-text-property prev-point 'prettify-symbols-end)))
(delete-region pretty-start pretty-past-end)
(funcall orig-func n killflag)))
(advice-add 'delete-backward-char :around #'delete-backward-pretty-symbol-advice)
;; an advice around evil-delete-char for evil-mode
(defun evil-delete-char-symbol-advice (orig-func beg past-end &optional type register)
"Include \"pretty-symbol\"s into region calculation for
`evil-delete-char'"
(let ((new-start
;; return `beg' if property is `nil'
(or (get-text-property beg 'prettify-symbols-start) beg))
(new-past-end
(max past-end
;; return `0' if property is `nil'
(or (get-text-property (- past-end 1) 'prettify-symbols-end) 0))))
(funcall orig-func new-start new-past-end type register)))
(advice-add 'evil-delete-char :around #'evil-delete-char-symbol-advice)
With the first advice in your init file, pressing Backspace should completely remove a "pretty symbol" if it's there.
The second one is for evil-mode
: pressing x while in "normal" mode of evil-mode
while the caret is over a "pretty symbol" should remove it as well.
M-d
perhaps (bound tokill-word
) or its evil equivalent?