delete_temp_file fix
[bpt/emacs.git] / lisp / printing.el
index ecbc82e..39da132 100644 (file)
@@ -1,7 +1,6 @@
 ;;; printing.el --- printing utilities
 
-;; Copyright (C) 2000, 2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
-;;   2010  Free Software Foundation, Inc.
+;; Copyright (C) 2000-2001, 2003-2014 Free Software Foundation, Inc.
 
 ;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br>
 ;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br>
@@ -13,7 +12,7 @@
   "printing.el, v 6.9.3 <2007/12/09 vinicius>
 
 Please send all bug fixes and enhancements to
-       Vinicius Jose Latorre <viniciusjl@ig.com.br>
+       bug-gnu-emacs@gnu.org and Vinicius Jose Latorre <viniciusjl@ig.com.br>
 ")
 
 ;; This file is part of GNU Emacs.
@@ -140,10 +139,9 @@ Please send all bug fixes and enhancements to
 ;;
 ;; One way to set variables is by calling `pr-customize', customize all
 ;; variables and save the customization by future sessions (see Options
-;; section).  Other way is by coding your settings on Emacs init file (that is,
-;; ~/.emacs file), see below for a first setting template that it should be
-;; inserted on your ~/.emacs file (or c:/_emacs, if you're using Windows 9x/NT
-;; or MS-DOS):
+;; section).  Other way is by adding code to your init file; see below
+;; for a first setting template that it should be inserted on your
+;; init file:
 ;;
 ;; * Example of setting for Windows system:
 ;;
@@ -298,8 +296,7 @@ Please send all bug fixes and enhancements to
 ;; Using `printing'
 ;; ----------------
 ;;
-;; To use `printing' insert in your ~/.emacs file (or c:/_emacs, if you're
-;; using Windows 9x/NT or MS-DOS):
+;; To use `printing' insert in your init file:
 ;;
 ;;    (require 'printing)
 ;;    ;; ...some user settings...
@@ -548,7 +545,7 @@ Please send all bug fixes and enhancements to
 ;; `pr-auto-region'            Non-nil means region is automagically detected.
 ;;
 ;; `pr-auto-mode'              Non-nil means major-mode specific printing is
-;;                             prefered over normal printing.
+;;                             preferred over normal printing.
 ;;
 ;; `pr-mode-alist'             Specify an alist for a major-mode and printing
 ;;                             function.
@@ -1033,7 +1030,7 @@ Please send all bug fixes and enhancements to
 
 
 (defconst pr-cygwin-system
-  (and ps-windows-system (getenv "OSTYPE")
+  (and lpr-windows-system (getenv "OSTYPE")
        (string-match "cygwin" (getenv "OSTYPE"))))
 
 
@@ -1041,20 +1038,27 @@ Please send all bug fixes and enhancements to
 ;; To avoid compilation gripes
 
 
-(or (fboundp 'subst-char-in-string)    ; hacked from subr.el
-    (defun subst-char-in-string (fromchar tochar string &optional inplace)
-      "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
+;; Emacs has this since at least 21.1.
+(when (featurep 'xemacs)
+  (or (fboundp 'subst-char-in-string)  ; hacked from subr.el
+      (defun subst-char-in-string (fromchar tochar string &optional inplace)
+       "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
 Unless optional argument INPLACE is non-nil, return a new string."
-      (let ((i (length string))
-           (newstr (if inplace string (copy-sequence string))))
-       (while (> (setq i (1- i)) 0)
-         (if (eq (aref newstr i) fromchar)
-             (aset newstr i tochar)))
-       newstr)))
-
-
-(or (fboundp 'make-temp-file)          ; hacked from subr.el
-    (defun make-temp-file (prefix &optional dir-flag suffix)
+       (let ((i (length string))
+             (newstr (if inplace string (copy-sequence string))))
+         (while (> (setq i (1- i)) 0)
+           (if (eq (aref newstr i) fromchar)
+               (aset newstr i tochar)))
+         newstr))))
+
+
+;; Emacs has this since at least 21.1, but the SUFFIX argument
+;; (which this file uses) only since 22.1.  So the fboundp test
+;; wasn't even correct/adequate.  Whatever, no-one is using
+;; this file on older Emacs version, so it's irrelevant.
+(when (featurep 'xemacs)
+  (or (fboundp 'make-temp-file)                ; hacked from subr.el
+      (defun make-temp-file (prefix &optional dir-flag suffix)
       "Create a temporary file.
 The returned file name (created by appending some random characters at the end
 of PREFIX, and expanding against `temporary-file-directory' if necessary),
@@ -1089,7 +1093,7 @@ If SUFFIX is non-nil, add that at the end of the file name."
                nil)
              file)
          ;; Reset the umask.
-         (set-default-file-modes umask)))))
+         (set-default-file-modes umask))))))
 
 
 (eval-when-compile
@@ -1345,6 +1349,10 @@ Used by `pr-menu-bind' and `pr-update-menus'.")
 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; GNU Emacs Definitions
 
+(eval-and-compile
+  (unless (featurep 'xemacs)
+    (defvar pr-menu-bar nil
+      "Specify Printing menu-bar entry.")))
 
 (cond
  ((featurep 'xemacs)                   ; XEmacs
@@ -1375,9 +1383,6 @@ Used by `pr-menu-bind' and `pr-update-menus'.")
   (defun pr-menu-char-width ()
     (frame-char-width))
 
-  (defvar pr-menu-bar nil
-    "Specify Printing menu-bar entry.")
-
   ;; GNU Emacs
   ;; Menu binding
   ;; Replace existing "print" item by "Printing" item.
@@ -1386,6 +1391,10 @@ Used by `pr-menu-bind' and `pr-update-menus'.")
   (eval-when-compile
     (require 'easymenu))               ; to avoid compilation gripes
 
+  (declare-function easy-menu-add-item "easymenu"
+                    (map path item &optional before))
+  (declare-function easy-menu-remove-item "easymenu" (map path name))
+
   (eval-and-compile
       (defun pr-global-menubar (pr-menu-spec)
        (require 'easymenu)
@@ -1412,7 +1421,7 @@ Used by `pr-menu-bind' and `pr-update-menus'.")
 
   (eval-and-compile
     (cond
-     (ps-windows-system
+     (lpr-windows-system
       ;; GNU Emacs for Windows 9x/NT
       (defun pr-menu-position (entry index horizontal)
        (let ((pos (cdr (mouse-pixel-position))))
@@ -1612,7 +1621,7 @@ Used by `pr-menu-bind' and `pr-update-menus'.")
   "Ensure the proper directory separator depending on the OS.
 That is, if Emacs is running on DOS/Windows, ensure dos/windows-style directory
 separator; otherwise, ensure unix-style directory separator."
-  (if (or pr-cygwin-system ps-windows-system)
+  (if (or pr-cygwin-system lpr-windows-system)
       (subst-char-in-string ?/ ?\\ path)
     (subst-char-in-string ?\\ ?/ path)))
 
@@ -1665,7 +1674,7 @@ separator; otherwise, ensure unix-style directory separator."
 
 (defcustom pr-path-style
   (if (and (not pr-cygwin-system)
-          ps-windows-system)
+          lpr-windows-system)
       'windows
     'unix)
   "Specify which path style to use for external commands.
@@ -1776,7 +1785,7 @@ function (see it for documentation) to update text printer menu."
 (defcustom pr-txt-printer-alist
   (list (list 'default lpr-command nil
              (cond ((boundp 'printer-name) printer-name)
-                   (ps-windows-system "PRN")
+                   (lpr-windows-system "PRN")
                    (t nil)
                    )))
   ;; Examples:
@@ -1799,7 +1808,7 @@ The alist element has the form:
 Where:
 
 SYMBOL         It's a symbol to identify a text printer.  It's for
-               `pr-txt-name' variable setting and for menu selection.
+               setting option `pr-txt-name' and for menu selection.
                Examples:
                        'prt_06a
                        'my_printer
@@ -1921,8 +1930,8 @@ function (see it for documentation) to update PostScript printer menu."
 
 (defcustom pr-ps-printer-alist
   (list (list 'default lpr-command nil
-             (cond (ps-windows-system  nil)
-                   (ps-lp-system       "-d")
+             (cond (lpr-windows-system  nil)
+                   (lpr-lp-system       "-d")
                    (t                  "-P"))
              (or (getenv "PRINTER") (getenv "LPDEST") ps-printer-name)))
   ;; Examples:
@@ -1950,7 +1959,7 @@ The alist element has the form:
 Where:
 
 SYMBOL         It's a symbol to identify a PostScript printer.  It's for
-               `pr-ps-name' variable setting and for menu selection.
+               setting option `pr-ps-name' and for menu selection.
                Examples:
                        'prt_06a
                        'my_printer
@@ -2142,7 +2151,7 @@ Useful links:
   `http://bama.ua.edu/cgi-bin/man-cgi?lp'
   `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lp'
 
-* GNU utilities for Win32 (cp.exe)
+* GNU utilities for w32 (cp.exe)
   `http://unxutils.sourceforge.net/'
 "
   :type '(repeat
@@ -2198,7 +2207,7 @@ Useful links:
      ;; hacked from `temporary-file-directory' variable in files.el
      (file-name-as-directory
       (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP")
-         (cond (ps-windows-system "c:/temp")
+         (cond (lpr-windows-system "c:/temp")
                (t "/tmp")
                )))))
   "Specify a directory for temporary files during printing.
@@ -2230,7 +2239,7 @@ See also `pr-temp-dir' and `pr-ps-temp-file'."
 
 
 (defcustom pr-gv-command
-  (if ps-windows-system
+  (if lpr-windows-system
       "gsview32.exe"
     "gv")
   "Specify path and name of the gsview/gv utility.
@@ -2271,7 +2280,7 @@ Useful links:
 
 
 (defcustom pr-gs-command
-  (if ps-windows-system
+  (if lpr-windows-system
       "gswin32.exe"
     "gs")
   "Specify path and name of the ghostscript utility.
@@ -2297,7 +2306,7 @@ Useful links:
 
 
 (defcustom pr-gs-switches
-  (if ps-windows-system
+  (if lpr-windows-system
       '("-q -dNOPAUSE -Ic:/gs/gs5.50;c:/gs/gs5.50/fonts")
     '("-q -dNOPAUSE -I/usr/share/ghostscript/5.10"))
   "Specify ghostscript switches.  See the documentation on GS for more info.
@@ -2339,7 +2348,7 @@ Useful links:
 
 
 (defcustom pr-gs-device
-  (if ps-windows-system
+  (if lpr-windows-system
       "mswinpr2"
     "uniprint")
   "Specify the ghostscript device switch value (-sDEVICE=).
@@ -2427,7 +2436,7 @@ marked instead of all buffer."
 
 
 (defcustom pr-auto-mode t
-  "Non-nil means major-mode specific printing is prefered over normal printing.
+  "Non-nil means major-mode specific printing is preferred over normal printing.
 
 That is, if current major-mode is declared in `pr-mode-alist', the `*-buffer*'
 and `*-region*' commands will behave like `*-mode*' commands; otherwise,
@@ -2537,7 +2546,7 @@ LPR-PRINT It's a symbol function for text printing.  It's invoked with
                nil, it's used (point-max).
 
 PS-PRINT       It's a symbol function for PostScript printing.  It's invoked
-               with 3 arguments: n-up printing, file name and the list:
+               with three arguments: n-up printing, file name and the list:
                (HEADER-LINES  LEFT-HEADER  RIGHT-HEADER DEFAULT...).
 
                Usually PS-PRINT function prepares the environment or buffer
@@ -2934,9 +2943,9 @@ INHERITS  Specify the inheritance for SYMBOL group.  It's a symbol name
 
                The example above has two setting groups: no-duplex and
                no-duplex-and-landscape.  When setting no-duplex is activated
-               through `inherits-from:' (see `pr-ps-utility', `pr-mode-alist'
-               and `pr-ps-printer-alist'), the variables pr-file-duplex and
-               pr-file-tumble are both set to nil.
+               through `inherits-from:' (see option `pr-ps-utility',
+               `pr-mode-alist' and `pr-ps-printer-alist'), the variables
+               pr-file-duplex and pr-file-tumble are both set to nil.
 
                Now when setting no-duplex-and-landscape is activated through
                `inherits-from:', the variable pr-file-landscape is set to nil
@@ -3162,12 +3171,9 @@ See `pr-ps-printer-alist'.")
 
 
 (defmacro pr-save-file-modes (&rest body)
-  "Set temporally file modes to `pr-file-modes'."
-  `(let ((pr--default-file-modes (default-file-modes)))        ; save default
-     (set-default-file-modes pr-file-modes)
-     ,@body
-     (set-default-file-modes pr--default-file-modes))) ; restore default
-
+  "Execute BODY with file permissions temporarily set to `pr-file-modes'."
+  (declare (obsolete with-file-modes "24.5"))
+  `(with-file-modes pr-file-modes ,@body))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Keys & Menus
@@ -3190,9 +3196,10 @@ See `pr-ps-printer-alist'.")
 
 
 (defalias 'pr-get-symbol
-  (if (fboundp 'easy-menu-intern)      ; hacked from easymenu.el
-      'easy-menu-intern
-    (lambda (s) (if (stringp s) (intern s) s))))
+  (if (featurep 'emacs) 'easy-menu-intern ; since 22.1
+    (if (fboundp 'easy-menu-intern)    ; hacked from easymenu.el
+       'easy-menu-intern
+      (lambda (s) (if (stringp s) (intern s) s)))))
 
 
 (defconst pr-menu-spec
@@ -3693,7 +3700,7 @@ VI. Customization:
          "\n\n
 The printing interface buffer has the same functionality as the printing menu.
 The major difference is that the states (like sending PostScript generated to a
-file, n-up printing, etc.) are set and saved between priting buffer
+file, n-up printing, etc.) are set and saved between printing buffer
 activation.  Also, the landscape, duplex and tumble values are the same for
 PostScript file and directory/buffer/region/mode processing; using menu, there
 are different value sets for PostScript file and directory/buffer/region/mode
@@ -4362,12 +4369,12 @@ Noninteractively, the argument FILENAME is treated as follows: if it is nil,
 send the image to the printer.  If FILENAME is a string, save the PostScript
 image in a file with that name."
   (interactive (list (ps-print-preprint current-prefix-arg)))
-  (pr-save-file-modes
-   (let ((ps-lpr-command         (pr-command pr-ps-command))
-        (ps-lpr-switches        pr-ps-switches)
-        (ps-printer-name-option pr-ps-printer-switch)
-        (ps-printer-name        pr-ps-printer))
-     (ps-despool filename))))
+  (with-file-modes pr-file-modes
+    (let ((ps-lpr-command         (pr-command pr-ps-command))
+         (ps-lpr-switches        pr-ps-switches)
+         (ps-printer-name-option pr-ps-printer-switch)
+         (ps-printer-name        pr-ps-printer))
+      (ps-despool filename))))
 
 
 ;;;###autoload
@@ -4612,7 +4619,7 @@ bottom."
 
 ;;;###autoload
 (defun pr-toggle-region ()
-  "Toggle auto region."
+  "Toggle whether the region is automagically detected."
   (interactive)
   (pr-toggle-region-menu t))
 
@@ -4625,21 +4632,21 @@ bottom."
 
 
 ;;;###autoload
-(defun pr-customize (&rest ignore)
+(defun pr-customize (&rest _ignore)
   "Customization of the `printing' group."
   (interactive)
   (customize-group 'printing))
 
 
 ;;;###autoload
-(defun lpr-customize (&rest ignore)
+(defun lpr-customize (&rest _ignore)
   "Customization of the `lpr' group."
   (interactive)
   (customize-group 'lpr))
 
 
 ;;;###autoload
-(defun pr-help (&rest ignore)
+(defun pr-help (&rest _ignore)
   "Help for the printing package."
   (interactive)
   (pr-show-setup pr-help-message "*Printing Help*"))
@@ -4668,26 +4675,26 @@ bottom."
   "Interactively select a PostScript utility."
   (interactive)
   (pr-menu-set-utility-title
-   (pr-complete-alist "Postscript utility"
+   (pr-complete-alist "PostScript utility"
                      pr-ps-utility-alist pr-ps-utility)))
 
 
 ;;;###autoload
-(defun pr-show-ps-setup (&rest ignore)
+(defun pr-show-ps-setup (&rest _ignore)
   "Show current ps-print settings."
   (interactive)
   (pr-show-setup (ps-setup) "*PS Setup*"))
 
 
 ;;;###autoload
-(defun pr-show-pr-setup (&rest ignore)
+(defun pr-show-pr-setup (&rest _ignore)
   "Show current printing settings."
   (interactive)
   (pr-show-setup (pr-setup) "*PR Setup*"))
 
 
 ;;;###autoload
-(defun pr-show-lpr-setup (&rest ignore)
+(defun pr-show-lpr-setup (&rest _ignore)
   "Show current lpr settings."
   (interactive)
   (pr-show-setup (lpr-setup) "*LPR Setup*"))
@@ -4711,12 +4718,12 @@ Interactively, you have the following situations:
 
    M-x pr-ps-fast-fire RET
       The command prompts the user for a N-UP value and printing will
-      immediatelly be done using the current active printer.
+      immediately be done using the current active printer.
 
    C-u   M-x pr-ps-fast-fire RET
    C-u 0 M-x pr-ps-fast-fire RET
       The command prompts the user for a N-UP value and also for a current
-      PostScript printer, then printing will immediatelly be done using the new
+      PostScript printer, then printing will immediately be done using the new
       current active printer.
 
    C-u 1 M-x pr-ps-fast-fire RET
@@ -4737,7 +4744,7 @@ zero and the argument SELECT is treated as follows:
    If it's nil, send the image to the printer.
 
    If it's a list or an integer lesser or equal to zero, the command prompts
-   the user for a current PostScript printer, then printing will immediatelly
+   the user for a current PostScript printer, then printing will immediately
    be done using the new current active printer.
 
    If it's an integer equal to 1, the command prompts the user for a file name
@@ -4750,7 +4757,7 @@ zero and the argument SELECT is treated as follows:
    instead of sending it to the printer.
 
    If it's a symbol which it's defined in `pr-ps-printer-alist', it's the new
-   active printer and printing will immediatelly be done using the new active
+   active printer and printing will immediately be done using the new active
    printer.
 
    Otherwise, send the image to the printer.
@@ -4801,7 +4808,7 @@ Noninteractively, the argument SELECT-PRINTER is treated as follows:
    If it's nil, the printing is sent to the current active text printer.
 
    If it's a symbol which it's defined in `pr-txt-printer-alist', it's the new
-   active printer and printing will immediatelly be done using the new active
+   active printer and printing will immediately be done using the new active
    printer.
 
    If it's non-nil, the command prompts the user for a new active text printer.
@@ -4850,8 +4857,8 @@ Or choose the menu option Printing/Show Settings/printing."
       (ps-comment-string "pr-ps-printer-switch" pr-ps-printer-switch)
       (ps-comment-string "pr-ps-printer       " pr-ps-printer)
       (ps-comment-string "pr-cygwin-system    " pr-cygwin-system)
-      (ps-comment-string "ps-windows-system   " ps-windows-system)
-      (ps-comment-string "ps-lp-system        " ps-lp-system)
+      (ps-comment-string "lpr-windows-system   " lpr-windows-system)
+      (ps-comment-string "lpr-lp-system        " lpr-lp-system)
       nil
       '(14 . pr-path-style)
       '(14 . pr-path-alist)
@@ -5233,14 +5240,14 @@ If menu binding was not done, calls `pr-menu-bind'."
          pr-ps-printer        (nth 3 ps))
     (or (stringp pr-ps-command)
        (setq pr-ps-command
-             (cond (ps-windows-system "print")
-                   (ps-lp-system      "lp")
+             (cond (lpr-windows-system "print")
+                   (lpr-lp-system      "lp")
                    (t                 "lpr")
                    )))
     (or (stringp pr-ps-printer-switch)
        (setq pr-ps-printer-switch
-             (cond (ps-windows-system "/D:")
-                   (ps-lp-system      "-d")
+             (cond (lpr-windows-system "/D:")
+                   (lpr-lp-system      "-d")
                    (t                 "-P")
                    )))
     (pr-eval-alist (nthcdr 4 ps)))
@@ -5258,8 +5265,8 @@ If menu binding was not done, calls `pr-menu-bind'."
          pr-txt-printer  (nth 2 txt)))
   (or (stringp pr-txt-command)
       (setq pr-txt-command
-           (cond (ps-windows-system "print")
-                 (ps-lp-system      "lp")
+           (cond (lpr-windows-system "print")
+                 (lpr-lp-system      "lp")
                  (t                 "lpr")
                  )))
   (pr-update-mode-line))
@@ -5347,102 +5354,119 @@ If menu binding was not done, calls `pr-menu-bind'."
 
 
 (defun pr-toggle-file-duplex-menu (&optional no-menu)
+  "Toggle whether to print PostScript files in duplex mode."
   (interactive)
   (pr-toggle 'pr-file-duplex "PS file duplex" nil 7 5 nil
             '("PostScript Print" "File") no-menu))
 
 
 (defun pr-toggle-file-tumble-menu (&optional no-menu)
+  "Toggle whether to print PostScript files in tumble mode."
   (interactive)
   (pr-toggle 'pr-file-tumble "PS file tumble" nil 8 5 nil
             '("PostScript Print" "File") no-menu))
 
 
 (defun pr-toggle-file-landscape-menu (&optional no-menu)
+  "Toggle whether to print PostScript files in landscape orientation."
   (interactive)
   (pr-toggle 'pr-file-landscape "PS file landscape" nil 6 5 nil
             '("PostScript Print" "File") no-menu))
 
 
 (defun pr-toggle-ghostscript-menu (&optional no-menu)
+  "Toggle whether to print using ghostscript."
   (interactive)
   (pr-toggle 'pr-print-using-ghostscript "Printing using ghostscript"
             'postscript-process 2 12 'toggle nil no-menu))
 
 
 (defun pr-toggle-faces-menu (&optional no-menu)
+  "Toggle whether to print with face attributes."
   (interactive)
   (pr-toggle 'pr-faces-p "Printing with faces"
             'postscript-process 1 12 'toggle nil no-menu))
 
 
 (defun pr-toggle-spool-menu (&optional no-menu)
+  "Toggle whether to spool printing in a buffer."
   (interactive)
   (pr-toggle 'pr-spool-p "Spooling printing"
             'postscript-process 0 12 'toggle nil no-menu))
 
 
 (defun pr-toggle-duplex-menu (&optional no-menu)
+  "Toggle whether to generate PostScript for a two-sided printer."
   (interactive)
   (pr-toggle 'ps-spool-duplex "Printing duplex"
             'postscript-options 5 12 'toggle nil no-menu))
 
 
 (defun pr-toggle-tumble-menu (&optional no-menu)
+  "Toggle how pages on opposite sides of a sheet are oriented."
   (interactive)
   (pr-toggle 'ps-spool-tumble "Tumble"
             'postscript-options 6 12 'toggle nil no-menu))
 
 
 (defun pr-toggle-landscape-menu (&optional no-menu)
+  "Toggle whether to print in landscape mode."
   (interactive)
   (pr-toggle 'ps-landscape-mode "Landscape"
             'postscript-options 0 12 'toggle nil no-menu))
 
 
 (defun pr-toggle-upside-down-menu (&optional no-menu)
+  "Toggle whether to print upside-down (that is, rotated by 180 degrees)."
   (interactive)
   (pr-toggle 'ps-print-upside-down "Upside-Down"
             'postscript-options 7 12 'toggle nil no-menu))
 
 
 (defun pr-toggle-line-menu (&optional no-menu)
+  "Toggle whether to means print line numbers."
   (interactive)
   (pr-toggle 'ps-line-number "Line number"
             'postscript-options 3 12 'toggle nil no-menu))
 
 
 (defun pr-toggle-zebra-menu (&optional no-menu)
+  "Toggle whether to print zebra stripes."
   (interactive)
   (pr-toggle 'ps-zebra-stripes "Zebra stripe"
             'postscript-options 4 12 'toggle nil no-menu))
 
 
 (defun pr-toggle-header-menu (&optional no-menu)
+  "Toggle whether to print a header at the top of each page."
   (interactive)
   (pr-toggle 'ps-print-header "Print header"
             'postscript-options 1 12 'toggle nil no-menu))
 
 
 (defun pr-toggle-header-frame-menu (&optional no-menu)
+  "Toggle whether to draw a gaudy frame around the header."
   (interactive)
   (pr-toggle 'ps-print-header-frame "Print header frame"
             'postscript-options 2 12 'toggle nil no-menu))
 
 
 (defun pr-toggle-lock-menu (&optional no-menu)
+  "Toggle whether the menu is locked while selecting toggle options."
   (interactive)
   (pr-toggle 'pr-menu-lock "Menu lock"
             'printing 2 12 'toggle nil no-menu))
 
 
 (defun pr-toggle-region-menu (&optional no-menu)
+  "Toggle whether the region is automagically detected."
   (interactive)
   (pr-toggle 'pr-auto-region "Auto region"
             'printing 0 12 'toggle nil no-menu))
 
 
 (defun pr-toggle-mode-menu (&optional no-menu)
+  "Toggle whether major-mode specific printing is preferred over normal printing."
   (interactive)
   (pr-toggle 'pr-auto-mode "Auto mode"
             'printing 1 12 'toggle nil no-menu))
@@ -5613,12 +5637,12 @@ If menu binding was not done, calls `pr-menu-bind'."
       (goto-char (point-max))
       (insert (format "%s %S\n" cmd args)))
     ;; *Printing Command Output* == show any return message from command
-    (pr-save-file-modes
-     (setq status
-          (condition-case data
-              (apply 'call-process cmd nil buffer nil args)
-            ((quit error)
-             (error-message-string data)))))
+    (with-file-modes pr-file-modes
+      (setq status
+           (condition-case data
+               (apply 'call-process cmd nil buffer nil args)
+             ((quit error)
+              (error-message-string data)))))
     ;; *Printing Command Output* == show exit status
     (with-current-buffer buffer
       (goto-char (point-max))
@@ -5648,7 +5672,7 @@ If menu binding was not done, calls `pr-menu-bind'."
 (defun pr-switches (switches mess)
   (or (listp switches)
       (error "%S should have a list of strings" mess))
-  (ps-flatten-list                     ; dynamic evaluation
+  (lpr-flatten-list                    ; dynamic evaluation
    (mapcar 'ps-eval-switch switches)))
 
 
@@ -5708,8 +5732,8 @@ If menu binding was not done, calls `pr-menu-bind'."
   (let* ((dir-name   (file-name-directory (or (buffer-file-name)
                                              default-directory)))
         (fmt-prompt (concat "%s[" mess "] Directory to print: "))
-        (dir        (read-file-name (format fmt-prompt "")
-                                    "" dir-name nil dir-name))
+        (dir        (read-directory-name (format fmt-prompt "")
+                                         "" dir-name nil dir-name))
         prompt)
     (while (cond ((not (file-directory-p dir))
                  (ding)
@@ -5719,8 +5743,8 @@ If menu binding was not done, calls `pr-menu-bind'."
                  (setq prompt "Directory is unreadable! "))
                 (t nil))
       (setq dir-name (file-name-directory dir)
-           dir      (read-file-name (format fmt-prompt prompt)
-                                    "" dir-name nil dir-name)))
+           dir      (read-directory-name (format fmt-prompt prompt)
+                                         "" dir-name nil dir-name)))
     (file-name-as-directory dir)))
 
 
@@ -5806,7 +5830,7 @@ If menu binding was not done, calls `pr-menu-bind'."
 
 (defun pr-find-buffer-visiting (file)
   (if (not (file-directory-p file))
-      (find-buffer-visiting (if ps-windows-system
+      (find-buffer-visiting (if lpr-windows-system
                                (downcase file)
                              file))
     (let ((truename (file-truename file))
@@ -5863,42 +5887,42 @@ If menu binding was not done, calls `pr-menu-bind'."
 
 
 (defun pr-text2ps (kind n-up filename &optional from to)
-  (pr-save-file-modes
-   (let ((ps-n-up-printing n-up)
-        (ps-spool-config (and (eq ps-spool-config 'setpagedevice)
-                              'setpagedevice)))
-     (pr-delete-file-if-exists filename)
-     (cond (pr-faces-p
-           (cond (pr-spool-p
-                  ;; pr-faces-p and pr-spool-p
-                  ;; here FILENAME arg is ignored
-                  (cond ((eq kind 'buffer)
-                         (ps-spool-buffer-with-faces))
-                        ((eq kind 'region)
-                         (ps-spool-region-with-faces (or from (point))
-                                                     (or to (mark))))
-                        ))
-                 ;; pr-faces-p and not pr-spool-p
-                 ((eq kind 'buffer)
-                  (ps-print-buffer-with-faces filename))
-                 ((eq kind 'region)
-                  (ps-print-region-with-faces (or from (point))
-                                              (or to (mark)) filename))
-                 ))
-          (pr-spool-p
-           ;; not pr-faces-p and pr-spool-p
-           ;; here FILENAME arg is ignored
-           (cond ((eq kind 'buffer)
-                  (ps-spool-buffer))
-                 ((eq kind 'region)
-                  (ps-spool-region (or from (point)) (or to (mark))))
-                 ))
-          ;; not pr-faces-p and not pr-spool-p
-          ((eq kind 'buffer)
-           (ps-print-buffer filename))
-          ((eq kind 'region)
-           (ps-print-region (or from (point)) (or to (mark)) filename))
-          ))))
+  (with-file-modes pr-file-modes
+    (let ((ps-n-up-printing n-up)
+         (ps-spool-config (and (eq ps-spool-config 'setpagedevice)
+                               'setpagedevice)))
+      (pr-delete-file-if-exists filename)
+      (cond (pr-faces-p
+            (cond (pr-spool-p
+                   ;; pr-faces-p and pr-spool-p
+                   ;; here FILENAME arg is ignored
+                   (cond ((eq kind 'buffer)
+                          (ps-spool-buffer-with-faces))
+                         ((eq kind 'region)
+                          (ps-spool-region-with-faces (or from (point))
+                                                      (or to (mark))))
+                         ))
+                  ;; pr-faces-p and not pr-spool-p
+                  ((eq kind 'buffer)
+                   (ps-print-buffer-with-faces filename))
+                  ((eq kind 'region)
+                   (ps-print-region-with-faces (or from (point))
+                                               (or to (mark)) filename))
+                  ))
+           (pr-spool-p
+            ;; not pr-faces-p and pr-spool-p
+            ;; here FILENAME arg is ignored
+            (cond ((eq kind 'buffer)
+                   (ps-spool-buffer))
+                  ((eq kind 'region)
+                   (ps-spool-region (or from (point)) (or to (mark))))
+                  ))
+           ;; not pr-faces-p and not pr-spool-p
+           ((eq kind 'buffer)
+            (ps-print-buffer filename))
+           ((eq kind 'region)
+            (ps-print-region (or from (point)) (or to (mark)) filename))
+           ))))
 
 
 (defun pr-command (command)
@@ -5920,7 +5944,7 @@ COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
     (pr-dosify-file-name
      (or (pr-find-command command)
         (pr-path-command (cond (pr-cygwin-system  'cygwin)
-                               (ps-windows-system 'windows)
+                               (lpr-windows-system 'windows)
                                (t                 'unix))
                          (file-name-nondirectory command)
                          nil)
@@ -5957,7 +5981,7 @@ COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
 
 
 (defun pr-find-command (cmd)
-  (if ps-windows-system
+  (if lpr-windows-system
       ;; windows system
       (let ((ext (cons (file-name-extension cmd t)
                       (list ".exe" ".bat" ".com")))
@@ -6065,6 +6089,8 @@ COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
   (and pr-i-region                     ; let region activated
        (pr-keep-region-active)))
 
+(declare-function widget-field-action "wid-edit" (widget &optional _event))
+(declare-function widget-value-set "wid-edit" (widget value))
 
 (defun pr-insert-section-1 ()
   ;; 1. Print:
@@ -6104,7 +6130,7 @@ COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
        (pr-insert-checkbox
        "\n               "
        'pr-i-region
-       #'(lambda (widget &rest ignore)
+       #'(lambda (widget &rest _ignore)
            (let ((region-p (pr-interface-save
                             (ps-mark-active-p))))
              (cond ((null (widget-value widget)) ; widget is nil
@@ -6125,7 +6151,7 @@ COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
        (pr-insert-checkbox
        "    "
        'pr-i-mode
-       #'(lambda (widget &rest ignore)
+       #'(lambda (widget &rest _ignore)
            (let ((mode-p (pr-interface-save
                           (pr-mode-alist-p))))
              (cond
@@ -6161,7 +6187,7 @@ COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
   (widget-create 'regexp
                 :size 58
                 :format "\n      File Regexp : %v\n"
-                :notify (lambda (widget &rest ignore)
+                :notify (lambda (widget &rest _ignore)
                           (setq pr-i-regexp (widget-value widget)))
                 pr-i-regexp)
   ;;    1b. Directory: List Directory Entry
@@ -6201,7 +6227,7 @@ COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
        (pr-insert-checkbox
        "    "
        'pr-i-despool
-       #'(lambda (widget &rest ignore)
+       #'(lambda (widget &rest _ignore)
            (if pr-spool-p
                (setq pr-i-despool (not pr-i-despool))
              (ding)
@@ -6238,7 +6264,7 @@ COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
    'integer
    :size 3
    :format "\n  N-Up : %v"
-   :notify (lambda (widget &rest ignore)
+   :notify (lambda (widget &rest _ignore)
             (let ((value (if (string= (widget-apply widget :value-get) "")
                              0
                            (widget-value widget))))
@@ -6267,7 +6293,7 @@ COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
   ;; 4. Settings:
   ;; 4. Settings: Landscape             Auto Region    Verbose
   (pr-insert-checkbox "\n\n  " 'ps-landscape-mode
-                     #'(lambda (&rest ignore)
+                     #'(lambda (&rest _ignore)
                          (setq ps-landscape-mode (not ps-landscape-mode)
                                pr-file-landscape ps-landscape-mode))
                      " Landscape             ")
@@ -6289,7 +6315,7 @@ COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
   (pr-insert-toggle 'ps-zebra-stripes " Zebra Stripes")
   (pr-insert-checkbox "         "
                      'pr-spool-p
-                     #'(lambda (&rest ignore)
+                     #'(lambda (&rest _ignore)
                          (setq pr-spool-p (not pr-spool-p))
                          (unless pr-spool-p
                            (setq pr-i-despool nil)
@@ -6299,7 +6325,7 @@ COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
   ;; 4. Settings: Duplex                Print with faces
   (pr-insert-checkbox "\n  "
                      'ps-spool-duplex
-                     #'(lambda (&rest ignore)
+                     #'(lambda (&rest _ignore)
                          (setq ps-spool-duplex (not ps-spool-duplex)
                                pr-file-duplex  ps-spool-duplex))
                      " Duplex                ")
@@ -6308,7 +6334,7 @@ COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
   ;; 4. Settings: Tumble                Print via Ghostscript
   (pr-insert-checkbox "\n  "
                      'ps-spool-tumble
-                     #'(lambda (&rest ignore)
+                     #'(lambda (&rest _ignore)
                          (setq ps-spool-tumble (not ps-spool-tumble)
                                pr-file-tumble  ps-spool-tumble))
                      " Tumble                ")
@@ -6331,7 +6357,7 @@ COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
   ;; 5. Customize:
   (pr-insert-italic "\n\nCustomize     :   " 2 11)
   (pr-insert-button 'pr-customize "printing" "   ")
-  (pr-insert-button #'(lambda (&rest ignore) (ps-print-customize))
+  (pr-insert-button #'(lambda (&rest _ignore) (ps-print-customize))
                    "ps-print" "   ")
   (pr-insert-button 'lpr-customize "lpr"))
 
@@ -6353,7 +6379,7 @@ COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
   (pr-insert-button 'pr-kill-help "Kill All Printing Help Buffer"))
 
 
-(defun pr-kill-help (&rest ignore)
+(defun pr-kill-help (&rest _ignore)
   "Kill all printing help buffer."
   (interactive)
   (let ((help '("*Printing Interface Help*" "*Printing Help*"
@@ -6367,20 +6393,20 @@ COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
   (recenter (- (window-height) 2)))
 
 
-(defun pr-interface-quit (&rest ignore)
+(defun pr-interface-quit (&rest _ignore)
   "Kill the printing buffer interface and quit."
   (interactive)
   (kill-buffer pr-buffer-name)
   (set-window-configuration pr-i-window-configuration))
 
 
-(defun pr-interface-help (&rest ignore)
+(defun pr-interface-help (&rest _ignore)
   "printing buffer interface help."
   (interactive)
   (pr-show-setup pr-interface-help-message "*Printing Interface Help*"))
 
 
-(defun pr-interface-txt-print (&rest ignore)
+(defun pr-interface-txt-print (&rest _ignore)
   "Print using lpr package."
   (interactive)
   (condition-case data
@@ -6412,7 +6438,7 @@ COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
      (message "%s" (error-message-string data)))))
 
 
-(defun pr-interface-printify (&rest ignore)
+(defun pr-interface-printify (&rest _ignore)
   "Printify a buffer."
   (interactive)
   (condition-case data
@@ -6437,7 +6463,7 @@ COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
      (message "%s" (error-message-string data)))))
 
 
-(defun pr-interface-ps-print (&rest ignore)
+(defun pr-interface-ps-print (&rest _ignore)
   "Print using ps-print package."
   (interactive)
   (pr-interface-ps 'pr-despool-ps-print 'pr-ps-directory-ps-print
@@ -6446,7 +6472,7 @@ COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
                   'pr-ps-buffer-ps-print))
 
 
-(defun pr-interface-preview (&rest ignore)
+(defun pr-interface-preview (&rest _ignore)
   "Preview a PostScript file."
   (interactive)
   (pr-interface-ps 'pr-despool-preview 'pr-ps-directory-preview
@@ -6522,21 +6548,19 @@ COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
 
 
 (defun pr-i-directory ()
-  (or (and (file-directory-p pr-i-directory)
-          (file-readable-p pr-i-directory))
+  (or (file-accessible-directory-p pr-i-directory)
       (error "Please specify be a readable directory")))
 
 
-(defun pr-interface-directory (widget &rest ignore)
+(defun pr-interface-directory (widget &rest _ignore)
   (and pr-buffer-verbose
        (message "You can use M-TAB or ESC TAB for file completion"))
   (let ((dir (widget-value widget)))
-    (and (file-directory-p dir)
-        (file-readable-p dir)
+    (and (file-accessible-directory-p dir)
         (setq pr-i-directory dir))))
 
 
-(defun pr-interface-infile (widget &rest ignore)
+(defun pr-interface-infile (widget &rest _ignore)
   (and pr-buffer-verbose
        (message "You can use M-TAB or ESC TAB for file completion"))
   (let ((file (widget-value widget)))
@@ -6545,7 +6569,7 @@ COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
         (setq pr-i-ps-file file))))
 
 
-(defun pr-interface-outfile (widget &rest ignore)
+(defun pr-interface-outfile (widget &rest _ignore)
   (setq pr-i-answer-yes nil)
   (and pr-buffer-verbose
        (message "You can use M-TAB or ESC TAB for file completion"))
@@ -6581,7 +6605,7 @@ COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
 
 (defun pr-insert-toggle (var-sym label)
   (widget-create 'checkbox
-                :notify `(lambda (&rest ignore)
+                :notify `(lambda (&rest _ignore)
                            (setq ,var-sym (not ,var-sym)))
                 (symbol-value var-sym))
   (widget-insert label))
@@ -6602,7 +6626,7 @@ COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
                        :format "%v"
                        :inline t
                        :value ,var-sym
-                       :notify (lambda (widget &rest ignore)
+                       :notify (lambda (widget &rest _ignore)
                                  (setq ,var-sym (widget-value widget))
                                  ,@body)
                        :void '(choice-item :format "%[%t%]"
@@ -6618,7 +6642,7 @@ COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
                     'radio-button
                     :format "  %[%v%]"
                     :value (eq ,var-sym (quote ,sym))
-                    :notify (lambda (&rest ignore)
+                    :notify (lambda (&rest _ignore)
                               (setq ,var-sym (quote ,sym))
                               (pr-update-radio-button (quote ,var-sym)))))))
     (put var-sym 'pr-widget-list (cons (cons wid sym) wid-list))))