emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Use date in Easy Templates?


From: Nick Dokos
Subject: Re: [O] Use date in Easy Templates?
Date: Sun, 16 Feb 2014 13:08:47 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Rainer M Krug <address@hidden> 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]