From mboxrd@z Thu Jan 1 00:00:00 1970 From: Xebar Saram Subject: Re: function for inserting a block Date: Sat, 21 Oct 2017 16:32:33 +0300 Message-ID: References: <877exghblx.fsf@ericabrahamsen.net> <874lsabdop.fsf@ericabrahamsen.net> <87vak1l11m.fsf@nicolasgoaziou.fr> <87r2uoc4q7.fsf@ericabrahamsen.net> <87bmllk5xy.fsf@nicolasgoaziou.fr> <878tgmwwsa.fsf@ericabrahamsen.net> <87po9q2e8k.fsf@nicolasgoaziou.fr> <87tvyyvpst.fsf@ericabrahamsen.net> <87fuaiz069.fsf@nicolasgoaziou.fr> <87lgk9eo4d.fsf@ericabrahamsen.net> <87fuahxxvs.fsf@nicolasgoaziou.fr> <87r2u1cuwj.fsf@ericabrahamsen.net> <87infdctzq.fsf@ericabrahamsen.net> <87k1zsbizs.fsf@ericabrahamsen.net> <87k1zp4rxj.fsf@ericabrahamsen.net> <871slx4j6p.fsf@ericabrahamsen.net> <84o9p07lve.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="001a114696bc358947055c0e9f37" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:58721) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5ttE-0006s3-E2 for emacs-orgmode@gnu.org; Sat, 21 Oct 2017 09:32:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e5ttD-0008Bj-71 for emacs-orgmode@gnu.org; Sat, 21 Oct 2017 09:32:36 -0400 Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]:51236) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e5ttC-0008B3-UF for emacs-orgmode@gnu.org; Sat, 21 Oct 2017 09:32:35 -0400 Received: by mail-wm0-x235.google.com with SMTP id f4so2406674wme.0 for ; Sat, 21 Oct 2017 06:32:34 -0700 (PDT) In-Reply-To: <84o9p07lve.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Marco Wahl , org mode --001a114696bc358947055c0e9f37 Content-Type: text/plain; charset="UTF-8" thx thats perfect Z On Sat, Oct 21, 2017 at 2:59 PM, Marco Wahl wrote: > 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 (&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 > --001a114696bc358947055c0e9f37 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
thx thats perfect

Z

On Sat, Oct 21, 2017 at 2= :59 PM, Marco Wahl <marcowahlsoft@gmail.com> wrote:
The following message is a courtesy copy of= an article
that has been posted to gmane.emacs.orgmode as well.

Hi!

Xebar Saram <zeltakc@gmail.com&= gt; 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 cre= ate 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*.=C2=A0 The relevant code = is

#+BEGIN_SRC elisp
(defcustom org-structure-predefined-blocks
=C2=A0 '("SRC" "EXAMPLE" "QUOTE" "VE= RSE" "VERBATIM" "CENTER" "COMMENT" "= ;EXPORT")
=C2=A0 "Block structure completion names."
=C2=A0 :group 'org-completion
=C2=A0 :type '(repeat string)
=C2=A0 :package-version '(Org . "9.1.3"))

(defun org-insert-structure-template (&optional type)
=C2=A0 "Insert a block structure of the type #+BEGIN_= FOO/#+END_FOO.
Prompts for a block type, and inserts the block.=C2= =A0 With an active
region, wrap the region in the block.=C2=A0 With an element under point, wrap the element in the block.=C2=A0 Otherwise, insert an empty
block."
=C2=A0 (interactive)
=C2=A0 (setq type (or type (completing-read "Block type: "
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0org-struc= ture-predefined-blocks)))
=C2=A0 (unless (use-region-p)
=C2=A0 =C2=A0 (when (org-element-at-point)
=C2=A0 =C2=A0 =C2=A0 (org-mark-element)))
=C2=A0 (let ((s (if (use-region-p)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(region-beginning) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(point)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (e (copy-marker (if (use-region-p)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 (region-end)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 (point))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 t))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 column)
=C2=A0 =C2=A0 (when (string-equal (downcase type) "ex= ample")
=C2=A0 =C2=A0 =C2=A0 (org-escape-code-in-region s e))
=C2=A0 =C2=A0 (goto-char s)
=C2=A0 =C2=A0 (setq column (current-indentation))
=C2=A0 =C2=A0 (beginning-of-line)
=C2=A0 =C2=A0 (indent-to column)
=C2=A0 =C2=A0 (insert (format "#+BEGIN_%s\n" type))
=C2=A0 =C2=A0 (goto-char e)
=C2=A0 =C2=A0 (if (bolp)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (progn
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (skip-chars-backward " \n\t")<= br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (forward-line))
=C2=A0 =C2=A0 =C2=A0 (end-of-line)
=C2=A0 =C2=A0 =C2=A0 (insert "\n"))
=C2=A0 =C2=A0 (indent-to column)
=C2=A0 =C2=A0 (insert (format "#+END_%s\n"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 type)= )
=C2=A0 =C2=A0 (set-marker e nil)))

(org-defkey org-mode-map "\C-c\C-xw"=C2=A0 =C2=A0 'org-insert= -structure-template)
#+END_SRC

2. In buffer *scratch* do

=C2=A0 =C2=A0 M-x eval-buffer

3. Voila!=C2=A0 Check out C-c C-x w in an org mode buffer.


Best regards
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 Marco

--001a114696bc358947055c0e9f37--