autoconf.el 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. ;;; autoconf.el --- mode for editing Autoconf configure.ac files
  2. ;; Copyright (C) 2000-2015 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.ac 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.ac 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.ac files.
  25. ;;; Code:
  26. (defvar autoconf-mode-map (make-sparse-keymap))
  27. (defvar autoconf-mode-hook nil
  28. "Hook run by `autoconf-mode'.")
  29. (defconst autoconf-definition-regexp
  30. "A\\(?:H_TEMPLATE\\|C_\\(?:SUBST\\|DEFINE\\(?:_UNQUOTED\\)?\\)\\)(\\[*\\(\\(?:\\sw\\|\\s_\\)+\\)\\]*")
  31. (defvar autoconf-font-lock-keywords
  32. `(("\\_<A[CHMS]_\\(?:\\sw\\|\\s_\\)+" . font-lock-keyword-face)
  33. (,autoconf-definition-regexp
  34. 1 font-lock-function-name-face)
  35. ;; Are any other M4 keywords really appropriate for configure.ac,
  36. ;; given that we do `dnl'?
  37. ("changequote" . font-lock-keyword-face)))
  38. (defvar autoconf-mode-syntax-table
  39. (let ((table (make-syntax-table)))
  40. (modify-syntax-entry ?\" "." table)
  41. (modify-syntax-entry ?\n ">" table)
  42. (modify-syntax-entry ?# "<" table)
  43. table))
  44. (defvar autoconf-imenu-generic-expression
  45. (list (list nil autoconf-definition-regexp 1)))
  46. ;; It's not clear how best to implement this.
  47. (defun autoconf-current-defun-function ()
  48. "Function to use for `add-log-current-defun-function' in Autoconf mode.
  49. This version looks back for an AC_DEFINE or AC_SUBST. It will stop
  50. searching backwards at another AC_... command."
  51. (save-excursion
  52. (skip-syntax-forward "w_" (line-end-position))
  53. (if (re-search-backward autoconf-definition-regexp
  54. (save-excursion (beginning-of-defun) (point))
  55. t)
  56. (match-string-no-properties 1))))
  57. ;;;###autoload
  58. (define-derived-mode autoconf-mode prog-mode "Autoconf"
  59. "Major mode for editing Autoconf configure.ac files."
  60. (setq-local parens-require-spaces nil) ; for M4 arg lists
  61. (setq-local defun-prompt-regexp "^[ \t]*A[CM]_\\(\\sw\\|\\s_\\)+")
  62. (setq-local comment-start "dnl ")
  63. ;; We want to avoid matching "dnl" in other text.
  64. (setq-local comment-start-skip "\\(?:\\(\\W\\|^\\)dnl\\|#\\) +")
  65. (setq-local syntax-propertize-function
  66. (syntax-propertize-rules ("\\<dnl\\>" (0 "<"))))
  67. (setq-local font-lock-defaults
  68. `(autoconf-font-lock-keywords nil nil))
  69. (setq-local imenu-generic-expression autoconf-imenu-generic-expression)
  70. (setq-local indent-line-function #'indent-relative)
  71. (setq-local add-log-current-defun-function
  72. #'autoconf-current-defun-function))
  73. (provide 'autoconf-mode)
  74. (provide 'autoconf)
  75. ;;; autoconf.el ends here