* counter macro doesn't increment when additional macro is on same line
@ 2017-08-26 21:09 Matt Price
2017-08-27 0:07 ` Matt Price
0 siblings, 1 reply; 2+ messages in thread
From: Matt Price @ 2017-08-26 21:09 UTC (permalink / raw)
To: Org Mode
[-- Attachment #1: Type: text/plain, Size: 1874 bytes --]
the {{{n}}} macro seems to reset to "1" if it is located on the same line
as another macro that I've defined. I'm not sure if it's error with my
macro or some kind or race condition-ish problem in macro expansion.
Here's a minimal example:
--------
#+MACRO: ts (eval (get-ts+7))
#+BEGIN_SRC emacs-lisp
(defun mwp-add-week-to-next-ts ()
(interactive )
(save-excursion
(re-search-forward org-ts-regexp)
(let ((base (match-string 0)))
(message base)
(message (format-time-string "<%Y-%m-%d %a>"
(time-add (date-to-time base)
(days-to-time (1+ 7)))))
(replace-match (format-time-string "<%Y-%m-%d %a>"
(time-add (date-to-time base)
(seconds-to-time (1+(* 7 60 60 24))))) nil nil nil nil))))
#+END_SRC
(week {{{n(w)}}})
(week {{{n(w)}}})
(week {{{n(w)}}})
** <2017-09-12 Tue> (Week {{{n(w)}}}) Hacking History in the Himalaya
** {{{ts}}} (Week {{{n(w)}}}) Language of the Web
-----------------
And here's the ASCII export:
------
Matt Price
,----
| (defun mwp-add-week-to-next-ts ()
| (interactive )
| (save-excursion
| (re-search-forward org-ts-regexp)
|
| (let ((base (match-string 0)))
| (message base)
| (message (format-time-string "<%Y-%m-%d %a>"
| (time-add (date-to-time base)
(days-to-time (1+ 7)))))
|
| (replace-match (format-time-string "<%Y-%m-%d %a>"
| (time-add (date-to-time base)
(seconds-to-time (1+(* 7 60 60 24))))) nil nil nil nil))))
`----
1
2
3
<2017-09-12 Tue> (Week 4) Hacking History in the Himalaya
==========================================================
<2017-09-19 Tue> (Week 1) Language of the Web
==============================================
-----------------
Any thoughts? thank you!
[-- Attachment #2: Type: text/html, Size: 2599 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: counter macro doesn't increment when additional macro is on same line
2017-08-26 21:09 counter macro doesn't increment when additional macro is on same line Matt Price
@ 2017-08-27 0:07 ` Matt Price
0 siblings, 0 replies; 2+ messages in thread
From: Matt Price @ 2017-08-27 0:07 UTC (permalink / raw)
To: Org Mode
[-- Attachment #1: Type: text/plain, Size: 3352 bytes --]
Argh, wish I could delete this post. I was using a defective macro
definition (I pasted the wrong code in my original post!):
(defun get-ts+7 ()
(interactive)
(let ((base-date (save-excursion
(re-search-backward
(org-re-timestamp 'all))
(match-string 0)))
(result nil))
(with-temp-buffer
(org-mode)
(insert base-date )
(backward-char)
(org-timestamp-change 7 'day)
(end-of-buffer)
(insert " ")
(end-of-buffer)
(setq result (save-excursion
(re-search-backward
(org-re-timestamp 'all))
(match-string 0))))
result))
--
something about that buffer switching gets org confused -- maybe the value
of hte {{{n}}} gets reset when the temp buffer is initialized? -- anyway,
this much simpler defun solves the problem:
(defun get-ts+7 ()
(interactive)
(let ((base-date (save-excursion
(re-search-backward
(org-re-timestamp 'all))
(match-string 0)))
(result nil))
(format-time-string "<%Y-%m-%d %a>"
(time-add
(date-to-time base-date) (days-to-time (1+ 7))))
))
On Sat, Aug 26, 2017 at 5:09 PM, Matt Price <moptop99@gmail.com> wrote:
>
> the {{{n}}} macro seems to reset to "1" if it is located on the same line
> as another macro that I've defined. I'm not sure if it's error with my
> macro or some kind or race condition-ish problem in macro expansion.
> Here's a minimal example:
>
> --------
> #+MACRO: ts (eval (get-ts+7))
>
> #+BEGIN_SRC emacs-lisp
> (defun mwp-add-week-to-next-ts ()
> (interactive )
> (save-excursion
> (re-search-forward org-ts-regexp)
>
> (let ((base (match-string 0)))
> (message base)
> (message (format-time-string "<%Y-%m-%d %a>"
> (time-add (date-to-time base)
> (days-to-time (1+ 7)))))
>
> (replace-match (format-time-string "<%Y-%m-%d %a>"
> (time-add (date-to-time base)
> (seconds-to-time (1+(* 7 60 60 24))))) nil nil nil nil))))
> #+END_SRC
>
> (week {{{n(w)}}})
>
> (week {{{n(w)}}})
>
> (week {{{n(w)}}})
>
>
> ** <2017-09-12 Tue> (Week {{{n(w)}}}) Hacking History in the Himalaya
>
> ** {{{ts}}} (Week {{{n(w)}}}) Language of the Web
>
> -----------------
>
> And here's the ASCII export:
>
> ------
> Matt Price
>
>
> ,----
> | (defun mwp-add-week-to-next-ts ()
> | (interactive )
> | (save-excursion
> | (re-search-forward org-ts-regexp)
> |
> | (let ((base (match-string 0)))
> | (message base)
> | (message (format-time-string "<%Y-%m-%d %a>"
> | (time-add (date-to-time base)
> (days-to-time (1+ 7)))))
> |
> | (replace-match (format-time-string "<%Y-%m-%d %a>"
> | (time-add (date-to-time base)
> (seconds-to-time (1+(* 7 60 60 24))))) nil nil nil nil))))
> `----
>
> 1
>
> 2
>
> 3
>
>
> <2017-09-12 Tue> (Week 4) Hacking History in the Himalaya
> ==========================================================
>
>
> <2017-09-19 Tue> (Week 1) Language of the Web
> ==============================================
> -----------------
>
> Any thoughts? thank you!
>
>
>
[-- Attachment #2: Type: text/html, Size: 4791 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-08-27 0:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-26 21:09 counter macro doesn't increment when additional macro is on same line Matt Price
2017-08-27 0:07 ` Matt Price
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).