emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* how to add some features in a newly added headline?
@ 2016-01-16 13:14 Bingo UV
  2016-01-16 13:59 ` John Kitchin
  0 siblings, 1 reply; 3+ messages in thread
From: Bingo UV @ 2016-01-16 13:14 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

   When I create a new headline, I want a set of features in it:
1. The ID property in the properties drawer
2. The properties drawer should be collapsed
3. An inactive timestamp at the beginning of text
4. Cursor at the beginning of heading

Currently, I have a hook for org-insert-heading-hook, after learning
and experimenting with emacs lisp for a while, but it has serious
problems:

(add-hook 'org-insert-heading-hook
      '(lambda()
         (org-id-get-create) ;-> Adds ID property
         (insert-char 48) ;-> required for next 2 org-cycles to collapse the properties drawer
         (org-cycle)
         (org-cycle)
         (save-excursion ;-> add time stamp
           (org-end-of-meta-data t)
           (org-time-stamp-inactive '(16))
           (newline)
           )
         )
      )

This makes org-insert-heading create an entry like the following:

* 0 -> cursur after this 0
:PROPERTIES:
[2016-01-16 Sat 08:40]

Most of the problems stem from the insert-char. First of all, it enters a useless "0" character
which I have to manually remove by backspace. Secondly, when I read from mobile-org, it converts
TODO into 0TODO, which is to say it converts useful into useless. But I cannot live without it
because without this 0, org-cycle doesn't collapse the entry but instead, indents the subtree.

Can someone show a simple way to achieve the 4 features automatically in a new entry? I used
to strongly feel it should be very easy, but I am at my wits' end now.

thanks a lot

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

* Re: how to add some features in a newly added headline?
  2016-01-16 13:14 how to add some features in a newly added headline? Bingo UV
@ 2016-01-16 13:59 ` John Kitchin
  2016-01-16 17:18   ` Bingo UV
  0 siblings, 1 reply; 3+ messages in thread
From: John Kitchin @ 2016-01-16 13:59 UTC (permalink / raw)
  To: Bingo UV; +Cc: emacs-orgmode@gnu.org

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

I would define a function for this, so you can call it only when you want.
this does what you describe for me (org 8.2.10)

(defun my-heading ()
  (interactive)
  (org-insert-heading)
  (org-id-get-create)

  (save-excursion ;-> add time stamp
    (org-end-of-meta-data-and-drawers)
    (newline)
    (org-time-stamp-inactive '(16))))



On Sat, Jan 16, 2016 at 8:14 AM, Bingo UV <right.ho@gmail.com> wrote:

> (add-hook 'org-insert-heading-hook
>       '(lambda()
>          (org-id-get-create) ;-> Adds ID property
>          (insert-char 48) ;-> required for next 2 org-cycles to collapse
> the properties drawer
>          (org-cycle)
>          (org-cycle)
>          (save-excursion ;-> add time stamp
>            (org-end-of-meta-data t)
>            (org-time-stamp-inactive '(16))
>            (newline)
>            )
>          )
>       )
>



John

-----------------------------------
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

[-- Attachment #2: Type: text/html, Size: 2342 bytes --]

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

* Re: how to add some features in a newly added headline?
  2016-01-16 13:59 ` John Kitchin
@ 2016-01-16 17:18   ` Bingo UV
  0 siblings, 0 replies; 3+ messages in thread
From: Bingo UV @ 2016-01-16 17:18 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

Hi John,
   Thanks a lot. 

In org 8.3, there seems to be no org-end-of-meta-data-and-drawers. If I
replace it with org-end-of-meta-data, I get a PROPERTIES drawer which
is open, not collapsed. Since it is a new heading, it should have no
 drawers, so I am guessing org-end-of-meta-data-and-drawers and
org-end-of-meta-data should be identical?


I don't want to sound too demanding about a collapsed PROPERTIES
drawer but it is so distracting I cannot stop myself from compulsively
collapsing it after adding every heading. Which is when I added the
insert-char and 2 org-cycles.


(sorry, meant to reply to mailing list, not personally)


On Sat, 16 Jan 2016 08:59:17 -0500
John Kitchin <jkitchin@andrew.cmu.edu> wrote:

> I would define a function for this, so you can call it only when you
> want. this does what you describe for me (org 8.2.10)
> 
> (defun my-heading ()
>   (interactive)
>   (org-insert-heading)
>   (org-id-get-create)
> 
>   (save-excursion ;-> add time stamp
>     (org-end-of-meta-data-and-drawers)
>     (newline)
>     (org-time-stamp-inactive '(16))))
> 
> 
> 
> On Sat, Jan 16, 2016 at 8:14 AM, Bingo UV <right.ho@gmail.com> wrote:
> 
> > (add-hook 'org-insert-heading-hook
> >       '(lambda()
> >          (org-id-get-create) ;-> Adds ID property
> >          (insert-char 48) ;-> required for next 2 org-cycles to
> > collapse the properties drawer
> >          (org-cycle)
> >          (org-cycle)
> >          (save-excursion ;-> add time stamp
> >            (org-end-of-meta-data t)
> >            (org-time-stamp-inactive '(16))
> >            (newline)
> >            )
> >          )
> >       )
> >
> 
> 
> 
> John
> 
> -----------------------------------
> Professor John Kitchin
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu

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

end of thread, other threads:[~2016-01-16 17:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-16 13:14 how to add some features in a newly added headline? Bingo UV
2016-01-16 13:59 ` John Kitchin
2016-01-16 17:18   ` Bingo UV

Code repositories for project(s) associated with this public 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).