[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] default headers for source code blocks
From: |
Thorsten Jolitz |
Subject: |
Re: [O] default headers for source code blocks |
Date: |
Tue, 09 Sep 2014 21:11:44 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
Subhan Michael Tindall <address@hidden> 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