;;; auctex-init.el --- Initialize AUCTeX

;; This file is part of Michael Olson's Emacs settings.

;; The code in this file may be used, distributed, and modified
;; without restriction.

;; I use initsplit.el to separate customize settings on a per-project
;; basis.

;; Set load path
;(add-to-list 'load-path "/usr/share/emacs/site-lisp/auctex")
;(add-to-list 'load-path "/usr/share/emacs/site-lisp/auctex/style")

;; Load AUCTeX
;;(load "rng-auto")
;;(require 'tex-site)

;;; Functions

;; Force AUCTeX items to the end of the load path, since they have a
;; suboptimal version of url.el.
(defun my-sift-list (list test)
  "Remove items from LIST where calling TEST with the item yields non-nil.
The removed items are returned.
LIST should be the symbol of the list, not the list itself."
  (let ((seq (symbol-value list))
        removed)
    ;; remove from car
    (while (when (funcall test (car seq))
             (setq removed (cons (car seq) removed)
                   seq (cdr seq))))
    ;; remove from cdr
    (let ((ptr seq)
          (next (cdr seq)))
      (while next
        (when (funcall test (car next))
          (setq removed (cons (car next) removed))
          (setcdr ptr (if (consp next)
                          (cdr next)
                        nil)))
        (setq ptr (cdr ptr))
        (setq next (cdr ptr))))
    (set list seq)
    removed))

(when (and (not (featurep 'xemacs))
           (> emacs-major-version 21))
  (let ((auctex (my-sift-list 'load-path
                              #'(lambda (item)
                                  (string-match "/auctex/" item)))))
    (nconc load-path (nreverse auctex))))

;;; Customizations

;;; auctex-init.el ends here