autoconf.el 3.8 KB

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