emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Use date in Easy Templates?
@ 2014-02-16 17:22 Rainer M Krug
  2014-02-16 18:08 ` Nick Dokos
  0 siblings, 1 reply; 4+ messages in thread
From: Rainer M Krug @ 2014-02-16 17:22 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi

is it possible to insert the actual date into Easy Templates?

Thanks,

Rainer


-- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :       +33 - (0)9 53 10 27 44
Cell:       +33 - (0)6 85 62 59 98
Fax :       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      Rainer@krugs.de

Skype:      RMkrug


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 560 bytes --]

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

* Re: Use date in Easy Templates?
  2014-02-16 17:22 Use date in Easy Templates? Rainer M Krug
@ 2014-02-16 18:08 ` Nick Dokos
  2014-02-16 19:33   ` Rainer M Krug
  0 siblings, 1 reply; 4+ messages in thread
From: Nick Dokos @ 2014-02-16 18:08 UTC (permalink / raw)
  To: emacs-orgmode

Rainer M Krug <Rainer@krugs.de> writes:

> is it possible to insert the actual date into Easy Templates?
>

No - but it's not difficult to crib the %file code and add %date:

--8<---------------cut here---------------start------------->8---
(defun org-complete-expand-structure-template (start cell)
  "Expand a structure template."
  (let* ((musep (org-bound-and-true-p org-mtags-prefer-muse-templates))
	 (rpl (nth (if musep 2 1) cell))
	 (ind ""))
    (delete-region start (point))
    (when (string-match "\\`#\\+" rpl)
      (cond
       ((bolp))
       ((not (string-match "\\S-" (buffer-substring (point-at-bol) (point))))
	(setq ind (buffer-substring (point-at-bol) (point))))
       (t (newline))))
    (setq start (point))
    (if (string-match "%file" rpl)
	(setq rpl (replace-match
		   (concat
		    "\""
		    (save-match-data
		      (abbreviate-file-name (read-file-name "Include file: ")))
		    "\"")
		   t t rpl)))
;;; ADDED CODE
    (if (string-match "%date" rpl)
	(setq rpl (replace-match
		    (save-match-data
		      (format-time-string "%Y-%m-%d" (current-time)))
		   t t rpl)))
;;; END OF ADDED CODE
    (setq rpl (mapconcat 'identity (split-string rpl "\n")
			 (concat "\n" ind)))
    (insert rpl)
    (if (re-search-backward "\\?" start t) (delete-char 1))))

--8<---------------cut here---------------end--------------->8---

However, the next thing somebody will ask is a different format for the
date which will require YACV[fn:1]. But maybe one exists already?

And the next thing is more of these %thingies... so it would be better
to add yet another layer to the function, so that arbitrary %thingies
can be added by customizing YACV, probably an alist of 

 ("thingie" . thingie-function)

pairs...

Footnotes:

[fn:1] Yet Another Customization Variable :-)

-- 
Nick

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

* Re: Use date in Easy Templates?
  2014-02-16 18:08 ` Nick Dokos
@ 2014-02-16 19:33   ` Rainer M Krug
  2014-02-21 15:26     ` John Kitchin
  0 siblings, 1 reply; 4+ messages in thread
From: Rainer M Krug @ 2014-02-16 19:33 UTC (permalink / raw)
  To: Nick Dokos, emacs-orgmode

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



On 02/16/14, 19:08 , Nick Dokos wrote:
> Rainer M Krug <Rainer@krugs.de> writes:
> 
>> is it possible to insert the actual date into Easy Templates?
>>

That's what I thought as well.

> 
> No - but it's not difficult to crib the %file code and add %date:
> 
> --8<---------------cut here---------------start------------->8---
> (defun org-complete-expand-structure-template (start cell)
>   "Expand a structure template."
>   (let* ((musep (org-bound-and-true-p org-mtags-prefer-muse-templates))
> 	 (rpl (nth (if musep 2 1) cell))
> 	 (ind ""))
>     (delete-region start (point))
>     (when (string-match "\\`#\\+" rpl)
>       (cond
>        ((bolp))
>        ((not (string-match "\\S-" (buffer-substring (point-at-bol) (point))))
> 	(setq ind (buffer-substring (point-at-bol) (point))))
>        (t (newline))))
>     (setq start (point))
>     (if (string-match "%file" rpl)
> 	(setq rpl (replace-match
> 		   (concat
> 		    "\""
> 		    (save-match-data
> 		      (abbreviate-file-name (read-file-name "Include file: ")))
> 		    "\"")
> 		   t t rpl)))
> ;;; ADDED CODE
>     (if (string-match "%date" rpl)
> 	(setq rpl (replace-match
> 		    (save-match-data
> 		      (format-time-string "%Y-%m-%d" (current-time)))
> 		   t t rpl)))
> ;;; END OF ADDED CODE
>     (setq rpl (mapconcat 'identity (split-string rpl "\n")
> 			 (concat "\n" ind)))
>     (insert rpl)
>     (if (re-search-backward "\\?" start t) (delete-char 1))))
> 
> --8<---------------cut here---------------end--------------->8---
> 
> However, the next thing somebody will ask is a different format for the
> date which will require YACV[fn:1]. But maybe one exists already?
> 
> And the next thing is more of these %thingies... so it would be better
> to add yet another layer to the function, so that arbitrary %thingies
> can be added by customizing YACV, probably an alist of 
> 
>  ("thingie" . thingie-function)
> 
> pairs...

That sounds like a good idea which would make the Easy Templates more
powerful.

Cheers,

Rainer

> 
> Footnotes:
> 
> [fn:1] Yet Another Customization Variable :-)
> 

-- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :       +33 - (0)9 53 10 27 44
Cell:       +33 - (0)6 85 62 59 98
Fax :       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      Rainer@krugs.de

Skype:      RMkrug


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 560 bytes --]

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

* Re: Use date in Easy Templates?
  2014-02-16 19:33   ` Rainer M Krug
@ 2014-02-21 15:26     ` John Kitchin
  0 siblings, 0 replies; 4+ messages in thread
From: John Kitchin @ 2014-02-21 15:26 UTC (permalink / raw)
  To: Rainer; +Cc: Nick Dokos, emacs-orgmode@gnu.org

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

I solved a similar problem to this with yasnippets:

http://kitchingroup.cheme.cmu.edu/blog/2014/02/16/A-dynamic-snippet-for-a-task-due-7-days-from-now/

You can dynamically evaluate lisp code in the snippet when it is expanded.
That way you can get whatever format suits you!

John

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



On Sun, Feb 16, 2014 at 2:33 PM, Rainer M Krug <Rainer@krugs.de> wrote:

>
>
> On 02/16/14, 19:08 , Nick Dokos wrote:
> > Rainer M Krug <Rainer@krugs.de> writes:
> >
> >> is it possible to insert the actual date into Easy Templates?
> >>
>
> That's what I thought as well.
>
> >
> > No - but it's not difficult to crib the %file code and add %date:
> >
> > --8<---------------cut here---------------start------------->8---
> > (defun org-complete-expand-structure-template (start cell)
> >   "Expand a structure template."
> >   (let* ((musep (org-bound-and-true-p org-mtags-prefer-muse-templates))
> >        (rpl (nth (if musep 2 1) cell))
> >        (ind ""))
> >     (delete-region start (point))
> >     (when (string-match "\\`#\\+" rpl)
> >       (cond
> >        ((bolp))
> >        ((not (string-match "\\S-" (buffer-substring (point-at-bol)
> (point))))
> >       (setq ind (buffer-substring (point-at-bol) (point))))
> >        (t (newline))))
> >     (setq start (point))
> >     (if (string-match "%file" rpl)
> >       (setq rpl (replace-match
> >                  (concat
> >                   "\""
> >                   (save-match-data
> >                     (abbreviate-file-name (read-file-name "Include file:
> ")))
> >                   "\"")
> >                  t t rpl)))
> > ;;; ADDED CODE
> >     (if (string-match "%date" rpl)
> >       (setq rpl (replace-match
> >                   (save-match-data
> >                     (format-time-string "%Y-%m-%d" (current-time)))
> >                  t t rpl)))
> > ;;; END OF ADDED CODE
> >     (setq rpl (mapconcat 'identity (split-string rpl "\n")
> >                        (concat "\n" ind)))
> >     (insert rpl)
> >     (if (re-search-backward "\\?" start t) (delete-char 1))))
> >
> > --8<---------------cut here---------------end--------------->8---
> >
> > However, the next thing somebody will ask is a different format for the
> > date which will require YACV[fn:1]. But maybe one exists already?
> >
> > And the next thing is more of these %thingies... so it would be better
> > to add yet another layer to the function, so that arbitrary %thingies
> > can be added by customizing YACV, probably an alist of
> >
> >  ("thingie" . thingie-function)
> >
> > pairs...
>
> That sounds like a good idea which would make the Easy Templates more
> powerful.
>
> Cheers,
>
> Rainer
>
> >
> > Footnotes:
> >
> > [fn:1] Yet Another Customization Variable :-)
> >
>
> --
> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
> Biology, UCT), Dipl. Phys. (Germany)
>
> Centre of Excellence for Invasion Biology
> Stellenbosch University
> South Africa
>
> Tel :       +33 - (0)9 53 10 27 44
> Cell:       +33 - (0)6 85 62 59 98
> Fax :       +33 - (0)9 58 10 27 44
>
> Fax (D):    +49 - (0)3 21 21 25 22 44
>
> email:      Rainer@krugs.de
>
> Skype:      RMkrug
>
>

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

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

end of thread, other threads:[~2014-02-21 15:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-16 17:22 Use date in Easy Templates? Rainer M Krug
2014-02-16 18:08 ` Nick Dokos
2014-02-16 19:33   ` Rainer M Krug
2014-02-21 15:26     ` John Kitchin

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).