From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Re: Dedicated buffer with buttons that show messages in a central display area Date: Fri, 11 Nov 2022 21:38:42 +0300 Message-ID: References: <7JoMGtkVaj2vOMXLHgljVCzArGL8AADy9AiTLvPrnQ80fWENK2Lv73o5DxLfZ4PwAt6G3PgqgBC_tzkSVMsrC3fQd7vW7WNHGHJchNejiW0=@protonmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40118"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.2.7+37 (a90f69b) (2022-09-02) Cc: Heime via Users list for the GNU Emacs text editor To: Heime Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 12 07:40:26 2022 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1otkBm-000AFA-9L for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 12 Nov 2022 07:40:26 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1otkBC-0007Aj-MT; Sat, 12 Nov 2022 01:39:50 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1otkB7-0007AS-6V for help-gnu-emacs@gnu.org; Sat, 12 Nov 2022 01:39:46 -0500 Original-Received: from stw1.rcdrun.com ([217.170.207.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1otkB4-0006T7-Vv for help-gnu-emacs@gnu.org; Sat, 12 Nov 2022 01:39:44 -0500 Original-Received: from localhost ([::ffff:154.227.216.217]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 0000000000056263.00000000636F3F8D.000076FE; Fri, 11 Nov 2022 23:39:08 -0700 Mail-Followup-To: Heime , Heime via Users list for the GNU Emacs text editor Content-Disposition: inline In-Reply-To: <7JoMGtkVaj2vOMXLHgljVCzArGL8AADy9AiTLvPrnQ80fWENK2Lv73o5DxLfZ4PwAt6G3PgqgBC_tzkSVMsrC3fQd7vW7WNHGHJchNejiW0=@protonmail.com> Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_12_24=1.049, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:140911 Archived-At: * Heime [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/