From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thorsten Jolitz Subject: Re: default headers for source code blocks Date: Tue, 09 Sep 2014 21:11:44 +0200 Message-ID: <87wq9cy5fz.fsf@gmail.com> References: <6583026da8c34bcf9acce84acadc801a@fbmailsvr1.familycareinc.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41565) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XRQpq-0007Eq-Ep for emacs-orgmode@gnu.org; Tue, 09 Sep 2014 15:12:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XRQpj-0007Vi-B3 for emacs-orgmode@gnu.org; Tue, 09 Sep 2014 15:12:14 -0400 Received: from plane.gmane.org ([80.91.229.3]:58418) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XRQpj-0007UU-0x for emacs-orgmode@gnu.org; Tue, 09 Sep 2014 15:12:07 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XRQpg-0007Yc-W8 for emacs-orgmode@gnu.org; Tue, 09 Sep 2014 21:12:04 +0200 Received: from e178059041.adsl.alicedsl.de ([85.178.59.41]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 09 Sep 2014 21:12:04 +0200 Received: from tjolitz by e178059041.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 09 Sep 2014 21:12:04 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Subhan Michael Tindall writes: > My apologies if this is in TFM, but I can’t seem to find it after > substantial digging. > > I’m using a lot of source code blocks lately. > > What I’d like is a way to specify a set of default headers to insert > when a new block is created. I have written an 'all-inclusive' function for this case (https://github.com/tj64/org-dp), it handles all kinds of blocks, all kinds of header-args including affiliated keywords, knows how to insert empty blocks, wrap sexps or regions (between lines or marked), how to 'unwrap' a src-block and how to convert one type of block into another reusing its contents/parts: ,----[ C-h f org-dp-wrap-in-block RET ] | org-dp-wrap-in-block is an interactive Lisp function in | `org-dp-lib.el'. | | (org-dp-wrap-in-block &optional LINES USER-INFO &rest PROMPT-SPEC) | | Wrap sexp-at-point or region in Org block. | | A region instead of the sexp-at-point is wrapped if either | | - optional arg LINES is an (positive or negative) integer or | | - the region is active | | In the first case the region is determined by moving LINES lines | up (LINES is positive) or down (LINES is negative) from point | using `forward-line', in the second case the active region is | used. | | If point is already inside of a block, modify it or unwrap its | content/value instead of wrapping it in another block, except if | explicitly asked for by user. | | If USER-INFO is given, it should be a list in the format returned | by `org-dp-prompt', i.e. | | (elem-type contents replace affiliated args) | | Look up that function's docstring for more information about the | list's elements. A non-nil USER-INFO suppresses calls to | `org-dp-prompt' and is used instead of its return value. | | Possible &rest PROMPT-SPEC should be keyword/value pairs used for | restricting user-prompting via `org-dp-prompt', e.g. | | :noprompt-affiliated t :noprompt-replace t | | see the docstring of that function for more info. `---- It is possible (and easy) to define new utility functions by restricting this very generic function to special use cases, e.g. from my init.el: #+BEGIN_SRC emacs-lisp ;; *** Org DP (when (require 'org-dp-lib nil t) (defun tj/wrap-in-elisp-block () (org-dp-wrap-in-block nil '(src-block nil nil nil (:language "emacs-lisp" :preserve-indent 1)))) (global-set-key (kbd "C-c w w") 'org-dp-wrap-in-block) (global-set-key (kbd "C-c w l") (lambda () (interactive) (let ((current-prefix-arg '(4))) (call-interactively 'org-dp-wrap-in-block)))) (global-set-key (kbd "C-c w e") (lambda () (interactive) (tj/wrap-in-elisp-block))) (global-set-key (kbd "C-c w a") (lambda () (interactive) (backward-sexp) (tj/wrap-in-elisp-block))) ) #+END_SRC I you tell me exactly what you need I could write you an utility function, or maybe play around with the function yourself, its very powerfull. -- cheers, Thorsten