Heikki Lehvaslaiho <heikki.lehvasla...@gmail.com> writes:

> Unless someone beats me to it, I'll write it one day. :)

What about:

#+begin_src emacs-lisp
  (defun tj/toggle-example-and-comment-blocks ()
    "Toggle example and comment blocks in current buffer."
    (interactive)
    (org-block-map
     (lambda ()
       (org-mark-element)
       (when (use-region-p)
         (let ((beg (region-beginning))
               (end (region-end)))
           (cond
            ((save-excursion
               (re-search-forward "#\\+begin_comment"
                                  (line-end-position) 'NOERROR))
             (replace-string "#+begin_comment" "#+begin_example"
                             nil beg end)
             (replace-string "#+end_comment" "#+end_example"
                             nil beg end))
            ((save-excursion
               (re-search-forward "#\\+begin_example"
                                  (line-end-position) 'NOERROR))
             (replace-string "#+begin_example" "#+begin_comment"
                             nil beg end)
             (replace-string "#+end_example" "#+end_comment"
                             nil beg end))
            (t nil))
           (deactivate-mark))))))
#+end_src


-- 
cheers,
Thorsten


Reply via email to