emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] function for inserting a block


From: Eric Abrahamsen
Subject: Re: [O] function for inserting a block
Date: Fri, 08 Sep 2017 11:52:51 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

Eric Abrahamsen <address@hidden> writes:

[...]

> Here's another stab at it. Is "example" the only block that should be
> verbatim? Will using `newline-and-indent' instead of inserting literal
> newlines solve the indentation problem?
>
>
> (defun org-insert-structure-template (type)
>   "Insert a block structure of the type #+BEGIN_FOO/#+END_FOO.
> Prompts for a block type, and inserts the block.  With an active
> region, wrap the region in the block.  With no active region, wrap the
> current element."
>   (interactive "sBlock type: ")
>   (unless (use-region-p)
>     (org-mark-element))
>   (let ((s (copy-marker (min (point) (mark))))
>       (e (copy-marker (max (point) (mark)))))
>     (when (string-equal (downcase type) "example")
>       (org-escape-code-in-region s e))
>     (goto-char s)
>     (beginning-of-line)
>     (insert (format "#+BEGIN_%s" type))
>     (newline-and-indent)
>     (goto-char e)
>     (unless (bolp)
>       (end-of-line)
>       (newline-and-indent))
>     (insert (format "#+END_%s" type))
>     (newline-and-indent)
>     (set-marker s nil)
>     (set-marker e nil)))

And here's an actual patch, with docs.

Attachment: 0001-New-function-org-insert-structure-template.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]