Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 672a10f523
Fetching contributors…

Cannot retrieve contributors at this time

file 96 lines (93 sloc) 3.212 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
(defvar rafl:buffer-settings)
(setq rafl:buffer-settings
      '((((:not ((:mode "^gnus") (:mode w3m-mode) (:mode "^erc")
                 (:mode eshell-mode) (:mode term-mode))))
         (lambda ()
           (highlight-beyond-fill-column)))
        ((:not ((:mode eshell-mode) (:mode term-mode)))
         (lambda () (hl-line-mode t)))
        (((:mode message-mode)
          (:mode org-mode)
          (:mode pod-mode)
          (:mode markdown-mode)
          (:mode git-commit-mode)
          (:filename "\\.\\(txt\\|mkn\\)$"))
         (lambda ()
           (flyspell-mode 1)
           (auto-fill-mode 1)))
        (((:mode c-mode)
          (:mode cperl-mode)
          (:mode emacs-lisp-mode))
         (lambda ()
           (flyspell-prog-mode)))
        (((:project "perl"))
         (lambda ()
           (when (save-excursion
                   (goto-char (point-min))
                   (re-search-forward "\t" nil t))
             (setq
              tab-width 8
              indent-tabs-mode t))))
        (((:project "Sub-Name"))
         (lambda ()
           (setq
            tab-width 8
            indent-tabs-mode t
            c-basic-offset 8)))
        (((:project "gnus"))
         (lambda ()
           (setq tab-width 8)))))

(defun rafl:evaluate-buffer-condition (con)
  (cond
   ((functionp con) (funcall con))
   ((listp con)
    (cond
     ((listp (car con))
      (reduce (lambda (a b) (or a b))
              (mapcar #'rafl:evaluate-buffer-condition con)
              :initial-value nil))
     (t
      (reduce
       (lambda (a b) (and a b))
       (let (ret)
         (while con
           (let ((k (pop con))
                 (v (pop con)))
             (push
              (cond
               ((eq k :fun) (funcall v))
               ((eq k :not)
                (when (not (listp v)) (error ":not requires a list"))
                (not (rafl:evaluate-buffer-condition v)))
               ((eq k :mode)
                (if (stringp v)
                    (string-match-p v (symbol-name major-mode))
                  (eq v major-mode)))
               ((eq k :name)
                (string-match-p v (buffer-name)))
               ((eq k :filename)
                (cond ((and (buffer-file-name) (stringp v))
                       (string-match-p v (buffer-file-name)))
                      ((buffer-file-name) v)
                      (t (not v))))
               ((eq k :project)
                ;; assume eproject-maybe-turn-on was called from an earlier hook
                (cond
                 ((and eproject-root (stringp v))
                  (string= v (eproject-name)))
                 (eproject-root v)
                 (t (not v))))
               (t (error "unknown cond")))
              ret)))
         ret)
       :initial-value t))))
   (t (error "invalid condition"))))

(defun rafl:apply-buffer-settings (settings)
  (dolist (setting rafl:buffer-settings)
    (let ((condition (car setting))
          (action (cadr setting)))
      (when (rafl:evaluate-buffer-condition condition)
        (funcall action)))))

(add-hook 'after-change-major-mode-hook
          (lambda () (rafl:apply-buffer-settings rafl:buffer-settings))
          'append)
Something went wrong with that request. Please try again.