diff options
| author | Richard M. Stallman | 1998-03-08 00:53:39 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-03-08 00:53:39 +0000 |
| commit | e275fa086c90111a0ca83c9bd64ce3c7debbce07 (patch) | |
| tree | 094bd21d0929122766b6868adc0cfea31cbfa96e | |
| parent | 73b3354550f3f7a4f544d5be5f431a91cd6f0123 (diff) | |
| download | emacs-e275fa086c90111a0ca83c9bd64ce3c7debbce07.tar.gz emacs-e275fa086c90111a0ca83c9bd64ce3c7debbce07.zip | |
Initial revision
| -rw-r--r-- | lisp/zone-mode.el | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/lisp/zone-mode.el b/lisp/zone-mode.el new file mode 100644 index 00000000000..345fd22e53d --- /dev/null +++ b/lisp/zone-mode.el | |||
| @@ -0,0 +1,118 @@ | |||
| 1 | ;;; zone-mode.el -- major mode for editing DNS zone files. | ||
| 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 | |||
| 25 | ;;; | ||
| 26 | ;;; See the comments in ``define-derived-mode zone-mode'' | ||
| 27 | ;;; (the last function in this file) | ||
| 28 | ;;; for what this mode is and how to use it automatically. | ||
| 29 | ;;; | ||
| 30 | |||
| 31 | ;;; | ||
| 32 | ;;; Credits: | ||
| 33 | ;;; Zone-mode was written by John Heidemann <johnh@isi.edu>, | ||
| 34 | ;;; with bug fixes from Simon Leinen <simon@limmat.switch.ch>. | ||
| 35 | ;;; | ||
| 36 | |||
| 37 | ;;; Code: | ||
| 38 | |||
| 39 | (defun zone-mode-update-serial () | ||
| 40 | "Update the serial number in a zone." | ||
| 41 | (interactive) | ||
| 42 | (save-excursion | ||
| 43 | (goto-char (point-min)) | ||
| 44 | (while (re-search-forward "\\b\\([0-9]+\\)\\([0-9][0-9]\\)\\([ \t]+;[ \t]+[Ss]erial\\)" (point-max) t) | ||
| 45 | (let* ((old-date (match-string 1)) | ||
| 46 | (old-seq (match-string 2)) | ||
| 47 | (old-seq-num (string-to-number (match-string 2))) | ||
| 48 | (old-flag (match-string 3)) | ||
| 49 | (cur-date (format-time-string "%Y%m%d")) | ||
| 50 | (new-seq | ||
| 51 | (cond | ||
| 52 | ((not (string= old-date cur-date)) | ||
| 53 | "00") ;; reset sequeence number | ||
| 54 | ((>= old-seq-num 99) | ||
| 55 | (error "Serial number's sequenece cannot increment beyond 99.")) | ||
| 56 | (t | ||
| 57 | (format "%02d" (1+ old-seq-num))))) | ||
| 58 | (old-serial (concat old-date old-seq)) | ||
| 59 | (new-serial (concat cur-date new-seq))) | ||
| 60 | (if (string-lessp new-serial old-serial) | ||
| 61 | (error (format "Serial numbers want to move backwards from %s to %s!" old-serial new-serial)) | ||
| 62 | (replace-match (concat cur-date new-seq old-flag) t t)))))) | ||
| 63 | |||
| 64 | ;;;###autoload | ||
| 65 | (defun zone-mode-update-serial-hook () | ||
| 66 | "Update the serial number in a zone if the file was modified" | ||
| 67 | (interactive) | ||
| 68 | (if (buffer-modified-p (current-buffer)) | ||
| 69 | (zone-mode-update-serial)) | ||
| 70 | nil ;; so we can run from write-file-hooks | ||
| 71 | ) | ||
| 72 | |||
| 73 | (defvar zone-mode-syntax-table nil | ||
| 74 | "Zone-mode's syntax table.") | ||
| 75 | |||
| 76 | (defun zone-mode-load-time-setup () | ||
| 77 | "init zone-mode stuff" | ||
| 78 | (setq zone-mode-syntax-table (make-syntax-table)) | ||
| 79 | (modify-syntax-entry ?\; "<" zone-mode-syntax-table) | ||
| 80 | (modify-syntax-entry ?\n ">" zone-mode-syntax-table)) | ||
| 81 | |||
| 82 | ;;;###autoload | ||
| 83 | (define-derived-mode zone-mode fundamental-mode "zone" | ||
| 84 | "A mode for editing DNS zone files. | ||
| 85 | |||
| 86 | Zone-mode does two things: | ||
| 87 | |||
| 88 | - automatically update the serial number for a zone | ||
| 89 | when saving the file | ||
| 90 | |||
| 91 | - fontification" | ||
| 92 | |||
| 93 | (require 'zone-mode) | ||
| 94 | (make-variable-buffer-local 'write-file-hooks) | ||
| 95 | (add-hook 'write-file-hooks 'zone-mode-update-serial-hook) | ||
| 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 | ||