From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: Use date in Easy Templates? Date: Fri, 21 Feb 2014 10:26:20 -0500 Message-ID: References: <5300F3D8.6040104@krugs.de> <87eh33exqo.fsf@gmail.com> <530112A2.3030203@krugs.de> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=e89a8ff2569c6f139e04f2ec3eac Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:48551) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGrzc-0001TF-J0 for emacs-orgmode@gnu.org; Fri, 21 Feb 2014 10:26:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WGrzb-0002AZ-35 for emacs-orgmode@gnu.org; Fri, 21 Feb 2014 10:26:24 -0500 Received: from mail-pa0-x22a.google.com ([2607:f8b0:400e:c03::22a]:44381) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGrza-0002AI-Na for emacs-orgmode@gnu.org; Fri, 21 Feb 2014 10:26:23 -0500 Received: by mail-pa0-f42.google.com with SMTP id kl14so3589414pab.29 for ; Fri, 21 Feb 2014 07:26:20 -0800 (PST) In-Reply-To: <530112A2.3030203@krugs.de> 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-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Rainer@krugs.de Cc: Nick Dokos , "emacs-orgmode@gnu.org" --e89a8ff2569c6f139e04f2ec3eac Content-Type: text/plain; charset=ISO-8859-1 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 wrote: > > > On 02/16/14, 19:08 , Nick Dokos wrote: > > Rainer M Krug 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 > > --e89a8ff2569c6f139e04f2ec3eac Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
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<= br>412-268-7803
http://kitchingroup.cheme.cmu.edu



On Sun, Feb 16, 2014 at 2:33 PM, Rainer = M Krug <Rainer@krugs.de> wrote:
That's what I thought as well.

>
> No - but it's not difficult to crib the %file code and add %date:<= br> >
> --8<---------------cut here---------------start------------->8--= -
> (defun org-complete-expand-structure-template (start cell)
> =A0 "Expand a structure template."
> =A0 (let* ((musep (org-bound-and-true-p org-mtags-prefer-muse-template= s))
> =A0 =A0 =A0 =A0(rpl (nth (if musep 2 1) cell))
> =A0 =A0 =A0 =A0(ind ""))
> =A0 =A0 (delete-region start (point))
> =A0 =A0 (when (string-match "\\`#\\+" rpl)
> =A0 =A0 =A0 (cond
> =A0 =A0 =A0 =A0((bolp))
> =A0 =A0 =A0 =A0((not (string-match "\\S-" (buffer-substring = (point-at-bol) (point))))
> =A0 =A0 =A0 (setq ind (buffer-substring (point-at-bol) (point))))
> =A0 =A0 =A0 =A0(t (newline))))
> =A0 =A0 (setq start (point))
> =A0 =A0 (if (string-match "%file" rpl)
> =A0 =A0 =A0 (setq rpl (replace-match
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(concat
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "\""
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (save-match-data
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (abbreviate-file-name (read-fi= le-name "Include file: ")))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "\"")
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0t t rpl)))
> ;;; ADDED CODE
> =A0 =A0 (if (string-match "%date" rpl)
> =A0 =A0 =A0 (setq rpl (replace-match
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (save-match-data
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (format-time-string "%Y-%= m-%d" (current-time)))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0t t rpl)))
> ;;; END OF ADDED CODE
> =A0 =A0 (setq rpl (mapconcat 'identity (split-string rpl "\n&= quot;)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(concat "\n" = ind)))
> =A0 =A0 (insert rpl)
> =A0 =A0 (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 th= e
> 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<= br> > can be added by customizing YACV, probably an alist of
>
> =A0("thingie" . thingie-function)
>
> pairs...

That sounds like a good idea which would make the Easy Template= s more
powerful.

Cheers,

Rainer

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

--

--e89a8ff2569c6f139e04f2ec3eac--