Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs function to open file [current date].tex

I'm trying to write an emacs function that uses the current date to create a file. I'm new to emacs and so I'm having trouble with variables and syntax. Here's what I have:

(defun daily ()
    (interactive)
    (let daily-name (format-time-string "%T"))
    (find-file (daily-name)))

I don't understand how emacs uses variables well enough to get it to set the time string as a variable and feed that variable into the find-file function. Any help is appreciated.

like image 687
Iovan Avatar asked Feb 16 '11 17:02

Iovan


3 Answers

To build on what others are saying:

(defun daily-tex-file ()
  (interactive)
  (let ((daily-name (format-time-string "%Y-%m-%d")))
    (find-file (expand-file-name (concat "~/" daily-name ".tex")))))

Main differences:

  • Different format string, which gives date instead of time (which is what you want, I think)
  • specifying the directory (~/) -- if you don't put this, you'll get files all over the place, depending on what the current working directory is at the moment you invoke the function
  • better function name
like image 115
Joe Casadonte Avatar answered Oct 21 '22 03:10

Joe Casadonte


(defun daily ()
  (interactive)
  (let ((daily-name (format-time-string "%T")))
    (find-file (format "%s.tex" daily-name))))

Calling M-x daily now opens a file "12:34:56.tex".

like image 1
nominolo Avatar answered Oct 21 '22 03:10

nominolo


(defun daily ()     
  (interactive)     
  (let ((daily-name (format-time-string "%T")))
      (find-file (concat daily-name ".tex"))))
like image 1
John Avatar answered Oct 21 '22 01:10

John