Eric Abrahamsen <e...@ericabrahamsen.net> writes:

> And here's an actual patch, with docs.

Thank you! Some comments follow.

> +This function can be used to wrap existing text or Org elements in
> +a #+BEGIN_FOO/#+END_FOO block.  Not bound to a key by default.

Some free key bindings:
- C-c C-x C-e
- C-c C-x C-g
- C-c C-x C-h
- C-c C-x C-k
- C-c C-x h
- C-c C-x j
- C-c C-x k
- C-c C-x l
- C-c C-x m
- C-c C-x n
- C-c C-x r
- C-c C-x s
- C-c C-x t
- C-c C-x u
- C-c C-x w
- C-c C-x x
- C-c C-x y
- C-c C-x z

For the record, `C-c C-x C-f' is `org-emphasize', which is related.

> +(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."
> +  (interactive "sBlock type: ")
> +  (unless (use-region-p)
> +    (org-mark-element))
> +  (let ((s (copy-marker (min (point) (mark))))
> +     (e (copy-marker (max (point) (mark)))))





If there is no active region, is it better to mark element or to create
an empty block at point?

> +    (when (string-equal (downcase type) "example")
> +      (org-escape-code-in-region s e))
> +    (goto-char s)
> +    (beginning-of-line)
> +    (insert (format "#+BEGIN_%s" type))

I would store current indentation here and insert it in front of the
block openening, and closing, line. In any case, I would not use
`newline-and-indent' which could do unrelated stuff (e.g., re-indenting
a whole part of the buffer).

> +    (newline-and-indent)
> +    (goto-char e)
> +    (unless (bolp)
> +      (end-of-line)
> +      (newline-and-indent))
> +    (insert (format "#+END_%s" type))
> +    (newline-and-indent)

See above.

> +    (goto-char s)
> +    (end-of-line)

Why going to S? Initial position might be at the end of the region.

Also, could you write some tests along with your function?


Nicolas Goaziou

Reply via email to