1 ;;; flymu.el --- Flymake for mumamo-mode
3 ;; Author: Lennart Borgman (lennart O borgman A gmail O com)
4 ;; Created: Sun Dec 02 14:52:32 2007
11 ;; Features that might be required by this library:
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19 ;; Flymake syntax checks for mumamo chunks.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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.
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.
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.
45 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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."
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
64 (mode (let ((m (cdr (assoc regexp auto-mode-alist))))
65 ;; Don't use this if it is complicated:
66 (when (commandp m) m)))
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'.
79 ;; Find first matching alist entry.
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
86 ;; System is case-sensitive.
88 ;; First match case-sensitively.
89 (let ((case-fold-search nil))
90 (assoc-default name auto-mode-alist
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
100 (setq name (substring name 0 (match-beginning 0)))
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))))))
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)
121 (defvar flymu-mumamo-chunk nil)
122 (make-variable-buffer-local 'flymu-mumamo-chunk)
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?
130 ;; Advice these functions:
131 (defadvice flymake-get-file-name-mode-and-masks (around
132 flymu-ad-flymake-get-file-name-mode-and-masks
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)))
139 (setq ad-return-value (cdr rec))))
141 (ad-activate 'flymake-get-file-name-mode-and-masks)
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
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))
156 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
157 ;;; flymu.el ends here