1 ;;; mpc-mode.el --- Makefile Project Creator mode for Emacs
3 ;; Author: Jules Colding <colding@42tools.com>
4 ;; Maintainer: Jules Colding
5 ;; Keywords: languages, faces, mpc
7 ;; Copyright (C) 2008 Jules Colding <colding@42tools.com>
9 ;; This program is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
22 ;; A major mode for editing MPC input. Please see:
24 ;; http://downloads.ociweb.com/MPC/MakeProjectCreator.pdf
26 ;; Derived from autoconf-mode.el by Martin Buchholz (martin@xemacs.org)
29 ;; Many thanks to the follwing kind people for extensions, bugfixes and
30 ;; other contributions:
32 ;; * William R. Otte <wotte@dre.vanderbilt.edu>
33 ;; Indentation and syntax table.
36 ;; Put this file somewhere in your emacs load path and add the following
37 ;; to your Emacs configuration file:
39 ;; (require 'mpc-mode)
42 ;; You may also add something like this to the top of your MPC files
43 ;; to force a specific indentation mode:
45 ;; // -*- Mode: MPC; tab-width: 2; indent-tabs-mode: t; -*-
51 (defvar mpc-mode-hook nil
)
54 (let ((mpc-mode-map (make-sparse-keymap)))
55 (define-key mpc-mode-map
'[(control c
) (control c
)] 'comment-region
)
56 (define-key mpc-mode-map
'[(control j
)] 'newline-and-indent
)
58 "Keymap for MPC major mode")
60 (defvar mpc-font-lock-keywords
62 ("\\(project\\)" 1 font-lock-warning-face t
)
63 ("\\(workspace\\)" 1 font-lock-warning-face t
)
64 ("(\\([^()]*\\))" 1 font-lock-constant-face t
)
65 ("\\(IDL_Files\\)" 1 font-lock-keyword-face t
)
66 ("\\(Source_Files\\)" 1 font-lock-keyword-face t
)
67 ("\\(Header_Files\\)" 1 font-lock-keyword-face t
)
68 ("\\(Inline_Files\\)" 1 font-lock-keyword-face t
)
69 ("\\(Template_Files\\)" 1 font-lock-keyword-face t
)
70 ("\\(Resource_Files\\)" 1 font-lock-keyword-face t
)
71 ("\\(Pkgconfig_Files\\)" 1 font-lock-keyword-face t
)
72 ("\\(exclude\\)" 1 font-lock-type-face t
)
73 ("\\(custom_only\\)" 1 font-lock-type-face t
)
74 ("\\(cmdline\\)" 1 font-lock-type-face t
)
75 ("\\(avoids\\)" 1 font-lock-type-face t
)
76 ("\\(exename\\)" 1 font-lock-type-face t
)
77 ("\\(install =\\)" 1 font-lock-type-face t
)
78 ("\\(install +=\\)" 1 font-lock-type-face t
)
79 ("\\(install -=\\)" 1 font-lock-type-face t
)
80 ("\\(libs\\)" 1 font-lock-type-face t
)
81 ("\\(lit_libs\\)" 1 font-lock-type-face t
)
82 ("\\(linkflags\\)" 1 font-lock-type-face t
)
83 ("\\(specific\\)" 1 font-lock-type-face t
)
84 ("\\(macros\\)" 1 font-lock-type-face t
)
85 ("\\(after\\)" 1 font-lock-type-face t
)
86 ("\\(libout\\)" 1 font-lock-type-face t
)
87 ("\\(libpaths\\)" 1 font-lock-type-face t
)
88 ("\\(includes\\)" 1 font-lock-type-face t
)
89 ("\\(automatic\\)" 1 font-lock-type-face t
)
90 ("\\(command\\)" 1 font-lock-type-face t
)
91 ("\\(output_option\\)" 1 font-lock-type-face t
)
92 ("\\(header_pre_extension\\)" 1 font-lock-type-face t
)
93 ("\\(header_outputext\\)" 1 font-lock-type-face t
)
94 ("\\(sharedname\\)" 1 font-lock-type-face t
)
95 ("\\(dynamicflags\\)" 1 font-lock-type-face t
)
96 ("\\(idlflags\\)" 1 font-lock-type-face t
)
97 ("\\(:\\)" 1 font-lock-builtin-face t
)
98 ("\\( = \\)" 1 font-lock-builtin-face t
)
99 ("\\(+=\\)" 1 font-lock-builtin-face t
)
100 ("\\(-=\\)" 1 font-lock-builtin-face t
)
101 ("\\(//\\)" 1 font-lock-comment-face t
)
102 ("\\//\\(.*\\)" 1 font-lock-comment-face t
)
103 "default font-lock-keywords")
107 (defun mpc-indent-line ()
108 "Indent current line as MPC directives"
113 (indent-line-to 0) ; if we are at start of file, zero indent
114 (let ((not-found-hint t
) cur-indent
(close-brace nil
))
115 (save-excursion ; otherwise, we are not looking at a }, so we need to go back to find the
116 (if (looking-at ".*}")
117 (setq close-brace t
))
118 (while not-found-hint
; nearest indentation hint
120 (if (looking-at ".*{")
122 (setq cur-indent
(+ (current-indentation) tab-width
))
123 (setq not-found-hint nil
))
124 (if (looking-at ".*}")
126 (setq cur-indent
(current-indentation))
129 (setq not-found-hint nil
))
131 (setq not-found-hint nil
))))))
133 (setq cur-indent
(- cur-indent tab-width
)))
135 (indent-line-to cur-indent
)
136 (indent-line-to 0))))
139 ;; Create a syntax table. Derived from fundamental mode, it will automatically
140 ;; highlight strings, and behave correctly on most words.
141 (defvar mpc-mode-syntax-table nil
142 "syntax table used in mpc mode")
143 (setq mpc-mode-syntax-table
(make-syntax-table))
144 (modify-syntax-entry ?_
"w" mpc-mode-syntax-table
) ; underscore is a valid part of a word
145 (modify-syntax-entry ?-
"w" mpc-mode-syntax-table
) ; hyphen is a valid part of a word
146 (modify-syntax-entry ?
/ ". 12b" mpc-mode-syntax-table
) ; c++-style comments
147 (modify-syntax-entry ?
\n "> b" mpc-mode-syntax-table
) ; c++-style comments
151 "A major-mode to edit MPC files.
155 (kill-all-local-variables)
156 (use-local-map mpc-mode-map
)
158 (make-local-variable 'comment-start
)
159 (setq comment-start
"//")
160 (make-local-variable 'parse-sexp-ignore-comments
)
161 (setq parse-sexp-ignore-comments t
)
163 (make-local-variable 'tab-width
)
164 (make-local-variable 'font-lock-defaults
)
165 (make-local-variable 'indent-line-function
)
167 (setq major-mode
'mpc-mode
)
168 (setq mode-name
"MPC")
170 (setq font-lock-defaults
`(mpc-font-lock-keywords nil t
))
171 (setq indent-line-function
'mpc-indent-line
)
173 (set-syntax-table mpc-mode-syntax-table
)
174 (run-hooks 'mpc-mode-hook
)
177 (add-to-list 'auto-mode-alist
'("\\.mwb\\'" . mpc-mode
))
178 (add-to-list 'auto-mode-alist
'("\\.mwc\\'" . mpc-mode
))
179 (add-to-list 'auto-mode-alist
'("\\.mpb\\'" . mpc-mode
))
180 (add-to-list 'auto-mode-alist
'("\\.mpc\\'" . mpc-mode
))
185 ;;; mpc-mode.el ends here