I have a buffer that will have either plain text or an image (text properties) near the end of the buffer. I would like to delete any new lines or whitespace at the end of the buffer. How can I do this?
The following works if there is an image:
(delete-region (previous-property-change (point-max)) (point-max)). However, if there is no image, it deletes plain text -- which is not what I want.
The following works if there is no image, but deletes the image if there is one (which is also not what I want):
(save-excursion (goto-char (point-max)) (let ((trailing-whitespace+newlines (abs (skip-chars-backward "\s\r\n\t")))) (when (> trailing-whitespace+newlines 0) (delete-char trailing-whitespace+newlines))))