Re: "Buttons" in a message buffer that evaluate to plain text?
Jean Louis <[email protected]>
| Newsgroups | gmane.emacs.help |
|---|---|
| Organization | GNU Support |
| Message-ID | <[email protected]> |
I made it to toggle on/off some variables:
(defun rcd-dashboard-button-check-item-toggle (check-item symbol key
check-in check-out rcd-dashboard-mode-name
&optional tip prefix symbol-name)
"Insert button CHECK-ITEM and enable toggling of SYMBOL value found
inside.
SYMBOL represents symbol of global variable.
Variables are toggled to be TRUE or FALSE.
CHECK-IN may be \"[ ]\", and CHECK-OUT \"[X]\" for Org mode. It
may be anything else.
Variable is expected to be global to function for it to work.
TIP is text that appears after the button.
PREFIX when available is inserted before the CHECK-IN."
(when (boundp symbol)
(let* ((my-line (line-number-at-pos (point)))
(function (lambda (&rest _)
(interactive)
(rcd-variable-toggle-global symbol)
(save-excursion
(read-only-mode 0)
(goto-char (point-min))
(forward-line (1- my-line))
(rcd-check check-in check-out)
(read-only-mode 1)))))
(keymap-set rcd-dashboard-mode-name key function)
(when prefix (insert prefix))
(insert (cond ((symbol-value symbol) check-out)
(t check-in)))
(insert " ")
(rcd-button-insert check-item
(lambda (_)
(interactive)
(rcd-variable-toggle-global symbol)
(read-only-mode 0)
(rcd-check check-in check-out)
(read-only-mode 1))
nil (or symbol-name "rcd-symbol") symbol)
(when tip (insert " " tip))
(insert "\n"))))
(defun rcd-variable-toggle-global (symbol)
"Toggle value of SYMBOL as TRUE or FALSE.
SYMBOL is expected to be global to the function."
(cond ((boundp symbol)
(cond ((eq (symbol-value symbol) t)
(set symbol nil)
(rcd-message "Variable `%s' OFF" symbol)
(rcd-speak "Off"))
((eq (symbol-value symbol) nil)
(set symbol t)
(rcd-message "Variable `%s' ON" symbol)
(rcd-speak "On")))
(symbol-value symbol))
(t (user-error "Cannot toggle non-global variable `%s'" symbol))))
(defun rcd-button-insert (button-text action-function &optional how-many
revert-key revert-value)
"Insert button BUTTON-TEXT with ACTION-FUNCTION.
Optional number HOW-MANY adds superscript digits to BUTTON-TEXT."
(let* ((revert-key (or revert-key "revert-key"))
(revert-key (intern revert-key))
(revert-value (or revert-value button-text)))
(insert-text-button button-text
'action
action-function
'follow-link t
revert-key revert-value)
(when how-many
(insert (rcd-superscript-digits how-many)))))
(defun rcd-check (&optional check-in check-out)
"Replace matches of CHECK-IN with CHECK-OUT in a line.
It is useful to toggle [ ] to [✔]"
(interactive)
(let* ((start (line-beginning-position))
(end (line-end-position))
(check-in (or check-in "❰ ❱"))
(check-out (or check-out "❰DONE❱")))
(rcd-check-start check-in check-out)
(save-excursion
(goto-char start)
(cond ((search-forward-regexp (regexp-quote check-in) end t)
(replace-match check-out))
((search-forward-regexp (regexp-quote check-out) end t)
(replace-match check-in))))))
(rcd-dashboard-button-check-item-toggle
"Toggle speech" 'rcd-speech "S" "❰ ❱" "❰✔️❱"
rcd-dashboard-RCD-notes-mode-map)
So then it works as on video attached. But it would need some re-work to
make it for you.
At least it can be starting point to understand how to make it.
--
Jean Louis
P.S. Video shows only toggling of variables, not the actual "full
screen" activity, as the agenda dashboard appears from time to time,
sometimes in split window, sometimes in full. So button is only about
toggling variables. Though it can do any action once programmed.
2026-04-18-10:54:49.mp4
(video/mp4, 742.3 KB) - not displayed