[O] [PATCH v3 3/3] org-capture.el: Add support for week trees.
* lisp/org-capture.el (org-capture-templates): Add file+weektree(+prompt) options. (org-capture-set-target-location): Add support for week trees. * doc/org.texi (Template elements): Document file+weektree(+prompt) options. --- doc/org.texi| 7 +++ etc/ORG-NEWS| 13 + lisp/org-capture.el | 26 +- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index 8f3e248..dfa989a 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -7176,6 +7176,13 @@ @item (file+datetree+prompt "path/to/file") Will create a heading in a date tree, but will prompt for the date. +@item (file+weektree "path/to/file") +Will create a heading in a week tree for today's date. Week trees are sorted +by week and not by month unlike datetrees. + +@item (file+weektree+prompt "path/to/file") +Will create a heading in a week tree, but will prompt for the date. + @item (file+function "path/to/file" function-finding-location) A function to find the right location in the file. diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 4ab48c4..b56add3 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -167,6 +167,19 @@ for details. *** org-bbdb-anniversaries-future Used like org-bbdb-anniversaries, it provides a few days warning for upcoming anniversaries (default: 7 days). +*** Support for ISO week trees +ISO week trees are an alternative date tree format that orders entries +by ISO week and not by month. + +For example: + +: * 2015 +: ** 2015-W35 +: ** 2015-W36 +: *** 2015-08-31 Monday + +They are supported in org-capture via ~file+weektree~ and +~file+weektree+prompt~ target specifications. ** New functions *** ~org-show-children~ It is a faster implementation of ~outline-show-children~. diff --git a/lisp/org-capture.el b/lisp/org-capture.el index f92ea35..13cbe9b 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -151,6 +151,12 @@ (defcustom org-capture-templates nil (file+datetree+prompt \"path/to/file\") Will create a heading in a date tree, prompts for date + (file+weektree \"path/to/file\") + Will create a heading in a week tree for today's date + + (file+weektree+prompt \"path/to/file\") + Will create a heading in a week tree, prompts for date + (file+function \"path/to/file\" function-finding-location) A function to find the right location in the file @@ -331,6 +337,12 @@ (defcustom org-capture-templates nil (list :tag "File & Date tree, prompt for date" (const :format "" file+datetree+prompt) (file :tag " File")) + (list :tag "File & Week tree" + (const :format "" file+weektree) + (file :tag " File")) + (list :tag "File & Week tree, prompt for date" + (const :format "" file+weektree+prompt) + (file :tag " File")) (list :tag "File & function" (const :format "" file+function) (file :tag " File") @@ -908,21 +920,25 @@ (defun org-capture-set-target-location ( target) (setq target-entry-p (and (derived-mode-p 'org-mode) (org-at-heading-p (error "No match for target regexp in file %s" (nth 1 target - ((memq (car target) '(file+datetree file+datetree+prompt)) + ((memq (car target) '(file+datetree file+datetree+prompt file+weektree file+weektree+prompt)) (require 'org-datetree) (set-buffer (org-capture-target-buffer (nth 1 target))) (org-capture-put-target-region-and-position) (widen) - ;; Make a date tree entry, with the current date (or yesterday, - ;; if we are extending dates for a couple of hours) - (org-datetree-find-date-create + ;; Make a date/week tree entry, with the current date (or + ;; yesterday, if we are extending dates for a couple of hours) + (funcall +(cond + ((memq (car target) '(file+weektree file+weektree+prompt)) + #'org-datetree-find-iso-week-create) + (t #'org-datetree-find-date-create)) (calendar-gregorian-from-absolute (cond (org-overriding-default-time ;; use the overriding default time (time-to-days org-overriding-default-time)) - ((eq (car target) 'file+datetree+prompt) + ((memq (car target) '(file+datetree+prompt file+weektree+prompt)) ;; prompt for date (let ((prompt-time (org-read-date nil t nil "Date for tree entry:" -- 2.6.4
[O] [PATCH v3 1/3] org-datetree.el: Code cleanup.
* lisp/org-datetree.el (org-datetree--find-create): New function. (org-datetree-find-year-create, org-datetree-find-month-create, org-datetree-find-day-create): Removed functions (org-datetree-find-date-create): Use `org-datetree--find-create' instead of removed functions. Use calendar extract functions. (org-datetree-insert-line): Do more formatting in `format-time-string' since we call it anyway * testing/lisp/test-org-datetree.el (test-org-datetree/find-date-create): Test if new entries are put at the right place. --- lisp/org-datetree.el | 90 +-- testing/lisp/test-org-datetree.el | 9 2 files changed, 38 insertions(+), 61 deletions(-) diff --git a/lisp/org-datetree.el b/lisp/org-datetree.el index 6c4a410..2c9ffdf 100644 --- a/lisp/org-datetree.el +++ b/lisp/org-datetree.el @@ -64,70 +64,42 @@ (defun org-datetree-find-date-create (date keep-restriction) (org-get-valid-level (org-current-level) 1)) (org-narrow-to-subtree))) (goto-char (point-min)) -(let ((year (nth 2 date)) - (month (car date)) - (day (nth 1 date))) - (org-datetree-find-year-create year) - (org-datetree-find-month-create year month) - (org-datetree-find-day-create year month day - -(defun org-datetree-find-year-create (year) - "Find the YEAR datetree or create it." - (let ((re "^\\*+[ \t]+\\([12][0-9]\\{3\\}\\)\\(\\s-*?\\([ \t]:[[:alnum:]:_@#%]+:\\)?\\s-*$\\)") +(let ((year (calendar-extract-year date)) + (month (calendar-extract-month date)) + (day (calendar-extract-day date))) + (org-datetree--find-create + "^\\*+[ \t]+\\([12][0-9]\\{3\\}\\)\\(\\s-*?\ +\\([ \t]:[[:alnum:]:_@#%%]+:\\)?\\s-*$\\)" + year) + (org-datetree--find-create + "^\\*+[ \t]+%d-\\([01][0-9]\\) \\w+$" + year month) + (org-datetree--find-create + "^\\*+[ \t]+%d-%02d-\\([0123][0-9]\\) \\w+$" + year month day + +(defun org-datetree--find-create (regex year month day) + "Find the datetree matched by REGEX for YEAR, MONTH, or DAY. +REGEX is passed to `format' with YEAR, MONTH, and DAY as +arguments. Match group 1 is compared against the specified date +component." + (when (or month day) +(org-narrow-to-subtree)) + (let ((re (format regex year month day)) match) (goto-char (point-min)) (while (and (setq match (re-search-forward re nil t)) (goto-char (match-beginning 1)) - (< (string-to-number (match-string 1)) year))) + (< (string-to-number (match-string 1)) (or day month year (cond ((not match) (goto-char (point-max)) - (or (bolp) (newline)) - (org-datetree-insert-line year)) - ((= (string-to-number (match-string 1)) year) - (goto-char (point-at-bol))) - (t - (beginning-of-line 1) - (org-datetree-insert-line year) - -(defun org-datetree-find-month-create (year month) - "Find the datetree for YEAR and MONTH or create it." - (org-narrow-to-subtree) - (let ((re (format "^\\*+[ \t]+%d-\\([01][0-9]\\) \\w+$" year)) - match) -(goto-char (point-min)) -(while (and (setq match (re-search-forward re nil t)) - (goto-char (match-beginning 1)) - (< (string-to-number (match-string 1)) month))) -(cond - ((not match) - (goto-char (point-max)) - (or (bolp) (newline)) - (org-datetree-insert-line year month)) - ((= (string-to-number (match-string 1)) month) - (goto-char (point-at-bol))) - (t - (beginning-of-line 1) - (org-datetree-insert-line year month) - -(defun org-datetree-find-day-create (year month day) - "Find the datetree for YEAR, MONTH and DAY or create it." - (org-narrow-to-subtree) - (let ((re (format "^\\*+[ \t]+%d-%02d-\\([0123][0-9]\\) \\w+$" year month)) - match) -(goto-char (point-min)) -(while (and (setq match (re-search-forward re nil t)) - (goto-char (match-beginning 1)) - (< (string-to-number (match-string 1)) day))) -(cond - ((not match) - (goto-char (point-max)) - (or (bolp) (newline)) + (unless (bolp) (insert "\n")) (org-datetree-insert-line year month day)) - ((= (string-to-number (match-string 1)) day) - (goto-char (point-at-bol))) + ((= (string-to-number (match-string 1)) (or day month year)) + (beginning-of-line)) (t - (beginning-of-line 1) + (beginning-of-line) (org-datetree-insert-line year month day) (defun org-datetree-insert-line (year month day) @@ -139,13 +111,9 @@ (defun org-datetree-insert-line (year month day) (insert (format "%d" year)) (when month (insert - (format "-%02d" month) (if day -(format "-%02d %s" -day -(format-time-string "%A" (encode-time 0 0 0 day month year))) - (format " %s" - (format-time-string "%B"
[O] [PATCH v3 2/3] org-datetree.el: Add support for ISO week trees.
* lisp/org-datetree.el (org-datetree-find-iso-date-create): New function. (org-datetree--find-create): Support fixed text for insert. (org-datetree-insert-line): Support fixed text for insert. * testing/lisp/test-org-datetree.el (test-org-datetree/find-iso-date-create): New test. ISO week trees order dates by week and not by month. --- lisp/org-datetree.el | 75 +-- testing/lisp/test-org-datetree.el | 92 +++ 2 files changed, 153 insertions(+), 14 deletions(-) diff --git a/lisp/org-datetree.el b/lisp/org-datetree.el index 2c9ffdf..5d52756 100644 --- a/lisp/org-datetree.el +++ b/lisp/org-datetree.el @@ -34,9 +34,10 @@ (require 'org) (defvar org-datetree-base-level 1 "The level at which years should be placed in the date tree. -This is normally one, but if the buffer has an entry with a DATE_TREE -property (any value), the date tree will become a subtree under that entry, -so the base level will be properly adjusted.") +This is normally one, but if the buffer has an entry with a +DATE_TREE (or WEEK_TREE for ISO week entries) property (any +value), the date tree will become a subtree under that entry, so +the base level will be properly adjusted.") (defcustom org-datetree-add-timestamp nil "When non-nil, add a time stamp matching date of entry. @@ -78,11 +79,55 @@ (defun org-datetree-find-date-create (date keep-restriction) "^\\*+[ \t]+%d-%02d-\\([0123][0-9]\\) \\w+$" year month day -(defun org-datetree--find-create (regex year month day) +;;;###autoload +(defun org-datetree-find-iso-week-create (date keep-restriction) + "Find or create an ISO week entry for DATE. +Compared to `org-datetree-find-date-create' this function creates +entries ordered by week instead of months. +If KEEP-RESTRICTION is non-nil, do not widen the buffer. When it +is nil, the buffer will be widened to make sure an existing date +tree can be found." + (org-set-local 'org-datetree-base-level 1) + (or keep-restriction (widen)) + (save-restriction +(let ((prop (org-find-property "WEEK_TREE"))) + (when prop + (goto-char prop) + (org-set-local 'org-datetree-base-level + (org-get-valid-level (org-current-level) 1)) + (org-narrow-to-subtree))) +(goto-char (point-min)) +(require 'cal-iso) +(let* ((year (calendar-extract-year date)) + (month (calendar-extract-month date)) + (day (calendar-extract-day date)) + (time (encode-time 0 0 0 day month year)) + (iso-date (calendar-iso-from-absolute + (calendar-absolute-from-gregorian date))) + (weekyear (nth 2 iso-date)) + (week (nth 0 iso-date)) + (weekday (nth 1 iso-date))) + ;; ISO 8601 week format is %G-W%V(-%u) + (org-datetree--find-create + "^\\*+[ \t]+\\([12][0-9]\\{3\\}\\)\\(\\s-*?\ +\\([ \t]:[[:alnum:]:_@#%%]+:\\)?\\s-*$\\)" + weekyear nil nil + (format-time-string "%G" time)) + (org-datetree--find-create + "^\\*+[ \t]+%d-W\\([0-5][0-9]\\)$" + weekyear week nil + (format-time-string "%G-W%V" time)) + ;; For the actual day we use the regular date instead of ISO week. + (org-datetree--find-create + "^\\*+[ \t]+%d-%02d-\\([0123][0-9]\\) \\w+$" + year month day + +(defun org-datetree--find-create (regex year month day insert) "Find the datetree matched by REGEX for YEAR, MONTH, or DAY. REGEX is passed to `format' with YEAR, MONTH, and DAY as arguments. Match group 1 is compared against the specified date -component." +component. If INSERT is non-nil and there is no match then it is +inserted into the buffer." (when (or month day) (org-narrow-to-subtree)) (let ((re (format regex year month day)) @@ -95,25 +140,27 @@ (defun org-datetree--find-create (regex year month day) ((not match) (goto-char (point-max)) (unless (bolp) (insert "\n")) - (org-datetree-insert-line year month day)) + (org-datetree-insert-line year month day insert)) ((= (string-to-number (match-string 1)) (or day month year)) (beginning-of-line)) (t (beginning-of-line) - (org-datetree-insert-line year month day) + (org-datetree-insert-line year month day insert) -(defun org-datetree-insert-line (year month day) +(defun org-datetree-insert-line (year month day text) (delete-region (save-excursion (skip-chars-backward " \t\n") (point)) (point)) (insert "\n" (make-string org-datetree-base-level ?*) " \n") (backward-char) (when month (org-do-demote)) (when day (org-do-demote)) - (insert (format "%d" year)) - (when month -(insert - (if day -(format-time-string "-%m-%d %A" (encode-time 0 0 0 day month year)) - (format-time-string "-%m %B" (encode-time 0 0 0 1 month year) + (if text + (insert text) +(insert (format "%d" year)) +(when month +
[O] [PATCH v2 3/3] org-capture.el: Add support for week trees.
* lisp/org-capture.el (org-capture-templates): Add file+weektree(+prompt) options. (org-capture-set-target-location): Add support for week trees. * doc/org.texi (Template elements): Document file+weektree(+prompt) options. --- doc/org.texi| 7 +++ lisp/org-capture.el | 26 +- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index ed808be..d894f91 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -7187,6 +7187,13 @@ @item (file+datetree+prompt "path/to/file") Will create a heading in a date tree, but will prompt for the date. +@item (file+weektree "path/to/file") +Will create a heading in a week tree for today's date. Week trees are sorted +by week and not by month unlike datetrees. + +@item (file+weektree+prompt "path/to/file") +Will create a heading in a week tree, but will prompt for the date. + @item (file+function "path/to/file" function-finding-location) A function to find the right location in the file. diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 93a7f2a..320954e 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -149,6 +149,12 @@ (defcustom org-capture-templates nil (file+datetree+prompt \"path/to/file\") Will create a heading in a date tree, prompts for date + (file+weektree \"path/to/file\") + Will create a heading in a week tree for today's date + + (file+weektree+prompt \"path/to/file\") + Will create a heading in a week tree, prompts for date + (file+function \"path/to/file\" function-finding-location) A function to find the right location in the file @@ -321,6 +327,12 @@ (defcustom org-capture-templates nil (list :tag "File & Date tree, prompt for date" (const :format "" file+datetree+prompt) (file :tag " File")) + (list :tag "File & Week tree" + (const :format "" file+weektree) + (file :tag " File")) + (list :tag "File & Week tree, prompt for date" + (const :format "" file+weektree+prompt) + (file :tag " File")) (list :tag "File & function" (const :format "" file+function) (file :tag " File") @@ -895,21 +907,25 @@ (defun org-capture-set-target-location ( target) (setq target-entry-p (and (derived-mode-p 'org-mode) (org-at-heading-p (error "No match for target regexp in file %s" (nth 1 target - ((memq (car target) '(file+datetree file+datetree+prompt)) + ((memq (car target) '(file+datetree file+datetree+prompt file+weektree file+weektree+prompt)) (require 'org-datetree) (set-buffer (org-capture-target-buffer (nth 1 target))) (org-capture-put-target-region-and-position) (widen) - ;; Make a date tree entry, with the current date (or yesterday, - ;; if we are extending dates for a couple of hours) - (org-datetree-find-date-create + ;; Make a date/week tree entry, with the current date (or + ;; yesterday, if we are extending dates for a couple of hours) + (funcall +(cond + ((memq (car target) '(file+weektree file+weektree+prompt)) + #'org-datetree-find-iso-week-create) + (t #'org-datetree-find-date-create)) (calendar-gregorian-from-absolute (cond (org-overriding-default-time ;; use the overriding default time (time-to-days org-overriding-default-time)) - ((eq (car target) 'file+datetree+prompt) + ((memq (car target) '(file+datetree+prompt file+weektree+prompt)) ;; prompt for date (let ((prompt-time (org-read-date nil t nil "Date for tree entry:" -- 2.5.1
Re: [O] [PATCH 2/3] org-datetree.el: Add support for ISO week trees.
On Thursday 03 September 2015 07:55:08 Nicolas Goaziou wrote: > Rüdiger Sonderfeld <ruedi...@c-plusplus.de> writes: > > On Wednesday 02 September 2015 21:58:17 Nicolas Goaziou wrote: > >> Rüdiger Sonderfeld <ruedi...@c-plusplus.net> writes: > >> > +(let ((prop (org-find-property "DATE_WEEK_TREE"))) > >> > >> I don't think we need to introduce a new property for that. DATE_TREE is > >> enough. > > > > Since DATE_TREE and DATE_WEEK_TREE (or WEEK_TREE instead?) are structured > > differently it might make sense to keep the property separated. > > If you want both a date tree and a week tree in the same, you probably > want them to start at the same level, don't you? I don't think that's necessarily true since both formats don't mix well. If anyone still wants it then they can simply add both properties. I've send updated versions of the patches as a reply to this message. Regards, Rüdiger
[O] [PATCH v2 2/3] org-datetree.el: Add support for ISO week trees.
* lisp/org-datetree.el (org-datetree-find-iso-date-create): New function. (org-datetree--find-create): Support fixed text for insert. (org-datetree-insert-line): Support fixed text for insert. * testing/lisp/test-org-datetree.el (test-org-datetree/find-iso-date-create): New test. ISO week trees order dates by week and not by month. --- lisp/org-datetree.el | 68 - testing/lisp/test-org-datetree.el | 92 +++ 2 files changed, 149 insertions(+), 11 deletions(-) diff --git a/lisp/org-datetree.el b/lisp/org-datetree.el index ea7afe7..1c24927 100644 --- a/lisp/org-datetree.el +++ b/lisp/org-datetree.el @@ -78,11 +78,55 @@ (defun org-datetree-find-date-create (date keep-restriction) "^\\*+[ \t]+%d-%02d-\\([0123][0-9]\\) \\w+$" year month day -(defun org-datetree--find-create (regex year month day) +;;;###autoload +(defun org-datetree-find-iso-week-create (date keep-restriction) + "Find or create an ISO week entry for DATE. +Compared to `org-datetree-find-date-create' this function creates +entries ordered by week instead of months. +If KEEP-RESTRICTION is non-nil, do not widen the buffer. When it +is nil, the buffer will be widened to make sure an existing date +tree can be found." + (org-set-local 'org-datetree-base-level 1) + (or keep-restriction (widen)) + (save-restriction +(let ((prop (org-find-property "WEEK_TREE"))) + (when prop + (goto-char prop) + (org-set-local 'org-datetree-base-level + (org-get-valid-level (org-current-level) 1)) + (org-narrow-to-subtree))) +(goto-char (point-min)) +(require 'cal-iso) +(let* ((year (calendar-extract-year date)) + (month (calendar-extract-month date)) + (day (calendar-extract-day date)) + (time (encode-time 0 0 0 day month year)) + (iso-date (calendar-iso-from-absolute + (calendar-absolute-from-gregorian date))) + (weekyear (nth 2 iso-date)) + (week (nth 0 iso-date)) + (weekday (nth 1 iso-date))) + ;; ISO 8601 week format is %G-W%V(-%u) + (org-datetree--find-create + "^\\*+[ \t]+\\([12][0-9]\\{3\\}\\)\\(\\s-*?\ +\\([ \t]:[[:alnum:]:_@#%%]+:\\)?\\s-*$\\)" + weekyear nil nil + (format-time-string "%G" time)) + (org-datetree--find-create + "^\\*+[ \t]+%d-W\\([0-5][0-9]\\)$" + weekyear week nil + (format-time-string "%G-W%V" time)) + ;; For the actual day we use the regular date instead of ISO week. + (org-datetree--find-create + "^\\*+[ \t]+%d-%02d-\\([0123][0-9]\\) \\w+$" + year month day + +(defun org-datetree--find-create (regex year month day insert) "Find the datetree matched by REGEX for YEAR, MONTH, or DAY. REGEX is passed to `format' with YEAR, MONTH, and DAY as arguments. Match group 1 is compared against the specified date -component." +component. If INSERT is non-nil and there is no match then it is +inserted into the buffer." (when (or month day) (org-narrow-to-subtree)) (let ((re (format regex year month day)) @@ -95,25 +139,27 @@ (defun org-datetree--find-create (regex year month day) ((not match) (goto-char (point-max)) (unless (bolp) (insert "\n")) - (org-datetree-insert-line year month day)) + (org-datetree-insert-line year month day insert)) ((= (string-to-number (match-string 1)) (or day month year)) (beginning-of-line)) (t (beginning-of-line) - (org-datetree-insert-line year month day) + (org-datetree-insert-line year month day insert) -(defun org-datetree-insert-line (year month day) +(defun org-datetree-insert-line (year month day text) (delete-region (save-excursion (skip-chars-backward " \t\n") (point)) (point)) (insert "\n" (make-string org-datetree-base-level ?*) " \n") (backward-char) (when month (org-do-demote)) (when day (org-do-demote)) - (insert (format "%d" year)) - (when month -(insert - (if day -(format-time-string "-%m-%d %A" (encode-time 0 0 0 day month year)) - (format-time-string "-%m %B" (encode-time 0 0 0 1 month year) + (if text + (insert text) +(insert (format "%d" year)) +(when month + (insert + (if day + (format-time-string "-%m-%d %A" (encode-time 0 0 0 day month year)) +(format-time-string "-%m %B" (encode-time 0 0 0 1 month year)) (when (and day org-datetree-add-timestamp) (save-excursion (insert "\n") diff --git a/testing/lisp/test-org-datetree.el b/testing/lisp/test-org-datetree.el index bbc8e14..dab54ba 100644 --- a/testing/lisp/test-org-datetree.el +++ b/testing/lisp/test-org-datetree.el @@ -113,5 +113,97 @@ (ert-deftest test-org-datetree/find-date-create () (org-datetree-find-date-create '(3 29 2012))) (buffer-substring (point) (line-end-position)) +(ert-deftest
[O] [PATCH v2 1/3] org-datetree.el: Code cleanup.
* lisp/org-datetree.el (org-datetree--find-create): New function. (org-datetree-find-year-create, org-datetree-find-month-create, org-datetree-find-day-create): Removed functions (org-datetree-find-date-create): Use `org-datetree--find-create' instead of removed functions. Use calendar extract functions. (org-datetree-insert-line): Do more formatting in `format-time-string' since we call it anyway * testing/lisp/test-org-datetree.el (test-org-datetree/find-date-create): Test if new entries are put at the right place. --- lisp/org-datetree.el | 90 +-- testing/lisp/test-org-datetree.el | 9 2 files changed, 38 insertions(+), 61 deletions(-) diff --git a/lisp/org-datetree.el b/lisp/org-datetree.el index a97a9d0..ea7afe7 100644 --- a/lisp/org-datetree.el +++ b/lisp/org-datetree.el @@ -64,70 +64,42 @@ (defun org-datetree-find-date-create (date keep-restriction) (org-get-valid-level (org-current-level) 1)) (org-narrow-to-subtree))) (goto-char (point-min)) -(let ((year (nth 2 date)) - (month (car date)) - (day (nth 1 date))) - (org-datetree-find-year-create year) - (org-datetree-find-month-create year month) - (org-datetree-find-day-create year month day - -(defun org-datetree-find-year-create (year) - "Find the YEAR datetree or create it." - (let ((re "^\\*+[ \t]+\\([12][0-9]\\{3\\}\\)\\(\\s-*?\\([ \t]:[[:alnum:]:_@#%]+:\\)?\\s-*$\\)") +(let ((year (calendar-extract-year date)) + (month (calendar-extract-month date)) + (day (calendar-extract-day date))) + (org-datetree--find-create + "^\\*+[ \t]+\\([12][0-9]\\{3\\}\\)\\(\\s-*?\ +\\([ \t]:[[:alnum:]:_@#%%]+:\\)?\\s-*$\\)" + year) + (org-datetree--find-create + "^\\*+[ \t]+%d-\\([01][0-9]\\) \\w+$" + year month) + (org-datetree--find-create + "^\\*+[ \t]+%d-%02d-\\([0123][0-9]\\) \\w+$" + year month day + +(defun org-datetree--find-create (regex year month day) + "Find the datetree matched by REGEX for YEAR, MONTH, or DAY. +REGEX is passed to `format' with YEAR, MONTH, and DAY as +arguments. Match group 1 is compared against the specified date +component." + (when (or month day) +(org-narrow-to-subtree)) + (let ((re (format regex year month day)) match) (goto-char (point-min)) (while (and (setq match (re-search-forward re nil t)) (goto-char (match-beginning 1)) - (< (string-to-number (match-string 1)) year))) + (< (string-to-number (match-string 1)) (or day month year (cond ((not match) (goto-char (point-max)) - (or (bolp) (newline)) - (org-datetree-insert-line year)) - ((= (string-to-number (match-string 1)) year) - (goto-char (point-at-bol))) - (t - (beginning-of-line 1) - (org-datetree-insert-line year) - -(defun org-datetree-find-month-create (year month) - "Find the datetree for YEAR and MONTH or create it." - (org-narrow-to-subtree) - (let ((re (format "^\\*+[ \t]+%d-\\([01][0-9]\\) \\w+$" year)) - match) -(goto-char (point-min)) -(while (and (setq match (re-search-forward re nil t)) - (goto-char (match-beginning 1)) - (< (string-to-number (match-string 1)) month))) -(cond - ((not match) - (goto-char (point-max)) - (or (bolp) (newline)) - (org-datetree-insert-line year month)) - ((= (string-to-number (match-string 1)) month) - (goto-char (point-at-bol))) - (t - (beginning-of-line 1) - (org-datetree-insert-line year month) - -(defun org-datetree-find-day-create (year month day) - "Find the datetree for YEAR, MONTH and DAY or create it." - (org-narrow-to-subtree) - (let ((re (format "^\\*+[ \t]+%d-%02d-\\([0123][0-9]\\) \\w+$" year month)) - match) -(goto-char (point-min)) -(while (and (setq match (re-search-forward re nil t)) - (goto-char (match-beginning 1)) - (< (string-to-number (match-string 1)) day))) -(cond - ((not match) - (goto-char (point-max)) - (or (bolp) (newline)) + (unless (bolp) (insert "\n")) (org-datetree-insert-line year month day)) - ((= (string-to-number (match-string 1)) day) - (goto-char (point-at-bol))) + ((= (string-to-number (match-string 1)) (or day month year)) + (beginning-of-line)) (t - (beginning-of-line 1) + (beginning-of-line) (org-datetree-insert-line year month day) (defun org-datetree-insert-line (year month day) @@ -139,13 +111,9 @@ (defun org-datetree-insert-line (year month day) (insert (format "%d" year)) (when month (insert - (format "-%02d" month) (if day -(format "-%02d %s" -day -(format-time-string "%A" (encode-time 0 0 0 day month year))) - (format " %s" - (format-time-string "%B"
Re: [O] ob-csharp
On Monday 07 September 2015 15:10:59 Grant Rettke wrote: > On Mon, Sep 7, 2015 at 2:28 PM, Thomas S. Dyewrote: > > It can live in core, contrib, or as an emacs package. > > When it lives in core, it is available to everyone who downloads > Emacs. That is valuable because some users never install a single > package. But it requires csharp-mode, which is not part of GNU Emacs. Regards, Rüdiger
[O] [PATCH 0/3] Support week trees in datetree/capture
Hello, this series of patches adds support for ISO week trees in org-datetree and subsequently in org-capture. Week trees differ from regular date trees because they are ordered by week and not by month. Example * 2015 ** 2015-W35 ** 2015-W36 *** 2015-08-31 Monday (I did try to send those patches on Monday. But it appears they were lost) Cheers, Rüdiger Rüdiger Sonderfeld (3): org-datetree.el: Code cleanup. org-datetree.el: Add support for ISO week trees. org-capture.el: Add support for week trees. doc/org.texi | 7 +++ lisp/org-capture.el | 26 ++-- lisp/org-datetree.el | 129 +++--- testing/lisp/test-org-datetree.el | 101 + 4 files changed, 194 insertions(+), 69 deletions(-) -- 2.5.1
[O] [PATCH 1/3] org-datetree.el: Code cleanup.
* lisp/org-datetree.el (org-datetree--find-create): New function. (org-datetree-find-year-create, org-datetree-find-month-create, org-datetree-find-day-create): Removed functions (org-datetree-find-date-create): Use `org-datetree--find-create' instead of removed functions. Use calendar extract functions. (org-datetree-insert-line): Do more formatting in `format-time-string' since we call it anyway * testing/lisp/test-org-datetree.el (test-org-datetree/find-date-create): Test if new entries are put at the right place. --- lisp/org-datetree.el | 77 +-- testing/lisp/test-org-datetree.el | 9 + 2 files changed, 27 insertions(+), 59 deletions(-) diff --git a/lisp/org-datetree.el b/lisp/org-datetree.el index a97a9d0..3620bbd 100644 --- a/lisp/org-datetree.el +++ b/lisp/org-datetree.el @@ -64,67 +64,30 @@ (defun org-datetree-find-date-create (date keep-restriction) (org-get-valid-level (org-current-level) 1)) (org-narrow-to-subtree))) (goto-char (point-min)) -(let ((year (nth 2 date)) - (month (car date)) - (day (nth 1 date))) - (org-datetree-find-year-create year) - (org-datetree-find-month-create year month) - (org-datetree-find-day-create year month day - -(defun org-datetree-find-year-create (year) - "Find the YEAR datetree or create it." - (let ((re "^\\*+[ \t]+\\([12][0-9]\\{3\\}\\)\\(\\s-*?\\([ \t]:[[:alnum:]:_@#%]+:\\)?\\s-*$\\)") +(let ((year (calendar-extract-year date)) + (month (calendar-extract-month date)) + (day (calendar-extract-day date))) + (org-datetree--find-create "^\\*+[ \t]+\\([12][0-9]\\{3\\}\\)\\(\\s-*?\\([ \t]:[[:alnum:]:_@#%%]+:\\)?\\s-*$\\)" +year) + (org-datetree--find-create "^\\*+[ \t]+%d-\\([01][0-9]\\) \\w+$" +year month) + (org-datetree--find-create "^\\*+[ \t]+%d-%02d-\\([0123][0-9]\\) \\w+$" +year month day + +(defun org-datetree--find-create (regex year month day) + "Find the datetree matched by REGEX for YEAR, MONTH, or DAY." + (let ((re (format regex year month day)) match) (goto-char (point-min)) (while (and (setq match (re-search-forward re nil t)) (goto-char (match-beginning 1)) - (< (string-to-number (match-string 1)) year))) + (< (string-to-number (match-string 1)) (or day month year (cond ((not match) (goto-char (point-max)) - (or (bolp) (newline)) - (org-datetree-insert-line year)) - ((= (string-to-number (match-string 1)) year) - (goto-char (point-at-bol))) - (t - (beginning-of-line 1) - (org-datetree-insert-line year) - -(defun org-datetree-find-month-create (year month) - "Find the datetree for YEAR and MONTH or create it." - (org-narrow-to-subtree) - (let ((re (format "^\\*+[ \t]+%d-\\([01][0-9]\\) \\w+$" year)) - match) -(goto-char (point-min)) -(while (and (setq match (re-search-forward re nil t)) - (goto-char (match-beginning 1)) - (< (string-to-number (match-string 1)) month))) -(cond - ((not match) - (goto-char (point-max)) - (or (bolp) (newline)) - (org-datetree-insert-line year month)) - ((= (string-to-number (match-string 1)) month) - (goto-char (point-at-bol))) - (t - (beginning-of-line 1) - (org-datetree-insert-line year month) - -(defun org-datetree-find-day-create (year month day) - "Find the datetree for YEAR, MONTH and DAY or create it." - (org-narrow-to-subtree) - (let ((re (format "^\\*+[ \t]+%d-%02d-\\([0123][0-9]\\) \\w+$" year month)) - match) -(goto-char (point-min)) -(while (and (setq match (re-search-forward re nil t)) - (goto-char (match-beginning 1)) - (< (string-to-number (match-string 1)) day))) -(cond - ((not match) - (goto-char (point-max)) - (or (bolp) (newline)) + (unless (bolp) (newline)) (org-datetree-insert-line year month day)) - ((= (string-to-number (match-string 1)) day) + ((= (string-to-number (match-string 1)) (or day month year)) (goto-char (point-at-bol))) (t (beginning-of-line 1) @@ -139,13 +102,9 @@ (defun org-datetree-insert-line (year month day) (insert (format "%d" year)) (when month (insert - (format "-%02d" month) (if day -(format "-%02d %s" -day -(format-time-string "%A" (encode-time 0 0 0 day month year))) - (format " %s" - (format-time-string "%B" (encode-time 0 0 0 1 month year)) +(format-time-string "-%m-%d %A" (encode-time 0 0 0 day month year)) + (format-time-string "-%m %B" (encode-time 0 0 0 1 month year) (when (and day org-datetree-add-timestamp) (save-excursion (insert "\n") diff --git
[O] [PATCH 2/3] org-datetree.el: Add support for ISO week trees.
* lisp/org-datetree.el (org-datetree-find-iso-date-create): New function. (org-datetree--find-create): Support fixed text for insert. (org-datetree-insert-line): Support fixed text for insert. * testing/lisp/test-org-datetree.el (test-org-datetree/find-iso-date-create): New test. ISO week trees order dates by week and not by month. --- lisp/org-datetree.el | 64 ++- testing/lisp/test-org-datetree.el | 92 +++ 2 files changed, 145 insertions(+), 11 deletions(-) diff --git a/lisp/org-datetree.el b/lisp/org-datetree.el index 3620bbd..a5a542e 100644 --- a/lisp/org-datetree.el +++ b/lisp/org-datetree.el @@ -74,8 +74,48 @@ (defun org-datetree-find-date-create (date keep-restriction) (org-datetree--find-create "^\\*+[ \t]+%d-%02d-\\([0123][0-9]\\) \\w+$" year month day -(defun org-datetree--find-create (regex year month day) - "Find the datetree matched by REGEX for YEAR, MONTH, or DAY." +;;;###autoload +(defun org-datetree-find-iso-week-create (date keep-restriction) + "Find or create an ISO week entry for DATE. +Compared to `org-datetree-find-date-create' this function creates +entries ordered by week instead of months. +If KEEP-RESTRICTION is non-nil, do not widen the buffer. When it +is nil, the buffer will be widened to make sure an existing date +tree can be found." + (org-set-local 'org-datetree-base-level 1) + (or keep-restriction (widen)) + (save-restriction +(let ((prop (org-find-property "DATE_WEEK_TREE"))) + (when prop + (goto-char prop) + (org-set-local 'org-datetree-base-level + (org-get-valid-level (org-current-level) 1)) + (org-narrow-to-subtree))) +(goto-char (point-min)) +(require 'cal-iso) +(let* ((year (calendar-extract-year date)) + (month (calendar-extract-month date)) + (day (calendar-extract-day date)) + (time (encode-time 0 0 0 day month year)) + (iso-date (calendar-iso-from-absolute + (calendar-absolute-from-gregorian date))) + (weekyear (nth 2 iso-date)) + (week (car iso-date)) + (weekday (cadr iso-date))) + ;; ISO 8601 week format is %G-W%V(-%u) + (org-datetree--find-create "^\\*+[ \t]+\\([12][0-9]\\{3\\}\\)\\(\\s-*?\\([ \t]:[[:alnum:]:_@#%%]+:\\)?\\s-*$\\)" +weekyear nil nil +(format-time-string "%G" time)) + (org-datetree--find-create "^\\*+[ \t]+%d-W\\([0-5][0-9]\\)$" +weekyear week nil +(format-time-string "%G-W%V" time)) + ;; For the actual day we use the regular date instead of ISO week. + (org-datetree--find-create "^\\*+[ \t]+%d-%02d-\\([0123][0-9]\\) \\w+$" +year month day + +(defun org-datetree--find-create (regex year month day insert) + "Find the datetree matched by REGEX for YEAR, MONTH, or DAY. +If INSERT is non-nil insert the text if not found." (let ((re (format regex year month day)) match) (goto-char (point-min)) @@ -86,25 +126,27 @@ (defun org-datetree--find-create (regex year month day) ((not match) (goto-char (point-max)) (unless (bolp) (newline)) - (org-datetree-insert-line year month day)) + (org-datetree-insert-line year month day insert)) ((= (string-to-number (match-string 1)) (or day month year)) (goto-char (point-at-bol))) (t (beginning-of-line 1) - (org-datetree-insert-line year month day) + (org-datetree-insert-line year month day insert) -(defun org-datetree-insert-line (year month day) +(defun org-datetree-insert-line (year month day text) (delete-region (save-excursion (skip-chars-backward " \t\n") (point)) (point)) (insert "\n" (make-string org-datetree-base-level ?*) " \n") (backward-char) (when month (org-do-demote)) (when day (org-do-demote)) - (insert (format "%d" year)) - (when month -(insert - (if day -(format-time-string "-%m-%d %A" (encode-time 0 0 0 day month year)) - (format-time-string "-%m %B" (encode-time 0 0 0 1 month year) + (if text + (insert text) +(insert (format "%d" year)) +(when month + (insert + (if day + (format-time-string "-%m-%d %A" (encode-time 0 0 0 day month year)) +(format-time-string "-%m %B" (encode-time 0 0 0 1 month year)) (when (and day org-datetree-add-timestamp) (save-excursion (insert "\n") diff --git a/testing/lisp/test-org-datetree.el b/testing/lisp/test-org-datetree.el index 0135ab9..9b839ca 100644 --- a/testing/lisp/test-org-datetree.el +++ b/testing/lisp/test-org-datetree.el @@ -113,5 +113,97 @@ (ert-deftest test-org-datetree/find-date-create () (org-datetree-find-date-create '(3 29 2012))) (buffer-substring (point)
[O] [PATCH 3/3] org-capture.el: Add support for week trees.
* lisp/org-capture.el (org-capture-templates): Add file+weektree(+prompt) options. (org-capture-set-target-location): Add support for week trees. * doc/org.texi (Template elements): Document file+weektree(+prompt) options. --- doc/org.texi| 7 +++ lisp/org-capture.el | 26 +- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index ed808be..d894f91 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -7187,6 +7187,13 @@ @item (file+datetree+prompt "path/to/file") Will create a heading in a date tree, but will prompt for the date. +@item (file+weektree "path/to/file") +Will create a heading in a week tree for today's date. Week trees are sorted +by week and not by month unlike datetrees. + +@item (file+weektree+prompt "path/to/file") +Will create a heading in a week tree, but will prompt for the date. + @item (file+function "path/to/file" function-finding-location) A function to find the right location in the file. diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 93a7f2a..320954e 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -149,6 +149,12 @@ (defcustom org-capture-templates nil (file+datetree+prompt \"path/to/file\") Will create a heading in a date tree, prompts for date + (file+weektree \"path/to/file\") + Will create a heading in a week tree for today's date + + (file+weektree+prompt \"path/to/file\") + Will create a heading in a week tree, prompts for date + (file+function \"path/to/file\" function-finding-location) A function to find the right location in the file @@ -321,6 +327,12 @@ (defcustom org-capture-templates nil (list :tag "File & Date tree, prompt for date" (const :format "" file+datetree+prompt) (file :tag " File")) + (list :tag "File & Week tree" + (const :format "" file+weektree) + (file :tag " File")) + (list :tag "File & Week tree, prompt for date" + (const :format "" file+weektree+prompt) + (file :tag " File")) (list :tag "File & function" (const :format "" file+function) (file :tag " File") @@ -895,21 +907,25 @@ (defun org-capture-set-target-location ( target) (setq target-entry-p (and (derived-mode-p 'org-mode) (org-at-heading-p (error "No match for target regexp in file %s" (nth 1 target - ((memq (car target) '(file+datetree file+datetree+prompt)) + ((memq (car target) '(file+datetree file+datetree+prompt file+weektree file+weektree+prompt)) (require 'org-datetree) (set-buffer (org-capture-target-buffer (nth 1 target))) (org-capture-put-target-region-and-position) (widen) - ;; Make a date tree entry, with the current date (or yesterday, - ;; if we are extending dates for a couple of hours) - (org-datetree-find-date-create + ;; Make a date/week tree entry, with the current date (or + ;; yesterday, if we are extending dates for a couple of hours) + (funcall +(cond + ((memq (car target) '(file+weektree file+weektree+prompt)) + #'org-datetree-find-iso-week-create) + (t #'org-datetree-find-date-create)) (calendar-gregorian-from-absolute (cond (org-overriding-default-time ;; use the overriding default time (time-to-days org-overriding-default-time)) - ((eq (car target) 'file+datetree+prompt) + ((memq (car target) '(file+datetree+prompt file+weektree+prompt)) ;; prompt for date (let ((prompt-time (org-read-date nil t nil "Date for tree entry:" -- 2.5.1
Re: [O] [PATCH 2/3] org-datetree.el: Add support for ISO week trees.
On Wednesday 02 September 2015 21:58:17 Nicolas Goaziou wrote: > Rüdiger Sonderfeld <ruedi...@c-plusplus.net> writes: > > +(let ((prop (org-find-property "DATE_WEEK_TREE"))) > > I don't think we need to introduce a new property for that. DATE_TREE is > enough. Since DATE_TREE and DATE_WEEK_TREE (or WEEK_TREE instead?) are structured differently it might make sense to keep the property separated. > > + ;; ISO 8601 week format is %G-W%V(-%u) > > + (org-datetree--find-create "^\\*+[ > > \t]+\\([12][0-9]\\{3\\}\\)\\(\\s-*?\\([ > > \t]:[[:alnum:]:_@#%%]+:\\)?\\s-*$\\)" > Isn't this line too long? What's the limit? Because if it's 80 char then I'd need to do some `concat' ugliness because the regex is over 80 char long. I've fixed the rest and will send updated patches. Cheers, Rüdiger
[O] [PATCH 2/3] org-datetree.el: Add support for ISO week trees.
* lisp/org-datetree.el (org-datetree-find-iso-date-create): New function. (org-datetree--find-create): Support fixed text for insert. (org-datetree-insert-line): Support fixed text for insert. * testing/lisp/test-org-datetree.el (test-org-datetree/find-iso-date-create): New test. ISO week trees order dates by week and not by month. --- lisp/org-datetree.el | 64 ++- testing/lisp/test-org-datetree.el | 92 +++ 2 files changed, 145 insertions(+), 11 deletions(-) diff --git a/lisp/org-datetree.el b/lisp/org-datetree.el index 3620bbd..a5a542e 100644 --- a/lisp/org-datetree.el +++ b/lisp/org-datetree.el @@ -74,8 +74,48 @@ (defun org-datetree-find-date-create (date keep-restriction) (org-datetree--find-create "^\\*+[ \t]+%d-%02d-\\([0123][0-9]\\) \\w+$" year month day -(defun org-datetree--find-create (regex year month day) - "Find the datetree matched by REGEX for YEAR, MONTH, or DAY." +;;;###autoload +(defun org-datetree-find-iso-week-create (date keep-restriction) + "Find or create an ISO week entry for DATE. +Compared to `org-datetree-find-date-create' this function creates +entries ordered by week instead of months. +If KEEP-RESTRICTION is non-nil, do not widen the buffer. When it +is nil, the buffer will be widened to make sure an existing date +tree can be found." + (org-set-local 'org-datetree-base-level 1) + (or keep-restriction (widen)) + (save-restriction +(let ((prop (org-find-property "DATE_WEEK_TREE"))) + (when prop + (goto-char prop) + (org-set-local 'org-datetree-base-level + (org-get-valid-level (org-current-level) 1)) + (org-narrow-to-subtree))) +(goto-char (point-min)) +(require 'cal-iso) +(let* ((year (calendar-extract-year date)) + (month (calendar-extract-month date)) + (day (calendar-extract-day date)) + (time (encode-time 0 0 0 day month year)) + (iso-date (calendar-iso-from-absolute + (calendar-absolute-from-gregorian date))) + (weekyear (nth 2 iso-date)) + (week (car iso-date)) + (weekday (cadr iso-date))) + ;; ISO 8601 week format is %G-W%V(-%u) + (org-datetree--find-create "^\\*+[ \t]+\\([12][0-9]\\{3\\}\\)\\(\\s-*?\\([ \t]:[[:alnum:]:_@#%%]+:\\)?\\s-*$\\)" +weekyear nil nil +(format-time-string "%G" time)) + (org-datetree--find-create "^\\*+[ \t]+%d-W\\([0-5][0-9]\\)$" +weekyear week nil +(format-time-string "%G-W%V" time)) + ;; For the actual day we use the regular date instead of ISO week. + (org-datetree--find-create "^\\*+[ \t]+%d-%02d-\\([0123][0-9]\\) \\w+$" +year month day + +(defun org-datetree--find-create (regex year month day insert) + "Find the datetree matched by REGEX for YEAR, MONTH, or DAY. +If INSERT is non-nil insert the text if not found." (let ((re (format regex year month day)) match) (goto-char (point-min)) @@ -86,25 +126,27 @@ (defun org-datetree--find-create (regex year month day) ((not match) (goto-char (point-max)) (unless (bolp) (newline)) - (org-datetree-insert-line year month day)) + (org-datetree-insert-line year month day insert)) ((= (string-to-number (match-string 1)) (or day month year)) (goto-char (point-at-bol))) (t (beginning-of-line 1) - (org-datetree-insert-line year month day) + (org-datetree-insert-line year month day insert) -(defun org-datetree-insert-line (year month day) +(defun org-datetree-insert-line (year month day text) (delete-region (save-excursion (skip-chars-backward " \t\n") (point)) (point)) (insert "\n" (make-string org-datetree-base-level ?*) " \n") (backward-char) (when month (org-do-demote)) (when day (org-do-demote)) - (insert (format "%d" year)) - (when month -(insert - (if day -(format-time-string "-%m-%d %A" (encode-time 0 0 0 day month year)) - (format-time-string "-%m %B" (encode-time 0 0 0 1 month year) + (if text + (insert text) +(insert (format "%d" year)) +(when month + (insert + (if day + (format-time-string "-%m-%d %A" (encode-time 0 0 0 day month year)) +(format-time-string "-%m %B" (encode-time 0 0 0 1 month year)) (when (and day org-datetree-add-timestamp) (save-excursion (insert "\n") diff --git a/testing/lisp/test-org-datetree.el b/testing/lisp/test-org-datetree.el index 0135ab9..9b839ca 100644 --- a/testing/lisp/test-org-datetree.el +++ b/testing/lisp/test-org-datetree.el @@ -113,5 +113,97 @@ (ert-deftest test-org-datetree/find-date-create () (org-datetree-find-date-create '(3 29 2012))) (buffer-substring (point)
[O] [PATCH 1/3] org-datetree.el: Code cleanup.
* lisp/org-datetree.el (org-datetree--find-create): New function. (org-datetree-find-year-create, org-datetree-find-month-create, org-datetree-find-day-create): Removed functions (org-datetree-find-date-create): Use `org-datetree--find-create' instead of removed functions. Use calendar extract functions. (org-datetree-insert-line): Do more formatting in `format-time-string' since we call it anyway * testing/lisp/test-org-datetree.el (test-org-datetree/find-date-create): Test if new entries are put at the right place. --- lisp/org-datetree.el | 77 +-- testing/lisp/test-org-datetree.el | 9 + 2 files changed, 27 insertions(+), 59 deletions(-) diff --git a/lisp/org-datetree.el b/lisp/org-datetree.el index a97a9d0..3620bbd 100644 --- a/lisp/org-datetree.el +++ b/lisp/org-datetree.el @@ -64,67 +64,30 @@ (defun org-datetree-find-date-create (date keep-restriction) (org-get-valid-level (org-current-level) 1)) (org-narrow-to-subtree))) (goto-char (point-min)) -(let ((year (nth 2 date)) - (month (car date)) - (day (nth 1 date))) - (org-datetree-find-year-create year) - (org-datetree-find-month-create year month) - (org-datetree-find-day-create year month day - -(defun org-datetree-find-year-create (year) - "Find the YEAR datetree or create it." - (let ((re "^\\*+[ \t]+\\([12][0-9]\\{3\\}\\)\\(\\s-*?\\([ \t]:[[:alnum:]:_@#%]+:\\)?\\s-*$\\)") +(let ((year (calendar-extract-year date)) + (month (calendar-extract-month date)) + (day (calendar-extract-day date))) + (org-datetree--find-create "^\\*+[ \t]+\\([12][0-9]\\{3\\}\\)\\(\\s-*?\\([ \t]:[[:alnum:]:_@#%%]+:\\)?\\s-*$\\)" +year) + (org-datetree--find-create "^\\*+[ \t]+%d-\\([01][0-9]\\) \\w+$" +year month) + (org-datetree--find-create "^\\*+[ \t]+%d-%02d-\\([0123][0-9]\\) \\w+$" +year month day + +(defun org-datetree--find-create (regex year month day) + "Find the datetree matched by REGEX for YEAR, MONTH, or DAY." + (let ((re (format regex year month day)) match) (goto-char (point-min)) (while (and (setq match (re-search-forward re nil t)) (goto-char (match-beginning 1)) - (< (string-to-number (match-string 1)) year))) + (< (string-to-number (match-string 1)) (or day month year (cond ((not match) (goto-char (point-max)) - (or (bolp) (newline)) - (org-datetree-insert-line year)) - ((= (string-to-number (match-string 1)) year) - (goto-char (point-at-bol))) - (t - (beginning-of-line 1) - (org-datetree-insert-line year) - -(defun org-datetree-find-month-create (year month) - "Find the datetree for YEAR and MONTH or create it." - (org-narrow-to-subtree) - (let ((re (format "^\\*+[ \t]+%d-\\([01][0-9]\\) \\w+$" year)) - match) -(goto-char (point-min)) -(while (and (setq match (re-search-forward re nil t)) - (goto-char (match-beginning 1)) - (< (string-to-number (match-string 1)) month))) -(cond - ((not match) - (goto-char (point-max)) - (or (bolp) (newline)) - (org-datetree-insert-line year month)) - ((= (string-to-number (match-string 1)) month) - (goto-char (point-at-bol))) - (t - (beginning-of-line 1) - (org-datetree-insert-line year month) - -(defun org-datetree-find-day-create (year month day) - "Find the datetree for YEAR, MONTH and DAY or create it." - (org-narrow-to-subtree) - (let ((re (format "^\\*+[ \t]+%d-%02d-\\([0123][0-9]\\) \\w+$" year month)) - match) -(goto-char (point-min)) -(while (and (setq match (re-search-forward re nil t)) - (goto-char (match-beginning 1)) - (< (string-to-number (match-string 1)) day))) -(cond - ((not match) - (goto-char (point-max)) - (or (bolp) (newline)) + (unless (bolp) (newline)) (org-datetree-insert-line year month day)) - ((= (string-to-number (match-string 1)) day) + ((= (string-to-number (match-string 1)) (or day month year)) (goto-char (point-at-bol))) (t (beginning-of-line 1) @@ -139,13 +102,9 @@ (defun org-datetree-insert-line (year month day) (insert (format "%d" year)) (when month (insert - (format "-%02d" month) (if day -(format "-%02d %s" -day -(format-time-string "%A" (encode-time 0 0 0 day month year))) - (format " %s" - (format-time-string "%B" (encode-time 0 0 0 1 month year)) +(format-time-string "-%m-%d %A" (encode-time 0 0 0 day month year)) + (format-time-string "-%m %B" (encode-time 0 0 0 1 month year) (when (and day org-datetree-add-timestamp) (save-excursion (insert "\n") diff --git
[O] [PATCH 0/3] Add ISO week trees.
This series of patches adds support for ISO week trees to org-datetree and org-capture. Unlike regular date trees the tree is ordered by week instead of month. For example: * 2015 ** 2015-W35 *** 2015-08-30 Sunday Foo Bar ** 2015-W36 *** 2015-08-31 Monday Fou *** 2015-09-01 Tuesday Baz I find this more useful to order my work log than a month based tree. Rüdiger Sonderfeld (3): org-datetree.el: Code cleanup. org-datetree.el: Add support for ISO week trees. org-capture.el: Add support for week trees. doc/org.texi | 7 +++ lisp/org-capture.el | 26 ++-- lisp/org-datetree.el | 129 +++--- testing/lisp/test-org-datetree.el | 101 + 4 files changed, 194 insertions(+), 69 deletions(-) -- 2.5.1
[O] [PATCH 3/3] org-capture.el: Add support for week trees.
* lisp/org-capture.el (org-capture-templates): Add file+weektree(+prompt) options. (org-capture-set-target-location): Add support for week trees. * doc/org.texi (Template elements): Document file+weektree(+prompt) options. --- doc/org.texi| 7 +++ lisp/org-capture.el | 26 +- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index ed808be..d894f91 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -7187,6 +7187,13 @@ @item (file+datetree+prompt "path/to/file") Will create a heading in a date tree, but will prompt for the date. +@item (file+weektree "path/to/file") +Will create a heading in a week tree for today's date. Week trees are sorted +by week and not by month unlike datetrees. + +@item (file+weektree+prompt "path/to/file") +Will create a heading in a week tree, but will prompt for the date. + @item (file+function "path/to/file" function-finding-location) A function to find the right location in the file. diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 93a7f2a..320954e 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -149,6 +149,12 @@ (defcustom org-capture-templates nil (file+datetree+prompt \"path/to/file\") Will create a heading in a date tree, prompts for date + (file+weektree \"path/to/file\") + Will create a heading in a week tree for today's date + + (file+weektree+prompt \"path/to/file\") + Will create a heading in a week tree, prompts for date + (file+function \"path/to/file\" function-finding-location) A function to find the right location in the file @@ -321,6 +327,12 @@ (defcustom org-capture-templates nil (list :tag "File & Date tree, prompt for date" (const :format "" file+datetree+prompt) (file :tag " File")) + (list :tag "File & Week tree" + (const :format "" file+weektree) + (file :tag " File")) + (list :tag "File & Week tree, prompt for date" + (const :format "" file+weektree+prompt) + (file :tag " File")) (list :tag "File & function" (const :format "" file+function) (file :tag " File") @@ -895,21 +907,25 @@ (defun org-capture-set-target-location ( target) (setq target-entry-p (and (derived-mode-p 'org-mode) (org-at-heading-p (error "No match for target regexp in file %s" (nth 1 target - ((memq (car target) '(file+datetree file+datetree+prompt)) + ((memq (car target) '(file+datetree file+datetree+prompt file+weektree file+weektree+prompt)) (require 'org-datetree) (set-buffer (org-capture-target-buffer (nth 1 target))) (org-capture-put-target-region-and-position) (widen) - ;; Make a date tree entry, with the current date (or yesterday, - ;; if we are extending dates for a couple of hours) - (org-datetree-find-date-create + ;; Make a date/week tree entry, with the current date (or + ;; yesterday, if we are extending dates for a couple of hours) + (funcall +(cond + ((memq (car target) '(file+weektree file+weektree+prompt)) + #'org-datetree-find-iso-week-create) + (t #'org-datetree-find-date-create)) (calendar-gregorian-from-absolute (cond (org-overriding-default-time ;; use the overriding default time (time-to-days org-overriding-default-time)) - ((eq (car target) 'file+datetree+prompt) + ((memq (car target) '(file+datetree+prompt file+weektree+prompt)) ;; prompt for date (let ((prompt-time (org-read-date nil t nil "Date for tree entry:" -- 2.5.1
Re: [O] org-weather for openweathermap.org
Hi, On Saturday 14 June 2014 15:11:21 Chris Raschl wrote: recently I wanted to add a weather forecast to my org-agenda. I found org-google-weather, but this package is obsolete since 2012, because the API is not available any more. So I wrote my own version which is backed by the openweathermap.org API. I've written the `weather-metno-el' package. Which uses the weather data from met.no (CC licensed). It supports showing weather data in the org-agenda as well. https://github.com/ruediger/weather-metno-el Regards, Rüdiger
[O] World Cup 2014 Schedule for Org-mode
Hello, I've created an org-mode schedule for the 2014 football world cup https://github.com/ruediger/org-world-cup2014 Feel free to correct mistakes and add match results! Regards, Rüdiger
Re: [O] [ANN] google-contacts.el can now export to org-contacts.
Hello, On Wednesday 29 January 2014 18:47:39 Robert Eckl wrote: I wanted to play with it, but if I use *M-x google-contacts* and type string i get google-oauth-auth-and-store: Symbol's function definition is void: oauth2-auth-and-store google-contacts requires oauth2.el version 0.10 (the latest from GNU elpa). You should upgrade and try again. I think Julien forgot do update the requirement. Sorry about that. Regards, Rüdiger
[O] [ANN] google-contacts.el can now export to org-contacts.
Hello, Julien Danjou's google-contacts.el is a GNU Emacs package to display contacts from Google Contacts within Emacs. I have recently added support to export contacts to org-contacts format (See contrib/lisp/org-contacts.el). Calling `M-x google-contacts-to-org-contacts' will export all contacts into the current buffer. There currently is no support for synchronisation. http://julien.danjou.info/projects/emacs-packages#google-contacts Regards, Rüdiger
Re: [O] Bug: Babel calc sqrt float var
Hi, the problem is that calc does not operate on regular elisp types but instead uses a different format: (float NUM EXP) for decimal floats. But ob-calc.el seems to simply push any value it gets on the stack and assigns it to a variable. And since calc treats anything which isn't in such a lisp form as an integer it tries to call idiv. To fix this the value should be converted to calc format before `calc-push- list' is called. But after a quick look into calc.el I couldn't find any generic function to convert elisp values to calc values. The function `math- read-number' seems to be the only way and it requires a string. However my knowledge of calc internals is rather limited. Regards, Rüdiger On Tuesday 10 December 2013 10:43:02 Miguel Ruiz wrote: Hi, Please, I am communicating the following problematic behaviour: #--- problematic code #+begin_src calc sqrt(0.8) #+end_src #+RESULTS: : 0.894427191 # OK #+begin_src calc :var x=0.8 sqrt(x) #+end_src #+RESULTS: =Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p 0.80004) math-idivmod(0.80004 0.80004) math-div(0.80004 0.80004) math-cancel-common-factor(0.80004 0.80004) math-simplify-sqrt() #[(math-simplify-expr) \300 \207 [math-simplify-sqrt] 1]((calcFunc-sqrt 0.80004)) math-simplify-step((calcFunc-sqrt 0.80004)) math-simplify((calcFunc-sqrt 0.80004)) calc-normalize-fancy((calcFunc-sqrt 0.80004)) calc-normalize((calcFunc-sqrt 0.80004)) math-evaluate-expr((calcFunc-sqrt 0.80004)) #[(line) not copy-yank-able string [line var-names calc-mode-map res x 0 calc-recall intern 1 ' lookup-key nil calc-push-list calc-eval math-read-number error Calc error \%s\ on input \%s\ replace-regexp-in-string math-evaluate-expr mapcar org-babel-calc-maybe-resolve-var math-read-exprs] 11] (sqrt(x))) org-babel-execute:calc(sqrt(x) ((:comments . ) (:shebang . ) (:cache . no) (:padline . ) (:noweb . no) (:tangle . no) (:exports . code) (:results . replace) (:var x . 0.80004) (:session . none) (:hlines . no) (:result-type . value) (:result-params replace) (:rowname-names) (:colname-names))) org-babel-execute-src-block(nil) org-babel-execute-src-block-maybe() org-babel-execute-maybe() org-babel-execute-safely-maybe() run-hook-with-args-until-success(org-babel-execute-safely-maybe) org-ctrl-c-ctrl-c(nil) call-interactively(org-ctrl-c-ctrl-c nil nil) #-- end of problematic code Command line: emacs -Q -l minimal-org.el ;;; minimal-org.el: ;;; Minimal setup to load latest `org-mode' ;; activate debugging (setq debug-on-error t debug-on-signal nil debug-on-quit nil) ;; add latest org-mode to load path (add-to-list 'load-path (expand-file-name ~/org-mode/maint/lisp)) (add-to-list 'load-path (expand-file-name ~/org-mode/maint/contrib/lisp t)) ;; active Babel languages (org-babel-do-load-languages 'org-babel-load-languages '((calc . t))) ;;; end of minimal-org.el GNU Emacs 24.3.1 (i686-pc-cygwin) of 2013-08-14 on moufang Org-mode version 8.2.4 (release_8.2.4-3-g7fe99a @ /home/usuario/org-mode/maint/lisp/) TIA. Miguel Ruiz.
Re: [O] Captions on Code Blocks -- work for ox-ascii but not ox-html or ox-latex
On Tuesday 26 November 2013 07:23:33 Eric Schulte wrote: I see that Captions on code blocks work as expected for ASCII export, but not for HTML or LaTeX export. Is this intentional? If not could captions be easily added to HTML and LaTeX export? What do you expect differently? For me the captions are exported in both HTML and LaTeX (also checked for lstlisting and minted) as well. Regards, Rüdiger
Re: [O] [PATCH] Re: \newpage in HTML export
On Friday 22 November 2013 11:24:17 Nicolas Goaziou wrote: Anyway, I don't think this is a good idea to introduce a new syntax just to avoid a one-liner (or a hook, see below). Also, this would only make sense in few export back-ends. But is it really a new syntax or just support for an existing Emacs convention? See (info (emacs) Pages). It seems like a feature which could be supported in many back-ends: LaTeX, ODT, HTML, Texinfo, Ascii, Org, (Groff), maybe even md with pandoc. Regards, Rüdiger
Re: [O] Converting org-mode/org-contacts to VCard (importing to Android)
On Friday 22 November 2013 17:37:01 Karl Voit wrote: The reason I wrote it in Python is that I don't know ELISP well enough. The reason I wrote the script instead of using existing export methods: I only want to export a small sub-set (names, phone numbers, email addresses, contact image) due to privacy reasons. That should be possible with the existing VCard export. See `org-contacts- ignore-property' to ignore specific properties. And `org-contacts-export-as- vcard' takes a NAME parameter to limit the names. Regards, Rüdiger
Re: [O] Converting org-mode/org-contacts to VCard (importing to Android)
On Friday 22 November 2013 18:09:42 Karl Voit wrote: I have to admit that I don't know the feature-set of the Org-mode export. I would be very surprised, if the Org-mode export method is able to follow my custom photo: link I am using, grab the image file, test if it has a image format that works with VCard 2.1 on Android, and encodes it in base64 accordingly. Org-contacts has an :ICON: property and supports Gravatar. It doesn't seem to be handled in the VCard export though. You see: I want to have ways to tweak the export process. And as long as I don't know ELISP that well, I stick to the tools I know. I understand that and it solved your problem for now. But having an external tool in a different programming language is usually not a good idea to solve the problem in the long run. The code base of org-contacts and your tool is under the risk of diverting quickly. If it's in org-contacts then it is maintained in one piece and easily accessible to other users. So my point is you should take a look at elisp. It's a lot of fun to use and if you are using org-mode and Emacs then you will have to learn it sooner or later. A side remark of mine: a couple of months ago I tried to find out how to store address information, phone numbers, and so on in org-contact properties. AFAIR I could not find anything except the :EMAIL: property. Is there a standard out there that answers questions like separate street from house number?, how to cope with multiple addresses for one contact?, and so forth? I created something on my own as you can see on [1]. I have to admit the org-contacts format is pretty much ad-hoc and not really well designed. It is documented a bit in the file itself (contrib/lisp/contacts.el). M-x customize-group RET org-contacts RET should also tell you more about the options. Your format choice is not fully compatible with the existing org-contacts. Right now multiple entries are separated by space (which sadly breaks for addresses) and different entry names are used. However I'd look forward to some new ideas and improvements. Right now it's not ideal solution. Regards, Rüdiger
Re: [O] imaxima babel
TeX output is a feature of Maxima. See (info (maxima) Functions and Variables for TeX Output) E.g. #+name: solve-maxima #+header: :exports results #+begin_src maxima :results output tex(exp(-x)/x); #+end_src #+RESULTS: solve-maxima : $${{e^ {- x }}\over{x}}$$ On Thursday 21 November 2013 23:58:35 yggdra...@gmx.co.uk wrote: Hi, Is there a way to evaluate imaxima source code in org-mode to display the latex output inline in the org-buffer? I have found in [1] how to evaluate maxima code, but I don't understand if and how to adopt it to get the nice latex/pdf output. Any pointers appreciated, or just whether it is possible or not. I am running emacs 24.3.1 with org mode 7.9.3f. Thanks, Johnny Footnotes: [1] http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-maxima.html
Re: [O] org-contacts, multi-line properties, postal addresses
On Wednesday 13 November 2013 14:23:17 Norman Walsh wrote: Hello world, I'm just taking another look at org-contacts. I wonder what the best practice is for dealing with multi-line properties like postal addresses. I store addresses like that :PROPERTIES: :ADDRESS: street no, postal-code city, country :END: That way of formatting is supported by the vCard export and should work fine with the Map support (the only two features really supporting Addresses anyway). But it is not very flexible and there is no real way to add several addresses (usually space is used to separate several entries). Overall the org-contacts format is a bit limited and not consistently designed. It could use some refactoring. Regards, Rüdiger signature.asc Description: This is a digitally signed message part.
[O] [PATCH] ox-latex: Don't quote const in defcustom.
Quoting it would set `org-export-latex' not to `minted' but `(quote minted)' and thus breaking the export. * lisp/ox-latex.el (org-latex-listings): Don't quote const value. Signed-off-by: Rüdiger Sonderfeld ruedi...@c-plusplus.de --- lisp/ox-latex.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index 2af5de6..87c503c 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -655,7 +655,7 @@ (defcustom org-latex-listings nil :group 'org-export-latex :type '(choice (const :tag Use listings t) - (const :tag Use minted 'minted) + (const :tag Use minted minted) (const :tag Export verbatim nil))) (defcustom org-latex-listings-langs -- 1.8.4.1
Re: [O] [RFC] BibELTeX: native bibtex support in org-mode
Rasmus rasmus at gmx.us writes: Rüdiger Sonderfeld ruediger at c-plusplus.de writes: I've started writing BibELTeX as an alternative to =ox-bibtex.el=. https://github.com/ruediger/bibeltex Would you consider providing a test file showing off its features? I added a file test/example.org. Put bibeltex.el somewhere in your load-path and require it. This should be enough to make it work (use unload-feature to remove it again). You can then export the document to any format you like. Good test case is using org-mode export (ox-org.el). I'm skeptical but probably it is 'cause I've misunderstood something! Someone put a lot of thought into writing e.g. biblatex or odt-bibliographies. Surely(?) we would want to leverage upon those and only have org-support insofar as serving some backend-specific parser enough information to do its work? Certainly. BibELTeX is designed to do this. For LaTeX export it just generates the corresponding LaTeX instructions (can be adopted even for biblatex). But except for LaTeX there doesn't seem to be a real support for bibliography. It can be simulated for html using bibtex2html (ox-bibtex.el). But even that is not compatible with biber/biblatex. That's the reason behind BibELTeX. Regards
[O] [RFC] BibELTeX: native bibtex support in org-mode
Hello, I've started writing BibELTeX as an alternative to =ox-bibtex.el=. https://github.com/ruediger/bibeltex Instead of calling =bibtex2html= it uses the functionality from =org- bibtex.el= to parse the BibTeX file and generates org-mode format for it. This has the advantage that it works with any output format (latex, html, odt, ascii, ...) and that it does not require external tools. BibELTeX is currently in a very early stage of development. The biggest design issue is the style format. Currently I use a =format-spec= like format which is not very good to work with (See =bibeltex-style-default=). Please feel free to criticise, comment, and open pull requests! Regards Rüdiger
[O] [PATCH] ob-C: Add list support.
* lisp/ob-C.el (org-babel-C-var-to-C): Add list support (org-babel-C-val-to-C-list-type, org-babel-C-val-to-C-type, org-babel-C-format-val): New functions. (org-babel-C-ensure-main-wrap, org-babel-execute:C, org-babel-execute:C++, rg-babel-execute:cpp, org-babel-C++-compiler, org-babel-C-compiler): Improve docstring. * testing/examples/ob-C-test.org (string_var): Add required std:: (Array): Add missing ID. (Matrix): Add tests for list support. * testing/lisp/test-ob-C.el (ob-C/table): Test succeeds. (ob-C/list-var, ob-C/vector-var, ob-C/list-list-var): Add tests for list support. Signed-off-by: Rüdiger Sonderfeld ruedi...@c-plusplus.de --- lisp/ob-C.el | 98 +++--- testing/examples/ob-C-test.org | 28 +++- testing/lisp/test-ob-C.el | 20 - 3 files changed, 118 insertions(+), 28 deletions(-) diff --git a/lisp/ob-C.el b/lisp/ob-C.el index b1e8a06..e9eec93 100644 --- a/lisp/ob-C.el +++ b/lisp/ob-C.el @@ -44,24 +44,24 @@ (defvar org-babel-default-header-args:C '()) (defvar org-babel-C-compiler gcc Command used to compile a C source code file into an - executable.) +executable.) (defvar org-babel-C++-compiler g++ Command used to compile a C++ source code file into an - executable.) +executable.) (defvar org-babel-c-variant nil Internal variable used to hold which type of C (e.g. C or C++) is currently being evaluated.) (defun org-babel-execute:cpp (body params) - Execute BODY according to PARAMS. This function calls -`org-babel-execute:C++'. + Execute BODY according to PARAMS. +This function calls `org-babel-execute:C++'. (org-babel-execute:C++ body params)) (defun org-babel-execute:C++ (body params) - Execute a block of C++ code with org-babel. This function is -called by `org-babel-execute-src-block'. + Execute a block of C++ code with org-babel. +This function is called by `org-babel-execute-src-block'. (let ((org-babel-c-variant 'cpp)) (org-babel-C-execute body params))) (defun org-babel-expand-body:C++ (body params) @@ -70,8 +70,8 @@ (defun org-babel-expand-body:C++ (body params) (let ((org-babel-c-variant 'cpp)) (org-babel-C-expand body params))) (defun org-babel-execute:C (body params) - Execute a block of C code with org-babel. This function is -called by `org-babel-execute-src-block'. + Execute a block of C code with org-babel. +This function is called by `org-babel-execute-src-block'. (let ((org-babel-c-variant 'c)) (org-babel-C-execute body params))) (defun org-babel-expand-body:c (body params) @@ -146,10 +146,10 @@ (defun org-babel-C-expand (body params) body) \n) \n))) (defun org-babel-C-ensure-main-wrap (body) - Wrap body in a \main\ function call if none exists. + Wrap BODY in a \main\ function call if none exists. (if (string-match ^[ \t]*[intvod]+[ \t\n\r]*main[ \t]*(.*) body) body -(format int main() {\n%s\nreturn(0);\n}\n body))) +(format int main() {\n%s\nreturn 0;\n}\n body))) (defun org-babel-prep-session:C (session params) This function does nothing as C is a compiled language with no @@ -163,6 +163,59 @@ (defun org-babel-load-session:C (session body params) ;; helper functions +(defun org-babel-C-format-val (type val) + Handle the FORMAT part of TYPE with the data from VAL. + (let ((format-data (cadr type))) +(if (stringp format-data) + (cons (format format-data val)) + (funcall format-data val + +(defun org-babel-C-val-to-C-type (val) + Determine the type of VAL. +Return a list (TYPE-NAME FORMAT). TYPE-NAME should be the name of the type. +FORMAT can be either a format string or a function which is called with VAL. + (cond + ((integerp val) '(int %d)) + ((floatp val) '(double %f)) + ((or (listp val) (vectorp val)) +(lexical-let ((type (org-babel-C-val-to-C-list-type val))) + (list (car type) + (lambda (val) + (cons + (format [%d]%s + (length val) + (car (org-babel-C-format-val type (elt val 0 + (concat { + (mapconcat (lambda (v) + (cdr (org-babel-C-format-val type v))) + val + , ) + })) + (t ;; treat unknown types as string +'(char (lambda (val) + (let ((s (format %s val))) ;; convert to string for unknown types +(cons (format [%d] (1+ (length s))) + (concat \ s \ + +(defun org-babel-C-val-to-C-list-type (val) + Determine the C array type of a VAL. + (let (type) +(mapc + #'(lambda (i) +(let* ((tmp-type (org-babel-C-val-to-C-type i)) + (type-name (car type)) + (tmp-type-name (car tmp-type))) + (when (and type (not (string= type-name tmp-type-name))) +(if (and (member type-name '(int double int32_t
Re: [O] [PATCH] ob-C: Add list support.
On Thursday 06 June 2013 12:10:11 Eric Schulte wrote: Applied, Thanks for the excellent patch, test code and examples! Thank you for all the great work on org-mode! Regards Rüdiger
[O] [PATCH] org-entities: Add support for hbar.
* lisp/org-entities.el (org-entities): Add support for hbar. Signed-off-by: Rüdiger Sonderfeld ruedi...@c-plusplus.de --- lisp/org-entities.el | 1 + 1 file changed, 1 insertion(+) diff --git a/lisp/org-entities.el b/lisp/org-entities.el index 019b6c8..a1519b0 100644 --- a/lisp/org-entities.el +++ b/lisp/org-entities.el @@ -366,6 +366,7 @@ (defconst org-entities (rfloor \\rfloor t rfloor; [right floor] [right floor] ⌋) (lang \\langle t lang; ⟨) (rang \\rangle t rang; ⟩) +(hbar \\hbar t #8463; hbar hbar ℏ) ** Arrows (larr \\leftarrow t larr; - - ←) -- 1.8.3
[O] [PATCH] ob-C: Add list support.
* lisp/ob-C.el (org-babel-C-var-to-C): Add list support (org-babel-C-val-to-C-list-type, org-babel-C-val-to-C-type, org-babel-C-format-val): New functions. (org-babel-C-ensure-main-wrap, org-babel-execute:C, org-babel-execute:C++, rg-babel-execute:cpp, org-babel-C++-compiler, org-babel-C-compiler): Improve docstring. * testing/examples/ob-C-test.org (string_var): Add required std:: (Array): Add missing ID. (Matrix): Add tests for list support. * testing/lisp/test-ob-C.el (ob-C/table): Test succeeds. (ob-C/list-var, ob-C/vector-var, ob-C/list-list-var): Add tests for list support. Signed-off-by: Rüdiger Sonderfeld ruedi...@c-plusplus.de --- lisp/ob-C.el | 98 +++--- testing/examples/ob-C-test.org | 28 +++- testing/lisp/test-ob-C.el | 20 - 3 files changed, 118 insertions(+), 28 deletions(-) diff --git a/lisp/ob-C.el b/lisp/ob-C.el index b1e8a06..e9eec93 100644 --- a/lisp/ob-C.el +++ b/lisp/ob-C.el @@ -44,24 +44,24 @@ (defvar org-babel-default-header-args:C '()) (defvar org-babel-C-compiler gcc Command used to compile a C source code file into an - executable.) +executable.) (defvar org-babel-C++-compiler g++ Command used to compile a C++ source code file into an - executable.) +executable.) (defvar org-babel-c-variant nil Internal variable used to hold which type of C (e.g. C or C++) is currently being evaluated.) (defun org-babel-execute:cpp (body params) - Execute BODY according to PARAMS. This function calls -`org-babel-execute:C++'. + Execute BODY according to PARAMS. +This function calls `org-babel-execute:C++'. (org-babel-execute:C++ body params)) (defun org-babel-execute:C++ (body params) - Execute a block of C++ code with org-babel. This function is -called by `org-babel-execute-src-block'. + Execute a block of C++ code with org-babel. +This function is called by `org-babel-execute-src-block'. (let ((org-babel-c-variant 'cpp)) (org-babel-C-execute body params))) (defun org-babel-expand-body:C++ (body params) @@ -70,8 +70,8 @@ (defun org-babel-expand-body:C++ (body params) (let ((org-babel-c-variant 'cpp)) (org-babel-C-expand body params))) (defun org-babel-execute:C (body params) - Execute a block of C code with org-babel. This function is -called by `org-babel-execute-src-block'. + Execute a block of C code with org-babel. +This function is called by `org-babel-execute-src-block'. (let ((org-babel-c-variant 'c)) (org-babel-C-execute body params))) (defun org-babel-expand-body:c (body params) @@ -146,10 +146,10 @@ (defun org-babel-C-expand (body params) body) \n) \n))) (defun org-babel-C-ensure-main-wrap (body) - Wrap body in a \main\ function call if none exists. + Wrap BODY in a \main\ function call if none exists. (if (string-match ^[ \t]*[intvod]+[ \t\n\r]*main[ \t]*(.*) body) body -(format int main() {\n%s\nreturn(0);\n}\n body))) +(format int main() {\n%s\nreturn 0;\n}\n body))) (defun org-babel-prep-session:C (session params) This function does nothing as C is a compiled language with no @@ -163,6 +163,59 @@ (defun org-babel-load-session:C (session body params) ;; helper functions +(defun org-babel-C-format-val (type val) + Handle the FORMAT part of TYPE with the data from VAL. + (let ((format-data (cadr type))) +(if (stringp format-data) + (cons (format format-data val)) + (funcall format-data val + +(defun org-babel-C-val-to-C-type (val) + Determine the type of VAL. +Return a list (TYPE-NAME FORMAT). TYPE-NAME should be the name of the type. +FORMAT can be either a format string or a function which is called with VAL. + (cond + ((integerp val) '(int %d)) + ((floatp val) '(double %f)) + ((or (listp val) (vectorp val)) +(lexical-let ((type (org-babel-C-val-to-C-list-type val))) + (list (car type) + (lambda (val) + (cons + (format [%d]%s + (length val) + (car (org-babel-C-format-val type (elt val 0 + (concat { + (mapconcat (lambda (v) + (cdr (org-babel-C-format-val type v))) + val + , ) + })) + (t ;; treat unknown types as string +'(char (lambda (val) + (let ((s (format %s val))) ;; convert to string for unknown types +(cons (format [%d] (1+ (length s))) + (concat \ s \ + +(defun org-babel-C-val-to-C-list-type (val) + Determine the C array type of a VAL. + (let (type) +(mapc + #'(lambda (i) +(let* ((tmp-type (org-babel-C-val-to-C-type i)) + (type-name (car type)) + (tmp-type-name (car tmp-type))) + (when (and type (not (string= type-name tmp-type-name))) +(if (and (member type-name '(int double int32_t
[O] [PATCH] orgcontacts.el: Fix `date' being broken in `org-contacts-anniversaries'.
* contrib/lisp/org-contacts.el: Add defvar for date. Similar to org.el. (org-contacts-anniversaries): Setting date to nil breaks the function. Bug was introduced in e4cebbe40. Signed-off-by: Rüdiger Sonderfeld ruedi...@c-plusplus.de --- contrib/lisp/org-contacts.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/lisp/org-contacts.el b/contrib/lisp/org-contacts.el index 4ffe360..d849e7f 100644 --- a/contrib/lisp/org-contacts.el +++ b/contrib/lisp/org-contacts.el @@ -499,6 +499,7 @@ A group FOO is composed of contacts with the tag FOO. ;; show the next heading (org-flag-heading nil))) +(org-no-warnings (defvar date)) ;; unprefixed, from calendar.el (defun org-contacts-anniversaries (optional field format) Compute FIELD anniversary for each contact, returning FORMAT. Default FIELD value is \BIRTHDAY\. @@ -512,8 +513,7 @@ Format is a string matching the following format specification: (let ((calendar-date-style 'american) (entry )) (unless format (setq format org-contacts-birthday-format)) -(loop with date = nil ; FIXME: prevent a warning - for contact in (org-contacts-filter) +(loop for contact in (org-contacts-filter) for anniv = (let ((anniv (cdr (assoc-string (or field org-contacts-birthday-property) (caddr contact) -- 1.8.1.1
[O] [PATCH] org-contacts: Fix Agenda format.
* contrib/lisp/org-contacts.el: Use `org-agenda-prefix-format' to format entry instead of unused org-agenda-format. Signed-off-by: Rüdiger Sonderfeld ruedi...@c-plusplus.de --- contrib/lisp/org-contacts.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/lisp/org-contacts.el b/contrib/lisp/org-contacts.el index 49bf489..5858a07 100644 --- a/contrib/lisp/org-contacts.el +++ b/contrib/lisp/org-contacts.el @@ -544,9 +544,9 @@ This function should be called from `gnus-article-prepare-hook'. (let ((org-agenda-files (org-contacts-files)) (org-agenda-skip-function (lambda () (org-agenda-skip-if nil `(notregexp ,name -(org-agenda-format (propertize -%(org-contacts-icon-as-string)% p% s%(org-contacts-irc-number-of-unread-messages)%+T -'keymap org-contacts-keymap)) +(org-agenda-prefix-format (propertize + %(org-contacts-icon-as-string)% s%(org-contacts-irc-number-of-unread-messages) + 'keymap org-contacts-keymap)) (org-agenda-overriding-header (or org-agenda-overriding-header (concat List of contacts matching ` name ': -- 1.8.1.1
Re: [O] Patch: Mark org-diary-class as obsolete and skip entries on holidays in org-class
Hi Carsten, On Tue, 25 Oct 2011 16:08:43 +0200, Carsten Dominik carsten.domi...@gmail.com wrote: The first is accepted. The second I have modified. If any of SKIP-WEEKS is the symbol `holidays', then holidays will be skipped. That sounds good. Thank you. Regards, Rüdiger
[O] Patch: Mark org-diary-class as obsolete and skip entries on holidays in org-class
Hello, I wrote two small patches. The first one marks org-diary-class as obsolete (according to its documentation it is deprecated). The second one is a patch for org-class. It changes org-class to skip entries that are on holidays. Maybe the second change should be made optional. Regards, Rüdiger P.S. I have signed the FSF papers. From 3774298aeb959b36bf39ac0988999b94198c1984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Sonderfeld?= ruedi...@c-plusplus.de Date: Mon, 10 Oct 2011 20:59:28 +0200 Subject: [PATCH 1/2] Mark org-diary-class as obsolete (use org-class). --- lisp/org-agenda.el |1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el index b208d1e..faca285 100644 --- a/lisp/org-agenda.el +++ b/lisp/org-agenda.el @@ -4913,6 +4913,7 @@ please use `org-class' instead. (nth 2 date1) (car date1) (nth 1 date1) (nth 2 date2) (car date2) (nth 1 date2) dayname skip-weeks))) +(make-obsolete 'org-diary-class 'org-class ) (defalias 'org-get-closed 'org-agenda-get-progress) (defun org-agenda-get-progress () -- 1.7.7 From 66fdd7995556002c4b5061641dbac5c1a7788d02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Sonderfeld?= ruedi...@c-plusplus.de Date: Mon, 10 Oct 2011 21:07:02 +0200 Subject: [PATCH 2/2] org-class: Skip entries on holidays. --- lisp/org-agenda.el |3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el index faca285..8fe9cc7 100644 --- a/lisp/org-agenda.el +++ b/lisp/org-agenda.el @@ -4881,7 +4881,7 @@ This function is invoked if `org-agenda-todo-ignore-deadlines', Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS is any number of ISO weeks in the block period for which the item should -be skipped. +be skipped. Entries are also skipped if they happen on a holiday. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1))) (date2 (calendar-absolute-from-gregorian (list m2 d2 y2))) (d (calendar-absolute-from-gregorian date))) @@ -4893,6 +4893,7 @@ be skipped. (progn (require 'cal-iso) (not (member (car (calendar-iso-from-absolute d)) skip-weeks + (not (calendar-check-holidays date)) entry))) (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname rest skip-weeks) -- 1.7.7
[Orgmode] Feature Request: Timestamp with repeater interval in Date range
Hello, I have a Feature Request: It would be really great if there was (an easy way) to define a Timestamp with repeating interval but only in a specific time range. For example I want to define a repeating event on every Tuesday between 2010-10-05 and 2011-01-27: 2010-10-05 Tue 09:15-11:00 +1w--2011-01-27 Thu This would be especially useful to manage dates for university courses. Regards, Rüdiger Sonderfeld ___ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode