[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: RFC on implementation adding buttons beside headings
From: |
Bruno Barbier |
Subject: |
Re: RFC on implementation adding buttons beside headings |
Date: |
Mon, 20 Feb 2023 20:17:20 +0100 |
pareto optimal <pareto.optimal@mailfence.com> writes:
> I found the only way to place the button where I wanted was to insert
> some blank space after the heading. Is that expected and best practice
> or is there some other way to do it?
FWIW, instead of inserting some blank spaces, you could overlay existing
characters, you'll just need to re-inject them at display time so that
the display doesn't change. That way, you don't modified the text.
Here is a way to add a button, in place, without modifying the
buffer. The trick is to overlay the EOL and to re-inject an EOL
using the "after-string" property.
(with-current-buffer (generate-new-buffer "=test")
(cl-flet ((run (f) (lambda (&rest args) (interactive) (funcall f))))
(let (pos)
(insert "* My title\n")
(setq pos (1- (point)))
(insert "An amazing note.\n\n")
(insert "** My 2 title\n")
(insert "An even more amazing note.\n")
(org-mode)
(make-button pos (1+ pos)
'before-string "\n\n "
'display '((height 2) "Click me!")
'after-string "\n\n"
'face 'custom-button
'action (run (lambda () (message "Thanks!")))
)))
(pop-to-buffer (current-buffer))
)
Note that the above expression requires lexical-binding.
Bruno