annotate lisp/zone-mode.el @ 26596:f908261703d3

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