From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Price Subject: Re: counter macro doesn't increment when additional macro is on same line Date: Sat, 26 Aug 2017 20:07:18 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="94eb2c12e5e22127050557b0f611" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43471) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dll6s-0004nQ-8x for emacs-orgmode@gnu.org; Sat, 26 Aug 2017 20:07:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dll6m-0003hR-E5 for emacs-orgmode@gnu.org; Sat, 26 Aug 2017 20:07:21 -0400 Received: from mail-pf0-x22f.google.com ([2607:f8b0:400e:c00::22f]:35319) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dll6m-0003gx-4V for emacs-orgmode@gnu.org; Sat, 26 Aug 2017 20:07:20 -0400 Received: by mail-pf0-x22f.google.com with SMTP id c15so5731633pfm.2 for ; Sat, 26 Aug 2017 17:07:20 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Org Mode --94eb2c12e5e22127050557b0f611 Content-Type: text/plain; charset="UTF-8" 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 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! > > > --94eb2c12e5e22127050557b0f611 Content-Type: text/html; charset="UTF-8" Content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