[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] function for inserting a block
From: |
Marco Wahl |
Subject: |
Re: [O] function for inserting a block |
Date: |
Sat, 21 Oct 2017 13:59:01 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
Hi!
Xebar Saram <address@hidden> 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 (&optional 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, (continued)
- Re: [O] function for inserting a block, Carsten Dominik, 2017/10/18
- Re: [O] function for inserting a block, Eric Abrahamsen, 2017/10/18
- Re: [O] function for inserting a block, Carsten Dominik, 2017/10/19
- Re: [O] function for inserting a block, Eric Abrahamsen, 2017/10/20
- Re: [O] function for inserting a block, Kaushal Modi, 2017/10/20
- Re: [O] function for inserting a block, Kaushal Modi, 2017/10/20
- Re: [O] function for inserting a block, Eric Abrahamsen, 2017/10/20
- Re: [O] function for inserting a block, Eric Abrahamsen, 2017/10/20
- Re: [O] function for inserting a block, Kaushal Modi, 2017/10/20
- Re: [O] function for inserting a block, Xebar Saram, 2017/10/21
- Re: [O] function for inserting a block,
Marco Wahl <=
- Re: [O] function for inserting a block, Xebar Saram, 2017/10/21
- Re: [O] function for inserting a block, Eric Abrahamsen, 2017/10/21
- Re: [O] function for inserting a block, Kaushal Modi, 2017/10/23
- Re: [O] function for inserting a block, Carsten Dominik, 2017/10/23
- Re: [O] function for inserting a block, Kaushal Modi, 2017/10/23
- Re: [O] function for inserting a block, Eric Abrahamsen, 2017/10/23
- Re: [O] function for inserting a block, Nicolas Goaziou, 2017/10/23
- Re: [O] function for inserting a block, Eric Abrahamsen, 2017/10/23
- Re: [O] function for inserting a block, Eric Abrahamsen, 2017/10/23
- Re: [O] function for inserting a block, Nicolas Goaziou, 2017/10/24