[Top][All Lists]

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

[O] function for inserting a block

From: Eric Abrahamsen
Subject: [O] function for inserting a block
Date: Sat, 02 Sep 2017 17:25:30 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

The easy template entry thing is useful as far as it goes, but for some
reason I find myself "marking up" existing text in Org as least as often
as I'm writing new text from scratch. I've always wanted a "wrap region
in block" command, and finally wrote one. Don't know why it took me so
long. Would something like this be attractive for inclusion in Org?

(defun org-insert-structure-template (type start end)
  "Insert a block structure as in #+BEGIN_TYPE/#+END_TYPE.

Prompts for a block TYPE, and inserts the block.  With an active
region, wrap the region in the block."
  (interactive "sBlock type: \nr")
  (let ((s (set-marker (make-marker) start))
        (e (set-marker (make-marker) end)))
   (goto-char s)
   (goto-char (line-beginning-position))
   (insert (format "#+BEGIN_%s\n" (upcase type)))
   (goto-char e)
   (goto-char (line-end-position))
   (insert (format "\n#+END_%s" (upcase type)))))

Other possibilities:

- A "close current block" command, a la `sgml-close-tag'. Inserts
  a #+END_FOO tag if needed.
- Provide completion for the block type prompt, though that might create
  some redundancy with `org-structure-template-alist'.

If this is acceptable, I'd like to bind it to "C-c i", and would provide


reply via email to

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