From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rainer M Krug Subject: Re: Use date in Easy Templates? Date: Sun, 16 Feb 2014 20:33:54 +0100 Message-ID: <530112A2.3030203@krugs.de> References: <5300F3D8.6040104@krugs.de> <87eh33exqo.fsf@gmail.com> Reply-To: Rainer@krugs.de Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="7MtidBkupt1lgUp2OofkheatCJDdFSsNk" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:44921) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WF7TZ-0001EG-Qr for emacs-orgmode@gnu.org; Sun, 16 Feb 2014 14:34:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WF7TT-0005Gz-N0 for emacs-orgmode@gnu.org; Sun, 16 Feb 2014 14:34:05 -0500 Received: from mail-we0-f174.google.com ([74.125.82.174]:49265) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WF7TT-0005Gb-G8 for emacs-orgmode@gnu.org; Sun, 16 Feb 2014 14:33:59 -0500 Received: by mail-we0-f174.google.com with SMTP id w61so4328591wes.19 for ; Sun, 16 Feb 2014 11:33:58 -0800 (PST) In-Reply-To: <87eh33exqo.fsf@gmail.com> 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: Nick Dokos , emacs-orgmode@gnu.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --7MtidBkupt1lgUp2OofkheatCJDdFSsNk Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 02/16/14, 19:08 , Nick Dokos wrote: > Rainer M Krug writes: >=20 >> is it possible to insert the actual date into Easy Templates? >> That's what I thought as well. >=20 > No - but it's not difficult to crib the %file code and add %date: >=20 > --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) (poi= nt)))) > (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)))) >=20 > --8<---------------cut here---------------end--------------->8--- >=20 > 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? >=20 > 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=20 >=20 > ("thingie" . thingie-function) >=20 > pairs... That sounds like a good idea which would make the Easy Templates more powerful. Cheers, Rainer >=20 > Footnotes: >=20 > [fn:1] Yet Another Customization Variable :-) >=20 --=20 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 --7MtidBkupt1lgUp2OofkheatCJDdFSsNk Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.22 (Darwin) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJTARKiAAoJENvXNx4PUvmCZhoH/0oEf/3JEYADOk+7+5pQyJzC vWz0h+uFn2PAW1DewAmCcewcbaUaShDvZ70GX07SmXlb7YLnuPl3GRr2MbIkQGdS HojlYwCWVYfF7QzCvag0Gz4CPoK/OKTH7ByaBReTvfE82nS3wQs7sEDFWJPRcDK7 8seEA+lzjGAKrl7Hoq1CB+FpkFX8M8GhkVfv06ez/EkmoTRI+KcF0fpcn2H2pTbd UJFV/yb0bFaDU4Ki3m1ecUYkjPJ0l47GRHvETslilSoMJi3z7Rw/rH3UR3BlNG/i YgLGQ4MCP8EHldyx1e6GD+KfeZCRNTT45RGXwZ3zStc5zT8MiS2GiEwi6WXaTOM= =tCzU -----END PGP SIGNATURE----- --7MtidBkupt1lgUp2OofkheatCJDdFSsNk--