2

(Environment: Emacs 24.4 stable with built-in org-mode.)

I want to have a file+datetree for Org-mode's Capture, so I set like this:

(setq org-capture-templates
      '(("D" "Diary + Timer" entry
         (file+datetree (concat org-directory "/diary/diary.org"))
         "* %^{Description: } %^g  \n  %i %?\n" :clock-in t :clock-keep t)
        ("d" "Diary" entry
         (file+datetree (concat org-directory "/diary/diary.org"))
         "* %? %U")
        ))

And use these captures to add items for diary.org several times. I expect the file has:

* 2014   
** 2014-11 11 月
*** 2014-11-21 金曜日
**** test1 [2014-11-21 金 03:08]
**** test2 [2014-11-21 金 03:08]
**** test3 [2014-11-21 金 03:08]

But what I get is like this:

* 2014
** 2014-11 11 月
*** 2014-11-21 金曜日
**** test1 [2014-11-21 金 03:08]
** 2014-11 11 月
*** 2014-11-21 金曜日
**** test2 [2014-11-21 金 03:09]
** 2014-11 11 月
*** 2014-11-21 金曜日
**** test3 [2014-11-21 金 03:09]

How to solve this problem...? (I've ever used Org's Capture one year ago, and it worked just liked I wish; I have no idea why it becomes this.)


[Edited] Finally, totally out of expect, the problem is resulted from Pangu-Spacing.... https://github.com/coldnew/pangu-spacing/issues/5

  • Maybe the regexp org is using to find an existing line is failing to match for some reason? Does a regexp search work for e.g. "^\\*+[ ]+2014-\\([01][0-9]\\) \\w+$" (which I derived to match month headers from org-datetree.el). – glucas Nov 20 '14 at 20:09
  • Seems it will not match because your month line has an extra 'word'. Looking at the org source I don't quite see why you're getting "2014-11 11 ..." on the month line, but that will never be matched so a new month line will always get added. – glucas Nov 20 '14 at 20:18
  • With your config, my month line is created as ** 2014-11 November, which matches the regexp above. So the issue seems to be the month name being formatted to 11 月. – glucas Nov 20 '14 at 20:20
  • I doesn't touch any language-related settings within Emacs; the time string format is from system. (By the way, in somehow elder version Org-mode 8.x, this function seemed to be able to work correctly, because I just found some my old diary archives.) – kuanyui Nov 20 '14 at 20:30
4

The problem seems to be a mismatch with how org-datetree is creating the month line and the regexp it uses when you create a second entry for the same month.

On my machine (with my locale etc) the current month line is generated as:

** 2014-11 November

Org is using a regular expression like this one to match the line when I create a new entry:

"^\\*+[     ]+2014-\\([01][0-9]\\) \\w+$"

This matches properly for me. In your example, it looks like the month name is written as two "words" rather than one:

** 2014-11 11 月

Therefore the regular expression will never match, and org-datetree will create a new month line every time.

Org-datetree is generating the month name using:

(format " %s" 
    (format-time-string
     "%B" (encode-time 0 0 0 1 11 2014)))

where %B means to use the current locale's full name for the month. Not matching your locale's default representation of the month seems like a bug in Org mode.

To work around it you either need to figure out how to change that locale representation, or perhaps hack your org-datetree.el to fix the regexp to match an additional word (in org-datetree-find-month-create, e.g. \\w+ \\w+$). You might also be able to use 'after' advice on org-datetree-insert-line to revise the month line after it is written.

  • Well, maybe it's time to report bug to Org-devel... :S – kuanyui Nov 20 '14 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.