all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to remove all text properties?
@ 2022-11-10  4:25 Jean Louis
  2022-11-10 18:18 ` Emanuel Berg
  2022-11-13  5:16 ` Eduardo Ochs
  0 siblings, 2 replies; 4+ messages in thread
From: Jean Louis @ 2022-11-10  4:25 UTC (permalink / raw)
  To: Help GNU Emacs

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/



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to remove all text properties?
  2022-11-10  4:25 How to remove all text properties? Jean Louis
@ 2022-11-10 18:18 ` Emanuel Berg
  2022-11-12  8:33   ` Jean Louis
  2022-11-13  5:16 ` Eduardo Ochs
  1 sibling, 1 reply; 4+ messages in thread
From: Emanuel Berg @ 2022-11-10 18:18 UTC (permalink / raw)
  To: help-gnu-emacs

Can you inhibit them globally? Maybe that would make Emacs
much faster, the interactive feel ...

`default-text-properties' already defaults to nil.

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to remove all text properties?
  2022-11-10 18:18 ` Emanuel Berg
@ 2022-11-12  8:33   ` Jean Louis
  0 siblings, 0 replies; 4+ messages in thread
From: Jean Louis @ 2022-11-12  8:33 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg <incal@dataswamp.org> [2022-11-11 23:48]:
> Can you inhibit them globally? Maybe that would make Emacs
> much faster, the interactive feel ...
> 
> `default-text-properties' already defaults to nil.

Hmm. Question is related to particular function, it is not general, förlåt.

-- 
Jean

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

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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to remove all text properties?
  2022-11-10  4:25 How to remove all text properties? Jean Louis
  2022-11-10 18:18 ` Emanuel Berg
@ 2022-11-13  5:16 ` Eduardo Ochs
  1 sibling, 0 replies; 4+ messages in thread
From: Eduardo Ochs @ 2022-11-13  5:16 UTC (permalink / raw)
  To: Jean Louis; +Cc: Help GNU Emacs

On Thu, 10 Nov 2022 at 01:26, Jean Louis <bugs@gnu.support> wrote:
>
> 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.


Hi Jean Louis,

I saved this to the file /tmp/o,

--snip--snip--

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

(defun rcd-revert-source ()
  (interactive)
  (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)))

;; (rcd-insert-hello)
;; (rcd-revert-source)

--snip--snip--

and then I tried this:

  1. without changing its mode from fundamental-mode to something else
     I ran the two defuns and the (rcd-insert-hello); it inserted a
     button whose text was "Hello",

  2. I ran my `find-eregionpp', defined here,

       (find-efunction 'find-eregionpp)
       (find-eev "eev-blinks.el" "find-eregionpp")
       http://angg.twu.net/eev-current/eev-blinks.el.html#find-eregionpp

     on the ")Hello\n", and saved its output in another file - I will
     discuss it soon,

  3. I ran the (rcd-revert-source) - it converted the "Hello" to this:

       "⟦ (hyperscope-link 123) ⟧"

  4. I ran some undos to delete the "⟦ (hyperscope-link 123) ⟧" and
     the "Hello",

  5. I ran `M-x emacs-lisp-mode',

  6. I ran the (rcd-insert-hello) again. It inserted a button whose
     text was "Hello". That button worked as expected - typing
     RET on it ran (message "Here") - but it didn't look like a
     button: it was displayed in font-lock-comment-face,

  7. I ran `M-x find-eregionpp' on the ")Hello\n" and saved its
     output in another file,

  8. I ran the (rcd-revert-source). It worked as before - it
     converted the "Hello" to this:

       "⟦ (hyperscope-link 123) ⟧"

  9. I ran some undos.

Here is the output of the `find-eregionpp's. The first one, that
was run with the file in fundamental-mode, gave this:

  ((")")
   ("Hello"
    (action (lambda (b) (message "Here")))
    (button (t))
    (category default-button)
    (follow-link t)
    (hyperscope-link 123))
   ("\n"))

and the second one, that was run with the file in
emacs-lisp-mode, gave this:

  ((")"
    (face font-lock-comment-face)
    (fontified t))
   ("Hello"
    (action (lambda (b) (message "Here")))
    (button (t))
    (category default-button)
    (face font-lock-comment-face)
    (follow-link t)
    (fontified t)
    (hyperscope-link 123))
   ("\n"
    (face font-lock-comment-face)
    (fontified t)))

The difference was that in emacs-lisp-mode all three intervals
had these extra properties:

    (face font-lock-comment-face)
    (fontified t)

In fundamental-mode the face of the "Hello" was inherited from the
`(category default-button)'. I found that face - `button' - with `C-u
C-x =', but here are three low-level links that sort of point to that
information:

  (find-egrep "grep --color=auto -nH --null -e default-button *.el */*.el")
  (find-efile "button.el" "(put 'default-button 'face 'button)")
  (describe-text-category 'default-button)

In emacs-lisp-mode the "Hello" had this among its text properties,

  (face font-lock-comment-face)

and this took precedence over the face from the category.

Does that help?
  Cheers,
    Eduardo Ochs
    http://angg.twu.net/eepitch.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-13  5:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-10  4:25 How to remove all text properties? Jean Louis
2022-11-10 18:18 ` Emanuel Berg
2022-11-12  8:33   ` Jean Louis
2022-11-13  5:16 ` Eduardo Ochs

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.