.emacs.d / files / defuns-macros.el

(defmacro save-kill-ring (&rest body)
  "Save the kill ring and execute the BODY.  After BODY is
executed, the kill-ring value is restored to the state before
BODY was executed"
  (declare (indent 0))
  ;; initialize new binding for the ,@body.  It starts with the global
  ;; original value.  After ,@body is executed, the new binding is
  ;; thrown away!
  `(let ((kill-ring kill-ring))

(defmacro save-buffer-list (&rest forms)
  "Execute FORMS while preserving the list of opened buffers.
After the FORMS are executed, close all buffers that were not
opened before.  This does not re-open closed buffers as that
might often be impossible."
  (declare (indent 0))
  `(let ((old-buffer-list (buffer-list)))
     (mapc (lambda (buffer)
             (when (member buffer old-buffer-list)
               (kill-buffer buffer)))

;; this is still broken :/
(defmacro with-files-in-dir (directory &rest forms)
  (declare (indent 1))
       (mapc (lambda (file)
               (find-file (concat ,directory "/" file))
             (directory-files ,directory)))))

(defmacro with-map-bind-keys (map &rest forms)
  (declare (indent 1))
     ,@(mapcar (lambda (form) (append '(bind-key) form `(,map))) forms)))

(defvar my-macro-names

(font-lock-add-keywords 'emacs-lisp-mode `((,(concat "\\<"
                                                     (regexp-opt my-macro-names 'paren)
                                            1 font-lock-keyword-face)) 'append)