mirrored from git://git.sv.gnu.org/emacs.git
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathprinting.el
6193 lines (5184 loc) · 209 KB
/
printing.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; printing.el --- printing utilities -*- lexical-binding:t -*-
;; Copyright (C) 2000-2025 Free Software Foundation, Inc.
;; Author: Vinicius Jose Latorre <viniciusjl.gnu@gmail.com>
;; Keywords: text, print, PostScript
;; Old-Version: 6.9.3
;; URL: https://www.emacswiki.org/cgi-bin/wiki/ViniciusJoseLatorre
;; 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:
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Introduction
;; ------------
;;
;; With `printing' you can preview or print a PostScript file. You can also
;; print a text file using PostScript, and preview or print buffers that use
;; certain special modes like mh-folder-mode, rmail-summary-mode,
;; gnus-summary-mode, etc. This package also includes a PostScript/text
;; printer database.
;;
;; There are two user interfaces:
;;
;; * Menu interface:
;; The `printing' menu replaces the usual print options in the menu bar.
;; This is the default user interface.
;;
;; * Buffer interface:
;; You can use a buffer interface instead of menus. It looks like a
;; customization buffer. Basically, it has the same options found in the
;; menu and some extra options, all this on a buffer.
;;
;; `printing' is prepared to run on GNU, Unix and NT systems.
;; On GNU or Unix system, `printing' depends on gs and gv utilities.
;; On NT system, `printing' depends on gstools (gswin32.exe and gsview32.exe).
;; To obtain ghostscript, ghostview and GSview see the URL
;; `https://www.gnu.org/software/ghostscript/ghostscript.html'.
;;
;; `printing' depends on ps-print package to generate PostScript files, to
;; spool and to despool PostScript buffer. So, `printing' provides an
;; interface to ps-print package and it also provides some extra stuff.
;;
;; `printing' was inspired by:
;;
;; print-nt.el Frederic Corne <frederic.corne@erli.fr>
;; Special printing functions for Windows NT
;;
;; mh-e-init.el Tom Vogels <tov@ece.cmu.edu>
;; PS-print for mail messages
;;
;; win32-ps-print.el Matthew O. Persico <mpersico@erols.com>
;; PostScript printing with ghostscript
;;
;; ps-print-interface.el Volker Franz <volker.franz@tuebingen.mpg.de>
;; Graphical front end for ps-print and previewing
;;
;;
;; Log Messages
;; ------------
;;
;; The buffer *Printing Command Output* is where the `printing' log messages
;; are inserted. All program called by `printing' has a log entry in the
;; buffer *Printing Command Output*. A log entry has the following form:
;;
;; PROGRAM (ARG...)
;; MESSAGE
;; Exit status: CODE
;;
;; Where
;; PROGRAM is the program activated by `printing',
;; ARG is an argument passed to PROGRAM (it can have more than one argument),
;; MESSAGE is an error message returned by PROGRAM (it can have no message, if
;; PROGRAM is successful),
;; and CODE is a numeric exit status or a signal description string.
;;
;; For example, after previewing a PostScript file, *Printing Command Output*
;; will have the following entry:
;;
;; /usr/bin/gv ("/home/user/example/file.ps")
;; Exit status: 0
;;
;; In the example above, the previewing was successful. If during previewing,
;; you quit gv execution (by typing C-g during Emacs session), the log entry
;; would be:
;;
;; /usr/bin/gv ("/home/user/example/file.ps")
;; Exit status: Quit
;;
;; So, if something goes wrong, a good place to take a look is the buffer
;; *Printing Command Output*. Don't forget to see also the buffer *Messages*,
;; it can help.
;;
;;
;; Novices (First Users)
;; ---------------------
;;
;; First of all, see printing documentation only to get an idea of what
;; `printing' is capable.
;;
;; Then try to set the variables: `pr-ps-name', `pr-ps-printer-alist',
;; `pr-txt-name', `pr-txt-printer-alist' and `pr-path-alist'. These variables
;; are the main variables for printing processing.
;;
;; Now, please, see these variables documentation deeper. You can do this by
;; typing C-h v pr-ps-name RET (for example) if you already loaded printing
;; package, or by browsing printing.el source file.
;;
;; If the documentation isn't clear or if you find a way to improve the
;; documentation, please, send an email to maintainer. All printing users
;; will thank you.
;;
;; 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 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:
;;
;; (require 'printing) ; load printing package
;; (setq pr-path-alist
;; '((windows "c:/applications/executables" PATH ghostview mpage)
;; (ghostview "c:/gs/gsview-dir")
;; (mpage "c:/mpage-dir")
;; ))
;; (setq pr-txt-name 'prt_06a)
;; (setq pr-txt-printer-alist
;; '((prt_06a "print" nil "/D:\\\\printers\\prt_06a")
;; (prt_07c nil nil "/D:\\\\printers\\prt_07c")
;; (PRN "" nil "PRN")
;; (standard "redpr.exe" nil "")
;; ))
;; (setq pr-ps-name 'lps_06b)
;; (setq pr-ps-printer-alist
;; '((lps_06a "print" nil "/D:" "\\\\printers\\lps_06a")
;; (lps_06b "print" nil nil "\\\\printers\\lps_06b")
;; (lps_07c "print" nil "" "/D:\\\\printers\\lps_07c")
;; (lps_08c nil nil nil "\\\\printers\\lps_08c")
;; (LPT1 "" nil "" "LPT1:")
;; (PRN "" nil "" "PRN")
;; (standard "redpr.exe" nil "" "")
;; ))
;; (pr-update-menus t) ; update now printer and utility menus
;;
;; * Example of setting for GNU or Unix system:
;;
;; (require 'printing) ; load printing package
;; (setq pr-path-alist
;; '((unix "." "~/bin" ghostview mpage PATH)
;; (ghostview "$HOME/bin/gsview-dir")
;; (mpage "$HOME/bin/mpage-dir")
;; ))
;; (setq pr-txt-name 'prt_06a)
;; (setq pr-txt-printer-alist
;; '((prt_06a "lpr" nil "prt_06a")
;; (prt_07c nil nil "prt_07c")
;; ))
;; (setq pr-ps-name 'lps_06b)
;; (setq pr-ps-printer-alist
;; '((lps_06b "lpr" nil "-P" "lps_06b")
;; (lps_07c "lpr" nil nil "lps_07c")
;; (lps_08c nil nil nil "lps_08c")
;; ))
;; (pr-update-menus t) ; update now printer and utility menus
;;
;;
;; NOTE 1: Don't forget to download and install ghostscript utilities (see
;; Utilities section).
;;
;; NOTE 2: The `printer-name' and `ps-printer-name' variables don't need to be
;; set, as they are implicit set by `pr-ps-printer-alist' and
;; `pr-txt-printer-alist'.
;;
;; NOTE 3: The duplex feature will only work on PostScript printers that
;; support this feature.
;; You can check if your PostScript printer supports duplex feature
;; by checking the printer manual. Or you can try these steps:
;; 1. Open a buffer (or use the *scratch* buffer).
;; 2. Type:
;; First line (on first page)
;; ^L
;; Second line (on second page)
;; 3. Print this buffer with duplex turned on.
;; If it's printed 2 (two) sheets of paper, then your PostScript
;; printer doesn't have duplex feature; otherwise, it's ok, your
;; printer does have duplex feature.
;;
;; NOTE 4: See Tips section.
;;
;;
;; Tips
;; ----
;;
;; 1. If you have a local printer, that is, a printer which is connected
;; directly to your computer, don't forget to connect the printer to your
;; computer before printing.
;;
;; 2. If you try to print a file and it seems that the file was printed, but
;; there is no paper in the printer, then try to set `pr-delete-temp-file'
;; to nil. Probably `printing' is deleting the temporary file before your
;; local system can get it to send to the printer.
;;
;; 3. Don't try to print a dynamic buffer, that is, a buffer which is
;; modifying while `printing' tries to print. Eventually you got an error
;; message. Instead, save the dynamic buffer to a file or copy it in
;; another buffer and, then, print the file or the new static buffer.
;; An example of dynamic buffer is the *Messages* buffer.
;;
;; 4. When running Emacs on Windows (with or without cygwin), check if your
;; printer is a text printer or not by typing in a DOS window:
;;
;; print /D:\\host\printer somefile.txt
;;
;; Where, `host' is the machine where the printer is directly connected,
;; `printer' is the printer name and `somefile.txt' is a text file.
;;
;; If the printer `\\host\printer' doesn't print the content of
;; `somefile.txt' or, instead, it returns the following message:
;;
;; PostScript Error Handler
;; Offending Command = CCC
;; Stack =
;;
;; Where `CCC' is whatever is at the beginning of the text to be printed.
;;
;; Therefore, the printer `\\host\printer' is not a text printer, but a
;; PostScript printer. So, please, don't include this printer in
;; `pr-txt-printer-alist' (which see).
;;
;; 5. You can use gsprint instead of ghostscript to print monochrome PostScript
;; files in Windows. The gsprint utility documentation says that it is more
;; efficient than ghostscript to print monochrome PostScript.
;;
;; To print non-monochrome PostScript file, the efficiency of ghostscript
;; is similar to gsprint.
;;
;; Also the gsprint utility comes together with gsview distribution.
;;
;; For more information about gsprint see
;; `https://www.cs.wisc.edu/~ghost/gsview/gsprint.htm'.
;;
;; As an example of gsprint declaration:
;;
;; (setq pr-ps-printer-alist
;; '((A "gsprint" ("-all" "-twoup") "-printer " "my-b/w-printer-name")
;; (B "gsprint" ("-all" "-twoup") nil "-printer my-b/w-printer-name")
;; ;; some other printer declaration
;; ))
;;
;; The example above declares that printer A prints all pages (-all) and two
;; pages per sheet (-twoup). The printer B declaration does the same as the
;; printer A declaration, the only difference is the printer name selection.
;;
;; There are other command line options like:
;;
;; -mono Render in monochrome as 1bit/pixel (only black and white).
;; -grey Render in greyscale as 8bits/pixel.
;; -color Render in color as 24bits/pixel.
;;
;; The default is `-mono'. So, printer A and B in the example above are
;; using implicitly the `-mono' option. Note that in `-mono' no gray tone
;; or color is printed, this includes the zebra stripes, that is, in `-mono'
;; the zebra stripes are not printed.
;;
;; See also documentation for `pr-ps-printer-alist'.
;;
;;
;; Using `printing'
;; ----------------
;;
;; To use `printing' insert in your init file:
;;
;; (require 'printing)
;; ;; ...some user settings...
;; (pr-update-menus t)
;;
;; During `pr-update-menus' evaluation:
;; * On Emacs 20:
;; it replaces the Tools/Print menu by Tools/Printing menu.
;; * On Emacs 21:
;; it replaces the File/Print* menu entries by File/Print menu.
;; Please, see section Menu Layout below for menu explanation.
;;
;; To use `printing' utilities you can use the Printing menu options, type M-x
;; followed by one of the commands below, or type a key associated with the
;; command you want (if there is a key binding).
;;
;; `printing' has the following commands:
;;
;; pr-interface
;; pr-ps-directory-preview
;; pr-ps-directory-using-ghostscript
;; pr-ps-directory-print
;; pr-ps-directory-ps-print
;; pr-ps-buffer-preview
;; pr-ps-buffer-using-ghostscript
;; pr-ps-buffer-print
;; pr-ps-buffer-ps-print
;; pr-ps-region-preview
;; pr-ps-region-using-ghostscript
;; pr-ps-region-print
;; pr-ps-region-ps-print
;; pr-ps-mode-preview
;; pr-ps-mode-using-ghostscript
;; pr-ps-mode-print
;; pr-ps-mode-ps-print
;; pr-ps-file-preview
;; pr-ps-file-up-preview
;; pr-ps-file-using-ghostscript
;; pr-ps-file-print
;; pr-ps-file-ps-print
;; pr-ps-file-up-ps-print
;; pr-ps-fast-fire
;; pr-despool-preview
;; pr-despool-using-ghostscript
;; pr-despool-print
;; pr-despool-ps-print
;; pr-printify-directory
;; pr-printify-buffer
;; pr-printify-region
;; pr-txt-directory
;; pr-txt-buffer
;; pr-txt-region
;; pr-txt-mode
;; pr-txt-fast-fire
;; pr-toggle-file-duplex
;; pr-toggle-file-tumble
;; pr-toggle-file-landscape
;; pr-toggle-ghostscript
;; pr-toggle-faces
;; pr-toggle-spool
;; pr-toggle-duplex
;; pr-toggle-tumble
;; pr-toggle-landscape
;; pr-toggle-upside-down
;; pr-toggle-line
;; pr-toggle-zebra
;; pr-toggle-header
;; pr-toggle-lock
;; pr-toggle-region
;; pr-toggle-mode
;; pr-customize
;; lpr-customize
;; pr-help
;; pr-ps-name
;; pr-txt-name
;; pr-ps-utility
;; pr-show-ps-setup
;; pr-show-pr-setup
;; pr-show-lpr-setup
;;
;; The general meanings of above commands are:
;;
;; PREFIX:
;; `pr-interface' buffer interface for printing package.
;; `pr-help' help for printing package.
;; `pr-ps-name' interactively select a PostScript printer.
;; `pr-txt-name' interactively select a text printer.
;; `pr-ps-utility' interactively select a PostScript utility.
;; `pr-show-*-setup' show current settings.
;; `pr-ps-*' deal with PostScript code generation.
;; `pr-txt-*' deal with text generation.
;; `pr-toggle-*' toggle on/off some boolean variable.
;; `pr-despool-*' despool the PostScript spooling buffer.
;; `pr-printify-*' replace nonprintable ASCII by printable ASCII
;; representation.
;;
;; SUFFIX:
;; `*-customize' customization.
;; `*-preview' preview a PostScript file.
;; `*-using-ghostscript' use ghostscript to print.
;; `*-fast-fire' fast fire command (see it for documentation).
;; `*-print' send PostScript directly to printer.
;; `*-ps-print' send PostScript directly to printer or use
;; ghostscript to print. It depends on
;; `pr-print-using-ghostscript' option.
;;
;; INFIX/SUFFIX:
;; `*-directory*' process a directory.
;; `*-buffer*' process a buffer.
;; `*-region*' process a region.
;; `*-mode*' process a major mode (see explanation below).
;; `*-file-*' process a PostScript file.
;; `*-file-up-*' process a PostScript file using a filter utility.
;;
;; Here are some examples:
;;
;; `pr-ps-buffer-using-ghostscript'
;; Use ghostscript to print a buffer.
;;
;; `pr-ps-file-print'
;; Print a PostScript file.
;;
;; `pr-toggle-spool'
;; Toggle spooling buffer.
;;
;; So you can preview through ghostview, use ghostscript to print (if you don't
;; have a PostScript printer) or send directly to printer a PostScript code
;; generated by `ps-print' package.
;;
;; Besides operating one buffer or region each time, you also can postpone
;; previewing or printing by saving the PostScript code generated in a
;; temporary Emacs buffer. This way you can save banner pages between
;; successive printing. You can toggle on/off spooling by invoking
;; `pr-toggle-spool' interactively or through menu bar.
;;
;; If you type, for example:
;;
;; C-u M-x pr-ps-buffer-print RET
;;
;; The `pr-ps-buffer-print' command prompts you for a n-up printing number and
;; a file name, and save the PostScript code generated to the file name instead
;; of sending to printer.
;;
;; This behavior is similar with the commands that deal with PostScript code
;; generation, that is, with `pr-ps-*' and `pr-despool-*' commands. If
;; spooling is on, only `pr-despool-*' commands prompt for a file name and save
;; the PostScript code spooled in this file.
;;
;; Besides the behavior described above, the `*-directory*' commands also
;; prompt for a directory and a file name regexp. So, it's possible to process
;; all or certain files on a directory at once (see also documentation for
;; `pr-list-directory').
;;
;; `printing' has also a special way to handle some major mode through
;; `*-mode*' commands. So it's possible to customize a major mode printing,
;; it's only needed to declare the customization in `pr-mode-alist' (see
;; section Options) and invoke some of `*-mode*' commands. An example for
;; major mode usage is when you're using gnus (or mh, or rmail, etc.) and
;; you're in the *Summary* buffer, if you forget to switch to the *Article*
;; buffer before printing, you'll get a nicely formatted list of article
;; subjects shows up at the printer. With major mode printing you don't need
;; to switch from gnus *Summary* buffer first.
;;
;; Current global keyboard mapping is:
;;
;; (keymap-global-set "<print>" 'pr-ps-fast-fire)
;; (keymap-global-set "M-<print>" 'pr-ps-mode-using-ghostscript)
;; (keymap-global-set "S-<print>" 'pr-ps-mode-using-ghostscript)
;; (keymap-global-set "C-<print>" 'pr-txt-fast-fire)
;; (keymap-global-set "C-M-<print>" 'pr-txt-fast-fire)
;;
;; As a suggestion of global keyboard mapping for some `printing' commands:
;;
;; (keymap-global-set "C-c i" 'pr-interface)
;; (keymap-global-set "C-c b p" 'pr-ps-buffer-print)
;; (keymap-global-set "C-c b x" 'pr-ps-buffer-preview)
;; (keymap-global-set "C-c b b" 'pr-ps-buffer-using-ghostscript)
;; (keymap-global-set "C-c r p" 'pr-ps-region-print)
;; (keymap-global-set "C-c r x" 'pr-ps-region-preview)
;; (keymap-global-set "C-c r r" 'pr-ps-region-using-ghostscript)
;;
;;
;; Options
;; -------
;;
;; Below it's shown a brief description of `printing' options, please, see the
;; options declaration in the code for a long documentation.
;;
;; `pr-filename-style' Specify which filename style to use for external
;; commands.
;;
;; `pr-path-alist' Specify an alist for command paths.
;;
;; `pr-txt-name' Specify a printer for printing a text file.
;;
;; `pr-txt-printer-alist' Specify an alist of all text printers.
;;
;; `pr-ps-name' Specify a printer for printing a PostScript
;; file.
;;
;; `pr-ps-printer-alist' Specify an alist for all PostScript printers.
;;
;; `pr-temp-dir' Specify a directory for temporary files during
;; printing.
;;
;; `pr-ps-temp-file' Specify PostScript temporary file name prefix.
;;
;; `pr-file-modes' Specify the file permission bits for newly
;; created files.
;;
;; `pr-gv-command' Specify path and name of the gsview/gv
;; utility.
;;
;; `pr-gs-command' Specify path and name of the ghostscript
;; utility.
;;
;; `pr-gs-switches' Specify ghostscript switches.
;;
;; `pr-gs-device' Specify ghostscript device switch value.
;;
;; `pr-gs-resolution' Specify ghostscript resolution switch value.
;;
;; `pr-print-using-ghostscript' Non-nil means print using ghostscript.
;;
;; `pr-faces-p' Non-nil means print with face attributes.
;;
;; `pr-spool-p' Non-nil means spool printing in a buffer.
;;
;; `pr-file-landscape' Non-nil means print PostScript file in
;; landscape orientation.
;;
;; `pr-file-duplex' Non-nil means print PostScript file in duplex
;; mode.
;;
;; `pr-file-tumble' Non-nil means print PostScript file in tumble
;; mode.
;;
;; `pr-auto-region' Non-nil means region is automagically detected.
;;
;; `pr-auto-mode' Non-nil means major-mode specific printing is
;; preferred over normal printing.
;;
;; `pr-mode-alist' Specify an alist for a major-mode and printing
;; function.
;;
;; `pr-ps-utility' Specify PostScript utility processing.
;;
;; `pr-ps-utility-alist' Specify an alist for PostScript utility
;; processing.
;;
;; `pr-menu-lock' Non-nil means menu is locked while selecting
;; toggle options.
;;
;; `pr-menu-char-height' Specify menu char height in pixels.
;;
;; `pr-menu-char-width' Specify menu char width in pixels.
;;
;; `pr-setting-database' Specify an alist for settings in general.
;;
;; `pr-visible-entry-list' Specify a list of Printing menu visible
;; entries.
;;
;; `pr-delete-temp-file' Non-nil means delete temporary files.
;;
;; `pr-list-directory' Non-nil means list directory when processing a
;; directory.
;;
;; `pr-buffer-name' Specify the name of the buffer interface for
;; printing package.
;;
;; `pr-buffer-name-ignore' Specify a regexp list for buffer names to be
;; ignored in interface buffer.
;;
;; `pr-buffer-verbose' Non-nil means to be verbose when editing a
;; field in interface buffer.
;;
;; To set the above options you may:
;;
;; a) insert the code in your ~/.emacs, like:
;;
;; (setq pr-faces-p t)
;;
;; This way always keep your default settings when you enter a new Emacs
;; session.
;;
;; b) or use `set-variable' in your Emacs session, like:
;;
;; M-x set-variable RET pr-faces-p RET t RET
;;
;; This way keep your settings only during the current Emacs session.
;;
;; c) or use customization, for example:
;; click on menu-bar *Help* option,
;; then click on *Customize*,
;; then click on *Browse Customization Groups*,
;; expand *PostScript* group,
;; expand *Printing* group
;; and then customize `printing' options.
;; Through this way, you may choose if the settings are kept or not when
;; you leave out the current Emacs session.
;;
;; d) or see the option value:
;;
;; C-h v pr-faces-p RET
;;
;; and click the *customize* hypertext button.
;; Through this way, you may choose if the settings are kept or not when
;; you leave out the current Emacs session.
;;
;; e) or invoke:
;;
;; M-x pr-customize RET
;;
;; and then customize `printing' options.
;; Through this way, you may choose if the settings are kept or not when
;; you leave out the current Emacs session.
;;
;; f) or use menu bar, for example:
;; click on menu-bar *File* option,
;; then click on *Printing*,
;; then click on *Customize*,
;; then click on *printing*
;; and then customize `printing' options.
;; Through this way, you may choose if the settings are kept or not when
;; you leave out the current Emacs session.
;;
;;
;; Menu Layout
;; -----------
;;
;; The `printing' menu (Tools/Printing or File/Print) has the following layout:
;;
;; +-----------------------------+
;; A 0 | Printing Interface |
;; +-----------------------------+ +-A---------+ +-B------+
;; I 1 | PostScript Preview >|-------|Directory >|-----|1-up |
;; 2 | PostScript Print >|---- A |Buffer >|-- B |2-up |
;; 3 | PostScript Printer: name >|---- C |Region >|-- B |4-up |
;; +-----------------------------+ |Mode >|-- B |Other...|
;; II 4 | Printify >|-----\ |File >|--\ +--------+
;; 5 | Print >|---\ | |Despool... | |
;; 6 | Text Printer: name >|-\ | | +-----------+ |
;; +-----------------------------+ | | | +---------+ +------------+
;; III 7 |[ ]Landscape | | | \-|Directory| | No Prep... | Ia
;; 8 |[ ]Print Header | | | |Buffer | +------------+ Ib
;; 9 |[ ]Print Header Frame | | | |Region | | name >|- C
;; 10 |[ ]Line Number | | | +---------+ +------------+
;; 11 |[ ]Zebra Stripes | | | +---------+ | 1-up... | Ic
;; 12 |[ ]Duplex | | \---|Directory| | 2-up... |
;; 13 |[ ]Tumble | \--\ |Buffer | | 4-up... |
;; 14 |[ ]Upside-Down | | |Region | | Other... |
;; 15 | Print All Pages >|--\ | |Mode | +------------+
;; +-----------------------------+ | | +---------+ |[ ]Landscape| Id
;; IV 16 |[ ]Spool Buffer | | | +-C-------+ |[ ]Duplex | Ie
;; 17 |[ ]Print with faces | | \--|( )name A| |[ ]Tumble | If
;; 18 |[ ]Print via Ghostscript | | |( )name B| +------------+
;; +-----------------------------+ | |... |
;; V 19 |[ ]Auto Region | | |(*)name |
;; 20 |[ ]Auto Mode | | |... |
;; 21 |[ ]Menu Lock | | +---------+ +--------------+
;; +-----------------------------+ \------------------|(*)All Pages |
;; VI 22 | Customize >|--- D +-D------+ |( )Even Pages |
;; 23 | Show Settings >|-------|printing| |( )Odd Pages |
;; 24 | Help | |ps-print| |( )Even Sheets|
;; +-----------------------------+ |lpr | |( )Odd Sheets |
;; +--------+ +--------------+
;;
;; See `pr-visible-entry-list' for hiding some parts of the menu.
;;
;; The menu has the following sections:
;;
;; A. Interface:
;;
;; 0. You can use a buffer interface instead of menus. It looks like the
;; customization buffer. Basically, it has the same options found in the
;; menu and some extra options, all this on a buffer.
;;
;; I. PostScript printing:
;;
;; 1. You can generate a PostScript file (if you type C-u before activating
;; menu) or PostScript temporary file for a directory, a buffer, a region
;; or a major mode, choosing 1-up, 2-up, 4-up or any other n-up printing;
;; after file generation, ghostview is activated using the file generated
;; as argument. This option is disabled if spooling is on (option 16).
;; Also, if you already have a PostScript file you can preview it.
;; Instead of previewing each buffer, region or major mode at once, you
;; can save temporarily the PostScript code generated in a buffer and
;; preview it later. The option `Despool...' despools the PostScript
;; spooling buffer in a temporary file and uses ghostview to preview it.
;; If you type C-u before choosing this option, the PostScript code
;; generated is saved in a file instead of saving in a temporary file.
;; To spool the PostScript code generated you need to turn on the option
;; 16. The option `Despool...' is enabled if spooling is on (option
;; 16).
;;
;; NOTE 1: It's possible to customize a major mode printing, just declare
;; the customization in `pr-mode-alist' and invoke some of
;; `*-mode*' commands or select Mode option in Printing menu. An
;; example for major mode usage is when you're using gnus (or mh,
;; or rmail, etc.) and you're in the *Summary* buffer, if you
;; forget to switch to the *Article* buffer before printing,
;; you'll get a nicely formatted list of article subjects shows
;; up at the printer. With major mode printing you don't need to
;; switch from gnus *Summary* buffer first.
;;
;; NOTE 2: There are the following options for PostScript file
;; processing:
;; Ia. Print the file *No Preprocessing*, that is, send it
;; directly to PostScript printer.
;; Ib. PostScript utility processing selection.
;; See `pr-ps-utility-alist' and `pr-setting-database' for
;; documentation.
;; Ic. Do n-up processing before printing.
;; Id. Toggle on/off landscape for PostScript file processing.
;; Ie. Toggle on/off duplex for PostScript file processing.
;; If. Toggle on/off tumble for PostScript file processing.
;;
;; NOTE 3: Don't forget to download and install the utilities declared on
;; `pr-ps-utility-alist'.
;;
;; 2. Operate the same way as option 1, but it sends directly the PostScript
;; code (or put in a file, if you've typed C-u) or it uses ghostscript to
;; print the PostScript file generated. It depends on option 18, if it's
;; turned on, it uses ghostscript; otherwise, it sends directly to
;; printer. If spooling is on (option 16), the PostScript code is saved
;; temporarily in a buffer instead of printing it or saving it in a file.
;; Also, if you already have a PostScript file you can print it. Instead
;; of printing each buffer, region or major mode at once, you can save
;; temporarily the PostScript code generated in a buffer and print it
;; later. The option `Despool...' despools the PostScript spooling
;; buffer directly on a printer. If you type C-u before choosing this
;; option, the PostScript code generated is saved in a file instead of
;; sending to printer. To spool the PostScript code generated you need
;; to turn on the option 16. This option is enabled if spooling is on
;; (option 16). See also the NOTE 1, NOTE 2 and NOTE 3 on option 1.
;;
;; 3. You can select a new PostScript printer to send PostScript code
;; generated. For selection it's used all PostScript printers defined
;; in `pr-ps-printer-alist' variable (see it for documentation).
;; See also `pr-setting-database'.
;;
;; II. Text printing:
;;
;; 4. If you have control characters (character code from \000 to \037) in a
;; buffer and you want to print them in a text printer, select this
;; option. All control characters in your buffer or region will be
;; replaced by a printable representation. The printable representations
;; use ^ (for ASCII control characters) or hex. The characters tab,
;; linefeed, space, return and formfeed are not affected. You don't need
;; to select this option if you use any option of section I, the
;; PostScript engine treats control characters properly.
;;
;; 5. If you want to print a directory, buffer, region or major mode in a
;; text printer, select this option. See also the NOTE 1 on option 1.
;;
;; 6. You can select a new text printer to send text generated. For
;; selection it's used all text printers defined in
;; `pr-txt-printer-alist' variable (see it for documentation).
;; See also `pr-setting-database'.
;;
;; III. PostScript page toggle options:
;;
;; 7. If you want a PostScript landscape printing, turn on this option.
;;
;; 8. If you want to have a header in each page in your PostScript code,
;; turn on this option.
;;
;; 9. If you want to draw a gaudy frame around the header, turn on this
;; option. This option is enabled if print header is on (option 8).
;;
;; 10. If you want that the line number is printed in your PostScript code,
;; turn on this option.
;;
;; 11. If you want background zebra stripes in your PostScript code, turn on
;; this option.
;;
;; 12. If you want a duplex printing and your PostScript printer has this
;; feature, turn on this option.
;;
;; 13. If you turned on duplex printing, you can choose if you want to have
;; a printing suitable for binding on the left or right (tumble off), or
;; to have a printing suitable for binding at top or bottom (tumble on).
;; This option is enabled if duplex is on (option 12).
;;
;; 14. If you want a PostScript upside-down printing, turn on this option.
;;
;; 15. With this option, you can choose if you want to print all pages, odd
;; pages, even pages, odd sheets or even sheets.
;; See also `ps-even-or-odd-pages'.
;;
;; IV. PostScript processing toggle options:
;;
;; 16. If you want to spool the PostScript code generated, turn on this
;; option. To spool the PostScript code generated use option 2. You
;; can despool later by choosing option 1 or 2, sub-option `Despool...'.
;;
;; 17. If you use colors in your buffers and want to see these colors on
;; your PostScript code generated, turn on this option. If you have a
;; black/white PostScript printer, these colors are displayed in gray
;; scale by PostScript printer interpreter.
;;
;; 18. If you don't have a PostScript printer to send PostScript files, turn
;; on this option. When this option is on, the ghostscript is used to
;; print PostScript files. In GNU or Unix system, if ghostscript is set
;; as a PostScript filter, you don't need to turn on this option.
;;
;; V. Printing customization:
;;
;; 19. If you want that region is automagically detected, turn on this
;; option. Note that this will only work if you're using transient mark
;; mode. When this option is on, the `*-buffer*' commands will behave
;; like `*-region*' commands, that is, `*-buffer*' commands will print
;; only the region marked instead of all buffer.
;;
;; 20. Turn this option on if you want that when current major-mode is
;; declared in `pr-mode-alist', the `*-buffer*' and `*-region*' commands
;; behave like `*-mode*' commands.
;;
;; 21. If you want that Printing menu stays open while you are setting
;; toggle options, turn on this option. The variables
;; `pr-menu-char-height' and `pr-menu-char-width' are used to guess the
;; menu position, so don't forget to adjust these variables if menu
;; position is not ok.
;;
;; VI. Customization:
;;
;; 22. Besides all options in section III, IV and V, you can customize much
;; more PostScript options in `ps-print' option. Or you can customize
;; some `lpr' options for text printing. Or customize `printing'
;; options.
;;
;; 23. Show current settings for `printing', `ps-print' or `lpr'.
;;
;; 24. Quick help for printing menu layout.
;;
;;
;; Option Settings
;; ---------------
;;
;; Below it's shown only the main options that affect all `printing' package.
;; Check all the settings below *BEFORE* running `printing' commands.
;;
;; * Example of setting for GNU or Unix system:
;;
;; (require 'printing)
;; (setq pr-path-alist
;; '((unix "." "~/bin" ghostview mpage PATH)
;; (ghostview "$HOME/bin/gsview-dir")
;; (mpage "$HOME/bin/mpage-dir")
;; ))
;; (setq pr-txt-name 'prt_06a)
;; (setq pr-txt-printer-alist
;; '((prt_06a "lpr" nil "prt_06a")
;; (prt_07c nil nil "prt_07c")
;; ))
;; (setq pr-ps-name 'lps_06b)
;; (setq pr-ps-printer-alist
;; '((lps_06b "lpr" nil "-P" "lps_06b")
;; (lps_07c "lpr" nil nil "lps_07c")
;; (lps_08c nil nil nil "lps_08c")
;; ))
;; (setq pr-temp-dir "/tmp/")
;; (setq pr-gv-command "gv")
;; (setq pr-gs-command "gs")
;; (setq pr-gs-switches '("-q -dNOPAUSE -I/usr/share/ghostscript/5.10"))
;; (setq pr-gs-device "uniprint")
;; (setq pr-gs-resolution 300)
;; (setq pr-ps-utility 'mpage)
;; (setq pr-ps-utility-alist
;; '((mpage "mpage" nil "-b%s" "-%d" "-l" "-t" "-T" ">" nil)
;; (psnup "psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
;; (inherits-from: . no-duplex))
;; ))
;; (setq pr-setting-database
;; '((no-duplex
;; nil nil nil
;; (pr-file-duplex . nil)
;; (pr-file-tumble . nil))
;; ))
;; (pr-update-menus t) ; update now printer and utility menus
;;
;; * Example of setting for Windows system:
;;
;; (require 'printing)
;; (setq pr-path-alist
;; '((windows "c:/applications/executables" PATH ghostview mpage)
;; (ghostview "c:/gs/gsview-dir")
;; (mpage "c:/mpage-dir")
;; ))
;; (setq pr-txt-name 'prt_06a)
;; (setq pr-txt-printer-alist
;; '((prt_06a "print" nil "/D:\\\\printers\\prt_06a")
;; (prt_07c nil nil "/D:\\\\printers\\prt_07c")
;; (PRN "" nil "PRN")
;; (standard "redpr.exe" nil "")
;; ))
;; (setq pr-ps-name 'lps_06b)
;; (setq pr-ps-printer-alist
;; '((lps_06a "print" nil "/D:" "\\\\printers\\lps_06a")
;; (lps_06b "print" nil nil "\\\\printers\\lps_06b")
;; (lps_07c "print" nil "" "/D:\\\\printers\\lps_07c")
;; (lps_08c nil nil nil "\\\\printers\\lps_08c")
;; (b/w "gsprint" ("-all" "-twoup") "-printer " "b/w-pr-name")
;; (LPT1 "" nil "" "LPT1:")
;; (PRN "" nil "" "PRN")
;; (standard "redpr.exe" nil "" "")
;; ))
;; (setq pr-temp-dir "C:/WINDOWS/TEMP/")
;; (setq pr-gv-command "c:/gs/gsview/gsview32.exe")
;; (setq pr-gs-command "c:/gs/gswin32.exe")
;; (setq pr-gs-switches '("-q -dNOPAUSE -Ic:/gs/gs5.50;c:/gs/gs5.50/fonts"))
;; (setq pr-gs-device "mswinpr2")
;; (setq pr-gs-resolution 300)
;; (setq pr-ps-utility 'psnup)
;; (setq pr-ps-utility-alist
;; '((psnup "c:/psutils/psnup" ("-q") "-P%s" "-%d" "-l" nil nil " "
;; nil (inherits-from: . no-duplex))
;; ))
;; (setq pr-setting-database
;; '((no-duplex
;; nil nil nil
;; (pr-file-duplex . nil)
;; (pr-file-tumble . nil))
;; ))
;; (pr-update-menus t) ; update now printer and utility menus
;;
;; NOTE: Don't forget to download and install the utilities declared on
;; `pr-ps-utility-alist'.
;;
;;
;; Utilities
;; ---------
;;
;; `printing' package has the following utilities:
;;
;; `pr-setup' Return the current `printing' setup.
;;
;; `lpr-setup' Return the current `lpr' setup.
;;
;; `pr-update-menus' Update utility, PostScript and text printer menus.
;;
;; `pr-menu-bind' Install `printing' menu in the menubar.
;;
;;
;; Below are some URL where you can find good utilities.
;;
;; * For GNU or Unix system:
;;
;; gs, gv `https://www.gnu.org/software/ghostscript/ghostscript.html'
;; enscript `https://people.ssh.fi/mtr/genscript/'
;; psnup `http://www.knackered.org/angus/psutils/'
;; mpage `https://www.mesa.nl/pub/mpage/'
;;
;; * For Windows system:
;;
;; gswin32, gsview32
;; `https://www.gnu.org/software/ghostscript/ghostscript.html'
;; gsprint `https://www.cs.wisc.edu/~ghost/gsview/gsprint.htm'.
;; enscript `https://people.ssh.fi/mtr/genscript/'
;; psnup `https://gnuwin32.sourceforge.net/packages/psutils.htm'
;; redmon `http://www.ghostgum.com.au/software/redmon.htm'
;;
;;
;; Acknowledgments
;; ---------------
;;
;; Thanks to Stefan Monnier <monnier@iro.umontreal.ca> for GNU Emacs and XEmacs
;; printing menu (in `pr-menu-spec') merging suggestion.
;;
;; Thanks to Lennart Borgman <lennart.borgman.073@student.lu.se> for gsprint
;; suggestion (see tip 5 in section Tips).
;;
;; Thanks to Drew Adams <drew.adams@oracle.com> for suggestions:
;; - directory processing.
;; - `pr-path-alist' variable.
;; - doc fix.
;; - a lot of tests on Windows.
;;
;; Thanks to Fred Labrosse <f.labrosse@maths.bath.ac.uk> for XEmacs tests.
;;
;; Thanks to Klaus Berndl <klaus.berndl@sdm.de> for invaluable help/debugging
;; and for suggestions:
;; - even/odd pages printing.
;; - ghostscript parameters for `pr-ps-printer-alist'.
;; - default printer name.
;; - completion functions.
;; - automagic region detection.
;; - menu entry hiding.
;; - fast fire PostScript printing command.
;; - `pr-filename-style' variable.
;;
;; Thanks to Kim F. Storm <storm@filanet.dk> for beta-test and for suggestions:
;; - PostScript Print and PostScript Print Preview merge.
;; - Tools/Printing menu.
;; - replace *-using-preview by *-using-ghostscript.
;; - printer selection.
;; - extra parameters for `pr-ps-printer-alist'.
;;
;; Thanks to:
;; Frederic Corne <frederic.corne@erli.fr> print-nt.el
;; Tom Vogels <tov@ece.cmu.edu> mh-e-init.el
;; Matthew O. Persico <mpersico@erols.com> win32-ps-print.el
;; Volker Franz <volker.franz@tuebingen.mpg.de> ps-print-interface.el
;; And to all people who contributed with them.
;;
;;
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Code:
(require 'lpr)
(require 'ps-print)