printing.el 220 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693
  1. ;;; printing.el --- printing utilities
  2. ;; Copyright (C) 2000-2001, 2003-2015 Free Software Foundation, Inc.
  3. ;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br>
  4. ;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br>
  5. ;; Keywords: wp, print, PostScript
  6. ;; Version: 6.9.3
  7. ;; X-URL: http://www.emacswiki.org/cgi-bin/wiki/ViniciusJoseLatorre
  8. (defconst pr-version "6.9.3"
  9. "printing.el, v 6.9.3 <2007/12/09 vinicius>
  10. Please send all bug fixes and enhancements to
  11. bug-gnu-emacs@gnu.org and Vinicius Jose Latorre <viniciusjl@ig.com.br>
  12. ")
  13. ;; This file is part of GNU Emacs.
  14. ;; GNU Emacs is free software: you can redistribute it and/or modify
  15. ;; it under the terms of the GNU General Public License as published by
  16. ;; the Free Software Foundation, either version 3 of the License, or
  17. ;; (at your option) any later version.
  18. ;; GNU Emacs is distributed in the hope that it will be useful,
  19. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. ;; GNU General Public License for more details.
  22. ;; You should have received a copy of the GNU General Public License
  23. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  24. ;;; Commentary:
  25. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  26. ;;
  27. ;; Introduction
  28. ;; ------------
  29. ;;
  30. ;; With `printing' you can preview or print a PostScript file. You can also
  31. ;; print a text file using PostScript, and preview or print buffers that use
  32. ;; certain special modes like mh-folder-mode, rmail-summary-mode,
  33. ;; gnus-summary-mode, etc. This package also includes a PostScript/text
  34. ;; printer database.
  35. ;;
  36. ;; There are two user interfaces:
  37. ;;
  38. ;; * Menu interface:
  39. ;; The `printing' menu replaces the usual print options in the menu bar.
  40. ;; This is the default user interface.
  41. ;;
  42. ;; * Buffer interface:
  43. ;; You can use a buffer interface instead of menus. It looks like a
  44. ;; customization buffer. Basically, it has the same options found in the
  45. ;; menu and some extra options, all this on a buffer.
  46. ;;
  47. ;; `printing' is prepared to run on GNU, Unix and NT systems.
  48. ;; On GNU or Unix system, `printing' depends on gs and gv utilities.
  49. ;; On NT system, `printing' depends on gstools (gswin32.exe and gsview32.exe).
  50. ;; To obtain ghostscript, ghostview and GSview see the URL
  51. ;; `http://www.gnu.org/software/ghostscript/ghostscript.html'.
  52. ;;
  53. ;; `printing' depends on ps-print package to generate PostScript files, to
  54. ;; spool and to despool PostScript buffer. So, `printing' provides an
  55. ;; interface to ps-print package and it also provides some extra stuff.
  56. ;;
  57. ;; To download the latest ps-print package see
  58. ;; `http://www.emacswiki.org/cgi-bin/wiki/PsPrintPackage'.
  59. ;; Please, see README file for ps-print installation instructions.
  60. ;;
  61. ;; `printing' was inspired by:
  62. ;;
  63. ;; print-nt.el Frederic Corne <frederic.corne@erli.fr>
  64. ;; Special printing functions for Windows NT
  65. ;;
  66. ;; mh-e-init.el Tom Vogels <tov@ece.cmu.edu>
  67. ;; PS-print for mail messages
  68. ;;
  69. ;; win32-ps-print.el Matthew O. Persico <mpersico@erols.com>
  70. ;; PostScript printing with ghostscript
  71. ;;
  72. ;; ps-print-interface.el Volker Franz <volker.franz@tuebingen.mpg.de>
  73. ;; Graphical front end for ps-print and previewing
  74. ;;
  75. ;;
  76. ;; Log Messages
  77. ;; ------------
  78. ;;
  79. ;; The buffer *Printing Command Output* is where the `printing' log messages
  80. ;; are inserted. All program called by `printing' has a log entry in the
  81. ;; buffer *Printing Command Output*. A log entry has the following form:
  82. ;;
  83. ;; PROGRAM (ARG...)
  84. ;; MESSAGE
  85. ;; Exit status: CODE
  86. ;;
  87. ;; Where
  88. ;; PROGRAM is the program activated by `printing',
  89. ;; ARG is an argument passed to PROGRAM (it can have more than one argument),
  90. ;; MESSAGE is an error message returned by PROGRAM (it can have no message, if
  91. ;; PROGRAM is successful),
  92. ;; and CODE is a numeric exit status or a signal description string.
  93. ;;
  94. ;; For example, after previewing a PostScript file, *Printing Command Output*
  95. ;; will have the following entry:
  96. ;;
  97. ;; /usr/X11R6/bin/gv ("/home/user/example/file.ps")
  98. ;; Exit status: 0
  99. ;;
  100. ;; In the example above, the previewing was successful. If during previewing,
  101. ;; you quit gv execution (by typing C-g during Emacs session), the log entry
  102. ;; would be:
  103. ;;
  104. ;; /usr/X11R6/bin/gv ("/home/user/example/file.ps")
  105. ;; Exit status: Quit
  106. ;;
  107. ;; So, if something goes wrong, a good place to take a look is the buffer
  108. ;; *Printing Command Output*. Don't forget to see also the buffer *Messages*,
  109. ;; it can help.
  110. ;;
  111. ;;
  112. ;; Novices (First Users)
  113. ;; ---------------------
  114. ;;
  115. ;; First of all, see printing documentation only to get an idea of what
  116. ;; `printing' is capable.
  117. ;;
  118. ;; Then try to set the variables: `pr-ps-name', `pr-ps-printer-alist',
  119. ;; `pr-txt-name', `pr-txt-printer-alist' and `pr-path-alist'. These variables
  120. ;; are the main variables for printing processing.
  121. ;;
  122. ;; Now, please, see these variables documentation deeper. You can do this by
  123. ;; typing C-h v pr-ps-name RET (for example) if you already loaded printing
  124. ;; package, or by browsing printing.el source file.
  125. ;;
  126. ;; If the documentation isn't clear or if you find a way to improve the
  127. ;; documentation, please, send an email to maintainer. All printing users
  128. ;; will thank you.
  129. ;;
  130. ;; One way to set variables is by calling `pr-customize', customize all
  131. ;; variables and save the customization by future sessions (see Options
  132. ;; section). Other way is by adding code to your init file; see below
  133. ;; for a first setting template that it should be inserted on your
  134. ;; init file:
  135. ;;
  136. ;; * Example of setting for Windows system:
  137. ;;
  138. ;; (require 'printing) ; load printing package
  139. ;; (setq pr-path-alist
  140. ;; '((windows "c:/applications/executables" PATH ghostview mpage)
  141. ;; (ghostview "c:/gs/gsview-dir")
  142. ;; (mpage "c:/mpage-dir")
  143. ;; ))
  144. ;; (setq pr-txt-name 'prt_06a)
  145. ;; (setq pr-txt-printer-alist
  146. ;; '((prt_06a "print" nil "/D:\\\\printers\\prt_06a")
  147. ;; (prt_07c nil nil "/D:\\\\printers\\prt_07c")
  148. ;; (PRN "" nil "PRN")
  149. ;; (standard "redpr.exe" nil "")
  150. ;; ))
  151. ;; (setq pr-ps-name 'lps_06b)
  152. ;; (setq pr-ps-printer-alist
  153. ;; '((lps_06a "print" nil "/D:" "\\\\printers\\lps_06a")
  154. ;; (lps_06b "print" nil nil "\\\\printers\\lps_06b")
  155. ;; (lps_07c "print" nil "" "/D:\\\\printers\\lps_07c")
  156. ;; (lps_08c nil nil nil "\\\\printers\\lps_08c")
  157. ;; (LPT1 "" nil "" "LPT1:")
  158. ;; (PRN "" nil "" "PRN")
  159. ;; (standard "redpr.exe" nil "" "")
  160. ;; ))
  161. ;; (pr-update-menus t) ; update now printer and utility menus
  162. ;;
  163. ;; * Example of setting for GNU or Unix system:
  164. ;;
  165. ;; (require 'printing) ; load printing package
  166. ;; (setq pr-path-alist
  167. ;; '((unix "." "~/bin" ghostview mpage PATH)
  168. ;; (ghostview "$HOME/bin/gsview-dir")
  169. ;; (mpage "$HOME/bin/mpage-dir")
  170. ;; ))
  171. ;; (setq pr-txt-name 'prt_06a)
  172. ;; (setq pr-txt-printer-alist
  173. ;; '((prt_06a "lpr" nil "prt_06a")
  174. ;; (prt_07c nil nil "prt_07c")
  175. ;; ))
  176. ;; (setq pr-ps-name 'lps_06b)
  177. ;; (setq pr-ps-printer-alist
  178. ;; '((lps_06b "lpr" nil "-P" "lps_06b")
  179. ;; (lps_07c "lpr" nil nil "lps_07c")
  180. ;; (lps_08c nil nil nil "lps_08c")
  181. ;; ))
  182. ;; (pr-update-menus t) ; update now printer and utility menus
  183. ;;
  184. ;;
  185. ;; NOTE 1: Don't forget to download and install ghostscript utilities (see
  186. ;; Utilities section).
  187. ;;
  188. ;; NOTE 2: The `printer-name' and `ps-printer-name' variables don't need to be
  189. ;; set, as they are implicit set by `pr-ps-printer-alist' and
  190. ;; `pr-txt-printer-alist'.
  191. ;;
  192. ;; NOTE 3: The duplex feature will only work on PostScript printers that
  193. ;; support this feature.
  194. ;; You can check if your PostScript printer supports duplex feature
  195. ;; by checking the printer manual. Or you can try these steps:
  196. ;; 1. Open a buffer (or use the *scratch* buffer).
  197. ;; 2. Type:
  198. ;; First line (on first page)
  199. ;; ^L
  200. ;; Second line (on second page)
  201. ;; 3. Print this buffer with duplex turned on.
  202. ;; If it's printed 2 (two) sheets of paper, then your PostScript
  203. ;; printer doesn't have duplex feature; otherwise, it's ok, your
  204. ;; printer does have duplex feature.
  205. ;;
  206. ;; NOTE 4: See Tips section.
  207. ;;
  208. ;;
  209. ;; Tips
  210. ;; ----
  211. ;;
  212. ;; 1. If you have a local printer, that is, a printer which is connected
  213. ;; directly to your computer, don't forget to connect the printer to your
  214. ;; computer before printing.
  215. ;;
  216. ;; 2. If you try to print a file and it seems that the file was printed, but
  217. ;; there is no paper in the printer, then try to set `pr-delete-temp-file'
  218. ;; to nil. Probably `printing' is deleting the temporary file before your
  219. ;; local system can get it to send to the printer.
  220. ;;
  221. ;; 3. Don't try to print a dynamic buffer, that is, a buffer which is
  222. ;; modifying while `printing' tries to print. Eventually you got an error
  223. ;; message. Instead, save the dynamic buffer to a file or copy it in
  224. ;; another buffer and, then, print the file or the new static buffer.
  225. ;; An example of dynamic buffer is the *Messages* buffer.
  226. ;;
  227. ;; 4. When running Emacs on Windows (with or without cygwin), check if your
  228. ;; printer is a text printer or not by typing in a DOS window:
  229. ;;
  230. ;; print /D:\\host\printer somefile.txt
  231. ;;
  232. ;; Where, `host' is the machine where the printer is directly connected,
  233. ;; `printer' is the printer name and `somefile.txt' is a text file.
  234. ;;
  235. ;; If the printer `\\host\printer' doesn't print the content of
  236. ;; `somefile.txt' or, instead, it returns the following message:
  237. ;;
  238. ;; PostScript Error Handler
  239. ;; Offending Command = CCC
  240. ;; Stack =
  241. ;;
  242. ;; Where `CCC' is whatever is at the beginning of the text to be printed.
  243. ;;
  244. ;; Therefore, the printer `\\host\printer' is not a text printer, but a
  245. ;; PostScript printer. So, please, don't include this printer in
  246. ;; `pr-txt-printer-alist' (which see).
  247. ;;
  248. ;; 5. You can use gsprint instead of ghostscript to print monochrome PostScript
  249. ;; files in Windows. The gsprint utility documentation says that it is more
  250. ;; efficient than ghostscript to print monochrome PostScript.
  251. ;;
  252. ;; To print non-monochrome PostScript file, the efficiency of ghostscript
  253. ;; is similar to gsprint.
  254. ;;
  255. ;; Also the gsprint utility comes together with gsview distribution.
  256. ;;
  257. ;; For more information about gsprint see
  258. ;; `http://www.cs.wisc.edu/~ghost/gsview/gsprint.htm'.
  259. ;;
  260. ;; As an example of gsprint declaration:
  261. ;;
  262. ;; (setq pr-ps-printer-alist
  263. ;; '((A "gsprint" ("-all" "-twoup") "-printer " "my-b/w-printer-name")
  264. ;; (B "gsprint" ("-all" "-twoup") nil "-printer my-b/w-printer-name")
  265. ;; ;; some other printer declaration
  266. ;; ))
  267. ;;
  268. ;; The example above declares that printer A prints all pages (-all) and two
  269. ;; pages per sheet (-twoup). The printer B declaration does the same as the
  270. ;; printer A declaration, the only difference is the printer name selection.
  271. ;;
  272. ;; There are other command line options like:
  273. ;;
  274. ;; -mono Render in monochrome as 1bit/pixel (only black and white).
  275. ;; -grey Render in greyscale as 8bits/pixel.
  276. ;; -color Render in color as 24bits/pixel.
  277. ;;
  278. ;; The default is `-mono'. So, printer A and B in the example above are
  279. ;; using implicitly the `-mono' option. Note that in `-mono' no gray tone
  280. ;; or color is printed, this includes the zebra stripes, that is, in `-mono'
  281. ;; the zebra stripes are not printed.
  282. ;;
  283. ;; See also documentation for `pr-ps-printer-alist'.
  284. ;;
  285. ;;
  286. ;; Using `printing'
  287. ;; ----------------
  288. ;;
  289. ;; To use `printing' insert in your init file:
  290. ;;
  291. ;; (require 'printing)
  292. ;; ;; ...some user settings...
  293. ;; (pr-update-menus t)
  294. ;;
  295. ;; During `pr-update-menus' evaluation:
  296. ;; * On Emacs 20:
  297. ;; it replaces the Tools/Print menu by Tools/Printing menu.
  298. ;; * On Emacs 21:
  299. ;; it replaces the File/Print* menu entries by File/Print menu.
  300. ;; Please, see section Menu Layout below for menu explanation.
  301. ;;
  302. ;; To use `printing' utilities you can use the Printing menu options, type M-x
  303. ;; followed by one of the commands below, or type a key associated with the
  304. ;; command you want (if there is a key binding).
  305. ;;
  306. ;; `printing' has the following commands:
  307. ;;
  308. ;; pr-interface
  309. ;; pr-ps-directory-preview
  310. ;; pr-ps-directory-using-ghostscript
  311. ;; pr-ps-directory-print
  312. ;; pr-ps-directory-ps-print
  313. ;; pr-ps-buffer-preview
  314. ;; pr-ps-buffer-using-ghostscript
  315. ;; pr-ps-buffer-print
  316. ;; pr-ps-buffer-ps-print
  317. ;; pr-ps-region-preview
  318. ;; pr-ps-region-using-ghostscript
  319. ;; pr-ps-region-print
  320. ;; pr-ps-region-ps-print
  321. ;; pr-ps-mode-preview
  322. ;; pr-ps-mode-using-ghostscript
  323. ;; pr-ps-mode-print
  324. ;; pr-ps-mode-ps-print
  325. ;; pr-ps-file-preview
  326. ;; pr-ps-file-up-preview
  327. ;; pr-ps-file-using-ghostscript
  328. ;; pr-ps-file-print
  329. ;; pr-ps-file-ps-print
  330. ;; pr-ps-file-up-ps-print
  331. ;; pr-ps-fast-fire
  332. ;; pr-despool-preview
  333. ;; pr-despool-using-ghostscript
  334. ;; pr-despool-print
  335. ;; pr-despool-ps-print
  336. ;; pr-printify-directory
  337. ;; pr-printify-buffer
  338. ;; pr-printify-region
  339. ;; pr-txt-directory
  340. ;; pr-txt-buffer
  341. ;; pr-txt-region
  342. ;; pr-txt-mode
  343. ;; pr-txt-fast-fire
  344. ;; pr-toggle-file-duplex
  345. ;; pr-toggle-file-tumble
  346. ;; pr-toggle-file-landscape
  347. ;; pr-toggle-ghostscript
  348. ;; pr-toggle-faces
  349. ;; pr-toggle-spool
  350. ;; pr-toggle-duplex
  351. ;; pr-toggle-tumble
  352. ;; pr-toggle-landscape
  353. ;; pr-toggle-upside-down
  354. ;; pr-toggle-line
  355. ;; pr-toggle-zebra
  356. ;; pr-toggle-header
  357. ;; pr-toggle-lock
  358. ;; pr-toggle-region
  359. ;; pr-toggle-mode
  360. ;; pr-customize
  361. ;; lpr-customize
  362. ;; pr-help
  363. ;; pr-ps-name
  364. ;; pr-txt-name
  365. ;; pr-ps-utility
  366. ;; pr-show-ps-setup
  367. ;; pr-show-pr-setup
  368. ;; pr-show-lpr-setup
  369. ;;
  370. ;; The general meanings of above commands are:
  371. ;;
  372. ;; PREFIX:
  373. ;; `pr-interface' buffer interface for printing package.
  374. ;; `pr-help' help for printing package.
  375. ;; `pr-ps-name' interactively select a PostScript printer.
  376. ;; `pr-txt-name' interactively select a text printer.
  377. ;; `pr-ps-utility' interactively select a PostScript utility.
  378. ;; `pr-show-*-setup' show current settings.
  379. ;; `pr-ps-*' deal with PostScript code generation.
  380. ;; `pr-txt-*' deal with text generation.
  381. ;; `pr-toggle-*' toggle on/off some boolean variable.
  382. ;; `pr-despool-*' despool the PostScript spooling buffer.
  383. ;; `pr-printify-*' replace nonprintable ASCII by printable ASCII
  384. ;; representation.
  385. ;;
  386. ;; SUFFIX:
  387. ;; `*-customize' customization.
  388. ;; `*-preview' preview a PostScript file.
  389. ;; `*-using-ghostscript' use ghostscript to print.
  390. ;; `*-fast-fire' fast fire command (see it for documentation).
  391. ;; `*-print' send PostScript directly to printer.
  392. ;; `*-ps-print' send PostScript directly to printer or use
  393. ;; ghostscript to print. It depends on
  394. ;; `pr-print-using-ghostscript' option.
  395. ;;
  396. ;; INFIX/SUFFIX:
  397. ;; `*-directory*' process a directory.
  398. ;; `*-buffer*' process a buffer.
  399. ;; `*-region*' process a region.
  400. ;; `*-mode*' process a major mode (see explanation below).
  401. ;; `*-file-*' process a PostScript file.
  402. ;; `*-file-up-*' process a PostScript file using a filter utility.
  403. ;;
  404. ;; Here are some examples:
  405. ;;
  406. ;; `pr-ps-buffer-using-ghostscript'
  407. ;; Use ghostscript to print a buffer.
  408. ;;
  409. ;; `pr-ps-file-print'
  410. ;; Print a PostScript file.
  411. ;;
  412. ;; `pr-toggle-spool'
  413. ;; Toggle spooling buffer.
  414. ;;
  415. ;; So you can preview through ghostview, use ghostscript to print (if you don't
  416. ;; have a PostScript printer) or send directly to printer a PostScript code
  417. ;; generated by `ps-print' package.
  418. ;;
  419. ;; Besides operating one buffer or region each time, you also can postpone
  420. ;; previewing or printing by saving the PostScript code generated in a
  421. ;; temporary Emacs buffer. This way you can save banner pages between
  422. ;; successive printing. You can toggle on/off spooling by invoking
  423. ;; `pr-toggle-spool' interactively or through menu bar.
  424. ;;
  425. ;; If you type, for example:
  426. ;;
  427. ;; C-u M-x pr-ps-buffer-print RET
  428. ;;
  429. ;; The `pr-ps-buffer-print' command prompts you for a n-up printing number and
  430. ;; a file name, and save the PostScript code generated to the file name instead
  431. ;; of sending to printer.
  432. ;;
  433. ;; This behavior is similar with the commands that deal with PostScript code
  434. ;; generation, that is, with `pr-ps-*' and `pr-despool-*' commands. If
  435. ;; spooling is on, only `pr-despool-*' commands prompt for a file name and save
  436. ;; the PostScript code spooled in this file.
  437. ;;
  438. ;; Besides the behavior described above, the `*-directory*' commands also
  439. ;; prompt for a directory and a file name regexp. So, it's possible to process
  440. ;; all or certain files on a directory at once (see also documentation for
  441. ;; `pr-list-directory').
  442. ;;
  443. ;; `printing' has also a special way to handle some major mode through
  444. ;; `*-mode*' commands. So it's possible to customize a major mode printing,
  445. ;; it's only needed to declare the customization in `pr-mode-alist' (see
  446. ;; section Options) and invoke some of `*-mode*' commands. An example for
  447. ;; major mode usage is when you're using gnus (or mh, or rmail, etc.) and
  448. ;; you're in the *Summary* buffer, if you forget to switch to the *Article*
  449. ;; buffer before printing, you'll get a nicely formatted list of article
  450. ;; subjects shows up at the printer. With major mode printing you don't need
  451. ;; to switch from gnus *Summary* buffer first.
  452. ;;
  453. ;; Current global keyboard mapping for GNU Emacs is:
  454. ;;
  455. ;; (global-set-key [print] 'pr-ps-fast-fire)
  456. ;; (global-set-key [M-print] 'pr-ps-mode-using-ghostscript)
  457. ;; (global-set-key [S-print] 'pr-ps-mode-using-ghostscript)
  458. ;; (global-set-key [C-print] 'pr-txt-fast-fire)
  459. ;; (global-set-key [C-M-print] 'pr-txt-fast-fire)
  460. ;;
  461. ;; And for XEmacs is:
  462. ;;
  463. ;; (global-set-key 'f22 'pr-ps-fast-fire)
  464. ;; (global-set-key '(meta f22) 'pr-ps-mode-using-ghostscript)
  465. ;; (global-set-key '(shift f22) 'pr-ps-mode-using-ghostscript)
  466. ;; (global-set-key '(control f22) 'pr-txt-fast-fire)
  467. ;; (global-set-key '(control meta f22) 'pr-txt-fast-fire)
  468. ;;
  469. ;; As a suggestion of global keyboard mapping for some `printing' commands:
  470. ;;
  471. ;; (global-set-key "\C-ci" 'pr-interface)
  472. ;; (global-set-key "\C-cbp" 'pr-ps-buffer-print)
  473. ;; (global-set-key "\C-cbx" 'pr-ps-buffer-preview)
  474. ;; (global-set-key "\C-cbb" 'pr-ps-buffer-using-ghostscript)
  475. ;; (global-set-key "\C-crp" 'pr-ps-region-print)
  476. ;; (global-set-key "\C-crx" 'pr-ps-region-preview)
  477. ;; (global-set-key "\C-crr" 'pr-ps-region-using-ghostscript)
  478. ;;
  479. ;;
  480. ;; Options
  481. ;; -------
  482. ;;
  483. ;; Below it's shown a brief description of `printing' options, please, see the
  484. ;; options declaration in the code for a long documentation.
  485. ;;
  486. ;; `pr-path-style' Specify which path style to use for external
  487. ;; commands.
  488. ;;
  489. ;; `pr-path-alist' Specify an alist for command paths.
  490. ;;
  491. ;; `pr-txt-name' Specify a printer for printing a text file.
  492. ;;
  493. ;; `pr-txt-printer-alist' Specify an alist of all text printers.
  494. ;;
  495. ;; `pr-ps-name' Specify a printer for printing a PostScript
  496. ;; file.
  497. ;;
  498. ;; `pr-ps-printer-alist' Specify an alist for all PostScript printers.
  499. ;;
  500. ;; `pr-temp-dir' Specify a directory for temporary files during
  501. ;; printing.
  502. ;;
  503. ;; `pr-ps-temp-file' Specify PostScript temporary file name prefix.
  504. ;;
  505. ;; `pr-file-modes' Specify the file permission bits for newly
  506. ;; created files.
  507. ;;
  508. ;; `pr-gv-command' Specify path and name of the gsview/gv
  509. ;; utility.
  510. ;;
  511. ;; `pr-gs-command' Specify path and name of the ghostscript
  512. ;; utility.
  513. ;;
  514. ;; `pr-gs-switches' Specify ghostscript switches.
  515. ;;
  516. ;; `pr-gs-device' Specify ghostscript device switch value.
  517. ;;
  518. ;; `pr-gs-resolution' Specify ghostscript resolution switch value.
  519. ;;
  520. ;; `pr-print-using-ghostscript' Non-nil means print using ghostscript.
  521. ;;
  522. ;; `pr-faces-p' Non-nil means print with face attributes.
  523. ;;
  524. ;; `pr-spool-p' Non-nil means spool printing in a buffer.
  525. ;;
  526. ;; `pr-file-landscape' Non-nil means print PostScript file in
  527. ;; landscape orientation.
  528. ;;
  529. ;; `pr-file-duplex' Non-nil means print PostScript file in duplex
  530. ;; mode.
  531. ;;
  532. ;; `pr-file-tumble' Non-nil means print PostScript file in tumble
  533. ;; mode.
  534. ;;
  535. ;; `pr-auto-region' Non-nil means region is automagically detected.
  536. ;;
  537. ;; `pr-auto-mode' Non-nil means major-mode specific printing is
  538. ;; preferred over normal printing.
  539. ;;
  540. ;; `pr-mode-alist' Specify an alist for a major-mode and printing
  541. ;; function.
  542. ;;
  543. ;; `pr-ps-utility' Specify PostScript utility processing.
  544. ;;
  545. ;; `pr-ps-utility-alist' Specify an alist for PostScript utility
  546. ;; processing.
  547. ;;
  548. ;; `pr-menu-lock' Non-nil means menu is locked while selecting
  549. ;; toggle options.
  550. ;;
  551. ;; `pr-menu-char-height' Specify menu char height in pixels.
  552. ;;
  553. ;; `pr-menu-char-width' Specify menu char width in pixels.
  554. ;;
  555. ;; `pr-setting-database' Specify an alist for settings in general.
  556. ;;
  557. ;; `pr-visible-entry-list' Specify a list of Printing menu visible
  558. ;; entries.
  559. ;;
  560. ;; `pr-delete-temp-file' Non-nil means delete temporary files.
  561. ;;
  562. ;; `pr-list-directory' Non-nil means list directory when processing a
  563. ;; directory.
  564. ;;
  565. ;; `pr-buffer-name' Specify the name of the buffer interface for
  566. ;; printing package.
  567. ;;
  568. ;; `pr-buffer-name-ignore' Specify a regexp list for buffer names to be
  569. ;; ignored in interface buffer.
  570. ;;
  571. ;; `pr-buffer-verbose' Non-nil means to be verbose when editing a
  572. ;; field in interface buffer.
  573. ;;
  574. ;; To set the above options you may:
  575. ;;
  576. ;; a) insert the code in your ~/.emacs, like:
  577. ;;
  578. ;; (setq pr-faces-p t)
  579. ;;
  580. ;; This way always keep your default settings when you enter a new Emacs
  581. ;; session.
  582. ;;
  583. ;; b) or use `set-variable' in your Emacs session, like:
  584. ;;
  585. ;; M-x set-variable RET pr-faces-p RET t RET
  586. ;;
  587. ;; This way keep your settings only during the current Emacs session.
  588. ;;
  589. ;; c) or use customization, for example:
  590. ;; click on menu-bar *Help* option,
  591. ;; then click on *Customize*,
  592. ;; then click on *Browse Customization Groups*,
  593. ;; expand *PostScript* group,
  594. ;; expand *Printing* group
  595. ;; and then customize `printing' options.
  596. ;; Through this way, you may choose if the settings are kept or not when
  597. ;; you leave out the current Emacs session.
  598. ;;
  599. ;; d) or see the option value:
  600. ;;
  601. ;; C-h v pr-faces-p RET
  602. ;;
  603. ;; and click the *customize* hypertext button.
  604. ;; Through this way, you may choose if the settings are kept or not when
  605. ;; you leave out the current Emacs session.
  606. ;;
  607. ;; e) or invoke:
  608. ;;
  609. ;; M-x pr-customize RET
  610. ;;
  611. ;; and then customize `printing' options.
  612. ;; Through this way, you may choose if the settings are kept or not when
  613. ;; you leave out the current Emacs session.
  614. ;;
  615. ;; f) or use menu bar, for example:
  616. ;; click on menu-bar *File* option,
  617. ;; then click on *Printing*,
  618. ;; then click on *Customize*,
  619. ;; then click on *printing*
  620. ;; and then customize `printing' options.
  621. ;; Through this way, you may choose if the settings are kept or not when
  622. ;; you leave out the current Emacs session.
  623. ;;
  624. ;;
  625. ;; Menu Layout
  626. ;; -----------
  627. ;;
  628. ;; The `printing' menu (Tools/Printing or File/Print) has the following layout:
  629. ;;
  630. ;; +-----------------------------+
  631. ;; A 0 | Printing Interface |
  632. ;; +-----------------------------+ +-A---------+ +-B------+
  633. ;; I 1 | PostScript Preview >|-------|Directory >|-----|1-up |
  634. ;; 2 | PostScript Print >|---- A |Buffer >|-- B |2-up |
  635. ;; 3 | PostScript Printer: name >|---- C |Region >|-- B |4-up |
  636. ;; +-----------------------------+ |Mode >|-- B |Other...|
  637. ;; II 4 | Printify >|-----\ |File >|--\ +--------+
  638. ;; 5 | Print >|---\ | |Despool... | |
  639. ;; 6 | Text Printer: name >|-\ | | +-----------+ |
  640. ;; +-----------------------------+ | | | +---------+ +------------+
  641. ;; III 7 |[ ]Landscape | | | \-|Directory| | No Prep... | Ia
  642. ;; 8 |[ ]Print Header | | | |Buffer | +------------+ Ib
  643. ;; 9 |[ ]Print Header Frame | | | |Region | | name >|- C
  644. ;; 10 |[ ]Line Number | | | +---------+ +------------+
  645. ;; 11 |[ ]Zebra Stripes | | | +---------+ | 1-up... | Ic
  646. ;; 12 |[ ]Duplex | | \---|Directory| | 2-up... |
  647. ;; 13 |[ ]Tumble | \--\ |Buffer | | 4-up... |
  648. ;; 14 |[ ]Upside-Down | | |Region | | Other... |
  649. ;; 15 | Print All Pages >|--\ | |Mode | +------------+
  650. ;; +-----------------------------+ | | +---------+ |[ ]Landscape| Id
  651. ;; IV 16 |[ ]Spool Buffer | | | +-C-------+ |[ ]Duplex | Ie
  652. ;; 17 |[ ]Print with faces | | \--|( )name A| |[ ]Tumble | If
  653. ;; 18 |[ ]Print via Ghostscript | | |( )name B| +------------+
  654. ;; +-----------------------------+ | |... |
  655. ;; V 19 |[ ]Auto Region | | |(*)name |
  656. ;; 20 |[ ]Auto Mode | | |... |
  657. ;; 21 |[ ]Menu Lock | | +---------+ +--------------+
  658. ;; +-----------------------------+ \------------------|(*)All Pages |
  659. ;; VI 22 | Customize >|--- D +-D------+ |( )Even Pages |
  660. ;; 23 | Show Settings >|-------|printing| |( )Odd Pages |
  661. ;; 24 | Help | |ps-print| |( )Even Sheets|
  662. ;; +-----------------------------+ |lpr | |( )Odd Sheets |
  663. ;; +--------+ +--------------+
  664. ;;
  665. ;; See `pr-visible-entry-list' for hiding some parts of the menu.
  666. ;;
  667. ;; The menu has the following sections:
  668. ;;
  669. ;; A. Interface:
  670. ;;
  671. ;; 0. You can use a buffer interface instead of menus. It looks like the
  672. ;; customization buffer. Basically, it has the same options found in the
  673. ;; menu and some extra options, all this on a buffer.
  674. ;;
  675. ;; I. PostScript printing:
  676. ;;
  677. ;; 1. You can generate a PostScript file (if you type C-u before activating
  678. ;; menu) or PostScript temporary file for a directory, a buffer, a region
  679. ;; or a major mode, choosing 1-up, 2-up, 4-up or any other n-up printing;
  680. ;; after file generation, ghostview is activated using the file generated
  681. ;; as argument. This option is disabled if spooling is on (option 16).
  682. ;; Also, if you already have a PostScript file you can preview it.
  683. ;; Instead of previewing each buffer, region or major mode at once, you
  684. ;; can save temporarily the PostScript code generated in a buffer and
  685. ;; preview it later. The option `Despool...' despools the PostScript
  686. ;; spooling buffer in a temporary file and uses ghostview to preview it.
  687. ;; If you type C-u before choosing this option, the PostScript code
  688. ;; generated is saved in a file instead of saving in a temporary file.
  689. ;; To spool the PostScript code generated you need to turn on the option
  690. ;; 16. The option `Despool...' is enabled if spooling is on (option
  691. ;; 16).
  692. ;;
  693. ;; NOTE 1: It's possible to customize a major mode printing, just declare
  694. ;; the customization in `pr-mode-alist' and invoke some of
  695. ;; `*-mode*' commands or select Mode option in Printing menu. An
  696. ;; example for major mode usage is when you're using gnus (or mh,
  697. ;; or rmail, etc.) and you're in the *Summary* buffer, if you
  698. ;; forget to switch to the *Article* buffer before printing,
  699. ;; you'll get a nicely formatted list of article subjects shows
  700. ;; up at the printer. With major mode printing you don't need to
  701. ;; switch from gnus *Summary* buffer first.
  702. ;;
  703. ;; NOTE 2: There are the following options for PostScript file
  704. ;; processing:
  705. ;; Ia. Print the file *No Preprocessing*, that is, send it
  706. ;; directly to PostScript printer.
  707. ;; Ib. PostScript utility processing selection.
  708. ;; See `pr-ps-utility-alist' and `pr-setting-database' for
  709. ;; documentation.
  710. ;; Ic. Do n-up processing before printing.
  711. ;; Id. Toggle on/off landscape for PostScript file processing.
  712. ;; Ie. Toggle on/off duplex for PostScript file processing.
  713. ;; If. Toggle on/off tumble for PostScript file processing.
  714. ;;
  715. ;; NOTE 3: Don't forget to download and install the utilities declared on
  716. ;; `pr-ps-utility-alist'.
  717. ;;
  718. ;; 2. Operate the same way as option 1, but it sends directly the PostScript
  719. ;; code (or put in a file, if you've typed C-u) or it uses ghostscript to
  720. ;; print the PostScript file generated. It depends on option 18, if it's
  721. ;; turned on, it uses ghostscript; otherwise, it sends directly to
  722. ;; printer. If spooling is on (option 16), the PostScript code is saved
  723. ;; temporarily in a buffer instead of printing it or saving it in a file.
  724. ;; Also, if you already have a PostScript file you can print it. Instead
  725. ;; of printing each buffer, region or major mode at once, you can save
  726. ;; temporarily the PostScript code generated in a buffer and print it
  727. ;; later. The option `Despool...' despools the PostScript spooling
  728. ;; buffer directly on a printer. If you type C-u before choosing this
  729. ;; option, the PostScript code generated is saved in a file instead of
  730. ;; sending to printer. To spool the PostScript code generated you need
  731. ;; to turn on the option 16. This option is enabled if spooling is on
  732. ;; (option 16). See also the NOTE 1, NOTE 2 and NOTE 3 on option 1.
  733. ;;
  734. ;; 3. You can select a new PostScript printer to send PostScript code
  735. ;; generated. For selection it's used all PostScript printers defined
  736. ;; in `pr-ps-printer-alist' variable (see it for documentation).
  737. ;; See also `pr-setting-database'.
  738. ;;
  739. ;; II. Text printing:
  740. ;;
  741. ;; 4. If you have control characters (character code from \000 to \037) in a
  742. ;; buffer and you want to print them in a text printer, select this
  743. ;; option. All control characters in your buffer or region will be
  744. ;; replaced by a printable representation. The printable representations
  745. ;; use ^ (for ASCII control characters) or hex. The characters tab,
  746. ;; linefeed, space, return and formfeed are not affected. You don't need
  747. ;; to select this option if you use any option of section I, the
  748. ;; PostScript engine treats control characters properly.
  749. ;;
  750. ;; 5. If you want to print a directory, buffer, region or major mode in a
  751. ;; text printer, select this option. See also the NOTE 1 on option 1.
  752. ;;
  753. ;; 6. You can select a new text printer to send text generated. For
  754. ;; selection it's used all text printers defined in
  755. ;; `pr-txt-printer-alist' variable (see it for documentation).
  756. ;; See also `pr-setting-database'.
  757. ;;
  758. ;; III. PostScript page toggle options:
  759. ;;
  760. ;; 7. If you want a PostScript landscape printing, turn on this option.
  761. ;;
  762. ;; 8. If you want to have a header in each page in your PostScript code,
  763. ;; turn on this option.
  764. ;;
  765. ;; 9. If you want to draw a gaudy frame around the header, turn on this
  766. ;; option. This option is enabled if print header is on (option 8).
  767. ;;
  768. ;; 10. If you want that the line number is printed in your PostScript code,
  769. ;; turn on this option.
  770. ;;
  771. ;; 11. If you want background zebra stripes in your PostScript code, turn on
  772. ;; this option.
  773. ;;
  774. ;; 12. If you want a duplex printing and your PostScript printer has this
  775. ;; feature, turn on this option.
  776. ;;
  777. ;; 13. If you turned on duplex printing, you can choose if you want to have
  778. ;; a printing suitable for binding on the left or right (tumble off), or
  779. ;; to have a printing suitable for binding at top or bottom (tumble on).
  780. ;; This option is enabled if duplex is on (option 12).
  781. ;;
  782. ;; 14. If you want a PostScript upside-down printing, turn on this option.
  783. ;;
  784. ;; 15. With this option, you can choose if you want to print all pages, odd
  785. ;; pages, even pages, odd sheets or even sheets.
  786. ;; See also `ps-even-or-odd-pages'.
  787. ;;
  788. ;; IV. PostScript processing toggle options:
  789. ;;
  790. ;; 16. If you want to spool the PostScript code generated, turn on this
  791. ;; option. To spool the PostScript code generated use option 2. You
  792. ;; can despool later by choosing option 1 or 2, sub-option `Despool...'.
  793. ;;
  794. ;; 17. If you use colors in your buffers and want to see these colors on
  795. ;; your PostScript code generated, turn on this option. If you have a
  796. ;; black/white PostScript printer, these colors are displayed in gray
  797. ;; scale by PostScript printer interpreter.
  798. ;;
  799. ;; 18. If you don't have a PostScript printer to send PostScript files, turn
  800. ;; on this option. When this option is on, the ghostscript is used to
  801. ;; print PostScript files. In GNU or Unix system, if ghostscript is set
  802. ;; as a PostScript filter, you don't need to turn on this option.
  803. ;;
  804. ;; V. Printing customization:
  805. ;;
  806. ;; 19. If you want that region is automagically detected, turn on this
  807. ;; option. Note that this will only work if you're using transient mark
  808. ;; mode. When this option is on, the `*-buffer*' commands will behave
  809. ;; like `*-region*' commands, that is, `*-buffer*' commands will print
  810. ;; only the region marked instead of all buffer.
  811. ;;
  812. ;; 20. Turn this option on if you want that when current major-mode is
  813. ;; declared in `pr-mode-alist', the `*-buffer*' and `*-region*' commands
  814. ;; behave like `*-mode*' commands.
  815. ;;
  816. ;; 21. If you want that Printing menu stays open while you are setting
  817. ;; toggle options, turn on this option. The variables
  818. ;; `pr-menu-char-height' and `pr-menu-char-width' are used to guess the
  819. ;; menu position, so don't forget to adjust these variables if menu
  820. ;; position is not ok.
  821. ;;
  822. ;; VI. Customization:
  823. ;;
  824. ;; 22. Besides all options in section III, IV and V, you can customize much
  825. ;; more PostScript options in `ps-print' option. Or you can customize
  826. ;; some `lpr' options for text printing. Or customize `printing'
  827. ;; options.
  828. ;;
  829. ;; 23. Show current settings for `printing', `ps-print' or `lpr'.
  830. ;;
  831. ;; 24. Quick help for printing menu layout.
  832. ;;
  833. ;;
  834. ;; Option Settings
  835. ;; ---------------
  836. ;;
  837. ;; Below it's shown only the main options that affect all `printing' package.
  838. ;; Check all the settings below *BEFORE* running `printing' commands.
  839. ;;
  840. ;; * Example of setting for GNU or Unix system:
  841. ;;
  842. ;; (require 'printing)
  843. ;; (setq pr-path-alist
  844. ;; '((unix "." "~/bin" ghostview mpage PATH)
  845. ;; (ghostview "$HOME/bin/gsview-dir")
  846. ;; (mpage "$HOME/bin/mpage-dir")
  847. ;; ))
  848. ;; (setq pr-txt-name 'prt_06a)
  849. ;; (setq pr-txt-printer-alist
  850. ;; '((prt_06a "lpr" nil "prt_06a")
  851. ;; (prt_07c nil nil "prt_07c")
  852. ;; ))
  853. ;; (setq pr-ps-name 'lps_06b)
  854. ;; (setq pr-ps-printer-alist
  855. ;; '((lps_06b "lpr" nil "-P" "lps_06b")
  856. ;; (lps_07c "lpr" nil nil "lps_07c")
  857. ;; (lps_08c nil nil nil "lps_08c")
  858. ;; ))
  859. ;; (setq pr-temp-dir "/tmp/")
  860. ;; (setq pr-gv-command "gv")
  861. ;; (setq pr-gs-command "gs")
  862. ;; (setq pr-gs-switches '("-q -dNOPAUSE -I/usr/share/ghostscript/5.10"))
  863. ;; (setq pr-gs-device "uniprint")
  864. ;; (setq pr-gs-resolution 300)
  865. ;; (setq pr-ps-utility 'mpage)
  866. ;; (setq pr-ps-utility-alist
  867. ;; '((mpage "mpage" nil "-b%s" "-%d" "-l" "-t" "-T" ">" nil)
  868. ;; (psnup "psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
  869. ;; (inherits-from: . no-duplex))
  870. ;; ))
  871. ;; (setq pr-setting-database
  872. ;; '((no-duplex
  873. ;; nil nil nil
  874. ;; (pr-file-duplex . nil)
  875. ;; (pr-file-tumble . nil))
  876. ;; ))
  877. ;; (pr-update-menus t) ; update now printer and utility menus
  878. ;;
  879. ;; * Example of setting for Windows system:
  880. ;;
  881. ;; (require 'printing)
  882. ;; (setq pr-path-alist
  883. ;; '((windows "c:/applications/executables" PATH ghostview mpage)
  884. ;; (ghostview "c:/gs/gsview-dir")
  885. ;; (mpage "c:/mpage-dir")
  886. ;; ))
  887. ;; (setq pr-txt-name 'prt_06a)
  888. ;; (setq pr-txt-printer-alist
  889. ;; '((prt_06a "print" nil "/D:\\\\printers\\prt_06a")
  890. ;; (prt_07c nil nil "/D:\\\\printers\\prt_07c")
  891. ;; (PRN "" nil "PRN")
  892. ;; (standard "redpr.exe" nil "")
  893. ;; ))
  894. ;; (setq pr-ps-name 'lps_06b)
  895. ;; (setq pr-ps-printer-alist
  896. ;; '((lps_06a "print" nil "/D:" "\\\\printers\\lps_06a")
  897. ;; (lps_06b "print" nil nil "\\\\printers\\lps_06b")
  898. ;; (lps_07c "print" nil "" "/D:\\\\printers\\lps_07c")
  899. ;; (lps_08c nil nil nil "\\\\printers\\lps_08c")
  900. ;; (b/w "gsprint" ("-all" "-twoup") "-printer " "b/w-pr-name")
  901. ;; (LPT1 "" nil "" "LPT1:")
  902. ;; (PRN "" nil "" "PRN")
  903. ;; (standard "redpr.exe" nil "" "")
  904. ;; ))
  905. ;; (setq pr-temp-dir "C:/WINDOWS/TEMP/")
  906. ;; (setq pr-gv-command "c:/gs/gsview/gsview32.exe")
  907. ;; (setq pr-gs-command "c:/gs/gswin32.exe")
  908. ;; (setq pr-gs-switches '("-q -dNOPAUSE -Ic:/gs/gs5.50;c:/gs/gs5.50/fonts"))
  909. ;; (setq pr-gs-device "mswinpr2")
  910. ;; (setq pr-gs-resolution 300)
  911. ;; (setq pr-ps-utility 'psnup)
  912. ;; (setq pr-ps-utility-alist
  913. ;; '((psnup "c:/psutils/psnup" ("-q") "-P%s" "-%d" "-l" nil nil " "
  914. ;; nil (inherits-from: . no-duplex))
  915. ;; ))
  916. ;; (setq pr-setting-database
  917. ;; '((no-duplex
  918. ;; nil nil nil
  919. ;; (pr-file-duplex . nil)
  920. ;; (pr-file-tumble . nil))
  921. ;; ))
  922. ;; (pr-update-menus t) ; update now printer and utility menus
  923. ;;
  924. ;; NOTE: Don't forget to download and install the utilities declared on
  925. ;; `pr-ps-utility-alist'.
  926. ;;
  927. ;;
  928. ;; Utilities
  929. ;; ---------
  930. ;;
  931. ;; `printing' package has the following utilities:
  932. ;;
  933. ;; `pr-setup' Return the current `printing' setup.
  934. ;;
  935. ;; `lpr-setup' Return the current `lpr' setup.
  936. ;;
  937. ;; `pr-update-menus' Update utility, PostScript and text printer menus.
  938. ;;
  939. ;; `pr-menu-bind' Install `printing' menu in the menubar.
  940. ;;
  941. ;;
  942. ;; Below are some URL where you can find good utilities.
  943. ;;
  944. ;; * For `printing' package:
  945. ;;
  946. ;; printing `http://www.emacswiki.org/cgi-bin/emacs/download/printing.el'
  947. ;; ps-print `http://www.emacswiki.org/cgi-bin/wiki/PsPrintPackage'
  948. ;;
  949. ;; * For GNU or Unix system:
  950. ;;
  951. ;; gs, gv `http://www.gnu.org/software/ghostscript/ghostscript.html'
  952. ;; enscript `http://people.ssh.fi/mtr/genscript/'
  953. ;; psnup `http://www.knackered.org/angus/psutils/'
  954. ;; mpage `http://www.mesa.nl/pub/mpage/'
  955. ;;
  956. ;; * For Windows system:
  957. ;;
  958. ;; gswin32, gsview32
  959. ;; `http://www.gnu.org/software/ghostscript/ghostscript.html'
  960. ;; gsprint `http://www.cs.wisc.edu/~ghost/gsview/gsprint.htm'.
  961. ;; enscript `http://people.ssh.fi/mtr/genscript/'
  962. ;; psnup `http://gnuwin32.sourceforge.net/packages/psutils.htm'
  963. ;; redmon `http://www.cs.wisc.edu/~ghost/redmon/'
  964. ;;
  965. ;;
  966. ;; Acknowledgments
  967. ;; ---------------
  968. ;;
  969. ;; Thanks to Stefan Monnier <monnier@iro.umontreal.ca> for GNU Emacs and XEmacs
  970. ;; printing menu (in `pr-menu-spec') merging suggestion.
  971. ;;
  972. ;; Thanks to Lennart Borgman <lennart.borgman.073@student.lu.se> for gsprint
  973. ;; suggestion (see tip 5 in section Tips).
  974. ;;
  975. ;; Thanks to Drew Adams <drew.adams@oracle.com> for suggestions:
  976. ;; - directory processing.
  977. ;; - `pr-path-alist' variable.
  978. ;; - doc fix.
  979. ;; - a lot of tests on Windows.
  980. ;;
  981. ;; Thanks to Fred Labrosse <f.labrosse@maths.bath.ac.uk> for XEmacs tests.
  982. ;;
  983. ;; Thanks to Klaus Berndl <klaus.berndl@sdm.de> for invaluable help/debugging
  984. ;; and for suggestions:
  985. ;; - even/odd pages printing.
  986. ;; - ghostscript parameters for `pr-ps-printer-alist'.
  987. ;; - default printer name.
  988. ;; - completion functions.
  989. ;; - automagic region detection.
  990. ;; - menu entry hiding.
  991. ;; - fast fire PostScript printing command.
  992. ;; - `pr-path-style' variable.
  993. ;;
  994. ;; Thanks to Kim F. Storm <storm@filanet.dk> for beta-test and for suggestions:
  995. ;; - PostScript Print and PostScript Print Preview merge.
  996. ;; - Tools/Printing menu.
  997. ;; - replace *-using-preview by *-using-ghostscript.
  998. ;; - printer selection.
  999. ;; - extra parameters for `pr-ps-printer-alist'.
  1000. ;;
  1001. ;; Thanks to:
  1002. ;; Frederic Corne <frederic.corne@erli.fr> print-nt.el
  1003. ;; Tom Vogels <tov@ece.cmu.edu> mh-e-init.el
  1004. ;; Matthew O. Persico <mpersico@erols.com> win32-ps-print.el
  1005. ;; Volker Franz <volker.franz@tuebingen.mpg.de> ps-print-interface.el
  1006. ;; And to all people who contributed with them.
  1007. ;;
  1008. ;;
  1009. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1010. ;;; Code:
  1011. (require 'lpr)
  1012. (require 'ps-print)
  1013. (and (string< ps-print-version "6.6.4")
  1014. (error "`printing' requires `ps-print' package version 6.6.4 or later"))
  1015. (defconst pr-cygwin-system
  1016. (and lpr-windows-system (getenv "OSTYPE")
  1017. (string-match "cygwin" (getenv "OSTYPE"))))
  1018. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1019. ;; To avoid compilation gripes
  1020. ;; Emacs has this since at least 21.1.
  1021. (when (featurep 'xemacs)
  1022. (or (fboundp 'subst-char-in-string) ; hacked from subr.el
  1023. (defun subst-char-in-string (fromchar tochar string &optional inplace)
  1024. "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
  1025. Unless optional argument INPLACE is non-nil, return a new string."
  1026. (let ((i (length string))
  1027. (newstr (if inplace string (copy-sequence string))))
  1028. (while (> (setq i (1- i)) 0)
  1029. (if (eq (aref newstr i) fromchar)
  1030. (aset newstr i tochar)))
  1031. newstr))))
  1032. ;; Emacs has this since at least 21.1, but the SUFFIX argument
  1033. ;; (which this file uses) only since 22.1. So the fboundp test
  1034. ;; wasn't even correct/adequate. Whatever, no-one is using
  1035. ;; this file on older Emacs version, so it's irrelevant.
  1036. (when (featurep 'xemacs)
  1037. (or (fboundp 'make-temp-file) ; hacked from subr.el
  1038. (defun make-temp-file (prefix &optional dir-flag suffix)
  1039. "Create a temporary file.
  1040. The returned file name (created by appending some random characters at the end
  1041. of PREFIX, and expanding against `temporary-file-directory' if necessary),
  1042. is guaranteed to point to a newly created empty file.
  1043. You can then use `write-region' to write new data into the file.
  1044. If DIR-FLAG is non-nil, create a new empty directory instead of a file.
  1045. If SUFFIX is non-nil, add that at the end of the file name."
  1046. (let ((umask (default-file-modes))
  1047. file)
  1048. (unwind-protect
  1049. (progn
  1050. ;; Create temp files with strict access rights. It's easy to
  1051. ;; loosen them later, whereas it's impossible to close the
  1052. ;; time-window of loose permissions otherwise.
  1053. (set-default-file-modes ?\700)
  1054. (while (condition-case ()
  1055. (progn
  1056. (setq file
  1057. (make-temp-name
  1058. (expand-file-name prefix temporary-file-directory)))
  1059. (if suffix
  1060. (setq file (concat file suffix)))
  1061. (if dir-flag
  1062. (make-directory file)
  1063. (write-region "" nil file nil 'silent nil 'excl))
  1064. nil)
  1065. (file-already-exists t))
  1066. ;; the file was somehow created by someone else between
  1067. ;; `make-temp-name' and `write-region', let's try again.
  1068. nil)
  1069. file)
  1070. ;; Reset the umask.
  1071. (set-default-file-modes umask))))))
  1072. (eval-when-compile
  1073. ;; User Interface --- declared here to avoid compiler warnings
  1074. (defvar pr-path-style)
  1075. (defvar pr-auto-region)
  1076. (defvar pr-menu-char-height)
  1077. (defvar pr-menu-char-width)
  1078. (defvar pr-menu-lock)
  1079. (defvar pr-ps-printer-alist)
  1080. (defvar pr-txt-printer-alist)
  1081. (defvar pr-ps-utility-alist)
  1082. ;; Internal fun alias to avoid compilation gripes
  1083. (defalias 'pr-menu-lookup 'ignore)
  1084. (defalias 'pr-menu-lock 'ignore)
  1085. (defalias 'pr-menu-alist 'ignore)
  1086. (defalias 'pr-even-or-odd-pages 'ignore)
  1087. (defalias 'pr-menu-get-item 'ignore)
  1088. (defalias 'pr-menu-set-item-name 'ignore)
  1089. (defalias 'pr-menu-set-utility-title 'ignore)
  1090. (defalias 'pr-menu-set-ps-title 'ignore)
  1091. (defalias 'pr-menu-set-txt-title 'ignore)
  1092. (defalias 'pr-region-active-p 'ignore)
  1093. (defalias 'pr-do-update-menus 'ignore)
  1094. (defalias 'pr-update-mode-line 'ignore)
  1095. (defalias 'pr-read-string 'ignore)
  1096. (defalias 'pr-set-keymap-parents 'ignore)
  1097. (defalias 'pr-keep-region-active 'ignore))
  1098. ;; Internal Vars --- defined here to avoid compiler warnings
  1099. (defvar pr-menu-print-item "print"
  1100. "Non-nil means that menu binding was not done.
  1101. Used by `pr-menu-bind' and `pr-update-menus'.")
  1102. (defvar pr-ps-printer-menu-modified t
  1103. "Non-nil means `pr-ps-printer-alist' was modified and we need to update menu.")
  1104. (defvar pr-txt-printer-menu-modified t
  1105. "Non-nil means `pr-txt-printer-alist' was modified and we need to update menu.")
  1106. (defvar pr-ps-utility-menu-modified t
  1107. "Non-nil means `pr-ps-utility-alist' was modified and we need to update menu.")
  1108. (defconst pr-even-or-odd-alist
  1109. '((nil . "Print All Pages")
  1110. (even-page . "Print Even Pages")
  1111. (odd-page . "Print Odd Pages")
  1112. (even-sheet . "Print Even Sheets")
  1113. (odd-sheet . "Print Odd Sheets")))
  1114. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1115. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1116. ;; XEmacs Definitions
  1117. (cond
  1118. ((featurep 'xemacs) ; XEmacs
  1119. ;; XEmacs
  1120. (defalias 'pr-set-keymap-parents 'set-keymap-parents)
  1121. (defalias 'pr-set-keymap-name 'set-keymap-name)
  1122. ;; XEmacs
  1123. (defun pr-read-string (prompt initial history default)
  1124. (let ((str (read-string prompt initial)))
  1125. (if (and str (not (string= str "")))
  1126. str
  1127. default)))
  1128. ;; XEmacs
  1129. (defvar zmacs-region-stays nil)
  1130. ;; XEmacs
  1131. (defun pr-keep-region-active ()
  1132. (setq zmacs-region-stays t))
  1133. ;; XEmacs
  1134. (defun pr-region-active-p ()
  1135. (and pr-auto-region (not zmacs-region-stays) (ps-mark-active-p)))
  1136. ;; XEmacs
  1137. (defun pr-menu-char-height ()
  1138. (font-height (face-font 'default)))
  1139. ;; XEmacs
  1140. (defun pr-menu-char-width ()
  1141. (font-width (face-font 'default)))
  1142. ;; XEmacs
  1143. (defmacro pr-xemacs-global-menubar (&rest body)
  1144. `(save-excursion
  1145. (let ((temp (get-buffer-create (make-temp-name " *Temp"))))
  1146. ;; be sure to access global menubar
  1147. (set-buffer temp)
  1148. ,@body
  1149. (kill-buffer temp))))
  1150. ;; XEmacs
  1151. (defun pr-global-menubar (pr-menu-spec)
  1152. ;; Menu binding
  1153. (pr-xemacs-global-menubar
  1154. (add-submenu nil (cons "Printing" pr-menu-spec) "Apps"))
  1155. (setq pr-menu-print-item nil))
  1156. ;; XEmacs
  1157. (defvar current-mouse-event nil)
  1158. (defun pr-menu-position (entry index horizontal)
  1159. (make-event
  1160. 'button-release
  1161. (list 'button 1
  1162. 'x (- (event-x-pixel current-mouse-event) ; X
  1163. (* horizontal pr-menu-char-width))
  1164. 'y (- (event-y-pixel current-mouse-event) ; Y
  1165. (* (pr-menu-index entry index) pr-menu-char-height)))))
  1166. (defvar pr-menu-position nil)
  1167. (defvar pr-menu-state nil)
  1168. ;; XEmacs
  1169. (defvar current-menubar nil) ; to avoid compilation gripes
  1170. (defun pr-menu-lookup (path)
  1171. (car (find-menu-item current-menubar (cons "Printing" path))))
  1172. ;; XEmacs
  1173. (defun pr-menu-lock (entry index horizontal state path)
  1174. (when pr-menu-lock
  1175. (or (and pr-menu-position (eq state pr-menu-state))
  1176. (setq pr-menu-position (pr-menu-position entry index horizontal)
  1177. pr-menu-state state))
  1178. (let* ((menu (pr-menu-lookup path))
  1179. (result (get-popup-menu-response menu pr-menu-position)))
  1180. (and (misc-user-event-p result)
  1181. (funcall (event-function result)
  1182. (event-object result))))
  1183. (setq pr-menu-position nil)))
  1184. ;; XEmacs
  1185. (defalias 'pr-update-mode-line 'set-menubar-dirty-flag)
  1186. ;; XEmacs
  1187. (defvar pr-ps-name-old "PostScript Printers")
  1188. (defvar pr-txt-name-old "Text Printers")
  1189. (defvar pr-ps-utility-old "PostScript Utility")
  1190. (defvar pr-even-or-odd-old "Print All Pages")
  1191. ;; XEmacs
  1192. (defun pr-do-update-menus (&optional force)
  1193. (pr-menu-alist pr-ps-printer-alist
  1194. 'pr-ps-name
  1195. 'pr-menu-set-ps-title
  1196. '("Printing")
  1197. 'pr-ps-printer-menu-modified
  1198. force
  1199. pr-ps-name-old
  1200. 'postscript 2)
  1201. (pr-menu-alist pr-txt-printer-alist
  1202. 'pr-txt-name
  1203. 'pr-menu-set-txt-title
  1204. '("Printing")
  1205. 'pr-txt-printer-menu-modified
  1206. force
  1207. pr-txt-name-old
  1208. 'text 2)
  1209. (let ((save-var pr-ps-utility-menu-modified))
  1210. (pr-menu-alist pr-ps-utility-alist
  1211. 'pr-ps-utility
  1212. 'pr-menu-set-utility-title
  1213. '("Printing" "PostScript Print" "File")
  1214. 'save-var
  1215. force
  1216. pr-ps-utility-old
  1217. nil 1))
  1218. (pr-menu-alist pr-ps-utility-alist
  1219. 'pr-ps-utility
  1220. 'pr-menu-set-utility-title
  1221. '("Printing" "PostScript Preview" "File")
  1222. 'pr-ps-utility-menu-modified
  1223. force
  1224. pr-ps-utility-old
  1225. nil 1)
  1226. (pr-even-or-odd-pages ps-even-or-odd-pages force))
  1227. ;; XEmacs
  1228. (defun pr-menu-alist (alist var-sym fun menu-path modified-sym force name
  1229. entry index)
  1230. (when (and alist (or force (symbol-value modified-sym)))
  1231. (pr-xemacs-global-menubar
  1232. (add-submenu menu-path
  1233. (pr-menu-create name alist var-sym
  1234. fun entry index)))
  1235. (funcall fun (symbol-value var-sym))
  1236. (set modified-sym nil)))
  1237. ;; XEmacs
  1238. (defun pr-relabel-menu-item (newname var-sym)
  1239. (pr-xemacs-global-menubar
  1240. (relabel-menu-item
  1241. (list "Printing" (symbol-value var-sym))
  1242. newname)
  1243. (set var-sym newname)))
  1244. ;; XEmacs
  1245. (defun pr-menu-set-ps-title (value &optional item entry index)
  1246. (pr-relabel-menu-item (format "PostScript Printer: %s" value)
  1247. 'pr-ps-name-old)
  1248. (pr-ps-set-printer value)
  1249. (and index
  1250. (pr-menu-lock entry index 12 'toggle nil)))
  1251. ;; XEmacs
  1252. (defun pr-menu-set-txt-title (value &optional item entry index)
  1253. (pr-relabel-menu-item (format "Text Printer: %s" value)
  1254. 'pr-txt-name-old)
  1255. (pr-txt-set-printer value)
  1256. (and index
  1257. (pr-menu-lock entry index 12 'toggle nil)))
  1258. ;; XEmacs
  1259. (defun pr-menu-set-utility-title (value &optional item entry index)
  1260. (pr-xemacs-global-menubar
  1261. (let ((newname (format "%s" value)))
  1262. (relabel-menu-item
  1263. (list "Printing" "PostScript Print" "File" pr-ps-utility-old)
  1264. newname)
  1265. (relabel-menu-item
  1266. (list "Printing" "PostScript Preview" "File" pr-ps-utility-old)
  1267. newname)
  1268. (setq pr-ps-utility-old newname)))
  1269. (pr-ps-set-utility value)
  1270. (and index
  1271. (pr-menu-lock entry index 5 nil '("PostScript Print" "File"))))
  1272. ;; XEmacs
  1273. (defun pr-even-or-odd-pages (value &optional no-lock)
  1274. (pr-relabel-menu-item (cdr (assq value pr-even-or-odd-alist))
  1275. 'pr-even-or-odd-old)
  1276. (setq ps-even-or-odd-pages value)
  1277. (or no-lock
  1278. (pr-menu-lock 'postscript-options 8 12 'toggle nil)))
  1279. )
  1280. (t ; GNU Emacs
  1281. ;; Do nothing
  1282. )) ; end cond featurep
  1283. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1284. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1285. ;; GNU Emacs Definitions
  1286. (eval-and-compile
  1287. (unless (featurep 'xemacs)
  1288. (defvar pr-menu-bar nil
  1289. "Specify Printing menu-bar entry.")))
  1290. (cond
  1291. ((featurep 'xemacs) ; XEmacs
  1292. ;; Do nothing
  1293. )
  1294. (t ; GNU Emacs
  1295. ;; GNU Emacs
  1296. (defalias 'pr-set-keymap-parents 'set-keymap-parent)
  1297. (defalias 'pr-set-keymap-name 'ignore)
  1298. (defalias 'pr-read-string 'read-string)
  1299. ;; GNU Emacs
  1300. (defvar deactivate-mark)
  1301. ;; GNU Emacs
  1302. (defun pr-keep-region-active ()
  1303. (setq deactivate-mark nil))
  1304. ;; GNU Emacs
  1305. (defun pr-region-active-p ()
  1306. (and pr-auto-region transient-mark-mode mark-active))
  1307. ;; GNU Emacs
  1308. (defun pr-menu-char-height ()
  1309. (frame-char-height))
  1310. ;; GNU Emacs
  1311. (defun pr-menu-char-width ()
  1312. (frame-char-width))
  1313. ;; GNU Emacs
  1314. ;; Menu binding
  1315. ;; Replace existing "print" item by "Printing" item.
  1316. ;; If you're changing this file, you'll load it a second,
  1317. ;; third... time, but "print" item exists only in the first load.
  1318. (eval-when-compile
  1319. (require 'easymenu)) ; to avoid compilation gripes
  1320. (declare-function easy-menu-add-item "easymenu"
  1321. (map path item &optional before))
  1322. (declare-function easy-menu-remove-item "easymenu" (map path name))
  1323. (eval-and-compile
  1324. (defun pr-global-menubar (pr-menu-spec)
  1325. (require 'easymenu)
  1326. (let ((menu-file (if (= emacs-major-version 21)
  1327. '("menu-bar" "files") ; GNU Emacs 21
  1328. '("menu-bar" "file")))) ; GNU Emacs 22 or higher
  1329. (cond
  1330. (pr-menu-print-item
  1331. (easy-menu-add-item global-map menu-file
  1332. (easy-menu-create-menu "Print" pr-menu-spec)
  1333. "print-buffer")
  1334. (dolist (item '("print-buffer" "print-region"
  1335. "ps-print-buffer-faces" "ps-print-region-faces"
  1336. "ps-print-buffer" "ps-print-region"))
  1337. (easy-menu-remove-item global-map menu-file item))
  1338. (setq pr-menu-print-item nil
  1339. pr-menu-bar (vector 'menu-bar
  1340. (pr-get-symbol (nth 1 menu-file))
  1341. (pr-get-symbol "Print"))))
  1342. (t
  1343. (easy-menu-add-item global-map menu-file
  1344. (easy-menu-create-menu "Print" pr-menu-spec)))
  1345. ))))
  1346. (eval-and-compile
  1347. (cond
  1348. (lpr-windows-system
  1349. ;; GNU Emacs for Windows 9x/NT
  1350. (defun pr-menu-position (entry index horizontal)
  1351. (let ((pos (cdr (mouse-pixel-position))))
  1352. (list
  1353. (list (or (car pos) 0) ; X
  1354. (- (or (cdr pos) 0) ; Y
  1355. (* (pr-menu-index entry index) pr-menu-char-height)))
  1356. (selected-frame)))) ; frame
  1357. )
  1358. (t
  1359. ;; GNU Emacs
  1360. (defun pr-menu-position (entry index horizontal)
  1361. (let ((pos (cdr (mouse-pixel-position))))
  1362. (list
  1363. (list (- (or (car pos) 0) ; X
  1364. (* horizontal pr-menu-char-width))
  1365. (- (or (cdr pos) 0) ; Y
  1366. (* (pr-menu-index entry index) pr-menu-char-height)))
  1367. (selected-frame)))) ; frame
  1368. )))
  1369. (defvar pr-menu-position nil)
  1370. (defvar pr-menu-state nil)
  1371. ;; GNU Emacs
  1372. (defun pr-menu-lookup (path)
  1373. (lookup-key global-map
  1374. (if path
  1375. (vconcat pr-menu-bar
  1376. (mapcar 'pr-get-symbol
  1377. (if (listp path)
  1378. path
  1379. (list path))))
  1380. pr-menu-bar)))
  1381. ;; GNU Emacs
  1382. (defun pr-menu-lock (entry index horizontal state path)
  1383. (when pr-menu-lock
  1384. (or (and pr-menu-position (eq state pr-menu-state))
  1385. (setq pr-menu-position (pr-menu-position entry index horizontal)
  1386. pr-menu-state state))
  1387. (let* ((menu (pr-menu-lookup path))
  1388. (result (x-popup-menu pr-menu-position menu)))
  1389. (and result
  1390. (let ((command (lookup-key menu (vconcat result))))
  1391. (if (fboundp command)
  1392. (funcall command)
  1393. (eval command)))))
  1394. (setq pr-menu-position nil)))
  1395. ;; GNU Emacs
  1396. (defalias 'pr-update-mode-line 'force-mode-line-update)
  1397. ;; GNU Emacs
  1398. (defun pr-do-update-menus (&optional force)
  1399. (pr-menu-alist pr-ps-printer-alist
  1400. 'pr-ps-name
  1401. 'pr-menu-set-ps-title
  1402. "PostScript Printers"
  1403. 'pr-ps-printer-menu-modified
  1404. force
  1405. "PostScript Printers"
  1406. 'postscript 2)
  1407. (pr-menu-alist pr-txt-printer-alist
  1408. 'pr-txt-name
  1409. 'pr-menu-set-txt-title
  1410. "Text Printers"
  1411. 'pr-txt-printer-menu-modified
  1412. force
  1413. "Text Printers"
  1414. 'text 2)
  1415. (let ((save-var pr-ps-utility-menu-modified))
  1416. (pr-menu-alist pr-ps-utility-alist
  1417. 'pr-ps-utility
  1418. 'pr-menu-set-utility-title
  1419. '("PostScript Print" "File" "PostScript Utility")
  1420. 'save-var
  1421. force
  1422. "PostScript Utility"
  1423. nil 1))
  1424. (pr-menu-alist pr-ps-utility-alist
  1425. 'pr-ps-utility
  1426. 'pr-menu-set-utility-title
  1427. '("PostScript Preview" "File" "PostScript Utility")
  1428. 'pr-ps-utility-menu-modified
  1429. force
  1430. "PostScript Utility"
  1431. nil 1)
  1432. (pr-even-or-odd-pages ps-even-or-odd-pages force))
  1433. ;; GNU Emacs
  1434. (defun pr-menu-get-item (name-list)
  1435. ;; NAME-LIST is a string or a list of strings.
  1436. (or (listp name-list)
  1437. (setq name-list (list name-list)))
  1438. (and name-list
  1439. (let* ((reversed (reverse name-list))
  1440. (name (pr-get-symbol (car reversed)))
  1441. (path (nreverse (cdr reversed)))
  1442. (menu (lookup-key
  1443. global-map
  1444. (vconcat pr-menu-bar
  1445. (mapcar 'pr-get-symbol path)))))
  1446. (assq name (nthcdr 2 menu)))))
  1447. ;; GNU Emacs
  1448. (defvar pr-temp-menu nil)
  1449. ;; GNU Emacs
  1450. (defun pr-menu-alist (alist var-sym fun menu-path modified-sym force name
  1451. entry index)
  1452. (when (and alist (or force (symbol-value modified-sym)))
  1453. (easy-menu-define pr-temp-menu nil ""
  1454. (pr-menu-create name alist var-sym fun entry index))
  1455. (let ((item (pr-menu-get-item menu-path)))
  1456. (and item
  1457. (let* ((binding (nthcdr 3 item))
  1458. (key-binding (cdr binding)))
  1459. (setcar binding pr-temp-menu)
  1460. (and key-binding (listp (car key-binding))
  1461. (setcdr binding (cdr key-binding))) ; skip KEY-BINDING
  1462. (funcall fun (symbol-value var-sym) item))))
  1463. (set modified-sym nil)))
  1464. ;; GNU Emacs
  1465. (defun pr-menu-set-item-name (item name)
  1466. (and item
  1467. (setcar (nthcdr 2 item) name))) ; ITEM-NAME
  1468. ;; GNU Emacs
  1469. (defun pr-menu-set-ps-title (value &optional item entry index)
  1470. (pr-menu-set-item-name (or item
  1471. (pr-menu-get-item "PostScript Printers"))
  1472. (format "PostScript Printer: %s" value))
  1473. (pr-ps-set-printer value)
  1474. (and index
  1475. (pr-menu-lock entry index 12 'toggle nil)))
  1476. ;; GNU Emacs
  1477. (defun pr-menu-set-txt-title (value &optional item entry index)
  1478. (pr-menu-set-item-name (or item
  1479. (pr-menu-get-item "Text Printers"))
  1480. (format "Text Printer: %s" value))
  1481. (pr-txt-set-printer value)
  1482. (and index
  1483. (pr-menu-lock entry index 12 'toggle nil)))
  1484. ;; GNU Emacs
  1485. (defun pr-menu-set-utility-title (value &optional item entry index)
  1486. (let ((name (symbol-name value)))
  1487. (if item
  1488. (pr-menu-set-item-name item name)
  1489. (pr-menu-set-item-name
  1490. (pr-menu-get-item
  1491. '("PostScript Print" "File" "PostScript Utility"))
  1492. name)
  1493. (pr-menu-set-item-name
  1494. (pr-menu-get-item
  1495. '("PostScript Preview" "File" "PostScript Utility"))
  1496. name)))
  1497. (pr-ps-set-utility value)
  1498. (and index
  1499. (pr-menu-lock entry index 5 nil '("PostScript Print" "File"))))
  1500. ;; GNU Emacs
  1501. (defun pr-even-or-odd-pages (value &optional no-lock)
  1502. (pr-menu-set-item-name (pr-menu-get-item "Print All Pages")
  1503. (cdr (assq value pr-even-or-odd-alist)))
  1504. (setq ps-even-or-odd-pages value)
  1505. (or no-lock
  1506. (pr-menu-lock 'postscript-options 8 12 'toggle nil)))
  1507. )) ; end cond featurep
  1508. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1509. ;; Internal Functions (I)
  1510. (defun pr-dosify-file-name (path)
  1511. "Replace unix-style directory separator character with dos/windows one."
  1512. (interactive "sPath: ")
  1513. (if (eq pr-path-style 'windows)
  1514. (subst-char-in-string ?/ ?\\ path)
  1515. path))
  1516. (defun pr-unixify-file-name (path)
  1517. "Replace dos/windows-style directory separator character with unix one."
  1518. (interactive "sPath: ")
  1519. (if (eq pr-path-style 'windows)
  1520. (subst-char-in-string ?\\ ?/ path)
  1521. path))
  1522. (defun pr-standard-file-name (path)
  1523. "Ensure the proper directory separator depending on the OS.
  1524. That is, if Emacs is running on DOS/Windows, ensure dos/windows-style directory
  1525. separator; otherwise, ensure unix-style directory separator."
  1526. (if (or pr-cygwin-system lpr-windows-system)
  1527. (subst-char-in-string ?/ ?\\ path)
  1528. (subst-char-in-string ?\\ ?/ path)))
  1529. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1530. ;; Customization Functions
  1531. (defun pr-alist-custom-set (symbol value)
  1532. "Set the value of custom variables for printer & utility selection."
  1533. (set symbol value)
  1534. (and (featurep 'printing) ; update only after printing is loaded
  1535. (pr-update-menus t)))
  1536. (defun pr-ps-utility-custom-set (symbol value)
  1537. "Update utility menu entry."
  1538. (set symbol value)
  1539. (and (featurep 'printing) ; update only after printing is loaded
  1540. (pr-menu-set-utility-title value)))
  1541. (defun pr-ps-name-custom-set (symbol value)
  1542. "Update `PostScript Printer:' menu entry."
  1543. (set symbol value)
  1544. (and (featurep 'printing) ; update only after printing is loaded
  1545. (pr-menu-set-ps-title value)))
  1546. (defun pr-txt-name-custom-set (symbol value)
  1547. "Update `Text Printer:' menu entry."
  1548. (set symbol value)
  1549. (and (featurep 'printing) ; update only after printing is loaded
  1550. (pr-menu-set-txt-title value)))
  1551. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1552. ;; User Interface
  1553. (defgroup printing nil
  1554. "Printing Utilities group."
  1555. :tag "Printing Utilities"
  1556. :link '(emacs-library-link :tag "Source Lisp File" "printing.el")
  1557. :prefix "pr-"
  1558. :version "22.1"
  1559. :group 'wp
  1560. :group 'postscript)
  1561. (defcustom pr-path-style
  1562. (if (and (not pr-cygwin-system)
  1563. lpr-windows-system)
  1564. 'windows
  1565. 'unix)
  1566. "Specify which path style to use for external commands.
  1567. Valid values are:
  1568. windows Windows 9x/NT style (\\)
  1569. unix Unix style (/)"
  1570. :type '(choice :tag "Path style"
  1571. (const :tag "Windows 9x/NT Style (\\)" :value windows)
  1572. (const :tag "Unix Style (/)" :value unix))
  1573. :group 'printing)
  1574. (defcustom pr-path-alist
  1575. '((unix PATH)
  1576. (cygwin PATH)
  1577. (windows PATH))
  1578. "Specify an alist for command paths.
  1579. It's used to find commands used for printing package, like gv, gs, gsview.exe,
  1580. mpage, print.exe, etc. See also `pr-command' function.
  1581. Each element has the form:
  1582. (ENTRY DIRECTORY...)
  1583. Where:
  1584. ENTRY It's a symbol, used to identify this entry.
  1585. There must exist at least one of the following entries:
  1586. unix this entry is used when Emacs is running on GNU or
  1587. Unix system.
  1588. cygwin this entry is used when Emacs is running on Windows
  1589. 95/98/NT/2000 with Cygwin.
  1590. windows this entry is used when Emacs is running on Windows
  1591. 95/98/NT/2000.
  1592. DIRECTORY It should be a string or a symbol. If it's a symbol, it should
  1593. exist an equal entry in `pr-path-alist'. If it's a string,
  1594. it's considered a directory specification.
  1595. The directory specification may contain:
  1596. $var environment variable expansion
  1597. ~/ tilde expansion
  1598. ./ current directory
  1599. ../ previous directory
  1600. For example, let's say the home directory is /home/my and the
  1601. current directory is /home/my/dir, so:
  1602. THE ENTRY IS EXPANDED TO
  1603. ~/entry /home/my/entry
  1604. ./entry /home/my/dir/entry
  1605. ../entry /home/my/entry
  1606. $HOME/entry /home/my/entry
  1607. $HOME/~/other/../my/entry /home/my/entry
  1608. SPECIAL SYMBOL: If the symbol `PATH' is used in the directory
  1609. list and there isn't a `PATH' entry in `pr-path-alist' or the
  1610. `PATH' entry has a null directory list, the PATH environment
  1611. variable is used.
  1612. Examples:
  1613. * On GNU or Unix system:
  1614. ((unix \".\" \"~/bin\" ghostview mpage PATH)
  1615. (ghostview \"$HOME/bin/gsview-dir\")
  1616. (mpage \"$HOME/bin/mpage-dir\")
  1617. )
  1618. * On Windows system:
  1619. ((windows \"c:/applications/executables\" PATH ghostview mpage)
  1620. (ghostview \"c:/gs/gsview-dir\")
  1621. (mpage \"c:/mpage-dir\")
  1622. )"
  1623. :type '(repeat
  1624. (cons :tag ""
  1625. (symbol :tag "Identifier ")
  1626. (repeat :tag "Directory List"
  1627. (choice :menu-tag "Directory"
  1628. :tag "Directory"
  1629. (string :value "")
  1630. (symbol :value symbol)))))
  1631. :group 'printing)
  1632. (defcustom pr-txt-name 'default
  1633. "Specify a printer for printing a text file.
  1634. The printer name symbol should be defined on `pr-txt-printer-alist' (see it for
  1635. documentation).
  1636. This variable should be modified by customization engine. If this variable is
  1637. modified by other means (for example, a lisp function), use `pr-update-menus'
  1638. function (see it for documentation) to update text printer menu."
  1639. :type 'symbol
  1640. :set 'pr-txt-name-custom-set
  1641. :group 'printing)
  1642. (defcustom pr-txt-printer-alist
  1643. (list (list 'default lpr-command nil
  1644. (cond ((boundp 'printer-name) printer-name)
  1645. (lpr-windows-system "PRN")
  1646. (t nil)
  1647. )))
  1648. ;; Examples:
  1649. ;; * On GNU or Unix system:
  1650. ;; '((prt_06a "lpr" nil "prt_06a")
  1651. ;; (prt_07c nil nil "prt_07c")
  1652. ;; )
  1653. ;; * On Windows system:
  1654. ;; '((prt_06a "print" nil "/D:\\\\printers\\prt_06a")
  1655. ;; (prt_07c nil nil "/D:\\\\printers\\prt_07c")
  1656. ;; (PRN "" nil "PRN")
  1657. ;; (standard "redpr.exe" nil "")
  1658. ;; )
  1659. "Specify an alist of all text printers (text printer database).
  1660. The alist element has the form:
  1661. (SYMBOL COMMAND SWITCHES NAME)
  1662. Where:
  1663. SYMBOL It's a symbol to identify a text printer. It's for
  1664. setting option `pr-txt-name' and for menu selection.
  1665. Examples:
  1666. prt_06a
  1667. my_printer
  1668. COMMAND Name of the program for printing a text file. On MS-DOS and
  1669. MS-Windows systems, if the value is an empty string, then Emacs
  1670. will write directly to the printer port given by NAME (see text
  1671. below), that is, the NAME should be something like \"PRN\" or
  1672. \"LPT1:\".
  1673. If NAME is something like \"\\\\\\\\host\\\\share-name\" then
  1674. COMMAND shouldn't be an empty string.
  1675. The programs `print' and `nprint' (the standard print programs
  1676. on Windows NT and Novell Netware respectively) are handled
  1677. specially, using NAME as the destination for output; any other
  1678. program is treated like `lpr' except that an explicit filename
  1679. is given as the last argument.
  1680. If COMMAND is nil, it's used the default printing program:
  1681. `print' for Windows system, `lp' for lp system and `lpr' for
  1682. all other systems. See also `pr-path-alist'.
  1683. Examples:
  1684. \"print\"
  1685. \"lpr\"
  1686. \"lp\"
  1687. SWITCHES List of sexp's to pass as extra options for text printer
  1688. program. It is recommended to set NAME (see text below)
  1689. instead of including an explicit switch on this list.
  1690. Example:
  1691. . for lpr
  1692. (\"-#3\" \"-l\")
  1693. nil
  1694. NAME A string that specifies a text printer name.
  1695. On Unix-like systems, a string value should be a name
  1696. understood by lpr's -P option (or lp's -d option).
  1697. On MS-DOS and MS-Windows systems, it is the name of a printer
  1698. device or port. Typical non-default settings would be \"LPT1:\"
  1699. to \"LPT3:\" for parallel printers, or \"COM1\" to \"COM4\" or
  1700. \"AUX\" for serial printers, or \"\\\\\\\\hostname\\\\printer\"
  1701. (or \"/D:\\\\\\\\hostname\\\\printer\") for a shared network
  1702. printer. You can also set it to a name of a file, in which
  1703. case the output gets appended to that file. If you want to
  1704. discard the printed output, set this to \"NUL\".
  1705. Examples:
  1706. . for print.exe
  1707. \"/D:\\\\\\\\host\\\\share-name\"
  1708. \"LPT1:\"
  1709. \"PRN\"
  1710. . for lpr or lp
  1711. \"share-name\"
  1712. This variable should be modified by customization engine. If this variable is
  1713. modified by other means (for example, a lisp function), use `pr-update-menus'
  1714. function (see it for documentation) to update text printer menu.
  1715. Examples:
  1716. * On GNU or Unix system:
  1717. ((prt_06a \"lpr\" nil \"prt_06a\")
  1718. (prt_07c nil nil \"prt_07c\")
  1719. )
  1720. * On Windows system:
  1721. ((prt_06a \"print\" nil \"/D:\\\\\\\\printers\\\\prt_06a\")
  1722. (prt_07c nil nil \"/D:\\\\\\\\printers\\\\prt_07c\")
  1723. (PRN \"\" nil \"PRN\")
  1724. (standard \"redpr.exe\" nil \"\")
  1725. )
  1726. Useful links:
  1727. * Information about the print command (print.exe)
  1728. `http://www.computerhope.com/printhlp.htm'
  1729. * RedMon - Redirection Port Monitor (redpr.exe)
  1730. `http://www.cs.wisc.edu/~ghost/redmon/index.htm'
  1731. * Redirection Port Monitor (redpr.exe on-line help)
  1732. `http://www.cs.wisc.edu/~ghost/redmon/en/redmon.htm'
  1733. * UNIX man pages: lpr (or type `man lpr')
  1734. `http://bama.ua.edu/cgi-bin/man-cgi?lpr'
  1735. `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lpr'
  1736. * UNIX man pages: lp (or type `man lp')
  1737. `http://bama.ua.edu/cgi-bin/man-cgi?lp'
  1738. `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lp'
  1739. "
  1740. :type '(repeat
  1741. (list :tag "Text Printer"
  1742. (symbol :tag "Printer Symbol Name")
  1743. (string :tag "Printer Command")
  1744. (repeat :tag "Printer Switches"
  1745. (sexp :tag "Switch" :value ""))
  1746. (choice :menu-tag "Printer Name"
  1747. :tag "Printer Name"
  1748. (const :tag "None" nil)
  1749. string)))
  1750. :set 'pr-alist-custom-set
  1751. :group 'printing)
  1752. (defcustom pr-ps-name 'default
  1753. "Specify a printer for printing a PostScript file.
  1754. This printer name symbol should be defined on `pr-ps-printer-alist' (see it for
  1755. documentation).
  1756. This variable should be modified by customization engine. If this variable is
  1757. modified by other means (for example, a lisp function), use `pr-update-menus'
  1758. function (see it for documentation) to update PostScript printer menu."
  1759. :type 'symbol
  1760. :set 'pr-ps-name-custom-set
  1761. :group 'printing)
  1762. (defcustom pr-ps-printer-alist
  1763. (list (list 'default lpr-command nil
  1764. (cond (lpr-windows-system nil)
  1765. (lpr-lp-system "-d")
  1766. (t "-P"))
  1767. (or (getenv "PRINTER") (getenv "LPDEST") ps-printer-name)))
  1768. ;; Examples:
  1769. ;; * On GNU or Unix system:
  1770. ;; '((lps_06b "lpr" nil "-P" "lps_06b")
  1771. ;; (lps_07c "lpr" nil nil "lps_07c")
  1772. ;; (lps_08c nil nil nil "lps_08c")
  1773. ;; )
  1774. ;; * On Windows system:
  1775. ;; '((lps_06a "print" nil "/D:" "\\\\printers\\lps_06a")
  1776. ;; (lps_06b "print" nil nil "\\\\printers\\lps_06b")
  1777. ;; (lps_07c "print" nil "" "/D:\\\\printers\\lps_07c")
  1778. ;; (lps_08c nil nil nil "\\\\printers\\lps_08c")
  1779. ;; (b/w "gsprint" ("-all" "-twoup") "-printer " "b/w-pr-name")
  1780. ;; (LPT1 "" nil "" "LPT1:")
  1781. ;; (PRN "" nil "" "PRN")
  1782. ;; (standard "redpr.exe" nil "" "")
  1783. ;; )
  1784. "Specify an alist for all PostScript printers (PostScript printer database).
  1785. The alist element has the form:
  1786. (SYMBOL COMMAND SWITCHES PRINTER-SWITCH NAME DEFAULT...)
  1787. Where:
  1788. SYMBOL It's a symbol to identify a PostScript printer. It's for
  1789. setting option `pr-ps-name' and for menu selection.
  1790. Examples:
  1791. prt_06a
  1792. my_printer
  1793. COMMAND Name of the program for printing a PostScript file. On MS-DOS
  1794. and MS-Windows systems, if the value is an empty string then
  1795. Emacs will write directly to the printer port given by NAME
  1796. (see text below), that is, the NAME should be something like
  1797. \"PRN\" or \"LPT1:\".
  1798. If NAME is something like \"\\\\\\\\host\\\\share-name\" then
  1799. COMMAND shouldn't be an empty string.
  1800. The programs `print' and `nprint' (the standard print programs
  1801. on Windows NT and Novell Netware respectively) are handled
  1802. specially, using NAME as the destination for output; any other
  1803. program is treated like `lpr' except that an explicit filename
  1804. is given as the last argument.
  1805. If COMMAND is nil, it's used the default printing program:
  1806. `print' for Windows system, `lp' for lp system and `lpr' for
  1807. all other systems. See also `pr-path-alist'.
  1808. Examples:
  1809. \"print\"
  1810. \"lpr\"
  1811. \"lp\"
  1812. \"cp\"
  1813. \"gsprint\"
  1814. SWITCHES List of sexp's to pass as extra options for PostScript printer
  1815. program. It is recommended to set NAME (see text below)
  1816. instead of including an explicit switch on this list.
  1817. Example:
  1818. . for lpr
  1819. (\"-#3\" \"-l\")
  1820. nil
  1821. . for gsprint.exe
  1822. (\"-all\" \"-twoup\")
  1823. PRINTER-SWITCH A string that specifies PostScript printer name switch. If
  1824. it's necessary to have a space between PRINTER-SWITCH and NAME,
  1825. it should be inserted at the end of PRINTER-SWITCH string.
  1826. If PRINTER-SWITCH is nil, it's used the default printer name
  1827. switch: `/D:' for Windows system, `-d' for lp system and `-P'
  1828. for all other systems.
  1829. Examples:
  1830. . for lpr
  1831. \"-P \"
  1832. . for lp
  1833. \"-d \"
  1834. . for print.exe
  1835. \"/D:\"
  1836. . for gsprint.exe
  1837. \"-printer \"
  1838. NAME A string that specifies a PostScript printer name.
  1839. On Unix-like systems, a string value should be a name
  1840. understood by lpr's -P option (or lp's -d option).
  1841. On MS-DOS and MS-Windows systems, it is the name of a printer
  1842. device or port. Typical non-default settings would be \"LPT1:\"
  1843. to \"LPT3:\" for parallel printers, or \"COM1\" to \"COM4\" or
  1844. \"AUX\" for serial printers, or \"\\\\\\\\hostname\\\\printer\"
  1845. (or \"/D:\\\\\\\\hostname\\\\printer\") for a shared network
  1846. printer. You can also set it to a name of a file, in which
  1847. case the output gets appended to that file. If you want to
  1848. discard the printed output, set this to \"NUL\".
  1849. Examples:
  1850. . for cp.exe
  1851. \"\\\\\\\\host\\\\share-name\"
  1852. . for print.exe or gsprint.exe
  1853. \"/D:\\\\\\\\host\\\\share-name\"
  1854. \"\\\\\\\\host\\\\share-name\"
  1855. \"LPT1:\"
  1856. \"PRN\"
  1857. . for lpr or lp
  1858. \"share-name\"
  1859. DEFAULT It's a way to set default values when this entry is selected.
  1860. It's a cons like:
  1861. (VARIABLE . VALUE)
  1862. Which associates VARIABLE with VALUE. When this entry is
  1863. selected, it's executed the following command:
  1864. (set VARIABLE (eval VALUE))
  1865. Note that VALUE can be any valid lisp expression. So, don't
  1866. forget to quote symbols and constant lists.
  1867. If VARIABLE is the special keyword `inherits-from:', VALUE must
  1868. be a symbol name setting defined in `pr-setting-database' from
  1869. which the current setting inherits the context. Take care with
  1870. circular inheritance.
  1871. Examples:
  1872. (ps-landscape-mode . nil)
  1873. (ps-spool-duplex . t)
  1874. (pr-gs-device . (my-gs-device t))
  1875. This variable should be modified by customization engine. If this variable is
  1876. modified by other means (for example, a lisp function), use `pr-update-menus'
  1877. function (see it for documentation) to update PostScript printer menu.
  1878. Examples:
  1879. * On GNU or Unix system:
  1880. ((lps_06b \"lpr\" nil \"-P\" \"lps_06b\")
  1881. (lps_07c \"lpr\" nil nil \"lps_07c\")
  1882. (lps_08c nil nil nil \"lps_08c\")
  1883. )
  1884. * On Windows system:
  1885. ((lps_06a \"print\" nil \"/D:\" \"\\\\\\\\printers\\\\lps_06a\")
  1886. (lps_06b \"print\" nil nil \"\\\\\\\\printers\\\\lps_06b\")
  1887. (lps_07c \"print\" nil \"\" \"/D:\\\\\\\\printers\\\\lps_07c\")
  1888. (lps_08c nil nil nil \"\\\\\\\\printers\\\\lps_08c\")
  1889. (b/w1 \"gsprint\" (\"-all\" \"-twoup\") \"-printer \" \"b/w-pr-name\")
  1890. (b/w2 \"gsprint\" (\"-all\" \"-twoup\") nil \"-printer \\\\\\\\printers\\\\lps_06a\")
  1891. (LPT1 \"\" nil \"\" \"LPT1:\")
  1892. (PRN \"\" nil \"\" \"PRN\")
  1893. (standard \"redpr.exe\" nil \"\" \"\")
  1894. )
  1895. gsprint:
  1896. You can use gsprint instead of ghostscript to print monochrome PostScript files
  1897. in Windows. The gsprint utility documentation says that it is more efficient
  1898. than ghostscript to print monochrome PostScript.
  1899. To print non-monochrome PostScript file, the efficiency of ghostscript is
  1900. similar to gsprint.
  1901. Also the gsprint utility comes together with gsview distribution.
  1902. As an example of gsprint declaration:
  1903. (setq pr-ps-printer-alist
  1904. \\='((A \"gsprint\" (\"-all\" \"-twoup\") \"-printer \" \"lps_015\")
  1905. (B \"gsprint\" (\"-all\" \"-twoup\") nil \"-printer lps_015\")
  1906. ;; some other printer declaration
  1907. ))
  1908. The example above declares that printer A prints all pages (-all) and two pages
  1909. per sheet (-twoup). The printer B declaration does the same as the printer A
  1910. declaration, the only difference is the printer name selection.
  1911. There are other command line options like:
  1912. -mono Render in monochrome as 1bit/pixel (only black and white).
  1913. -grey Render in greyscale as 8bits/pixel.
  1914. -color Render in color as 24bits/pixel.
  1915. The default is `-mono'. So, printer A and B in the example above are using
  1916. implicitly the `-mono' option. Note that in `-mono' no gray tone or color is
  1917. printed, this includes the zebra stripes, that is, in `-mono' the zebra stripes
  1918. are not printed.
  1919. Useful links:
  1920. * GSPRINT - Ghostscript print to Windows printer
  1921. `http://www.cs.wisc.edu/~ghost/gsview/gsprint.htm'
  1922. * Introduction to Ghostscript
  1923. `http://www.cs.wisc.edu/~ghost/doc/intro.htm'
  1924. * How to use Ghostscript
  1925. `http://www.cs.wisc.edu/~ghost/doc/cvs/Use.htm'
  1926. * Information about the print command (print.exe)
  1927. `http://www.computerhope.com/printhlp.htm'
  1928. * RedMon - Redirection Port Monitor (redpr.exe)
  1929. `http://www.cs.wisc.edu/~ghost/redmon/index.htm'
  1930. * Redirection Port Monitor (redpr.exe on-line help)
  1931. `http://www.cs.wisc.edu/~ghost/redmon/en/redmon.htm'
  1932. * UNIX man pages: lpr (or type `man lpr')
  1933. `http://bama.ua.edu/cgi-bin/man-cgi?lpr'
  1934. `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lpr'
  1935. * UNIX man pages: lp (or type `man lp')
  1936. `http://bama.ua.edu/cgi-bin/man-cgi?lp'
  1937. `http://www.mediacollege.com/cgi-bin/man/page.cgi?section=all&topic=lp'
  1938. * GNU utilities for w32 (cp.exe)
  1939. `http://unxutils.sourceforge.net/'
  1940. "
  1941. :type '(repeat
  1942. (list
  1943. :tag "PostScript Printer"
  1944. (symbol :tag "Printer Symbol Name")
  1945. (string :tag "Printer Command")
  1946. (repeat :tag "Printer Switches"
  1947. (sexp :tag "Switch" :value ""))
  1948. (choice :menu-tag "Printer Name Switch"
  1949. :tag "Printer Name Switch"
  1950. (const :tag "None" nil)
  1951. string)
  1952. (choice :menu-tag "Printer Name"
  1953. :tag "Printer Name"
  1954. (const :tag "None" nil)
  1955. string)
  1956. (repeat
  1957. :tag "Default Value List"
  1958. :inline t
  1959. (cons
  1960. :tag ""
  1961. (choice
  1962. :menu-tag "Variable"
  1963. :tag "Variable"
  1964. (const :tag "Landscape" ps-landscape-mode)
  1965. (const :tag "Print Header" ps-print-header)
  1966. (const :tag "Print Header Frame" ps-print-header-frame)
  1967. (const :tag "Line Number" ps-line-number)
  1968. (const :tag "Zebra Stripes" ps-zebra-stripes)
  1969. (const :tag "Duplex" ps-spool-duplex)
  1970. (const :tag "Tumble" ps-spool-tumble)
  1971. (const :tag "Upside-Down" ps-print-upside-down)
  1972. (const :tag "PS File Landscape" pr-file-landscape)
  1973. (const :tag "PS File Duplex" pr-file-duplex)
  1974. (const :tag "PS File Tumble" pr-file-tumble)
  1975. (const :tag "Auto Region" pr-auto-region)
  1976. (const :tag "Auto Mode" pr-auto-mode)
  1977. (const :tag "Ghostscript Device" pr-gs-device)
  1978. (const :tag "Ghostscript Resolution" pr-gs-resolution)
  1979. (const :tag "inherits-from:" inherits-from:)
  1980. (variable :tag "Other"))
  1981. (sexp :tag "Value")))
  1982. ))
  1983. :set 'pr-alist-custom-set
  1984. :group 'printing)
  1985. (defcustom pr-temp-dir
  1986. (pr-dosify-file-name
  1987. (if (boundp 'temporary-file-directory)
  1988. (symbol-value 'temporary-file-directory)
  1989. ;; hacked from `temporary-file-directory' variable in files.el
  1990. (file-name-as-directory
  1991. (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP")
  1992. (cond (lpr-windows-system "c:/temp")
  1993. (t "/tmp")
  1994. )))))
  1995. "Specify a directory for temporary files during printing.
  1996. See also `pr-ps-temp-file' and `pr-file-modes'."
  1997. :type '(directory :tag "Temporary Directory")
  1998. :group 'printing)
  1999. (defcustom pr-ps-temp-file "prspool-"
  2000. "Specify PostScript temporary file name prefix.
  2001. See also `pr-temp-dir' and `pr-file-modes'."
  2002. :type '(file :tag "PostScript Temporary File Name")
  2003. :group 'printing)
  2004. ;; It uses 0600 as default instead of (default-file-modes).
  2005. ;; So, by default, only the session owner have permission to deal with files
  2006. ;; generated by `printing'.
  2007. (defcustom pr-file-modes ?\600
  2008. "Specify the file permission bits for newly created files.
  2009. It should be an integer; only the low 9 bits are used.
  2010. See also `pr-temp-dir' and `pr-ps-temp-file'."
  2011. :type '(integer :tag "File Permission Bits")
  2012. :group 'printing)
  2013. (defcustom pr-gv-command
  2014. (if lpr-windows-system
  2015. "gsview32.exe"
  2016. "gv")
  2017. "Specify path and name of the gsview/gv utility.
  2018. See also `pr-path-alist'.
  2019. Useful links:
  2020. * GNU gv manual
  2021. `http://www.gnu.org/software/gv/manual/gv.html'
  2022. * GSview Help
  2023. `http://www.cs.wisc.edu/~ghost/gsview/gsviewen.htm'
  2024. * GSview Help - Common Problems
  2025. `http://www.cs.wisc.edu/~ghost/gsview/gsviewen.htm#Common_Problems'
  2026. * GSview Readme (compilation & installation)
  2027. `http://www.cs.wisc.edu/~ghost/gsview/Readme.htm'
  2028. * GSview (main site)
  2029. `http://www.cs.wisc.edu/~ghost/gsview/index.htm'
  2030. * Ghostscript, Ghostview and GSview
  2031. `http://www.cs.wisc.edu/~ghost/'
  2032. * Ghostview
  2033. `http://www.cs.wisc.edu/~ghost/gv/index.htm'
  2034. * gv 3.5, June 1997
  2035. `http://www.cs.wisc.edu/~ghost/gv/gv_doc/gv.html'
  2036. * MacGSView (MacOS)
  2037. `http://www.cs.wisc.edu/~ghost/macos/index.htm'
  2038. "
  2039. :type '(string :tag "Ghostview Utility")
  2040. :group 'printing)
  2041. (defcustom pr-gs-command
  2042. (if lpr-windows-system
  2043. "gswin32.exe"
  2044. "gs")
  2045. "Specify path and name of the ghostscript utility.
  2046. See also `pr-path-alist'.
  2047. Useful links:
  2048. * Ghostscript, Ghostview and GSview
  2049. `http://www.cs.wisc.edu/~ghost/'
  2050. * Introduction to Ghostscript
  2051. `http://www.cs.wisc.edu/~ghost/doc/intro.htm'
  2052. * How to use Ghostscript
  2053. `http://www.cs.wisc.edu/~ghost/doc/cvs/Use.htm'
  2054. * Printer compatibility
  2055. `http://www.cs.wisc.edu/~ghost/doc/printer.htm'
  2056. "
  2057. :type '(string :tag "Ghostscript Utility")
  2058. :group 'printing)
  2059. (defcustom pr-gs-switches
  2060. (if lpr-windows-system
  2061. '("-q -dNOPAUSE -Ic:/gs/gs5.50;c:/gs/gs5.50/fonts")
  2062. '("-q -dNOPAUSE -I/usr/share/ghostscript/5.10"))
  2063. "Specify ghostscript switches. See the documentation on GS for more info.
  2064. It's a list of strings, where each string is one or more ghostscript switches.
  2065. A note on the gs switches:
  2066. -q quiet
  2067. -dNOPAUSE don't wait for user intervention
  2068. -Ic:/gs/gs5.50;c:/gs/gs5.50/fonts the directories needed for gs
  2069. -c quit it's added at the end to terminate gs
  2070. To see ghostscript documentation for more information:
  2071. * On GNU or Unix system:
  2072. - for full documentation, type: man gs
  2073. - for brief documentation, type: gs -h
  2074. * On Windows system:
  2075. - for full documentation, see in a browser the file
  2076. c:/gstools/gs5.50/index.html, that is, the file index.html which is
  2077. located in the same directory as gswin32.exe.
  2078. - for brief documentation, type: gswin32.exe -h
  2079. Useful links:
  2080. * Introduction to Ghostscript
  2081. `http://www.cs.wisc.edu/~ghost/doc/intro.htm'
  2082. * How to use Ghostscript
  2083. `http://www.cs.wisc.edu/~ghost/doc/cvs/Use.htm'
  2084. * Printer compatibility
  2085. `http://www.cs.wisc.edu/~ghost/doc/printer.htm'
  2086. "
  2087. :type '(repeat (string :tag "Ghostscript Switch"))
  2088. :group 'printing)
  2089. (defcustom pr-gs-device
  2090. (if lpr-windows-system
  2091. "mswinpr2"
  2092. "uniprint")
  2093. "Specify the ghostscript device switch value (-sDEVICE=).
  2094. A note on the gs switches:
  2095. -sDEVICE=djet500 the printer - works with HP DeskJet 540
  2096. See `pr-gs-switches' for documentation.
  2097. See also `pr-ps-printer-alist'."
  2098. :type '(string :tag "Ghostscript Device")
  2099. :group 'printing)
  2100. (defcustom pr-gs-resolution 300
  2101. "Specify ghostscript resolution switch value (-r).
  2102. A note on the gs switches:
  2103. -r300 resolution 300x300
  2104. See `pr-gs-switches' for documentation.
  2105. See also `pr-ps-printer-alist'."
  2106. :type '(integer :tag "Ghostscript Resolution")
  2107. :group 'printing)
  2108. (defcustom pr-print-using-ghostscript nil
  2109. "Non-nil means print using ghostscript.
  2110. This is useful if you don't have a PostScript printer, so you could use the
  2111. ghostscript to print a PostScript file.
  2112. In GNU or Unix system, if ghostscript is set as a PostScript filter, this
  2113. variable should be nil."
  2114. :type 'boolean
  2115. :group 'printing)
  2116. (defcustom pr-faces-p nil
  2117. "Non-nil means print with face attributes."
  2118. :type 'boolean
  2119. :group 'printing)
  2120. (defcustom pr-spool-p nil
  2121. "Non-nil means spool printing in a buffer."
  2122. :type 'boolean
  2123. :group 'printing)
  2124. (defcustom pr-file-landscape nil
  2125. "Non-nil means print PostScript file in landscape orientation."
  2126. :type 'boolean
  2127. :group 'printing)
  2128. (defcustom pr-file-duplex nil
  2129. "Non-nil means print PostScript file in duplex mode."
  2130. :type 'boolean
  2131. :group 'printing)
  2132. (defcustom pr-file-tumble nil
  2133. "Non-nil means print PostScript file in tumble mode.
  2134. If tumble is off, produces a printing suitable for binding on the left or
  2135. right.
  2136. If tumble is on, produces a printing suitable for binding at the top or
  2137. bottom."
  2138. :type 'boolean
  2139. :group 'printing)
  2140. (defcustom pr-auto-region t
  2141. "Non-nil means region is automagically detected.
  2142. Note that this will only work if you're using transient mark mode.
  2143. When this variable is non-nil, the `*-buffer*' commands will behave like
  2144. `*-region*' commands, that is, `*-buffer*' commands will print only the region
  2145. marked instead of all buffer."
  2146. :type 'boolean
  2147. :group 'printing)
  2148. (defcustom pr-auto-mode t
  2149. "Non-nil means major-mode specific printing is preferred over normal printing.
  2150. That is, if current major-mode is declared in `pr-mode-alist', the `*-buffer*'
  2151. and `*-region*' commands will behave like `*-mode*' commands; otherwise,
  2152. `*-buffer*' commands will print the current buffer and `*-region*' commands
  2153. will print the current region."
  2154. :type 'boolean
  2155. :group 'printing)
  2156. (defcustom pr-mode-alist
  2157. '((mh-folder-mode ; mh summary buffer
  2158. pr-mh-lpr-1 pr-mh-print-1
  2159. 2
  2160. (ps-article-author ps-article-subject)
  2161. ("/pagenumberstring load" pr-article-date)
  2162. nil
  2163. )
  2164. (mh-letter-mode ; mh letter buffer
  2165. pr-mh-lpr-2 pr-mh-print-2
  2166. 2
  2167. (ps-article-author ps-article-subject)
  2168. ("/pagenumberstring load" pr-article-date)
  2169. nil
  2170. )
  2171. (rmail-summary-mode ; rmail summary buffer
  2172. pr-rmail-lpr pr-rmail-print
  2173. 3
  2174. (ps-article-subject ps-article-author buffer-name)
  2175. nil
  2176. nil
  2177. )
  2178. (rmail-mode ; rmail buffer
  2179. pr-rmail-lpr pr-rmail-print
  2180. 3
  2181. (ps-article-subject ps-article-author buffer-name)
  2182. nil
  2183. nil
  2184. )
  2185. (gnus-summary-mode ; gnus summary buffer
  2186. pr-gnus-lpr pr-gnus-print
  2187. 3
  2188. (ps-article-subject ps-article-author gnus-newsgroup-name)
  2189. nil
  2190. nil
  2191. )
  2192. (gnus-article-mode ; gnus article buffer
  2193. pr-gnus-lpr pr-gnus-print
  2194. 3
  2195. (ps-article-subject ps-article-author gnus-newsgroup-name)
  2196. nil
  2197. nil
  2198. )
  2199. (Info-mode ; Info buffer
  2200. pr-mode-lpr pr-mode-print
  2201. 2
  2202. (ps-info-node ps-info-file)
  2203. nil
  2204. nil
  2205. )
  2206. (vm-mode ; vm mode
  2207. pr-vm-lpr pr-vm-print
  2208. 3
  2209. (ps-article-subject ps-article-author buffer-name)
  2210. nil
  2211. nil
  2212. )
  2213. )
  2214. "Specify an alist for a major-mode and printing functions.
  2215. To customize a major mode printing, just declare the customization in
  2216. `pr-mode-alist' and invoke some of `*-mode*' commands. An example for major
  2217. mode usage is when you're using gnus (or mh, or rmail, etc.) and you're in the
  2218. *Summary* buffer, if you forget to switch to the *Article* buffer before
  2219. printing, you'll get a nicely formatted list of article subjects shows up at
  2220. the printer. With major mode printing you don't need to switch from gnus
  2221. *Summary* buffer first.
  2222. The elements have the following form:
  2223. (MAJOR-MODE
  2224. LPR-PRINT PS-PRINT
  2225. HEADER-LINES
  2226. LEFT-HEADER
  2227. RIGHT-HEADER
  2228. KILL-LOCAL-VARIABLE
  2229. DEFAULT...)
  2230. Where:
  2231. MAJOR-MODE It's the major mode symbol.
  2232. LPR-PRINT It's a symbol function for text printing. It's invoked with
  2233. one argument:
  2234. (HEADER-LINES LEFT-HEADER RIGHT-HEADER DEFAULT...).
  2235. Usually LPR-PRINT function prepares the environment or buffer
  2236. and then call the function `pr-mode-lpr' which it's used to
  2237. process the buffer and send it to text printer.
  2238. The `pr-mode-lpr' definition is:
  2239. (pr-mode-lpr HEADER-LIST &optional FROM TO)
  2240. Where HEADER-LIST is like the argument passed to LPR-PRINT.
  2241. FROM and TO are the beginning and end markers, respectively,
  2242. for a region. If FROM is nil, it's used (point-min); if TO is
  2243. nil, it's used (point-max).
  2244. PS-PRINT It's a symbol function for PostScript printing. It's invoked
  2245. with three arguments: n-up printing, file name and the list:
  2246. (HEADER-LINES LEFT-HEADER RIGHT-HEADER DEFAULT...).
  2247. Usually PS-PRINT function prepares the environment or buffer
  2248. and then call the function `pr-mode-print' which it's used to
  2249. process the buffer and send it to PostScript printer.
  2250. The `pr-mode-print' definition is:
  2251. (pr-mode-print N-UP FILENAME HEADER-LIST &optional FROM TO)
  2252. Where N-UP, FILENAME and HEADER-LIST are like the arguments
  2253. passed to PS-PRINT. FROM and TO are the beginning and end
  2254. markers, respectively, for a region. If TO is nil, it's used
  2255. (point-max).
  2256. HEADER-LINES It's the number of header lines; if is nil, it uses
  2257. `ps-header-lines' value.
  2258. LEFT-HEADER It's the left header part, it's a list of string, variable
  2259. symbol or function symbol (with no argument); if is nil, it
  2260. uses `ps-left-header' value.
  2261. RIGHT-HEADER It's the right header part, it's a list of string, variable
  2262. symbol or function symbol (with no argument); if is nil, it
  2263. uses `ps-right-header' value.
  2264. KILL-LOCAL-VARIABLE
  2265. Non-nil means to kill all buffer local variable declared in
  2266. DEFAULT (see below).
  2267. DEFAULT It's a way to set default values when this entry is selected.
  2268. It's a cons like:
  2269. (VARIABLE-SYM . VALUE)
  2270. Which associates VARIABLE-SYM with VALUE. When this entry is
  2271. selected, it's executed the following command:
  2272. (set (make-local-variable VARIABLE-SYM) (eval VALUE))
  2273. Note that VALUE can be any valid lisp expression. So, don't
  2274. forget to quote symbols and constant lists.
  2275. If VARIABLE is the special keyword `inherits-from:', VALUE must
  2276. be a symbol name setting defined in `pr-setting-database' from
  2277. which the current setting inherits the context. Take care with
  2278. circular inheritance.
  2279. Examples:
  2280. (ps-landscape-mode . nil)
  2281. (ps-spool-duplex . t)
  2282. (pr-gs-device . (my-gs-device t))"
  2283. :type '(repeat
  2284. (list
  2285. :tag ""
  2286. (symbol :tag "Major Mode")
  2287. (function :tag "Text Printing Function")
  2288. (function :tag "PS Printing Function")
  2289. (choice :menu-tag "Number of Header Lines"
  2290. :tag "Number of Header Lines"
  2291. (integer :tag "Number")
  2292. (const :tag "Default Number" nil))
  2293. (repeat :tag "Left Header List"
  2294. (choice :menu-tag "Left Header"
  2295. :tag "Left Header"
  2296. string symbol))
  2297. (repeat :tag "Right Header List"
  2298. (choice :menu-tag "Right Header"
  2299. :tag "Right Header"
  2300. string symbol))
  2301. (boolean :tag "Kill Local Variable At End")
  2302. (repeat
  2303. :tag "Default Value List"
  2304. :inline t
  2305. (cons
  2306. :tag ""
  2307. (choice
  2308. :menu-tag "Variable"
  2309. :tag "Variable"
  2310. (const :tag "Landscape" ps-landscape-mode)
  2311. (const :tag "Print Header" ps-print-header)
  2312. (const :tag "Print Header Frame" ps-print-header-frame)
  2313. (const :tag "Line Number" ps-line-number)
  2314. (const :tag "Zebra Stripes" ps-zebra-stripes)
  2315. (const :tag "Duplex" ps-spool-duplex)
  2316. (const :tag "Tumble" ps-spool-tumble)
  2317. (const :tag "Upside-Down" ps-print-upside-down)
  2318. (const :tag "PS File Landscape" pr-file-landscape)
  2319. (const :tag "PS File Duplex" pr-file-duplex)
  2320. (const :tag "PS File Tumble" pr-file-tumble)
  2321. (const :tag "Auto Region" pr-auto-region)
  2322. (const :tag "Auto Mode" pr-auto-mode)
  2323. (const :tag "Ghostscript Device" pr-gs-device)
  2324. (const :tag "Ghostscript Resolution" pr-gs-resolution)
  2325. (const :tag "inherits-from:" inherits-from:)
  2326. (variable :tag "Other"))
  2327. (sexp :tag "Value")))
  2328. ))
  2329. :group 'printing)
  2330. (defcustom pr-ps-utility 'mpage
  2331. "Specify PostScript utility symbol.
  2332. This utility symbol should be defined on `pr-ps-utility-alist' (see it for
  2333. documentation).
  2334. This variable should be modified by customization engine. If this variable is
  2335. modified by other means (for example, a lisp function), use `pr-update-menus'
  2336. function (see it for documentation) to update PostScript utility menu.
  2337. NOTE: Don't forget to download and install the utilities declared on
  2338. `pr-ps-utility-alist'."
  2339. :type '(symbol :tag "PS File Utility")
  2340. :set 'pr-ps-utility-custom-set
  2341. :group 'printing)
  2342. (defcustom pr-ps-utility-alist
  2343. '((mpage "mpage" nil "-b%s" "-%d" "-l" "-t" "-T" ">" nil)
  2344. (psnup "psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
  2345. (inherits-from: . no-duplex))
  2346. )
  2347. ;; Examples:
  2348. ;; * On GNU or Unix system:
  2349. ;; '((mpage "mpage" nil "-b%s" "-%d" "-l" "-t" "-T" ">" nil)
  2350. ;; (psnup "psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
  2351. ;; (pr-file-duplex . nil) (pr-file-tumble . nil))
  2352. ;; )
  2353. ;; * On Windows system:
  2354. ;; '((psnup "c:/psutils/psnup" ("-q") "-P%s" "-%d" "-l" nil nil " " nil
  2355. ;; (pr-file-duplex . nil) (pr-file-tumble . nil))
  2356. ;; )
  2357. "Specify an alist for PostScript utility processing (PS utility database).
  2358. The alist element has the form:
  2359. (SYMBOL UTILITY MUST-SWITCHES PAPERSIZE N-UP LANDSCAPE DUPLEX TUMBLE OUTPUT
  2360. SWITCHES DEFAULT...)
  2361. Where:
  2362. SYMBOL It's a symbol to identify a PostScript utility. It's for
  2363. `pr-ps-utility' variable setting and for menu selection.
  2364. Examples:
  2365. mpage
  2366. psnup
  2367. UTILITY Name of utility for processing a PostScript file.
  2368. See also `pr-path-alist'.
  2369. Examples:
  2370. . for GNU or Unix system:
  2371. \"mpage\"
  2372. \"psnup -q\"
  2373. . for Windows system:
  2374. \"c:/psutils/psnup -q\"
  2375. MUST-SWITCHES List of sexp's to pass as options to the PostScript utility
  2376. program. These options are necessary to process the utility
  2377. program and must be placed before any other switches.
  2378. Example:
  2379. . for psnup:
  2380. (\"-q\")
  2381. PAPERSIZE It's a format string to specify paper size switch.
  2382. Example:
  2383. . for mpage
  2384. \"-b%s\"
  2385. N-UP It's a format string to specify n-up switch.
  2386. Example:
  2387. . for psnup
  2388. \"-%d\"
  2389. LANDSCAPE It's a string to specify landscape switch. If the utility
  2390. doesn't have landscape switch, set to nil.
  2391. Example:
  2392. . for psnup
  2393. \"-l\"
  2394. DUPLEX It's a string to specify duplex switch. If the utility doesn't
  2395. have duplex switch, set to nil.
  2396. Example:
  2397. . for psnup
  2398. nil
  2399. TUMBLE It's a string to specify tumble switch. If the utility doesn't
  2400. have tumble switch, set to nil.
  2401. Example:
  2402. . for psnup
  2403. nil
  2404. OUTPUT It's a string to specify how to generate an output file. Some
  2405. utilities accept an output file option, but some others need
  2406. output redirection or some other way to specify an output file.
  2407. Example:
  2408. . for psnup
  2409. \" \" ; psnup ... input output
  2410. . for mpage
  2411. \">\" ; mpage ... input > output
  2412. SWITCHES List of sexp's to pass as extra options to the PostScript utility
  2413. program.
  2414. Example:
  2415. . for psnup
  2416. (\"-q\")
  2417. nil
  2418. DEFAULT It's a way to set default values when this entry is selected.
  2419. It's a cons like:
  2420. (VARIABLE . VALUE)
  2421. Which associates VARIABLE with VALUE. When this entry is
  2422. selected, it's executed the following command:
  2423. (set VARIABLE (eval VALUE))
  2424. Note that VALUE can be any valid lisp expression. So, don't
  2425. forget to quote symbols and constant lists.
  2426. If VARIABLE is the special keyword `inherits-from:', VALUE must
  2427. be a symbol name setting defined in `pr-setting-database' from
  2428. which the current setting inherits the context. Take care with
  2429. circular inheritance.
  2430. Examples:
  2431. (pr-file-landscape . nil)
  2432. (pr-file-duplex . t)
  2433. (pr-gs-device . (my-gs-device t))
  2434. This variable should be modified by customization engine. If this variable is
  2435. modified by other means (for example, a lisp function), use `pr-update-menus'
  2436. function (see it for documentation) to update PostScript utility menu.
  2437. NOTE: Don't forget to download and install the utilities declared on
  2438. `pr-ps-utility-alist'.
  2439. Examples:
  2440. * On GNU or Unix system:
  2441. ((mpage \"mpage\" nil \"-b%s\" \"-%d\" \"-l\" \"-t\" \"-T\" \">\" nil)
  2442. (psnup \"psnup\" (\"-q\") \"-P%s\" \"-%d\" \"-l\" nil nil \" \" nil
  2443. (pr-file-duplex . nil) (pr-file-tumble . nil))
  2444. )
  2445. * On Windows system:
  2446. ((psnup \"c:/psutils/psnup\" (\"-q\") \"-P%s\" \"-%d\" \"-l\" nil nil \" \"
  2447. nil (pr-file-duplex . nil) (pr-file-tumble . nil))
  2448. )
  2449. Useful links:
  2450. * mpage download (GNU or Unix)
  2451. `http://www.mesa.nl/pub/mpage/'
  2452. * mpage documentation (GNU or Unix - or type `man mpage')
  2453. `http://www.cs.umd.edu/faq/guides/manual_unix/node48.html'
  2454. `http://www.rt.com/man/mpage.1.html'
  2455. * psnup (Windows, GNU or Unix)
  2456. `http://www.knackered.org/angus/psutils/'
  2457. `http://gershwin.ens.fr/vdaniel/Doc-Locale/Outils-Gnu-Linux/PsUtils/'
  2458. * psnup (PsUtils for Windows)
  2459. `http://gnuwin32.sourceforge.net/packages/psutils.htm'
  2460. * psnup documentation (GNU or Unix - or type `man psnup')
  2461. `http://linux.about.com/library/cmd/blcmdl1_psnup.htm'
  2462. `http://amath.colorado.edu/computing/software/man/psnup.html'
  2463. * GNU Enscript (Windows, GNU or Unix)
  2464. `http://people.ssh.com/mtr/genscript/'
  2465. * GNU Enscript documentation (Windows, GNU or Unix)
  2466. `http://people.ssh.com/mtr/genscript/enscript.man.html'
  2467. (on GNU or Unix, type `man enscript')
  2468. "
  2469. :type '(repeat
  2470. (list :tag "PS File Utility"
  2471. (symbol :tag "Utility Symbol")
  2472. (string :tag "Utility Name")
  2473. (repeat :tag "Must Utility Switches"
  2474. (sexp :tag "Switch" :value ""))
  2475. (choice :menu-tag "Paper Size"
  2476. :tag "Paper Size"
  2477. (const :tag "No Paper Size" nil)
  2478. (string :tag "Paper Size Format"))
  2479. (choice :menu-tag "N-Up"
  2480. :tag "N-Up"
  2481. (const :tag "No N-Up" nil)
  2482. (string :tag "N-Up Format"))
  2483. (choice :menu-tag "Landscape"
  2484. :tag "Landscape"
  2485. (const :tag "No Landscape" nil)
  2486. (string :tag "Landscape Switch"))
  2487. (choice :menu-tag "Duplex"
  2488. :tag "Duplex"
  2489. (const :tag "No Duplex" nil)
  2490. (string :tag "Duplex Switch"))
  2491. (choice :menu-tag "Tumble"
  2492. :tag "Tumble"
  2493. (const :tag "No Tumble" nil)
  2494. (string :tag "Tumble Switch"))
  2495. (string :tag "Output Separator")
  2496. (repeat :tag "Utility Switches"
  2497. (sexp :tag "Switch" :value ""))
  2498. (repeat
  2499. :tag "Default Value List"
  2500. :inline t
  2501. (cons
  2502. :tag ""
  2503. (choice
  2504. :menu-tag "Variable"
  2505. :tag "Variable"
  2506. (const :tag "PS File Landscape" pr-file-landscape)
  2507. (const :tag "PS File Duplex" pr-file-duplex)
  2508. (const :tag "PS File Tumble" pr-file-tumble)
  2509. (const :tag "Ghostscript Device" pr-gs-device)
  2510. (const :tag "Ghostscript Resolution" pr-gs-resolution)
  2511. (const :tag "inherits-from:" inherits-from:)
  2512. (variable :tag "Other"))
  2513. (sexp :tag "Value")))
  2514. ))
  2515. :set 'pr-alist-custom-set
  2516. :group 'printing)
  2517. (defcustom pr-menu-lock t
  2518. "Non-nil means menu is locked while selecting toggle options.
  2519. See also `pr-menu-char-height' and `pr-menu-char-width'."
  2520. :type 'boolean
  2521. :group 'printing)
  2522. (defcustom pr-menu-char-height (pr-menu-char-height)
  2523. "Specify menu char height in pixels.
  2524. This variable is used to guess which vertical position should be locked the
  2525. menu, so don't forget to adjust it if menu position is not ok.
  2526. See also `pr-menu-lock' and `pr-menu-char-width'."
  2527. :type 'integer
  2528. :group 'printing)
  2529. (defcustom pr-menu-char-width (pr-menu-char-width)
  2530. "Specify menu char width in pixels.
  2531. This variable is used to guess which horizontal position should be locked the
  2532. menu, so don't forget to adjust it if menu position is not ok.
  2533. See also `pr-menu-lock' and `pr-menu-char-height'."
  2534. :type 'integer
  2535. :group 'printing)
  2536. (defcustom pr-setting-database
  2537. '((no-duplex ; setting symbol name
  2538. nil nil nil ; inherits local kill-local
  2539. (pr-file-duplex . nil) ; settings
  2540. (pr-file-tumble . nil))
  2541. )
  2542. "Specify an alist for settings in general.
  2543. The elements have the following form:
  2544. (SYMBOL INHERITS LOCAL KILL-LOCAL SETTING...)
  2545. Where:
  2546. SYMBOL It's a symbol to identify the setting group.
  2547. INHERITS Specify the inheritance for SYMBOL group. It's a symbol name
  2548. setting from which the current setting inherits the context.
  2549. If INHERITS is nil, means that there is no inheritance.
  2550. This is a simple inheritance mechanism.
  2551. Let's see an example to illustrate the inheritance mechanism:
  2552. (setq pr-setting-database
  2553. '((no-duplex ; setting symbol name
  2554. nil ; inherits
  2555. nil nil ; local kill-local
  2556. (pr-file-duplex . nil) ; settings
  2557. (pr-file-tumble . nil)
  2558. )
  2559. (no-duplex-and-landscape ; setting symbol name
  2560. no-duplex ; inherits
  2561. nil nil ; local kill-local
  2562. (pr-file-landscape . nil) ; settings
  2563. )))
  2564. The example above has two setting groups: no-duplex and
  2565. no-duplex-and-landscape. When setting no-duplex is activated
  2566. through `inherits-from:' (see option `pr-ps-utility',
  2567. `pr-mode-alist' and `pr-ps-printer-alist'), the variables
  2568. pr-file-duplex and pr-file-tumble are both set to nil.
  2569. Now when setting no-duplex-and-landscape is activated through
  2570. `inherits-from:', the variable pr-file-landscape is set to nil
  2571. and also the settings for no-duplex are done, because
  2572. no-duplex-and-landscape inherits settings from no-duplex.
  2573. Take care with circular inheritance. It's an error if circular
  2574. inheritance happens.
  2575. LOCAL Non-nil means that all settings for SYMBOL group will be
  2576. declared local buffer.
  2577. KILL-LOCAL Non-nil means that all settings for SYMBOL group will be
  2578. killed at end. It has effect only when LOCAL is non-nil.
  2579. SETTING It's a cons like:
  2580. (VARIABLE . VALUE)
  2581. Which associates VARIABLE with VALUE. When this entry is
  2582. selected, it's executed the following command:
  2583. * If LOCAL is non-nil:
  2584. (set (make-local-variable VARIABLE) (eval VALUE))
  2585. * If LOCAL is nil:
  2586. (set VARIABLE (eval VALUE))
  2587. Note that VALUE can be any valid lisp expression. So, don't
  2588. forget to quote symbols and constant lists.
  2589. This setting is ignored if VARIABLE is equal to keyword
  2590. `inherits-from:'.
  2591. Examples:
  2592. '(ps-landscape-mode . nil)
  2593. '(ps-spool-duplex . t)
  2594. '(pr-gs-device . (my-gs-device t))"
  2595. :type '(repeat
  2596. (list
  2597. :tag ""
  2598. (symbol :tag "Setting Name")
  2599. (choice :menu-tag "Inheritance"
  2600. :tag "Inheritance"
  2601. (const :tag "No Inheritance" nil)
  2602. (symbol :tag "Inherits From"))
  2603. (boolean :tag "Local Buffer Setting")
  2604. (boolean :tag "Kill Local Variable At End")
  2605. (repeat
  2606. :tag "Setting List"
  2607. :inline t
  2608. (cons
  2609. :tag ""
  2610. (choice
  2611. :menu-tag "Variable"
  2612. :tag "Variable"
  2613. (const :tag "Landscape" ps-landscape-mode)
  2614. (const :tag "Print Header" ps-print-header)
  2615. (const :tag "Print Header Frame" ps-print-header-frame)
  2616. (const :tag "Line Number" ps-line-number)
  2617. (const :tag "Zebra Stripes" ps-zebra-stripes)
  2618. (const :tag "Duplex" ps-spool-duplex)
  2619. (const :tag "Tumble" ps-spool-tumble)
  2620. (const :tag "Upside-Down" ps-print-upside-down)
  2621. (const :tag "PS File Landscape" pr-file-landscape)
  2622. (const :tag "PS File Duplex" pr-file-duplex)
  2623. (const :tag "PS File Tumble" pr-file-tumble)
  2624. (const :tag "Auto Region" pr-auto-region)
  2625. (const :tag "Auto Mode" pr-auto-mode)
  2626. (const :tag "Ghostscript Device" pr-gs-device)
  2627. (const :tag "Ghostscript Resolution" pr-gs-resolution)
  2628. (variable :tag "Other"))
  2629. (sexp :tag "Value")))
  2630. ))
  2631. :group 'printing)
  2632. (defcustom pr-visible-entry-list
  2633. '(postscript text postscript-options postscript-process printing help)
  2634. "Specify a list of Printing menu visible entries.
  2635. Valid values with the corresponding menu parts are:
  2636. +------------------------------+
  2637. | Printing Interface |
  2638. +------------------------------+
  2639. `postscript' | PostScript Preview >|
  2640. | PostScript Print >|
  2641. | PostScript Printer: name >|
  2642. +------------------------------+
  2643. `text' | Printify >|
  2644. | Print >|
  2645. | Text Printer: name >|
  2646. +------------------------------+
  2647. `postscript-options' |[ ] Landscape |
  2648. |[ ] Print Header |
  2649. |[ ] Print Header Frame |
  2650. |[ ] Line Number |
  2651. |[ ] Zebra Stripes |
  2652. |[ ] Duplex |
  2653. |[ ] Tumble |
  2654. |[ ] Upside-Down |
  2655. | Print All Pages >|
  2656. +------------------------------+
  2657. `postscript-process' |[ ] Spool Buffer |
  2658. |[ ] Print with faces |
  2659. |[ ] Print via Ghostscript |
  2660. +------------------------------+
  2661. `printing' |[ ] Auto Region |
  2662. |[ ] Auto Mode |
  2663. |[ ] Menu Lock |
  2664. +------------------------------+
  2665. `help' | Customize >|
  2666. | Show Settings >|
  2667. | Help |
  2668. +------------------------------+
  2669. Any other value is ignored."
  2670. :type '(repeat :tag "Menu Visible Part"
  2671. (choice :menu-tag "Menu Part"
  2672. :tag "Menu Part"
  2673. (const postscript)
  2674. (const text)
  2675. (const postscript-options)
  2676. (const postscript-process)
  2677. (const printing)
  2678. (const help)))
  2679. :group 'printing)
  2680. (defcustom pr-delete-temp-file t
  2681. "Non-nil means delete temporary files.
  2682. Set `pr-delete-temp-file' to nil, if the following message (or a similar)
  2683. happens when printing:
  2684. Error: could not open \"c:\\temp\\prspool.ps\" for reading."
  2685. :type 'boolean
  2686. :group 'printing)
  2687. (defcustom pr-list-directory nil
  2688. "Non-nil means list directory when processing a directory.
  2689. That is, any subdirectories (and the superdirectory) of the directory (given as
  2690. argument of functions below) are also printed (as dired-mode listings).
  2691. It's used by `pr-ps-directory-preview', `pr-ps-directory-using-ghostscript',
  2692. `pr-ps-directory-print', `pr-ps-directory-ps-print', `pr-printify-directory'
  2693. and `pr-txt-directory'."
  2694. :type 'boolean
  2695. :group 'printing)
  2696. (defcustom pr-buffer-name "*Printing Interface*"
  2697. "Specify the name of the buffer interface for printing package.
  2698. It's used by `pr-interface'."
  2699. :type 'string
  2700. :group 'printing)
  2701. (defcustom pr-buffer-name-ignore
  2702. (list (regexp-quote pr-buffer-name) ; ignore printing interface buffer
  2703. "^ .*$") ; ignore invisible buffers
  2704. "Specify a regexp list for buffer names to be ignored in interface buffer.
  2705. NOTE: Case is important for matching, that is, `case-fold-search' is always
  2706. nil.
  2707. It's used by `pr-interface'."
  2708. :type '(repeat (regexp :tag "Buffer Name Regexp"))
  2709. :group 'printing)
  2710. (defcustom pr-buffer-verbose t
  2711. "Non-nil means to be verbose when editing a field in interface buffer.
  2712. It's used by `pr-interface'."
  2713. :type 'boolean
  2714. :group 'printing)
  2715. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2716. ;; Internal Variables
  2717. (defvar pr-txt-command nil
  2718. "Name of program for printing a text file.
  2719. See `pr-txt-printer-alist'.")
  2720. (defvar pr-txt-switches nil
  2721. "List of sexp's to pass as extra options to the text printer program.
  2722. See `pr-txt-printer-alist'.")
  2723. (defvar pr-txt-printer nil
  2724. "Specify text printer name.
  2725. See `pr-txt-printer-alist'.")
  2726. (defvar pr-ps-command nil
  2727. "Name of program for printing a PostScript file.
  2728. See `pr-ps-printer-alist'.")
  2729. (defvar pr-ps-switches nil
  2730. "List of sexp's to pass as extra options to the PostScript printer program.
  2731. See `pr-ps-printer-alist'.")
  2732. (defvar pr-ps-printer-switch nil
  2733. "Specify PostScript printer name switch.
  2734. See `pr-ps-printer-alist'.")
  2735. (defvar pr-ps-printer nil
  2736. "Specify PostScript printer name.
  2737. See `pr-ps-printer-alist'.")
  2738. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2739. ;; Macros
  2740. (defmacro pr-save-file-modes (&rest body)
  2741. "Execute BODY with file permissions temporarily set to `pr-file-modes'."
  2742. (declare (obsolete with-file-modes "25.1"))
  2743. `(with-file-modes pr-file-modes ,@body))
  2744. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2745. ;; Keys & Menus
  2746. (defsubst pr-visible-p (key)
  2747. (memq key pr-visible-entry-list))
  2748. (defsubst pr-mode-alist-p ()
  2749. (cdr (assq major-mode pr-mode-alist)))
  2750. (defsubst pr-auto-mode-p ()
  2751. (and pr-auto-mode (pr-mode-alist-p)))
  2752. (defsubst pr-using-ghostscript-p ()
  2753. (and pr-print-using-ghostscript (not pr-spool-p)))
  2754. (defalias 'pr-get-symbol
  2755. (if (featurep 'emacs) 'easy-menu-intern ; since 22.1
  2756. (if (fboundp 'easy-menu-intern) ; hacked from easymenu.el
  2757. 'easy-menu-intern
  2758. (lambda (s) (if (stringp s) (intern s) s)))))
  2759. (defconst pr-menu-spec
  2760. ;; Menu mapping:
  2761. ;; unfortunately XEmacs doesn't support :active for submenus,
  2762. ;; only for items.
  2763. ;; So, it uses :included instead of :active.
  2764. ;; Also, XEmacs doesn't support :help tag.
  2765. (let ((pr-:active (if (featurep 'xemacs)
  2766. :included ; XEmacs
  2767. :active)) ; GNU Emacs
  2768. (pr-:help (if (featurep 'xemacs)
  2769. 'ignore ; XEmacs
  2770. #'(lambda (text) (list :help text))))) ; GNU Emacs
  2771. `(
  2772. ["Printing Interface" pr-interface
  2773. ,@(funcall
  2774. pr-:help "Use buffer interface instead of menu interface")]
  2775. "--"
  2776. ("PostScript Preview" :included (pr-visible-p 'postscript)
  2777. ,@(funcall
  2778. pr-:help "Preview PostScript instead of sending to printer")
  2779. ("Directory" ,pr-:active (not pr-spool-p)
  2780. ["1-up" (pr-ps-directory-preview 1 nil nil t) t]
  2781. ["2-up" (pr-ps-directory-preview 2 nil nil t) t]
  2782. ["4-up" (pr-ps-directory-preview 4 nil nil t) t]
  2783. ["Other..." (pr-ps-directory-preview nil nil nil t)
  2784. :keys "\\[pr-ps-buffer-preview]"])
  2785. ("Buffer" ,pr-:active (not pr-spool-p)
  2786. ["1-up" (pr-ps-buffer-preview 1 t) t]
  2787. ["2-up" (pr-ps-buffer-preview 2 t) t]
  2788. ["4-up" (pr-ps-buffer-preview 4 t) t]
  2789. ["Other..." (pr-ps-buffer-preview nil t)
  2790. :keys "\\[pr-ps-buffer-preview]"])
  2791. ("Region" ,pr-:active (and (not pr-spool-p) (ps-mark-active-p))
  2792. ["1-up" (pr-ps-region-preview 1 t) t]
  2793. ["2-up" (pr-ps-region-preview 2 t) t]
  2794. ["4-up" (pr-ps-region-preview 4 t) t]
  2795. ["Other..." (pr-ps-region-preview nil t)
  2796. :keys "\\[pr-ps-region-preview]"])
  2797. ("Mode" ,pr-:active (and (not pr-spool-p) (pr-mode-alist-p))
  2798. ["1-up" (pr-ps-mode-preview 1 t) t]
  2799. ["2-up" (pr-ps-mode-preview 2 t) t]
  2800. ["4-up" (pr-ps-mode-preview 4 t) t]
  2801. ["Other..." (pr-ps-mode-preview nil t)
  2802. :keys "\\[pr-ps-mode-preview]"])
  2803. ("File"
  2804. ["No Preprocessing..." (call-interactively 'pr-ps-file-preview)
  2805. :keys "\\[pr-ps-file-preview]"
  2806. ,@(funcall
  2807. pr-:help "Preview PostScript file")]
  2808. "--"
  2809. ["PostScript Utility" pr-update-menus :active pr-ps-utility-alist
  2810. ,@(funcall
  2811. pr-:help "Select PostScript utility")]
  2812. "--"
  2813. ["1-up..." (pr-ps-file-up-preview 1 t t) pr-ps-utility-alist]
  2814. ["2-up..." (pr-ps-file-up-preview 2 t t) pr-ps-utility-alist]
  2815. ["4-up..." (pr-ps-file-up-preview 4 t t) pr-ps-utility-alist]
  2816. ["Other..." (pr-ps-file-up-preview nil t t)
  2817. :keys "\\[pr-ps-file-up-preview]" :active pr-ps-utility-alist]
  2818. "--"
  2819. ["Landscape" pr-toggle-file-landscape-menu
  2820. :style toggle :selected pr-file-landscape
  2821. ,@(funcall
  2822. pr-:help "Toggle landscape for PostScript file")
  2823. :active pr-ps-utility-alist]
  2824. ["Duplex" pr-toggle-file-duplex-menu
  2825. :style toggle :selected pr-file-duplex
  2826. ,@(funcall
  2827. pr-:help "Toggle duplex for PostScript file")
  2828. :active pr-ps-utility-alist]
  2829. ["Tumble" pr-toggle-file-tumble-menu
  2830. :style toggle :selected pr-file-tumble
  2831. ,@(funcall
  2832. pr-:help "Toggle tumble for PostScript file")
  2833. :active (and pr-file-duplex pr-ps-utility-alist)])
  2834. ["Despool..." (call-interactively 'pr-despool-preview)
  2835. :active pr-spool-p :keys "\\[pr-despool-preview]"
  2836. ,@(funcall
  2837. pr-:help "Despool PostScript buffer to printer or file (C-u)")])
  2838. ("PostScript Print" :included (pr-visible-p 'postscript)
  2839. ,@(funcall
  2840. pr-:help "Send PostScript to printer or file (C-u)")
  2841. ("Directory"
  2842. ["1-up" (pr-ps-directory-ps-print 1 nil nil t) t]
  2843. ["2-up" (pr-ps-directory-ps-print 2 nil nil t) t]
  2844. ["4-up" (pr-ps-directory-ps-print 4 nil nil t) t]
  2845. ["Other..." (pr-ps-directory-ps-print nil nil nil t)
  2846. :keys "\\[pr-ps-buffer-ps-print]"])
  2847. ("Buffer"
  2848. ["1-up" (pr-ps-buffer-ps-print 1 t) t]
  2849. ["2-up" (pr-ps-buffer-ps-print 2 t) t]
  2850. ["4-up" (pr-ps-buffer-ps-print 4 t) t]
  2851. ["Other..." (pr-ps-buffer-ps-print nil t)
  2852. :keys "\\[pr-ps-buffer-ps-print]"])
  2853. ("Region" ,pr-:active (ps-mark-active-p)
  2854. ["1-up" (pr-ps-region-ps-print 1 t) t]
  2855. ["2-up" (pr-ps-region-ps-print 2 t) t]
  2856. ["4-up" (pr-ps-region-ps-print 4 t) t]
  2857. ["Other..." (pr-ps-region-ps-print nil t)
  2858. :keys "\\[pr-ps-region-ps-print]"])
  2859. ("Mode" ,pr-:active (pr-mode-alist-p)
  2860. ["1-up" (pr-ps-mode-ps-print 1 t) t]
  2861. ["2-up" (pr-ps-mode-ps-print 2 t) t]
  2862. ["4-up" (pr-ps-mode-ps-print 4 t) t]
  2863. ["Other..." (pr-ps-mode-ps-print nil t)
  2864. :keys "\\[pr-ps-mode-ps-print]"])
  2865. ("File"
  2866. ["No Preprocessing..." (call-interactively 'pr-ps-file-ps-print)
  2867. :keys "\\[pr-ps-file-ps-print]"
  2868. ,@(funcall
  2869. pr-:help "Send PostScript file to printer")]
  2870. "--"
  2871. ["PostScript Utility" pr-update-menus :active pr-ps-utility-alist
  2872. ,@(funcall
  2873. pr-:help "Select PostScript utility")]
  2874. "--"
  2875. ["1-up..." (pr-ps-file-up-ps-print 1 t t) pr-ps-utility-alist]
  2876. ["2-up..." (pr-ps-file-up-ps-print 2 t t) pr-ps-utility-alist]
  2877. ["4-up..." (pr-ps-file-up-ps-print 4 t t) pr-ps-utility-alist]
  2878. ["Other..." (pr-ps-file-up-ps-print nil t t)
  2879. :keys "\\[pr-ps-file-up-ps-print]" :active pr-ps-utility-alist]
  2880. "--"
  2881. ["Landscape" pr-toggle-file-landscape-menu
  2882. :style toggle :selected pr-file-landscape
  2883. ,@(funcall
  2884. pr-:help "Toggle landscape for PostScript file")
  2885. :active pr-ps-utility-alist]
  2886. ["Duplex" pr-toggle-file-duplex-menu
  2887. :style toggle :selected pr-file-duplex
  2888. ,@(funcall
  2889. pr-:help "Toggle duplex for PostScript file")
  2890. :active pr-ps-utility-alist]
  2891. ["Tumble" pr-toggle-file-tumble-menu
  2892. :style toggle :selected pr-file-tumble
  2893. ,@(funcall
  2894. pr-:help "Toggle tumble for PostScript file")
  2895. :active (and pr-file-duplex pr-ps-utility-alist)])
  2896. ["Despool..." (call-interactively 'pr-despool-ps-print)
  2897. :active pr-spool-p :keys "\\[pr-despool-ps-print]"
  2898. ,@(funcall
  2899. pr-:help "Despool PostScript buffer to printer or file (C-u)")])
  2900. ["PostScript Printers" pr-update-menus
  2901. :active pr-ps-printer-alist :included (pr-visible-p 'postscript)
  2902. ,@(funcall
  2903. pr-:help "Select PostScript printer")]
  2904. "--"
  2905. ("Printify" :included (pr-visible-p 'text)
  2906. ,@(funcall
  2907. pr-:help
  2908. "Replace non-printing chars with printable representations.")
  2909. ["Directory" pr-printify-directory t]
  2910. ["Buffer" pr-printify-buffer t]
  2911. ["Region" pr-printify-region (ps-mark-active-p)])
  2912. ("Print" :included (pr-visible-p 'text)
  2913. ,@(funcall
  2914. pr-:help "Send text to printer")
  2915. ["Directory" pr-txt-directory t]
  2916. ["Buffer" pr-txt-buffer t]
  2917. ["Region" pr-txt-region (ps-mark-active-p)]
  2918. ["Mode" pr-txt-mode (pr-mode-alist-p)])
  2919. ["Text Printers" pr-update-menus
  2920. :active pr-txt-printer-alist :included (pr-visible-p 'text)
  2921. ,@(funcall
  2922. pr-:help "Select text printer")]
  2923. "--"
  2924. ["Landscape" pr-toggle-landscape-menu
  2925. :style toggle :selected ps-landscape-mode
  2926. :included (pr-visible-p 'postscript-options)]
  2927. ["Print Header" pr-toggle-header-menu
  2928. :style toggle :selected ps-print-header
  2929. :included (pr-visible-p 'postscript-options)]
  2930. ["Print Header Frame" pr-toggle-header-frame-menu
  2931. :style toggle :selected ps-print-header-frame :active ps-print-header
  2932. :included (pr-visible-p 'postscript-options)]
  2933. ["Line Number" pr-toggle-line-menu
  2934. :style toggle :selected ps-line-number
  2935. :included (pr-visible-p 'postscript-options)]
  2936. ["Zebra Stripes" pr-toggle-zebra-menu
  2937. :style toggle :selected ps-zebra-stripes
  2938. :included (pr-visible-p 'postscript-options)]
  2939. ["Duplex" pr-toggle-duplex-menu
  2940. :style toggle :selected ps-spool-duplex
  2941. :included (pr-visible-p 'postscript-options)]
  2942. ["Tumble" pr-toggle-tumble-menu
  2943. :style toggle :selected ps-spool-tumble :active ps-spool-duplex
  2944. :included (pr-visible-p 'postscript-options)]
  2945. ["Upside-Down" pr-toggle-upside-down-menu
  2946. :style toggle :selected ps-print-upside-down
  2947. :included (pr-visible-p 'postscript-options)]
  2948. ("Print All Pages" :included (pr-visible-p 'postscript-options)
  2949. ,@(funcall
  2950. pr-:help "Select odd/even pages/sheets to print")
  2951. ["All Pages" (pr-even-or-odd-pages nil)
  2952. :style radio :selected (eq ps-even-or-odd-pages nil)]
  2953. ["Even Pages" (pr-even-or-odd-pages 'even-page)
  2954. :style radio :selected (eq ps-even-or-odd-pages 'even-page)]
  2955. ["Odd Pages" (pr-even-or-odd-pages 'odd-page)
  2956. :style radio :selected (eq ps-even-or-odd-pages 'odd-page)]
  2957. ["Even Sheets" (pr-even-or-odd-pages 'even-sheet)
  2958. :style radio :selected (eq ps-even-or-odd-pages 'even-sheet)]
  2959. ["Odd Sheets" (pr-even-or-odd-pages 'odd-sheet)
  2960. :style radio :selected (eq ps-even-or-odd-pages 'odd-sheet)])
  2961. "--"
  2962. ["Spool Buffer" pr-toggle-spool-menu
  2963. :style toggle :selected pr-spool-p
  2964. :included (pr-visible-p 'postscript-process)
  2965. ,@(funcall
  2966. pr-:help "Toggle PostScript spooling")]
  2967. ["Print with faces" pr-toggle-faces-menu
  2968. :style toggle :selected pr-faces-p
  2969. :included (pr-visible-p 'postscript-process)
  2970. ,@(funcall
  2971. pr-:help "Toggle PostScript printing with faces")]
  2972. ["Print via Ghostscript" pr-toggle-ghostscript-menu
  2973. :style toggle :selected pr-print-using-ghostscript
  2974. :included (pr-visible-p 'postscript-process)
  2975. ,@(funcall
  2976. pr-:help "Toggle PostScript generation using ghostscript")]
  2977. "--"
  2978. ["Auto Region" pr-toggle-region-menu
  2979. :style toggle :selected pr-auto-region
  2980. :included (pr-visible-p 'printing)]
  2981. ["Auto Mode" pr-toggle-mode-menu
  2982. :style toggle :selected pr-auto-mode
  2983. :included (pr-visible-p 'printing)]
  2984. ["Menu Lock" pr-toggle-lock-menu
  2985. :style toggle :selected pr-menu-lock
  2986. :included (pr-visible-p 'printing)]
  2987. "--"
  2988. ("Customize" :included (pr-visible-p 'help)
  2989. ["printing" pr-customize t]
  2990. ["ps-print" ps-print-customize t]
  2991. ["lpr" lpr-customize t])
  2992. ("Show Settings" :included (pr-visible-p 'help)
  2993. ["printing" pr-show-pr-setup t]
  2994. ["ps-print" pr-show-ps-setup t]
  2995. ["lpr" pr-show-lpr-setup t])
  2996. ["Help" pr-help :active t :included (pr-visible-p 'help)]
  2997. )))
  2998. (defun pr-menu-bind ()
  2999. "Install `printing' menu in the menubar.
  3000. This replaces the File/Print* menu entries with a File/Print sub-menu.
  3001. Calls `pr-update-menus' to adjust menus."
  3002. (interactive)
  3003. (pr-global-menubar pr-menu-spec)
  3004. (pr-update-menus t))
  3005. ;; Key binding
  3006. (let ((pr-print-key (if (featurep 'xemacs)
  3007. 'f22 ; XEmacs
  3008. 'print))) ; GNU Emacs
  3009. (global-set-key `[,pr-print-key] 'pr-ps-fast-fire)
  3010. ;; Well, M-print and S-print are used because in my keyboard S-print works
  3011. ;; and M-print doesn't. But M-print can work in other keyboard.
  3012. (global-set-key `[(meta ,pr-print-key)] 'pr-ps-mode-using-ghostscript)
  3013. (global-set-key `[(shift ,pr-print-key)] 'pr-ps-mode-using-ghostscript)
  3014. ;; Well, C-print and C-M-print are used because in my keyboard C-M-print works
  3015. ;; and C-print doesn't. But C-print can work in other keyboard.
  3016. (global-set-key `[(control ,pr-print-key)] 'pr-txt-fast-fire)
  3017. (global-set-key `[(control meta ,pr-print-key)] 'pr-txt-fast-fire))
  3018. ;;; You can also use something like:
  3019. ;;;(global-set-key "\C-ci" 'pr-interface)
  3020. ;;;(global-set-key "\C-cbp" 'pr-ps-buffer-print)
  3021. ;;;(global-set-key "\C-cbx" 'pr-ps-buffer-preview)
  3022. ;;;(global-set-key "\C-cbb" 'pr-ps-buffer-using-ghostscript)
  3023. ;;;(global-set-key "\C-crp" 'pr-ps-region-print)
  3024. ;;;(global-set-key "\C-crx" 'pr-ps-region-preview)
  3025. ;;;(global-set-key "\C-crr" 'pr-ps-region-using-ghostscript)
  3026. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3027. ;; Help Message
  3028. (defconst pr-help-message
  3029. (concat "printing.el version " pr-version
  3030. " ps-print.el version " ps-print-version
  3031. "\n\n
  3032. Menu Layout
  3033. -----------
  3034. The `printing' menu (Tools/Printing or File/Print) has the following layout:
  3035. +-----------------------------+
  3036. A 0 | Printing Interface |
  3037. +-----------------------------+ +-A---------+ +-B------+
  3038. I 1 | PostScript Preview >|-------|Directory >|-----|1-up |
  3039. 2 | PostScript Print >|---- A |Buffer >|-- B |2-up |
  3040. 3 | PostScript Printer: name >|---- C |Region >|-- B |4-up |
  3041. +-----------------------------+ |Mode >|-- B |Other...|
  3042. II 4 | Printify >|-----\\ |File >|--\\ +--------+
  3043. 5 | Print >|---\\ | |Despool... | |
  3044. 6 | Text Printer: name >|-\\ | | +-----------+ |
  3045. +-----------------------------+ | | | +---------+ +------------+
  3046. III 7 |[ ]Landscape | | | \\-|Directory| | No Prep... | Ia
  3047. 8 |[ ]Print Header | | | |Buffer | +------------+ Ib
  3048. 9 |[ ]Print Header Frame | | | |Region | | name >|- C
  3049. 10 |[ ]Line Number | | | +---------+ +------------+
  3050. 11 |[ ]Zebra Stripes | | | +---------+ | 1-up... | Ic
  3051. 12 |[ ]Duplex | | \\---|Directory| | 2-up... |
  3052. 13 |[ ]Tumble | \\--\\ |Buffer | | 4-up... |
  3053. 14 |[ ]Upside-Down | | |Region | | Other... |
  3054. 15 | Print All Pages >|--\\ | |Mode | +------------+
  3055. +-----------------------------+ | | +---------+ |[ ]Landscape| Id
  3056. IV 16 |[ ]Spool Buffer | | | +-C-------+ |[ ]Duplex | Ie
  3057. 17 |[ ]Print with faces | | \\--|( )name A| |[ ]Tumble | If
  3058. 18 |[ ]Print via Ghostscript | | |( )name B| +------------+
  3059. +-----------------------------+ | |... |
  3060. V 19 |[ ]Auto Region | | |(*)name |
  3061. 20 |[ ]Auto Mode | | |... |
  3062. 21 |[ ]Menu Lock | | +---------+ +--------------+
  3063. +-----------------------------+ \\------------------|(*)All Pages |
  3064. VI 22 | Customize >|--- D +-D------+ |( )Even Pages |
  3065. 23 | Show Settings >|-------|printing| |( )Odd Pages |
  3066. 24 | Help | |ps-print| |( )Even Sheets|
  3067. +-----------------------------+ |lpr | |( )Odd Sheets |
  3068. +--------+ +--------------+
  3069. See `pr-visible-entry-list' for hiding some parts of the menu.
  3070. The menu has the following sections:
  3071. A. Interface:
  3072. 0. You can use a buffer interface instead of menus. It looks like the
  3073. customization buffer. Basically, it has the same options found in the
  3074. menu and some extra options, all this on a buffer.
  3075. I. PostScript printing:
  3076. 1. You can generate a PostScript file (if you type C-u before activating
  3077. menu) or PostScript temporary file for a directory, a buffer, a region
  3078. or a major mode, choosing 1-up, 2-up, 4-up or any other n-up printing;
  3079. after file generation, ghostview is activated using the file generated
  3080. as argument. This option is disabled if spooling is on (option 16).
  3081. Also, if you already have a PostScript file you can preview it.
  3082. Instead of previewing each buffer, region or major mode at once, you
  3083. can save temporarily the PostScript code generated in a buffer and
  3084. preview it later. The option `Despool...' despools the PostScript
  3085. spooling buffer in a temporary file and uses ghostview to preview it.
  3086. If you type C-u before choosing this option, the PostScript code
  3087. generated is saved in a file instead of saving in a temporary file. To
  3088. spool the PostScript code generated you need to turn on the option 16.
  3089. The option `Despool...' is enabled if spooling is on (option 16).
  3090. NOTE 1: It's possible to customize a major mode printing, just declare
  3091. the customization in `pr-mode-alist' and invoke some of
  3092. `*-mode*' commands or select Mode option in Printing menu. An
  3093. example for major mode usage is when you're using gnus (or mh,
  3094. or rmail, etc.) and you're in the *Summary* buffer, if you
  3095. forget to switch to the *Article* buffer before printing,
  3096. you'll get a nicely formatted list of article subjects shows
  3097. up at the printer. With major mode printing you don't need to
  3098. switch from gnus *Summary* buffer first.
  3099. NOTE 2: There are the following options for PostScript file processing:
  3100. Ia. Print the file *No Preprocessing*, that is, send it
  3101. directly to PostScript printer.
  3102. Ib. PostScript utility processing selection.
  3103. See `pr-ps-utility-alist' and `pr-setting-database' for
  3104. documentation.
  3105. Ic. Do n-up processing before printing.
  3106. Id. Toggle on/off landscape for PostScript file processing.
  3107. Ie. Toggle on/off duplex for PostScript file processing.
  3108. If. Toggle on/off tumble for PostScript file processing.
  3109. NOTE 3: Don't forget to download and install the utilities declared on
  3110. `pr-ps-utility-alist'.
  3111. 2. Operate the same way as option 1, but it sends directly the PostScript
  3112. code (or put in a file, if you've typed C-u) or it uses ghostscript to
  3113. print the PostScript file generated. It depends on option 18, if it's
  3114. turned on, it uses ghostscript; otherwise, it sends directly to
  3115. printer. If spooling is on (option 16), the PostScript code is saved
  3116. temporarily in a buffer instead of printing it or saving it in a file.
  3117. Also, if you already have a PostScript file you can print it.
  3118. Instead of printing each buffer, region or major mode at once, you can
  3119. save temporarily the PostScript code generated in a buffer and print it
  3120. later. The option `Despool...' despools the PostScript spooling buffer
  3121. directly on a printer. If you type C-u before choosing this option,
  3122. the PostScript code generated is saved in a file instead of sending it to
  3123. the printer. To spool the PostScript code generated you need to turn on
  3124. option 16. This option is enabled if spooling is on (option 16).
  3125. See also the NOTE 1, NOTE 2 and NOTE 3 on option 1.
  3126. 3. You can select a new PostScript printer to send PostScript code
  3127. generated. For selection it's used all PostScript printers defined
  3128. in `pr-ps-printer-alist' variable (see it for documentation).
  3129. See also `pr-setting-database'.
  3130. II. Text printing:
  3131. 4. If you have control characters (character code from \\000 to \\037) in a
  3132. buffer and you want to print them in a text printer, select this
  3133. option. All control characters in your buffer or region will be
  3134. replaced by a printable representation. The printable representations
  3135. use ^ (for ASCII control characters) or hex. The characters tab,
  3136. linefeed, space, return and formfeed are not affected.
  3137. You don't need to select this option if you use any option of section
  3138. I, the PostScript engine treats control characters properly.
  3139. 5. If you want to print a directory, buffer, region or major mode in a
  3140. text printer, select this option. See also the NOTE 1 on option 1.
  3141. 6. You can select a new text printer to send text generated. For
  3142. selection it's used all text printers defined in `pr-txt-printer-alist'
  3143. variable (see it for documentation).
  3144. See also `pr-setting-database'.
  3145. III. PostScript page toggle options:
  3146. 7. If you want a PostScript landscape printing, turn on this option.
  3147. 8. If you want to have a header in each page in your PostScript code,
  3148. turn on this option.
  3149. 9. If you want to draw a gaudy frame around the header, turn on this
  3150. option. This option is enabled if print header is on (option 8).
  3151. 10. If you want that the line number is printed in your PostScript code,
  3152. turn on this option.
  3153. 11. If you want background zebra stripes in your PostScript code, turn on
  3154. this option.
  3155. 12. If you want a duplex printing and your PostScript printer has this
  3156. feature, turn on this option.
  3157. 13. If you turned on duplex printing, you can choose if you want to have a
  3158. printing suitable for binding on the left or right (tumble off), or to
  3159. have a printing suitable for binding at top or bottom (tumble on).
  3160. This option is enabled if duplex is on (option 12).
  3161. 14. If you want a PostScript upside-down printing, turn on this option.
  3162. 15. With this option, you can choose if you want to print all pages, odd
  3163. pages, even pages, odd sheets or even sheets.
  3164. See also `ps-even-or-odd-pages'.
  3165. IV. PostScript processing toggle options:
  3166. 16. If you want to spool the PostScript code generated, turn on this
  3167. option. To spool the PostScript code generated use option 2. You can
  3168. despool later by choosing option 1 or 2, sub-option `Despool...'.
  3169. 17. If you use colors in your buffers and want to see these colors on your
  3170. PostScript code generated, turn on this option. If you have a
  3171. black/white PostScript printer, these colors are displayed in gray
  3172. scale by PostScript printer interpreter.
  3173. 18. If you don't have a PostScript printer to send PostScript files, turn
  3174. on this option. When this option is on, the ghostscript is used to
  3175. print PostScript files. In GNU or Unix system, if ghostscript is set
  3176. as a PostScript filter, you don't need to turn on this option.
  3177. V. Printing customization:
  3178. 19. If you want that region is automagically detected, turn on this
  3179. option. Note that this will only work if you're using transient mark
  3180. mode. When this option is on, the `*-buffer*' commands will behave
  3181. like `*-region*' commands, that is, `*-buffer*' commands will print
  3182. only the region marked instead of all buffer.
  3183. 20. Turn this option on if you want that when current major-mode is
  3184. declared in `pr-mode-alist', the `*-buffer*' and `*-region*' commands
  3185. behave like `*-mode*' commands.
  3186. 21. If you want that Printing menu stays open while you are setting
  3187. toggle options, turn on this option. The variables
  3188. `pr-menu-char-height' and `pr-menu-char-width' are used to guess the
  3189. menu position, so don't forget to adjust these variables if menu
  3190. position is not ok.
  3191. VI. Customization:
  3192. 22. Besides all options in section III, IV and V, you can customize much
  3193. more PostScript options in `ps-print' option. Or you can customize
  3194. some `lpr' options for text printing. Or customize `printing'
  3195. options.
  3196. 23. Show current settings for `printing', `ps-print' or `lpr'.
  3197. 24. Quick help for printing menu layout.
  3198. ")
  3199. "Printing help message.")
  3200. (defconst pr-interface-help-message
  3201. (concat "printing.el version " pr-version
  3202. " ps-print.el version " ps-print-version
  3203. "\n\n
  3204. The printing interface buffer has the same functionality as the printing menu.
  3205. The major difference is that the states (like sending PostScript generated to a
  3206. file, n-up printing, etc.) are set and saved between printing buffer
  3207. activation. Also, the landscape, duplex and tumble values are the same for
  3208. PostScript file and directory/buffer/region/mode processing; using menu, there
  3209. are different value sets for PostScript file and directory/buffer/region/mode
  3210. processing.
  3211. The printing interface buffer has the following sections:
  3212. 1. Print:
  3213. Here you can choose to print/preview a buffer, a directory or a PostScript
  3214. file:
  3215. 1a. Buffer:
  3216. * Buffer List:
  3217. Select a buffer from the current buffer list.
  3218. * Region:
  3219. If it's on, this means that the selected buffer has an active region,
  3220. so you can turn on/off, as you wish.
  3221. If it's off when a buffer is selected, this means that the selected
  3222. buffer has no active region, so it'll not be possible to turn it on.
  3223. If you want to process the region, let this option on.
  3224. If you want to process the whole buffer, let this option off.
  3225. * Mode:
  3226. If it's on, this means that the selected buffer major mode is declared
  3227. for major mode processing, so you can turn on/off, as you wish.
  3228. If it's off when a buffer is selected, this means that the selected
  3229. buffer major mode isn't declared for major mode processing, so it'll
  3230. not be possible to turn it on.
  3231. If you want the major mode processing, let this option on.
  3232. If you don't want the major mode processing, let this option off.
  3233. NOTE 1: It's possible to customize a major mode printing, just declare
  3234. the customization in `pr-mode-alist' and invoke some of
  3235. `*-mode*' commands or select Mode option in Printing menu. An
  3236. example for major mode usage is when you're using gnus (or mh,
  3237. or rmail, etc.) and you're in the *Summary* buffer, if you
  3238. forget to switch to the *Article* buffer before printing,
  3239. you'll get a nicely formatted list of article subjects shows
  3240. up at the printer. With major mode printing you don't need to
  3241. switch from gnus *Summary* buffer first.
  3242. 1b. Directory:
  3243. * Directory:
  3244. Specify a valid directory path.
  3245. * File Regexp:
  3246. Specify a file name regexp. All file names in the directory that
  3247. match with regexp will be printed/previewed. An empty file name
  3248. regexp means to print/preview all files in the directory.
  3249. * List Directory Entry:
  3250. If it's turned on, list directory entries besides file entries.
  3251. 1c. PostScript file:
  3252. * PostScript File:
  3253. Specify an existent PostScript file to print/preview.
  3254. * PostScript Utility:
  3255. Select a PostScript utility.
  3256. See `pr-ps-utility-alist' and `pr-setting-database' for documentation.
  3257. NOTE 2: Don't forget to download and install the utilities declared on
  3258. `pr-ps-utility-alist'.
  3259. * No Preprocessing:
  3260. If it's turned on, don't use the PostScript utility to preprocess the
  3261. PostScript file before printing/previewing.
  3262. 2. PostScript printer:
  3263. * PostScript Printer:
  3264. You can select a new PostScript printer to send PostScript code
  3265. generated. For selection it's used all PostScript printers defined
  3266. in `pr-ps-printer-alist' variable (see it for documentation).
  3267. See also `pr-setting-database'.
  3268. * Despool:
  3269. If spooling is on, you can turn it on/off, as you wish.
  3270. If spooling is off, it'll not be possible to turn it on.
  3271. If it's turned on, specify to despools the PostScript spooling buffer in
  3272. a temporary file or in the selected PostScript file when
  3273. printing/previewing.
  3274. * Preview:
  3275. Preview the PostScript generated.
  3276. * Print:
  3277. Print the PostScript generated.
  3278. * Quit:
  3279. Quit from printing interface buffer.
  3280. * Send to Printer/Temporary File:
  3281. If it's turned on, the PostScript generated is sent directly to
  3282. PostScript printer or, for previewing, to a temporary file.
  3283. * Send to File:
  3284. Specify a file name to send the PostScript generated.
  3285. * N-Up:
  3286. Specify n-up printing.
  3287. 3. Text printer:
  3288. * Text Printer:
  3289. Select a new text printer to send text generated. For selection it's used
  3290. all text printers defined in `pr-txt-printer-alist' variable (see it for
  3291. documentation). See also `pr-setting-database'.
  3292. * Printify:
  3293. If you have control characters (character code from \\000 to \\037) in a
  3294. buffer and you want to print them in a text printer, select this
  3295. option. All control characters in your buffer or region will be
  3296. replaced by a printable representation. The printable representations
  3297. use ^ (for ASCII control characters) or hex. The characters tab,
  3298. linefeed, space, return and formfeed are not affected.
  3299. You don't need to select this option if you use any option of section
  3300. I, the PostScript engine treats control characters properly.
  3301. * Print:
  3302. To print a directory, buffer, region or major mode in a
  3303. text printer, select this option. See also the NOTE 1 on section 1.
  3304. * Quit:
  3305. Quit from printing interface buffer.
  3306. 4. Settings:
  3307. There are 3 setting columns:
  3308. 4a. First column (left column):
  3309. * Landscape:
  3310. PostScript landscape printing.
  3311. * Print Header:
  3312. To have a header in each page in your PostScript code.
  3313. * Print Header Frame:
  3314. To draw a gaudy frame around the header.
  3315. * Line Number:
  3316. The line number is printed in your PostScript code.
  3317. * Zebra Stripes:
  3318. Background zebra stripes in your PostScript code.
  3319. * Duplex:
  3320. Duplex printing (if your PostScript printer has this feature).
  3321. * Tumble:
  3322. If duplex printing is on, you can choose if you want to have a
  3323. printing suitable for binding on the left or right (tumble off), or to
  3324. have a printing suitable for binding at top or bottom (tumble on).
  3325. * Upside-Down:
  3326. PostScript upside-down printing.
  3327. 4b. Second column (middle column):
  3328. * Auto Region:
  3329. If you want that region is automagically detected, turn on this
  3330. option. Note that this will only work if you're using transient mark
  3331. mode. When this option is on, the `*-buffer*' commands will behave
  3332. like `*-region*' commands, that is, `*-buffer*' commands will print
  3333. only the region marked instead of all buffer.
  3334. * Auto Mode:
  3335. Turn this option on if you want that when current major-mode is
  3336. declared in `pr-mode-alist', the `*-buffer*' and `*-region*' commands
  3337. behave like `*-mode*' commands.
  3338. * Menu Lock:
  3339. If you want that Printing menu stays open while you are setting
  3340. toggle options, turn on this option. The variables
  3341. `pr-menu-char-height' and `pr-menu-char-width' are used to guess the
  3342. menu position, so don't forget to adjust these variables if menu
  3343. position is not ok.
  3344. * Spool Buffer:
  3345. To spool the PostScript code generated. You can despool later by
  3346. setting Despool option on PostScript printer section.
  3347. * Print with faces:
  3348. If you use colors in your buffers and want to see these colors on your
  3349. PostScript code generated, turn on this option. If you have a
  3350. black/white PostScript printer, these colors are displayed in gray
  3351. scale by PostScript printer interpreter.
  3352. * Print via Ghostscript:
  3353. If you don't have a PostScript printer to send PostScript files, turn
  3354. on this option. When this option is on, the ghostscript is used to
  3355. print PostScript files. In GNU or Unix system, if ghostscript is set
  3356. as a PostScript filter, you don't need to turn on this option.
  3357. * Parity Page Menu:
  3358. To print all pages, odd pages, even pages, odd sheets or even sheets.
  3359. See also `ps-even-or-odd-pages'.
  3360. 4c. Third column (right column):
  3361. * Verbose:
  3362. That is, to be verbose when editing a field in interface buffer.
  3363. 5. Customize:
  3364. Besides all options in section 4, you can customize much more PostScript
  3365. options in `ps-print' option. Or you can customize some `lpr' options for
  3366. text printing. Or customize `printing' options.
  3367. 6. Show settings:
  3368. Show current settings for `printing', `ps-print' or `lpr'.
  3369. 7. Help:
  3370. Quick help for printing interface buffer and printing menu layout. You can
  3371. also quit the printing interface buffer or kill all printing help buffer.
  3372. ")
  3373. "Printing buffer interface help message.")
  3374. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3375. ;; Commands
  3376. ;;;###autoload
  3377. (defun pr-interface (&optional buffer)
  3378. "Activate the printing interface buffer.
  3379. If BUFFER is nil, the current buffer is used for printing.
  3380. For more information, type \\[pr-interface-help]."
  3381. (interactive)
  3382. (with-current-buffer (or buffer (current-buffer))
  3383. (pr-create-interface)))
  3384. ;;;###autoload
  3385. (defun pr-ps-directory-preview (n-up dir file-regexp &optional filename)
  3386. "Preview directory using ghostview.
  3387. Interactively, the command prompts for N-UP printing number, a directory, a
  3388. file name regexp for matching and, when you use a prefix argument (C-u), the
  3389. command prompts the user for a file name, and saves the PostScript image in
  3390. that file instead of saving it in a temporary file.
  3391. Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
  3392. nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
  3393. FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
  3394. save the image in a temporary file. If FILENAME is a string, save the
  3395. PostScript image in a file with that name. If FILENAME is t, prompts for a
  3396. file name.
  3397. See also documentation for `pr-list-directory'."
  3398. (interactive (pr-interactive-ps-dir-args (pr-prompt "PS preview dir")))
  3399. (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
  3400. (pr-prompt "PS preview dir"))
  3401. (setq filename (pr-ps-file filename))
  3402. (pr-ps-file-list n-up dir file-regexp filename)
  3403. (or pr-spool-p
  3404. (pr-ps-file-preview filename)))
  3405. ;;;###autoload
  3406. (defun pr-ps-directory-using-ghostscript (n-up dir file-regexp &optional filename)
  3407. "Print directory using PostScript through ghostscript.
  3408. Interactively, the command prompts for N-UP printing number, a directory, a
  3409. file name regexp for matching and, when you use a prefix argument (C-u), the
  3410. command prompts the user for a file name, and saves the PostScript image in
  3411. that file instead of saving it in a temporary file.
  3412. Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
  3413. nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
  3414. FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
  3415. save the image in a temporary file. If FILENAME is a string, save the
  3416. PostScript image in a file with that name. If FILENAME is t, prompts for a
  3417. file name.
  3418. See also documentation for `pr-list-directory'."
  3419. (interactive (pr-interactive-ps-dir-args (pr-prompt "PS print dir GS")))
  3420. (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
  3421. (pr-prompt "PS print dir GS"))
  3422. (let ((file (pr-ps-file filename)))
  3423. (pr-ps-file-list n-up dir file-regexp file)
  3424. (pr-ps-file-using-ghostscript file)
  3425. (or filename (pr-delete-file file))))
  3426. ;;;###autoload
  3427. (defun pr-ps-directory-print (n-up dir file-regexp &optional filename)
  3428. "Print directory using PostScript printer.
  3429. Interactively, the command prompts for N-UP printing number, a directory, a
  3430. file name regexp for matching and, when you use a prefix argument (C-u), the
  3431. command prompts the user for a file name, and saves the PostScript image in
  3432. that file instead of saving it in a temporary file.
  3433. Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
  3434. nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
  3435. FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
  3436. save the image in a temporary file. If FILENAME is a string, save the
  3437. PostScript image in a file with that name. If FILENAME is t, prompts for a
  3438. file name.
  3439. See also documentation for `pr-list-directory'."
  3440. (interactive (pr-interactive-ps-dir-args (pr-prompt "PS print dir")))
  3441. (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
  3442. (pr-prompt "PS print dir"))
  3443. (let ((file (pr-ps-file filename)))
  3444. (pr-ps-file-list n-up dir file-regexp file)
  3445. (pr-ps-file-print file)
  3446. (or filename (pr-delete-file file))))
  3447. ;;;###autoload
  3448. (defun pr-ps-directory-ps-print (n-up dir file-regexp &optional filename)
  3449. "Print directory using PostScript printer or through ghostscript.
  3450. It depends on `pr-print-using-ghostscript'.
  3451. Interactively, the command prompts for N-UP printing number, a directory, a
  3452. file name regexp for matching and, when you use a prefix argument (C-u), the
  3453. command prompts the user for a file name, and saves the PostScript image in
  3454. that file instead of saving it in a temporary file.
  3455. Noninteractively, if N-UP is nil, prompts for N-UP printing number. If DIR is
  3456. nil, prompts for DIRectory. If FILE-REGEXP is nil, prompts for
  3457. FILE(name)-REGEXP. The argument FILENAME is treated as follows: if it's nil,
  3458. save the image in a temporary file. If FILENAME is a string, save the
  3459. PostScript image in a file with that name. If FILENAME is t, prompts for a
  3460. file name.
  3461. See also documentation for `pr-list-directory'."
  3462. (interactive (pr-interactive-ps-dir-args
  3463. (pr-prompt (pr-prompt-gs "PS print dir"))))
  3464. (pr-set-ps-dir-args 'n-up 'dir 'file-regexp 'filename
  3465. (pr-prompt (pr-prompt-gs "PS print dir")))
  3466. (if (pr-using-ghostscript-p)
  3467. (pr-ps-directory-using-ghostscript n-up dir file-regexp filename)
  3468. (pr-ps-directory-print n-up dir file-regexp filename)))
  3469. ;;;###autoload
  3470. (defun pr-ps-buffer-preview (n-up &optional filename)
  3471. "Preview buffer using ghostview.
  3472. Interactively, the command prompts for N-UP printing number and, when you use a
  3473. prefix argument (C-u), the command prompts the user for a file name, and saves
  3474. the PostScript image in that file instead of saving it in a temporary file.
  3475. Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
  3476. argument FILENAME is treated as follows: if it's nil, save the image in a
  3477. temporary file. If FILENAME is a string, save the PostScript image in a file
  3478. with that name. If FILENAME is t, prompts for a file name."
  3479. (interactive (pr-interactive-n-up-file (pr-prompt "PS preview")))
  3480. (if (pr-auto-mode-p)
  3481. (pr-ps-mode-preview n-up filename)
  3482. (pr-ps-preview (pr-region-active-symbol) n-up filename
  3483. (pr-region-active-string "PS preview"))))
  3484. ;;;###autoload
  3485. (defun pr-ps-buffer-using-ghostscript (n-up &optional filename)
  3486. "Print buffer using PostScript through ghostscript.
  3487. Interactively, the command prompts for N-UP printing number and, when you use a
  3488. prefix argument (C-u), the command prompts the user for a file name, and saves
  3489. the PostScript image in that file instead of sending it to the printer.
  3490. Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
  3491. argument FILENAME is treated as follows: if it's nil, send the image to the
  3492. printer. If FILENAME is a string, save the PostScript image in a file with
  3493. that name. If FILENAME is t, prompts for a file name."
  3494. (interactive (pr-interactive-n-up-file (pr-prompt "PS print GS")))
  3495. (if (pr-auto-mode-p)
  3496. (pr-ps-mode-using-ghostscript n-up filename)
  3497. (pr-ps-using-ghostscript (pr-region-active-symbol) n-up filename
  3498. (pr-region-active-string "PS print GS"))))
  3499. ;;;###autoload
  3500. (defun pr-ps-buffer-print (n-up &optional filename)
  3501. "Print buffer using PostScript printer.
  3502. Interactively, the command prompts for N-UP printing number and, when you use a
  3503. prefix argument (C-u), the command prompts the user for a file name, and saves
  3504. the PostScript image in that file instead of sending it to the printer.
  3505. Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
  3506. argument FILENAME is treated as follows: if it's nil, send the image to the
  3507. printer. If FILENAME is a string, save the PostScript image in a file with
  3508. that name. If FILENAME is t, prompts for a file name."
  3509. (interactive (pr-interactive-n-up-file (pr-prompt "PS print")))
  3510. (if (pr-auto-mode-p)
  3511. (pr-ps-mode-print n-up filename)
  3512. (pr-ps-print (pr-region-active-symbol) n-up filename
  3513. (pr-region-active-string "PS print"))))
  3514. ;;;###autoload
  3515. (defun pr-ps-buffer-ps-print (n-up &optional filename)
  3516. "Print buffer using PostScript printer or through ghostscript.
  3517. It depends on `pr-print-using-ghostscript'.
  3518. Interactively, the command prompts for N-UP printing number and, when you use a
  3519. prefix argument (C-u), the command prompts the user for a file name, and saves
  3520. the PostScript image in that file instead of sending it to the printer.
  3521. Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
  3522. argument FILENAME is treated as follows: if it's nil, send the image to the
  3523. printer. If FILENAME is a string, save the PostScript image in a file with
  3524. that name. If FILENAME is t, prompts for a file name."
  3525. (interactive (pr-interactive-n-up-file
  3526. (pr-prompt (pr-prompt-gs "PS print"))))
  3527. (cond ((pr-auto-mode-p)
  3528. (pr-ps-mode-ps-print n-up filename))
  3529. ((pr-using-ghostscript-p)
  3530. (pr-ps-using-ghostscript (pr-region-active-symbol) n-up filename
  3531. (pr-region-active-string "PS print GS")))
  3532. (t
  3533. (pr-ps-print (pr-region-active-symbol) n-up filename
  3534. (pr-region-active-string "PS print")))))
  3535. ;;;###autoload
  3536. (defun pr-ps-region-preview (n-up &optional filename)
  3537. "Preview region using ghostview.
  3538. See also `pr-ps-buffer-preview'."
  3539. (interactive (pr-interactive-n-up-file (pr-prompt-region "PS preview")))
  3540. (if (pr-auto-mode-p)
  3541. (let ((pr-auto-region t))
  3542. (pr-ps-mode-preview n-up filename))
  3543. (pr-ps-preview 'region n-up filename "PS preview region")))
  3544. ;;;###autoload
  3545. (defun pr-ps-region-using-ghostscript (n-up &optional filename)
  3546. "Print region using PostScript through ghostscript.
  3547. See also `pr-ps-buffer-using-ghostscript'."
  3548. (interactive (pr-interactive-n-up-file (pr-prompt-region "PS print GS")))
  3549. (if (pr-auto-mode-p)
  3550. (let ((pr-auto-region t))
  3551. (pr-ps-mode-using-ghostscript n-up filename))
  3552. (pr-ps-using-ghostscript 'region n-up filename "PS print GS region")))
  3553. ;;;###autoload
  3554. (defun pr-ps-region-print (n-up &optional filename)
  3555. "Print region using PostScript printer.
  3556. See also `pr-ps-buffer-print'."
  3557. (interactive (pr-interactive-n-up-file (pr-prompt-region "PS print")))
  3558. (if (pr-auto-mode-p)
  3559. (let ((pr-auto-region t))
  3560. (pr-ps-mode-print n-up filename))
  3561. (pr-ps-print 'region n-up filename "PS print region")))
  3562. ;;;###autoload
  3563. (defun pr-ps-region-ps-print (n-up &optional filename)
  3564. "Print region using PostScript printer or through ghostscript.
  3565. See also `pr-ps-buffer-ps-print'."
  3566. (interactive (pr-interactive-n-up-file
  3567. (pr-prompt-region (pr-prompt-gs "PS print"))))
  3568. (cond ((pr-auto-mode-p)
  3569. (let ((pr-auto-region t))
  3570. (pr-ps-mode-ps-print n-up filename)))
  3571. ((pr-using-ghostscript-p)
  3572. (pr-ps-using-ghostscript 'region n-up filename "PS print GS region"))
  3573. (t
  3574. (pr-ps-print 'region n-up filename "PS print region"))))
  3575. ;;;###autoload
  3576. (defun pr-ps-mode-preview (n-up &optional filename)
  3577. "Preview major mode using ghostview.
  3578. See also `pr-ps-buffer-preview'."
  3579. (interactive (pr-interactive-n-up-file "PS preview mode"))
  3580. (pr-set-n-up-and-filename 'n-up 'filename "PS preview mode")
  3581. (let ((file (pr-ps-file filename)))
  3582. (and (pr-ps-mode n-up file)
  3583. (not pr-spool-p)
  3584. (pr-ps-file-preview file))))
  3585. ;;;###autoload
  3586. (defun pr-ps-mode-using-ghostscript (n-up &optional filename)
  3587. "Print major mode using PostScript through ghostscript.
  3588. See also `pr-ps-buffer-using-ghostscript'."
  3589. (interactive (pr-interactive-n-up-file "PS print GS mode"))
  3590. (pr-set-n-up-and-filename 'n-up 'filename "PS print GS mode")
  3591. (let ((file (pr-ps-file filename)))
  3592. (when (and (pr-ps-mode n-up file)
  3593. (not pr-spool-p))
  3594. (pr-ps-file-using-ghostscript file)
  3595. (or filename (pr-delete-file file)))))
  3596. ;;;###autoload
  3597. (defun pr-ps-mode-print (n-up &optional filename)
  3598. "Print major mode using PostScript printer.
  3599. See also `pr-ps-buffer-print'."
  3600. (interactive (pr-interactive-n-up-file "PS print mode"))
  3601. (pr-set-n-up-and-filename 'n-up 'filename "PS print mode")
  3602. (pr-ps-mode n-up filename))
  3603. ;;;###autoload
  3604. (defun pr-ps-mode-ps-print (n-up &optional filename)
  3605. "Print major mode using PostScript or through ghostscript.
  3606. See also `pr-ps-buffer-ps-print'."
  3607. (interactive (pr-interactive-n-up-file (pr-prompt-gs "PS print mode")))
  3608. (if (pr-using-ghostscript-p)
  3609. (pr-ps-mode-using-ghostscript n-up filename)
  3610. (pr-ps-mode-print n-up filename)))
  3611. ;;;###autoload
  3612. (defun pr-printify-directory (&optional dir file-regexp)
  3613. "Replace nonprinting characters in directory with printable representations.
  3614. The printable representations use ^ (for ASCII control characters) or hex.
  3615. The characters tab, linefeed, space, return and formfeed are not affected.
  3616. Interactively, the command prompts for a directory and a file name regexp for
  3617. matching.
  3618. Noninteractively, if DIR is nil, prompts for DIRectory. If FILE-REGEXP is nil,
  3619. prompts for FILE(name)-REGEXP.
  3620. See also documentation for `pr-list-directory'."
  3621. (interactive (pr-interactive-dir-args "Printify dir"))
  3622. (pr-set-dir-args 'dir 'file-regexp "Printify dir")
  3623. (pr-file-list dir file-regexp 'pr-printify-buffer))
  3624. ;;;###autoload
  3625. (defun pr-printify-buffer ()
  3626. "Replace nonprinting characters in buffer with printable representations.
  3627. The printable representations use ^ (for ASCII control characters) or hex.
  3628. The characters tab, linefeed, space, return and formfeed are not affected."
  3629. (interactive "*")
  3630. (if (pr-region-active-p)
  3631. (pr-printify-region)
  3632. (printify-region (point-min) (point-max))))
  3633. ;;;###autoload
  3634. (defun pr-printify-region ()
  3635. "Replace nonprinting characters in region with printable representations.
  3636. The printable representations use ^ (for ASCII control characters) or hex.
  3637. The characters tab, linefeed, space, return and formfeed are not affected."
  3638. (interactive "*")
  3639. (printify-region (point) (mark)))
  3640. ;;;###autoload
  3641. (defun pr-txt-directory (&optional dir file-regexp)
  3642. "Print directory using text printer.
  3643. Interactively, the command prompts for a directory and a file name regexp for
  3644. matching.
  3645. Noninteractively, if DIR is nil, prompts for DIRectory. If FILE-REGEXP is nil,
  3646. prompts for FILE(name)-REGEXP.
  3647. See also documentation for `pr-list-directory'."
  3648. (interactive (pr-interactive-dir-args "Print dir"))
  3649. (pr-set-dir-args 'dir 'file-regexp "Print dir")
  3650. (pr-file-list dir file-regexp 'pr-txt-buffer))
  3651. ;;;###autoload
  3652. (defun pr-txt-buffer ()
  3653. "Print buffer using text printer."
  3654. (interactive)
  3655. (cond ((pr-auto-mode-p)
  3656. (pr-txt-mode))
  3657. ((pr-region-active-p)
  3658. (pr-txt-region))
  3659. (t
  3660. (pr-txt-print (point-min) (point-max)))))
  3661. ;;;###autoload
  3662. (defun pr-txt-region ()
  3663. "Print region using text printer."
  3664. (interactive)
  3665. (if (pr-auto-mode-p)
  3666. (let ((pr-auto-region t))
  3667. (pr-txt-mode))
  3668. (pr-txt-print (point) (mark))))
  3669. ;;;###autoload
  3670. (defun pr-txt-mode ()
  3671. "Print major mode using text printer."
  3672. (interactive)
  3673. (let ((args (pr-mode-alist-p)))
  3674. (if args
  3675. (funcall (car args) (nthcdr 2 args))
  3676. (ding)
  3677. (message "`%s' major mode not declared." major-mode))))
  3678. ;;;###autoload
  3679. (defun pr-despool-preview (&optional filename)
  3680. "Preview spooled PostScript.
  3681. Interactively, when you use a prefix argument (C-u), the command prompts the
  3682. user for a file name, and saves the spooled PostScript image in that file
  3683. instead of saving it in a temporary file.
  3684. Noninteractively, the argument FILENAME is treated as follows: if it is nil,
  3685. save the image in a temporary file. If FILENAME is a string, save the
  3686. PostScript image in a file with that name."
  3687. (interactive (list (ps-print-preprint current-prefix-arg)))
  3688. (let ((file (pr-ps-file filename)))
  3689. (when (stringp file)
  3690. (pr-despool-print file)
  3691. (pr-ps-file-preview file))))
  3692. ;;;###autoload
  3693. (defun pr-despool-using-ghostscript (&optional filename)
  3694. "Print spooled PostScript using ghostscript.
  3695. Interactively, when you use a prefix argument (C-u), the command prompts the
  3696. user for a file name, and saves the spooled PostScript image in that file
  3697. instead of sending it to the printer.
  3698. Noninteractively, the argument FILENAME is treated as follows: if it is nil,
  3699. send the image to the printer. If FILENAME is a string, save the PostScript
  3700. image in a file with that name."
  3701. (interactive (list (ps-print-preprint current-prefix-arg)))
  3702. (let ((file (pr-ps-file filename)))
  3703. (when (stringp file)
  3704. (pr-despool-print file)
  3705. (pr-ps-file-using-ghostscript file)
  3706. (or filename (pr-delete-file file)))))
  3707. ;;;###autoload
  3708. (defun pr-despool-print (&optional filename)
  3709. "Send the spooled PostScript to the printer.
  3710. Interactively, when you use a prefix argument (C-u), the command prompts the
  3711. user for a file name, and saves the spooled PostScript image in that file
  3712. instead of sending it to the printer.
  3713. Noninteractively, the argument FILENAME is treated as follows: if it is nil,
  3714. send the image to the printer. If FILENAME is a string, save the PostScript
  3715. image in a file with that name."
  3716. (interactive (list (ps-print-preprint current-prefix-arg)))
  3717. (with-file-modes pr-file-modes
  3718. (let ((ps-lpr-command (pr-command pr-ps-command))
  3719. (ps-lpr-switches pr-ps-switches)
  3720. (ps-printer-name-option pr-ps-printer-switch)
  3721. (ps-printer-name pr-ps-printer))
  3722. (ps-despool filename))))
  3723. ;;;###autoload
  3724. (defun pr-despool-ps-print (&optional filename)
  3725. "Send the spooled PostScript to the printer or use ghostscript to print it.
  3726. Interactively, when you use a prefix argument (C-u), the command prompts the
  3727. user for a file name, and saves the spooled PostScript image in that file
  3728. instead of sending it to the printer.
  3729. Noninteractively, the argument FILENAME is treated as follows: if it is nil,
  3730. send the image to the printer. If FILENAME is a string, save the PostScript
  3731. image in a file with that name."
  3732. (interactive (list (ps-print-preprint current-prefix-arg)))
  3733. (if pr-print-using-ghostscript
  3734. (pr-despool-using-ghostscript filename)
  3735. (pr-despool-print filename)))
  3736. ;;;###autoload
  3737. (defun pr-ps-file-preview (filename)
  3738. "Preview PostScript file FILENAME."
  3739. (interactive (list (pr-ps-infile-preprint "Preview ")))
  3740. (and (stringp filename) (file-exists-p filename)
  3741. (pr-call-process pr-gv-command filename)))
  3742. ;;;###autoload
  3743. (defun pr-ps-file-up-preview (n-up ifilename &optional ofilename)
  3744. "Preview PostScript file FILENAME."
  3745. (interactive (pr-interactive-n-up-inout "PS preview"))
  3746. (let ((outfile (pr-ps-utility-args 'n-up 'ifilename 'ofilename
  3747. "PS preview ")))
  3748. (pr-ps-utility-process n-up ifilename outfile)
  3749. (pr-ps-file-preview outfile)))
  3750. ;;;###autoload
  3751. (defun pr-ps-file-using-ghostscript (filename)
  3752. "Print PostScript file FILENAME using ghostscript."
  3753. (interactive (list (pr-ps-infile-preprint "Print preview ")))
  3754. (and (stringp filename) (file-exists-p filename)
  3755. (let* ((file (pr-expand-file-name filename))
  3756. (tempfile (pr-dosify-file-name (make-temp-file file))))
  3757. ;; gs use
  3758. (pr-call-process pr-gs-command
  3759. (format "-sDEVICE=%s" pr-gs-device)
  3760. (format "-r%d" pr-gs-resolution)
  3761. (pr-switches-string pr-gs-switches "pr-gs-switches")
  3762. (format "-sOutputFile=\"%s\"" tempfile)
  3763. file
  3764. "-c quit")
  3765. ;; printing
  3766. (pr-ps-file-print tempfile)
  3767. ;; deleting
  3768. (pr-delete-file tempfile))))
  3769. ;;;###autoload
  3770. (defun pr-ps-file-print (filename)
  3771. "Print PostScript file FILENAME."
  3772. (interactive (list (pr-ps-infile-preprint "Print ")))
  3773. (and (stringp filename) (file-exists-p filename)
  3774. ;; printing
  3775. (let ((file (pr-expand-file-name filename)))
  3776. (if (string= pr-ps-command "")
  3777. ;; default action
  3778. (let ((ps-spool-buffer (get-buffer-create ps-spool-buffer-name)))
  3779. (with-current-buffer ps-spool-buffer
  3780. (erase-buffer)
  3781. (insert-file-contents-literally file))
  3782. (pr-despool-print))
  3783. ;; use `pr-ps-command' to print
  3784. (apply 'pr-call-process
  3785. pr-ps-command
  3786. (pr-switches-string pr-ps-switches "pr-ps-switches")
  3787. (if (string-match "cp" pr-ps-command)
  3788. ;; for "cp" (cmd in out)
  3789. (list file
  3790. (concat pr-ps-printer-switch pr-ps-printer))
  3791. ;; else, for others (cmd out in)
  3792. (list (concat pr-ps-printer-switch pr-ps-printer)
  3793. file)))))))
  3794. ;;;###autoload
  3795. (defun pr-ps-file-ps-print (filename)
  3796. "Send PostScript file FILENAME to printer or use ghostscript to print it."
  3797. (interactive (list (pr-ps-infile-preprint
  3798. (if pr-print-using-ghostscript
  3799. "Print preview "
  3800. "Print "))))
  3801. (if pr-print-using-ghostscript
  3802. (pr-ps-file-using-ghostscript filename)
  3803. (pr-ps-file-print filename)))
  3804. ;;;###autoload
  3805. (defun pr-ps-file-up-ps-print (n-up ifilename &optional ofilename)
  3806. "Process a PostScript file IFILENAME and send it to printer.
  3807. Interactively, the command prompts for N-UP printing number, for an input
  3808. PostScript file IFILENAME and, when you use a prefix argument (C-u), the
  3809. command prompts the user for an output PostScript file name OFILENAME, and
  3810. saves the PostScript image in that file instead of sending it to the printer.
  3811. Noninteractively, if N-UP is nil, prompts for N-UP printing number. The
  3812. argument IFILENAME is treated as follows: if it's t, prompts for an input
  3813. PostScript file name; otherwise, it *must* be a string that it's an input
  3814. PostScript file name. The argument OFILENAME is treated as follows: if it's
  3815. nil, send the image to the printer. If OFILENAME is a string, save the
  3816. PostScript image in a file with that name. If OFILENAME is t, prompts for a
  3817. file name."
  3818. (interactive (pr-interactive-n-up-inout
  3819. (if pr-print-using-ghostscript
  3820. "PS print GS"
  3821. "PS print")))
  3822. (let ((outfile (pr-ps-utility-args 'n-up 'ifilename 'ofilename
  3823. (if pr-print-using-ghostscript
  3824. "PS print GS "
  3825. "PS print "))))
  3826. (pr-ps-utility-process n-up ifilename outfile)
  3827. (unless ofilename
  3828. (pr-ps-file-ps-print outfile)
  3829. (pr-delete-file outfile))))
  3830. ;;;###autoload
  3831. (defun pr-toggle-file-duplex ()
  3832. "Toggle duplex for PostScript file."
  3833. (interactive)
  3834. (pr-toggle-file-duplex-menu t))
  3835. ;;;###autoload
  3836. (defun pr-toggle-file-tumble ()
  3837. "Toggle tumble for PostScript file.
  3838. If tumble is off, produces a printing suitable for binding on the left or
  3839. right.
  3840. If tumble is on, produces a printing suitable for binding at the top or
  3841. bottom."
  3842. (interactive)
  3843. (pr-toggle-file-tumble-menu t))
  3844. ;;;###autoload
  3845. (defun pr-toggle-file-landscape ()
  3846. "Toggle landscape for PostScript file."
  3847. (interactive)
  3848. (pr-toggle-file-landscape-menu t))
  3849. ;;;###autoload
  3850. (defun pr-toggle-ghostscript ()
  3851. "Toggle printing using ghostscript."
  3852. (interactive)
  3853. (pr-toggle-ghostscript-menu t))
  3854. ;;;###autoload
  3855. (defun pr-toggle-faces ()
  3856. "Toggle printing with faces."
  3857. (interactive)
  3858. (pr-toggle-faces-menu t))
  3859. ;;;###autoload
  3860. (defun pr-toggle-spool ()
  3861. "Toggle spooling."
  3862. (interactive)
  3863. (pr-toggle-spool-menu t))
  3864. ;;;###autoload
  3865. (defun pr-toggle-duplex ()
  3866. "Toggle duplex."
  3867. (interactive)
  3868. (pr-toggle-duplex-menu t))
  3869. ;;;###autoload
  3870. (defun pr-toggle-tumble ()
  3871. "Toggle tumble.
  3872. If tumble is off, produces a printing suitable for binding on the left or
  3873. right.
  3874. If tumble is on, produces a printing suitable for binding at the top or
  3875. bottom."
  3876. (interactive)
  3877. (pr-toggle-tumble-menu t))
  3878. ;;;###autoload
  3879. (defun pr-toggle-landscape ()
  3880. "Toggle landscape."
  3881. (interactive)
  3882. (pr-toggle-landscape-menu t))
  3883. ;;;###autoload
  3884. (defun pr-toggle-upside-down ()
  3885. "Toggle upside-down."
  3886. (interactive)
  3887. (pr-toggle-upside-down-menu t))
  3888. ;;;###autoload
  3889. (defun pr-toggle-line ()
  3890. "Toggle line number."
  3891. (interactive)
  3892. (pr-toggle-line-menu t))
  3893. ;;;###autoload
  3894. (defun pr-toggle-zebra ()
  3895. "Toggle zebra stripes."
  3896. (interactive)
  3897. (pr-toggle-zebra-menu t))
  3898. ;;;###autoload
  3899. (defun pr-toggle-header ()
  3900. "Toggle printing header."
  3901. (interactive)
  3902. (pr-toggle-header-menu t))
  3903. ;;;###autoload
  3904. (defun pr-toggle-header-frame ()
  3905. "Toggle printing header frame."
  3906. (interactive)
  3907. (pr-toggle-header-frame-menu t))
  3908. ;;;###autoload
  3909. (defun pr-toggle-lock ()
  3910. "Toggle menu lock."
  3911. (interactive)
  3912. (pr-toggle-lock-menu t))
  3913. ;;;###autoload
  3914. (defun pr-toggle-region ()
  3915. "Toggle whether the region is automagically detected."
  3916. (interactive)
  3917. (pr-toggle-region-menu t))
  3918. ;;;###autoload
  3919. (defun pr-toggle-mode ()
  3920. "Toggle auto mode."
  3921. (interactive)
  3922. (pr-toggle-mode-menu t))
  3923. ;;;###autoload
  3924. (defun pr-customize (&rest _ignore)
  3925. "Customization of the `printing' group."
  3926. (interactive)
  3927. (customize-group 'printing))
  3928. ;;;###autoload
  3929. (defun lpr-customize (&rest _ignore)
  3930. "Customization of the `lpr' group."
  3931. (interactive)
  3932. (customize-group 'lpr))
  3933. ;;;###autoload
  3934. (defun pr-help (&rest _ignore)
  3935. "Help for the printing package."
  3936. (interactive)
  3937. (pr-show-setup pr-help-message "*Printing Help*"))
  3938. ;;;###autoload
  3939. (defun pr-ps-name ()
  3940. "Interactively select a PostScript printer."
  3941. (interactive)
  3942. (pr-menu-set-ps-title
  3943. (pr-complete-alist "PostScript printer"
  3944. pr-ps-printer-alist pr-ps-name)))
  3945. ;;;###autoload
  3946. (defun pr-txt-name ()
  3947. "Interactively select a text printer."
  3948. (interactive)
  3949. (pr-menu-set-txt-title
  3950. (pr-complete-alist "Text printer"
  3951. pr-txt-printer-alist pr-txt-name)))
  3952. ;;;###autoload
  3953. (defun pr-ps-utility ()
  3954. "Interactively select a PostScript utility."
  3955. (interactive)
  3956. (pr-menu-set-utility-title
  3957. (pr-complete-alist "PostScript utility"
  3958. pr-ps-utility-alist pr-ps-utility)))
  3959. ;;;###autoload
  3960. (defun pr-show-ps-setup (&rest _ignore)
  3961. "Show current ps-print settings."
  3962. (interactive)
  3963. (pr-show-setup (ps-setup) "*PS Setup*"))
  3964. ;;;###autoload
  3965. (defun pr-show-pr-setup (&rest _ignore)
  3966. "Show current printing settings."
  3967. (interactive)
  3968. (pr-show-setup (pr-setup) "*PR Setup*"))
  3969. ;;;###autoload
  3970. (defun pr-show-lpr-setup (&rest _ignore)
  3971. "Show current lpr settings."
  3972. (interactive)
  3973. (pr-show-setup (lpr-setup) "*LPR Setup*"))
  3974. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3975. ;; Fast Commands
  3976. ;;;###autoload
  3977. (defun pr-ps-fast-fire (n-up &optional select)
  3978. "Fast fire function for PostScript printing.
  3979. If a region is active, the region will be printed instead of the whole buffer.
  3980. Also if the current major-mode is defined in `pr-mode-alist', the settings in
  3981. `pr-mode-alist' will be used, that is, the current buffer or region will be
  3982. printed using `pr-ps-mode-ps-print'.
  3983. Interactively, you have the following situations:
  3984. M-x pr-ps-fast-fire RET
  3985. The command prompts the user for a N-UP value and printing will
  3986. immediately be done using the current active printer.
  3987. C-u M-x pr-ps-fast-fire RET
  3988. C-u 0 M-x pr-ps-fast-fire RET
  3989. The command prompts the user for a N-UP value and also for a current
  3990. PostScript printer, then printing will immediately be done using the new
  3991. current active printer.
  3992. C-u 1 M-x pr-ps-fast-fire RET
  3993. The command prompts the user for a N-UP value and also for a file name,
  3994. and saves the PostScript image in that file instead of sending it to the
  3995. printer.
  3996. C-u 2 M-x pr-ps-fast-fire RET
  3997. The command prompts the user for a N-UP value, then for a current
  3998. PostScript printer and, finally, for a file name. Then change the active
  3999. printer to that chosen by user and saves the PostScript image in
  4000. that file instead of sending it to the printer.
  4001. Noninteractively, the argument N-UP should be a positive integer greater than
  4002. zero and the argument SELECT is treated as follows:
  4003. If it's nil, send the image to the printer.
  4004. If it's a list or an integer lesser or equal to zero, the command prompts
  4005. the user for a current PostScript printer, then printing will immediately
  4006. be done using the new current active printer.
  4007. If it's an integer equal to 1, the command prompts the user for a file name
  4008. and saves the PostScript image in that file instead of sending it to the
  4009. printer.
  4010. If it's an integer greater or equal to 2, the command prompts the user for a
  4011. current PostScript printer and for a file name. Then change the active
  4012. printer to that chosen by user and saves the PostScript image in that file
  4013. instead of sending it to the printer.
  4014. If it's a symbol which it's defined in `pr-ps-printer-alist', it's the new
  4015. active printer and printing will immediately be done using the new active
  4016. printer.
  4017. Otherwise, send the image to the printer.
  4018. Note that this command always behaves as if `pr-auto-region' and `pr-auto-mode'
  4019. are both set to t."
  4020. (interactive (list (pr-interactive-n-up (pr-prompt-gs "PS print fast"))
  4021. current-prefix-arg))
  4022. (let ((pr-auto-region t)
  4023. (pr-auto-mode t)
  4024. filename)
  4025. (cond ((null select))
  4026. ((listp select)
  4027. (pr-ps-name))
  4028. ((and (symbolp select)
  4029. (assq select pr-ps-printer-alist))
  4030. (pr-menu-set-ps-title select))
  4031. ((integerp select)
  4032. (and (/= select 1)
  4033. (pr-ps-name))
  4034. (and (>= select 1) (not pr-spool-p)
  4035. (setq filename (pr-ps-outfile-preprint
  4036. (if pr-print-using-ghostscript
  4037. "Fast GS "
  4038. "Fast "))))))
  4039. (pr-ps-buffer-ps-print
  4040. (if (integerp n-up)
  4041. (min (max n-up 1) 100)
  4042. (error "n-up must be an integer greater than zero"))
  4043. filename)))
  4044. ;;;###autoload
  4045. (defun pr-txt-fast-fire (&optional select-printer)
  4046. "Fast fire function for text printing.
  4047. If a region is active, the region will be printed instead of the whole buffer.
  4048. Also if the current major-mode is defined in `pr-mode-alist', the settings in
  4049. `pr-mode-alist' will be used, that is, the current buffer or region will be
  4050. printed using `pr-txt-mode'.
  4051. Interactively, when you use a prefix argument (C-u), the command prompts the
  4052. user for a new active text printer.
  4053. Noninteractively, the argument SELECT-PRINTER is treated as follows:
  4054. If it's nil, the printing is sent to the current active text printer.
  4055. If it's a symbol which it's defined in `pr-txt-printer-alist', it's the new
  4056. active printer and printing will immediately be done using the new active
  4057. printer.
  4058. If it's non-nil, the command prompts the user for a new active text printer.
  4059. Note that this command always behaves as if `pr-auto-region' and `pr-auto-mode'
  4060. are both set to t."
  4061. (interactive (list current-prefix-arg))
  4062. (cond ((null select-printer))
  4063. ((and (symbolp select-printer)
  4064. (assq select-printer pr-txt-printer-alist))
  4065. (pr-menu-set-txt-title select-printer))
  4066. (t
  4067. (pr-txt-name)))
  4068. (let ((pr-auto-region t)
  4069. (pr-auto-mode t))
  4070. (pr-txt-buffer)))
  4071. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4072. ;; Utilities
  4073. (defun pr-setup ()
  4074. "Return the current `printing' setup.
  4075. This is *not* an interactive command.
  4076. One way to see `printing' setup is to switch to a *Scratch* buffer and type:
  4077. M-: (insert (pr-setup)) RET
  4078. Or choose the menu option Printing/Show Settings/printing."
  4079. (let (ps-prefix-quote)
  4080. (mapconcat
  4081. #'ps-print-quote
  4082. (list
  4083. (concat "\n;;; printing.el version " pr-version "\n")
  4084. ";; internal vars"
  4085. (ps-comment-string "emacs-version " emacs-version)
  4086. (ps-comment-string "pr-txt-command " pr-txt-command)
  4087. (ps-comment-string "pr-txt-switches "
  4088. (pr-switches-string pr-txt-switches "pr-txt-switches"))
  4089. (ps-comment-string "pr-txt-printer " pr-txt-printer)
  4090. (ps-comment-string "pr-ps-command " pr-ps-command)
  4091. (ps-comment-string "pr-ps-switches "
  4092. (pr-switches-string pr-ps-switches "pr-ps-switches"))
  4093. (ps-comment-string "pr-ps-printer-switch" pr-ps-printer-switch)
  4094. (ps-comment-string "pr-ps-printer " pr-ps-printer)
  4095. (ps-comment-string "pr-cygwin-system " pr-cygwin-system)
  4096. (ps-comment-string "lpr-windows-system " lpr-windows-system)
  4097. (ps-comment-string "lpr-lp-system " lpr-lp-system)
  4098. nil
  4099. '(14 . pr-path-style)
  4100. '(14 . pr-path-alist)
  4101. nil
  4102. '(21 . pr-txt-name)
  4103. '(21 . pr-txt-printer-alist)
  4104. nil
  4105. '(20 . pr-ps-name)
  4106. '(20 . pr-ps-printer-alist)
  4107. nil
  4108. '(20 . pr-temp-dir)
  4109. '(20 . pr-ps-temp-file)
  4110. '(20 . pr-file-modes)
  4111. '(20 . pr-delete-temp-file)
  4112. '(20 . pr-list-directory)
  4113. nil
  4114. '(17 . pr-gv-command)
  4115. '(17 . pr-gs-command)
  4116. '(17 . pr-gs-switches)
  4117. '(17 . pr-gs-device)
  4118. '(17 . pr-gs-resolution)
  4119. nil
  4120. '(27 . pr-print-using-ghostscript)
  4121. '(27 . pr-faces-p)
  4122. '(27 . pr-spool-p)
  4123. '(27 . pr-file-landscape)
  4124. '(27 . pr-file-duplex)
  4125. '(27 . pr-file-tumble)
  4126. '(27 . pr-auto-region)
  4127. '(27 . pr-auto-mode)
  4128. nil
  4129. '(20 . pr-ps-utility)
  4130. '(20 . pr-ps-utility-alist)
  4131. nil
  4132. '(14 . pr-mode-alist)
  4133. nil
  4134. '(20 . pr-menu-lock)
  4135. '(20 . pr-menu-char-height)
  4136. '(20 . pr-menu-char-width)
  4137. nil
  4138. '(20 . pr-setting-database)
  4139. nil
  4140. '(22 . pr-visible-entry-list)
  4141. nil
  4142. '(22 . pr-buffer-verbose)
  4143. '(22 . pr-buffer-name)
  4144. '(22 . pr-buffer-name-ignore)
  4145. ")\n\n;;; printing.el - end of settings\n")
  4146. "\n")))
  4147. (defun lpr-setup ()
  4148. "Return the current `lpr' setup.
  4149. This is *not* an interactive command.
  4150. One way to see `lpr' setup is to switch to a *Scratch* buffer and type:
  4151. M-: (insert (lpr-setup)) RET
  4152. Or choose the menu option Printing/Show Settings/lpr."
  4153. (let (ps-prefix-quote)
  4154. (mapconcat
  4155. #'ps-print-quote
  4156. (list
  4157. "\n;;; lpr.el settings\n"
  4158. (ps-comment-string "emacs-version" emacs-version)
  4159. nil
  4160. '(25 . printer-name)
  4161. '(25 . lpr-switches)
  4162. '(25 . lpr-add-switches)
  4163. '(25 . lpr-command)
  4164. '(25 . lpr-headers-switches)
  4165. '(25 . print-region-function)
  4166. '(25 . lpr-page-header-program)
  4167. '(25 . lpr-page-header-switches)
  4168. ")\n\n;;; lpr.el - end of settings\n")
  4169. "\n")))
  4170. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4171. ;; mh-e (adapted from mh-e-init.el -- Tom Vogels <tov@ece.cmu.edu>)
  4172. (declare-function mh-get-msg-num "mh-utils" (error-if-no-message))
  4173. (declare-function mh-show "mh-show" (&optional message redisplay-flag))
  4174. (declare-function mh-start-of-uncleaned-message "mh-show" ())
  4175. (defvar mh-show-buffer)
  4176. (defun pr-article-date ()
  4177. "Find the date of an article or mail message in current buffer.
  4178. Return only the dayname, if present, weekday, month, and year."
  4179. (save-excursion
  4180. (goto-char (point-min))
  4181. (if (re-search-forward
  4182. "^Date:[ \t]+\\(\\([A-Za-z]+, \\)?[0-9]+ [A-Za-z]+ [0-9]+\\)" nil t)
  4183. (buffer-substring (match-beginning 1) (match-end 1))
  4184. (format-time-string "%Y/%m/%d"))))
  4185. (defun pr-mh-current-message ()
  4186. "Go to mh-inbox current message."
  4187. (let ((msg (or (mh-get-msg-num nil) 0)))
  4188. (mh-show)
  4189. (set-buffer mh-show-buffer)
  4190. (goto-char (point-min))
  4191. (mh-start-of-uncleaned-message)
  4192. (message "Printing message %d" msg)))
  4193. (defun pr-mh-print-1 (n-up filename header-list)
  4194. "Print mh-inbox current message in PostScript."
  4195. (save-excursion
  4196. (save-window-excursion
  4197. (pr-mh-current-message)
  4198. (pr-mode-print n-up filename header-list (point)))))
  4199. (defun pr-mh-lpr-1 (header-list)
  4200. "Print mh-inbox current message in text printer."
  4201. (save-excursion
  4202. (save-window-excursion
  4203. (pr-mh-current-message)
  4204. (pr-mode-lpr header-list (point)))))
  4205. (defalias 'pr-mh-print-2 'pr-mode-print)
  4206. (defalias 'pr-mh-lpr-2 'pr-mode-lpr)
  4207. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4208. ;; rmail (hacked from ps-print.el)
  4209. (defun pr-rmail-lpr (header-list)
  4210. "Print RMAIL current message in text printer."
  4211. (pr-lpr-message-from-summary header-list
  4212. 'rmail-buffer 'rmail-summary-buffer))
  4213. (defun pr-rmail-print (n-up filename header-list)
  4214. "Print RMAIL current message in PostScript."
  4215. (pr-ps-message-from-summary n-up filename header-list
  4216. 'rmail-buffer 'rmail-summary-buffer))
  4217. (defun pr-ps-message-from-summary (n-up filename header-list
  4218. summary-buffer summary-default)
  4219. "Print current message in PostScript."
  4220. (let ((buf (or (and (boundp summary-buffer)
  4221. (symbol-value summary-buffer))
  4222. (symbol-value summary-default))))
  4223. (and (get-buffer buf)
  4224. (with-current-buffer buf
  4225. (pr-mode-print n-up filename header-list)))))
  4226. (defun pr-lpr-message-from-summary (header-list summary-buffer summary-default)
  4227. "Print current message in text printer."
  4228. (let ((buf (or (and (boundp summary-buffer)
  4229. (symbol-value summary-buffer))
  4230. (symbol-value summary-default))))
  4231. (and (get-buffer buf)
  4232. (with-current-buffer buf
  4233. (pr-mode-lpr header-list)))))
  4234. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4235. ;; gnus (hacked from ps-print.el)
  4236. (defvar pr-gnus-article "*Article*")
  4237. (defun pr-gnus-print (n-up filename header-list)
  4238. "Print *Article* current message in PostScript."
  4239. (pr-ps-message-from-summary n-up filename header-list
  4240. 'gnus-article-buffer 'pr-gnus-article))
  4241. (defun pr-gnus-lpr (header-list)
  4242. "Print *Article* current message in text printer."
  4243. (pr-lpr-message-from-summary header-list
  4244. 'gnus-article-buffer 'pr-gnus-article))
  4245. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4246. ;; vm (hacked from ps-print.el)
  4247. (defvar pr-vm-summary "")
  4248. (defun pr-vm-print (n-up filename header-list)
  4249. "Print current vm message in PostScript."
  4250. (pr-ps-message-from-summary n-up filename header-list
  4251. 'vm-mail-buffer 'pr-vm-summary))
  4252. (defun pr-vm-lpr (header-list)
  4253. "Print current vm message in text printer."
  4254. (pr-lpr-message-from-summary header-list
  4255. 'vm-mail-buffer 'pr-vm-summary))
  4256. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4257. ;; Mode Functions
  4258. (defun pr-ps-mode (n-up filename)
  4259. "If current major mode is declared, print it in PostScript."
  4260. (let ((args (pr-mode-alist-p)))
  4261. (if args
  4262. (let ((fun (cdr args)))
  4263. (funcall (car fun) n-up filename (cdr fun))
  4264. t)
  4265. (ding)
  4266. (message "`%s' major mode not declared." major-mode)
  4267. nil)))
  4268. (defmacro pr-local-variable (header-list &rest body)
  4269. `(save-excursion
  4270. (let ((ps-header-lines (or (nth 0 ,header-list) ps-header-lines))
  4271. (ps-left-header (or (nth 1 ,header-list) ps-left-header))
  4272. (ps-right-header (or (nth 2 ,header-list) ps-right-header))
  4273. ps-razzle-dazzle)
  4274. (let ((local-var-list (pr-eval-local-alist (nthcdr 4 ,header-list))))
  4275. ,@body
  4276. (and (nth 3 ,header-list)
  4277. (pr-kill-local-variable local-var-list))))))
  4278. (defun pr-mode-print (n-up filename header-list &optional from to)
  4279. "Print current major mode in PostScript."
  4280. (pr-local-variable
  4281. header-list
  4282. (let ((file (pr-ps-file filename))
  4283. (start (cond (from)
  4284. ((pr-region-active-p) (region-beginning))
  4285. (t nil)
  4286. )))
  4287. (pr-text2ps (pr-region-active-symbol start) n-up file start
  4288. (cond (to)
  4289. ((pr-region-active-p) (region-end))
  4290. (from (point-max))
  4291. ))
  4292. (unless (or pr-spool-p filename)
  4293. (pr-ps-file-print file)
  4294. (pr-delete-file file)))))
  4295. (defun pr-mode-lpr (header-list &optional from to)
  4296. "Print current major mode in text printer."
  4297. (pr-local-variable
  4298. header-list
  4299. (pr-txt-print (cond (from)
  4300. ((pr-region-active-p) (region-beginning))
  4301. (t (point-min)))
  4302. (cond (to)
  4303. ((pr-region-active-p) (region-end))
  4304. (t (point-max))))))
  4305. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4306. ;; Menu Lock
  4307. (defconst pr-menu-entry-alist
  4308. '((postscript . 3)
  4309. (text . 3)
  4310. (postscript-options . 9)
  4311. (postscript-process . 3)
  4312. (printing . 3)
  4313. (help . 3)
  4314. )
  4315. "Alist that associates menu part with number of items per part.
  4316. It's used by `pr-menu-index'.
  4317. Each element has the form:
  4318. (MENU-PART . NUMBER-OF-ITEMS)
  4319. See `pr-visible-entry-alist'.")
  4320. (defun pr-menu-index (entry index)
  4321. (let ((base-list
  4322. (cond ((eq entry 'text)
  4323. '(postscript))
  4324. ((eq entry 'postscript-options)
  4325. '(postscript text))
  4326. ((eq entry 'postscript-process)
  4327. '(postscript text postscript-options))
  4328. ((eq entry 'printing)
  4329. '(postscript text postscript-options postscript-process))
  4330. (t
  4331. nil)
  4332. ))
  4333. key)
  4334. (while base-list
  4335. (setq key (car base-list)
  4336. base-list (cdr base-list))
  4337. (and (pr-visible-p key)
  4338. (setq index (+ index
  4339. (cdr (assq key pr-menu-entry-alist)))))))
  4340. (+ index 2))
  4341. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4342. ;; Printer & Utility Selection
  4343. (defun pr-update-var (var-sym alist)
  4344. (or (assq (symbol-value var-sym) alist)
  4345. (set var-sym (car (car alist)))))
  4346. (defun pr-update-menus (&optional force)
  4347. "Update utility, PostScript and text printer menus.
  4348. If FORCE is non-nil, update menus doesn't matter if `pr-ps-printer-alist',
  4349. `pr-txt-printer-alist' or `pr-ps-utility-alist' were modified or not;
  4350. otherwise, update PostScript printer menu if `pr-ps-printer-menu-modified' is
  4351. non-nil, update text printer menu if `pr-txt-printer-menu-modified' is
  4352. non-nil, and update PostScript File menus if `pr-ps-utility-menu-modified' is
  4353. non-nil.
  4354. If menu binding was not done, calls `pr-menu-bind'."
  4355. (interactive "P")
  4356. (if pr-menu-print-item ; since v6.8.4
  4357. ;; There was no menu binding yet, so do it now!
  4358. ;; This is a hack to be compatible with old versions of printing.
  4359. ;; So, user does not need to change printing calling in init files.
  4360. (pr-menu-bind)
  4361. ;; Here menu binding is ok.
  4362. (pr-update-var 'pr-ps-name pr-ps-printer-alist)
  4363. (pr-update-var 'pr-txt-name pr-txt-printer-alist)
  4364. (pr-update-var 'pr-ps-utility pr-ps-utility-alist)
  4365. (pr-do-update-menus force)))
  4366. (defun pr-menu-create (name alist var-sym fun entry index)
  4367. (cons name
  4368. (mapcar
  4369. #'(lambda (elt)
  4370. (let ((sym (car elt)))
  4371. (vector
  4372. (symbol-name sym)
  4373. (list fun (list 'quote sym) nil (list 'quote entry) index)
  4374. :style 'radio
  4375. :selected (list 'eq var-sym (list 'quote sym)))))
  4376. alist)))
  4377. (defun pr-ps-set-utility (value)
  4378. (let ((item (cdr (assq value pr-ps-utility-alist))))
  4379. (or item
  4380. (error
  4381. "Invalid PostScript utility name `%s' for variable `pr-ps-utility'"
  4382. value))
  4383. (setq pr-ps-utility value)
  4384. (pr-eval-alist (nthcdr 9 item)))
  4385. (pr-update-mode-line))
  4386. (defun pr-ps-set-printer (value)
  4387. (let ((ps (cdr (assq value pr-ps-printer-alist))))
  4388. (or ps
  4389. (error
  4390. "Invalid PostScript printer name `%s' for variable `pr-ps-name'"
  4391. value))
  4392. (setq pr-ps-name value
  4393. pr-ps-command (pr-dosify-file-name (nth 0 ps))
  4394. pr-ps-switches (nth 1 ps)
  4395. pr-ps-printer-switch (nth 2 ps)
  4396. pr-ps-printer (nth 3 ps))
  4397. (or (stringp pr-ps-command)
  4398. (setq pr-ps-command
  4399. (cond (lpr-windows-system "print")
  4400. (lpr-lp-system "lp")
  4401. (t "lpr")
  4402. )))
  4403. (or (stringp pr-ps-printer-switch)
  4404. (setq pr-ps-printer-switch
  4405. (cond (lpr-windows-system "/D:")
  4406. (lpr-lp-system "-d")
  4407. (t "-P")
  4408. )))
  4409. (pr-eval-alist (nthcdr 4 ps)))
  4410. (pr-update-mode-line))
  4411. (defun pr-txt-set-printer (value)
  4412. (let ((txt (cdr (assq value pr-txt-printer-alist))))
  4413. (or txt
  4414. (error "Invalid text printer name `%s' for variable `pr-txt-name'"
  4415. value))
  4416. (setq pr-txt-name value
  4417. pr-txt-command (pr-dosify-file-name (nth 0 txt))
  4418. pr-txt-switches (nth 1 txt)
  4419. pr-txt-printer (nth 2 txt)))
  4420. (or (stringp pr-txt-command)
  4421. (setq pr-txt-command
  4422. (cond (lpr-windows-system "print")
  4423. (lpr-lp-system "lp")
  4424. (t "lpr")
  4425. )))
  4426. (pr-update-mode-line))
  4427. (defun pr-eval-alist (alist)
  4428. (mapcar #'(lambda (option)
  4429. (let ((var-sym (car option))
  4430. (value (cdr option)))
  4431. (if (eq var-sym 'inherits-from:)
  4432. (pr-eval-setting-alist value 'global)
  4433. (set var-sym (eval value)))))
  4434. alist))
  4435. (defun pr-eval-local-alist (alist)
  4436. (let (local-list)
  4437. (mapc #'(lambda (option)
  4438. (let ((var-sym (car option))
  4439. (value (cdr option)))
  4440. (setq local-list
  4441. (if (eq var-sym 'inherits-from:)
  4442. (nconc (pr-eval-setting-alist value) local-list)
  4443. (set (make-local-variable var-sym) (eval value))
  4444. (cons var-sym local-list)))))
  4445. alist)
  4446. local-list))
  4447. (defun pr-eval-setting-alist (key &optional global old)
  4448. (let ((setting (cdr (assq key pr-setting-database))))
  4449. (and setting
  4450. (let ((inherits (nth 0 setting))
  4451. (local (nth 1 setting))
  4452. (kill (nth 2 setting))
  4453. local-list)
  4454. (and local global
  4455. (progn
  4456. (ding)
  4457. (message "There are local buffer settings for `%S'." key)
  4458. (setq global nil)))
  4459. (and inherits
  4460. (if (memq inherits old)
  4461. (error "Circular inheritance for `%S'" inherits)
  4462. (setq local-list
  4463. (pr-eval-setting-alist inherits global
  4464. (cons inherits old)))))
  4465. (mapc
  4466. (cond ((not local) ; global settings
  4467. #'(lambda (option)
  4468. (let ((var-sym (car option)))
  4469. (or (eq var-sym 'inherits-from:)
  4470. (set var-sym (eval (cdr option)))))))
  4471. (kill ; local settings with killing
  4472. #'(lambda (option)
  4473. (let ((var-sym (car option)))
  4474. (unless (eq var-sym 'inherits-from:)
  4475. (setq local-list (cons var-sym local-list))
  4476. (set (make-local-variable var-sym)
  4477. (eval (cdr option)))))))
  4478. (t ; local settings without killing
  4479. #'(lambda (option)
  4480. (let ((var-sym (car option)))
  4481. (or (eq var-sym 'inherits-from:)
  4482. (set (make-local-variable var-sym)
  4483. (eval (cdr option))))))))
  4484. (nthcdr 3 setting))
  4485. local-list))))
  4486. (defun pr-kill-local-variable (local-var-list)
  4487. (mapcar 'kill-local-variable local-var-list))
  4488. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4489. ;; Internal Functions (II)
  4490. (defun pr-toggle (var-sym mess entry index horizontal state
  4491. &optional path no-menu)
  4492. (set var-sym (not (symbol-value var-sym)))
  4493. (message "%s is %s" mess (if (symbol-value var-sym) "on" "off"))
  4494. (or no-menu
  4495. (pr-menu-lock entry index horizontal state path)))
  4496. (defun pr-toggle-file-duplex-menu (&optional no-menu)
  4497. "Toggle whether to print PostScript files in duplex mode."
  4498. (interactive)
  4499. (pr-toggle 'pr-file-duplex "PS file duplex" nil 7 5 nil
  4500. '("PostScript Print" "File") no-menu))
  4501. (defun pr-toggle-file-tumble-menu (&optional no-menu)
  4502. "Toggle whether to print PostScript files in tumble mode."
  4503. (interactive)
  4504. (pr-toggle 'pr-file-tumble "PS file tumble" nil 8 5 nil
  4505. '("PostScript Print" "File") no-menu))
  4506. (defun pr-toggle-file-landscape-menu (&optional no-menu)
  4507. "Toggle whether to print PostScript files in landscape orientation."
  4508. (interactive)
  4509. (pr-toggle 'pr-file-landscape "PS file landscape" nil 6 5 nil
  4510. '("PostScript Print" "File") no-menu))
  4511. (defun pr-toggle-ghostscript-menu (&optional no-menu)
  4512. "Toggle whether to print using ghostscript."
  4513. (interactive)
  4514. (pr-toggle 'pr-print-using-ghostscript "Printing using ghostscript"
  4515. 'postscript-process 2 12 'toggle nil no-menu))
  4516. (defun pr-toggle-faces-menu (&optional no-menu)
  4517. "Toggle whether to print with face attributes."
  4518. (interactive)
  4519. (pr-toggle 'pr-faces-p "Printing with faces"
  4520. 'postscript-process 1 12 'toggle nil no-menu))
  4521. (defun pr-toggle-spool-menu (&optional no-menu)
  4522. "Toggle whether to spool printing in a buffer."
  4523. (interactive)
  4524. (pr-toggle 'pr-spool-p "Spooling printing"
  4525. 'postscript-process 0 12 'toggle nil no-menu))
  4526. (defun pr-toggle-duplex-menu (&optional no-menu)
  4527. "Toggle whether to generate PostScript for a two-sided printer."
  4528. (interactive)
  4529. (pr-toggle 'ps-spool-duplex "Printing duplex"
  4530. 'postscript-options 5 12 'toggle nil no-menu))
  4531. (defun pr-toggle-tumble-menu (&optional no-menu)
  4532. "Toggle how pages on opposite sides of a sheet are oriented."
  4533. (interactive)
  4534. (pr-toggle 'ps-spool-tumble "Tumble"
  4535. 'postscript-options 6 12 'toggle nil no-menu))
  4536. (defun pr-toggle-landscape-menu (&optional no-menu)
  4537. "Toggle whether to print in landscape mode."
  4538. (interactive)
  4539. (pr-toggle 'ps-landscape-mode "Landscape"
  4540. 'postscript-options 0 12 'toggle nil no-menu))
  4541. (defun pr-toggle-upside-down-menu (&optional no-menu)
  4542. "Toggle whether to print upside-down (that is, rotated by 180 degrees)."
  4543. (interactive)
  4544. (pr-toggle 'ps-print-upside-down "Upside-Down"
  4545. 'postscript-options 7 12 'toggle nil no-menu))
  4546. (defun pr-toggle-line-menu (&optional no-menu)
  4547. "Toggle whether to means print line numbers."
  4548. (interactive)
  4549. (pr-toggle 'ps-line-number "Line number"
  4550. 'postscript-options 3 12 'toggle nil no-menu))
  4551. (defun pr-toggle-zebra-menu (&optional no-menu)
  4552. "Toggle whether to print zebra stripes."
  4553. (interactive)
  4554. (pr-toggle 'ps-zebra-stripes "Zebra stripe"
  4555. 'postscript-options 4 12 'toggle nil no-menu))
  4556. (defun pr-toggle-header-menu (&optional no-menu)
  4557. "Toggle whether to print a header at the top of each page."
  4558. (interactive)
  4559. (pr-toggle 'ps-print-header "Print header"
  4560. 'postscript-options 1 12 'toggle nil no-menu))
  4561. (defun pr-toggle-header-frame-menu (&optional no-menu)
  4562. "Toggle whether to draw a gaudy frame around the header."
  4563. (interactive)
  4564. (pr-toggle 'ps-print-header-frame "Print header frame"
  4565. 'postscript-options 2 12 'toggle nil no-menu))
  4566. (defun pr-toggle-lock-menu (&optional no-menu)
  4567. "Toggle whether the menu is locked while selecting toggle options."
  4568. (interactive)
  4569. (pr-toggle 'pr-menu-lock "Menu lock"
  4570. 'printing 2 12 'toggle nil no-menu))
  4571. (defun pr-toggle-region-menu (&optional no-menu)
  4572. "Toggle whether the region is automagically detected."
  4573. (interactive)
  4574. (pr-toggle 'pr-auto-region "Auto region"
  4575. 'printing 0 12 'toggle nil no-menu))
  4576. (defun pr-toggle-mode-menu (&optional no-menu)
  4577. "Toggle whether major-mode specific printing is preferred over normal printing."
  4578. (interactive)
  4579. (pr-toggle 'pr-auto-mode "Auto mode"
  4580. 'printing 1 12 'toggle nil no-menu))
  4581. (defun pr-prompt (str)
  4582. (if (pr-auto-mode-p)
  4583. (concat str " mode")
  4584. (pr-region-active-string str)))
  4585. (defun pr-prompt-region (str)
  4586. (concat str (if (pr-auto-mode-p)
  4587. " mode"
  4588. " region")))
  4589. (defun pr-prompt-gs (str)
  4590. (if (pr-using-ghostscript-p)
  4591. (concat str " GS")
  4592. str))
  4593. (defun pr-region-active-symbol (&optional region-p)
  4594. (if (or region-p (pr-region-active-p))
  4595. 'region
  4596. 'buffer))
  4597. (defun pr-region-active-string (prefix)
  4598. (concat prefix
  4599. (if (pr-region-active-p)
  4600. " region"
  4601. " buffer")))
  4602. (defun pr-show-setup (settings buffer-name)
  4603. (with-output-to-temp-buffer buffer-name
  4604. (princ settings)
  4605. (help-print-return-message)))
  4606. (defun pr-complete-alist (prompt alist default)
  4607. (let ((collection (mapcar #'(lambda (elt)
  4608. (setq elt (car elt))
  4609. (cons (symbol-name elt) elt))
  4610. alist)))
  4611. (cdr (assoc (completing-read (concat prompt ": ")
  4612. collection nil t
  4613. (symbol-name default) nil
  4614. (symbol-name default))
  4615. collection))))
  4616. (defun pr-delete-file (file)
  4617. (and pr-delete-temp-file (file-exists-p file)
  4618. (delete-file file)))
  4619. (defun pr-expand-file-name (filename)
  4620. (pr-dosify-file-name (expand-file-name filename)))
  4621. (defun pr-ps-outfile-preprint (&optional mess)
  4622. (let* ((prompt (format "%soutput PostScript file name: " (or mess "")))
  4623. (res (read-file-name prompt default-directory "" nil)))
  4624. (while (cond ((not (file-writable-p res))
  4625. (ding)
  4626. (setq prompt "is unwritable"))
  4627. ((file-directory-p res)
  4628. (ding)
  4629. (setq prompt "is a directory"))
  4630. ((file-exists-p res)
  4631. (ding)
  4632. (setq prompt "exists")
  4633. (not (y-or-n-p (format-message
  4634. "File `%s' exists; overwrite? " res))))
  4635. (t nil))
  4636. (setq res (read-file-name
  4637. (format "File %s; PostScript file: " prompt)
  4638. (file-name-directory res) nil nil
  4639. (file-name-nondirectory res))))
  4640. (pr-expand-file-name res)))
  4641. (defun pr-ps-infile-preprint (&optional mess)
  4642. (let* ((prompt (format "%sinput PostScript file name: " (or mess "")))
  4643. (res (read-file-name prompt default-directory "" nil)))
  4644. (while (cond ((not (file-exists-p res))
  4645. (ding)
  4646. (setq prompt "doesn't exist"))
  4647. ((not (file-readable-p res))
  4648. (ding)
  4649. (setq prompt "is unreadable"))
  4650. ((file-directory-p res)
  4651. (ding)
  4652. (setq prompt "is a directory"))
  4653. (t nil))
  4654. (setq res (read-file-name
  4655. (format "File %s; PostScript file: " prompt)
  4656. (file-name-directory res) nil nil
  4657. (file-name-nondirectory res))))
  4658. (pr-expand-file-name res)))
  4659. (defun pr-ps-utility-args (n-up-sym infile-sym outfile-sym prompt)
  4660. ;; check arguments for PostScript file processing.
  4661. ;; n-up
  4662. (or (symbol-value n-up-sym)
  4663. (set n-up-sym (pr-interactive-n-up prompt)))
  4664. ;; input file
  4665. (and (eq (symbol-value infile-sym) t)
  4666. (set infile-sym (pr-ps-infile-preprint prompt)))
  4667. (or (symbol-value infile-sym)
  4668. (error "%s: input PostScript file name is missing" prompt))
  4669. (set infile-sym (pr-dosify-file-name (symbol-value infile-sym)))
  4670. ;; output file
  4671. (and (eq (symbol-value outfile-sym) t)
  4672. (set outfile-sym (and current-prefix-arg
  4673. (pr-ps-outfile-preprint prompt))))
  4674. (and (symbol-value outfile-sym)
  4675. (set outfile-sym (pr-dosify-file-name (symbol-value outfile-sym))))
  4676. (pr-ps-file (symbol-value outfile-sym)))
  4677. (defun pr-ps-utility-process (n-up infile outfile)
  4678. ;; activate utility to process a PostScript file.
  4679. (let (item)
  4680. (and (stringp infile) (file-exists-p infile)
  4681. (setq item (cdr (assq pr-ps-utility pr-ps-utility-alist)))
  4682. (pr-call-process (nth 0 item)
  4683. (pr-switches-string (nth 1 item)
  4684. "pr-ps-utility-alist entry")
  4685. (pr-switches-string (nth 8 item)
  4686. "pr-ps-utility-alist entry")
  4687. (and (nth 2 item)
  4688. (format (nth 2 item) ps-paper-type))
  4689. (format (nth 3 item) n-up)
  4690. (and pr-file-landscape (nth 4 item))
  4691. (and pr-file-duplex (nth 5 item))
  4692. (and pr-file-tumble (nth 6 item))
  4693. (pr-expand-file-name infile)
  4694. (nth 7 item)
  4695. (pr-expand-file-name outfile)))))
  4696. (defun pr-remove-nil-from-list (lst)
  4697. (while (and lst (null (car lst)))
  4698. (setq lst (cdr lst)))
  4699. (let ((b lst)
  4700. (l (cdr lst)))
  4701. (while l
  4702. (if (car l)
  4703. (setq b l
  4704. l (cdr l))
  4705. (setq l (cdr l))
  4706. (setcdr b l))))
  4707. lst)
  4708. (defun pr-call-process (command &rest args)
  4709. (let ((buffer (get-buffer-create "*Printing Command Output*"))
  4710. (cmd (pr-command command))
  4711. status)
  4712. (setq args (pr-remove-nil-from-list args))
  4713. ;; *Printing Command Output* == show command & args
  4714. (with-current-buffer buffer
  4715. (goto-char (point-max))
  4716. (insert (format "%s %S\n" cmd args)))
  4717. ;; *Printing Command Output* == show any return message from command
  4718. (with-file-modes pr-file-modes
  4719. (setq status
  4720. (condition-case data
  4721. (apply 'call-process cmd nil buffer nil args)
  4722. ((quit error)
  4723. (error-message-string data)))))
  4724. ;; *Printing Command Output* == show exit status
  4725. (with-current-buffer buffer
  4726. (goto-char (point-max))
  4727. (insert (format "Exit status: %s\n\n" status)))
  4728. ;; message if error status
  4729. (if (or (stringp status)
  4730. (and (integerp status) (/= status 0)))
  4731. (message
  4732. "Printing error status: %s (see *Printing Command Output* buffer)"
  4733. status))))
  4734. (defun pr-txt-print (from to)
  4735. (let ((lpr-command (pr-standard-file-name (pr-command pr-txt-command)))
  4736. (lpr-switches (pr-switches pr-txt-switches "pr-txt-switches"))
  4737. (printer-name pr-txt-printer))
  4738. (lpr-region from to)))
  4739. (defun pr-switches-string (switches mess)
  4740. ;; If SWITCHES is nil, return nil.
  4741. ;; Otherwise, return the list of string in a string.
  4742. (and switches
  4743. (mapconcat 'identity (pr-switches switches mess) " ")))
  4744. (defun pr-switches (switches mess)
  4745. (or (listp switches)
  4746. (error "%S should have a list of strings" mess))
  4747. (lpr-flatten-list ; dynamic evaluation
  4748. (mapcar 'ps-eval-switch switches)))
  4749. (defun pr-ps-preview (kind n-up filename mess)
  4750. (pr-set-n-up-and-filename 'n-up 'filename mess)
  4751. (let ((file (pr-ps-file filename)))
  4752. (pr-text2ps kind n-up file)
  4753. (or pr-spool-p (pr-ps-file-preview file))))
  4754. (defun pr-ps-using-ghostscript (kind n-up filename mess)
  4755. (pr-set-n-up-and-filename 'n-up 'filename mess)
  4756. (let ((file (pr-ps-file filename)))
  4757. (pr-text2ps kind n-up file)
  4758. (unless (or pr-spool-p filename)
  4759. (pr-ps-file-using-ghostscript file)
  4760. (pr-delete-file file))))
  4761. (defun pr-ps-print (kind n-up filename mess)
  4762. (pr-set-n-up-and-filename 'n-up 'filename mess)
  4763. (let ((file (pr-ps-file filename)))
  4764. (pr-text2ps kind n-up file)
  4765. (unless (or pr-spool-p filename)
  4766. (pr-ps-file-print file)
  4767. (pr-delete-file file))))
  4768. (defun pr-ps-file (&optional filename)
  4769. (pr-dosify-file-name (or filename
  4770. (make-temp-file
  4771. (convert-standard-filename
  4772. (expand-file-name pr-ps-temp-file pr-temp-dir))
  4773. nil ".ps"))))
  4774. (defun pr-interactive-n-up (mess)
  4775. (or (stringp mess) (setq mess "*"))
  4776. (save-match-data
  4777. (let* ((fmt-prompt "%s[%s] N-up printing (default 1): ")
  4778. (prompt "")
  4779. (str (pr-read-string (format fmt-prompt prompt mess) "1" nil "1"))
  4780. int)
  4781. (while (if (string-match "^\\s *[0-9]+$" str)
  4782. (setq int (string-to-number str)
  4783. prompt (cond ((< int 1) "Integer below 1; ")
  4784. ((> int 100) "Integer above 100; ")
  4785. (t nil)))
  4786. (setq prompt "Invalid integer syntax; "))
  4787. (ding)
  4788. (setq str
  4789. (pr-read-string (format fmt-prompt prompt mess) str nil "1")))
  4790. int)))
  4791. (defun pr-interactive-dir (mess)
  4792. (let* ((dir-name (file-name-directory (or (buffer-file-name)
  4793. default-directory)))
  4794. (fmt-prompt (concat "%s[" mess "] Directory to print: "))
  4795. (dir (read-directory-name (format fmt-prompt "")
  4796. "" dir-name nil dir-name))
  4797. prompt)
  4798. (while (cond ((not (file-directory-p dir))
  4799. (ding)
  4800. (setq prompt "It's not a directory! "))
  4801. ((not (file-readable-p dir))
  4802. (ding)
  4803. (setq prompt "Directory is unreadable! "))
  4804. (t nil))
  4805. (setq dir-name (file-name-directory dir)
  4806. dir (read-directory-name (format fmt-prompt prompt)
  4807. "" dir-name nil dir-name)))
  4808. (file-name-as-directory dir)))
  4809. (defun pr-interactive-regexp (mess)
  4810. (pr-read-string (format "[%s] File regexp to print: " mess) "" nil ""))
  4811. (defun pr-interactive-dir-args (mess)
  4812. (list
  4813. ;; get directory argument
  4814. (pr-interactive-dir mess)
  4815. ;; get file name regexp
  4816. (pr-interactive-regexp mess)))
  4817. (defun pr-interactive-ps-dir-args (mess)
  4818. (list
  4819. ;; get n-up argument
  4820. (pr-interactive-n-up mess)
  4821. ;; get directory argument
  4822. (pr-interactive-dir mess)
  4823. ;; get file name regexp
  4824. (pr-interactive-regexp mess)
  4825. ;; get output file name
  4826. (and (not pr-spool-p)
  4827. (ps-print-preprint current-prefix-arg))))
  4828. (defun pr-interactive-n-up-file (mess)
  4829. (list
  4830. ;; get n-up argument
  4831. (pr-interactive-n-up mess)
  4832. ;; get output file name
  4833. (and (not pr-spool-p)
  4834. (ps-print-preprint current-prefix-arg))))
  4835. (defun pr-interactive-n-up-inout (mess)
  4836. (list
  4837. ;; get n-up argument
  4838. (pr-interactive-n-up mess)
  4839. ;; get input file name
  4840. (pr-ps-infile-preprint (concat mess " "))
  4841. ;; get output file name
  4842. (ps-print-preprint current-prefix-arg)))
  4843. (defun pr-set-outfilename (filename-sym)
  4844. (and (not pr-spool-p)
  4845. (eq (symbol-value filename-sym) t)
  4846. (set filename-sym (and current-prefix-arg
  4847. (ps-print-preprint current-prefix-arg))))
  4848. (and (symbol-value filename-sym)
  4849. (set filename-sym (pr-dosify-file-name (symbol-value filename-sym)))))
  4850. (defun pr-set-n-up-and-filename (n-up-sym filename-sym mess)
  4851. ;; n-up
  4852. (or (symbol-value n-up-sym)
  4853. (set n-up-sym (pr-interactive-n-up mess)))
  4854. ;; output file
  4855. (pr-set-outfilename filename-sym))
  4856. (defun pr-set-dir-args (dir-sym regexp-sym mess)
  4857. ;; directory
  4858. (or (symbol-value dir-sym)
  4859. (set dir-sym (pr-interactive-dir mess)))
  4860. ;; file name regexp
  4861. (or (symbol-value regexp-sym)
  4862. (set regexp-sym (pr-interactive-regexp mess))))
  4863. (defun pr-set-ps-dir-args (n-up-sym dir-sym regexp-sym filename-sym mess)
  4864. ;; n-up
  4865. (or (symbol-value n-up-sym)
  4866. (set n-up-sym (pr-interactive-n-up mess)))
  4867. ;; directory & file name regexp
  4868. (pr-set-dir-args dir-sym regexp-sym mess)
  4869. ;; output file
  4870. (pr-set-outfilename filename-sym))
  4871. (defun pr-find-buffer-visiting (file)
  4872. (if (not (file-directory-p file))
  4873. (find-buffer-visiting (if lpr-windows-system
  4874. (downcase file)
  4875. file))
  4876. (let ((truename (file-truename file))
  4877. (blist (buffer-list))
  4878. found)
  4879. (while (and (not found) blist)
  4880. (with-current-buffer (car blist)
  4881. (and (eq major-mode 'dired-mode)
  4882. (save-excursion
  4883. (goto-char (point-min))
  4884. (string= (buffer-substring-no-properties
  4885. (+ (point-min) 2)
  4886. (progn
  4887. (end-of-line)
  4888. (1- (point))))
  4889. truename))
  4890. (setq found (car blist))))
  4891. (setq blist (cdr blist)))
  4892. found)))
  4893. (defun pr-file-list (dir file-regexp fun)
  4894. (mapcar #'(lambda (file)
  4895. (and (or pr-list-directory
  4896. (not (file-directory-p file)))
  4897. (let ((buffer (pr-find-buffer-visiting file))
  4898. pop-up-windows
  4899. pop-up-frames)
  4900. (and (or buffer
  4901. (file-readable-p file))
  4902. (with-current-buffer (or buffer
  4903. (find-file-noselect file))
  4904. (funcall fun)
  4905. (or buffer
  4906. (kill-buffer (current-buffer))))))))
  4907. (directory-files dir t file-regexp)))
  4908. (defun pr-delete-file-if-exists (filename)
  4909. (and (not pr-spool-p) (stringp filename) (file-exists-p filename)
  4910. (delete-file filename)))
  4911. (defun pr-ps-file-list (n-up dir file-regexp filename)
  4912. (pr-delete-file-if-exists (setq filename (pr-expand-file-name filename)))
  4913. (let ((pr-spool-p t))
  4914. (pr-file-list dir file-regexp
  4915. #'(lambda ()
  4916. (if (pr-auto-mode-p)
  4917. (pr-ps-mode n-up filename)
  4918. (pr-text2ps 'buffer n-up filename)))))
  4919. (or pr-spool-p
  4920. (pr-despool-print filename)))
  4921. (defun pr-text2ps (kind n-up filename &optional from to)
  4922. (with-file-modes pr-file-modes
  4923. (let ((ps-n-up-printing n-up)
  4924. (ps-spool-config (and (eq ps-spool-config 'setpagedevice)
  4925. 'setpagedevice)))
  4926. (pr-delete-file-if-exists filename)
  4927. (cond (pr-faces-p
  4928. (cond (pr-spool-p
  4929. ;; pr-faces-p and pr-spool-p
  4930. ;; here FILENAME arg is ignored
  4931. (cond ((eq kind 'buffer)
  4932. (ps-spool-buffer-with-faces))
  4933. ((eq kind 'region)
  4934. (ps-spool-region-with-faces (or from (point))
  4935. (or to (mark))))
  4936. ))
  4937. ;; pr-faces-p and not pr-spool-p
  4938. ((eq kind 'buffer)
  4939. (ps-print-buffer-with-faces filename))
  4940. ((eq kind 'region)
  4941. (ps-print-region-with-faces (or from (point))
  4942. (or to (mark)) filename))
  4943. ))
  4944. (pr-spool-p
  4945. ;; not pr-faces-p and pr-spool-p
  4946. ;; here FILENAME arg is ignored
  4947. (cond ((eq kind 'buffer)
  4948. (ps-spool-buffer))
  4949. ((eq kind 'region)
  4950. (ps-spool-region (or from (point)) (or to (mark))))
  4951. ))
  4952. ;; not pr-faces-p and not pr-spool-p
  4953. ((eq kind 'buffer)
  4954. (ps-print-buffer filename))
  4955. ((eq kind 'region)
  4956. (ps-print-region (or from (point)) (or to (mark)) filename))
  4957. ))))
  4958. (defun pr-command (command)
  4959. "Return absolute file name specification for COMMAND.
  4960. If COMMAND is an empty string, return it.
  4961. If COMMAND is already an absolute file name specification, return it.
  4962. Else it uses `pr-path-alist' to find COMMAND, if find it then return it;
  4963. otherwise, gives an error.
  4964. When using `pr-path-alist' to find COMMAND, the entries `cygwin', `windows' and
  4965. `unix' are used (see `pr-path-alist' for documentation).
  4966. If Emacs is running on Windows 95/98/NT/2000, tries to find COMMAND,
  4967. COMMAND.exe, COMMAND.bat and COMMAND.com in this order."
  4968. (if (string= command "")
  4969. command
  4970. (pr-dosify-file-name
  4971. (or (pr-find-command command)
  4972. (pr-path-command (cond (pr-cygwin-system 'cygwin)
  4973. (lpr-windows-system 'windows)
  4974. (t 'unix))
  4975. (file-name-nondirectory command)
  4976. nil)
  4977. (error "Command not found: %s"
  4978. (file-name-nondirectory command))))))
  4979. (defun pr-path-command (symbol command sym-list)
  4980. (let ((lpath (cdr (assq symbol pr-path-alist)))
  4981. cmd)
  4982. ;; PATH expansion
  4983. (and (eq symbol 'PATH) (null lpath)
  4984. (setq lpath (parse-colon-path (getenv "PATH"))))
  4985. (while (and lpath
  4986. (not
  4987. (setq cmd
  4988. (let ((path (car lpath)))
  4989. (cond
  4990. ;; symbol expansion
  4991. ((symbolp path)
  4992. (and (not (memq path sym-list))
  4993. (pr-path-command path command
  4994. (cons path sym-list))))
  4995. ;; normal path
  4996. ((stringp path)
  4997. (pr-find-command
  4998. (expand-file-name
  4999. (substitute-in-file-name
  5000. (concat (file-name-as-directory path)
  5001. command)))))
  5002. )))))
  5003. (setq lpath (cdr lpath)))
  5004. cmd))
  5005. (defun pr-find-command (cmd)
  5006. (if lpr-windows-system
  5007. ;; windows system
  5008. (let ((ext (cons (file-name-extension cmd t)
  5009. (list ".exe" ".bat" ".com")))
  5010. found)
  5011. (setq cmd (file-name-sans-extension cmd))
  5012. (while (and ext
  5013. (setq found (concat cmd (car ext)))
  5014. (not (and (file-regular-p found)
  5015. (file-executable-p found))))
  5016. (setq ext (cdr ext)
  5017. found nil))
  5018. found)
  5019. ;; non-windows systems
  5020. (and (file-regular-p cmd)
  5021. (file-executable-p cmd)
  5022. cmd)))
  5023. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5024. ;; Printing Interface (inspired by ps-print-interface.el)
  5025. (eval-when-compile
  5026. (require 'cus-edit)
  5027. (require 'wid-edit)
  5028. (require 'widget))
  5029. (defvar pr-i-window-configuration nil)
  5030. (defvar pr-i-buffer nil)
  5031. (defvar pr-i-region nil)
  5032. (defvar pr-i-mode nil)
  5033. (defvar pr-i-despool nil)
  5034. (defvar pr-i-ps-as-is t)
  5035. (defvar pr-i-n-up 1)
  5036. (defvar pr-i-directory "./")
  5037. (defvar pr-i-regexp "")
  5038. (defvar pr-i-ps-file "")
  5039. (defvar pr-i-out-file "")
  5040. (defvar pr-i-answer-yes nil)
  5041. (defvar pr-i-process 'buffer)
  5042. (defvar pr-i-ps-send 'printer)
  5043. (defvar pr-interface-map nil
  5044. "Keymap for pr-interface.")
  5045. (unless pr-interface-map
  5046. (let ((map (make-sparse-keymap)))
  5047. (cond ((featurep 'xemacs) ; XEmacs
  5048. (pr-set-keymap-parents map (list widget-keymap))
  5049. (pr-set-keymap-name map 'pr-interface-map))
  5050. (t ; GNU Emacs
  5051. (pr-set-keymap-parents map widget-keymap)))
  5052. (define-key map "q" 'pr-interface-quit)
  5053. (define-key map "?" 'pr-interface-help)
  5054. (setq pr-interface-map map)))
  5055. (defmacro pr-interface-save (&rest body)
  5056. `(with-current-buffer pr-i-buffer
  5057. ,@body))
  5058. (defun pr-create-interface ()
  5059. "Create the front end for printing package."
  5060. (setq pr-i-buffer (buffer-name (current-buffer))
  5061. pr-i-region (ps-mark-active-p)
  5062. pr-i-mode (pr-mode-alist-p)
  5063. pr-i-window-configuration (current-window-configuration))
  5064. (put 'pr-i-process 'pr-widget-list nil)
  5065. (put 'pr-i-ps-send 'pr-widget-list nil)
  5066. (delete-other-windows)
  5067. (kill-buffer (get-buffer-create pr-buffer-name))
  5068. (switch-to-buffer (get-buffer-create pr-buffer-name))
  5069. ;; header
  5070. (let ((versions (concat "printing v" pr-version
  5071. " ps-print v" ps-print-version)))
  5072. ;; to keep compatibility with Emacs 20 & 21:
  5073. ;; DO NOT REPLACE `?\ ' BY `?\s'
  5074. (widget-insert (make-string (- 79 (length versions)) ?\ ) versions))
  5075. (pr-insert-italic "\nCurrent Directory : " 1)
  5076. (pr-insert-italic default-directory)
  5077. (pr-insert-section-1) ; 1. Print
  5078. (pr-insert-section-2) ; 2. PostScript Printer
  5079. (pr-insert-section-3) ; 3. Text Printer
  5080. ;; separator
  5081. (widget-insert "\n\n " (make-string 77 ?-))
  5082. (pr-insert-section-4) ; 4. Settings
  5083. (pr-insert-section-5) ; 5. Customize
  5084. (pr-insert-section-6) ; 6. Show Settings
  5085. (pr-insert-section-7) ; 7. Help
  5086. (use-local-map pr-interface-map)
  5087. (widget-setup)
  5088. (goto-char (point-min))
  5089. (and pr-i-region ; let region activated
  5090. (pr-keep-region-active)))
  5091. (declare-function widget-field-action "wid-edit" (widget &optional _event))
  5092. (declare-function widget-value-set "wid-edit" (widget value))
  5093. (defun pr-insert-section-1 ()
  5094. ;; 1. Print:
  5095. (pr-insert-italic "\nPrint :" 1)
  5096. ;; 1a. Buffer:
  5097. ;; 1a. Buffer: Buffer List
  5098. (pr-insert-radio-button 'pr-i-process 'buffer)
  5099. (pr-insert-menu "Buffer List" 'pr-i-buffer
  5100. (let ((blist (buffer-list))
  5101. case-fold-search choices)
  5102. (while blist
  5103. (let ((name (buffer-name (car blist)))
  5104. (ignore pr-buffer-name-ignore)
  5105. found)
  5106. (setq blist (cdr blist))
  5107. (while (and ignore (not found))
  5108. (setq found (string-match (car ignore) name)
  5109. ignore (cdr ignore)))
  5110. (or found
  5111. (setq choices
  5112. (cons (list 'quote
  5113. (list 'choice-item
  5114. :format "%[%t%]"
  5115. name))
  5116. choices)))))
  5117. (nreverse choices))
  5118. " Buffer : " nil
  5119. '(progn
  5120. (pr-interface-save
  5121. (setq pr-i-region (ps-mark-active-p)
  5122. pr-i-mode (pr-mode-alist-p)))
  5123. (pr-update-checkbox 'pr-i-region)
  5124. (pr-update-checkbox 'pr-i-mode)))
  5125. ;; 1a. Buffer: Region
  5126. (put 'pr-i-region 'pr-widget
  5127. (pr-insert-checkbox
  5128. "\n "
  5129. 'pr-i-region
  5130. #'(lambda (widget &rest _ignore)
  5131. (let ((region-p (pr-interface-save
  5132. (ps-mark-active-p))))
  5133. (cond ((null (widget-value widget)) ; widget is nil
  5134. (setq pr-i-region nil))
  5135. (region-p ; widget is true and there is a region
  5136. (setq pr-i-region t)
  5137. (widget-value-set widget t)
  5138. (widget-setup)) ; MUST be called after widget-value-set
  5139. (t ; widget is true and there is no region
  5140. (ding)
  5141. (message "There is no region active")
  5142. (setq pr-i-region nil)
  5143. (widget-value-set widget nil)
  5144. (widget-setup))))) ; MUST be called after widget-value-set
  5145. " Region"))
  5146. ;; 1a. Buffer: Mode
  5147. (put 'pr-i-mode 'pr-widget
  5148. (pr-insert-checkbox
  5149. " "
  5150. 'pr-i-mode
  5151. #'(lambda (widget &rest _ignore)
  5152. (let ((mode-p (pr-interface-save
  5153. (pr-mode-alist-p))))
  5154. (cond
  5155. ((null (widget-value widget)) ; widget is nil
  5156. (setq pr-i-mode nil))
  5157. (mode-p ; widget is true and there is a `mode'
  5158. (setq pr-i-mode t)
  5159. (widget-value-set widget t)
  5160. (widget-setup)) ; MUST be called after widget-value-set
  5161. (t ; widget is true and there is no `mode'
  5162. (ding)
  5163. (message
  5164. "This buffer isn't in a mode that printing treats specially.")
  5165. (setq pr-i-mode nil)
  5166. (widget-value-set widget nil)
  5167. (widget-setup))))) ; MUST be called after widget-value-set
  5168. " Mode\n"))
  5169. ;; 1b. Directory:
  5170. (pr-insert-radio-button 'pr-i-process 'directory)
  5171. (widget-create
  5172. 'directory
  5173. :size 58
  5174. :format " Directory : %v"
  5175. :notify 'pr-interface-directory
  5176. :action (lambda (widget &optional event)
  5177. (if (pr-interface-directory widget)
  5178. (pr-widget-field-action widget event)
  5179. (ding)
  5180. (message "Please specify a readable directory")))
  5181. pr-i-directory)
  5182. ;; 1b. Directory: File Regexp
  5183. (widget-create 'regexp
  5184. :size 58
  5185. :format "\n File Regexp : %v\n"
  5186. :notify (lambda (widget &rest _ignore)
  5187. (setq pr-i-regexp (widget-value widget)))
  5188. pr-i-regexp)
  5189. ;; 1b. Directory: List Directory Entry
  5190. (widget-insert " ")
  5191. (pr-insert-toggle 'pr-list-directory " List Directory Entry\n")
  5192. ;; 1c. PostScript File:
  5193. (pr-insert-radio-button 'pr-i-process 'file)
  5194. (widget-create
  5195. 'file
  5196. :size 51
  5197. :format " PostScript File : %v"
  5198. :notify 'pr-interface-infile
  5199. :action (lambda (widget &rest event)
  5200. (if (pr-interface-infile widget)
  5201. (pr-widget-field-action widget event)
  5202. (ding)
  5203. (message "Please specify a readable PostScript file")))
  5204. pr-i-ps-file)
  5205. ;; 1c. PostScript File: PostScript Utility
  5206. (pr-insert-menu "PostScript Utility" 'pr-ps-utility
  5207. (pr-choice-alist pr-ps-utility-alist)
  5208. "\n PostScript Utility : "
  5209. " ")
  5210. ;; 1c. PostScript File: No Preprocessing
  5211. (pr-insert-toggle 'pr-i-ps-as-is " No Preprocessing"))
  5212. (defun pr-insert-section-2 ()
  5213. ;; 2. PostScript Printer:
  5214. ;; 2. PostScript Printer: PostScript Printer List
  5215. (pr-insert-italic "\n\nPostScript Printer : " 2 20)
  5216. (pr-insert-menu "PostScript Printer" 'pr-ps-name
  5217. (pr-choice-alist pr-ps-printer-alist))
  5218. ;; 2. PostScript Printer: Despool
  5219. (put 'pr-i-despool 'pr-widget
  5220. (pr-insert-checkbox
  5221. " "
  5222. 'pr-i-despool
  5223. #'(lambda (widget &rest _ignore)
  5224. (if pr-spool-p
  5225. (setq pr-i-despool (not pr-i-despool))
  5226. (ding)
  5227. (message "Can despool only when spooling is actually selected")
  5228. (setq pr-i-despool nil))
  5229. (widget-value-set widget pr-i-despool)
  5230. (widget-setup)) ; MUST be called after widget-value-set
  5231. " Despool "))
  5232. ;; 2. PostScript Printer: Preview Print Quit
  5233. (pr-insert-button 'pr-interface-preview "Preview" " ")
  5234. (pr-insert-button 'pr-interface-ps-print "Print" " ")
  5235. (pr-insert-button 'pr-interface-quit "Quit")
  5236. ;; 2. PostScript Printer: Send to Printer/Temporary File
  5237. (pr-insert-radio-button 'pr-i-ps-send 'printer)
  5238. (widget-insert " Send to Printer/Temporary File")
  5239. ;; 2. PostScript Printer: Send to File
  5240. (pr-insert-radio-button 'pr-i-ps-send 'file)
  5241. (widget-create
  5242. 'file
  5243. :size 57
  5244. :format " Send to File : %v"
  5245. :notify 'pr-interface-outfile
  5246. :action (lambda (widget &rest event)
  5247. (if (and (pr-interface-outfile widget)
  5248. (or (not (file-exists-p pr-i-out-file))
  5249. (setq pr-i-answer-yes
  5250. (y-or-n-p "File exists; overwrite? "))))
  5251. (pr-widget-field-action widget event)
  5252. (ding)
  5253. (message "Please specify a writable PostScript file")))
  5254. pr-i-out-file)
  5255. ;; 2. PostScript Printer: N-Up
  5256. (widget-create
  5257. 'integer
  5258. :size 3
  5259. :format "\n N-Up : %v"
  5260. :notify (lambda (widget &rest _ignore)
  5261. (let ((value (if (string= (widget-apply widget :value-get) "")
  5262. 0
  5263. (widget-value widget))))
  5264. (if (and (integerp value)
  5265. (<= 1 value) (<= value 100))
  5266. (progn
  5267. (message " ")
  5268. (setq pr-i-n-up value))
  5269. (ding)
  5270. (message "Please specify an integer between 1 and 100"))))
  5271. pr-i-n-up))
  5272. (defun pr-insert-section-3 ()
  5273. ;; 3. Text Printer:
  5274. (pr-insert-italic "\n\nText Printer : " 2 14)
  5275. (pr-insert-menu "Text Printer" 'pr-txt-name
  5276. (pr-choice-alist pr-txt-printer-alist)
  5277. nil " ")
  5278. (pr-insert-button 'pr-interface-printify "Printify" " ")
  5279. (pr-insert-button 'pr-interface-txt-print "Print" " ")
  5280. (pr-insert-button 'pr-interface-quit "Quit"))
  5281. (defun pr-insert-section-4 ()
  5282. ;; 4. Settings:
  5283. ;; 4. Settings: Landscape Auto Region Verbose
  5284. (pr-insert-checkbox "\n\n " 'ps-landscape-mode
  5285. #'(lambda (&rest _ignore)
  5286. (setq ps-landscape-mode (not ps-landscape-mode)
  5287. pr-file-landscape ps-landscape-mode))
  5288. " Landscape ")
  5289. (pr-insert-toggle 'pr-auto-region " Auto Region ")
  5290. (pr-insert-toggle 'pr-buffer-verbose " Verbose\n ")
  5291. ;; 4. Settings: Print Header Auto Mode
  5292. (pr-insert-toggle 'ps-print-header " Print Header ")
  5293. (pr-insert-toggle 'pr-auto-mode " Auto Mode\n ")
  5294. ;; 4. Settings: Print Header Frame Menu Lock
  5295. (pr-insert-toggle 'ps-print-header-frame " Print Header Frame ")
  5296. (pr-insert-toggle 'pr-menu-lock " Menu Lock\n ")
  5297. ;; 4. Settings: Line Number
  5298. (pr-insert-toggle 'ps-line-number " Line Number\n ")
  5299. ;; 4. Settings: Zebra Stripes Spool Buffer
  5300. (pr-insert-toggle 'ps-zebra-stripes " Zebra Stripes")
  5301. (pr-insert-checkbox " "
  5302. 'pr-spool-p
  5303. #'(lambda (&rest _ignore)
  5304. (setq pr-spool-p (not pr-spool-p))
  5305. (unless pr-spool-p
  5306. (setq pr-i-despool nil)
  5307. (pr-update-checkbox 'pr-i-despool)))
  5308. " Spool Buffer")
  5309. ;; 4. Settings: Duplex Print with faces
  5310. (pr-insert-checkbox "\n "
  5311. 'ps-spool-duplex
  5312. #'(lambda (&rest _ignore)
  5313. (setq ps-spool-duplex (not ps-spool-duplex)
  5314. pr-file-duplex ps-spool-duplex))
  5315. " Duplex ")
  5316. (pr-insert-toggle 'pr-faces-p " Print with faces")
  5317. ;; 4. Settings: Tumble Print via Ghostscript
  5318. (pr-insert-checkbox "\n "
  5319. 'ps-spool-tumble
  5320. #'(lambda (&rest _ignore)
  5321. (setq ps-spool-tumble (not ps-spool-tumble)
  5322. pr-file-tumble ps-spool-tumble))
  5323. " Tumble ")
  5324. (pr-insert-toggle 'pr-print-using-ghostscript " Print via Ghostscript\n ")
  5325. ;; 4. Settings: Upside-Down Page Parity
  5326. (pr-insert-toggle 'ps-print-upside-down " Upside-Down")
  5327. (pr-insert-italic "\n\nSelect Pages : " 2 14)
  5328. (pr-insert-menu "Page Parity" 'ps-even-or-odd-pages
  5329. (mapcar #'(lambda (alist)
  5330. (list 'quote
  5331. (list 'choice-item
  5332. :format "%[%t%]"
  5333. :tag (cdr alist)
  5334. :value (car alist))))
  5335. pr-even-or-odd-alist)))
  5336. (defun pr-insert-section-5 ()
  5337. ;; 5. Customize:
  5338. (pr-insert-italic "\n\nCustomize : " 2 11)
  5339. (pr-insert-button 'pr-customize "printing" " ")
  5340. (pr-insert-button #'(lambda (&rest _ignore) (ps-print-customize))
  5341. "ps-print" " ")
  5342. (pr-insert-button 'lpr-customize "lpr"))
  5343. (defun pr-insert-section-6 ()
  5344. ;; 6. Show Settings:
  5345. (pr-insert-italic "\nShow Settings : " 1 14)
  5346. (pr-insert-button 'pr-show-pr-setup "printing" " ")
  5347. (pr-insert-button 'pr-show-ps-setup "ps-print" " ")
  5348. (pr-insert-button 'pr-show-lpr-setup "lpr"))
  5349. (defun pr-insert-section-7 ()
  5350. ;; 7. Help:
  5351. (pr-insert-italic "\nHelp : " 1 5)
  5352. (pr-insert-button 'pr-interface-help "Interface Help" " ")
  5353. (pr-insert-button 'pr-help "Menu Help" " ")
  5354. (pr-insert-button 'pr-interface-quit "Quit" "\n ")
  5355. (pr-insert-button 'pr-kill-help "Kill All Printing Help Buffer"))
  5356. (defun pr-kill-help (&rest _ignore)
  5357. "Kill all printing help buffer."
  5358. (interactive)
  5359. (let ((help '("*Printing Interface Help*" "*Printing Help*"
  5360. "*LPR Setup*" "*PR Setup*" "*PS Setup*")))
  5361. (while help
  5362. (let ((buffer (get-buffer (car help))))
  5363. (setq help (cdr help))
  5364. (when buffer
  5365. (delete-windows-on buffer)
  5366. (kill-buffer buffer)))))
  5367. (recenter (- (window-height) 2)))
  5368. (defun pr-interface-quit (&rest _ignore)
  5369. "Kill the printing buffer interface and quit."
  5370. (interactive)
  5371. (kill-buffer pr-buffer-name)
  5372. (set-window-configuration pr-i-window-configuration))
  5373. (defun pr-interface-help (&rest _ignore)
  5374. "printing buffer interface help."
  5375. (interactive)
  5376. (pr-show-setup pr-interface-help-message "*Printing Interface Help*"))
  5377. (defun pr-interface-txt-print (&rest _ignore)
  5378. "Print using lpr package."
  5379. (interactive)
  5380. (condition-case data
  5381. (cond
  5382. ((eq pr-i-process 'directory)
  5383. (pr-i-directory)
  5384. (pr-interface-save
  5385. (pr-txt-directory pr-i-directory pr-i-regexp)))
  5386. ((eq pr-i-process 'buffer)
  5387. (pr-interface-save
  5388. (cond (pr-i-region
  5389. (let ((pr-auto-mode pr-i-mode))
  5390. (pr-txt-region)))
  5391. (pr-i-mode
  5392. (let (pr-auto-region)
  5393. (pr-txt-mode)))
  5394. (t
  5395. (let (pr-auto-mode pr-auto-region)
  5396. (pr-txt-buffer)))
  5397. )))
  5398. ((eq pr-i-process 'file)
  5399. (error "Please specify a text file"))
  5400. (t
  5401. (error "Internal error: `pr-i-process' = %S" pr-i-process))
  5402. )
  5403. ;; handlers
  5404. ((quit error)
  5405. (ding)
  5406. (message "%s" (error-message-string data)))))
  5407. (defun pr-interface-printify (&rest _ignore)
  5408. "Printify a buffer."
  5409. (interactive)
  5410. (condition-case data
  5411. (cond
  5412. ((eq pr-i-process 'directory)
  5413. (pr-i-directory)
  5414. (pr-interface-save
  5415. (pr-printify-directory pr-i-directory pr-i-regexp)))
  5416. ((eq pr-i-process 'buffer)
  5417. (pr-interface-save
  5418. (if pr-i-region
  5419. (pr-printify-region)
  5420. (pr-printify-buffer))))
  5421. ((eq pr-i-process 'file)
  5422. (error "Cannot printify a PostScript file"))
  5423. (t
  5424. (error "Internal error: `pr-i-process' = %S" pr-i-process))
  5425. )
  5426. ;; handlers
  5427. ((quit error)
  5428. (ding)
  5429. (message "%s" (error-message-string data)))))
  5430. (defun pr-interface-ps-print (&rest _ignore)
  5431. "Print using ps-print package."
  5432. (interactive)
  5433. (pr-interface-ps 'pr-despool-ps-print 'pr-ps-directory-ps-print
  5434. 'pr-ps-file-ps-print 'pr-ps-file-up-ps-print
  5435. 'pr-ps-region-ps-print 'pr-ps-mode-ps-print
  5436. 'pr-ps-buffer-ps-print))
  5437. (defun pr-interface-preview (&rest _ignore)
  5438. "Preview a PostScript file."
  5439. (interactive)
  5440. (pr-interface-ps 'pr-despool-preview 'pr-ps-directory-preview
  5441. 'pr-ps-file-preview 'pr-ps-file-up-preview
  5442. 'pr-ps-region-preview 'pr-ps-mode-preview
  5443. 'pr-ps-buffer-preview))
  5444. (defun pr-interface-ps (ps-despool ps-directory ps-file ps-file-up ps-region
  5445. ps-mode ps-buffer)
  5446. (condition-case data
  5447. (let ((outfile (or (and (eq pr-i-process 'file) pr-i-ps-as-is)
  5448. (pr-i-ps-send))))
  5449. (cond
  5450. ((and pr-i-despool pr-spool-p)
  5451. (pr-interface-save
  5452. (funcall ps-despool outfile))
  5453. (setq pr-i-despool nil)
  5454. (pr-update-checkbox 'pr-i-despool))
  5455. ((eq pr-i-process 'directory)
  5456. (pr-i-directory)
  5457. (pr-interface-save
  5458. (funcall ps-directory
  5459. pr-i-n-up pr-i-directory pr-i-regexp outfile)))
  5460. ((eq pr-i-process 'file)
  5461. (cond ((or (file-directory-p pr-i-ps-file)
  5462. (not (file-readable-p pr-i-ps-file)))
  5463. (error "Please specify a readable PostScript file"))
  5464. (pr-i-ps-as-is
  5465. (pr-interface-save
  5466. (funcall ps-file pr-i-ps-file)))
  5467. (t
  5468. (pr-interface-save
  5469. (funcall ps-file-up pr-i-n-up pr-i-ps-file outfile)))
  5470. ))
  5471. ((eq pr-i-process 'buffer)
  5472. (pr-interface-save
  5473. (cond (pr-i-region
  5474. (let ((pr-auto-mode pr-i-mode))
  5475. (funcall ps-region pr-i-n-up outfile)))
  5476. (pr-i-mode
  5477. (let (pr-auto-region)
  5478. (funcall ps-mode pr-i-n-up outfile)))
  5479. (t
  5480. (let (pr-auto-mode pr-auto-region)
  5481. (funcall ps-buffer pr-i-n-up outfile)))
  5482. )))
  5483. (t
  5484. (error "Internal error: `pr-i-process' = %S" pr-i-process))
  5485. ))
  5486. ;; handlers
  5487. ((quit error)
  5488. (ding)
  5489. (message "%s" (error-message-string data)))))
  5490. (defun pr-i-ps-send ()
  5491. (cond ((eq pr-i-ps-send 'printer)
  5492. nil)
  5493. ((not (eq pr-i-ps-send 'file))
  5494. (error "Internal error: `pr-i-ps-send' = %S" pr-i-ps-send))
  5495. ((or (file-directory-p pr-i-out-file)
  5496. (not (file-writable-p pr-i-out-file)))
  5497. (error "Please specify a writable PostScript file"))
  5498. ((or (not (file-exists-p pr-i-out-file))
  5499. pr-i-answer-yes
  5500. (setq pr-i-answer-yes
  5501. (y-or-n-p (format-message "File `%s' exists; overwrite? "
  5502. pr-i-out-file))))
  5503. pr-i-out-file)
  5504. (t
  5505. (error "File already exists"))))
  5506. (defun pr-i-directory ()
  5507. (or (file-accessible-directory-p pr-i-directory)
  5508. (error "Please specify be a readable directory")))
  5509. (defun pr-interface-directory (widget &rest _ignore)
  5510. (and pr-buffer-verbose
  5511. (message "You can use M-TAB or ESC TAB for file completion"))
  5512. (let ((dir (widget-value widget)))
  5513. (and (file-accessible-directory-p dir)
  5514. (setq pr-i-directory dir))))
  5515. (defun pr-interface-infile (widget &rest _ignore)
  5516. (and pr-buffer-verbose
  5517. (message "You can use M-TAB or ESC TAB for file completion"))
  5518. (let ((file (widget-value widget)))
  5519. (and (not (file-directory-p file))
  5520. (file-readable-p file)
  5521. (setq pr-i-ps-file file))))
  5522. (defun pr-interface-outfile (widget &rest _ignore)
  5523. (setq pr-i-answer-yes nil)
  5524. (and pr-buffer-verbose
  5525. (message "You can use M-TAB or ESC TAB for file completion"))
  5526. (let ((file (widget-value widget)))
  5527. (and (not (file-directory-p file))
  5528. (file-writable-p file)
  5529. (setq pr-i-out-file file))))
  5530. (defun pr-widget-field-action (widget event)
  5531. (and (get-buffer "*Completions*") ; clean frame window
  5532. (delete-windows-on "*Completions*"))
  5533. (message " ") ; clean echo area
  5534. (widget-field-action widget event))
  5535. (defun pr-insert-italic (str &optional from to)
  5536. (let ((len (length str)))
  5537. (put-text-property (if from (max from 0) 0)
  5538. (if to (max to len) len)
  5539. 'face 'italic str)
  5540. (widget-insert str)))
  5541. (defun pr-insert-checkbox (before var-sym fun label)
  5542. (widget-insert before)
  5543. (prog1
  5544. (widget-create 'checkbox
  5545. :notify fun
  5546. (symbol-value var-sym))
  5547. (widget-insert label)))
  5548. (defun pr-insert-toggle (var-sym label)
  5549. (widget-create 'checkbox
  5550. :notify `(lambda (&rest _ignore)
  5551. (setq ,var-sym (not ,var-sym)))
  5552. (symbol-value var-sym))
  5553. (widget-insert label))
  5554. (defun pr-insert-button (fun label &optional separator)
  5555. (widget-create 'push-button
  5556. :notify fun
  5557. label)
  5558. (and separator
  5559. (widget-insert separator)))
  5560. (defun pr-insert-menu (tag var-sym choices &optional before after &rest body)
  5561. (and before (widget-insert before))
  5562. (eval `(widget-create 'menu-choice
  5563. :tag ,tag
  5564. :format "%v"
  5565. :inline t
  5566. :value ,var-sym
  5567. :notify (lambda (widget &rest _ignore)
  5568. (setq ,var-sym (widget-value widget))
  5569. ,@body)
  5570. :void '(choice-item :format "%[%t%]"
  5571. :tag "Can not display value!")
  5572. ,@choices))
  5573. (and after (widget-insert after)))
  5574. (defun pr-insert-radio-button (var-sym sym)
  5575. (widget-insert "\n")
  5576. (let ((wid-list (get var-sym 'pr-widget-list))
  5577. (wid (eval `(widget-create
  5578. 'radio-button
  5579. :format " %[%v%]"
  5580. :value (eq ,var-sym (quote ,sym))
  5581. :notify (lambda (&rest _ignore)
  5582. (setq ,var-sym (quote ,sym))
  5583. (pr-update-radio-button (quote ,var-sym)))))))
  5584. (put var-sym 'pr-widget-list (cons (cons wid sym) wid-list))))
  5585. (defun pr-update-radio-button (var-sym)
  5586. (let ((wid-list (get var-sym 'pr-widget-list)))
  5587. (while wid-list
  5588. (let ((wid (car (car wid-list)))
  5589. (value (cdr (car wid-list))))
  5590. (setq wid-list (cdr wid-list))
  5591. (widget-value-set wid (eq (symbol-value var-sym) value))))
  5592. (widget-setup)))
  5593. (defun pr-update-checkbox (var-sym)
  5594. (let ((wid (get var-sym 'pr-widget)))
  5595. (when wid
  5596. (widget-value-set wid (symbol-value var-sym))
  5597. (widget-setup))))
  5598. (defun pr-choice-alist (alist)
  5599. (let ((max (apply 'max (mapcar #'(lambda (alist)
  5600. (length (symbol-name (car alist))))
  5601. alist))))
  5602. (mapcar #'(lambda (alist)
  5603. (let* ((sym (car alist))
  5604. (name (symbol-name sym)))
  5605. (list
  5606. 'quote
  5607. (list
  5608. 'choice-item
  5609. :format "%[%t%]"
  5610. :tag (concat name
  5611. (make-string (- max (length name)) ?_))
  5612. :value sym))))
  5613. alist)))
  5614. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5615. (provide 'printing)
  5616. ;;; printing.el ends here