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

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

Correctly fontify Org-mode code blocks


From: Sébastien Vauban
Subject: Correctly fontify Org-mode code blocks
Date: Thu, 06 Jan 2011 11:38:39 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (windows-nt)

Hi Lars,

Lars Magne Ingebrigtsen wrote:
> Sébastien Vauban <wxhgmqzgwmuf@spammotel.com> writes:
>> Sébastien Vauban <wxhgmqzgwmuf@spammotel.com> writes:
>>
>>> I would like to get such Org constructs:
>>>
>>> #+begin_src emacs-lisp
>>> (setq org-latex-to-pdf-process '("sh -v -x texi2dvi -p -b -c -V %f"))
>>> #+end_src
>>>
>>> or
>>>
>>> #+begin_src sh
>>> ls
>>> #+end_src
>>>
>>> to be *highlighted* when viewed (while reading received messages).
>>
>> Does this sound good to you?
>
> Looks good. Could you provide a patch to Gnus?

This is the best final code I currently have:

--8<---------------cut here---------------start------------->8---
      (eval-after-load "mm-uu"
        '(progn
           ;; correctly fontify Org-mode attachments
           (add-to-list 'mailcap-mime-extensions '(".org" . "text/org"))
           (add-to-list 'mm-automatic-display "text/org")

           (add-to-list 'mm-inline-media-tests
                        '("text/org" my/display-org-inline
                          (lambda (el) t)))

           (defun my/display-org-inline (handle)
             (condition-case nil
                 (mm-display-inline-fontify handle 'org-mode)
               (error
                (insert
                 (with-temp-buffer (mm-insert-part handle) (buffer-string))
                 "\n"))))

           ;; fontify code blocks in the text of messages
           (defun my/mm-org-src-code-block-extract ()
             (mm-make-handle (mm-uu-copy-to-buffer start-point end-point)
                             '("text/org")))

           (add-to-list 'mm-uu-type-alist
                        '(org-src-code-block
                          "^[ \t]*#\\+begin_"
                          "^[ \t]*#\\+end_"
                          my/mm-org-src-code-block-extract
                          nil))

           (add-to-list 'mm-uu-type-alist
                        '(org-meta-line
                          "^[ \t]*#\\+[[:alpha:]]+: "
                          "$"
                          my/mm-org-src-code-block-extract
                          nil))

           (mm-uu-configure)))
--8<---------------cut here---------------end--------------->8---

It is based on my original code, and has been slightly reviewed by Eric
Schulte (adding error handling).


> And do you have copyright assignment papers on file with the FSF? That's
> needed for "substantial changes", which is "more than ten lines of code",
> basically.

I did. I will send a digital copy to you by private email.

Best regards,
  Seb

-- 
Sébastien Vauban


reply via email to

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