From: Nick Dokos <ndokos@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: Use date in Easy Templates?
Date: Sun, 16 Feb 2014 13:08:47 -0500 [thread overview]
Message-ID: <87eh33exqo.fsf@gmail.com> (raw)
In-Reply-To: 5300F3D8.6040104@krugs.de
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
next prev parent reply other threads:[~2014-02-16 18:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-16 17:22 Use date in Easy Templates? Rainer M Krug
2014-02-16 18:08 ` Nick Dokos [this message]
2014-02-16 19:33 ` Rainer M Krug
2014-02-21 15:26 ` John Kitchin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87eh33exqo.fsf@gmail.com \
--to=ndokos@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).