Hello, Eric Abrahamsen <e...@ericabrahamsen.net> writes:
> 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? Thanks. I agree Org needs something like this. > (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))) (set-marker (make-marker) start) -> (copy-marker start) You need to clean these markers at the end of the function. Markers set to a position are never garbage-collected. Usually, it happens at the end of an `unwind-protect'. > (goto-char s) > (goto-char (line-beginning-position)) > (insert (format "#+BEGIN_%s\n" (upcase type))) (upcase type) is wrong, because special blocks are case sensitive. > (goto-char e) > (goto-char (line-end-position)) (end-of-line) ? > (insert (format "\n#+END_%s" (upcase type))))) The function also needs to take care about global indentation. Inserting at column 0 may not be desirable. What happens if no region is active? Can it mark the element at point (see `org-mark-element')? What happens if the chosen type is verbatim (e.g. "example"), can it protect "#+", "*" and so on with commas (see `org-escape-code-in-region')? > If this is acceptable, I'd like to bind it to "C-c i", and would provide > docs. We cannot bind it to "C-c i", this is a reserved key-binding. But we can suggest users to do so in the manual. Or find another binding. Regards, -- Nicolas Goaziou