printing.el 219 KB

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