* Highlighting text next to button @ 2024-06-30 20:00 Heime 2024-06-30 21:52 ` Heime 0 siblings, 1 reply; 7+ messages in thread From: Heime @ 2024-06-30 20:00 UTC (permalink / raw To: Heime via Users list for the GNU Emacs text editor I have the function monde that displays some buttons with associated text describing what the button does. I would like to highlight the description text corresponding to the button that was pressed, with NORM being the default when calling the function. What can I do ? (defun spaz (w) "Make a string of width W made of spaces." (make-string w ?\s)) (defun mondu () (interactive) (with-current-buffer (get-buffer-create "Mondu") (insert " MAIN PANEL DU \n\n") (insert " ") (insert-button "[-]" 'action 'mondu-outbd) (insert " OUTBD ") (insert-button "[-]" 'action 'mondu-norm) (insert " NORM ") ;;------------------------------------------------------------ (insert-button "[-]" 'action 'mondu-inbd-eng-pri) (insert " INBD ENG PRI \n") (insert (spaz 24)) (insert-button "[-]" 'action 'mondu-inbd-pfd) (insert " INBD PFD \n") (insert (spaz 24)) (insert-button "[-]" 'action 'mondu-inbd-hfd) (insert " INBD HFD \n") ) (pop-to-buffer "Mondu") ) ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Highlighting text next to button 2024-06-30 20:00 Highlighting text next to button Heime @ 2024-06-30 21:52 ` Heime 2024-06-30 22:11 ` Stephen Berman 0 siblings, 1 reply; 7+ messages in thread From: Heime @ 2024-06-30 21:52 UTC (permalink / raw To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor On Sunday, June 30th, 2024 at 8:00 PM, Heime <heimeborgia@protonmail.com> wrote: > I have the function monde that displays some buttons with associated text > describing what the button does. > > I would like to highlight the description text corresponding to the button > that was pressed, with NORM being the default when calling the function. > What can I do ? > > (defun spaz (w) > "Make a string of width W made of spaces." > (make-string w ?\s)) > > (defun mondu () > > (interactive) > > (with-current-buffer (get-buffer-create "Mondu") > > (insert " MAIN PANEL DU \n\n") > > (insert " ") > (insert-button "[-]" 'action 'mondu-outbd) > (insert " OUTBD ") > > (insert-button "[-]" 'action 'mondu-norm) > (insert " NORM ") > > ;;------------------------------------------------------------ > > (insert-button "[-]" 'action 'mondu-inbd-eng-pri) > (insert " INBD ENG PRI \n") > > (insert (spaz 24)) > (insert-button "[-]" 'action 'mondu-inbd-pfd) > (insert " INBD PFD \n") > > (insert (spaz 24)) > (insert-button "[-]" 'action 'mondu-inbd-hfd) > (insert " INBD HFD \n") ) > > (pop-to-buffer "Mondu") ) Have made the following. But I also have to activate the text that is printed to the help buffer when pressing the button. (defun mondu-color-text (text color) "Color TEXT in the specified COLOR in the Mondu buffer." (with-current-buffer "Mondu" (save-excursion (goto-char (point-min)) (when (search-forward text nil t) (let ((start (match-beginning 0)) (end (match-end 0))) (add-text-properties start end `(face (:foreground ,color)))))))) (defun mondu () "Set up the Mondu buffer with buttons and text." (interactive) (with-current-buffer (get-buffer-create "Mondu") (erase-buffer) ;; Clear the buffer to avoid repeated content on multiple invocations (insert " MAIN PANEL DU \n\n") (insert " ") (insert-button "[-]" 'action (lambda (_) (mondu-color-text " OUTBD " "red"))) (insert " OUTBD ") (insert-button "[-]" 'action (lambda (_) (mondu-color-text " NORM " "red"))) (montejura-insert-colorat " NORM " "red") (insert-button "[-]" 'action (lambda (_) (mondu-color-text " INBD ENG PRI " "red"))) (insert " INBD ENG PRI \n") (insert (espz 24)) (insert-button "[-]" 'action (lambda (_) (mondu-color-text " INBD PFD " "red"))) (insert " INBD PFD \n") (insert (espz 24)) (insert-button "[-]" 'action (lambda (_) (mondu-color-text " INBD HFD " "red"))) (insert " INBD HFD \n")) (pop-to-buffer "Mondu")) ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Highlighting text next to button 2024-06-30 21:52 ` Heime @ 2024-06-30 22:11 ` Stephen Berman 2024-06-30 22:32 ` Heime 0 siblings, 1 reply; 7+ messages in thread From: Stephen Berman @ 2024-06-30 22:11 UTC (permalink / raw To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor On Sun, 30 Jun 2024 21:52:12 +0000 Heime <heimeborgia@protonmail.com> wrote: > On Sunday, June 30th, 2024 at 8:00 PM, Heime <heimeborgia@protonmail.com> wrote: > >> I have the function monde that displays some buttons with associated text >> describing what the button does. >> >> I would like to highlight the description text corresponding to the button >> that was pressed, with NORM being the default when calling the function. >> What can I do ? >> >> (defun spaz (w) >> "Make a string of width W made of spaces." >> (make-string w ?\s)) >> >> (defun mondu () >> >> (interactive) >> >> (with-current-buffer (get-buffer-create "Mondu") >> >> (insert " MAIN PANEL DU \n\n") >> >> (insert " ") >> (insert-button "[-]" 'action 'mondu-outbd) >> (insert " OUTBD ") >> >> (insert-button "[-]" 'action 'mondu-norm) >> (insert " NORM ") >> >> ;;------------------------------------------------------------ >> >> (insert-button "[-]" 'action 'mondu-inbd-eng-pri) >> (insert " INBD ENG PRI \n") >> >> (insert (spaz 24)) >> (insert-button "[-]" 'action 'mondu-inbd-pfd) >> (insert " INBD PFD \n") >> >> (insert (spaz 24)) >> (insert-button "[-]" 'action 'mondu-inbd-hfd) >> (insert " INBD HFD \n") ) >> >> (pop-to-buffer "Mondu") ) > > Have made the following. But I also have to activate the text that is printed > to the help buffer when pressing the button. > > > (defun mondu-color-text (text color) > "Color TEXT in the specified COLOR in the Mondu buffer." > > (with-current-buffer "Mondu" > (save-excursion > (goto-char (point-min)) > (when (search-forward text nil t) > (let ((start (match-beginning 0)) > (end (match-end 0))) > (add-text-properties start end `(face (:foreground ,color)))))))) > > > (defun mondu () > "Set up the Mondu buffer with buttons and text." > > (interactive) > > (with-current-buffer (get-buffer-create "Mondu") > > (erase-buffer) ;; Clear the buffer to avoid repeated content on multiple invocations > > (insert " MAIN PANEL DU \n\n") > > (insert " ") > (insert-button "[-]" > 'action (lambda (_) (mondu-color-text " OUTBD " "red"))) > (insert " OUTBD ") > > (insert-button "[-]" > 'action (lambda (_) (mondu-color-text " NORM " "red"))) > (montejura-insert-colorat " NORM " "red") > > (insert-button "[-]" > 'action (lambda (_) (mondu-color-text " INBD ENG PRI " "red"))) > (insert " INBD ENG PRI \n") > > (insert (espz 24)) > (insert-button "[-]" > 'action (lambda (_) (mondu-color-text " INBD PFD " "red"))) > (insert " INBD PFD \n") > > (insert (espz 24)) > (insert-button "[-]" > 'action (lambda (_) (mondu-color-text " INBD HFD " "red"))) > (insert " INBD HFD \n")) > > (pop-to-buffer "Mondu")) Perhaps this (based on the first version): (defun mondu () (interactive) (with-current-buffer (get-buffer-create "Mondu") (let ((make-desc (lambda (&optional description) (insert (propertize (or description " NORM ") 'face '( :weight bold :slant italic :background "lightgray")))))) (insert " MAIN PANEL DU \n\n") (insert " ") (insert-button "[-]" 'action 'mondu-outbd) (funcall make-desc " OUTBD ") (insert-button "[-]" 'action 'mondu-norm) (funcall make-desc) ;;------------------------------------------------------------ (insert-button "[-]" 'action 'mondu-inbd-eng-pri) (funcall make-desc " INBD ENG PRI \n") (insert (spaz 24)) (insert-button "[-]" 'action 'mondu-inbd-pfd) (funcall make-desc " INBD PFD \n") (insert (spaz 24)) (insert-button "[-]" 'action 'mondu-inbd-hfd) (funcall make-desc" INBD HFD \n"))) (pop-to-buffer "Mondu")) Steve Berman ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Highlighting text next to button 2024-06-30 22:11 ` Stephen Berman @ 2024-06-30 22:32 ` Heime 2024-07-01 7:53 ` Stephen Berman 0 siblings, 1 reply; 7+ messages in thread From: Heime @ 2024-06-30 22:32 UTC (permalink / raw To: Stephen Berman; +Cc: Heime via Users list for the GNU Emacs text editor On Sunday, June 30th, 2024 at 10:11 PM, Stephen Berman <stephen.berman@gmx.net> wrote: > On Sun, 30 Jun 2024 21:52:12 +0000 Heime heimeborgia@protonmail.com wrote: > > > On Sunday, June 30th, 2024 at 8:00 PM, Heime heimeborgia@protonmail.com wrote: > > > > > I have the function monde that displays some buttons with associated text > > > describing what the button does. > > > > > > I would like to highlight the description text corresponding to the button > > > that was pressed, with NORM being the default when calling the function. > > > What can I do ? > > > > > > (defun spaz (w) > > > "Make a string of width W made of spaces." > > > (make-string w ?\s)) > > > > > > (defun mondu () > > > > > > (interactive) > > > > > > (with-current-buffer (get-buffer-create "Mondu") > > > > > > (insert " MAIN PANEL DU \n\n") > > > > > > (insert " ") > > > (insert-button "[-]" 'action 'mondu-outbd) > > > (insert " OUTBD ") > > > > > > (insert-button "[-]" 'action 'mondu-norm) > > > (insert " NORM ") > > > > > > ;;------------------------------------------------------------ > > > > > > (insert-button "[-]" 'action 'mondu-inbd-eng-pri) > > > (insert " INBD ENG PRI \n") > > > > > > (insert (spaz 24)) > > > (insert-button "[-]" 'action 'mondu-inbd-pfd) > > > (insert " INBD PFD \n") > > > > > > (insert (spaz 24)) > > > (insert-button "[-]" 'action 'mondu-inbd-hfd) > > > (insert " INBD HFD \n") ) > > > > > > (pop-to-buffer "Mondu") ) > > > > Have made the following. But I also have to activate the text that is printed > > to the help buffer when pressing the button. > > > > (defun mondu-color-text (text color) > > "Color TEXT in the specified COLOR in the Mondu buffer." > > > > (with-current-buffer "Mondu" > > (save-excursion > > (goto-char (point-min)) > > (when (search-forward text nil t) > > (let ((start (match-beginning 0)) > > (end (match-end 0))) > > (add-text-properties start end `(face (:foreground ,color)))))))) > > > > (defun mondu () > > "Set up the Mondu buffer with buttons and text." > > > > (interactive) > > > > (with-current-buffer (get-buffer-create "Mondu") > > > > (erase-buffer) ;; Clear the buffer to avoid repeated content on multiple invocations > > > > (insert " MAIN PANEL DU \n\n") > > > > (insert " ") > > (insert-button "[-]" > > 'action (lambda (_) (mondu-color-text " OUTBD " "red"))) > > (insert " OUTBD ") > > > > (insert-button "[-]" > > 'action (lambda (_) (mondu-color-text " NORM " "red"))) > > (montejura-insert-colorat " NORM " "red") > > > > (insert-button "[-]" > > 'action (lambda (_) (mondu-color-text " INBD ENG PRI " "red"))) > > (insert " INBD ENG PRI \n") > > > > (insert (espz 24)) > > (insert-button "[-]" > > 'action (lambda (_) (mondu-color-text " INBD PFD " "red"))) > > (insert " INBD PFD \n") > > > > (insert (espz 24)) > > (insert-button "[-]" > > 'action (lambda (_) (mondu-color-text " INBD HFD " "red"))) > > (insert " INBD HFD \n")) > > > > (pop-to-buffer "Mondu")) > > > Perhaps this (based on the first version): > > (defun mondu () > (interactive) > (with-current-buffer (get-buffer-create "Mondu") > (let ((make-desc (lambda (&optional description) > (insert (propertize (or description " NORM ") > 'face '( :weight bold > :slant italic > :background "lightgray")))))) > (insert " MAIN PANEL DU \n\n") > (insert " ") > (insert-button "[-]" 'action 'mondu-outbd) > (funcall make-desc " OUTBD ") > (insert-button "[-]" 'action 'mondu-norm) > (funcall make-desc) > ;;------------------------------------------------------------ > (insert-button "[-]" 'action 'mondu-inbd-eng-pri) > (funcall make-desc " INBD ENG PRI \n") > (insert (spaz 24)) > (insert-button "[-]" 'action 'mondu-inbd-pfd) > (funcall make-desc " INBD PFD \n") > (insert (spaz 24)) > (insert-button "[-]" 'action 'mondu-inbd-hfd) > (funcall make-desc" INBD HFD \n"))) > (pop-to-buffer "Mondu")) > > Steve Berman Steve, your function highlights everything, not only the text next to where the button was pressed. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Highlighting text next to button 2024-06-30 22:32 ` Heime @ 2024-07-01 7:53 ` Stephen Berman 2024-07-01 8:52 ` Heime 0 siblings, 1 reply; 7+ messages in thread From: Stephen Berman @ 2024-07-01 7:53 UTC (permalink / raw To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor On Sun, 30 Jun 2024 22:32:24 +0000 Heime <heimeborgia@protonmail.com> wrote: > On Sunday, June 30th, 2024 at 10:11 PM, Stephen Berman > <stephen.berman@gmx.net> wrote: > >> On Sun, 30 Jun 2024 21:52:12 +0000 Heime heimeborgia@protonmail.com wrote: >> >> > On Sunday, June 30th, 2024 at 8:00 PM, Heime heimeborgia@protonmail.com wrote: >> > >> > > I have the function monde that displays some buttons with associated text >> > > describing what the button does. >> > > >> > > I would like to highlight the description text corresponding to the button >> > > that was pressed, with NORM being the default when calling the function. >> > > What can I do ? >> > > >> > > (defun spaz (w) >> > > "Make a string of width W made of spaces." >> > > (make-string w ?\s)) >> > > >> > > (defun mondu () >> > > >> > > (interactive) >> > > >> > > (with-current-buffer (get-buffer-create "Mondu") >> > > >> > > (insert " MAIN PANEL DU \n\n") >> > > >> > > (insert " ") >> > > (insert-button "[-]" 'action 'mondu-outbd) >> > > (insert " OUTBD ") >> > > >> > > (insert-button "[-]" 'action 'mondu-norm) >> > > (insert " NORM ") >> > > >> > > ;;------------------------------------------------------------ >> > > >> > > (insert-button "[-]" 'action 'mondu-inbd-eng-pri) >> > > (insert " INBD ENG PRI \n") >> > > >> > > (insert (spaz 24)) >> > > (insert-button "[-]" 'action 'mondu-inbd-pfd) >> > > (insert " INBD PFD \n") >> > > >> > > (insert (spaz 24)) >> > > (insert-button "[-]" 'action 'mondu-inbd-hfd) >> > > (insert " INBD HFD \n") ) >> > > >> > > (pop-to-buffer "Mondu") ) >> > >> > Have made the following. But I also have to activate the text that is printed >> > to the help buffer when pressing the button. >> > >> > (defun mondu-color-text (text color) >> > "Color TEXT in the specified COLOR in the Mondu buffer." >> > >> > (with-current-buffer "Mondu" >> > (save-excursion >> > (goto-char (point-min)) >> > (when (search-forward text nil t) >> > (let ((start (match-beginning 0)) >> > (end (match-end 0))) >> > (add-text-properties start end `(face (:foreground ,color)))))))) >> > >> > (defun mondu () >> > "Set up the Mondu buffer with buttons and text." >> > >> > (interactive) >> > >> > (with-current-buffer (get-buffer-create "Mondu") >> > >> > (erase-buffer) ;; Clear the buffer to avoid repeated content on multiple >> > invocations >> > >> > (insert " MAIN PANEL DU \n\n") >> > >> > (insert " ") >> > (insert-button "[-]" >> > 'action (lambda (_) (mondu-color-text " OUTBD " "red"))) >> > (insert " OUTBD ") >> > >> > (insert-button "[-]" >> > 'action (lambda (_) (mondu-color-text " NORM " "red"))) >> > (montejura-insert-colorat " NORM " "red") >> > >> > (insert-button "[-]" >> > 'action (lambda (_) (mondu-color-text " INBD ENG PRI " "red"))) >> > (insert " INBD ENG PRI \n") >> > >> > (insert (espz 24)) >> > (insert-button "[-]" >> > 'action (lambda (_) (mondu-color-text " INBD PFD " "red"))) >> > (insert " INBD PFD \n") >> > >> > (insert (espz 24)) >> > (insert-button "[-]" >> > 'action (lambda (_) (mondu-color-text " INBD HFD " "red"))) >> > (insert " INBD HFD \n")) >> > >> > (pop-to-buffer "Mondu")) >> >> >> Perhaps this (based on the first version): >> >> (defun mondu () >> (interactive) >> (with-current-buffer (get-buffer-create "Mondu") >> (let ((make-desc (lambda (&optional description) >> (insert (propertize (or description " NORM ") >> 'face '( :weight bold >> :slant italic >> :background "lightgray")))))) >> (insert " MAIN PANEL DU \n\n") >> (insert " ") >> (insert-button "[-]" 'action 'mondu-outbd) >> (funcall make-desc " OUTBD ") >> (insert-button "[-]" 'action 'mondu-norm) >> (funcall make-desc) >> ;;------------------------------------------------------------ >> (insert-button "[-]" 'action 'mondu-inbd-eng-pri) >> (funcall make-desc " INBD ENG PRI \n") >> (insert (spaz 24)) >> (insert-button "[-]" 'action 'mondu-inbd-pfd) >> (funcall make-desc " INBD PFD \n") >> (insert (spaz 24)) >> (insert-button "[-]" 'action 'mondu-inbd-hfd) >> (funcall make-desc" INBD HFD \n"))) >> (pop-to-buffer "Mondu")) >> >> Steve Berman > > Steve, your function highlights everything, not only the text next to > where the button was pressed. Do you mean the background color? That was just an example; if you don't want it, then just don't include it in the value of the `face' property. E.g., if you just want the text next to the button to be red, just use '(:foreground "red") as the value of the `face' property. Steve Berman ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Highlighting text next to button 2024-07-01 7:53 ` Stephen Berman @ 2024-07-01 8:52 ` Heime 2024-07-01 9:26 ` Stephen Berman 0 siblings, 1 reply; 7+ messages in thread From: Heime @ 2024-07-01 8:52 UTC (permalink / raw To: Stephen Berman; +Cc: Heime via Users list for the GNU Emacs text editor On Monday, July 1st, 2024 at 7:53 AM, Stephen Berman <stephen.berman@gmx.net> wrote: > On Sun, 30 Jun 2024 22:32:24 +0000 Heime heimeborgia@protonmail.com wrote: > > > On Sunday, June 30th, 2024 at 10:11 PM, Stephen Berman > > stephen.berman@gmx.net wrote: > > > > > On Sun, 30 Jun 2024 21:52:12 +0000 Heime heimeborgia@protonmail.com wrote: > > > > > > > On Sunday, June 30th, 2024 at 8:00 PM, Heime heimeborgia@protonmail.com wrote: > > > > > > > > > I have the function monde that displays some buttons with associated text > > > > > describing what the button does. > > > > > > > > > > I would like to highlight the description text corresponding to the button > > > > > that was pressed, with NORM being the default when calling the function. > > > > > What can I do ? > > > > > > > > > > (defun spaz (w) > > > > > "Make a string of width W made of spaces." > > > > > (make-string w ?\s)) > > > > > > > > > > (defun mondu () > > > > > > > > > > (interactive) > > > > > > > > > > (with-current-buffer (get-buffer-create "Mondu") > > > > > > > > > > (insert " MAIN PANEL DU \n\n") > > > > > > > > > > (insert " ") > > > > > (insert-button "[-]" 'action 'mondu-outbd) > > > > > (insert " OUTBD ") > > > > > > > > > > (insert-button "[-]" 'action 'mondu-norm) > > > > > (insert " NORM ") > > > > > > > > > > ;;------------------------------------------------------------ > > > > > > > > > > (insert-button "[-]" 'action 'mondu-inbd-eng-pri) > > > > > (insert " INBD ENG PRI \n") > > > > > > > > > > (insert (spaz 24)) > > > > > (insert-button "[-]" 'action 'mondu-inbd-pfd) > > > > > (insert " INBD PFD \n") > > > > > > > > > > (insert (spaz 24)) > > > > > (insert-button "[-]" 'action 'mondu-inbd-hfd) > > > > > (insert " INBD HFD \n") ) > > > > > > > > > > (pop-to-buffer "Mondu") ) > > > > > > > > Have made the following. But I also have to activate the text that is printed > > > > to the help buffer when pressing the button. > > > > > > > > (defun mondu-color-text (text color) > > > > "Color TEXT in the specified COLOR in the Mondu buffer." > > > > > > > > (with-current-buffer "Mondu" > > > > (save-excursion > > > > (goto-char (point-min)) > > > > (when (search-forward text nil t) > > > > (let ((start (match-beginning 0)) > > > > (end (match-end 0))) > > > > (add-text-properties start end `(face (:foreground ,color)))))))) > > > > > > > > (defun mondu () > > > > "Set up the Mondu buffer with buttons and text." > > > > > > > > (interactive) > > > > > > > > (with-current-buffer (get-buffer-create "Mondu") > > > > > > > > (erase-buffer) ;; Clear the buffer to avoid repeated content on multiple > > > > invocations > > > > > > > > (insert " MAIN PANEL DU \n\n") > > > > > > > > (insert " ") > > > > (insert-button "[-]" > > > > 'action (lambda (_) (mondu-color-text " OUTBD " "red"))) > > > > (insert " OUTBD ") > > > > > > > > (insert-button "[-]" > > > > 'action (lambda (_) (mondu-color-text " NORM " "red"))) > > > > (montejura-insert-colorat " NORM " "red") > > > > > > > > (insert-button "[-]" > > > > 'action (lambda (_) (mondu-color-text " INBD ENG PRI " "red"))) > > > > (insert " INBD ENG PRI \n") > > > > > > > > (insert (espz 24)) > > > > (insert-button "[-]" > > > > 'action (lambda (_) (mondu-color-text " INBD PFD " "red"))) > > > > (insert " INBD PFD \n") > > > > > > > > (insert (espz 24)) > > > > (insert-button "[-]" > > > > 'action (lambda (_) (mondu-color-text " INBD HFD " "red"))) > > > > (insert " INBD HFD \n")) > > > > > > > > (pop-to-buffer "Mondu")) > > > > > > Perhaps this (based on the first version): > > > > > > (defun mondu () > > > (interactive) > > > (with-current-buffer (get-buffer-create "Mondu") > > > (let ((make-desc (lambda (&optional description) > > > (insert (propertize (or description " NORM ") > > > 'face '( :weight bold > > > :slant italic > > > :background "lightgray")))))) > > > (insert " MAIN PANEL DU \n\n") > > > (insert " ") > > > (insert-button "[-]" 'action 'mondu-outbd) > > > (funcall make-desc " OUTBD ") > > > (insert-button "[-]" 'action 'mondu-norm) > > > (funcall make-desc) > > > ;;------------------------------------------------------------ > > > (insert-button "[-]" 'action 'mondu-inbd-eng-pri) > > > (funcall make-desc " INBD ENG PRI \n") > > > (insert (spaz 24)) > > > (insert-button "[-]" 'action 'mondu-inbd-pfd) > > > (funcall make-desc " INBD PFD \n") > > > (insert (spaz 24)) > > > (insert-button "[-]" 'action 'mondu-inbd-hfd) > > > (funcall make-desc" INBD HFD \n"))) > > > (pop-to-buffer "Mondu")) > > > > > > Steve Berman > > > > Steve, your function highlights everything, not only the text next to > > where the button was pressed. > > > Do you mean the background color? That was just an example; if you > don't want it, then just don't include it in the value of the `face' > property. E.g., if you just want the text next to the button to be > red, just use '(:foreground "red") as the value of the` face' property. > > Steve Berman It is more complicated. When one presses the button "OUTBD", only the word "OUTBD" gets coloured red. The other string are reset with no color. Meaning that the highlight is only applied to the text to which the key was pressed. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Highlighting text next to button 2024-07-01 8:52 ` Heime @ 2024-07-01 9:26 ` Stephen Berman 0 siblings, 0 replies; 7+ messages in thread From: Stephen Berman @ 2024-07-01 9:26 UTC (permalink / raw To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor On Mon, 01 Jul 2024 08:52:34 +0000 Heime <heimeborgia@protonmail.com> wrote: > On Monday, July 1st, 2024 at 7:53 AM, Stephen Berman <stephen.berman@gmx.net> wrote: > >> On Sun, 30 Jun 2024 22:32:24 +0000 Heime heimeborgia@protonmail.com wrote: >> >> > On Sunday, June 30th, 2024 at 10:11 PM, Stephen Berman >> > stephen.berman@gmx.net wrote: >> > >> > > On Sun, 30 Jun 2024 21:52:12 +0000 Heime heimeborgia@protonmail.com wrote: >> > > >> > > > On Sunday, June 30th, 2024 at 8:00 PM, Heime >> > > > heimeborgia@protonmail.com wrote: >> > > > >> > > > > I have the function monde that displays some buttons with associated text >> > > > > describing what the button does. >> > > > > >> > > > > I would like to highlight the description text corresponding to the button >> > > > > that was pressed, with NORM being the default when calling the function. >> > > > > What can I do ? >> > > > > >> > > > > (defun spaz (w) >> > > > > "Make a string of width W made of spaces." >> > > > > (make-string w ?\s)) >> > > > > >> > > > > (defun mondu () >> > > > > >> > > > > (interactive) >> > > > > >> > > > > (with-current-buffer (get-buffer-create "Mondu") >> > > > > >> > > > > (insert " MAIN PANEL DU \n\n") >> > > > > >> > > > > (insert " ") >> > > > > (insert-button "[-]" 'action 'mondu-outbd) >> > > > > (insert " OUTBD ") >> > > > > >> > > > > (insert-button "[-]" 'action 'mondu-norm) >> > > > > (insert " NORM ") >> > > > > >> > > > > ;;------------------------------------------------------------ >> > > > > >> > > > > (insert-button "[-]" 'action 'mondu-inbd-eng-pri) >> > > > > (insert " INBD ENG PRI \n") >> > > > > >> > > > > (insert (spaz 24)) >> > > > > (insert-button "[-]" 'action 'mondu-inbd-pfd) >> > > > > (insert " INBD PFD \n") >> > > > > >> > > > > (insert (spaz 24)) >> > > > > (insert-button "[-]" 'action 'mondu-inbd-hfd) >> > > > > (insert " INBD HFD \n") ) >> > > > > >> > > > > (pop-to-buffer "Mondu") ) >> > > > >> > > > Have made the following. But I also have to activate the text that is printed >> > > > to the help buffer when pressing the button. >> > > > >> > > > (defun mondu-color-text (text color) >> > > > "Color TEXT in the specified COLOR in the Mondu buffer." >> > > > >> > > > (with-current-buffer "Mondu" >> > > > (save-excursion >> > > > (goto-char (point-min)) >> > > > (when (search-forward text nil t) >> > > > (let ((start (match-beginning 0)) >> > > > (end (match-end 0))) >> > > > (add-text-properties start end `(face (:foreground ,color)))))))) >> > > > >> > > > (defun mondu () >> > > > "Set up the Mondu buffer with buttons and text." >> > > > >> > > > (interactive) >> > > > >> > > > (with-current-buffer (get-buffer-create "Mondu") >> > > > >> > > > (erase-buffer) ;; Clear the buffer to avoid repeated content on multiple >> > > > invocations >> > > > >> > > > (insert " MAIN PANEL DU \n\n") >> > > > >> > > > (insert " ") >> > > > (insert-button "[-]" >> > > > 'action (lambda (_) (mondu-color-text " OUTBD " "red"))) >> > > > (insert " OUTBD ") >> > > > >> > > > (insert-button "[-]" >> > > > 'action (lambda (_) (mondu-color-text " NORM " "red"))) >> > > > (montejura-insert-colorat " NORM " "red") >> > > > >> > > > (insert-button "[-]" >> > > > 'action (lambda (_) (mondu-color-text " INBD ENG PRI " "red"))) >> > > > (insert " INBD ENG PRI \n") >> > > > >> > > > (insert (espz 24)) >> > > > (insert-button "[-]" >> > > > 'action (lambda (_) (mondu-color-text " INBD PFD " "red"))) >> > > > (insert " INBD PFD \n") >> > > > >> > > > (insert (espz 24)) >> > > > (insert-button "[-]" >> > > > 'action (lambda (_) (mondu-color-text " INBD HFD " "red"))) >> > > > (insert " INBD HFD \n")) >> > > > >> > > > (pop-to-buffer "Mondu")) >> > > >> > > Perhaps this (based on the first version): >> > > >> > > (defun mondu () >> > > (interactive) >> > > (with-current-buffer (get-buffer-create "Mondu") >> > > (let ((make-desc (lambda (&optional description) >> > > (insert (propertize (or description " NORM ") >> > > 'face '( :weight bold >> > > :slant italic >> > > :background "lightgray")))))) >> > > (insert " MAIN PANEL DU \n\n") >> > > (insert " ") >> > > (insert-button "[-]" 'action 'mondu-outbd) >> > > (funcall make-desc " OUTBD ") >> > > (insert-button "[-]" 'action 'mondu-norm) >> > > (funcall make-desc) >> > > ;;------------------------------------------------------------ >> > > (insert-button "[-]" 'action 'mondu-inbd-eng-pri) >> > > (funcall make-desc " INBD ENG PRI \n") >> > > (insert (spaz 24)) >> > > (insert-button "[-]" 'action 'mondu-inbd-pfd) >> > > (funcall make-desc " INBD PFD \n") >> > > (insert (spaz 24)) >> > > (insert-button "[-]" 'action 'mondu-inbd-hfd) >> > > (funcall make-desc" INBD HFD \n"))) >> > > (pop-to-buffer "Mondu")) >> > > >> > > Steve Berman >> > >> > Steve, your function highlights everything, not only the text next to >> > where the button was pressed. >> >> >> Do you mean the background color? That was just an example; if you >> don't want it, then just don't include it in the value of the `face' >> property. E.g., if you just want the text next to the button to be >> red, just use '(:foreground "red") as the value of the` face' property. >> >> Steve Berman > > It is more complicated. When one presses the button "OUTBD", only the > word "OUTBD" gets coloured red. The other string are reset with no color. > Meaning that the highlight is only applied to the text to which the key > was pressed. I guess you're talking not about the code I posted but about your second version that uses the function `mondu-color-text'. With that code what I see is that the text next to the pressed button turns red and the text next to the other buttons is left alone, i.e., if it is already red, it remains red, does not get reset. (However, since you didn't supply the code for `montejura-insert-colorat', I just replaced that with `insert', so maybe that's why I don't see what you describe.) If that's not what you want, you should explain more precisely what you want. (I thought you just wanted the text next to each button fontified to begin with (i.e, not just upon pressing the associated button), which is what the code I posted does, but it seems you want something else.) Steve Berman ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-07-01 9:26 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-06-30 20:00 Highlighting text next to button Heime 2024-06-30 21:52 ` Heime 2024-06-30 22:11 ` Stephen Berman 2024-06-30 22:32 ` Heime 2024-07-01 7:53 ` Stephen Berman 2024-07-01 8:52 ` Heime 2024-07-01 9:26 ` Stephen Berman
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.