]> git.rkrishnan.org Git - .emacs.d.git/blob - emacs/nxhtml/related/flymu.el
6b3a552873a27c66e3c32183e00ee5c7c0b3906c
[.emacs.d.git] / emacs / nxhtml / related / flymu.el
1 ;;; flymu.el --- Flymake for mumamo-mode
2 ;;
3 ;; Author: Lennart Borgman (lennart O borgman A gmail O com)
4 ;; Created: Sun Dec 02 14:52:32 2007
5 ;; Version: 0.1
6 ;; Last-Updated:
7 ;; URL:
8 ;; Keywords:
9 ;; Compatibility:
10 ;;
11 ;; Features that might be required by this library:
12 ;;
13 ;;   None
14 ;;
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16 ;;
17 ;;; Commentary:
18 ;;
19 ;; Flymake syntax checks for mumamo chunks.
20 ;;
21 ;; Not ready yet!!!
22 ;;
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24 ;;
25 ;;; Change log:
26 ;;
27 ;;
28 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29 ;;
30 ;; This program is free software; you can redistribute it and/or
31 ;; modify it under the terms of the GNU General Public License as
32 ;; published by the Free Software Foundation; either version 2, or
33 ;; (at your option) any later version.
34 ;;
35 ;; This program is distributed in the hope that it will be useful,
36 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
37 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
38 ;; General Public License for more details.
39 ;;
40 ;; You should have received a copy of the GNU General Public License
41 ;; along with this program; see the file COPYING.  If not, write to
42 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
43 ;; Floor, Boston, MA 02110-1301, USA.
44 ;;
45 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
46 ;;
47 ;;; Code:
48
49 (require 'flymake)
50
51 ;;(flymu-make-major-mode-alist)
52 (defun flymu-make-major-mode-alist ()
53   "Grab values from `flymake-allowed-file-name-masks'.
54 We need a list of major modes and the corresponding init and
55 cleanup functions for flymake. This functions creates such a list
56 from flymakes dito list for file names."
57   (let ((allowed nil))
58     (save-match-data
59       (dolist (regexp-init flymake-allowed-file-name-masks)
60         (let* ((regexp (car regexp-init))
61                (init   (cdr regexp-init))
62                ;; Make it as simple as possible. First see if the same
63                ;; regexp is used:
64                (mode (let ((m (cdr (assoc regexp auto-mode-alist))))
65                        ;; Don't use this if it is complicated:
66                        (when (commandp m) m)))
67                (ext regexp))
68           (unless mode
69             ;; Try to make a simple file name, this could be made
70             ;; better but I do not know if that would be meaningful:
71             (setq ext (replace-regexp-in-string "\\\\\\." "." ext))
72             (setq ext (replace-regexp-in-string "\\\\'" "" ext))
73             (setq ext (replace-regexp-in-string "[\\$?+*]" "" ext))
74             ;; Next compare the filename against the entries in
75             ;; auto-mode-alist. The code is from `set-auto-mode'.
76             (let ((name ext)
77                   (done nil))
78               (while name
79                 ;; Find first matching alist entry.
80                 (setq mode
81                       (if (memq system-type '(vax-vms windows-nt cygwin))
82                           ;; System is case-insensitive.
83                           (let ((case-fold-search t))
84                             (assoc-default name auto-mode-alist
85                                            'string-match))
86                         ;; System is case-sensitive.
87                         (or
88                          ;; First match case-sensitively.
89                          (let ((case-fold-search nil))
90                            (assoc-default name auto-mode-alist
91                                           'string-match))
92                          ;; Fallback to case-insensitive match.
93                          (and auto-mode-case-fold
94                               (let ((case-fold-search t))
95                                 (assoc-default name auto-mode-alist
96                                                'string-match))))))
97                 (if (and mode
98                          (consp mode)
99                          (cadr mode))
100                     (setq name (substring name 0 (match-beginning 0)))
101                   (setq name)))))
102           (when (and mode
103                      ;; nxml-mode's do not need flymake:
104                      (let ((major-mode mode))
105                        (not (derived-mode-p 'nxml-mode))))
106             (let ((rec (append (list mode) init)))
107               (when (= (length rec) 2)
108                 (setq rec (append rec (list nil))))
109               (add-to-list 'allowed rec))))))
110     allowed))
111
112 (defcustom flymu-allowed-major-modes (flymu-make-major-mode-alist)
113   "Major modes syntax checking is allowed for."
114   :type '(repeat (list (function :tag "Major mode")
115                        (function :tag "Init function")
116                        (choice (const :tag "No cleanup function" nil)
117                                (function :tag "Cleanup function"))))
118   :set-after '(flymake-allowed-file-name-masks)
119   :group 'flymu)
120
121 (defvar flymu-mumamo-chunk nil)
122 (make-variable-buffer-local 'flymu-mumamo-chunk)
123
124
125 ;; Fix-me: What to check? When? Make flymu-mumamo-chunk a function
126 ;; instead? Mark chunks for checking - let mumamo do that? Flymake
127 ;; should be able to mark a chunk to, even if it is not a whole
128 ;; line. What about line numbers?
129
130 ;; Advice these functions:
131 (defadvice flymake-get-file-name-mode-and-masks (around
132                                                  flymu-ad-flymake-get-file-name-mode-and-masks
133                                                  (file-name))
134   "Make flymake init file selection according to mode."
135   (if flymu-mumamo-chunk
136       (let ((major (overlay-get ovl 'mumamo-major-mode))
137             (rec (assq major flymu-allowed-major-modes)))
138         (when rec
139           (setq ad-return-value (cdr rec))))
140     ad-do-it))
141 (ad-activate 'flymake-get-file-name-mode-and-masks)
142
143 ;;(defun flymake-save-buffer-in-file (file-name)
144 (defadvice flymake-save-buffer-in-file (around
145                                         flymu-ad-flymake-save-buffer-in-file
146                                         (file-name))
147   (if flymu-mumamo-chunk
148       (let ((min (overlay-start flymu-mumamo-chunk))
149             (max (overlay-end   flymu-mumamo-chunk)))
150         (make-directory (file-name-directory file-name) 1)
151         (write-region min max file-name nil 566)
152         (flymake-log 3 "saved chunk %s:%s-%s in file %s" (buffer-name) min ma file-name))
153     ad-do-it))
154
155 (provide 'flymu)
156 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
157 ;;; flymu.el ends here