1

I don't want themes. I use bold,italics, and highlights. I also use background colors per file, so the code as in for background need to be embedded inside file.

But when I Edit->Text Properties->Face->other And select highlight upon reopening the file it's gone as the encoding isn't embedded inside the file, but bold does in this format when I open M-x find-file-literally I see this encoding <bold> BOLDED FONT <\bold>.

Background color is not changed even though foreground color of text changes! What's wrong with background color?

I save them in enriched mode.

Mini kute
  • 15
  • 4

2 Answers2

1

As far as I can see, the problem is that enriched-face-ans does not consider inherited face attributes when it queries attributes with function face-attribute.
It should call face-attribute with the INHERIT argument set to t.

I assume that failing to do so is a bug in enriched-face-ans. Maybe, you should file a bug report to bug-gnu-emacs@gnu.org.

There follows a bugfix. It is essentially the original version of enriched-face-ans with my small modifications marked by Tobias.

(defun ad-enriched-face-ans (face)
  "Return annotations specifying FACE.
FACE may be a list of faces instead of a single face;
it can also be anything allowed as an element of a list
which can be the value of the `face' text property."
  (cond ((and (consp face) (eq (car face) 'foreground-color))
     (list (list "x-color" (cdr face))))
    ((and (consp face) (eq (car face) 'background-color))
     (list (list "x-bg-color" (cdr face))))
    ((and (listp face) (eq (car face) :foreground))
     (list (list "x-color" (cadr face))))
    ((and (listp face) (eq (car face) :background))
     (list (list "x-bg-color" (cadr face))))
    ((listp face)
     (apply 'append (mapcar 'enriched-face-ans face)))
    ((let* ((fg (face-attribute face :foreground nil t)) ;; Tobias: Set INHERIT argument to t
        (bg (face-attribute face :background nil t)) ;; Tobias: Set INHERIT argument to t
        (props (face-font face t))
        (ans (cdr (format-annotate-single-property-change
               'face nil props enriched-translations))))
       (unless (eq fg 'unspecified)
         (setq ans (cons (list "x-color" fg) ans)))
       (unless (eq bg 'unspecified)
         (setq ans (cons (list "x-bg-color" bg) ans)))
       ans))))

(advice-add 'enriched-face-ans :override #'ad-enriched-face-ans)

Tested with GNU Emacs 26.3 (build 2, i686-pc-linux-gnu, GTK+ Version 3.22.30) of 2019-09-16
by loading built-in library add-log.el and setting the change-log-function face on a stretch of text through "Edit → Text Properties → Face → Other → change-log-function" in an enriched buffer, saving and killing the buffer, and re-opening the corresponding file in Emacs.

Tobias
  • 32,569
  • 1
  • 34
  • 75
  • thx and what about backgroung color. – Mini kute Dec 30 '19 at 07:46
  • @Minikute The background color `darkseagreen2` of face `highlight` is saved in the enriched file with Emacs 26.3. Please add your Emacs version and a reproducible reconstruction procedure to your question. – Tobias Dec 30 '19 at 16:51
  • @Minikute Your edit of this answer does not make sense. Especially not since saving of the background color `darkseagreen2` of face `highlight` does work out of the box with enriched mode in Emacs 26.3. You failed to give your Emacs version and a reproducible reconstruction procedure in your question. So we cannot reproduce what your actual problem is. My answer was the closest guess. – Tobias Dec 30 '19 at 20:56
  • My answer was my closest guess. Maybe it does not address your actual problem. Nevertheless it addresses your problem for cases where the background color is inherited from another face (therefore my guess). – Tobias Dec 30 '19 at 21:03
  • I use the latest version of emacs and portacle. In portacle when i change the background doesn't change? can you reproduce the same problem? – Mini kute Dec 31 '19 at 18:27
0

i use GNU Emacs 26.3.

I had issue to save persistent highlighted text, using Text Property Face, under Enriched mode. I wanted to highlight with different style. So looking around the web and see this thread, which i don't really understand.

I finally am able to save persistent highlighted text, by doing below. added my own face style through the variable "Facemenu Keybindings"

Then, ex. for the newly added face "Company Scrollbar Bg", i go to customize the variable of "Company Scrollbar Bg"

Customize the face i added

where, i think it needs to check/define its Foreground, Background and Inherit from Default. Then Save and Apply.

Also, in file .emacs, i have... [.... '(font-lock-global-modes t) '(global-font-lock-mode t) '(global-hi-lock-mode nil) ...] since some posts says hi-lock mode would interfere Enriched mode's highlight.

That's all i did. Hope it helps for those who has similar issue.

Drew
  • 75,699
  • 9
  • 109
  • 225
  • *in the first picture, the newly added face "Company Scrollbar Bg" is added in the menu by editing the variable "Facemenu Keybindings " – Telescopic_Sum Oct 20 '21 at 04:09
  • Please consider describing in the answer's text, what you expect someone to understand from the first screenshot. Assume someone can't see clearly what you want them to see in the image. – Drew Oct 20 '21 at 16:10