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.

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.

  • thx and what about backgroung color. – Mini kute Dec 30 '19 at 7: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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.