Mercurial > emacs
annotate lisp/net/zone-mode.el @ 69185:ee54b3a792ff
This version does *not* work with Emacs 22.
It is just the initial import from gpm-1.20.1.
author | Nick Roberts <nickrob@snap.net.nz> |
---|---|
date | Mon, 27 Feb 2006 22:10:43 +0000 |
parents | 067115a6e738 |
children | c5406394f567 |
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 |
68648
067115a6e738
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64701
diff
changeset
|
3 ;; Copyright (C) 1998, 2002, 2003, 2004, 2005, |
067115a6e738
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64701
diff
changeset
|
4 ;; 2006 Free Software Foundation, Inc. |
28210 | 5 |
6 ;; Author: John Heidemann <johnh@isi.edu> | |
7 ;; Keywords: DNS, languages | |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64085 | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 ;; Boston, MA 02110-1301, USA. | |
28210 | 25 |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
28210
diff
changeset
|
26 ;;; Commentary: |
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
28210
diff
changeset
|
27 |
28210 | 28 ;;; |
29 ;;; See the comments in ``define-derived-mode zone-mode'' | |
30 ;;; (the last function in this file) | |
31 ;;; for what this mode is and how to use it automatically. | |
32 ;;; | |
33 | |
34 ;;; | |
35 ;;; Credits: | |
36 ;;; Zone-mode was written by John Heidemann <johnh@isi.edu>, | |
37 ;;; with bug fixes from Simon Leinen <simon@limmat.switch.ch>. | |
38 ;;; | |
39 | |
40 ;;; Code: | |
41 | |
42 (defun zone-mode-update-serial () | |
43 "Update the serial number in a zone." | |
44 (interactive) | |
45 (save-excursion | |
46 (goto-char (point-min)) | |
47 (while (re-search-forward "\\b\\([0-9]+\\)\\([0-9][0-9]\\)\\([ \t]+;[ \t]+[Ss]erial\\)" (point-max) t) | |
48 (let* ((old-date (match-string 1)) | |
49 (old-seq (match-string 2)) | |
50 (old-seq-num (string-to-number (match-string 2))) | |
51 (old-flag (match-string 3)) | |
52 (cur-date (format-time-string "%Y%m%d")) | |
53 (new-seq | |
54 (cond | |
55 ((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
|
56 "00") ;; reset sequence number |
28210 | 57 ((>= old-seq-num 99) |
41944
66a34741f47c
(zone-mode): Don't use make-local-hook.
Pavel Janík <Pavel@Janik.cz>
parents:
38436
diff
changeset
|
58 (error "Serial number's sequence cannot increment beyond 99")) |
28210 | 59 (t |
60 (format "%02d" (1+ old-seq-num))))) | |
61 (old-serial (concat old-date old-seq)) | |
62 (new-serial (concat cur-date new-seq))) | |
63 (if (string-lessp new-serial old-serial) | |
63490
65b21147737a
(zone-mode-update-serial): Don't use `format' on `error' arguments.
Juanma Barranquero <lekktu@gmail.com>
parents:
62437
diff
changeset
|
64 (error "Serial numbers want to move backwards from %s to %s" old-serial new-serial) |
28210 | 65 (replace-match (concat cur-date new-seq old-flag) t t)))))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
45017
diff
changeset
|
66 |
28210 | 67 ;;;###autoload |
68 (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
|
69 "Update the serial number in a zone if the file was modified." |
28210 | 70 (interactive) |
71 (if (buffer-modified-p (current-buffer)) | |
72 (zone-mode-update-serial)) | |
73 nil ;; so we can run from write-file-hooks | |
74 ) | |
75 | |
76 (defvar zone-mode-syntax-table nil | |
77 "Zone-mode's syntax table.") | |
78 | |
79 (defun zone-mode-load-time-setup () | |
63515
e32d37b16b0e
(zone-mode-load-time-setup): Fix spelling in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents:
63490
diff
changeset
|
80 "Initialize `zone-mode' stuff." |
28210 | 81 (setq zone-mode-syntax-table (make-syntax-table)) |
82 (modify-syntax-entry ?\; "<" zone-mode-syntax-table) | |
83 (modify-syntax-entry ?\n ">" zone-mode-syntax-table)) | |
84 | |
85 ;;;###autoload | |
86 (define-derived-mode zone-mode fundamental-mode "zone" | |
87 "A mode for editing DNS zone files. | |
88 | |
89 Zone-mode does two things: | |
90 | |
91 - automatically update the serial number for a zone | |
92 when saving the file | |
93 | |
94 - fontification" | |
95 | |
53382
2a2faa2f1d56
(zone-mode): Use write-file-functions, not write-file-hooks.
Eli Zaretskii <eliz@is.elta.co.il>
parents:
52401
diff
changeset
|
96 (add-hook 'write-file-functions 'zone-mode-update-serial-hook nil t) |
28210 | 97 |
98 (if (null zone-mode-syntax-table) | |
99 (zone-mode-load-time-setup)) ;; should have been run at load-time | |
100 | |
101 ;; font-lock support: | |
102 (set-syntax-table zone-mode-syntax-table) | |
103 (make-local-variable 'comment-start) | |
104 (setq comment-start ";") | |
105 (make-local-variable 'comment-start-skip) | |
106 ;; Look within the line for a ; following an even number of backslashes | |
107 ;; after either a non-backslash or the line beginning. | |
108 (setq comment-start-skip "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\);+[ \t]*") | |
109 (make-local-variable 'comment-column) | |
110 (setq comment-column 40) | |
111 (make-local-variable 'font-lock-defaults) | |
112 (setq font-lock-defaults | |
113 '(nil nil nil nil beginning-of-line))) | |
114 | |
115 (zone-mode-load-time-setup) | |
116 | |
117 (provide 'zone-mode) | |
118 | |
52401 | 119 ;;; arch-tag: 6a2940ef-fd4f-4de7-b979-b027b09821fe |
28210 | 120 ;;; zone-mode.el ends here |