autoconf-mode.el 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. ;;; autoconf-mode.el --- autoconf code editing commands for Emacs
  2. ;; Author: Martin Buchholz (martin@xemacs.org)
  3. ;; Maintainer: Martin Buchholz
  4. ;; Keywords: languages, faces, m4, configure
  5. ;; This file is part of Autoconf
  6. ;; Copyright (C) 2001, 2006, 2009-2012 Free Software Foundation, Inc.
  7. ;;
  8. ;; This program is free software: you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation, either version 3 of the License, or
  11. ;; (at your option) any later version.
  12. ;;
  13. ;; This program is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;;
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. ;; A major mode for editing autoconf input (like configure.in).
  21. ;; Derived from m4-mode.el by Andrew Csillag (drew@staff.prodigy.com)
  22. ;;; Your should add the following to your Emacs configuration file:
  23. ;; (autoload 'autoconf-mode "autoconf-mode"
  24. ;; "Major mode for editing autoconf files." t)
  25. ;; (setq auto-mode-alist
  26. ;; (cons '("\\.ac\\'\\|configure\\.in\\'" . autoconf-mode)
  27. ;; auto-mode-alist))
  28. ;;; Code:
  29. ;;thank god for make-regexp.el!
  30. (defvar autoconf-font-lock-keywords
  31. `(("\\bdnl \\(.*\\)" 1 font-lock-comment-face t)
  32. ("\\$[0-9*#@]" . font-lock-variable-name-face)
  33. ("\\b\\(m4_\\)?\\(builtin\\|change\\(com\\|quote\\|word\\)\\|d\\(e\\(bug\\(file\\|mode\\)\\|cr\\|f\\(ine\\|n\\)\\)\\|iv\\(ert\\|num\\)\\|nl\\|umpdef\\)\\|e\\(rrprint\\|syscmd\\|val\\)\\|f\\(ile\\|ormat\\)\\|gnu\\|i\\(f\\(def\\|else\\)\\|n\\(c\\(lude\\|r\\)\\|d\\(ex\\|ir\\)\\)\\)\\|l\\(en\\|ine\\)\\|m\\(4\\(exit\\|wrap\\)\\|aketemp\\|kstemp\\)\\|p\\(atsubst\\|opdef\\|ushdef\\)\\|regexp\\|s\\(hift\\|include\\|ubstr\\|ys\\(cmd\\|val\\)\\)\\|tra\\(ceo\\(ff\\|n\\)\\|nslit\\)\\|un\\(d\\(efine\\|ivert\\)\\|ix\\)\\)\\b" . font-lock-keyword-face)
  34. ("^\\(\\(m4_\\)?define\\(_default\\)?\\|A._DEFUN\\|m4_defun\\(_once\\|_init\\)?\\)(\\[?\\([A-Za-z0-9_]+\\)" 5 font-lock-function-name-face)
  35. "default font-lock-keywords")
  36. )
  37. (defvar autoconf-mode-syntax-table nil
  38. "syntax table used in autoconf mode")
  39. (setq autoconf-mode-syntax-table (make-syntax-table))
  40. (modify-syntax-entry ?\" "\"" autoconf-mode-syntax-table)
  41. ;;(modify-syntax-entry ?\' "\"" autoconf-mode-syntax-table)
  42. (modify-syntax-entry ?# "<\n" autoconf-mode-syntax-table)
  43. (modify-syntax-entry ?\n ">#" autoconf-mode-syntax-table)
  44. (modify-syntax-entry ?\( "()" autoconf-mode-syntax-table)
  45. (modify-syntax-entry ?\) ")(" autoconf-mode-syntax-table)
  46. (modify-syntax-entry ?\[ "(]" autoconf-mode-syntax-table)
  47. (modify-syntax-entry ?\] ")[" autoconf-mode-syntax-table)
  48. (modify-syntax-entry ?* "." autoconf-mode-syntax-table)
  49. (modify-syntax-entry ?_ "_" autoconf-mode-syntax-table)
  50. (defvar autoconf-mode-map
  51. (let ((map (make-sparse-keymap)))
  52. (define-key map '[(control c) (\;)] 'comment-region)
  53. map))
  54. (defun autoconf-current-defun ()
  55. "Autoconf value for `add-log-current-defun-function'.
  56. This tells add-log.el how to find the current macro."
  57. (save-excursion
  58. (if (re-search-backward "^\\(m4_define\\(_default\\)?\\|m4_defun\\(_once\\|_init\\)?\\|A._DEFUN\\)(\\[*\\([A-Za-z0-9_]+\\)" nil t)
  59. (buffer-substring (match-beginning 4)
  60. (match-end 4))
  61. nil)))
  62. ;;;###autoload
  63. (defun autoconf-mode ()
  64. "A major-mode to edit Autoconf files like configure.ac.
  65. \\{autoconf-mode-map}
  66. "
  67. (interactive)
  68. (kill-all-local-variables)
  69. (use-local-map autoconf-mode-map)
  70. (make-local-variable 'add-log-current-defun-function)
  71. (setq add-log-current-defun-function 'autoconf-current-defun)
  72. (make-local-variable 'comment-start)
  73. (setq comment-start "# ")
  74. (make-local-variable 'parse-sexp-ignore-comments)
  75. (setq parse-sexp-ignore-comments t)
  76. (make-local-variable 'font-lock-defaults)
  77. (setq major-mode 'autoconf-mode)
  78. (setq mode-name "Autoconf")
  79. (setq font-lock-defaults `(autoconf-font-lock-keywords nil))
  80. (set-syntax-table autoconf-mode-syntax-table)
  81. (run-hooks 'autoconf-mode-hook))
  82. (provide 'autoconf-mode)
  83. ;;; autoconf-mode.el ends here