Test for `point` within an attachment in `mail-mode`
- by lawlist
I'm looking for a better test to determine when point is within a hidden attachment in mail-mode (which is used by wl-draft-mode). The attachments are mostly hidden and look like this:
--[[application/xls
Content-Disposition: attachment; filename="hello-world.xls"][base64]]
The test of invisible-p yields a result of nil. I am current using the following test, but it seems rather poor:
(save-excursion
(goto-char (point-max))
(goto-char (previous-char-property-change (point)))
(goto-char (previous-char-property-change (point)))
(re-search-backward "]]" (point-at-bol) t)))
Any suggestions would be greatly appreciated.
Here is the full snippet:
(goto-char (point-max))
(cond
((= (save-excursion (abs (skip-chars-backward "\n\t"))) 0)
(insert "\n\n"))
((and
(= (save-excursion (abs (skip-chars-backward "\n\t"))) 1)
(not
(save-excursion
(goto-char (previous-char-property-change (point)))
(goto-char (previous-char-property-change (point)))
(re-search-backward "]]" (point-at-bol) t))))
(insert "\n")))
GOAL: If there are no attachments and no new lines at the end of the buffer, then insert \n\n and then insert the attachment thereafter. If there is just one new line at the end of the buffer, then insert \n and then insert the attachment thereafter. If there is an attachment at the end of the buffer, then do not insert any new lines.