emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Thorsten Jolitz <tjolitz@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: default headers for source code blocks
Date: Tue, 09 Sep 2014 21:11:44 +0200	[thread overview]
Message-ID: <87wq9cy5fz.fsf@gmail.com> (raw)
In-Reply-To: 6583026da8c34bcf9acce84acadc801a@fbmailsvr1.familycareinc.org

Subhan Michael Tindall <SubhanT@familycareinc.org> 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

  parent reply	other threads:[~2014-09-09 19:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-09 17:24 default headers for source code blocks Subhan Michael Tindall
2014-09-09 17:44 ` Ista Zahn
2014-09-09 19:11 ` Thorsten Jolitz [this message]
2014-09-10  4:24 ` Ken Mankoff
2014-09-10  7:31   ` Sebastien Vauban

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wq9cy5fz.fsf@gmail.com \
    --to=tjolitz@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).