Debian Codegraph @

lib/emacs/autoconf-mode.el

raw
1 ;;; autoconf-mode.el - Edit autoconf for Emacs -*- lexical-binding: t -*-
2
3 ;; Author: Martin Buchholz ([email protected])
4 ;; Maintainer: Martin Buchholz
5 ;; Keywords: languages, faces, m4, configure
6
7 ;; This file is part of Autoconf
8
9 ;; Copyright (C) 2001, 2006, 2009-2017, 2020-2026 Free Software
10 ;; Foundation, Inc.
11 ;;
12 ;; This program is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
16 ;;
17 ;; This program is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
21 ;;
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
24
25 ;; A major mode for editing autoconf input (like configure.in).
26 ;; Derived from m4-mode.el by Andrew Csillag ([email protected])
27
28 ;;; Your should add the following to your Emacs configuration file:
29
30 ;; (autoload 'autoconf-mode "autoconf-mode"
31 ;; "Major mode for editing autoconf files." t)
32 ;; (setq auto-mode-alist
33 ;; (cons '("\\.ac\\'\\|configure\\.in\\'" . autoconf-mode)
34 ;; auto-mode-alist))
35
36 ;;; Code:
37
38 ;;thank god for make-regexp.el!
39 (defvar autoconf-font-lock-keywords
40 `(("\\bdnl \\(.*\\)" 1 font-lock-comment-face t)
41 ("\\$[0-9*#@]" . font-lock-variable-name-face)
42 ("\\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)
43 ("^\\(\\(m4_\\)?define\\(_default\\)?\\|A._DEFUN\\|m4_defun\\(_once\\|_init\\)?\\)(\\[?\\([A-Za-z0-9_]+\\)" 5 font-lock-function-name-face)
44 "default font-lock-keywords")
45 )
46
47 (defvar autoconf-mode-syntax-table nil
48 "syntax table used in autoconf mode")
49 (setq autoconf-mode-syntax-table (make-syntax-table))
50 (modify-syntax-entry ?\" "\"" autoconf-mode-syntax-table)
51 ;;(modify-syntax-entry ?\' "\"" autoconf-mode-syntax-table)
52 (modify-syntax-entry ?# "<\n" autoconf-mode-syntax-table)
53 (modify-syntax-entry ?\n ">#" autoconf-mode-syntax-table)
54 (modify-syntax-entry ?\( "()" autoconf-mode-syntax-table)
55 (modify-syntax-entry ?\) ")(" autoconf-mode-syntax-table)
56 (modify-syntax-entry ?\[ "(]" autoconf-mode-syntax-table)
57 (modify-syntax-entry ?\] ")[" autoconf-mode-syntax-table)
58 (modify-syntax-entry ?* "." autoconf-mode-syntax-table)
59 (modify-syntax-entry ?_ "_" autoconf-mode-syntax-table)
60
61 (defvar autoconf-mode-map
62 (let ((map (make-sparse-keymap)))
63 (define-key map '[(control c) (\;)] 'comment-region)
64 map))
65
66 (defun autoconf-current-defun ()
67 "Autoconf value for `add-log-current-defun-function'.
68 This tells add-log.el how to find the current macro."
69 (save-excursion
70 (if (re-search-backward "^\\(m4_define\\(_default\\)?\\|m4_defun\\(_once\\|_init\\)?\\|A._DEFUN\\)(\\[*\\([A-Za-z0-9_]+\\)" nil t)
71 (buffer-substring (match-beginning 4)
72 (match-end 4))
73 nil)))
74
75 ;;;###autoload
76 (defun autoconf-mode ()
77 "A major-mode to edit Autoconf files like configure.ac.
78 \\{autoconf-mode-map}
79 "
80 (interactive)
81 (kill-all-local-variables)
82 (use-local-map autoconf-mode-map)
83
84 (make-local-variable 'add-log-current-defun-function)
85 (setq add-log-current-defun-function 'autoconf-current-defun)
86
87 (make-local-variable 'comment-start)
88 (setq comment-start "# ")
89 (make-local-variable 'parse-sexp-ignore-comments)
90 (setq parse-sexp-ignore-comments t)
91
92 (make-local-variable 'font-lock-defaults)
93 (setq major-mode 'autoconf-mode)
94 (setq mode-name "Autoconf")
95 (setq font-lock-defaults `(autoconf-font-lock-keywords nil))
96 (set-syntax-table autoconf-mode-syntax-table)
97 (run-hooks 'autoconf-mode-hook))
98
99 (provide 'autoconf-mode)
100
101 ;;; autoconf-mode.el ends here