I would like to have a dedicated buffer that has a number of buttons that display messages in a central display area when pressed. Can this be done?
Heime wrote: > I would like to have a dedicated buffer that has a number of > buttons that display messages in a central display area when > pressed. Can this be done? Sure, start with a (1) button ... -- underground experts united https://dataswamp.org/~incal
* Heime <heimeborgia@protonmail.com> [2022-11-11 17:35]: > I would like to have a dedicated buffer that has a number of buttons that display messages in a central display area > when pressed. Can this be done? It can be done, but you do not define your desires clearly. Each buffer in Emacs is dedicated, that I know. "number of buttons", what kind of buttons? Do you mean like button links as explained in (info "(elisp) Buttons") ? Define "central display area", do you mean center of the visible window? Or center of the buffer? Horizontally and vertically to window or buffer? Or center of the text width before wrap? I have this function: (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)) (rever-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))))) Which uses this one: (defun rcd-superscript-digits (number) "Return unicode digits for NUMBER." (let* ((string (cond ((numberp number) (number-to-string number)) ((stringp number) number))) (digits (split-string string "" t " "))) (with-temp-buffer (while digits (insert (rcd-superscript-digit-1 (string-to-number (pop digits))))) (buffer-string)))) Then you go like this: (rcd-button-insert "Display my message" (lambda (_) (message "My message"))) <-- evaluate it here or like this: (rcd-button-insert "Display my message" (lambda (_) (message "My message")) 21)Display my message²¹ Function is made so that buttons displayed may be reverted, but that is not subject of your interest now. (defun rcd-button-revert-source (&optional revert-key) "Revert the button source. REVERT-KEY is optional and by default the symbol 'REVERT-KEY. The value of REVERT-KEY will be returned as source." ;; (rcd-button-insert "Hello" (lambda (_) (message-box "Hello")) nil nil "⟦ (hyperscope 123) ⟧") (let ((point (point)) (revert-key (or revert-key 'revert-key))) (save-excursion (goto-char (point-min)) (let (my-prop) (while (setq my-prop (text-property-search-forward revert-key)) (when my-prop (let ((begin (prop-match-beginning my-prop)) (end (prop-match-end my-prop)) (value (prop-match-value my-prop))) (set-text-properties (1- begin) end nil) (delete-region begin end) (goto-char begin) (insert (format "%s" value))))))) (goto-char point))) -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns In support of Richard M. Stallman https://stallmansupport.org/
Sent with Proton Mail secure email. ------- Original Message ------- On Friday, November 11th, 2022 at 6:38 PM, Jean Louis <bugs@gnu.support> wrote: > * Heime heimeborgia@protonmail.com [2022-11-11 17:35]: > > > I would like to have a dedicated buffer that has a number of buttons that display messages in a central display area > > when pressed. Can this be done? > > > It can be done, but you do not define your desires clearly. > > Each buffer in Emacs is dedicated, that I know. > > "number of buttons", what kind of buttons? Do you mean like button > links as explained in (info "(elisp) Buttons") ? > > Define "central display area", do you mean center of the visible > window? Or center of the buffer? Horizontally and vertically to window > or buffer? Or center of the text width before wrap? To look like MCDU (Multi-Function Control Display Unit) on aircraft. https://www.uasc.com/home/shop/avionics/mcdu > I have this function: > > (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)) > (rever-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))))) > > Which uses this one: > > (defun rcd-superscript-digits (number) > "Return unicode digits for NUMBER." > (let* ((string (cond ((numberp number) (number-to-string number)) > ((stringp number) number))) > (digits (split-string string "" t " "))) > (with-temp-buffer > (while digits > (insert (rcd-superscript-digit-1 (string-to-number (pop digits))))) > (buffer-string)))) > > Then you go like this: > > (rcd-button-insert "Display my message" > (lambda () (message "My message"))) <-- evaluate it here > > or like this: > > (rcd-button-insert "Display my message" > (lambda () (message "My message")) 21)Display my message²¹ > > Function is made so that buttons displayed may be reverted, but that > is not subject of your interest now. > > (defun rcd-button-revert-source (&optional revert-key) > "Revert the button source. > > REVERT-KEY is optional and by default the symbol 'REVERT-KEY. The > value of REVERT-KEY will be returned as source." > ;; (rcd-button-insert "Hello" (lambda (_) (message-box "Hello")) nil nil "⟦ (hyperscope 123) ⟧") > (let ((point (point)) > (revert-key (or revert-key 'revert-key))) > (save-excursion > (goto-char (point-min)) > (let (my-prop) > (while (setq my-prop > (text-property-search-forward > revert-key)) > (when my-prop > (let ((begin (prop-match-beginning my-prop)) > (end (prop-match-end my-prop)) > (value (prop-match-value my-prop))) > (set-text-properties (1- begin) end nil) > (delete-region begin end) > (goto-char begin) > (insert (format "%s" value))))))) > (goto-char point))) > > -- > Jean > > Take action in Free Software Foundation campaigns: > https://www.fsf.org/campaigns > > In support of Richard M. Stallman > https://stallmansupport.org/
* Heime <heimeborgia@protonmail.com> [2022-11-12 10:59]: > > Define "central display area", do you mean center of the visible > > window? Or center of the buffer? Horizontally and vertically to window > > or buffer? Or center of the text width before wrap? > > To look like MCDU (Multi-Function Control Display Unit) on aircraft. > > https://www.uasc.com/home/shop/avionics/mcdu Hey, why not tell me earlier. That is already built-in Emacs feature, just do M-x mcdu and the control panel is displayed. -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns In support of Richard M. Stallman https://stallmansupport.org/
Would you give me an example of how to place a button at a specified buffer position?
------- Original Message -------
On Saturday, November 12th, 2022 at 8:31 AM, Jean Louis <bugs@gnu.support> wrote:
> * Heime heimeborgia@protonmail.com [2022-11-12 10:59]:
>
> > > Define "central display area", do you mean center of the visible
> > > window? Or center of the buffer? Horizontally and vertically to window
> > > or buffer? Or center of the text width before wrap?
> >
> > To look like MCDU (Multi-Function Control Display Unit) on aircraft.
> >
> > https://www.uasc.com/home/shop/avionics/mcdu
>
>
> Hey, why not tell me earlier.
>
> That is already built-in Emacs feature, just do M-x mcdu and the
> control panel is displayed.
>
>
> --
> Jean
>
> Take action in Free Software Foundation campaigns:
> https://www.fsf.org/campaigns
>
> In support of Richard M. Stallman
> https://stallmansupport.org/
Jean Louis wrote: >>> Define "central display area", do you mean center of the >>> visible window? Or center of the buffer? Horizontally and >>> vertically to window or buffer? Or center of the text >>> width before wrap? >> >> To look like MCDU (Multi-Function Control Display Unit) >> on aircraft. >> >> https://www.uasc.com/home/shop/avionics/mcdu > > Hey, why not tell me earlier. > > That is already built-in Emacs feature, just do M-x mcdu and > the control panel is displayed. In US and western fighter jets they have HUDs - Head-up displays - so can we have M-x hud RET as well, please? Actually development seems to have gone forward since I played F/A-18 Hornet in the 90s, as it says Although they were initially developed for military aviation, HUDs are now used in commercial aircraft, automobiles, and other (mostly professional) applications. [1] And isn't this what geek guys now build for their homes from old monitors, so-called smart/magic mirrors? So you see? There is absolutely no reason for us not to have it! [1] https://en.wikipedia.org/wiki/Head-up_display -- underground experts united https://dataswamp.org/~incal
* Heime <heimeborgia@protonmail.com> [2022-11-13 13:02]: > Would you give me an example of how to place a button at a specified buffer position? How would you specify it? You may use function `goto-char' as linear movement. You could as well use `goto-line' and then (goto-char (point-at-bol)) and after `forward-char' to go to some column of the text, this reminds me as coordinate with X and Y. (defun goto-x-y (x y) "Goto to line X, char Y." (goto-line x) (goto-char (point-at-bol)) (forward-char y)) (goto-x-y 10 20) -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns In support of Richard M. Stallman https://stallmansupport.org/
Jean Louis wrote: > You may use function `goto-char' as linear movement. > > You could as well use `goto-line' and then (goto-char > (point-at-bol)) and after `forward-char' to go to some > column of the text, this reminds me as coordinate with > X and Y. > > (defun goto-x-y (x y) > "Goto to line X, char Y." > (goto-line x) > (goto-char (point-at-bol)) > (forward-char y)) Problematic, you can use gamegrid for this M-x tetris RET > (goto-char (point-at-bol)) It's called `line-beginning-position' now ... -- underground experts united https://dataswamp.org/~incal
------- Original Message ------- On Tuesday, November 15th, 2022 at 12:54 AM, Emanuel Berg <incal@dataswamp.org> wrote: > Jean Louis wrote: > > > You may use function `goto-char' as linear movement. > > > > You could as well use `goto-line' and then (goto-char (point-at-bol)) and after` forward-char' to go to some > > column of the text, this reminds me as coordinate with > > X and Y. > > > > (defun goto-x-y (x y) > > "Goto to line X, char Y." > > (goto-line x) > > (goto-char (point-at-bol)) > > (forward-char y)) This does not work when buffer does not have position (x,y) as whitespace. > Problematic, you can use gamegrid for this > > M-x tetris RET > > > (goto-char (point-at-bol)) > > > It's called `line-beginning-position' now ... > > -- > underground experts united > https://dataswamp.org/~incal