kaushalmodi / .emacs.d

My emacs configuration
MIT License
261 stars 49 forks source link

Pass also milliseconds to destructuring-bind #7

Closed ReneFroger closed 9 years ago

ReneFroger commented 9 years ago

Hi there! Thanks for sharing your Emacs configuration.

I looked at your .emacs configuration to get more insipiration. I liked the ability to record the startup time of the emacs. So I wanted to steal your snippet of code. Currently I have the following in my init.el

;; Record the start time
(setq *emacs-load-start* (current-time))

(require 'package)
(package-initialize)

[Block of my preciousss configuration] 

  ;; Load destructuring-bind, which seems to be a common lisp function.
  (eval-when-compile (require 'cl))
  (eval-when-compile (require 'cl-lib))

;; Write out a message indicating how long it took to process the init script
(defun startup-time () 
    (message "Yo dude, Emacs recorded %f seconds to get started!"
         (destructuring-bind (hi lo ms ps) (current-time)
           (- (+ hi lo)
              (+ (first *emacs-load-start*)
                 (second *emacs-load-start*)))))
)

(add-hook 'emacs-startup-hook 'startup-time)

Everything worked fine at all. I wanted to get the milliseconds, so I see Emacs started up in 3.11 seconds instead Emacs started up in 3 seconds in the messages buffer. So I replaced the %d with the floating %f. However, I get zero decimals. I could't find anything in the documentation of destructuring-bind, to pass the milliseconds.

Any suggestion?

ReneFroger commented 9 years ago

I found much better alternative, propbably it is even faster and more clean codebase without the need to put emacs-load-start and startup-time in your init.el.

Add the following in your setup-hooks:

(defun startup-time() 
   (message (concat "init.el loaded in " (emacs-init-time) ".")))
  )

(add-hook 'emacs-startup-hook 'startup-time)
kaushalmodi commented 9 years ago

Thanks for that suggestion! I am now using that in my config. I had stolen that earlier snippet from somewhere when I had just started learning elisp :)