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