sample.emacs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. ;; $Id$ -*- emacs-lisp -*-
  2. ;; This file was contributed by Mats Lidell
  3. ;; Here's a sample .emacs file that might help you along the way.
  4. ;; First comes a setup that is ideal when you are only working with curl. Just
  5. ;; select the next few lines, paste it into your .emacs and change the path to
  6. ;; the tools folder. (If you are using more than one style. Look further down
  7. ;; this file.)
  8. (load-file "<YOUR-PATH-TO-CURL>/curl-style.el")
  9. (add-hook 'c-mode-common-hook 'curl-c-mode-common-hook)
  10. ;; If you are using more than one style in maybe more than one project the
  11. ;; example below might help out. It uses a predicate hook pair to select the
  12. ;; right hook to use.
  13. (defvar my-style-selective-mode-hook nil
  14. "Holds a list of predicate and hooks pairs. (list (PREDICATE . HOOK)
  15. ...) It is used by my-mode-selective-mood-hook-function for choosing
  16. the right hook to run.")
  17. (defun my-style-selective-mode-hook-function ()
  18. "Run each PREDICATE in `my-style-selective-mode-hook' to see if the
  19. HOOK in the pair should be executed. If the PREDICATE evaluate to non
  20. nil HOOK is executed and the rest of the hooks are ignored."
  21. (let ((h my-style-selective-mode-hook))
  22. (while (not (eval (caar h)))
  23. (setq h (cdr h)))
  24. (funcall (cdar h))))
  25. ;;; Example configuration.
  26. ;; Add the selective hook to the c-mode-common-hook
  27. (add-hook 'c-mode-common-hook 'my-style-selective-mode-hook-function)
  28. ;; Add your own hooks and predicates. The predicate should evaluate to
  29. ;; non nil if the hook in the pair is supposed to be evaluated. In the
  30. ;; example a part of the path is used to select what style to
  31. ;; use. Choose what is appropriate for you.
  32. (add-hook 'my-style-selective-mode-hook
  33. '((string-match "curl" (buffer-file-name)) . curl-c-mode-common-hook))
  34. (add-hook 'my-style-selective-mode-hook
  35. '((string-match "other" (buffer-file-name)) . other-c-mode-common-hook))
  36. ;; Make sure the default style is appended.
  37. (add-hook 'my-style-selective-mode-hook '(t . my-c-mode-common-hook) t)