emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* How do I create a drawer?
@ 2012-01-25  0:46 Nick Dokos
  2012-01-25  8:29 ` Olaf Dietsche
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Nick Dokos @ 2012-01-25  0:46 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: nicholas.dokos


The only way I found so far to create a drawer is to actually type the
damn thing in (I'm talking about my own drawers, not the special
drawers that org knows something about). I didn't find any utility
functions to insert drawers (except for :PROPERTIES:), and somewhat to
my surprise, completion does not seem to work for drawer names: I
expected typing a colon and M-TAB would allow me to use drawer names for
completion, but it seems to only care about property keys, even if I'm
not in the context of a :PROPERTIES: drawer. Am I missing something?

Thanks,
Nick

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How do I create a drawer?
  2012-01-25  0:46 How do I create a drawer? Nick Dokos
@ 2012-01-25  8:29 ` Olaf Dietsche
  2012-01-25 14:25   ` Bastien
  2012-01-25  8:44 ` Russell Adams
  2012-01-25  9:03 ` Bastien
  2 siblings, 1 reply; 16+ messages in thread
From: Olaf Dietsche @ 2012-01-25  8:29 UTC (permalink / raw)
  To: nicholas.dokos; +Cc: emacs-orgmode

Nick Dokos <nicholas.dokos@hp.com> writes:

> The only way I found so far to create a drawer is to actually type the
> damn thing in (I'm talking about my own drawers, not the special
> drawers that org knows something about). I didn't find any utility
> functions to insert drawers (except for :PROPERTIES:), and somewhat to
> my surprise, completion does not seem to work for drawer names: I
> expected typing a colon and M-TAB would allow me to use drawer names for
> completion, but it seems to only care about property keys, even if I'm
> not in the context of a :PROPERTIES: drawer. Am I missing something?

For a quick hack, you might try this one:

diff --git a/lisp/org.el b/lisp/org.el
index 7163e8f..129e08c 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -14397,6 +14397,11 @@ formats in the current buffer."
 (defun org-insert-property-drawer ()
   "Insert a property drawer into the current entry."
   (interactive)
+  (org-insert-drawer "PROPERTIES"))
+
+(defun org-insert-drawer (drawer)
+  "Insert a drawer into the current entry."
+  (interactive "sDrawer: ")
   (org-back-to-heading t)
   (looking-at org-outline-regexp)
   (let ((indent (if org-adapt-indentation
@@ -14422,7 +14427,7 @@ formats in the current buffer."
     (org-skip-over-state-notes)
     (skip-chars-backward " \t\n\r")
     (if (eq (char-before) ?*) (forward-char 1))
-    (let ((inhibit-read-only t)) (insert "\n:PROPERTIES:\n:END:"))
+    (let ((inhibit-read-only t)) (insert "\n:" drawer ":\n:END:"))
     (beginning-of-line 0)
     (org-indent-to-column indent)
     (beginning-of-line 2)

With M-x org-insert-drawer RET drawer-name RET inserts your own
drawer. It doesn't support completion though.

Regards, Olaf

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How do I create a drawer?
  2012-01-25  0:46 How do I create a drawer? Nick Dokos
  2012-01-25  8:29 ` Olaf Dietsche
@ 2012-01-25  8:44 ` Russell Adams
  2012-01-25  9:03 ` Bastien
  2 siblings, 0 replies; 16+ messages in thread
From: Russell Adams @ 2012-01-25  8:44 UTC (permalink / raw)
  To: emacs-orgmode

On Tue, Jan 24, 2012 at 07:46:12PM -0500, Nick Dokos wrote:
>
> The only way I found so far to create a drawer is to actually type the
> damn thing in (I'm talking about my own drawers, not the special
> drawers that org knows something about). I didn't find any utility
> functions to insert drawers (except for :PROPERTIES:), and somewhat to
> my surprise, completion does not seem to work for drawer names: I
> expected typing a colon and M-TAB would allow me to use drawer names for
> completion, but it seems to only care about property keys, even if I'm
> not in the context of a :PROPERTIES: drawer. Am I missing something?

Nick,

I'd suggest you look at a tool like yas-snippet, which allows template
insertion into any mode of all kinds of text templates. When I do
drawers that follow a regular format, that's what I use.



------------------------------------------------------------------
Russell Adams                            RLAdams@AdamsInfoServ.com

PGP Key ID:     0x1160DCB3           http://www.adamsinfoserv.com/

Fingerprint:    1723 D8CA 4280 1EC9 557F  66E8 1154 E018 1160 DCB3

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How do I create a drawer?
  2012-01-25  0:46 How do I create a drawer? Nick Dokos
  2012-01-25  8:29 ` Olaf Dietsche
  2012-01-25  8:44 ` Russell Adams
@ 2012-01-25  9:03 ` Bastien
  2012-01-25  9:17   ` Rainer M Krug
  2012-01-25 13:16   ` Carsten Dominik
  2 siblings, 2 replies; 16+ messages in thread
From: Bastien @ 2012-01-25  9:03 UTC (permalink / raw)
  To: nicholas.dokos; +Cc: emacs-orgmode

Hi Nick,

Nick Dokos <nicholas.dokos@hp.com> writes:

> The only way I found so far to create a drawer is to actually type the
> damn thing in (I'm talking about my own drawers, not the special
> drawers that org knows something about). I didn't find any utility
> functions to insert drawers (except for :PROPERTIES:), and somewhat to
> my surprise, completion does not seem to work for drawer names: I
> expected typing a colon and M-TAB would allow me to use drawer names for
> completion, but it seems to only care about property keys, even if I'm
> not in the context of a :PROPERTIES: drawer.

You can now complete drawer names using M-TAB.  It will insert the
drawer name and the ":END:" string.

HTH,

-- 
 Bastien

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How do I create a drawer?
  2012-01-25  9:03 ` Bastien
@ 2012-01-25  9:17   ` Rainer M Krug
  2012-01-25 13:16   ` Carsten Dominik
  1 sibling, 0 replies; 16+ messages in thread
From: Rainer M Krug @ 2012-01-25  9:17 UTC (permalink / raw)
  To: Bastien; +Cc: nicholas.dokos, emacs-orgmode

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 25/01/12 10:03, Bastien wrote:
> Hi Nick,
> 
> Nick Dokos <nicholas.dokos@hp.com> writes:
> 
>> The only way I found so far to create a drawer is to actually
>> type the damn thing in (I'm talking about my own drawers, not the
>> special drawers that org knows something about). I didn't find
>> any utility functions to insert drawers (except for
>> :PROPERTIES:), and somewhat to my surprise, completion does not
>> seem to work for drawer names: I expected typing a colon and
>> M-TAB would allow me to use drawer names for completion, but it
>> seems to only care about property keys, even if I'm not in the
>> context of a :PROPERTIES: drawer.
> 
> You can now complete drawer names using M-TAB.  It will insert the 
> drawer name and the ":END:" string.

You know, these are the things I *love* about org-mode and it's community.

Thanks a lot, although I did not ask for the feature,

Rainer


> 
> HTH,
> 


- -- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :       +33 - (0)9 53 10 27 44
Cell:       +33 - (0)6 85 62 59 98
Fax :       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      Rainer@krugs.de

Skype:      RMkrug
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk8fyIwACgkQoYgNqgF2egrnwACdEeGBomkyBf/pax3/mSR92gdB
os4AniuHpniznMSKKSImMu7a3M0Rb036
=TkNK
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How do I create a drawer?
  2012-01-25  9:03 ` Bastien
  2012-01-25  9:17   ` Rainer M Krug
@ 2012-01-25 13:16   ` Carsten Dominik
  2012-01-25 13:29     ` Nicolas Goaziou
  2012-01-25 14:26     ` Bastien
  1 sibling, 2 replies; 16+ messages in thread
From: Carsten Dominik @ 2012-01-25 13:16 UTC (permalink / raw)
  To: Bastien; +Cc: nicholas.dokos, emacs-orgmode


On 25.1.2012, at 09:03, Bastien wrote:

> Hi Nick,
> 
> Nick Dokos <nicholas.dokos@hp.com> writes:
> 
>> The only way I found so far to create a drawer is to actually type the
>> damn thing in (I'm talking about my own drawers, not the special
>> drawers that org knows something about). I didn't find any utility
>> functions to insert drawers (except for :PROPERTIES:), and somewhat to
>> my surprise, completion does not seem to work for drawer names: I
>> expected typing a colon and M-TAB would allow me to use drawer names for
>> completion, but it seems to only care about property keys, even if I'm
>> not in the context of a :PROPERTIES: drawer.
> 
> You can now complete drawer names using M-TAB.  It will insert the
> drawer name and the ":END:" string.

This is nice.  But I think Olaf's patch would still be useful to apply.

Cheers

- Carsten

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How do I create a drawer?
  2012-01-25 13:16   ` Carsten Dominik
@ 2012-01-25 13:29     ` Nicolas Goaziou
  2012-01-25 14:09       ` Carsten Dominik
  2012-01-25 14:26     ` Bastien
  1 sibling, 1 reply; 16+ messages in thread
From: Nicolas Goaziou @ 2012-01-25 13:29 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: Bastien, nicholas.dokos, emacs-orgmode

Hello,

Carsten Dominik <carsten.dominik@gmail.com> writes:

> On 25.1.2012, at 09:03, Bastien wrote:
>
>> Nick Dokos <nicholas.dokos@hp.com> writes:
>> 
>>> The only way I found so far to create a drawer is to actually type the
>>> damn thing in (I'm talking about my own drawers, not the special
>>> drawers that org knows something about). I didn't find any utility
>>> functions to insert drawers (except for :PROPERTIES:), and somewhat to
>>> my surprise, completion does not seem to work for drawer names: I
>>> expected typing a colon and M-TAB would allow me to use drawer names for
>>> completion, but it seems to only care about property keys, even if I'm
>>> not in the context of a :PROPERTIES: drawer.
>> 
>> You can now complete drawer names using M-TAB.  It will insert the
>> drawer name and the ":END:" string.
>
> This is nice.  But I think Olaf's patch would still be useful to
> apply.

And while we're at suggestions, it would be even better if the
`org-insert-drawer' function supported regions.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How do I create a drawer?
  2012-01-25 13:29     ` Nicolas Goaziou
@ 2012-01-25 14:09       ` Carsten Dominik
  2012-01-25 14:17         ` Nicolas Goaziou
  0 siblings, 1 reply; 16+ messages in thread
From: Carsten Dominik @ 2012-01-25 14:09 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Bastien, nicholas.dokos, emacs-orgmode


On 25.1.2012, at 13:29, Nicolas Goaziou wrote:

> Hello,
> 
> Carsten Dominik <carsten.dominik@gmail.com> writes:
> 
>> On 25.1.2012, at 09:03, Bastien wrote:
>> 
>>> Nick Dokos <nicholas.dokos@hp.com> writes:
>>> 
>>>> The only way I found so far to create a drawer is to actually type the
>>>> damn thing in (I'm talking about my own drawers, not the special
>>>> drawers that org knows something about). I didn't find any utility
>>>> functions to insert drawers (except for :PROPERTIES:), and somewhat to
>>>> my surprise, completion does not seem to work for drawer names: I
>>>> expected typing a colon and M-TAB would allow me to use drawer names for
>>>> completion, but it seems to only care about property keys, even if I'm
>>>> not in the context of a :PROPERTIES: drawer.
>>> 
>>> You can now complete drawer names using M-TAB.  It will insert the
>>> drawer name and the ":END:" string.
>> 
>> This is nice.  But I think Olaf's patch would still be useful to
>> apply.
> 
> And while we're at suggestions, it would be even better if the
> `org-insert-drawer' function supported regions.

Meaning it should insert the drawer in every headline in the region?

- Carsten

> 
> 
> Regards,
> 
> -- 
> Nicolas Goaziou

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How do I create a drawer?
  2012-01-25 14:09       ` Carsten Dominik
@ 2012-01-25 14:17         ` Nicolas Goaziou
  2012-01-25 14:27           ` Bastien
  0 siblings, 1 reply; 16+ messages in thread
From: Nicolas Goaziou @ 2012-01-25 14:17 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: Bastien, nicholas.dokos, emacs-orgmode

>> And while we're at suggestions, it would be even better if the
>> `org-insert-drawer' function supported regions.
>
> Meaning it should insert the drawer in every headline in the region?

No. Around the region. If an headline is found within the region, the
function should return an error instead, telling the user that drawers
cannot contain headlines.

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How do I create a drawer?
  2012-01-25  8:29 ` Olaf Dietsche
@ 2012-01-25 14:25   ` Bastien
  0 siblings, 0 replies; 16+ messages in thread
From: Bastien @ 2012-01-25 14:25 UTC (permalink / raw)
  To: Olaf Dietsche; +Cc: nicholas.dokos, emacs-orgmode

Olaf Dietsche <olaf+list.orgmode@olafdietsche.de> writes:

> For a quick hack, you might try this one:

Applied, thanks!

-- 
 Bastien

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How do I create a drawer?
  2012-01-25 13:16   ` Carsten Dominik
  2012-01-25 13:29     ` Nicolas Goaziou
@ 2012-01-25 14:26     ` Bastien
  2012-01-25 14:34       ` Nick Dokos
  1 sibling, 1 reply; 16+ messages in thread
From: Bastien @ 2012-01-25 14:26 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: nicholas.dokos, emacs-orgmode

Carsten Dominik <carsten.dominik@gmail.com> writes:

> This is nice.  But I think Olaf's patch would still be useful to
> apply.

Indeed.  I applied a slightly enhanced version, supporting 
completion and region, as Nicolas just suggested.

Thanks all for the feedback,

-- 
 Bastien

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How do I create a drawer?
  2012-01-25 14:17         ` Nicolas Goaziou
@ 2012-01-25 14:27           ` Bastien
  2012-01-25 16:33             ` Nicolas Goaziou
  0 siblings, 1 reply; 16+ messages in thread
From: Bastien @ 2012-01-25 14:27 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: nicholas.dokos, emacs-orgmode, Carsten Dominik

Hi Nicolas,

Nicolas Goaziou <n.goaziou@gmail.com> writes:

> No. Around the region. If an headline is found within the region, the
> function should return an error instead, telling the user that drawers
> cannot contain headlines.

The version I just pushed does not handle this kind of problem.
If you think it's worth the trouble, can you have a look at it?

Thanks in advance!

-- 
 Bastien

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How do I create a drawer?
  2012-01-25 14:26     ` Bastien
@ 2012-01-25 14:34       ` Nick Dokos
  2012-01-26  1:46         ` François Pinard
  0 siblings, 1 reply; 16+ messages in thread
From: Nick Dokos @ 2012-01-25 14:34 UTC (permalink / raw)
  To: Bastien; +Cc: nicholas.dokos, emacs-orgmode, Carsten Dominik

Bastien <bzg@altern.org> wrote:

> Carsten Dominik <carsten.dominik@gmail.com> writes:
> 
> > This is nice.  But I think Olaf's patch would still be useful to
> > apply.
> 
> Indeed.  I applied a slightly enhanced version, supporting 
> completion and region, as Nicolas just suggested.
> 
> Thanks all for the feedback,
> 

I go to sleep wondering how to do something and I wake up with not one,
but two solutions, both of them newly implemented. Rainer said it best:
I *love* org-mode and its community. Off to try them out...

Thanks!
Nick

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How do I create a drawer?
  2012-01-25 14:27           ` Bastien
@ 2012-01-25 16:33             ` Nicolas Goaziou
  2012-01-26  8:28               ` Bastien
  0 siblings, 1 reply; 16+ messages in thread
From: Nicolas Goaziou @ 2012-01-25 16:33 UTC (permalink / raw)
  To: Bastien; +Cc: nicholas.dokos, emacs-orgmode, Carsten Dominik

[-- Attachment #1: Type: text/plain, Size: 1455 bytes --]

Hello,

Bastien <bzg@altern.org> writes:

> The version I just pushed does not handle this kind of problem.
> If you think it's worth the trouble, can you have a look at it?

I've checked the code, and the `org-insert-drawer' is actually not what
I had in mind.

To me, there are really two types of drawers: system drawers and user's
drawers (which I'll simply call "drawers" from now).  System drawers
usually go just below the current headline (which is mandatory) and are
inserted automatically by some Org mechanism. Drawers can go anywhere,
even before the first headline, and are usually inserted manually.

Being interactive, `org-insert-drawer' is clearly user-oriented. An user
calling this function will probably want to insert a drawer at point (if
not around region), much less likely to insert a system drawer manually.

Thus, that function shouldn't be used for `org-insert-property-drawer'
internals, which needs to move point back to the headline.

Therefore, I suggest the following draft of a patch, that mostly reverts
commit splitting `org-insert-property-drawer' and makes
`org-insert-drawer' more user friendly. It provides the following
facilities:

  - headline inclusion check,
  - drawer insertion without requiring an headline above,
  - skip trailing blank lines (i.e. to wrap buffer around a just marked
    paragraph),
  - Ignore system drawer's names in completion list.

What do you think?


Regards,

-- 
Nicolas Goaziou

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: insert drawer patch --]
[-- Type: text/x-patch, Size: 6275 bytes --]

From f3c76eb772d1d8e0fa9fc53f10ed8985334c75bf Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <n.goaziou@gmail.com>
Date: Wed, 25 Jan 2012 16:48:21 +0100
Subject: [PATCH] Make org-insert-drawer more user oriented

* lisp/org.el (org-insert-property-drawer): Do not rely on
  `org-insert-drawer' since properties drawers are not meant for
  user's consumption.
(org-insert-drawer): Insert drawer at point.  If a region is provided,
wrap the drawer around it instead.  When offering completion, ignore
internal drawers.  Provide an error message when region contains an
headline.
---
 lisp/org.el |  143 +++++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 91 insertions(+), 52 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 1fa7259..cada815 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -14399,61 +14399,100 @@ formats in the current buffer."
 (defun org-insert-property-drawer ()
   "Insert a property drawer into the current entry."
   (interactive)
-  (org-insert-drawer "PROPERTIES"))
+  (org-back-to-heading t)
+  (looking-at org-outline-regexp)
+  (let ((indent (if org-adapt-indentation
+		    (- (match-end 0) (match-beginning 0))
+		  0))
+	(beg (point))
+	(re (concat "^[ \t]*" org-keyword-time-regexp))
+	end hiddenp)
+    (outline-next-heading)
+    (setq end (point))
+    (goto-char beg)
+    (while (re-search-forward re end t))
+    (setq hiddenp (outline-invisible-p))
+    (end-of-line 1)
+    (and (equal (char-after) ?\n) (forward-char 1))
+    (while (looking-at "^[ \t]*\\(:CLOCK:\\|:LOGBOOK:\\|CLOCK:\\|:END:\\)")
+      (if (member (match-string 1) '("CLOCK:" ":END:"))
+	  ;; just skip this line
+	  (beginning-of-line 2)
+	;; Drawer start, find the end
+	(re-search-forward "^\\*+ \\|^[ \t]*:END:" nil t)
+	(beginning-of-line 1)))
+    (org-skip-over-state-notes)
+    (skip-chars-backward " \t\n\r")
+    (if (eq (char-before) ?*) (forward-char 1))
+    (let ((inhibit-read-only t)) (insert "\n:PROPERTIES:\n:END:"))
+    (beginning-of-line 0)
+    (org-indent-to-column indent)
+    (beginning-of-line 2)
+    (org-indent-to-column indent)
+    (beginning-of-line 0)
+    (if hiddenp
+	(save-excursion
+	  (org-back-to-heading t)
+	  (hide-entry))
+      (org-flag-drawer t))))
 
 (defun org-insert-drawer (&optional drawer)
-  "Insert a drawer into the current entry."
+  "Insert a drawer at point.
+
+Optional argument DRAWER, when non-nil, is a string representing
+drawer's name.  Otherwise, the user is prompted for a name.
+
+If a region is active, insert the drawer around that region
+instead.
+
+Point is left between drawer's boundaries."
   (interactive)
-  (if (org-region-active-p)
-    (let ((rbeg (region-beginning))
-	  (rend (region-end))
-	  (drawer (or drawer (completing-read "Drawer: " org-drawers))))
-      (goto-char rbeg)
-      (insert ":" drawer ":\n")
-      (move-beginning-of-line 1)
-      (indent-for-tab-command)
-      (goto-char rend)
-      (move-end-of-line 1)
-      (insert "\n:END:")
-      (move-beginning-of-line 1)
-      (indent-for-tab-command))
-    (org-back-to-heading t)
-    (looking-at org-outline-regexp)
-    (let ((indent (if org-adapt-indentation
-		      (- (match-end 0) (match-beginning 0))
-		    0))
-	  (beg (point))
-	  (re (concat "^[ \t]*" org-keyword-time-regexp))
-	  (drawer (or drawer (completing-read "Drawer: " org-drawers)))
-	  end hiddenp)
-      (outline-next-heading)
-      (setq end (point))
-      (goto-char beg)
-      (while (re-search-forward re end t))
-      (setq hiddenp (outline-invisible-p))
-      (end-of-line 1)
-      (and (equal (char-after) ?\n) (forward-char 1))
-      (while (looking-at "^[ \t]*\\(:CLOCK:\\|:LOGBOOK:\\|CLOCK:\\|:END:\\)")
-	(if (member (match-string 1) '("CLOCK:" ":END:"))
-	    ;; just skip this line
-	    (beginning-of-line 2)
-	  ;; Drawer start, find the end
-	  (re-search-forward "^\\*+ \\|^[ \t]*:END:" nil t)
-	  (beginning-of-line 1)))
-      (org-skip-over-state-notes)
-      (skip-chars-backward " \t\n\r")
-      (if (eq (char-before) ?*) (forward-char 1))
-      (let ((inhibit-read-only t)) (insert "\n:" drawer ":\n:END:"))
-      (beginning-of-line 0)
-      (org-indent-to-column indent)
-      (beginning-of-line 2)
-      (org-indent-to-column indent)
-      (beginning-of-line 0)
-      (if hiddenp
-	  (save-excursion
-	    (org-back-to-heading t)
-	    (hide-entry))
-	(org-flag-drawer t)))))
+  (let* ((logbook (if (stringp org-log-into-drawer) org-log-into-drawer
+		    "LOGBOOK"))
+	 ;; SYSTEM-DRAWERS is a list of drawer names that are used
+	 ;; internally by Org.  They are meant to be inserted
+	 ;; automatically.
+	 (system-drawers `("CLOCK" ,logbook "PROPERTIES"))
+	 ;; Remove system drawers from list.  Note: For some reason,
+	 ;; `org-completing-read' ignores the predicate while
+	 ;; `completing-read' handles it fine.
+	 (drawer (or drawer
+		     (completing-read
+		      "Drawer: " org-drawers
+		      (lambda (d) (not (member d system-drawers)))))))
+    (if (not (org-region-active-p))
+	;; Insert a drawer at point.
+	(progn
+	  (unless (bolp) (insert "\n"))
+	  (insert (format ":%s:\n\n:END:\n" drawer))
+	  (forward-line -2))
+      (let ((rbeg (region-beginning))
+	    (rend (copy-marker (region-end))))
+	(unwind-protect
+	    (progn
+	      (goto-char rbeg)
+	      (beginning-of-line)
+	      (when (save-excursion
+		      (re-search-forward org-outline-regexp-bol rend t))
+		(error "Drawers cannot contain headlines"))
+	      ;; Position point at the beginning of the first
+	      ;; non-blank line in region. Insert drawer's opening
+	      ;; there, then indent it.
+	      (org-skip-whitespace)
+	      (beginning-of-line)
+	      (insert ":" drawer ":\n")
+	      (forward-line -1)
+	      (indent-for-tab-command)
+	      ;; Move point to the beginning of the first blank line
+	      ;; after the last non-blank line in region.  Insert
+	      ;; drawer's closing, then indent it.
+	      (goto-char rend)
+	      (skip-chars-backward " \r\t\n")
+	      (insert "\n:END:")
+	      (indent-for-tab-command)
+	      (unless (eolp) (insert "\n")))
+	  ;; Clear marker, whatever the outcome of insertion is.
+	  (set-marker rend nil))))))
 
 (defvar org-property-set-functions-alist nil
   "Property set function alist.
-- 
1.7.8.4


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How do I create a drawer?
  2012-01-25 14:34       ` Nick Dokos
@ 2012-01-26  1:46         ` François Pinard
  0 siblings, 0 replies; 16+ messages in thread
From: François Pinard @ 2012-01-26  1:46 UTC (permalink / raw)
  To: emacs-orgmode

Nick Dokos <nicholas.dokos@hp.com> writes:

> I *love* org-mode and its community.

Indeed.  This is an enthusiastic, and enthusiasming crowd!  All fueled
by maintainers who not only listen and understand, but are also take
decisions (so things go on, instead of turning into endless debates).

A /special/ place, as youngsters would put it :-).

François

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: How do I create a drawer?
  2012-01-25 16:33             ` Nicolas Goaziou
@ 2012-01-26  8:28               ` Bastien
  0 siblings, 0 replies; 16+ messages in thread
From: Bastien @ 2012-01-26  8:28 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: nicholas.dokos, emacs-orgmode, Carsten Dominik

Hi Nicolas,

Nicolas Goaziou <n.goaziou@gmail.com> writes:

> Therefore, I suggest the following draft of a patch, that mostly reverts
> commit splitting `org-insert-property-drawer' and makes
> `org-insert-drawer' more user friendly. It provides the following
> facilities:
>
>   - headline inclusion check,
>   - drawer insertion without requiring an headline above,
>   - skip trailing blank lines (i.e. to wrap buffer around a just marked
>     paragraph),
>   - Ignore system drawer's names in completion list.
>
> What do you think?

I think it's good -- thanks for the patch.  I just pushed a slightly
modified version of it, adding `C-c C-x d' as a keybinding for
`org-insert-drawer', and adding the possibility to call
`org-insert-property-drawer' from `org-insert-drawer' directly using a
prefix argument.  I agree special drawers should not be offered in the
completion table, but it's still using to be able to quickly insert
a property drawer, especially in combination with property completion.

Anyway, I think we moved in the right direction.

Thanks again!

-- 
 Bastien

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2012-01-26  8:27 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-25  0:46 How do I create a drawer? Nick Dokos
2012-01-25  8:29 ` Olaf Dietsche
2012-01-25 14:25   ` Bastien
2012-01-25  8:44 ` Russell Adams
2012-01-25  9:03 ` Bastien
2012-01-25  9:17   ` Rainer M Krug
2012-01-25 13:16   ` Carsten Dominik
2012-01-25 13:29     ` Nicolas Goaziou
2012-01-25 14:09       ` Carsten Dominik
2012-01-25 14:17         ` Nicolas Goaziou
2012-01-25 14:27           ` Bastien
2012-01-25 16:33             ` Nicolas Goaziou
2012-01-26  8:28               ` Bastien
2012-01-25 14:26     ` Bastien
2012-01-25 14:34       ` Nick Dokos
2012-01-26  1:46         ` François Pinard

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).