info-gnus-english
[Top][All Lists]
Advanced

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

Re: selectively disabling HTML rendering?


From: Mike Small
Subject: Re: selectively disabling HTML rendering?
Date: Wed, 08 Apr 2015 13:11:33 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (berkeley-unix)

Emanuel Berg <embe8573@student.uu.se> writes:

> Mike Small <smallm@panix.com> writes:
>
>> Is there an easy way to selectively disable HTML
>> rendering, dependent upon header info? I've come up
>> with the following, which does what I want, but
>> I don't like its chances across emacs upgrades:
>
> You don't have to worry about that. Upgrades are to
> fix things and add new things, they are not supposed
> to break existing code which adhere to general good
> practices - normal, everyday code that is good tend
> to stay that way across upgrades.
>
> It is rather like this: if the upgrade breaks your
> code, either it is a bug from their side which you
> should report, or you did something really unorthodox
> and you should identify what and analyze why you made
> it that way, and how you can make it better.
>

I'm thinking I'm in this category of being unorthodox in that I'm
depending on the implementation of internal undocumented Gnus functions.
Here's the relevant part of gnus-mime-display-part for reference:

(defun gnus-mime-display-part (handle)
  (cond
   ;; Maybe a broken MIME message.
   ((null handle))
   ;; Single part.
   ((not (stringp (car handle)))
    (gnus-mime-display-single handle))
   ;; User-defined multipart
   ((cdr (assoc (car handle) gnus-mime-multipart-functions))
    (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
             handle))
   ;; multipart/alternative
   ((and (equal (car handle) "multipart/alternative")
         (not (or gnus-mime-display-multipart-as-mixed
                  gnus-mime-display-multipart-alternative-as-mixed)))
    (let ((id (1+ (length gnus-article-mime-handle-alist))))
      (push (cons id handle) gnus-article-mime-handle-alist)
      (gnus-mime-display-alternative (cdr handle) nil nil id)))
...

My function gets called in the User-defined multipart cond action and
bind mm-discouraged-alternatives if it's Anu's mail.  Then it tries to
act as if I'd jumped back out into the cond again to land in the
multipart/alternative action. And in doing that it ignores the two
as-mixed variables (which I don't care about now but it could puzzle me
if I set them someday and forget about this customization).  It's bound
to break if gnus-mime-display-part and gnus-mime-display-alternative
change.  But if there's no better way to do this without having me press
extra keys to read my mail, it's not a huge deal. If something breaks
and I forget what I've done here it will give me another chance to
practice with edebug. (I'm in awe of this debugger -- can't believe it's
part of a text editor. Do any free software common lisp implementations
have anything as good? If Slime has as much it's well hidden.)

>> (defun mms-gnus-mime-display-alternative (handle)
>>   "My own function for displaying mime multipart/alternative articles in Gnus
>> Use by placing in gnus-mime-multipart-functions.
>>
>> Beware when upgrading. Some of this is copied out of and makes assumptions 
>> about
>> gnus-mime-display-part from version 5.13 of Gnus.  It also bypasses 
>> gnus-mime-display-multipart-as-mixed and 
>> gnus-mime-display-multipart-alternative-as-mixed."
>>   (let ((id (1+ (length gnus-article-mime-handle-alist)))
>>      (mm-discouraged-alternatives
>>       (if (string= (get-text-property 0 'from (car handle))
>>                    "wsmith@wordsmith.org")
>>           (list "text/html")
>>         mm-discouraged-alternatives)))
>>     (push (cons id handle) gnus-article-mime-handle-alist)
>>     (gnus-mime-display-alternative (cdr handle) nil
>> nil id)))

...

Thanks for the tips on documentation and coding style. I've applied some
of that. What I've not followed (e.g. documenting the argument and not
hard coding the from value) I ignored only because I don't see myself
publishing this function to others. Er, other than on this news group,
that is.

...

> The idea as such is close to over-engineering - how
> about to just open the message as "not HTML", then
> have a key assigned to HTML-ize it?

My usual case is to want the html rendering. It's only Anu's Word a Day
where I want the text alternative. I was manually switching it over to
text for a while, but wanted to have it happen automatically. I read his
emails every weekday so a manual step would be annoying.

-- 
Mike Small
smallm@panix.com


reply via email to

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