Mercurial > emacs
annotate lisp/textmodes/dns-mode.el @ 63711:34f124e4af5e
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 23 Jun 2005 17:30:56 +0000 |
parents | 9c7d08864aa8 |
children | a8fa7c632ee4 |
rev | line source |
---|---|
57100
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
1 ;;; dns-mode.el --- a mode for viewing/editing Domain Name System master files |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
2 ;; Copyright (c) 2000, 2001, 2003, 2004 Free Software Foundation, Inc. |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
3 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
4 ;; Author: Simon Josefsson <simon@josefsson.org> |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
5 ;; Keywords: DNS master zone file SOA |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
6 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
7 ;; This file is part of GNU Emacs. |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
8 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
9 ;; GNU Emacs is free software; you can redistribute it and/or modify |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
10 ;; it under the terms of the GNU General Public License as published by |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
11 ;; the Free Software Foundation; either version 2, or (at your option) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
12 ;; any later version. |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
13 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
14 ;; GNU Emacs is distributed in the hope that it will be useful, |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
17 ;; GNU General Public License for more details. |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
18 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
19 ;; You should have received a copy of the GNU General Public License |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
22 ;; Boston, MA 02111-1307, USA. |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
23 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
24 ;;; Commentary: |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
25 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
26 ;; Use M-x dns-mode RET to invoke in master files. |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
27 ;; |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
28 ;; C-c C-s Increment SOA serial. |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
29 ;; Understands YYYYMMDDNN, Unix time, and serial number formats, |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
30 ;; and complains if it fail to find SOA serial. |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
31 ;; |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
32 ;; Put something similar to the following in your ~/.emacs to use this file: |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
33 ;; |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
34 ;; (load "~/path/to/dns-mode.el") |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
35 ;; (setq auto-mode-alist (cons '("\\.soa\\'" . dns-mode) auto-mode-alist)) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
36 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
37 ;;; References: |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
38 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
39 ;; RFC 1034, "DOMAIN NAMES - CONCEPTS AND FACILITIES", P. Mockapetris. |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
40 ;; RFC 1035, "DOMAIN NAMES - IMPLEMENTATION AND SPECIFICATION", P. Mockapetris. |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
41 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
42 ;;; Release history: |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
43 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
44 ;; 2004-09-11 Posted on gnu.emacs.sources. |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
45 ;; 2004-09-13 Ported to XEmacs. |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
46 ;; 2004-09-14 Installed in Emacs CVS. |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
47 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
48 ;;; Code: |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
49 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
50 (defgroup dns-mode nil |
62807
9c7d08864aa8
(dns-mode): Specify customization group.
Lute Kamstra <lute@gnu.org>
parents:
57100
diff
changeset
|
51 "DNS master file mode configuration." |
9c7d08864aa8
(dns-mode): Specify customization group.
Lute Kamstra <lute@gnu.org>
parents:
57100
diff
changeset
|
52 :group 'data) |
57100
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
53 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
54 (defconst dns-mode-classes '("IN" "CS" "CH" "HS") |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
55 "List of strings with known DNS classes.") |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
56 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
57 (defconst dns-mode-types '("A" "NS" "MD" "MF" "CNAME" "SOA" "MB" "MG" "MR" |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
58 "NULL" "WKS" "PTR" "HINFO" "MINFO" "MX" "TXT" |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
59 "RP" "AFSDB" "X25" "ISDN" "RT" "NSAP" "NSAP" |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
60 "SIG" "KEY" "PX" "GPOS" "AAAA" "LOC" "NXT" |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
61 "EID" "NIMLOC" "SRV" "ATMA" "NAPTR" "KX" "CERT" |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
62 "A6" "DNAME" "SINK" "OPT" "APL" "DS" "SSHFP" |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
63 "RRSIG" "NSEC" "DNSKEY" "UINFO" "UID" "GID" |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
64 "UNSPEC" "TKEY" "TSIG" "IXFR" "AXFR" "MAILB" |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
65 "MAILA") |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
66 "List of strings with known DNS types.") |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
67 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
68 ;; Font lock. |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
69 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
70 (defvar dns-mode-control-entity-face 'font-lock-keyword-face |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
71 "Name of face used for control entities, e.g. $ORIGIN.") |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
72 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
73 (defvar dns-mode-bad-control-entity-face 'font-lock-warning-face |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
74 "Name of face used for non-standard control entities, e.g. $FOO.") |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
75 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
76 (defvar dns-mode-type-face 'font-lock-type-face |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
77 "Name of face used for DNS types, e.g., SOA.") |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
78 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
79 (defvar dns-mode-class-face 'font-lock-constant-face |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
80 "Name of face used for DNS classes, e.g., IN.") |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
81 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
82 (defcustom dns-mode-font-lock-keywords |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
83 `(("^$ORIGIN" 0 ,dns-mode-control-entity-face) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
84 ("^$INCLUDE" 0 ,dns-mode-control-entity-face) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
85 ("^$[a-z0-9A-Z]+" 0 ,dns-mode-bad-control-entity-face) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
86 (,(regexp-opt dns-mode-classes) 0 ,dns-mode-class-face) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
87 (,(regexp-opt dns-mode-types) 0 ,dns-mode-type-face)) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
88 "Font lock keywords used to highlight text in DNS master file mode." |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
89 :type 'sexp |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
90 :group 'dns-mode) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
91 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
92 ;; Syntax table. |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
93 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
94 (defvar dns-mode-syntax-table |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
95 (let ((table (make-syntax-table))) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
96 (modify-syntax-entry ?\; "< " table) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
97 (modify-syntax-entry ?\n "> " table) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
98 table) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
99 "Syntax table in use in DNS master file buffers.") |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
100 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
101 ;; Keymap. |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
102 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
103 (defvar dns-mode-map |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
104 (let ((map (make-sparse-keymap))) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
105 (define-key map "\C-c\C-s" 'dns-mode-soa-increment-serial) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
106 map) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
107 "Keymap for DNS master file mode.") |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
108 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
109 ;; Menu. |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
110 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
111 (defvar dns-mode-menu nil |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
112 "Menubar used in DNS master file mode.") |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
113 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
114 (easy-menu-define dns-mode-menu dns-mode-map |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
115 "DNS Menu." |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
116 '("DNS" |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
117 ["Increment SOA serial" dns-mode-soa-increment-serial t])) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
118 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
119 ;; Mode. |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
120 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
121 ;;;###autoload |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
122 (define-derived-mode dns-mode text-mode "DNS" |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
123 "Major mode for viewing and editing DNS master files. |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
124 This mode is inherited from text mode. It add syntax |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
125 highlighting, and some commands for handling DNS master files. |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
126 Its keymap inherits from `text-mode' and it has the same |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
127 variables for customizing indentation. It has its own abbrev |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
128 table and its own syntax table. |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
129 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
130 Turning on DNS mode runs `dns-mode-hook'." |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
131 (set (make-local-variable 'comment-start) ";") |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
132 (set (make-local-variable 'comment-end) "") |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
133 (set (make-local-variable 'comment-start-skip) ";+ *") |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
134 (unless (featurep 'xemacs) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
135 (set (make-local-variable 'font-lock-defaults) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
136 '(dns-mode-font-lock-keywords nil nil ((?_ . "w"))))) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
137 (easy-menu-add dns-mode-menu dns-mode-map)) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
138 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
139 ;; Tools. |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
140 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
141 ;;;###autoload |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
142 (defun dns-mode-soa-increment-serial () |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
143 "Locate SOA record and increment the serial field." |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
144 (interactive) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
145 (save-excursion |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
146 (goto-char (point-min)) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
147 (unless (re-search-forward |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
148 (concat "^\\(\\(\\([^ \t]+[ \t]+\\)?[^ \t]+" |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
149 "[ \t]+\\)?[^ \t]+[ \t]+\\)?SOA") nil t) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
150 (error "Cannot locate SOA record")) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
151 (if (re-search-forward (concat "\\<\\(" |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
152 ;; year |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
153 "\\(198\\|199\\|20[0-9]\\)[0-9]" |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
154 ;; month |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
155 "\\(0[0-9]\\|10\\|11\\|12\\)" |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
156 ;; day |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
157 "\\([012][0-9]\\|30\\|31\\)" |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
158 ;; counter |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
159 "\\([0-9]\\{1,3\\}\\)" |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
160 "\\)\\>") |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
161 nil t) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
162 ;; YYYYMMDDIII format, one to three I's. |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
163 (let* ((serial (match-string 1)) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
164 (counterstr (match-string 5)) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
165 (counter (string-to-number counterstr)) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
166 (now (format-time-string "%Y%m%d")) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
167 (nowandoldserial (concat now counterstr))) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
168 (if (string< serial nowandoldserial) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
169 (let ((new (format "%s00" now))) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
170 (replace-match new nil nil nil 1) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
171 (message "Replaced old serial %s with %s" serial new)) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
172 (if (string= serial nowandoldserial) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
173 (let ((new (format (format "%%s%%0%dd" (length counterstr)) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
174 now (1+ counter)))) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
175 (replace-match new nil nil nil 1) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
176 (message "Replaced old serial %s with %s" serial new)) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
177 (error "Current SOA serial is in the future")))) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
178 (if (re-search-forward "\\<\\([0-9]\\{9,10\\}\\)\\>" nil t) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
179 ;; Unix time |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
180 (let* ((serial (match-string 1)) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
181 (new (format-time-string "%s"))) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
182 (if (not (string< serial new)) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
183 (error "Current SOA serial is in the future") |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
184 (replace-match new nil nil nil 1) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
185 (message "Replaced old serial %s with %s" serial new))) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
186 (if (re-search-forward "\\<\\([0-9]+\\)\\>" nil t) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
187 ;; Just any serial number. |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
188 (let* ((serial (match-string 1)) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
189 (new (format "%d" (1+ (string-to-number serial))))) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
190 (replace-match new nil nil nil 1) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
191 (message "Replaced old serial %s with %s" serial new)) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
192 (error "Cannot locate serial number in SOA record")))))) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
193 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
194 ;;;###autoload(add-to-list 'auto-mode-alist '("\\.soa\\'" . dns-mode)) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
195 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
196 (provide 'dns-mode) |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
197 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
198 ;; arch-tag: 6a179f0a-072f-49db-8b01-37b8f23998c0 |
3eab555cf92b
files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff
changeset
|
199 ;;; dns-mode.el ends here |