emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [Orgmode] org-babel - utility to ease chopping src chunks into small


From: Eric Schulte
Subject: Re: [Orgmode] org-babel - utility to ease chopping src chunks into smaller org entries
Date: Sun, 19 Sep 2010 12:21:37 -0600
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

Hi Richard,

This is a good idea, I too frequently find myself splitting code blocks.
How about this following alternative implementation which should be
smart enough to notice if it is inside of a code block, and should work
across any code block type.
--8<---------------cut here---------------start------------->8---
(defun org-babel-split-block-maybe (&optional arg)
  "Split the current source code block on the cursor."
  (interactive "P")
  ((lambda (info)
     (if info
         (let ((lang (nth 0 info))
               (indent (make-string (nth 6 info) ? ))
               (stars (concat (make-string (org-current-level) ?*) " ")))
           (insert (concat (if (looking-at "^") "" "\n")
                           indent "#+end_src\n"
                           (if arg stars indent) "\n"
                           indent "#+begin_src " lang
                           (if (looking-at "[\n\r]") "" "\n  ")))
           (when arg (previous-line) (move-end-of-line 1)))
       (message "Not in src block.")))
   (org-babel-get-src-block-info)))
--8<---------------cut here---------------end--------------->8---

Let me know what you think.  I notice your implementation uses regions,
where as this one does not, so it's possible I left out some
functionality.  I'd like to include some version of this functionality
into Org-mode core.

Best -- Eric

Richard Riley <address@hidden> writes:

> I often find myself chopping a large source code block into smaller
> entities with their own notes, tags and comments etc. This small utility
> facilitates that by wrapping the current region with org entry markers
> and src code delimiters. It assumes you are in a currently src block.
>
> http://splash-of-open-sauce.blogspot.com/2010/09/mark-region-as-src-code-if-prefix-used.html
>
> Its currently hardcoded for emacs-lisp but it might be useful nonetheless.
>
> (Anyone know how to make blogspot line wrap?)
>
>
> r.
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> address@hidden
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode



reply via email to

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