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

[BUGREPORT] "saving-face"



I'm not totally sure about this, but I think I've come across several bugs in
function `w3m-remove-face-property' of file `w3m-util.el'.

1) The function expects the 'face property to be a value of type list,
   and on that basis pops off the symbol and later creates a list for
   it. However, that seems incorrect. For example, navigate POINT to
   some text with a face, such as the word reserved word "defun" in an
   elisp buffer, and perform M-: (get-text-property (point) 'face), and
   see that the result is just a symbol, not a list with a single symbol
   inside.

2) It performs its comparison test using 'eq instead of 'equal:

     (unless (eq elem name)

   However, the face could be explicitly defined instead of a symbol,
   eg. '(:weight bold).

3) It doesn't perform `remove-text-properties', so properties not caught
   by the 'eq test accumulate.

4) It accepts an OBJECT argument, and uses it to retrieve properties,
   but not to restore the properties when it calls
   w3m-add-text-properties.

Here's my "fixed" version (presuming my analysis is correct):


#+BEGIN_SRC emacs-lisp
  (let ((pos start)
	next prop new-prop elem)
    (while (< pos end)
      (setq prop (get-text-property pos 'face object))
      (setq next (next-single-property-change pos 'face object end))
      (setq new-prop (cond
                      ((listp prop)
                        (setq new-prop (remove name prop))
                        (if (= 1 (length new-prop))
                          (car new-prop)
                         new-prop))
                      ((equal name prop) nil)
                      (t                 prop)))
      (remove-text-properties pos next 'face object)
      (when new-prop
        (add-text-properties pos next (list 'face new-prop) object))
      (setq pos next))))
#+END_SRC

--
hkp://keys.gnupg.net
CA45 09B5 5351 7C11 A9D1  7286 0036 9E45 1595 8BC0