Advertisement
Vermiculus

Untitled

Dec 19th, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 2.34 KB | None | 0 0
  1. ; Enables the given minor mode for the current buffer it it matches regex
  2. ; my-pair is a cons cell (regular-expression . minor-mode)
  3. ;(defun enable-minor-mode (my-pair)
  4. ;  (if (buffer-file-name) ; If we are visiting a file,
  5. ;      (if (string-match (car my-pair) buffer-file-name) ; and the filename matches our regular expression,
  6. ;     (funcall (cdr my-pair))))) ; enable the minor mode
  7.  
  8. ;; the wrapping up of the two loads make sure
  9. ;; auctex is loaded only when editing tex files.
  10. (eval-after-load "tex-mode"
  11.   '(progn
  12.      (load "auctex.el"  nil nil t)
  13.      (load "preview-latex.el" nil nil t)
  14.      )
  15.   )
  16.  
  17. ; Sets my default directory to my dropbox (platform-dependent)
  18. (setq default-directory
  19.       (concat
  20.        (if (eq system-type 'windows-nt)
  21.        "t:" "~")
  22.        "/Dropbox/Public/School/TeX/"))
  23.  
  24. ; Sets up the notes extension
  25.  
  26. (defvar auto-minor-mode-alist ()
  27.   "Alist of filename patterns vs correpsonding minor mode functions, see `auto-mode-alist'
  28. All elements of this alist are checked, meaning you can enable multiple minor modes for the same regexp.")
  29.  
  30.  
  31. (setq auto-mode-alist
  32.       (cons '("\\.notes$" . text-mode) auto-mode-alist))
  33. (setq auto-minor-mode-alist
  34.       (cons '("\\.notes$" . auto-fill-mode) auto-minor-mode-alist))
  35.  
  36. (defun enable-minor-mode-based-on-extension ()
  37.   "check file name against auto-minor-mode-alist to enable minor modes
  38. the checking happens for all pairs in auto-minor-mode-alist"
  39.   (when buffer-file-name
  40.     (let ((name buffer-file-name)
  41.           (remote-id (file-remote-p buffer-file-name))
  42.           (alist auto-minor-mode-alist))
  43.       ;; Remove backup-suffixes from file name.
  44.       (setq name (file-name-sans-versions name))
  45.       ;; Remove remote file name identification.
  46.       (when (and (stringp remote-id)
  47.                  (string-match-p (regexp-quote remote-id) name))
  48.         (setq name (substring name (match-end 0))))
  49.       (while (and alist (caar alist) (cdar alist))
  50.         (if (string-match (caar alist) name)
  51.             (funcall (cdar alist) 1))
  52.         (setq alist (cdr alist))))))
  53.  
  54. (add-hook 'find-file-hook 'enable-minor-mode-based-on-extension)
  55.  
  56.  
  57. ;; AUCTeX replaces latex-mode-hook with LaTeX-mode-hook
  58. (add-hook 'LaTeX-mode-hook
  59. (lambda ()
  60. (setq TeX-auto-save t)
  61. (setq TeX-parse-self t)
  62. ;; (setq-default TeX-master nil)
  63. (reftex-mode t)
  64. (TeX-fold-mode t)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement