all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jean Louis <bugs@gnu.support>
To: Help GNU Emacs <help-gnu-emacs@gnu.org>
Subject: How to remove all text properties?
Date: Thu, 10 Nov 2022 07:25:18 +0300	[thread overview]
Message-ID: <2eca931bf774b4459744cabda9638c49.support1@rcdrun.com> (raw)

This particular situation is related to showing arbitrary links in
Emacs buffers.

My intention is to have this type of Hyperlinks in Emacs buffers:

⟦ (hyperscope 123) ⟧

The above is template interpolation snippet, reference: RCD Template
Interpolation System for Emacs:
https://hyperscope.link/3/7/1/3/3/RCD-Template-Interpolation-System-for-Emacs.html

The snippet alone is supposed to be bound to 2 possible directions:

- to display itself as Emacs button (link) within Emacs buffer,
  depending of the mode of invocation; 

- to contain function that is to be executed upon pressing the button;

What I wish to solve is removal of button text properties at time
point when I wish to delete the button and reverse it back to
original.

The original link or snippet will be following: ⟦ (hyperscope 123) ⟧

The button will be "Hello"

I wish to reverse the text properties of "Hello" to plain text
properties and display original ⟦ (hyperscope 123) ⟧

Here is how button will be displayed:

(insert-text-button "Hello"
		    'action (lambda (b) (message "Here"))
		    'follow-link t
		    'hyperscope-link 123)

If one evaluates the above, one will see "Hello" underlined and with
some text color, in general it will have different text properties.

After evaluating above, user will get following:

(insert-text-button "Hello"
		    'action (lambda (b) (message "Here"))
		    'follow-link t
		    'hyperscope-link 123)Hello

And then by executing the function below, the "Hello" above will
disappear and it will be reverted to ⟦ (hyperscope 123) ⟧

(defun rcd-revert-source ()
  (let ((point (point)))
    (save-excursion
      (goto-char (point-min))
      (let (my-prop)
	(while (setq my-prop 
		     (text-property-search-forward 
		      'hyperscope-link))
	  (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 "⟦ (hyperscope-link %s) ⟧" value)))))))
    (goto-char point)))

;; It searches for text properties and reverts it back,
;; but with errors, as font is still red.

(rcd-revert-source)

The problem that I see is that my function above can revert text
properties in this *mail* buffer in major-mode ⇒ mail-mode, but it
cannot revert text properties in emacs-lisp-mode, where "Hello"
becomes read, and then after reverting, the original snippet ⟦
(hyperscope 123) ⟧ becomes red too.

I guess that (rcd-revert-source) is not perfect, what am I missing?

Why are text properties removed in mail-mode but not in Emacs Lisp mode?

--
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



             reply	other threads:[~2022-11-10  4:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-10  4:25 Jean Louis [this message]
2022-11-10 18:18 ` How to remove all text properties? Emanuel Berg
2022-11-12  8:33   ` Jean Louis
2022-11-13  5:16 ` Eduardo Ochs

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

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

  git send-email \
    --in-reply-to=2eca931bf774b4459744cabda9638c49.support1@rcdrun.com \
    --to=bugs@gnu.support \
    --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.
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.