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: Nicolas Goaziou
Subject: Re: [O] function for inserting a block
Date: Sun, 10 Sep 2017 14:44:37 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)

Hello,

Eric Abrahamsen <address@hidden> 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)))))

Use:

  (region-beginning)
  (region-end)

not

  (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?

Regards,

-- 
Nicolas Goaziou



reply via email to

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