  "C-x C-b"  ibuffer
  "M-n"      cua-scroll-up
  "M-p"      cua-scroll-down
- "<M-f4>"   ng/delete-frame-or-exit
+ "<M-f4>"   ng/quit
+ "s-q"      ng/quit
+ "C-x C-c"  ng/quit
  "C-x C-k"  ng/kill-other-buffer-and-window
  "C-x k"    ng/kill-this-buffer-and-window
  "<C-tab>"  next-buffer

;; use common lisp extensions below
(eval-when-compile (require 'cl))

;; disable startup message
(setq inhibit-startup-message t)

      (unless (eq new-window old-window)
        (delete-window new-window)))))

;; make exit commands kill extra frames without quitting and when
;; there's only one frame left, hide without exiting. The idea is
;; to keep emacs alive for emacsclient.
(defun ng/quit ()
  (interactive)

  ;; if we have more than one frame, just delete the current frame.
  (when multiple-frames
    (delete-frame)
    (return))

  ;; if we're not in a Mac OS X GUI frame, exit
  (when (or (not window-system)
            (not (eq system-type 'darwin)))
    (save-buffers-kill-terminal)
    (return))

  ;; if we are in a Mac OS GUI frame, kill all buffers and hide.
  (save-some-buffers)
  (dolist (b (buffer-list))
    (kill-buffer b))

  (do-applescript
   (concat
    "tell application \"System Events\" "
          "to tell process \"Emacs\" "
          "to set visible to false")))

(defadvice handle-delete-frame (around ng/hdf activate)
  (if multiple-frames
      ad-do-it
    (ng/quit)))
