emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

`add-face'


From: Lars Ingebrigtsen
Subject: `add-face'
Date: Thu, 06 Sep 2012 17:51:16 +0200
User-agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.2.50 (gnu/linux)

Wolfgang Jenkner has just made me aware that `face' text properties are
combining!  That is, you can have lists of them and they work like
overlays.

I've always disliked working with overlays, because they are so fiddly.
Just look (or don't!) at the code in shr.el, but I thought I had to,
since text properties didn't combine.

However, the Emacs functions for working with combining text property
faces are kinda...  weak.  You basically have to check yourself, so you
end up with code like this:

(defun gnus-combine-text-property (beg end prop val)
  "Combine PROP with text properties between BEG and END.
This combines attributes if PROP is `face' otherwise this is just
like `put-text-property', more or less.
Beware: Proof-of-concept."
  (let ((b beg))
    (while (< b end)
      (let ((oldval (get-text-property b prop)))
        (gnus-put-text-property
         b (setq b (next-single-property-change b prop nil end))
         prop (cond ((or (not (eq prop 'face))
                         (null oldval))
                     val)
                    ((and (consp oldval)
                          (not (keywordp (car oldval))))
                     (cons val oldval))
                    (t
                     (list val oldval))))))))

So here's my suggestion for exposing this rather nice functionality in a
more convenient form.

Add a function `add-face', that will do what you think it does.  Or
perhaps `add-face-region'?  Or `add-text-property-face'?

Anyway, this will call `add-text-properties' with a new optional
parameter NOREPLACE, that will tell `add-text-properties' to add to the
list of properties instead of replacing.  This, in turn, will then call
add_properties with a new parameter, and it will do the trivial list
manipulation stuff instead of just

            Fsetcar (this_cdr, val1);

If this sounds like a good idea, I can implement this right away.  And
then change shr.el to use the new function, which should speed table
rendering up a bit, as well as getting rid of some uglee code.

-- 
(domestic pets only, the antidote for overdose, milk.)
  http://lars.ingebrigtsen.no  *  Lars Magne Ingebrigtsen



reply via email to

[Prev in Thread] Current Thread [Next in Thread]