0

I'm trying to get to grips with printing from emacs.

I've added the following to my .emacs file:

(add-to-list 'lpr-switches "-P HP_ENVY_Photo_6200_series_685E88_")
(add-to-list 'lpr-switches "-o sides=two-sided-long-edge")
(add-to-list 'lpr-switches "-o number-up=2")

When I try to print (so far I've only tried with M-x print-region), the following is written to * Messages * (after a prompt about printing to the default destination):

Spooling with options -P HP_ENVY_Photo_6200_series_685E88_... user-error: Spooling with options -P HP_ENVY_Photo_6200_series_685E88_...done: /usr/bin/lpr: No such file or directory

If I cut the displayed command and paste it to the command line, prefixed by lpr and suffixed by a space and the name of an existing file, that file is printed without problem, which makes me think that I haven't mistyped the over-long printer name. What's going wrong?

I'm running Linux Mint Ulyana 20 and GNU Emacs 26.3 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.14) of 2020-03-26, modified by Debian

UPDATE

From * Help * in response to C-h v exec-path

exec-path is a variable defined in ‘C source code’. Its value is ("/opt/Qt/Tools/QtCreator/bin" "/opt/chromedriver" "/opt/fossil" "/opt/ActiveTcl-8.6/bin" "/usr/local/sbin" "/usr/local/bin" "/usr/sbin" "/usr/bin" "/sbin" "/bin" "/usr/games" "/usr/local/games" "/snap/bin" "/usr/lib/emacs/26.3/x86_64-linux-gnu")

From the command line:

$ which lpr

/usr/bin/lpr

4
  • First, make sure that you can print from the command line. When you can do that reilably, the emacs part is trivial. From what you show above, right now you are missing packages: you need to resolve that first.
    – NickD
    Oct 12 '20 at 14:13
  • 1
    I can print from the command line with the command lpr -P HP_ENVY_Photo_6200_series_685E88_ <filename> Which packages am I missing?
    – nurdglaw
    Oct 12 '20 at 14:22
  • I was wrong about the packages: that looks OK, It's just that your emacs cannot find /usr/bin/lpr for some reason. Check exec-path and post its value in your question.
    – NickD
    Oct 12 '20 at 14:46
  • Part of the problem is that you're using add-to-list, which according to the docstring, will "Add ELEMENT to the value of LIST-VAR if it isn’t there yet." At most your first call to add-to-list will work, unless lpr-switches is already non-nil, at which points none of your calls will work.
    – Dan
    Oct 12 '20 at 16:31
1

lpr-switches is a list of arguments. So think of them as each element of the list being implicitly quoted. E.g.:

(setq lpr-switches
      (append '("-P" "HP_ENVY_Photo_6200_series_685E88_"
                "-o" "sides=two-sided-long-edge"
                "-o" "number-up=2")
              lpr-switches))
2
  • Thanks. That's fixed it. Clearly I need to learn a bit more about writing Emacs lisp. Can you recommend a good book?
    – nurdglaw
    Oct 12 '20 at 16:03
  • A parital answer, but you can also use (setq printer-name "HP_ENVY_Photo_6200_series_685E88_") Jul 21 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.