From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: Re: org-babel - utility to ease chopping src chunks into smaller org entries Date: Mon, 20 Sep 2010 08:30:18 -0600 Message-ID: <87fwx4sco2.fsf@gmail.com> References: <878w2xfllt.fsf@gmail.com> <877hihdqtz.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from [140.186.70.92] (port=45420 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OxhVo-0003LB-Hn for emacs-orgmode@gnu.org; Mon, 20 Sep 2010 10:38:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OxhVi-0004BR-VL for emacs-orgmode@gnu.org; Mon, 20 Sep 2010 10:38:28 -0400 Received: from mail-px0-f169.google.com ([209.85.212.169]:39482) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OxhVi-0004BL-KC for emacs-orgmode@gnu.org; Mon, 20 Sep 2010 10:38:26 -0400 Received: by pxi5 with SMTP id 5so3112045pxi.0 for ; Mon, 20 Sep 2010 07:38:25 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Richard Riley Cc: emacs-orgmode@gnu.org Richard Riley writes: > "Eric Schulte" writes: > >> Hi Richard, >> >> Richard Riley writes: >> >>> Richard Riley writes: >>> >>>> "Eric Schulte" 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. >>> >>> 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. >>> >>> >> >> I was just pulling up my email to share my next iteration when I saw >> your next iteration. They look very similar. If my version covers all >> of your use cases, then I'd like to add it to the Babel key map, >> probably under "d" for demarcate or delimit, unless you can think of a >> better mnemonic. > > I've just added this to the org-mode repo. > > Not in the babel key map - in the org key map (I use it most in normal > non src org entries to mark a block of elisp as src for samples/examples). For now it still lives in the babel keymap behind (C-c C-v d) since it is fundamentally code-block related, however it can be called from anywhere in an org-mode file, and could of course be bound to any other key sequence in a personal config. > > But,yes I suspect your code is better ;) Note my func works in two > fundamentally different ways - in a babel src block where it creates > new org items and also in normal (non src) modes where it just creates > a src block. > I believe both of those use cases are supported by the current version of the function. Thanks -- Eric > >> >> >> >> >> --8<---------------cut here---------------start------------->8--- >> (defun org-babel-demarcate-block (&optional arg) >> "Wrap or split the code in the region or on the point." >> (interactive "P") >> (let ((info (org-babel-get-src-block-info))) >> (if info >> (mapc >> (lambda (place) >> (save-excursion >> (goto-char place) >> (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))))) >> (sort (if (region-active-p) (list (mark) (point)) (list (point))) #'>)) >> (insert (concat (if (looking-at "^") "" "\n") >> (if arg (concat stars "\n") "") >> "#+begin_src " (read-from-minibuffer "Lang: ") "\n" >> (delete-and-extract-region (or (mark) (point)) (point)) >> "\n#+end_src")) >> (previous-line) (move-end-of-line 1)))) >> --8<---------------cut here---------------end--------------->8--- >> >> >> >> Cheers -- Eric >> >>> >>> >>> (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)))) >>>