1

I tried to use text-property to decorate specific texts as well as automatically color tab characters in a text-mode buffer, but didn't find a way to realize them at the same time.

This is my try:

  1. Start Emacs with the option -Q:

    foo@bar:~$ emacs -Q
    
  2. Open a new text file and an existing C file:

    Open a new text file and an existing C file

  3. Copy a colored text from the c-mode buffer (M-w : kill-ring-save) to the text-mode buffer (C-y : yank).

    enter image description here

    The pasted text at this time is colored the same.

  4. Then, make a font-lock rule to set backgound color of tab characters in the text mode buffer to make tab visible.

    (font-lock-add-keywords nil              ; current buffer
                            `(("\\(\t+\\)"   ; Tab
                             1
                            '((t (:background "gray")))
                            prepend)))
    

    enter image description here

    While all tab characters get colored as expected, the pasted decorated texts become back to default uncolored look.

    I want only the tab background to be colored, while keeping existing texts decorated. And, I want to make it by 2 strokes, copy and paste (M-w and C-y).

    Newly copied texts to the text buffer also no longer keep the original colors.

    enter image description here

How can I make use of font-lock feature, as well as keeping existing static text-property faces in a buffer?

Emacs 27.1, Ubuntu 22.04.3 LTS

9
  • 2
    Does this answer your question? Add text property, when global-font-lock mode is on
    – Drew
    Commented Jan 28 at 22:43
  • See also this question: emacs.stackexchange.com/a/27185/105
    – Drew
    Commented Jan 28 at 22:44
  • Thanks for your comment. After #4 too, I want to do #2 and #3 several times, keeping own or original text-property faces, and even insert many tabs. Given that, after #4, replacing face with font-lock-face works for #2, but for #3, original text property faces already disappeared on the current buffer befor replacing. So, I believe other measures are also necessary.
    – yos
    Commented Jan 29 at 1:55
  • The question is unclear. Please specify a step-by-step recipe to reproduce your problem, starting with emacs -Q (no init file). At each step show exactly what you do, say what you expect to see as the effect, and what you see instead.
    – Drew
    Commented Jan 29 at 2:29
  • @ Drew Thank you for pointing this out. I will correct it.
    – yos
    Commented Jan 29 at 2:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.