-;;; lpr.el --- print Emacs buffer on line printer
+;;; lpr.el --- print Emacs buffer on line printer -*- lexical-binding: t -*-
;; Copyright (C) 1985, 1988, 1992, 1994, 2001-2021 Free Software
;; Foundation, Inc.
(memq system-type '(usg-unix-v hpux))
"Non-nil if running on a system type that uses the \"lp\" command.")
-
(defgroup lpr nil
"Print Emacs buffer on line printer."
:group 'text)
-
;;;###autoload
(defcustom printer-name
(and (eq system-type 'ms-dos) "PRN")
:tag "Printer Name"
(const :tag "Default" nil)
;; could use string but then we lose completion for files.
- (file :tag "Name"))
- :group 'lpr)
+ (file :tag "Name")))
;;;###autoload
(defcustom lpr-switches nil
It is recommended to set `printer-name' instead of including an explicit
switch on this list.
See `lpr-command'."
- :type '(repeat (string :tag "Argument"))
- :group 'lpr)
+ :type '(repeat (string :tag "Argument")))
(defcustom lpr-add-switches (memq system-type '(berkeley-unix gnu/linux))
"Non-nil means construct `-T' and `-J' options for the printer program.
These are made assuming that the program is `lpr';
if you are using some other incompatible printer program,
this variable should be nil."
- :type 'boolean
- :group 'lpr)
+ :type 'boolean)
(defcustom lpr-printer-switch
(if lpr-lp-system
:type '(choice :menu-tag "Printer Name Switch"
:tag "Printer Name Switch"
(const :tag "None" nil)
- (string :tag "Printer Switch"))
- :group 'lpr)
+ (string :tag "Printer Switch")))
;;;###autoload
(defcustom lpr-command
`printer-name' as the destination for output; any other program is
treated like `lpr' except that an explicit filename is given as the last
argument."
- :type 'string
- :group 'lpr)
+ :type 'string)
;; Default is nil, because that enables us to use pr -f
;; which is more reliable than pr with no args, which is what lpr -p does.
and print the result."
:type '(choice (const nil)
(string :tag "Single argument")
- (repeat :tag "Multiple arguments" (string :tag "Argument")))
- :group 'lpr)
+ (repeat :tag "Multiple arguments" (string :tag "Argument"))))
(defcustom print-region-function
(if (memq system-type '(ms-dos windows-nt))
- #'w32-direct-print-region-function
+ (progn
+ (declare-function w32-direct-print-region-function "w32-fns")
+ #'w32-direct-print-region-function)
#'call-process-region)
"Function to call to print the region on a printer.
See definition of `print-region-1' for calling conventions."
- :type 'function
- :group 'lpr)
+ :type 'function)
(defcustom lpr-page-header-program "pr"
"Name of program for adding page headers to a file."
- :type 'string
- :group 'lpr)
+ :type 'string)
;; Berkeley systems support -F, and GNU pr supports both -f and -F,
;; So it looks like -F is a better default.
If `%s' appears in any of the strings, it is substituted by the page title.
Note that for correct quoting, `%s' should normally be a separate element.
The variable `lpr-page-header-program' specifies the program to use."
- :type '(repeat string)
- :group 'lpr)
+ :type '(repeat string))
;;;###autoload
(defun lpr-buffer ()
nil
;; Run a separate program to get page headers.
(let ((new-coords (print-region-new-buffer start end)))
- (apply 'call-process-region (car new-coords) (cdr new-coords)
+ (apply #'call-process-region (car new-coords) (cdr new-coords)
lpr-page-header-program t t nil
(mapcar (lambda (e) (format e name))
lpr-page-header-switches)))
(let ((retval
(let ((tempbuf (current-buffer)))
(with-current-buffer buf
- (apply (or print-region-function 'call-process-region)
+ (apply (or print-region-function #'call-process-region)
start end lpr-command
nil tempbuf nil
(nconc (and name lpr-add-switches
--- /dev/null
+;;; lpr-tests.el --- Tests for lpr.el -*- lexical-binding: t -*-
+
+;; Copyright (C) 2021 Free Software Foundation, Inc.
+
+;; This file is part of GNU Emacs.
+
+;; 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.
+
+;; 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;; Code:
+
+(require 'ert)
+(require 'lpr)
+
+(ert-deftest lpr-test-printify-region ()
+ (with-temp-buffer
+ (insert "foo\^@-\^h\^k\^n-\^_\177bar")
+ (printify-region (point-min) (point-max))
+ (should (equal (buffer-string) "foo\\^@-\\^H\\^K\\^N-\\^_\\7fbar"))))
+
+(ert-deftest lpr-test-lpr-eval-switch ()
+ (should (equal (lpr-eval-switch "foo") "foo"))
+ (should (equal (lpr-eval-switch (lambda () "foo")) "foo"))
+ (let ((v "foo"))
+ (should (equal (lpr-eval-switch v) "foo")))
+ (should (equal (lpr-eval-switch (list #'identity "foo")) "foo"))
+ (should (equal (lpr-eval-switch 1) nil)))
+
+;;; lpr-tests.el ends here