[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: efficiently viewing Unix timestamps as dates
From: |
Stefan Monnier |
Subject: |
Re: efficiently viewing Unix timestamps as dates |
Date: |
Tue, 24 May 2011 20:01:00 -0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
> mouse to look at the date as a tooltip. I didn't like how it looked
> with the `display' property: you would hit backspace from a string of 8
> digits to 7, and the display property would remain the previously
> computed date.
You have to explicit remove the `display' property before refreshing
with font-lock. My sample code did not bother to do it because it was
just a proof of concept.
A naive way to do that is to add `display' to
font-lock-extra-managed-props, tho this will also remove `display'
properties added by other packages for other purposes.
So a better way is to add not just a `display' property but also another
property that is specific to your package, so that you can recognize
which `display' properties are yours, and then in font-lock-keywords you
can add a pseudo-keyword which will look for those display properties
and remove them.
Something like (untested):
(defun foo-remove-display (limit)
(let ((beg (point)))
(while (< beg limit)
(let ((next (next-single-property-change beg 'display nil end))
(prop (get-text-property beg 'display)))
(if (and prop (get-text-property beg 'foo-owned))
(put-text-property beg next 'display nil))
(setq beg next))))
nil)
(add-hook 'foo-mode-hook
(lambda ()
(font-lock-add-keywords
nil
'((foo-remove-display)
("[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]"
(0 `(face foo-owned t nil display
,(format-time-string "%F %T"
(seconds-to-time
(car
(read-from-string
(concat
(match-string 0)
".0"))))))))))))
-- Stefan
- Re: efficiently viewing Unix timestamps as dates, Ted Zlatanov, 2011/05/24
- Re: efficiently viewing Unix timestamps as dates,
Stefan Monnier <=
- Re: efficiently viewing Unix timestamps as dates, Ted Zlatanov, 2011/05/24
- Re: efficiently viewing Unix timestamps as dates, Stefan Monnier, 2011/05/24
- Re: efficiently viewing Unix timestamps as dates, Ted Zlatanov, 2011/05/24
- Re: efficiently viewing Unix timestamps as dates, Stefan Monnier, 2011/05/24
- Re: efficiently viewing Unix timestamps as dates, Ted Zlatanov, 2011/05/24
- Re: efficiently viewing Unix timestamps as dates, Stefan Monnier, 2011/05/24
- Re: efficiently viewing Unix timestamps as dates, Ted Zlatanov, 2011/05/24
- Re: efficiently viewing Unix timestamps as dates, Stefan Monnier, 2011/05/24
- Re: efficiently viewing Unix timestamps as dates, Ted Zlatanov, 2011/05/24
- Re: efficiently viewing Unix timestamps as dates, Ted Zlatanov, 2011/05/24