Richard Riley <rile...@gmail.com> writes:

> "Eric Schulte" <schulte.e...@gmail.com> writes:
>
>>
>> Let me know what you think.  I notice your implementation uses
>> regions,
>
> It puts the begin/src markers around the region if selected or current word.
>
>> 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.
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>

using your lang selection example

If not in a source block then just surround current region with
#+begin/end_src. If no region just put in markers around empty
area. Dont create new org items since probably just including src code
in an existing org item.

If in a source block with region create new region with current
region. If no region just create new empty block. previous src blocks
delimited and marked as org items at current level (because almost
certainly splitting the code to maintain it in discreate titled blocks.



--8<---------------cut here---------------start------------->8---
(define-key org-mode-map (kbd "C-c C-b") 'rgr/org-split-src)

(defun rgr/org-split-src(&optional arg)
  (interactive "P")
  (beginning-of-line)
  (save-excursion((lambda(info)
     (if info
         (let ((lang (nth 0 info))
               (stars (make-string (org-current-level) ?*)))
           (insert 
            (format 
             "%s\n%s\n#+begin_src %s\n%s#+end_src\n%s\n#+begin_src %s\n" 
             "#+end_src"
             stars
             lang
             (if (region-active-p) 
                 (delete-and-extract-region (region-beginning) (region-end)) 
"\n")
             stars
             lang)))
       (insert 
        (format 
         "\n#+begin_src\n%s\n#+end_src\n" 
         (if (region-active-p) 
             (delete-and-extract-region (region-beginning) (region-end)) "")))))
   (org-babel-get-src-block-info))))
--8<---------------cut here---------------end--------------->8---



_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

Reply via email to