On Sat, Sep 2, 2017, 10:23 PM Adam Porter wrote: > Hi Eric, > > Thanks for doing this. I've had some similar code in my config for a > while. I'll share some of it here in case you find it useful in doing > this. You especially might find the org-read-structure-template > function useful. > And here's my version, which also uses hydra. But the function modi/org-template-expand to insert the BEGIN_../END_.. blocks can be reused. This at least tells that there's a good need to have the easy template do the right thing when it is called with a region selected. @Adam: Looks like your code is doing a lot more than just that. I'll put that to my list to understand once I get to a computer. > (defun modi/org-template-expand (str &optional lang) "Expand Org template." (let (beg old-beg end content) ;; Save restriction to automatically undo the upcoming `narrow-to-region' (save-restriction (when (use-region-p) (setq beg (region-beginning)) (setq end (region-end)) ;; Note that regardless of the direction of selection, we will always ;; have (region-beginning) < (region-end). (save-excursion ;; If `point' is at `end', exchange point and mark so that now the ;; `point' is now at `beg' (when (> (point) (mark)) (exchange-point-and-mark)) ;; Insert a newline if `beg' is *not* at beginning of the line. ;; Example: You have ^abc$ where ^ is bol and $ is eol. ;; "bc" is selected and