Gnus development mailing list
 help / color / mirror / Atom feed
* Adding MIME viewers
@ 1999-09-10  9:48 Toby Speight
  1999-09-25  8:59 ` Lars Magne Ingebrigtsen
  0 siblings, 1 reply; 8+ messages in thread
From: Toby Speight @ 1999-09-10  9:48 UTC (permalink / raw)


Has anyone written a good guide for writing viewers for MIME-types
not built-in to Gnus?  In particular, I've recently installed Stefan
Monnier's diff-mode.el, and I'd like to use his font-lock rules to
fontify "text/x-patch" bodyparts.

And how do I unify my viewers for Gnus and w3 to share as much code
and config as possible?



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding MIME viewers
  1999-09-10  9:48 Adding MIME viewers Toby Speight
@ 1999-09-25  8:59 ` Lars Magne Ingebrigtsen
  1999-09-27 13:44   ` Toby Speight
  1999-10-04 12:06   ` Toby Speight
  0 siblings, 2 replies; 8+ messages in thread
From: Lars Magne Ingebrigtsen @ 1999-09-25  8:59 UTC (permalink / raw)


Toby Speight <Toby.Speight@streapadair.freeserve.co.uk> writes:

> Has anyone written a good guide for writing viewers for MIME-types
> not built-in to Gnus?  In particular, I've recently installed Stefan
> Monnier's diff-mode.el, and I'd like to use his font-lock rules to
> fontify "text/x-patch" bodyparts.

I've now added the following section to the Emacs-MIME manual:

New Viewers
===========

   Here's an example viewer for displaying `text/enriched' inline:

     (defun mm-display-enriched-inline (handle)
       (with-temp-buffer
         (mm-insert-part handle)
         (save-window-excursion
           (enriched-decode (point-min) (point-max))
           (setq text (buffer-string))))
       (mm-insert-inline handle text))

   We see that the function takes a MIME handle as its parameter.  It
then goes to a temporary buffer, inserts the text of the part, does some
work on the text, stores the result, goes back to the buffer it was
called from and inserts the result.

   The two important helper functions here are `mm-insert-part' and
`mm-insert-inline'.  The first function inserts the text of the handle
in the current buffer.  It handles charset and/or content transfer
decoding.  The second function just inserts whatever text you tell it
to insert, but it also sets things up so that the text can be
"undisplayed' in a convenient manner.


-- 
(domestic pets only, the antidote for overdose, milk.)
  larsi@gnus.org * Lars Magne Ingebrigtsen


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding MIME viewers
  1999-09-25  8:59 ` Lars Magne Ingebrigtsen
@ 1999-09-27 13:44   ` Toby Speight
  1999-09-27 14:07     ` Lars Magne Ingebrigtsen
  1999-10-04 12:06   ` Toby Speight
  1 sibling, 1 reply; 8+ messages in thread
From: Toby Speight @ 1999-09-27 13:44 UTC (permalink / raw)


Lars> Lars Magne Ingebrigtsen <URL:mailto:larsi@gnus.org>

0> In article <m33dw374ea.fsf@quimbies.gnus.org>, Lars wrote:

Lars> Toby Speight <Toby.Speight@streapadair.freeserve.co.uk> writes:

>> Has anyone written a good guide for writing viewers for MIME-types
>> not built-in to Gnus?  In particular, I've recently installed
>> Stefan Monnier's diff-mode.el, and I'd like to use his font-lock
>> rules to fontify "text/x-patch" bodyparts.

Lars> I've now added the following section to the Emacs-MIME manual:
Lars>
Lars> New Viewers
Lars> ===========
Lars>
Lars> Here's an example viewer for displaying `text/enriched' inline:
Lars>
Lars>   (defun mm-display-enriched-inline (handle)
Lars>     (with-temp-buffer
Lars>       (mm-insert-part handle)
Lars>       (save-window-excursion
Lars>         (enriched-decode (point-min) (point-max))
Lars>         (setq text (buffer-string))))
Lars>     (mm-insert-inline handle text))


Thanks, Lars - that's exactly what I was looking for.  Perhaps there
should be a cross-ref to `inline-media-tests' and friends?

BTW, shouldn't there be a (let (text) ...) around the example?



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding MIME viewers
  1999-09-27 13:44   ` Toby Speight
@ 1999-09-27 14:07     ` Lars Magne Ingebrigtsen
  0 siblings, 0 replies; 8+ messages in thread
From: Lars Magne Ingebrigtsen @ 1999-09-27 14:07 UTC (permalink / raw)


Toby Speight <Toby.Speight@streapadair.freeserve.co.uk> writes:

> BTW, shouldn't there be a (let (text) ...) around the example?

Yup.  Fix in Pterodactyl Gnus v0.97.

-- 
(domestic pets only, the antidote for overdose, milk.)
  larsi@gnus.org * Lars Magne Ingebrigtsen


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding MIME viewers
  1999-09-25  8:59 ` Lars Magne Ingebrigtsen
  1999-09-27 13:44   ` Toby Speight
@ 1999-10-04 12:06   ` Toby Speight
  1999-10-09 14:20     ` Robert Bihlmeyer
  1999-11-06  2:53     ` Lars Magne Ingebrigtsen
  1 sibling, 2 replies; 8+ messages in thread
From: Toby Speight @ 1999-10-04 12:06 UTC (permalink / raw)


Lars> Lars Magne Ingebrigtsen <URL:mailto:larsi@gnus.org>

0> Toby Speight <Toby.Speight@streapadair.freeserve.co.uk> writes:

>> Has anyone written a good guide for writing viewers for MIME-types
>> not built-in to Gnus?  In particular, I've recently installed
>> Stefan Monnier's diff-mode.el, and I'd like to use his font-lock
>> rules to fontify "text/x-patch" bodyparts.


0> In article <m33dw374ea.fsf@quimbies.gnus.org>, Lars wrote:

Lars> I've now added the following section to the Emacs-MIME manual:
Lars>
Lars> New Viewers
Lars> ===========
Lars>
Lars> [...]

So here's my viewer for application/x-diff:


(defun mm-display-patch-inline (handle)
  (let (text)
    (with-temp-buffer
      (mm-insert-part handle)
      (diff-mode)
      (font-lock-fontify-buffer)
      (setq text (buffer-string)))
    (mm-insert-inline handle text)))

(eval-after-load "mm-decode"
  '(progn
     (push '("text/x-patch" mm-display-patch-inline identity) mm-inline-media-tests)
     (push "text/x-patch" mm-automatic-display)
     (push "text/x-patch" mm-inlined-types)
     (push "text/x-patch" mm-attachment-override-types)))


I guess I ought to put something more useful in `mm-inline-media-tests',
like (fboundp 'diff-mode), but I thought others may find this useful. (For
those who don't have diff-mode, search gnu.emacs.sources over 1999 for
Stefan Monnier's code.)



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding MIME viewers
  1999-10-04 12:06   ` Toby Speight
@ 1999-10-09 14:20     ` Robert Bihlmeyer
  1999-10-11  8:51       ` Hrvoje Niksic
  1999-11-06  2:53     ` Lars Magne Ingebrigtsen
  1 sibling, 1 reply; 8+ messages in thread
From: Robert Bihlmeyer @ 1999-10-09 14:20 UTC (permalink / raw)


Hi,

>>>>> On 04 Oct 1999 13:06:15 +0100
>>>>> Toby Speight <Toby.Speight@streapadair.freeserve.co.uk> said:

 Toby> (defun mm-display-patch-inline (handle)
 Toby>   (let (text)
 Toby>     (with-temp-buffer
 Toby>       (mm-insert-part handle)
 Toby>       (diff-mode)
 Toby>       (font-lock-fontify-buffer)
 Toby>       (setq text (buffer-string)))
 Toby>     (mm-insert-inline handle text)))

this does not work as expected here on XEmacs 21.1 (patch 7), because
these colors are not duplicable. FWIW, the following does the trick:

(defun mm-display-patch-inline (handle)
  (let (text)
    (with-temp-buffer
      (mm-insert-part handle)
      (diff-mode)
      (font-lock-fontify-buffer)
      (if (fboundp 'extent-list)
	  (mapc (lambda (el) (set-extent-property el 'duplicable t))
		(extent-list)))
      (setq text (buffer-string)))
    (mm-insert-inline handle text)))

Maybe this is really a misfeature of fontification, and the original
version should work?

        Robbe

-- 
Robert Bihlmeyer       reads: Deutsch, English, MIME, Latin-1, NO SPAM!
<robbe@orcus.priv.at>    <http://stud2.tuwien.ac.at/~e9426626/sig.html>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding MIME viewers
  1999-10-09 14:20     ` Robert Bihlmeyer
@ 1999-10-11  8:51       ` Hrvoje Niksic
  0 siblings, 0 replies; 8+ messages in thread
From: Hrvoje Niksic @ 1999-10-11  8:51 UTC (permalink / raw)


Robert Bihlmeyer <robbe@orcus.priv.at> writes:

> (defun mm-display-patch-inline (handle)
>   (let (text)
>     (with-temp-buffer
>       (mm-insert-part handle)
>       (diff-mode)
>       (font-lock-fontify-buffer)
>       (if (fboundp 'extent-list)
> 	  (mapc (lambda (el) (set-extent-property el 'duplicable t))
> 		(extent-list)))
>       (setq text (buffer-string)))
>     (mm-insert-inline handle text)))

mapc on the extent-list is a waste of resources -- use map-extents
instead.  Also, don't duplicate *all* the extents, but only the
relevant ones, say those with the `text-prop' property.  For instance:

(map-extents (lambda (ext ignored)
               (set-extent-property ext 'duplicable t)
               nil)
             nil nil nil nil nil 'text-prop)

(The above is untested.)

> Maybe this is really a misfeature of fontification, and the original
> version should work?

No, using nonduplicable properties is a feature, because normally we
*don't* want the colors to leak elsewhere.  font-lock uses the
text-properties interface because it comes more naturally than the
extents interface, not because of a need for automatic duplication.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding MIME viewers
  1999-10-04 12:06   ` Toby Speight
  1999-10-09 14:20     ` Robert Bihlmeyer
@ 1999-11-06  2:53     ` Lars Magne Ingebrigtsen
  1 sibling, 0 replies; 8+ messages in thread
From: Lars Magne Ingebrigtsen @ 1999-11-06  2:53 UTC (permalink / raw)


Toby Speight <Toby.Speight@streapadair.freeserve.co.uk> writes:

> So here's my viewer for application/x-diff:

I've added this to the CVS, after applying the changes from Robert and 
Hrvoje.

> I guess I ought to put something more useful in
> `mm-inline-media-tests', like (fboundp 'diff-mode), but I thought
> others may find this useful.

I've made it check for the diff-mode library.

-- 
(domestic pets only, the antidote for overdose, milk.)
   larsi@gnus.org * Lars Magne Ingebrigtsen


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~1999-11-06  2:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-09-10  9:48 Adding MIME viewers Toby Speight
1999-09-25  8:59 ` Lars Magne Ingebrigtsen
1999-09-27 13:44   ` Toby Speight
1999-09-27 14:07     ` Lars Magne Ingebrigtsen
1999-10-04 12:06   ` Toby Speight
1999-10-09 14:20     ` Robert Bihlmeyer
1999-10-11  8:51       ` Hrvoje Niksic
1999-11-06  2:53     ` Lars Magne Ingebrigtsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).