home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / gnu / emacs / help / 4771 < prev    next >
Encoding:
Text File  |  1992-11-12  |  1.8 KB  |  52 lines

  1. Newsgroups: gnu.emacs.help
  2. Path: sparky!uunet!stanford.edu!agate!ames!sun-barr!cs.utexas.edu!usc!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbnewsk!cbnewsj!att-out!cbnewsh!cbnewsh!tds
  3. From: tds@hoserve.att.com (Tony DeSimone)
  4. Subject: Re: HELP: function insert current date and time into buffer
  5. Reply-To: tds@hoserve.att.com (Tony DeSimone)
  6. Organization: AT&T Bell Laboratories
  7. Date: Thu, 12 Nov 1992 20:38:43 GMT
  8. Message-ID: <TDS.92Nov12153843@qpc1.ATT.COM>
  9. In-Reply-To: ron@wc18.yorku.ca's message of Thu, 12 Nov 1992 19:09:56 GMT
  10. References: <1992Nov7.214255.14388@magnus.acs.ohio-state.edu>
  11.     <RON.92Nov12140956@wc18.yorku.ca>
  12. Sender: news@cbnewsh.cb.att.com (NetNews Administrator)
  13. Nntp-Posting-Host: qpc1.ho.att.com
  14. Lines: 36
  15.  
  16. >>>>> On Thu, 12 Nov 1992 19:09:56 GMT, ron@wc18.yorku.ca (Ron Sheese) said:
  17.  
  18. Ron> Hi, all,
  19.  
  20. Ron> Is there a function in emacs which can insert the current date and
  21. Ron> time into current buffer?
  22.  
  23. This is what I have in my .emacs, to make things like [tds 92/11/12 15:38].
  24.  
  25. (defconst month-number-alist 
  26.   '(("Jan" . "01") ("Feb" . "02") ("Mar" . "03")
  27.     ("Apr" . "04") ("May" . "05") ("Jun" . "06")
  28.     ("Jul" . "07") ("Aug" . "08") ("Sep" . "09")
  29.     ("Oct" . "10") ("Nov" . "11") ("Dec" . "12"))
  30.   "assoc list of months/numeric string numbers.")
  31.  
  32. (defun insert-date-stamp ()
  33.   "Put date-stamp at point."
  34.   (interactive)
  35.   (let ((date (current-time-string)))
  36.     (insert "[" (getenv "USER") " " 
  37.         (substring date -2 nil)    ; yyyy
  38.         "/"
  39.         (cdr (assoc (substring date 4 7)
  40.             month-number-alist)) ; MM
  41.         "/"
  42.         (let ((d (substring date 8 9)))
  43.           (if (equal d " ") "0" d))
  44.         (substring date 9 10)    ; d
  45.         " "
  46.         (substring date 11 13)    ; hh
  47.         ":"
  48.         (substring date 14 16)    ; mm
  49.         "]")))
  50. (global-set-key "\C-cd" 'insert-date-stamp)
  51.  
  52.