Initial Commit
[packages] / xemacs-packages / ede / autoconf-compat.el
1 ;;; autoconf-compat.el --- Copied from Emacs 21 for backward compatibility
2 ;;;                        with older emacsen.
3 ;; Delta: 1) this comment
4 ;;           provide `autoconf-compat' instead of autoconf-mode.
5 ;;           Added `with-syntax-table' compatibility code.
6
7 ;;; autoconf.el --- Mode for editing Autoconf configure.in files.
8
9 ;; Copyright (C) 2000, 2004, 2007 Free Software Foundation, Inc.
10
11 ;; Author: Dave Love <fx@gnu.org>
12 ;; Keywords: languages
13 ;; $Revision: 1.1 $
14
15 ;; This software is free software; you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; any later version.
19
20 ;; This software is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 ;; GNU General Public License for more details.
24
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
27 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
28 ;; Boston, MA 02110-1301, USA.
29
30 ;;; Commentary:
31
32 ;; Provides fairly minimal font-lock, imenu and indentation support
33 ;; for editing configure.in files.  Only Autoconf syntax is processed.
34 ;; There is no attempt to deal with shell text -- probably that will
35 ;; always lose.
36
37 ;; This is specialized for configure.in files.  It doesn't inherit the
38 ;; general M4 stuff from M4 mode.
39
40 ;; There is also an autoconf-mode.el in existence.  That appears to be
41 ;; for editing the Autoconf M4 source, rather than configure.in files.
42
43 ;;; Code:
44
45 (eval-when-compile
46   (require 'font-lock))
47
48 (eval-and-compile (if (not (fboundp 'with-syntax-table))
49                         
50 ;; Copied from Emacs 21 for compatibility with released Emacses.
51 (defmacro with-syntax-table (table &rest body)
52   "Evaluate BODY with syntax table of current buffer set to a copy of TABLE.
53 The syntax table of the current buffer is saved, BODY is evaluated, and the
54 saved table is restored, even in case of an abnormal exit.
55 Value is what BODY returns."
56   (let ((old-table (make-symbol "table"))
57         (old-buffer (make-symbol "buffer")))
58     `(let ((,old-table (syntax-table))
59            (,old-buffer (current-buffer)))
60        (unwind-protect
61            (progn
62              (set-syntax-table (copy-syntax-table ,table))
63              ,@body)
64          (save-current-buffer
65            (set-buffer ,old-buffer)
66            (set-syntax-table ,old-table))))))
67
68 ))
69
70 (defvar autoconf-mode-map (make-sparse-keymap))
71
72 (defvar autoconf-mode-hook nil
73   "Hook run by `autoconf-mode'.")
74
75 (defconst autoconf-font-lock-syntactic-keywords
76   '(("\\<dnl\\>" 0 '(11))))
77
78 (defconst autoconf-definition-regexp
79   "AC_\\(SUBST\\|DEFINE\\(_UNQUOTED\\)?\\)(\\(\\sw+\\)")
80
81 (defvar autoconf-font-lock-keywords
82   `(("A[CM]_\\sw+" . font-lock-keyword-face)
83     (,autoconf-definition-regexp
84      3 font-lock-function-name-face)
85     ;; Are any other M4 keywords really appropriate for configure.in,
86     ;; given that we do `dnl'?
87     ("changequote" . font-lock-keyword-face)))
88
89 (defvar autoconf-mode-syntax-table
90   (let ((table (make-syntax-table)))
91     (modify-syntax-entry ?\" "." table)
92     (modify-syntax-entry ?\n ">" table)
93     (modify-syntax-entry ?# "<" table)
94     table))
95
96 (defvar autoconf-imenu-generic-expression
97   (list (list nil autoconf-definition-regexp 3)))
98
99 ;; It's not clear how best to implement this.
100 (defun autoconf-current-defun-function ()
101   "Function to use for `add-log-current-defun-function' in Autoconf mode.
102 This version looks back for an AC_DEFINE or AC_SUBST.  It will stop
103 searching backwards at another AC_... command."
104   (save-excursion
105     (with-syntax-table autoconf-mode-syntax-table
106       (modify-syntax-entry ?_ "w")
107       (if (re-search-backward autoconf-definition-regexp
108                               (save-excursion (beginning-of-defun) (point))
109                               t)
110           (match-string-no-properties 3)))))
111
112 (defun autoconf-mode ()
113   "Major mode for editing Autoconf configure.in files."
114   (interactive)
115   (kill-all-local-variables)
116   (use-local-map autoconf-mode-map)
117   (setq major-mode 'autoconf-mode)
118   (setq mode-name "Autoconf")
119   (set-syntax-table autoconf-mode-syntax-table)
120   (set (make-local-variable 'parens-require-spaces) nil) ; for M4 arg lists
121   (set (make-local-variable 'defun-prompt-regexp)
122        "^[ \t]*A[CM]_\\(\\sw\\|\\s_\\)+")
123   (set (make-local-variable 'comment-start) "dnl ")
124   (set (make-local-variable 'comment-start-skip) "\\(\\<dnl\\|#\\) +")
125   (set (make-local-variable 'font-lock-syntactic-keywords)
126        autoconf-font-lock-syntactic-keywords)
127   (set (make-local-variable 'font-lock-defaults)
128        `(autoconf-font-lock-keywords nil nil (("_" . "w"))))
129   (set (make-local-variable 'imenu-generic-expression)
130        autoconf-imenu-generic-expression)
131   (set (make-local-variable 'imenu-syntax-alist) '(("_" . "w")))
132   (set (make-local-variable 'indent-line-function) #'indent-relative)
133   (set (make-local-variable 'add-log-current-defun-function)
134         #'autoconf-current-defun-function)
135   (run-hooks 'autoconf-mode-hook))
136
137 (provide 'autoconf-compat)
138
139 ;;; autoconf.el ends here