Re: [O] function for inserting a block
Kaushal Modiwrites: > On Fri, Oct 20, 2017 at 5:15 PM Eric Abrahamsen > wrote: > > The template really only inserts the block type, not anything specific > like the source language or export backend. > > Right, but based on the code you have, you can easily add "SRC org", "SRC > emacs-lisp" to the default value of that list. Looking at that, users can > also get an idea that > they can add their favorite languages to that list too. > > I think prompting for > "second-level" information like that might be a little overkill. > > I second that. The first-level prompt also feels a bit slow, honestly, > compared to using easy templates like " (just an example) to insert > the, well, EXAMPLE block as usual. But *if region is selected*, it does the > wrapping as in your code. Perhaps it would make sense to combine the two functionalities; that's not a decision I can make, though.
Re: [O] function for inserting a block
thx thats perfect Z On Sat, Oct 21, 2017 at 2:59 PM, Marco Wahlwrote: > The following message is a courtesy copy of an article > that has been posted to gmane.emacs.orgmode as well. > > Hi! > > Xebar Saram writes: > > > this looks really cool and would love to try. as a non technical user, > how > > does one use the patch to get the functionality? is there a way to > create a > > clean function only version from the patch i can try? > > You could simply pick the relevant parts from the patch and evaluate > them. > > Concretely you could do: > > 1. Copy Eric's code to empty buffer *scratch*. The relevant code is > > #+BEGIN_SRC elisp > (defcustom org-structure-predefined-blocks > '("SRC" "EXAMPLE" "QUOTE" "VERSE" "VERBATIM" "CENTER" "COMMENT" "EXPORT") > "Block structure completion names." > :group 'org-completion > :type '(repeat string) > :package-version '(Org . "9.1.3")) > > (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. With an element under > point, wrap the element in the block. Otherwise, insert an empty > block." > (interactive) > (setq type (or type (completing-read "Block type: " >org-structure-predefined-blocks))) > (unless (use-region-p) > (when (org-element-at-point) > (org-mark-element))) > (let ((s (if (use-region-p) >(region-beginning) > (point))) > (e (copy-marker (if (use-region-p) > (region-end) > (point)) > t)) > column) > (when (string-equal (downcase type) "example") > (org-escape-code-in-region s e)) > (goto-char s) > (setq column (current-indentation)) > (beginning-of-line) > (indent-to column) > (insert (format "#+BEGIN_%s\n" type)) > (goto-char e) > (if (bolp) > (progn > (skip-chars-backward " \n\t") > (forward-line)) > (end-of-line) > (insert "\n")) > (indent-to column) > (insert (format "#+END_%s\n" > type)) > (set-marker e nil))) > > (org-defkey org-mode-map "\C-c\C-xw"'org-insert-structure-template) > #+END_SRC > > 2. In buffer *scratch* do > > M-x eval-buffer > > 3. Voila! Check out C-c C-x w in an org mode buffer. > > > Best regards > Marco >
Re: [O] function for inserting a block
Hi! Xebar Saramwrites: > this looks really cool and would love to try. as a non technical user, how > does one use the patch to get the functionality? is there a way to create a > clean function only version from the patch i can try? You could simply pick the relevant parts from the patch and evaluate them. Concretely you could do: 1. Copy Eric's code to empty buffer *scratch*. The relevant code is #+BEGIN_SRC elisp (defcustom org-structure-predefined-blocks '("SRC" "EXAMPLE" "QUOTE" "VERSE" "VERBATIM" "CENTER" "COMMENT" "EXPORT") "Block structure completion names." :group 'org-completion :type '(repeat string) :package-version '(Org . "9.1.3")) (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. With an element under point, wrap the element in the block. Otherwise, insert an empty block." (interactive) (setq type (or type (completing-read "Block type: " org-structure-predefined-blocks))) (unless (use-region-p) (when (org-element-at-point) (org-mark-element))) (let ((s (if (use-region-p) (region-beginning) (point))) (e (copy-marker (if (use-region-p) (region-end) (point)) t)) column) (when (string-equal (downcase type) "example") (org-escape-code-in-region s e)) (goto-char s) (setq column (current-indentation)) (beginning-of-line) (indent-to column) (insert (format "#+BEGIN_%s\n" type)) (goto-char e) (if (bolp) (progn (skip-chars-backward " \n\t") (forward-line)) (end-of-line) (insert "\n")) (indent-to column) (insert (format "#+END_%s\n" type)) (set-marker e nil))) (org-defkey org-mode-map "\C-c\C-xw"'org-insert-structure-template) #+END_SRC 2. In buffer *scratch* do M-x eval-buffer 3. Voila! Check out C-c C-x w in an org mode buffer. Best regards Marco
Re: [O] function for inserting a block
Hi all this looks really cool and would love to try. as a non technical user, how does one use the patch to get the functionality? is there a way to create a clean function only version from the patch i can try? thx! Z On Sat, Oct 21, 2017 at 12:43 AM, Kaushal Modiwrote: > On Fri, Oct 20, 2017 at 5:15 PM Eric Abrahamsen > wrote: > >> The template really only inserts the block type, not anything specific >> like the source language or export backend. > > > Right, but based on the code you have, you can easily add "SRC org", "SRC > emacs-lisp" to the default value of that list. Looking at that, users can > also get an idea that they can add their favorite languages to that list > too. > > >> I think prompting for >> "second-level" information like that might be a little overkill. >> > > I second that. The first-level prompt also feels a bit slow, honestly, > compared to using easy templates like " (just an example) to insert the, well, EXAMPLE block as usual. But *if > region is selected*, it does the wrapping as in your code. > > This is what I mean (GIF animation): > > https://i.imgur.com/201TISW.gifv > > I use hydra to provide those awesome hints.. but the same can be done > without hydras too. > > As for what should be escaped and what shouldn't, I defer to Nicolas, >> let's see what he says. >> > -- > > Kaushal Modi >