Great Emacs Lisp Snippets

'Inserting a timestamp: '

 (defun my-insert-timeofday ()
  "function to insert time of day at point . format: DayOfWeek, Date Month Year24hrTime"
  (interactive)
  (let (localstring mytime)
(setq localstring (current-time-string))
; example:  Mon, 17 Jun 96  12:52
(setq mytime (concat (substring localstring 0 3)  ;day-of-week
 ", " 
 (substring localstring 8 10) ;day number
 " "
 (substring localstring 4 7)  ;month 
 " "
 (substring localstring 22 24 ) ;2-digit year
 "  "
 (substring localstring 11 16 ) ;24-hr time
 "\n"
 ))
(insert mytime))
 ) 

(global-set-key "\C-ct"'my-insert-timeofday)


A more concise version:

 (defun my-insert-timeofday ()
   (interactive "*")
   (insert (format-time-string "%a, %d %b %y %H:%M\n")))


or just:

Bind control-u meta-! date to \C-ct like this:

   (global-set-key [(control c) ?t]
     (function (lambda () (interactive) (shell-command "date" 0))))

'Help for confused vi users'

  (setq wq "You're not using vi!")

'What file was I editing anyway?'

  (define-key global-map "\C-c\C-sf" 
    '(lambda () (interactive nil) (message "%s" (buffer-file-name))))


See also EmacsWiki, which seems to be made for stuff like this.

Also http://github.com/trending?l=emacs-lisp


CategoryEmacs


EditText of this page (last edited July 28, 2014) or FindPage with title or text search