Commit | Line | Data |
---|---|---|
c4444d16 | 1 | ;;; autoconf.el --- mode for editing Autoconf configure.ac files |
c926a73b | 2 | |
acaf905b | 3 | ;; Copyright (C) 2000-2012 Free Software Foundation, Inc. |
c926a73b DL |
4 | |
5 | ;; Author: Dave Love <fx@gnu.org> | |
6 | ;; Keywords: languages | |
c926a73b DL |
7 | |
8 | ;; This file is part of GNU Emacs. | |
9 | ||
b1fc2b50 | 10 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
c926a73b | 11 | ;; it under the terms of the GNU General Public License as published by |
b1fc2b50 GM |
12 | ;; the Free Software Foundation, either version 3 of the License, or |
13 | ;; (at your option) any later version. | |
c926a73b DL |
14 | |
15 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | ;; GNU General Public License for more details. | |
19 | ||
20 | ;; You should have received a copy of the GNU General Public License | |
b1fc2b50 | 21 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
c926a73b DL |
22 | |
23 | ;;; Commentary: | |
24 | ||
25 | ;; Provides fairly minimal font-lock, imenu and indentation support | |
c4444d16 | 26 | ;; for editing configure.ac files. Only Autoconf syntax is processed. |
c926a73b DL |
27 | ;; There is no attempt to deal with shell text -- probably that will |
28 | ;; always lose. | |
29 | ||
c4444d16 | 30 | ;; This is specialized for configure.ac files. It doesn't inherit the |
c926a73b DL |
31 | ;; general M4 stuff from M4 mode. |
32 | ||
33 | ;; There is also an autoconf-mode.el in existence. That appears to be | |
c4444d16 | 34 | ;; for editing the Autoconf M4 source, rather than configure.ac files. |
c926a73b DL |
35 | |
36 | ;;; Code: | |
37 | ||
d9df5bff JB |
38 | (defvar font-lock-syntactic-keywords) |
39 | ||
c926a73b DL |
40 | (defvar autoconf-mode-map (make-sparse-keymap)) |
41 | ||
42 | (defvar autoconf-mode-hook nil | |
43 | "Hook run by `autoconf-mode'.") | |
44 | ||
c926a73b | 45 | (defconst autoconf-definition-regexp |
0d26d7c4 | 46 | "A\\(?:H_TEMPLATE\\|C_\\(?:SUBST\\|DEFINE\\(?:_UNQUOTED\\)?\\)\\)(\\[*\\(\\sw+\\)\\]*") |
c926a73b DL |
47 | |
48 | (defvar autoconf-font-lock-keywords | |
d9674f33 | 49 | `(("\\_<A[CHMS]_\\sw+" . font-lock-keyword-face) |
c926a73b | 50 | (,autoconf-definition-regexp |
0d26d7c4 | 51 | 1 font-lock-function-name-face) |
c4444d16 | 52 | ;; Are any other M4 keywords really appropriate for configure.ac, |
c926a73b DL |
53 | ;; given that we do `dnl'? |
54 | ("changequote" . font-lock-keyword-face))) | |
55 | ||
56 | (defvar autoconf-mode-syntax-table | |
57 | (let ((table (make-syntax-table))) | |
58 | (modify-syntax-entry ?\" "." table) | |
59 | (modify-syntax-entry ?\n ">" table) | |
60 | (modify-syntax-entry ?# "<" table) | |
61 | table)) | |
62 | ||
63 | (defvar autoconf-imenu-generic-expression | |
0d26d7c4 | 64 | (list (list nil autoconf-definition-regexp 1))) |
c926a73b DL |
65 | |
66 | ;; It's not clear how best to implement this. | |
67 | (defun autoconf-current-defun-function () | |
68 | "Function to use for `add-log-current-defun-function' in Autoconf mode. | |
69 | This version looks back for an AC_DEFINE or AC_SUBST. It will stop | |
70 | searching backwards at another AC_... command." | |
71 | (save-excursion | |
f4103aec | 72 | (with-syntax-table (copy-syntax-table autoconf-mode-syntax-table) |
c926a73b | 73 | (modify-syntax-entry ?_ "w") |
0d26d7c4 | 74 | (skip-syntax-forward "w" (line-end-position)) |
c926a73b DL |
75 | (if (re-search-backward autoconf-definition-regexp |
76 | (save-excursion (beginning-of-defun) (point)) | |
77 | t) | |
0d26d7c4 | 78 | (match-string-no-properties 1))))) |
c926a73b DL |
79 | |
80 | ;;;###autoload | |
175069ef | 81 | (define-derived-mode autoconf-mode prog-mode "Autoconf" |
c4444d16 | 82 | "Major mode for editing Autoconf configure.ac files." |
c926a73b DL |
83 | (set (make-local-variable 'parens-require-spaces) nil) ; for M4 arg lists |
84 | (set (make-local-variable 'defun-prompt-regexp) | |
85 | "^[ \t]*A[CM]_\\(\\sw\\|\\s_\\)+") | |
86 | (set (make-local-variable 'comment-start) "dnl ") | |
ce7ddba0 CY |
87 | (set (make-local-variable 'comment-start-skip) |
88 | "\\(?:\\(\\W\\|\\`\\)dnl\\|#\\) +") | |
cf38dd42 SM |
89 | (set (make-local-variable 'syntax-propertize-function) |
90 | (syntax-propertize-rules ("\\<dnl\\>" (0 "<")))) | |
c926a73b DL |
91 | (set (make-local-variable 'font-lock-defaults) |
92 | `(autoconf-font-lock-keywords nil nil (("_" . "w")))) | |
93 | (set (make-local-variable 'imenu-generic-expression) | |
94 | autoconf-imenu-generic-expression) | |
95 | (set (make-local-variable 'imenu-syntax-alist) '(("_" . "w"))) | |
96 | (set (make-local-variable 'indent-line-function) #'indent-relative) | |
97 | (set (make-local-variable 'add-log-current-defun-function) | |
175069ef | 98 | #'autoconf-current-defun-function)) |
c926a73b DL |
99 | |
100 | (provide 'autoconf-mode) | |
15120dec | 101 | (provide 'autoconf) |
c926a73b DL |
102 | |
103 | ;;; autoconf.el ends here |