annotate lisp/textmodes/dns-mode.el @ 112314:b43e3dd4da2d

* lib/COPYING: New file, a copy of COPYING.
author Paul Eggert <eggert@cs.ucla.edu>
date Sat, 08 Jan 2011 23:43:55 -0800
parents 77c2be84591c
children 417b1e4d63cd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
64751
5b1a238fcbb4 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64084
diff changeset
2
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 106251
diff changeset
3 ;; Copyright (C) 2000, 2001, 2004, 2005, 2006, 2007, 2008, 2009, 2010
79719
dc100f64b2b7 Add 2008 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 78225
diff changeset
4 ;; Free Software Foundation, Inc.
57100
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
5
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
6 ;; Author: Simon Josefsson <simon@josefsson.org>
106251
76837abf70c1 * textmodes/dns-mode.el: Add "Keywords: comm". It's only an
Kevin Ryde <user42@zip.com.au>
parents: 105870
diff changeset
7 ;; Keywords: DNS master zone file SOA comm
57100
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 ;; 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
10
94670
f4a69fedbd46 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79719
diff changeset
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
57100
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
94670
f4a69fedbd46 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79719
diff changeset
13 ;; the Free Software Foundation, either version 3 of the License, or
f4a69fedbd46 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79719
diff changeset
14 ;; (at your option) any later version.
57100
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
15
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
16 ;; 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
17 ;; 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
18 ;; 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
19 ;; 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
20
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
94670
f4a69fedbd46 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79719
diff changeset
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
57100
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 ;;; References:
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 ;; 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
35 ;; 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
36
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
37 ;;; Release history:
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 ;; 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
40 ;; 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
41 ;; 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
42
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
43 ;;; Code:
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
44
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
45 (defgroup dns-mode nil
62807
9c7d08864aa8 (dns-mode): Specify customization group.
Lute Kamstra <lute@gnu.org>
parents: 57100
diff changeset
46 "DNS master file mode configuration."
9c7d08864aa8 (dns-mode): Specify customization group.
Lute Kamstra <lute@gnu.org>
parents: 57100
diff changeset
47 :group 'data)
57100
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
48
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
49 (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
50 "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
51
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
52 (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
53 "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
54 "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
55 "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
56 "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
57 "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
58 "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
59 "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
60 "MAILA")
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
61 "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
62
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
63 ;; Font lock.
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
64
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
65 (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
66 "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
67
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
68 (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
69 "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
70
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
71 (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
72 "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
73
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
74 (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
75 "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
76
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
77 (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
78 `(("^$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
79 ("^$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
80 ("^$[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
81 (,(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
82 (,(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
83 "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
84 :type 'sexp
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
85 :group 'dns-mode)
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
86
72350
45347140c0d0 * textmodes/dns-mode.el: Alias `zone-mode' to `dns-mode'.
Romain Francoise <romain@orebokech.com>
parents: 68648
diff changeset
87 (defcustom dns-mode-soa-auto-increment-serial t
45347140c0d0 * textmodes/dns-mode.el: Alias `zone-mode' to `dns-mode'.
Romain Francoise <romain@orebokech.com>
parents: 68648
diff changeset
88 "Whether to increment the SOA serial number automatically.
45347140c0d0 * textmodes/dns-mode.el: Alias `zone-mode' to `dns-mode'.
Romain Francoise <romain@orebokech.com>
parents: 68648
diff changeset
89
45347140c0d0 * textmodes/dns-mode.el: Alias `zone-mode' to `dns-mode'.
Romain Francoise <romain@orebokech.com>
parents: 68648
diff changeset
90 If this variable is t, the serial number is incremented upon each save of
45347140c0d0 * textmodes/dns-mode.el: Alias `zone-mode' to `dns-mode'.
Romain Francoise <romain@orebokech.com>
parents: 68648
diff changeset
91 the file. If it is `ask', Emacs asks for confirmation whether it should
45347140c0d0 * textmodes/dns-mode.el: Alias `zone-mode' to `dns-mode'.
Romain Francoise <romain@orebokech.com>
parents: 68648
diff changeset
92 increment the serial upon saving. If nil, serials must be incremented
45347140c0d0 * textmodes/dns-mode.el: Alias `zone-mode' to `dns-mode'.
Romain Francoise <romain@orebokech.com>
parents: 68648
diff changeset
93 manually with \\[dns-mode-soa-increment-serial]."
45347140c0d0 * textmodes/dns-mode.el: Alias `zone-mode' to `dns-mode'.
Romain Francoise <romain@orebokech.com>
parents: 68648
diff changeset
94 :type '(choice (const :tag "Always" t)
45347140c0d0 * textmodes/dns-mode.el: Alias `zone-mode' to `dns-mode'.
Romain Francoise <romain@orebokech.com>
parents: 68648
diff changeset
95 (const :tag "Ask" ask)
45347140c0d0 * textmodes/dns-mode.el: Alias `zone-mode' to `dns-mode'.
Romain Francoise <romain@orebokech.com>
parents: 68648
diff changeset
96 (const :tag "Never" nil))
45347140c0d0 * textmodes/dns-mode.el: Alias `zone-mode' to `dns-mode'.
Romain Francoise <romain@orebokech.com>
parents: 68648
diff changeset
97 :group 'dns-mode)
45347140c0d0 * textmodes/dns-mode.el: Alias `zone-mode' to `dns-mode'.
Romain Francoise <romain@orebokech.com>
parents: 68648
diff changeset
98
57100
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
99 ;; Syntax table.
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 (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
102 (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
103 (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
104 (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
105 table)
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
106 "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
107
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
108 ;; Keymap.
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
109
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
110 (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
111 (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
112 (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
113 map)
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
114 "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
115
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
116 ;; Menu.
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
117
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
118 (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
119 "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
120
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
121 (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
122 "DNS Menu."
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
123 '("DNS"
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
124 ["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
125
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
126 ;; Mode.
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
127
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
128 ;;;###autoload
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
129 (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
130 "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
131 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
132 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
133 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
134 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
135 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
136
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
137 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
138 (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
139 (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
140 (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
141 (unless (featurep 'xemacs)
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
142 (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
143 '(dns-mode-font-lock-keywords nil nil ((?_ . "w")))))
72359
2b576e9ebfa4 (dns-mode): Use before-save-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72350
diff changeset
144 (add-hook 'before-save-hook 'dns-mode-soa-maybe-increment-serial
72350
45347140c0d0 * textmodes/dns-mode.el: Alias `zone-mode' to `dns-mode'.
Romain Francoise <romain@orebokech.com>
parents: 68648
diff changeset
145 nil t)
57100
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
146 (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
147
72350
45347140c0d0 * textmodes/dns-mode.el: Alias `zone-mode' to `dns-mode'.
Romain Francoise <romain@orebokech.com>
parents: 68648
diff changeset
148 ;;;###autoload (defalias 'zone-mode 'dns-mode)
45347140c0d0 * textmodes/dns-mode.el: Alias `zone-mode' to `dns-mode'.
Romain Francoise <romain@orebokech.com>
parents: 68648
diff changeset
149
57100
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
150 ;; Tools.
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
151
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
152 ;;;###autoload
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
153 (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
154 "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
155 (interactive)
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
156 (save-excursion
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
157 (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
158 (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
159 (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
160 "[ \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
161 (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
162 (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
163 ;; year
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
164 "\\(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
165 ;; month
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
166 "\\(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
167 ;; day
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
168 "\\([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
169 ;; counter
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
170 "\\([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
171 "\\)\\>")
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
172 nil t)
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
173 ;; 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
174 (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
175 (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
176 (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
177 (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
178 (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
179 (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
180 (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
181 (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
182 (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
183 (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
184 (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
185 now (1+ counter))))
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
186 (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
187 (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
188 (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
189 (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
190 ;; Unix time
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
191 (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
192 (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
193 (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
194 (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
195 (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
196 (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
197 (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
198 ;; 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
199 (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
200 (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
201 (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
202 (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
203 (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
204
72350
45347140c0d0 * textmodes/dns-mode.el: Alias `zone-mode' to `dns-mode'.
Romain Francoise <romain@orebokech.com>
parents: 68648
diff changeset
205 (defun dns-mode-soa-maybe-increment-serial ()
45347140c0d0 * textmodes/dns-mode.el: Alias `zone-mode' to `dns-mode'.
Romain Francoise <romain@orebokech.com>
parents: 68648
diff changeset
206 "Increment SOA serial if needed.
45347140c0d0 * textmodes/dns-mode.el: Alias `zone-mode' to `dns-mode'.
Romain Francoise <romain@orebokech.com>
parents: 68648
diff changeset
207
72359
2b576e9ebfa4 (dns-mode): Use before-save-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72350
diff changeset
208 This function is run from `before-save-hook'."
72350
45347140c0d0 * textmodes/dns-mode.el: Alias `zone-mode' to `dns-mode'.
Romain Francoise <romain@orebokech.com>
parents: 68648
diff changeset
209 (when (and (buffer-modified-p)
45347140c0d0 * textmodes/dns-mode.el: Alias `zone-mode' to `dns-mode'.
Romain Francoise <romain@orebokech.com>
parents: 68648
diff changeset
210 dns-mode-soa-auto-increment-serial
45347140c0d0 * textmodes/dns-mode.el: Alias `zone-mode' to `dns-mode'.
Romain Francoise <romain@orebokech.com>
parents: 68648
diff changeset
211 (or (eq dns-mode-soa-auto-increment-serial t)
45347140c0d0 * textmodes/dns-mode.el: Alias `zone-mode' to `dns-mode'.
Romain Francoise <romain@orebokech.com>
parents: 68648
diff changeset
212 (y-or-n-p "Increment SOA serial? ")))
72361
3b5cb5e41d55 Fix formatting/indentation.
Romain Francoise <romain@orebokech.com>
parents: 72359
diff changeset
213 ;; If `dns-mode-soa-increment-serial' signals an error saving will
3b5cb5e41d55 Fix formatting/indentation.
Romain Francoise <romain@orebokech.com>
parents: 72359
diff changeset
214 ;; fail but that probably means that the serial should be fixed to
3b5cb5e41d55 Fix formatting/indentation.
Romain Francoise <romain@orebokech.com>
parents: 72359
diff changeset
215 ;; comply with the RFC anyway! -rfr
72359
2b576e9ebfa4 (dns-mode): Use before-save-hook.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72350
diff changeset
216 (progn (dns-mode-soa-increment-serial)
72361
3b5cb5e41d55 Fix formatting/indentation.
Romain Francoise <romain@orebokech.com>
parents: 72359
diff changeset
217 ;; We return nil in case this is used in write-contents-functions.
3b5cb5e41d55 Fix formatting/indentation.
Romain Francoise <romain@orebokech.com>
parents: 72359
diff changeset
218 nil)))
72350
45347140c0d0 * textmodes/dns-mode.el: Alias `zone-mode' to `dns-mode'.
Romain Francoise <romain@orebokech.com>
parents: 68648
diff changeset
219
57100
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
220 (provide 'dns-mode)
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
221
3eab555cf92b files.el (auto-mode-alist): Map .soa and .zone to dns-mode.
Simon Josefsson <jas@extundo.com>
parents:
diff changeset
222 ;;; dns-mode.el ends here