annotate lisp/net/zone-mode.el @ 39822:0c3ebbbc4922

*** empty log message ***
author Gerd Moellmann <gerd@gnu.org>
date Fri, 12 Oct 2001 10:05:27 +0000
parents b174db545cfd
children 66a34741f47c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 28210
diff changeset
1 ;;; zone-mode.el --- major mode for editing DNS zone files
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1998 Free Software Foundation, Inc.
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
4
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5 ;; Author: John Heidemann <johnh@isi.edu>
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
6 ;; Keywords: DNS, languages
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13 ;; any later version.
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 28210
diff changeset
25 ;;; Commentary:
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 28210
diff changeset
26
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27 ;;;
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28 ;;; See the comments in ``define-derived-mode zone-mode''
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29 ;;; (the last function in this file)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
30 ;;; for what this mode is and how to use it automatically.
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31 ;;;
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33 ;;;
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34 ;;; Credits:
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35 ;;; Zone-mode was written by John Heidemann <johnh@isi.edu>,
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36 ;;; with bug fixes from Simon Leinen <simon@limmat.switch.ch>.
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37 ;;;
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39 ;;; Code:
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 (defun zone-mode-update-serial ()
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42 "Update the serial number in a zone."
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43 (interactive)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44 (save-excursion
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45 (goto-char (point-min))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46 (while (re-search-forward "\\b\\([0-9]+\\)\\([0-9][0-9]\\)\\([ \t]+;[ \t]+[Ss]erial\\)" (point-max) t)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47 (let* ((old-date (match-string 1))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 (old-seq (match-string 2))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
49 (old-seq-num (string-to-number (match-string 2)))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
50 (old-flag (match-string 3))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
51 (cur-date (format-time-string "%Y%m%d"))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 (new-seq
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 (cond
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54 ((not (string= old-date cur-date))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55 "00") ;; reset sequeence number
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56 ((>= old-seq-num 99)
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 28210
diff changeset
57 (error "Serial number's sequenece cannot increment beyond 99"))
28210
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 (t
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59 (format "%02d" (1+ old-seq-num)))))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60 (old-serial (concat old-date old-seq))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61 (new-serial (concat cur-date new-seq)))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62 (if (string-lessp new-serial old-serial)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63 (error (format "Serial numbers want to move backwards from %s to %s!" old-serial new-serial))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64 (replace-match (concat cur-date new-seq old-flag) t t))))))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66 ;;;###autoload
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 (defun zone-mode-update-serial-hook ()
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68 "Update the serial number in a zone if the file was modified"
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69 (interactive)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 (if (buffer-modified-p (current-buffer))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71 (zone-mode-update-serial))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72 nil ;; so we can run from write-file-hooks
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73 )
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 (defvar zone-mode-syntax-table nil
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76 "Zone-mode's syntax table.")
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 (defun zone-mode-load-time-setup ()
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79 "init zone-mode stuff"
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 (setq zone-mode-syntax-table (make-syntax-table))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81 (modify-syntax-entry ?\; "<" zone-mode-syntax-table)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82 (modify-syntax-entry ?\n ">" zone-mode-syntax-table))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 ;;;###autoload
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85 (define-derived-mode zone-mode fundamental-mode "zone"
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86 "A mode for editing DNS zone files.
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88 Zone-mode does two things:
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90 - automatically update the serial number for a zone
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91 when saving the file
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 - fontification"
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 (make-local-hook 'write-file-hooks)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96 (add-hook 'write-file-hooks 'zone-mode-update-serial-hook)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
97
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 (if (null zone-mode-syntax-table)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99 (zone-mode-load-time-setup)) ;; should have been run at load-time
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101 ;; font-lock support:
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 (set-syntax-table zone-mode-syntax-table)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103 (make-local-variable 'comment-start)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104 (setq comment-start ";")
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105 (make-local-variable 'comment-start-skip)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106 ;; Look within the line for a ; following an even number of backslashes
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
107 ;; after either a non-backslash or the line beginning.
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
108 (setq comment-start-skip "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\);+[ \t]*")
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
109 (make-local-variable 'comment-column)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
110 (setq comment-column 40)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
111 (make-local-variable 'font-lock-defaults)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
112 (setq font-lock-defaults
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
113 '(nil nil nil nil beginning-of-line)))
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
114
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115 (zone-mode-load-time-setup)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
116
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
117 (provide 'zone-mode)
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118
b56f9152e329 Moved here from lisp.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
119 ;;; zone-mode.el ends here