unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Jean Louis <bugs@gnu.support>
To: Heime <heimeborgia@protonmail.com>
Cc: Heime via Users list for the GNU Emacs text editor
	<help-gnu-emacs@gnu.org>
Subject: Re: Dedicated buffer with buttons that show messages in a central display area
Date: Fri, 11 Nov 2022 21:38:42 +0300	[thread overview]
Message-ID: <Y26WsjxIJ/5x9OBH@protected.localdomain> (raw)
In-Reply-To: <7JoMGtkVaj2vOMXLHgljVCzArGL8AADy9AiTLvPrnQ80fWENK2Lv73o5DxLfZ4PwAt6G3PgqgBC_tzkSVMsrC3fQd7vW7WNHGHJchNejiW0=@protonmail.com>

* 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/



  parent reply	other threads:[~2022-11-11 18:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-11 14:33 Dedicated buffer with buttons that show messages in a central display area Heime
2022-11-11 15:15 ` Emanuel Berg
2022-11-11 18:38 ` Jean Louis [this message]
2022-11-12  7:58   ` Heime
2022-11-12  8:31     ` Jean Louis
2022-11-13 10:02       ` Heime
2022-11-13 15:42         ` Jean Louis
2022-11-15  0:54           ` Emanuel Berg
2022-11-15 19:39             ` Heime
2022-11-13 11:26       ` Emanuel Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y26WsjxIJ/5x9OBH@protected.localdomain \
    --to=bugs@gnu.support \
    --cc=heimeborgia@protonmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).