Update copyright year to 2016
[gnus] / lisp / dns-mode.el
index d484bfb..521b1f3 100644 (file)
@@ -1,25 +1,24 @@
 ;;; dns-mode.el --- a mode for viewing/editing Domain Name System master files
-;; Copyright (c) 2000, 2001, 2003, 2004 Free Software Foundation, Inc.
+
+;; Copyright (C) 2000-2001, 2004-2016 Free Software Foundation, Inc.
 
 ;; Author: Simon Josefsson <simon@josefsson.org>
-;; Keywords: DNS master zone file SOA
+;; Keywords: DNS master zone file SOA comm
 
-;; This file is not part of GNU Emacs.
+;; This file is part of GNU Emacs.
 
-;; This file is free software; you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published
-;; by the Free Software Foundation; either version 2, or (at your
-;; option) any later version.
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
-;; This file is distributed in the hope that it will be useful, but
-;; WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-;; General Public License for more details.
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with This file; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
 ;; C-c C-s  Increment SOA serial.
 ;;          Understands YYYYMMDDNN, Unix time, and serial number formats,
 ;;          and complains if it fail to find SOA serial.
-;;
-;; Put something similar to the following in your ~/.emacs to use this file:
-;;
-;; (load "~/path/to/dns-mode.el")
-;; (setq auto-mode-alist (cons '("\\.soa\\'" . dns-mode) auto-mode-alist))
 
 ;;; References:
 
 
 ;;; Release history:
 
-;; 2004-09-11  posted on gnu.emacs.sources
+;; 2004-09-11  Posted on gnu.emacs.sources.
+;; 2004-09-13  Ported to XEmacs.
+;; 2004-09-14  Installed in Emacs CVS.
 
 ;;; Code:
 
 (defgroup dns-mode nil
-  "DNS master file mode configuration.")
+  "DNS master file mode configuration."
+  :group 'data)
 
 (defconst dns-mode-classes '("IN" "CS" "CH" "HS")
   "List of strings with known DNS classes.")
   "Name of face used for DNS classes, e.g., IN.")
 
 (defcustom dns-mode-font-lock-keywords
-  `(("^$ORIGIN" 0 dns-mode-control-entity-face)
-    ("^$INCLUDE" 0 dns-mode-control-entity-face)
-    ("^$[a-z0-9A-Z]+" 0 dns-mode-bad-control-entity-face)
-    (,(regexp-opt dns-mode-classes) 0 dns-mode-class-face)
-    (,(regexp-opt dns-mode-types) 0 dns-mode-type-face))
+  `(("^$ORIGIN" 0 ,dns-mode-control-entity-face)
+    ("^$INCLUDE" 0 ,dns-mode-control-entity-face)
+    ("^$[a-z0-9A-Z]+" 0 ,dns-mode-bad-control-entity-face)
+    (,(regexp-opt dns-mode-classes) 0 ,dns-mode-class-face)
+    (,(regexp-opt dns-mode-types) 0 ,dns-mode-type-face))
   "Font lock keywords used to highlight text in DNS master file mode."
   :type 'sexp
   :group 'dns-mode)
 
+(defcustom dns-mode-soa-auto-increment-serial t
+  "Whether to increment the SOA serial number automatically.
+
+If this variable is t, the serial number is incremented upon each save of
+the file.  If it is `ask', Emacs asks for confirmation whether it should
+increment the serial upon saving.  If nil, serials must be incremented
+manually with \\[dns-mode-soa-increment-serial]."
+  :type '(choice (const :tag "Always" t)
+                (const :tag "Ask" ask)
+                (const :tag "Never" nil))
+  :group 'dns-mode)
+
 ;; Syntax table.
 
 (defvar dns-mode-syntax-table
@@ -131,7 +140,11 @@ Turning on DNS mode runs `dns-mode-hook'."
   (unless (featurep 'xemacs)
     (set (make-local-variable 'font-lock-defaults)
         '(dns-mode-font-lock-keywords nil nil ((?_ . "w")))))
-  (easy-menu-add-item nil nil dns-mode-menu))
+  (add-hook 'before-save-hook 'dns-mode-soa-maybe-increment-serial
+           nil t)
+  (easy-menu-add dns-mode-menu dns-mode-map))
+
+;;;###autoload (defalias 'zone-mode 'dns-mode)
 
 ;; Tools.
 
@@ -188,6 +201,21 @@ Turning on DNS mode runs `dns-mode-hook'."
              (message "Replaced old serial %s with %s" serial new))
          (error "Cannot locate serial number in SOA record"))))))
 
+(defun dns-mode-soa-maybe-increment-serial ()
+  "Increment SOA serial if needed.
+
+This function is run from `before-save-hook'."
+  (when (and (buffer-modified-p)
+            dns-mode-soa-auto-increment-serial
+            (or (eq dns-mode-soa-auto-increment-serial t)
+                (y-or-n-p "Increment SOA serial? ")))
+    ;; If `dns-mode-soa-increment-serial' signals an error saving will
+    ;; fail but that probably means that the serial should be fixed to
+    ;; comply with the RFC anyway! -rfr
+    (progn (dns-mode-soa-increment-serial)
+          ;; We return nil in case this is used in write-contents-functions.
+          nil)))
+
 (provide 'dns-mode)
 
 ;;; dns-mode.el ends here