]> code.delx.au - gnu-emacs/blob - lisp/progmodes/autoconf.el
Merge from emacs-24; up to 2012-12-06T01:39:03Z!monnier@iro.umontreal.ca
[gnu-emacs] / lisp / progmodes / autoconf.el
1 ;;; autoconf.el --- mode for editing Autoconf configure.ac files
2
3 ;; Copyright (C) 2000-2013 Free Software Foundation, Inc.
4
5 ;; Author: Dave Love <fx@gnu.org>
6 ;; Keywords: languages
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
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
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;; Provides fairly minimal font-lock, imenu and indentation support
26 ;; for editing configure.ac files. Only Autoconf syntax is processed.
27 ;; There is no attempt to deal with shell text -- probably that will
28 ;; always lose.
29
30 ;; This is specialized for configure.ac files. It doesn't inherit the
31 ;; general M4 stuff from M4 mode.
32
33 ;; There is also an autoconf-mode.el in existence. That appears to be
34 ;; for editing the Autoconf M4 source, rather than configure.ac files.
35
36 ;;; Code:
37
38 (defvar autoconf-mode-map (make-sparse-keymap))
39
40 (defvar autoconf-mode-hook nil
41 "Hook run by `autoconf-mode'.")
42
43 (defconst autoconf-definition-regexp
44 "A\\(?:H_TEMPLATE\\|C_\\(?:SUBST\\|DEFINE\\(?:_UNQUOTED\\)?\\)\\)(\\[*\\(\\sw+\\)\\]*")
45
46 (defvar autoconf-font-lock-keywords
47 `(("\\_<A[CHMS]_\\sw+" . font-lock-keyword-face)
48 (,autoconf-definition-regexp
49 1 font-lock-function-name-face)
50 ;; Are any other M4 keywords really appropriate for configure.ac,
51 ;; given that we do `dnl'?
52 ("changequote" . font-lock-keyword-face)))
53
54 (defvar autoconf-mode-syntax-table
55 (let ((table (make-syntax-table)))
56 (modify-syntax-entry ?\" "." table)
57 (modify-syntax-entry ?\n ">" table)
58 (modify-syntax-entry ?# "<" table)
59 table))
60
61 (defvar autoconf-imenu-generic-expression
62 (list (list nil autoconf-definition-regexp 1)))
63
64 ;; It's not clear how best to implement this.
65 (defun autoconf-current-defun-function ()
66 "Function to use for `add-log-current-defun-function' in Autoconf mode.
67 This version looks back for an AC_DEFINE or AC_SUBST. It will stop
68 searching backwards at another AC_... command."
69 (save-excursion
70 (with-syntax-table (copy-syntax-table autoconf-mode-syntax-table)
71 (modify-syntax-entry ?_ "w")
72 (skip-syntax-forward "w" (line-end-position))
73 (if (re-search-backward autoconf-definition-regexp
74 (save-excursion (beginning-of-defun) (point))
75 t)
76 (match-string-no-properties 1)))))
77
78 ;;;###autoload
79 (define-derived-mode autoconf-mode prog-mode "Autoconf"
80 "Major mode for editing Autoconf configure.ac files."
81 (setq-local parens-require-spaces nil) ; for M4 arg lists
82 (setq-local defun-prompt-regexp "^[ \t]*A[CM]_\\(\\sw\\|\\s_\\)+")
83 (setq-local comment-start "dnl ")
84 (setq-local comment-start-skip "\\(?:\\(\\W\\|\\`\\)dnl\\|#\\) +")
85 (setq-local syntax-propertize-function
86 (syntax-propertize-rules ("\\<dnl\\>" (0 "<"))))
87 (setq-local font-lock-defaults
88 `(autoconf-font-lock-keywords nil nil (("_" . "w"))))
89 (setq-local imenu-generic-expression autoconf-imenu-generic-expression)
90 (setq-local imenu-syntax-alist '(("_" . "w")))
91 (setq-local indent-line-function #'indent-relative)
92 (setq-local add-log-current-defun-function
93 #'autoconf-current-defun-function))
94
95 (provide 'autoconf-mode)
96 (provide 'autoconf)
97
98 ;;; autoconf.el ends here