vhdl-mode.el 645 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963
  1. ;;; vhdl-mode.el --- major mode for editing VHDL code
  2. ;; Copyright (C) 1992-2012 Free Software Foundation, Inc.
  3. ;; Authors: Reto Zimmermann <reto@gnu.org>
  4. ;; Rodney J. Whitby <software.vhdl-mode@rwhitby.net>
  5. ;; Maintainer: Reto Zimmermann <reto@gnu.org>
  6. ;; Keywords: languages vhdl
  7. ;; WWW: http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html
  8. ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
  9. ;; file on 18/3/2008, and the maintainer agreed that when a bug is
  10. ;; filed in the Emacs bug reporting system against this file, a copy
  11. ;; of the bug report be sent to the maintainer's email address.
  12. (defconst vhdl-version "3.33.6"
  13. "VHDL Mode version number.")
  14. (defconst vhdl-time-stamp "2005-08-30"
  15. "VHDL Mode time stamp for last update.")
  16. ;; This file is part of GNU Emacs.
  17. ;; GNU Emacs is free software: you can redistribute it and/or modify
  18. ;; it under the terms of the GNU General Public License as published by
  19. ;; the Free Software Foundation, either version 3 of the License, or
  20. ;; (at your option) any later version.
  21. ;; GNU Emacs is distributed in the hope that it will be useful,
  22. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. ;; GNU General Public License for more details.
  25. ;; You should have received a copy of the GNU General Public License
  26. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  27. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  28. ;;; Commentary:
  29. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  30. ;; This package provides an Emacs major mode for editing VHDL code.
  31. ;; It includes the following features:
  32. ;; - Syntax highlighting
  33. ;; - Indentation
  34. ;; - Template insertion (electrification)
  35. ;; - Insertion of file headers
  36. ;; - Insertion of user-specified models
  37. ;; - Port translation / testbench generation
  38. ;; - Structural composition
  39. ;; - Configuration generation
  40. ;; - Sensitivity list updating
  41. ;; - File browser
  42. ;; - Design hierarchy browser
  43. ;; - Source file compilation (syntax analysis)
  44. ;; - Makefile generation
  45. ;; - Code hiding
  46. ;; - Word/keyword completion
  47. ;; - Block commenting
  48. ;; - Code fixing/alignment/beautification
  49. ;; - PostScript printing
  50. ;; - VHDL'87/'93 and VHDL-AMS supported
  51. ;; - Comprehensive menu
  52. ;; - Fully customizable
  53. ;; - Works under GNU Emacs (recommended) and XEmacs
  54. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  55. ;; Documentation
  56. ;; See comment string of function `vhdl-mode' or type `C-c C-h' in Emacs.
  57. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  58. ;; Emacs Versions
  59. ;; supported: GNU Emacs 20.X/21.X/22.X, XEmacs 20.X/21.X
  60. ;; tested on: GNU Emacs 20.4, XEmacs 21.1 (marginally)
  61. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  62. ;; Installation
  63. ;; Prerequisites: GNU Emacs 20.X/21.X/22.X, XEmacs 20.X/21.X.
  64. ;; Put `vhdl-mode.el' into the `site-lisp' directory of your Emacs installation
  65. ;; or into an arbitrary directory that is added to the load path by the
  66. ;; following line in your Emacs start-up file `.emacs':
  67. ;; (setq load-path (cons (expand-file-name "<directory-name>") load-path))
  68. ;; If you already have the compiled `vhdl-mode.elc' file, put it in the same
  69. ;; directory. Otherwise, byte-compile the source file:
  70. ;; Emacs: M-x byte-compile-file RET vhdl-mode.el RET
  71. ;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vhdl-mode.el
  72. ;; Add the following lines to the `site-start.el' file in the `site-lisp'
  73. ;; directory of your Emacs installation or to your Emacs start-up file `.emacs'
  74. ;; (not required in Emacs 20.X):
  75. ;; (autoload 'vhdl-mode "vhdl-mode" "VHDL Mode" t)
  76. ;; (setq auto-mode-alist (cons '("\\.vhdl?\\'" . vhdl-mode) auto-mode-alist))
  77. ;; More detailed installation instructions are included in the official
  78. ;; VHDL Mode distribution.
  79. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  80. ;; Acknowledgements
  81. ;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu>
  82. ;; and Steve Grout.
  83. ;; Fontification approach suggested by Ken Wood <ken@eda.com.au>.
  84. ;; Ideas about alignment from John Wiegley <johnw@gnu.org>.
  85. ;; Many thanks to all the users who sent me bug reports and enhancement
  86. ;; requests.
  87. ;; Thanks to Colin Marquardt for his serious beta testing, his innumerable
  88. ;; enhancement suggestions and the fruitful discussions.
  89. ;; Thanks to Dan Nicolaescu for reviewing the code and for his valuable hints.
  90. ;; Thanks to Ulf Klaperski for the indentation speedup hint.
  91. ;; Special thanks go to Wolfgang Fichtner and the crew from the Integrated
  92. ;; Systems Laboratory, Swiss Federal Institute of Technology Zurich, for
  93. ;; giving me the opportunity to develop this code.
  94. ;; This work has been funded in part by MICROSWISS, a Microelectronics Program
  95. ;; of the Swiss Government.
  96. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  97. ;;; Code:
  98. ;; Emacs 21+ handling
  99. (defconst vhdl-emacs-21 (and (<= 21 emacs-major-version) (not (featurep 'xemacs)))
  100. "Non-nil if GNU Emacs 21, 22, ... is used.")
  101. (defconst vhdl-emacs-22 (and (<= 22 emacs-major-version) (not (featurep 'xemacs)))
  102. "Non-nil if GNU Emacs 22, ... is used.")
  103. (defvar compilation-file-regexp-alist)
  104. (defvar conf-alist)
  105. (defvar conf-entry)
  106. (defvar conf-key)
  107. (defvar ent-alist)
  108. (defvar itimer-version)
  109. (defvar lazy-lock-defer-contextually)
  110. (defvar lazy-lock-defer-on-scrolling)
  111. (defvar lazy-lock-defer-on-the-fly)
  112. (defvar speedbar-attached-frame)
  113. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  114. ;;; Variables
  115. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  116. ;; help function for user options
  117. (defun vhdl-custom-set (variable value &rest functions)
  118. "Set variables as in `custom-set-default' and call FUNCTIONS afterwards."
  119. (if (fboundp 'custom-set-default)
  120. (custom-set-default variable value)
  121. (set-default variable value))
  122. (while functions
  123. (when (fboundp (car functions)) (funcall (car functions)))
  124. (setq functions (cdr functions))))
  125. (defun vhdl-widget-directory-validate (widget)
  126. "Check that the value of WIDGET is a valid directory entry (i.e. ends with
  127. '/' or is empty)."
  128. (let ((val (widget-value widget)))
  129. (unless (string-match "^\\(\\|.*/\\)$" val)
  130. (widget-put widget :error "Invalid directory entry: must end with '/'")
  131. widget)))
  132. ;; help string for user options
  133. (defconst vhdl-name-doc-string "
  134. FROM REGEXP is a regular expression matching the original name:
  135. \".*\" matches the entire string
  136. \"\\(...\\)\" matches a substring
  137. TO STRING specifies the string to be inserted as new name:
  138. \"\\&\" means substitute entire matched text
  139. \"\\N\" means substitute what matched the Nth \"\\(...\\)\"
  140. Examples:
  141. \".*\" \"\\&\" inserts original string
  142. \".*\" \"\\&_i\" attaches \"_i\" to original string
  143. \"\\(.*\\)_[io]$\" \"\\1\" strips off \"_i\" or \"_o\" from original string
  144. \".*\" \"foo\" inserts constant string \"foo\"
  145. \".*\" \"\" inserts empty string")
  146. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  147. ;; User variables
  148. (defgroup vhdl nil
  149. "Customizations for VHDL Mode."
  150. :prefix "vhdl-"
  151. :group 'languages
  152. ; :version "21.2" ; comment out for XEmacs
  153. )
  154. (defgroup vhdl-mode nil
  155. "Customizations for modes."
  156. :group 'vhdl)
  157. (defcustom vhdl-indent-tabs-mode nil
  158. "*Non-nil means indentation can insert tabs.
  159. Overrides local variable `indent-tabs-mode'."
  160. :type 'boolean
  161. :group 'vhdl-mode)
  162. (defgroup vhdl-compile nil
  163. "Customizations for compilation."
  164. :group 'vhdl)
  165. (defcustom vhdl-compiler-alist
  166. '(
  167. ;; Cadence Leapfrog: cv -file test.vhd
  168. ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
  169. ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
  170. nil "mkdir \\1" "./" "work/" "Makefile" "leapfrog"
  171. ("duluth: \\*E,[0-9]+ (\\(.+\\),\\([0-9]+\\)):" 1 2 0) ("" 0)
  172. ("\\1/entity" "\\2/\\1" "\\1/configuration"
  173. "\\1/package" "\\1/body" downcase))
  174. ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
  175. ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
  176. ;; (PLL_400X_TOP) is not declared [10.3].
  177. ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
  178. nil "mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
  179. ("ncvhdl_p: \\*E,\\w+ (\\(.+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
  180. ("\\1/entity/pc.db" "\\2/\\1/pc.db" "\\1/configuration/pc.db"
  181. "\\1/package/pc.db" "\\1/body/pc.db" downcase))
  182. ;; Ikos Voyager: analyze test.vhd
  183. ;; analyze test.vhd
  184. ;; E L4/C5: this library unit is inaccessible
  185. ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
  186. nil "mkdir \\1" "./" "work/" "Makefile" "ikos"
  187. ("E L\\([0-9]+\\)/C\\([0-9]+\\):" 0 1 2)
  188. ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
  189. nil)
  190. ;; ModelSim, Model Technology: vcom test.vhd
  191. ;; ERROR: test.vhd(14): Unknown identifier: positiv
  192. ;; WARNING[2]: test.vhd(85): Possible infinite loop
  193. ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
  194. ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
  195. nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
  196. ("\\(ERROR\\|WARNING\\|\\*\\* Error\\|\\*\\* Warning\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
  197. ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
  198. "\\1/_primary.dat" "\\1/body.dat" downcase))
  199. ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
  200. ;; test.vhd:34: error message
  201. ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
  202. nil "mkdir \\1" "./" "work/" "Makefile" "provhdl"
  203. ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
  204. ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
  205. "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase))
  206. ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
  207. ;; ERROR: test.vhd(24): near "dnd": expecting: END
  208. ;; WARNING[4]: test.vhd(30): A space is required between ...
  209. ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
  210. nil "mkdir \\1" "./" "work/" "Makefile" "quickhdl"
  211. ("\\(ERROR\\|WARNING\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
  212. ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
  213. "\\1/_primary.dat" "\\1/body.dat" downcase))
  214. ;; Savant: scram -publish-cc test.vhd
  215. ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
  216. ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
  217. nil "mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
  218. ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
  219. ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
  220. "\\1_config.vhdl" "\\1_package.vhdl"
  221. "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase))
  222. ;; Simili: vhdlp -work test.vhd
  223. ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
  224. ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
  225. nil "mkdir \\1" "./" "work/" "Makefile" "simili"
  226. ("\\(Error\\|Warning\\): \\w+: \\(.+\\): (line \\([0-9]+\\)): " 2 3 0) ("" 0)
  227. ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
  228. "\\1/prim.var" "\\1/_body.var" downcase))
  229. ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
  230. ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
  231. ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
  232. nil "mkdir \\1" "./" "work/" "Makefile" "speedwave"
  233. ("^ *ERROR\[[0-9]+\]::File \\(.+\\) Line \\([0-9]+\\):" 1 2 0) ("" 0)
  234. nil)
  235. ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
  236. ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
  237. ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
  238. nil "mkdir \\1" "./" "work/" "Makefile" "synopsys"
  239. ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
  240. ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase))
  241. ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
  242. ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
  243. ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
  244. nil "mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
  245. ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
  246. ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase))
  247. ;; Synplify:
  248. ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
  249. ("Synplify" "n/a" "n/a" "make" "-f \\1"
  250. nil "mkdir \\1" "./" "work/" "Makefile" "synplify"
  251. ("@[EWN]:\"\\(.+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
  252. nil)
  253. ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
  254. ;; Compiling "test.vhd" line 1...
  255. ;; **Error: LINE 49 *** No aggregate value is valid in this context.
  256. ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
  257. nil "mkdir \\1" "./" "work/" "Makefile" "vantage"
  258. ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
  259. ("^ *Compiling \"\\(.+\\)\" " 1)
  260. nil)
  261. ;; VeriBest: vc vhdl test.vhd
  262. ;; (no file name printed out!)
  263. ;; 32: Z <= A and BitA ;
  264. ;; ^^^^
  265. ;; [Error] Name BITA is unknown
  266. ("VeriBest" "vc" "vhdl" "make" "-f \\1"
  267. nil "mkdir \\1" "./" "work/" "Makefile" "veribest"
  268. ("^ +\\([0-9]+\\): +[^ ]" 0 1 0) ("" 0)
  269. nil)
  270. ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
  271. ;; Compiling "test.vhd" line 1...
  272. ;; **Error: LINE 49 *** No aggregate value is valid in this context.
  273. ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
  274. nil "mkdir \\1" "./" "work/" "Makefile" "viewlogic"
  275. ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
  276. ("^ *Compiling \"\\(.+\\)\" " 1)
  277. nil)
  278. )
  279. "*List of available VHDL compilers and their properties.
  280. Each list entry specifies the following items for a compiler:
  281. Compiler:
  282. Compiler name : name used in option `vhdl-compiler' to choose compiler
  283. Compile command : command used for source file compilation
  284. Compile options : compile options (\"\\1\" inserts library name)
  285. Make command : command used for compilation using a Makefile
  286. Make options : make options (\"\\1\" inserts Makefile name)
  287. Generate Makefile: use built-in function or command to generate a Makefile
  288. \(\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
  289. Library command : command to create library directory \(\"\\1\" inserts
  290. library directory, \"\\2\" inserts library name)
  291. Compile directory: where compilation is run and the Makefile is placed
  292. Library directory: directory of default library
  293. Makefile name : name of Makefile (default is \"Makefile\")
  294. ID string : compiler identification string (see `vhdl-project-alist')
  295. Error message:
  296. Regexp : regular expression to match error messages (*)
  297. File subexp index: index of subexpression that matches the file name
  298. Line subexp index: index of subexpression that matches the line number
  299. Column subexp idx: index of subexpression that matches the column number
  300. File message:
  301. Regexp : regular expression to match a file name message
  302. File subexp index: index of subexpression that matches the file name
  303. Unit-to-file name mapping: mapping of library unit names to names of files
  304. generated by the compiler (used for Makefile generation)
  305. To string : string a name is mapped to (\"\\1\" inserts the unit name,
  306. \"\\2\" inserts the entity name for architectures)
  307. Case adjustment : adjust case of inserted unit names
  308. \(*) The regular expression must match the error message starting from the
  309. beginning of the line (but not necessarily to the end of the line).
  310. Compile options allows insertion of the library name (see `vhdl-project-alist')
  311. in order to set the compilers library option (e.g. \"vcom -work my_lib\").
  312. For Makefile generation, the built-in function can be used (requires
  313. specification of the unit-to-file name mapping). Alternatively, an
  314. external command can be specified. Work directory allows specification of
  315. an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
  316. used for Makefile generation). To use another library name than \"work\",
  317. customize `vhdl-project-alist'. The library command is inserted in Makefiles
  318. to automatically create the library directory if not existent.
  319. Compile options, compile directory, library directory, and Makefile name are
  320. overwritten by the project settings if a project is defined (see
  321. `vhdl-project-alist'). Directory paths are relative to the source file
  322. directory.
  323. Some compilers do not include the file name in the error message, but print
  324. out a file name message in advance. In this case, set \"File Subexp Index\"
  325. under \"Error Message\" to 0 and fill out the \"File Message\" entries.
  326. If no file name at all is printed out, set both \"File Message\" entries to 0
  327. \(a default file name message will be printed out instead, does not work in
  328. XEmacs).
  329. A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
  330. assigning its name to option `vhdl-compiler'.
  331. Please send any missing or erroneous compiler properties to the maintainer for
  332. updating.
  333. NOTE: Activate new error and file message regexps and reflect the new setting
  334. in the choice list of option `vhdl-compiler' by restarting Emacs."
  335. :type '(repeat
  336. (list :tag "Compiler" :indent 2
  337. (string :tag "Compiler name ")
  338. (string :tag "Compile command ")
  339. (string :tag "Compile options " "-work \\1")
  340. (string :tag "Make command " "make")
  341. (string :tag "Make options " "-f \\1")
  342. (choice :tag "Generate Makefile "
  343. (const :tag "Built-in function" nil)
  344. (string :tag "Command" "vmake \\2 > \\1"))
  345. (string :tag "Library command " "mkdir \\1")
  346. (directory :tag "Compile directory "
  347. :validate vhdl-widget-directory-validate "./")
  348. (directory :tag "Library directory "
  349. :validate vhdl-widget-directory-validate "work/")
  350. (file :tag "Makefile name " "Makefile")
  351. (string :tag "ID string ")
  352. (list :tag "Error message" :indent 4
  353. (regexp :tag "Regexp ")
  354. (integer :tag "File subexp index")
  355. (integer :tag "Line subexp index")
  356. (integer :tag "Column subexp idx"))
  357. (list :tag "File message" :indent 4
  358. (regexp :tag "Regexp ")
  359. (integer :tag "File subexp index"))
  360. (choice :tag "Unit-to-file name mapping"
  361. :format "%t: %[Value Menu%] %v\n"
  362. (const :tag "Not defined" nil)
  363. (list :tag "To string" :indent 4
  364. (string :tag "Entity " "\\1.vhd")
  365. (string :tag "Architecture " "\\2_\\1.vhd")
  366. (string :tag "Configuration " "\\1.vhd")
  367. (string :tag "Package " "\\1.vhd")
  368. (string :tag "Package Body " "\\1_body.vhd")
  369. (choice :tag "Case adjustment "
  370. (const :tag "None" identity)
  371. (const :tag "Upcase" upcase)
  372. (const :tag "Downcase" downcase))))))
  373. :set (lambda (variable value)
  374. (vhdl-custom-set variable value 'vhdl-update-mode-menu))
  375. :group 'vhdl-compile)
  376. (defcustom vhdl-compiler "ModelSim"
  377. "*Specifies the VHDL compiler to be used for syntax analysis.
  378. Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
  379. :type (let ((alist vhdl-compiler-alist) list)
  380. (while alist
  381. (setq list (cons (list 'const (caar alist)) list))
  382. (setq alist (cdr alist)))
  383. (append '(choice) (nreverse list)))
  384. :group 'vhdl-compile)
  385. (defcustom vhdl-compile-use-local-error-regexp t
  386. "*Non-nil means use buffer-local `compilation-error-regexp-alist'.
  387. In this case, only error message regexps for VHDL compilers are active if
  388. compilation is started from a VHDL buffer. Otherwise, the error message
  389. regexps are appended to the predefined global regexps, and all regexps are
  390. active all the time. Note that by doing that, the predefined global regexps
  391. might result in erroneous parsing of error messages for some VHDL compilers.
  392. NOTE: Activate the new setting by restarting Emacs."
  393. :type 'boolean
  394. :group 'vhdl-compile)
  395. (defcustom vhdl-makefile-generation-hook nil
  396. "*Functions to run at the end of Makefile generation.
  397. Allows to insert user specific parts into a Makefile.
  398. Example:
  399. \(lambda nil
  400. \(re-search-backward \"^# Rule for compiling entire design\")
  401. \(insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
  402. :type 'hook
  403. :group 'vhdl-compile)
  404. (defcustom vhdl-default-library "work"
  405. "*Name of default library.
  406. Is overwritten by project settings if a project is active."
  407. :type 'string
  408. :group 'vhdl-compile)
  409. (defgroup vhdl-project nil
  410. "Customizations for projects."
  411. :group 'vhdl)
  412. (defcustom vhdl-project-alist
  413. '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
  414. "~/example1/" ("src/system/" "src/components/") ""
  415. (("ModelSim" "-87 \\2" "-f \\1 top_level" nil)
  416. ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" . "-optimize \\3") (".*_tb\\.vhd" . nil))))
  417. "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
  418. ("Example 2" "Individual source files, multiple compilers in different directories"
  419. "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
  420. nil "\\1/" "work" "\\1/work/" "Makefile" "")
  421. ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
  422. "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
  423. nil "./" "work" "work-\\1/" "Makefile-\\1" "\
  424. -------------------------------------------------------------------------------
  425. -- This is a multi-line project description
  426. -- that can be used as a project dependent part of the file header.
  427. "))
  428. "*List of projects and their properties.
  429. Name : name used in option `vhdl-project' to choose project
  430. Title : title of project (single-line string)
  431. Default directory: default project directory (absolute path)
  432. Sources : a) source files : path + \"/\" + file name
  433. b) directory : path + \"/\"
  434. c) directory tree: \"-r \" + path + \"/\"
  435. Exclude regexp : matches file/directory names to be excluded as sources
  436. Compile options : project-specific options for each compiler
  437. Compiler name : name of compiler for which these options are valid
  438. Compile options: project-specific compiler options
  439. (\"\\1\" inserts library name, \"\\2\" default options)
  440. Make options: project-specific make options
  441. (\"\\1\" inserts Makefile name, \"\\2\" default options)
  442. Exceptions : file-specific exceptions
  443. File name regexp: matches file names for which exceptions are valid
  444. - Options : file-specific compiler options string
  445. (\"\\1\" inserts library name, \"\\2\" default options,
  446. \"\\3\" project-specific options)
  447. - Do not compile: do not compile this file (in Makefile)
  448. Compile directory: where compilation is run and the Makefile is placed
  449. \(\"\\1\" inserts compiler ID string)
  450. Library name : name of library (default is \"work\")
  451. Library directory: path to library (\"\\1\" inserts compiler ID string)
  452. Makefile name : name of Makefile
  453. (\"\\1\" inserts compiler ID string, \"\\2\" library name)
  454. Description : description of project (multi-line string)
  455. Project title and description are used to insert into the file header (see
  456. option `vhdl-file-header').
  457. The default directory must have an absolute path (use `M-TAB' for completion).
  458. All other paths can be absolute or relative to the default directory. All
  459. paths must end with '/'.
  460. The design units found in the sources (files and directories) are shown in the
  461. hierarchy browser. Path and file name can contain wildcards `*' and `?' as
  462. well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
  463. Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
  464. specified, the default directory is taken as source directory. Otherwise,
  465. the default directory is only taken as source directory if there is a sources
  466. entry with the empty string or \"./\". Exclude regexp allows to filter out
  467. specific file and directory names from the list of sources (e.g. CVS
  468. directories).
  469. Files are compiled in the compile directory. Makefiles are also placed into
  470. the compile directory. Library directory specifies which directory the
  471. compiler compiles into (used to generate the Makefile).
  472. Since different compile/library directories and Makefiles may exist for
  473. different compilers within one project, these paths and names allow the
  474. insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
  475. Compile options, compile directory, library directory, and Makefile name
  476. overwrite the settings of the current compiler.
  477. File-specific compiler options (highest priority) overwrite project-specific
  478. options which overwrite default options (lowest priority). Lower priority
  479. options can be inserted in higher priority options. This allows to reuse
  480. default options (e.g. \"-file\") in project- or file-specific options (e.g.
  481. \"-93 -file\").
  482. NOTE: Reflect the new setting in the choice list of option `vhdl-project'
  483. by restarting Emacs."
  484. :type `(repeat
  485. (list :tag "Project" :indent 2
  486. (string :tag "Name ")
  487. (string :tag "Title ")
  488. (directory :tag "Default directory"
  489. :validate vhdl-widget-directory-validate
  490. ,(abbreviate-file-name default-directory))
  491. (repeat :tag "Sources " :indent 4
  492. (directory :format " %v" "./"))
  493. (regexp :tag "Exclude regexp ")
  494. (repeat
  495. :tag "Compile options " :indent 4
  496. (list :tag "Compiler" :indent 6
  497. ,(let ((alist vhdl-compiler-alist) list)
  498. (while alist
  499. (setq list (cons (list 'const (caar alist)) list))
  500. (setq alist (cdr alist)))
  501. (append '(choice :tag "Compiler name")
  502. (nreverse list)))
  503. (string :tag "Compile options" "\\2")
  504. (string :tag "Make options " "\\2")
  505. (repeat
  506. :tag "Exceptions " :indent 8
  507. (cons :format "%v"
  508. (regexp :tag "File name regexp ")
  509. (choice :format "%[Value Menu%] %v"
  510. (string :tag "Options" "\\3")
  511. (const :tag "Do not compile" nil))))))
  512. (directory :tag "Compile directory"
  513. :validate vhdl-widget-directory-validate "./")
  514. (string :tag "Library name " "work")
  515. (directory :tag "Library directory"
  516. :validate vhdl-widget-directory-validate "work/")
  517. (file :tag "Makefile name " "Makefile")
  518. (string :tag "Description: (type `C-j' for newline)"
  519. :format "%t\n%v\n")))
  520. :set (lambda (variable value)
  521. (vhdl-custom-set variable value
  522. 'vhdl-update-mode-menu
  523. 'vhdl-speedbar-refresh))
  524. :group 'vhdl-project)
  525. (defcustom vhdl-project nil
  526. "*Specifies the default for the current project.
  527. Select a project name from the ones defined in option `vhdl-project-alist'.
  528. Is used to determine the project title and description to be inserted in file
  529. headers and the source files/directories to be scanned in the hierarchy
  530. browser. The current project can also be changed temporarily in the menu."
  531. :type (let ((alist vhdl-project-alist) list)
  532. (while alist
  533. (setq list (cons (list 'const (caar alist)) list))
  534. (setq alist (cdr alist)))
  535. (append '(choice (const :tag "None" nil) (const :tag "--"))
  536. (nreverse list)))
  537. :group 'vhdl-project)
  538. (defcustom vhdl-project-file-name '("\\1.prj")
  539. "*List of file names/paths for importing/exporting project setups.
  540. \"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
  541. replaced by the user name (allows to have user-specific project setups).
  542. The first entry is used as file name to import/export individual project
  543. setups. All entries are used to automatically import project setups at
  544. startup (see option `vhdl-project-auto-load'). Projects loaded from the
  545. first entry are automatically made current. Hint: specify local project
  546. setups in first entry, global setups in following entries; loading a local
  547. project setup will make it current, while loading the global setups
  548. is done without changing the current project.
  549. Names can also have an absolute path (i.e. project setups can be stored
  550. in global directories)."
  551. :type '(repeat (string :tag "File name" "\\1.prj"))
  552. :group 'vhdl-project)
  553. (defcustom vhdl-project-auto-load '(startup)
  554. "*Automatically load project setups from files.
  555. All project setup files that match the file names specified in option
  556. `vhdl-project-file-name' are automatically loaded. The project of the
  557. \(alphabetically) last loaded setup of the first `vhdl-project-file-name'
  558. entry is activated.
  559. A project setup file can be obtained by exporting a project (see menu).
  560. At startup: project setup file is loaded at Emacs startup"
  561. :type '(set (const :tag "At startup" startup))
  562. :group 'vhdl-project)
  563. (defcustom vhdl-project-sort t
  564. "*Non-nil means projects are displayed in alphabetical order."
  565. :type 'boolean
  566. :group 'vhdl-project)
  567. (defgroup vhdl-style nil
  568. "Customizations for coding styles."
  569. :group 'vhdl
  570. :group 'vhdl-template
  571. :group 'vhdl-port
  572. :group 'vhdl-compose)
  573. (defcustom vhdl-standard '(87 nil)
  574. "*VHDL standards used.
  575. Basic standard:
  576. VHDL'87 : IEEE Std 1076-1987
  577. VHDL'93 : IEEE Std 1076-1993
  578. Additional standards:
  579. VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
  580. Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
  581. NOTE: Activate the new setting in a VHDL buffer by using the menu entry
  582. \"Activate Options\"."
  583. :type '(list (choice :tag "Basic standard"
  584. (const :tag "VHDL'87" 87)
  585. (const :tag "VHDL'93" 93))
  586. (set :tag "Additional standards" :indent 2
  587. (const :tag "VHDL-AMS" ams)
  588. (const :tag "Math packages" math)))
  589. :set (lambda (variable value)
  590. (vhdl-custom-set variable value
  591. 'vhdl-template-map-init
  592. 'vhdl-mode-abbrev-table-init
  593. 'vhdl-template-construct-alist-init
  594. 'vhdl-template-package-alist-init
  595. 'vhdl-update-mode-menu
  596. 'vhdl-words-init 'vhdl-font-lock-init))
  597. :group 'vhdl-style)
  598. (defcustom vhdl-basic-offset 2
  599. "*Amount of basic offset used for indentation.
  600. This value is used by + and - symbols in `vhdl-offsets-alist'."
  601. :type 'integer
  602. :group 'vhdl-style)
  603. (defcustom vhdl-upper-case-keywords nil
  604. "*Non-nil means convert keywords to upper case.
  605. This is done when typed or expanded or by the fix case functions."
  606. :type 'boolean
  607. :set (lambda (variable value)
  608. (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
  609. :group 'vhdl-style)
  610. (defcustom vhdl-upper-case-types nil
  611. "*Non-nil means convert standardized types to upper case.
  612. This is done when expanded or by the fix case functions."
  613. :type 'boolean
  614. :set (lambda (variable value)
  615. (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
  616. :group 'vhdl-style)
  617. (defcustom vhdl-upper-case-attributes nil
  618. "*Non-nil means convert standardized attributes to upper case.
  619. This is done when expanded or by the fix case functions."
  620. :type 'boolean
  621. :set (lambda (variable value)
  622. (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
  623. :group 'vhdl-style)
  624. (defcustom vhdl-upper-case-enum-values nil
  625. "*Non-nil means convert standardized enumeration values to upper case.
  626. This is done when expanded or by the fix case functions."
  627. :type 'boolean
  628. :set (lambda (variable value)
  629. (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
  630. :group 'vhdl-style)
  631. (defcustom vhdl-upper-case-constants t
  632. "*Non-nil means convert standardized constants to upper case.
  633. This is done when expanded."
  634. :type 'boolean
  635. :set (lambda (variable value)
  636. (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
  637. :group 'vhdl-style)
  638. (defcustom vhdl-use-direct-instantiation 'standard
  639. "*Non-nil means use VHDL'93 direct component instantiation.
  640. Never : never
  641. Standard: only in VHDL standards that allow it (VHDL'93 and higher)
  642. Always : always"
  643. :type '(choice (const :tag "Never" never)
  644. (const :tag "Standard" standard)
  645. (const :tag "Always" always))
  646. :group 'vhdl-style)
  647. (defgroup vhdl-naming nil
  648. "Customizations for naming conventions."
  649. :group 'vhdl)
  650. (defcustom vhdl-entity-file-name '(".*" . "\\&")
  651. (concat
  652. "*Specifies how the entity file name is obtained.
  653. The entity file name can be obtained by modifying the entity name (e.g.
  654. attaching or stripping off a substring). The file extension is automatically
  655. taken from the file name of the current buffer."
  656. vhdl-name-doc-string)
  657. :type '(cons (regexp :tag "From regexp")
  658. (string :tag "To string "))
  659. :group 'vhdl-naming
  660. :group 'vhdl-compose)
  661. (defcustom vhdl-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
  662. (concat
  663. "*Specifies how the architecture file name is obtained.
  664. The architecture file name can be obtained by modifying the entity
  665. and/or architecture name (e.g. attaching or stripping off a substring). The
  666. file extension is automatically taken from the file name of the current
  667. buffer. The string that is matched against the regexp is the concatenation
  668. of the entity and the architecture name separated by a space. This gives
  669. access to both names (see default setting as example)."
  670. vhdl-name-doc-string)
  671. :type '(cons (regexp :tag "From regexp")
  672. (string :tag "To string "))
  673. :group 'vhdl-naming
  674. :group 'vhdl-compose)
  675. (defcustom vhdl-configuration-file-name '(".*" . "\\&")
  676. (concat
  677. "*Specifies how the configuration file name is obtained.
  678. The configuration file name can be obtained by modifying the configuration
  679. name (e.g. attaching or stripping off a substring). The file extension is
  680. automatically taken from the file name of the current buffer."
  681. vhdl-name-doc-string)
  682. :type '(cons (regexp :tag "From regexp")
  683. (string :tag "To string "))
  684. :group 'vhdl-naming
  685. :group 'vhdl-compose)
  686. (defcustom vhdl-package-file-name '(".*" . "\\&")
  687. (concat
  688. "*Specifies how the package file name is obtained.
  689. The package file name can be obtained by modifying the package name (e.g.
  690. attaching or stripping off a substring). The file extension is automatically
  691. taken from the file name of the current buffer. Package files can be created
  692. in a different directory by prepending a relative or absolute path to the
  693. file name."
  694. vhdl-name-doc-string)
  695. :type '(cons (regexp :tag "From regexp")
  696. (string :tag "To string "))
  697. :group 'vhdl-naming
  698. :group 'vhdl-compose)
  699. (defcustom vhdl-file-name-case 'identity
  700. "*Specifies how to change case for obtaining file names.
  701. When deriving a file name from a VHDL unit name, case can be changed as
  702. follows:
  703. As Is: case is not changed (taken as is)
  704. Lower Case: whole name is changed to lower case
  705. Upper Case: whole name is changed to upper case
  706. Capitalize: first letter of each word in name is capitalized"
  707. :type '(choice (const :tag "As Is" identity)
  708. (const :tag "Lower Case" downcase)
  709. (const :tag "Upper Case" upcase)
  710. (const :tag "Capitalize" capitalize))
  711. :group 'vhdl-naming
  712. :group 'vhdl-compose)
  713. (defgroup vhdl-template nil
  714. "Customizations for electrification."
  715. :group 'vhdl)
  716. (defcustom vhdl-electric-keywords '(vhdl user)
  717. "*Type of keywords for which electrification is enabled.
  718. VHDL keywords: invoke built-in templates
  719. User keywords: invoke user models (see option `vhdl-model-alist')"
  720. :type '(set (const :tag "VHDL keywords" vhdl)
  721. (const :tag "User model keywords" user))
  722. :set (lambda (variable value)
  723. (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
  724. :group 'vhdl-template)
  725. (defcustom vhdl-optional-labels 'process
  726. "*Constructs for which labels are to be queried.
  727. Template generators prompt for optional labels for:
  728. None : no constructs
  729. Processes only: processes only (also procedurals in VHDL-AMS)
  730. All constructs: all constructs with optional labels and keyword END"
  731. :type '(choice (const :tag "None" none)
  732. (const :tag "Processes only" process)
  733. (const :tag "All constructs" all))
  734. :group 'vhdl-template)
  735. (defcustom vhdl-insert-empty-lines 'unit
  736. "*Specifies whether to insert empty lines in some templates.
  737. This improves readability of code. Empty lines are inserted in:
  738. None : no constructs
  739. Design units only: entities, architectures, configurations, packages only
  740. All constructs : also all constructs with BEGIN...END parts
  741. Replaces option `vhdl-additional-empty-lines'."
  742. :type '(choice (const :tag "None" none)
  743. (const :tag "Design units only" unit)
  744. (const :tag "All constructs" all))
  745. :group 'vhdl-template
  746. :group 'vhdl-port
  747. :group 'vhdl-compose)
  748. (defcustom vhdl-argument-list-indent nil
  749. "*Non-nil means indent argument lists relative to opening parenthesis.
  750. That is, argument, association, and port lists start on the same line as the
  751. opening parenthesis and subsequent lines are indented accordingly.
  752. Otherwise, lists start on a new line and are indented as normal code."
  753. :type 'boolean
  754. :group 'vhdl-template
  755. :group 'vhdl-port
  756. :group 'vhdl-compose)
  757. (defcustom vhdl-association-list-with-formals t
  758. "*Non-nil means write association lists with formal parameters.
  759. Templates prompt for formal and actual parameters (ports/generics).
  760. When pasting component instantiations, formals are included.
  761. If nil, only a list of actual parameters is entered."
  762. :type 'boolean
  763. :group 'vhdl-template
  764. :group 'vhdl-port
  765. :group 'vhdl-compose)
  766. (defcustom vhdl-conditions-in-parenthesis nil
  767. "*Non-nil means place parenthesis around condition expressions."
  768. :type 'boolean
  769. :group 'vhdl-template)
  770. (defcustom vhdl-zero-string "'0'"
  771. "*String to use for a logic zero."
  772. :type 'string
  773. :group 'vhdl-template)
  774. (defcustom vhdl-one-string "'1'"
  775. "*String to use for a logic one."
  776. :type 'string
  777. :group 'vhdl-template)
  778. (defgroup vhdl-header nil
  779. "Customizations for file header."
  780. :group 'vhdl-template
  781. :group 'vhdl-compose)
  782. (defcustom vhdl-file-header "\
  783. -------------------------------------------------------------------------------
  784. -- Title : <title string>
  785. -- Project : <project>
  786. -------------------------------------------------------------------------------
  787. -- File : <filename>
  788. -- Author : <author>
  789. -- Company : <company>
  790. -- Created : <date>
  791. -- Last update: <date>
  792. -- Platform : <platform>
  793. -- Standard : <standard>
  794. <projectdesc>-------------------------------------------------------------------------------
  795. -- Description: <cursor>
  796. <copyright>-------------------------------------------------------------------------------
  797. -- Revisions :
  798. -- Date Version Author Description
  799. -- <date> 1.0 <login>\tCreated
  800. -------------------------------------------------------------------------------
  801. "
  802. "*String or file to insert as file header.
  803. If the string specifies an existing file name, the contents of the file is
  804. inserted, otherwise the string itself is inserted as file header.
  805. Type `C-j' for newlines.
  806. If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
  807. if the header needs to be version controlled.
  808. The following keywords for template generation are supported:
  809. <filename> : replaced by the name of the buffer
  810. <author> : replaced by the user name and email address
  811. \(`user-full-name', `mail-host-address', `user-mail-address')
  812. <login> : replaced by user login name (`user-login-name')
  813. <company> : replaced by contents of option `vhdl-company-name'
  814. <date> : replaced by the current date
  815. <year> : replaced by the current year
  816. <project> : replaced by title of current project (`vhdl-project')
  817. <projectdesc> : replaced by description of current project (`vhdl-project')
  818. <copyright> : replaced by copyright string (`vhdl-copyright-string')
  819. <platform> : replaced by contents of option `vhdl-platform-spec'
  820. <standard> : replaced by the VHDL language standard(s) used
  821. <... string> : replaced by a queried string (\"...\" is the prompt word)
  822. <title string>: replaced by file title in automatically generated files
  823. <cursor> : final cursor position
  824. The (multi-line) project description <projectdesc> can be used as a project
  825. dependent part of the file header and can also contain the above keywords."
  826. :type 'string
  827. :group 'vhdl-header)
  828. (defcustom vhdl-file-footer ""
  829. "*String or file to insert as file footer.
  830. If the string specifies an existing file name, the contents of the file is
  831. inserted, otherwise the string itself is inserted as file footer (i.e. at
  832. the end of the file).
  833. Type `C-j' for newlines.
  834. The same keywords as in option `vhdl-file-header' can be used."
  835. :type 'string
  836. :group 'vhdl-header)
  837. (defcustom vhdl-company-name ""
  838. "*Name of company to insert in file header.
  839. See option `vhdl-file-header'."
  840. :type 'string
  841. :group 'vhdl-header)
  842. (defcustom vhdl-copyright-string "\
  843. -------------------------------------------------------------------------------
  844. -- Copyright (c) <year> <company>
  845. "
  846. "*Copyright string to insert in file header.
  847. Can be multi-line string (type `C-j' for newline) and contain other file
  848. header keywords (see option `vhdl-file-header')."
  849. :type 'string
  850. :group 'vhdl-header)
  851. (defcustom vhdl-platform-spec ""
  852. "*Specification of VHDL platform to insert in file header.
  853. The platform specification should contain names and versions of the
  854. simulation and synthesis tools used.
  855. See option `vhdl-file-header'."
  856. :type 'string
  857. :group 'vhdl-header)
  858. (defcustom vhdl-date-format "%Y-%m-%d"
  859. "*Specifies the date format to use in the header.
  860. This string is passed as argument to the command `format-time-string'.
  861. For more information on format strings, see the documentation for the
  862. `format-time-string' command (C-h f `format-time-string')."
  863. :type 'string
  864. :group 'vhdl-header)
  865. (defcustom vhdl-modify-date-prefix-string "-- Last update: "
  866. "*Prefix string of modification date in VHDL file header.
  867. If actualization of the modification date is called (menu,
  868. `\\[vhdl-template-modify]'), this string is searched and the rest
  869. of the line replaced by the current date."
  870. :type 'string
  871. :group 'vhdl-header)
  872. (defcustom vhdl-modify-date-on-saving t
  873. "*Non-nil means update the modification date when the buffer is saved.
  874. Calls function `\\[vhdl-template-modify]').
  875. NOTE: Activate the new setting in a VHDL buffer by using the menu entry
  876. \"Activate Options\"."
  877. :type 'boolean
  878. :group 'vhdl-header)
  879. (defgroup vhdl-sequential-process nil
  880. "Customizations for sequential processes."
  881. :group 'vhdl-template)
  882. (defcustom vhdl-reset-kind 'async
  883. "*Specifies which kind of reset to use in sequential processes."
  884. :type '(choice (const :tag "None" none)
  885. (const :tag "Synchronous" sync)
  886. (const :tag "Asynchronous" async))
  887. :group 'vhdl-sequential-process)
  888. (defcustom vhdl-reset-active-high nil
  889. "*Non-nil means reset in sequential processes is active high.
  890. Otherwise, reset is active low."
  891. :type 'boolean
  892. :group 'vhdl-sequential-process)
  893. (defcustom vhdl-clock-rising-edge t
  894. "*Non-nil means rising edge of clock triggers sequential processes.
  895. Otherwise, falling edge triggers."
  896. :type 'boolean
  897. :group 'vhdl-sequential-process)
  898. (defcustom vhdl-clock-edge-condition 'standard
  899. "*Syntax of the clock edge condition.
  900. Standard: \"clk'event and clk = '1'\"
  901. Function: \"rising_edge(clk)\""
  902. :type '(choice (const :tag "Standard" standard)
  903. (const :tag "Function" function))
  904. :group 'vhdl-sequential-process)
  905. (defcustom vhdl-clock-name ""
  906. "*Name of clock signal to use in templates."
  907. :type 'string
  908. :group 'vhdl-sequential-process)
  909. (defcustom vhdl-reset-name ""
  910. "*Name of reset signal to use in templates."
  911. :type 'string
  912. :group 'vhdl-sequential-process)
  913. (defgroup vhdl-model nil
  914. "Customizations for user models."
  915. :group 'vhdl)
  916. (defcustom vhdl-model-alist
  917. '(("Example Model"
  918. "<label> : process (<clock>, <reset>)
  919. begin -- process <label>
  920. if <reset> = '0' then -- asynchronous reset (active low)
  921. <cursor>
  922. elsif <clock>'event and <clock> = '1' then -- rising clock edge
  923. if <enable> = '1' then -- synchronous load
  924. end if;
  925. end if;
  926. end process <label>;"
  927. "e" ""))
  928. "*List of user models.
  929. VHDL models (templates) can be specified by the user in this list. They can be
  930. invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
  931. electrification (i.e. overriding existing or creating new keywords, see
  932. option `vhdl-electric-keywords').
  933. Name : name of model (string of words and spaces)
  934. String : string or name of file to be inserted as model (newline: `C-j')
  935. Key Binding: key binding to invoke model, added to prefix `C-c C-m'
  936. (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
  937. Keyword : keyword to invoke model
  938. The models can contain prompts to be queried. A prompt is of the form \"<...>\".
  939. A prompt that appears several times is queried once and replaced throughout
  940. the model. Special prompts are:
  941. <clock> : name specified in `vhdl-clock-name' (if not empty)
  942. <reset> : name specified in `vhdl-reset-name' (if not empty)
  943. <cursor>: final cursor position
  944. File header prompts (see variable `vhdl-file-header') are automatically
  945. replaced, so that user models can also be used to insert different types of
  946. headers.
  947. If the string specifies an existing file name, the contents of the file is
  948. inserted, otherwise the string itself is inserted.
  949. The code within the models should be correctly indented.
  950. Type `C-j' for newlines.
  951. NOTE: Activate the new setting in a VHDL buffer by using the menu entry
  952. \"Activate Options\"."
  953. :type '(repeat (list :tag "Model" :indent 2
  954. (string :tag "Name ")
  955. (string :tag "String : (type `C-j' for newline)"
  956. :format "%t\n%v")
  957. (sexp :tag "Key binding" x)
  958. (string :tag "Keyword " :format "%t: %v\n")))
  959. :set (lambda (variable value)
  960. (vhdl-custom-set variable value
  961. 'vhdl-model-map-init
  962. 'vhdl-model-defun
  963. 'vhdl-mode-abbrev-table-init
  964. 'vhdl-update-mode-menu))
  965. :group 'vhdl-model)
  966. (defgroup vhdl-compose nil
  967. "Customizations for structural composition."
  968. :group 'vhdl)
  969. (defcustom vhdl-compose-architecture-name '(".*" . "str")
  970. (concat
  971. "*Specifies how the component architecture name is obtained.
  972. The component architecture name can be obtained by modifying the entity name
  973. \(e.g. attaching or stripping off a substring).
  974. If TO STRING is empty, the architecture name is queried."
  975. vhdl-name-doc-string)
  976. :type '(cons (regexp :tag "From regexp")
  977. (string :tag "To string "))
  978. :group 'vhdl-compose)
  979. (defcustom vhdl-compose-configuration-name
  980. '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
  981. (concat
  982. "*Specifies how the configuration name is obtained.
  983. The configuration name can be obtained by modifying the entity and/or
  984. architecture name (e.g. attaching or stripping off a substring). The string
  985. that is matched against the regexp is the concatenation of the entity and the
  986. architecture name separated by a space. This gives access to both names (see
  987. default setting as example)."
  988. vhdl-name-doc-string)
  989. :type '(cons (regexp :tag "From regexp")
  990. (string :tag "To string "))
  991. :group 'vhdl-compose)
  992. (defcustom vhdl-components-package-name
  993. '((".*" . "\\&_components") . "components")
  994. (concat
  995. "*Specifies how the name for the components package is obtained.
  996. The components package is a package containing all component declarations for
  997. the current design. Its name can be obtained by modifying the project name
  998. \(e.g. attaching or stripping off a substring). If no project is defined, the
  999. DIRECTORY entry is chosen."
  1000. vhdl-name-doc-string)
  1001. :type '(cons (cons :tag "Project" :indent 2
  1002. (regexp :tag "From regexp")
  1003. (string :tag "To string "))
  1004. (string :tag "Directory:\n String "))
  1005. :group 'vhdl-compose)
  1006. (defcustom vhdl-use-components-package nil
  1007. "*Non-nil means use a separate components package for component declarations.
  1008. Otherwise, component declarations are inserted and searched for in the
  1009. architecture declarative parts."
  1010. :type 'boolean
  1011. :group 'vhdl-compose)
  1012. (defcustom vhdl-compose-include-header t
  1013. "*Non-nil means include a header in automatically generated files."
  1014. :type 'boolean
  1015. :group 'vhdl-compose)
  1016. (defcustom vhdl-compose-create-files 'single
  1017. "*Specifies whether new files should be created for the new component.
  1018. The component's entity and architecture are inserted:
  1019. None : in current buffer
  1020. Single file : in new single file
  1021. Separate files: in two separate files
  1022. The file names are obtained from variables `vhdl-entity-file-name' and
  1023. `vhdl-architecture-file-name'."
  1024. :type '(choice (const :tag "None" none)
  1025. (const :tag "Single file" single)
  1026. (const :tag "Separate files" separate))
  1027. :group 'vhdl-compose)
  1028. (defcustom vhdl-compose-configuration-create-file nil
  1029. "*Specifies whether a new file should be created for the configuration.
  1030. If non-nil, a new file is created for the configuration.
  1031. The file name is obtained from variable `vhdl-configuration-file-name'."
  1032. :type 'boolean
  1033. :group 'vhdl-compose)
  1034. (defcustom vhdl-compose-configuration-hierarchical t
  1035. "*Specifies whether hierarchical configurations should be created.
  1036. If non-nil, automatically created configurations are hierarchical and include
  1037. the whole hierarchy of subcomponents. Otherwise the configuration only
  1038. includes one level of subcomponents."
  1039. :type 'boolean
  1040. :group 'vhdl-compose)
  1041. (defcustom vhdl-compose-configuration-use-subconfiguration t
  1042. "*Specifies whether subconfigurations should be used inside configurations.
  1043. If non-nil, automatically created configurations use configurations in binding
  1044. indications for subcomponents, if such configurations exist. Otherwise,
  1045. entities are used in binding indications for subcomponents."
  1046. :type 'boolean
  1047. :group 'vhdl-compose)
  1048. (defgroup vhdl-port nil
  1049. "Customizations for port translation functions."
  1050. :group 'vhdl
  1051. :group 'vhdl-compose)
  1052. (defcustom vhdl-include-port-comments nil
  1053. "*Non-nil means include port comments when a port is pasted."
  1054. :type 'boolean
  1055. :group 'vhdl-port)
  1056. (defcustom vhdl-include-direction-comments nil
  1057. "*Non-nil means include port direction in instantiations as comments."
  1058. :type 'boolean
  1059. :group 'vhdl-port)
  1060. (defcustom vhdl-include-type-comments nil
  1061. "*Non-nil means include generic/port type in instantiations as comments."
  1062. :type 'boolean
  1063. :group 'vhdl-port)
  1064. (defcustom vhdl-include-group-comments 'never
  1065. "*Specifies whether to include group comments and spacings.
  1066. The comments and empty lines between groups of ports are pasted:
  1067. Never : never
  1068. Declarations: in entity/component/constant/signal declarations only
  1069. Always : also in generic/port maps"
  1070. :type '(choice (const :tag "Never" never)
  1071. (const :tag "Declarations" decl)
  1072. (const :tag "Always" always))
  1073. :group 'vhdl-port)
  1074. (defcustom vhdl-actual-port-name '(".*" . "\\&")
  1075. (concat
  1076. "*Specifies how actual port names are obtained from formal port names.
  1077. In a component instantiation, an actual port name can be obtained by
  1078. modifying the formal port name (e.g. attaching or stripping off a substring)."
  1079. vhdl-name-doc-string)
  1080. :type '(cons (regexp :tag "From regexp")
  1081. (string :tag "To string "))
  1082. :group 'vhdl-port)
  1083. (defcustom vhdl-instance-name '(".*" . "\\&_%d")
  1084. (concat
  1085. "*Specifies how an instance name is obtained.
  1086. The instance name can be obtained by modifying the name of the component to be
  1087. instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
  1088. by a unique number (starting with 1).
  1089. If TO STRING is empty, the instance name is queried."
  1090. vhdl-name-doc-string)
  1091. :type '(cons (regexp :tag "From regexp")
  1092. (string :tag "To string "))
  1093. :group 'vhdl-port)
  1094. (defgroup vhdl-testbench nil
  1095. "Customizations for testbench generation."
  1096. :group 'vhdl-port)
  1097. (defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
  1098. (concat
  1099. "*Specifies how the testbench entity name is obtained.
  1100. The entity name of a testbench can be obtained by modifying the name of
  1101. the component to be tested (e.g. attaching or stripping off a substring)."
  1102. vhdl-name-doc-string)
  1103. :type '(cons (regexp :tag "From regexp")
  1104. (string :tag "To string "))
  1105. :group 'vhdl-testbench)
  1106. (defcustom vhdl-testbench-architecture-name '(".*" . "")
  1107. (concat
  1108. "*Specifies how the testbench architecture name is obtained.
  1109. The testbench architecture name can be obtained by modifying the name of
  1110. the component to be tested (e.g. attaching or stripping off a substring).
  1111. If TO STRING is empty, the architecture name is queried."
  1112. vhdl-name-doc-string)
  1113. :type '(cons (regexp :tag "From regexp")
  1114. (string :tag "To string "))
  1115. :group 'vhdl-testbench)
  1116. (defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
  1117. (concat
  1118. "*Specifies how the testbench configuration name is obtained.
  1119. The configuration name of a testbench can be obtained by modifying the entity
  1120. and/or architecture name (e.g. attaching or stripping off a substring). The
  1121. string that is matched against the regexp is the concatenation of the entity
  1122. and the architecture name separated by a space. This gives access to both
  1123. names (see default setting as example)."
  1124. vhdl-name-doc-string)
  1125. :type '(cons (regexp :tag "From regexp")
  1126. (string :tag "To string "))
  1127. :group 'vhdl-testbench)
  1128. (defcustom vhdl-testbench-dut-name '(".*" . "DUT")
  1129. (concat
  1130. "*Specifies how a DUT instance name is obtained.
  1131. The design-under-test instance name (i.e. the component instantiated in the
  1132. testbench) can be obtained by modifying the component name (e.g. attaching
  1133. or stripping off a substring)."
  1134. vhdl-name-doc-string)
  1135. :type '(cons (regexp :tag "From regexp")
  1136. (string :tag "To string "))
  1137. :group 'vhdl-testbench)
  1138. (defcustom vhdl-testbench-include-header t
  1139. "*Non-nil means include a header in automatically generated files."
  1140. :type 'boolean
  1141. :group 'vhdl-testbench)
  1142. (defcustom vhdl-testbench-declarations "\
  1143. -- clock
  1144. signal Clk : std_logic := '1';
  1145. "
  1146. "*String or file to be inserted in the testbench declarative part.
  1147. If the string specifies an existing file name, the contents of the file is
  1148. inserted, otherwise the string itself is inserted in the testbench
  1149. architecture before the BEGIN keyword.
  1150. Type `C-j' for newlines."
  1151. :type 'string
  1152. :group 'vhdl-testbench)
  1153. (defcustom vhdl-testbench-statements "\
  1154. -- clock generation
  1155. Clk <= not Clk after 10 ns;
  1156. -- waveform generation
  1157. WaveGen_Proc: process
  1158. begin
  1159. -- insert signal assignments here
  1160. wait until Clk = '1';
  1161. end process WaveGen_Proc;
  1162. "
  1163. "*String or file to be inserted in the testbench statement part.
  1164. If the string specifies an existing file name, the contents of the file is
  1165. inserted, otherwise the string itself is inserted in the testbench
  1166. architecture before the END keyword.
  1167. Type `C-j' for newlines."
  1168. :type 'string
  1169. :group 'vhdl-testbench)
  1170. (defcustom vhdl-testbench-initialize-signals nil
  1171. "*Non-nil means initialize signals with `0' when declared in testbench."
  1172. :type 'boolean
  1173. :group 'vhdl-testbench)
  1174. (defcustom vhdl-testbench-include-library t
  1175. "*Non-nil means a library/use clause for std_logic_1164 is included."
  1176. :type 'boolean
  1177. :group 'vhdl-testbench)
  1178. (defcustom vhdl-testbench-include-configuration t
  1179. "*Non-nil means a testbench configuration is attached at the end."
  1180. :type 'boolean
  1181. :group 'vhdl-testbench)
  1182. (defcustom vhdl-testbench-create-files 'single
  1183. "*Specifies whether new files should be created for the testbench.
  1184. testbench entity and architecture are inserted:
  1185. None : in current buffer
  1186. Single file : in new single file
  1187. Separate files: in two separate files
  1188. The file names are obtained from variables `vhdl-testbench-entity-file-name'
  1189. and `vhdl-testbench-architecture-file-name'."
  1190. :type '(choice (const :tag "None" none)
  1191. (const :tag "Single file" single)
  1192. (const :tag "Separate files" separate))
  1193. :group 'vhdl-testbench)
  1194. (defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
  1195. (concat
  1196. "*Specifies how the testbench entity file name is obtained.
  1197. The entity file name can be obtained by modifying the testbench entity name
  1198. \(e.g. attaching or stripping off a substring). The file extension is
  1199. automatically taken from the file name of the current buffer. Testbench
  1200. files can be created in a different directory by prepending a relative or
  1201. absolute path to the file name."
  1202. vhdl-name-doc-string)
  1203. :type '(cons (regexp :tag "From regexp")
  1204. (string :tag "To string "))
  1205. :group 'vhdl-testbench)
  1206. (defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
  1207. (concat
  1208. "*Specifies how the testbench architecture file name is obtained.
  1209. The architecture file name can be obtained by modifying the testbench entity
  1210. and/or architecture name (e.g. attaching or stripping off a substring). The
  1211. string that is matched against the regexp is the concatenation of the entity
  1212. and the architecture name separated by a space. This gives access to both
  1213. names (see default setting as example). Testbench files can be created in
  1214. a different directory by prepending a relative or absolute path to the file
  1215. name."
  1216. vhdl-name-doc-string)
  1217. :type '(cons (regexp :tag "From regexp")
  1218. (string :tag "To string "))
  1219. :group 'vhdl-testbench)
  1220. (defgroup vhdl-comment nil
  1221. "Customizations for comments."
  1222. :group 'vhdl)
  1223. (defcustom vhdl-self-insert-comments t
  1224. "*Non-nil means various templates automatically insert help comments."
  1225. :type 'boolean
  1226. :group 'vhdl-comment)
  1227. (defcustom vhdl-prompt-for-comments t
  1228. "*Non-nil means various templates prompt for user definable comments."
  1229. :type 'boolean
  1230. :group 'vhdl-comment)
  1231. (defcustom vhdl-inline-comment-column 40
  1232. "*Column to indent and align inline comments to.
  1233. Overrides local option `comment-column'.
  1234. NOTE: Activate the new setting in a VHDL buffer by using the menu entry
  1235. \"Activate Options\"."
  1236. :type 'integer
  1237. :group 'vhdl-comment)
  1238. (defcustom vhdl-end-comment-column 79
  1239. "*End of comment column.
  1240. Comments that exceed this column number are wrapped.
  1241. NOTE: Activate the new setting in a VHDL buffer by using the menu entry
  1242. \"Activate Options\"."
  1243. :type 'integer
  1244. :group 'vhdl-comment)
  1245. (defvar end-comment-column)
  1246. (defgroup vhdl-align nil
  1247. "Customizations for alignment."
  1248. :group 'vhdl)
  1249. (defcustom vhdl-auto-align t
  1250. "*Non-nil means align some templates automatically after generation."
  1251. :type 'boolean
  1252. :group 'vhdl-align)
  1253. (defcustom vhdl-align-groups t
  1254. "*Non-nil means align groups of code lines separately.
  1255. A group of code lines is a region of consecutive lines between two lines that
  1256. match the regexp in option `vhdl-align-group-separate'."
  1257. :type 'boolean
  1258. :group 'vhdl-align)
  1259. (defcustom vhdl-align-group-separate "^\\s-*$"
  1260. "*Regexp for matching a line that separates groups of lines for alignment.
  1261. Examples:
  1262. \"^\\s-*$\": matches an empty line
  1263. \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
  1264. :type 'regexp
  1265. :group 'vhdl-align)
  1266. (defcustom vhdl-align-same-indent t
  1267. "*Non-nil means align blocks with same indent separately.
  1268. When a region or the entire buffer is aligned, the code is divided into
  1269. blocks of same indent which are aligned separately (except for argument/port
  1270. lists). This gives nicer alignment in most cases.
  1271. Option `vhdl-align-groups' still applies within these blocks."
  1272. :type 'boolean
  1273. :group 'vhdl-align)
  1274. (defgroup vhdl-highlight nil
  1275. "Customizations for highlighting."
  1276. :group 'vhdl)
  1277. (defcustom vhdl-highlight-keywords t
  1278. "*Non-nil means highlight VHDL keywords and other standardized words.
  1279. The following faces are used:
  1280. `font-lock-keyword-face' : keywords
  1281. `font-lock-type-face' : standardized types
  1282. `vhdl-font-lock-attribute-face': standardized attributes
  1283. `vhdl-font-lock-enumvalue-face': standardized enumeration values
  1284. `vhdl-font-lock-function-face' : standardized function and package names
  1285. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1286. entry \"Fontify Buffer\")."
  1287. :type 'boolean
  1288. :set (lambda (variable value)
  1289. (vhdl-custom-set variable value 'vhdl-font-lock-init))
  1290. :group 'vhdl-highlight)
  1291. (defcustom vhdl-highlight-names t
  1292. "*Non-nil means highlight declaration names and construct labels.
  1293. The following faces are used:
  1294. `font-lock-function-name-face' : names in declarations of units,
  1295. subprograms, components, as well as labels of VHDL constructs
  1296. `font-lock-type-face' : names in type/nature declarations
  1297. `vhdl-font-lock-attribute-face': names in attribute declarations
  1298. `font-lock-variable-name-face' : names in declarations of signals,
  1299. variables, constants, subprogram parameters, generics, and ports
  1300. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1301. entry \"Fontify Buffer\")."
  1302. :type 'boolean
  1303. :set (lambda (variable value)
  1304. (vhdl-custom-set variable value 'vhdl-font-lock-init))
  1305. :group 'vhdl-highlight)
  1306. (defcustom vhdl-highlight-special-words nil
  1307. "*Non-nil means highlight words with special syntax.
  1308. The words with syntax and color specified in option `vhdl-special-syntax-alist'
  1309. are highlighted accordingly.
  1310. Can be used for visual support of naming conventions.
  1311. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1312. entry \"Fontify Buffer\")."
  1313. :type 'boolean
  1314. :set (lambda (variable value)
  1315. (vhdl-custom-set variable value 'vhdl-font-lock-init))
  1316. :group 'vhdl-highlight)
  1317. (defcustom vhdl-highlight-forbidden-words nil
  1318. "*Non-nil means highlight forbidden words.
  1319. The reserved words specified in option `vhdl-forbidden-words' or having the
  1320. syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
  1321. warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
  1322. use them.
  1323. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1324. entry \"Fontify Buffer\")."
  1325. :type 'boolean
  1326. :set (lambda (variable value)
  1327. (vhdl-custom-set variable value
  1328. 'vhdl-words-init 'vhdl-font-lock-init))
  1329. :group 'vhdl-highlight)
  1330. (defcustom vhdl-highlight-verilog-keywords nil
  1331. "*Non-nil means highlight Verilog keywords as reserved words.
  1332. Verilog keywords are highlighted in a warning color (face
  1333. `vhdl-font-lock-reserved-words-face') to indicate not to use them.
  1334. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1335. entry \"Fontify Buffer\")."
  1336. :type 'boolean
  1337. :set (lambda (variable value)
  1338. (vhdl-custom-set variable value
  1339. 'vhdl-words-init 'vhdl-font-lock-init))
  1340. :group 'vhdl-highlight)
  1341. (defcustom vhdl-highlight-translate-off nil
  1342. "*Non-nil means background-highlight code excluded from translation.
  1343. That is, all code between \"-- pragma translate_off\" and
  1344. \"-- pragma translate_on\" is highlighted using a different background color
  1345. \(face `vhdl-font-lock-translate-off-face').
  1346. Note: this might slow down on-the-fly fontification (and thus editing).
  1347. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1348. entry \"Fontify Buffer\")."
  1349. :type 'boolean
  1350. :set (lambda (variable value)
  1351. (vhdl-custom-set variable value 'vhdl-font-lock-init))
  1352. :group 'vhdl-highlight)
  1353. (defcustom vhdl-highlight-case-sensitive nil
  1354. "*Non-nil means consider case for highlighting.
  1355. Possible trade-off:
  1356. non-nil also upper-case VHDL words are highlighted, but case of words with
  1357. special syntax is not considered
  1358. nil only lower-case VHDL words are highlighted, but case of words with
  1359. special syntax is considered
  1360. Overrides local option `font-lock-keywords-case-fold-search'.
  1361. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1362. entry \"Fontify Buffer\")."
  1363. :type 'boolean
  1364. :group 'vhdl-highlight)
  1365. (defcustom vhdl-special-syntax-alist
  1366. '(("generic/constant" "\\w+_[cg]" "Gold3" "BurlyWood1")
  1367. ("type" "\\w+_t" "ForestGreen" "PaleGreen")
  1368. ("variable" "\\w+_v" "Grey50" "Grey80"))
  1369. "*List of special syntax to be highlighted.
  1370. If option `vhdl-highlight-special-words' is non-nil, words with the specified
  1371. syntax (as regular expression) are highlighted in the corresponding color.
  1372. Name : string of words and spaces
  1373. Regexp : regular expression describing word syntax
  1374. (e.g. \"\\\w+_c\" matches word with suffix \"_c\")
  1375. Color (light): foreground color for light background
  1376. (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
  1377. LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
  1378. Color (dark) : foreground color for dark background
  1379. (matching color examples: BurlyWood1, Grey80, Green, Coral,
  1380. AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
  1381. Can be used for visual support of naming conventions, such as highlighting
  1382. different kinds of signals (e.g. \"Clk50\", \"Rst_n\") or objects (e.g.
  1383. \"Signal_s\", \"Variable_v\", \"Constant_c\") by distinguishing them using
  1384. common substrings or name suffices.
  1385. For each entry, a new face is generated with the specified colors and name
  1386. \"vhdl-font-lock-\" + name + \"-face\".
  1387. NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
  1388. entry \"Fontify Buffer\"). All other changes require restarting Emacs."
  1389. :type '(repeat (list :tag "Face" :indent 2
  1390. (string :tag "Name ")
  1391. (regexp :tag "Regexp " "\\w+_")
  1392. (string :tag "Color (light)")
  1393. (string :tag "Color (dark) ")))
  1394. :set (lambda (variable value)
  1395. (vhdl-custom-set variable value 'vhdl-font-lock-init))
  1396. :group 'vhdl-highlight)
  1397. (defcustom vhdl-forbidden-words '()
  1398. "*List of forbidden words to be highlighted.
  1399. If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
  1400. words are highlighted in a warning color to indicate not to use them.
  1401. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1402. entry \"Fontify Buffer\")."
  1403. :type '(repeat (string :format "%v"))
  1404. :set (lambda (variable value)
  1405. (vhdl-custom-set variable value
  1406. 'vhdl-words-init 'vhdl-font-lock-init))
  1407. :group 'vhdl-highlight)
  1408. (defcustom vhdl-forbidden-syntax ""
  1409. "*Syntax of forbidden words to be highlighted.
  1410. If option `vhdl-highlight-forbidden-words' is non-nil, words with this
  1411. syntax are highlighted in a warning color to indicate not to use them.
  1412. Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
  1413. highlights identifiers with 10 or more characters).
  1414. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1415. entry \"Fontify Buffer\")."
  1416. :type 'regexp
  1417. :set (lambda (variable value)
  1418. (vhdl-custom-set variable value
  1419. 'vhdl-words-init 'vhdl-font-lock-init))
  1420. :group 'vhdl-highlight)
  1421. (defcustom vhdl-directive-keywords '("pragma" "synopsys")
  1422. "*List of compiler directive keywords recognized for highlighting.
  1423. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1424. entry \"Fontify Buffer\")."
  1425. :type '(repeat (string :format "%v"))
  1426. :set (lambda (variable value)
  1427. (vhdl-custom-set variable value
  1428. 'vhdl-words-init 'vhdl-font-lock-init))
  1429. :group 'vhdl-highlight)
  1430. (defgroup vhdl-speedbar nil
  1431. "Customizations for speedbar."
  1432. :group 'vhdl)
  1433. (defcustom vhdl-speedbar-auto-open nil
  1434. "*Non-nil means automatically open speedbar at startup.
  1435. Alternatively, the speedbar can be opened from the VHDL menu."
  1436. :type 'boolean
  1437. :group 'vhdl-speedbar)
  1438. (defcustom vhdl-speedbar-display-mode 'files
  1439. "*Specifies the default displaying mode when opening speedbar.
  1440. Alternatively, the displaying mode can be selected from the speedbar menu or
  1441. by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
  1442. :type '(choice (const :tag "Files" files)
  1443. (const :tag "Directory hierarchy" directory)
  1444. (const :tag "Project hierarchy" project))
  1445. :group 'vhdl-speedbar)
  1446. (defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
  1447. "*Limits scanning of large files and netlists.
  1448. Design units: maximum file size to scan for design units
  1449. Hierarchy (instances of subcomponents):
  1450. File size: maximum file size to scan for instances (in bytes)
  1451. Instances per arch: maximum number of instances to scan per architecture
  1452. \"None\" always means that there is no limit.
  1453. In case of files not or incompletely scanned, a warning message and the file
  1454. names are printed out.
  1455. Background: scanning for instances is considerably slower than scanning for
  1456. design units, especially when there are many instances. These limits should
  1457. prevent the scanning of large netlists."
  1458. :type '(list (choice :tag "Design units"
  1459. :format "%t : %[Value Menu%] %v"
  1460. (const :tag "None" nil)
  1461. (integer :tag "File size"))
  1462. (list :tag "Hierarchy" :indent 2
  1463. (choice :tag "File size"
  1464. :format "%t : %[Value Menu%] %v"
  1465. (const :tag "None" nil)
  1466. (integer :tag "Size "))
  1467. (choice :tag "Instances per arch"
  1468. (const :tag "None" nil)
  1469. (integer :tag "Number "))))
  1470. :group 'vhdl-speedbar)
  1471. (defcustom vhdl-speedbar-jump-to-unit t
  1472. "*Non-nil means jump to the design unit code when opened in a buffer.
  1473. The buffer cursor position is left unchanged otherwise."
  1474. :type 'boolean
  1475. :group 'vhdl-speedbar)
  1476. (defcustom vhdl-speedbar-update-on-saving t
  1477. "*Automatically update design hierarchy when buffer is saved."
  1478. :type 'boolean
  1479. :group 'vhdl-speedbar)
  1480. (defcustom vhdl-speedbar-save-cache '(hierarchy display)
  1481. "*Automatically save modified hierarchy caches when exiting Emacs.
  1482. Hierarchy: design hierarchy information
  1483. Display: displaying information (which design units to expand)"
  1484. :type '(set (const :tag "Hierarchy" hierarchy)
  1485. (const :tag "Display" display))
  1486. :group 'vhdl-speedbar)
  1487. (defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
  1488. "*Name of file for saving hierarchy cache.
  1489. \"\\1\" is replaced by the project name if a project is specified,
  1490. \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
  1491. different users to have cache files in the same directory). Can also have
  1492. an absolute path (i.e. all caches can be stored in one global directory)."
  1493. :type 'string
  1494. :group 'vhdl-speedbar)
  1495. (defgroup vhdl-menu nil
  1496. "Customizations for menus."
  1497. :group 'vhdl)
  1498. (defcustom vhdl-index-menu nil
  1499. "*Non-nil means add an index menu for a source file when loading.
  1500. Alternatively, the speedbar can be used. Note that the index menu scans a file
  1501. when it is opened, while speedbar only scans the file upon request."
  1502. :type 'boolean
  1503. :group 'vhdl-menu)
  1504. (defcustom vhdl-source-file-menu nil
  1505. "*Non-nil means add a menu of all source files in current directory.
  1506. Alternatively, the speedbar can be used."
  1507. :type 'boolean
  1508. :group 'vhdl-menu)
  1509. (defcustom vhdl-hideshow-menu nil
  1510. "*Non-nil means add hideshow menu and functionality at startup.
  1511. Hideshow can also be enabled from the VHDL Mode menu.
  1512. Hideshow allows hiding code of various VHDL constructs.
  1513. NOTE: Activate the new setting in a VHDL buffer by using the menu entry
  1514. \"Activate Options\"."
  1515. :type 'boolean
  1516. :group 'vhdl-menu)
  1517. (defcustom vhdl-hide-all-init nil
  1518. "*Non-nil means hide all design units initially after a file is loaded."
  1519. :type 'boolean
  1520. :group 'vhdl-menu)
  1521. (defgroup vhdl-print nil
  1522. "Customizations for printing."
  1523. :group 'vhdl)
  1524. (defcustom vhdl-print-two-column t
  1525. "*Non-nil means print code in two columns and landscape format.
  1526. Adjusts settings in a way that PostScript printing (\"File\" menu, `ps-print')
  1527. prints VHDL files in a nice two-column landscape style.
  1528. NOTE: Activate the new setting by restarting Emacs.
  1529. Overrides `ps-print' settings locally."
  1530. :type 'boolean
  1531. :group 'vhdl-print)
  1532. (defcustom vhdl-print-customize-faces t
  1533. "*Non-nil means use an optimized set of faces for PostScript printing.
  1534. NOTE: Activate the new setting by restarting Emacs.
  1535. Overrides `ps-print' settings locally."
  1536. :type 'boolean
  1537. :group 'vhdl-print)
  1538. (defgroup vhdl-misc nil
  1539. "Miscellaneous customizations."
  1540. :group 'vhdl)
  1541. (defcustom vhdl-intelligent-tab t
  1542. "*Non-nil means `TAB' does indentation, word completion and tab insertion.
  1543. That is, if preceding character is part of a word then complete word,
  1544. else if not at beginning of line then insert tab,
  1545. else if last command was a `TAB' or `RET' then dedent one step,
  1546. else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
  1547. If nil, TAB always indents current line (i.e. `TAB' is bound to
  1548. `indent-according-to-mode').
  1549. NOTE: Activate the new setting in a VHDL buffer by using the menu entry
  1550. \"Activate Options\"."
  1551. :type 'boolean
  1552. :group 'vhdl-misc)
  1553. (defcustom vhdl-indent-syntax-based t
  1554. "*Non-nil means indent lines of code based on their syntactic context.
  1555. Otherwise, a line is indented like the previous nonblank line. This can be
  1556. useful in large files where syntax-based indentation gets very slow."
  1557. :type 'boolean
  1558. :group 'vhdl-misc)
  1559. (defcustom vhdl-word-completion-case-sensitive nil
  1560. "*Non-nil means word completion using `TAB' is case sensitive.
  1561. That is, `TAB' completes words that start with the same letters and case.
  1562. Otherwise, case is ignored."
  1563. :type 'boolean
  1564. :group 'vhdl-misc)
  1565. (defcustom vhdl-word-completion-in-minibuffer t
  1566. "*Non-nil enables word completion in minibuffer (for template prompts).
  1567. NOTE: Activate the new setting by restarting Emacs."
  1568. :type 'boolean
  1569. :group 'vhdl-misc)
  1570. (defcustom vhdl-underscore-is-part-of-word nil
  1571. "*Non-nil means consider the underscore character `_' as part of word.
  1572. An identifier containing underscores is then treated as a single word in
  1573. select and move operations. All parts of an identifier separated by underscore
  1574. are treated as single words otherwise.
  1575. NOTE: Activate the new setting in a VHDL buffer by using the menu entry
  1576. \"Activate Options\"."
  1577. :type 'boolean
  1578. :set (lambda (variable value)
  1579. (vhdl-custom-set variable value 'vhdl-mode-syntax-table-init))
  1580. :group 'vhdl-misc)
  1581. (defgroup vhdl-related nil
  1582. "Related general customizations."
  1583. :group 'vhdl)
  1584. ;; add related general customizations
  1585. (custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
  1586. (if (featurep 'xemacs)
  1587. (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
  1588. (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
  1589. (custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
  1590. (custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
  1591. (custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
  1592. (unless (featurep 'xemacs)
  1593. (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
  1594. (custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
  1595. (custom-add-to-group 'vhdl-related 'mail-host-address 'custom-variable)
  1596. (custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
  1597. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1598. ;; Internal variables
  1599. (defvar vhdl-menu-max-size 20
  1600. "*Specifies the maximum size of a menu before splitting it into submenus.")
  1601. (defvar vhdl-progress-interval 1
  1602. "*Interval used to update progress status during long operations.
  1603. If a number, percentage complete gets updated after each interval of
  1604. that many seconds. To inhibit all messages, set this option to nil.")
  1605. (defvar vhdl-inhibit-startup-warnings-p nil
  1606. "*If non-nil, inhibits start up compatibility warnings.")
  1607. (defvar vhdl-strict-syntax-p nil
  1608. "*If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
  1609. If the syntactic symbol for a particular line does not match a symbol
  1610. in the offsets alist, an error is generated, otherwise no error is
  1611. reported and the syntactic symbol is ignored.")
  1612. (defvar vhdl-echo-syntactic-information-p nil
  1613. "*If non-nil, syntactic info is echoed when the line is indented.")
  1614. (defconst vhdl-offsets-alist-default
  1615. '((string . -1000)
  1616. (cpp-macro . -1000)
  1617. (block-open . 0)
  1618. (block-close . 0)
  1619. (statement . 0)
  1620. (statement-cont . vhdl-lineup-statement-cont)
  1621. (statement-block-intro . +)
  1622. (statement-case-intro . +)
  1623. (case-alternative . +)
  1624. (comment . vhdl-lineup-comment)
  1625. (arglist-intro . +)
  1626. (arglist-cont . 0)
  1627. (arglist-cont-nonempty . vhdl-lineup-arglist)
  1628. (arglist-close . vhdl-lineup-arglist)
  1629. (entity . 0)
  1630. (configuration . 0)
  1631. (package . 0)
  1632. (architecture . 0)
  1633. (package-body . 0)
  1634. )
  1635. "Default settings for offsets of syntactic elements.
  1636. Do not change this constant! See the variable `vhdl-offsets-alist' for
  1637. more information.")
  1638. (defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
  1639. "*Association list of syntactic element symbols and indentation offsets.
  1640. As described below, each cons cell in this list has the form:
  1641. (SYNTACTIC-SYMBOL . OFFSET)
  1642. When a line is indented, `vhdl-mode' first determines the syntactic
  1643. context of the line by generating a list of symbols called syntactic
  1644. elements. This list can contain more than one syntactic element and
  1645. the global variable `vhdl-syntactic-context' contains the context list
  1646. for the line being indented. Each element in this list is actually a
  1647. cons cell of the syntactic symbol and a buffer position. This buffer
  1648. position is call the relative indent point for the line. Some
  1649. syntactic symbols may not have a relative indent point associated with
  1650. them.
  1651. After the syntactic context list for a line is generated, `vhdl-mode'
  1652. calculates the absolute indentation for the line by looking at each
  1653. syntactic element in the list. First, it compares the syntactic
  1654. element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
  1655. finds a match, it adds the OFFSET to the column of the relative indent
  1656. point. The sum of this calculation for each element in the syntactic
  1657. list is the absolute offset for line being indented.
  1658. If the syntactic element does not match any in the `vhdl-offsets-alist',
  1659. an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
  1660. the element is ignored.
  1661. Actually, OFFSET can be an integer, a function, a variable, or one of
  1662. the following symbols: `+', `-', `++', or `--'. These latter
  1663. designate positive or negative multiples of `vhdl-basic-offset',
  1664. respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
  1665. called with a single argument containing the cons of the syntactic
  1666. element symbol and the relative indent point. The function should
  1667. return an integer offset.
  1668. Here is the current list of valid syntactic element symbols:
  1669. string -- inside multi-line string
  1670. block-open -- statement block open
  1671. block-close -- statement block close
  1672. statement -- a VHDL statement
  1673. statement-cont -- a continuation of a VHDL statement
  1674. statement-block-intro -- the first line in a new statement block
  1675. statement-case-intro -- the first line in a case alternative block
  1676. case-alternative -- a case statement alternative clause
  1677. comment -- a line containing only a comment
  1678. arglist-intro -- the first line in an argument list
  1679. arglist-cont -- subsequent argument list lines when no
  1680. arguments follow on the same line as
  1681. the arglist opening paren
  1682. arglist-cont-nonempty -- subsequent argument list lines when at
  1683. least one argument follows on the same
  1684. line as the arglist opening paren
  1685. arglist-close -- the solo close paren of an argument list
  1686. entity -- inside an entity declaration
  1687. configuration -- inside a configuration declaration
  1688. package -- inside a package declaration
  1689. architecture -- inside an architecture body
  1690. package-body -- inside a package body")
  1691. (defvar vhdl-comment-only-line-offset 0
  1692. "*Extra offset for line which contains only the start of a comment.
  1693. Can contain an integer or a cons cell of the form:
  1694. (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
  1695. Where NON-ANCHORED-OFFSET is the amount of offset given to
  1696. non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
  1697. the amount of offset to give column-zero anchored comment-only lines.
  1698. Just an integer as value is equivalent to (<val> . 0)")
  1699. (defvar vhdl-special-indent-hook nil
  1700. "*Hook for user defined special indentation adjustments.
  1701. This hook gets called after a line is indented by the mode.")
  1702. (defvar vhdl-style-alist
  1703. '(("IEEE"
  1704. (vhdl-basic-offset . 4)
  1705. (vhdl-offsets-alist . ())))
  1706. "Styles of Indentation.
  1707. Elements of this alist are of the form:
  1708. (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
  1709. where STYLE-STRING is a short descriptive string used to select a
  1710. style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
  1711. value for that variable when using the selected style.
  1712. There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
  1713. case, the VALUE is a list containing elements of the form:
  1714. (SYNTACTIC-SYMBOL . VALUE)
  1715. as described in `vhdl-offsets-alist'. These are passed directly to
  1716. `vhdl-set-offset' so there is no need to set every syntactic symbol in
  1717. your style, only those that are different from the default.")
  1718. ;; dynamically append the default value of most variables
  1719. (or (assoc "Default" vhdl-style-alist)
  1720. (let* ((varlist '(vhdl-inhibit-startup-warnings-p
  1721. vhdl-strict-syntax-p
  1722. vhdl-echo-syntactic-information-p
  1723. vhdl-basic-offset
  1724. vhdl-offsets-alist
  1725. vhdl-comment-only-line-offset))
  1726. (default (cons "Default"
  1727. (mapcar
  1728. (function
  1729. (lambda (var)
  1730. (cons var (symbol-value var))))
  1731. varlist))))
  1732. (setq vhdl-style-alist (cons default vhdl-style-alist))))
  1733. (defvar vhdl-mode-hook nil
  1734. "*Hook called by `vhdl-mode'.")
  1735. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1736. ;;; Required packages
  1737. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1738. ;; mandatory
  1739. (require 'assoc)
  1740. (require 'compile) ; XEmacs
  1741. (require 'easymenu)
  1742. (require 'hippie-exp)
  1743. ;; optional (minimize warning messages during compile)
  1744. (eval-when-compile
  1745. (require 'font-lock)
  1746. (require 'ps-print)
  1747. (require 'speedbar))
  1748. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1749. ;;; Compatibility
  1750. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1751. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1752. ;; XEmacs compatibility
  1753. ;; active regions
  1754. (defun vhdl-keep-region-active ()
  1755. "Do whatever is necessary to keep the region active in XEmacs.
  1756. Ignore byte-compiler warnings you might see."
  1757. (and (featurep 'xemacs)
  1758. (setq zmacs-region-stays t)))
  1759. ;; `wildcard-to-regexp' is included only in XEmacs 21
  1760. (unless (fboundp 'wildcard-to-regexp)
  1761. (defun wildcard-to-regexp (wildcard)
  1762. "Simplified version of `wildcard-to-regexp' from Emacs's `files.el'."
  1763. (let* ((i (string-match "[*?]" wildcard))
  1764. (result (substring wildcard 0 i))
  1765. (len (length wildcard)))
  1766. (when i
  1767. (while (< i len)
  1768. (let ((ch (aref wildcard i)))
  1769. (setq result (concat result
  1770. (cond ((eq ch ?*) "[^\000]*")
  1771. ((eq ch ??) "[^\000]")
  1772. (t (char-to-string ch)))))
  1773. (setq i (1+ i)))))
  1774. (concat "\\`" result "\\'"))))
  1775. ;; `regexp-opt' undefined (`xemacs-devel' not installed)
  1776. ;; `regexp-opt' accelerates fontification by 10-20%
  1777. (unless (fboundp 'regexp-opt)
  1778. ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
  1779. (defun regexp-opt (strings &optional paren)
  1780. (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
  1781. (concat open (mapconcat 'regexp-quote strings "\\|") close))))
  1782. ;; `match-string-no-properties' undefined (XEmacs, what else?)
  1783. (unless (fboundp 'match-string-no-properties)
  1784. (defalias 'match-string-no-properties 'match-string))
  1785. ;; `subst-char-in-string' undefined (XEmacs)
  1786. (unless (fboundp 'subst-char-in-string)
  1787. (defun subst-char-in-string (fromchar tochar string &optional inplace)
  1788. (let ((i (length string))
  1789. (newstr (if inplace string (copy-sequence string))))
  1790. (while (> i 0)
  1791. (setq i (1- i))
  1792. (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
  1793. newstr)))
  1794. ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
  1795. (when (and (featurep 'xemacs) (string< itimer-version "1.09")
  1796. (not noninteractive))
  1797. (load "itimer")
  1798. (when (string< itimer-version "1.09")
  1799. (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
  1800. (beep) (sit-for 5)))
  1801. ;; `file-expand-wildcards' undefined (XEmacs)
  1802. (unless (fboundp 'file-expand-wildcards)
  1803. (defun file-expand-wildcards (pattern &optional full)
  1804. "Taken from Emacs's `files.el'."
  1805. (let* ((nondir (file-name-nondirectory pattern))
  1806. (dirpart (file-name-directory pattern))
  1807. (dirs (if (and dirpart (string-match "[[*?]" dirpart))
  1808. (mapcar 'file-name-as-directory
  1809. (file-expand-wildcards (directory-file-name dirpart)))
  1810. (list dirpart)))
  1811. contents)
  1812. (while dirs
  1813. (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
  1814. (file-directory-p (directory-file-name (car dirs))))
  1815. (let ((this-dir-contents
  1816. (delq nil
  1817. (mapcar #'(lambda (name)
  1818. (unless (string-match "\\`\\.\\.?\\'"
  1819. (file-name-nondirectory name))
  1820. name))
  1821. (directory-files (or (car dirs) ".") full
  1822. (wildcard-to-regexp nondir))))))
  1823. (setq contents
  1824. (nconc
  1825. (if (and (car dirs) (not full))
  1826. (mapcar (function (lambda (name) (concat (car dirs) name)))
  1827. this-dir-contents)
  1828. this-dir-contents)
  1829. contents))))
  1830. (setq dirs (cdr dirs)))
  1831. contents)))
  1832. ;; `member-ignore-case' undefined (XEmacs)
  1833. (unless (fboundp 'member-ignore-case)
  1834. (defalias 'member-ignore-case 'member))
  1835. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1836. ;; Compatibility with older VHDL Mode versions
  1837. (defvar vhdl-warnings nil
  1838. "Warnings to tell the user during start up.")
  1839. (defun vhdl-run-when-idle (secs repeat function)
  1840. "Wait until idle, then run FUNCTION."
  1841. (if (fboundp 'start-itimer)
  1842. (start-itimer "vhdl-mode" function secs repeat t)
  1843. ; (run-with-idle-timer secs repeat function)))
  1844. ;; explicitly activate timer (necessary when Emacs is already idle)
  1845. (aset (run-with-idle-timer secs repeat function) 0 nil)))
  1846. (defun vhdl-warning-when-idle (&rest args)
  1847. "Wait until idle, then print out warning STRING and beep."
  1848. (if noninteractive
  1849. (vhdl-warning (apply 'format args) t)
  1850. (unless vhdl-warnings
  1851. (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
  1852. (setq vhdl-warnings (cons (apply 'format args) vhdl-warnings))))
  1853. (defun vhdl-warning (string &optional nobeep)
  1854. "Print out warning STRING and beep."
  1855. (message "WARNING: %s" string)
  1856. (unless (or nobeep noninteractive) (beep)))
  1857. (defun vhdl-print-warnings ()
  1858. "Print out messages in variable `vhdl-warnings'."
  1859. (let ((no-warnings (length vhdl-warnings)))
  1860. (setq vhdl-warnings (nreverse vhdl-warnings))
  1861. (while vhdl-warnings
  1862. (message "WARNING: %s" (car vhdl-warnings))
  1863. (setq vhdl-warnings (cdr vhdl-warnings)))
  1864. (beep)
  1865. (when (> no-warnings 1)
  1866. (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
  1867. ;; Backward compatibility checks and fixes
  1868. ;; option `vhdl-compiler' changed format
  1869. (unless (stringp vhdl-compiler)
  1870. (setq vhdl-compiler "ModelSim")
  1871. (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
  1872. ;; option `vhdl-standard' changed format
  1873. (unless (listp vhdl-standard)
  1874. (setq vhdl-standard '(87 nil))
  1875. (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
  1876. ;; option `vhdl-model-alist' changed format
  1877. (when (= (length (car vhdl-model-alist)) 3)
  1878. (let ((old-alist vhdl-model-alist)
  1879. new-alist)
  1880. (while old-alist
  1881. (setq new-alist (cons (append (car old-alist) '("")) new-alist))
  1882. (setq old-alist (cdr old-alist)))
  1883. (setq vhdl-model-alist (nreverse new-alist)))
  1884. (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
  1885. ;; option `vhdl-project-alist' changed format
  1886. (when (= (length (car vhdl-project-alist)) 3)
  1887. (let ((old-alist vhdl-project-alist)
  1888. new-alist)
  1889. (while old-alist
  1890. (setq new-alist (cons (append (car old-alist) '("")) new-alist))
  1891. (setq old-alist (cdr old-alist)))
  1892. (setq vhdl-project-alist (nreverse new-alist)))
  1893. (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
  1894. ;; option `vhdl-project-alist' changed format (3.31.1)
  1895. (when (= (length (car vhdl-project-alist)) 4)
  1896. (let ((old-alist vhdl-project-alist)
  1897. new-alist elem)
  1898. (while old-alist
  1899. (setq elem (car old-alist))
  1900. (setq new-alist
  1901. (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
  1902. nil "./" "work" "work/" "Makefile" (nth 3 elem))
  1903. new-alist))
  1904. (setq old-alist (cdr old-alist)))
  1905. (setq vhdl-project-alist (nreverse new-alist)))
  1906. (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
  1907. ;; option `vhdl-project-alist' changed format (3.31.12)
  1908. (when (= (length (car vhdl-project-alist)) 10)
  1909. (let ((tmp-alist vhdl-project-alist))
  1910. (while tmp-alist
  1911. (setcdr (nthcdr 3 (car tmp-alist))
  1912. (cons "" (nthcdr 4 (car tmp-alist))))
  1913. (setq tmp-alist (cdr tmp-alist))))
  1914. (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
  1915. ;; option `vhdl-compiler-alist' changed format (3.31.1)
  1916. (when (= (length (car vhdl-compiler-alist)) 7)
  1917. (let ((old-alist vhdl-compiler-alist)
  1918. new-alist elem)
  1919. (while old-alist
  1920. (setq elem (car old-alist))
  1921. (setq new-alist
  1922. (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
  1923. (if (equal (nth 3 elem) "") nil (nth 3 elem))
  1924. (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
  1925. (nth 5 elem) (nth 6 elem) nil)
  1926. new-alist))
  1927. (setq old-alist (cdr old-alist)))
  1928. (setq vhdl-compiler-alist (nreverse new-alist)))
  1929. (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
  1930. ;; option `vhdl-compiler-alist' changed format (3.31.10)
  1931. (when (= (length (car vhdl-compiler-alist)) 12)
  1932. (let ((tmp-alist vhdl-compiler-alist))
  1933. (while tmp-alist
  1934. (setcdr (nthcdr 4 (car tmp-alist))
  1935. (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
  1936. (setq tmp-alist (cdr tmp-alist))))
  1937. (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
  1938. ;; option `vhdl-compiler-alist' changed format (3.31.11)
  1939. (when (= (length (car vhdl-compiler-alist)) 13)
  1940. (let ((tmp-alist vhdl-compiler-alist))
  1941. (while tmp-alist
  1942. (setcdr (nthcdr 3 (car tmp-alist))
  1943. (cons "" (nthcdr 4 (car tmp-alist))))
  1944. (setq tmp-alist (cdr tmp-alist))))
  1945. (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
  1946. ;; option `vhdl-compiler-alist' changed format (3.32.7)
  1947. (when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
  1948. (let ((tmp-alist vhdl-compiler-alist))
  1949. (while tmp-alist
  1950. (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
  1951. '(0 . nil))
  1952. (setq tmp-alist (cdr tmp-alist))))
  1953. (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
  1954. ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
  1955. (when (equal vhdl-project "")
  1956. (setq vhdl-project nil)
  1957. (customize-save-variable 'vhdl-project vhdl-project))
  1958. ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
  1959. (when (stringp vhdl-project-file-name)
  1960. (setq vhdl-project-file-name (list vhdl-project-file-name))
  1961. (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
  1962. ;; option `speedbar-indentation-width': introduced in speedbar 0.10
  1963. (if (not (boundp 'speedbar-indentation-width))
  1964. (defvar speedbar-indentation-width 2)
  1965. ;; set default to 2 if not already customized
  1966. (unless (get 'speedbar-indentation-width 'saved-value)
  1967. (setq speedbar-indentation-width 2)))
  1968. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1969. ;;; Help functions / inline substitutions / macros
  1970. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1971. (defun vhdl-standard-p (standard)
  1972. "Check if STANDARD is specified as used standard."
  1973. (or (eq standard (car vhdl-standard))
  1974. (memq standard (cadr vhdl-standard))))
  1975. (defun vhdl-project-p (&optional warning)
  1976. "Return non-nil if a project is displayed, i.e. directories or files are
  1977. specified."
  1978. (if (assoc vhdl-project vhdl-project-alist)
  1979. vhdl-project
  1980. (when (and vhdl-project warning)
  1981. (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
  1982. nil))
  1983. (defun vhdl-resolve-env-variable (string)
  1984. "Resolve environment variables in STRING."
  1985. (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
  1986. (setq string (concat (match-string 1 string)
  1987. (getenv (match-string 2 string))
  1988. (match-string 4 string))))
  1989. string)
  1990. (defun vhdl-default-directory ()
  1991. "Return the default directory of the current project or the directory of the
  1992. current buffer if no project is defined."
  1993. (if (vhdl-project-p)
  1994. (expand-file-name (vhdl-resolve-env-variable
  1995. (nth 1 (aget vhdl-project-alist vhdl-project))))
  1996. default-directory))
  1997. (defmacro vhdl-prepare-search-1 (&rest body)
  1998. "Enable case insensitive search and switch to syntax table that includes '_',
  1999. then execute BODY, and finally restore the old environment. Used for
  2000. consistent searching."
  2001. `(let ((case-fold-search t)) ; case insensitive search
  2002. ;; use extended syntax table
  2003. (with-syntax-table vhdl-mode-ext-syntax-table
  2004. ,@body)))
  2005. (defmacro vhdl-prepare-search-2 (&rest body)
  2006. "Enable case insensitive search, switch to syntax table that includes '_',
  2007. and remove `intangible' overlays, then execute BODY, and finally restore the
  2008. old environment. Used for consistent searching."
  2009. ;; FIXME: Why not just let-bind `inhibit-point-motion-hooks'? --Stef
  2010. `(let ((case-fold-search t) ; case insensitive search
  2011. (current-syntax-table (syntax-table))
  2012. overlay-all-list overlay-intangible-list overlay)
  2013. ;; use extended syntax table
  2014. (set-syntax-table vhdl-mode-ext-syntax-table)
  2015. ;; remove `intangible' overlays
  2016. (when (fboundp 'overlay-lists)
  2017. (setq overlay-all-list (overlay-lists))
  2018. (setq overlay-all-list
  2019. (append (car overlay-all-list) (cdr overlay-all-list)))
  2020. (while overlay-all-list
  2021. (setq overlay (car overlay-all-list))
  2022. (when (memq 'intangible (overlay-properties overlay))
  2023. (setq overlay-intangible-list
  2024. (cons overlay overlay-intangible-list))
  2025. (overlay-put overlay 'intangible nil))
  2026. (setq overlay-all-list (cdr overlay-all-list))))
  2027. ;; execute BODY safely
  2028. (unwind-protect
  2029. (progn ,@body)
  2030. ;; restore syntax table
  2031. (set-syntax-table current-syntax-table)
  2032. ;; restore `intangible' overlays
  2033. (when (fboundp 'overlay-lists)
  2034. (while overlay-intangible-list
  2035. (overlay-put (car overlay-intangible-list) 'intangible t)
  2036. (setq overlay-intangible-list
  2037. (cdr overlay-intangible-list)))))))
  2038. (defmacro vhdl-visit-file (file-name issue-error &rest body)
  2039. "Visit file FILE-NAME and execute BODY."
  2040. `(if (null ,file-name)
  2041. (progn ,@body)
  2042. (unless (file-directory-p ,file-name)
  2043. (let ((source-buffer (current-buffer))
  2044. (visiting-buffer (find-buffer-visiting ,file-name))
  2045. file-opened)
  2046. (when (or (and visiting-buffer (set-buffer visiting-buffer))
  2047. (condition-case ()
  2048. (progn (set-buffer (create-file-buffer ,file-name))
  2049. (setq file-opened t)
  2050. (vhdl-insert-file-contents ,file-name)
  2051. (modify-syntax-entry ?\- ". 12" (syntax-table))
  2052. (modify-syntax-entry ?\n ">" (syntax-table))
  2053. (modify-syntax-entry ?\^M ">" (syntax-table))
  2054. (modify-syntax-entry ?_ "w" (syntax-table))
  2055. t)
  2056. (error
  2057. (if ,issue-error
  2058. (progn
  2059. (when file-opened (kill-buffer (current-buffer)))
  2060. (set-buffer source-buffer)
  2061. (error "ERROR: File cannot be opened: \"%s\"" ,file-name))
  2062. (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
  2063. nil))))
  2064. (condition-case info
  2065. (progn ,@body)
  2066. (error
  2067. (if ,issue-error
  2068. (progn
  2069. (when file-opened (kill-buffer (current-buffer)))
  2070. (set-buffer source-buffer)
  2071. (error (cadr info)))
  2072. (vhdl-warning (cadr info))))))
  2073. (when file-opened (kill-buffer (current-buffer)))
  2074. (set-buffer source-buffer)))))
  2075. (defun vhdl-insert-file-contents (filename)
  2076. "Nicked from `insert-file-contents-literally', but allow coding system
  2077. conversion."
  2078. (let ((format-alist nil)
  2079. (after-insert-file-functions nil)
  2080. (jka-compr-compression-info-list nil))
  2081. (insert-file-contents filename t)))
  2082. (defun vhdl-sort-alist (alist)
  2083. "Sort ALIST."
  2084. (sort alist (function (lambda (a b) (string< (car a) (car b))))))
  2085. (defun vhdl-get-subdirs (directory)
  2086. "Recursively get subdirectories of DIRECTORY."
  2087. (let ((dir-list (list (file-name-as-directory directory)))
  2088. file-list)
  2089. (setq file-list (vhdl-directory-files directory t "\\w.*"))
  2090. (while file-list
  2091. (when (file-directory-p (car file-list))
  2092. (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
  2093. (setq file-list (cdr file-list)))
  2094. dir-list))
  2095. (defun vhdl-aput (alist-symbol key &optional value)
  2096. "As `aput', but delete key-value pair if VALUE is nil."
  2097. (if value
  2098. (aput alist-symbol key value)
  2099. (adelete alist-symbol key)))
  2100. (defun vhdl-delete (elt list)
  2101. "Delete by side effect the first occurrence of ELT as a member of LIST."
  2102. (setq list (cons nil list))
  2103. (let ((list1 list))
  2104. (while (and (cdr list1) (not (equal elt (cadr list1))))
  2105. (setq list1 (cdr list1)))
  2106. (when list
  2107. (setcdr list1 (cddr list1))))
  2108. (cdr list))
  2109. (defun vhdl-speedbar-refresh (&optional key)
  2110. "Refresh directory or project with name KEY."
  2111. (when (and (boundp 'speedbar-frame)
  2112. (frame-live-p speedbar-frame))
  2113. (let ((pos (point))
  2114. (last-frame (selected-frame)))
  2115. (if (null key)
  2116. (speedbar-refresh)
  2117. (select-frame speedbar-frame)
  2118. (when (save-excursion
  2119. (goto-char (point-min))
  2120. (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
  2121. (goto-char (match-end 1))
  2122. (speedbar-do-function-pointer)
  2123. (backward-char 2)
  2124. (speedbar-do-function-pointer)
  2125. (message "Refreshing speedbar...done"))
  2126. (select-frame last-frame)))))
  2127. (defun vhdl-show-messages ()
  2128. "Get *Messages* buffer to show recent messages."
  2129. (interactive)
  2130. (display-buffer (if (featurep 'xemacs) " *Message-Log*" "*Messages*")))
  2131. (defun vhdl-use-direct-instantiation ()
  2132. "Return whether direct instantiation is used."
  2133. (or (eq vhdl-use-direct-instantiation 'always)
  2134. (and (eq vhdl-use-direct-instantiation 'standard)
  2135. (not (vhdl-standard-p '87)))))
  2136. (defun vhdl-max-marker (marker1 marker2)
  2137. "Return larger marker."
  2138. (if (> marker1 marker2) marker1 marker2))
  2139. (defun vhdl-goto-marker (marker)
  2140. "Goto marker in appropriate buffer."
  2141. (when (markerp marker)
  2142. (set-buffer (marker-buffer marker)))
  2143. (goto-char marker))
  2144. (defun vhdl-menu-split (list title)
  2145. "Split menu LIST into several submenus, if number of
  2146. elements > `vhdl-menu-max-size'."
  2147. (if (> (length list) vhdl-menu-max-size)
  2148. (let ((remain list)
  2149. (result '())
  2150. (sublist '())
  2151. (menuno 1)
  2152. (i 0))
  2153. (while remain
  2154. (setq sublist (cons (car remain) sublist))
  2155. (setq remain (cdr remain))
  2156. (setq i (+ i 1))
  2157. (if (= i vhdl-menu-max-size)
  2158. (progn
  2159. (setq result (cons (cons (format "%s %s" title menuno)
  2160. (nreverse sublist)) result))
  2161. (setq i 0)
  2162. (setq menuno (+ menuno 1))
  2163. (setq sublist '()))))
  2164. (and sublist
  2165. (setq result (cons (cons (format "%s %s" title menuno)
  2166. (nreverse sublist)) result)))
  2167. (nreverse result))
  2168. list))
  2169. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2170. ;;; Bindings
  2171. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2172. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2173. ;; Key bindings
  2174. (defvar vhdl-template-map nil
  2175. "Keymap for VHDL templates.")
  2176. (defun vhdl-template-map-init ()
  2177. "Initialize `vhdl-template-map'."
  2178. (setq vhdl-template-map (make-sparse-keymap))
  2179. ;; key bindings for VHDL templates
  2180. (define-key vhdl-template-map "al" 'vhdl-template-alias)
  2181. (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
  2182. (define-key vhdl-template-map "at" 'vhdl-template-assert)
  2183. (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
  2184. (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
  2185. (define-key vhdl-template-map "bl" 'vhdl-template-block)
  2186. (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
  2187. (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
  2188. (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
  2189. (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
  2190. (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
  2191. (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
  2192. (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
  2193. (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
  2194. (define-key vhdl-template-map "co" 'vhdl-template-constant)
  2195. (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
  2196. (define-key vhdl-template-map "el" 'vhdl-template-else)
  2197. (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
  2198. (define-key vhdl-template-map "en" 'vhdl-template-entity)
  2199. (define-key vhdl-template-map "ex" 'vhdl-template-exit)
  2200. (define-key vhdl-template-map "fi" 'vhdl-template-file)
  2201. (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
  2202. (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
  2203. (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
  2204. (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
  2205. (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
  2206. (define-key vhdl-template-map "ge" 'vhdl-template-generic)
  2207. (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
  2208. (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
  2209. (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
  2210. (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
  2211. (define-key vhdl-template-map "it" 'vhdl-template-if-then)
  2212. (define-key vhdl-template-map "li" 'vhdl-template-library)
  2213. (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
  2214. (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
  2215. (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
  2216. (define-key vhdl-template-map "ma" 'vhdl-template-map)
  2217. (define-key vhdl-template-map "ne" 'vhdl-template-next)
  2218. (define-key vhdl-template-map "ot" 'vhdl-template-others)
  2219. (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
  2220. (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
  2221. (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
  2222. (define-key vhdl-template-map "po" 'vhdl-template-port)
  2223. (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
  2224. (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
  2225. (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
  2226. (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
  2227. (define-key vhdl-template-map "rp" 'vhdl-template-report)
  2228. (define-key vhdl-template-map "rt" 'vhdl-template-return)
  2229. (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
  2230. (define-key vhdl-template-map "si" 'vhdl-template-signal)
  2231. (define-key vhdl-template-map "su" 'vhdl-template-subtype)
  2232. (define-key vhdl-template-map "ty" 'vhdl-template-type)
  2233. (define-key vhdl-template-map "us" 'vhdl-template-use)
  2234. (define-key vhdl-template-map "va" 'vhdl-template-variable)
  2235. (define-key vhdl-template-map "wa" 'vhdl-template-wait)
  2236. (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
  2237. (define-key vhdl-template-map "wi" 'vhdl-template-with)
  2238. (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
  2239. (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
  2240. (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
  2241. (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
  2242. (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
  2243. (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
  2244. (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
  2245. (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
  2246. (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
  2247. (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
  2248. (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
  2249. (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
  2250. (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
  2251. (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
  2252. (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
  2253. (when (vhdl-standard-p 'ams)
  2254. (define-key vhdl-template-map "br" 'vhdl-template-break)
  2255. (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
  2256. (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
  2257. (define-key vhdl-template-map "lm" 'vhdl-template-limit)
  2258. (define-key vhdl-template-map "na" 'vhdl-template-nature)
  2259. (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
  2260. (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
  2261. (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
  2262. (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
  2263. (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
  2264. (define-key vhdl-template-map "te" 'vhdl-template-terminal)
  2265. )
  2266. (when (vhdl-standard-p 'math)
  2267. (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
  2268. (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
  2269. ))
  2270. ;; initialize template map for VHDL Mode
  2271. (vhdl-template-map-init)
  2272. (defun vhdl-function-name (prefix string &optional postfix)
  2273. "Generate a Lisp function name.
  2274. PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
  2275. STRING are replaced by `-' and substrings are converted to lower case."
  2276. (let ((name prefix))
  2277. (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
  2278. (setq name
  2279. (concat name "-" (downcase (substring string 0 (match-end 1)))))
  2280. (setq string (substring string (match-beginning 2))))
  2281. (when postfix (setq name (concat name "-" postfix)))
  2282. (intern name)))
  2283. (defvar vhdl-model-map nil
  2284. "Keymap for VHDL models.")
  2285. (defun vhdl-model-map-init ()
  2286. "Initialize `vhdl-model-map'."
  2287. (setq vhdl-model-map (make-sparse-keymap))
  2288. ;; key bindings for VHDL models
  2289. (let ((model-alist vhdl-model-alist) model)
  2290. (while model-alist
  2291. (setq model (car model-alist))
  2292. (define-key vhdl-model-map (nth 2 model)
  2293. (vhdl-function-name "vhdl-model" (nth 0 model)))
  2294. (setq model-alist (cdr model-alist)))))
  2295. ;; initialize user model map for VHDL Mode
  2296. (vhdl-model-map-init)
  2297. (defvar vhdl-mode-map nil
  2298. "Keymap for VHDL Mode.")
  2299. (defun vhdl-mode-map-init ()
  2300. "Initialize `vhdl-mode-map'."
  2301. (setq vhdl-mode-map (make-sparse-keymap))
  2302. ;; template key bindings
  2303. (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
  2304. ;; model key bindings
  2305. (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
  2306. ;; standard key bindings
  2307. (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
  2308. (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
  2309. (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
  2310. (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
  2311. (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
  2312. (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
  2313. (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
  2314. (unless (featurep 'xemacs) ; would override `M-backspace' in XEmacs
  2315. (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
  2316. (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
  2317. (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
  2318. ;; backspace/delete key bindings
  2319. (define-key vhdl-mode-map [backspace] 'backward-delete-char-untabify)
  2320. (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
  2321. (define-key vhdl-mode-map [delete] 'delete-char)
  2322. (define-key vhdl-mode-map [(meta delete)] 'kill-word))
  2323. ;; mode specific key bindings
  2324. (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
  2325. (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
  2326. (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
  2327. (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
  2328. (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
  2329. (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
  2330. (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
  2331. (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
  2332. (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
  2333. (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
  2334. (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
  2335. (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
  2336. (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
  2337. (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
  2338. (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
  2339. (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
  2340. (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
  2341. (if (featurep 'xemacs) ; `... C-g' not allowed in XEmacs
  2342. (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
  2343. (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
  2344. (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
  2345. (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
  2346. (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
  2347. (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
  2348. (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
  2349. (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
  2350. (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
  2351. (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
  2352. (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
  2353. (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
  2354. (define-key vhdl-mode-map "\C-c\C-m\C-n" 'vhdl-compose-new-component)
  2355. (define-key vhdl-mode-map "\C-c\C-m\C-p" 'vhdl-compose-place-component)
  2356. (define-key vhdl-mode-map "\C-c\C-m\C-w" 'vhdl-compose-wire-components)
  2357. (define-key vhdl-mode-map "\C-c\C-m\C-f" 'vhdl-compose-configuration)
  2358. (define-key vhdl-mode-map "\C-c\C-m\C-k" 'vhdl-compose-components-package)
  2359. (define-key vhdl-mode-map "\C-c\C-c" 'vhdl-comment-uncomment-region)
  2360. (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
  2361. (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
  2362. (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
  2363. (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
  2364. (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
  2365. (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
  2366. (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
  2367. (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
  2368. (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
  2369. (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
  2370. (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
  2371. (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
  2372. (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
  2373. (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
  2374. (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
  2375. (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
  2376. (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
  2377. (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
  2378. (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
  2379. (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
  2380. (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
  2381. (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
  2382. (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
  2383. (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
  2384. (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
  2385. (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
  2386. (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
  2387. (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
  2388. (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
  2389. (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
  2390. (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
  2391. (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
  2392. (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
  2393. (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
  2394. (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
  2395. (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
  2396. (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
  2397. (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
  2398. (define-key vhdl-mode-map "\C-c\C-i\C-f" 'vhdl-fontify-buffer)
  2399. (define-key vhdl-mode-map "\C-c\C-i\C-s" 'vhdl-statistics-buffer)
  2400. (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
  2401. (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
  2402. (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
  2403. (define-key vhdl-mode-map "\M-\t" 'insert-tab)
  2404. ;; insert commands bindings
  2405. (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
  2406. (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
  2407. (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
  2408. (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
  2409. ;; electric key bindings
  2410. (define-key vhdl-mode-map " " 'vhdl-electric-space)
  2411. (when vhdl-intelligent-tab
  2412. (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
  2413. (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
  2414. (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
  2415. (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
  2416. (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
  2417. (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
  2418. (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
  2419. (define-key vhdl-mode-map "," 'vhdl-electric-comma)
  2420. (define-key vhdl-mode-map "." 'vhdl-electric-period)
  2421. (when (vhdl-standard-p 'ams)
  2422. (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
  2423. ;; initialize mode map for VHDL Mode
  2424. (vhdl-mode-map-init)
  2425. ;; define special minibuffer keymap for enabling word completion in minibuffer
  2426. ;; (useful in template generator prompts)
  2427. (defvar vhdl-minibuffer-local-map
  2428. (let ((map (make-sparse-keymap)))
  2429. (set-keymap-parent map minibuffer-local-map)
  2430. (when vhdl-word-completion-in-minibuffer
  2431. (define-key map "\t" 'vhdl-minibuffer-tab))
  2432. map)
  2433. "Keymap for minibuffer used in VHDL Mode.")
  2434. ;; set up electric character functions to work with
  2435. ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
  2436. (mapc
  2437. (function
  2438. (lambda (sym)
  2439. (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
  2440. (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
  2441. '(vhdl-electric-space
  2442. vhdl-electric-tab
  2443. vhdl-electric-return
  2444. vhdl-electric-dash
  2445. vhdl-electric-open-bracket
  2446. vhdl-electric-close-bracket
  2447. vhdl-electric-quote
  2448. vhdl-electric-semicolon
  2449. vhdl-electric-comma
  2450. vhdl-electric-period
  2451. vhdl-electric-equal))
  2452. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2453. ;; Syntax table
  2454. (defvar vhdl-mode-syntax-table nil
  2455. "Syntax table used in `vhdl-mode' buffers.")
  2456. (defvar vhdl-mode-ext-syntax-table nil
  2457. "Syntax table extended by `_' used in `vhdl-mode' buffers.")
  2458. (defun vhdl-mode-syntax-table-init ()
  2459. "Initialize `vhdl-mode-syntax-table'."
  2460. (setq vhdl-mode-syntax-table (make-syntax-table))
  2461. ;; define punctuation
  2462. (modify-syntax-entry ?\# "." vhdl-mode-syntax-table)
  2463. (modify-syntax-entry ?\$ "." vhdl-mode-syntax-table)
  2464. (modify-syntax-entry ?\% "." vhdl-mode-syntax-table)
  2465. (modify-syntax-entry ?\& "." vhdl-mode-syntax-table)
  2466. (modify-syntax-entry ?\' "." vhdl-mode-syntax-table)
  2467. (modify-syntax-entry ?\* "." vhdl-mode-syntax-table)
  2468. (modify-syntax-entry ?\+ "." vhdl-mode-syntax-table)
  2469. (modify-syntax-entry ?\. "." vhdl-mode-syntax-table)
  2470. (modify-syntax-entry ?\/ "." vhdl-mode-syntax-table)
  2471. (modify-syntax-entry ?\: "." vhdl-mode-syntax-table)
  2472. (modify-syntax-entry ?\; "." vhdl-mode-syntax-table)
  2473. (modify-syntax-entry ?\< "." vhdl-mode-syntax-table)
  2474. (modify-syntax-entry ?\= "." vhdl-mode-syntax-table)
  2475. (modify-syntax-entry ?\> "." vhdl-mode-syntax-table)
  2476. (modify-syntax-entry ?\\ "." vhdl-mode-syntax-table)
  2477. (modify-syntax-entry ?\| "." vhdl-mode-syntax-table)
  2478. ;; define string
  2479. (modify-syntax-entry ?\" "\"" vhdl-mode-syntax-table)
  2480. ;; define underscore
  2481. (when vhdl-underscore-is-part-of-word
  2482. (modify-syntax-entry ?\_ "w" vhdl-mode-syntax-table))
  2483. ;; a single hyphen is punctuation, but a double hyphen starts a comment
  2484. (modify-syntax-entry ?\- ". 12" vhdl-mode-syntax-table)
  2485. ;; and \n and \^M end a comment
  2486. (modify-syntax-entry ?\n ">" vhdl-mode-syntax-table)
  2487. (modify-syntax-entry ?\^M ">" vhdl-mode-syntax-table)
  2488. ;; define parentheses to match
  2489. (modify-syntax-entry ?\( "()" vhdl-mode-syntax-table)
  2490. (modify-syntax-entry ?\) ")(" vhdl-mode-syntax-table)
  2491. (modify-syntax-entry ?\[ "(]" vhdl-mode-syntax-table)
  2492. (modify-syntax-entry ?\] ")[" vhdl-mode-syntax-table)
  2493. (modify-syntax-entry ?\{ "(}" vhdl-mode-syntax-table)
  2494. (modify-syntax-entry ?\} "){" vhdl-mode-syntax-table)
  2495. ;; extended syntax table including '_' (for simpler search regexps)
  2496. (setq vhdl-mode-ext-syntax-table (copy-syntax-table vhdl-mode-syntax-table))
  2497. (modify-syntax-entry ?_ "w" vhdl-mode-ext-syntax-table))
  2498. ;; initialize syntax table for VHDL Mode
  2499. (vhdl-mode-syntax-table-init)
  2500. (defvar vhdl-syntactic-context nil
  2501. "Buffer local variable containing syntactic analysis list.")
  2502. (make-variable-buffer-local 'vhdl-syntactic-context)
  2503. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2504. ;; Abbrev ook bindings
  2505. (defvar vhdl-mode-abbrev-table nil
  2506. "Abbrev table to use in `vhdl-mode' buffers.")
  2507. (defun vhdl-mode-abbrev-table-init ()
  2508. "Initialize `vhdl-mode-abbrev-table'."
  2509. (define-abbrev-table 'vhdl-mode-abbrev-table
  2510. (append
  2511. (when (memq 'vhdl vhdl-electric-keywords)
  2512. ;; VHDL'93 keywords
  2513. (mapcar (lambda (x) (list (car x) "" (cdr x) 0 'system))
  2514. '(
  2515. ("--" . vhdl-template-display-comment-hook)
  2516. ("abs" . vhdl-template-default-hook)
  2517. ("access" . vhdl-template-default-hook)
  2518. ("after" . vhdl-template-default-hook)
  2519. ("alias" . vhdl-template-alias-hook)
  2520. ("all" . vhdl-template-default-hook)
  2521. ("and" . vhdl-template-default-hook)
  2522. ("arch" . vhdl-template-architecture-hook)
  2523. ("architecture" . vhdl-template-architecture-hook)
  2524. ("array" . vhdl-template-default-hook)
  2525. ("assert" . vhdl-template-assert-hook)
  2526. ("attr" . vhdl-template-attribute-hook)
  2527. ("attribute" . vhdl-template-attribute-hook)
  2528. ("begin" . vhdl-template-default-indent-hook)
  2529. ("block" . vhdl-template-block-hook)
  2530. ("body" . vhdl-template-default-hook)
  2531. ("buffer" . vhdl-template-default-hook)
  2532. ("bus" . vhdl-template-default-hook)
  2533. ("case" . vhdl-template-case-hook)
  2534. ("comp" . vhdl-template-component-hook)
  2535. ("component" . vhdl-template-component-hook)
  2536. ("cond" . vhdl-template-conditional-signal-asst-hook)
  2537. ("conditional" . vhdl-template-conditional-signal-asst-hook)
  2538. ("conf" . vhdl-template-configuration-hook)
  2539. ("configuration" . vhdl-template-configuration-hook)
  2540. ("cons" . vhdl-template-constant-hook)
  2541. ("constant" . vhdl-template-constant-hook)
  2542. ("disconnect" . vhdl-template-disconnect-hook)
  2543. ("downto" . vhdl-template-default-hook)
  2544. ("else" . vhdl-template-else-hook)
  2545. ("elseif" . vhdl-template-elsif-hook)
  2546. ("elsif" . vhdl-template-elsif-hook)
  2547. ("end" . vhdl-template-default-indent-hook)
  2548. ("entity" . vhdl-template-entity-hook)
  2549. ("exit" . vhdl-template-exit-hook)
  2550. ("file" . vhdl-template-file-hook)
  2551. ("for" . vhdl-template-for-hook)
  2552. ("func" . vhdl-template-function-hook)
  2553. ("function" . vhdl-template-function-hook)
  2554. ("generic" . vhdl-template-generic-hook)
  2555. ("group" . vhdl-template-group-hook)
  2556. ("guarded" . vhdl-template-default-hook)
  2557. ("if" . vhdl-template-if-hook)
  2558. ("impure" . vhdl-template-default-hook)
  2559. ("in" . vhdl-template-default-hook)
  2560. ("inertial" . vhdl-template-default-hook)
  2561. ("inout" . vhdl-template-default-hook)
  2562. ("inst" . vhdl-template-instance-hook)
  2563. ("instance" . vhdl-template-instance-hook)
  2564. ("is" . vhdl-template-default-hook)
  2565. ("label" . vhdl-template-default-hook)
  2566. ("library" . vhdl-template-library-hook)
  2567. ("linkage" . vhdl-template-default-hook)
  2568. ("literal" . vhdl-template-default-hook)
  2569. ("loop" . vhdl-template-bare-loop-hook)
  2570. ("map" . vhdl-template-map-hook)
  2571. ("mod" . vhdl-template-default-hook)
  2572. ("nand" . vhdl-template-default-hook)
  2573. ("new" . vhdl-template-default-hook)
  2574. ("next" . vhdl-template-next-hook)
  2575. ("nor" . vhdl-template-default-hook)
  2576. ("not" . vhdl-template-default-hook)
  2577. ("null" . vhdl-template-default-hook)
  2578. ("of" . vhdl-template-default-hook)
  2579. ("on" . vhdl-template-default-hook)
  2580. ("open" . vhdl-template-default-hook)
  2581. ("or" . vhdl-template-default-hook)
  2582. ("others" . vhdl-template-others-hook)
  2583. ("out" . vhdl-template-default-hook)
  2584. ("pack" . vhdl-template-package-hook)
  2585. ("package" . vhdl-template-package-hook)
  2586. ("port" . vhdl-template-port-hook)
  2587. ("postponed" . vhdl-template-default-hook)
  2588. ("procedure" . vhdl-template-procedure-hook)
  2589. ("process" . vhdl-template-process-hook)
  2590. ("pure" . vhdl-template-default-hook)
  2591. ("range" . vhdl-template-default-hook)
  2592. ("record" . vhdl-template-default-hook)
  2593. ("register" . vhdl-template-default-hook)
  2594. ("reject" . vhdl-template-default-hook)
  2595. ("rem" . vhdl-template-default-hook)
  2596. ("report" . vhdl-template-report-hook)
  2597. ("return" . vhdl-template-return-hook)
  2598. ("rol" . vhdl-template-default-hook)
  2599. ("ror" . vhdl-template-default-hook)
  2600. ("select" . vhdl-template-selected-signal-asst-hook)
  2601. ("severity" . vhdl-template-default-hook)
  2602. ("shared" . vhdl-template-default-hook)
  2603. ("sig" . vhdl-template-signal-hook)
  2604. ("signal" . vhdl-template-signal-hook)
  2605. ("sla" . vhdl-template-default-hook)
  2606. ("sll" . vhdl-template-default-hook)
  2607. ("sra" . vhdl-template-default-hook)
  2608. ("srl" . vhdl-template-default-hook)
  2609. ("subtype" . vhdl-template-subtype-hook)
  2610. ("then" . vhdl-template-default-hook)
  2611. ("to" . vhdl-template-default-hook)
  2612. ("transport" . vhdl-template-default-hook)
  2613. ("type" . vhdl-template-type-hook)
  2614. ("unaffected" . vhdl-template-default-hook)
  2615. ("units" . vhdl-template-default-hook)
  2616. ("until" . vhdl-template-default-hook)
  2617. ("use" . vhdl-template-use-hook)
  2618. ("var" . vhdl-template-variable-hook)
  2619. ("variable" . vhdl-template-variable-hook)
  2620. ("wait" . vhdl-template-wait-hook)
  2621. ("when" . vhdl-template-when-hook)
  2622. ("while" . vhdl-template-while-loop-hook)
  2623. ("with" . vhdl-template-with-hook)
  2624. ("xnor" . vhdl-template-default-hook)
  2625. ("xor" . vhdl-template-default-hook)
  2626. )))
  2627. ;; VHDL-AMS keywords
  2628. (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
  2629. (mapcar (lambda (x) (list (car x) "" (cdr x) 0 'system))
  2630. '(
  2631. ("across" . vhdl-template-default-hook)
  2632. ("break" . vhdl-template-break-hook)
  2633. ("limit" . vhdl-template-limit-hook)
  2634. ("nature" . vhdl-template-nature-hook)
  2635. ("noise" . vhdl-template-default-hook)
  2636. ("procedural" . vhdl-template-procedural-hook)
  2637. ("quantity" . vhdl-template-quantity-hook)
  2638. ("reference" . vhdl-template-default-hook)
  2639. ("spectrum" . vhdl-template-default-hook)
  2640. ("subnature" . vhdl-template-subnature-hook)
  2641. ("terminal" . vhdl-template-terminal-hook)
  2642. ("through" . vhdl-template-default-hook)
  2643. ("tolerance" . vhdl-template-default-hook)
  2644. )))
  2645. ;; user model keywords
  2646. (when (memq 'user vhdl-electric-keywords)
  2647. (let (abbrev-list keyword)
  2648. (dolist (elem vhdl-model-alist)
  2649. (setq keyword (nth 3 elem))
  2650. (unless (equal keyword "")
  2651. (push (list keyword ""
  2652. (vhdl-function-name
  2653. "vhdl-model" (nth 0 elem) "hook") 0 'system)
  2654. abbrev-list)))
  2655. abbrev-list)))))
  2656. ;; initialize abbrev table for VHDL Mode
  2657. (vhdl-mode-abbrev-table-init)
  2658. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2659. ;; Template completion lists
  2660. (defvar vhdl-template-construct-alist nil
  2661. "List of built-in construct templates.")
  2662. (defun vhdl-template-construct-alist-init ()
  2663. "Initialize `vhdl-template-construct-alist'."
  2664. (setq
  2665. vhdl-template-construct-alist
  2666. (append
  2667. '(
  2668. ("alias declaration" vhdl-template-alias)
  2669. ("architecture body" vhdl-template-architecture)
  2670. ("assertion" vhdl-template-assert)
  2671. ("attribute declaration" vhdl-template-attribute-decl)
  2672. ("attribute specification" vhdl-template-attribute-spec)
  2673. ("block configuration" vhdl-template-block-configuration)
  2674. ("block statement" vhdl-template-block)
  2675. ("case statement" vhdl-template-case-is)
  2676. ("component configuration" vhdl-template-component-conf)
  2677. ("component declaration" vhdl-template-component-decl)
  2678. ("component instantiation statement" vhdl-template-component-inst)
  2679. ("conditional signal assignment" vhdl-template-conditional-signal-asst)
  2680. ("configuration declaration" vhdl-template-configuration-decl)
  2681. ("configuration specification" vhdl-template-configuration-spec)
  2682. ("constant declaration" vhdl-template-constant)
  2683. ("disconnection specification" vhdl-template-disconnect)
  2684. ("entity declaration" vhdl-template-entity)
  2685. ("exit statement" vhdl-template-exit)
  2686. ("file declaration" vhdl-template-file)
  2687. ("generate statement" vhdl-template-generate)
  2688. ("generic clause" vhdl-template-generic)
  2689. ("group declaration" vhdl-template-group-decl)
  2690. ("group template declaration" vhdl-template-group-template)
  2691. ("if statement" vhdl-template-if-then)
  2692. ("library clause" vhdl-template-library)
  2693. ("loop statement" vhdl-template-loop)
  2694. ("next statement" vhdl-template-next)
  2695. ("package declaration" vhdl-template-package-decl)
  2696. ("package body" vhdl-template-package-body)
  2697. ("port clause" vhdl-template-port)
  2698. ("process statement" vhdl-template-process)
  2699. ("report statement" vhdl-template-report)
  2700. ("return statement" vhdl-template-return)
  2701. ("selected signal assignment" vhdl-template-selected-signal-asst)
  2702. ("signal declaration" vhdl-template-signal)
  2703. ("subprogram declaration" vhdl-template-subprogram-decl)
  2704. ("subprogram body" vhdl-template-subprogram-body)
  2705. ("subtype declaration" vhdl-template-subtype)
  2706. ("type declaration" vhdl-template-type)
  2707. ("use clause" vhdl-template-use)
  2708. ("variable declaration" vhdl-template-variable)
  2709. ("wait statement" vhdl-template-wait)
  2710. )
  2711. (when (vhdl-standard-p 'ams)
  2712. '(
  2713. ("break statement" vhdl-template-break)
  2714. ("nature declaration" vhdl-template-nature)
  2715. ("quantity declaration" vhdl-template-quantity)
  2716. ("simultaneous case statement" vhdl-template-case-use)
  2717. ("simultaneous if statement" vhdl-template-if-use)
  2718. ("simultaneous procedural statement" vhdl-template-procedural)
  2719. ("step limit specification" vhdl-template-limit)
  2720. ("subnature declaration" vhdl-template-subnature)
  2721. ("terminal declaration" vhdl-template-terminal)
  2722. )))))
  2723. ;; initialize for VHDL Mode
  2724. (vhdl-template-construct-alist-init)
  2725. (defvar vhdl-template-package-alist nil
  2726. "List of built-in package templates.")
  2727. (defun vhdl-template-package-alist-init ()
  2728. "Initialize `vhdl-template-package-alist'."
  2729. (setq
  2730. vhdl-template-package-alist
  2731. (append
  2732. '(
  2733. ("numeric_bit" vhdl-template-package-numeric-bit)
  2734. ("numeric_std" vhdl-template-package-numeric-std)
  2735. ("std_logic_1164" vhdl-template-package-std-logic-1164)
  2736. ("std_logic_arith" vhdl-template-package-std-logic-arith)
  2737. ("std_logic_misc" vhdl-template-package-std-logic-misc)
  2738. ("std_logic_signed" vhdl-template-package-std-logic-signed)
  2739. ("std_logic_textio" vhdl-template-package-std-logic-textio)
  2740. ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
  2741. ("textio" vhdl-template-package-textio)
  2742. )
  2743. (when (vhdl-standard-p 'math)
  2744. '(
  2745. ("math_complex" vhdl-template-package-math-complex)
  2746. ("math_real" vhdl-template-package-math-real)
  2747. )))))
  2748. ;; initialize for VHDL Mode
  2749. (vhdl-template-package-alist-init)
  2750. (defvar vhdl-template-directive-alist
  2751. '(
  2752. ("translate_on" vhdl-template-directive-translate-on)
  2753. ("translate_off" vhdl-template-directive-translate-off)
  2754. ("synthesis_on" vhdl-template-directive-synthesis-on)
  2755. ("synthesis_off" vhdl-template-directive-synthesis-off)
  2756. )
  2757. "List of built-in directive templates.")
  2758. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2759. ;;; Menus
  2760. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2761. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2762. ;; VHDL menu (using `easy-menu.el')
  2763. (defun vhdl-customize ()
  2764. "Call the customize function with `vhdl' as argument."
  2765. (interactive)
  2766. (customize-browse 'vhdl))
  2767. (defun vhdl-create-mode-menu ()
  2768. "Create VHDL Mode menu."
  2769. `("VHDL"
  2770. ,(append
  2771. '("Project"
  2772. ["None" (vhdl-set-project "")
  2773. :style radio :selected (null vhdl-project)]
  2774. "--")
  2775. ;; add menu entries for defined projects
  2776. (let ((project-alist vhdl-project-alist) menu-list name)
  2777. (while project-alist
  2778. (setq name (caar project-alist))
  2779. (setq menu-list
  2780. (cons `[,name (vhdl-set-project ,name)
  2781. :style radio :selected (equal ,name vhdl-project)]
  2782. menu-list))
  2783. (setq project-alist (cdr project-alist)))
  2784. (setq menu-list
  2785. (if vhdl-project-sort
  2786. (sort menu-list
  2787. (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
  2788. (nreverse menu-list)))
  2789. (vhdl-menu-split menu-list "Project"))
  2790. '("--" "--"
  2791. ["Select Project..." vhdl-set-project t]
  2792. ["Set As Default Project" vhdl-set-default-project t]
  2793. "--"
  2794. ["Duplicate Project" vhdl-duplicate-project vhdl-project]
  2795. ["Import Project..." vhdl-import-project
  2796. :keys "C-c C-p C-m" :active t]
  2797. ["Export Project" vhdl-export-project vhdl-project]
  2798. "--"
  2799. ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
  2800. "--"
  2801. ("Compile"
  2802. ["Compile Buffer" vhdl-compile t]
  2803. ["Stop Compilation" kill-compilation t]
  2804. "--"
  2805. ["Make" vhdl-make t]
  2806. ["Generate Makefile" vhdl-generate-makefile t]
  2807. "--"
  2808. ["Next Error" next-error t]
  2809. ["Previous Error" previous-error t]
  2810. ["First Error" first-error t]
  2811. "--"
  2812. ,(append
  2813. '("Compiler")
  2814. ;; add menu entries for defined compilers
  2815. (let ((comp-alist vhdl-compiler-alist) menu-list name)
  2816. (while comp-alist
  2817. (setq name (caar comp-alist))
  2818. (setq menu-list
  2819. (cons `[,name (setq vhdl-compiler ,name)
  2820. :style radio :selected (equal ,name vhdl-compiler)]
  2821. menu-list))
  2822. (setq comp-alist (cdr comp-alist)))
  2823. (setq menu-list (nreverse menu-list))
  2824. (vhdl-menu-split menu-list "Compiler"))
  2825. '("--" "--"
  2826. ["Select Compiler..." vhdl-set-compiler t]
  2827. "--"
  2828. ["Customize Compiler..."
  2829. (customize-option 'vhdl-compiler-alist) t])))
  2830. "--"
  2831. ,(append
  2832. '("Template"
  2833. ("VHDL Construct 1"
  2834. ["Alias" vhdl-template-alias t]
  2835. ["Architecture" vhdl-template-architecture t]
  2836. ["Assert" vhdl-template-assert t]
  2837. ["Attribute (Decl)" vhdl-template-attribute-decl t]
  2838. ["Attribute (Spec)" vhdl-template-attribute-spec t]
  2839. ["Block" vhdl-template-block t]
  2840. ["Case" vhdl-template-case-is t]
  2841. ["Component (Decl)" vhdl-template-component-decl t]
  2842. ["(Component) Instance" vhdl-template-component-inst t]
  2843. ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
  2844. ["Configuration (Block)" vhdl-template-block-configuration t]
  2845. ["Configuration (Comp)" vhdl-template-component-conf t]
  2846. ["Configuration (Decl)" vhdl-template-configuration-decl t]
  2847. ["Configuration (Spec)" vhdl-template-configuration-spec t]
  2848. ["Constant" vhdl-template-constant t]
  2849. ["Disconnect" vhdl-template-disconnect t]
  2850. ["Else" vhdl-template-else t]
  2851. ["Elsif" vhdl-template-elsif t]
  2852. ["Entity" vhdl-template-entity t]
  2853. ["Exit" vhdl-template-exit t]
  2854. ["File" vhdl-template-file t]
  2855. ["For (Generate)" vhdl-template-for-generate t]
  2856. ["For (Loop)" vhdl-template-for-loop t]
  2857. ["Function (Body)" vhdl-template-function-body t]
  2858. ["Function (Decl)" vhdl-template-function-decl t]
  2859. ["Generic" vhdl-template-generic t]
  2860. ["Group (Decl)" vhdl-template-group-decl t]
  2861. ["Group (Template)" vhdl-template-group-template t])
  2862. ("VHDL Construct 2"
  2863. ["If (Generate)" vhdl-template-if-generate t]
  2864. ["If (Then)" vhdl-template-if-then t]
  2865. ["Library" vhdl-template-library t]
  2866. ["Loop" vhdl-template-bare-loop t]
  2867. ["Map" vhdl-template-map t]
  2868. ["Next" vhdl-template-next t]
  2869. ["Others (Aggregate)" vhdl-template-others t]
  2870. ["Package (Decl)" vhdl-template-package-decl t]
  2871. ["Package (Body)" vhdl-template-package-body t]
  2872. ["Port" vhdl-template-port t]
  2873. ["Procedure (Body)" vhdl-template-procedure-body t]
  2874. ["Procedure (Decl)" vhdl-template-procedure-decl t]
  2875. ["Process (Comb)" vhdl-template-process-comb t]
  2876. ["Process (Seq)" vhdl-template-process-seq t]
  2877. ["Report" vhdl-template-report t]
  2878. ["Return" vhdl-template-return t]
  2879. ["Select" vhdl-template-selected-signal-asst t]
  2880. ["Signal" vhdl-template-signal t]
  2881. ["Subtype" vhdl-template-subtype t]
  2882. ["Type" vhdl-template-type t]
  2883. ["Use" vhdl-template-use t]
  2884. ["Variable" vhdl-template-variable t]
  2885. ["Wait" vhdl-template-wait t]
  2886. ["(Clocked Wait)" vhdl-template-clocked-wait t]
  2887. ["When" vhdl-template-when t]
  2888. ["While (Loop)" vhdl-template-while-loop t]
  2889. ["With" vhdl-template-with t]))
  2890. (when (vhdl-standard-p 'ams)
  2891. '(("VHDL-AMS Construct"
  2892. ["Break" vhdl-template-break t]
  2893. ["Case (Use)" vhdl-template-case-use t]
  2894. ["If (Use)" vhdl-template-if-use t]
  2895. ["Limit" vhdl-template-limit t]
  2896. ["Nature" vhdl-template-nature t]
  2897. ["Procedural" vhdl-template-procedural t]
  2898. ["Quantity (Free)" vhdl-template-quantity-free t]
  2899. ["Quantity (Branch)" vhdl-template-quantity-branch t]
  2900. ["Quantity (Source)" vhdl-template-quantity-source t]
  2901. ["Subnature" vhdl-template-subnature t]
  2902. ["Terminal" vhdl-template-terminal t])))
  2903. '(["Insert Construct..." vhdl-template-insert-construct
  2904. :keys "C-c C-i C-t"]
  2905. "--")
  2906. (list
  2907. (append
  2908. '("Package")
  2909. (when (vhdl-standard-p 'math)
  2910. '(["math_complex" vhdl-template-package-math-complex t]
  2911. ["math_real" vhdl-template-package-math-real t]))
  2912. '(["numeric_bit" vhdl-template-package-numeric-bit t]
  2913. ["numeric_std" vhdl-template-package-numeric-std t]
  2914. ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
  2915. ["textio" vhdl-template-package-textio t]
  2916. "--"
  2917. ["std_logic_arith" vhdl-template-package-std-logic-arith t]
  2918. ["std_logic_signed" vhdl-template-package-std-logic-signed t]
  2919. ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
  2920. ["std_logic_misc" vhdl-template-package-std-logic-misc t]
  2921. ["std_logic_textio" vhdl-template-package-std-logic-textio t]
  2922. "--"
  2923. ["Insert Package..." vhdl-template-insert-package
  2924. :keys "C-c C-i C-p"])))
  2925. '(("Directive"
  2926. ["translate_on" vhdl-template-directive-translate-on t]
  2927. ["translate_off" vhdl-template-directive-translate-off t]
  2928. ["synthesis_on" vhdl-template-directive-synthesis-on t]
  2929. ["synthesis_off" vhdl-template-directive-synthesis-off t]
  2930. "--"
  2931. ["Insert Directive..." vhdl-template-insert-directive
  2932. :keys "C-c C-i C-d"])
  2933. "--"
  2934. ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
  2935. ["Insert Footer" vhdl-template-footer t]
  2936. ["Insert Date" vhdl-template-insert-date t]
  2937. ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
  2938. "--"
  2939. ["Query Next Prompt" vhdl-template-search-prompt t]))
  2940. ,(append
  2941. '("Model")
  2942. ;; add menu entries for defined models
  2943. (let ((model-alist vhdl-model-alist) menu-list model)
  2944. (while model-alist
  2945. (setq model (car model-alist))
  2946. (setq menu-list
  2947. (cons
  2948. (vector
  2949. (nth 0 model)
  2950. (vhdl-function-name "vhdl-model" (nth 0 model))
  2951. :keys (concat "C-c C-m " (key-description (nth 2 model))))
  2952. menu-list))
  2953. (setq model-alist (cdr model-alist)))
  2954. (setq menu-list (nreverse menu-list))
  2955. (vhdl-menu-split menu-list "Model"))
  2956. '("--" "--"
  2957. ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
  2958. ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
  2959. ("Port"
  2960. ["Copy" vhdl-port-copy t]
  2961. "--"
  2962. ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
  2963. ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
  2964. ["Paste As Instance" vhdl-port-paste-instance
  2965. :keys "C-c C-p C-i" :active vhdl-port-list]
  2966. ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
  2967. ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
  2968. ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
  2969. ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
  2970. "--"
  2971. ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
  2972. "--"
  2973. ["Flatten" vhdl-port-flatten
  2974. :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
  2975. ["Reverse Direction" vhdl-port-reverse-direction
  2976. :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
  2977. ("Compose"
  2978. ["New Component" vhdl-compose-new-component t]
  2979. ["Copy Component" vhdl-port-copy t]
  2980. ["Place Component" vhdl-compose-place-component vhdl-port-list]
  2981. ["Wire Components" vhdl-compose-wire-components t]
  2982. "--"
  2983. ["Generate Configuration" vhdl-compose-configuration t]
  2984. ["Generate Components Package" vhdl-compose-components-package t])
  2985. ("Subprogram"
  2986. ["Copy" vhdl-subprog-copy t]
  2987. "--"
  2988. ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
  2989. ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
  2990. ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
  2991. "--"
  2992. ["Flatten" vhdl-subprog-flatten
  2993. :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
  2994. "--"
  2995. ("Comment"
  2996. ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
  2997. "--"
  2998. ["Insert Inline Comment" vhdl-comment-append-inline t]
  2999. ["Insert Horizontal Line" vhdl-comment-display-line t]
  3000. ["Insert Display Comment" vhdl-comment-display t]
  3001. "--"
  3002. ["Fill Comment" fill-paragraph t]
  3003. ["Fill Comment Region" fill-region (mark)]
  3004. ["Kill Comment Region" vhdl-comment-kill-region (mark)]
  3005. ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
  3006. ("Line"
  3007. ["Kill" vhdl-line-kill t]
  3008. ["Copy" vhdl-line-copy t]
  3009. ["Yank" vhdl-line-yank t]
  3010. ["Expand" vhdl-line-expand t]
  3011. "--"
  3012. ["Transpose Next" vhdl-line-transpose-next t]
  3013. ["Transpose Prev" vhdl-line-transpose-previous t]
  3014. ["Open" vhdl-line-open t]
  3015. ["Join" vhdl-delete-indentation t]
  3016. "--"
  3017. ["Goto" goto-line t]
  3018. ["(Un)Comment Out" vhdl-comment-uncomment-line t])
  3019. ("Move"
  3020. ["Forward Statement" vhdl-end-of-statement t]
  3021. ["Backward Statement" vhdl-beginning-of-statement t]
  3022. ["Forward Expression" vhdl-forward-sexp t]
  3023. ["Backward Expression" vhdl-backward-sexp t]
  3024. ["Forward Same Indent" vhdl-forward-same-indent t]
  3025. ["Backward Same Indent" vhdl-backward-same-indent t]
  3026. ["Forward Function" vhdl-end-of-defun t]
  3027. ["Backward Function" vhdl-beginning-of-defun t]
  3028. ["Mark Function" vhdl-mark-defun t])
  3029. "--"
  3030. ("Indent"
  3031. ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
  3032. ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
  3033. ["Region" vhdl-indent-region (mark)]
  3034. ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
  3035. ("Align"
  3036. ["Group" vhdl-align-group t]
  3037. ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
  3038. ["List" vhdl-align-list t]
  3039. ["Declarations" vhdl-align-declarations t]
  3040. ["Region" vhdl-align-region (mark)]
  3041. ["Buffer" vhdl-align-buffer t]
  3042. "--"
  3043. ["Inline Comment Group" vhdl-align-inline-comment-group t]
  3044. ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
  3045. ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
  3046. ("Fill"
  3047. ["List" vhdl-fill-list t]
  3048. ["Group" vhdl-fill-group t]
  3049. ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
  3050. ["Region" vhdl-fill-region (mark)])
  3051. ("Beautify"
  3052. ["Region" vhdl-beautify-region (mark)]
  3053. ["Buffer" vhdl-beautify-buffer t])
  3054. ("Fix"
  3055. ["Generic/Port Clause" vhdl-fix-clause t]
  3056. "--"
  3057. ["Case Region" vhdl-fix-case-region (mark)]
  3058. ["Case Buffer" vhdl-fix-case-buffer t]
  3059. "--"
  3060. ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
  3061. ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
  3062. "--"
  3063. ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
  3064. ("Update"
  3065. ["Sensitivity List" vhdl-update-sensitivity-list-process t]
  3066. ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
  3067. "--"
  3068. ["Fontify Buffer" vhdl-fontify-buffer t]
  3069. ["Statistics Buffer" vhdl-statistics-buffer t]
  3070. ["Show Messages" vhdl-show-messages t]
  3071. ["Syntactic Info" vhdl-show-syntactic-information t]
  3072. "--"
  3073. ["Speedbar" vhdl-speedbar t]
  3074. ["Hide/Show" vhdl-hs-minor-mode t]
  3075. "--"
  3076. ("Documentation"
  3077. ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
  3078. ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
  3079. ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
  3080. ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
  3081. ["Version" vhdl-version t]
  3082. ["Bug Report..." vhdl-submit-bug-report t]
  3083. "--"
  3084. ("Options"
  3085. ("Mode"
  3086. ["Electric Mode"
  3087. (progn (customize-set-variable 'vhdl-electric-mode
  3088. (not vhdl-electric-mode)))
  3089. :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
  3090. ["Stutter Mode"
  3091. (progn (customize-set-variable 'vhdl-stutter-mode
  3092. (not vhdl-stutter-mode)))
  3093. :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
  3094. ["Indent Tabs Mode"
  3095. (progn (customize-set-variable 'vhdl-indent-tabs-mode
  3096. (not vhdl-indent-tabs-mode))
  3097. (setq indent-tabs-mode vhdl-indent-tabs-mode))
  3098. :style toggle :selected vhdl-indent-tabs-mode]
  3099. "--"
  3100. ["Customize Group..." (customize-group 'vhdl-mode) t])
  3101. ("Project"
  3102. ["Project Setup..." (customize-option 'vhdl-project-alist) t]
  3103. ,(append
  3104. '("Selected Project at Startup"
  3105. ["None" (progn (customize-set-variable 'vhdl-project nil)
  3106. (vhdl-set-project ""))
  3107. :style radio :selected (null vhdl-project)]
  3108. "--")
  3109. ;; add menu entries for defined projects
  3110. (let ((project-alist vhdl-project-alist) menu-list name)
  3111. (while project-alist
  3112. (setq name (caar project-alist))
  3113. (setq menu-list
  3114. (cons `[,name (progn (customize-set-variable
  3115. 'vhdl-project ,name)
  3116. (vhdl-set-project ,name))
  3117. :style radio :selected (equal ,name vhdl-project)]
  3118. menu-list))
  3119. (setq project-alist (cdr project-alist)))
  3120. (setq menu-list (nreverse menu-list))
  3121. (vhdl-menu-split menu-list "Project")))
  3122. ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
  3123. ("Auto Load Setup File"
  3124. ["At Startup"
  3125. (customize-set-variable 'vhdl-project-auto-load
  3126. (if (memq 'startup vhdl-project-auto-load)
  3127. (delq 'startup vhdl-project-auto-load)
  3128. (cons 'startup vhdl-project-auto-load)))
  3129. :style toggle :selected (memq 'startup vhdl-project-auto-load)])
  3130. ["Sort Projects"
  3131. (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
  3132. :style toggle :selected vhdl-project-sort]
  3133. "--"
  3134. ["Customize Group..." (customize-group 'vhdl-project) t])
  3135. ("Compiler"
  3136. ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
  3137. ,(append
  3138. '("Selected Compiler at Startup")
  3139. ;; add menu entries for defined compilers
  3140. (let ((comp-alist vhdl-compiler-alist) menu-list name)
  3141. (while comp-alist
  3142. (setq name (caar comp-alist))
  3143. (setq menu-list
  3144. (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
  3145. :style radio :selected (equal ,name vhdl-compiler)]
  3146. menu-list))
  3147. (setq comp-alist (cdr comp-alist)))
  3148. (setq menu-list (nreverse menu-list))
  3149. (vhdl-menu-split menu-list "Compiler")))
  3150. ["Use Local Error Regexp"
  3151. (customize-set-variable 'vhdl-compile-use-local-error-regexp
  3152. (not vhdl-compile-use-local-error-regexp))
  3153. :style toggle :selected vhdl-compile-use-local-error-regexp]
  3154. ["Makefile Generation Hook..."
  3155. (customize-option 'vhdl-makefile-generation-hook) t]
  3156. ["Default Library Name" (customize-option 'vhdl-default-library) t]
  3157. "--"
  3158. ["Customize Group..." (customize-group 'vhdl-compiler) t])
  3159. ("Style"
  3160. ("VHDL Standard"
  3161. ["VHDL'87"
  3162. (progn (customize-set-variable 'vhdl-standard
  3163. (list '87 (cadr vhdl-standard)))
  3164. (vhdl-activate-customizations))
  3165. :style radio :selected (eq '87 (car vhdl-standard))]
  3166. ["VHDL'93"
  3167. (progn (customize-set-variable 'vhdl-standard
  3168. (list '93 (cadr vhdl-standard)))
  3169. (vhdl-activate-customizations))
  3170. :style radio :selected (eq '93 (car vhdl-standard))]
  3171. "--"
  3172. ["VHDL-AMS"
  3173. (progn (customize-set-variable
  3174. 'vhdl-standard (list (car vhdl-standard)
  3175. (if (memq 'ams (cadr vhdl-standard))
  3176. (delq 'ams (cadr vhdl-standard))
  3177. (cons 'ams (cadr vhdl-standard)))))
  3178. (vhdl-activate-customizations))
  3179. :style toggle :selected (memq 'ams (cadr vhdl-standard))]
  3180. ["Math Packages"
  3181. (progn (customize-set-variable
  3182. 'vhdl-standard (list (car vhdl-standard)
  3183. (if (memq 'math (cadr vhdl-standard))
  3184. (delq 'math (cadr vhdl-standard))
  3185. (cons 'math (cadr vhdl-standard)))))
  3186. (vhdl-activate-customizations))
  3187. :style toggle :selected (memq 'math (cadr vhdl-standard))])
  3188. ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
  3189. ["Upper Case Keywords"
  3190. (customize-set-variable 'vhdl-upper-case-keywords
  3191. (not vhdl-upper-case-keywords))
  3192. :style toggle :selected vhdl-upper-case-keywords]
  3193. ["Upper Case Types"
  3194. (customize-set-variable 'vhdl-upper-case-types
  3195. (not vhdl-upper-case-types))
  3196. :style toggle :selected vhdl-upper-case-types]
  3197. ["Upper Case Attributes"
  3198. (customize-set-variable 'vhdl-upper-case-attributes
  3199. (not vhdl-upper-case-attributes))
  3200. :style toggle :selected vhdl-upper-case-attributes]
  3201. ["Upper Case Enumeration Values"
  3202. (customize-set-variable 'vhdl-upper-case-enum-values
  3203. (not vhdl-upper-case-enum-values))
  3204. :style toggle :selected vhdl-upper-case-enum-values]
  3205. ["Upper Case Constants"
  3206. (customize-set-variable 'vhdl-upper-case-constants
  3207. (not vhdl-upper-case-constants))
  3208. :style toggle :selected vhdl-upper-case-constants]
  3209. ("Use Direct Instantiation"
  3210. ["Never"
  3211. (customize-set-variable 'vhdl-use-direct-instantiation 'never)
  3212. :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
  3213. ["Standard"
  3214. (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
  3215. :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
  3216. ["Always"
  3217. (customize-set-variable 'vhdl-use-direct-instantiation 'always)
  3218. :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
  3219. "--"
  3220. ["Customize Group..." (customize-group 'vhdl-style) t])
  3221. ("Naming"
  3222. ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
  3223. ["Architecture File Name..."
  3224. (customize-option 'vhdl-architecture-file-name) t]
  3225. ["Configuration File Name..."
  3226. (customize-option 'vhdl-configuration-file-name) t]
  3227. ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
  3228. ("File Name Case"
  3229. ["As Is"
  3230. (customize-set-variable 'vhdl-file-name-case 'identity)
  3231. :style radio :selected (eq 'identity vhdl-file-name-case)]
  3232. ["Lower Case"
  3233. (customize-set-variable 'vhdl-file-name-case 'downcase)
  3234. :style radio :selected (eq 'downcase vhdl-file-name-case)]
  3235. ["Upper Case"
  3236. (customize-set-variable 'vhdl-file-name-case 'upcase)
  3237. :style radio :selected (eq 'upcase vhdl-file-name-case)]
  3238. ["Capitalize"
  3239. (customize-set-variable 'vhdl-file-name-case 'capitalize)
  3240. :style radio :selected (eq 'capitalize vhdl-file-name-case)])
  3241. "--"
  3242. ["Customize Group..." (customize-group 'vhdl-naming) t])
  3243. ("Template"
  3244. ("Electric Keywords"
  3245. ["VHDL Keywords"
  3246. (customize-set-variable 'vhdl-electric-keywords
  3247. (if (memq 'vhdl vhdl-electric-keywords)
  3248. (delq 'vhdl vhdl-electric-keywords)
  3249. (cons 'vhdl vhdl-electric-keywords)))
  3250. :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
  3251. ["User Model Keywords"
  3252. (customize-set-variable 'vhdl-electric-keywords
  3253. (if (memq 'user vhdl-electric-keywords)
  3254. (delq 'user vhdl-electric-keywords)
  3255. (cons 'user vhdl-electric-keywords)))
  3256. :style toggle :selected (memq 'user vhdl-electric-keywords)])
  3257. ("Insert Optional Labels"
  3258. ["None"
  3259. (customize-set-variable 'vhdl-optional-labels 'none)
  3260. :style radio :selected (eq 'none vhdl-optional-labels)]
  3261. ["Processes Only"
  3262. (customize-set-variable 'vhdl-optional-labels 'process)
  3263. :style radio :selected (eq 'process vhdl-optional-labels)]
  3264. ["All Constructs"
  3265. (customize-set-variable 'vhdl-optional-labels 'all)
  3266. :style radio :selected (eq 'all vhdl-optional-labels)])
  3267. ("Insert Empty Lines"
  3268. ["None"
  3269. (customize-set-variable 'vhdl-insert-empty-lines 'none)
  3270. :style radio :selected (eq 'none vhdl-insert-empty-lines)]
  3271. ["Design Units Only"
  3272. (customize-set-variable 'vhdl-insert-empty-lines 'unit)
  3273. :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
  3274. ["All Constructs"
  3275. (customize-set-variable 'vhdl-insert-empty-lines 'all)
  3276. :style radio :selected (eq 'all vhdl-insert-empty-lines)])
  3277. ["Argument List Indent"
  3278. (customize-set-variable 'vhdl-argument-list-indent
  3279. (not vhdl-argument-list-indent))
  3280. :style toggle :selected vhdl-argument-list-indent]
  3281. ["Association List with Formals"
  3282. (customize-set-variable 'vhdl-association-list-with-formals
  3283. (not vhdl-association-list-with-formals))
  3284. :style toggle :selected vhdl-association-list-with-formals]
  3285. ["Conditions in Parenthesis"
  3286. (customize-set-variable 'vhdl-conditions-in-parenthesis
  3287. (not vhdl-conditions-in-parenthesis))
  3288. :style toggle :selected vhdl-conditions-in-parenthesis]
  3289. ["Zero String..." (customize-option 'vhdl-zero-string) t]
  3290. ["One String..." (customize-option 'vhdl-one-string) t]
  3291. ("File Header"
  3292. ["Header String..." (customize-option 'vhdl-file-header) t]
  3293. ["Footer String..." (customize-option 'vhdl-file-footer) t]
  3294. ["Company Name..." (customize-option 'vhdl-company-name) t]
  3295. ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
  3296. ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
  3297. ["Date Format..." (customize-option 'vhdl-date-format) t]
  3298. ["Modify Date Prefix String..."
  3299. (customize-option 'vhdl-modify-date-prefix-string) t]
  3300. ["Modify Date on Saving"
  3301. (progn (customize-set-variable 'vhdl-modify-date-on-saving
  3302. (not vhdl-modify-date-on-saving))
  3303. (vhdl-activate-customizations))
  3304. :style toggle :selected vhdl-modify-date-on-saving])
  3305. ("Sequential Process"
  3306. ("Kind of Reset"
  3307. ["None"
  3308. (customize-set-variable 'vhdl-reset-kind 'none)
  3309. :style radio :selected (eq 'none vhdl-reset-kind)]
  3310. ["Synchronous"
  3311. (customize-set-variable 'vhdl-reset-kind 'sync)
  3312. :style radio :selected (eq 'sync vhdl-reset-kind)]
  3313. ["Asynchronous"
  3314. (customize-set-variable 'vhdl-reset-kind 'async)
  3315. :style radio :selected (eq 'async vhdl-reset-kind)])
  3316. ["Reset is Active High"
  3317. (customize-set-variable 'vhdl-reset-active-high
  3318. (not vhdl-reset-active-high))
  3319. :style toggle :selected vhdl-reset-active-high]
  3320. ["Use Rising Clock Edge"
  3321. (customize-set-variable 'vhdl-clock-rising-edge
  3322. (not vhdl-clock-rising-edge))
  3323. :style toggle :selected vhdl-clock-rising-edge]
  3324. ("Clock Edge Condition"
  3325. ["Standard"
  3326. (customize-set-variable 'vhdl-clock-edge-condition 'standard)
  3327. :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
  3328. ["Function \"rising_edge\""
  3329. (customize-set-variable 'vhdl-clock-edge-condition 'function)
  3330. :style radio :selected (eq 'function vhdl-clock-edge-condition)])
  3331. ["Clock Name..." (customize-option 'vhdl-clock-name) t]
  3332. ["Reset Name..." (customize-option 'vhdl-reset-name) t])
  3333. "--"
  3334. ["Customize Group..." (customize-group 'vhdl-template) t])
  3335. ("Model"
  3336. ["Model Definition..." (customize-option 'vhdl-model-alist) t])
  3337. ("Port"
  3338. ["Include Port Comments"
  3339. (customize-set-variable 'vhdl-include-port-comments
  3340. (not vhdl-include-port-comments))
  3341. :style toggle :selected vhdl-include-port-comments]
  3342. ["Include Direction Comments"
  3343. (customize-set-variable 'vhdl-include-direction-comments
  3344. (not vhdl-include-direction-comments))
  3345. :style toggle :selected vhdl-include-direction-comments]
  3346. ["Include Type Comments"
  3347. (customize-set-variable 'vhdl-include-type-comments
  3348. (not vhdl-include-type-comments))
  3349. :style toggle :selected vhdl-include-type-comments]
  3350. ("Include Group Comments"
  3351. ["Never"
  3352. (customize-set-variable 'vhdl-include-group-comments 'never)
  3353. :style radio :selected (eq 'never vhdl-include-group-comments)]
  3354. ["Declarations"
  3355. (customize-set-variable 'vhdl-include-group-comments 'decl)
  3356. :style radio :selected (eq 'decl vhdl-include-group-comments)]
  3357. ["Always"
  3358. (customize-set-variable 'vhdl-include-group-comments 'always)
  3359. :style radio :selected (eq 'always vhdl-include-group-comments)])
  3360. ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
  3361. ["Instance Name..." (customize-option 'vhdl-instance-name) t]
  3362. ("Testbench"
  3363. ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
  3364. ["Architecture Name..."
  3365. (customize-option 'vhdl-testbench-architecture-name) t]
  3366. ["Configuration Name..."
  3367. (customize-option 'vhdl-testbench-configuration-name) t]
  3368. ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
  3369. ["Include Header"
  3370. (customize-set-variable 'vhdl-testbench-include-header
  3371. (not vhdl-testbench-include-header))
  3372. :style toggle :selected vhdl-testbench-include-header]
  3373. ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
  3374. ["Statements..." (customize-option 'vhdl-testbench-statements) t]
  3375. ["Initialize Signals"
  3376. (customize-set-variable 'vhdl-testbench-initialize-signals
  3377. (not vhdl-testbench-initialize-signals))
  3378. :style toggle :selected vhdl-testbench-initialize-signals]
  3379. ["Include Library Clause"
  3380. (customize-set-variable 'vhdl-testbench-include-library
  3381. (not vhdl-testbench-include-library))
  3382. :style toggle :selected vhdl-testbench-include-library]
  3383. ["Include Configuration"
  3384. (customize-set-variable 'vhdl-testbench-include-configuration
  3385. (not vhdl-testbench-include-configuration))
  3386. :style toggle :selected vhdl-testbench-include-configuration]
  3387. ("Create Files"
  3388. ["None"
  3389. (customize-set-variable 'vhdl-testbench-create-files 'none)
  3390. :style radio :selected (eq 'none vhdl-testbench-create-files)]
  3391. ["Single"
  3392. (customize-set-variable 'vhdl-testbench-create-files 'single)
  3393. :style radio :selected (eq 'single vhdl-testbench-create-files)]
  3394. ["Separate"
  3395. (customize-set-variable 'vhdl-testbench-create-files 'separate)
  3396. :style radio :selected (eq 'separate vhdl-testbench-create-files)])
  3397. ["Testbench Entity File Name..."
  3398. (customize-option 'vhdl-testbench-entity-file-name) t]
  3399. ["Testbench Architecture File Name..."
  3400. (customize-option 'vhdl-testbench-architecture-file-name) t])
  3401. "--"
  3402. ["Customize Group..." (customize-group 'vhdl-port) t])
  3403. ("Compose"
  3404. ["Architecture Name..."
  3405. (customize-option 'vhdl-compose-architecture-name) t]
  3406. ["Configuration Name..."
  3407. (customize-option 'vhdl-compose-configuration-name) t]
  3408. ["Components Package Name..."
  3409. (customize-option 'vhdl-components-package-name) t]
  3410. ["Use Components Package"
  3411. (customize-set-variable 'vhdl-use-components-package
  3412. (not vhdl-use-components-package))
  3413. :style toggle :selected vhdl-use-components-package]
  3414. ["Include Header"
  3415. (customize-set-variable 'vhdl-compose-include-header
  3416. (not vhdl-compose-include-header))
  3417. :style toggle :selected vhdl-compose-include-header]
  3418. ("Create Entity/Architecture Files"
  3419. ["None"
  3420. (customize-set-variable 'vhdl-compose-create-files 'none)
  3421. :style radio :selected (eq 'none vhdl-compose-create-files)]
  3422. ["Single"
  3423. (customize-set-variable 'vhdl-compose-create-files 'single)
  3424. :style radio :selected (eq 'single vhdl-compose-create-files)]
  3425. ["Separate"
  3426. (customize-set-variable 'vhdl-compose-create-files 'separate)
  3427. :style radio :selected (eq 'separate vhdl-compose-create-files)])
  3428. ["Create Configuration File"
  3429. (customize-set-variable 'vhdl-compose-configuration-create-file
  3430. (not vhdl-compose-configuration-create-file))
  3431. :style toggle :selected vhdl-compose-configuration-create-file]
  3432. ["Hierarchical Configuration"
  3433. (customize-set-variable 'vhdl-compose-configuration-hierarchical
  3434. (not vhdl-compose-configuration-hierarchical))
  3435. :style toggle :selected vhdl-compose-configuration-hierarchical]
  3436. ["Use Subconfiguration"
  3437. (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
  3438. (not vhdl-compose-configuration-use-subconfiguration))
  3439. :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
  3440. "--"
  3441. ["Customize Group..." (customize-group 'vhdl-compose) t])
  3442. ("Comment"
  3443. ["Self Insert Comments"
  3444. (customize-set-variable 'vhdl-self-insert-comments
  3445. (not vhdl-self-insert-comments))
  3446. :style toggle :selected vhdl-self-insert-comments]
  3447. ["Prompt for Comments"
  3448. (customize-set-variable 'vhdl-prompt-for-comments
  3449. (not vhdl-prompt-for-comments))
  3450. :style toggle :selected vhdl-prompt-for-comments]
  3451. ["Inline Comment Column..."
  3452. (customize-option 'vhdl-inline-comment-column) t]
  3453. ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
  3454. "--"
  3455. ["Customize Group..." (customize-group 'vhdl-comment) t])
  3456. ("Align"
  3457. ["Auto Align Templates"
  3458. (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
  3459. :style toggle :selected vhdl-auto-align]
  3460. ["Align Line Groups"
  3461. (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
  3462. :style toggle :selected vhdl-align-groups]
  3463. ["Group Separation String..."
  3464. (customize-set-variable 'vhdl-align-group-separate) t]
  3465. ["Align Lines with Same Indent"
  3466. (customize-set-variable 'vhdl-align-same-indent
  3467. (not vhdl-align-same-indent))
  3468. :style toggle :selected vhdl-align-same-indent]
  3469. "--"
  3470. ["Customize Group..." (customize-group 'vhdl-align) t])
  3471. ("Highlight"
  3472. ["Highlighting On/Off..."
  3473. (customize-option
  3474. (if (fboundp 'global-font-lock-mode)
  3475. 'global-font-lock-mode 'font-lock-auto-fontify)) t]
  3476. ["Highlight Keywords"
  3477. (progn (customize-set-variable 'vhdl-highlight-keywords
  3478. (not vhdl-highlight-keywords))
  3479. (vhdl-fontify-buffer))
  3480. :style toggle :selected vhdl-highlight-keywords]
  3481. ["Highlight Names"
  3482. (progn (customize-set-variable 'vhdl-highlight-names
  3483. (not vhdl-highlight-names))
  3484. (vhdl-fontify-buffer))
  3485. :style toggle :selected vhdl-highlight-names]
  3486. ["Highlight Special Words"
  3487. (progn (customize-set-variable 'vhdl-highlight-special-words
  3488. (not vhdl-highlight-special-words))
  3489. (vhdl-fontify-buffer))
  3490. :style toggle :selected vhdl-highlight-special-words]
  3491. ["Highlight Forbidden Words"
  3492. (progn (customize-set-variable 'vhdl-highlight-forbidden-words
  3493. (not vhdl-highlight-forbidden-words))
  3494. (vhdl-fontify-buffer))
  3495. :style toggle :selected vhdl-highlight-forbidden-words]
  3496. ["Highlight Verilog Keywords"
  3497. (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
  3498. (not vhdl-highlight-verilog-keywords))
  3499. (vhdl-fontify-buffer))
  3500. :style toggle :selected vhdl-highlight-verilog-keywords]
  3501. ["Highlight \"translate_off\""
  3502. (progn (customize-set-variable 'vhdl-highlight-translate-off
  3503. (not vhdl-highlight-translate-off))
  3504. (vhdl-fontify-buffer))
  3505. :style toggle :selected vhdl-highlight-translate-off]
  3506. ["Case Sensitive Highlighting"
  3507. (progn (customize-set-variable 'vhdl-highlight-case-sensitive
  3508. (not vhdl-highlight-case-sensitive))
  3509. (vhdl-fontify-buffer))
  3510. :style toggle :selected vhdl-highlight-case-sensitive]
  3511. ["Special Syntax Definition..."
  3512. (customize-option 'vhdl-special-syntax-alist) t]
  3513. ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
  3514. ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
  3515. ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
  3516. ["Colors..." (customize-group 'vhdl-highlight-faces) t]
  3517. "--"
  3518. ["Customize Group..." (customize-group 'vhdl-highlight) t])
  3519. ("Speedbar"
  3520. ["Auto Open at Startup"
  3521. (customize-set-variable 'vhdl-speedbar-auto-open
  3522. (not vhdl-speedbar-auto-open))
  3523. :style toggle :selected vhdl-speedbar-auto-open]
  3524. ("Default Displaying Mode"
  3525. ["Files"
  3526. (customize-set-variable 'vhdl-speedbar-display-mode 'files)
  3527. :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
  3528. ["Directory Hierarchy"
  3529. (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
  3530. :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
  3531. ["Project Hierarchy"
  3532. (customize-set-variable 'vhdl-speedbar-display-mode 'project)
  3533. :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
  3534. ["Indentation Offset..."
  3535. (customize-option 'speedbar-indentation-width) t]
  3536. ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
  3537. ["Jump to Unit when Opening"
  3538. (customize-set-variable 'vhdl-speedbar-jump-to-unit
  3539. (not vhdl-speedbar-jump-to-unit))
  3540. :style toggle :selected vhdl-speedbar-jump-to-unit]
  3541. ["Update Hierarchy on File Saving"
  3542. (customize-set-variable 'vhdl-speedbar-update-on-saving
  3543. (not vhdl-speedbar-update-on-saving))
  3544. :style toggle :selected vhdl-speedbar-update-on-saving]
  3545. ("Save in Cache File"
  3546. ["Hierarchy Information"
  3547. (customize-set-variable 'vhdl-speedbar-save-cache
  3548. (if (memq 'hierarchy vhdl-speedbar-save-cache)
  3549. (delq 'hierarchy vhdl-speedbar-save-cache)
  3550. (cons 'hierarchy vhdl-speedbar-save-cache)))
  3551. :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
  3552. ["Displaying Status"
  3553. (customize-set-variable 'vhdl-speedbar-save-cache
  3554. (if (memq 'display vhdl-speedbar-save-cache)
  3555. (delq 'display vhdl-speedbar-save-cache)
  3556. (cons 'display vhdl-speedbar-save-cache)))
  3557. :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
  3558. ["Cache File Name..."
  3559. (customize-option 'vhdl-speedbar-cache-file-name) t]
  3560. "--"
  3561. ["Customize Group..." (customize-group 'vhdl-speedbar) t])
  3562. ("Menu"
  3563. ["Add Index Menu when Loading File"
  3564. (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
  3565. (vhdl-index-menu-init))
  3566. :style toggle :selected vhdl-index-menu]
  3567. ["Add Source File Menu when Loading File"
  3568. (progn (customize-set-variable 'vhdl-source-file-menu
  3569. (not vhdl-source-file-menu))
  3570. (vhdl-add-source-files-menu))
  3571. :style toggle :selected vhdl-source-file-menu]
  3572. ["Add Hideshow Menu at Startup"
  3573. (progn (customize-set-variable 'vhdl-hideshow-menu
  3574. (not vhdl-hideshow-menu))
  3575. (vhdl-activate-customizations))
  3576. :style toggle :selected vhdl-hideshow-menu]
  3577. ["Hide Everything Initially"
  3578. (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
  3579. :style toggle :selected vhdl-hide-all-init]
  3580. "--"
  3581. ["Customize Group..." (customize-group 'vhdl-menu) t])
  3582. ("Print"
  3583. ["In Two Column Format"
  3584. (progn (customize-set-variable 'vhdl-print-two-column
  3585. (not vhdl-print-two-column))
  3586. (message "Activate new setting by saving options and restarting Emacs"))
  3587. :style toggle :selected vhdl-print-two-column]
  3588. ["Use Customized Faces"
  3589. (progn (customize-set-variable 'vhdl-print-customize-faces
  3590. (not vhdl-print-customize-faces))
  3591. (message "Activate new setting by saving options and restarting Emacs"))
  3592. :style toggle :selected vhdl-print-customize-faces]
  3593. "--"
  3594. ["Customize Group..." (customize-group 'vhdl-print) t])
  3595. ("Miscellaneous"
  3596. ["Use Intelligent Tab"
  3597. (progn (customize-set-variable 'vhdl-intelligent-tab
  3598. (not vhdl-intelligent-tab))
  3599. (vhdl-activate-customizations))
  3600. :style toggle :selected vhdl-intelligent-tab]
  3601. ["Indent Syntax-Based"
  3602. (customize-set-variable 'vhdl-indent-syntax-based
  3603. (not vhdl-indent-syntax-based))
  3604. :style toggle :selected vhdl-indent-syntax-based]
  3605. ["Word Completion is Case Sensitive"
  3606. (customize-set-variable 'vhdl-word-completion-case-sensitive
  3607. (not vhdl-word-completion-case-sensitive))
  3608. :style toggle :selected vhdl-word-completion-case-sensitive]
  3609. ["Word Completion in Minibuffer"
  3610. (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
  3611. (not vhdl-word-completion-in-minibuffer))
  3612. (message "Activate new setting by saving options and restarting Emacs"))
  3613. :style toggle :selected vhdl-word-completion-in-minibuffer]
  3614. ["Underscore is Part of Word"
  3615. (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
  3616. (not vhdl-underscore-is-part-of-word))
  3617. (vhdl-activate-customizations))
  3618. :style toggle :selected vhdl-underscore-is-part-of-word]
  3619. "--"
  3620. ["Customize Group..." (customize-group 'vhdl-misc) t])
  3621. ["Related..." (customize-browse 'vhdl-related) t]
  3622. "--"
  3623. ["Save Options" customize-save-customized t]
  3624. ["Activate Options" vhdl-activate-customizations t]
  3625. ["Browse Options..." vhdl-customize t])))
  3626. (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
  3627. "VHDL Mode menu.")
  3628. (defun vhdl-update-mode-menu ()
  3629. "Update VHDL Mode menu."
  3630. (interactive)
  3631. (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
  3632. (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
  3633. (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
  3634. (easy-menu-define vhdl-mode-menu vhdl-mode-map
  3635. "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
  3636. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3637. ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
  3638. (defconst vhdl-imenu-generic-expression
  3639. '(
  3640. ("Subprogram"
  3641. "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
  3642. 4)
  3643. ("Instance"
  3644. "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
  3645. 1)
  3646. ("Component"
  3647. "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
  3648. 2)
  3649. ("Procedural"
  3650. "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
  3651. 1)
  3652. ("Process"
  3653. "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
  3654. 1)
  3655. ("Block"
  3656. "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
  3657. 1)
  3658. ("Package"
  3659. "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
  3660. 3)
  3661. ("Configuration"
  3662. "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
  3663. 2)
  3664. ("Architecture"
  3665. "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
  3666. 2)
  3667. ("Entity"
  3668. "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
  3669. 2)
  3670. )
  3671. "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
  3672. (defun vhdl-index-menu-init ()
  3673. "Initialize index menu."
  3674. (set (make-local-variable 'imenu-case-fold-search) t)
  3675. (set (make-local-variable 'imenu-generic-expression)
  3676. vhdl-imenu-generic-expression)
  3677. (when (and vhdl-index-menu (fboundp 'imenu))
  3678. (if (or (not (boundp 'font-lock-maximum-size))
  3679. (> font-lock-maximum-size (buffer-size)))
  3680. (imenu-add-to-menubar "Index")
  3681. (message "Scanning buffer for index...buffer too big"))))
  3682. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3683. ;; Source file menu (using `easy-menu.el')
  3684. (defvar vhdl-sources-menu nil)
  3685. (defun vhdl-directory-files (directory &optional full match)
  3686. "Call `directory-files' if DIRECTORY exists, otherwise generate error
  3687. message."
  3688. (if (not (file-directory-p directory))
  3689. (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
  3690. (let ((dir (directory-files directory full match)))
  3691. (setq dir (delete "." dir))
  3692. (setq dir (delete ".." dir))
  3693. dir)))
  3694. (defun vhdl-get-source-files (&optional full directory)
  3695. "Get list of VHDL source files in DIRECTORY or current directory."
  3696. (let ((mode-alist auto-mode-alist)
  3697. filename-regexp)
  3698. ;; create regular expressions for matching file names
  3699. (setq filename-regexp "\\`[^.].*\\(")
  3700. (while mode-alist
  3701. (when (eq (cdar mode-alist) 'vhdl-mode)
  3702. (setq filename-regexp
  3703. (concat filename-regexp (caar mode-alist) "\\|")))
  3704. (setq mode-alist (cdr mode-alist)))
  3705. (setq filename-regexp
  3706. (concat (substring filename-regexp 0
  3707. (string-match "\\\\|$" filename-regexp)) "\\)"))
  3708. ;; find files
  3709. (vhdl-directory-files
  3710. (or directory default-directory) full filename-regexp)))
  3711. (defun vhdl-add-source-files-menu ()
  3712. "Scan directory for all VHDL source files and generate menu.
  3713. The directory of the current source file is scanned."
  3714. (interactive)
  3715. (message "Scanning directory for source files ...")
  3716. (let ((newmap (current-local-map))
  3717. (file-list (vhdl-get-source-files))
  3718. menu-list found)
  3719. ;; Create list for menu
  3720. (setq found nil)
  3721. (while file-list
  3722. (setq found t)
  3723. (setq menu-list (cons (vector (car file-list)
  3724. (list 'find-file (car file-list)) t)
  3725. menu-list))
  3726. (setq file-list (cdr file-list)))
  3727. (setq menu-list (vhdl-menu-split menu-list "Sources"))
  3728. (when found (setq menu-list (cons "--" menu-list)))
  3729. (setq menu-list (cons ["*Rescan*" vhdl-add-source-files-menu t] menu-list))
  3730. (setq menu-list (cons "Sources" menu-list))
  3731. ;; Create menu
  3732. (easy-menu-add menu-list)
  3733. (easy-menu-define vhdl-sources-menu newmap
  3734. "VHDL source files menu" menu-list))
  3735. (message ""))
  3736. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3737. ;;; Mode definition
  3738. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3739. ;; performs all buffer local initializations
  3740. ;;;###autoload
  3741. (define-derived-mode vhdl-mode prog-mode
  3742. '("VHDL" (vhdl-electric-mode "/" (vhdl-stutter-mode "/"))
  3743. (vhdl-electric-mode "e")
  3744. (vhdl-stutter-mode "s"))
  3745. "Major mode for editing VHDL code.
  3746. Usage:
  3747. ------
  3748. TEMPLATE INSERTION (electrification):
  3749. After typing a VHDL keyword and entering `SPC', you are prompted for
  3750. arguments while a template is generated for that VHDL construct. Typing
  3751. `RET' or `C-g' at the first \(mandatory) prompt aborts the current
  3752. template generation. Optional arguments are indicated by square
  3753. brackets and removed if the queried string is left empty. Prompts for
  3754. mandatory arguments remain in the code if the queried string is left
  3755. empty. They can be queried again by `C-c C-t C-q'. Enabled
  3756. electrification is indicated by `/e' in the modeline.
  3757. Typing `M-SPC' after a keyword inserts a space without calling the
  3758. template generator. Automatic template generation (i.e.
  3759. electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
  3760. setting option `vhdl-electric-mode' (see OPTIONS).
  3761. Template generators can be invoked from the VHDL menu, by key
  3762. bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
  3763. the keyword (i.e. first word of menu entry not in parenthesis) and
  3764. `SPC'. The following abbreviations can also be used: arch, attr, cond,
  3765. conf, comp, cons, func, inst, pack, sig, var.
  3766. Template styles can be customized in customization group
  3767. `vhdl-template' \(see OPTIONS).
  3768. HEADER INSERTION:
  3769. A file header can be inserted by `C-c C-t C-h'. A file footer
  3770. (template at the end of the file) can be inserted by `C-c C-t C-f'.
  3771. See customization group `vhdl-header'.
  3772. STUTTERING:
  3773. Double striking of some keys inserts cumbersome VHDL syntax elements.
  3774. Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
  3775. option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
  3776. the modeline. The stuttering keys and their effects are:
  3777. ;; --> \" : \" [ --> ( -- --> comment
  3778. ;;; --> \" := \" [[ --> [ --CR --> comment-out code
  3779. .. --> \" => \" ] --> ) --- --> horizontal line
  3780. ,, --> \" <= \" ]] --> ] ---- --> display comment
  3781. == --> \" == \" '' --> \\\"
  3782. WORD COMPLETION:
  3783. Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
  3784. word in the buffer that starts alike, inserts it and adjusts case.
  3785. Re-typing `TAB' toggles through alternative word completions. This also
  3786. works in the minibuffer (i.e. in template generator prompts).
  3787. Typing `TAB' after `(' looks for and inserts complete parenthesized
  3788. expressions (e.g. for array index ranges). All keywords as well as
  3789. standard types and subprograms of VHDL have predefined abbreviations
  3790. \(e.g. type \"std\" and `TAB' will toggle through all standard types
  3791. beginning with \"std\").
  3792. Typing `TAB' after a non-word character indents the line if at the
  3793. beginning of a line (i.e. no preceding non-blank characters), and
  3794. inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
  3795. stop.
  3796. COMMENTS:
  3797. `--' puts a single comment.
  3798. `---' draws a horizontal line for separating code segments.
  3799. `----' inserts a display comment, i.e. two horizontal lines
  3800. with a comment in between.
  3801. `--CR' comments out code on that line. Re-hitting CR comments
  3802. out following lines.
  3803. `C-c c' comments out a region if not commented out,
  3804. uncomments a region if already commented out.
  3805. You are prompted for comments after object definitions (i.e. signals,
  3806. variables, constants, ports) and after subprogram and process
  3807. specifications if option `vhdl-prompt-for-comments' is non-nil.
  3808. Comments are automatically inserted as additional labels (e.g. after
  3809. begin statements) and as help comments if `vhdl-self-insert-comments' is
  3810. non-nil.
  3811. Inline comments (i.e. comments after a piece of code on the same line)
  3812. are indented at least to `vhdl-inline-comment-column'. Comments go at
  3813. maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
  3814. will open a new comment line. Typing beyond `vhdl-end-comment-column'
  3815. in a comment automatically opens a new comment line. `M-q' re-fills
  3816. multi-line comments.
  3817. INDENTATION:
  3818. `TAB' indents a line if at the beginning of the line. The amount of
  3819. indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
  3820. always indents the current line (is bound to `TAB' if option
  3821. `vhdl-intelligent-tab' is nil).
  3822. Indentation can be done for a group of lines (`C-c C-i C-g'), a region
  3823. \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
  3824. indented normally (nil) or relative to the opening parenthesis (non-nil)
  3825. according to option `vhdl-argument-list-indent'.
  3826. If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
  3827. tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
  3828. and vice versa.
  3829. Syntax-based indentation can be very slow in large files. Option
  3830. `vhdl-indent-syntax-based' allows to use faster but simpler indentation.
  3831. ALIGNMENT:
  3832. The alignment functions align operators, keywords, and inline comments
  3833. to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
  3834. separated by blank lines, `C-c C-a C-i' a block of lines with same
  3835. indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
  3836. a pair of parentheses (e.g. port clause/map, argument list), and `C-c
  3837. C-a C-d' all lines within the declarative part of a design unit. `C-c
  3838. C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
  3839. for a group of lines, and `C-c C-a M-c' for a region.
  3840. If option `vhdl-align-groups' is non-nil, groups of code lines
  3841. separated by special lines (see option `vhdl-align-group-separate') are
  3842. aligned individually. If option `vhdl-align-same-indent' is non-nil,
  3843. blocks of lines with same indent are aligned separately. Some templates
  3844. are automatically aligned after generation if option `vhdl-auto-align'
  3845. is non-nil.
  3846. Alignment tries to align inline comments at
  3847. `vhdl-inline-comment-column' and tries inline comment not to exceed
  3848. `vhdl-end-comment-column'.
  3849. `C-c C-x M-w' fixes up whitespace in a region. That is, operator
  3850. symbols are surrounded by one space, and multiple spaces are eliminated.
  3851. CODE FILLING:
  3852. Code filling allows to condense code (e.g. sensitivity lists or port
  3853. maps) by removing comments and newlines and re-wrapping so that all
  3854. lines are maximally filled (block filling). `C-c C-f C-f' fills a list
  3855. enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
  3856. blank lines, `C-c C-f C-i' a block of lines with same indent, and
  3857. `C-c C-f M-f' an entire region.
  3858. CODE BEAUTIFICATION:
  3859. `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
  3860. buffer respectively. This includes indentation, alignment, and case
  3861. fixing. Code beautification can also be run non-interactively using the
  3862. command:
  3863. emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
  3864. PORT TRANSLATION:
  3865. Generic and port clauses from entity or component declarations can be
  3866. copied (`C-c C-p C-w') and pasted as entity and component declarations,
  3867. as component instantiations and corresponding internal constants and
  3868. signals, as a generic map with constants as actual generics, and as
  3869. internal signal initializations (menu).
  3870. To include formals in component instantiations, see option
  3871. `vhdl-association-list-with-formals'. To include comments in pasting,
  3872. see options `vhdl-include-...-comments'.
  3873. A clause with several generic/port names on the same line can be
  3874. flattened (`C-c C-p C-f') so that only one name per line exists. The
  3875. direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
  3876. outputs and vice versa, which can be useful in testbenches. (This
  3877. reversion is done on the internal data structure and is only reflected
  3878. in subsequent paste operations.)
  3879. Names for actual ports, instances, testbenches, and
  3880. design-under-test instances can be derived from existing names according
  3881. to options `vhdl-...-name'. See customization group `vhdl-port'.
  3882. SUBPROGRAM TRANSLATION:
  3883. Similar functionality exists for copying/pasting the interface of
  3884. subprograms (function/procedure). A subprogram interface can be copied
  3885. and then pasted as a subprogram declaration, body or call (uses
  3886. association list with formals).
  3887. TESTBENCH GENERATION:
  3888. A copied port can also be pasted as a testbench. The generated
  3889. testbench includes an entity, an architecture, and an optional
  3890. configuration. The architecture contains the component declaration and
  3891. instantiation of the DUT as well as internal constant and signal
  3892. declarations. Additional user-defined templates can be inserted. The
  3893. names used for entity/architecture/configuration/DUT as well as the file
  3894. structure to be generated can be customized. See customization group
  3895. `vhdl-testbench'.
  3896. KEY BINDINGS:
  3897. Key bindings (`C-c ...') exist for most commands (see in menu).
  3898. VHDL MENU:
  3899. All commands can be found in the VHDL menu including their key bindings.
  3900. FILE BROWSER:
  3901. The speedbar allows browsing of directories and file contents. It can
  3902. be accessed from the VHDL menu and is automatically opened if option
  3903. `vhdl-speedbar-auto-open' is non-nil.
  3904. In speedbar, open files and directories with `mouse-2' on the name and
  3905. browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
  3906. DESIGN HIERARCHY BROWSER:
  3907. The speedbar can also be used for browsing the hierarchy of design units
  3908. contained in the source files of the current directory or the specified
  3909. projects (see option `vhdl-project-alist').
  3910. The speedbar can be switched between file, directory hierarchy and
  3911. project hierarchy browsing mode in the speedbar menu or by typing `f',
  3912. `h' or `H' in speedbar.
  3913. In speedbar, open design units with `mouse-2' on the name and browse
  3914. their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
  3915. from entities and components (in packages). Individual design units and
  3916. complete designs can directly be compiled (\"Make\" menu entry).
  3917. The hierarchy is automatically updated upon saving a modified source
  3918. file when option `vhdl-speedbar-update-on-saving' is non-nil. The
  3919. hierarchy is only updated for projects that have been opened once in the
  3920. speedbar. The hierarchy is cached between Emacs sessions in a file (see
  3921. options in group `vhdl-speedbar').
  3922. Simple design consistency checks are done during scanning, such as
  3923. multiple declarations of the same unit or missing primary units that are
  3924. required by secondary units.
  3925. STRUCTURAL COMPOSITION:
  3926. Enables simple structural composition. `C-c C-c C-n' creates a skeleton
  3927. for a new component. Subcomponents (i.e. component declaration and
  3928. instantiation) can be automatically placed from a previously read port
  3929. \(`C-c C-c C-p') or directly from the hierarchy browser (`P'). Finally,
  3930. all subcomponents can be automatically connected using internal signals
  3931. and ports (`C-c C-c C-w') following these rules:
  3932. - subcomponent actual ports with same name are considered to be
  3933. connected by a signal (internal signal or port)
  3934. - signals that are only inputs to subcomponents are considered as
  3935. inputs to this component -> input port created
  3936. - signals that are only outputs from subcomponents are considered as
  3937. outputs from this component -> output port created
  3938. - signals that are inputs to AND outputs from subcomponents are
  3939. considered as internal connections -> internal signal created
  3940. Purpose: With appropriate naming conventions it is possible to
  3941. create higher design levels with only a few mouse clicks or key
  3942. strokes. A new design level can be created by simply generating a new
  3943. component, placing the required subcomponents from the hierarchy
  3944. browser, and wiring everything automatically.
  3945. Note: Automatic wiring only works reliably on templates of new
  3946. components and component instantiations that were created by VHDL mode.
  3947. Component declarations can be placed in a components package (option
  3948. `vhdl-use-components-package') which can be automatically generated for
  3949. an entire directory or project (`C-c C-c M-p'). The VHDL'93 direct
  3950. component instantiation is also supported (option
  3951. `vhdl-use-direct-instantiation').
  3952. | Configuration declarations can automatically be generated either from
  3953. | the menu (`C-c C-c C-f') (for the architecture the cursor is in) or from
  3954. | the speedbar menu (for the architecture under the cursor). The
  3955. | configurations can optionally be hierarchical (i.e. include all
  3956. | component levels of a hierarchical design, option
  3957. | `vhdl-compose-configuration-hierarchical') or include subconfigurations
  3958. | (option `vhdl-compose-configuration-use-subconfiguration'). For
  3959. | subcomponents in hierarchical configurations, the most-recently-analyzed
  3960. | (mra) architecture is selected. If another architecture is desired, it
  3961. | can be marked as most-recently-analyzed (speedbar menu) before
  3962. | generating the configuration.
  3963. |
  3964. | Note: Configurations of subcomponents (i.e. hierarchical configuration
  3965. | declarations) are currently not considered when displaying
  3966. | configurations in speedbar.
  3967. See the options group `vhdl-compose' for all relevant user options.
  3968. SOURCE FILE COMPILATION:
  3969. The syntax of the current buffer can be analyzed by calling a VHDL
  3970. compiler (menu, `C-c C-k'). The compiler to be used is specified by
  3971. option `vhdl-compiler'. The available compilers are listed in option
  3972. `vhdl-compiler-alist' including all required compilation command,
  3973. command options, compilation directory, and error message syntax
  3974. information. New compilers can be added.
  3975. All the source files of an entire design can be compiled by the `make'
  3976. command (menu, `C-c M-C-k') if an appropriate Makefile exists.
  3977. MAKEFILE GENERATION:
  3978. Makefiles can be generated automatically by an internal generation
  3979. routine (`C-c M-k'). The library unit dependency information is
  3980. obtained from the hierarchy browser. Makefile generation can be
  3981. customized for each compiler in option `vhdl-compiler-alist'.
  3982. Makefile generation can also be run non-interactively using the
  3983. command:
  3984. emacs -batch -l ~/.emacs -l vhdl-mode
  3985. [-compiler compilername] [-project projectname]
  3986. -f vhdl-generate-makefile
  3987. The Makefile's default target \"all\" compiles the entire design, the
  3988. target \"clean\" removes it and the target \"library\" creates the
  3989. library directory if not existent. The Makefile also includes a target
  3990. for each primary library unit which allows selective compilation of this
  3991. unit, its secondary units and its subhierarchy (example: compilation of
  3992. a design specified by a configuration). User specific parts can be
  3993. inserted into a Makefile with option `vhdl-makefile-generation-hook'.
  3994. Limitations:
  3995. - Only library units and dependencies within the current library are
  3996. considered. Makefiles for designs that span multiple libraries are
  3997. not (yet) supported.
  3998. - Only one-level configurations are supported (also hierarchical),
  3999. but configurations that go down several levels are not.
  4000. - The \"others\" keyword in configurations is not supported.
  4001. PROJECTS:
  4002. Projects can be defined in option `vhdl-project-alist' and a current
  4003. project be selected using option `vhdl-project' (permanently) or from
  4004. the menu or speedbar (temporarily). For each project, title and
  4005. description strings (for the file headers), source files/directories
  4006. (for the hierarchy browser and Makefile generation), library name, and
  4007. compiler-dependent options, exceptions and compilation directory can be
  4008. specified. Compilation settings overwrite the settings of option
  4009. `vhdl-compiler-alist'.
  4010. Project setups can be exported (i.e. written to a file) and imported.
  4011. Imported setups are not automatically saved in `vhdl-project-alist' but
  4012. can be saved afterwards in its customization buffer. When starting
  4013. Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
  4014. vhdl-mode\") in a directory with an existing project setup file, it is
  4015. automatically loaded and its project activated if option
  4016. `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
  4017. files can be specified in option `vhdl-project-file-name'. Multiple
  4018. project setups can be automatically loaded from global directories.
  4019. This is an alternative to specifying project setups with option
  4020. `vhdl-project-alist'.
  4021. SPECIAL MENUES:
  4022. As an alternative to the speedbar, an index menu can be added (set
  4023. option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
  4024. (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
  4025. file) for browsing the file contents (is not populated if buffer is
  4026. larger than `font-lock-maximum-size'). Also, a source file menu can be
  4027. added (set option `vhdl-source-file-menu' to non-nil) for browsing the
  4028. current directory for VHDL source files.
  4029. VHDL STANDARDS:
  4030. The VHDL standards to be used are specified in option `vhdl-standard'.
  4031. Available standards are: VHDL'87/'93, VHDL-AMS, and Math Packages.
  4032. KEYWORD CASE:
  4033. Lower and upper case for keywords and standardized types, attributes,
  4034. and enumeration values is supported. If the option
  4035. `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
  4036. lower case and are converted into upper case automatically (not for
  4037. types, attributes, and enumeration values). The case of keywords,
  4038. types, attributes,and enumeration values can be fixed for an entire
  4039. region (menu) or buffer (`C-c C-x C-c') according to the options
  4040. `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
  4041. HIGHLIGHTING (fontification):
  4042. Keywords and standardized types, attributes, enumeration values, and
  4043. function names (controlled by option `vhdl-highlight-keywords'), as well
  4044. as comments, strings, and template prompts are highlighted using
  4045. different colors. Unit, subprogram, signal, variable, constant,
  4046. parameter and generic/port names in declarations as well as labels are
  4047. highlighted if option `vhdl-highlight-names' is non-nil.
  4048. Additional reserved words or words with a forbidden syntax (e.g. words
  4049. that should be avoided) can be specified in option
  4050. `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
  4051. a warning color (option `vhdl-highlight-forbidden-words'). Verilog
  4052. keywords are highlighted as forbidden words if option
  4053. `vhdl-highlight-verilog-keywords' is non-nil.
  4054. Words with special syntax can be highlighted by specifying their
  4055. syntax and color in option `vhdl-special-syntax-alist' and by setting
  4056. option `vhdl-highlight-special-words' to non-nil. This allows to
  4057. establish some naming conventions (e.g. to distinguish different kinds
  4058. of signals or other objects by using name suffices) and to support them
  4059. visually.
  4060. Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
  4061. to support case-sensitive highlighting. However, keywords are then only
  4062. highlighted if written in lower case.
  4063. Code between \"translate_off\" and \"translate_on\" pragmas is
  4064. highlighted using a different background color if option
  4065. `vhdl-highlight-translate-off' is non-nil.
  4066. For documentation and customization of the used colors see
  4067. customization group `vhdl-highlight-faces' (`M-x customize-group'). For
  4068. highlighting of matching parenthesis, see customization group
  4069. `paren-showing'. Automatic buffer highlighting is turned on/off by
  4070. option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
  4071. USER MODELS:
  4072. VHDL models (templates) can be specified by the user and made accessible
  4073. in the menu, through key bindings (`C-c C-m ...'), or by keyword
  4074. electrification. See option `vhdl-model-alist'.
  4075. HIDE/SHOW:
  4076. The code of blocks, processes, subprograms, component declarations and
  4077. instantiations, generic/port clauses, and configuration declarations can
  4078. be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
  4079. the code (see customization group `vhdl-menu'). XEmacs: limited
  4080. functionality due to old `hideshow.el' package.
  4081. CODE UPDATING:
  4082. - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
  4083. current process, `C-c C-u M-s' of all processes in the current buffer.
  4084. Limitations:
  4085. - Only declared local signals (ports, signals declared in
  4086. architecture and blocks) are automatically inserted.
  4087. - Global signals declared in packages are not automatically inserted.
  4088. Insert them once manually (will be kept afterwards).
  4089. - Out parameters of procedures are considered to be read.
  4090. Use option `vhdl-entity-file-name' to specify the entity file name
  4091. \(used to obtain the port names).
  4092. CODE FIXING:
  4093. `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
  4094. \(e.g. if the closing parenthesis is on the wrong line or is missing).
  4095. PRINTING:
  4096. PostScript printing with different faces (an optimized set of faces is
  4097. used if `vhdl-print-customize-faces' is non-nil) or colors \(if
  4098. `ps-print-color-p' is non-nil) is possible using the standard Emacs
  4099. PostScript printing commands. Option `vhdl-print-two-column' defines
  4100. appropriate default settings for nice landscape two-column printing.
  4101. The paper format can be set by option `ps-paper-type'. Do not forget to
  4102. switch `ps-print-color-p' to nil for printing on black-and-white
  4103. printers.
  4104. OPTIONS:
  4105. User options allow customization of VHDL Mode. All options are
  4106. accessible from the \"Options\" menu entry. Simple options (switches
  4107. and choices) can directly be changed, while for complex options a
  4108. customization buffer is opened. Changed options can be saved for future
  4109. sessions using the \"Save Options\" menu entry.
  4110. Options and their detailed descriptions can also be accessed by using
  4111. the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
  4112. customize-group' for groups). Some customizations only take effect
  4113. after some action (read the NOTE in the option documentation).
  4114. Customization can also be done globally (i.e. site-wide, read the
  4115. INSTALL file).
  4116. Not all options are described in this documentation, so go and see
  4117. what other useful user options there are (`M-x vhdl-customize' or menu)!
  4118. FILE EXTENSIONS:
  4119. As default, files with extensions \".vhd\" and \".vhdl\" are
  4120. automatically recognized as VHDL source files. To add an extension
  4121. \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
  4122. \(setq auto-mode-alist (cons '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist))
  4123. HINTS:
  4124. - To start Emacs with open VHDL hierarchy browser without having to load
  4125. a VHDL file first, use the command:
  4126. emacs -l vhdl-mode -f speedbar-frame-mode
  4127. - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
  4128. - Some features only work on properly indented code.
  4129. RELEASE NOTES:
  4130. See also the release notes (menu) for added features in new releases.
  4131. Maintenance:
  4132. ------------
  4133. To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
  4134. Add a description of the problem and include a reproducible test case.
  4135. Questions and enhancement requests can be sent to <reto@gnu.org>.
  4136. The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
  4137. The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
  4138. releases. You are kindly invited to participate in beta testing. Subscribe
  4139. to above mailing lists by sending an email to <reto@gnu.org>.
  4140. VHDL Mode is officially distributed at
  4141. URL `http://opensource.ethz.ch/emacs/vhdl-mode.html'
  4142. where the latest version can be found.
  4143. Known problems:
  4144. ---------------
  4145. - Indentation bug in simultaneous if- and case-statements (VHDL-AMS).
  4146. - XEmacs: Incorrect start-up when automatically opening speedbar.
  4147. - XEmacs: Indentation in XEmacs 21.4 (and higher).
  4148. The VHDL Mode Authors
  4149. Reto Zimmermann and Rod Whitby
  4150. Key bindings:
  4151. -------------
  4152. \\{vhdl-mode-map}"
  4153. :abbrev-table vhdl-mode-abbrev-table
  4154. ;; set local variables
  4155. (set (make-local-variable 'paragraph-start)
  4156. "\\s-*\\(--+\\s-*$\\|[^ -]\\|$\\)")
  4157. (set (make-local-variable 'paragraph-separate) paragraph-start)
  4158. (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
  4159. (set (make-local-variable 'parse-sexp-ignore-comments) t)
  4160. (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
  4161. (set (make-local-variable 'comment-start) "--")
  4162. (set (make-local-variable 'comment-end) "")
  4163. (when vhdl-emacs-21
  4164. (set (make-local-variable 'comment-padding) ""))
  4165. (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
  4166. (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
  4167. (set (make-local-variable 'comment-start-skip) "--+\\s-*")
  4168. (set (make-local-variable 'comment-multi-line) nil)
  4169. (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
  4170. (set (make-local-variable 'hippie-expand-verbose) nil)
  4171. ;; setup the comment indent variable in a Emacs version portable way
  4172. ;; ignore any byte compiler warnings you might get here
  4173. (when (boundp 'comment-indent-function)
  4174. (set (make-local-variable 'comment-indent-function) 'vhdl-comment-indent))
  4175. ;; initialize font locking
  4176. (set (make-local-variable 'font-lock-defaults)
  4177. (list
  4178. '(nil vhdl-font-lock-keywords) nil
  4179. (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line))
  4180. (if (eval-when-compile (fboundp 'syntax-propertize-rules))
  4181. (set (make-local-variable 'syntax-propertize-function)
  4182. (syntax-propertize-rules
  4183. ;; Mark single quotes as having string quote syntax in
  4184. ;; 'c' instances.
  4185. ("\\(\'\\).\\(\'\\)" (1 "\"'") (2 "\"'"))))
  4186. (set (make-local-variable 'font-lock-syntactic-keywords)
  4187. vhdl-font-lock-syntactic-keywords))
  4188. (unless vhdl-emacs-21
  4189. (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
  4190. (set (make-local-variable 'lazy-lock-defer-contextually) nil)
  4191. (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
  4192. ; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
  4193. (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
  4194. ; (turn-on-font-lock)
  4195. ;; variables for source file compilation
  4196. (when vhdl-compile-use-local-error-regexp
  4197. (set (make-local-variable 'compilation-error-regexp-alist) nil)
  4198. (set (make-local-variable 'compilation-file-regexp-alist) nil))
  4199. ;; add index menu
  4200. (vhdl-index-menu-init)
  4201. ;; add source file menu
  4202. (if vhdl-source-file-menu (vhdl-add-source-files-menu))
  4203. ;; add VHDL menu
  4204. (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
  4205. (easy-menu-define vhdl-mode-menu vhdl-mode-map
  4206. "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
  4207. ;; initialize hideshow and add menu
  4208. (vhdl-hideshow-init)
  4209. (run-hooks 'menu-bar-update-hook)
  4210. ;; miscellaneous
  4211. (vhdl-ps-print-init)
  4212. (vhdl-write-file-hooks-init)
  4213. (message "VHDL Mode %s.%s" vhdl-version
  4214. (if noninteractive "" " See menu for documentation and release notes.")))
  4215. (defun vhdl-activate-customizations ()
  4216. "Activate all customizations on local variables."
  4217. (interactive)
  4218. (vhdl-mode-map-init)
  4219. (use-local-map vhdl-mode-map)
  4220. (set-syntax-table vhdl-mode-syntax-table)
  4221. (setq comment-column vhdl-inline-comment-column)
  4222. (setq end-comment-column vhdl-end-comment-column)
  4223. (vhdl-write-file-hooks-init)
  4224. (vhdl-update-mode-menu)
  4225. (vhdl-hideshow-init)
  4226. (run-hooks 'menu-bar-update-hook))
  4227. (defun vhdl-write-file-hooks-init ()
  4228. "Add/remove hooks when buffer is saved."
  4229. (if vhdl-modify-date-on-saving
  4230. (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror nil t)
  4231. (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror t))
  4232. (if (featurep 'xemacs) (make-local-hook 'after-save-hook))
  4233. (add-hook 'after-save-hook 'vhdl-add-modified-file nil t))
  4234. (defun vhdl-process-command-line-option (option)
  4235. "Process command line options for VHDL Mode."
  4236. (cond
  4237. ;; set compiler
  4238. ((equal option "-compiler")
  4239. (vhdl-set-compiler (car command-line-args-left))
  4240. (setq command-line-args-left (cdr command-line-args-left)))
  4241. ;; set project
  4242. ((equal option "-project")
  4243. (vhdl-set-project (car command-line-args-left))
  4244. (setq command-line-args-left (cdr command-line-args-left)))))
  4245. ;; make Emacs process VHDL Mode options
  4246. (setq command-switch-alist
  4247. (append command-switch-alist
  4248. '(("-compiler" . vhdl-process-command-line-option)
  4249. ("-project" . vhdl-process-command-line-option))))
  4250. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4251. ;;; Keywords and standardized words
  4252. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4253. (defconst vhdl-93-keywords
  4254. '(
  4255. "abs" "access" "after" "alias" "all" "and" "architecture" "array"
  4256. "assert" "attribute"
  4257. "begin" "block" "body" "buffer" "bus"
  4258. "case" "component" "configuration" "constant"
  4259. "disconnect" "downto"
  4260. "else" "elsif" "end" "entity" "exit"
  4261. "file" "for" "function"
  4262. "generate" "generic" "group" "guarded"
  4263. "if" "impure" "in" "inertial" "inout" "is"
  4264. "label" "library" "linkage" "literal" "loop"
  4265. "map" "mod"
  4266. "nand" "new" "next" "nor" "not" "null"
  4267. "of" "on" "open" "or" "others" "out"
  4268. "package" "port" "postponed" "procedure" "process" "pure"
  4269. "range" "record" "register" "reject" "rem" "report" "return"
  4270. "rol" "ror"
  4271. "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
  4272. "then" "to" "transport" "type"
  4273. "unaffected" "units" "until" "use"
  4274. "variable"
  4275. "wait" "when" "while" "with"
  4276. "xnor" "xor"
  4277. )
  4278. "List of VHDL'93 keywords.")
  4279. (defconst vhdl-ams-keywords
  4280. '(
  4281. "across" "break" "limit" "nature" "noise" "procedural" "quantity"
  4282. "reference" "spectrum" "subnature" "terminal" "through"
  4283. "tolerance"
  4284. )
  4285. "List of VHDL-AMS keywords.")
  4286. (defconst vhdl-verilog-keywords
  4287. '(
  4288. "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
  4289. "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
  4290. "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
  4291. "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
  4292. "endprimitive" "endspecify" "endtable" "endtask" "event"
  4293. "for" "force" "forever" "fork" "function"
  4294. "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
  4295. "macromodule" "makefile" "medium" "module"
  4296. "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
  4297. "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
  4298. "pullup"
  4299. "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
  4300. "rtranif0" "rtranif1"
  4301. "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
  4302. "strong1" "supply" "supply0" "supply1"
  4303. "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
  4304. "triand" "trior" "trireg"
  4305. "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
  4306. )
  4307. "List of Verilog keywords as candidate for additional reserved words.")
  4308. (defconst vhdl-93-types
  4309. '(
  4310. "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
  4311. "real" "time" "natural" "positive" "string" "line" "text" "side"
  4312. "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
  4313. "std_logic" "std_logic_vector"
  4314. "std_ulogic" "std_ulogic_vector"
  4315. )
  4316. "List of VHDL'93 standardized types.")
  4317. (defconst vhdl-ams-types
  4318. '(
  4319. "domain_type" "real_vector"
  4320. ;; from `nature_pkg' package
  4321. "voltage" "current" "electrical" "position" "velocity" "force"
  4322. "mechanical_vf" "mechanical_pf" "rotvel" "torque" "rotational"
  4323. "pressure" "flowrate" "fluid"
  4324. )
  4325. "List of VHDL-AMS standardized types.")
  4326. (defconst vhdl-math-types
  4327. '(
  4328. "complex" "complex_polar"
  4329. )
  4330. "List of Math Packages standardized types.")
  4331. (defconst vhdl-93-attributes
  4332. '(
  4333. "base" "left" "right" "high" "low" "pos" "val" "succ"
  4334. "pred" "leftof" "rightof" "range" "reverse_range"
  4335. "length" "delayed" "stable" "quiet" "transaction"
  4336. "event" "active" "last_event" "last_active" "last_value"
  4337. "driving" "driving_value" "ascending" "value" "image"
  4338. "simple_name" "instance_name" "path_name"
  4339. "foreign"
  4340. )
  4341. "List of VHDL'93 standardized attributes.")
  4342. (defconst vhdl-ams-attributes
  4343. '(
  4344. "across" "through"
  4345. "reference" "contribution" "tolerance"
  4346. "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
  4347. "ramp" "slew"
  4348. )
  4349. "List of VHDL-AMS standardized attributes.")
  4350. (defconst vhdl-93-enum-values
  4351. '(
  4352. "true" "false"
  4353. "note" "warning" "error" "failure"
  4354. "read_mode" "write_mode" "append_mode"
  4355. "open_ok" "status_error" "name_error" "mode_error"
  4356. "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
  4357. "right" "left"
  4358. )
  4359. "List of VHDL'93 standardized enumeration values.")
  4360. (defconst vhdl-ams-enum-values
  4361. '(
  4362. "quiescent_domain" "time_domain" "frequency_domain"
  4363. ;; from `nature_pkg' package
  4364. "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
  4365. )
  4366. "List of VHDL-AMS standardized enumeration values.")
  4367. (defconst vhdl-math-constants
  4368. '(
  4369. "math_e" "math_1_over_e"
  4370. "math_pi" "math_two_pi" "math_1_over_pi"
  4371. "math_half_pi" "math_q_pi" "math_3_half_pi"
  4372. "math_log_of_2" "math_log_of_10" "math_log2_of_e" "math_log10_of_e"
  4373. "math_sqrt2" "math_sqrt1_2" "math_sqrt_pi"
  4374. "math_deg_to_rad" "math_rad_to_deg"
  4375. "cbase_1" "cbase_j" "czero"
  4376. )
  4377. "List of Math Packages standardized constants.")
  4378. (defconst vhdl-93-functions
  4379. '(
  4380. "now" "resolved" "rising_edge" "falling_edge"
  4381. "read" "readline" "write" "writeline" "endfile"
  4382. "resize" "is_X" "std_match"
  4383. "shift_left" "shift_right" "rotate_left" "rotate_right"
  4384. "to_unsigned" "to_signed" "to_integer"
  4385. "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
  4386. "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
  4387. "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
  4388. "shl" "shr" "ext" "sxt"
  4389. "deallocate"
  4390. )
  4391. "List of VHDL'93 standardized functions.")
  4392. (defconst vhdl-ams-functions
  4393. '(
  4394. "frequency"
  4395. )
  4396. "List of VHDL-AMS standardized functions.")
  4397. (defconst vhdl-math-functions
  4398. '(
  4399. "sign" "ceil" "floor" "round" "trunc" "fmax" "fmin" "uniform"
  4400. "sqrt" "cbrt" "exp" "log"
  4401. "sin" "cos" "tan" "arcsin" "arccos" "arctan"
  4402. "sinh" "cosh" "tanh" "arcsinh" "arccosh" "arctanh"
  4403. "cmplx" "complex_to_polar" "polar_to_complex" "arg" "conj"
  4404. )
  4405. "List of Math Packages standardized functions.")
  4406. (defconst vhdl-93-packages
  4407. '(
  4408. "std_logic_1164" "numeric_std" "numeric_bit"
  4409. "standard" "textio"
  4410. "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
  4411. "std_logic_misc" "std_logic_textio"
  4412. "ieee" "std" "work"
  4413. )
  4414. "List of VHDL'93 standardized packages and libraries.")
  4415. (defconst vhdl-ams-packages
  4416. '(
  4417. ;; from `nature_pkg' package
  4418. "nature_pkg"
  4419. )
  4420. "List of VHDL-AMS standardized packages and libraries.")
  4421. (defconst vhdl-math-packages
  4422. '(
  4423. "math_real" "math_complex"
  4424. )
  4425. "List of Math Packages standardized packages and libraries.")
  4426. (defvar vhdl-keywords nil
  4427. "List of VHDL keywords.")
  4428. (defvar vhdl-types nil
  4429. "List of VHDL standardized types.")
  4430. (defvar vhdl-attributes nil
  4431. "List of VHDL standardized attributes.")
  4432. (defvar vhdl-enum-values nil
  4433. "List of VHDL standardized enumeration values.")
  4434. (defvar vhdl-constants nil
  4435. "List of VHDL standardized constants.")
  4436. (defvar vhdl-functions nil
  4437. "List of VHDL standardized functions.")
  4438. (defvar vhdl-packages nil
  4439. "List of VHDL standardized packages and libraries.")
  4440. (defvar vhdl-reserved-words nil
  4441. "List of additional reserved words.")
  4442. (defvar vhdl-keywords-regexp nil
  4443. "Regexp for VHDL keywords.")
  4444. (defvar vhdl-types-regexp nil
  4445. "Regexp for VHDL standardized types.")
  4446. (defvar vhdl-attributes-regexp nil
  4447. "Regexp for VHDL standardized attributes.")
  4448. (defvar vhdl-enum-values-regexp nil
  4449. "Regexp for VHDL standardized enumeration values.")
  4450. (defvar vhdl-functions-regexp nil
  4451. "Regexp for VHDL standardized functions.")
  4452. (defvar vhdl-packages-regexp nil
  4453. "Regexp for VHDL standardized packages and libraries.")
  4454. (defvar vhdl-reserved-words-regexp nil
  4455. "Regexp for additional reserved words.")
  4456. (defvar vhdl-directive-keywords-regexp nil
  4457. "Regexp for compiler directive keywords.")
  4458. (defun vhdl-words-init ()
  4459. "Initialize reserved words."
  4460. (setq vhdl-keywords
  4461. (append vhdl-93-keywords
  4462. (when (vhdl-standard-p 'ams) vhdl-ams-keywords)))
  4463. (setq vhdl-types
  4464. (append vhdl-93-types
  4465. (when (vhdl-standard-p 'ams) vhdl-ams-types)
  4466. (when (vhdl-standard-p 'math) vhdl-math-types)))
  4467. (setq vhdl-attributes
  4468. (append vhdl-93-attributes
  4469. (when (vhdl-standard-p 'ams) vhdl-ams-attributes)))
  4470. (setq vhdl-enum-values
  4471. (append vhdl-93-enum-values
  4472. (when (vhdl-standard-p 'ams) vhdl-ams-enum-values)))
  4473. (setq vhdl-constants
  4474. (append (when (vhdl-standard-p 'math) vhdl-math-constants)))
  4475. (setq vhdl-functions
  4476. (append vhdl-93-functions
  4477. (when (vhdl-standard-p 'ams) vhdl-ams-functions)
  4478. (when (vhdl-standard-p 'math) vhdl-math-functions)))
  4479. (setq vhdl-packages
  4480. (append vhdl-93-packages
  4481. (when (vhdl-standard-p 'ams) vhdl-ams-packages)
  4482. (when (vhdl-standard-p 'math) vhdl-math-packages)))
  4483. (setq vhdl-reserved-words
  4484. (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
  4485. (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
  4486. '("")))
  4487. (setq vhdl-keywords-regexp
  4488. (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
  4489. (setq vhdl-types-regexp
  4490. (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
  4491. (setq vhdl-attributes-regexp
  4492. (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
  4493. (setq vhdl-enum-values-regexp
  4494. (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
  4495. (setq vhdl-functions-regexp
  4496. (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
  4497. (setq vhdl-packages-regexp
  4498. (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
  4499. (setq vhdl-reserved-words-regexp
  4500. (concat "\\<\\("
  4501. (unless (equal vhdl-forbidden-syntax "")
  4502. (concat vhdl-forbidden-syntax "\\|"))
  4503. (regexp-opt vhdl-reserved-words)
  4504. "\\)\\>"))
  4505. (setq vhdl-directive-keywords-regexp
  4506. (concat "\\<\\(" (mapconcat 'regexp-quote
  4507. vhdl-directive-keywords "\\|") "\\)\\>"))
  4508. (vhdl-abbrev-list-init))
  4509. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4510. ;; Words to expand
  4511. (defvar vhdl-abbrev-list nil
  4512. "Predefined abbreviations for VHDL.")
  4513. (defun vhdl-abbrev-list-init ()
  4514. (setq vhdl-abbrev-list
  4515. (append
  4516. (list vhdl-upper-case-keywords) vhdl-keywords
  4517. (list vhdl-upper-case-types) vhdl-types
  4518. (list vhdl-upper-case-attributes) vhdl-attributes
  4519. (list vhdl-upper-case-enum-values) vhdl-enum-values
  4520. (list vhdl-upper-case-constants) vhdl-constants
  4521. (list nil) vhdl-functions
  4522. (list nil) vhdl-packages)))
  4523. ;; initialize reserved words for VHDL Mode
  4524. (vhdl-words-init)
  4525. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4526. ;;; Indentation
  4527. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4528. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4529. ;; Syntax analysis
  4530. ;; constant regular expressions for looking at various constructs
  4531. (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
  4532. "Regexp describing a VHDL symbol.
  4533. We cannot use just `word' syntax class since `_' cannot be in word
  4534. class. Putting underscore in word class breaks forward word movement
  4535. behavior that users are familiar with.")
  4536. (defconst vhdl-case-header-key "case[( \t\n][^;=>]+[) \t\n]is"
  4537. "Regexp describing a case statement header key.")
  4538. (defconst vhdl-label-key
  4539. (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
  4540. "Regexp describing a VHDL label.")
  4541. ;; Macro definitions:
  4542. (defmacro vhdl-point (position)
  4543. "Return the value of point at certain commonly referenced POSITIONs.
  4544. POSITION can be one of the following symbols:
  4545. bol -- beginning of line
  4546. eol -- end of line
  4547. bod -- beginning of defun
  4548. boi -- back to indentation
  4549. eoi -- last whitespace on line
  4550. ionl -- indentation of next line
  4551. iopl -- indentation of previous line
  4552. bonl -- beginning of next line
  4553. bopl -- beginning of previous line
  4554. This function does not modify point or mark."
  4555. (or (and (eq 'quote (car-safe position))
  4556. (null (cddr position)))
  4557. (error "ERROR: Bad buffer position requested: %s" position))
  4558. (setq position (nth 1 position))
  4559. `(let ((here (point)))
  4560. ,@(cond
  4561. ((eq position 'bol) '((beginning-of-line)))
  4562. ((eq position 'eol) '((end-of-line)))
  4563. ((eq position 'bod) '((save-match-data
  4564. (vhdl-beginning-of-defun))))
  4565. ((eq position 'boi) '((back-to-indentation)))
  4566. ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
  4567. ((eq position 'bonl) '((forward-line 1)))
  4568. ((eq position 'bopl) '((forward-line -1)))
  4569. ((eq position 'iopl)
  4570. '((forward-line -1)
  4571. (back-to-indentation)))
  4572. ((eq position 'ionl)
  4573. '((forward-line 1)
  4574. (back-to-indentation)))
  4575. (t (error "ERROR: Unknown buffer position requested: %s" position))
  4576. )
  4577. (prog1
  4578. (point)
  4579. (goto-char here))
  4580. ;; workaround for an Emacs18 bug -- blech! Well, at least it
  4581. ;; doesn't hurt for v19
  4582. ,@nil
  4583. ))
  4584. (defmacro vhdl-safe (&rest body)
  4585. "Safely execute BODY, return nil if an error occurred."
  4586. `(condition-case nil
  4587. (progn ,@body)
  4588. (error nil)))
  4589. (defmacro vhdl-add-syntax (symbol &optional relpos)
  4590. "A simple macro to append the syntax in SYMBOL to the syntax list.
  4591. Try to increase performance by using this macro."
  4592. `(setq vhdl-syntactic-context
  4593. (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
  4594. (defmacro vhdl-has-syntax (symbol)
  4595. "A simple macro to return check the syntax list.
  4596. Try to increase performance by using this macro."
  4597. `(assoc ,symbol vhdl-syntactic-context))
  4598. ;; Syntactic element offset manipulation:
  4599. (defun vhdl-read-offset (langelem)
  4600. "Read new offset value for LANGELEM from minibuffer.
  4601. Return a valid value only."
  4602. (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
  4603. (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
  4604. (prompt "Offset: ")
  4605. offset input interned)
  4606. (while (not offset)
  4607. (setq input (read-string prompt oldoff)
  4608. offset (cond ((string-equal "+" input) '+)
  4609. ((string-equal "-" input) '-)
  4610. ((string-equal "++" input) '++)
  4611. ((string-equal "--" input) '--)
  4612. ((string-match "^-?[0-9]+$" input)
  4613. (string-to-number input))
  4614. ((fboundp (setq interned (intern input)))
  4615. interned)
  4616. ((boundp interned) interned)
  4617. ;; error, but don't signal one, keep trying
  4618. ;; to read an input value
  4619. (t (ding)
  4620. (setq prompt errmsg)
  4621. nil))))
  4622. offset))
  4623. (defun vhdl-set-offset (symbol offset &optional add-p)
  4624. "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
  4625. SYMBOL is the syntactic element symbol to change and OFFSET is the new
  4626. offset for that syntactic element. Optional ADD-P says to add SYMBOL to
  4627. `vhdl-offsets-alist' if it doesn't already appear there."
  4628. (interactive
  4629. (let* ((langelem
  4630. (intern (completing-read
  4631. (concat "Syntactic symbol to change"
  4632. (if current-prefix-arg " or add" "")
  4633. ": ")
  4634. (mapcar
  4635. (function
  4636. (lambda (langelem)
  4637. (cons (format "%s" (car langelem)) nil)))
  4638. vhdl-offsets-alist)
  4639. nil (not current-prefix-arg)
  4640. ;; initial contents tries to be the last element
  4641. ;; on the syntactic analysis list for the current
  4642. ;; line
  4643. (let* ((syntax (vhdl-get-syntactic-context))
  4644. (len (length syntax))
  4645. (ic (format "%s" (car (nth (1- len) syntax)))))
  4646. ic)
  4647. )))
  4648. (offset (vhdl-read-offset langelem)))
  4649. (list langelem offset current-prefix-arg)))
  4650. ;; sanity check offset
  4651. (or (eq offset '+)
  4652. (eq offset '-)
  4653. (eq offset '++)
  4654. (eq offset '--)
  4655. (integerp offset)
  4656. (fboundp offset)
  4657. (boundp offset)
  4658. (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
  4659. offset))
  4660. (let ((entry (assq symbol vhdl-offsets-alist)))
  4661. (if entry
  4662. (setcdr entry offset)
  4663. (if add-p
  4664. (setq vhdl-offsets-alist
  4665. (cons (cons symbol offset) vhdl-offsets-alist))
  4666. (error "ERROR: %s is not a valid syntactic symbol" symbol))))
  4667. (vhdl-keep-region-active))
  4668. (defun vhdl-set-style (style &optional local)
  4669. "Set `vhdl-mode' variables to use one of several different indentation styles.
  4670. STYLE is a string representing the desired style and optional LOCAL is
  4671. a flag which, if non-nil, means to make the style variables being
  4672. changed buffer local, instead of the default, which is to set the
  4673. global variables. Interactively, the flag comes from the prefix
  4674. argument. The styles are chosen from the `vhdl-style-alist' variable."
  4675. (interactive (list (completing-read "Use which VHDL indentation style? "
  4676. vhdl-style-alist nil t)
  4677. current-prefix-arg))
  4678. (let ((vars (cdr (assoc style vhdl-style-alist))))
  4679. (or vars
  4680. (error "ERROR: Invalid VHDL indentation style `%s'" style))
  4681. ;; set all the variables
  4682. (mapc
  4683. (function
  4684. (lambda (varentry)
  4685. (let ((var (car varentry))
  4686. (val (cdr varentry)))
  4687. ;; special case for vhdl-offsets-alist
  4688. (if (not (eq var 'vhdl-offsets-alist))
  4689. (set (if local (make-local-variable var) var) val)
  4690. ;; reset vhdl-offsets-alist to the default value first
  4691. (set (if local (make-local-variable var) var)
  4692. (copy-alist vhdl-offsets-alist-default))
  4693. ;; now set the langelems that are different
  4694. (mapcar
  4695. (function
  4696. (lambda (langentry)
  4697. (let ((langelem (car langentry))
  4698. (offset (cdr langentry)))
  4699. (vhdl-set-offset langelem offset)
  4700. )))
  4701. val))
  4702. )))
  4703. vars))
  4704. (vhdl-keep-region-active))
  4705. (defun vhdl-get-offset (langelem)
  4706. "Get offset from LANGELEM which is a cons cell of the form:
  4707. \(SYMBOL . RELPOS). The symbol is matched against
  4708. vhdl-offsets-alist and the offset found there is either returned,
  4709. or added to the indentation at RELPOS. If RELPOS is nil, then
  4710. the offset is simply returned."
  4711. (let* ((symbol (car langelem))
  4712. (relpos (cdr langelem))
  4713. (match (assq symbol vhdl-offsets-alist))
  4714. (offset (cdr-safe match)))
  4715. ;; offset can be a number, a function, a variable, or one of the
  4716. ;; symbols + or -
  4717. (cond
  4718. ((not match)
  4719. (if vhdl-strict-syntax-p
  4720. (error "ERROR: Don't know how to indent a %s" symbol)
  4721. (setq offset 0
  4722. relpos 0)))
  4723. ((eq offset '+) (setq offset vhdl-basic-offset))
  4724. ((eq offset '-) (setq offset (- vhdl-basic-offset)))
  4725. ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
  4726. ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
  4727. ((and (not (numberp offset))
  4728. (fboundp offset))
  4729. (setq offset (funcall offset langelem)))
  4730. ((not (numberp offset))
  4731. (setq offset (eval offset)))
  4732. )
  4733. (+ (if (and relpos
  4734. (< relpos (vhdl-point 'bol)))
  4735. (save-excursion
  4736. (goto-char relpos)
  4737. (current-column))
  4738. 0)
  4739. offset)))
  4740. ;; Syntactic support functions:
  4741. (defun vhdl-in-comment-p ()
  4742. "Check if point is in a comment."
  4743. (eq (vhdl-in-literal) 'comment))
  4744. (defun vhdl-in-string-p ()
  4745. "Check if point is in a string."
  4746. (eq (vhdl-in-literal) 'string))
  4747. (defun vhdl-in-literal ()
  4748. "Determine if point is in a VHDL literal."
  4749. (save-excursion
  4750. (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
  4751. (cond
  4752. ((nth 3 state) 'string)
  4753. ((nth 4 state) 'comment)
  4754. ((vhdl-beginning-of-macro) 'pound)
  4755. (t nil)))))
  4756. (defun vhdl-forward-comment (&optional direction)
  4757. "Skip all comments (including whitespace). Skip backwards if DIRECTION is
  4758. negative, skip forward otherwise."
  4759. (interactive "p")
  4760. (if (and direction (< direction 0))
  4761. ;; skip backwards
  4762. (progn
  4763. (skip-chars-backward " \t\n")
  4764. (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
  4765. (goto-char (match-beginning 3))
  4766. (skip-chars-backward " \t\n")))
  4767. ;; skip forwards
  4768. (skip-chars-forward " \t\n")
  4769. (while (looking-at "--.*")
  4770. (goto-char (match-end 0))
  4771. (skip-chars-forward " \t\n"))))
  4772. ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
  4773. (unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
  4774. (defalias 'vhdl-forward-comment 'forward-comment))
  4775. ;; This is the best we can do in Win-Emacs.
  4776. (defun vhdl-win-il (&optional lim)
  4777. "Determine if point is in a VHDL literal."
  4778. (save-excursion
  4779. (let* ((here (point))
  4780. (state nil)
  4781. (match nil)
  4782. (lim (or lim (vhdl-point 'bod))))
  4783. (goto-char lim )
  4784. (while (< (point) here)
  4785. (setq match
  4786. (and (re-search-forward "--\\|[\"']"
  4787. here 'move)
  4788. (buffer-substring (match-beginning 0) (match-end 0))))
  4789. (setq state
  4790. (cond
  4791. ;; no match
  4792. ((null match) nil)
  4793. ;; looking at the opening of a VHDL style comment
  4794. ((string= "--" match)
  4795. (if (<= here (progn (end-of-line) (point))) 'comment))
  4796. ;; looking at the opening of a double quote string
  4797. ((string= "\"" match)
  4798. (if (not (save-restriction
  4799. ;; this seems to be necessary since the
  4800. ;; re-search-forward will not work without it
  4801. (narrow-to-region (point) here)
  4802. (re-search-forward
  4803. ;; this regexp matches a double quote
  4804. ;; which is preceded by an even number
  4805. ;; of backslashes, including zero
  4806. "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
  4807. 'string))
  4808. ;; looking at the opening of a single quote string
  4809. ((string= "'" match)
  4810. (if (not (save-restriction
  4811. ;; see comments from above
  4812. (narrow-to-region (point) here)
  4813. (re-search-forward
  4814. ;; this matches a single quote which is
  4815. ;; preceded by zero or two backslashes.
  4816. "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
  4817. here 'move)))
  4818. 'string))
  4819. (t nil)))
  4820. ) ; end-while
  4821. state)))
  4822. (and (string-match "Win-Emacs" emacs-version)
  4823. (fset 'vhdl-in-literal 'vhdl-win-il))
  4824. ;; Skipping of "syntactic whitespace". Syntactic whitespace is
  4825. ;; defined as lexical whitespace or comments. Search no farther back
  4826. ;; or forward than optional LIM. If LIM is omitted, (point-min) is
  4827. ;; used for backward skipping, (point-max) is used for forward
  4828. ;; skipping.
  4829. (defun vhdl-forward-syntactic-ws (&optional lim)
  4830. "Forward skip of syntactic whitespace."
  4831. (let* ((here (point-max))
  4832. (hugenum (point-max)))
  4833. (while (/= here (point))
  4834. (setq here (point))
  4835. (vhdl-forward-comment hugenum)
  4836. ;; skip preprocessor directives
  4837. (when (and (eq (char-after) ?#)
  4838. (= (vhdl-point 'boi) (point)))
  4839. (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
  4840. (= (forward-line 1) 0)))
  4841. (end-of-line)))
  4842. (if lim (goto-char (min (point) lim)))))
  4843. ;; This is the best we can do in Win-Emacs.
  4844. (defun vhdl-win-fsws (&optional lim)
  4845. "Forward skip syntactic whitespace for Win-Emacs."
  4846. (let ((lim (or lim (point-max)))
  4847. stop)
  4848. (while (not stop)
  4849. (skip-chars-forward " \t\n\r\f" lim)
  4850. (cond
  4851. ;; vhdl comment
  4852. ((looking-at "--") (end-of-line))
  4853. ;; none of the above
  4854. (t (setq stop t))))))
  4855. (and (string-match "Win-Emacs" emacs-version)
  4856. (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
  4857. (defun vhdl-beginning-of-macro (&optional lim)
  4858. "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
  4859. (let ((here (point)))
  4860. (beginning-of-line)
  4861. (while (eq (char-before (1- (point))) ?\\)
  4862. (forward-line -1))
  4863. (back-to-indentation)
  4864. (if (and (<= (point) here)
  4865. (eq (char-after) ?#))
  4866. t
  4867. (goto-char here)
  4868. nil)))
  4869. (defun vhdl-backward-syntactic-ws (&optional lim)
  4870. "Backward skip over syntactic whitespace."
  4871. (let* ((here (point-min))
  4872. (hugenum (- (point-max))))
  4873. (while (/= here (point))
  4874. (setq here (point))
  4875. (vhdl-forward-comment hugenum)
  4876. (vhdl-beginning-of-macro))
  4877. (if lim (goto-char (max (point) lim)))))
  4878. ;; This is the best we can do in Win-Emacs.
  4879. (defun vhdl-win-bsws (&optional lim)
  4880. "Backward skip syntactic whitespace for Win-Emacs."
  4881. (let ((lim (or lim (vhdl-point 'bod)))
  4882. stop)
  4883. (while (not stop)
  4884. (skip-chars-backward " \t\n\r\f" lim)
  4885. (cond
  4886. ;; vhdl comment
  4887. ((eq (vhdl-in-literal) 'comment)
  4888. (skip-chars-backward "^-" lim)
  4889. (skip-chars-backward "-" lim)
  4890. (while (not (or (and (= (following-char) ?-)
  4891. (= (char-after (1+ (point))) ?-))
  4892. (<= (point) lim)))
  4893. (skip-chars-backward "^-" lim)
  4894. (skip-chars-backward "-" lim)))
  4895. ;; none of the above
  4896. (t (setq stop t))))))
  4897. (and (string-match "Win-Emacs" emacs-version)
  4898. (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
  4899. ;; Functions to help finding the correct indentation column:
  4900. (defun vhdl-first-word (point)
  4901. "If the keyword at POINT is at boi, then return (current-column) at
  4902. that point, else nil."
  4903. (save-excursion
  4904. (and (goto-char point)
  4905. (eq (point) (vhdl-point 'boi))
  4906. (current-column))))
  4907. (defun vhdl-last-word (point)
  4908. "If the keyword at POINT is at eoi, then return (current-column) at
  4909. that point, else nil."
  4910. (save-excursion
  4911. (and (goto-char point)
  4912. (save-excursion (or (eq (progn (forward-sexp) (point))
  4913. (vhdl-point 'eoi))
  4914. (looking-at "\\s-*\\(--\\)?")))
  4915. (current-column))))
  4916. ;; Core syntactic evaluation functions:
  4917. (defconst vhdl-libunit-re
  4918. "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
  4919. (defun vhdl-libunit-p ()
  4920. (and
  4921. (save-excursion
  4922. (forward-sexp)
  4923. (skip-chars-forward " \t\n")
  4924. (not (looking-at "is\\b[^_]")))
  4925. (save-excursion
  4926. (backward-sexp)
  4927. (and (not (looking-at "use\\b[^_]"))
  4928. (progn
  4929. (forward-sexp)
  4930. (vhdl-forward-syntactic-ws)
  4931. (/= (following-char) ?:))))
  4932. ))
  4933. (defconst vhdl-defun-re
  4934. "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
  4935. (defun vhdl-defun-p ()
  4936. (save-excursion
  4937. (if (looking-at "block\\|process\\|procedural")
  4938. ;; "block", "process", "procedural":
  4939. (save-excursion
  4940. (backward-sexp)
  4941. (not (looking-at "end\\s-+\\w")))
  4942. ;; "architecture", "configuration", "entity",
  4943. ;; "package", "procedure", "function":
  4944. t)))
  4945. (defun vhdl-corresponding-defun ()
  4946. "If the word at the current position corresponds to a \"defun\"
  4947. keyword, then return a string that can be used to find the
  4948. corresponding \"begin\" keyword, else return nil."
  4949. (save-excursion
  4950. (and (looking-at vhdl-defun-re)
  4951. (vhdl-defun-p)
  4952. (if (looking-at "block\\|process\\|procedural")
  4953. ;; "block", "process". "procedural:
  4954. (buffer-substring (match-beginning 0) (match-end 0))
  4955. ;; "architecture", "configuration", "entity", "package",
  4956. ;; "procedure", "function":
  4957. "is"))))
  4958. (defconst vhdl-begin-fwd-re
  4959. "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b\\([^_]\\|\\'\\)"
  4960. "A regular expression for searching forward that matches all known
  4961. \"begin\" keywords.")
  4962. (defconst vhdl-begin-bwd-re
  4963. "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\|units\\|record\\|for\\)\\b[^_]"
  4964. "A regular expression for searching backward that matches all known
  4965. \"begin\" keywords.")
  4966. (defun vhdl-begin-p (&optional lim)
  4967. "Return t if we are looking at a real \"begin\" keyword.
  4968. Assumes that the caller will make sure that we are looking at
  4969. vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
  4970. the middle of an identifier that just happens to contain a \"begin\"
  4971. keyword."
  4972. (cond
  4973. ;; "[architecture|case|configuration|entity|package|
  4974. ;; procedure|function] ... is":
  4975. ((and (looking-at "i")
  4976. (save-excursion
  4977. ;; Skip backward over first sexp (needed to skip over a
  4978. ;; procedure interface list, and is harmless in other
  4979. ;; situations). Note that we need "return" in the
  4980. ;; following search list so that we don't run into
  4981. ;; semicolons in the function interface list.
  4982. (backward-sexp)
  4983. (let (foundp)
  4984. (while (and (not foundp)
  4985. (re-search-backward
  4986. ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
  4987. lim 'move))
  4988. (if (or (= (preceding-char) ?_)
  4989. (vhdl-in-literal))
  4990. (backward-char)
  4991. (setq foundp t))))
  4992. (and (/= (following-char) ?\;)
  4993. (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
  4994. t)
  4995. ;; "begin", "then":
  4996. ((looking-at "be\\|t")
  4997. t)
  4998. ;; "else":
  4999. ((and (looking-at "e")
  5000. ;; make sure that the "else" isn't inside a
  5001. ;; conditional signal assignment.
  5002. (save-excursion
  5003. (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
  5004. (or (eq (following-char) ?\;)
  5005. (eq (point) lim))))
  5006. t)
  5007. ;; "block", "generate", "loop", "process", "procedural",
  5008. ;; "units", "record":
  5009. ((and (looking-at "bl\\|[glpur]")
  5010. (save-excursion
  5011. (backward-sexp)
  5012. (not (looking-at "end\\s-+\\w"))))
  5013. t)
  5014. ;; "component":
  5015. ((and (looking-at "c")
  5016. (save-excursion
  5017. (backward-sexp)
  5018. (not (looking-at "end\\s-+\\w")))
  5019. ;; look out for the dreaded entity class in an attribute
  5020. (save-excursion
  5021. (vhdl-backward-syntactic-ws lim)
  5022. (/= (preceding-char) ?:)))
  5023. t)
  5024. ;; "for" (inside configuration declaration):
  5025. ((and (looking-at "f")
  5026. (save-excursion
  5027. (backward-sexp)
  5028. (not (looking-at "end\\s-+\\w")))
  5029. (vhdl-has-syntax 'configuration))
  5030. t)
  5031. ))
  5032. (defun vhdl-corresponding-mid (&optional lim)
  5033. (cond
  5034. ((looking-at "is\\|block\\|generate\\|process\\|procedural")
  5035. "begin")
  5036. ((looking-at "then")
  5037. "<else>")
  5038. (t
  5039. "end")))
  5040. (defun vhdl-corresponding-end (&optional lim)
  5041. "If the word at the current position corresponds to a \"begin\"
  5042. keyword, then return a vector containing enough information to find
  5043. the corresponding \"end\" keyword, else return nil. The keyword to
  5044. search forward for is aref 0. The column in which the keyword must
  5045. appear is aref 1 or nil if any column is suitable.
  5046. Assumes that the caller will make sure that we are not in the middle
  5047. of an identifier that just happens to contain a \"begin\" keyword."
  5048. (save-excursion
  5049. (and (looking-at vhdl-begin-fwd-re)
  5050. (/= (preceding-char) ?_)
  5051. (not (vhdl-in-literal))
  5052. (vhdl-begin-p lim)
  5053. (cond
  5054. ;; "is", "generate", "loop":
  5055. ((looking-at "[igl]")
  5056. (vector "end"
  5057. (and (vhdl-last-word (point))
  5058. (or (vhdl-first-word (point))
  5059. (save-excursion
  5060. (vhdl-beginning-of-statement-1 lim)
  5061. (vhdl-backward-skip-label lim)
  5062. (vhdl-first-word (point)))))))
  5063. ;; "begin", "else", "for":
  5064. ((looking-at "be\\|[ef]")
  5065. (vector "end"
  5066. (and (vhdl-last-word (point))
  5067. (or (vhdl-first-word (point))
  5068. (save-excursion
  5069. (vhdl-beginning-of-statement-1 lim)
  5070. (vhdl-backward-skip-label lim)
  5071. (vhdl-first-word (point)))))))
  5072. ;; "component", "units", "record":
  5073. ((looking-at "[cur]")
  5074. ;; The first end found will close the block
  5075. (vector "end" nil))
  5076. ;; "block", "process", "procedural":
  5077. ((looking-at "bl\\|p")
  5078. (vector "end"
  5079. (or (vhdl-first-word (point))
  5080. (save-excursion
  5081. (vhdl-beginning-of-statement-1 lim)
  5082. (vhdl-backward-skip-label lim)
  5083. (vhdl-first-word (point))))))
  5084. ;; "then":
  5085. ((looking-at "t")
  5086. (vector "elsif\\|else\\|end\\s-+if"
  5087. (and (vhdl-last-word (point))
  5088. (or (vhdl-first-word (point))
  5089. (save-excursion
  5090. (vhdl-beginning-of-statement-1 lim)
  5091. (vhdl-backward-skip-label lim)
  5092. (vhdl-first-word (point)))))))
  5093. ))))
  5094. (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
  5095. (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
  5096. (defun vhdl-end-p (&optional lim)
  5097. "Return t if we are looking at a real \"end\" keyword.
  5098. Assumes that the caller will make sure that we are looking at
  5099. vhdl-end-fwd-re, and are not inside a literal, and that we are not in
  5100. the middle of an identifier that just happens to contain an \"end\"
  5101. keyword."
  5102. (or (not (looking-at "else"))
  5103. ;; make sure that the "else" isn't inside a conditional signal
  5104. ;; assignment.
  5105. (save-excursion
  5106. (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
  5107. (or (eq (following-char) ?\;)
  5108. (eq (point) lim)
  5109. (vhdl-in-literal)))))
  5110. (defun vhdl-corresponding-begin (&optional lim)
  5111. "If the word at the current position corresponds to an \"end\"
  5112. keyword, then return a vector containing enough information to find
  5113. the corresponding \"begin\" keyword, else return nil. The keyword to
  5114. search backward for is aref 0. The column in which the keyword must
  5115. appear is aref 1 or nil if any column is suitable. The supplementary
  5116. keyword to search forward for is aref 2 or nil if this is not
  5117. required. If aref 3 is t, then the \"begin\" keyword may be found in
  5118. the middle of a statement.
  5119. Assumes that the caller will make sure that we are not in the middle
  5120. of an identifier that just happens to contain an \"end\" keyword."
  5121. (save-excursion
  5122. (let (pos)
  5123. (if (and (looking-at vhdl-end-fwd-re)
  5124. (not (vhdl-in-literal))
  5125. (vhdl-end-p lim))
  5126. (if (looking-at "el")
  5127. ;; "else", "elsif":
  5128. (vector "if\\|elsif" (vhdl-first-word (point)) "then" nil)
  5129. ;; "end ...":
  5130. (setq pos (point))
  5131. (forward-sexp)
  5132. (skip-chars-forward " \t\n")
  5133. (cond
  5134. ;; "end if":
  5135. ((looking-at "if\\b[^_]")
  5136. (vector "else\\|elsif\\|if"
  5137. (vhdl-first-word pos)
  5138. "else\\|then" nil))
  5139. ;; "end component":
  5140. ((looking-at "component\\b[^_]")
  5141. (vector (buffer-substring (match-beginning 1)
  5142. (match-end 1))
  5143. (vhdl-first-word pos)
  5144. nil nil))
  5145. ;; "end units", "end record":
  5146. ((looking-at "\\(units\\|record\\)\\b[^_]")
  5147. (vector (buffer-substring (match-beginning 1)
  5148. (match-end 1))
  5149. (vhdl-first-word pos)
  5150. nil t))
  5151. ;; "end block", "end process", "end procedural":
  5152. ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
  5153. (vector "begin" (vhdl-first-word pos) nil nil))
  5154. ;; "end case":
  5155. ((looking-at "case\\b[^_]")
  5156. (vector "case" (vhdl-first-word pos) "is" nil))
  5157. ;; "end generate":
  5158. ((looking-at "generate\\b[^_]")
  5159. (vector "generate\\|for\\|if"
  5160. (vhdl-first-word pos)
  5161. "generate" nil))
  5162. ;; "end loop":
  5163. ((looking-at "loop\\b[^_]")
  5164. (vector "loop\\|while\\|for"
  5165. (vhdl-first-word pos)
  5166. "loop" nil))
  5167. ;; "end for" (inside configuration declaration):
  5168. ((looking-at "for\\b[^_]")
  5169. (vector "for" (vhdl-first-word pos) nil nil))
  5170. ;; "end [id]":
  5171. (t
  5172. (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
  5173. (vhdl-first-word pos)
  5174. ;; return an alist of (statement . keyword) mappings
  5175. '(
  5176. ;; "begin ... end [id]":
  5177. ("begin" . nil)
  5178. ;; "architecture ... is ... begin ... end [id]":
  5179. ("architecture" . "is")
  5180. ;; "configuration ... is ... end [id]":
  5181. ("configuration" . "is")
  5182. ;; "entity ... is ... end [id]":
  5183. ("entity" . "is")
  5184. ;; "package ... is ... end [id]":
  5185. ("package" . "is")
  5186. ;; "procedure ... is ... begin ... end [id]":
  5187. ("procedure" . "is")
  5188. ;; "function ... is ... begin ... end [id]":
  5189. ("function" . "is")
  5190. )
  5191. nil))
  5192. ))) ; "end ..."
  5193. )))
  5194. (defconst vhdl-leader-re
  5195. "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
  5196. (defun vhdl-end-of-leader ()
  5197. (save-excursion
  5198. (cond ((looking-at "block\\|process\\|procedural")
  5199. (if (save-excursion
  5200. (forward-sexp)
  5201. (skip-chars-forward " \t\n")
  5202. (= (following-char) ?\())
  5203. (forward-sexp 2)
  5204. (forward-sexp))
  5205. (when (looking-at "[ \t\n]*is")
  5206. (goto-char (match-end 0)))
  5207. (point))
  5208. ((looking-at "component")
  5209. (forward-sexp 2)
  5210. (when (looking-at "[ \t\n]*is")
  5211. (goto-char (match-end 0)))
  5212. (point))
  5213. ((looking-at "for")
  5214. (forward-sexp 2)
  5215. (skip-chars-forward " \t\n")
  5216. (while (looking-at "[,:(]")
  5217. (forward-sexp)
  5218. (skip-chars-forward " \t\n"))
  5219. (point))
  5220. (t nil)
  5221. )))
  5222. (defconst vhdl-trailer-re
  5223. "\\b\\(is\\|then\\|generate\\|loop\\|record\\)\\b[^_]")
  5224. (defconst vhdl-statement-fwd-re
  5225. "\\b\\(if\\|for\\|while\\)\\b\\([^_]\\|\\'\\)"
  5226. "A regular expression for searching forward that matches all known
  5227. \"statement\" keywords.")
  5228. (defconst vhdl-statement-bwd-re
  5229. "\\b\\(if\\|for\\|while\\)\\b[^_]"
  5230. "A regular expression for searching backward that matches all known
  5231. \"statement\" keywords.")
  5232. (defun vhdl-statement-p (&optional lim)
  5233. "Return t if we are looking at a real \"statement\" keyword.
  5234. Assumes that the caller will make sure that we are looking at
  5235. vhdl-statement-fwd-re, and are not inside a literal, and that we are not
  5236. in the middle of an identifier that just happens to contain a
  5237. \"statement\" keyword."
  5238. (cond
  5239. ;; "for" ... "generate":
  5240. ((and (looking-at "f")
  5241. ;; Make sure it's the start of a parameter specification.
  5242. (save-excursion
  5243. (forward-sexp 2)
  5244. (skip-chars-forward " \t\n")
  5245. (looking-at "in\\b[^_]"))
  5246. ;; Make sure it's not an "end for".
  5247. (save-excursion
  5248. (backward-sexp)
  5249. (not (looking-at "end\\s-+\\w"))))
  5250. t)
  5251. ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
  5252. ((and (looking-at "i")
  5253. ;; Make sure it's not an "end if".
  5254. (save-excursion
  5255. (backward-sexp)
  5256. (not (looking-at "end\\s-+\\w"))))
  5257. t)
  5258. ;; "while" ... "loop":
  5259. ((looking-at "w")
  5260. t)
  5261. ))
  5262. (defconst vhdl-case-alternative-re "when[( \t\n][^;=>]+=>"
  5263. "Regexp describing a case statement alternative key.")
  5264. (defun vhdl-case-alternative-p (&optional lim)
  5265. "Return t if we are looking at a real case alternative.
  5266. Assumes that the caller will make sure that we are looking at
  5267. vhdl-case-alternative-re, and are not inside a literal, and that
  5268. we are not in the middle of an identifier that just happens to
  5269. contain a \"when\" keyword."
  5270. (save-excursion
  5271. (let (foundp)
  5272. (while (and (not foundp)
  5273. (re-search-backward ";\\|<=" lim 'move))
  5274. (if (or (= (preceding-char) ?_)
  5275. (vhdl-in-literal))
  5276. (backward-char)
  5277. (setq foundp t)))
  5278. (or (eq (following-char) ?\;)
  5279. (eq (point) lim)))
  5280. ))
  5281. ;; Core syntactic movement functions:
  5282. (defconst vhdl-b-t-b-re
  5283. (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
  5284. (defun vhdl-backward-to-block (&optional lim)
  5285. "Move backward to the previous \"begin\" or \"end\" keyword."
  5286. (let (foundp)
  5287. (while (and (not foundp)
  5288. (re-search-backward vhdl-b-t-b-re lim 'move))
  5289. (if (or (= (preceding-char) ?_)
  5290. (vhdl-in-literal))
  5291. (backward-char)
  5292. (cond
  5293. ;; "begin" keyword:
  5294. ((and (looking-at vhdl-begin-fwd-re)
  5295. (/= (preceding-char) ?_)
  5296. (vhdl-begin-p lim))
  5297. (setq foundp 'begin))
  5298. ;; "end" keyword:
  5299. ((and (looking-at vhdl-end-fwd-re)
  5300. (/= (preceding-char) ?_)
  5301. (vhdl-end-p lim))
  5302. (setq foundp 'end))
  5303. ))
  5304. )
  5305. foundp
  5306. ))
  5307. (defun vhdl-forward-sexp (&optional count lim)
  5308. "Move forward across one balanced expression (sexp).
  5309. With COUNT, do it that many times."
  5310. (interactive "p")
  5311. (let ((count (or count 1))
  5312. (case-fold-search t)
  5313. end-vec target)
  5314. (save-excursion
  5315. (while (> count 0)
  5316. ;; skip whitespace
  5317. (skip-chars-forward " \t\n")
  5318. ;; Check for an unbalanced "end" keyword
  5319. (if (and (looking-at vhdl-end-fwd-re)
  5320. (/= (preceding-char) ?_)
  5321. (not (vhdl-in-literal))
  5322. (vhdl-end-p lim)
  5323. (not (looking-at "else")))
  5324. (error
  5325. "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
  5326. ;; If the current keyword is a "begin" keyword, then find the
  5327. ;; corresponding "end" keyword.
  5328. (if (setq end-vec (vhdl-corresponding-end lim))
  5329. (let (
  5330. ;; end-re is the statement keyword to search for
  5331. (end-re
  5332. (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
  5333. ;; column is either the statement keyword target column
  5334. ;; or nil
  5335. (column (aref end-vec 1))
  5336. (eol (vhdl-point 'eol))
  5337. foundp literal placeholder)
  5338. ;; Look for the statement keyword.
  5339. (while (and (not foundp)
  5340. (re-search-forward end-re nil t)
  5341. (setq placeholder (match-end 1))
  5342. (goto-char (match-beginning 0)))
  5343. ;; If we are in a literal, or not in the right target
  5344. ;; column and not on the same line as the begin, then
  5345. ;; try again.
  5346. (if (or (and column
  5347. (/= (current-indentation) column)
  5348. (> (point) eol))
  5349. (= (preceding-char) ?_)
  5350. (setq literal (vhdl-in-literal)))
  5351. (if (eq literal 'comment)
  5352. (end-of-line)
  5353. (forward-char))
  5354. ;; An "else" keyword corresponds to both the opening brace
  5355. ;; of the following sexp and the closing brace of the
  5356. ;; previous sexp.
  5357. (if (not (looking-at "else"))
  5358. (goto-char placeholder))
  5359. (setq foundp t))
  5360. )
  5361. (if (not foundp)
  5362. (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
  5363. )
  5364. ;; If the current keyword is not a "begin" keyword, then just
  5365. ;; perform the normal forward-sexp.
  5366. (forward-sexp)
  5367. )
  5368. (setq count (1- count))
  5369. )
  5370. (setq target (point)))
  5371. (goto-char target)
  5372. nil))
  5373. (defun vhdl-backward-sexp (&optional count lim)
  5374. "Move backward across one balanced expression (sexp).
  5375. With COUNT, do it that many times. LIM bounds any required backward
  5376. searches."
  5377. (interactive "p")
  5378. (let ((count (or count 1))
  5379. (case-fold-search t)
  5380. begin-vec target)
  5381. (save-excursion
  5382. (while (> count 0)
  5383. ;; Perform the normal backward-sexp, unless we are looking at
  5384. ;; "else" - an "else" keyword corresponds to both the opening brace
  5385. ;; of the following sexp and the closing brace of the previous sexp.
  5386. (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
  5387. (/= (preceding-char) ?_)
  5388. (not (vhdl-in-literal)))
  5389. nil
  5390. (backward-sexp)
  5391. (if (and (looking-at vhdl-begin-fwd-re)
  5392. (/= (preceding-char) ?_)
  5393. (not (vhdl-in-literal))
  5394. (vhdl-begin-p lim))
  5395. (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
  5396. ;; If the current keyword is an "end" keyword, then find the
  5397. ;; corresponding "begin" keyword.
  5398. (if (and (setq begin-vec (vhdl-corresponding-begin lim))
  5399. (/= (preceding-char) ?_))
  5400. (let (
  5401. ;; begin-re is the statement keyword to search for
  5402. (begin-re
  5403. (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
  5404. ;; column is either the statement keyword target column
  5405. ;; or nil
  5406. (column (aref begin-vec 1))
  5407. ;; internal-p controls where the statement keyword can
  5408. ;; be found.
  5409. (internal-p (aref begin-vec 3))
  5410. (last-backward (point)) last-forward
  5411. foundp literal keyword)
  5412. ;; Look for the statement keyword.
  5413. (while (and (not foundp)
  5414. (re-search-backward begin-re lim t)
  5415. (setq keyword
  5416. (buffer-substring (match-beginning 1)
  5417. (match-end 1))))
  5418. ;; If we are in a literal or in the wrong column,
  5419. ;; then try again.
  5420. (if (or (and column
  5421. (and (/= (current-indentation) column)
  5422. ;; possibly accept current-column as
  5423. ;; well as current-indentation.
  5424. (or (not internal-p)
  5425. (/= (current-column) column))))
  5426. (= (preceding-char) ?_)
  5427. (vhdl-in-literal))
  5428. (backward-char)
  5429. ;; If there is a supplementary keyword, then
  5430. ;; search forward for it.
  5431. (if (and (setq begin-re (aref begin-vec 2))
  5432. (or (not (listp begin-re))
  5433. ;; If begin-re is an alist, then find the
  5434. ;; element corresponding to the actual
  5435. ;; keyword that we found.
  5436. (progn
  5437. (setq begin-re
  5438. (assoc keyword begin-re))
  5439. (and begin-re
  5440. (setq begin-re (cdr begin-re))))))
  5441. (and
  5442. (setq begin-re
  5443. (concat "\\b\\(" begin-re "\\)\\b[^_]"))
  5444. (save-excursion
  5445. (setq last-forward (point))
  5446. ;; Look for the supplementary keyword
  5447. ;; (bounded by the backward search start
  5448. ;; point).
  5449. (while (and (not foundp)
  5450. (re-search-forward begin-re
  5451. last-backward t)
  5452. (goto-char (match-beginning 1)))
  5453. ;; If we are in a literal, then try again.
  5454. (if (or (= (preceding-char) ?_)
  5455. (setq literal
  5456. (vhdl-in-literal)))
  5457. (if (eq literal 'comment)
  5458. (goto-char
  5459. (min (vhdl-point 'eol) last-backward))
  5460. (forward-char))
  5461. ;; We have found the supplementary keyword.
  5462. ;; Save the position of the keyword in foundp.
  5463. (setq foundp (point)))
  5464. )
  5465. foundp)
  5466. ;; If the supplementary keyword was found, then
  5467. ;; move point to the supplementary keyword.
  5468. (goto-char foundp))
  5469. ;; If there was no supplementary keyword, then
  5470. ;; point is already at the statement keyword.
  5471. (setq foundp t)))
  5472. ) ; end of the search for the statement keyword
  5473. (if (not foundp)
  5474. (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
  5475. ))
  5476. (setq count (1- count))
  5477. )
  5478. (setq target (point)))
  5479. (goto-char target)
  5480. nil))
  5481. (defun vhdl-backward-up-list (&optional count limit)
  5482. "Move backward out of one level of blocks.
  5483. With argument, do this that many times."
  5484. (interactive "p")
  5485. (let ((count (or count 1))
  5486. target)
  5487. (save-excursion
  5488. (while (> count 0)
  5489. (if (looking-at vhdl-defun-re)
  5490. (error "ERROR: Unbalanced blocks"))
  5491. (vhdl-backward-to-block limit)
  5492. (setq count (1- count)))
  5493. (setq target (point)))
  5494. (goto-char target)))
  5495. (defun vhdl-end-of-defun (&optional count)
  5496. "Move forward to the end of a VHDL defun."
  5497. (interactive)
  5498. (let ((case-fold-search t))
  5499. (vhdl-beginning-of-defun)
  5500. (if (not (looking-at "block\\|process\\|procedural"))
  5501. (re-search-forward "\\bis\\b"))
  5502. (vhdl-forward-sexp)))
  5503. (defun vhdl-mark-defun ()
  5504. "Put mark at end of this \"defun\", point at beginning."
  5505. (interactive)
  5506. (let ((case-fold-search t))
  5507. (push-mark)
  5508. (vhdl-beginning-of-defun)
  5509. (push-mark)
  5510. (if (not (looking-at "block\\|process\\|procedural"))
  5511. (re-search-forward "\\bis\\b"))
  5512. (vhdl-forward-sexp)
  5513. (exchange-point-and-mark)))
  5514. (defun vhdl-beginning-of-libunit ()
  5515. "Move backward to the beginning of a VHDL library unit.
  5516. Returns the location of the corresponding begin keyword, unless search
  5517. stops due to beginning or end of buffer.
  5518. Note that if point is between the \"libunit\" keyword and the
  5519. corresponding \"begin\" keyword, then that libunit will not be
  5520. recognized, and the search will continue backwards. If point is
  5521. at the \"begin\" keyword, then the defun will be recognized. The
  5522. returned point is at the first character of the \"libunit\" keyword."
  5523. (let ((last-forward (point))
  5524. (last-backward
  5525. ;; Just in case we are actually sitting on the "begin"
  5526. ;; keyword, allow for the keyword and an extra character,
  5527. ;; as this will be used when looking forward for the
  5528. ;; "begin" keyword.
  5529. (save-excursion (forward-word 1) (1+ (point))))
  5530. foundp literal placeholder)
  5531. ;; Find the "libunit" keyword.
  5532. (while (and (not foundp)
  5533. (re-search-backward vhdl-libunit-re nil 'move))
  5534. ;; If we are in a literal, or not at a real libunit, then try again.
  5535. (if (or (= (preceding-char) ?_)
  5536. (vhdl-in-literal)
  5537. (not (vhdl-libunit-p)))
  5538. (backward-char)
  5539. ;; Find the corresponding "begin" keyword.
  5540. (setq last-forward (point))
  5541. (while (and (not foundp)
  5542. (re-search-forward "\\bis\\b[^_]" last-backward t)
  5543. (setq placeholder (match-beginning 0)))
  5544. (if (or (= (preceding-char) ?_)
  5545. (setq literal (vhdl-in-literal)))
  5546. ;; It wasn't a real keyword, so keep searching.
  5547. (if (eq literal 'comment)
  5548. (goto-char
  5549. (min (vhdl-point 'eol) last-backward))
  5550. (forward-char))
  5551. ;; We have found the begin keyword, loop will exit.
  5552. (setq foundp placeholder)))
  5553. ;; Go back to the libunit keyword
  5554. (goto-char last-forward)))
  5555. foundp))
  5556. (defun vhdl-beginning-of-defun (&optional count)
  5557. "Move backward to the beginning of a VHDL defun.
  5558. With argument, do it that many times.
  5559. Returns the location of the corresponding begin keyword, unless search
  5560. stops due to beginning or end of buffer."
  5561. ;; Note that if point is between the "defun" keyword and the
  5562. ;; corresponding "begin" keyword, then that defun will not be
  5563. ;; recognized, and the search will continue backwards. If point is
  5564. ;; at the "begin" keyword, then the defun will be recognized. The
  5565. ;; returned point is at the first character of the "defun" keyword.
  5566. (interactive "p")
  5567. (let ((count (or count 1))
  5568. (case-fold-search t)
  5569. (last-forward (point))
  5570. foundp)
  5571. (while (> count 0)
  5572. (setq foundp nil)
  5573. (goto-char last-forward)
  5574. (let ((last-backward
  5575. ;; Just in case we are actually sitting on the "begin"
  5576. ;; keyword, allow for the keyword and an extra character,
  5577. ;; as this will be used when looking forward for the
  5578. ;; "begin" keyword.
  5579. (save-excursion (forward-word 1) (1+ (point))))
  5580. begin-string literal)
  5581. (while (and (not foundp)
  5582. (re-search-backward vhdl-defun-re nil 'move))
  5583. ;; If we are in a literal, then try again.
  5584. (if (or (= (preceding-char) ?_)
  5585. (vhdl-in-literal))
  5586. (backward-char)
  5587. (if (setq begin-string (vhdl-corresponding-defun))
  5588. ;; This is a real defun keyword.
  5589. ;; Find the corresponding "begin" keyword.
  5590. ;; Look for the begin keyword.
  5591. (progn
  5592. ;; Save the search start point.
  5593. (setq last-forward (point))
  5594. (while (and (not foundp)
  5595. (search-forward begin-string last-backward t))
  5596. (if (or (= (preceding-char) ?_)
  5597. (save-match-data
  5598. (setq literal (vhdl-in-literal))))
  5599. ;; It wasn't a real keyword, so keep searching.
  5600. (if (eq literal 'comment)
  5601. (goto-char
  5602. (min (vhdl-point 'eol) last-backward))
  5603. (forward-char))
  5604. ;; We have found the begin keyword, loop will exit.
  5605. (setq foundp (match-beginning 0)))
  5606. )
  5607. ;; Go back to the defun keyword
  5608. (goto-char last-forward)) ; end search for begin keyword
  5609. ))
  5610. ) ; end of the search for the defun keyword
  5611. )
  5612. (setq count (1- count))
  5613. )
  5614. (vhdl-keep-region-active)
  5615. foundp))
  5616. (defun vhdl-beginning-of-statement (&optional count lim interactive)
  5617. "Go to the beginning of the innermost VHDL statement.
  5618. With prefix arg, go back N - 1 statements. If already at the
  5619. beginning of a statement then go to the beginning of the preceding
  5620. one. If within a string or comment, or next to a comment (only
  5621. whitespace between), move by sentences instead of statements.
  5622. When called from a program, this function takes 3 optional args: the
  5623. prefix arg, a buffer position limit which is the farthest back to
  5624. search, and an argument indicating an interactive call."
  5625. (interactive "p\np")
  5626. (let ((count (or count 1))
  5627. (case-fold-search t)
  5628. (lim (or lim (point-min)))
  5629. (here (point))
  5630. state)
  5631. (save-excursion
  5632. (goto-char lim)
  5633. (setq state (parse-partial-sexp (point) here nil nil)))
  5634. (if (and interactive
  5635. (or (nth 3 state)
  5636. (nth 4 state)
  5637. (looking-at (concat "[ \t]*" comment-start-skip))))
  5638. (forward-sentence (- count))
  5639. (while (> count 0)
  5640. (vhdl-beginning-of-statement-1 lim)
  5641. (setq count (1- count))))
  5642. ;; its possible we've been left up-buf of lim
  5643. (goto-char (max (point) lim))
  5644. )
  5645. (vhdl-keep-region-active))
  5646. (defconst vhdl-e-o-s-re
  5647. (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
  5648. (defun vhdl-end-of-statement ()
  5649. "Very simple implementation."
  5650. (interactive)
  5651. (re-search-forward vhdl-e-o-s-re))
  5652. (defconst vhdl-b-o-s-re
  5653. (concat ";\\|\(\\|\)\\|\\bwhen\\b[^_]\\|"
  5654. vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
  5655. (defun vhdl-beginning-of-statement-1 (&optional lim)
  5656. "Move to the start of the current statement, or the previous
  5657. statement if already at the beginning of one."
  5658. (let ((lim (or lim (point-min)))
  5659. (here (point))
  5660. (pos (point))
  5661. donep)
  5662. ;; go backwards one balanced expression, but be careful of
  5663. ;; unbalanced paren being reached
  5664. (if (not (vhdl-safe (progn (backward-sexp) t)))
  5665. (progn
  5666. (backward-up-list 1)
  5667. (forward-char)
  5668. (vhdl-forward-syntactic-ws here)
  5669. (setq donep t)))
  5670. (while (and (not donep)
  5671. (not (bobp))
  5672. ;; look backwards for a statement boundary
  5673. (re-search-backward vhdl-b-o-s-re lim 'move))
  5674. (if (or (= (preceding-char) ?_)
  5675. (vhdl-in-literal))
  5676. (backward-char)
  5677. (cond
  5678. ;; If we are looking at an open paren, then stop after it
  5679. ((eq (following-char) ?\()
  5680. (forward-char)
  5681. (vhdl-forward-syntactic-ws here)
  5682. (setq donep t))
  5683. ;; If we are looking at a close paren, then skip it
  5684. ((eq (following-char) ?\))
  5685. (forward-char)
  5686. (setq pos (point))
  5687. (backward-sexp)
  5688. (if (< (point) lim)
  5689. (progn (goto-char pos)
  5690. (vhdl-forward-syntactic-ws here)
  5691. (setq donep t))))
  5692. ;; If we are looking at a semicolon, then stop
  5693. ((eq (following-char) ?\;)
  5694. (progn
  5695. (forward-char)
  5696. (vhdl-forward-syntactic-ws here)
  5697. (setq donep t)))
  5698. ;; If we are looking at a "begin", then stop
  5699. ((and (looking-at vhdl-begin-fwd-re)
  5700. (/= (preceding-char) ?_)
  5701. (vhdl-begin-p nil))
  5702. ;; If it's a leader "begin", then find the
  5703. ;; right place
  5704. (if (looking-at vhdl-leader-re)
  5705. (save-excursion
  5706. ;; set a default stop point at the begin
  5707. (setq pos (point))
  5708. ;; is the start point inside the leader area ?
  5709. (goto-char (vhdl-end-of-leader))
  5710. (vhdl-forward-syntactic-ws here)
  5711. (if (< (point) here)
  5712. ;; start point was not inside leader area
  5713. ;; set stop point at word after leader
  5714. (setq pos (point))))
  5715. (forward-word 1)
  5716. (vhdl-forward-syntactic-ws here)
  5717. (setq pos (point)))
  5718. (goto-char pos)
  5719. (setq donep t))
  5720. ;; If we are looking at a "statement", then stop
  5721. ((and (looking-at vhdl-statement-fwd-re)
  5722. (/= (preceding-char) ?_)
  5723. (vhdl-statement-p nil))
  5724. (setq donep t))
  5725. ;; If we are looking at a case alternative key, then stop
  5726. ((and (looking-at vhdl-case-alternative-re)
  5727. (vhdl-case-alternative-p lim))
  5728. (save-excursion
  5729. ;; set a default stop point at the when
  5730. (setq pos (point))
  5731. ;; is the start point inside the case alternative key ?
  5732. (looking-at vhdl-case-alternative-re)
  5733. (goto-char (match-end 0))
  5734. (vhdl-forward-syntactic-ws here)
  5735. (if (< (point) here)
  5736. ;; start point was not inside the case alternative key
  5737. ;; set stop point at word after case alternative keyleader
  5738. (setq pos (point))))
  5739. (goto-char pos)
  5740. (setq donep t))
  5741. ;; Bogus find, continue
  5742. (t
  5743. (backward-char)))))
  5744. ))
  5745. ;; Defuns for calculating the current syntactic state:
  5746. (defun vhdl-get-library-unit (bod placeholder)
  5747. "If there is an enclosing library unit at BOD, with its \"begin\"
  5748. keyword at PLACEHOLDER, then return the library unit type."
  5749. (let ((here (vhdl-point 'bol)))
  5750. (if (save-excursion
  5751. (goto-char placeholder)
  5752. (vhdl-safe (vhdl-forward-sexp 1 bod))
  5753. (<= here (point)))
  5754. (save-excursion
  5755. (goto-char bod)
  5756. (cond
  5757. ((looking-at "e") 'entity)
  5758. ((looking-at "a") 'architecture)
  5759. ((looking-at "c") 'configuration)
  5760. ((looking-at "p")
  5761. (save-excursion
  5762. (goto-char bod)
  5763. (forward-sexp)
  5764. (vhdl-forward-syntactic-ws here)
  5765. (if (looking-at "body\\b[^_]")
  5766. 'package-body 'package))))))
  5767. ))
  5768. (defun vhdl-get-block-state (&optional lim)
  5769. "Finds and records all the closest opens.
  5770. LIM is the furthest back we need to search (it should be the
  5771. previous libunit keyword)."
  5772. (let ((here (point))
  5773. (lim (or lim (point-min)))
  5774. keyword sexp-start sexp-mid sexp-end
  5775. preceding-sexp containing-sexp
  5776. containing-begin containing-mid containing-paren)
  5777. (save-excursion
  5778. ;; Find the containing-paren, and use that as the limit
  5779. (if (setq containing-paren
  5780. (save-restriction
  5781. (narrow-to-region lim (point))
  5782. (vhdl-safe (scan-lists (point) -1 1))))
  5783. (setq lim containing-paren))
  5784. ;; Look backwards for "begin" and "end" keywords.
  5785. (while (and (> (point) lim)
  5786. (not containing-sexp))
  5787. (setq keyword (vhdl-backward-to-block lim))
  5788. (cond
  5789. ((eq keyword 'begin)
  5790. ;; Found a "begin" keyword
  5791. (setq sexp-start (point))
  5792. (setq sexp-mid (vhdl-corresponding-mid lim))
  5793. (setq sexp-end (vhdl-safe
  5794. (save-excursion
  5795. (vhdl-forward-sexp 1 lim) (point))))
  5796. (if (and sexp-end (<= sexp-end here))
  5797. ;; we want to record this sexp, but we only want to
  5798. ;; record the last-most of any of them before here
  5799. (or preceding-sexp
  5800. (setq preceding-sexp sexp-start))
  5801. ;; we're contained in this sexp so put sexp-start on
  5802. ;; front of list
  5803. (setq containing-sexp sexp-start)
  5804. (setq containing-mid sexp-mid)
  5805. (setq containing-begin t)))
  5806. ((eq keyword 'end)
  5807. ;; Found an "end" keyword
  5808. (forward-sexp)
  5809. (setq sexp-end (point))
  5810. (setq sexp-mid nil)
  5811. (setq sexp-start
  5812. (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
  5813. (progn (backward-sexp) (point))))
  5814. ;; we want to record this sexp, but we only want to
  5815. ;; record the last-most of any of them before here
  5816. (or preceding-sexp
  5817. (setq preceding-sexp sexp-start)))
  5818. )))
  5819. ;; Check if the containing-paren should be the containing-sexp
  5820. (if (and containing-paren
  5821. (or (null containing-sexp)
  5822. (< containing-sexp containing-paren)))
  5823. (setq containing-sexp containing-paren
  5824. preceding-sexp nil
  5825. containing-begin nil
  5826. containing-mid nil))
  5827. (vector containing-sexp preceding-sexp containing-begin containing-mid)
  5828. ))
  5829. (defconst vhdl-s-c-a-re
  5830. (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
  5831. (defun vhdl-skip-case-alternative (&optional lim)
  5832. "Skip forward over case/when bodies, with optional maximal
  5833. limit. If no next case alternative is found, nil is returned and
  5834. point is not moved."
  5835. (let ((lim (or lim (point-max)))
  5836. (here (point))
  5837. donep foundp)
  5838. (while (and (< (point) lim)
  5839. (not donep))
  5840. (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
  5841. (save-match-data
  5842. (not (vhdl-in-literal)))
  5843. (/= (match-beginning 0) here))
  5844. (progn
  5845. (goto-char (match-beginning 0))
  5846. (cond
  5847. ((and (looking-at "case")
  5848. (re-search-forward "\\bis[^_]" lim t))
  5849. (backward-sexp)
  5850. (vhdl-forward-sexp))
  5851. (t
  5852. (setq donep t
  5853. foundp t))))))
  5854. (if (not foundp)
  5855. (goto-char here))
  5856. foundp))
  5857. (defun vhdl-backward-skip-label (&optional lim)
  5858. "Skip backward over a label, with optional maximal
  5859. limit. If label is not found, nil is returned and point
  5860. is not moved."
  5861. (let ((lim (or lim (point-min)))
  5862. placeholder)
  5863. (if (save-excursion
  5864. (vhdl-backward-syntactic-ws lim)
  5865. (and (eq (preceding-char) ?:)
  5866. (progn
  5867. (backward-sexp)
  5868. (setq placeholder (point))
  5869. (looking-at vhdl-label-key))))
  5870. (goto-char placeholder))
  5871. ))
  5872. (defun vhdl-forward-skip-label (&optional lim)
  5873. "Skip forward over a label, with optional maximal
  5874. limit. If label is not found, nil is returned and point
  5875. is not moved."
  5876. (let ((lim (or lim (point-max))))
  5877. (if (looking-at vhdl-label-key)
  5878. (progn
  5879. (goto-char (match-end 0))
  5880. (vhdl-forward-syntactic-ws lim)))
  5881. ))
  5882. (defun vhdl-get-syntactic-context ()
  5883. "Guess the syntactic description of the current line of VHDL code."
  5884. (save-excursion
  5885. (save-restriction
  5886. (beginning-of-line)
  5887. (let* ((indent-point (point))
  5888. (case-fold-search t)
  5889. vec literal containing-sexp preceding-sexp
  5890. containing-begin containing-mid containing-leader
  5891. char-before-ip char-after-ip begin-after-ip end-after-ip
  5892. placeholder lim library-unit
  5893. )
  5894. ;; Reset the syntactic context
  5895. (setq vhdl-syntactic-context nil)
  5896. (save-excursion
  5897. ;; Move to the start of the previous library unit, and
  5898. ;; record the position of the "begin" keyword.
  5899. (setq placeholder (vhdl-beginning-of-libunit))
  5900. ;; The position of the "libunit" keyword gives us a gross
  5901. ;; limit point.
  5902. (setq lim (point))
  5903. )
  5904. ;; If there is a previous library unit, and we are enclosed by
  5905. ;; it, then set the syntax accordingly.
  5906. (and placeholder
  5907. (setq library-unit (vhdl-get-library-unit lim placeholder))
  5908. (vhdl-add-syntax library-unit lim))
  5909. ;; Find the surrounding state.
  5910. (if (setq vec (vhdl-get-block-state lim))
  5911. (progn
  5912. (setq containing-sexp (aref vec 0))
  5913. (setq preceding-sexp (aref vec 1))
  5914. (setq containing-begin (aref vec 2))
  5915. (setq containing-mid (aref vec 3))
  5916. ))
  5917. ;; set the limit on the farthest back we need to search
  5918. (setq lim (if containing-sexp
  5919. (save-excursion
  5920. (goto-char containing-sexp)
  5921. ;; set containing-leader if required
  5922. (if (looking-at vhdl-leader-re)
  5923. (setq containing-leader (vhdl-end-of-leader)))
  5924. (vhdl-point 'bol))
  5925. (point-min)))
  5926. ;; cache char before and after indent point, and move point to
  5927. ;; the most likely position to perform the majority of tests
  5928. (goto-char indent-point)
  5929. (skip-chars-forward " \t")
  5930. (setq literal (vhdl-in-literal))
  5931. (setq char-after-ip (following-char))
  5932. (setq begin-after-ip (and
  5933. (not literal)
  5934. (looking-at vhdl-begin-fwd-re)
  5935. (vhdl-begin-p)))
  5936. (setq end-after-ip (and
  5937. (not literal)
  5938. (looking-at vhdl-end-fwd-re)
  5939. (vhdl-end-p)))
  5940. (vhdl-backward-syntactic-ws lim)
  5941. (setq char-before-ip (preceding-char))
  5942. (goto-char indent-point)
  5943. (skip-chars-forward " \t")
  5944. ;; now figure out syntactic qualities of the current line
  5945. (cond
  5946. ;; CASE 1: in a string or comment.
  5947. ((memq literal '(string comment))
  5948. (vhdl-add-syntax literal (vhdl-point 'bopl)))
  5949. ;; CASE 2: Line is at top level.
  5950. ((null containing-sexp)
  5951. ;; Find the point to which indentation will be relative
  5952. (save-excursion
  5953. (if (null preceding-sexp)
  5954. ;; CASE 2X.1
  5955. ;; no preceding-sexp -> use the preceding statement
  5956. (vhdl-beginning-of-statement-1 lim)
  5957. ;; CASE 2X.2
  5958. ;; if there is a preceding-sexp then indent relative to it
  5959. (goto-char preceding-sexp)
  5960. ;; if not at boi, then the block-opening keyword is
  5961. ;; probably following a label, so we need a different
  5962. ;; relpos
  5963. (if (/= (point) (vhdl-point 'boi))
  5964. ;; CASE 2X.3
  5965. (vhdl-beginning-of-statement-1 lim)))
  5966. ;; v-b-o-s could have left us at point-min
  5967. (and (bobp)
  5968. ;; CASE 2X.4
  5969. (vhdl-forward-syntactic-ws indent-point))
  5970. (setq placeholder (point)))
  5971. (cond
  5972. ;; CASE 2A : we are looking at a block-open
  5973. (begin-after-ip
  5974. (vhdl-add-syntax 'block-open placeholder))
  5975. ;; CASE 2B: we are looking at a block-close
  5976. (end-after-ip
  5977. (vhdl-add-syntax 'block-close placeholder))
  5978. ;; CASE 2C: we are looking at a top-level statement
  5979. ((progn
  5980. (vhdl-backward-syntactic-ws lim)
  5981. (or (bobp)
  5982. (= (preceding-char) ?\;)))
  5983. (vhdl-add-syntax 'statement placeholder))
  5984. ;; CASE 2D: we are looking at a top-level statement-cont
  5985. (t
  5986. (vhdl-beginning-of-statement-1 lim)
  5987. ;; v-b-o-s could have left us at point-min
  5988. (and (bobp)
  5989. ;; CASE 2D.1
  5990. (vhdl-forward-syntactic-ws indent-point))
  5991. (vhdl-add-syntax 'statement-cont (point)))
  5992. )) ; end CASE 2
  5993. ;; CASE 3: line is inside parentheses. Most likely we are
  5994. ;; either in a subprogram argument (interface) list, or a
  5995. ;; continued expression containing parentheses.
  5996. ((null containing-begin)
  5997. (vhdl-backward-syntactic-ws containing-sexp)
  5998. (cond
  5999. ;; CASE 3A: we are looking at the arglist closing paren
  6000. ((eq char-after-ip ?\))
  6001. (goto-char containing-sexp)
  6002. (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
  6003. ;; CASE 3B: we are looking at the first argument in an empty
  6004. ;; argument list.
  6005. ((eq char-before-ip ?\()
  6006. (goto-char containing-sexp)
  6007. (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
  6008. ;; CASE 3C: we are looking at an arglist continuation line,
  6009. ;; but the preceding argument is on the same line as the
  6010. ;; opening paren. This case includes multi-line
  6011. ;; expression paren groupings.
  6012. ((and (save-excursion
  6013. (goto-char (1+ containing-sexp))
  6014. (skip-chars-forward " \t")
  6015. (not (eolp))
  6016. (not (looking-at "--")))
  6017. (save-excursion
  6018. (vhdl-beginning-of-statement-1 containing-sexp)
  6019. (skip-chars-backward " \t(")
  6020. (<= (point) containing-sexp)))
  6021. (goto-char containing-sexp)
  6022. (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
  6023. ;; CASE 3D: we are looking at just a normal arglist
  6024. ;; continuation line
  6025. (t (vhdl-beginning-of-statement-1 containing-sexp)
  6026. (vhdl-forward-syntactic-ws indent-point)
  6027. (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
  6028. ))
  6029. ;; CASE 4: A block mid open
  6030. ((and begin-after-ip
  6031. (looking-at containing-mid))
  6032. (goto-char containing-sexp)
  6033. ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
  6034. (if (looking-at vhdl-trailer-re)
  6035. ;; CASE 4.1
  6036. (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
  6037. (vhdl-backward-skip-label (vhdl-point 'boi))
  6038. (vhdl-add-syntax 'block-open (point)))
  6039. ;; CASE 5: block close brace
  6040. (end-after-ip
  6041. (goto-char containing-sexp)
  6042. ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
  6043. (if (looking-at vhdl-trailer-re)
  6044. ;; CASE 5.1
  6045. (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
  6046. (vhdl-backward-skip-label (vhdl-point 'boi))
  6047. (vhdl-add-syntax 'block-close (point)))
  6048. ;; CASE 6: A continued statement
  6049. ((and (/= char-before-ip ?\;)
  6050. ;; check it's not a trailer begin keyword, or a begin
  6051. ;; keyword immediately following a label.
  6052. (not (and begin-after-ip
  6053. (or (looking-at vhdl-trailer-re)
  6054. (save-excursion
  6055. (vhdl-backward-skip-label containing-sexp)))))
  6056. ;; check it's not a statement keyword
  6057. (not (and (looking-at vhdl-statement-fwd-re)
  6058. (vhdl-statement-p)))
  6059. ;; see if the b-o-s is before the indent point
  6060. (> indent-point
  6061. (save-excursion
  6062. (vhdl-beginning-of-statement-1 containing-sexp)
  6063. ;; If we ended up after a leader, then this will
  6064. ;; move us forward to the start of the first
  6065. ;; statement. Note that a containing sexp here is
  6066. ;; always a keyword, not a paren, so this will
  6067. ;; have no effect if we hit the containing-sexp.
  6068. (vhdl-forward-syntactic-ws indent-point)
  6069. (setq placeholder (point))))
  6070. ;; check it's not a block-intro
  6071. (/= placeholder containing-sexp)
  6072. ;; check it's not a case block-intro
  6073. (save-excursion
  6074. (goto-char placeholder)
  6075. (or (not (looking-at vhdl-case-alternative-re))
  6076. (> (match-end 0) indent-point))))
  6077. ;; Make placeholder skip a label, but only if it puts us
  6078. ;; before the indent point at the start of a line.
  6079. (let ((new placeholder))
  6080. (if (and (> indent-point
  6081. (save-excursion
  6082. (goto-char placeholder)
  6083. (vhdl-forward-skip-label indent-point)
  6084. (setq new (point))))
  6085. (save-excursion
  6086. (goto-char new)
  6087. (eq new (progn (back-to-indentation) (point)))))
  6088. (setq placeholder new)))
  6089. (vhdl-add-syntax 'statement-cont placeholder)
  6090. (if begin-after-ip
  6091. (vhdl-add-syntax 'block-open)))
  6092. ;; Statement. But what kind?
  6093. ;; CASE 7: A case alternative key
  6094. ((and (looking-at vhdl-case-alternative-re)
  6095. (vhdl-case-alternative-p containing-sexp))
  6096. ;; for a case alternative key, we set relpos to the first
  6097. ;; non-whitespace char on the line containing the "case"
  6098. ;; keyword.
  6099. (goto-char containing-sexp)
  6100. ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
  6101. (if (looking-at vhdl-trailer-re)
  6102. (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
  6103. (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
  6104. ;; CASE 8: statement catchall
  6105. (t
  6106. ;; we know its a statement, but we need to find out if it is
  6107. ;; the first statement in a block
  6108. (if containing-leader
  6109. (goto-char containing-leader)
  6110. (goto-char containing-sexp)
  6111. ;; Note that a containing sexp here is always a keyword,
  6112. ;; not a paren, so skip over the keyword.
  6113. (forward-sexp))
  6114. ;; move to the start of the first statement
  6115. (vhdl-forward-syntactic-ws indent-point)
  6116. (setq placeholder (point))
  6117. ;; we want to ignore case alternatives keys when skipping forward
  6118. (let (incase-p)
  6119. (while (looking-at vhdl-case-alternative-re)
  6120. (setq incase-p (point))
  6121. ;; we also want to skip over the body of the
  6122. ;; case/when statement if that doesn't put us at
  6123. ;; after the indent-point
  6124. (while (vhdl-skip-case-alternative indent-point))
  6125. ;; set up the match end
  6126. (looking-at vhdl-case-alternative-re)
  6127. (goto-char (match-end 0))
  6128. ;; move to the start of the first case alternative statement
  6129. (vhdl-forward-syntactic-ws indent-point)
  6130. (setq placeholder (point)))
  6131. (cond
  6132. ;; CASE 8A: we saw a case/when statement so we must be
  6133. ;; in a switch statement. find out if we are at the
  6134. ;; statement just after a case alternative key
  6135. ((and incase-p
  6136. (= (point) indent-point))
  6137. ;; relpos is the "when" keyword
  6138. (vhdl-add-syntax 'statement-case-intro incase-p))
  6139. ;; CASE 8B: any old statement
  6140. ((< (point) indent-point)
  6141. ;; relpos is the first statement of the block
  6142. (vhdl-add-syntax 'statement placeholder)
  6143. (if begin-after-ip
  6144. (vhdl-add-syntax 'block-open)))
  6145. ;; CASE 8C: first statement in a block
  6146. (t
  6147. (goto-char containing-sexp)
  6148. ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
  6149. (if (looking-at vhdl-trailer-re)
  6150. (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
  6151. (vhdl-backward-skip-label (vhdl-point 'boi))
  6152. (vhdl-add-syntax 'statement-block-intro (point))
  6153. (if begin-after-ip
  6154. (vhdl-add-syntax 'block-open)))
  6155. )))
  6156. )
  6157. ;; now we need to look at any modifiers
  6158. (goto-char indent-point)
  6159. (skip-chars-forward " \t")
  6160. (if (looking-at "--")
  6161. (vhdl-add-syntax 'comment))
  6162. (if (eq literal 'pound)
  6163. (vhdl-add-syntax 'cpp-macro))
  6164. ;; return the syntax
  6165. vhdl-syntactic-context))))
  6166. ;; Standard indentation line-ups:
  6167. (defun vhdl-lineup-arglist (langelem)
  6168. "Lineup the current arglist line with the arglist appearing just
  6169. after the containing paren which starts the arglist."
  6170. (save-excursion
  6171. (let* ((containing-sexp
  6172. (save-excursion
  6173. ;; arglist-cont-nonempty gives relpos ==
  6174. ;; to boi of containing-sexp paren. This
  6175. ;; is good when offset is +, but bad
  6176. ;; when it is vhdl-lineup-arglist, so we
  6177. ;; have to special case a kludge here.
  6178. (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
  6179. (progn
  6180. (beginning-of-line)
  6181. (backward-up-list 1)
  6182. (skip-chars-forward " \t" (vhdl-point 'eol)))
  6183. (goto-char (cdr langelem)))
  6184. (point)))
  6185. (cs-curcol (save-excursion
  6186. (goto-char (cdr langelem))
  6187. (current-column))))
  6188. (if (save-excursion
  6189. (beginning-of-line)
  6190. (looking-at "[ \t]*)"))
  6191. (progn (goto-char (match-end 0))
  6192. (backward-sexp)
  6193. (forward-char)
  6194. (vhdl-forward-syntactic-ws)
  6195. (- (current-column) cs-curcol))
  6196. (goto-char containing-sexp)
  6197. (or (eolp)
  6198. (let ((eol (vhdl-point 'eol))
  6199. (here (progn
  6200. (forward-char)
  6201. (skip-chars-forward " \t")
  6202. (point))))
  6203. (vhdl-forward-syntactic-ws)
  6204. (if (< (point) eol)
  6205. (goto-char here))))
  6206. (- (current-column) cs-curcol)
  6207. ))))
  6208. (defun vhdl-lineup-arglist-intro (langelem)
  6209. "Lineup an arglist-intro line to just after the open paren."
  6210. (save-excursion
  6211. (let ((cs-curcol (save-excursion
  6212. (goto-char (cdr langelem))
  6213. (current-column)))
  6214. (ce-curcol (save-excursion
  6215. (beginning-of-line)
  6216. (backward-up-list 1)
  6217. (skip-chars-forward " \t" (vhdl-point 'eol))
  6218. (current-column))))
  6219. (- ce-curcol cs-curcol -1))))
  6220. (defun vhdl-lineup-comment (langelem)
  6221. "Support old behavior for comment indentation. We look at
  6222. vhdl-comment-only-line-offset to decide how to indent comment
  6223. only-lines."
  6224. (save-excursion
  6225. (back-to-indentation)
  6226. ;; at or to the right of comment-column
  6227. (if (>= (current-column) comment-column)
  6228. (vhdl-comment-indent)
  6229. ;; otherwise, indent as specified by vhdl-comment-only-line-offset
  6230. (if (not (bolp))
  6231. (or (car-safe vhdl-comment-only-line-offset)
  6232. vhdl-comment-only-line-offset)
  6233. (or (cdr-safe vhdl-comment-only-line-offset)
  6234. (car-safe vhdl-comment-only-line-offset)
  6235. -1000 ;jam it against the left side
  6236. )))))
  6237. (defun vhdl-lineup-statement-cont (langelem)
  6238. "Line up statement-cont after the assignment operator."
  6239. (save-excursion
  6240. (let* ((relpos (cdr langelem))
  6241. (assignp (save-excursion
  6242. (goto-char (vhdl-point 'boi))
  6243. (and (re-search-forward "\\(<\\|:\\)="
  6244. (vhdl-point 'eol) t)
  6245. (- (point) (vhdl-point 'boi)))))
  6246. (curcol (progn
  6247. (goto-char relpos)
  6248. (current-column)))
  6249. foundp)
  6250. (while (and (not foundp)
  6251. (< (point) (vhdl-point 'eol)))
  6252. (re-search-forward "\\(<\\|:\\)=\\|(" (vhdl-point 'eol) 'move)
  6253. (if (vhdl-in-literal)
  6254. (forward-char)
  6255. (if (= (preceding-char) ?\()
  6256. ;; skip over any parenthesized expressions
  6257. (goto-char (min (vhdl-point 'eol)
  6258. (scan-lists (point) 1 1)))
  6259. ;; found an assignment operator (not at eol)
  6260. (setq foundp (not (looking-at "\\s-*$"))))))
  6261. (if (not foundp)
  6262. ;; there's no assignment operator on the line
  6263. vhdl-basic-offset
  6264. ;; calculate indentation column after assign and ws, unless
  6265. ;; our line contains an assignment operator
  6266. (if (not assignp)
  6267. (progn
  6268. (forward-char)
  6269. (skip-chars-forward " \t")
  6270. (setq assignp 0)))
  6271. (- (current-column) assignp curcol))
  6272. )))
  6273. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6274. ;; Progress reporting
  6275. (defvar vhdl-progress-info nil
  6276. "Array variable for progress information: 0 begin, 1 end, 2 time.")
  6277. (defun vhdl-update-progress-info (string pos)
  6278. "Update progress information."
  6279. (when (and vhdl-progress-info (not noninteractive)
  6280. (< vhdl-progress-interval
  6281. (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
  6282. (let ((delta (- (aref vhdl-progress-info 1)
  6283. (aref vhdl-progress-info 0))))
  6284. (if (= 0 delta)
  6285. (message (concat string "... (100%s)") "%")
  6286. (message (concat string "... (%2d%s)")
  6287. (/ (* 100 (- pos (aref vhdl-progress-info 0)))
  6288. delta) "%")))
  6289. (aset vhdl-progress-info 2 (nth 1 (current-time)))))
  6290. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6291. ;; Indentation commands
  6292. (defun vhdl-electric-tab (&optional prefix-arg)
  6293. "If preceding character is part of a word or a paren then hippie-expand,
  6294. else if right of non whitespace on line then insert tab,
  6295. else if last command was a tab or return then dedent one step or if a comment
  6296. toggle between normal indent and inline comment indent,
  6297. else indent `correctly'."
  6298. (interactive "*P")
  6299. (vhdl-prepare-search-2
  6300. (cond
  6301. ;; indent region if region is active
  6302. ((and (not (featurep 'xemacs)) (use-region-p))
  6303. (vhdl-indent-region (region-beginning) (region-end) nil))
  6304. ;; expand word
  6305. ((= (char-syntax (preceding-char)) ?w)
  6306. (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
  6307. (case-replace nil)
  6308. (hippie-expand-only-buffers
  6309. (or (and (boundp 'hippie-expand-only-buffers)
  6310. hippie-expand-only-buffers)
  6311. '(vhdl-mode))))
  6312. (vhdl-expand-abbrev prefix-arg)))
  6313. ;; expand parenthesis
  6314. ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
  6315. (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
  6316. (case-replace nil))
  6317. (vhdl-expand-paren prefix-arg)))
  6318. ;; insert tab
  6319. ((> (current-column) (current-indentation))
  6320. (insert-tab))
  6321. ;; toggle comment indent
  6322. ((and (looking-at "--")
  6323. (or (eq last-command 'vhdl-electric-tab)
  6324. (eq last-command 'vhdl-electric-return)))
  6325. (cond ((= (current-indentation) 0) ; no indent
  6326. (indent-to 1)
  6327. (indent-according-to-mode))
  6328. ((< (current-indentation) comment-column) ; normal indent
  6329. (indent-to comment-column)
  6330. (indent-according-to-mode))
  6331. (t ; inline comment indent
  6332. (delete-region (line-beginning-position) (point)))))
  6333. ;; dedent
  6334. ((and (>= (current-indentation) vhdl-basic-offset)
  6335. (or (eq last-command 'vhdl-electric-tab)
  6336. (eq last-command 'vhdl-electric-return)))
  6337. (backward-delete-char-untabify vhdl-basic-offset nil))
  6338. ;; indent line
  6339. (t (indent-according-to-mode)))
  6340. (setq this-command 'vhdl-electric-tab)))
  6341. (defun vhdl-electric-return ()
  6342. "newline-and-indent or indent-new-comment-line if in comment and preceding
  6343. character is a space."
  6344. (interactive)
  6345. (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
  6346. (indent-new-comment-line)
  6347. (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
  6348. (vhdl-fix-case-word -1))
  6349. (newline-and-indent)))
  6350. (defun vhdl-indent-line ()
  6351. "Indent the current line as VHDL code. Returns the amount of
  6352. indentation change."
  6353. (interactive)
  6354. (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
  6355. (pos (- (point-max) (point)))
  6356. (indent
  6357. (if syntax
  6358. ;; indent syntax-based
  6359. (if (and (eq (caar syntax) 'comment)
  6360. (>= (vhdl-get-offset (car syntax)) comment-column))
  6361. ;; special case: comments at or right of comment-column
  6362. (vhdl-get-offset (car syntax))
  6363. (apply '+ (mapcar 'vhdl-get-offset syntax)))
  6364. ;; indent like previous nonblank line
  6365. (save-excursion (beginning-of-line)
  6366. (re-search-backward "^[^\n]" nil t)
  6367. (current-indentation))))
  6368. (shift-amt (- indent (current-indentation))))
  6369. (and vhdl-echo-syntactic-information-p
  6370. (message "syntax: %s, indent= %d" syntax indent))
  6371. (unless (zerop shift-amt)
  6372. (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
  6373. (beginning-of-line)
  6374. (indent-to indent))
  6375. (if (< (point) (vhdl-point 'boi))
  6376. (back-to-indentation)
  6377. ;; If initial point was within line's indentation, position after
  6378. ;; the indentation. Else stay at same point in text.
  6379. (when (> (- (point-max) pos) (point))
  6380. (goto-char (- (point-max) pos))))
  6381. (run-hooks 'vhdl-special-indent-hook)
  6382. (vhdl-update-progress-info "Indenting" (vhdl-current-line))
  6383. shift-amt))
  6384. (defun vhdl-indent-region (beg end column)
  6385. "Indent region as VHDL code.
  6386. Adds progress reporting to `indent-region'."
  6387. (interactive "r\nP")
  6388. (when vhdl-progress-interval
  6389. (setq vhdl-progress-info (vector (count-lines (point-min) beg)
  6390. (count-lines (point-min) end) 0)))
  6391. (indent-region beg end column)
  6392. (when vhdl-progress-interval (message "Indenting...done"))
  6393. (setq vhdl-progress-info nil))
  6394. (defun vhdl-indent-buffer ()
  6395. "Indent whole buffer as VHDL code.
  6396. Calls `indent-region' for whole buffer and adds progress reporting."
  6397. (interactive)
  6398. (vhdl-indent-region (point-min) (point-max) nil))
  6399. (defun vhdl-indent-group ()
  6400. "Indent group of lines between empty lines."
  6401. (interactive)
  6402. (let ((beg (save-excursion
  6403. (if (re-search-backward vhdl-align-group-separate nil t)
  6404. (point-marker)
  6405. (point-min-marker))))
  6406. (end (save-excursion
  6407. (if (re-search-forward vhdl-align-group-separate nil t)
  6408. (point-marker)
  6409. (point-max-marker)))))
  6410. (vhdl-indent-region beg end nil)))
  6411. (defun vhdl-indent-sexp (&optional endpos)
  6412. "Indent each line of the list starting just after point.
  6413. If optional arg ENDPOS is given, indent each line, stopping when
  6414. ENDPOS is encountered."
  6415. (interactive)
  6416. (save-excursion
  6417. (let ((beg (point))
  6418. (end (progn (vhdl-forward-sexp nil endpos) (point))))
  6419. (indent-region beg end nil))))
  6420. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6421. ;; Miscellaneous commands
  6422. (defun vhdl-show-syntactic-information ()
  6423. "Show syntactic information for current line."
  6424. (interactive)
  6425. (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
  6426. (vhdl-keep-region-active))
  6427. ;; Verification and regression functions:
  6428. (defun vhdl-regress-line (&optional arg)
  6429. "Check syntactic information for current line."
  6430. (interactive "P")
  6431. (let ((expected (save-excursion
  6432. (end-of-line)
  6433. (when (search-backward " -- ((" (vhdl-point 'bol) t)
  6434. (forward-char 4)
  6435. (read (current-buffer)))))
  6436. (actual (vhdl-get-syntactic-context))
  6437. (expurgated))
  6438. ;; remove the library unit symbols
  6439. (mapc
  6440. (function
  6441. (lambda (elt)
  6442. (if (memq (car elt) '(entity configuration package
  6443. package-body architecture))
  6444. nil
  6445. (setq expurgated (append expurgated (list elt))))))
  6446. actual)
  6447. (if (and (not arg) expected (listp expected))
  6448. (if (not (equal expected expurgated))
  6449. (error "ERROR: Should be: %s, is: %s" expected expurgated))
  6450. (save-excursion
  6451. (beginning-of-line)
  6452. (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
  6453. (end-of-line)
  6454. (if (search-backward " -- ((" (vhdl-point 'bol) t)
  6455. (delete-region (point) (line-end-position)))
  6456. (insert " -- ")
  6457. (insert (format "%s" expurgated))))))
  6458. (vhdl-keep-region-active))
  6459. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6460. ;;; Alignment, whitespace fixup, beautifying
  6461. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6462. (defconst vhdl-align-alist
  6463. '(
  6464. ;; after some keywords
  6465. (vhdl-mode "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)[ \t]"
  6466. "^\\s-*\\(constant\\|quantity\\|signal\\|subtype\\|terminal\\|type\\|variable\\)\\([ \t]+\\)" 2)
  6467. ;; before ':'
  6468. (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
  6469. ;; after direction specifications
  6470. (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
  6471. ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
  6472. ;; before "==", ":=", "=>", and "<="
  6473. (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "<= ... =>" can occur
  6474. (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
  6475. (vhdl-mode "[<:=]=" "\\([ \t]*\\)[<:=]=" 1) ; since "=> ... <=" can occur
  6476. ;; before some keywords
  6477. (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
  6478. (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
  6479. (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
  6480. ;; before "=>" since "when/else ... =>" can occur
  6481. (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
  6482. )
  6483. "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
  6484. It is searched in order. If REGEXP is found anywhere in the first
  6485. line of a region to be aligned, ALIGN-PATTERN will be used for that
  6486. region. ALIGN-PATTERN must include the whitespace to be expanded or
  6487. contracted. It may also provide regexps for the text surrounding the
  6488. whitespace. SUBEXP specifies which sub-expression of
  6489. ALIGN-PATTERN matches the white space to be expanded/contracted.")
  6490. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6491. ;; Align code
  6492. (defvar vhdl-align-try-all-clauses t
  6493. "If REGEXP is not found on the first line of the region that clause
  6494. is ignored. If this variable is non-nil, then the clause is tried anyway.")
  6495. (defun vhdl-do-group (function &optional spacing)
  6496. "Apply FUNCTION on group of lines between empty lines."
  6497. (let
  6498. ;; search for group beginning
  6499. ((beg (save-excursion
  6500. (if (re-search-backward vhdl-align-group-separate nil t)
  6501. (progn (beginning-of-line 2) (back-to-indentation) (point))
  6502. (point-min))))
  6503. ;; search for group end
  6504. (end (save-excursion
  6505. (if (re-search-forward vhdl-align-group-separate nil t)
  6506. (progn (beginning-of-line) (point))
  6507. (point-max)))))
  6508. ;; run FUNCTION
  6509. (funcall function beg end spacing)))
  6510. (defun vhdl-do-list (function &optional spacing)
  6511. "Apply FUNCTION to the lines of a list surrounded by a balanced group of
  6512. parentheses."
  6513. (let (beg end)
  6514. (save-excursion
  6515. ;; search for beginning of balanced group of parentheses
  6516. (setq beg (vhdl-re-search-backward "[()]" nil t))
  6517. (while (looking-at ")")
  6518. (forward-char) (backward-sexp)
  6519. (setq beg (vhdl-re-search-backward "[()]" nil t)))
  6520. ;; search for end of balanced group of parentheses
  6521. (when beg
  6522. (forward-list)
  6523. (setq end (point))
  6524. (goto-char (1+ beg))
  6525. (skip-chars-forward " \t\n")
  6526. (setq beg (point))))
  6527. ;; run FUNCTION
  6528. (if beg
  6529. (funcall function beg end spacing)
  6530. (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
  6531. (defun vhdl-do-same-indent (function &optional spacing)
  6532. "Apply FUNCTION to block of lines with same indent."
  6533. (let ((indent (current-indentation))
  6534. beg end)
  6535. ;; search for first line with same indent
  6536. (save-excursion
  6537. (while (and (not (bobp))
  6538. (or (looking-at "^\\s-*\\(--.*\\)?$")
  6539. (= (current-indentation) indent)))
  6540. (unless (looking-at "^\\s-*$")
  6541. (back-to-indentation) (setq beg (point)))
  6542. (beginning-of-line -0)))
  6543. ;; search for last line with same indent
  6544. (save-excursion
  6545. (while (and (not (eobp))
  6546. (or (looking-at "^\\s-*\\(--.*\\)?$")
  6547. (= (current-indentation) indent)))
  6548. (if (looking-at "^\\s-*$")
  6549. (beginning-of-line 2)
  6550. (beginning-of-line 2)
  6551. (setq end (point)))))
  6552. ;; run FUNCTION
  6553. (funcall function beg end spacing)))
  6554. (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
  6555. "Attempt to align a range of lines based on the content of the
  6556. lines. The definition of `alignment-list' determines the matching
  6557. order and the manner in which the lines are aligned. If ALIGNMENT-LIST
  6558. is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
  6559. indentation is done before aligning."
  6560. (interactive "r\np")
  6561. (setq alignment-list (or alignment-list vhdl-align-alist))
  6562. (setq spacing (or spacing 1))
  6563. (save-excursion
  6564. (let (bol indent)
  6565. (goto-char end)
  6566. (setq end (point-marker))
  6567. (goto-char begin)
  6568. (setq bol (setq begin (progn (beginning-of-line) (point))))
  6569. ; (untabify bol end)
  6570. (when indent
  6571. (indent-region bol end nil))))
  6572. (let ((copy (copy-alist alignment-list)))
  6573. (vhdl-prepare-search-2
  6574. (while copy
  6575. (save-excursion
  6576. (goto-char begin)
  6577. (let (element
  6578. (eol (point-at-eol)))
  6579. (setq element (nth 0 copy))
  6580. (when (and (or (and (listp (car element))
  6581. (memq major-mode (car element)))
  6582. (eq major-mode (car element)))
  6583. (or vhdl-align-try-all-clauses
  6584. (re-search-forward (car (cdr element)) eol t)))
  6585. (vhdl-align-region-2 begin end (car (cdr (cdr element)))
  6586. (car (cdr (cdr (cdr element)))) spacing))
  6587. (setq copy (cdr copy))))))))
  6588. (defun vhdl-align-region-2 (begin end match &optional substr spacing)
  6589. "Align a range of lines from BEGIN to END. The regular expression
  6590. MATCH must match exactly one field: the whitespace to be
  6591. contracted/expanded. The alignment column will equal the
  6592. rightmost column of the widest whitespace block. SPACING is
  6593. the amount of extra spaces to add to the calculated maximum required.
  6594. SPACING defaults to 1 so that at least one space is inserted after
  6595. the token in MATCH."
  6596. (setq spacing (or spacing 1))
  6597. (setq substr (or substr 1))
  6598. (save-excursion
  6599. (let (distance (max 0) (lines 0) bol eol width)
  6600. ;; Determine the greatest whitespace distance to the alignment
  6601. ;; character
  6602. (goto-char begin)
  6603. (setq eol (point-at-eol)
  6604. bol (setq begin (progn (beginning-of-line) (point))))
  6605. (while (< bol end)
  6606. (save-excursion
  6607. (when (and (re-search-forward match eol t)
  6608. (not (vhdl-in-literal)))
  6609. (setq distance (- (match-beginning substr) bol))
  6610. (when (> distance max)
  6611. (setq max distance))))
  6612. (forward-line)
  6613. (setq bol (point)
  6614. eol (point-at-eol))
  6615. (setq lines (1+ lines)))
  6616. ;; Now insert enough maxs to push each assignment operator to
  6617. ;; the same column. We need to use 'lines' as a counter, since
  6618. ;; the location of the mark may change
  6619. (goto-char (setq bol begin))
  6620. (setq eol (point-at-eol))
  6621. (while (> lines 0)
  6622. (when (and (re-search-forward match eol t)
  6623. (not (vhdl-in-literal)))
  6624. (setq width (- (match-end substr) (match-beginning substr)))
  6625. (setq distance (- (match-beginning substr) bol))
  6626. (goto-char (match-beginning substr))
  6627. (delete-char width)
  6628. (insert-char ? (+ (- max distance) spacing)))
  6629. (beginning-of-line)
  6630. (forward-line)
  6631. (setq bol (point)
  6632. eol (point-at-eol))
  6633. (setq lines (1- lines))))))
  6634. (defun vhdl-align-region-groups (beg end &optional spacing
  6635. no-message no-comments)
  6636. "Align region, treat groups of lines separately."
  6637. (interactive "r\nP")
  6638. (save-excursion
  6639. (let (orig pos)
  6640. (goto-char beg)
  6641. (beginning-of-line)
  6642. (setq orig (point-marker))
  6643. (setq beg (point))
  6644. (goto-char end)
  6645. (setq end (point-marker))
  6646. (untabify beg end)
  6647. (unless no-message
  6648. (when vhdl-progress-interval
  6649. (setq vhdl-progress-info (vector (count-lines (point-min) beg)
  6650. (count-lines (point-min) end) 0))))
  6651. (vhdl-fixup-whitespace-region beg end t)
  6652. (goto-char beg)
  6653. (if (not vhdl-align-groups)
  6654. ;; align entire region
  6655. (progn (vhdl-align-region-1 beg end spacing)
  6656. (unless no-comments
  6657. (vhdl-align-inline-comment-region-1 beg end)))
  6658. ;; align groups
  6659. (while (and (< beg end)
  6660. (re-search-forward vhdl-align-group-separate end t))
  6661. (setq pos (point-marker))
  6662. (vhdl-align-region-1 beg pos spacing)
  6663. (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
  6664. (vhdl-update-progress-info "Aligning" (vhdl-current-line))
  6665. (setq beg (1+ pos))
  6666. (goto-char beg))
  6667. ;; align last group
  6668. (when (< beg end)
  6669. (vhdl-align-region-1 beg end spacing)
  6670. (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
  6671. (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
  6672. (when vhdl-indent-tabs-mode
  6673. (tabify orig end))
  6674. (unless no-message
  6675. (when vhdl-progress-interval (message "Aligning...done"))
  6676. (setq vhdl-progress-info nil)))))
  6677. (defun vhdl-align-region (beg end &optional spacing)
  6678. "Align region, treat blocks with same indent and argument lists separately."
  6679. (interactive "r\nP")
  6680. (if (not vhdl-align-same-indent)
  6681. ;; align entire region
  6682. (vhdl-align-region-groups beg end spacing)
  6683. ;; align blocks with same indent and argument lists
  6684. (save-excursion
  6685. (let ((cur-beg beg)
  6686. indent cur-end)
  6687. (when vhdl-progress-interval
  6688. (setq vhdl-progress-info (vector (count-lines (point-min) beg)
  6689. (count-lines (point-min) end) 0)))
  6690. (goto-char end)
  6691. (setq end (point-marker))
  6692. (goto-char cur-beg)
  6693. (while (< (point) end)
  6694. ;; is argument list opening?
  6695. (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
  6696. (point) (vhdl-point 'eol)))))
  6697. ;; determine region for argument list
  6698. (progn (goto-char cur-beg)
  6699. (forward-sexp)
  6700. (setq cur-end (point))
  6701. (beginning-of-line 2))
  6702. ;; determine region with same indent
  6703. (setq indent (current-indentation))
  6704. (setq cur-beg (point))
  6705. (setq cur-end (vhdl-point 'bonl))
  6706. (beginning-of-line 2)
  6707. (while (and (< (point) end)
  6708. (or (looking-at "^\\s-*\\(--.*\\)?$")
  6709. (= (current-indentation) indent))
  6710. (<= (save-excursion
  6711. (nth 0 (parse-partial-sexp
  6712. (point) (vhdl-point 'eol)))) 0))
  6713. (unless (looking-at "^\\s-*$")
  6714. (setq cur-end (vhdl-point 'bonl)))
  6715. (beginning-of-line 2)))
  6716. ;; align region
  6717. (vhdl-align-region-groups cur-beg cur-end spacing t t))
  6718. (vhdl-align-inline-comment-region beg end spacing noninteractive)
  6719. (when vhdl-progress-interval (message "Aligning...done"))
  6720. (setq vhdl-progress-info nil)))))
  6721. (defun vhdl-align-group (&optional spacing)
  6722. "Align group of lines between empty lines."
  6723. (interactive)
  6724. (vhdl-do-group 'vhdl-align-region spacing))
  6725. (defun vhdl-align-list (&optional spacing)
  6726. "Align the lines of a list surrounded by a balanced group of parentheses."
  6727. (interactive)
  6728. (vhdl-do-list 'vhdl-align-region-groups spacing))
  6729. (defun vhdl-align-same-indent (&optional spacing)
  6730. "Align block of lines with same indent."
  6731. (interactive)
  6732. (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
  6733. (defun vhdl-align-declarations (&optional spacing)
  6734. "Align the lines within the declarative part of a design unit."
  6735. (interactive)
  6736. (let (beg end)
  6737. (vhdl-prepare-search-2
  6738. (save-excursion
  6739. ;; search for declarative part
  6740. (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
  6741. (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
  6742. (setq beg (point))
  6743. (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
  6744. (setq end (point)))))
  6745. (if beg
  6746. (vhdl-align-region-groups beg end spacing)
  6747. (error "ERROR: Not within the declarative part of a design unit"))))
  6748. (defun vhdl-align-buffer ()
  6749. "Align buffer."
  6750. (interactive)
  6751. (vhdl-align-region (point-min) (point-max)))
  6752. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6753. ;; Align inline comments
  6754. (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
  6755. "Align inline comments in region."
  6756. (save-excursion
  6757. (let ((start-max comment-column)
  6758. (length-max 0)
  6759. comment-list start-list tmp-list start length
  6760. cur-start prev-start no-code)
  6761. (setq spacing (or spacing 2))
  6762. (vhdl-prepare-search-2
  6763. (goto-char beg)
  6764. ;; search for comment start positions and lengths
  6765. (while (< (point) end)
  6766. (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
  6767. (looking-at "^\\(.*[^ \t\n-]+\\)\\s-*\\(--.*\\)$")
  6768. (not (save-excursion (goto-char (match-beginning 2))
  6769. (vhdl-in-literal))))
  6770. (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
  6771. (setq length (- (match-end 2) (match-beginning 2)))
  6772. (setq start-max (max start start-max))
  6773. (setq length-max (max length length-max))
  6774. (setq comment-list (cons (cons start length) comment-list)))
  6775. (beginning-of-line 2))
  6776. (setq comment-list
  6777. (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
  6778. ;; reduce start positions
  6779. (setq start-list (list (caar comment-list)))
  6780. (setq comment-list (cdr comment-list))
  6781. (while comment-list
  6782. (unless (or (= (caar comment-list) (car start-list))
  6783. (<= (+ (car start-list) (cdar comment-list))
  6784. end-comment-column))
  6785. (setq start-list (cons (caar comment-list) start-list)))
  6786. (setq comment-list (cdr comment-list)))
  6787. ;; align lines as nicely as possible
  6788. (goto-char beg)
  6789. (while (< (point) end)
  6790. (setq cur-start nil)
  6791. (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
  6792. (or (and (looking-at "^\\(.*[^ \t\n-]+\\)\\(\\s-*\\)\\(--.*\\)$")
  6793. (not (save-excursion
  6794. (goto-char (match-beginning 3))
  6795. (vhdl-in-literal))))
  6796. (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
  6797. (>= (- (match-end 2) (match-beginning 2))
  6798. comment-column))))
  6799. (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
  6800. (setq length (- (match-end 3) (match-beginning 3)))
  6801. (setq no-code (= (match-beginning 1) (match-end 1)))
  6802. ;; insert minimum whitespace
  6803. (goto-char (match-end 2))
  6804. (delete-region (match-beginning 2) (match-end 2))
  6805. (insert-char ?\ spacing)
  6806. (setq tmp-list start-list)
  6807. ;; insert additional whitespace to align
  6808. (setq cur-start
  6809. (cond
  6810. ;; align comment-only line to inline comment of previous line
  6811. ((and no-code prev-start
  6812. (<= length (- end-comment-column prev-start)))
  6813. prev-start)
  6814. ;; align all comments at `start-max' if this is possible
  6815. ((<= (+ start-max length-max) end-comment-column)
  6816. start-max)
  6817. ;; align at `comment-column' if possible
  6818. ((and (<= start comment-column)
  6819. (<= length (- end-comment-column comment-column)))
  6820. comment-column)
  6821. ;; align at left-most possible start position otherwise
  6822. (t
  6823. (while (and tmp-list (< (car tmp-list) start))
  6824. (setq tmp-list (cdr tmp-list)))
  6825. (car tmp-list))))
  6826. (indent-to cur-start))
  6827. (setq prev-start cur-start)
  6828. (beginning-of-line 2))))))
  6829. (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
  6830. "Align inline comments within a region. Groups of code lines separated by
  6831. empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
  6832. (interactive "r\nP")
  6833. (save-excursion
  6834. (let (orig pos)
  6835. (goto-char beg)
  6836. (beginning-of-line)
  6837. (setq orig (point-marker))
  6838. (setq beg (point))
  6839. (goto-char end)
  6840. (setq end (point-marker))
  6841. (untabify beg end)
  6842. (unless no-message (message "Aligning inline comments..."))
  6843. (goto-char beg)
  6844. (if (not vhdl-align-groups)
  6845. ;; align entire region
  6846. (vhdl-align-inline-comment-region-1 beg end spacing)
  6847. ;; align groups
  6848. (while (and (< beg end)
  6849. (re-search-forward vhdl-align-group-separate end t))
  6850. (setq pos (point-marker))
  6851. (vhdl-align-inline-comment-region-1 beg pos spacing)
  6852. (setq beg (1+ pos))
  6853. (goto-char beg))
  6854. ;; align last group
  6855. (when (< beg end)
  6856. (vhdl-align-inline-comment-region-1 beg end spacing)))
  6857. (when vhdl-indent-tabs-mode
  6858. (tabify orig end))
  6859. (unless no-message (message "Aligning inline comments...done")))))
  6860. (defun vhdl-align-inline-comment-group (&optional spacing)
  6861. "Align inline comments within a group of lines between empty lines."
  6862. (interactive)
  6863. (save-excursion
  6864. (let ((start (point))
  6865. beg end)
  6866. (setq end (if (re-search-forward vhdl-align-group-separate nil t)
  6867. (point-marker) (point-max)))
  6868. (goto-char start)
  6869. (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
  6870. (point) (point-min)))
  6871. (untabify beg end)
  6872. (message "Aligning inline comments...")
  6873. (vhdl-align-inline-comment-region-1 beg end)
  6874. (when vhdl-indent-tabs-mode
  6875. (tabify beg end))
  6876. (message "Aligning inline comments...done"))))
  6877. (defun vhdl-align-inline-comment-buffer ()
  6878. "Align inline comments within buffer. Groups of code lines separated by
  6879. empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
  6880. (interactive)
  6881. (vhdl-align-inline-comment-region (point-min) (point-max)))
  6882. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6883. ;; Fixup whitespace
  6884. (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
  6885. "Fixup whitespace in region. Surround operator symbols by one space,
  6886. eliminate multiple spaces (except at beginning of line), eliminate spaces at
  6887. end of line, do nothing in comments and strings."
  6888. (interactive "r")
  6889. (unless no-message (message "Fixing up whitespace..."))
  6890. (save-excursion
  6891. (goto-char end)
  6892. (setq end (point-marker))
  6893. ;; have no space before and one space after `,' and ';'
  6894. (goto-char beg)
  6895. (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
  6896. (if (match-string 1)
  6897. (goto-char (match-end 1))
  6898. (replace-match "\\3 " nil nil nil 3)))
  6899. ;; have no space after `('
  6900. (goto-char beg)
  6901. (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\((\\)\\s-+" end t)
  6902. (if (match-string 1)
  6903. (goto-char (match-end 1))
  6904. (replace-match "\\2")))
  6905. ;; have no space before `)'
  6906. (goto-char beg)
  6907. (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
  6908. (if (match-string 1)
  6909. (goto-char (match-end 1))
  6910. (replace-match "\\2")))
  6911. ;; surround operator symbols by one space
  6912. (goto-char beg)
  6913. (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\)\\|\\(\\([^/:<>=]\\)\\(:\\|=\\|<\\|>\\|:=\\|<=\\|>=\\|=>\\|/=\\)\\([^=>]\\|$\\)\\)" end t)
  6914. (if (match-string 1)
  6915. (goto-char (match-end 1))
  6916. (replace-match "\\3 \\4 \\5")
  6917. (goto-char (match-end 2))))
  6918. ;; eliminate multiple spaces and spaces at end of line
  6919. (goto-char beg)
  6920. (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
  6921. (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
  6922. (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
  6923. (progn (replace-match "" nil nil) t))
  6924. (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
  6925. (progn (replace-match ";" nil nil) t))
  6926. (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
  6927. (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
  6928. (progn (replace-match " " nil nil) t))
  6929. (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
  6930. (progn (replace-match " " nil nil) t))
  6931. ; (re-search-forward "[^ \t-]+" end t))))
  6932. (re-search-forward "[^ \t\"-]+" end t))))
  6933. (unless no-message (message "Fixing up whitespace...done")))
  6934. (defun vhdl-fixup-whitespace-buffer ()
  6935. "Fixup whitespace in buffer. Surround operator symbols by one space,
  6936. eliminate multiple spaces (except at beginning of line), eliminate spaces at
  6937. end of line, do nothing in comments."
  6938. (interactive)
  6939. (vhdl-fixup-whitespace-region (point-min) (point-max)))
  6940. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6941. ;; Beautify
  6942. (defun vhdl-beautify-region (beg end)
  6943. "Beautify region by applying indentation, whitespace fixup, alignment, and
  6944. case fixing to a region. Calls functions `vhdl-indent-buffer',
  6945. `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
  6946. `vhdl-fix-case-buffer'."
  6947. (interactive "r")
  6948. (setq end (save-excursion (goto-char end) (point-marker)))
  6949. (vhdl-indent-region beg end nil)
  6950. (let ((vhdl-align-groups t))
  6951. (vhdl-align-region beg end))
  6952. (vhdl-fix-case-region beg end))
  6953. (defun vhdl-beautify-buffer ()
  6954. "Beautify buffer by applying indentation, whitespace fixup, alignment, and
  6955. case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
  6956. buffer."
  6957. (interactive)
  6958. (vhdl-beautify-region (point-min) (point-max))
  6959. (when noninteractive (save-buffer)))
  6960. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6961. ;; Code filling
  6962. (defun vhdl-fill-region (beg end &optional arg)
  6963. "Fill lines for a region of code."
  6964. (interactive "r\np")
  6965. (save-excursion
  6966. (goto-char beg)
  6967. (let ((margin (if arg (current-indentation) (current-column))))
  6968. (goto-char end)
  6969. (setq end (point-marker))
  6970. ;; remove inline comments, newlines and whitespace
  6971. (vhdl-comment-kill-region beg end)
  6972. (vhdl-comment-kill-inline-region beg end)
  6973. (subst-char-in-region beg (1- end) ?\n ?\ )
  6974. (vhdl-fixup-whitespace-region beg end)
  6975. ;; wrap and end-comment-column
  6976. (goto-char beg)
  6977. (while (re-search-forward "\\s-" end t)
  6978. (when(> (current-column) vhdl-end-comment-column)
  6979. (backward-char)
  6980. (when (re-search-backward "\\s-" beg t)
  6981. (replace-match "\n")
  6982. (indent-to margin)))))))
  6983. (defun vhdl-fill-group ()
  6984. "Fill group of lines between empty lines."
  6985. (interactive)
  6986. (vhdl-do-group 'vhdl-fill-region))
  6987. (defun vhdl-fill-list ()
  6988. "Fill the lines of a list surrounded by a balanced group of parentheses."
  6989. (interactive)
  6990. (vhdl-do-list 'vhdl-fill-region))
  6991. (defun vhdl-fill-same-indent ()
  6992. "Fill the lines of block of lines with same indent."
  6993. (interactive)
  6994. (vhdl-do-same-indent 'vhdl-fill-region))
  6995. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6996. ;;; Code updating/fixing
  6997. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6998. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6999. ;; Sensitivity list update
  7000. ;; Strategy:
  7001. ;; - no sensitivity list is generated for processes with wait statements
  7002. ;; - otherwise, do the following:
  7003. ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
  7004. ;; 2. scan for all signals already in the sensitivity list (in order to catch
  7005. ;; manually entered global signals)
  7006. ;; 3. signals from 1. and 2. form the list of visible signals
  7007. ;; 4. search for if/elsif conditions containing an event (sequential code)
  7008. ;; 5. scan for strings that are within syntactical regions where signals are
  7009. ;; read but not within sequential code, and that correspond to visible
  7010. ;; signals
  7011. ;; 6. replace sensitivity list by list of signals from 5.
  7012. (defun vhdl-update-sensitivity-list-process ()
  7013. "Update sensitivity list of current process."
  7014. (interactive)
  7015. (save-excursion
  7016. (vhdl-prepare-search-2
  7017. (end-of-line)
  7018. ;; look whether in process
  7019. (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
  7020. (equal (upcase (match-string 2)) "PROCESS")
  7021. (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
  7022. (error "ERROR: Not within a process")
  7023. (message "Updating sensitivity list...")
  7024. (vhdl-update-sensitivity-list)
  7025. (message "Updating sensitivity list...done")))))
  7026. (defun vhdl-update-sensitivity-list-buffer ()
  7027. "Update sensitivity list of all processes in current buffer."
  7028. (interactive)
  7029. (save-excursion
  7030. (vhdl-prepare-search-2
  7031. (goto-char (point-min))
  7032. (message "Updating sensitivity lists...")
  7033. (while (re-search-forward "^\\s-*\\(\\w+[ \t\n]*:[ \t\n]*\\)?process\\>" nil t)
  7034. (goto-char (match-beginning 0))
  7035. (condition-case nil (vhdl-update-sensitivity-list) (error "")))
  7036. (message "Updating sensitivity lists...done"))))
  7037. (defun vhdl-update-sensitivity-list ()
  7038. "Update sensitivity list."
  7039. (let ((proc-beg (point))
  7040. (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
  7041. (proc-mid (re-search-backward "^\\s-*begin\\>" nil t))
  7042. seq-region-list)
  7043. (cond
  7044. ;; search for wait statement (no sensitivity list allowed)
  7045. ((progn (goto-char proc-mid)
  7046. (vhdl-re-search-forward "\\<wait\\>" proc-end t))
  7047. (error "ERROR: Process with wait statement, sensitivity list not generated"))
  7048. ;; combinational process (update sensitivity list)
  7049. (t
  7050. (let
  7051. ;; scan for visible signals
  7052. ((visible-list (vhdl-get-visible-signals))
  7053. ;; define syntactic regions where signals are read
  7054. (scan-regions-list
  7055. '(;; right-hand side of signal/variable assignment
  7056. ;; (special case: "<=" is relational operator in a condition)
  7057. ((re-search-forward "[<:]=" proc-end t)
  7058. (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
  7059. ;; if condition
  7060. ((re-search-forward "^\\s-*if\\>" proc-end t)
  7061. (re-search-forward "\\<then\\>" proc-end t))
  7062. ;; elsif condition
  7063. ((re-search-forward "\\<elsif\\>" proc-end t)
  7064. (re-search-forward "\\<then\\>" proc-end t))
  7065. ;; while loop condition
  7066. ((re-search-forward "^\\s-*while\\>" proc-end t)
  7067. (re-search-forward "\\<loop\\>" proc-end t))
  7068. ;; exit/next condition
  7069. ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
  7070. (re-search-forward ";" proc-end t))
  7071. ;; assert condition
  7072. ((re-search-forward "\\<assert\\>" proc-end t)
  7073. (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
  7074. ;; case expression
  7075. ((re-search-forward "^\\s-*case\\>" proc-end t)
  7076. (re-search-forward "\\<is\\>" proc-end t))
  7077. ;; parameter list of procedure call
  7078. ((and (re-search-forward "^\\s-*\\w+[ \t\n]*(" proc-end t)
  7079. (1- (point)))
  7080. (progn (backward-char) (forward-sexp)
  7081. (while (looking-at "(") (forward-sexp)) (point)))))
  7082. name read-list sens-list signal-list
  7083. sens-beg sens-end beg end margin)
  7084. ;; scan for signals in old sensitivity list
  7085. (goto-char proc-beg)
  7086. (re-search-forward "\\<process\\>" proc-mid t)
  7087. (if (not (looking-at "[ \t\n]*("))
  7088. (setq sens-beg (point))
  7089. (setq sens-beg (re-search-forward "\\([ \t\n]*\\)([ \t\n]*" nil t))
  7090. (goto-char (match-end 1))
  7091. (forward-sexp)
  7092. (setq sens-end (1- (point)))
  7093. (goto-char sens-beg)
  7094. (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
  7095. (setq sens-list
  7096. (cons (downcase (match-string 0)) sens-list))
  7097. (re-search-forward "\\s-*,\\s-*" sens-end t))))
  7098. (setq signal-list (append visible-list sens-list))
  7099. ;; search for sequential parts
  7100. (goto-char proc-mid)
  7101. (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
  7102. (setq end (re-search-forward "\\<then\\>" proc-end t))
  7103. (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
  7104. (goto-char end)
  7105. (backward-word 1)
  7106. (vhdl-forward-sexp)
  7107. (setq seq-region-list (cons (cons end (point)) seq-region-list))
  7108. (beginning-of-line)))
  7109. ;; scan for signals read in process
  7110. (while scan-regions-list
  7111. (goto-char proc-mid)
  7112. (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
  7113. (setq end (eval (nth 1 (car scan-regions-list)))))
  7114. (goto-char beg)
  7115. (unless (or (vhdl-in-literal)
  7116. (and seq-region-list
  7117. (let ((tmp-list seq-region-list))
  7118. (while (and tmp-list
  7119. (< (point) (caar tmp-list)))
  7120. (setq tmp-list (cdr tmp-list)))
  7121. (and tmp-list (< (point) (cdar tmp-list))))))
  7122. (while (vhdl-re-search-forward "[^'\"]\\<\\([a-zA-Z]\\w*\\)\\>[ \t\n]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
  7123. (setq name (match-string 1))
  7124. (when (and (not (match-string 4)) ; not when formal parameter
  7125. (not (and (match-string 3) ; not event attribute
  7126. (not (member (downcase (match-string 3))
  7127. '("event" "last_event" "transaction")))))
  7128. (member (downcase name) signal-list))
  7129. (unless (member-ignore-case name read-list)
  7130. (setq read-list (cons name read-list))))
  7131. (goto-char (match-end 1)))))
  7132. (setq scan-regions-list (cdr scan-regions-list)))
  7133. ;; update sensitivity list
  7134. (goto-char sens-beg)
  7135. (if sens-end
  7136. (delete-region sens-beg sens-end)
  7137. (when read-list
  7138. (insert " ()") (backward-char)))
  7139. (setq read-list (sort read-list 'string<))
  7140. (when read-list
  7141. (setq margin (current-column))
  7142. (insert (car read-list))
  7143. (setq read-list (cdr read-list))
  7144. (while read-list
  7145. (insert ",")
  7146. (if (<= (+ (current-column) (length (car read-list)) 2)
  7147. end-comment-column)
  7148. (insert " ")
  7149. (insert "\n") (indent-to margin))
  7150. (insert (car read-list))
  7151. (setq read-list (cdr read-list)))))))))
  7152. (defun vhdl-get-visible-signals ()
  7153. "Get all signals visible in the current block."
  7154. (let (beg end signal-list entity-name file-name)
  7155. (vhdl-prepare-search-2
  7156. ;; get entity name
  7157. (save-excursion
  7158. (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
  7159. (not (equal "END" (upcase (match-string 1))))
  7160. (setq entity-name (match-string 2)))
  7161. (error "ERROR: Not within an architecture")))
  7162. ;; search for signals declared in entity port clause
  7163. (save-excursion
  7164. (goto-char (point-min))
  7165. (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
  7166. (setq file-name
  7167. (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
  7168. "." (file-name-extension (buffer-file-name)))))
  7169. (vhdl-visit-file
  7170. file-name t
  7171. (vhdl-prepare-search-2
  7172. (goto-char (point-min))
  7173. (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
  7174. (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
  7175. (when (setq beg (re-search-forward
  7176. "^\\s-*port[ \t\n]*("
  7177. (save-excursion
  7178. (re-search-forward "^end\\>" nil t)) t))
  7179. (setq end (save-excursion
  7180. (backward-char) (forward-sexp) (point)))
  7181. (vhdl-forward-syntactic-ws)
  7182. (while (< (point) end)
  7183. (when (looking-at "signal[ \t\n]+")
  7184. (goto-char (match-end 0)))
  7185. (while (looking-at "\\(\\w+\\)[ \t\n,]+")
  7186. (setq signal-list
  7187. (cons (downcase (match-string 1)) signal-list))
  7188. (goto-char (match-end 0))
  7189. (vhdl-forward-syntactic-ws))
  7190. (re-search-forward ";" end 1)
  7191. (vhdl-forward-syntactic-ws)))))))
  7192. ;; search for signals declared in architecture declarative part
  7193. (save-excursion
  7194. (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
  7195. (not (equal "END" (upcase (match-string 1))))
  7196. (setq end (re-search-forward "^begin\\>" nil t))))
  7197. (error "ERROR: No architecture declarative part found")
  7198. ;; scan for all declared signal and alias names
  7199. (goto-char beg)
  7200. (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
  7201. (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
  7202. (if (match-string 2)
  7203. ;; scan signal name
  7204. (while (looking-at "[ \t\n,]+\\(\\w+\\)")
  7205. (setq signal-list
  7206. (cons (downcase (match-string 1)) signal-list))
  7207. (goto-char (match-end 0)))
  7208. ;; scan alias name, check is alias of (declared) signal
  7209. (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
  7210. (member (downcase (match-string 2)) signal-list))
  7211. (setq signal-list
  7212. (cons (downcase (match-string 1)) signal-list))
  7213. (goto-char (match-end 0))))
  7214. (setq beg (point))))))
  7215. ;; search for signals declared in surrounding block declarative parts
  7216. (save-excursion
  7217. (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
  7218. (match-string 2))
  7219. (goto-char (match-end 2))
  7220. (vhdl-backward-sexp)
  7221. (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
  7222. beg)
  7223. (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
  7224. ;; scan for all declared signal names
  7225. (goto-char beg)
  7226. (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
  7227. (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
  7228. (if (match-string 2)
  7229. ;; scan signal name
  7230. (while (looking-at "[ \t\n,]+\\(\\w+\\)")
  7231. (setq signal-list
  7232. (cons (downcase (match-string 1)) signal-list))
  7233. (goto-char (match-end 0)))
  7234. ;; scan alias name, check is alias of (declared) signal
  7235. (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
  7236. (member (downcase (match-string 2)) signal-list))
  7237. (setq signal-list
  7238. (cons (downcase (match-string 1)) signal-list))
  7239. (goto-char (match-end 0))))))
  7240. (goto-char beg)))
  7241. signal-list)))
  7242. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7243. ;; Generic/port clause fixing
  7244. (defun vhdl-fix-clause ()
  7245. "Fix closing parenthesis within generic/port clause."
  7246. (interactive)
  7247. (save-excursion
  7248. (vhdl-prepare-search-2
  7249. (let ((pos (point))
  7250. beg end)
  7251. (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n]*(" nil t))
  7252. (error "ERROR: Not within a generic/port clause")
  7253. ;; search for end of clause
  7254. (goto-char (match-end 0))
  7255. (setq beg (1- (point)))
  7256. (vhdl-forward-syntactic-ws)
  7257. (while (looking-at "\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*[ \t\n]*:[ \t\n]*\\w+[^;]*;")
  7258. (goto-char (1- (match-end 0)))
  7259. (setq end (point-marker))
  7260. (forward-char)
  7261. (vhdl-forward-syntactic-ws))
  7262. (goto-char end)
  7263. (when (> pos (point-at-eol))
  7264. (error "ERROR: Not within a generic/port clause"))
  7265. ;; delete closing parenthesis on separate line (not supported style)
  7266. (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
  7267. (vhdl-line-kill)
  7268. (vhdl-backward-syntactic-ws)
  7269. (setq end (point-marker))
  7270. (insert ";"))
  7271. ;; delete superfluous parentheses
  7272. (while (progn (goto-char beg)
  7273. (condition-case () (forward-sexp)
  7274. (error (goto-char (point-max))))
  7275. (< (point) end))
  7276. (delete-char -1))
  7277. ;; add closing parenthesis
  7278. (when (> (point) end)
  7279. (goto-char end)
  7280. (insert ")")))))))
  7281. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7282. ;; Miscellaneous
  7283. (defun vhdl-remove-trailing-spaces ()
  7284. "Remove trailing spaces in the whole buffer."
  7285. (interactive)
  7286. (save-match-data
  7287. (save-excursion
  7288. (goto-char (point-min))
  7289. (while (re-search-forward "[ \t]+$" (point-max) t)
  7290. (unless (vhdl-in-literal)
  7291. (replace-match "" nil nil))))))
  7292. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7293. ;;; Electrification
  7294. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7295. (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
  7296. "Syntax of prompt inserted by template generators.")
  7297. (defvar vhdl-template-invoked-by-hook nil
  7298. "Indicates whether a template has been invoked by a hook or by key or menu.
  7299. Used for undoing after template abortion.")
  7300. ;; correct different behavior of function `unread-command-events' in XEmacs
  7301. (defun vhdl-character-to-event (arg))
  7302. (defalias 'vhdl-character-to-event
  7303. (if (fboundp 'character-to-event) 'character-to-event 'identity))
  7304. (defun vhdl-work-library ()
  7305. "Return the working library name of the current project or \"work\" if no
  7306. project is defined."
  7307. (vhdl-resolve-env-variable
  7308. (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
  7309. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7310. ;; Enabling/disabling
  7311. (define-minor-mode vhdl-electric-mode
  7312. "Toggle VHDL electric mode.
  7313. With a prefix argument ARG, enable the mode if ARG is positive,
  7314. and disable it otherwise. If called from Lisp, enable it if ARG
  7315. is omitted or nil."
  7316. :global t)
  7317. (define-minor-mode vhdl-stutter-mode
  7318. "Toggle VHDL stuttering mode.
  7319. With a prefix argument ARG, enable the mode if ARG is positive,
  7320. and disable it otherwise. If called from Lisp, enable it if ARG
  7321. is omitted or nil."
  7322. :global t)
  7323. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7324. ;; Stuttering
  7325. (defun vhdl-electric-dash (count)
  7326. "-- starts a comment, --- draws a horizontal line,
  7327. ---- starts a display comment."
  7328. (interactive "p")
  7329. (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
  7330. (cond
  7331. ((and abbrev-start-location (= abbrev-start-location (point)))
  7332. (setq abbrev-start-location nil)
  7333. (goto-char last-abbrev-location)
  7334. (beginning-of-line nil)
  7335. (vhdl-comment-display))
  7336. ((/= (preceding-char) ?-) ; standard dash (minus)
  7337. (self-insert-command count))
  7338. (t (self-insert-command count)
  7339. (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
  7340. (let ((next-input (read-char)))
  7341. (if (= next-input ?-) ; triple dash
  7342. (progn
  7343. (vhdl-comment-display-line)
  7344. (message
  7345. "Enter '-' for display comment, else continue coding")
  7346. (let ((next-input (read-char)))
  7347. (if (= next-input ?-) ; four dashes
  7348. (vhdl-comment-display t)
  7349. (setq unread-command-events ; pushback the char
  7350. (list (vhdl-character-to-event next-input))))))
  7351. (setq unread-command-events ; pushback the char
  7352. (list (vhdl-character-to-event next-input)))
  7353. (vhdl-comment-insert)))))
  7354. (self-insert-command count)))
  7355. (defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
  7356. (interactive "p")
  7357. (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
  7358. (if (= (preceding-char) ?\()
  7359. (progn (delete-char -1) (insert-char ?\[ 1))
  7360. (insert-char ?\( 1))
  7361. (self-insert-command count)))
  7362. (defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
  7363. (interactive "p")
  7364. (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
  7365. (progn
  7366. (if (= (preceding-char) ?\))
  7367. (progn (delete-char -1) (insert-char ?\] 1))
  7368. (insert-char ?\) 1))
  7369. (blink-matching-open))
  7370. (self-insert-command count)))
  7371. (defun vhdl-electric-quote (count) "'' --> \""
  7372. (interactive "p")
  7373. (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
  7374. (if (= (preceding-char) last-input-event)
  7375. (progn (delete-char -1) (insert-char ?\" 1))
  7376. (insert-char ?\' 1))
  7377. (self-insert-command count)))
  7378. (defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
  7379. (interactive "p")
  7380. (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
  7381. (cond ((= (preceding-char) last-input-event)
  7382. (progn (delete-char -1)
  7383. (unless (eq (preceding-char) ? ) (insert " "))
  7384. (insert ": ")
  7385. (setq this-command 'vhdl-electric-colon)))
  7386. ((and
  7387. (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
  7388. (progn (delete-char -1) (insert "= ")))
  7389. (t (insert-char ?\; 1)))
  7390. (self-insert-command count)))
  7391. (defun vhdl-electric-comma (count) "',,' --> ' <= '"
  7392. (interactive "p")
  7393. (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
  7394. (cond ((= (preceding-char) last-input-event)
  7395. (progn (delete-char -1)
  7396. (unless (eq (preceding-char) ? ) (insert " "))
  7397. (insert "<= ")))
  7398. (t (insert-char ?\, 1)))
  7399. (self-insert-command count)))
  7400. (defun vhdl-electric-period (count) "'..' --> ' => '"
  7401. (interactive "p")
  7402. (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
  7403. (cond ((= (preceding-char) last-input-event)
  7404. (progn (delete-char -1)
  7405. (unless (eq (preceding-char) ? ) (insert " "))
  7406. (insert "=> ")))
  7407. (t (insert-char ?\. 1)))
  7408. (self-insert-command count)))
  7409. (defun vhdl-electric-equal (count) "'==' --> ' == '"
  7410. (interactive "p")
  7411. (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
  7412. (cond ((= (preceding-char) last-input-event)
  7413. (progn (delete-char -1)
  7414. (unless (eq (preceding-char) ? ) (insert " "))
  7415. (insert "== ")))
  7416. (t (insert-char ?\= 1)))
  7417. (self-insert-command count)))
  7418. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7419. ;; VHDL templates
  7420. (defun vhdl-template-paired-parens ()
  7421. "Insert a pair of round parentheses, placing point between them."
  7422. (interactive)
  7423. (insert "()")
  7424. (backward-char))
  7425. (defun vhdl-template-alias ()
  7426. "Insert alias declaration."
  7427. (interactive)
  7428. (let ((start (point)))
  7429. (vhdl-insert-keyword "ALIAS ")
  7430. (when (vhdl-template-field "name" nil t start (point))
  7431. (insert " : ")
  7432. (unless (vhdl-template-field
  7433. (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
  7434. nil t)
  7435. (delete-char -3))
  7436. (vhdl-insert-keyword " IS ")
  7437. (vhdl-template-field "name" ";")
  7438. (vhdl-comment-insert-inline))))
  7439. (defun vhdl-template-architecture ()
  7440. "Insert architecture."
  7441. (interactive)
  7442. (let ((margin (current-indentation))
  7443. (start (point))
  7444. arch-name)
  7445. (vhdl-insert-keyword "ARCHITECTURE ")
  7446. (when (setq arch-name
  7447. (vhdl-template-field "name" nil t start (point)))
  7448. (vhdl-insert-keyword " OF ")
  7449. (if (save-excursion
  7450. (vhdl-prepare-search-1
  7451. (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
  7452. (insert (match-string 1))
  7453. (vhdl-template-field "entity name"))
  7454. (vhdl-insert-keyword " IS\n")
  7455. (vhdl-template-begin-end
  7456. (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
  7457. (memq vhdl-insert-empty-lines '(unit all))))))
  7458. (defun vhdl-template-array (kind &optional secondary)
  7459. "Insert array type definition."
  7460. (interactive)
  7461. (let ((start (point)))
  7462. (vhdl-insert-keyword "ARRAY (")
  7463. (when (or (vhdl-template-field "range" nil (not secondary) start (point))
  7464. secondary)
  7465. (vhdl-insert-keyword ") OF ")
  7466. (vhdl-template-field (if (eq kind 'type) "type" "nature"))
  7467. (vhdl-insert-keyword ";"))))
  7468. (defun vhdl-template-assert ()
  7469. "Insert an assertion statement."
  7470. (interactive)
  7471. (let ((start (point)))
  7472. (vhdl-insert-keyword "ASSERT ")
  7473. (when vhdl-conditions-in-parenthesis (insert "("))
  7474. (when (vhdl-template-field "condition (negated)" nil t start (point))
  7475. (when vhdl-conditions-in-parenthesis (insert ")"))
  7476. (setq start (point))
  7477. (vhdl-insert-keyword " REPORT ")
  7478. (unless (vhdl-template-field "string expression" nil nil nil nil t)
  7479. (delete-region start (point)))
  7480. (setq start (point))
  7481. (vhdl-insert-keyword " SEVERITY ")
  7482. (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
  7483. (delete-region start (point)))
  7484. (insert ";"))))
  7485. (defun vhdl-template-attribute ()
  7486. "Insert an attribute declaration or specification."
  7487. (interactive)
  7488. (if (eq (vhdl-decision-query
  7489. "attribute" "(d)eclaration or (s)pecification?" t) ?s)
  7490. (vhdl-template-attribute-spec)
  7491. (vhdl-template-attribute-decl)))
  7492. (defun vhdl-template-attribute-decl ()
  7493. "Insert an attribute declaration."
  7494. (interactive)
  7495. (let ((start (point)))
  7496. (vhdl-insert-keyword "ATTRIBUTE ")
  7497. (when (vhdl-template-field "name" " : " t start (point))
  7498. (vhdl-template-field "type" ";")
  7499. (vhdl-comment-insert-inline))))
  7500. (defun vhdl-template-attribute-spec ()
  7501. "Insert an attribute specification."
  7502. (interactive)
  7503. (let ((start (point)))
  7504. (vhdl-insert-keyword "ATTRIBUTE ")
  7505. (when (vhdl-template-field "name" nil t start (point))
  7506. (vhdl-insert-keyword " OF ")
  7507. (vhdl-template-field "entity names | OTHERS | ALL" " : ")
  7508. (vhdl-template-field "entity class")
  7509. (vhdl-insert-keyword " IS ")
  7510. (vhdl-template-field "expression" ";"))))
  7511. (defun vhdl-template-block ()
  7512. "Insert a block."
  7513. (interactive)
  7514. (let ((margin (current-indentation))
  7515. (start (point))
  7516. label)
  7517. (vhdl-insert-keyword ": BLOCK ")
  7518. (goto-char start)
  7519. (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
  7520. (forward-word 1)
  7521. (forward-char 1)
  7522. (insert "(")
  7523. (if (vhdl-template-field "[guard expression]" nil t)
  7524. (insert ")")
  7525. (delete-char -2))
  7526. (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
  7527. (insert "\n")
  7528. (vhdl-template-begin-end "BLOCK" label margin)
  7529. (vhdl-comment-block))))
  7530. (defun vhdl-template-block-configuration ()
  7531. "Insert a block configuration statement."
  7532. (interactive)
  7533. (let ((margin (current-indentation))
  7534. (start (point)))
  7535. (vhdl-insert-keyword "FOR ")
  7536. (when (vhdl-template-field "block name" nil t start (point))
  7537. (vhdl-insert-keyword "\n\n")
  7538. (indent-to margin)
  7539. (vhdl-insert-keyword "END FOR;")
  7540. (end-of-line 0)
  7541. (indent-to (+ margin vhdl-basic-offset)))))
  7542. (defun vhdl-template-break ()
  7543. "Insert a break statement."
  7544. (interactive)
  7545. (let (position)
  7546. (vhdl-insert-keyword "BREAK")
  7547. (setq position (point))
  7548. (insert " ")
  7549. (while (or
  7550. (progn (vhdl-insert-keyword "FOR ")
  7551. (if (vhdl-template-field "[quantity name]" " USE " t)
  7552. (progn (vhdl-template-field "quantity name" " => ") t)
  7553. (delete-region (point)
  7554. (progn (forward-word -1) (point)))
  7555. nil))
  7556. (vhdl-template-field "[quantity name]" " => " t))
  7557. (vhdl-template-field "expression")
  7558. (setq position (point))
  7559. (insert ", "))
  7560. (delete-region position (point))
  7561. (unless (vhdl-sequential-statement-p)
  7562. (vhdl-insert-keyword " ON ")
  7563. (if (vhdl-template-field "[sensitivity list]" nil t)
  7564. (setq position (point))
  7565. (delete-region position (point))))
  7566. (vhdl-insert-keyword " WHEN ")
  7567. (when vhdl-conditions-in-parenthesis (insert "("))
  7568. (if (vhdl-template-field "[condition]" nil t)
  7569. (when vhdl-conditions-in-parenthesis (insert ")"))
  7570. (delete-region position (point)))
  7571. (insert ";")))
  7572. (defun vhdl-template-case (&optional kind)
  7573. "Insert a case statement."
  7574. (interactive)
  7575. (let ((margin (current-indentation))
  7576. (start (point))
  7577. label)
  7578. (unless kind (setq kind (if (vhdl-sequential-statement-p) 'is 'use)))
  7579. (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
  7580. (vhdl-insert-keyword "CASE ")
  7581. (vhdl-insert-keyword ": CASE ")
  7582. (goto-char start)
  7583. (setq label (vhdl-template-field "[label]" nil t))
  7584. (unless label (delete-char 2))
  7585. (forward-word 1)
  7586. (forward-char 1))
  7587. (when (vhdl-template-field "expression" nil t start (point))
  7588. (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
  7589. (indent-to margin)
  7590. (vhdl-insert-keyword "END CASE")
  7591. (when label (insert " " label))
  7592. (insert ";")
  7593. (forward-line -1)
  7594. (indent-to (+ margin vhdl-basic-offset))
  7595. (vhdl-insert-keyword "WHEN ")
  7596. (let ((position (point)))
  7597. (insert " => ;\n")
  7598. (indent-to (+ margin vhdl-basic-offset))
  7599. (vhdl-insert-keyword "WHEN OTHERS => null;")
  7600. (goto-char position)))))
  7601. (defun vhdl-template-case-is ()
  7602. "Insert a sequential case statement."
  7603. (interactive)
  7604. (vhdl-template-case 'is))
  7605. (defun vhdl-template-case-use ()
  7606. "Insert a simultaneous case statement."
  7607. (interactive)
  7608. (vhdl-template-case 'use))
  7609. (defun vhdl-template-component ()
  7610. "Insert a component declaration."
  7611. (interactive)
  7612. (vhdl-template-component-decl))
  7613. (defun vhdl-template-component-conf ()
  7614. "Insert a component configuration (uses `vhdl-template-configuration-spec'
  7615. since these are almost equivalent)."
  7616. (interactive)
  7617. (let ((margin (current-indentation))
  7618. (result (vhdl-template-configuration-spec t)))
  7619. (when result
  7620. (insert "\n")
  7621. (indent-to margin)
  7622. (vhdl-insert-keyword "END FOR;")
  7623. (when (eq result 'no-use)
  7624. (end-of-line -0)))))
  7625. (defun vhdl-template-component-decl ()
  7626. "Insert a component declaration."
  7627. (interactive)
  7628. (let ((margin (current-indentation))
  7629. (start (point))
  7630. name end-column)
  7631. (vhdl-insert-keyword "COMPONENT ")
  7632. (when (setq name (vhdl-template-field "name" nil t start (point)))
  7633. (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
  7634. (insert "\n\n")
  7635. (indent-to margin)
  7636. (vhdl-insert-keyword "END COMPONENT")
  7637. (unless (vhdl-standard-p '87) (insert " " name))
  7638. (insert ";")
  7639. (setq end-column (current-column))
  7640. (end-of-line -0)
  7641. (indent-to (+ margin vhdl-basic-offset))
  7642. (vhdl-template-generic-list t t)
  7643. (insert "\n")
  7644. (indent-to (+ margin vhdl-basic-offset))
  7645. (vhdl-template-port-list t)
  7646. (beginning-of-line 2)
  7647. (forward-char end-column))))
  7648. (defun vhdl-template-component-inst ()
  7649. "Insert a component instantiation statement."
  7650. (interactive)
  7651. (let ((margin (current-indentation))
  7652. (start (point))
  7653. unit position)
  7654. (when (vhdl-template-field "instance label" nil t start (point))
  7655. (insert ": ")
  7656. (if (not (vhdl-use-direct-instantiation))
  7657. (vhdl-template-field "component name")
  7658. ;; direct instantiation
  7659. (setq unit (vhdl-template-field
  7660. "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
  7661. (setq unit (upcase (or unit "")))
  7662. (cond ((equal unit "ENTITY")
  7663. (vhdl-template-field "library name" "." nil nil nil nil
  7664. (vhdl-work-library))
  7665. (vhdl-template-field "entity name" "(")
  7666. (if (vhdl-template-field "[architecture name]" nil t)
  7667. (insert ")")
  7668. (delete-char -1)))
  7669. ((equal unit "CONFIGURATION")
  7670. (vhdl-template-field "library name" "." nil nil nil nil
  7671. (vhdl-work-library))
  7672. (vhdl-template-field "configuration name"))
  7673. (t (vhdl-template-field "component name"))))
  7674. (insert "\n")
  7675. (indent-to (+ margin vhdl-basic-offset))
  7676. (setq position (point))
  7677. (vhdl-insert-keyword "GENERIC ")
  7678. (when (vhdl-template-map position t t)
  7679. (insert "\n")
  7680. (indent-to (+ margin vhdl-basic-offset)))
  7681. (setq position (point))
  7682. (vhdl-insert-keyword "PORT ")
  7683. (unless (vhdl-template-map position t t)
  7684. (delete-region (line-beginning-position) (point))
  7685. (delete-char -1))
  7686. (insert ";"))))
  7687. (defun vhdl-template-conditional-signal-asst ()
  7688. "Insert a conditional signal assignment."
  7689. (interactive)
  7690. (when (vhdl-template-field "target signal")
  7691. (insert " <= ")
  7692. ; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
  7693. ; (insert " "))
  7694. (let ((margin (current-column))
  7695. (start (point))
  7696. position)
  7697. (vhdl-template-field "waveform")
  7698. (setq position (point))
  7699. (vhdl-insert-keyword " WHEN ")
  7700. (when vhdl-conditions-in-parenthesis (insert "("))
  7701. (while (and (vhdl-template-field "[condition]" nil t)
  7702. (progn
  7703. (when vhdl-conditions-in-parenthesis (insert ")"))
  7704. (setq position (point))
  7705. (vhdl-insert-keyword " ELSE")
  7706. (insert "\n")
  7707. (indent-to margin)
  7708. (vhdl-template-field "[waveform]" nil t)))
  7709. (setq position (point))
  7710. (vhdl-insert-keyword " WHEN ")
  7711. (when vhdl-conditions-in-parenthesis (insert "(")))
  7712. (delete-region position (point))
  7713. (insert ";")
  7714. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
  7715. (defun vhdl-template-configuration ()
  7716. "Insert a configuration specification if within an architecture,
  7717. a block or component configuration if within a configuration declaration,
  7718. a configuration declaration if not within a design unit."
  7719. (interactive)
  7720. (vhdl-prepare-search-1
  7721. (cond
  7722. ((and (save-excursion ; architecture body
  7723. (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
  7724. (equal "ARCHITECTURE" (upcase (match-string 1))))
  7725. (vhdl-template-configuration-spec))
  7726. ((and (save-excursion ; configuration declaration
  7727. (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
  7728. (equal "CONFIGURATION" (upcase (match-string 1))))
  7729. (if (eq (vhdl-decision-query
  7730. "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
  7731. (vhdl-template-component-conf)
  7732. (vhdl-template-block-configuration)))
  7733. (t (vhdl-template-configuration-decl))))) ; otherwise
  7734. (defun vhdl-template-configuration-spec (&optional optional-use)
  7735. "Insert a configuration specification."
  7736. (interactive)
  7737. (let ((margin (current-indentation))
  7738. (start (point))
  7739. aspect position)
  7740. (vhdl-insert-keyword "FOR ")
  7741. (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
  7742. t start (point))
  7743. (vhdl-template-field "component name" "\n")
  7744. (indent-to (+ margin vhdl-basic-offset))
  7745. (setq start (point))
  7746. (vhdl-insert-keyword "USE ")
  7747. (if (and optional-use
  7748. (not (setq aspect (vhdl-template-field
  7749. "[ENTITY | CONFIGURATION | OPEN]" " " t))))
  7750. (progn (delete-region start (point)) 'no-use)
  7751. (unless optional-use
  7752. (setq aspect (vhdl-template-field
  7753. "ENTITY | CONFIGURATION | OPEN" " ")))
  7754. (setq aspect (upcase (or aspect "")))
  7755. (cond ((equal aspect "ENTITY")
  7756. (vhdl-template-field "library name" "." nil nil nil nil
  7757. (vhdl-work-library))
  7758. (vhdl-template-field "entity name" "(")
  7759. (if (vhdl-template-field "[architecture name]" nil t)
  7760. (insert ")")
  7761. (delete-char -1))
  7762. (insert "\n")
  7763. (indent-to (+ margin (* 2 vhdl-basic-offset)))
  7764. (setq position (point))
  7765. (vhdl-insert-keyword "GENERIC ")
  7766. (when (vhdl-template-map position t t)
  7767. (insert "\n")
  7768. (indent-to (+ margin (* 2 vhdl-basic-offset))))
  7769. (setq position (point))
  7770. (vhdl-insert-keyword "PORT ")
  7771. (unless (vhdl-template-map position t t)
  7772. (delete-region (line-beginning-position) (point))
  7773. (delete-char -1))
  7774. (insert ";")
  7775. t)
  7776. ((equal aspect "CONFIGURATION")
  7777. (vhdl-template-field "library name" "." nil nil nil nil
  7778. (vhdl-work-library))
  7779. (vhdl-template-field "configuration name" ";"))
  7780. (t (delete-char -1) (insert ";") t))))))
  7781. (defun vhdl-template-configuration-decl ()
  7782. "Insert a configuration declaration."
  7783. (interactive)
  7784. (let ((margin (current-indentation))
  7785. (start (point))
  7786. entity-exists string name position)
  7787. (vhdl-insert-keyword "CONFIGURATION ")
  7788. (when (setq name (vhdl-template-field "name" nil t start (point)))
  7789. (vhdl-insert-keyword " OF ")
  7790. (save-excursion
  7791. (vhdl-prepare-search-1
  7792. (setq entity-exists (vhdl-re-search-backward
  7793. "\\<entity \\(\\w*\\) is\\>" nil t))
  7794. (setq string (match-string 1))))
  7795. (if (and entity-exists (not (equal string "")))
  7796. (insert string)
  7797. (vhdl-template-field "entity name"))
  7798. (vhdl-insert-keyword " IS\n")
  7799. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  7800. (indent-to (+ margin vhdl-basic-offset))
  7801. (setq position (point))
  7802. (insert "\n")
  7803. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  7804. (indent-to margin)
  7805. (vhdl-insert-keyword "END ")
  7806. (unless (vhdl-standard-p '87)
  7807. (vhdl-insert-keyword "CONFIGURATION "))
  7808. (insert name ";")
  7809. (goto-char position))))
  7810. (defun vhdl-template-constant ()
  7811. "Insert a constant declaration."
  7812. (interactive)
  7813. (let ((start (point))
  7814. (in-arglist (vhdl-in-argument-list-p)))
  7815. (vhdl-insert-keyword "CONSTANT ")
  7816. (when (vhdl-template-field "name" nil t start (point))
  7817. (insert " : ")
  7818. (when in-arglist (vhdl-insert-keyword "IN "))
  7819. (vhdl-template-field "type")
  7820. (if in-arglist
  7821. (progn (insert ";")
  7822. (vhdl-comment-insert-inline))
  7823. (let ((position (point)))
  7824. (insert " := ")
  7825. (unless (vhdl-template-field "[initialization]" nil t)
  7826. (delete-region position (point)))
  7827. (insert ";")
  7828. (vhdl-comment-insert-inline))))))
  7829. (defun vhdl-template-default ()
  7830. "Insert nothing."
  7831. (interactive)
  7832. (insert " ")
  7833. (unexpand-abbrev)
  7834. (backward-word 1)
  7835. (vhdl-case-word 1)
  7836. (forward-char 1))
  7837. (defun vhdl-template-default-indent ()
  7838. "Insert nothing and indent."
  7839. (interactive)
  7840. (insert " ")
  7841. (unexpand-abbrev)
  7842. (backward-word 1)
  7843. (vhdl-case-word 1)
  7844. (forward-char 1)
  7845. (indent-according-to-mode))
  7846. (defun vhdl-template-disconnect ()
  7847. "Insert a disconnect statement."
  7848. (interactive)
  7849. (let ((start (point)))
  7850. (vhdl-insert-keyword "DISCONNECT ")
  7851. (when (vhdl-template-field "signal names | OTHERS | ALL"
  7852. " : " t start (point))
  7853. (vhdl-template-field "type")
  7854. (vhdl-insert-keyword " AFTER ")
  7855. (vhdl-template-field "time expression" ";"))))
  7856. (defun vhdl-template-else ()
  7857. "Insert an else statement."
  7858. (interactive)
  7859. (let (margin)
  7860. (vhdl-prepare-search-1
  7861. (vhdl-insert-keyword "ELSE")
  7862. (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
  7863. (equal "WHEN" (upcase (match-string 1))))
  7864. (insert " ")
  7865. (indent-according-to-mode)
  7866. (setq margin (current-indentation))
  7867. (insert "\n")
  7868. (indent-to (+ margin vhdl-basic-offset))))))
  7869. (defun vhdl-template-elsif ()
  7870. "Insert an elsif statement."
  7871. (interactive)
  7872. (let ((start (point))
  7873. margin)
  7874. (vhdl-insert-keyword "ELSIF ")
  7875. (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
  7876. (when vhdl-conditions-in-parenthesis (insert "("))
  7877. (when (vhdl-template-field "condition" nil t start (point))
  7878. (when vhdl-conditions-in-parenthesis (insert ")"))
  7879. (indent-according-to-mode)
  7880. (setq margin (current-indentation))
  7881. (vhdl-insert-keyword
  7882. (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
  7883. (indent-to (+ margin vhdl-basic-offset))))))
  7884. (defun vhdl-template-entity ()
  7885. "Insert an entity."
  7886. (interactive)
  7887. (let ((margin (current-indentation))
  7888. (start (point))
  7889. name end-column)
  7890. (vhdl-insert-keyword "ENTITY ")
  7891. (when (setq name (vhdl-template-field "name" nil t start (point)))
  7892. (vhdl-insert-keyword " IS\n\n")
  7893. (indent-to margin)
  7894. (vhdl-insert-keyword "END ")
  7895. (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
  7896. (insert name ";")
  7897. (setq end-column (current-column))
  7898. (end-of-line -0)
  7899. (indent-to (+ margin vhdl-basic-offset))
  7900. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  7901. (indent-to (+ margin vhdl-basic-offset))
  7902. (when (vhdl-template-generic-list t)
  7903. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
  7904. (insert "\n")
  7905. (indent-to (+ margin vhdl-basic-offset))
  7906. (when (vhdl-template-port-list t)
  7907. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
  7908. (beginning-of-line 2)
  7909. (forward-char end-column))))
  7910. (defun vhdl-template-exit ()
  7911. "Insert an exit statement."
  7912. (interactive)
  7913. (let ((start (point)))
  7914. (vhdl-insert-keyword "EXIT ")
  7915. (if (vhdl-template-field "[loop label]" nil t start (point))
  7916. (let ((position (point)))
  7917. (vhdl-insert-keyword " WHEN ")
  7918. (when vhdl-conditions-in-parenthesis (insert "("))
  7919. (if (vhdl-template-field "[condition]" nil t)
  7920. (when vhdl-conditions-in-parenthesis (insert ")"))
  7921. (delete-region position (point))))
  7922. (delete-char -1))
  7923. (insert ";")))
  7924. (defun vhdl-template-file ()
  7925. "Insert a file declaration."
  7926. (interactive)
  7927. (let ((start (point)))
  7928. (vhdl-insert-keyword "FILE ")
  7929. (when (vhdl-template-field "name" nil t start (point))
  7930. (insert " : ")
  7931. (vhdl-template-field "type")
  7932. (unless (vhdl-standard-p '87)
  7933. (vhdl-insert-keyword " OPEN ")
  7934. (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
  7935. nil t)
  7936. (delete-char -6)))
  7937. (vhdl-insert-keyword " IS ")
  7938. (when (vhdl-standard-p '87)
  7939. (vhdl-template-field "[IN | OUT]" " " t))
  7940. (vhdl-template-field "filename-string" nil nil nil nil t)
  7941. (insert ";")
  7942. (vhdl-comment-insert-inline))))
  7943. (defun vhdl-template-for ()
  7944. "Insert a block or component configuration if within a configuration
  7945. declaration, a configuration specification if within an architecture
  7946. declarative part (and not within a subprogram), a for-loop if within a
  7947. sequential statement part (subprogram or process), and a for-generate
  7948. otherwise."
  7949. (interactive)
  7950. (vhdl-prepare-search-1
  7951. (cond
  7952. ((vhdl-sequential-statement-p) ; sequential statement
  7953. (vhdl-template-for-loop))
  7954. ((and (save-excursion ; configuration declaration
  7955. (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
  7956. (equal "CONFIGURATION" (upcase (match-string 1))))
  7957. (if (eq (vhdl-decision-query
  7958. "for" "(b)lock or (c)omponent configuration?" t) ?c)
  7959. (vhdl-template-component-conf)
  7960. (vhdl-template-block-configuration)))
  7961. ((and (save-excursion
  7962. (re-search-backward ; architecture declarative part
  7963. "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
  7964. (equal "ARCHITECTURE" (upcase (match-string 1))))
  7965. (vhdl-template-configuration-spec))
  7966. (t (vhdl-template-for-generate))))) ; concurrent statement
  7967. (defun vhdl-template-for-generate ()
  7968. "Insert a for-generate."
  7969. (interactive)
  7970. (let ((margin (current-indentation))
  7971. (start (point))
  7972. label position)
  7973. (vhdl-insert-keyword ": FOR ")
  7974. (setq position (point-marker))
  7975. (goto-char start)
  7976. (when (setq label (vhdl-template-field "label" nil t start position))
  7977. (goto-char position)
  7978. (vhdl-template-field "loop variable")
  7979. (vhdl-insert-keyword " IN ")
  7980. (vhdl-template-field "range")
  7981. (vhdl-template-generate-body margin label))))
  7982. (defun vhdl-template-for-loop ()
  7983. "Insert a for loop."
  7984. (interactive)
  7985. (let ((margin (current-indentation))
  7986. (start (point))
  7987. label index)
  7988. (if (not (eq vhdl-optional-labels 'all))
  7989. (vhdl-insert-keyword "FOR ")
  7990. (vhdl-insert-keyword ": FOR ")
  7991. (goto-char start)
  7992. (setq label (vhdl-template-field "[label]" nil t))
  7993. (unless label (delete-char 2))
  7994. (forward-word 1)
  7995. (forward-char 1))
  7996. (when (setq index (vhdl-template-field "loop variable"
  7997. nil t start (point)))
  7998. (vhdl-insert-keyword " IN ")
  7999. (vhdl-template-field "range")
  8000. (vhdl-insert-keyword " LOOP\n\n")
  8001. (indent-to margin)
  8002. (vhdl-insert-keyword "END LOOP")
  8003. (if label
  8004. (insert " " label ";")
  8005. (insert ";")
  8006. (when vhdl-self-insert-comments (insert " -- " index)))
  8007. (forward-line -1)
  8008. (indent-to (+ margin vhdl-basic-offset)))))
  8009. (defun vhdl-template-function (&optional kind)
  8010. "Insert a function declaration or body."
  8011. (interactive)
  8012. (let ((margin (current-indentation))
  8013. (start (point))
  8014. name)
  8015. (vhdl-insert-keyword "FUNCTION ")
  8016. (when (setq name (vhdl-template-field "name" nil t start (point)))
  8017. (vhdl-template-argument-list t)
  8018. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
  8019. (end-of-line)
  8020. (insert "\n")
  8021. (indent-to (+ margin vhdl-basic-offset))
  8022. (vhdl-insert-keyword "RETURN ")
  8023. (vhdl-template-field "type")
  8024. (if (if kind (eq kind 'body)
  8025. (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
  8026. (progn (vhdl-insert-keyword " IS\n")
  8027. (vhdl-template-begin-end
  8028. (unless (vhdl-standard-p '87) "FUNCTION") name margin)
  8029. (vhdl-comment-block))
  8030. (insert ";")))))
  8031. (defun vhdl-template-function-decl ()
  8032. "Insert a function declaration."
  8033. (interactive)
  8034. (vhdl-template-function 'decl))
  8035. (defun vhdl-template-function-body ()
  8036. "Insert a function declaration."
  8037. (interactive)
  8038. (vhdl-template-function 'body))
  8039. (defun vhdl-template-generate ()
  8040. "Insert a generation scheme."
  8041. (interactive)
  8042. (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
  8043. (vhdl-template-if-generate)
  8044. (vhdl-template-for-generate)))
  8045. (defun vhdl-template-generic ()
  8046. "Insert generic declaration, or generic map in instantiation statements."
  8047. (interactive)
  8048. (let ((start (point)))
  8049. (vhdl-prepare-search-1
  8050. (cond
  8051. ((and (save-excursion ; entity declaration
  8052. (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
  8053. (equal "ENTITY" (upcase (match-string 1))))
  8054. (vhdl-template-generic-list nil))
  8055. ((or (save-excursion
  8056. (or (beginning-of-line)
  8057. (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
  8058. (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
  8059. (vhdl-insert-keyword "GENERIC ")
  8060. (vhdl-template-map start))
  8061. (t (vhdl-template-generic-list nil t))))))
  8062. (defun vhdl-template-group ()
  8063. "Insert group or group template declaration."
  8064. (interactive)
  8065. (let ((start (point)))
  8066. (if (eq (vhdl-decision-query
  8067. "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
  8068. (vhdl-template-group-template)
  8069. (vhdl-template-group-decl))))
  8070. (defun vhdl-template-group-decl ()
  8071. "Insert group declaration."
  8072. (interactive)
  8073. (let ((start (point)))
  8074. (vhdl-insert-keyword "GROUP ")
  8075. (when (vhdl-template-field "name" " : " t start (point))
  8076. (vhdl-template-field "template name" " (")
  8077. (vhdl-template-field "constituent list" ");")
  8078. (vhdl-comment-insert-inline))))
  8079. (defun vhdl-template-group-template ()
  8080. "Insert group template declaration."
  8081. (interactive)
  8082. (let ((start (point)))
  8083. (vhdl-insert-keyword "GROUP ")
  8084. (when (vhdl-template-field "template name" nil t start (point))
  8085. (vhdl-insert-keyword " IS (")
  8086. (vhdl-template-field "entity class list" ");")
  8087. (vhdl-comment-insert-inline))))
  8088. (defun vhdl-template-if ()
  8089. "Insert a sequential if statement or an if-generate statement."
  8090. (interactive)
  8091. (if (vhdl-sequential-statement-p)
  8092. (vhdl-template-if-then)
  8093. (if (and (vhdl-standard-p 'ams)
  8094. (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
  8095. (vhdl-template-if-use)
  8096. (vhdl-template-if-generate))))
  8097. (defun vhdl-template-if-generate ()
  8098. "Insert an if-generate."
  8099. (interactive)
  8100. (let ((margin (current-indentation))
  8101. (start (point))
  8102. label position)
  8103. (vhdl-insert-keyword ": IF ")
  8104. (setq position (point-marker))
  8105. (goto-char start)
  8106. (when (setq label (vhdl-template-field "label" nil t start position))
  8107. (goto-char position)
  8108. (when vhdl-conditions-in-parenthesis (insert "("))
  8109. (vhdl-template-field "condition")
  8110. (when vhdl-conditions-in-parenthesis (insert ")"))
  8111. (vhdl-template-generate-body margin label))))
  8112. (defun vhdl-template-if-then-use (kind)
  8113. "Insert a sequential if statement."
  8114. (interactive)
  8115. (let ((margin (current-indentation))
  8116. (start (point))
  8117. label)
  8118. (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
  8119. (vhdl-insert-keyword "IF ")
  8120. (vhdl-insert-keyword ": IF ")
  8121. (goto-char start)
  8122. (setq label (vhdl-template-field "[label]" nil t))
  8123. (unless label (delete-char 2))
  8124. (forward-word 1)
  8125. (forward-char 1))
  8126. (when vhdl-conditions-in-parenthesis (insert "("))
  8127. (when (vhdl-template-field "condition" nil t start (point))
  8128. (when vhdl-conditions-in-parenthesis (insert ")"))
  8129. (vhdl-insert-keyword
  8130. (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
  8131. (indent-to margin)
  8132. (vhdl-insert-keyword "END IF")
  8133. (when label (insert " " label))
  8134. (insert ";")
  8135. (forward-line -1)
  8136. (indent-to (+ margin vhdl-basic-offset)))))
  8137. (defun vhdl-template-if-then ()
  8138. "Insert a sequential if statement."
  8139. (interactive)
  8140. (vhdl-template-if-then-use 'then))
  8141. (defun vhdl-template-if-use ()
  8142. "Insert a simultaneous if statement."
  8143. (interactive)
  8144. (vhdl-template-if-then-use 'use))
  8145. (defun vhdl-template-instance ()
  8146. "Insert a component instantiation statement."
  8147. (interactive)
  8148. (vhdl-template-component-inst))
  8149. (defun vhdl-template-library ()
  8150. "Insert a library specification."
  8151. (interactive)
  8152. (let ((margin (current-indentation))
  8153. (start (point))
  8154. name end-pos)
  8155. (vhdl-insert-keyword "LIBRARY ")
  8156. (when (setq name (vhdl-template-field "names" nil t start (point)))
  8157. (insert ";")
  8158. (unless (string-match "," name)
  8159. (setq end-pos (point))
  8160. (insert "\n")
  8161. (indent-to margin)
  8162. (vhdl-insert-keyword "USE ")
  8163. (insert name)
  8164. (vhdl-insert-keyword "..ALL;")
  8165. (backward-char 5)
  8166. (if (vhdl-template-field "package name")
  8167. (forward-char 5)
  8168. (delete-region end-pos (+ (point) 5)))))))
  8169. (defun vhdl-template-limit ()
  8170. "Insert a limit."
  8171. (interactive)
  8172. (let ((start (point)))
  8173. (vhdl-insert-keyword "LIMIT ")
  8174. (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
  8175. t start (point))
  8176. (vhdl-template-field "type")
  8177. (vhdl-insert-keyword " WITH ")
  8178. (vhdl-template-field "real expression" ";"))))
  8179. (defun vhdl-template-loop ()
  8180. "Insert a loop."
  8181. (interactive)
  8182. (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
  8183. (cond ((eq char ?w)
  8184. (vhdl-template-while-loop))
  8185. ((eq char ?f)
  8186. (vhdl-template-for-loop))
  8187. (t (vhdl-template-bare-loop)))))
  8188. (defun vhdl-template-bare-loop ()
  8189. "Insert a loop."
  8190. (interactive)
  8191. (let ((margin (current-indentation))
  8192. (start (point))
  8193. label)
  8194. (if (not (eq vhdl-optional-labels 'all))
  8195. (vhdl-insert-keyword "LOOP ")
  8196. (vhdl-insert-keyword ": LOOP ")
  8197. (goto-char start)
  8198. (setq label (vhdl-template-field "[label]" nil t))
  8199. (unless label (delete-char 2))
  8200. (forward-word 1)
  8201. (delete-char 1))
  8202. (insert "\n\n")
  8203. (indent-to margin)
  8204. (vhdl-insert-keyword "END LOOP")
  8205. (insert (if label (concat " " label ";") ";"))
  8206. (forward-line -1)
  8207. (indent-to (+ margin vhdl-basic-offset))))
  8208. (defun vhdl-template-map (&optional start optional secondary)
  8209. "Insert a map specification with association list."
  8210. (interactive)
  8211. (let ((start (or start (point)))
  8212. margin end-pos)
  8213. (vhdl-insert-keyword "MAP (")
  8214. (if (not vhdl-association-list-with-formals)
  8215. (if (vhdl-template-field
  8216. (concat (and optional "[") "association list" (and optional "]"))
  8217. ")" (or (not secondary) optional)
  8218. (and (not secondary) start) (point))
  8219. t
  8220. (if (and optional secondary) (delete-region start (point)))
  8221. nil)
  8222. (if vhdl-argument-list-indent
  8223. (setq margin (current-column))
  8224. (setq margin (+ (current-indentation) vhdl-basic-offset))
  8225. (insert "\n")
  8226. (indent-to margin))
  8227. (if (vhdl-template-field
  8228. (concat (and optional "[") "formal" (and optional "]"))
  8229. " => " (or (not secondary) optional)
  8230. (and (not secondary) start) (point))
  8231. (progn
  8232. (vhdl-template-field "actual" ",")
  8233. (setq end-pos (point))
  8234. (insert "\n")
  8235. (indent-to margin)
  8236. (while (vhdl-template-field "[formal]" " => " t)
  8237. (vhdl-template-field "actual" ",")
  8238. (setq end-pos (point))
  8239. (insert "\n")
  8240. (indent-to margin))
  8241. (delete-region end-pos (point))
  8242. (delete-char -1)
  8243. (insert ")")
  8244. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
  8245. t)
  8246. (when (and optional secondary) (delete-region start (point)))
  8247. nil))))
  8248. (defun vhdl-template-modify (&optional noerror)
  8249. "Actualize modification date."
  8250. (interactive)
  8251. (vhdl-prepare-search-2
  8252. (save-excursion
  8253. (goto-char (point-min))
  8254. (if (re-search-forward vhdl-modify-date-prefix-string nil t)
  8255. (progn (delete-region (point) (progn (end-of-line) (point)))
  8256. (vhdl-template-insert-date))
  8257. (unless noerror
  8258. (error "ERROR: Modification date prefix string \"%s\" not found"
  8259. vhdl-modify-date-prefix-string))))))
  8260. (defun vhdl-template-modify-noerror ()
  8261. "Call `vhdl-template-modify' with NOERROR non-nil."
  8262. (vhdl-template-modify t))
  8263. (defun vhdl-template-nature ()
  8264. "Insert a nature declaration."
  8265. (interactive)
  8266. (let ((start (point))
  8267. name mid-pos end-pos)
  8268. (vhdl-insert-keyword "NATURE ")
  8269. (when (setq name (vhdl-template-field "name" nil t start (point)))
  8270. (vhdl-insert-keyword " IS ")
  8271. (let ((definition
  8272. (upcase
  8273. (or (vhdl-template-field
  8274. "across type | ARRAY | RECORD")
  8275. ""))))
  8276. (cond ((equal definition "")
  8277. (insert ";"))
  8278. ((equal definition "ARRAY")
  8279. (delete-region (point) (progn (forward-word -1) (point)))
  8280. (vhdl-template-array 'nature t))
  8281. ((equal definition "RECORD")
  8282. (setq mid-pos (point-marker))
  8283. (delete-region (point) (progn (forward-word -1) (point)))
  8284. (vhdl-template-record 'nature name t))
  8285. (t
  8286. (vhdl-insert-keyword " ACROSS ")
  8287. (vhdl-template-field "through type")
  8288. (vhdl-insert-keyword " THROUGH ")
  8289. (vhdl-template-field "reference name")
  8290. (vhdl-insert-keyword " REFERENCE;")))
  8291. (when mid-pos
  8292. (setq end-pos (point-marker))
  8293. (goto-char mid-pos)
  8294. (end-of-line))
  8295. (vhdl-comment-insert-inline)
  8296. (when end-pos (goto-char end-pos))))))
  8297. (defun vhdl-template-next ()
  8298. "Insert a next statement."
  8299. (interactive)
  8300. (let ((start (point)))
  8301. (vhdl-insert-keyword "NEXT ")
  8302. (if (vhdl-template-field "[loop label]" nil t start (point))
  8303. (let ((position (point)))
  8304. (vhdl-insert-keyword " WHEN ")
  8305. (when vhdl-conditions-in-parenthesis (insert "("))
  8306. (if (vhdl-template-field "[condition]" nil t)
  8307. (when vhdl-conditions-in-parenthesis (insert ")"))
  8308. (delete-region position (point))))
  8309. (delete-char -1))
  8310. (insert ";")))
  8311. (defun vhdl-template-others ()
  8312. "Insert an others aggregate."
  8313. (interactive)
  8314. (let ((start (point)))
  8315. (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
  8316. (progn (unless vhdl-template-invoked-by-hook (insert "("))
  8317. (vhdl-insert-keyword "OTHERS => '")
  8318. (when (vhdl-template-field "value" nil t start (point))
  8319. (insert "')")))
  8320. (vhdl-insert-keyword "OTHERS "))))
  8321. (defun vhdl-template-package (&optional kind)
  8322. "Insert a package specification or body."
  8323. (interactive)
  8324. (let ((margin (current-indentation))
  8325. (start (point))
  8326. name body position)
  8327. (vhdl-insert-keyword "PACKAGE ")
  8328. (setq body (if kind (eq kind 'body)
  8329. (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
  8330. (when body
  8331. (vhdl-insert-keyword "BODY ")
  8332. (when (save-excursion
  8333. (vhdl-prepare-search-1
  8334. (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
  8335. (insert (setq name (match-string 1)))))
  8336. (when (or name
  8337. (setq name (vhdl-template-field "name" nil t start (point))))
  8338. (vhdl-insert-keyword " IS\n")
  8339. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  8340. (indent-to (+ margin vhdl-basic-offset))
  8341. (setq position (point))
  8342. (insert "\n")
  8343. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  8344. (indent-to margin)
  8345. (vhdl-insert-keyword "END ")
  8346. (unless (vhdl-standard-p '87)
  8347. (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
  8348. (insert (or name "") ";")
  8349. (goto-char position))))
  8350. (defun vhdl-template-package-decl ()
  8351. "Insert a package specification."
  8352. (interactive)
  8353. (vhdl-template-package 'decl))
  8354. (defun vhdl-template-package-body ()
  8355. "Insert a package body."
  8356. (interactive)
  8357. (vhdl-template-package 'body))
  8358. (defun vhdl-template-port ()
  8359. "Insert a port declaration, or port map in instantiation statements."
  8360. (interactive)
  8361. (let ((start (point)))
  8362. (vhdl-prepare-search-1
  8363. (cond
  8364. ((and (save-excursion ; entity declaration
  8365. (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
  8366. (equal "ENTITY" (upcase (match-string 1))))
  8367. (vhdl-template-port-list nil))
  8368. ((or (save-excursion
  8369. (or (beginning-of-line)
  8370. (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
  8371. (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
  8372. (vhdl-insert-keyword "PORT ")
  8373. (vhdl-template-map start))
  8374. (t (vhdl-template-port-list nil))))))
  8375. (defun vhdl-template-procedural ()
  8376. "Insert a procedural."
  8377. (interactive)
  8378. (let ((margin (current-indentation))
  8379. (start (point))
  8380. (case-fold-search t)
  8381. label)
  8382. (vhdl-insert-keyword "PROCEDURAL ")
  8383. (when (memq vhdl-optional-labels '(process all))
  8384. (goto-char start)
  8385. (insert ": ")
  8386. (goto-char start)
  8387. (setq label (vhdl-template-field "[label]" nil t))
  8388. (unless label (delete-char 2))
  8389. (forward-word 1)
  8390. (forward-char 1))
  8391. (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
  8392. (insert "\n")
  8393. (vhdl-template-begin-end "PROCEDURAL" label margin)
  8394. (vhdl-comment-block)))
  8395. (defun vhdl-template-procedure (&optional kind)
  8396. "Insert a procedure declaration or body."
  8397. (interactive)
  8398. (let ((margin (current-indentation))
  8399. (start (point))
  8400. name)
  8401. (vhdl-insert-keyword "PROCEDURE ")
  8402. (when (setq name (vhdl-template-field "name" nil t start (point)))
  8403. (vhdl-template-argument-list)
  8404. (if (if kind (eq kind 'body)
  8405. (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
  8406. (progn (vhdl-insert-keyword " IS")
  8407. (when vhdl-auto-align
  8408. (vhdl-align-region-groups start (point) 1))
  8409. (end-of-line) (insert "\n")
  8410. (vhdl-template-begin-end
  8411. (unless (vhdl-standard-p '87) "PROCEDURE")
  8412. name margin)
  8413. (vhdl-comment-block))
  8414. (insert ";")
  8415. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
  8416. (end-of-line)))))
  8417. (defun vhdl-template-procedure-decl ()
  8418. "Insert a procedure declaration."
  8419. (interactive)
  8420. (vhdl-template-procedure 'decl))
  8421. (defun vhdl-template-procedure-body ()
  8422. "Insert a procedure body."
  8423. (interactive)
  8424. (vhdl-template-procedure 'body))
  8425. (defun vhdl-template-process (&optional kind)
  8426. "Insert a process."
  8427. (interactive)
  8428. (let ((margin (current-indentation))
  8429. (start (point))
  8430. label seq input-signals clock reset final-pos)
  8431. (setq seq (if kind (eq kind 'seq)
  8432. (eq (vhdl-decision-query
  8433. "process" "(c)ombinational or (s)equential?" t) ?s)))
  8434. (vhdl-insert-keyword "PROCESS ")
  8435. (when (memq vhdl-optional-labels '(process all))
  8436. (goto-char start)
  8437. (insert ": ")
  8438. (goto-char start)
  8439. (setq label (vhdl-template-field "[label]" nil t))
  8440. (unless label (delete-char 2))
  8441. (forward-word 1)
  8442. (forward-char 1))
  8443. (insert "(")
  8444. (if (not seq)
  8445. (unless (setq input-signals
  8446. (vhdl-template-field "[sensitivity list]" ")" t))
  8447. (setq input-signals "")
  8448. (delete-char -2))
  8449. (setq clock (or (and (not (equal "" vhdl-clock-name))
  8450. (progn (insert vhdl-clock-name) vhdl-clock-name))
  8451. (vhdl-template-field "clock name") "<clock>"))
  8452. (when (eq vhdl-reset-kind 'async)
  8453. (insert ", ")
  8454. (setq reset (or (and (not (equal "" vhdl-reset-name))
  8455. (progn (insert vhdl-reset-name) vhdl-reset-name))
  8456. (vhdl-template-field "reset name") "<reset>")))
  8457. (insert ")"))
  8458. (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
  8459. (insert "\n")
  8460. (vhdl-template-begin-end "PROCESS" label margin)
  8461. (when seq (setq reset (vhdl-template-seq-process clock reset)))
  8462. (when vhdl-prompt-for-comments
  8463. (setq final-pos (point-marker))
  8464. (vhdl-prepare-search-2
  8465. (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
  8466. (vhdl-re-search-backward "\\<process\\>" nil t))
  8467. (end-of-line -0)
  8468. (if (bobp)
  8469. (progn (insert "\n") (forward-line -1))
  8470. (insert "\n"))
  8471. (indent-to margin)
  8472. (insert "-- purpose: ")
  8473. (if (not (vhdl-template-field "[description]" nil t))
  8474. (vhdl-line-kill-entire)
  8475. (insert "\n")
  8476. (indent-to margin)
  8477. (insert "-- type : ")
  8478. (insert (if seq "sequential" "combinational") "\n")
  8479. (indent-to margin)
  8480. (insert "-- inputs : ")
  8481. (if (not seq)
  8482. (insert input-signals)
  8483. (insert clock ", ")
  8484. (when reset (insert reset ", "))
  8485. (unless (vhdl-template-field "[signal names]" nil t)
  8486. (delete-char -2)))
  8487. (insert "\n")
  8488. (indent-to margin)
  8489. (insert "-- outputs: ")
  8490. (vhdl-template-field "[signal names]" nil t))))
  8491. (goto-char final-pos))))
  8492. (defun vhdl-template-process-comb ()
  8493. "Insert a combinational process."
  8494. (interactive)
  8495. (vhdl-template-process 'comb))
  8496. (defun vhdl-template-process-seq ()
  8497. "Insert a sequential process."
  8498. (interactive)
  8499. (vhdl-template-process 'seq))
  8500. (defun vhdl-template-quantity ()
  8501. "Insert a quantity declaration."
  8502. (interactive)
  8503. (if (vhdl-in-argument-list-p)
  8504. (let ((start (point)))
  8505. (vhdl-insert-keyword "QUANTITY ")
  8506. (when (vhdl-template-field "names" nil t start (point))
  8507. (insert " : ")
  8508. (vhdl-template-field "[IN | OUT]" " " t)
  8509. (vhdl-template-field "type")
  8510. (insert ";")
  8511. (vhdl-comment-insert-inline)))
  8512. (let ((char (vhdl-decision-query
  8513. "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
  8514. (cond ((eq char ?f) (vhdl-template-quantity-free))
  8515. ((eq char ?b) (vhdl-template-quantity-branch))
  8516. ((eq char ?s) (vhdl-template-quantity-source))
  8517. (t (vhdl-template-undo (point) (point)))))))
  8518. (defun vhdl-template-quantity-free ()
  8519. "Insert a free quantity declaration."
  8520. (interactive)
  8521. (vhdl-insert-keyword "QUANTITY ")
  8522. (vhdl-template-field "names")
  8523. (insert " : ")
  8524. (vhdl-template-field "type")
  8525. (let ((position (point)))
  8526. (insert " := ")
  8527. (unless (vhdl-template-field "[initialization]" nil t)
  8528. (delete-region position (point)))
  8529. (insert ";")
  8530. (vhdl-comment-insert-inline)))
  8531. (defun vhdl-template-quantity-branch ()
  8532. "Insert a branch quantity declaration."
  8533. (interactive)
  8534. (let (position)
  8535. (vhdl-insert-keyword "QUANTITY ")
  8536. (when (vhdl-template-field "[across names]" " " t)
  8537. (vhdl-insert-keyword "ACROSS "))
  8538. (when (vhdl-template-field "[through names]" " " t)
  8539. (vhdl-insert-keyword "THROUGH "))
  8540. (vhdl-template-field "plus terminal name")
  8541. (setq position (point))
  8542. (vhdl-insert-keyword " TO ")
  8543. (unless (vhdl-template-field "[minus terminal name]" nil t)
  8544. (delete-region position (point)))
  8545. (insert ";")
  8546. (vhdl-comment-insert-inline)))
  8547. (defun vhdl-template-quantity-source ()
  8548. "Insert a source quantity declaration."
  8549. (interactive)
  8550. (vhdl-insert-keyword "QUANTITY ")
  8551. (vhdl-template-field "names")
  8552. (insert " : ")
  8553. (vhdl-template-field "type" " ")
  8554. (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
  8555. (progn (vhdl-insert-keyword "NOISE ")
  8556. (vhdl-template-field "power expression"))
  8557. (vhdl-insert-keyword "SPECTRUM ")
  8558. (vhdl-template-field "magnitude expression" ", ")
  8559. (vhdl-template-field "phase expression"))
  8560. (insert ";")
  8561. (vhdl-comment-insert-inline))
  8562. (defun vhdl-template-record (kind &optional name secondary)
  8563. "Insert a record type declaration."
  8564. (interactive)
  8565. (let ((margin (current-column))
  8566. (start (point))
  8567. (first t))
  8568. (vhdl-insert-keyword "RECORD\n")
  8569. (indent-to (+ margin vhdl-basic-offset))
  8570. (when (or (vhdl-template-field "element names"
  8571. nil (not secondary) start (point))
  8572. secondary)
  8573. (while (or first (vhdl-template-field "[element names]" nil t))
  8574. (insert " : ")
  8575. (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
  8576. (vhdl-comment-insert-inline)
  8577. (insert "\n")
  8578. (indent-to (+ margin vhdl-basic-offset))
  8579. (setq first nil))
  8580. (delete-region (line-beginning-position) (point))
  8581. (indent-to margin)
  8582. (vhdl-insert-keyword "END RECORD")
  8583. (unless (vhdl-standard-p '87) (and name (insert " " name)))
  8584. (insert ";")
  8585. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
  8586. (defun vhdl-template-report ()
  8587. "Insert a report statement."
  8588. (interactive)
  8589. (let ((start (point)))
  8590. (vhdl-insert-keyword "REPORT ")
  8591. (if (equal "\"\"" (vhdl-template-field
  8592. "string expression" nil t start (point) t))
  8593. (delete-char -2)
  8594. (setq start (point))
  8595. (vhdl-insert-keyword " SEVERITY ")
  8596. (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
  8597. (delete-region start (point)))
  8598. (insert ";"))))
  8599. (defun vhdl-template-return ()
  8600. "Insert a return statement."
  8601. (interactive)
  8602. (let ((start (point)))
  8603. (vhdl-insert-keyword "RETURN ")
  8604. (unless (vhdl-template-field "[expression]" nil t start (point))
  8605. (delete-char -1))
  8606. (insert ";")))
  8607. (defun vhdl-template-selected-signal-asst ()
  8608. "Insert a selected signal assignment."
  8609. (interactive)
  8610. (let ((margin (current-indentation))
  8611. (start (point))
  8612. (choices t))
  8613. (let ((position (point)))
  8614. (vhdl-insert-keyword " SELECT ")
  8615. (goto-char position))
  8616. (vhdl-insert-keyword "WITH ")
  8617. (when (vhdl-template-field "selector expression"
  8618. nil t start (+ (point) 7))
  8619. (forward-word 1)
  8620. (delete-char 1)
  8621. (insert "\n")
  8622. (indent-to (+ margin vhdl-basic-offset))
  8623. (vhdl-template-field "target signal" " <= ")
  8624. ; (vhdl-template-field "[GUARDED] [TRANSPORT]")
  8625. (insert "\n")
  8626. (indent-to (+ margin vhdl-basic-offset))
  8627. (vhdl-template-field "waveform")
  8628. (vhdl-insert-keyword " WHEN ")
  8629. (vhdl-template-field "choices" ",")
  8630. (insert "\n")
  8631. (indent-to (+ margin vhdl-basic-offset))
  8632. (while (and choices (vhdl-template-field "[waveform]" nil t))
  8633. (vhdl-insert-keyword " WHEN ")
  8634. (if (setq choices (vhdl-template-field "[choices]" "," t))
  8635. (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
  8636. (vhdl-insert-keyword "OTHERS")))
  8637. (when choices
  8638. (fixup-whitespace)
  8639. (delete-char -2))
  8640. (insert ";")
  8641. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
  8642. (defun vhdl-template-signal ()
  8643. "Insert a signal declaration."
  8644. (interactive)
  8645. (let ((start (point))
  8646. (in-arglist (vhdl-in-argument-list-p)))
  8647. (vhdl-insert-keyword "SIGNAL ")
  8648. (when (vhdl-template-field "names" nil t start (point))
  8649. (insert " : ")
  8650. (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
  8651. (vhdl-template-field "type")
  8652. (if in-arglist
  8653. (progn (insert ";")
  8654. (vhdl-comment-insert-inline))
  8655. (let ((position (point)))
  8656. (insert " := ")
  8657. (unless (vhdl-template-field "[initialization]" nil t)
  8658. (delete-region position (point)))
  8659. (insert ";")
  8660. (vhdl-comment-insert-inline))))))
  8661. (defun vhdl-template-subnature ()
  8662. "Insert a subnature declaration."
  8663. (interactive)
  8664. (let ((start (point))
  8665. position)
  8666. (vhdl-insert-keyword "SUBNATURE ")
  8667. (when (vhdl-template-field "name" nil t start (point))
  8668. (vhdl-insert-keyword " IS ")
  8669. (vhdl-template-field "nature" " (")
  8670. (if (vhdl-template-field "[index range]" nil t)
  8671. (insert ")")
  8672. (delete-char -2))
  8673. (setq position (point))
  8674. (vhdl-insert-keyword " TOLERANCE ")
  8675. (if (equal "\"\"" (vhdl-template-field "[string expression]"
  8676. nil t nil nil t))
  8677. (delete-region position (point))
  8678. (vhdl-insert-keyword " ACROSS ")
  8679. (vhdl-template-field "string expression" nil nil nil nil t)
  8680. (vhdl-insert-keyword " THROUGH"))
  8681. (insert ";")
  8682. (vhdl-comment-insert-inline))))
  8683. (defun vhdl-template-subprogram-body ()
  8684. "Insert a subprogram body."
  8685. (interactive)
  8686. (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
  8687. (vhdl-template-function-body)
  8688. (vhdl-template-procedure-body)))
  8689. (defun vhdl-template-subprogram-decl ()
  8690. "Insert a subprogram declaration."
  8691. (interactive)
  8692. (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
  8693. (vhdl-template-function-decl)
  8694. (vhdl-template-procedure-decl)))
  8695. (defun vhdl-template-subtype ()
  8696. "Insert a subtype declaration."
  8697. (interactive)
  8698. (let ((start (point)))
  8699. (vhdl-insert-keyword "SUBTYPE ")
  8700. (when (vhdl-template-field "name" nil t start (point))
  8701. (vhdl-insert-keyword " IS ")
  8702. (vhdl-template-field "type" " ")
  8703. (unless
  8704. (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
  8705. (delete-char -1))
  8706. (insert ";")
  8707. (vhdl-comment-insert-inline))))
  8708. (defun vhdl-template-terminal ()
  8709. "Insert a terminal declaration."
  8710. (interactive)
  8711. (let ((start (point)))
  8712. (vhdl-insert-keyword "TERMINAL ")
  8713. (when (vhdl-template-field "names" nil t start (point))
  8714. (insert " : ")
  8715. (vhdl-template-field "nature")
  8716. (insert ";")
  8717. (vhdl-comment-insert-inline))))
  8718. (defun vhdl-template-type ()
  8719. "Insert a type declaration."
  8720. (interactive)
  8721. (let ((start (point))
  8722. name mid-pos end-pos)
  8723. (vhdl-insert-keyword "TYPE ")
  8724. (when (setq name (vhdl-template-field "name" nil t start (point)))
  8725. (vhdl-insert-keyword " IS ")
  8726. (let ((definition
  8727. (upcase
  8728. (or (vhdl-template-field
  8729. "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
  8730. ""))))
  8731. (cond ((equal definition "")
  8732. (delete-char -4)
  8733. (insert ";"))
  8734. ((equal definition "ARRAY")
  8735. (delete-region (point) (progn (forward-word -1) (point)))
  8736. (vhdl-template-array 'type t))
  8737. ((equal definition "RECORD")
  8738. (setq mid-pos (point-marker))
  8739. (delete-region (point) (progn (forward-word -1) (point)))
  8740. (vhdl-template-record 'type name t))
  8741. ((equal definition "ACCESS")
  8742. (insert " ")
  8743. (vhdl-template-field "type" ";"))
  8744. ((equal definition "FILE")
  8745. (vhdl-insert-keyword " OF ")
  8746. (vhdl-template-field "type" ";"))
  8747. (t (insert ";")))
  8748. (when mid-pos
  8749. (setq end-pos (point-marker))
  8750. (goto-char mid-pos)
  8751. (end-of-line))
  8752. (vhdl-comment-insert-inline)
  8753. (when end-pos (goto-char end-pos))))))
  8754. (defun vhdl-template-use ()
  8755. "Insert a use clause."
  8756. (interactive)
  8757. (let ((start (point)))
  8758. (vhdl-prepare-search-1
  8759. (vhdl-insert-keyword "USE ")
  8760. (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
  8761. (vhdl-insert-keyword "..ALL;")
  8762. (backward-char 6)
  8763. (when (vhdl-template-field "library name" nil t start (+ (point) 6))
  8764. (forward-char 1)
  8765. (vhdl-template-field "package name")
  8766. (forward-char 5))))))
  8767. (defun vhdl-template-variable ()
  8768. "Insert a variable declaration."
  8769. (interactive)
  8770. (let ((start (point))
  8771. (in-arglist (vhdl-in-argument-list-p)))
  8772. (vhdl-prepare-search-2
  8773. (if (or (save-excursion
  8774. (and (vhdl-re-search-backward
  8775. "\\<function\\|procedure\\|process\\|procedural\\|end\\>"
  8776. nil t)
  8777. (not (progn (backward-word 1) (looking-at "\\<end\\>")))))
  8778. (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
  8779. (vhdl-insert-keyword "VARIABLE ")
  8780. (vhdl-insert-keyword "SHARED VARIABLE ")))
  8781. (when (vhdl-template-field "names" nil t start (point))
  8782. (insert " : ")
  8783. (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
  8784. (vhdl-template-field "type")
  8785. (if in-arglist
  8786. (progn (insert ";")
  8787. (vhdl-comment-insert-inline))
  8788. (let ((position (point)))
  8789. (insert " := ")
  8790. (unless (vhdl-template-field "[initialization]" nil t)
  8791. (delete-region position (point)))
  8792. (insert ";")
  8793. (vhdl-comment-insert-inline))))))
  8794. (defun vhdl-template-wait ()
  8795. "Insert a wait statement."
  8796. (interactive)
  8797. (vhdl-insert-keyword "WAIT ")
  8798. (unless (vhdl-template-field
  8799. "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
  8800. nil t)
  8801. (delete-char -1))
  8802. (insert ";"))
  8803. (defun vhdl-template-when ()
  8804. "Indent correctly if within a case statement."
  8805. (interactive)
  8806. (let ((position (point))
  8807. margin)
  8808. (vhdl-prepare-search-2
  8809. (if (and (= (current-column) (current-indentation))
  8810. (vhdl-re-search-forward "\\<end\\>" nil t)
  8811. (looking-at "\\s-*\\<case\\>"))
  8812. (progn
  8813. (setq margin (current-indentation))
  8814. (goto-char position)
  8815. (delete-horizontal-space)
  8816. (indent-to (+ margin vhdl-basic-offset)))
  8817. (goto-char position)))
  8818. (vhdl-insert-keyword "WHEN ")))
  8819. (defun vhdl-template-while-loop ()
  8820. "Insert a while loop."
  8821. (interactive)
  8822. (let* ((margin (current-indentation))
  8823. (start (point))
  8824. label)
  8825. (if (not (eq vhdl-optional-labels 'all))
  8826. (vhdl-insert-keyword "WHILE ")
  8827. (vhdl-insert-keyword ": WHILE ")
  8828. (goto-char start)
  8829. (setq label (vhdl-template-field "[label]" nil t))
  8830. (unless label (delete-char 2))
  8831. (forward-word 1)
  8832. (forward-char 1))
  8833. (when vhdl-conditions-in-parenthesis (insert "("))
  8834. (when (vhdl-template-field "condition" nil t start (point))
  8835. (when vhdl-conditions-in-parenthesis (insert ")"))
  8836. (vhdl-insert-keyword " LOOP\n\n")
  8837. (indent-to margin)
  8838. (vhdl-insert-keyword "END LOOP")
  8839. (insert (if label (concat " " label ";") ";"))
  8840. (forward-line -1)
  8841. (indent-to (+ margin vhdl-basic-offset)))))
  8842. (defun vhdl-template-with ()
  8843. "Insert a with statement (i.e. selected signal assignment)."
  8844. (interactive)
  8845. (vhdl-prepare-search-1
  8846. (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
  8847. (equal ";" (match-string 1)))
  8848. (vhdl-template-selected-signal-asst)
  8849. (vhdl-insert-keyword "WITH "))))
  8850. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8851. ;; Special templates
  8852. (defun vhdl-template-clocked-wait ()
  8853. "Insert a wait statement for rising/falling clock edge."
  8854. (interactive)
  8855. (let ((start (point))
  8856. clock)
  8857. (vhdl-insert-keyword "WAIT UNTIL ")
  8858. (when (setq clock
  8859. (or (and (not (equal "" vhdl-clock-name))
  8860. (progn (insert vhdl-clock-name) vhdl-clock-name))
  8861. (vhdl-template-field "clock name" nil t start (point))))
  8862. (insert "'event")
  8863. (vhdl-insert-keyword " AND ")
  8864. (insert clock)
  8865. (insert
  8866. " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
  8867. (vhdl-comment-insert-inline
  8868. (concat (if vhdl-clock-rising-edge "rising" "falling")
  8869. " clock edge")))))
  8870. (defun vhdl-template-seq-process (clock reset)
  8871. "Insert a template for the body of a sequential process."
  8872. (let ((margin (current-indentation))
  8873. position)
  8874. (vhdl-insert-keyword "IF ")
  8875. (when (eq vhdl-reset-kind 'async)
  8876. (insert reset " = "
  8877. (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
  8878. (vhdl-insert-keyword " THEN")
  8879. (vhdl-comment-insert-inline
  8880. (concat "asynchronous reset (active "
  8881. (if vhdl-reset-active-high "high" "low") ")"))
  8882. (insert "\n") (indent-to (+ margin vhdl-basic-offset))
  8883. (setq position (point))
  8884. (insert "\n") (indent-to margin)
  8885. (vhdl-insert-keyword "ELSIF "))
  8886. (if (eq vhdl-clock-edge-condition 'function)
  8887. (insert (if vhdl-clock-rising-edge "rising" "falling")
  8888. "_edge(" clock ")")
  8889. (insert clock "'event")
  8890. (vhdl-insert-keyword " AND ")
  8891. (insert clock " = "
  8892. (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
  8893. (vhdl-insert-keyword " THEN")
  8894. (vhdl-comment-insert-inline
  8895. (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
  8896. (insert "\n") (indent-to (+ margin vhdl-basic-offset))
  8897. (when (eq vhdl-reset-kind 'sync)
  8898. (vhdl-insert-keyword "IF ")
  8899. (setq reset (or (and (not (equal "" vhdl-reset-name))
  8900. (progn (insert vhdl-reset-name) vhdl-reset-name))
  8901. (vhdl-template-field "reset name") "<reset>"))
  8902. (insert " = "
  8903. (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
  8904. (vhdl-insert-keyword " THEN")
  8905. (vhdl-comment-insert-inline
  8906. (concat "synchronous reset (active "
  8907. (if vhdl-reset-active-high "high" "low") ")"))
  8908. (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
  8909. (setq position (point))
  8910. (insert "\n") (indent-to (+ margin vhdl-basic-offset))
  8911. (vhdl-insert-keyword "ELSE")
  8912. (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
  8913. (insert "\n") (indent-to (+ margin vhdl-basic-offset))
  8914. (vhdl-insert-keyword "END IF;"))
  8915. (when (eq vhdl-reset-kind 'none)
  8916. (setq position (point)))
  8917. (insert "\n") (indent-to margin)
  8918. (vhdl-insert-keyword "END IF;")
  8919. (goto-char position)
  8920. reset))
  8921. (defun vhdl-template-standard-package (library package)
  8922. "Insert specification of a standard package. Include a library
  8923. specification, if not already there."
  8924. (let ((margin (current-indentation)))
  8925. (unless (equal library "std")
  8926. (unless (or (save-excursion
  8927. (vhdl-prepare-search-1
  8928. (and (not (bobp))
  8929. (re-search-backward
  8930. (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
  8931. library "\\|end\\)\\>") nil t)
  8932. (match-string 2))))
  8933. (equal (downcase library) "work"))
  8934. (vhdl-insert-keyword "LIBRARY ")
  8935. (insert library ";")
  8936. (when package
  8937. (insert "\n")
  8938. (indent-to margin)))
  8939. (when package
  8940. (vhdl-insert-keyword "USE ")
  8941. (insert library "." package)
  8942. (vhdl-insert-keyword ".ALL;")))))
  8943. (defun vhdl-template-package-math-complex ()
  8944. "Insert specification of `math_complex' package."
  8945. (interactive)
  8946. (vhdl-template-standard-package "ieee" "math_complex"))
  8947. (defun vhdl-template-package-math-real ()
  8948. "Insert specification of `math_real' package."
  8949. (interactive)
  8950. (vhdl-template-standard-package "ieee" "math_real"))
  8951. (defun vhdl-template-package-numeric-bit ()
  8952. "Insert specification of `numeric_bit' package."
  8953. (interactive)
  8954. (vhdl-template-standard-package "ieee" "numeric_bit"))
  8955. (defun vhdl-template-package-numeric-std ()
  8956. "Insert specification of `numeric_std' package."
  8957. (interactive)
  8958. (vhdl-template-standard-package "ieee" "numeric_std"))
  8959. (defun vhdl-template-package-std-logic-1164 ()
  8960. "Insert specification of `std_logic_1164' package."
  8961. (interactive)
  8962. (vhdl-template-standard-package "ieee" "std_logic_1164"))
  8963. (defun vhdl-template-package-std-logic-arith ()
  8964. "Insert specification of `std_logic_arith' package."
  8965. (interactive)
  8966. (vhdl-template-standard-package "ieee" "std_logic_arith"))
  8967. (defun vhdl-template-package-std-logic-misc ()
  8968. "Insert specification of `std_logic_misc' package."
  8969. (interactive)
  8970. (vhdl-template-standard-package "ieee" "std_logic_misc"))
  8971. (defun vhdl-template-package-std-logic-signed ()
  8972. "Insert specification of `std_logic_signed' package."
  8973. (interactive)
  8974. (vhdl-template-standard-package "ieee" "std_logic_signed"))
  8975. (defun vhdl-template-package-std-logic-textio ()
  8976. "Insert specification of `std_logic_textio' package."
  8977. (interactive)
  8978. (vhdl-template-standard-package "ieee" "std_logic_textio"))
  8979. (defun vhdl-template-package-std-logic-unsigned ()
  8980. "Insert specification of `std_logic_unsigned' package."
  8981. (interactive)
  8982. (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
  8983. (defun vhdl-template-package-textio ()
  8984. "Insert specification of `textio' package."
  8985. (interactive)
  8986. (vhdl-template-standard-package "std" "textio"))
  8987. (defun vhdl-template-directive (directive)
  8988. "Insert directive."
  8989. (unless (= (current-indentation) (current-column))
  8990. (delete-horizontal-space)
  8991. (insert " "))
  8992. (insert "-- pragma " directive))
  8993. (defun vhdl-template-directive-translate-on ()
  8994. "Insert directive 'translate_on'."
  8995. (interactive)
  8996. (vhdl-template-directive "translate_on"))
  8997. (defun vhdl-template-directive-translate-off ()
  8998. "Insert directive 'translate_off'."
  8999. (interactive)
  9000. (vhdl-template-directive "translate_off"))
  9001. (defun vhdl-template-directive-synthesis-on ()
  9002. "Insert directive 'synthesis_on'."
  9003. (interactive)
  9004. (vhdl-template-directive "synthesis_on"))
  9005. (defun vhdl-template-directive-synthesis-off ()
  9006. "Insert directive 'synthesis_off'."
  9007. (interactive)
  9008. (vhdl-template-directive "synthesis_off"))
  9009. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9010. ;; Header and footer templates
  9011. (defun vhdl-template-header (&optional file-title)
  9012. "Insert a VHDL file header."
  9013. (interactive)
  9014. (unless (equal vhdl-file-header "")
  9015. (let (pos)
  9016. (save-excursion
  9017. (goto-char (point-min))
  9018. (vhdl-insert-string-or-file vhdl-file-header)
  9019. (setq pos (point-marker)))
  9020. (vhdl-template-replace-header-keywords
  9021. (point-min-marker) pos file-title))))
  9022. (defun vhdl-template-footer ()
  9023. "Insert a VHDL file footer."
  9024. (interactive)
  9025. (unless (equal vhdl-file-footer "")
  9026. (let (pos)
  9027. (save-excursion
  9028. (goto-char (point-max))
  9029. (setq pos (point-marker))
  9030. (vhdl-insert-string-or-file vhdl-file-footer)
  9031. (unless (= (preceding-char) ?\n)
  9032. (insert "\n")))
  9033. (vhdl-template-replace-header-keywords pos (point-max-marker)))))
  9034. (defun vhdl-template-replace-header-keywords (beg end &optional file-title
  9035. is-model)
  9036. "Replace keywords in header and footer."
  9037. (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
  9038. (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
  9039. pos)
  9040. (vhdl-prepare-search-2
  9041. (save-excursion
  9042. (goto-char beg)
  9043. (while (search-forward "<projectdesc>" end t)
  9044. (replace-match project-desc t t))
  9045. (goto-char beg)
  9046. (while (search-forward "<filename>" end t)
  9047. (replace-match (buffer-name) t t))
  9048. (goto-char beg)
  9049. (while (search-forward "<copyright>" end t)
  9050. (replace-match vhdl-copyright-string t t))
  9051. (goto-char beg)
  9052. (while (search-forward "<author>" end t)
  9053. (replace-match "" t t)
  9054. (insert (user-full-name))
  9055. (when user-mail-address (insert " <" user-mail-address ">")))
  9056. (goto-char beg)
  9057. (while (search-forward "<login>" end t)
  9058. (replace-match (user-login-name) t t))
  9059. (goto-char beg)
  9060. (while (search-forward "<project>" end t)
  9061. (replace-match project-title t t))
  9062. (goto-char beg)
  9063. (while (search-forward "<company>" end t)
  9064. (replace-match vhdl-company-name t t))
  9065. (goto-char beg)
  9066. (while (search-forward "<platform>" end t)
  9067. (replace-match vhdl-platform-spec t t))
  9068. (goto-char beg)
  9069. (while (search-forward "<standard>" end t)
  9070. (replace-match
  9071. (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
  9072. ((vhdl-standard-p '93) "'93"))
  9073. (when (vhdl-standard-p 'ams) ", VHDL-AMS")
  9074. (when (vhdl-standard-p 'math) ", Math Packages")) t t))
  9075. (goto-char beg)
  9076. ;; Replace <RCS> with $, so that RCS for the source is
  9077. ;; not over-enthusiastic with replacements
  9078. (while (search-forward "<RCS>" end t)
  9079. (replace-match "$" nil t))
  9080. (goto-char beg)
  9081. (while (search-forward "<date>" end t)
  9082. (replace-match "" t t)
  9083. (vhdl-template-insert-date))
  9084. (goto-char beg)
  9085. (while (search-forward "<year>" end t)
  9086. (replace-match (format-time-string "%Y" nil) t t))
  9087. (goto-char beg)
  9088. (when file-title
  9089. (while (search-forward "<title string>" end t)
  9090. (replace-match file-title t t))
  9091. (goto-char beg))
  9092. (let (string)
  9093. (while
  9094. (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
  9095. (setq string (read-string (concat (match-string 1) ": ")))
  9096. (replace-match string t t)))
  9097. (goto-char beg)
  9098. (when (and (not is-model) (search-forward "<cursor>" end t))
  9099. (replace-match "" t t)
  9100. (setq pos (point))))
  9101. (when pos (goto-char pos))
  9102. (unless is-model
  9103. (when (or (not project-title) (equal project-title ""))
  9104. (message "You can specify a project title in user option `vhdl-project-alist'"))
  9105. (when (or (not project-desc) (equal project-desc ""))
  9106. (message "You can specify a project description in user option `vhdl-project-alist'"))
  9107. (when (equal vhdl-platform-spec "")
  9108. (message "You can specify a platform in user option `vhdl-platform-spec'"))
  9109. (when (equal vhdl-company-name "")
  9110. (message "You can specify a company name in user option `vhdl-company-name'"))))))
  9111. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9112. ;; Comment templates and functions
  9113. (defun vhdl-comment-indent ()
  9114. "Indent comments."
  9115. (let* ((position (point))
  9116. (col
  9117. (progn
  9118. (forward-line -1)
  9119. (if (re-search-forward "--" position t)
  9120. (- (current-column) 2) ; existing comment at bol stays there
  9121. (goto-char position)
  9122. (skip-chars-backward " \t")
  9123. (max comment-column ; else indent to comment column
  9124. (1+ (current-column))))))) ; except leave at least one space
  9125. (goto-char position)
  9126. col))
  9127. (defun vhdl-comment-insert ()
  9128. "Start a comment at the end of the line.
  9129. If on line with code, indent at least `comment-column'.
  9130. If starting after end-comment-column, start a new line."
  9131. (interactive)
  9132. (when (> (current-column) end-comment-column) (newline-and-indent))
  9133. (if (or (looking-at "\\s-*$") ; end of line
  9134. (and (not unread-command-events) ; called with key binding or menu
  9135. (not (end-of-line))))
  9136. (let (margin)
  9137. (while (= (preceding-char) ?-) (delete-char -1))
  9138. (setq margin (current-column))
  9139. (delete-horizontal-space)
  9140. (if (bolp)
  9141. (progn (indent-to margin) (insert "--"))
  9142. (insert " ")
  9143. (indent-to comment-column)
  9144. (insert "--"))
  9145. (if (not unread-command-events) (insert " ")))
  9146. ;; else code following current point implies commenting out code
  9147. (let (next-input code)
  9148. (while (= (preceding-char) ?-) (delete-char -2))
  9149. (while (= (setq next-input (read-char)) 13) ; CR
  9150. (insert "--") ; or have a space after it?
  9151. (forward-char -2)
  9152. (forward-line 1)
  9153. (message "Enter CR if commenting out a line of code.")
  9154. (setq code t))
  9155. (unless code
  9156. (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
  9157. (setq unread-command-events
  9158. (list (vhdl-character-to-event next-input)))))) ; pushback the char
  9159. (defun vhdl-comment-display (&optional line-exists)
  9160. "Add 2 comment lines at the current indent, making a display comment."
  9161. (interactive)
  9162. (let ((margin (current-indentation)))
  9163. (unless line-exists (vhdl-comment-display-line))
  9164. (insert "\n") (indent-to margin)
  9165. (insert "\n") (indent-to margin)
  9166. (vhdl-comment-display-line)
  9167. (end-of-line -0)
  9168. (insert "-- ")))
  9169. (defun vhdl-comment-display-line ()
  9170. "Displays one line of dashes."
  9171. (interactive)
  9172. (while (= (preceding-char) ?-) (delete-char -2))
  9173. (let* ((col (current-column))
  9174. (len (- end-comment-column col)))
  9175. (insert-char ?- len)))
  9176. (defun vhdl-comment-append-inline ()
  9177. "Append empty inline comment to current line."
  9178. (interactive)
  9179. (end-of-line)
  9180. (delete-horizontal-space)
  9181. (insert " ")
  9182. (indent-to comment-column)
  9183. (insert "-- "))
  9184. (defun vhdl-comment-insert-inline (&optional string always-insert)
  9185. "Insert inline comment."
  9186. (when (or (and string (or vhdl-self-insert-comments always-insert))
  9187. (and (not string) vhdl-prompt-for-comments))
  9188. (let ((position (point)))
  9189. (insert " ")
  9190. (indent-to comment-column)
  9191. (insert "-- ")
  9192. (if (not (or (and string (progn (insert string) t))
  9193. (vhdl-template-field "[comment]" nil t)))
  9194. (delete-region position (point))
  9195. (while (= (preceding-char) ?\ ) (delete-char -1))
  9196. ;; (when (> (current-column) end-comment-column)
  9197. ;; (setq position (point-marker))
  9198. ;; (re-search-backward "-- ")
  9199. ;; (insert "\n")
  9200. ;; (indent-to comment-column)
  9201. ;; (goto-char position))
  9202. ))))
  9203. (defun vhdl-comment-block ()
  9204. "Insert comment for code block."
  9205. (when vhdl-prompt-for-comments
  9206. (let ((final-pos (point-marker)))
  9207. (vhdl-prepare-search-2
  9208. (when (and (re-search-backward "^\\s-*begin\\>" nil t)
  9209. (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
  9210. (let (margin)
  9211. (back-to-indentation)
  9212. (setq margin (current-column))
  9213. (end-of-line -0)
  9214. (if (bobp)
  9215. (progn (insert "\n") (forward-line -1))
  9216. (insert "\n"))
  9217. (indent-to margin)
  9218. (insert "-- purpose: ")
  9219. (unless (vhdl-template-field "[description]" nil t)
  9220. (vhdl-line-kill-entire)))))
  9221. (goto-char final-pos))))
  9222. (defun vhdl-comment-uncomment-region (beg end &optional arg)
  9223. "Comment out region if not commented out, uncomment otherwise."
  9224. (interactive "r\nP")
  9225. (save-excursion
  9226. (goto-char (1- end))
  9227. (end-of-line)
  9228. (setq end (point-marker))
  9229. (goto-char beg)
  9230. (beginning-of-line)
  9231. (setq beg (point))
  9232. (if (looking-at comment-start)
  9233. (comment-region beg end '(4))
  9234. (comment-region beg end))))
  9235. (defun vhdl-comment-uncomment-line (&optional arg)
  9236. "Comment out line if not commented out, uncomment otherwise."
  9237. (interactive "p")
  9238. (save-excursion
  9239. (beginning-of-line)
  9240. (let ((position (point)))
  9241. (forward-line (or arg 1))
  9242. (vhdl-comment-uncomment-region position (point)))))
  9243. (defun vhdl-comment-kill-region (beg end)
  9244. "Kill comments in region."
  9245. (interactive "r")
  9246. (save-excursion
  9247. (goto-char end)
  9248. (setq end (point-marker))
  9249. (goto-char beg)
  9250. (beginning-of-line)
  9251. (while (< (point) end)
  9252. (if (looking-at "^\\(\\s-*--.*\n\\)")
  9253. (progn (delete-region (match-beginning 1) (match-end 1)))
  9254. (beginning-of-line 2)))))
  9255. (defun vhdl-comment-kill-inline-region (beg end)
  9256. "Kill inline comments in region."
  9257. (interactive "r")
  9258. (save-excursion
  9259. (goto-char end)
  9260. (setq end (point-marker))
  9261. (goto-char beg)
  9262. (beginning-of-line)
  9263. (while (< (point) end)
  9264. (when (looking-at "^.*[^ \t\n-]+\\(\\s-*--.*\\)$")
  9265. (delete-region (match-beginning 1) (match-end 1)))
  9266. (beginning-of-line 2))))
  9267. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9268. ;; Subtemplates
  9269. (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
  9270. "Insert a begin ... end pair with optional name after the end.
  9271. Point is left between them."
  9272. (let (position)
  9273. (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
  9274. (indent-to margin)
  9275. (vhdl-insert-keyword "BEGIN")
  9276. (when (and (or construct name) vhdl-self-insert-comments)
  9277. (insert " --")
  9278. (when construct (insert " ") (vhdl-insert-keyword construct))
  9279. (when name (insert " " name)))
  9280. (insert "\n")
  9281. (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
  9282. (indent-to (+ margin vhdl-basic-offset))
  9283. (setq position (point))
  9284. (insert "\n")
  9285. (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
  9286. (indent-to margin)
  9287. (vhdl-insert-keyword "END")
  9288. (when construct (insert " ") (vhdl-insert-keyword construct))
  9289. (insert (if name (concat " " name) "") ";")
  9290. (goto-char position)))
  9291. (defun vhdl-template-argument-list (&optional is-function)
  9292. "Read from user a procedure or function argument list."
  9293. (insert " (")
  9294. (let ((margin (current-column))
  9295. (start (point))
  9296. (end-pos (point))
  9297. not-empty interface semicolon-pos)
  9298. (unless vhdl-argument-list-indent
  9299. (setq margin (+ (current-indentation) vhdl-basic-offset))
  9300. (insert "\n")
  9301. (indent-to margin))
  9302. (setq interface (vhdl-template-field
  9303. (concat "[CONSTANT | SIGNAL"
  9304. (unless is-function " | VARIABLE") "]") " " t))
  9305. (while (vhdl-template-field "[names]" nil t)
  9306. (setq not-empty t)
  9307. (insert " : ")
  9308. (unless is-function
  9309. (if (and interface (equal (upcase interface) "CONSTANT"))
  9310. (vhdl-insert-keyword "IN ")
  9311. (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
  9312. (vhdl-template-field "type")
  9313. (setq semicolon-pos (point))
  9314. (insert ";")
  9315. (vhdl-comment-insert-inline)
  9316. (setq end-pos (point))
  9317. (insert "\n")
  9318. (indent-to margin)
  9319. (setq interface (vhdl-template-field
  9320. (concat "[CONSTANT | SIGNAL"
  9321. (unless is-function " | VARIABLE") "]") " " t)))
  9322. (delete-region end-pos (point))
  9323. (when semicolon-pos (goto-char semicolon-pos))
  9324. (if not-empty
  9325. (progn (delete-char 1) (insert ")"))
  9326. (delete-char -2))))
  9327. (defun vhdl-template-generic-list (optional &optional no-value)
  9328. "Read from user a generic spec argument list."
  9329. (let (margin
  9330. (start (point)))
  9331. (vhdl-insert-keyword "GENERIC (")
  9332. (setq margin (current-column))
  9333. (unless vhdl-argument-list-indent
  9334. (let ((position (point)))
  9335. (back-to-indentation)
  9336. (setq margin (+ (current-column) vhdl-basic-offset))
  9337. (goto-char position)
  9338. (insert "\n")
  9339. (indent-to margin)))
  9340. (let ((vhdl-generics (vhdl-template-field
  9341. (concat (and optional "[") "name"
  9342. (and no-value "s") (and optional "]"))
  9343. nil optional)))
  9344. (if (not vhdl-generics)
  9345. (if optional
  9346. (progn (vhdl-line-kill-entire) (end-of-line -0)
  9347. (unless vhdl-argument-list-indent
  9348. (vhdl-line-kill-entire) (end-of-line -0)))
  9349. (vhdl-template-undo start (point))
  9350. nil )
  9351. (insert " : ")
  9352. (let (semicolon-pos end-pos)
  9353. (while vhdl-generics
  9354. (vhdl-template-field "type")
  9355. (if no-value
  9356. (progn (setq semicolon-pos (point))
  9357. (insert ";"))
  9358. (insert " := ")
  9359. (unless (vhdl-template-field "[value]" nil t)
  9360. (delete-char -4))
  9361. (setq semicolon-pos (point))
  9362. (insert ";"))
  9363. (vhdl-comment-insert-inline)
  9364. (setq end-pos (point))
  9365. (insert "\n")
  9366. (indent-to margin)
  9367. (setq vhdl-generics (vhdl-template-field
  9368. (concat "[name" (and no-value "s") "]")
  9369. " : " t)))
  9370. (delete-region end-pos (point))
  9371. (goto-char semicolon-pos)
  9372. (insert ")")
  9373. (end-of-line)
  9374. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
  9375. t)))))
  9376. (defun vhdl-template-port-list (optional)
  9377. "Read from user a port spec argument list."
  9378. (let ((start (point))
  9379. margin vhdl-ports object)
  9380. (vhdl-insert-keyword "PORT (")
  9381. (setq margin (current-column))
  9382. (unless vhdl-argument-list-indent
  9383. (let ((position (point)))
  9384. (back-to-indentation)
  9385. (setq margin (+ (current-column) vhdl-basic-offset))
  9386. (goto-char position)
  9387. (insert "\n")
  9388. (indent-to margin)))
  9389. (when (vhdl-standard-p 'ams)
  9390. (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
  9391. " " t)))
  9392. (setq vhdl-ports (vhdl-template-field
  9393. (concat (and optional "[") "names" (and optional "]"))
  9394. nil optional))
  9395. (if (not vhdl-ports)
  9396. (if optional
  9397. (progn (vhdl-line-kill-entire) (end-of-line -0)
  9398. (unless vhdl-argument-list-indent
  9399. (vhdl-line-kill-entire) (end-of-line -0)))
  9400. (vhdl-template-undo start (point))
  9401. nil)
  9402. (insert " : ")
  9403. (let (semicolon-pos end-pos)
  9404. (while vhdl-ports
  9405. (cond ((or (null object) (equal "SIGNAL" (upcase object)))
  9406. (vhdl-template-field "IN | OUT | INOUT" " "))
  9407. ((equal "QUANTITY" (upcase object))
  9408. (vhdl-template-field "[IN | OUT]" " " t)))
  9409. (vhdl-template-field
  9410. (if (and object (equal "TERMINAL" (upcase object)))
  9411. "nature" "type"))
  9412. (setq semicolon-pos (point))
  9413. (insert ";")
  9414. (vhdl-comment-insert-inline)
  9415. (setq end-pos (point))
  9416. (insert "\n")
  9417. (indent-to margin)
  9418. (when (vhdl-standard-p 'ams)
  9419. (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
  9420. " " t)))
  9421. (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
  9422. (delete-region end-pos (point))
  9423. (goto-char semicolon-pos)
  9424. (insert ")")
  9425. (end-of-line)
  9426. (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
  9427. t))))
  9428. (defun vhdl-template-generate-body (margin label)
  9429. "Insert body for generate template."
  9430. (vhdl-insert-keyword " GENERATE")
  9431. ; (if (not (vhdl-standard-p '87))
  9432. ; (vhdl-template-begin-end "GENERATE" label margin)
  9433. (insert "\n\n")
  9434. (indent-to margin)
  9435. (vhdl-insert-keyword "END GENERATE ")
  9436. (insert label ";")
  9437. (end-of-line 0)
  9438. (indent-to (+ margin vhdl-basic-offset)))
  9439. (defun vhdl-template-insert-date ()
  9440. "Insert date in appropriate format."
  9441. (interactive)
  9442. (insert
  9443. (cond
  9444. ;; 'american, 'european, 'scientific kept for backward compatibility
  9445. ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
  9446. ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
  9447. ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
  9448. (t (format-time-string vhdl-date-format nil)))))
  9449. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9450. ;; Help functions
  9451. (defun vhdl-electric-space (count)
  9452. "Expand abbreviations and self-insert space(s), do indent-new-comment-line
  9453. if in comment and past end-comment-column."
  9454. (interactive "p")
  9455. (cond ((vhdl-in-comment-p)
  9456. (self-insert-command count)
  9457. (cond ((>= (current-column) (+ 2 end-comment-column))
  9458. (backward-char 1)
  9459. (skip-chars-backward "^ \t\n")
  9460. (indent-new-comment-line)
  9461. (skip-chars-forward "^ \t\n")
  9462. (forward-char 1))
  9463. ((>= (current-column) end-comment-column)
  9464. (indent-new-comment-line))
  9465. (t nil)))
  9466. ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
  9467. (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
  9468. (vhdl-prepare-search-1
  9469. (or (expand-abbrev) (vhdl-fix-case-word -1)))
  9470. (self-insert-command count))
  9471. (t (self-insert-command count))))
  9472. (defun vhdl-template-field (prompt &optional follow-string optional
  9473. begin end is-string default)
  9474. "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
  9475. If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
  9476. an empty string is inserted, return nil and call `vhdl-template-undo' for
  9477. the region between BEGIN and END. IS-STRING indicates whether a string
  9478. with double-quotes is to be inserted. DEFAULT specifies a default string."
  9479. (let ((position (point))
  9480. string)
  9481. (insert "<" prompt ">")
  9482. (setq string
  9483. (condition-case ()
  9484. (read-from-minibuffer (concat prompt ": ")
  9485. (or (and is-string '("\"\"" . 2)) default)
  9486. vhdl-minibuffer-local-map)
  9487. (quit (if (and optional begin end)
  9488. (progn (beep) "")
  9489. (keyboard-quit)))))
  9490. (when (or (not (equal string "")) optional)
  9491. (delete-region position (point)))
  9492. (when (and (equal string "") optional begin end)
  9493. (vhdl-template-undo begin end)
  9494. (message "Template aborted"))
  9495. (unless (equal string "")
  9496. (insert string)
  9497. (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
  9498. vhdl-keywords-regexp)
  9499. (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
  9500. vhdl-types-regexp)
  9501. (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
  9502. (concat "'" vhdl-attributes-regexp))
  9503. (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
  9504. vhdl-enum-values-regexp))
  9505. (when (or (not (equal string "")) (not optional))
  9506. (insert (or follow-string "")))
  9507. (if (equal string "") nil string)))
  9508. (defun vhdl-decision-query (string prompt &optional optional)
  9509. "Query a decision from the user."
  9510. (let ((start (point)))
  9511. (when string (vhdl-insert-keyword (concat string " ")))
  9512. (message "%s" (or prompt ""))
  9513. (let ((char (read-char)))
  9514. (delete-region start (point))
  9515. (if (and optional (eq char ?\r))
  9516. (progn (insert " ")
  9517. (unexpand-abbrev)
  9518. (throw 'abort "ERROR: Template aborted"))
  9519. char))))
  9520. (defun vhdl-insert-keyword (keyword)
  9521. "Insert KEYWORD and adjust case."
  9522. (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
  9523. (defun vhdl-case-keyword (keyword)
  9524. "Adjust case of KEYWORD."
  9525. (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
  9526. (defun vhdl-case-word (num)
  9527. "Adjust case of following NUM words."
  9528. (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
  9529. (defun vhdl-minibuffer-tab (&optional prefix-arg)
  9530. "If preceding character is part of a word or a paren then hippie-expand,
  9531. else insert tab (used for word completion in VHDL minibuffer)."
  9532. (interactive "P")
  9533. (cond
  9534. ;; expand word
  9535. ((= (char-syntax (preceding-char)) ?w)
  9536. (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
  9537. (case-replace nil)
  9538. (hippie-expand-only-buffers
  9539. (or (and (boundp 'hippie-expand-only-buffers)
  9540. hippie-expand-only-buffers)
  9541. '(vhdl-mode))))
  9542. (vhdl-expand-abbrev prefix-arg)))
  9543. ;; expand parenthesis
  9544. ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
  9545. (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
  9546. (case-replace nil))
  9547. (vhdl-expand-paren prefix-arg)))
  9548. ;; insert tab
  9549. (t (insert-tab))))
  9550. (defun vhdl-template-search-prompt ()
  9551. "Search for left out template prompts and query again."
  9552. (interactive)
  9553. (vhdl-prepare-search-2
  9554. (when (or (re-search-forward
  9555. (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
  9556. (re-search-backward
  9557. (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
  9558. (let ((string (match-string 1)))
  9559. (replace-match "")
  9560. (vhdl-template-field string)))))
  9561. (defun vhdl-template-undo (begin end)
  9562. "Undo aborted template by deleting region and unexpanding the keyword."
  9563. (cond (vhdl-template-invoked-by-hook
  9564. (goto-char end)
  9565. (insert " ")
  9566. (delete-region begin end)
  9567. (unexpand-abbrev))
  9568. (t (delete-region begin end))))
  9569. (defun vhdl-insert-string-or-file (string)
  9570. "Insert STRING or file contents if STRING is an existing file name."
  9571. (unless (equal string "")
  9572. (let ((file-name
  9573. (progn (string-match "^\\([^\n]+\\)" string)
  9574. (vhdl-resolve-env-variable (match-string 1 string)))))
  9575. (if (file-exists-p file-name)
  9576. (forward-char (cadr (insert-file-contents file-name)))
  9577. (insert string)))))
  9578. (defun vhdl-beginning-of-block ()
  9579. "Move cursor to the beginning of the enclosing block."
  9580. (let (pos)
  9581. (save-excursion
  9582. (beginning-of-line)
  9583. ;; search backward for block beginning or end
  9584. (while (or (while (and (setq pos (re-search-backward "^\\s-*\\(\\(end\\)\\|\\(\\(impure\\|pure\\)[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(for\\)\\|\\(architecture\\|component\\|configuration\\|entity\\|package\\|record\\|units\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(postponed[ \t\n]+\\)?\\(block\\|case\\|for\\|if\\|procedural\\|process\\|while\\)\\)\\>" nil t))
  9585. ;; not consider subprogram declarations
  9586. (or (and (match-string 5)
  9587. (save-match-data
  9588. (save-excursion
  9589. (goto-char (match-end 5))
  9590. (forward-word 1)
  9591. (vhdl-forward-syntactic-ws)
  9592. (when (looking-at "(")
  9593. (forward-sexp))
  9594. (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
  9595. (match-string 1)))
  9596. ;; not consider configuration specifications
  9597. (and (match-string 6)
  9598. (save-match-data
  9599. (save-excursion
  9600. (vhdl-end-of-block)
  9601. (beginning-of-line)
  9602. (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
  9603. (match-string 2))
  9604. ;; skip subblock if block end found
  9605. (vhdl-beginning-of-block)))
  9606. (when pos (goto-char pos))))
  9607. (defun vhdl-end-of-block ()
  9608. "Move cursor to the end of the enclosing block."
  9609. (let (pos)
  9610. (save-excursion
  9611. (end-of-line)
  9612. ;; search forward for block beginning or end
  9613. (while (or (while (and (setq pos (re-search-forward "^\\s-*\\(\\(end\\)\\|\\(\\(impure\\|pure\\)[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(for\\)\\|\\(architecture\\|component\\|configuration\\|entity\\|package\\|record\\|units\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(postponed[ \t\n]+\\)?\\(block\\|case\\|for\\|if\\|procedural\\|process\\|while\\)\\)\\>" nil t))
  9614. ;; not consider subprogram declarations
  9615. (or (and (match-string 5)
  9616. (save-match-data
  9617. (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
  9618. (match-string 1)))
  9619. ;; not consider configuration specifications
  9620. (and (match-string 6)
  9621. (save-match-data
  9622. (save-excursion
  9623. (vhdl-end-of-block)
  9624. (beginning-of-line)
  9625. (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
  9626. (not (match-string 2)))
  9627. ;; skip subblock if block beginning found
  9628. (vhdl-end-of-block)))
  9629. (when pos (goto-char pos))))
  9630. (defun vhdl-sequential-statement-p ()
  9631. "Check if point is within sequential statement part."
  9632. (let ((start (point)))
  9633. (save-excursion
  9634. (vhdl-prepare-search-2
  9635. ;; is sequential statement if ...
  9636. (and (re-search-backward "^\\s-*begin\\>" nil t)
  9637. ;; ... point is between "begin" and "end" of ...
  9638. (progn (vhdl-end-of-block)
  9639. (< start (point)))
  9640. ;; ... a sequential block
  9641. (progn (vhdl-beginning-of-block)
  9642. (looking-at "^\\s-*\\(\\(\\w+[ \t\n]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n]*:[ \t\n]*\\)?\\(\\w+[ \t\n]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
  9643. (defun vhdl-in-argument-list-p ()
  9644. "Check if within an argument list."
  9645. (save-excursion
  9646. (vhdl-prepare-search-2
  9647. (or (string-match "arglist"
  9648. (format "%s" (caar (vhdl-get-syntactic-context))))
  9649. (progn (beginning-of-line)
  9650. (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
  9651. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9652. ;; Abbrev hooks
  9653. (defun vhdl-hooked-abbrev (func)
  9654. "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
  9655. but not if inside a comment or quote."
  9656. (if (or (vhdl-in-literal)
  9657. (save-excursion
  9658. (forward-word -1)
  9659. (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
  9660. (progn
  9661. (insert " ")
  9662. (unexpand-abbrev)
  9663. (delete-char -1))
  9664. (if (not vhdl-electric-mode)
  9665. (progn
  9666. (insert " ")
  9667. (unexpand-abbrev)
  9668. (backward-word 1)
  9669. (vhdl-case-word 1)
  9670. (delete-char 1))
  9671. (let ((invoke-char last-command-event)
  9672. (abbrev-mode -1)
  9673. (vhdl-template-invoked-by-hook t))
  9674. (let ((caught (catch 'abort
  9675. (funcall func))))
  9676. (when (stringp caught) (message "%s" caught)))
  9677. (when (= invoke-char ?-) (setq abbrev-start-location (point)))
  9678. ;; delete CR which is still in event queue
  9679. (if (fboundp 'enqueue-eval-event)
  9680. (enqueue-eval-event 'delete-char -1)
  9681. (setq unread-command-events ; push back a delete char
  9682. (list (vhdl-character-to-event ?\177))))))))
  9683. (defun vhdl-template-alias-hook ()
  9684. (vhdl-hooked-abbrev 'vhdl-template-alias))
  9685. (defun vhdl-template-architecture-hook ()
  9686. (vhdl-hooked-abbrev 'vhdl-template-architecture))
  9687. (defun vhdl-template-assert-hook ()
  9688. (vhdl-hooked-abbrev 'vhdl-template-assert))
  9689. (defun vhdl-template-attribute-hook ()
  9690. (vhdl-hooked-abbrev 'vhdl-template-attribute))
  9691. (defun vhdl-template-block-hook ()
  9692. (vhdl-hooked-abbrev 'vhdl-template-block))
  9693. (defun vhdl-template-break-hook ()
  9694. (vhdl-hooked-abbrev 'vhdl-template-break))
  9695. (defun vhdl-template-case-hook ()
  9696. (vhdl-hooked-abbrev 'vhdl-template-case))
  9697. (defun vhdl-template-component-hook ()
  9698. (vhdl-hooked-abbrev 'vhdl-template-component))
  9699. (defun vhdl-template-instance-hook ()
  9700. (vhdl-hooked-abbrev 'vhdl-template-instance))
  9701. (defun vhdl-template-conditional-signal-asst-hook ()
  9702. (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
  9703. (defun vhdl-template-configuration-hook ()
  9704. (vhdl-hooked-abbrev 'vhdl-template-configuration))
  9705. (defun vhdl-template-constant-hook ()
  9706. (vhdl-hooked-abbrev 'vhdl-template-constant))
  9707. (defun vhdl-template-disconnect-hook ()
  9708. (vhdl-hooked-abbrev 'vhdl-template-disconnect))
  9709. (defun vhdl-template-display-comment-hook ()
  9710. (vhdl-hooked-abbrev 'vhdl-comment-display))
  9711. (defun vhdl-template-else-hook ()
  9712. (vhdl-hooked-abbrev 'vhdl-template-else))
  9713. (defun vhdl-template-elsif-hook ()
  9714. (vhdl-hooked-abbrev 'vhdl-template-elsif))
  9715. (defun vhdl-template-entity-hook ()
  9716. (vhdl-hooked-abbrev 'vhdl-template-entity))
  9717. (defun vhdl-template-exit-hook ()
  9718. (vhdl-hooked-abbrev 'vhdl-template-exit))
  9719. (defun vhdl-template-file-hook ()
  9720. (vhdl-hooked-abbrev 'vhdl-template-file))
  9721. (defun vhdl-template-for-hook ()
  9722. (vhdl-hooked-abbrev 'vhdl-template-for))
  9723. (defun vhdl-template-function-hook ()
  9724. (vhdl-hooked-abbrev 'vhdl-template-function))
  9725. (defun vhdl-template-generic-hook ()
  9726. (vhdl-hooked-abbrev 'vhdl-template-generic))
  9727. (defun vhdl-template-group-hook ()
  9728. (vhdl-hooked-abbrev 'vhdl-template-group))
  9729. (defun vhdl-template-library-hook ()
  9730. (vhdl-hooked-abbrev 'vhdl-template-library))
  9731. (defun vhdl-template-limit-hook ()
  9732. (vhdl-hooked-abbrev 'vhdl-template-limit))
  9733. (defun vhdl-template-if-hook ()
  9734. (vhdl-hooked-abbrev 'vhdl-template-if))
  9735. (defun vhdl-template-bare-loop-hook ()
  9736. (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
  9737. (defun vhdl-template-map-hook ()
  9738. (vhdl-hooked-abbrev 'vhdl-template-map))
  9739. (defun vhdl-template-nature-hook ()
  9740. (vhdl-hooked-abbrev 'vhdl-template-nature))
  9741. (defun vhdl-template-next-hook ()
  9742. (vhdl-hooked-abbrev 'vhdl-template-next))
  9743. (defun vhdl-template-others-hook ()
  9744. (vhdl-hooked-abbrev 'vhdl-template-others))
  9745. (defun vhdl-template-package-hook ()
  9746. (vhdl-hooked-abbrev 'vhdl-template-package))
  9747. (defun vhdl-template-port-hook ()
  9748. (vhdl-hooked-abbrev 'vhdl-template-port))
  9749. (defun vhdl-template-procedural-hook ()
  9750. (vhdl-hooked-abbrev 'vhdl-template-procedural))
  9751. (defun vhdl-template-procedure-hook ()
  9752. (vhdl-hooked-abbrev 'vhdl-template-procedure))
  9753. (defun vhdl-template-process-hook ()
  9754. (vhdl-hooked-abbrev 'vhdl-template-process))
  9755. (defun vhdl-template-quantity-hook ()
  9756. (vhdl-hooked-abbrev 'vhdl-template-quantity))
  9757. (defun vhdl-template-report-hook ()
  9758. (vhdl-hooked-abbrev 'vhdl-template-report))
  9759. (defun vhdl-template-return-hook ()
  9760. (vhdl-hooked-abbrev 'vhdl-template-return))
  9761. (defun vhdl-template-selected-signal-asst-hook ()
  9762. (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
  9763. (defun vhdl-template-signal-hook ()
  9764. (vhdl-hooked-abbrev 'vhdl-template-signal))
  9765. (defun vhdl-template-subnature-hook ()
  9766. (vhdl-hooked-abbrev 'vhdl-template-subnature))
  9767. (defun vhdl-template-subtype-hook ()
  9768. (vhdl-hooked-abbrev 'vhdl-template-subtype))
  9769. (defun vhdl-template-terminal-hook ()
  9770. (vhdl-hooked-abbrev 'vhdl-template-terminal))
  9771. (defun vhdl-template-type-hook ()
  9772. (vhdl-hooked-abbrev 'vhdl-template-type))
  9773. (defun vhdl-template-use-hook ()
  9774. (vhdl-hooked-abbrev 'vhdl-template-use))
  9775. (defun vhdl-template-variable-hook ()
  9776. (vhdl-hooked-abbrev 'vhdl-template-variable))
  9777. (defun vhdl-template-wait-hook ()
  9778. (vhdl-hooked-abbrev 'vhdl-template-wait))
  9779. (defun vhdl-template-when-hook ()
  9780. (vhdl-hooked-abbrev 'vhdl-template-when))
  9781. (defun vhdl-template-while-loop-hook ()
  9782. (vhdl-hooked-abbrev 'vhdl-template-while-loop))
  9783. (defun vhdl-template-with-hook ()
  9784. (vhdl-hooked-abbrev 'vhdl-template-with))
  9785. (defun vhdl-template-and-hook ()
  9786. (vhdl-hooked-abbrev 'vhdl-template-and))
  9787. (defun vhdl-template-or-hook ()
  9788. (vhdl-hooked-abbrev 'vhdl-template-or))
  9789. (defun vhdl-template-nand-hook ()
  9790. (vhdl-hooked-abbrev 'vhdl-template-nand))
  9791. (defun vhdl-template-nor-hook ()
  9792. (vhdl-hooked-abbrev 'vhdl-template-nor))
  9793. (defun vhdl-template-xor-hook ()
  9794. (vhdl-hooked-abbrev 'vhdl-template-xor))
  9795. (defun vhdl-template-xnor-hook ()
  9796. (vhdl-hooked-abbrev 'vhdl-template-xnor))
  9797. (defun vhdl-template-not-hook ()
  9798. (vhdl-hooked-abbrev 'vhdl-template-not))
  9799. (defun vhdl-template-default-hook ()
  9800. (vhdl-hooked-abbrev 'vhdl-template-default))
  9801. (defun vhdl-template-default-indent-hook ()
  9802. (vhdl-hooked-abbrev 'vhdl-template-default-indent))
  9803. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9804. ;; Template insertion from completion list
  9805. (defun vhdl-template-insert-construct (name)
  9806. "Insert the built-in construct template with NAME."
  9807. (interactive
  9808. (list (let ((completion-ignore-case t))
  9809. (completing-read "Construct name: "
  9810. vhdl-template-construct-alist nil t))))
  9811. (vhdl-template-insert-fun
  9812. (cadr (assoc name vhdl-template-construct-alist))))
  9813. (defun vhdl-template-insert-package (name)
  9814. "Insert the built-in package template with NAME."
  9815. (interactive
  9816. (list (let ((completion-ignore-case t))
  9817. (completing-read "Package name: "
  9818. vhdl-template-package-alist nil t))))
  9819. (vhdl-template-insert-fun
  9820. (cadr (assoc name vhdl-template-package-alist))))
  9821. (defun vhdl-template-insert-directive (name)
  9822. "Insert the built-in directive template with NAME."
  9823. (interactive
  9824. (list (let ((completion-ignore-case t))
  9825. (completing-read "Directive name: "
  9826. vhdl-template-directive-alist nil t))))
  9827. (vhdl-template-insert-fun
  9828. (cadr (assoc name vhdl-template-directive-alist))))
  9829. (defun vhdl-template-insert-fun (fun)
  9830. "Call FUN to insert a built-in template."
  9831. (let ((caught (catch 'abort (when fun (funcall fun)))))
  9832. (when (stringp caught) (message "%s" caught))))
  9833. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9834. ;;; Models
  9835. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9836. (defun vhdl-model-insert (model-name)
  9837. "Insert the user model with name MODEL-NAME."
  9838. (interactive
  9839. (let ((completion-ignore-case t))
  9840. (list (completing-read "Model name: " vhdl-model-alist))))
  9841. (indent-according-to-mode)
  9842. (let ((start (point-marker))
  9843. (margin (current-indentation))
  9844. model position prompt string end)
  9845. (vhdl-prepare-search-2
  9846. (when (setq model (assoc model-name vhdl-model-alist))
  9847. ;; insert model
  9848. (beginning-of-line)
  9849. (delete-horizontal-space)
  9850. (goto-char start)
  9851. (vhdl-insert-string-or-file (nth 1 model))
  9852. (setq end (point-marker))
  9853. ;; indent code
  9854. (goto-char start)
  9855. (beginning-of-line)
  9856. (while (< (point) end)
  9857. (unless (looking-at "^$")
  9858. (insert-char ? margin))
  9859. (beginning-of-line 2))
  9860. (goto-char start)
  9861. ;; insert clock
  9862. (unless (equal "" vhdl-clock-name)
  9863. (while (re-search-forward "<clock>" end t)
  9864. (replace-match vhdl-clock-name)))
  9865. (goto-char start)
  9866. ;; insert reset
  9867. (unless (equal "" vhdl-reset-name)
  9868. (while (re-search-forward "<reset>" end t)
  9869. (replace-match vhdl-reset-name)))
  9870. ;; replace header prompts
  9871. (vhdl-template-replace-header-keywords start end nil t)
  9872. (goto-char start)
  9873. ;; query other prompts
  9874. (while (re-search-forward
  9875. (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
  9876. (unless (equal "cursor" (match-string 1))
  9877. (setq position (match-beginning 1))
  9878. (setq prompt (match-string 1))
  9879. (replace-match "")
  9880. (setq string (vhdl-template-field prompt nil t))
  9881. ;; replace occurrences of same prompt
  9882. (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
  9883. (replace-match (or string "")))
  9884. (goto-char position)))
  9885. (goto-char start)
  9886. ;; goto final position
  9887. (if (re-search-forward "<cursor>" end t)
  9888. (replace-match "")
  9889. (goto-char end))))))
  9890. (defun vhdl-model-defun ()
  9891. "Define help and hook functions for user models."
  9892. (let ((model-alist vhdl-model-alist)
  9893. model-name model-keyword)
  9894. (while model-alist
  9895. ;; define functions for user models that can be invoked from menu and key
  9896. ;; bindings and which themselves call `vhdl-model-insert' with the model
  9897. ;; name as argument
  9898. (setq model-name (nth 0 (car model-alist)))
  9899. (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
  9900. ,(concat "Insert model for \"" model-name "\".")
  9901. (interactive)
  9902. (vhdl-model-insert ,model-name)))
  9903. ;; define hooks for user models that are invoked from keyword abbrevs
  9904. (setq model-keyword (nth 3 (car model-alist)))
  9905. (unless (equal model-keyword "")
  9906. (eval `(defun
  9907. ,(vhdl-function-name
  9908. "vhdl-model" model-name "hook") ()
  9909. (vhdl-hooked-abbrev
  9910. ',(vhdl-function-name "vhdl-model" model-name)))))
  9911. (setq model-alist (cdr model-alist)))))
  9912. (vhdl-model-defun)
  9913. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9914. ;;; Port translation
  9915. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9916. (defvar vhdl-port-list nil
  9917. "Variable to hold last port map parsed.")
  9918. ;; structure: (parenthesized expression means list of such entries)
  9919. ;; (ent-name
  9920. ;; ((generic-names) generic-type generic-init generic-comment group-comment)
  9921. ;; ((port-names) port-object port-direct port-type port-comment group-comment)
  9922. ;; (lib-name pack-key))
  9923. (defun vhdl-parse-string (string &optional optional)
  9924. "Check that the text following point matches the regexp in STRING."
  9925. (if (looking-at string)
  9926. (goto-char (match-end 0))
  9927. (unless optional
  9928. (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
  9929. (vhdl-current-line) string)))
  9930. nil))
  9931. (defun vhdl-replace-string (regexp-cons string &optional adjust-case)
  9932. "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
  9933. (vhdl-prepare-search-1
  9934. (if (string-match (car regexp-cons) string)
  9935. (if adjust-case
  9936. (funcall vhdl-file-name-case
  9937. (replace-match (cdr regexp-cons) t nil string))
  9938. (replace-match (cdr regexp-cons) t nil string))
  9939. string)))
  9940. (defun vhdl-parse-group-comment ()
  9941. "Parse comment and empty lines between groups of lines."
  9942. (let ((start (point))
  9943. string)
  9944. (vhdl-forward-comment (point-max))
  9945. (setq string (buffer-substring-no-properties start (point)))
  9946. (vhdl-forward-syntactic-ws)
  9947. ;; strip off leading blanks and first newline
  9948. (while (string-match "^\\(\\s-+\\)" string)
  9949. (setq string (concat (substring string 0 (match-beginning 1))
  9950. (substring string (match-end 1)))))
  9951. (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
  9952. (substring string 1)
  9953. string)))
  9954. (defun vhdl-paste-group-comment (string indent)
  9955. "Paste comment and empty lines from STRING between groups of lines
  9956. with INDENT."
  9957. (let ((pos (point-marker)))
  9958. (when (> indent 0)
  9959. (while (string-match "^\\(--\\)" string)
  9960. (setq string (concat (substring string 0 (match-beginning 1))
  9961. (make-string indent ? )
  9962. (substring string (match-beginning 1))))))
  9963. (beginning-of-line)
  9964. (insert string)
  9965. (goto-char pos)))
  9966. (defvar vhdl-port-flattened nil
  9967. "Indicates whether a port has been flattened.")
  9968. (defun vhdl-port-flatten (&optional as-alist)
  9969. "Flatten port list so that only one generic/port exists per line.
  9970. This operation is performed on an internally stored port and is only
  9971. reflected in a subsequent paste operation."
  9972. (interactive)
  9973. (if (not vhdl-port-list)
  9974. (error "ERROR: No port has been read")
  9975. (message "Flattening port for next paste...")
  9976. (let ((new-vhdl-port-list (list (car vhdl-port-list)))
  9977. (old-vhdl-port-list (cdr vhdl-port-list))
  9978. old-port-list new-port-list old-port new-port names)
  9979. ;; traverse port list and flatten entries
  9980. (while (cdr old-vhdl-port-list)
  9981. (setq old-port-list (car old-vhdl-port-list))
  9982. (setq new-port-list nil)
  9983. (while old-port-list
  9984. (setq old-port (car old-port-list))
  9985. (setq names (car old-port))
  9986. (while names
  9987. (setq new-port (cons (if as-alist (car names) (list (car names)))
  9988. (cdr old-port)))
  9989. (setq new-port-list (append new-port-list (list new-port)))
  9990. (setq names (cdr names)))
  9991. (setq old-port-list (cdr old-port-list)))
  9992. (setq old-vhdl-port-list (cdr old-vhdl-port-list))
  9993. (setq new-vhdl-port-list (append new-vhdl-port-list
  9994. (list new-port-list))))
  9995. (setq vhdl-port-list
  9996. (append new-vhdl-port-list (list old-vhdl-port-list))
  9997. vhdl-port-flattened t)
  9998. (message "Flattening port for next paste...done"))))
  9999. (defvar vhdl-port-reversed-direction nil
  10000. "Indicates whether port directions are reversed.")
  10001. (defun vhdl-port-reverse-direction ()
  10002. "Reverse direction for all ports (useful in testbenches).
  10003. This operation is performed on an internally stored port and is only
  10004. reflected in a subsequent paste operation."
  10005. (interactive)
  10006. (if (not vhdl-port-list)
  10007. (error "ERROR: No port has been read")
  10008. (message "Reversing port directions for next paste...")
  10009. (let ((port-list (nth 2 vhdl-port-list))
  10010. port-dir-car port-dir)
  10011. ;; traverse port list and reverse directions
  10012. (while port-list
  10013. (setq port-dir-car (cddr (car port-list))
  10014. port-dir (car port-dir-car))
  10015. (setcar port-dir-car
  10016. (cond ((equal port-dir "in") "out")
  10017. ((equal port-dir "out") "in")
  10018. (t port-dir)))
  10019. (setq port-list (cdr port-list)))
  10020. (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
  10021. (message "Reversing port directions for next paste...done"))))
  10022. (defun vhdl-port-copy ()
  10023. "Get generic and port information from an entity or component declaration."
  10024. (interactive)
  10025. (save-excursion
  10026. (let (parse-error end-of-list
  10027. decl-type name generic-list port-list context-clause
  10028. object names direct type init comment group-comment)
  10029. (vhdl-prepare-search-2
  10030. (setq
  10031. parse-error
  10032. (catch 'parse
  10033. ;; check if within entity or component declaration
  10034. (end-of-line)
  10035. (when (or (not (re-search-backward
  10036. "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
  10037. (equal "END" (upcase (match-string 1))))
  10038. (throw 'parse "ERROR: Not within an entity or component declaration"))
  10039. (setq decl-type (downcase (match-string-no-properties 1)))
  10040. (forward-word 1)
  10041. (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
  10042. (setq name (match-string-no-properties 1))
  10043. (message "Reading port of %s \"%s\"..." decl-type name)
  10044. (vhdl-forward-syntactic-ws)
  10045. ;; parse generic clause
  10046. (when (vhdl-parse-string "generic[ \t\n]*(" t)
  10047. ;; parse group comment and spacing
  10048. (setq group-comment (vhdl-parse-group-comment))
  10049. (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
  10050. (while (not end-of-list)
  10051. ;; parse names (accept extended identifiers)
  10052. (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
  10053. (setq names (list (match-string-no-properties 1)))
  10054. (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\)[ \t\n]*" t)
  10055. (setq names
  10056. (append names (list (match-string-no-properties 1)))))
  10057. ;; parse type
  10058. (vhdl-parse-string ":[ \t\n]*\\([^():;\n]+\\)")
  10059. (setq type (match-string-no-properties 1))
  10060. (setq comment nil)
  10061. (while (looking-at "(")
  10062. (setq type
  10063. (concat type
  10064. (buffer-substring-no-properties
  10065. (point) (progn (forward-sexp) (point)))
  10066. (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
  10067. (match-string-no-properties 1)))))
  10068. ;; special case: closing parenthesis is on separate line
  10069. (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
  10070. (setq comment (substring type (match-beginning 2)))
  10071. (setq type (substring type 0 (match-beginning 1))))
  10072. ;; strip of trailing group-comment
  10073. (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
  10074. (setq type (substring type 0 (match-end 1)))
  10075. ;; parse initialization expression
  10076. (setq init nil)
  10077. (when (vhdl-parse-string ":=[ \t\n]*" t)
  10078. (vhdl-parse-string "\\([^();\n]*\\)")
  10079. (setq init (match-string-no-properties 1))
  10080. (while (looking-at "(")
  10081. (setq init
  10082. (concat init
  10083. (buffer-substring-no-properties
  10084. (point) (progn (forward-sexp) (point)))
  10085. (and (vhdl-parse-string "\\([^();\n]*\\)" t)
  10086. (match-string-no-properties 1))))))
  10087. ;; special case: closing parenthesis is on separate line
  10088. (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
  10089. (setq comment (substring init (match-beginning 2)))
  10090. (setq init (substring init 0 (match-beginning 1)))
  10091. (vhdl-forward-syntactic-ws))
  10092. (skip-chars-forward " \t")
  10093. ;; parse inline comment, special case: as above, no initial.
  10094. (unless comment
  10095. (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
  10096. (match-string-no-properties 1))))
  10097. (vhdl-forward-syntactic-ws)
  10098. (setq end-of-list (vhdl-parse-string ")" t))
  10099. (vhdl-parse-string "\\s-*;\\s-*")
  10100. ;; parse inline comment
  10101. (unless comment
  10102. (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
  10103. (match-string-no-properties 1))))
  10104. ;; save everything in list
  10105. (setq generic-list (append generic-list
  10106. (list (list names type init
  10107. comment group-comment))))
  10108. ;; parse group comment and spacing
  10109. (setq group-comment (vhdl-parse-group-comment))))
  10110. ;; parse port clause
  10111. (when (vhdl-parse-string "port[ \t\n]*(" t)
  10112. ;; parse group comment and spacing
  10113. (setq group-comment (vhdl-parse-group-comment))
  10114. (setq end-of-list (vhdl-parse-string ")[ \t\n]*;[ \t\n]*" t))
  10115. (while (not end-of-list)
  10116. ;; parse object
  10117. (setq object
  10118. (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n]*" t)
  10119. (match-string-no-properties 1)))
  10120. ;; parse names (accept extended identifiers)
  10121. (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
  10122. (setq names (list (match-string-no-properties 1)))
  10123. (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
  10124. (setq names (append names (list (match-string-no-properties 1)))))
  10125. ;; parse direction
  10126. (vhdl-parse-string ":[ \t\n]*")
  10127. (setq direct
  10128. (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n]+" t)
  10129. (match-string-no-properties 1)))
  10130. ;; parse type
  10131. (vhdl-parse-string "\\([^();\n]+\\)")
  10132. (setq type (match-string-no-properties 1))
  10133. (setq comment nil)
  10134. (while (looking-at "(")
  10135. (setq type (concat type
  10136. (buffer-substring-no-properties
  10137. (point) (progn (forward-sexp) (point)))
  10138. (and (vhdl-parse-string "\\([^();\n]*\\)" t)
  10139. (match-string-no-properties 1)))))
  10140. ;; special case: closing parenthesis is on separate line
  10141. (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
  10142. (setq comment (substring type (match-beginning 2)))
  10143. (setq type (substring type 0 (match-beginning 1))))
  10144. ;; strip of trailing group-comment
  10145. (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
  10146. (setq type (substring type 0 (match-end 1)))
  10147. (vhdl-forward-syntactic-ws)
  10148. (setq end-of-list (vhdl-parse-string ")" t))
  10149. (vhdl-parse-string "\\s-*;\\s-*")
  10150. ;; parse inline comment
  10151. (unless comment
  10152. (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
  10153. (match-string-no-properties 1))))
  10154. ;; save everything in list
  10155. (setq port-list (append port-list
  10156. (list (list names object direct type
  10157. comment group-comment))))
  10158. ;; parse group comment and spacing
  10159. (setq group-comment (vhdl-parse-group-comment))))
  10160. ; (vhdl-parse-string "end\\>")
  10161. ;; parse context clause
  10162. (setq context-clause (vhdl-scan-context-clause))
  10163. ; ;; add surrounding package to context clause
  10164. ; (when (and (equal decl-type "component")
  10165. ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
  10166. ; (setq context-clause
  10167. ; (append context-clause
  10168. ; (list (cons (vhdl-work-library)
  10169. ; (match-string-no-properties 1))))))
  10170. (message "Reading port of %s \"%s\"...done" decl-type name)
  10171. nil)))
  10172. ;; finish parsing
  10173. (if parse-error
  10174. (error parse-error)
  10175. (setq vhdl-port-list (list name generic-list port-list context-clause)
  10176. vhdl-port-reversed-direction nil
  10177. vhdl-port-flattened nil)))))
  10178. (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
  10179. "Paste a context clause."
  10180. (let ((margin (current-indentation))
  10181. (clause-list (nth 3 vhdl-port-list))
  10182. clause)
  10183. (while clause-list
  10184. (setq clause (car clause-list))
  10185. (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
  10186. (downcase exclude-pack-name)))
  10187. (save-excursion
  10188. (re-search-backward
  10189. (concat "^\\s-*use\\s-+" (car clause)
  10190. "\." (cdr clause) "\\>") nil t)))
  10191. (vhdl-template-standard-package (car clause) (cdr clause))
  10192. (insert "\n"))
  10193. (setq clause-list (cdr clause-list)))))
  10194. (defun vhdl-port-paste-generic (&optional no-init)
  10195. "Paste a generic clause."
  10196. (let ((margin (current-indentation))
  10197. (generic-list (nth 1 vhdl-port-list))
  10198. list-margin start names generic)
  10199. ;; paste generic clause
  10200. (when generic-list
  10201. (setq start (point))
  10202. (vhdl-insert-keyword "GENERIC (")
  10203. (unless vhdl-argument-list-indent
  10204. (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
  10205. (setq list-margin (current-column))
  10206. (while generic-list
  10207. (setq generic (car generic-list))
  10208. ;; paste group comment and spacing
  10209. (when (memq vhdl-include-group-comments '(decl always))
  10210. (vhdl-paste-group-comment (nth 4 generic) list-margin))
  10211. ;; paste names
  10212. (setq names (nth 0 generic))
  10213. (while names
  10214. (insert (car names))
  10215. (setq names (cdr names))
  10216. (when names (insert ", ")))
  10217. ;; paste type
  10218. (insert " : " (nth 1 generic))
  10219. ;; paste initialization
  10220. (when (and (not no-init) (nth 2 generic))
  10221. (insert " := " (nth 2 generic)))
  10222. (unless (cdr generic-list) (insert ")"))
  10223. (insert ";")
  10224. ;; paste comment
  10225. (when (and vhdl-include-port-comments (nth 3 generic))
  10226. (vhdl-comment-insert-inline (nth 3 generic) t))
  10227. (setq generic-list (cdr generic-list))
  10228. (when generic-list (insert "\n") (indent-to list-margin)))
  10229. ;; align generic clause
  10230. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
  10231. (defun vhdl-port-paste-port ()
  10232. "Paste a port clause."
  10233. (let ((margin (current-indentation))
  10234. (port-list (nth 2 vhdl-port-list))
  10235. list-margin start names port)
  10236. ;; paste port clause
  10237. (when port-list
  10238. (setq start (point))
  10239. (vhdl-insert-keyword "PORT (")
  10240. (unless vhdl-argument-list-indent
  10241. (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
  10242. (setq list-margin (current-column))
  10243. (while port-list
  10244. (setq port (car port-list))
  10245. ;; paste group comment and spacing
  10246. (when (memq vhdl-include-group-comments '(decl always))
  10247. (vhdl-paste-group-comment (nth 5 port) list-margin))
  10248. ;; paste object
  10249. (when (nth 1 port) (insert (nth 1 port) " "))
  10250. ;; paste names
  10251. (setq names (nth 0 port))
  10252. (while names
  10253. (insert (car names))
  10254. (setq names (cdr names))
  10255. (when names (insert ", ")))
  10256. ;; paste direction
  10257. (insert " : ")
  10258. (when (nth 2 port) (insert (nth 2 port) " "))
  10259. ;; paste type
  10260. (insert (nth 3 port))
  10261. (unless (cdr port-list) (insert ")"))
  10262. (insert ";")
  10263. ;; paste comment
  10264. (when (and vhdl-include-port-comments (nth 4 port))
  10265. (vhdl-comment-insert-inline (nth 4 port) t))
  10266. (setq port-list (cdr port-list))
  10267. (when port-list (insert "\n") (indent-to list-margin)))
  10268. ;; align port clause
  10269. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
  10270. (defun vhdl-port-paste-declaration (kind &optional no-indent)
  10271. "Paste as an entity or component declaration."
  10272. (unless no-indent (indent-according-to-mode))
  10273. (let ((margin (current-indentation))
  10274. (name (nth 0 vhdl-port-list)))
  10275. (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
  10276. (insert name)
  10277. (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
  10278. (vhdl-insert-keyword " IS"))
  10279. ;; paste generic and port clause
  10280. (when (nth 1 vhdl-port-list)
  10281. (insert "\n")
  10282. (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
  10283. (insert "\n"))
  10284. (indent-to (+ margin vhdl-basic-offset))
  10285. (vhdl-port-paste-generic (eq kind 'component)))
  10286. (when (nth 2 vhdl-port-list)
  10287. (insert "\n")
  10288. (when (and (memq vhdl-insert-empty-lines '(unit all))
  10289. (eq kind 'entity))
  10290. (insert "\n"))
  10291. (indent-to (+ margin vhdl-basic-offset)))
  10292. (vhdl-port-paste-port)
  10293. (insert "\n")
  10294. (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
  10295. (insert "\n"))
  10296. (indent-to margin)
  10297. (vhdl-insert-keyword "END")
  10298. (if (eq kind 'entity)
  10299. (progn
  10300. (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
  10301. (insert " " name))
  10302. (vhdl-insert-keyword " COMPONENT")
  10303. (unless (vhdl-standard-p '87) (insert " " name)))
  10304. (insert ";")))
  10305. (defun vhdl-port-paste-entity (&optional no-indent)
  10306. "Paste as an entity declaration."
  10307. (interactive)
  10308. (if (not vhdl-port-list)
  10309. (error "ERROR: No port read")
  10310. (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
  10311. (vhdl-port-paste-declaration 'entity no-indent)
  10312. (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
  10313. (defun vhdl-port-paste-component (&optional no-indent)
  10314. "Paste as a component declaration."
  10315. (interactive)
  10316. (if (not vhdl-port-list)
  10317. (error "ERROR: No port read")
  10318. (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
  10319. (vhdl-port-paste-declaration 'component no-indent)
  10320. (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
  10321. (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
  10322. "Paste as a generic map."
  10323. (interactive)
  10324. (unless secondary (indent-according-to-mode))
  10325. (let ((margin (current-indentation))
  10326. list-margin start generic
  10327. (generic-list (nth 1 vhdl-port-list)))
  10328. (when generic-list
  10329. (setq start (point))
  10330. (vhdl-insert-keyword "GENERIC MAP (")
  10331. (if (not vhdl-association-list-with-formals)
  10332. ;; paste list of actual generics
  10333. (while generic-list
  10334. (insert (if no-constants
  10335. (car (nth 0 (car generic-list)))
  10336. (or (nth 2 (car generic-list)) " ")))
  10337. (setq generic-list (cdr generic-list))
  10338. (insert (if generic-list ", " ")"))
  10339. (when (and (not generic-list) secondary
  10340. (null (nth 2 vhdl-port-list)))
  10341. (insert ";")))
  10342. (unless vhdl-argument-list-indent
  10343. (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
  10344. (setq list-margin (current-column))
  10345. (while generic-list
  10346. (setq generic (car generic-list))
  10347. ;; paste group comment and spacing
  10348. (when (eq vhdl-include-group-comments 'always)
  10349. (vhdl-paste-group-comment (nth 4 generic) list-margin))
  10350. ;; paste formal and actual generic
  10351. (insert (car (nth 0 generic)) " => "
  10352. (if no-constants
  10353. (car (nth 0 generic))
  10354. (or (nth 2 generic) "")))
  10355. (setq generic-list (cdr generic-list))
  10356. (insert (if generic-list "," ")"))
  10357. (when (and (not generic-list) secondary
  10358. (null (nth 2 vhdl-port-list)))
  10359. (insert ";"))
  10360. ;; paste comment
  10361. (when (or vhdl-include-type-comments
  10362. (and vhdl-include-port-comments (nth 3 generic)))
  10363. (vhdl-comment-insert-inline
  10364. (concat
  10365. (when vhdl-include-type-comments
  10366. (concat "[" (nth 1 generic) "] "))
  10367. (when vhdl-include-port-comments (nth 3 generic))) t))
  10368. (when generic-list (insert "\n") (indent-to list-margin)))
  10369. ;; align generic map
  10370. (when vhdl-auto-align
  10371. (vhdl-align-region-groups start (point) 1 t))))))
  10372. (defun vhdl-port-paste-port-map ()
  10373. "Paste as a port map."
  10374. (let ((margin (current-indentation))
  10375. list-margin start port
  10376. (port-list (nth 2 vhdl-port-list)))
  10377. (when port-list
  10378. (setq start (point))
  10379. (vhdl-insert-keyword "PORT MAP (")
  10380. (if (not vhdl-association-list-with-formals)
  10381. ;; paste list of actual ports
  10382. (while port-list
  10383. (insert (vhdl-replace-string vhdl-actual-port-name
  10384. (car (nth 0 (car port-list)))))
  10385. (setq port-list (cdr port-list))
  10386. (insert (if port-list ", " ")")))
  10387. (unless vhdl-argument-list-indent
  10388. (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
  10389. (setq list-margin (current-column))
  10390. (while port-list
  10391. (setq port (car port-list))
  10392. ;; paste group comment and spacing
  10393. (when (eq vhdl-include-group-comments 'always)
  10394. (vhdl-paste-group-comment (nth 5 port) list-margin))
  10395. ;; paste formal and actual port
  10396. (insert (car (nth 0 port)) " => ")
  10397. (insert (vhdl-replace-string vhdl-actual-port-name
  10398. (car (nth 0 port))))
  10399. (setq port-list (cdr port-list))
  10400. (insert (if port-list "," ");"))
  10401. ;; paste comment
  10402. (when (or vhdl-include-direction-comments
  10403. vhdl-include-type-comments
  10404. (and vhdl-include-port-comments (nth 4 port)))
  10405. (vhdl-comment-insert-inline
  10406. (concat
  10407. (cond ((and vhdl-include-direction-comments
  10408. vhdl-include-type-comments)
  10409. (concat "[" (format "%-4s" (concat (nth 2 port) " "))
  10410. (nth 3 port) "] "))
  10411. ((and vhdl-include-direction-comments (nth 2 port))
  10412. (format "%-6s" (concat "[" (nth 2 port) "] ")))
  10413. (vhdl-include-direction-comments " ")
  10414. (vhdl-include-type-comments
  10415. (concat "[" (nth 3 port) "] ")))
  10416. (when vhdl-include-port-comments (nth 4 port))) t))
  10417. (when port-list (insert "\n") (indent-to list-margin)))
  10418. ;; align port clause
  10419. (when vhdl-auto-align
  10420. (vhdl-align-region-groups start (point) 1))))))
  10421. (defun vhdl-port-paste-instance (&optional name no-indent title)
  10422. "Paste as an instantiation."
  10423. (interactive)
  10424. (if (not vhdl-port-list)
  10425. (error "ERROR: No port read")
  10426. (let ((orig-vhdl-port-list vhdl-port-list))
  10427. ;; flatten local copy of port list (must be flat for port mapping)
  10428. (vhdl-port-flatten)
  10429. (unless no-indent (indent-according-to-mode))
  10430. (let ((margin (current-indentation)))
  10431. ;; paste instantiation
  10432. (cond (name
  10433. (insert name))
  10434. ((equal (cdr vhdl-instance-name) "")
  10435. (setq name (vhdl-template-field "instance name")))
  10436. ((string-match "\%d" (cdr vhdl-instance-name))
  10437. (let ((n 1))
  10438. (while (save-excursion
  10439. (setq name (format (vhdl-replace-string
  10440. vhdl-instance-name
  10441. (nth 0 vhdl-port-list)) n))
  10442. (goto-char (point-min))
  10443. (vhdl-re-search-forward name nil t))
  10444. (setq n (1+ n)))
  10445. (insert name)))
  10446. (t (insert (vhdl-replace-string vhdl-instance-name
  10447. (nth 0 vhdl-port-list)))))
  10448. (message "Pasting port as instantiation \"%s\"..." name)
  10449. (insert ": ")
  10450. (when title
  10451. (save-excursion
  10452. (beginning-of-line)
  10453. (indent-to vhdl-basic-offset)
  10454. (insert "-- instance \"" name "\"\n")))
  10455. (if (not (vhdl-use-direct-instantiation))
  10456. (insert (nth 0 vhdl-port-list))
  10457. (vhdl-insert-keyword "ENTITY ")
  10458. (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
  10459. (when (nth 1 vhdl-port-list)
  10460. (insert "\n") (indent-to (+ margin vhdl-basic-offset))
  10461. (vhdl-port-paste-generic-map t t))
  10462. (when (nth 2 vhdl-port-list)
  10463. (insert "\n") (indent-to (+ margin vhdl-basic-offset))
  10464. (vhdl-port-paste-port-map))
  10465. (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
  10466. (insert ";"))
  10467. (message "Pasting port as instantiation \"%s\"...done" name))
  10468. (setq vhdl-port-list orig-vhdl-port-list))))
  10469. (defun vhdl-port-paste-constants (&optional no-indent)
  10470. "Paste generics as constants."
  10471. (interactive)
  10472. (if (not vhdl-port-list)
  10473. (error "ERROR: No port read")
  10474. (let ((orig-vhdl-port-list vhdl-port-list))
  10475. (message "Pasting port as constants...")
  10476. ;; flatten local copy of port list (must be flat for constant initial.)
  10477. (vhdl-port-flatten)
  10478. (unless no-indent (indent-according-to-mode))
  10479. (let ((margin (current-indentation))
  10480. start generic name
  10481. (generic-list (nth 1 vhdl-port-list)))
  10482. (when generic-list
  10483. (setq start (point))
  10484. (while generic-list
  10485. (setq generic (car generic-list))
  10486. ;; paste group comment and spacing
  10487. (when (memq vhdl-include-group-comments '(decl always))
  10488. (vhdl-paste-group-comment (nth 4 generic) margin))
  10489. (vhdl-insert-keyword "CONSTANT ")
  10490. ;; paste generic constants
  10491. (setq name (nth 0 generic))
  10492. (when name
  10493. (insert (car name))
  10494. ;; paste type
  10495. (insert " : " (nth 1 generic))
  10496. ;; paste initialization
  10497. (when (nth 2 generic)
  10498. (insert " := " (nth 2 generic)))
  10499. (insert ";")
  10500. ;; paste comment
  10501. (when (and vhdl-include-port-comments (nth 3 generic))
  10502. (vhdl-comment-insert-inline (nth 3 generic) t))
  10503. (setq generic-list (cdr generic-list))
  10504. (when generic-list (insert "\n") (indent-to margin))))
  10505. ;; align signal list
  10506. (when vhdl-auto-align
  10507. (vhdl-align-region-groups start (point) 1))))
  10508. (message "Pasting port as constants...done")
  10509. (setq vhdl-port-list orig-vhdl-port-list))))
  10510. (defun vhdl-port-paste-signals (&optional initialize no-indent)
  10511. "Paste ports as internal signals."
  10512. (interactive)
  10513. (if (not vhdl-port-list)
  10514. (error "ERROR: No port read")
  10515. (message "Pasting port as signals...")
  10516. (unless no-indent (indent-according-to-mode))
  10517. (let ((margin (current-indentation))
  10518. start port names
  10519. (port-list (nth 2 vhdl-port-list)))
  10520. (when port-list
  10521. (setq start (point))
  10522. (while port-list
  10523. (setq port (car port-list))
  10524. ;; paste group comment and spacing
  10525. (when (memq vhdl-include-group-comments '(decl always))
  10526. (vhdl-paste-group-comment (nth 5 port) margin))
  10527. ;; paste object
  10528. (if (nth 1 port)
  10529. (insert (nth 1 port) " ")
  10530. (vhdl-insert-keyword "SIGNAL "))
  10531. ;; paste actual port signals
  10532. (setq names (nth 0 port))
  10533. (while names
  10534. (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
  10535. (setq names (cdr names))
  10536. (when names (insert ", ")))
  10537. ;; paste type
  10538. (insert " : " (nth 3 port))
  10539. ;; paste initialization (inputs only)
  10540. (when (and initialize (equal "IN" (upcase (nth 2 port))))
  10541. (insert " := " (if (string-match "(.+)" (nth 3 port))
  10542. "(others => '0')" "'0'")))
  10543. (insert ";")
  10544. ;; paste comment
  10545. (when (or vhdl-include-direction-comments
  10546. (and vhdl-include-port-comments (nth 4 port)))
  10547. (vhdl-comment-insert-inline
  10548. (concat
  10549. (cond ((and vhdl-include-direction-comments (nth 2 port))
  10550. (format "%-6s" (concat "[" (nth 2 port) "] ")))
  10551. (vhdl-include-direction-comments " "))
  10552. (when vhdl-include-port-comments (nth 4 port))) t))
  10553. (setq port-list (cdr port-list))
  10554. (when port-list (insert "\n") (indent-to margin)))
  10555. ;; align signal list
  10556. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
  10557. (message "Pasting port as signals...done")))
  10558. (defun vhdl-port-paste-initializations (&optional no-indent)
  10559. "Paste ports as signal initializations."
  10560. (interactive)
  10561. (if (not vhdl-port-list)
  10562. (error "ERROR: No port read")
  10563. (let ((orig-vhdl-port-list vhdl-port-list))
  10564. (message "Pasting port as initializations...")
  10565. ;; flatten local copy of port list (must be flat for signal initial.)
  10566. (vhdl-port-flatten)
  10567. (unless no-indent (indent-according-to-mode))
  10568. (let ((margin (current-indentation))
  10569. start port name
  10570. (port-list (nth 2 vhdl-port-list)))
  10571. (when port-list
  10572. (setq start (point))
  10573. (while port-list
  10574. (setq port (car port-list))
  10575. ;; paste actual port signal (inputs only)
  10576. (when (equal "IN" (upcase (nth 2 port)))
  10577. (setq name (car (nth 0 port)))
  10578. (insert (vhdl-replace-string vhdl-actual-port-name name))
  10579. ;; paste initialization
  10580. (insert " <= " (if (string-match "(.+)" (nth 3 port))
  10581. "(others => '0')" "'0'") ";"))
  10582. (setq port-list (cdr port-list))
  10583. (when (and port-list
  10584. (equal "IN" (upcase (nth 2 (car port-list)))))
  10585. (insert "\n") (indent-to margin)))
  10586. ;; align signal list
  10587. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
  10588. (message "Pasting port as initializations...done")
  10589. (setq vhdl-port-list orig-vhdl-port-list))))
  10590. (defun vhdl-port-paste-testbench ()
  10591. "Paste as a bare-bones testbench."
  10592. (interactive)
  10593. (if (not vhdl-port-list)
  10594. (error "ERROR: No port read")
  10595. (let ((case-fold-search t)
  10596. (ent-name (vhdl-replace-string vhdl-testbench-entity-name
  10597. (nth 0 vhdl-port-list)))
  10598. (source-buffer (current-buffer))
  10599. arch-name config-name ent-file-name arch-file-name
  10600. ent-buffer arch-buffer position)
  10601. ;; open entity file
  10602. (unless (eq vhdl-testbench-create-files 'none)
  10603. (setq ent-file-name
  10604. (concat (vhdl-replace-string vhdl-testbench-entity-file-name
  10605. ent-name t)
  10606. "." (file-name-extension (buffer-file-name))))
  10607. (if (file-exists-p ent-file-name)
  10608. (if (y-or-n-p
  10609. (concat "File \"" ent-file-name "\" exists; overwrite? "))
  10610. (progn (find-file ent-file-name)
  10611. (erase-buffer)
  10612. (set-buffer-modified-p nil))
  10613. (if (eq vhdl-testbench-create-files 'separate)
  10614. (setq ent-file-name nil)
  10615. (error "ERROR: Pasting port as testbench...aborted")))
  10616. (find-file ent-file-name)))
  10617. (unless (and (eq vhdl-testbench-create-files 'separate)
  10618. (null ent-file-name))
  10619. ;; paste entity header
  10620. (if vhdl-testbench-include-header
  10621. (progn (vhdl-template-header
  10622. (concat "Testbench for design \""
  10623. (nth 0 vhdl-port-list) "\""))
  10624. (goto-char (point-max)))
  10625. (vhdl-comment-display-line) (insert "\n\n"))
  10626. ;; paste std_logic_1164 package
  10627. (when vhdl-testbench-include-library
  10628. (vhdl-template-package-std-logic-1164)
  10629. (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
  10630. ;; paste entity declaration
  10631. (vhdl-insert-keyword "ENTITY ")
  10632. (insert ent-name)
  10633. (vhdl-insert-keyword " IS")
  10634. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  10635. (insert "\n")
  10636. (vhdl-insert-keyword "END ")
  10637. (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
  10638. (insert ent-name ";")
  10639. (insert "\n\n")
  10640. (vhdl-comment-display-line) (insert "\n"))
  10641. ;; get architecture name
  10642. (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
  10643. (read-from-minibuffer "architecture name: "
  10644. nil vhdl-minibuffer-local-map)
  10645. (vhdl-replace-string vhdl-testbench-architecture-name
  10646. (nth 0 vhdl-port-list))))
  10647. (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
  10648. ;; open architecture file
  10649. (if (not (eq vhdl-testbench-create-files 'separate))
  10650. (insert "\n")
  10651. (setq ent-buffer (current-buffer))
  10652. (setq arch-file-name
  10653. (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
  10654. (concat ent-name " " arch-name) t)
  10655. "." (file-name-extension (buffer-file-name))))
  10656. (when (and (file-exists-p arch-file-name)
  10657. (not (y-or-n-p (concat "File \"" arch-file-name
  10658. "\" exists; overwrite? "))))
  10659. (error "ERROR: Pasting port as testbench...aborted"))
  10660. (find-file arch-file-name)
  10661. (erase-buffer)
  10662. (set-buffer-modified-p nil)
  10663. ;; paste architecture header
  10664. (if vhdl-testbench-include-header
  10665. (progn (vhdl-template-header
  10666. (concat "Testbench architecture for design \""
  10667. (nth 0 vhdl-port-list) "\""))
  10668. (goto-char (point-max)))
  10669. (vhdl-comment-display-line) (insert "\n\n")))
  10670. ;; paste architecture body
  10671. (vhdl-insert-keyword "ARCHITECTURE ")
  10672. (insert arch-name)
  10673. (vhdl-insert-keyword " OF ")
  10674. (insert ent-name)
  10675. (vhdl-insert-keyword " IS")
  10676. (insert "\n\n") (indent-to vhdl-basic-offset)
  10677. ;; paste component declaration
  10678. (unless (vhdl-use-direct-instantiation)
  10679. (vhdl-port-paste-component t)
  10680. (insert "\n\n") (indent-to vhdl-basic-offset))
  10681. ;; paste constants
  10682. (when (nth 1 vhdl-port-list)
  10683. (insert "-- component generics\n") (indent-to vhdl-basic-offset)
  10684. (vhdl-port-paste-constants t)
  10685. (insert "\n\n") (indent-to vhdl-basic-offset))
  10686. ;; paste internal signals
  10687. (insert "-- component ports\n") (indent-to vhdl-basic-offset)
  10688. (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
  10689. (insert "\n")
  10690. ;; paste custom declarations
  10691. (unless (equal "" vhdl-testbench-declarations)
  10692. (insert "\n")
  10693. (vhdl-insert-string-or-file vhdl-testbench-declarations))
  10694. (setq position (point))
  10695. (insert "\n\n")
  10696. (vhdl-comment-display-line) (insert "\n")
  10697. (when vhdl-testbench-include-configuration
  10698. (setq config-name (vhdl-replace-string
  10699. vhdl-testbench-configuration-name
  10700. (concat ent-name " " arch-name)))
  10701. (insert "\n")
  10702. (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
  10703. (vhdl-insert-keyword " OF ") (insert ent-name)
  10704. (vhdl-insert-keyword " IS\n")
  10705. (indent-to vhdl-basic-offset)
  10706. (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
  10707. (indent-to vhdl-basic-offset)
  10708. (vhdl-insert-keyword "END FOR;\n")
  10709. (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
  10710. (vhdl-comment-display-line) (insert "\n"))
  10711. (goto-char position)
  10712. (vhdl-template-begin-end
  10713. (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
  10714. ;; paste instantiation
  10715. (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
  10716. (vhdl-port-paste-instance
  10717. (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
  10718. (insert "\n")
  10719. ;; paste custom statements
  10720. (unless (equal "" vhdl-testbench-statements)
  10721. (insert "\n")
  10722. (vhdl-insert-string-or-file vhdl-testbench-statements))
  10723. (insert "\n")
  10724. (indent-to vhdl-basic-offset)
  10725. (unless (eq vhdl-testbench-create-files 'none)
  10726. (setq arch-buffer (current-buffer))
  10727. (when ent-buffer (set-buffer ent-buffer) (save-buffer))
  10728. (set-buffer arch-buffer) (save-buffer))
  10729. (message "%s"
  10730. (concat (format "Pasting port as testbench \"%s(%s)\"...done"
  10731. ent-name arch-name)
  10732. (and ent-file-name
  10733. (format "\n File created: \"%s\"" ent-file-name))
  10734. (and arch-file-name
  10735. (format "\n File created: \"%s\"" arch-file-name)))))))
  10736. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10737. ;;; Subprogram interface translation
  10738. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10739. (defvar vhdl-subprog-list nil
  10740. "Variable to hold last subprogram interface parsed.")
  10741. ;; structure: (parenthesized expression means list of such entries)
  10742. ;; (subprog-name kind
  10743. ;; ((names) object direct type init comment group-comment)
  10744. ;; return-type return-comment group-comment)
  10745. (defvar vhdl-subprog-flattened nil
  10746. "Indicates whether an subprogram interface has been flattened.")
  10747. (defun vhdl-subprog-flatten ()
  10748. "Flatten interface list so that only one parameter exists per line."
  10749. (interactive)
  10750. (if (not vhdl-subprog-list)
  10751. (error "ERROR: No subprogram interface has been read")
  10752. (message "Flattening subprogram interface...")
  10753. (let ((old-subprog-list (nth 2 vhdl-subprog-list))
  10754. new-subprog-list old-subprog new-subprog names)
  10755. ;; traverse parameter list and flatten entries
  10756. (while old-subprog-list
  10757. (setq old-subprog (car old-subprog-list))
  10758. (setq names (car old-subprog))
  10759. (while names
  10760. (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
  10761. (setq new-subprog-list (append new-subprog-list (list new-subprog)))
  10762. (setq names (cdr names)))
  10763. (setq old-subprog-list (cdr old-subprog-list)))
  10764. (setq vhdl-subprog-list
  10765. (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
  10766. new-subprog-list (nth 3 vhdl-subprog-list)
  10767. (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
  10768. vhdl-subprog-flattened t)
  10769. (message "Flattening subprogram interface...done"))))
  10770. (defun vhdl-subprog-copy ()
  10771. "Get interface information from a subprogram specification."
  10772. (interactive)
  10773. (save-excursion
  10774. (let (parse-error pos end-of-list
  10775. name kind param-list object names direct type init
  10776. comment group-comment
  10777. return-type return-comment return-group-comment)
  10778. (vhdl-prepare-search-2
  10779. (setq
  10780. parse-error
  10781. (catch 'parse
  10782. ;; check if within function declaration
  10783. (setq pos (point))
  10784. (end-of-line)
  10785. (when (looking-at "[ \t\n]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
  10786. (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
  10787. (goto-char (match-end 0))
  10788. (save-excursion (backward-char)
  10789. (forward-sexp)
  10790. (<= pos (point))))
  10791. (throw 'parse "ERROR: Not within a subprogram specification"))
  10792. (setq name (match-string-no-properties 5))
  10793. (setq kind (if (match-string 2) 'procedure 'function))
  10794. (setq end-of-list (not (match-string 7)))
  10795. (message "Reading interface of subprogram \"%s\"..." name)
  10796. ;; parse parameter list
  10797. (setq group-comment (vhdl-parse-group-comment))
  10798. (setq end-of-list (or end-of-list
  10799. (vhdl-parse-string ")[ \t\n]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
  10800. (while (not end-of-list)
  10801. ;; parse object
  10802. (setq object
  10803. (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n]*" t)
  10804. (match-string-no-properties 1)))
  10805. ;; parse names (accept extended identifiers)
  10806. (vhdl-parse-string "\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*")
  10807. (setq names (list (match-string-no-properties 1)))
  10808. (while (vhdl-parse-string ",[ \t\n]*\\(\\w+\\|\\\\[^\\]+\\\\\\)[ \t\n]*" t)
  10809. (setq names (append names (list (match-string-no-properties 1)))))
  10810. ;; parse direction
  10811. (vhdl-parse-string ":[ \t\n]*")
  10812. (setq direct
  10813. (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n]+" t)
  10814. (match-string-no-properties 1)))
  10815. ;; parse type
  10816. (vhdl-parse-string "\\([^():;\n]+\\)")
  10817. (setq type (match-string-no-properties 1))
  10818. (setq comment nil)
  10819. (while (looking-at "(")
  10820. (setq type
  10821. (concat type
  10822. (buffer-substring-no-properties
  10823. (point) (progn (forward-sexp) (point)))
  10824. (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
  10825. (match-string-no-properties 1)))))
  10826. ;; special case: closing parenthesis is on separate line
  10827. (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
  10828. (setq comment (substring type (match-beginning 2)))
  10829. (setq type (substring type 0 (match-beginning 1))))
  10830. ;; strip off trailing group-comment
  10831. (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
  10832. (setq type (substring type 0 (match-end 1)))
  10833. ;; parse initialization expression
  10834. (setq init nil)
  10835. (when (vhdl-parse-string ":=[ \t\n]*" t)
  10836. (vhdl-parse-string "\\([^();\n]*\\)")
  10837. (setq init (match-string-no-properties 1))
  10838. (while (looking-at "(")
  10839. (setq init
  10840. (concat init
  10841. (buffer-substring-no-properties
  10842. (point) (progn (forward-sexp) (point)))
  10843. (and (vhdl-parse-string "\\([^();\n]*\\)" t)
  10844. (match-string-no-properties 1))))))
  10845. ;; special case: closing parenthesis is on separate line
  10846. (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
  10847. (setq comment (substring init (match-beginning 2)))
  10848. (setq init (substring init 0 (match-beginning 1)))
  10849. (vhdl-forward-syntactic-ws))
  10850. (skip-chars-forward " \t")
  10851. ;; parse inline comment, special case: as above, no initial.
  10852. (unless comment
  10853. (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
  10854. (match-string-no-properties 1))))
  10855. (vhdl-forward-syntactic-ws)
  10856. (setq end-of-list (vhdl-parse-string ")\\s-*" t))
  10857. ;; parse inline comment
  10858. (unless comment
  10859. (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
  10860. (match-string-no-properties 1))))
  10861. (setq return-group-comment (vhdl-parse-group-comment))
  10862. (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
  10863. ;; parse return type
  10864. (when (match-string 3)
  10865. (vhdl-parse-string "[ \t\n]*\\(.+\\)[ \t\n]*\\(;\\|is\\>\\)\\s-*")
  10866. (setq return-type (match-string-no-properties 1))
  10867. (when (and return-type
  10868. (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
  10869. (setq return-comment (substring return-type (match-beginning 2)))
  10870. (setq return-type (substring return-type 0 (match-beginning 1))))
  10871. ;; strip of trailing group-comment
  10872. (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
  10873. (setq return-type (substring return-type 0 (match-end 1)))
  10874. ;; parse return comment
  10875. (unless return-comment
  10876. (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
  10877. (match-string-no-properties 1)))))
  10878. ;; parse inline comment
  10879. (unless comment
  10880. (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
  10881. (match-string-no-properties 1))))
  10882. ;; save everything in list
  10883. (setq param-list (append param-list
  10884. (list (list names object direct type init
  10885. comment group-comment))))
  10886. ;; parse group comment and spacing
  10887. (setq group-comment (vhdl-parse-group-comment)))
  10888. (message "Reading interface of subprogram \"%s\"...done" name)
  10889. nil)))
  10890. ;; finish parsing
  10891. (if parse-error
  10892. (error parse-error)
  10893. (setq vhdl-subprog-list
  10894. (list name kind param-list return-type return-comment
  10895. return-group-comment)
  10896. vhdl-subprog-flattened nil)))))
  10897. (defun vhdl-subprog-paste-specification (kind)
  10898. "Paste as a subprogram specification."
  10899. (indent-according-to-mode)
  10900. (let ((margin (current-column))
  10901. (param-list (nth 2 vhdl-subprog-list))
  10902. list-margin start names param)
  10903. ;; paste keyword and name
  10904. (vhdl-insert-keyword
  10905. (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
  10906. (insert (nth 0 vhdl-subprog-list))
  10907. (if (not param-list)
  10908. (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
  10909. (setq start (point))
  10910. ;; paste parameter list
  10911. (insert " (")
  10912. (unless vhdl-argument-list-indent
  10913. (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
  10914. (setq list-margin (current-column))
  10915. (while param-list
  10916. (setq param (car param-list))
  10917. ;; paste group comment and spacing
  10918. (when (memq vhdl-include-group-comments (list kind 'always))
  10919. (vhdl-paste-group-comment (nth 6 param) list-margin))
  10920. ;; paste object
  10921. (when (nth 1 param) (insert (nth 1 param) " "))
  10922. ;; paste names
  10923. (setq names (nth 0 param))
  10924. (while names
  10925. (insert (car names))
  10926. (setq names (cdr names))
  10927. (when names (insert ", ")))
  10928. ;; paste direction
  10929. (insert " : ")
  10930. (when (nth 2 param) (insert (nth 2 param) " "))
  10931. ;; paste type
  10932. (insert (nth 3 param))
  10933. ;; paste initialization
  10934. (when (nth 4 param) (insert " := " (nth 4 param)))
  10935. ;; terminate line
  10936. (if (cdr param-list)
  10937. (insert ";")
  10938. (insert ")")
  10939. (when (null (nth 3 vhdl-subprog-list))
  10940. (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
  10941. ;; paste comment
  10942. (when (and vhdl-include-port-comments (nth 5 param))
  10943. (vhdl-comment-insert-inline (nth 5 param) t))
  10944. (setq param-list (cdr param-list))
  10945. (when param-list (insert "\n") (indent-to list-margin)))
  10946. (when (nth 3 vhdl-subprog-list)
  10947. (insert "\n") (indent-to list-margin)
  10948. ;; paste group comment and spacing
  10949. (when (memq vhdl-include-group-comments (list kind 'always))
  10950. (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
  10951. ;; paste return type
  10952. (insert "return " (nth 3 vhdl-subprog-list))
  10953. (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
  10954. (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
  10955. (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
  10956. ;; align parameter list
  10957. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
  10958. ;; paste body
  10959. (when (eq kind 'body)
  10960. (insert "\n")
  10961. (vhdl-template-begin-end
  10962. (unless (vhdl-standard-p '87)
  10963. (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
  10964. (nth 0 vhdl-subprog-list) margin))))
  10965. (defun vhdl-subprog-paste-declaration ()
  10966. "Paste as a subprogram declaration."
  10967. (interactive)
  10968. (if (not vhdl-subprog-list)
  10969. (error "ERROR: No subprogram interface read")
  10970. (message "Pasting interface as subprogram declaration \"%s\"..."
  10971. (car vhdl-subprog-list))
  10972. ;; paste specification
  10973. (vhdl-subprog-paste-specification 'decl)
  10974. (message "Pasting interface as subprogram declaration \"%s\"...done"
  10975. (car vhdl-subprog-list))))
  10976. (defun vhdl-subprog-paste-body ()
  10977. "Paste as a subprogram body."
  10978. (interactive)
  10979. (if (not vhdl-subprog-list)
  10980. (error "ERROR: No subprogram interface read")
  10981. (message "Pasting interface as subprogram body \"%s\"..."
  10982. (car vhdl-subprog-list))
  10983. ;; paste specification and body
  10984. (vhdl-subprog-paste-specification 'body)
  10985. (message "Pasting interface as subprogram body \"%s\"...done"
  10986. (car vhdl-subprog-list))))
  10987. (defun vhdl-subprog-paste-call ()
  10988. "Paste as a subprogram call."
  10989. (interactive)
  10990. (if (not vhdl-subprog-list)
  10991. (error "ERROR: No subprogram interface read")
  10992. (let ((orig-vhdl-subprog-list vhdl-subprog-list)
  10993. param-list margin list-margin param start)
  10994. ;; flatten local copy of interface list (must be flat for parameter mapping)
  10995. (vhdl-subprog-flatten)
  10996. (setq param-list (nth 2 vhdl-subprog-list))
  10997. (indent-according-to-mode)
  10998. (setq margin (current-indentation))
  10999. (message "Pasting interface as subprogram call \"%s\"..."
  11000. (car vhdl-subprog-list))
  11001. ;; paste name
  11002. (insert (nth 0 vhdl-subprog-list))
  11003. (if (not param-list)
  11004. (insert ";")
  11005. (setq start (point))
  11006. ;; paste parameter list
  11007. (insert " (")
  11008. (unless vhdl-argument-list-indent
  11009. (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
  11010. (setq list-margin (current-column))
  11011. (while param-list
  11012. (setq param (car param-list))
  11013. ;; paste group comment and spacing
  11014. (when (eq vhdl-include-group-comments 'always)
  11015. (vhdl-paste-group-comment (nth 6 param) list-margin))
  11016. ;; paste formal port
  11017. (insert (car (nth 0 param)) " => ")
  11018. (setq param-list (cdr param-list))
  11019. (insert (if param-list "," ");"))
  11020. ;; paste comment
  11021. (when (and vhdl-include-port-comments (nth 5 param))
  11022. (vhdl-comment-insert-inline (nth 5 param)))
  11023. (when param-list (insert "\n") (indent-to list-margin)))
  11024. ;; align parameter list
  11025. (when vhdl-auto-align
  11026. (vhdl-align-region-groups start (point) 1)))
  11027. (message "Pasting interface as subprogram call \"%s\"...done"
  11028. (car vhdl-subprog-list))
  11029. (setq vhdl-subprog-list orig-vhdl-subprog-list))))
  11030. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11031. ;;; Miscellaneous
  11032. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11033. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11034. ;; Hippie expand customization
  11035. (defvar vhdl-expand-upper-case nil)
  11036. (defun vhdl-try-expand-abbrev (old)
  11037. "Try expanding abbreviations from `vhdl-abbrev-list'."
  11038. (unless old
  11039. (he-init-string (he-dabbrev-beg) (point))
  11040. (setq he-expand-list
  11041. (let ((abbrev-list vhdl-abbrev-list)
  11042. (sel-abbrev-list '()))
  11043. (while abbrev-list
  11044. (when (or (not (stringp (car abbrev-list)))
  11045. (string-match
  11046. (concat "^" he-search-string) (car abbrev-list)))
  11047. (setq sel-abbrev-list
  11048. (cons (car abbrev-list) sel-abbrev-list)))
  11049. (setq abbrev-list (cdr abbrev-list)))
  11050. (nreverse sel-abbrev-list))))
  11051. (while (and he-expand-list
  11052. (or (not (stringp (car he-expand-list)))
  11053. (he-string-member (car he-expand-list) he-tried-table t)))
  11054. ; (equal (car he-expand-list) he-search-string)))
  11055. (unless (stringp (car he-expand-list))
  11056. (setq vhdl-expand-upper-case (car he-expand-list)))
  11057. (setq he-expand-list (cdr he-expand-list)))
  11058. (if (null he-expand-list)
  11059. (progn (when old (he-reset-string))
  11060. nil)
  11061. (he-substitute-string
  11062. (if vhdl-expand-upper-case
  11063. (upcase (car he-expand-list))
  11064. (car he-expand-list))
  11065. t)
  11066. (setq he-expand-list (cdr he-expand-list))
  11067. t))
  11068. (defun vhdl-he-list-beg ()
  11069. "Also looks at the word before `(' in order to better match parenthesized
  11070. expressions (e.g. for index ranges of types and signals)."
  11071. (save-excursion
  11072. (condition-case ()
  11073. (progn (backward-up-list 1)
  11074. (skip-syntax-backward "w_")) ; crashes in `viper-mode'
  11075. (error ()))
  11076. (point)))
  11077. ;; override `he-list-beg' from `hippie-exp'
  11078. (unless (and (boundp 'viper-mode) viper-mode)
  11079. (defalias 'he-list-beg 'vhdl-he-list-beg))
  11080. ;; function for expanding abbrevs and dabbrevs
  11081. (defun vhdl-expand-abbrev (arg))
  11082. (fset 'vhdl-expand-abbrev (make-hippie-expand-function
  11083. '(try-expand-dabbrev
  11084. try-expand-dabbrev-all-buffers
  11085. vhdl-try-expand-abbrev)))
  11086. ;; function for expanding parenthesis
  11087. (defun vhdl-expand-paren (arg))
  11088. (fset 'vhdl-expand-paren (make-hippie-expand-function
  11089. '(try-expand-list
  11090. try-expand-list-all-buffers)))
  11091. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11092. ;; Case fixing
  11093. (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
  11094. "Convert all words matching WORD-REGEXP in region to lower or upper case,
  11095. depending on parameter UPPER-CASE."
  11096. (let ((case-replace nil)
  11097. (last-update 0))
  11098. (vhdl-prepare-search-2
  11099. (save-excursion
  11100. (goto-char end)
  11101. (setq end (point-marker))
  11102. (goto-char beg)
  11103. (while (re-search-forward word-regexp end t)
  11104. (or (vhdl-in-literal)
  11105. (if upper-case
  11106. (upcase-word -1)
  11107. (downcase-word -1)))
  11108. (when (and count vhdl-progress-interval (not noninteractive)
  11109. (< vhdl-progress-interval
  11110. (- (nth 1 (current-time)) last-update)))
  11111. (message "Fixing case... (%2d%s)"
  11112. (+ (* count 25) (/ (* 25 (- (point) beg)) (- end beg)))
  11113. "%")
  11114. (setq last-update (nth 1 (current-time)))))
  11115. (goto-char end)))))
  11116. (defun vhdl-fix-case-region (beg end &optional arg)
  11117. "Convert all VHDL words in region to lower or upper case, depending on
  11118. options vhdl-upper-case-{keywords,types,attributes,enum-values}."
  11119. (interactive "r\nP")
  11120. (vhdl-fix-case-region-1
  11121. beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
  11122. (vhdl-fix-case-region-1
  11123. beg end vhdl-upper-case-types vhdl-types-regexp 1)
  11124. (vhdl-fix-case-region-1
  11125. beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
  11126. (vhdl-fix-case-region-1
  11127. beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
  11128. (when vhdl-progress-interval (message "Fixing case...done")))
  11129. (defun vhdl-fix-case-buffer ()
  11130. "Convert all VHDL words in buffer to lower or upper case, depending on
  11131. options vhdl-upper-case-{keywords,types,attributes,enum-values}."
  11132. (interactive)
  11133. (vhdl-fix-case-region (point-min) (point-max)))
  11134. (defun vhdl-fix-case-word (&optional arg)
  11135. "Convert word after cursor to upper case if necessary."
  11136. (interactive "p")
  11137. (save-excursion
  11138. (when arg (backward-word 1))
  11139. (vhdl-prepare-search-1
  11140. (when (and vhdl-upper-case-keywords
  11141. (looking-at vhdl-keywords-regexp))
  11142. (upcase-word 1))
  11143. (when (and vhdl-upper-case-types
  11144. (looking-at vhdl-types-regexp))
  11145. (upcase-word 1))
  11146. (when (and vhdl-upper-case-attributes
  11147. (looking-at vhdl-attributes-regexp))
  11148. (upcase-word 1))
  11149. (when (and vhdl-upper-case-enum-values
  11150. (looking-at vhdl-enum-values-regexp))
  11151. (upcase-word 1)))))
  11152. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11153. ;; Line handling functions
  11154. (defun vhdl-current-line ()
  11155. "Return the line number of the line containing point."
  11156. (save-restriction
  11157. (widen)
  11158. (1+ (count-lines (point-min) (point-at-bol)))))
  11159. (defun vhdl-line-kill-entire (&optional arg)
  11160. "Delete entire line."
  11161. (interactive "p")
  11162. (beginning-of-line)
  11163. (kill-line (or arg 1)))
  11164. (defun vhdl-line-kill (&optional arg)
  11165. "Kill current line."
  11166. (interactive "p")
  11167. (vhdl-line-kill-entire arg))
  11168. (defun vhdl-line-copy (&optional arg)
  11169. "Copy current line."
  11170. (interactive "p")
  11171. (save-excursion
  11172. (let ((position (point-at-bol)))
  11173. (forward-line (or arg 1))
  11174. (copy-region-as-kill position (point)))))
  11175. (defun vhdl-line-yank ()
  11176. "Yank entire line."
  11177. (interactive)
  11178. (beginning-of-line)
  11179. (yank))
  11180. (defun vhdl-line-expand (&optional prefix-arg)
  11181. "Hippie-expand current line."
  11182. (interactive "P")
  11183. (let ((case-fold-search t) (case-replace nil)
  11184. (hippie-expand-try-functions-list
  11185. '(try-expand-line try-expand-line-all-buffers)))
  11186. (hippie-expand prefix-arg)))
  11187. (defun vhdl-line-transpose-next (&optional arg)
  11188. "Interchange this line with next line."
  11189. (interactive "p")
  11190. (forward-line 1)
  11191. (transpose-lines (or arg 1))
  11192. (forward-line -1))
  11193. (defun vhdl-line-transpose-previous (&optional arg)
  11194. "Interchange this line with previous line."
  11195. (interactive "p")
  11196. (forward-line 1)
  11197. (transpose-lines (- 0 (or arg 0)))
  11198. (forward-line -1))
  11199. (defun vhdl-line-open ()
  11200. "Open a new line and indent."
  11201. (interactive)
  11202. (end-of-line -0)
  11203. (newline-and-indent))
  11204. (defun vhdl-delete-indentation ()
  11205. "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
  11206. it works within comments too."
  11207. (interactive)
  11208. (let ((fill-prefix "-- "))
  11209. (delete-indentation)))
  11210. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11211. ;; Move functions
  11212. (defun vhdl-forward-same-indent ()
  11213. "Move forward to next line with same indent."
  11214. (interactive)
  11215. (let ((pos (point))
  11216. (indent (current-indentation)))
  11217. (beginning-of-line 2)
  11218. (while (and (not (eobp))
  11219. (or (looking-at "^\\s-*\\(--.*\\)?$")
  11220. (> (current-indentation) indent)))
  11221. (beginning-of-line 2))
  11222. (if (= (current-indentation) indent)
  11223. (back-to-indentation)
  11224. (message "No following line with same indent found in this block")
  11225. (goto-char pos)
  11226. nil)))
  11227. (defun vhdl-backward-same-indent ()
  11228. "Move backward to previous line with same indent."
  11229. (interactive)
  11230. (let ((pos (point))
  11231. (indent (current-indentation)))
  11232. (beginning-of-line -0)
  11233. (while (and (not (bobp))
  11234. (or (looking-at "^\\s-*\\(--.*\\)?$")
  11235. (> (current-indentation) indent)))
  11236. (beginning-of-line -0))
  11237. (if (= (current-indentation) indent)
  11238. (back-to-indentation)
  11239. (message "No preceding line with same indent found in this block")
  11240. (goto-char pos)
  11241. nil)))
  11242. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11243. ;; Statistics
  11244. (defun vhdl-statistics-buffer ()
  11245. "Get some file statistics."
  11246. (interactive)
  11247. (let ((no-stats 0)
  11248. (no-code-lines 0)
  11249. (no-lines (count-lines (point-min) (point-max))))
  11250. (save-excursion
  11251. ;; count statements
  11252. (goto-char (point-min))
  11253. (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
  11254. (if (match-string 1)
  11255. (goto-char (match-end 1))
  11256. (setq no-stats (1+ no-stats))))
  11257. ;; count code lines
  11258. (goto-char (point-min))
  11259. (while (not (eobp))
  11260. (unless (looking-at "^\\s-*\\(--.*\\)?$")
  11261. (setq no-code-lines (1+ no-code-lines)))
  11262. (beginning-of-line 2)))
  11263. ;; print results
  11264. (message "\n\
  11265. File statistics: \"%s\"\n\
  11266. ---------------------\n\
  11267. # statements : %5d\n\
  11268. # code lines : %5d\n\
  11269. # total lines : %5d\n\ "
  11270. (buffer-file-name) no-stats no-code-lines no-lines)
  11271. (unless vhdl-emacs-21 (vhdl-show-messages))))
  11272. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11273. ;; Help functions
  11274. (defun vhdl-re-search-forward (regexp &optional bound noerror count)
  11275. "Like `re-search-forward', but does not match within literals."
  11276. (let (pos)
  11277. (save-excursion
  11278. (while (and (setq pos (re-search-forward regexp bound noerror count))
  11279. (vhdl-in-literal))))
  11280. (when pos (goto-char pos))
  11281. pos))
  11282. (defun vhdl-re-search-backward (regexp &optional bound noerror count)
  11283. "Like `re-search-backward', but does not match within literals."
  11284. (let (pos)
  11285. (save-excursion
  11286. (while (and (setq pos (re-search-backward regexp bound noerror count))
  11287. (vhdl-in-literal))))
  11288. (when pos (goto-char pos))
  11289. pos))
  11290. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11291. ;;; Project
  11292. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11293. (defun vhdl-set-project (name)
  11294. "Set current project to NAME."
  11295. (interactive
  11296. (list (let ((completion-ignore-case t))
  11297. (completing-read "Project name: " vhdl-project-alist nil t))))
  11298. (cond ((equal name "")
  11299. (setq vhdl-project nil)
  11300. (message "Current VHDL project: None"))
  11301. ((assoc name vhdl-project-alist)
  11302. (setq vhdl-project name)
  11303. (message "Current VHDL project: \"%s\"" name))
  11304. (t
  11305. (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
  11306. (vhdl-speedbar-update-current-project))
  11307. (defun vhdl-set-default-project ()
  11308. "Set current project as default on startup."
  11309. (interactive)
  11310. (customize-set-variable 'vhdl-project vhdl-project)
  11311. (customize-save-customized))
  11312. (defun vhdl-toggle-project (name token indent)
  11313. "Set current project to NAME or unset if NAME is current project."
  11314. (vhdl-set-project (if (equal name vhdl-project) "" name)))
  11315. (defun vhdl-export-project (file-name)
  11316. "Write project setup for current project."
  11317. (interactive
  11318. (let ((name (vhdl-resolve-env-variable
  11319. (vhdl-replace-string
  11320. (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
  11321. (concat (subst-char-in-string
  11322. ? ?_ (or (vhdl-project-p)
  11323. (error "ERROR: No current project")))
  11324. " " (user-login-name))))))
  11325. (list (read-file-name
  11326. "Write project file: "
  11327. (when (file-name-absolute-p name) "") nil nil name))))
  11328. (setq file-name (abbreviate-file-name file-name))
  11329. (let ((orig-buffer (current-buffer)))
  11330. (unless (file-exists-p (file-name-directory file-name))
  11331. (make-directory (file-name-directory file-name) t))
  11332. (if (not (file-writable-p file-name))
  11333. (error "ERROR: File not writable: \"%s\"" file-name)
  11334. (set-buffer (find-file-noselect file-name t t))
  11335. (erase-buffer)
  11336. (insert ";; -*- Emacs-Lisp -*-\n\n"
  11337. ";;; " (file-name-nondirectory file-name)
  11338. " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
  11339. ";; Project : " vhdl-project "\n"
  11340. ";; Saved : " (format-time-string "%Y-%m-%d %T ")
  11341. (user-login-name) "\n\n\n"
  11342. ";; project name\n"
  11343. "(setq vhdl-project \"" vhdl-project "\")\n\n"
  11344. ";; project setup\n"
  11345. "(aput 'vhdl-project-alist vhdl-project\n'")
  11346. (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
  11347. (insert ")\n")
  11348. (save-buffer)
  11349. (kill-buffer (current-buffer))
  11350. (set-buffer orig-buffer))))
  11351. (defun vhdl-import-project (file-name &optional auto not-make-current)
  11352. "Read project setup and set current project."
  11353. (interactive
  11354. (let ((name (vhdl-resolve-env-variable
  11355. (vhdl-replace-string
  11356. (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
  11357. (concat "" " " (user-login-name))))))
  11358. (list (read-file-name
  11359. "Read project file: " (when (file-name-absolute-p name) "") nil t
  11360. (file-name-directory name)))))
  11361. (when (file-exists-p file-name)
  11362. (condition-case ()
  11363. (let ((current-project vhdl-project))
  11364. (load-file file-name)
  11365. (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
  11366. (adelete 'vhdl-project-alist vhdl-project)
  11367. (error ""))
  11368. (when not-make-current
  11369. (setq vhdl-project current-project))
  11370. (vhdl-update-mode-menu)
  11371. (vhdl-speedbar-refresh)
  11372. (unless not-make-current
  11373. (message "Current VHDL project: \"%s\"%s"
  11374. vhdl-project (if auto " (auto-loaded)" ""))))
  11375. (error (vhdl-warning
  11376. (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
  11377. (defun vhdl-duplicate-project ()
  11378. "Duplicate setup of current project."
  11379. (interactive)
  11380. (let ((new-name (read-from-minibuffer "New project name: "))
  11381. (project-entry (aget vhdl-project-alist vhdl-project t)))
  11382. (setq vhdl-project-alist
  11383. (append vhdl-project-alist
  11384. (list (cons new-name project-entry))))
  11385. (vhdl-update-mode-menu)))
  11386. (defun vhdl-auto-load-project ()
  11387. "Automatically load project setup at startup."
  11388. (let ((file-name-list vhdl-project-file-name)
  11389. file-list list-length)
  11390. (while file-name-list
  11391. (setq file-list
  11392. (append file-list
  11393. (file-expand-wildcards
  11394. (vhdl-resolve-env-variable
  11395. (vhdl-replace-string
  11396. (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
  11397. (concat "\*" " " (user-login-name)))))))
  11398. (setq list-length (or list-length (length file-list)))
  11399. (setq file-name-list (cdr file-name-list)))
  11400. (while file-list
  11401. (vhdl-import-project (expand-file-name (car file-list)) t
  11402. (not (> list-length 0)))
  11403. (setq list-length (1- list-length))
  11404. (setq file-list (cdr file-list)))))
  11405. ;; automatically load project setup when idle after startup
  11406. (when (memq 'startup vhdl-project-auto-load)
  11407. (if noninteractive
  11408. (vhdl-auto-load-project)
  11409. (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
  11410. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11411. ;;; Hideshow
  11412. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11413. ;; (using `hideshow.el')
  11414. (defconst vhdl-hs-start-regexp
  11415. (concat
  11416. "\\(^\\)\\s-*\\("
  11417. ;; generic/port clause
  11418. "\\(generic\\|port\\)[ \t\n]*(\\|"
  11419. ;; component
  11420. "component\\>\\|"
  11421. ;; component instantiation
  11422. "\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*"
  11423. "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
  11424. "\\(\\w\\|\\s_\\)+\\([ \t\n]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n]*"
  11425. "\\(generic\\|port\\)[ \t\n]+map[ \t\n]*(\\|"
  11426. ;; subprogram
  11427. "\\(function\\|procedure\\)\\>\\|"
  11428. ;; process, block
  11429. "\\(\\(\\w\\|\\s_\\)+[ \t\n]*:[ \t\n]*\\)?\\(process\\|block\\)\\>\\|"
  11430. ;; configuration declaration
  11431. "configuration\\>"
  11432. "\\)")
  11433. "Regexp to match start of construct to hide.")
  11434. (defun vhdl-hs-forward-sexp-func (count)
  11435. "Find end of construct to hide (for hideshow). Only searches forward."
  11436. (let ((pos (point)))
  11437. (vhdl-prepare-search-2
  11438. (beginning-of-line)
  11439. (cond
  11440. ;; generic/port clause
  11441. ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n]*(")
  11442. (goto-char (match-end 0))
  11443. (backward-char)
  11444. (forward-sexp))
  11445. ;; component declaration
  11446. ((looking-at "^\\s-*component\\>")
  11447. (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
  11448. ;; component instantiation
  11449. ((looking-at
  11450. (concat
  11451. "^\\s-*\\w+\\s-*:[ \t\n]*"
  11452. "\\(\\(component\\|configuration\\|entity\\)[ \t\n]+\\)?"
  11453. "\\w+\\(\\s-*(\\w+)\\)?[ \t\n]*"
  11454. "\\(generic\\|port\\)\\s-+map[ \t\n]*("))
  11455. (goto-char (match-end 0))
  11456. (backward-char)
  11457. (forward-sexp)
  11458. (setq pos (point))
  11459. (vhdl-forward-syntactic-ws)
  11460. (when (looking-at "port\\s-+map[ \t\n]*(")
  11461. (goto-char (match-end 0))
  11462. (backward-char)
  11463. (forward-sexp)
  11464. (setq pos (point)))
  11465. (goto-char pos))
  11466. ;; subprogram declaration/body
  11467. ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
  11468. (goto-char (match-end 0))
  11469. (vhdl-forward-syntactic-ws)
  11470. (when (looking-at "(")
  11471. (forward-sexp))
  11472. (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
  11473. (vhdl-in-literal)))
  11474. ;; subprogram body
  11475. (when (match-string 2)
  11476. (re-search-forward "^\\s-*\\<begin\\>" nil t)
  11477. (backward-word 1)
  11478. (vhdl-forward-sexp)))
  11479. ;; block (recursive)
  11480. ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
  11481. (goto-char (match-end 0))
  11482. (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
  11483. (match-beginning 2))
  11484. (vhdl-hs-forward-sexp-func count)))
  11485. ;; process
  11486. ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
  11487. (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
  11488. ;; configuration declaration
  11489. ((looking-at "^\\s-*configuration\\>")
  11490. (forward-word 4)
  11491. (vhdl-forward-sexp))
  11492. (t (goto-char pos))))))
  11493. (defun vhdl-hideshow-init ()
  11494. "Initialize `hideshow'."
  11495. (when vhdl-hideshow-menu
  11496. (vhdl-hs-minor-mode 1)))
  11497. (defun vhdl-hs-minor-mode (&optional arg)
  11498. "Toggle hideshow minor mode and update menu bar."
  11499. (interactive "P")
  11500. (require 'hideshow)
  11501. ;; check for hideshow version 5.x
  11502. (if (not (boundp 'hs-block-start-mdata-select))
  11503. (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
  11504. ;; initialize hideshow
  11505. (unless (assoc 'vhdl-mode hs-special-modes-alist)
  11506. (setq hs-special-modes-alist
  11507. (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
  11508. 'vhdl-hs-forward-sexp-func nil)
  11509. hs-special-modes-alist)))
  11510. (if (featurep 'xemacs) (make-local-hook 'hs-minor-mode-hook))
  11511. (if vhdl-hide-all-init
  11512. (add-hook 'hs-minor-mode-hook 'hs-hide-all nil t)
  11513. (remove-hook 'hs-minor-mode-hook 'hs-hide-all t))
  11514. (hs-minor-mode arg)
  11515. (force-mode-line-update))) ; hack to update menu bar
  11516. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11517. ;;; Font locking
  11518. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11519. ;; (using `font-lock.el')
  11520. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11521. ;; Help functions
  11522. (defun vhdl-within-translate-off ()
  11523. "Return point if within translate-off region, else nil."
  11524. (and (save-excursion
  11525. (re-search-backward
  11526. "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
  11527. (equal "off" (match-string 1))
  11528. (point)))
  11529. (defun vhdl-start-translate-off (limit)
  11530. "Return point before translate-off pragma if before LIMIT, else nil."
  11531. (when (re-search-forward
  11532. "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
  11533. (match-beginning 0)))
  11534. (defun vhdl-end-translate-off (limit)
  11535. "Return point after translate-on pragma if before LIMIT, else nil."
  11536. (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
  11537. (defun vhdl-match-translate-off (limit)
  11538. "Match a translate-off block, setting match-data and returning t, else nil."
  11539. (when (< (point) limit)
  11540. (let ((start (or (vhdl-within-translate-off)
  11541. (vhdl-start-translate-off limit)))
  11542. (case-fold-search t))
  11543. (when start
  11544. (let ((end (or (vhdl-end-translate-off limit) limit)))
  11545. (set-match-data (list start end))
  11546. (goto-char end))))))
  11547. (defun vhdl-font-lock-match-item (limit)
  11548. "Match, and move over, any declaration item after point. Adapted from
  11549. `font-lock-match-c-style-declaration-item-and-skip-to-next'."
  11550. (condition-case nil
  11551. (save-restriction
  11552. (narrow-to-region (point-min) limit)
  11553. ;; match item
  11554. (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
  11555. (save-match-data
  11556. (goto-char (match-end 1))
  11557. ;; move to next item
  11558. (if (looking-at "\\(\\s-*,\\)")
  11559. (goto-char (match-end 1))
  11560. (end-of-line) t))))
  11561. (error t)))
  11562. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11563. ;; Syntax definitions
  11564. (defconst vhdl-font-lock-syntactic-keywords
  11565. '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
  11566. "Mark single quotes as having string quote syntax in 'c' instances.")
  11567. (defvar vhdl-font-lock-keywords nil
  11568. "Regular expressions to highlight in VHDL Mode.")
  11569. (defvar vhdl-font-lock-keywords-0
  11570. ;; set in `vhdl-font-lock-init' because dependent on user options
  11571. "For consideration as a value of `vhdl-font-lock-keywords'.
  11572. This does highlighting of template prompts and directives (pragmas).")
  11573. (defvar vhdl-font-lock-keywords-1 nil
  11574. ;; set in `vhdl-font-lock-init' because dependent on user options
  11575. "For consideration as a value of `vhdl-font-lock-keywords'.
  11576. This does highlighting of keywords and standard identifiers.")
  11577. (defconst vhdl-font-lock-keywords-2
  11578. (list
  11579. ;; highlight names of units, subprograms, and components when declared
  11580. (list
  11581. (concat
  11582. "^\\s-*\\("
  11583. "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
  11584. "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
  11585. "\\)\\s-+\\(\\w+\\)")
  11586. 5 'font-lock-function-name-face)
  11587. ;; highlight entity names of architectures and configurations
  11588. (list
  11589. "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
  11590. 2 'font-lock-function-name-face)
  11591. ;; highlight labels of common constructs
  11592. (list
  11593. (concat
  11594. "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\("
  11595. "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
  11596. "postponed\\|process\\|"
  11597. (when (vhdl-standard-p 'ams) "procedural\\|")
  11598. "with\\|while"
  11599. "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
  11600. 1 'font-lock-function-name-face)
  11601. ;; highlight label and component name of component instantiations
  11602. (list
  11603. (concat
  11604. "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*\\(\\w+\\)"
  11605. "\\(\\s-*\\(--[^\n]*\\)?$\\|\\s-+\\(generic\\|port\\)\\s-+map\\>\\)")
  11606. '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
  11607. ;; highlight label and instantiated unit of component instantiations
  11608. (list
  11609. (concat
  11610. "^\\s-*\\(\\w+\\)\\s-*:[ \t\n]*"
  11611. "\\(component\\|configuration\\|entity\\)\\s-+"
  11612. "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
  11613. '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
  11614. '(5 font-lock-function-name-face nil t)
  11615. '(7 font-lock-function-name-face nil t))
  11616. ;; highlight names and labels at end of constructs
  11617. (list
  11618. (concat
  11619. "^\\s-*end\\s-+\\(\\("
  11620. "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
  11621. "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
  11622. "procedure\\|\\(postponed\\s-+\\)?process\\|"
  11623. (when (vhdl-standard-p 'ams) "procedural\\|")
  11624. "units"
  11625. "\\)\\s-+\\)?\\(\\w*\\)")
  11626. 5 'font-lock-function-name-face)
  11627. ;; highlight labels in exit and next statements
  11628. (list
  11629. (concat
  11630. "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
  11631. 3 'font-lock-function-name-face)
  11632. ;; highlight entity name in attribute specifications
  11633. (list
  11634. (concat
  11635. "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
  11636. 1 'font-lock-function-name-face)
  11637. ;; highlight labels in block and component specifications
  11638. (list
  11639. (concat
  11640. "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
  11641. "\\(:[ \t\n]*\\(\\w+\\)\\|[^i \t]\\)")
  11642. '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
  11643. ;; highlight names in library clauses
  11644. (list "^\\s-*library\\>"
  11645. '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
  11646. ;; highlight names in use clauses
  11647. (list
  11648. (concat
  11649. "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
  11650. "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
  11651. '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
  11652. '(7 font-lock-function-name-face nil t))
  11653. ;; highlight attribute name in attribute declarations/specifications
  11654. (list
  11655. (concat
  11656. "^\\s-*attribute\\s-+\\(\\w+\\)")
  11657. 1 'vhdl-font-lock-attribute-face)
  11658. ;; highlight type/nature name in (sub)type/(sub)nature declarations
  11659. (list
  11660. (concat
  11661. "^\\s-*\\(sub\\)?\\(nature\\|type\\)\\s-+\\(\\w+\\)")
  11662. 3 'font-lock-type-face)
  11663. ;; highlight signal/variable/constant declaration names
  11664. (list "\\(:[^=]\\)"
  11665. '(vhdl-font-lock-match-item
  11666. (progn (goto-char (match-beginning 1))
  11667. (skip-syntax-backward " ")
  11668. (skip-syntax-backward "w_")
  11669. (skip-syntax-backward " ")
  11670. (while (= (preceding-char) ?,)
  11671. (backward-char 1)
  11672. (skip-syntax-backward " ")
  11673. (skip-syntax-backward "w_")
  11674. (skip-syntax-backward " ")))
  11675. ; (skip-chars-backward "^-(\n\";")
  11676. (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
  11677. ;; highlight formal parameters in component instantiations and subprogram
  11678. ;; calls
  11679. (list "\\(=>\\)"
  11680. '(vhdl-font-lock-match-item
  11681. (progn (goto-char (match-beginning 1))
  11682. (skip-syntax-backward " ")
  11683. (while (= (preceding-char) ?\)) (backward-sexp))
  11684. (skip-syntax-backward "w_")
  11685. (skip-syntax-backward " ")
  11686. (when (memq (preceding-char) '(?n ?N ?|))
  11687. (goto-char (point-max))))
  11688. (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
  11689. ;; highlight alias/group/quantity declaration names and for-loop/-generate
  11690. ;; variables
  11691. (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
  11692. '(vhdl-font-lock-match-item
  11693. (progn (goto-char (match-end 1)) (match-beginning 2))
  11694. nil (1 font-lock-variable-name-face)))
  11695. )
  11696. "For consideration as a value of `vhdl-font-lock-keywords'.
  11697. This does context sensitive highlighting of names and labels.")
  11698. (defvar vhdl-font-lock-keywords-3 nil
  11699. ;; set in `vhdl-font-lock-init' because dependent on user options
  11700. "For consideration as a value of `vhdl-font-lock-keywords'.
  11701. This does highlighting of words with special syntax.")
  11702. (defvar vhdl-font-lock-keywords-4 nil
  11703. ;; set in `vhdl-font-lock-init' because dependent on user options
  11704. "For consideration as a value of `vhdl-font-lock-keywords'.
  11705. This does highlighting of additional reserved words.")
  11706. (defconst vhdl-font-lock-keywords-5
  11707. ;; background highlight translate-off regions
  11708. '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
  11709. "For consideration as a value of `vhdl-font-lock-keywords'.
  11710. This does background highlighting of translate-off regions.")
  11711. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11712. ;; Font and color definitions
  11713. (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
  11714. "Face name to use for prompts.")
  11715. (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
  11716. "Face name to use for standardized attributes.")
  11717. (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
  11718. "Face name to use for standardized enumeration values.")
  11719. (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
  11720. "Face name to use for standardized functions and packages.")
  11721. (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
  11722. "Face name to use for directives.")
  11723. (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
  11724. "Face name to use for additional reserved words.")
  11725. (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
  11726. "Face name to use for translate-off regions.")
  11727. ;; face names to use for words with special syntax.
  11728. (let ((syntax-alist vhdl-special-syntax-alist)
  11729. name)
  11730. (while syntax-alist
  11731. (setq name (vhdl-function-name
  11732. "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
  11733. (eval `(defvar ,name ',name
  11734. ,(concat "Face name to use for "
  11735. (nth 0 (car syntax-alist)) ".")))
  11736. (setq syntax-alist (cdr syntax-alist))))
  11737. (defgroup vhdl-highlight-faces nil
  11738. "Faces for highlighting."
  11739. :group 'vhdl-highlight)
  11740. ;; add faces used from `font-lock'
  11741. (custom-add-to-group
  11742. 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
  11743. (custom-add-to-group
  11744. 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
  11745. (custom-add-to-group
  11746. 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
  11747. (custom-add-to-group
  11748. 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
  11749. (custom-add-to-group
  11750. 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
  11751. (custom-add-to-group
  11752. 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
  11753. (defface vhdl-font-lock-prompt-face
  11754. '((((min-colors 88) (class color) (background light))
  11755. (:foreground "Red1" :bold t))
  11756. (((class color) (background light)) (:foreground "Red" :bold t))
  11757. (((class color) (background dark)) (:foreground "Pink" :bold t))
  11758. (t (:inverse-video t)))
  11759. "Font lock mode face used to highlight prompts."
  11760. :group 'vhdl-highlight-faces)
  11761. (defface vhdl-font-lock-attribute-face
  11762. '((((class color) (background light)) (:foreground "Orchid"))
  11763. (((class color) (background dark)) (:foreground "LightSteelBlue"))
  11764. (t (:italic t :bold t)))
  11765. "Font lock mode face used to highlight standardized attributes."
  11766. :group 'vhdl-highlight-faces)
  11767. (defface vhdl-font-lock-enumvalue-face
  11768. '((((class color) (background light)) (:foreground "SaddleBrown"))
  11769. (((class color) (background dark)) (:foreground "BurlyWood"))
  11770. (t (:italic t :bold t)))
  11771. "Font lock mode face used to highlight standardized enumeration values."
  11772. :group 'vhdl-highlight-faces)
  11773. (defface vhdl-font-lock-function-face
  11774. '((((class color) (background light)) (:foreground "Cyan4"))
  11775. (((class color) (background dark)) (:foreground "Orchid1"))
  11776. (t (:italic t :bold t)))
  11777. "Font lock mode face used to highlight standardized functions and packages."
  11778. :group 'vhdl-highlight-faces)
  11779. (defface vhdl-font-lock-directive-face
  11780. '((((class color) (background light)) (:foreground "CadetBlue"))
  11781. (((class color) (background dark)) (:foreground "Aquamarine"))
  11782. (t (:italic t :bold t)))
  11783. "Font lock mode face used to highlight directives."
  11784. :group 'vhdl-highlight-faces)
  11785. (defface vhdl-font-lock-reserved-words-face
  11786. '((((class color) (background light)) (:foreground "Orange" :bold t))
  11787. (((min-colors 88) (class color) (background dark))
  11788. (:foreground "Yellow1" :bold t))
  11789. (((class color) (background dark)) (:foreground "Yellow" :bold t))
  11790. (t ()))
  11791. "Font lock mode face used to highlight additional reserved words."
  11792. :group 'vhdl-highlight-faces)
  11793. (defface vhdl-font-lock-translate-off-face
  11794. '((((class color) (background light)) (:background "LightGray"))
  11795. (((class color) (background dark)) (:background "DimGray"))
  11796. (t ()))
  11797. "Font lock mode face used to background highlight translate-off regions."
  11798. :group 'vhdl-highlight-faces)
  11799. ;; font lock mode faces used to highlight words with special syntax.
  11800. (let ((syntax-alist vhdl-special-syntax-alist))
  11801. (while syntax-alist
  11802. (eval `(defface ,(vhdl-function-name
  11803. "vhdl-font-lock" (caar syntax-alist) "face")
  11804. '((((class color) (background light))
  11805. (:foreground ,(nth 2 (car syntax-alist))))
  11806. (((class color) (background dark))
  11807. (:foreground ,(nth 3 (car syntax-alist))))
  11808. (t ()))
  11809. ,(concat "Font lock mode face used to highlight "
  11810. (nth 0 (car syntax-alist)) ".")
  11811. :group 'vhdl-highlight-faces))
  11812. (setq syntax-alist (cdr syntax-alist))))
  11813. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11814. ;; Font lock initialization
  11815. (defun vhdl-font-lock-init ()
  11816. "Initialize fontification."
  11817. ;; highlight template prompts and directives
  11818. (setq vhdl-font-lock-keywords-0
  11819. (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
  11820. vhdl-template-prompt-syntax ">\\)")
  11821. 2 'vhdl-font-lock-prompt-face t)
  11822. (list (concat "--\\s-*"
  11823. vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
  11824. 2 'vhdl-font-lock-directive-face t)
  11825. ;; highlight c-preprocessor directives
  11826. (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
  11827. '(1 font-lock-builtin-face)
  11828. '(3 font-lock-variable-name-face nil t))))
  11829. ;; highlight keywords and standardized types, attributes, enumeration
  11830. ;; values, and subprograms
  11831. (setq vhdl-font-lock-keywords-1
  11832. (list
  11833. (list (concat "'" vhdl-attributes-regexp)
  11834. 1 'vhdl-font-lock-attribute-face)
  11835. (list vhdl-types-regexp 1 'font-lock-type-face)
  11836. (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
  11837. (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
  11838. (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
  11839. (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
  11840. ;; highlight words with special syntax.
  11841. (setq vhdl-font-lock-keywords-3
  11842. (let ((syntax-alist vhdl-special-syntax-alist)
  11843. keywords)
  11844. (while syntax-alist
  11845. (setq keywords
  11846. (cons
  11847. (cons (concat "\\<\\(" (nth 1 (car syntax-alist)) "\\)\\>")
  11848. (vhdl-function-name
  11849. "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
  11850. keywords))
  11851. (setq syntax-alist (cdr syntax-alist)))
  11852. keywords))
  11853. ;; highlight additional reserved words
  11854. (setq vhdl-font-lock-keywords-4
  11855. (list (list vhdl-reserved-words-regexp 1
  11856. 'vhdl-font-lock-reserved-words-face)))
  11857. ;; highlight everything together
  11858. (setq vhdl-font-lock-keywords
  11859. (append
  11860. vhdl-font-lock-keywords-0
  11861. (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
  11862. (when (or vhdl-highlight-forbidden-words
  11863. vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
  11864. (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
  11865. (when vhdl-highlight-names vhdl-font-lock-keywords-2)
  11866. (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
  11867. ;; initialize fontification for VHDL Mode
  11868. (vhdl-font-lock-init)
  11869. (defun vhdl-fontify-buffer ()
  11870. "Re-initialize fontification and fontify buffer."
  11871. (interactive)
  11872. (setq font-lock-defaults
  11873. `(vhdl-font-lock-keywords
  11874. nil ,(not vhdl-highlight-case-sensitive) ((?\_ . "w"))
  11875. beginning-of-line))
  11876. (when (fboundp 'font-lock-unset-defaults)
  11877. (font-lock-unset-defaults)) ; not implemented in XEmacs
  11878. (font-lock-set-defaults)
  11879. (font-lock-mode nil)
  11880. (font-lock-mode t))
  11881. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11882. ;; Initialization for PostScript printing
  11883. (defun vhdl-ps-print-settings ()
  11884. "Initialize custom face and page settings for PostScript printing."
  11885. ;; define custom face settings
  11886. (unless (or (not vhdl-print-customize-faces)
  11887. ps-print-color-p)
  11888. (set (make-local-variable 'ps-bold-faces)
  11889. '(font-lock-keyword-face
  11890. font-lock-type-face
  11891. vhdl-font-lock-attribute-face
  11892. vhdl-font-lock-enumvalue-face
  11893. vhdl-font-lock-directive-face))
  11894. (set (make-local-variable 'ps-italic-faces)
  11895. '(font-lock-comment-face
  11896. font-lock-function-name-face
  11897. font-lock-type-face
  11898. vhdl-font-lock-attribute-face
  11899. vhdl-font-lock-enumvalue-face
  11900. vhdl-font-lock-directive-face))
  11901. (set (make-local-variable 'ps-underlined-faces)
  11902. '(font-lock-string-face))
  11903. (setq ps-always-build-face-reference t))
  11904. ;; define page settings, so that a line containing 79 characters (default)
  11905. ;; fits into one column
  11906. (when vhdl-print-two-column
  11907. (set (make-local-variable 'ps-landscape-mode) t)
  11908. (set (make-local-variable 'ps-number-of-columns) 2)
  11909. (set (make-local-variable 'ps-font-size) 7.0)
  11910. (set (make-local-variable 'ps-header-title-font-size) 10.0)
  11911. (set (make-local-variable 'ps-header-font-size) 9.0)
  11912. (set (make-local-variable 'ps-header-offset) 12.0)
  11913. (when (eq ps-paper-type 'letter)
  11914. (set (make-local-variable 'ps-inter-column) 40.0)
  11915. (set (make-local-variable 'ps-left-margin) 40.0)
  11916. (set (make-local-variable 'ps-right-margin) 40.0))))
  11917. (defun vhdl-ps-print-init ()
  11918. "Initialize PostScript printing."
  11919. (if (featurep 'xemacs)
  11920. (when (boundp 'ps-print-color-p)
  11921. (vhdl-ps-print-settings))
  11922. (if (featurep 'xemacs) (make-local-hook 'ps-print-hook))
  11923. (add-hook 'ps-print-hook 'vhdl-ps-print-settings nil t)))
  11924. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11925. ;;; Hierarchy browser (using `speedbar.el')
  11926. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11927. ;; Allows displaying the hierarchy of all VHDL design units contained in a
  11928. ;; directory by using the speedbar.
  11929. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11930. ;; Variables
  11931. (defvar vhdl-entity-alist nil
  11932. "Cache with entities and corresponding architectures for each
  11933. project/directory.")
  11934. ;; structure: (parenthesized expression means list of such entries)
  11935. ;; (cache-key
  11936. ;; (ent-key ent-name ent-file ent-line
  11937. ;; (arch-key arch-name arch-file arch-line
  11938. ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
  11939. ;; inst-arch-key inst-conf-key inst-lib-key inst-path)
  11940. ;; (lib-name pack-key))
  11941. ;; mra-key (lib-name pack-key))
  11942. (defvar vhdl-config-alist nil
  11943. "Cache with configurations for each project/directory.")
  11944. ;; structure: (parenthesized expression means list of such entries)
  11945. ;; (cache-key
  11946. ;; (conf-key conf-name conf-file conf-line ent-key arch-key
  11947. ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
  11948. ;; inst-conf-key inst-lib-key)
  11949. ;; (lib-name pack-key)))
  11950. (defvar vhdl-package-alist nil
  11951. "Cache with packages for each project/directory.")
  11952. ;; structure: (parenthesized expression means list of such entries)
  11953. ;; (cache-key
  11954. ;; (pack-key pack-name pack-file pack-line
  11955. ;; (comp-key comp-name comp-file comp-line)
  11956. ;; (func-key func-name func-file func-line)
  11957. ;; (lib-name pack-key)
  11958. ;; pack-body-file pack-body-line
  11959. ;; (func-key func-name func-body-file func-body-line)
  11960. ;; (lib-name pack-key)))
  11961. (defvar vhdl-ent-inst-alist nil
  11962. "Cache with instantiated entities for each project/directory.")
  11963. ;; structure: (parenthesized expression means list of such entries)
  11964. ;; (cache-key (inst-ent-key))
  11965. (defvar vhdl-file-alist nil
  11966. "Cache with design units in each file for each project/directory.")
  11967. ;; structure: (parenthesized expression means list of such entries)
  11968. ;; (cache-key
  11969. ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
  11970. ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
  11971. (defvar vhdl-directory-alist nil
  11972. "Cache with source directories for each project.")
  11973. ;; structure: (parenthesized expression means list of such entries)
  11974. ;; (cache-key (directory))
  11975. (defvar vhdl-speedbar-shown-unit-alist nil
  11976. "Alist of design units simultaneously open in the current speedbar for each
  11977. directory and project.")
  11978. (defvar vhdl-speedbar-shown-project-list nil
  11979. "List of projects simultaneously open in the current speedbar.")
  11980. (defvar vhdl-updated-project-list nil
  11981. "List of projects and directories with updated files.")
  11982. (defvar vhdl-modified-file-list nil
  11983. "List of modified files to be rescanned for hierarchy updating.")
  11984. (defvar vhdl-speedbar-hierarchy-depth 0
  11985. "Depth of instantiation hierarchy to display.")
  11986. (defvar vhdl-speedbar-show-projects nil
  11987. "Non-nil means project hierarchy is displayed in speedbar, directory
  11988. hierarchy otherwise.")
  11989. (defun vhdl-get-end-of-unit ()
  11990. "Return position of end of current unit."
  11991. (let ((pos (point)))
  11992. (save-excursion
  11993. (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
  11994. (save-excursion
  11995. (goto-char (match-beginning 0))
  11996. (vhdl-backward-syntactic-ws)
  11997. (and (/= (preceding-char) ?\;) (not (bobp))))))
  11998. (re-search-backward "^[ \t]*end\\>" pos 1)
  11999. (point))))
  12000. (defun vhdl-match-string-downcase (num &optional string)
  12001. "Like `match-string-no-properties' with down-casing."
  12002. (let ((match (match-string-no-properties num string)))
  12003. (and match (downcase match))))
  12004. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12005. ;; Scan functions
  12006. (defun vhdl-scan-context-clause ()
  12007. "Scan the context clause that precedes a design unit."
  12008. (let (lib-alist)
  12009. (save-excursion
  12010. (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
  12011. (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
  12012. (equal "USE" (upcase (match-string 1))))
  12013. (when (looking-at "^[ \t]*use[ \t\n]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
  12014. (setq lib-alist (cons (cons (match-string-no-properties 1)
  12015. (vhdl-match-string-downcase 2))
  12016. lib-alist))))))
  12017. lib-alist))
  12018. (defun vhdl-scan-directory-contents (name &optional project update num-string
  12019. non-final)
  12020. "Scan contents of VHDL files in directory or file pattern NAME."
  12021. (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
  12022. ; (unless (file-directory-p (match-string 1 name))
  12023. ; (message "No such directory: \"%s\"" (match-string 1 name)))
  12024. (let* ((dir-name (match-string 1 name))
  12025. (file-pattern (match-string 2 name))
  12026. (is-directory (= 0 (length file-pattern)))
  12027. (file-list
  12028. (if update
  12029. (list name)
  12030. (if is-directory
  12031. (vhdl-get-source-files t dir-name)
  12032. (vhdl-directory-files
  12033. dir-name t (wildcard-to-regexp file-pattern)))))
  12034. (key (or project dir-name))
  12035. (file-exclude-regexp
  12036. (or (nth 3 (aget vhdl-project-alist project)) ""))
  12037. (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
  12038. (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
  12039. (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
  12040. ent-alist conf-alist pack-alist ent-inst-list file-alist
  12041. tmp-list tmp-entry no-files files-exist big-files)
  12042. (when (or project update)
  12043. (setq ent-alist (aget vhdl-entity-alist key t)
  12044. conf-alist (aget vhdl-config-alist key t)
  12045. pack-alist (aget vhdl-package-alist key t)
  12046. ent-inst-list (car (aget vhdl-ent-inst-alist key t))
  12047. file-alist (aget vhdl-file-alist key t)))
  12048. (when (and (not is-directory) (null file-list))
  12049. (message "No such file: \"%s\"" name))
  12050. (setq files-exist file-list)
  12051. (when file-list
  12052. (setq no-files (length file-list))
  12053. (message "Scanning %s %s\"%s\"..."
  12054. (if is-directory "directory" "files") (or num-string "") name)
  12055. ;; exclude files
  12056. (unless (equal file-exclude-regexp "")
  12057. (let ((case-fold-search nil)
  12058. file-tmp-list)
  12059. (while file-list
  12060. (unless (string-match file-exclude-regexp (car file-list))
  12061. (setq file-tmp-list (cons (car file-list) file-tmp-list)))
  12062. (setq file-list (cdr file-list)))
  12063. (setq file-list (nreverse file-tmp-list))))
  12064. ;; do for all files
  12065. (while file-list
  12066. (unless noninteractive
  12067. (message "Scanning %s %s\"%s\"... (%2d%s)"
  12068. (if is-directory "directory" "files")
  12069. (or num-string "") name
  12070. (/ (* 100 (- no-files (length file-list))) no-files) "%"))
  12071. (let ((file-name (abbreviate-file-name (car file-list)))
  12072. ent-list arch-list arch-ent-list conf-list
  12073. pack-list pack-body-list inst-list inst-ent-list)
  12074. ;; scan file
  12075. (vhdl-visit-file
  12076. file-name nil
  12077. (vhdl-prepare-search-2
  12078. (save-excursion
  12079. ;; scan for design units
  12080. (if (and limit-design-file-size
  12081. (< limit-design-file-size (buffer-size)))
  12082. (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
  12083. (setq big-files t))
  12084. ;; scan for entities
  12085. (goto-char (point-min))
  12086. (while (re-search-forward "^[ \t]*entity[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
  12087. (let* ((ent-name (match-string-no-properties 1))
  12088. (ent-key (downcase ent-name))
  12089. (ent-entry (aget ent-alist ent-key t))
  12090. (lib-alist (vhdl-scan-context-clause)))
  12091. (if (nth 1 ent-entry)
  12092. (vhdl-warning-when-idle
  12093. "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
  12094. ent-name (nth 1 ent-entry) (nth 2 ent-entry)
  12095. file-name (vhdl-current-line))
  12096. (setq ent-list (cons ent-key ent-list))
  12097. (aput 'ent-alist ent-key
  12098. (list ent-name file-name (vhdl-current-line)
  12099. (nth 3 ent-entry) (nth 4 ent-entry)
  12100. lib-alist)))))
  12101. ;; scan for architectures
  12102. (goto-char (point-min))
  12103. (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
  12104. (let* ((arch-name (match-string-no-properties 1))
  12105. (arch-key (downcase arch-name))
  12106. (ent-name (match-string-no-properties 2))
  12107. (ent-key (downcase ent-name))
  12108. (ent-entry (aget ent-alist ent-key t))
  12109. (arch-alist (nth 3 ent-entry))
  12110. (arch-entry (aget arch-alist arch-key t))
  12111. (lib-arch-alist (vhdl-scan-context-clause)))
  12112. (if arch-entry
  12113. (vhdl-warning-when-idle
  12114. "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
  12115. arch-name ent-name (nth 1 arch-entry)
  12116. (nth 2 arch-entry) file-name (vhdl-current-line))
  12117. (setq arch-list (cons arch-key arch-list)
  12118. arch-ent-list (cons ent-key arch-ent-list))
  12119. (aput 'arch-alist arch-key
  12120. (list arch-name file-name (vhdl-current-line) nil
  12121. lib-arch-alist))
  12122. (aput 'ent-alist ent-key
  12123. (list (or (nth 0 ent-entry) ent-name)
  12124. (nth 1 ent-entry) (nth 2 ent-entry)
  12125. (vhdl-sort-alist arch-alist)
  12126. arch-key (nth 5 ent-entry))))))
  12127. ;; scan for configurations
  12128. (goto-char (point-min))
  12129. (while (re-search-forward "^[ \t]*configuration[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
  12130. (let* ((conf-name (match-string-no-properties 1))
  12131. (conf-key (downcase conf-name))
  12132. (conf-entry (aget conf-alist conf-key t))
  12133. (ent-name (match-string-no-properties 2))
  12134. (ent-key (downcase ent-name))
  12135. (lib-alist (vhdl-scan-context-clause))
  12136. (conf-line (vhdl-current-line))
  12137. (end-of-unit (vhdl-get-end-of-unit))
  12138. arch-key comp-conf-list inst-key-list
  12139. inst-comp-key inst-ent-key inst-arch-key
  12140. inst-conf-key inst-lib-key)
  12141. (when (vhdl-re-search-forward "\\<for[ \t\n]+\\(\\w+\\)")
  12142. (setq arch-key (vhdl-match-string-downcase 1)))
  12143. (if conf-entry
  12144. (vhdl-warning-when-idle
  12145. "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
  12146. conf-name ent-name (nth 1 conf-entry)
  12147. (nth 2 conf-entry) file-name conf-line)
  12148. (setq conf-list (cons conf-key conf-list))
  12149. ;; scan for subconfigurations and subentities
  12150. (while (re-search-forward "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+" end-of-unit t)
  12151. (setq inst-comp-key (vhdl-match-string-downcase 3)
  12152. inst-key-list (split-string
  12153. (vhdl-match-string-downcase 1)
  12154. "[ \t\n]*,[ \t\n]*"))
  12155. (vhdl-forward-syntactic-ws)
  12156. (when (looking-at "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n]*\\((\\(\\w+\\))\\)?")
  12157. (setq
  12158. inst-lib-key (vhdl-match-string-downcase 3)
  12159. inst-ent-key (and (match-string 2)
  12160. (vhdl-match-string-downcase 4))
  12161. inst-arch-key (and (match-string 2)
  12162. (vhdl-match-string-downcase 6))
  12163. inst-conf-key (and (not (match-string 2))
  12164. (vhdl-match-string-downcase 4)))
  12165. (while inst-key-list
  12166. (setq comp-conf-list
  12167. (cons (list (car inst-key-list)
  12168. inst-comp-key inst-ent-key
  12169. inst-arch-key inst-conf-key
  12170. inst-lib-key)
  12171. comp-conf-list))
  12172. (setq inst-key-list (cdr inst-key-list)))))
  12173. (aput 'conf-alist conf-key
  12174. (list conf-name file-name conf-line ent-key
  12175. arch-key comp-conf-list lib-alist)))))
  12176. ;; scan for packages
  12177. (goto-char (point-min))
  12178. (while (re-search-forward "^[ \t]*package[ \t\n]+\\(body[ \t\n]+\\)?\\(\\w+\\)[ \t\n]+is\\>" nil t)
  12179. (let* ((pack-name (match-string-no-properties 2))
  12180. (pack-key (downcase pack-name))
  12181. (is-body (match-string-no-properties 1))
  12182. (pack-entry (aget pack-alist pack-key t))
  12183. (pack-line (vhdl-current-line))
  12184. (end-of-unit (vhdl-get-end-of-unit))
  12185. comp-name func-name comp-alist func-alist lib-alist)
  12186. (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
  12187. (vhdl-warning-when-idle
  12188. "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
  12189. (if is-body " body" "") pack-name
  12190. (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
  12191. (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
  12192. file-name (vhdl-current-line))
  12193. ;; scan for context clauses
  12194. (setq lib-alist (vhdl-scan-context-clause))
  12195. ;; scan for component and subprogram declarations/bodies
  12196. (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
  12197. (if (equal (upcase (match-string 1)) "COMPONENT")
  12198. (setq comp-name (match-string-no-properties 2)
  12199. comp-alist
  12200. (cons (list (downcase comp-name) comp-name
  12201. file-name (vhdl-current-line))
  12202. comp-alist))
  12203. (setq func-name (match-string-no-properties 2)
  12204. func-alist
  12205. (cons (list (downcase func-name) func-name
  12206. file-name (vhdl-current-line))
  12207. func-alist))))
  12208. (setq func-alist (nreverse func-alist))
  12209. (setq comp-alist (nreverse comp-alist))
  12210. (if is-body
  12211. (setq pack-body-list (cons pack-key pack-body-list))
  12212. (setq pack-list (cons pack-key pack-list)))
  12213. (aput
  12214. 'pack-alist pack-key
  12215. (if is-body
  12216. (list (or (nth 0 pack-entry) pack-name)
  12217. (nth 1 pack-entry) (nth 2 pack-entry)
  12218. (nth 3 pack-entry) (nth 4 pack-entry)
  12219. (nth 5 pack-entry)
  12220. file-name pack-line func-alist lib-alist)
  12221. (list pack-name file-name pack-line
  12222. comp-alist func-alist lib-alist
  12223. (nth 6 pack-entry) (nth 7 pack-entry)
  12224. (nth 8 pack-entry) (nth 9 pack-entry))))))))
  12225. ;; scan for hierarchy
  12226. (if (and limit-hier-file-size
  12227. (< limit-hier-file-size (buffer-size)))
  12228. (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
  12229. (setq big-files t))
  12230. ;; scan for architectures
  12231. (goto-char (point-min))
  12232. (while (re-search-forward "^[ \t]*architecture[ \t\n]+\\(\\w+\\)[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
  12233. (let* ((ent-name (match-string-no-properties 2))
  12234. (ent-key (downcase ent-name))
  12235. (arch-name (match-string-no-properties 1))
  12236. (arch-key (downcase arch-name))
  12237. (ent-entry (aget ent-alist ent-key t))
  12238. (arch-alist (nth 3 ent-entry))
  12239. (arch-entry (aget arch-alist arch-key t))
  12240. (beg-of-unit (point))
  12241. (end-of-unit (vhdl-get-end-of-unit))
  12242. (inst-no 0)
  12243. inst-alist inst-path)
  12244. ;; scan for contained instantiations
  12245. (while (and (re-search-forward
  12246. (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
  12247. "\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(generic\\|port\\)[ \t\n]+map\\>\\|"
  12248. "component[ \t\n]+\\(\\w+\\)\\|"
  12249. "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?\\|"
  12250. "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
  12251. "\\(^[ \t]*end[ \t\n]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
  12252. (or (not limit-hier-inst-no)
  12253. (<= (setq inst-no (1+ inst-no))
  12254. limit-hier-inst-no)))
  12255. (cond
  12256. ;; block/generate beginning found
  12257. ((match-string 14)
  12258. (setq inst-path
  12259. (cons (match-string-no-properties 1) inst-path)))
  12260. ;; block/generate end found
  12261. ((match-string 16)
  12262. (setq inst-path (cdr inst-path)))
  12263. ;; instantiation found
  12264. (t
  12265. (let* ((inst-name (match-string-no-properties 1))
  12266. (inst-key (downcase inst-name))
  12267. (inst-comp-name
  12268. (or (match-string-no-properties 3)
  12269. (match-string-no-properties 6)))
  12270. (inst-ent-key
  12271. (or (and (match-string 8)
  12272. (vhdl-match-string-downcase 11))
  12273. (and inst-comp-name
  12274. (downcase inst-comp-name))))
  12275. (inst-arch-key (vhdl-match-string-downcase 13))
  12276. (inst-conf-key
  12277. (and (not (match-string 8))
  12278. (vhdl-match-string-downcase 11)))
  12279. (inst-lib-key (vhdl-match-string-downcase 10)))
  12280. (goto-char (match-end 1))
  12281. (setq inst-list (cons inst-key inst-list)
  12282. inst-ent-list
  12283. (cons inst-ent-key inst-ent-list))
  12284. (setq inst-alist
  12285. (append
  12286. inst-alist
  12287. (list (list inst-key inst-name file-name
  12288. (vhdl-current-line) inst-comp-name
  12289. inst-ent-key inst-arch-key
  12290. inst-conf-key inst-lib-key
  12291. (reverse inst-path)))))))))
  12292. ;; scan for contained configuration specifications
  12293. (goto-char beg-of-unit)
  12294. (while (re-search-forward
  12295. (concat "^[ \t]*for[ \t\n]+\\(\\w+\\([ \t\n]*,[ \t\n]*\\w+\\)*\\)[ \t\n]*:[ \t\n]*\\(\\w+\\)[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*"
  12296. "use[ \t\n]+\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?") end-of-unit t)
  12297. (let* ((inst-comp-name (match-string-no-properties 3))
  12298. (inst-ent-key
  12299. (and (match-string 6)
  12300. (vhdl-match-string-downcase 9)))
  12301. (inst-arch-key (vhdl-match-string-downcase 11))
  12302. (inst-conf-key
  12303. (and (not (match-string 6))
  12304. (vhdl-match-string-downcase 9)))
  12305. (inst-lib-key (vhdl-match-string-downcase 8))
  12306. (inst-key-list
  12307. (split-string (vhdl-match-string-downcase 1)
  12308. "[ \t\n]*,[ \t\n]*"))
  12309. (tmp-inst-alist inst-alist)
  12310. inst-entry)
  12311. (while tmp-inst-alist
  12312. (when (and (or (equal "all" (car inst-key-list))
  12313. (member (nth 0 (car tmp-inst-alist))
  12314. inst-key-list))
  12315. (equal
  12316. (downcase
  12317. (or (nth 4 (car tmp-inst-alist)) ""))
  12318. (downcase inst-comp-name)))
  12319. (setq inst-entry (car tmp-inst-alist))
  12320. (setq inst-ent-list
  12321. (cons (or inst-ent-key (nth 5 inst-entry))
  12322. (vhdl-delete
  12323. (nth 5 inst-entry) inst-ent-list)))
  12324. (setq inst-entry
  12325. (list (nth 0 inst-entry) (nth 1 inst-entry)
  12326. (nth 2 inst-entry) (nth 3 inst-entry)
  12327. (nth 4 inst-entry)
  12328. (or inst-ent-key (nth 5 inst-entry))
  12329. (or inst-arch-key (nth 6 inst-entry))
  12330. inst-conf-key inst-lib-key))
  12331. (setcar tmp-inst-alist inst-entry))
  12332. (setq tmp-inst-alist (cdr tmp-inst-alist)))))
  12333. ;; save in cache
  12334. (aput 'arch-alist arch-key
  12335. (list (nth 0 arch-entry) (nth 1 arch-entry)
  12336. (nth 2 arch-entry) inst-alist
  12337. (nth 4 arch-entry)))
  12338. (aput 'ent-alist ent-key
  12339. (list (nth 0 ent-entry) (nth 1 ent-entry)
  12340. (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
  12341. (nth 4 ent-entry) (nth 5 ent-entry)))
  12342. (when (and limit-hier-inst-no
  12343. (> inst-no limit-hier-inst-no))
  12344. (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
  12345. (setq big-files t))
  12346. (goto-char end-of-unit))))
  12347. ;; remember design units for this file
  12348. (aput 'file-alist file-name
  12349. (list ent-list arch-list arch-ent-list conf-list
  12350. pack-list pack-body-list inst-list inst-ent-list))
  12351. (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
  12352. (setq file-list (cdr file-list))))
  12353. (when (or (and (not project) files-exist)
  12354. (and project (not non-final)))
  12355. ;; consistency checks:
  12356. ;; check whether each architecture has a corresponding entity
  12357. (setq tmp-list ent-alist)
  12358. (while tmp-list
  12359. (when (null (nth 2 (car tmp-list)))
  12360. (setq tmp-entry (car (nth 4 (car tmp-list))))
  12361. (vhdl-warning-when-idle
  12362. "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
  12363. (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
  12364. (nth 3 tmp-entry)))
  12365. (setq tmp-list (cdr tmp-list)))
  12366. ;; check whether configuration has a corresponding entity/architecture
  12367. (setq tmp-list conf-alist)
  12368. (while tmp-list
  12369. (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
  12370. (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
  12371. (setq tmp-entry (car tmp-list))
  12372. (vhdl-warning-when-idle
  12373. "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
  12374. (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
  12375. (nth 2 tmp-entry) (nth 3 tmp-entry)))
  12376. (setq tmp-entry (car tmp-list))
  12377. (vhdl-warning-when-idle
  12378. "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
  12379. (nth 1 tmp-entry) (nth 4 tmp-entry)
  12380. (nth 2 tmp-entry) (nth 3 tmp-entry)))
  12381. (setq tmp-list (cdr tmp-list)))
  12382. ;; check whether each package body has a package declaration
  12383. (setq tmp-list pack-alist)
  12384. (while tmp-list
  12385. (when (null (nth 2 (car tmp-list)))
  12386. (setq tmp-entry (car tmp-list))
  12387. (vhdl-warning-when-idle
  12388. "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
  12389. (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
  12390. (setq tmp-list (cdr tmp-list)))
  12391. ;; sort lists
  12392. (setq ent-alist (vhdl-sort-alist ent-alist))
  12393. (setq conf-alist (vhdl-sort-alist conf-alist))
  12394. (setq pack-alist (vhdl-sort-alist pack-alist))
  12395. ;; remember updated directory/project
  12396. (add-to-list 'vhdl-updated-project-list (or project dir-name)))
  12397. ;; clear directory alists
  12398. (unless project
  12399. (adelete 'vhdl-entity-alist key)
  12400. (adelete 'vhdl-config-alist key)
  12401. (adelete 'vhdl-package-alist key)
  12402. (adelete 'vhdl-ent-inst-alist key)
  12403. (adelete 'vhdl-file-alist key))
  12404. ;; put directory contents into cache
  12405. (aput 'vhdl-entity-alist key ent-alist)
  12406. (aput 'vhdl-config-alist key conf-alist)
  12407. (aput 'vhdl-package-alist key pack-alist)
  12408. (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
  12409. (aput 'vhdl-file-alist key file-alist)
  12410. ;; final messages
  12411. (message "Scanning %s %s\"%s\"...done"
  12412. (if is-directory "directory" "files") (or num-string "") name)
  12413. (unless project (message "Scanning directory...done"))
  12414. (when big-files
  12415. (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
  12416. ;; save cache when scanned non-interactively
  12417. (when (or (not project) (not non-final))
  12418. (when (and noninteractive vhdl-speedbar-save-cache)
  12419. (vhdl-save-cache key)))
  12420. t))
  12421. (defun vhdl-scan-project-contents (project)
  12422. "Scan the contents of all VHDL files found in the directories and files
  12423. of PROJECT."
  12424. (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
  12425. (default-dir (vhdl-resolve-env-variable
  12426. (nth 1 (aget vhdl-project-alist project))))
  12427. (file-exclude-regexp
  12428. (or (nth 3 (aget vhdl-project-alist project)) ""))
  12429. dir-list-tmp dir dir-name num-dir act-dir recursive)
  12430. ;; clear project alists
  12431. (adelete 'vhdl-entity-alist project)
  12432. (adelete 'vhdl-config-alist project)
  12433. (adelete 'vhdl-package-alist project)
  12434. (adelete 'vhdl-ent-inst-alist project)
  12435. (adelete 'vhdl-file-alist project)
  12436. ;; expand directory names by default-directory
  12437. (message "Collecting source files...")
  12438. (while dir-list
  12439. (setq dir (vhdl-resolve-env-variable (car dir-list)))
  12440. (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
  12441. (setq recursive (match-string 1 dir)
  12442. dir-name (match-string 3 dir))
  12443. (setq dir-list-tmp
  12444. (cons (concat recursive
  12445. (if (file-name-absolute-p dir-name) "" default-dir)
  12446. dir-name)
  12447. dir-list-tmp))
  12448. (setq dir-list (cdr dir-list)))
  12449. ;; resolve path wildcards
  12450. (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
  12451. ;; expand directories
  12452. (while dir-list-tmp
  12453. (setq dir (car dir-list-tmp))
  12454. ;; get subdirectories
  12455. (if (string-match "-r \\(.*[/\\]\\)" dir)
  12456. (setq dir-list (append dir-list (vhdl-get-subdirs
  12457. (match-string 1 dir))))
  12458. (setq dir-list (append dir-list (list dir))))
  12459. (setq dir-list-tmp (cdr dir-list-tmp)))
  12460. ;; exclude files
  12461. (unless (equal file-exclude-regexp "")
  12462. (let ((case-fold-search nil))
  12463. (while dir-list
  12464. (unless (string-match file-exclude-regexp (car dir-list))
  12465. (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
  12466. (setq dir-list (cdr dir-list)))
  12467. (setq dir-list (nreverse dir-list-tmp))))
  12468. (message "Collecting source files...done")
  12469. ;; scan for design units for each directory in DIR-LIST
  12470. (setq dir-list-tmp nil
  12471. num-dir (length dir-list)
  12472. act-dir 1)
  12473. (while dir-list
  12474. (setq dir-name (abbreviate-file-name
  12475. (expand-file-name (car dir-list))))
  12476. (vhdl-scan-directory-contents dir-name project nil
  12477. (format "(%s/%s) " act-dir num-dir)
  12478. (cdr dir-list))
  12479. (add-to-list 'dir-list-tmp (file-name-directory dir-name))
  12480. (setq dir-list (cdr dir-list)
  12481. act-dir (1+ act-dir)))
  12482. (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
  12483. (message "Scanning project \"%s\"...done" project)))
  12484. (defun vhdl-update-file-contents (file-name)
  12485. "Update hierarchy information by contents of current buffer."
  12486. (setq file-name (abbreviate-file-name file-name))
  12487. (let* ((dir-name (file-name-directory file-name))
  12488. (directory-alist vhdl-directory-alist)
  12489. updated)
  12490. (while directory-alist
  12491. (when (member dir-name (nth 1 (car directory-alist)))
  12492. (let* ((vhdl-project (nth 0 (car directory-alist)))
  12493. (project (vhdl-project-p))
  12494. (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
  12495. (conf-alist (aget vhdl-config-alist (or project dir-name) t))
  12496. (pack-alist (aget vhdl-package-alist (or project dir-name) t))
  12497. (ent-inst-list (car (aget vhdl-ent-inst-alist
  12498. (or project dir-name) t)))
  12499. (file-alist (aget vhdl-file-alist (or project dir-name) t))
  12500. (file-entry (aget file-alist file-name t))
  12501. (ent-list (nth 0 file-entry))
  12502. (arch-list (nth 1 file-entry))
  12503. (arch-ent-list (nth 2 file-entry))
  12504. (conf-list (nth 3 file-entry))
  12505. (pack-list (nth 4 file-entry))
  12506. (pack-body-list (nth 5 file-entry))
  12507. (inst-ent-list (nth 7 file-entry))
  12508. (cache-key (or project dir-name))
  12509. arch-alist key ent-key entry)
  12510. ;; delete design units previously contained in this file:
  12511. ;; entities
  12512. (while ent-list
  12513. (setq key (car ent-list)
  12514. entry (aget ent-alist key t))
  12515. (when (equal file-name (nth 1 entry))
  12516. (if (nth 3 entry)
  12517. (aput 'ent-alist key
  12518. (list (nth 0 entry) nil nil (nth 3 entry) nil))
  12519. (adelete 'ent-alist key)))
  12520. (setq ent-list (cdr ent-list)))
  12521. ;; architectures
  12522. (while arch-list
  12523. (setq key (car arch-list)
  12524. ent-key (car arch-ent-list)
  12525. entry (aget ent-alist ent-key t)
  12526. arch-alist (nth 3 entry))
  12527. (when (equal file-name (nth 1 (aget arch-alist key t)))
  12528. (adelete 'arch-alist key)
  12529. (if (or (nth 1 entry) arch-alist)
  12530. (aput 'ent-alist ent-key
  12531. (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
  12532. arch-alist (nth 4 entry) (nth 5 entry)))
  12533. (adelete 'ent-alist ent-key)))
  12534. (setq arch-list (cdr arch-list)
  12535. arch-ent-list (cdr arch-ent-list)))
  12536. ;; configurations
  12537. (while conf-list
  12538. (setq key (car conf-list))
  12539. (when (equal file-name (nth 1 (aget conf-alist key t)))
  12540. (adelete 'conf-alist key))
  12541. (setq conf-list (cdr conf-list)))
  12542. ;; package declarations
  12543. (while pack-list
  12544. (setq key (car pack-list)
  12545. entry (aget pack-alist key t))
  12546. (when (equal file-name (nth 1 entry))
  12547. (if (nth 6 entry)
  12548. (aput 'pack-alist key
  12549. (list (nth 0 entry) nil nil nil nil nil
  12550. (nth 6 entry) (nth 7 entry) (nth 8 entry)
  12551. (nth 9 entry)))
  12552. (adelete 'pack-alist key)))
  12553. (setq pack-list (cdr pack-list)))
  12554. ;; package bodies
  12555. (while pack-body-list
  12556. (setq key (car pack-body-list)
  12557. entry (aget pack-alist key t))
  12558. (when (equal file-name (nth 6 entry))
  12559. (if (nth 1 entry)
  12560. (aput 'pack-alist key
  12561. (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
  12562. (nth 3 entry) (nth 4 entry) (nth 5 entry)
  12563. nil nil nil nil))
  12564. (adelete 'pack-alist key)))
  12565. (setq pack-body-list (cdr pack-body-list)))
  12566. ;; instantiated entities
  12567. (while inst-ent-list
  12568. (setq ent-inst-list
  12569. (vhdl-delete (car inst-ent-list) ent-inst-list))
  12570. (setq inst-ent-list (cdr inst-ent-list)))
  12571. ;; update caches
  12572. (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
  12573. (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
  12574. (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
  12575. (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
  12576. ;; scan file
  12577. (vhdl-scan-directory-contents file-name project t)
  12578. (when (or (and vhdl-speedbar-show-projects project)
  12579. (and (not vhdl-speedbar-show-projects) (not project)))
  12580. (vhdl-speedbar-refresh project))
  12581. (setq updated t)))
  12582. (setq directory-alist (cdr directory-alist)))
  12583. updated))
  12584. (defun vhdl-update-hierarchy ()
  12585. "Update directory and hierarchy information in speedbar."
  12586. (let ((file-list (reverse vhdl-modified-file-list))
  12587. updated)
  12588. (when (and vhdl-speedbar-update-on-saving file-list)
  12589. (while file-list
  12590. (setq updated
  12591. (or (vhdl-update-file-contents (car file-list))
  12592. updated))
  12593. (setq file-list (cdr file-list)))
  12594. (setq vhdl-modified-file-list nil)
  12595. (vhdl-speedbar-update-current-unit)
  12596. (when updated (message "Updating hierarchy...done")))))
  12597. ;; structure (parenthesized expression means list of such entries)
  12598. ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
  12599. ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
  12600. ;; comp-lib-name level)
  12601. (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
  12602. conf-inst-alist level indent
  12603. &optional include-top ent-hier)
  12604. "Get instantiation hierarchy beginning in architecture ARCH-KEY of
  12605. entity ENT-KEY."
  12606. (let* ((ent-entry (aget ent-alist ent-key t))
  12607. (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
  12608. (cdar (last (nth 3 ent-entry)))))
  12609. (inst-alist (nth 3 arch-entry))
  12610. inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
  12611. hier-list subcomp-list tmp-list inst-key inst-comp-name
  12612. inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
  12613. (when (= level 0) (message "Extract design hierarchy..."))
  12614. (when include-top
  12615. (setq level (1+ level)))
  12616. (when (member ent-key ent-hier)
  12617. (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
  12618. ;; check configured architecture (already checked during scanning)
  12619. ; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
  12620. ; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
  12621. ;; process all instances
  12622. (while inst-alist
  12623. (setq inst-entry (car inst-alist)
  12624. inst-key (nth 0 inst-entry)
  12625. inst-comp-name (nth 4 inst-entry)
  12626. inst-conf-key (nth 7 inst-entry))
  12627. ;; search entry in configuration's instantiations list
  12628. (setq tmp-list conf-inst-alist)
  12629. (while (and tmp-list
  12630. (not (and (member (nth 0 (car tmp-list))
  12631. (list "all" inst-key))
  12632. (equal (nth 1 (car tmp-list))
  12633. (downcase (or inst-comp-name ""))))))
  12634. (setq tmp-list (cdr tmp-list)))
  12635. (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
  12636. (setq inst-conf-entry (aget conf-alist inst-conf-key t))
  12637. (when (and inst-conf-key (not inst-conf-entry))
  12638. (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
  12639. ;; determine entity
  12640. (setq inst-ent-key
  12641. (or (nth 2 (car tmp-list)) ; from configuration
  12642. (nth 3 inst-conf-entry) ; from subconfiguration
  12643. (nth 3 (aget conf-alist (nth 7 inst-entry) t))
  12644. ; from configuration spec.
  12645. (nth 5 inst-entry))) ; from direct instantiation
  12646. (setq inst-ent-entry (aget ent-alist inst-ent-key t))
  12647. ;; determine architecture
  12648. (setq inst-arch-key
  12649. (or (nth 3 (car tmp-list)) ; from configuration
  12650. (nth 4 inst-conf-entry) ; from subconfiguration
  12651. (nth 6 inst-entry) ; from direct instantiation
  12652. (nth 4 (aget conf-alist (nth 7 inst-entry)))
  12653. ; from configuration spec.
  12654. (nth 4 inst-ent-entry) ; MRA
  12655. (caar (nth 3 inst-ent-entry)))) ; first alphabetically
  12656. (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
  12657. ;; set library
  12658. (setq inst-lib-key
  12659. (or (nth 5 (car tmp-list)) ; from configuration
  12660. (nth 8 inst-entry))) ; from direct instantiation
  12661. ;; gather information for this instance
  12662. (setq comp-entry
  12663. (list (nth 1 inst-entry)
  12664. (cons (nth 2 inst-entry) (nth 3 inst-entry))
  12665. (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
  12666. (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
  12667. (or (nth 0 inst-arch-entry) inst-arch-key)
  12668. (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
  12669. (or (nth 0 inst-conf-entry) inst-conf-key)
  12670. (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
  12671. inst-lib-key level))
  12672. ;; get subcomponent hierarchy
  12673. (setq subcomp-list (vhdl-get-hierarchy
  12674. ent-alist conf-alist
  12675. inst-ent-key inst-arch-key inst-conf-key
  12676. (nth 5 inst-conf-entry)
  12677. (1+ level) indent nil (cons ent-key ent-hier)))
  12678. ;; add to list
  12679. (setq hier-list (append hier-list (list comp-entry) subcomp-list))
  12680. (setq inst-alist (cdr inst-alist)))
  12681. (when include-top
  12682. (setq hier-list
  12683. (cons (list nil nil (nth 0 ent-entry)
  12684. (cons (nth 1 ent-entry) (nth 2 ent-entry))
  12685. (nth 0 arch-entry)
  12686. (cons (nth 1 arch-entry) (nth 2 arch-entry))
  12687. nil nil
  12688. nil (1- level))
  12689. hier-list)))
  12690. (when (or (= level 0) (and include-top (= level 1))) (message ""))
  12691. hier-list))
  12692. (defun vhdl-get-instantiations (ent-key indent)
  12693. "Get all instantiations of entity ENT-KEY."
  12694. (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
  12695. arch-alist inst-alist ent-inst-list
  12696. ent-entry arch-entry inst-entry)
  12697. (while ent-alist
  12698. (setq ent-entry (car ent-alist))
  12699. (setq arch-alist (nth 4 ent-entry))
  12700. (while arch-alist
  12701. (setq arch-entry (car arch-alist))
  12702. (setq inst-alist (nth 4 arch-entry))
  12703. (while inst-alist
  12704. (setq inst-entry (car inst-alist))
  12705. (when (equal ent-key (nth 5 inst-entry))
  12706. (setq ent-inst-list
  12707. (cons (list (nth 1 inst-entry)
  12708. (cons (nth 2 inst-entry) (nth 3 inst-entry))
  12709. (nth 1 ent-entry)
  12710. (cons (nth 2 ent-entry) (nth 3 ent-entry))
  12711. (nth 1 arch-entry)
  12712. (cons (nth 2 arch-entry) (nth 3 arch-entry)))
  12713. ent-inst-list)))
  12714. (setq inst-alist (cdr inst-alist)))
  12715. (setq arch-alist (cdr arch-alist)))
  12716. (setq ent-alist (cdr ent-alist)))
  12717. (nreverse ent-inst-list)))
  12718. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12719. ;; Caching in file
  12720. (defun vhdl-save-caches ()
  12721. "Save all updated hierarchy caches to file."
  12722. (interactive)
  12723. (condition-case nil
  12724. (when vhdl-speedbar-save-cache
  12725. ;; update hierarchy
  12726. (vhdl-update-hierarchy)
  12727. (let ((project-list vhdl-updated-project-list))
  12728. (message "Saving hierarchy caches...")
  12729. ;; write updated project caches
  12730. (while project-list
  12731. (vhdl-save-cache (car project-list))
  12732. (setq project-list (cdr project-list)))
  12733. (message "Saving hierarchy caches...done")))
  12734. (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
  12735. (sit-for 2)))))
  12736. (defun vhdl-save-cache (key)
  12737. "Save current hierarchy cache to file."
  12738. (let* ((orig-buffer (current-buffer))
  12739. (vhdl-project key)
  12740. (project (vhdl-project-p))
  12741. (default-directory key)
  12742. (directory (abbreviate-file-name (vhdl-default-directory)))
  12743. (file-name (vhdl-resolve-env-variable
  12744. (vhdl-replace-string
  12745. (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
  12746. (concat
  12747. (subst-char-in-string ? ?_ (or project "dir"))
  12748. " " (user-login-name)))))
  12749. (file-dir-name (expand-file-name file-name directory))
  12750. (cache-key (or project directory))
  12751. (key (if project "project" "directory")))
  12752. (unless (file-exists-p (file-name-directory file-dir-name))
  12753. (make-directory (file-name-directory file-dir-name) t))
  12754. (if (not (file-writable-p file-dir-name))
  12755. (progn (vhdl-warning (format "File not writable: \"%s\""
  12756. (abbreviate-file-name file-dir-name)))
  12757. (sit-for 2))
  12758. (message "Saving cache: \"%s\"" file-dir-name)
  12759. (set-buffer (find-file-noselect file-dir-name t t))
  12760. (erase-buffer)
  12761. (insert ";; -*- Emacs-Lisp -*-\n\n"
  12762. ";;; " (file-name-nondirectory file-name)
  12763. " - design hierarchy cache file for Emacs VHDL Mode "
  12764. vhdl-version "\n")
  12765. (insert "\n;; " (if project "Project " "Directory") " : ")
  12766. (if project (insert project) (prin1 directory (current-buffer)))
  12767. (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
  12768. (user-login-name) "\n\n"
  12769. "\n;; version number\n"
  12770. "(setq vhdl-cache-version \"" vhdl-version "\")\n"
  12771. "\n;; " (if project "project" "directory") " name"
  12772. "\n(setq " key " ")
  12773. (prin1 (or project directory) (current-buffer))
  12774. (insert ")\n")
  12775. (when (member 'hierarchy vhdl-speedbar-save-cache)
  12776. (insert "\n;; entity and architecture cache\n"
  12777. "(aput 'vhdl-entity-alist " key " '")
  12778. (print (aget vhdl-entity-alist cache-key t) (current-buffer))
  12779. (insert ")\n\n;; configuration cache\n"
  12780. "(aput 'vhdl-config-alist " key " '")
  12781. (print (aget vhdl-config-alist cache-key t) (current-buffer))
  12782. (insert ")\n\n;; package cache\n"
  12783. "(aput 'vhdl-package-alist " key " '")
  12784. (print (aget vhdl-package-alist cache-key t) (current-buffer))
  12785. (insert ")\n\n;; instantiated entities cache\n"
  12786. "(aput 'vhdl-ent-inst-alist " key " '")
  12787. (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
  12788. (insert ")\n\n;; design units per file cache\n"
  12789. "(aput 'vhdl-file-alist " key " '")
  12790. (print (aget vhdl-file-alist cache-key t) (current-buffer))
  12791. (when project
  12792. (insert ")\n\n;; source directories in project cache\n"
  12793. "(aput 'vhdl-directory-alist " key " '")
  12794. (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
  12795. (insert ")\n"))
  12796. (when (member 'display vhdl-speedbar-save-cache)
  12797. (insert "\n;; shown design units cache\n"
  12798. "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
  12799. (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
  12800. (current-buffer))
  12801. (insert ")\n"))
  12802. (setq vhdl-updated-project-list
  12803. (delete cache-key vhdl-updated-project-list))
  12804. (save-buffer)
  12805. (kill-buffer (current-buffer))
  12806. (set-buffer orig-buffer))))
  12807. (defun vhdl-load-cache (key)
  12808. "Load hierarchy cache information from file."
  12809. (let* ((vhdl-project key)
  12810. (default-directory key)
  12811. (directory (vhdl-default-directory))
  12812. (file-name (vhdl-resolve-env-variable
  12813. (vhdl-replace-string
  12814. (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
  12815. (concat
  12816. (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
  12817. " " (user-login-name)))))
  12818. (file-dir-name (expand-file-name file-name directory))
  12819. vhdl-cache-version)
  12820. (unless (memq 'vhdl-save-caches kill-emacs-hook)
  12821. (add-hook 'kill-emacs-hook 'vhdl-save-caches))
  12822. (when (file-exists-p file-dir-name)
  12823. (condition-case ()
  12824. (progn (load-file file-dir-name)
  12825. (string< (mapconcat
  12826. (lambda (a) (format "%3d" (string-to-number a)))
  12827. (split-string "3.33" "\\.") "")
  12828. (mapconcat
  12829. (lambda (a) (format "%3d" (string-to-number a)))
  12830. (split-string vhdl-cache-version "\\.") "")))
  12831. (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
  12832. nil))))))
  12833. (defun vhdl-require-hierarchy-info ()
  12834. "Make sure that hierarchy information is available. Load cache or scan files
  12835. if required."
  12836. (if (vhdl-project-p)
  12837. (unless (or (assoc vhdl-project vhdl-file-alist)
  12838. (vhdl-load-cache vhdl-project))
  12839. (vhdl-scan-project-contents vhdl-project))
  12840. (let ((directory (abbreviate-file-name default-directory)))
  12841. (unless (or (assoc directory vhdl-file-alist)
  12842. (vhdl-load-cache directory))
  12843. (vhdl-scan-directory-contents directory)))))
  12844. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12845. ;; Add hierarchy browser functionality to speedbar
  12846. (defvar vhdl-speedbar-key-map nil
  12847. "Keymap used when in the VHDL hierarchy browser mode.")
  12848. (defvar vhdl-speedbar-menu-items nil
  12849. "Additional menu-items to add to speedbar frame.")
  12850. (defun vhdl-speedbar-initialize ()
  12851. "Initialize speedbar."
  12852. ;; general settings
  12853. ; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
  12854. ;; VHDL file extensions (extracted from `auto-mode-alist')
  12855. (let ((mode-alist auto-mode-alist))
  12856. (while mode-alist
  12857. (when (eq (cdar mode-alist) 'vhdl-mode)
  12858. (speedbar-add-supported-extension (caar mode-alist)))
  12859. (setq mode-alist (cdr mode-alist))))
  12860. ;; hierarchy browser settings
  12861. (when (boundp 'speedbar-mode-functions-list)
  12862. ;; special functions
  12863. (speedbar-add-mode-functions-list
  12864. '("vhdl directory"
  12865. (speedbar-item-info . vhdl-speedbar-item-info)
  12866. (speedbar-line-directory . speedbar-files-line-path)))
  12867. (speedbar-add-mode-functions-list
  12868. '("vhdl project"
  12869. (speedbar-item-info . vhdl-speedbar-item-info)
  12870. (speedbar-line-directory . vhdl-speedbar-line-project)))
  12871. ;; keymap
  12872. (unless vhdl-speedbar-key-map
  12873. (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
  12874. (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
  12875. (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
  12876. (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
  12877. (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
  12878. (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
  12879. (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
  12880. (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
  12881. (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
  12882. (define-key vhdl-speedbar-key-map "F" 'vhdl-speedbar-configuration)
  12883. (define-key vhdl-speedbar-key-map "A" 'vhdl-speedbar-select-mra)
  12884. (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
  12885. (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
  12886. (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
  12887. (let ((key 0))
  12888. (while (<= key 9)
  12889. (define-key vhdl-speedbar-key-map (int-to-string key)
  12890. `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
  12891. (setq key (1+ key)))))
  12892. (define-key speedbar-key-map "h"
  12893. (lambda () (interactive)
  12894. (speedbar-change-initial-expansion-list "vhdl directory")))
  12895. (define-key speedbar-key-map "H"
  12896. (lambda () (interactive)
  12897. (speedbar-change-initial-expansion-list "vhdl project")))
  12898. ;; menu
  12899. (unless vhdl-speedbar-menu-items
  12900. (setq
  12901. vhdl-speedbar-menu-items
  12902. `(["Edit" speedbar-edit-line t]
  12903. ["Expand" speedbar-expand-line
  12904. (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
  12905. ["Contract" vhdl-speedbar-contract-level t]
  12906. ["Expand All" vhdl-speedbar-expand-all t]
  12907. ["Contract All" vhdl-speedbar-contract-all t]
  12908. ,(let ((key 0) (menu-list '("Hierarchy Depth")))
  12909. (while (<= key 9)
  12910. (setq menu-list
  12911. (cons `[,(if (= key 0) "All" (int-to-string key))
  12912. (vhdl-speedbar-set-depth ,key)
  12913. :style radio
  12914. :selected (= vhdl-speedbar-hierarchy-depth ,key)
  12915. :keys ,(int-to-string key)]
  12916. menu-list))
  12917. (setq key (1+ key)))
  12918. (nreverse menu-list))
  12919. "--"
  12920. ["Copy Port/Subprogram" vhdl-speedbar-port-copy
  12921. (or (vhdl-speedbar-check-unit 'entity)
  12922. (vhdl-speedbar-check-unit 'subprogram))]
  12923. ["Place Component" vhdl-speedbar-place-component
  12924. (vhdl-speedbar-check-unit 'entity)]
  12925. ["Generate Configuration" vhdl-speedbar-configuration
  12926. (vhdl-speedbar-check-unit 'architecture)]
  12927. ["Select as MRA" vhdl-speedbar-select-mra
  12928. (vhdl-speedbar-check-unit 'architecture)]
  12929. ["Make" vhdl-speedbar-make-design
  12930. (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
  12931. ["Generate Makefile" vhdl-speedbar-generate-makefile
  12932. (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
  12933. ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
  12934. :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
  12935. ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
  12936. ["Rescan Project" vhdl-speedbar-rescan-hierarchy
  12937. :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
  12938. ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
  12939. ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
  12940. ;; hook-ups
  12941. (speedbar-add-expansion-list
  12942. '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
  12943. vhdl-speedbar-display-directory))
  12944. (speedbar-add-expansion-list
  12945. '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
  12946. vhdl-speedbar-display-projects))
  12947. (setq speedbar-stealthy-function-list
  12948. (append
  12949. '(("vhdl directory" vhdl-speedbar-update-current-unit)
  12950. ("vhdl project" vhdl-speedbar-update-current-project
  12951. vhdl-speedbar-update-current-unit)
  12952. ; ("files" (lambda () (setq speedbar-ignored-path-regexp
  12953. ; (speedbar-extension-list-to-regex
  12954. ; speedbar-ignored-path-expressions))))
  12955. )
  12956. speedbar-stealthy-function-list))
  12957. (when (eq vhdl-speedbar-display-mode 'directory)
  12958. (setq speedbar-initial-expansion-list-name "vhdl directory"))
  12959. (when (eq vhdl-speedbar-display-mode 'project)
  12960. (setq speedbar-initial-expansion-list-name "vhdl project"))
  12961. (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
  12962. (defun vhdl-speedbar (&optional arg)
  12963. "Open/close speedbar."
  12964. (interactive)
  12965. (if (not (fboundp 'speedbar))
  12966. (error "WARNING: Speedbar is not available or not installed")
  12967. (condition-case ()
  12968. (speedbar-frame-mode arg)
  12969. (error (error "WARNING: An error occurred while opening speedbar")))))
  12970. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12971. ;; Display functions
  12972. (defvar vhdl-speedbar-last-selected-project nil
  12973. "Name of last selected project.")
  12974. ;; macros must be defined in the file they are used (copied from `speedbar.el')
  12975. (defmacro speedbar-with-writable (&rest forms)
  12976. "Allow the buffer to be writable and evaluate FORMS."
  12977. (list 'let '((inhibit-read-only t))
  12978. (cons 'progn forms)))
  12979. (put 'speedbar-with-writable 'lisp-indent-function 0)
  12980. (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
  12981. "Display directory and hierarchy information in speedbar."
  12982. (setq vhdl-speedbar-show-projects nil)
  12983. (setq speedbar-ignored-directory-regexp
  12984. (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
  12985. (setq directory (abbreviate-file-name (file-name-as-directory directory)))
  12986. (setq speedbar-last-selected-file nil)
  12987. (speedbar-with-writable
  12988. (condition-case nil
  12989. (progn
  12990. ;; insert directory path
  12991. (speedbar-directory-buttons directory depth)
  12992. ;; insert subdirectories
  12993. (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
  12994. ;; scan and insert hierarchy of current directory
  12995. (vhdl-speedbar-insert-dir-hierarchy directory depth
  12996. speedbar-power-click)
  12997. ;; expand subdirectories
  12998. (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
  12999. (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
  13000. (defun vhdl-speedbar-display-projects (project depth &optional rescan)
  13001. "Display projects and hierarchy information in speedbar."
  13002. (setq vhdl-speedbar-show-projects t)
  13003. (setq speedbar-ignored-directory-regexp ".")
  13004. (setq speedbar-last-selected-file nil)
  13005. (setq vhdl-speedbar-last-selected-project nil)
  13006. (speedbar-with-writable
  13007. (condition-case nil
  13008. ;; insert projects
  13009. (vhdl-speedbar-insert-projects)
  13010. (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
  13011. (setq speedbar-full-text-cache nil)) ; prevent caching
  13012. (defun vhdl-speedbar-insert-projects ()
  13013. "Insert all projects in speedbar."
  13014. (vhdl-speedbar-make-title-line "Projects:")
  13015. (let ((project-alist (if vhdl-project-sort
  13016. (vhdl-sort-alist (copy-alist vhdl-project-alist))
  13017. vhdl-project-alist))
  13018. (vhdl-speedbar-update-current-unit nil))
  13019. ;; insert projects
  13020. (while project-alist
  13021. (speedbar-make-tag-line
  13022. 'angle ?+ 'vhdl-speedbar-expand-project
  13023. (caar project-alist) (caar project-alist)
  13024. 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
  13025. (setq project-alist (cdr project-alist)))
  13026. (setq project-alist vhdl-project-alist)
  13027. ;; expand projects
  13028. (while project-alist
  13029. (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
  13030. (goto-char (point-min))
  13031. (when (re-search-forward
  13032. (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
  13033. (goto-char (match-end 1))
  13034. (speedbar-do-function-pointer)))
  13035. (setq project-alist (cdr project-alist))))
  13036. ; (vhdl-speedbar-update-current-project)
  13037. ; (vhdl-speedbar-update-current-unit nil t)
  13038. )
  13039. (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
  13040. "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
  13041. otherwise use cached data."
  13042. (when (or rescan (and (not (assoc project vhdl-file-alist))
  13043. (not (vhdl-load-cache project))))
  13044. (vhdl-scan-project-contents project))
  13045. ;; insert design hierarchy
  13046. (vhdl-speedbar-insert-hierarchy
  13047. (aget vhdl-entity-alist project t)
  13048. (aget vhdl-config-alist project t)
  13049. (aget vhdl-package-alist project t)
  13050. (car (aget vhdl-ent-inst-alist project t)) indent)
  13051. (insert (int-to-string indent) ":\n")
  13052. (put-text-property (- (point) 3) (1- (point)) 'invisible t)
  13053. (put-text-property (1- (point)) (point) 'invisible nil)
  13054. ;; expand design units
  13055. (vhdl-speedbar-expand-units project))
  13056. (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
  13057. "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
  13058. otherwise use cached data."
  13059. (when (or rescan (and (not (assoc directory vhdl-file-alist))
  13060. (not (vhdl-load-cache directory))))
  13061. (vhdl-scan-directory-contents directory))
  13062. ;; insert design hierarchy
  13063. (vhdl-speedbar-insert-hierarchy
  13064. (aget vhdl-entity-alist directory t)
  13065. (aget vhdl-config-alist directory t)
  13066. (aget vhdl-package-alist directory t)
  13067. (car (aget vhdl-ent-inst-alist directory t)) depth)
  13068. ;; expand design units
  13069. (vhdl-speedbar-expand-units directory)
  13070. (aput 'vhdl-directory-alist directory (list (list directory))))
  13071. (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
  13072. ent-inst-list depth)
  13073. "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
  13074. (if (not (or ent-alist conf-alist pack-alist))
  13075. (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
  13076. (let (ent-entry conf-entry pack-entry)
  13077. ;; insert entities
  13078. (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
  13079. (while ent-alist
  13080. (setq ent-entry (car ent-alist))
  13081. (speedbar-make-tag-line
  13082. 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
  13083. (nth 1 ent-entry) 'vhdl-speedbar-find-file
  13084. (cons (nth 2 ent-entry) (nth 3 ent-entry))
  13085. 'vhdl-speedbar-entity-face depth)
  13086. (unless (nth 2 ent-entry)
  13087. (end-of-line 0) (insert "!") (forward-char 1))
  13088. (unless (member (nth 0 ent-entry) ent-inst-list)
  13089. (end-of-line 0) (insert " (top)") (forward-char 1))
  13090. (setq ent-alist (cdr ent-alist)))
  13091. ;; insert configurations
  13092. (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
  13093. (while conf-alist
  13094. (setq conf-entry (car conf-alist))
  13095. (speedbar-make-tag-line
  13096. 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
  13097. (nth 1 conf-entry) 'vhdl-speedbar-find-file
  13098. (cons (nth 2 conf-entry) (nth 3 conf-entry))
  13099. 'vhdl-speedbar-configuration-face depth)
  13100. (setq conf-alist (cdr conf-alist)))
  13101. ;; insert packages
  13102. (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
  13103. (while pack-alist
  13104. (setq pack-entry (car pack-alist))
  13105. (vhdl-speedbar-make-pack-line
  13106. (nth 0 pack-entry) (nth 1 pack-entry)
  13107. (cons (nth 2 pack-entry) (nth 3 pack-entry))
  13108. (cons (nth 7 pack-entry) (nth 8 pack-entry))
  13109. depth)
  13110. (setq pack-alist (cdr pack-alist))))))
  13111. (defun vhdl-speedbar-rescan-hierarchy ()
  13112. "Rescan hierarchy for the directory or project under the cursor."
  13113. (interactive)
  13114. (let (key path)
  13115. (cond
  13116. ;; current project
  13117. (vhdl-speedbar-show-projects
  13118. (setq key (vhdl-speedbar-line-project))
  13119. (vhdl-scan-project-contents key))
  13120. ;; top-level directory
  13121. ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
  13122. (re-search-forward "[0-9]+:" nil t)
  13123. (vhdl-scan-directory-contents
  13124. (abbreviate-file-name (speedbar-line-directory))))
  13125. ;; current directory
  13126. (t (setq path (speedbar-line-directory))
  13127. (string-match "^\\(.+[/\\]\\)" path)
  13128. (vhdl-scan-directory-contents
  13129. (abbreviate-file-name (match-string 1 path)))))
  13130. (vhdl-speedbar-refresh key)))
  13131. (defun vhdl-speedbar-expand-dirs (directory)
  13132. "Expand subdirectories in DIRECTORY according to
  13133. `speedbar-shown-directories'."
  13134. ;; (nicked from `speedbar-default-directory-list')
  13135. (let ((sf (cdr (reverse speedbar-shown-directories)))
  13136. (vhdl-speedbar-update-current-unit nil))
  13137. (setq speedbar-shown-directories
  13138. (list (expand-file-name default-directory)))
  13139. (while sf
  13140. (when (speedbar-goto-this-file (car sf))
  13141. (beginning-of-line)
  13142. (when (looking-at "[0-9]+:\\s-*<")
  13143. (goto-char (match-end 0))
  13144. (speedbar-do-function-pointer)))
  13145. (setq sf (cdr sf))))
  13146. (vhdl-speedbar-update-current-unit nil t))
  13147. (defun vhdl-speedbar-expand-units (key)
  13148. "Expand design units in directory/project KEY according to
  13149. `vhdl-speedbar-shown-unit-alist'."
  13150. (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
  13151. (vhdl-speedbar-update-current-unit nil)
  13152. vhdl-updated-project-list)
  13153. (adelete 'vhdl-speedbar-shown-unit-alist key)
  13154. (vhdl-prepare-search-1
  13155. (while unit-alist ; expand units
  13156. (vhdl-speedbar-goto-this-unit key (caar unit-alist))
  13157. (beginning-of-line)
  13158. (let ((arch-alist (nth 1 (car unit-alist)))
  13159. position)
  13160. (when (looking-at "^[0-9]+:\\s-*\\[")
  13161. (goto-char (match-end 0))
  13162. (setq position (point))
  13163. (speedbar-do-function-pointer)
  13164. (select-frame speedbar-frame)
  13165. (while arch-alist ; expand architectures
  13166. (goto-char position)
  13167. (when (re-search-forward
  13168. (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
  13169. (car arch-alist) "\\>\\)") nil t)
  13170. (beginning-of-line)
  13171. (when (looking-at "^[0-9]+:\\s-*{")
  13172. (goto-char (match-end 0))
  13173. (speedbar-do-function-pointer)
  13174. (select-frame speedbar-frame)))
  13175. (setq arch-alist (cdr arch-alist))))
  13176. (setq unit-alist (cdr unit-alist))))))
  13177. (vhdl-speedbar-update-current-unit nil t))
  13178. (defun vhdl-speedbar-contract-level ()
  13179. "Contract current level in current directory/project."
  13180. (interactive)
  13181. (when (or (save-excursion
  13182. (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
  13183. (and (save-excursion
  13184. (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
  13185. (re-search-backward
  13186. (format "^[0-%d]:\\s-*[[{<]-"
  13187. (max (1- (string-to-number (match-string 1))) 0)) nil t)))
  13188. (goto-char (match-end 0))
  13189. (speedbar-do-function-pointer)
  13190. (speedbar-center-buffer-smartly)))
  13191. (defun vhdl-speedbar-contract-all ()
  13192. "Contract all expanded design units in current directory/project."
  13193. (interactive)
  13194. (if (and vhdl-speedbar-show-projects
  13195. (save-excursion (beginning-of-line) (looking-at "^0:")))
  13196. (progn (setq vhdl-speedbar-shown-project-list nil)
  13197. (vhdl-speedbar-refresh))
  13198. (let ((key (vhdl-speedbar-line-key)))
  13199. (adelete 'vhdl-speedbar-shown-unit-alist key)
  13200. (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
  13201. (when (memq 'display vhdl-speedbar-save-cache)
  13202. (add-to-list 'vhdl-updated-project-list key)))))
  13203. (defun vhdl-speedbar-expand-all ()
  13204. "Expand all design units in current directory/project."
  13205. (interactive)
  13206. (let* ((key (vhdl-speedbar-line-key))
  13207. (ent-alist (aget vhdl-entity-alist key t))
  13208. (conf-alist (aget vhdl-config-alist key t))
  13209. (pack-alist (aget vhdl-package-alist key t))
  13210. arch-alist unit-alist subunit-alist)
  13211. (add-to-list 'vhdl-speedbar-shown-project-list key)
  13212. (while ent-alist
  13213. (setq arch-alist (nth 4 (car ent-alist)))
  13214. (setq subunit-alist nil)
  13215. (while arch-alist
  13216. (setq subunit-alist (cons (caar arch-alist) subunit-alist))
  13217. (setq arch-alist (cdr arch-alist)))
  13218. (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
  13219. (setq ent-alist (cdr ent-alist)))
  13220. (while conf-alist
  13221. (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
  13222. (setq conf-alist (cdr conf-alist)))
  13223. (while pack-alist
  13224. (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
  13225. (setq pack-alist (cdr pack-alist)))
  13226. (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
  13227. (vhdl-speedbar-refresh)
  13228. (when (memq 'display vhdl-speedbar-save-cache)
  13229. (add-to-list 'vhdl-updated-project-list key))))
  13230. (defun vhdl-speedbar-expand-project (text token indent)
  13231. "Expand/contract the project under the cursor."
  13232. (cond
  13233. ((string-match "+" text) ; expand project
  13234. (speedbar-change-expand-button-char ?-)
  13235. (unless (member token vhdl-speedbar-shown-project-list)
  13236. (setq vhdl-speedbar-shown-project-list
  13237. (cons token vhdl-speedbar-shown-project-list)))
  13238. (speedbar-with-writable
  13239. (save-excursion
  13240. (end-of-line) (forward-char 1)
  13241. (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
  13242. speedbar-power-click))))
  13243. ((string-match "-" text) ; contract project
  13244. (speedbar-change-expand-button-char ?+)
  13245. (setq vhdl-speedbar-shown-project-list
  13246. (delete token vhdl-speedbar-shown-project-list))
  13247. (speedbar-delete-subblock indent))
  13248. (t (error "Nothing to display")))
  13249. (when (equal (selected-frame) speedbar-frame)
  13250. (speedbar-center-buffer-smartly)))
  13251. (defun vhdl-speedbar-expand-entity (text token indent)
  13252. "Expand/contract the entity under the cursor."
  13253. (cond
  13254. ((string-match "+" text) ; expand entity
  13255. (let* ((key (vhdl-speedbar-line-key indent))
  13256. (ent-alist (aget vhdl-entity-alist key t))
  13257. (ent-entry (aget ent-alist token t))
  13258. (arch-alist (nth 3 ent-entry))
  13259. (inst-alist (vhdl-get-instantiations token indent))
  13260. (subpack-alist (nth 5 ent-entry))
  13261. (multiple-arch (> (length arch-alist) 1))
  13262. arch-entry inst-entry)
  13263. (if (not (or arch-alist inst-alist subpack-alist))
  13264. (speedbar-change-expand-button-char ??)
  13265. (speedbar-change-expand-button-char ?-)
  13266. ;; add entity to `vhdl-speedbar-shown-unit-alist'
  13267. (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
  13268. (aput 'unit-alist token nil)
  13269. (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
  13270. (speedbar-with-writable
  13271. (save-excursion
  13272. (end-of-line) (forward-char 1)
  13273. ;; insert architectures
  13274. (when arch-alist
  13275. (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
  13276. (while arch-alist
  13277. (setq arch-entry (car arch-alist))
  13278. (speedbar-make-tag-line
  13279. 'curly ?+ 'vhdl-speedbar-expand-architecture
  13280. (cons token (nth 0 arch-entry))
  13281. (nth 1 arch-entry) 'vhdl-speedbar-find-file
  13282. (cons (nth 2 arch-entry) (nth 3 arch-entry))
  13283. 'vhdl-speedbar-architecture-face (1+ indent))
  13284. (when (and multiple-arch
  13285. (equal (nth 0 arch-entry) (nth 4 ent-entry)))
  13286. (end-of-line 0) (insert " (mra)") (forward-char 1))
  13287. (setq arch-alist (cdr arch-alist)))
  13288. ;; insert instantiations
  13289. (when inst-alist
  13290. (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
  13291. (while inst-alist
  13292. (setq inst-entry (car inst-alist))
  13293. (vhdl-speedbar-make-inst-line
  13294. (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
  13295. (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
  13296. nil nil nil (1+ indent) 0 " in ")
  13297. (setq inst-alist (cdr inst-alist)))
  13298. ;; insert required packages
  13299. (vhdl-speedbar-insert-subpackages
  13300. subpack-alist (1+ indent) indent)))
  13301. (when (memq 'display vhdl-speedbar-save-cache)
  13302. (add-to-list 'vhdl-updated-project-list key))
  13303. (vhdl-speedbar-update-current-unit t t))))
  13304. ((string-match "-" text) ; contract entity
  13305. (speedbar-change-expand-button-char ?+)
  13306. ;; remove entity from `vhdl-speedbar-shown-unit-alist'
  13307. (let* ((key (vhdl-speedbar-line-key indent))
  13308. (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
  13309. (adelete 'unit-alist token)
  13310. (if unit-alist
  13311. (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
  13312. (adelete 'vhdl-speedbar-shown-unit-alist key))
  13313. (speedbar-delete-subblock indent)
  13314. (when (memq 'display vhdl-speedbar-save-cache)
  13315. (add-to-list 'vhdl-updated-project-list key))))
  13316. (t (error "Nothing to display")))
  13317. (when (equal (selected-frame) speedbar-frame)
  13318. (speedbar-center-buffer-smartly)))
  13319. (defun vhdl-speedbar-expand-architecture (text token indent)
  13320. "Expand/contract the architecture under the cursor."
  13321. (cond
  13322. ((string-match "+" text) ; expand architecture
  13323. (let* ((key (vhdl-speedbar-line-key (1- indent)))
  13324. (ent-alist (aget vhdl-entity-alist key t))
  13325. (conf-alist (aget vhdl-config-alist key t))
  13326. (hier-alist (vhdl-get-hierarchy
  13327. ent-alist conf-alist (car token) (cdr token) nil nil
  13328. 0 (1- indent)))
  13329. (ent-entry (aget ent-alist (car token) t))
  13330. (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
  13331. (subpack-alist (nth 4 arch-entry))
  13332. entry)
  13333. (if (not (or hier-alist subpack-alist))
  13334. (speedbar-change-expand-button-char ??)
  13335. (speedbar-change-expand-button-char ?-)
  13336. ;; add architecture to `vhdl-speedbar-shown-unit-alist'
  13337. (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
  13338. (arch-alist (nth 0 (aget unit-alist (car token) t))))
  13339. (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
  13340. (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
  13341. (speedbar-with-writable
  13342. (save-excursion
  13343. (end-of-line) (forward-char 1)
  13344. ;; insert instance hierarchy
  13345. (when hier-alist
  13346. (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
  13347. (1+ indent)))
  13348. (while hier-alist
  13349. (setq entry (car hier-alist))
  13350. (when (or (= vhdl-speedbar-hierarchy-depth 0)
  13351. (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
  13352. (vhdl-speedbar-make-inst-line
  13353. (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
  13354. (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
  13355. (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
  13356. (setq hier-alist (cdr hier-alist)))
  13357. ;; insert required packages
  13358. (vhdl-speedbar-insert-subpackages
  13359. subpack-alist (1+ indent) (1- indent))))
  13360. (when (memq 'display vhdl-speedbar-save-cache)
  13361. (add-to-list 'vhdl-updated-project-list key))
  13362. (vhdl-speedbar-update-current-unit t t))))
  13363. ((string-match "-" text) ; contract architecture
  13364. (speedbar-change-expand-button-char ?+)
  13365. ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
  13366. (let* ((key (vhdl-speedbar-line-key (1- indent)))
  13367. (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
  13368. (arch-alist (nth 0 (aget unit-alist (car token) t))))
  13369. (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
  13370. (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
  13371. (speedbar-delete-subblock indent)
  13372. (when (memq 'display vhdl-speedbar-save-cache)
  13373. (add-to-list 'vhdl-updated-project-list key))))
  13374. (t (error "Nothing to display")))
  13375. (when (equal (selected-frame) speedbar-frame)
  13376. (speedbar-center-buffer-smartly)))
  13377. (defun vhdl-speedbar-expand-config (text token indent)
  13378. "Expand/contract the configuration under the cursor."
  13379. (cond
  13380. ((string-match "+" text) ; expand configuration
  13381. (let* ((key (vhdl-speedbar-line-key indent))
  13382. (conf-alist (aget vhdl-config-alist key t))
  13383. (conf-entry (aget conf-alist token))
  13384. (ent-alist (aget vhdl-entity-alist key t))
  13385. (hier-alist (vhdl-get-hierarchy
  13386. ent-alist conf-alist (nth 3 conf-entry)
  13387. (nth 4 conf-entry) token (nth 5 conf-entry)
  13388. 0 indent t))
  13389. (subpack-alist (nth 6 conf-entry))
  13390. entry)
  13391. (if (not (or hier-alist subpack-alist))
  13392. (speedbar-change-expand-button-char ??)
  13393. (speedbar-change-expand-button-char ?-)
  13394. ;; add configuration to `vhdl-speedbar-shown-unit-alist'
  13395. (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
  13396. (aput 'unit-alist token nil)
  13397. (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
  13398. (speedbar-with-writable
  13399. (save-excursion
  13400. (end-of-line) (forward-char 1)
  13401. ;; insert instance hierarchy
  13402. (when hier-alist
  13403. (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
  13404. (while hier-alist
  13405. (setq entry (car hier-alist))
  13406. (when (or (= vhdl-speedbar-hierarchy-depth 0)
  13407. (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
  13408. (vhdl-speedbar-make-inst-line
  13409. (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
  13410. (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
  13411. (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
  13412. (setq hier-alist (cdr hier-alist)))
  13413. ;; insert required packages
  13414. (vhdl-speedbar-insert-subpackages
  13415. subpack-alist (1+ indent) indent)))
  13416. (when (memq 'display vhdl-speedbar-save-cache)
  13417. (add-to-list 'vhdl-updated-project-list key))
  13418. (vhdl-speedbar-update-current-unit t t))))
  13419. ((string-match "-" text) ; contract configuration
  13420. (speedbar-change-expand-button-char ?+)
  13421. ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
  13422. (let* ((key (vhdl-speedbar-line-key indent))
  13423. (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
  13424. (adelete 'unit-alist token)
  13425. (if unit-alist
  13426. (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
  13427. (adelete 'vhdl-speedbar-shown-unit-alist key))
  13428. (speedbar-delete-subblock indent)
  13429. (when (memq 'display vhdl-speedbar-save-cache)
  13430. (add-to-list 'vhdl-updated-project-list key))))
  13431. (t (error "Nothing to display")))
  13432. (when (equal (selected-frame) speedbar-frame)
  13433. (speedbar-center-buffer-smartly)))
  13434. (defun vhdl-speedbar-expand-package (text token indent)
  13435. "Expand/contract the package under the cursor."
  13436. (cond
  13437. ((string-match "+" text) ; expand package
  13438. (let* ((key (vhdl-speedbar-line-key indent))
  13439. (pack-alist (aget vhdl-package-alist key t))
  13440. (pack-entry (aget pack-alist token t))
  13441. (comp-alist (nth 3 pack-entry))
  13442. (func-alist (nth 4 pack-entry))
  13443. (func-body-alist (nth 8 pack-entry))
  13444. (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
  13445. comp-entry func-entry func-body-entry)
  13446. (if (not (or comp-alist func-alist subpack-alist))
  13447. (speedbar-change-expand-button-char ??)
  13448. (speedbar-change-expand-button-char ?-)
  13449. ;; add package to `vhdl-speedbar-shown-unit-alist'
  13450. (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
  13451. (aput 'unit-alist token nil)
  13452. (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
  13453. (speedbar-with-writable
  13454. (save-excursion
  13455. (end-of-line) (forward-char 1)
  13456. ;; insert components
  13457. (when comp-alist
  13458. (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
  13459. (while comp-alist
  13460. (setq comp-entry (car comp-alist))
  13461. (speedbar-make-tag-line
  13462. nil nil nil
  13463. (cons token (nth 0 comp-entry))
  13464. (nth 1 comp-entry) 'vhdl-speedbar-find-file
  13465. (cons (nth 2 comp-entry) (nth 3 comp-entry))
  13466. 'vhdl-speedbar-entity-face (1+ indent))
  13467. (setq comp-alist (cdr comp-alist)))
  13468. ;; insert subprograms
  13469. (when func-alist
  13470. (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
  13471. (while func-alist
  13472. (setq func-entry (car func-alist)
  13473. func-body-entry (aget func-body-alist (car func-entry) t))
  13474. (when (nth 2 func-entry)
  13475. (vhdl-speedbar-make-subprogram-line
  13476. (nth 1 func-entry)
  13477. (cons (nth 2 func-entry) (nth 3 func-entry))
  13478. (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
  13479. (1+ indent)))
  13480. (setq func-alist (cdr func-alist)))
  13481. ;; insert required packages
  13482. (vhdl-speedbar-insert-subpackages
  13483. subpack-alist (1+ indent) indent)))
  13484. (when (memq 'display vhdl-speedbar-save-cache)
  13485. (add-to-list 'vhdl-updated-project-list key))
  13486. (vhdl-speedbar-update-current-unit t t))))
  13487. ((string-match "-" text) ; contract package
  13488. (speedbar-change-expand-button-char ?+)
  13489. ;; remove package from `vhdl-speedbar-shown-unit-alist'
  13490. (let* ((key (vhdl-speedbar-line-key indent))
  13491. (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
  13492. (adelete 'unit-alist token)
  13493. (if unit-alist
  13494. (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
  13495. (adelete 'vhdl-speedbar-shown-unit-alist key))
  13496. (speedbar-delete-subblock indent)
  13497. (when (memq 'display vhdl-speedbar-save-cache)
  13498. (add-to-list 'vhdl-updated-project-list key))))
  13499. (t (error "Nothing to display")))
  13500. (when (equal (selected-frame) speedbar-frame)
  13501. (speedbar-center-buffer-smartly)))
  13502. (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
  13503. "Insert required packages."
  13504. (let* ((pack-alist (aget vhdl-package-alist
  13505. (vhdl-speedbar-line-key dir-indent) t))
  13506. pack-key lib-name pack-entry)
  13507. (when subpack-alist
  13508. (vhdl-speedbar-make-title-line "Packages Used:" indent))
  13509. (while subpack-alist
  13510. (setq pack-key (cdar subpack-alist)
  13511. lib-name (caar subpack-alist))
  13512. (setq pack-entry (aget pack-alist pack-key t))
  13513. (vhdl-speedbar-make-subpack-line
  13514. (or (nth 0 pack-entry) pack-key) lib-name
  13515. (cons (nth 1 pack-entry) (nth 2 pack-entry))
  13516. (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
  13517. (setq subpack-alist (cdr subpack-alist)))))
  13518. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  13519. ;; Display help functions
  13520. (defvar vhdl-speedbar-update-current-unit t
  13521. "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
  13522. (defun vhdl-speedbar-update-current-project ()
  13523. "Highlight project that is currently active."
  13524. (when (and vhdl-speedbar-show-projects
  13525. (not (equal vhdl-speedbar-last-selected-project vhdl-project))
  13526. (and (boundp 'speedbar-frame)
  13527. (frame-live-p speedbar-frame)))
  13528. (let ((last-frame (selected-frame))
  13529. (project-alist vhdl-project-alist)
  13530. pos)
  13531. (select-frame speedbar-frame)
  13532. (speedbar-with-writable
  13533. (save-excursion
  13534. (while project-alist
  13535. (goto-char (point-min))
  13536. (when (re-search-forward
  13537. (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
  13538. (put-text-property (match-beginning 1) (match-end 1) 'face
  13539. (if (equal (caar project-alist) vhdl-project)
  13540. 'speedbar-selected-face
  13541. 'speedbar-directory-face))
  13542. (when (equal (caar project-alist) vhdl-project)
  13543. (setq pos (1- (match-beginning 1)))))
  13544. (setq project-alist (cdr project-alist))))
  13545. (when pos (goto-char pos)))
  13546. (select-frame last-frame)
  13547. (setq vhdl-speedbar-last-selected-project vhdl-project)))
  13548. t)
  13549. (defun vhdl-speedbar-update-current-unit (&optional no-position always)
  13550. "Highlight all design units that are contained in the current file.
  13551. NO-POSITION non-nil means do not re-position cursor."
  13552. (let ((last-frame (selected-frame))
  13553. (project-list vhdl-speedbar-shown-project-list)
  13554. file-alist pos file-name)
  13555. ;; get current file name
  13556. (if (fboundp 'speedbar-select-attached-frame)
  13557. (speedbar-select-attached-frame)
  13558. (select-frame speedbar-attached-frame))
  13559. (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
  13560. (when (and vhdl-speedbar-update-current-unit
  13561. (or always (not (equal file-name speedbar-last-selected-file))))
  13562. (if vhdl-speedbar-show-projects
  13563. (while project-list
  13564. (setq file-alist (append file-alist (aget vhdl-file-alist
  13565. (car project-list) t)))
  13566. (setq project-list (cdr project-list)))
  13567. (setq file-alist (aget vhdl-file-alist
  13568. (abbreviate-file-name default-directory) t)))
  13569. (select-frame speedbar-frame)
  13570. (set-buffer speedbar-buffer)
  13571. (speedbar-with-writable
  13572. (vhdl-prepare-search-1
  13573. (save-excursion
  13574. ;; unhighlight last units
  13575. (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
  13576. (vhdl-speedbar-update-units
  13577. "\\[.\\] " (nth 0 file-entry)
  13578. speedbar-last-selected-file 'vhdl-speedbar-entity-face)
  13579. (vhdl-speedbar-update-units
  13580. "{.} " (nth 1 file-entry)
  13581. speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
  13582. (vhdl-speedbar-update-units
  13583. "\\[.\\] " (nth 3 file-entry)
  13584. speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
  13585. (vhdl-speedbar-update-units
  13586. "[]>] " (nth 4 file-entry)
  13587. speedbar-last-selected-file 'vhdl-speedbar-package-face)
  13588. (vhdl-speedbar-update-units
  13589. "\\[.\\].+(" '("body")
  13590. speedbar-last-selected-file 'vhdl-speedbar-package-face)
  13591. (vhdl-speedbar-update-units
  13592. "> " (nth 6 file-entry)
  13593. speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
  13594. ;; highlight current units
  13595. (let* ((file-entry (aget file-alist file-name t)))
  13596. (setq
  13597. pos (vhdl-speedbar-update-units
  13598. "\\[.\\] " (nth 0 file-entry)
  13599. file-name 'vhdl-speedbar-entity-selected-face pos)
  13600. pos (vhdl-speedbar-update-units
  13601. "{.} " (nth 1 file-entry)
  13602. file-name 'vhdl-speedbar-architecture-selected-face pos)
  13603. pos (vhdl-speedbar-update-units
  13604. "\\[.\\] " (nth 3 file-entry)
  13605. file-name 'vhdl-speedbar-configuration-selected-face pos)
  13606. pos (vhdl-speedbar-update-units
  13607. "[]>] " (nth 4 file-entry)
  13608. file-name 'vhdl-speedbar-package-selected-face pos)
  13609. pos (vhdl-speedbar-update-units
  13610. "\\[.\\].+(" '("body")
  13611. file-name 'vhdl-speedbar-package-selected-face pos)
  13612. pos (vhdl-speedbar-update-units
  13613. "> " (nth 6 file-entry)
  13614. file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
  13615. ;; move speedbar so the first highlighted unit is visible
  13616. (when (and pos (not no-position))
  13617. (goto-char pos)
  13618. (speedbar-center-buffer-smartly)
  13619. (speedbar-position-cursor-on-line))
  13620. (setq speedbar-last-selected-file file-name))
  13621. (select-frame last-frame)
  13622. t))
  13623. (defun vhdl-speedbar-update-units (text unit-list file-name face
  13624. &optional pos)
  13625. "Help function to highlight design units."
  13626. (while unit-list
  13627. (goto-char (point-min))
  13628. (while (re-search-forward
  13629. (concat text "\\(" (car unit-list) "\\)\\>") nil t)
  13630. (when (equal file-name (car (get-text-property
  13631. (match-beginning 1) 'speedbar-token)))
  13632. (setq pos (or pos (point-marker)))
  13633. (put-text-property (match-beginning 1) (match-end 1) 'face face)))
  13634. (setq unit-list (cdr unit-list)))
  13635. pos)
  13636. (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
  13637. ent-name ent-file-marker
  13638. arch-name arch-file-marker
  13639. conf-name conf-file-marker
  13640. lib-name depth offset delimiter)
  13641. "Insert instantiation entry."
  13642. (let ((start (point))
  13643. visible-start)
  13644. (insert (int-to-string depth) ":")
  13645. (put-text-property start (point) 'invisible t)
  13646. (setq visible-start (point))
  13647. (insert-char ? (* depth speedbar-indentation-width))
  13648. (while (> offset 0)
  13649. (insert "|")
  13650. (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
  13651. (setq offset (1- offset)))
  13652. (put-text-property visible-start (point) 'invisible nil)
  13653. (setq start (point))
  13654. (insert ">")
  13655. (speedbar-make-button start (point) nil nil nil)
  13656. (setq visible-start (point))
  13657. (insert " ")
  13658. (setq start (point))
  13659. (if (not inst-name)
  13660. (insert "(top)")
  13661. (insert inst-name)
  13662. (speedbar-make-button
  13663. start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
  13664. 'vhdl-speedbar-find-file inst-file-marker))
  13665. (insert delimiter)
  13666. (when ent-name
  13667. (setq start (point))
  13668. (insert ent-name)
  13669. (speedbar-make-button
  13670. start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
  13671. 'vhdl-speedbar-find-file ent-file-marker)
  13672. (when arch-name
  13673. (insert " (")
  13674. (setq start (point))
  13675. (insert arch-name)
  13676. (speedbar-make-button
  13677. start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
  13678. 'vhdl-speedbar-find-file arch-file-marker)
  13679. (insert ")"))
  13680. (when conf-name
  13681. (insert " (")
  13682. (setq start (point))
  13683. (insert conf-name)
  13684. (speedbar-make-button
  13685. start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
  13686. 'vhdl-speedbar-find-file conf-file-marker)
  13687. (insert ")")))
  13688. (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
  13689. (setq start (point))
  13690. (insert " (" lib-name ")")
  13691. (put-text-property (+ 2 start) (1- (point)) 'face
  13692. 'vhdl-speedbar-library-face))
  13693. (insert-char ?\n 1)
  13694. (put-text-property visible-start (point) 'invisible nil)))
  13695. (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
  13696. body-file-marker depth)
  13697. "Insert package entry."
  13698. (let ((start (point))
  13699. visible-start)
  13700. (insert (int-to-string depth) ":")
  13701. (put-text-property start (point) 'invisible t)
  13702. (setq visible-start (point))
  13703. (insert-char ? (* depth speedbar-indentation-width))
  13704. (put-text-property visible-start (point) 'invisible nil)
  13705. (setq start (point))
  13706. (insert "[+]")
  13707. (speedbar-make-button
  13708. start (point) 'speedbar-button-face 'speedbar-highlight-face
  13709. 'vhdl-speedbar-expand-package pack-key)
  13710. (setq visible-start (point))
  13711. (insert-char ? 1 nil)
  13712. (setq start (point))
  13713. (insert pack-name)
  13714. (speedbar-make-button
  13715. start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
  13716. 'vhdl-speedbar-find-file pack-file-marker)
  13717. (unless (car pack-file-marker)
  13718. (insert "!"))
  13719. (when (car body-file-marker)
  13720. (insert " (")
  13721. (setq start (point))
  13722. (insert "body")
  13723. (speedbar-make-button
  13724. start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
  13725. 'vhdl-speedbar-find-file body-file-marker)
  13726. (insert ")"))
  13727. (insert-char ?\n 1)
  13728. (put-text-property visible-start (point) 'invisible nil)))
  13729. (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
  13730. pack-body-file-marker depth)
  13731. "Insert used package entry."
  13732. (let ((start (point))
  13733. visible-start)
  13734. (insert (int-to-string depth) ":")
  13735. (put-text-property start (point) 'invisible t)
  13736. (setq visible-start (point))
  13737. (insert-char ? (* depth speedbar-indentation-width))
  13738. (put-text-property visible-start (point) 'invisible nil)
  13739. (setq start (point))
  13740. (insert ">")
  13741. (speedbar-make-button start (point) nil nil nil)
  13742. (setq visible-start (point))
  13743. (insert " ")
  13744. (setq start (point))
  13745. (insert pack-name)
  13746. (speedbar-make-button
  13747. start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
  13748. 'vhdl-speedbar-find-file pack-file-marker)
  13749. (when (car pack-body-file-marker)
  13750. (insert " (")
  13751. (setq start (point))
  13752. (insert "body")
  13753. (speedbar-make-button
  13754. start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
  13755. 'vhdl-speedbar-find-file pack-body-file-marker)
  13756. (insert ")"))
  13757. (setq start (point))
  13758. (insert " (" lib-name ")")
  13759. (put-text-property (+ 2 start) (1- (point)) 'face
  13760. 'vhdl-speedbar-library-face)
  13761. (insert-char ?\n 1)
  13762. (put-text-property visible-start (point) 'invisible nil)))
  13763. (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
  13764. func-body-file-marker
  13765. depth)
  13766. "Insert subprogram entry."
  13767. (let ((start (point))
  13768. visible-start)
  13769. (insert (int-to-string depth) ":")
  13770. (put-text-property start (point) 'invisible t)
  13771. (setq visible-start (point))
  13772. (insert-char ? (* depth speedbar-indentation-width))
  13773. (put-text-property visible-start (point) 'invisible nil)
  13774. (setq start (point))
  13775. (insert ">")
  13776. (speedbar-make-button start (point) nil nil nil)
  13777. (setq visible-start (point))
  13778. (insert " ")
  13779. (setq start (point))
  13780. (insert func-name)
  13781. (speedbar-make-button
  13782. start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
  13783. 'vhdl-speedbar-find-file func-file-marker)
  13784. (when (car func-body-file-marker)
  13785. (insert " (")
  13786. (setq start (point))
  13787. (insert "body")
  13788. (speedbar-make-button
  13789. start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
  13790. 'vhdl-speedbar-find-file func-body-file-marker)
  13791. (insert ")"))
  13792. (insert-char ?\n 1)
  13793. (put-text-property visible-start (point) 'invisible nil)))
  13794. (defun vhdl-speedbar-make-title-line (text &optional depth)
  13795. "Insert design unit title entry."
  13796. (let ((start (point))
  13797. visible-start)
  13798. (when depth
  13799. (insert (int-to-string depth) ":")
  13800. (put-text-property start (point) 'invisible t))
  13801. (setq visible-start (point))
  13802. (insert-char ? (* (or depth 0) speedbar-indentation-width))
  13803. (setq start (point))
  13804. (insert text)
  13805. (speedbar-make-button start (point) nil nil nil nil)
  13806. (insert-char ?\n 1)
  13807. (put-text-property visible-start (point) 'invisible nil)))
  13808. (defun vhdl-speedbar-insert-dirs (files level)
  13809. "Insert subdirectories."
  13810. (let ((dirs (car files)))
  13811. (while dirs
  13812. (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
  13813. (car dirs) 'speedbar-dir-follow nil
  13814. 'speedbar-directory-face level)
  13815. (setq dirs (cdr dirs)))))
  13816. (defun vhdl-speedbar-dired (text token indent)
  13817. "Speedbar click handler for directory expand button in hierarchy mode."
  13818. (cond ((string-match "+" text) ; we have to expand this dir
  13819. (setq speedbar-shown-directories
  13820. (cons (expand-file-name
  13821. (concat (speedbar-line-directory indent) token "/"))
  13822. speedbar-shown-directories))
  13823. (speedbar-change-expand-button-char ?-)
  13824. (speedbar-reset-scanners)
  13825. (speedbar-with-writable
  13826. (save-excursion
  13827. (end-of-line) (forward-char 1)
  13828. (vhdl-speedbar-insert-dirs
  13829. (speedbar-file-lists
  13830. (concat (speedbar-line-directory indent) token "/"))
  13831. (1+ indent))
  13832. (speedbar-reset-scanners)
  13833. (vhdl-speedbar-insert-dir-hierarchy
  13834. (abbreviate-file-name
  13835. (concat (speedbar-line-directory indent) token "/"))
  13836. (1+ indent) speedbar-power-click)))
  13837. (vhdl-speedbar-update-current-unit t t))
  13838. ((string-match "-" text) ; we have to contract this node
  13839. (speedbar-reset-scanners)
  13840. (let ((oldl speedbar-shown-directories)
  13841. (newl nil)
  13842. (td (expand-file-name
  13843. (concat (speedbar-line-directory indent) token))))
  13844. (while oldl
  13845. (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
  13846. (setq newl (cons (car oldl) newl)))
  13847. (setq oldl (cdr oldl)))
  13848. (setq speedbar-shown-directories (nreverse newl)))
  13849. (speedbar-change-expand-button-char ?+)
  13850. (speedbar-delete-subblock indent))
  13851. (t (error "Nothing to display")))
  13852. (when (equal (selected-frame) speedbar-frame)
  13853. (speedbar-center-buffer-smartly)))
  13854. (defun vhdl-speedbar-item-info ()
  13855. "Derive and display information about this line item."
  13856. (save-excursion
  13857. (beginning-of-line)
  13858. ;; skip invisible number info
  13859. (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
  13860. (cond
  13861. ;; project/directory entry
  13862. ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
  13863. (if vhdl-speedbar-show-projects
  13864. (message "Project \"%s\"" (match-string-no-properties 1))
  13865. (speedbar-files-item-info)))
  13866. ;; design unit entry
  13867. ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
  13868. (goto-char (match-end 1))
  13869. (let ((face (get-text-property (point) 'face)))
  13870. (message
  13871. "%s \"%s\" in \"%s\""
  13872. ;; design unit kind
  13873. (cond ((or (eq face 'vhdl-speedbar-entity-face)
  13874. (eq face 'vhdl-speedbar-entity-selected-face))
  13875. (if (equal (match-string 2) ">") "Component" "Entity"))
  13876. ((or (eq face 'vhdl-speedbar-architecture-face)
  13877. (eq face 'vhdl-speedbar-architecture-selected-face))
  13878. "Architecture")
  13879. ((or (eq face 'vhdl-speedbar-configuration-face)
  13880. (eq face 'vhdl-speedbar-configuration-selected-face))
  13881. "Configuration")
  13882. ((or (eq face 'vhdl-speedbar-package-face)
  13883. (eq face 'vhdl-speedbar-package-selected-face))
  13884. "Package")
  13885. ((or (eq face 'vhdl-speedbar-instantiation-face)
  13886. (eq face 'vhdl-speedbar-instantiation-selected-face))
  13887. "Instantiation")
  13888. ((eq face 'vhdl-speedbar-subprogram-face)
  13889. "Subprogram")
  13890. (t ""))
  13891. ;; design unit name
  13892. (buffer-substring-no-properties
  13893. (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
  13894. (match-end 1))
  13895. ;; file name
  13896. (file-relative-name
  13897. (or (car (get-text-property (point) 'speedbar-token))
  13898. "?")
  13899. (vhdl-default-directory)))))
  13900. (t (message "")))))
  13901. (defun vhdl-speedbar-line-text ()
  13902. "Calls `speedbar-line-text' and removes text properties."
  13903. (let ((string (speedbar-line-text)))
  13904. (set-text-properties 0 (length string) nil string)
  13905. string))
  13906. (defun vhdl-speedbar-higher-text ()
  13907. "Get speedbar-line-text of higher level."
  13908. (let (depth string)
  13909. (save-excursion
  13910. (beginning-of-line)
  13911. (looking-at "^\\([0-9]+\\):")
  13912. (setq depth (string-to-number (match-string 1)))
  13913. (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
  13914. (setq string (match-string 1))
  13915. (set-text-properties 0 (length string) nil string)
  13916. string))))
  13917. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  13918. ;; Help functions
  13919. (defun vhdl-speedbar-line-key (&optional indent)
  13920. "Get currently displayed directory of project name."
  13921. (if vhdl-speedbar-show-projects
  13922. (vhdl-speedbar-line-project)
  13923. (abbreviate-file-name
  13924. (file-name-as-directory (speedbar-line-directory indent)))))
  13925. (defun vhdl-speedbar-line-project (&optional indent)
  13926. "Get currently displayed project name."
  13927. (and vhdl-speedbar-show-projects
  13928. (save-excursion
  13929. (end-of-line)
  13930. (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
  13931. (match-string-no-properties 1))))
  13932. (defun vhdl-add-modified-file ()
  13933. "Add file to `vhdl-modified-file-list'."
  13934. (when vhdl-file-alist
  13935. (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
  13936. nil)
  13937. (defun vhdl-resolve-paths (path-list)
  13938. "Resolve path wildcards in PATH-LIST."
  13939. (let (path-list-1 path-list-2 path-beg path-end dir)
  13940. ;; eliminate non-existent directories
  13941. (while path-list
  13942. (setq dir (car path-list))
  13943. (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
  13944. (if (file-directory-p (match-string 2 dir))
  13945. (setq path-list-1 (cons dir path-list-1))
  13946. (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
  13947. (setq path-list (cdr path-list)))
  13948. ;; resolve path wildcards
  13949. (while path-list-1
  13950. (setq dir (car path-list-1))
  13951. (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
  13952. (progn
  13953. (setq path-beg (match-string 1 dir)
  13954. path-end (match-string 5 dir))
  13955. (setq path-list-1
  13956. (append
  13957. (mapcar
  13958. (function
  13959. (lambda (var) (concat path-beg var path-end)))
  13960. (let ((all-list (vhdl-directory-files
  13961. (match-string 2 dir) t
  13962. (concat "\\<" (wildcard-to-regexp
  13963. (match-string 4 dir)))))
  13964. dir-list)
  13965. (while all-list
  13966. (when (file-directory-p (car all-list))
  13967. (setq dir-list (cons (car all-list) dir-list)))
  13968. (setq all-list (cdr all-list)))
  13969. dir-list))
  13970. (cdr path-list-1))))
  13971. (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
  13972. (when (file-directory-p (match-string 2 dir))
  13973. (setq path-list-2 (cons dir path-list-2)))
  13974. (setq path-list-1 (cdr path-list-1))))
  13975. (nreverse path-list-2)))
  13976. (defun vhdl-speedbar-goto-this-unit (directory unit)
  13977. "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
  13978. (let ((dest (point)))
  13979. (if (and (if vhdl-speedbar-show-projects
  13980. (progn (goto-char (point-min)) t)
  13981. (speedbar-goto-this-file directory))
  13982. (re-search-forward (concat "[]}] " unit "\\>") nil t))
  13983. (progn (speedbar-position-cursor-on-line)
  13984. t)
  13985. (goto-char dest)
  13986. nil)))
  13987. (defun vhdl-speedbar-find-file (text token indent)
  13988. "When user clicks on TEXT, load file with name and position in TOKEN.
  13989. Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
  13990. is already shown in a buffer."
  13991. (if (not (car token))
  13992. (error "ERROR: File cannot be found")
  13993. (let ((buffer (get-file-buffer (car token))))
  13994. (speedbar-find-file-in-frame (car token))
  13995. (when (or vhdl-speedbar-jump-to-unit buffer)
  13996. (goto-char (point-min))
  13997. (forward-line (1- (cdr token)))
  13998. (recenter))
  13999. (vhdl-speedbar-update-current-unit t t)
  14000. (speedbar-set-timer dframe-update-speed)
  14001. (speedbar-maybee-jump-to-attached-frame))))
  14002. (defun vhdl-speedbar-port-copy ()
  14003. "Copy the port of the entity/component or subprogram under the cursor."
  14004. (interactive)
  14005. (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
  14006. (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
  14007. (error "ERROR: No entity/component or subprogram under cursor")
  14008. (beginning-of-line)
  14009. (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
  14010. (condition-case info
  14011. (let ((token (get-text-property
  14012. (match-beginning 3) 'speedbar-token)))
  14013. (vhdl-visit-file (car token) t
  14014. (progn (goto-char (point-min))
  14015. (forward-line (1- (cdr token)))
  14016. (end-of-line)
  14017. (if is-entity
  14018. (vhdl-port-copy)
  14019. (vhdl-subprog-copy)))))
  14020. (error (error "ERROR: %s not scanned successfully\n (%s)"
  14021. (if is-entity "Port" "Interface") (cadr info))))
  14022. (error "ERROR: No entity/component or subprogram on current line")))))
  14023. (defun vhdl-speedbar-place-component ()
  14024. "Place the entity/component under the cursor as component."
  14025. (interactive)
  14026. (if (not (vhdl-speedbar-check-unit 'entity))
  14027. (error "ERROR: No entity/component under cursor")
  14028. (vhdl-speedbar-port-copy)
  14029. (if (fboundp 'speedbar-select-attached-frame)
  14030. (speedbar-select-attached-frame)
  14031. (select-frame speedbar-attached-frame))
  14032. (vhdl-compose-place-component)
  14033. (select-frame speedbar-frame)))
  14034. (defun vhdl-speedbar-configuration ()
  14035. "Generate configuration for the architecture under the cursor."
  14036. (interactive)
  14037. (if (not (vhdl-speedbar-check-unit 'architecture))
  14038. (error "ERROR: No architecture under cursor")
  14039. (let ((arch-name (vhdl-speedbar-line-text))
  14040. (ent-name (vhdl-speedbar-higher-text)))
  14041. (if (fboundp 'speedbar-select-attached-frame)
  14042. (speedbar-select-attached-frame)
  14043. (select-frame speedbar-attached-frame))
  14044. (vhdl-compose-configuration ent-name arch-name))))
  14045. (defun vhdl-speedbar-select-mra ()
  14046. "Select the architecture under the cursor as MRA."
  14047. (interactive)
  14048. (if (not (vhdl-speedbar-check-unit 'architecture))
  14049. (error "ERROR: No architecture under cursor")
  14050. (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
  14051. (ent-key (downcase (vhdl-speedbar-higher-text)))
  14052. (ent-alist (aget vhdl-entity-alist
  14053. (or (vhdl-project-p) default-directory) t))
  14054. (ent-entry (aget ent-alist ent-key t)))
  14055. (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
  14056. (speedbar-refresh))))
  14057. (defun vhdl-speedbar-make-design ()
  14058. "Make (compile) design unit or directory/project under the cursor."
  14059. (interactive)
  14060. (if (not (save-excursion (beginning-of-line)
  14061. (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
  14062. (error "ERROR: No primary design unit or directory/project under cursor")
  14063. (let ((is-unit (match-string 2))
  14064. (unit-name (vhdl-speedbar-line-text))
  14065. (vhdl-project (vhdl-speedbar-line-project))
  14066. (directory (file-name-as-directory
  14067. (or (speedbar-line-file) (speedbar-line-directory)))))
  14068. (if (fboundp 'speedbar-select-attached-frame)
  14069. (speedbar-select-attached-frame)
  14070. (select-frame speedbar-attached-frame))
  14071. (let ((default-directory directory))
  14072. (vhdl-make (and is-unit unit-name))))))
  14073. (defun vhdl-speedbar-generate-makefile ()
  14074. "Generate Makefile for directory/project under the cursor."
  14075. (interactive)
  14076. (let ((vhdl-project (vhdl-speedbar-line-project))
  14077. (default-directory (file-name-as-directory
  14078. (or (speedbar-line-file) (speedbar-line-directory)))))
  14079. (vhdl-generate-makefile)))
  14080. (defun vhdl-speedbar-check-unit (design-unit)
  14081. "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
  14082. expansion function)."
  14083. (save-excursion
  14084. (speedbar-position-cursor-on-line)
  14085. (cond ((eq design-unit 'entity)
  14086. (memq (get-text-property (match-end 0) 'face)
  14087. '(vhdl-speedbar-entity-face
  14088. vhdl-speedbar-entity-selected-face)))
  14089. ((eq design-unit 'architecture)
  14090. (memq (get-text-property (match-end 0) 'face)
  14091. '(vhdl-speedbar-architecture-face
  14092. vhdl-speedbar-architecture-selected-face)))
  14093. ((eq design-unit 'subprogram)
  14094. (eq (get-text-property (match-end 0) 'face)
  14095. 'vhdl-speedbar-subprogram-face))
  14096. (t nil))))
  14097. (defun vhdl-speedbar-set-depth (depth)
  14098. "Set hierarchy display depth to DEPTH and refresh speedbar."
  14099. (setq vhdl-speedbar-hierarchy-depth depth)
  14100. (speedbar-refresh))
  14101. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14102. ;; Fontification
  14103. (defface vhdl-speedbar-entity-face
  14104. '((((class color) (background light)) (:foreground "ForestGreen"))
  14105. (((class color) (background dark)) (:foreground "PaleGreen")))
  14106. "Face used for displaying entity names."
  14107. :group 'speedbar-faces)
  14108. (defface vhdl-speedbar-architecture-face
  14109. '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
  14110. (((class color) (background light)) (:foreground "Blue"))
  14111. (((class color) (background dark)) (:foreground "LightSkyBlue")))
  14112. "Face used for displaying architecture names."
  14113. :group 'speedbar-faces)
  14114. (defface vhdl-speedbar-configuration-face
  14115. '((((class color) (background light)) (:foreground "DarkGoldenrod"))
  14116. (((class color) (background dark)) (:foreground "Salmon")))
  14117. "Face used for displaying configuration names."
  14118. :group 'speedbar-faces)
  14119. (defface vhdl-speedbar-package-face
  14120. '((((class color) (background light)) (:foreground "Grey50"))
  14121. (((class color) (background dark)) (:foreground "Grey80")))
  14122. "Face used for displaying package names."
  14123. :group 'speedbar-faces)
  14124. (defface vhdl-speedbar-library-face
  14125. '((((class color) (background light)) (:foreground "Purple"))
  14126. (((class color) (background dark)) (:foreground "Orchid1")))
  14127. "Face used for displaying library names."
  14128. :group 'speedbar-faces)
  14129. (defface vhdl-speedbar-instantiation-face
  14130. '((((class color) (background light)) (:foreground "Brown"))
  14131. (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
  14132. (((class color) (background dark)) (:foreground "Yellow")))
  14133. "Face used for displaying instantiation names."
  14134. :group 'speedbar-faces)
  14135. (defface vhdl-speedbar-subprogram-face
  14136. '((((class color) (background light)) (:foreground "Orchid4"))
  14137. (((class color) (background dark)) (:foreground "BurlyWood2")))
  14138. "Face used for displaying subprogram names."
  14139. :group 'speedbar-faces)
  14140. (defface vhdl-speedbar-entity-selected-face
  14141. '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
  14142. (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
  14143. "Face used for displaying entity names."
  14144. :group 'speedbar-faces)
  14145. (defface vhdl-speedbar-architecture-selected-face
  14146. '((((min-colors 88) (class color) (background light)) (:foreground
  14147. "Blue1" :underline t))
  14148. (((class color) (background light)) (:foreground "Blue" :underline t))
  14149. (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
  14150. "Face used for displaying architecture names."
  14151. :group 'speedbar-faces)
  14152. (defface vhdl-speedbar-configuration-selected-face
  14153. '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
  14154. (((class color) (background dark)) (:foreground "Salmon" :underline t)))
  14155. "Face used for displaying configuration names."
  14156. :group 'speedbar-faces)
  14157. (defface vhdl-speedbar-package-selected-face
  14158. '((((class color) (background light)) (:foreground "Grey50" :underline t))
  14159. (((class color) (background dark)) (:foreground "Grey80" :underline t)))
  14160. "Face used for displaying package names."
  14161. :group 'speedbar-faces)
  14162. (defface vhdl-speedbar-instantiation-selected-face
  14163. '((((class color) (background light)) (:foreground "Brown" :underline t))
  14164. (((class color) (background dark)) (:foreground "Yellow" :underline t)))
  14165. "Face used for displaying instantiation names."
  14166. :group 'speedbar-faces)
  14167. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14168. ;; Initialization
  14169. ;; add speedbar
  14170. (when (fboundp 'speedbar)
  14171. (condition-case ()
  14172. (when (and vhdl-speedbar-auto-open
  14173. (not (and (boundp 'speedbar-frame)
  14174. (frame-live-p speedbar-frame))))
  14175. (speedbar-frame-mode 1)
  14176. (if (fboundp 'speedbar-select-attached-frame)
  14177. (speedbar-select-attached-frame)
  14178. (select-frame speedbar-attached-frame)))
  14179. (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
  14180. ;; initialize speedbar
  14181. (if (not (boundp 'speedbar-frame))
  14182. (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
  14183. (vhdl-speedbar-initialize)
  14184. (when speedbar-frame (vhdl-speedbar-refresh)))
  14185. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14186. ;;; Structural composition
  14187. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14188. (defun vhdl-get-components-package-name ()
  14189. "Return the name of the components package."
  14190. (let ((project (vhdl-project-p)))
  14191. (if project
  14192. (vhdl-replace-string (car vhdl-components-package-name)
  14193. (subst-char-in-string ? ?_ project))
  14194. (cdr vhdl-components-package-name))))
  14195. (defun vhdl-compose-new-component ()
  14196. "Create entity and architecture for new component."
  14197. (interactive)
  14198. (let* ((case-fold-search t)
  14199. (ent-name (read-from-minibuffer "entity name: "
  14200. nil vhdl-minibuffer-local-map))
  14201. (arch-name
  14202. (if (equal (cdr vhdl-compose-architecture-name) "")
  14203. (read-from-minibuffer "architecture name: "
  14204. nil vhdl-minibuffer-local-map)
  14205. (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
  14206. ent-file-name arch-file-name ent-buffer arch-buffer project)
  14207. (message "Creating component \"%s(%s)\"..." ent-name arch-name)
  14208. ;; open entity file
  14209. (unless (eq vhdl-compose-create-files 'none)
  14210. (setq ent-file-name
  14211. (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
  14212. "." (file-name-extension (buffer-file-name))))
  14213. (when (and (file-exists-p ent-file-name)
  14214. (not (y-or-n-p (concat "File \"" ent-file-name
  14215. "\" exists; overwrite? "))))
  14216. (error "ERROR: Creating component...aborted"))
  14217. (find-file ent-file-name)
  14218. (erase-buffer)
  14219. (set-buffer-modified-p nil))
  14220. ;; insert header
  14221. (if vhdl-compose-include-header
  14222. (progn (vhdl-template-header)
  14223. (goto-char (point-max)))
  14224. (vhdl-comment-display-line) (insert "\n\n"))
  14225. ;; insert library clause
  14226. (vhdl-template-package-std-logic-1164)
  14227. (when vhdl-use-components-package
  14228. (insert "\n")
  14229. (vhdl-template-standard-package (vhdl-work-library)
  14230. (vhdl-get-components-package-name)))
  14231. (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
  14232. ;; insert entity declaration
  14233. (vhdl-insert-keyword "ENTITY ") (insert ent-name)
  14234. (vhdl-insert-keyword " IS\n")
  14235. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  14236. (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
  14237. (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
  14238. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  14239. (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
  14240. (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
  14241. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  14242. (vhdl-insert-keyword "END ")
  14243. (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
  14244. (insert ent-name ";\n\n")
  14245. (vhdl-comment-display-line) (insert "\n")
  14246. ;; open architecture file
  14247. (if (not (eq vhdl-compose-create-files 'separate))
  14248. (insert "\n")
  14249. (setq ent-buffer (current-buffer))
  14250. (setq arch-file-name
  14251. (concat (vhdl-replace-string vhdl-architecture-file-name
  14252. (concat ent-name " " arch-name) t)
  14253. "." (file-name-extension (buffer-file-name))))
  14254. (when (and (file-exists-p arch-file-name)
  14255. (not (y-or-n-p (concat "File \"" arch-file-name
  14256. "\" exists; overwrite? "))))
  14257. (error "ERROR: Creating component...aborted"))
  14258. (find-file arch-file-name)
  14259. (erase-buffer)
  14260. (set-buffer-modified-p nil)
  14261. ;; insert header
  14262. (if vhdl-compose-include-header
  14263. (progn (vhdl-template-header)
  14264. (goto-char (point-max)))
  14265. (vhdl-comment-display-line) (insert "\n\n")))
  14266. ;; insert architecture body
  14267. (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
  14268. (vhdl-insert-keyword " OF ") (insert ent-name)
  14269. (vhdl-insert-keyword " IS\n\n")
  14270. (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
  14271. (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
  14272. (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
  14273. (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
  14274. (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
  14275. (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
  14276. (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
  14277. (vhdl-insert-keyword "BEGIN")
  14278. (when vhdl-self-insert-comments
  14279. (insert " -- ")
  14280. (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
  14281. (insert arch-name))
  14282. (insert "\n\n")
  14283. (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
  14284. (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
  14285. (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
  14286. (vhdl-insert-keyword "END ")
  14287. (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
  14288. (insert arch-name ";\n\n")
  14289. ;; insert footer and save
  14290. (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
  14291. (vhdl-template-footer)
  14292. (vhdl-comment-display-line) (insert "\n"))
  14293. (goto-char (point-min))
  14294. (setq arch-buffer (current-buffer))
  14295. (when ent-buffer (set-buffer ent-buffer) (save-buffer))
  14296. (set-buffer arch-buffer) (save-buffer)
  14297. (message "%s"
  14298. (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
  14299. (and ent-file-name
  14300. (format "\n File created: \"%s\"" ent-file-name))
  14301. (and arch-file-name
  14302. (format "\n File created: \"%s\"" arch-file-name))))))
  14303. (defun vhdl-compose-place-component ()
  14304. "Place new component by pasting current port as component declaration and
  14305. component instantiation."
  14306. (interactive)
  14307. (if (not vhdl-port-list)
  14308. (error "ERROR: No port has been read")
  14309. (save-excursion
  14310. (vhdl-prepare-search-2
  14311. (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
  14312. (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
  14313. (error "ERROR: No architecture found"))
  14314. (let* ((ent-name (match-string 1))
  14315. (ent-file-name
  14316. (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
  14317. "." (file-name-extension (buffer-file-name))))
  14318. (orig-buffer (current-buffer)))
  14319. (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
  14320. ;; place component declaration
  14321. (unless (or vhdl-use-components-package
  14322. (vhdl-use-direct-instantiation)
  14323. (save-excursion
  14324. (re-search-forward
  14325. (concat "^\\s-*component\\s-+"
  14326. (car vhdl-port-list) "\\>") nil t)))
  14327. (re-search-forward "^begin\\>" nil)
  14328. (beginning-of-line)
  14329. (skip-chars-backward " \t\n")
  14330. (insert "\n\n") (indent-to vhdl-basic-offset)
  14331. (vhdl-port-paste-component t))
  14332. ;; place component instantiation
  14333. (re-search-forward "^end\\>" nil)
  14334. (beginning-of-line)
  14335. (skip-chars-backward " \t\n")
  14336. (insert "\n\n") (indent-to vhdl-basic-offset)
  14337. (vhdl-port-paste-instance nil t t)
  14338. ;; place use clause for used packages
  14339. (when (nth 3 vhdl-port-list)
  14340. ;; open entity file
  14341. (when (file-exists-p ent-file-name)
  14342. (find-file ent-file-name))
  14343. (goto-char (point-min))
  14344. (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
  14345. (error "ERROR: Entity not found: \"%s\"" ent-name))
  14346. (goto-char (match-beginning 0))
  14347. (if (and (save-excursion
  14348. (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
  14349. (match-string 1))
  14350. (progn (goto-char (match-end 0))
  14351. (beginning-of-line 2))
  14352. (insert "\n")
  14353. (backward-char))
  14354. (vhdl-port-paste-context-clause)
  14355. (switch-to-buffer orig-buffer))
  14356. (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
  14357. (defun vhdl-compose-wire-components ()
  14358. "Connect components."
  14359. (interactive)
  14360. (save-excursion
  14361. (vhdl-prepare-search-2
  14362. (unless (or (re-search-backward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t)
  14363. (re-search-forward "^architecture[ \t\n]+\\w+[ \t\n]+of[ \t\n]+\\(\\w+\\)[ \t\n]+is\\>" nil t))
  14364. (error "ERROR: No architecture found"))
  14365. (let* ((ent-name (match-string 1))
  14366. (ent-file-name
  14367. (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
  14368. "." (file-name-extension (buffer-file-name))))
  14369. (arch-decl-pos (point-marker))
  14370. (arch-stat-pos (re-search-forward "^begin\\>" nil))
  14371. (arch-end-pos (re-search-forward "^end\\>" nil))
  14372. (pack-name (vhdl-get-components-package-name))
  14373. (pack-file-name
  14374. (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
  14375. "." (file-name-extension (buffer-file-name))))
  14376. inst-name comp-name comp-ent-name comp-ent-file-name has-generic
  14377. port-alist generic-alist inst-alist
  14378. signal-name signal-entry signal-alist local-list written-list
  14379. single-in-list multi-in-list single-out-list multi-out-list
  14380. constant-name constant-entry constant-alist single-list multi-list
  14381. port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
  14382. generic-beg-pos generic-pos generic-inst-pos generic-end-pos
  14383. signal-beg-pos signal-pos
  14384. constant-temp-pos port-temp-pos signal-temp-pos)
  14385. (message "Wiring components...")
  14386. ;; process all instances
  14387. (goto-char arch-stat-pos)
  14388. (while (re-search-forward
  14389. (concat "^[ \t]*\\(\\w+\\)[ \t\n]*:[ \t\n]*\\("
  14390. "\\(component[ \t\n]+\\)?\\(\\w+\\)"
  14391. "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\|"
  14392. "\\(\\(entity\\)\\|configuration\\)[ \t\n]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n]*(\\(\\w+\\))\\)?"
  14393. "[ \t\n]+\\(--[^\n]*\n[ \t\n]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n]+map\\)[ \t\n]*(") arch-end-pos t)
  14394. (setq inst-name (match-string-no-properties 1)
  14395. comp-name (match-string-no-properties 4)
  14396. comp-ent-name (match-string-no-properties 12)
  14397. has-generic (or (match-string 7) (match-string 17)))
  14398. ;; get port ...
  14399. (if comp-name
  14400. ;; ... from component declaration
  14401. (vhdl-visit-file
  14402. (when vhdl-use-components-package pack-file-name) t
  14403. (save-excursion
  14404. (goto-char (point-min))
  14405. (unless (re-search-forward (concat "^\\s-*component[ \t\n]+" comp-name "\\>") nil t)
  14406. (error "ERROR: Component declaration not found: \"%s\"" comp-name))
  14407. (vhdl-port-copy)))
  14408. ;; ... from entity declaration (direct instantiation)
  14409. (setq comp-ent-file-name
  14410. (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
  14411. "." (file-name-extension (buffer-file-name))))
  14412. (vhdl-visit-file
  14413. comp-ent-file-name t
  14414. (save-excursion
  14415. (goto-char (point-min))
  14416. (unless (re-search-forward (concat "^\\s-*entity[ \t\n]+" comp-ent-name "\\>") nil t)
  14417. (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
  14418. (vhdl-port-copy))))
  14419. (vhdl-port-flatten t)
  14420. (setq generic-alist (nth 1 vhdl-port-list)
  14421. port-alist (nth 2 vhdl-port-list)
  14422. vhdl-port-list nil)
  14423. (setq constant-alist nil
  14424. signal-alist nil)
  14425. (when has-generic
  14426. ;; process all constants in generic map
  14427. (vhdl-forward-syntactic-ws)
  14428. (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
  14429. (setq constant-name (match-string-no-properties 3))
  14430. (setq constant-entry
  14431. (cons constant-name
  14432. (if (match-string 1)
  14433. (or (aget generic-alist (match-string 2) t)
  14434. (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
  14435. (cdar generic-alist))))
  14436. (setq constant-alist (cons constant-entry constant-alist))
  14437. (setq constant-name (downcase constant-name))
  14438. (if (or (member constant-name single-list)
  14439. (member constant-name multi-list))
  14440. (progn (setq single-list (delete constant-name single-list))
  14441. (add-to-list 'multi-list constant-name))
  14442. (add-to-list 'single-list constant-name))
  14443. (unless (match-string 1)
  14444. (setq generic-alist (cdr generic-alist)))
  14445. (vhdl-forward-syntactic-ws))
  14446. (vhdl-re-search-forward "\\<port\\s-+map[ \t\n]*(" nil t))
  14447. ;; process all signals in port map
  14448. (vhdl-forward-syntactic-ws)
  14449. (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n]*=>[ \t\n]*\\)?\\(\\w+\\),?" t)
  14450. (setq signal-name (match-string-no-properties 3))
  14451. (setq signal-entry (cons signal-name
  14452. (if (match-string 1)
  14453. (or (aget port-alist (match-string 2) t)
  14454. (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
  14455. (cdar port-alist))))
  14456. (setq signal-alist (cons signal-entry signal-alist))
  14457. (setq signal-name (downcase signal-name))
  14458. (if (equal (upcase (nth 2 signal-entry)) "IN")
  14459. ;; input signal
  14460. (cond
  14461. ((member signal-name local-list)
  14462. nil)
  14463. ((or (member signal-name single-out-list)
  14464. (member signal-name multi-out-list))
  14465. (setq single-out-list (delete signal-name single-out-list))
  14466. (setq multi-out-list (delete signal-name multi-out-list))
  14467. (add-to-list 'local-list signal-name))
  14468. ((member signal-name single-in-list)
  14469. (setq single-in-list (delete signal-name single-in-list))
  14470. (add-to-list 'multi-in-list signal-name))
  14471. ((not (member signal-name multi-in-list))
  14472. (add-to-list 'single-in-list signal-name)))
  14473. ;; output signal
  14474. (cond
  14475. ((member signal-name local-list)
  14476. nil)
  14477. ((or (member signal-name single-in-list)
  14478. (member signal-name multi-in-list))
  14479. (setq single-in-list (delete signal-name single-in-list))
  14480. (setq multi-in-list (delete signal-name multi-in-list))
  14481. (add-to-list 'local-list signal-name))
  14482. ((member signal-name single-out-list)
  14483. (setq single-out-list (delete signal-name single-out-list))
  14484. (add-to-list 'multi-out-list signal-name))
  14485. ((not (member signal-name multi-out-list))
  14486. (add-to-list 'single-out-list signal-name))))
  14487. (unless (match-string 1)
  14488. (setq port-alist (cdr port-alist)))
  14489. (vhdl-forward-syntactic-ws))
  14490. (setq inst-alist (cons (list inst-name (nreverse constant-alist)
  14491. (nreverse signal-alist)) inst-alist)))
  14492. ;; prepare signal insertion
  14493. (vhdl-goto-marker arch-decl-pos)
  14494. (forward-line 1)
  14495. (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n]*-*\n" arch-stat-pos t)
  14496. (setq signal-pos (point-marker))
  14497. (while (progn (vhdl-forward-syntactic-ws)
  14498. (looking-at "signal\\>"))
  14499. (beginning-of-line 2)
  14500. (delete-region signal-pos (point)))
  14501. (setq signal-beg-pos signal-pos)
  14502. ;; open entity file
  14503. (when (file-exists-p ent-file-name)
  14504. (find-file ent-file-name))
  14505. (goto-char (point-min))
  14506. (unless (re-search-forward (concat "^entity[ \t\n]+" ent-name "[ \t\n]+is\\>") nil t)
  14507. (error "ERROR: Entity not found: \"%s\"" ent-name))
  14508. ;; prepare generic clause insertion
  14509. (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n]*(\\)\\|^end\\>" nil t)
  14510. (match-string 1))
  14511. (goto-char (match-beginning 0))
  14512. (indent-to vhdl-basic-offset)
  14513. (insert "generic ();\n\n")
  14514. (backward-char 4))
  14515. (backward-char)
  14516. (setq generic-pos (point-marker))
  14517. (forward-sexp) (end-of-line)
  14518. (delete-region generic-pos (point)) (delete-char 1)
  14519. (insert "(\n")
  14520. (when multi-list
  14521. (insert "\n")
  14522. (indent-to (* 2 vhdl-basic-offset))
  14523. (insert "-- global generics\n"))
  14524. (setq generic-beg-pos (point-marker) generic-pos (point-marker)
  14525. generic-inst-pos (point-marker) generic-end-pos (point-marker))
  14526. ;; prepare port clause insertion
  14527. (unless (and (re-search-forward "\\(^\\s-*port[ \t\n]*(\\)\\|^end\\>" nil t)
  14528. (match-string 1))
  14529. (goto-char (match-beginning 0))
  14530. (indent-to vhdl-basic-offset)
  14531. (insert "port ();\n\n")
  14532. (backward-char 4))
  14533. (backward-char)
  14534. (setq port-in-pos (point-marker))
  14535. (forward-sexp) (end-of-line)
  14536. (delete-region port-in-pos (point)) (delete-char 1)
  14537. (insert "(\n")
  14538. (when (or multi-in-list multi-out-list)
  14539. (insert "\n")
  14540. (indent-to (* 2 vhdl-basic-offset))
  14541. (insert "-- global ports\n"))
  14542. (setq port-beg-pos (point-marker) port-in-pos (point-marker)
  14543. port-out-pos (point-marker) port-inst-pos (point-marker)
  14544. port-end-pos (point-marker))
  14545. ;; insert generics, ports and signals
  14546. (setq inst-alist (nreverse inst-alist))
  14547. (while inst-alist
  14548. (setq inst-name (nth 0 (car inst-alist))
  14549. constant-alist (nth 1 (car inst-alist))
  14550. signal-alist (nth 2 (car inst-alist))
  14551. constant-temp-pos generic-inst-pos
  14552. port-temp-pos port-inst-pos
  14553. signal-temp-pos signal-pos)
  14554. ;; generics
  14555. (while constant-alist
  14556. (setq constant-name (downcase (caar constant-alist))
  14557. constant-entry (car constant-alist))
  14558. (cond ((member constant-name written-list)
  14559. nil)
  14560. ((member constant-name multi-list)
  14561. (vhdl-goto-marker generic-pos)
  14562. (setq generic-end-pos
  14563. (vhdl-max-marker
  14564. generic-end-pos
  14565. (vhdl-compose-insert-generic constant-entry)))
  14566. (setq generic-pos (point-marker))
  14567. (add-to-list 'written-list constant-name))
  14568. (t
  14569. (vhdl-goto-marker
  14570. (vhdl-max-marker generic-inst-pos generic-pos))
  14571. (setq generic-end-pos
  14572. (vhdl-compose-insert-generic constant-entry))
  14573. (setq generic-inst-pos (point-marker))
  14574. (add-to-list 'written-list constant-name)))
  14575. (setq constant-alist (cdr constant-alist)))
  14576. (when (/= constant-temp-pos generic-inst-pos)
  14577. (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
  14578. (insert "\n") (indent-to (* 2 vhdl-basic-offset))
  14579. (insert "-- generics for \"" inst-name "\"\n")
  14580. (vhdl-goto-marker generic-inst-pos))
  14581. ;; ports and signals
  14582. (while signal-alist
  14583. (setq signal-name (downcase (caar signal-alist))
  14584. signal-entry (car signal-alist))
  14585. (cond ((member signal-name written-list)
  14586. nil)
  14587. ((member signal-name multi-in-list)
  14588. (vhdl-goto-marker port-in-pos)
  14589. (setq port-end-pos
  14590. (vhdl-max-marker
  14591. port-end-pos (vhdl-compose-insert-port signal-entry)))
  14592. (setq port-in-pos (point-marker))
  14593. (add-to-list 'written-list signal-name))
  14594. ((member signal-name multi-out-list)
  14595. (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
  14596. (setq port-end-pos
  14597. (vhdl-max-marker
  14598. port-end-pos (vhdl-compose-insert-port signal-entry)))
  14599. (setq port-out-pos (point-marker))
  14600. (add-to-list 'written-list signal-name))
  14601. ((or (member signal-name single-in-list)
  14602. (member signal-name single-out-list))
  14603. (vhdl-goto-marker
  14604. (vhdl-max-marker
  14605. port-inst-pos
  14606. (vhdl-max-marker port-out-pos port-in-pos)))
  14607. (setq port-end-pos (vhdl-compose-insert-port signal-entry))
  14608. (setq port-inst-pos (point-marker))
  14609. (add-to-list 'written-list signal-name))
  14610. ((equal (upcase (nth 2 signal-entry)) "OUT")
  14611. (vhdl-goto-marker signal-pos)
  14612. (vhdl-compose-insert-signal signal-entry)
  14613. (setq signal-pos (point-marker))
  14614. (add-to-list 'written-list signal-name)))
  14615. (setq signal-alist (cdr signal-alist)))
  14616. (when (/= port-temp-pos port-inst-pos)
  14617. (vhdl-goto-marker
  14618. (vhdl-max-marker port-temp-pos
  14619. (vhdl-max-marker port-in-pos port-out-pos)))
  14620. (insert "\n") (indent-to (* 2 vhdl-basic-offset))
  14621. (insert "-- ports to \"" inst-name "\"\n")
  14622. (vhdl-goto-marker port-inst-pos))
  14623. (when (/= signal-temp-pos signal-pos)
  14624. (vhdl-goto-marker signal-temp-pos)
  14625. (insert "\n") (indent-to vhdl-basic-offset)
  14626. (insert "-- outputs of \"" inst-name "\"\n")
  14627. (vhdl-goto-marker signal-pos))
  14628. (setq inst-alist (cdr inst-alist)))
  14629. ;; finalize generic/port clause
  14630. (vhdl-goto-marker generic-end-pos) (backward-char)
  14631. (when (= generic-beg-pos generic-end-pos)
  14632. (insert "\n") (indent-to (* 2 vhdl-basic-offset))
  14633. (insert ";") (backward-char))
  14634. (insert ")")
  14635. (vhdl-goto-marker port-end-pos) (backward-char)
  14636. (when (= port-beg-pos port-end-pos)
  14637. (insert "\n") (indent-to (* 2 vhdl-basic-offset))
  14638. (insert ";") (backward-char))
  14639. (insert ")")
  14640. ;; align everything
  14641. (when vhdl-auto-align
  14642. (vhdl-goto-marker generic-beg-pos)
  14643. (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
  14644. (vhdl-align-region-groups port-beg-pos port-end-pos 1)
  14645. (vhdl-goto-marker signal-beg-pos)
  14646. (vhdl-align-region-groups signal-beg-pos signal-pos))
  14647. (switch-to-buffer (marker-buffer signal-beg-pos))
  14648. (message "Wiring components...done")))))
  14649. (defun vhdl-compose-insert-generic (entry)
  14650. "Insert ENTRY as generic declaration."
  14651. (let (pos)
  14652. (indent-to (* 2 vhdl-basic-offset))
  14653. (insert (nth 0 entry) " : " (nth 1 entry))
  14654. (when (nth 2 entry)
  14655. (insert " := " (nth 2 entry)))
  14656. (insert ";")
  14657. (setq pos (point-marker))
  14658. (when (and vhdl-include-port-comments (nth 3 entry))
  14659. (vhdl-comment-insert-inline (nth 3 entry) t))
  14660. (insert "\n")
  14661. pos))
  14662. (defun vhdl-compose-insert-port (entry)
  14663. "Insert ENTRY as port declaration."
  14664. (let (pos)
  14665. (indent-to (* 2 vhdl-basic-offset))
  14666. (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
  14667. (setq pos (point-marker))
  14668. (when (and vhdl-include-port-comments (nth 4 entry))
  14669. (vhdl-comment-insert-inline (nth 4 entry) t))
  14670. (insert "\n")
  14671. pos))
  14672. (defun vhdl-compose-insert-signal (entry)
  14673. "Insert ENTRY as signal declaration."
  14674. (indent-to vhdl-basic-offset)
  14675. (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
  14676. (when (and vhdl-include-port-comments (nth 4 entry))
  14677. (vhdl-comment-insert-inline (nth 4 entry) t))
  14678. (insert "\n"))
  14679. (defun vhdl-compose-components-package ()
  14680. "Generate a package containing component declarations for all entities in the
  14681. current project/directory."
  14682. (interactive)
  14683. (vhdl-require-hierarchy-info)
  14684. (let* ((project (vhdl-project-p))
  14685. (pack-name (vhdl-get-components-package-name))
  14686. (pack-file-name
  14687. (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
  14688. "." (file-name-extension (buffer-file-name))))
  14689. (ent-alist (aget vhdl-entity-alist
  14690. (or project default-directory) t))
  14691. (lazy-lock-minimum-size 0)
  14692. clause-pos component-pos)
  14693. (message "Generating components package \"%s\"..." pack-name)
  14694. ;; open package file
  14695. (when (and (file-exists-p pack-file-name)
  14696. (not (y-or-n-p (concat "File \"" pack-file-name
  14697. "\" exists; overwrite? "))))
  14698. (error "ERROR: Generating components package...aborted"))
  14699. (find-file pack-file-name)
  14700. (erase-buffer)
  14701. ;; insert header
  14702. (if vhdl-compose-include-header
  14703. (progn (vhdl-template-header
  14704. (concat "Components package (generated by Emacs VHDL Mode "
  14705. vhdl-version ")"))
  14706. (goto-char (point-max)))
  14707. (vhdl-comment-display-line) (insert "\n\n"))
  14708. ;; insert std_logic_1164 package
  14709. (vhdl-template-package-std-logic-1164)
  14710. (insert "\n") (setq clause-pos (point-marker))
  14711. (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
  14712. ;; insert package declaration
  14713. (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
  14714. (vhdl-insert-keyword " IS\n\n")
  14715. (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
  14716. (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
  14717. (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
  14718. (indent-to vhdl-basic-offset)
  14719. (setq component-pos (point-marker))
  14720. (insert "\n\n") (vhdl-insert-keyword "END ")
  14721. (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
  14722. (insert pack-name ";\n\n")
  14723. ;; insert footer
  14724. (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
  14725. (vhdl-template-footer)
  14726. (vhdl-comment-display-line) (insert "\n"))
  14727. ;; insert component declarations
  14728. (while ent-alist
  14729. (vhdl-visit-file (nth 2 (car ent-alist)) nil
  14730. (progn (goto-char (point-min))
  14731. (forward-line (1- (nth 3 (car ent-alist))))
  14732. (end-of-line)
  14733. (vhdl-port-copy)))
  14734. (goto-char component-pos)
  14735. (vhdl-port-paste-component t)
  14736. (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
  14737. (setq component-pos (point-marker))
  14738. (goto-char clause-pos)
  14739. (vhdl-port-paste-context-clause pack-name)
  14740. (setq clause-pos (point-marker))
  14741. (setq ent-alist (cdr ent-alist)))
  14742. (goto-char (point-min))
  14743. (save-buffer)
  14744. (message "Generating components package \"%s\"...done\n File created: \"%s\""
  14745. pack-name pack-file-name)))
  14746. (defun vhdl-compose-configuration-architecture (ent-name arch-name inst-alist
  14747. &optional insert-conf)
  14748. "Generate block configuration for architecture."
  14749. (let ((margin (current-indentation))
  14750. (beg (point-at-bol))
  14751. ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
  14752. ;; insert block configuration (for architecture)
  14753. (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
  14754. (setq margin (+ margin vhdl-basic-offset))
  14755. ;; process all instances
  14756. (while inst-alist
  14757. (setq inst-entry (car inst-alist))
  14758. ;; is component?
  14759. (when (nth 4 inst-entry)
  14760. (setq insert-conf t)
  14761. (setq inst-path (nth 9 inst-entry))
  14762. ;; skip common path with previous instance
  14763. (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
  14764. (setq inst-path (cdr inst-path)
  14765. inst-prev-path (cdr inst-prev-path)))
  14766. ;; insert block configuration end (for previous block/generate)
  14767. (while inst-prev-path
  14768. (setq margin (- margin vhdl-basic-offset))
  14769. (indent-to margin)
  14770. (vhdl-insert-keyword "END FOR;\n")
  14771. (setq inst-prev-path (cdr inst-prev-path)))
  14772. ;; insert block configuration beginning (for current block/generate)
  14773. (indent-to margin)
  14774. (while inst-path
  14775. (setq margin (+ margin vhdl-basic-offset))
  14776. (vhdl-insert-keyword "FOR ")
  14777. (insert (car inst-path) "\n")
  14778. (indent-to margin)
  14779. (setq inst-path (cdr inst-path)))
  14780. ;; insert component configuration beginning
  14781. (vhdl-insert-keyword "FOR ")
  14782. (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
  14783. ;; find subconfiguration
  14784. (setq conf-key (nth 7 inst-entry))
  14785. (setq tmp-alist conf-alist)
  14786. ;; use first configuration found for instance's entity
  14787. (while (and tmp-alist (null conf-key))
  14788. (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
  14789. (setq conf-key (nth 0 (car tmp-alist))))
  14790. (setq tmp-alist (cdr tmp-alist)))
  14791. (setq conf-entry (aget conf-alist conf-key t))
  14792. ;; insert binding indication ...
  14793. ;; ... with subconfiguration (if exists)
  14794. (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
  14795. (progn
  14796. (indent-to (+ margin vhdl-basic-offset))
  14797. (vhdl-insert-keyword "USE CONFIGURATION ")
  14798. (insert (vhdl-work-library) "." (nth 0 conf-entry))
  14799. (insert ";\n"))
  14800. ;; ... with entity (if exists)
  14801. (setq ent-entry (aget ent-alist (nth 5 inst-entry) t))
  14802. (when ent-entry
  14803. (indent-to (+ margin vhdl-basic-offset))
  14804. (vhdl-insert-keyword "USE ENTITY ")
  14805. (insert (vhdl-work-library) "." (nth 0 ent-entry))
  14806. ;; insert architecture name (if architecture exists)
  14807. (when (nth 3 ent-entry)
  14808. (setq arch-name
  14809. ;; choose architecture name a) from configuration,
  14810. ;; b) from mra, or c) from first architecture
  14811. (or (nth 0 (aget (nth 3 ent-entry)
  14812. (or (nth 6 inst-entry)
  14813. (nth 4 ent-entry)) t))
  14814. (nth 1 (car (nth 3 ent-entry)))))
  14815. (insert "(" arch-name ")"))
  14816. (insert ";\n")
  14817. ;; insert block configuration (for architecture of subcomponent)
  14818. (when (and vhdl-compose-configuration-hierarchical
  14819. (nth 3 ent-entry))
  14820. (indent-to (+ margin vhdl-basic-offset))
  14821. (vhdl-compose-configuration-architecture
  14822. (nth 0 ent-entry) arch-name
  14823. (nth 3 (aget (nth 3 ent-entry) (downcase arch-name) t))))))
  14824. ;; insert component configuration end
  14825. (indent-to margin)
  14826. (vhdl-insert-keyword "END FOR;\n")
  14827. (setq inst-prev-path (nth 9 inst-entry)))
  14828. (setq inst-alist (cdr inst-alist)))
  14829. ;; insert block configuration end (for block/generate)
  14830. (while inst-prev-path
  14831. (setq margin (- margin vhdl-basic-offset))
  14832. (indent-to margin)
  14833. (vhdl-insert-keyword "END FOR;\n")
  14834. (setq inst-prev-path (cdr inst-prev-path)))
  14835. (indent-to (- margin vhdl-basic-offset))
  14836. ;; insert block configuration end or remove beginning (for architecture)
  14837. (if insert-conf
  14838. (vhdl-insert-keyword "END FOR;\n")
  14839. (delete-region beg (point)))))
  14840. (defun vhdl-compose-configuration (&optional ent-name arch-name)
  14841. "Generate configuration declaration."
  14842. (interactive)
  14843. (vhdl-require-hierarchy-info)
  14844. (let ((ent-alist (aget vhdl-entity-alist
  14845. (or (vhdl-project-p) default-directory) t))
  14846. (conf-alist (aget vhdl-config-alist
  14847. (or (vhdl-project-p) default-directory) t))
  14848. (from-speedbar ent-name)
  14849. inst-alist conf-name conf-file-name pos)
  14850. (vhdl-prepare-search-2
  14851. ;; get entity and architecture name
  14852. (unless ent-name
  14853. (save-excursion
  14854. (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
  14855. (not (equal "END" (upcase (match-string 1))))
  14856. (setq ent-name (match-string-no-properties 3))
  14857. (setq arch-name (match-string-no-properties 2)))
  14858. (error "ERROR: Not within an architecture"))))
  14859. (setq conf-name (vhdl-replace-string
  14860. vhdl-compose-configuration-name
  14861. (concat ent-name " " arch-name)))
  14862. (setq inst-alist
  14863. (nth 3 (aget (nth 3 (aget ent-alist (downcase ent-name) t))
  14864. (downcase arch-name) t))))
  14865. (message "Generating configuration \"%s\"..." conf-name)
  14866. (if vhdl-compose-configuration-create-file
  14867. ;; open configuration file
  14868. (progn
  14869. (setq conf-file-name
  14870. (concat (vhdl-replace-string vhdl-configuration-file-name
  14871. conf-name t)
  14872. "." (file-name-extension (buffer-file-name))))
  14873. (when (and (file-exists-p conf-file-name)
  14874. (not (y-or-n-p (concat "File \"" conf-file-name
  14875. "\" exists; overwrite? "))))
  14876. (error "ERROR: Creating configuration...aborted"))
  14877. (find-file conf-file-name)
  14878. (erase-buffer)
  14879. (set-buffer-modified-p nil)
  14880. ;; insert header
  14881. (if vhdl-compose-include-header
  14882. (progn (vhdl-template-header
  14883. (concat "Configuration declaration for design \""
  14884. ent-name "(" arch-name ")\""))
  14885. (goto-char (point-max)))
  14886. (vhdl-comment-display-line) (insert "\n\n")))
  14887. ;; goto end of architecture
  14888. (unless from-speedbar
  14889. (re-search-forward "^end\\>" nil)
  14890. (end-of-line) (insert "\n\n")
  14891. (vhdl-comment-display-line) (insert "\n\n")))
  14892. ;; insert library clause
  14893. (setq pos (point))
  14894. (vhdl-template-standard-package (vhdl-work-library) nil)
  14895. (when (/= pos (point))
  14896. (insert "\n\n"))
  14897. ;; insert configuration
  14898. (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
  14899. (vhdl-insert-keyword " OF ") (insert ent-name)
  14900. (vhdl-insert-keyword " IS\n")
  14901. (indent-to vhdl-basic-offset)
  14902. ;; insert block configuration (for architecture)
  14903. (vhdl-compose-configuration-architecture ent-name arch-name inst-alist t)
  14904. (vhdl-insert-keyword "END ") (insert conf-name ";")
  14905. (when conf-file-name
  14906. ;; insert footer and save
  14907. (insert "\n\n")
  14908. (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
  14909. (vhdl-template-footer)
  14910. (vhdl-comment-display-line) (insert "\n"))
  14911. (save-buffer))
  14912. (message "%s"
  14913. (concat (format "Generating configuration \"%s\"...done" conf-name)
  14914. (and conf-file-name
  14915. (format "\n File created: \"%s\"" conf-file-name))))))
  14916. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14917. ;;; Compilation / Makefile generation
  14918. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14919. ;; (using `compile.el')
  14920. (defun vhdl-makefile-name ()
  14921. "Return the Makefile name of the current project or the current compiler if
  14922. no project is defined."
  14923. (let ((project-alist (aget vhdl-project-alist vhdl-project))
  14924. (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
  14925. (vhdl-replace-string
  14926. (cons "\\(.*\\)\n\\(.*\\)"
  14927. (or (nth 8 project-alist) (nth 8 compiler-alist)))
  14928. (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
  14929. (defun vhdl-compile-directory ()
  14930. "Return the directory where compilation/make should be run."
  14931. (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
  14932. (compiler (aget vhdl-compiler-alist vhdl-compiler))
  14933. (directory (vhdl-resolve-env-variable
  14934. (if project
  14935. (vhdl-replace-string
  14936. (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
  14937. (nth 6 compiler)))))
  14938. (file-name-as-directory
  14939. (if (file-name-absolute-p directory)
  14940. directory
  14941. (expand-file-name directory (vhdl-default-directory))))))
  14942. (defun vhdl-uniquify (in-list)
  14943. "Remove duplicate elements from IN-LIST."
  14944. (let (out-list)
  14945. (while in-list
  14946. (add-to-list 'out-list (car in-list))
  14947. (setq in-list (cdr in-list)))
  14948. out-list))
  14949. (defun vhdl-set-compiler (name)
  14950. "Set current compiler to NAME."
  14951. (interactive
  14952. (list (let ((completion-ignore-case t))
  14953. (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
  14954. (if (assoc name vhdl-compiler-alist)
  14955. (progn (setq vhdl-compiler name)
  14956. (message "Current compiler: \"%s\"" vhdl-compiler))
  14957. (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
  14958. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14959. ;; Compilation
  14960. (defun vhdl-compile-init ()
  14961. "Initialize for compilation."
  14962. (when (or (null compilation-error-regexp-alist)
  14963. (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
  14964. compilation-error-regexp-alist)))
  14965. ;; `compilation-error-regexp-alist'
  14966. (let ((commands-alist vhdl-compiler-alist)
  14967. regexp-alist sublist)
  14968. (while commands-alist
  14969. (setq sublist (nth 11 (car commands-alist)))
  14970. (unless (or (equal "" (car sublist))
  14971. (assoc (car sublist) regexp-alist))
  14972. (setq regexp-alist (cons (list (nth 0 sublist)
  14973. (if (= 0 (nth 1 sublist))
  14974. (if (featurep 'xemacs) 9 nil)
  14975. (nth 1 sublist))
  14976. (nth 2 sublist) (nth 3 sublist))
  14977. regexp-alist)))
  14978. (setq commands-alist (cdr commands-alist)))
  14979. (setq compilation-error-regexp-alist
  14980. (append compilation-error-regexp-alist (nreverse regexp-alist))))
  14981. ;; `compilation-file-regexp-alist'
  14982. (let ((commands-alist vhdl-compiler-alist)
  14983. regexp-alist sublist)
  14984. ;; matches vhdl-mode file name output
  14985. (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
  14986. (while commands-alist
  14987. (setq sublist (nth 12 (car commands-alist)))
  14988. (unless (or (equal "" (car sublist))
  14989. (assoc (car sublist) regexp-alist))
  14990. (setq regexp-alist (cons sublist regexp-alist)))
  14991. (setq commands-alist (cdr commands-alist)))
  14992. (setq compilation-file-regexp-alist
  14993. (append compilation-file-regexp-alist (nreverse regexp-alist))))))
  14994. (defvar vhdl-compile-file-name nil
  14995. "Name of file to be compiled.")
  14996. (defun vhdl-compile-print-file-name ()
  14997. "Function called within `compile' to print out file name for compilers that
  14998. do not print any file names."
  14999. (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
  15000. (defun vhdl-get-compile-options (project compiler file-name
  15001. &optional file-options-only)
  15002. "Get compiler options. Returning nil means do not compile this file."
  15003. (let* ((compiler-options (nth 1 compiler))
  15004. (project-entry (aget (nth 4 project) vhdl-compiler))
  15005. (project-options (nth 0 project-entry))
  15006. (exception-list (and file-name (nth 2 project-entry)))
  15007. (work-library (vhdl-work-library))
  15008. (case-fold-search nil)
  15009. file-options)
  15010. (while (and exception-list
  15011. (not (string-match (caar exception-list) file-name)))
  15012. (setq exception-list (cdr exception-list)))
  15013. (if (and exception-list (not (cdar exception-list)))
  15014. nil
  15015. (if (and file-options-only (not exception-list))
  15016. 'default
  15017. (setq file-options (cdar exception-list))
  15018. ;; insert library name in compiler-specific options
  15019. (setq compiler-options
  15020. (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
  15021. work-library))
  15022. ;; insert compiler-specific options in project-specific options
  15023. (when project-options
  15024. (setq project-options
  15025. (vhdl-replace-string
  15026. (cons "\\(.*\\)\n\\(.*\\)" project-options)
  15027. (concat work-library "\n" compiler-options))))
  15028. ;; insert project-specific options in file-specific options
  15029. (when file-options
  15030. (setq file-options
  15031. (vhdl-replace-string
  15032. (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
  15033. (concat work-library "\n" compiler-options "\n"
  15034. project-options))))
  15035. ;; return options
  15036. (or file-options project-options compiler-options)))))
  15037. (defun vhdl-get-make-options (project compiler)
  15038. "Get make options."
  15039. (let* ((compiler-options (nth 3 compiler))
  15040. (project-entry (aget (nth 4 project) vhdl-compiler))
  15041. (project-options (nth 1 project-entry))
  15042. (makefile-name (vhdl-makefile-name)))
  15043. ;; insert Makefile name in compiler-specific options
  15044. (setq compiler-options
  15045. (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
  15046. makefile-name))
  15047. ;; insert compiler-specific options in project-specific options
  15048. (when project-options
  15049. (setq project-options
  15050. (vhdl-replace-string
  15051. (cons "\\(.*\\)\n\\(.*\\)" project-options)
  15052. (concat makefile-name "\n" compiler-options))))
  15053. ;; return options
  15054. (or project-options compiler-options)))
  15055. (defun vhdl-compile ()
  15056. "Compile current buffer using the VHDL compiler specified in
  15057. `vhdl-compiler'."
  15058. (interactive)
  15059. (vhdl-compile-init)
  15060. (let* ((project (aget vhdl-project-alist vhdl-project))
  15061. (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
  15062. (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
  15063. (command (nth 0 compiler))
  15064. (file-name (buffer-file-name))
  15065. (options (vhdl-get-compile-options project compiler file-name))
  15066. (default-directory (vhdl-compile-directory))
  15067. compilation-process-setup-function)
  15068. (unless (file-directory-p default-directory)
  15069. (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
  15070. ;; put file name into quotes if it contains spaces
  15071. (when (string-match " " file-name)
  15072. (setq file-name (concat "\"" file-name "\"")))
  15073. ;; print out file name if compiler does not
  15074. (setq vhdl-compile-file-name (buffer-file-name))
  15075. (when (and (= 0 (nth 1 (nth 10 compiler)))
  15076. (= 0 (nth 1 (nth 11 compiler))))
  15077. (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
  15078. ;; run compilation
  15079. (if options
  15080. (when command
  15081. (compile (concat command " " options " " file-name)))
  15082. (vhdl-warning "Your project settings tell me not to compile this file"))))
  15083. (defvar vhdl-make-target "all"
  15084. "Default target for `vhdl-make' command.")
  15085. (defun vhdl-make (&optional target)
  15086. "Call make command for compilation of all updated source files (requires
  15087. `Makefile'). Optional argument TARGET allows to compile the design
  15088. specified by a target."
  15089. (interactive)
  15090. (setq vhdl-make-target
  15091. (or target (read-from-minibuffer "Target: " vhdl-make-target
  15092. vhdl-minibuffer-local-map)))
  15093. (vhdl-compile-init)
  15094. (let* ((project (aget vhdl-project-alist vhdl-project))
  15095. (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
  15096. (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
  15097. (command (nth 2 compiler))
  15098. (options (vhdl-get-make-options project compiler))
  15099. (default-directory (vhdl-compile-directory)))
  15100. (unless (file-directory-p default-directory)
  15101. (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
  15102. ;; run make
  15103. (compile (concat (if (equal command "") "make" command)
  15104. " " options " " vhdl-make-target))))
  15105. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15106. ;; Makefile generation
  15107. (defun vhdl-generate-makefile ()
  15108. "Generate `Makefile'."
  15109. (interactive)
  15110. (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
  15111. (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
  15112. (command (nth 4 compiler)))
  15113. ;; generate makefile
  15114. (if command
  15115. (let ((default-directory (vhdl-compile-directory)))
  15116. (compile (vhdl-replace-string
  15117. (cons "\\(.*\\) \\(.*\\)" command)
  15118. (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
  15119. (vhdl-generate-makefile-1))))
  15120. (defun vhdl-get-packages (lib-alist work-library)
  15121. "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
  15122. (let (pack-list)
  15123. (while lib-alist
  15124. (when (equal (downcase (caar lib-alist)) (downcase work-library))
  15125. (setq pack-list (cons (cdar lib-alist) pack-list)))
  15126. (setq lib-alist (cdr lib-alist)))
  15127. pack-list))
  15128. (defun vhdl-generate-makefile-1 ()
  15129. "Generate Makefile for current project or directory."
  15130. ;; scan hierarchy if required
  15131. (if (vhdl-project-p)
  15132. (unless (or (assoc vhdl-project vhdl-file-alist)
  15133. (vhdl-load-cache vhdl-project))
  15134. (vhdl-scan-project-contents vhdl-project))
  15135. (let ((directory (abbreviate-file-name default-directory)))
  15136. (unless (or (assoc directory vhdl-file-alist)
  15137. (vhdl-load-cache directory))
  15138. (vhdl-scan-directory-contents directory))))
  15139. (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
  15140. (project (vhdl-project-p))
  15141. (ent-alist (aget vhdl-entity-alist (or project directory) t))
  15142. (conf-alist (aget vhdl-config-alist (or project directory) t))
  15143. (pack-alist (aget vhdl-package-alist (or project directory) t))
  15144. (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
  15145. (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
  15146. (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
  15147. (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
  15148. (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
  15149. (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
  15150. (adjust-case (nth 5 regexp-list))
  15151. (work-library (downcase (vhdl-work-library)))
  15152. (compile-directory (expand-file-name (vhdl-compile-directory)
  15153. default-directory))
  15154. (makefile-name (vhdl-makefile-name))
  15155. rule-alist arch-alist inst-alist
  15156. target-list depend-list unit-list prim-list second-list subcomp-list
  15157. lib-alist lib-body-alist pack-list all-pack-list
  15158. ent-key ent-file-name arch-key arch-file-name ent-arch-key
  15159. conf-key conf-file-name pack-key pack-file-name
  15160. ent-entry arch-entry conf-entry pack-entry inst-entry
  15161. pack-body-key pack-body-file-name inst-ent-key inst-conf-key
  15162. tmp-key tmp-list rule)
  15163. ;; check prerequisites
  15164. (unless (file-exists-p compile-directory)
  15165. (make-directory compile-directory t))
  15166. (unless regexp-list
  15167. (error "Please contact the VHDL Mode maintainer for support of \"%s\""
  15168. vhdl-compiler))
  15169. (message "Generating makefile \"%s\"..." makefile-name)
  15170. ;; rules for all entities
  15171. (setq tmp-list ent-alist)
  15172. (while ent-alist
  15173. (setq ent-entry (car ent-alist)
  15174. ent-key (nth 0 ent-entry))
  15175. (when (nth 2 ent-entry)
  15176. (setq ent-file-name (file-relative-name
  15177. (nth 2 ent-entry) compile-directory)
  15178. arch-alist (nth 4 ent-entry)
  15179. lib-alist (nth 6 ent-entry)
  15180. rule (aget rule-alist ent-file-name)
  15181. target-list (nth 0 rule)
  15182. depend-list (nth 1 rule)
  15183. second-list nil
  15184. subcomp-list nil)
  15185. (setq tmp-key (vhdl-replace-string
  15186. ent-regexp (funcall adjust-case ent-key)))
  15187. (setq unit-list (cons (cons ent-key tmp-key) unit-list))
  15188. ;; rule target for this entity
  15189. (setq target-list (cons ent-key target-list))
  15190. ;; rule dependencies for all used packages
  15191. (setq pack-list (vhdl-get-packages lib-alist work-library))
  15192. (setq depend-list (append depend-list pack-list))
  15193. (setq all-pack-list pack-list)
  15194. ;; add rule
  15195. (aput 'rule-alist ent-file-name (list target-list depend-list))
  15196. ;; rules for all corresponding architectures
  15197. (while arch-alist
  15198. (setq arch-entry (car arch-alist)
  15199. arch-key (nth 0 arch-entry)
  15200. ent-arch-key (concat ent-key "-" arch-key)
  15201. arch-file-name (file-relative-name (nth 2 arch-entry)
  15202. compile-directory)
  15203. inst-alist (nth 4 arch-entry)
  15204. lib-alist (nth 5 arch-entry)
  15205. rule (aget rule-alist arch-file-name)
  15206. target-list (nth 0 rule)
  15207. depend-list (nth 1 rule))
  15208. (setq tmp-key (vhdl-replace-string
  15209. arch-regexp
  15210. (funcall adjust-case (concat arch-key " " ent-key))))
  15211. (setq unit-list
  15212. (cons (cons ent-arch-key tmp-key) unit-list))
  15213. (setq second-list (cons ent-arch-key second-list))
  15214. ;; rule target for this architecture
  15215. (setq target-list (cons ent-arch-key target-list))
  15216. ;; rule dependency for corresponding entity
  15217. (setq depend-list (cons ent-key depend-list))
  15218. ;; rule dependencies for contained component instantiations
  15219. (while inst-alist
  15220. (setq inst-entry (car inst-alist))
  15221. (when (or (null (nth 8 inst-entry))
  15222. (equal (downcase (nth 8 inst-entry)) work-library))
  15223. (setq inst-ent-key (or (nth 7 inst-entry)
  15224. (nth 5 inst-entry)))
  15225. (setq depend-list (cons inst-ent-key depend-list)
  15226. subcomp-list (cons inst-ent-key subcomp-list)))
  15227. (setq inst-alist (cdr inst-alist)))
  15228. ;; rule dependencies for all used packages
  15229. (setq pack-list (vhdl-get-packages lib-alist work-library))
  15230. (setq depend-list (append depend-list pack-list))
  15231. (setq all-pack-list (append all-pack-list pack-list))
  15232. ;; add rule
  15233. (aput 'rule-alist arch-file-name (list target-list depend-list))
  15234. (setq arch-alist (cdr arch-alist)))
  15235. (setq prim-list (cons (list ent-key second-list
  15236. (append subcomp-list all-pack-list))
  15237. prim-list)))
  15238. (setq ent-alist (cdr ent-alist)))
  15239. (setq ent-alist tmp-list)
  15240. ;; rules for all configurations
  15241. (setq tmp-list conf-alist)
  15242. (while conf-alist
  15243. (setq conf-entry (car conf-alist)
  15244. conf-key (nth 0 conf-entry)
  15245. conf-file-name (file-relative-name
  15246. (nth 2 conf-entry) compile-directory)
  15247. ent-key (nth 4 conf-entry)
  15248. arch-key (nth 5 conf-entry)
  15249. inst-alist (nth 6 conf-entry)
  15250. lib-alist (nth 7 conf-entry)
  15251. rule (aget rule-alist conf-file-name)
  15252. target-list (nth 0 rule)
  15253. depend-list (nth 1 rule)
  15254. subcomp-list (list ent-key))
  15255. (setq tmp-key (vhdl-replace-string
  15256. conf-regexp (funcall adjust-case conf-key)))
  15257. (setq unit-list (cons (cons conf-key tmp-key) unit-list))
  15258. ;; rule target for this configuration
  15259. (setq target-list (cons conf-key target-list))
  15260. ;; rule dependency for corresponding entity and architecture
  15261. (setq depend-list
  15262. (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
  15263. ;; rule dependencies for used packages
  15264. (setq pack-list (vhdl-get-packages lib-alist work-library))
  15265. (setq depend-list (append depend-list pack-list))
  15266. ;; rule dependencies for contained component configurations
  15267. (while inst-alist
  15268. (setq inst-entry (car inst-alist))
  15269. (setq inst-ent-key (nth 2 inst-entry)
  15270. ; comp-arch-key (nth 2 inst-entry))
  15271. inst-conf-key (nth 4 inst-entry))
  15272. (when (equal (downcase (nth 5 inst-entry)) work-library)
  15273. (when inst-ent-key
  15274. (setq depend-list (cons inst-ent-key depend-list)
  15275. subcomp-list (cons inst-ent-key subcomp-list)))
  15276. ; (when comp-arch-key
  15277. ; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
  15278. ; depend-list)))
  15279. (when inst-conf-key
  15280. (setq depend-list (cons inst-conf-key depend-list)
  15281. subcomp-list (cons inst-conf-key subcomp-list))))
  15282. (setq inst-alist (cdr inst-alist)))
  15283. ;; add rule
  15284. (aput 'rule-alist conf-file-name (list target-list depend-list))
  15285. (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
  15286. prim-list))
  15287. (setq conf-alist (cdr conf-alist)))
  15288. (setq conf-alist tmp-list)
  15289. ;; rules for all packages
  15290. (setq tmp-list pack-alist)
  15291. (while pack-alist
  15292. (setq pack-entry (car pack-alist)
  15293. pack-key (nth 0 pack-entry)
  15294. pack-body-key nil)
  15295. (when (nth 2 pack-entry)
  15296. (setq pack-file-name (file-relative-name (nth 2 pack-entry)
  15297. compile-directory)
  15298. lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
  15299. rule (aget rule-alist pack-file-name)
  15300. target-list (nth 0 rule) depend-list (nth 1 rule))
  15301. (setq tmp-key (vhdl-replace-string
  15302. pack-regexp (funcall adjust-case pack-key)))
  15303. (setq unit-list (cons (cons pack-key tmp-key) unit-list))
  15304. ;; rule target for this package
  15305. (setq target-list (cons pack-key target-list))
  15306. ;; rule dependencies for all used packages
  15307. (setq pack-list (vhdl-get-packages lib-alist work-library))
  15308. (setq depend-list (append depend-list pack-list))
  15309. (setq all-pack-list pack-list)
  15310. ;; add rule
  15311. (aput 'rule-alist pack-file-name (list target-list depend-list))
  15312. ;; rules for this package's body
  15313. (when (nth 7 pack-entry)
  15314. (setq pack-body-key (concat pack-key "-body")
  15315. pack-body-file-name (file-relative-name (nth 7 pack-entry)
  15316. compile-directory)
  15317. rule (aget rule-alist pack-body-file-name)
  15318. target-list (nth 0 rule)
  15319. depend-list (nth 1 rule))
  15320. (setq tmp-key (vhdl-replace-string
  15321. pack-body-regexp (funcall adjust-case pack-key)))
  15322. (setq unit-list
  15323. (cons (cons pack-body-key tmp-key) unit-list))
  15324. ;; rule target for this package's body
  15325. (setq target-list (cons pack-body-key target-list))
  15326. ;; rule dependency for corresponding package declaration
  15327. (setq depend-list (cons pack-key depend-list))
  15328. ;; rule dependencies for all used packages
  15329. (setq pack-list (vhdl-get-packages lib-body-alist work-library))
  15330. (setq depend-list (append depend-list pack-list))
  15331. (setq all-pack-list (append all-pack-list pack-list))
  15332. ;; add rule
  15333. (aput 'rule-alist pack-body-file-name
  15334. (list target-list depend-list)))
  15335. (setq prim-list
  15336. (cons (list pack-key (when pack-body-key (list pack-body-key))
  15337. all-pack-list)
  15338. prim-list)))
  15339. (setq pack-alist (cdr pack-alist)))
  15340. (setq pack-alist tmp-list)
  15341. ;; generate Makefile
  15342. (let* ((project (aget vhdl-project-alist project))
  15343. (compiler (aget vhdl-compiler-alist vhdl-compiler))
  15344. (compiler-id (nth 9 compiler))
  15345. (library-directory
  15346. (vhdl-resolve-env-variable
  15347. (vhdl-replace-string
  15348. (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
  15349. compiler-id)))
  15350. (makefile-path-name (expand-file-name
  15351. makefile-name compile-directory))
  15352. (orig-buffer (current-buffer))
  15353. cell second-list subcomp-list options unit-key unit-name)
  15354. ;; sort lists
  15355. (setq unit-list (vhdl-sort-alist unit-list))
  15356. (setq prim-list (vhdl-sort-alist prim-list))
  15357. (setq tmp-list rule-alist)
  15358. (while tmp-list ; pre-sort rule targets
  15359. (setq cell (cdar tmp-list))
  15360. (setcar cell (sort (car cell) 'string<))
  15361. (setq tmp-list (cdr tmp-list)))
  15362. (setq rule-alist ; sort by first rule target
  15363. (sort rule-alist
  15364. (function (lambda (a b)
  15365. (string< (car (cadr a)) (car (cadr b)))))))
  15366. ;; open and clear Makefile
  15367. (set-buffer (find-file-noselect makefile-path-name t t))
  15368. (erase-buffer)
  15369. (insert "# -*- Makefile -*-\n"
  15370. "### " (file-name-nondirectory makefile-name)
  15371. " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
  15372. "\n")
  15373. (if project
  15374. (insert "\n# Project : " (nth 0 project))
  15375. (insert "\n# Directory : \"" directory "\""))
  15376. (insert "\n# Platform : " vhdl-compiler
  15377. "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
  15378. (user-login-name) "\n")
  15379. ;; insert compile and option variable settings
  15380. (insert "\n\n# Define compilation command and options\n"
  15381. "\nCOMPILE = " (nth 0 compiler)
  15382. "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
  15383. "\n")
  15384. ;; insert library paths
  15385. (setq library-directory
  15386. (directory-file-name
  15387. (if (file-name-absolute-p library-directory)
  15388. library-directory
  15389. (file-relative-name
  15390. (expand-file-name library-directory directory)
  15391. compile-directory))))
  15392. (insert "\n\n# Define library paths\n"
  15393. "\nLIBRARY-" work-library " = " library-directory "\n")
  15394. ;; insert variable definitions for all library unit files
  15395. (insert "\n\n# Define library unit files\n")
  15396. (setq tmp-list unit-list)
  15397. (while unit-list
  15398. (insert "\nUNIT-" work-library "-" (caar unit-list)
  15399. " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
  15400. (setq unit-list (cdr unit-list)))
  15401. ;; insert variable definition for list of all library unit files
  15402. (insert "\n\n\n# Define list of all library unit files\n"
  15403. "\nALL_UNITS =")
  15404. (setq unit-list tmp-list)
  15405. (while unit-list
  15406. (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
  15407. (setq unit-list (cdr unit-list)))
  15408. (insert "\n")
  15409. (setq unit-list tmp-list)
  15410. ;; insert `make all' rule
  15411. (insert "\n\n\n# Rule for compiling entire design\n"
  15412. "\nall :"
  15413. " \\\n\t\tlibrary"
  15414. " \\\n\t\t$(ALL_UNITS)\n")
  15415. ;; insert `make clean' rule
  15416. (insert "\n\n# Rule for cleaning entire design\n"
  15417. "\nclean : "
  15418. "\n\t-rm -f $(ALL_UNITS)\n")
  15419. ;; insert `make library' rule
  15420. (insert "\n\n# Rule for creating library directory\n"
  15421. "\nlibrary :"
  15422. " \\\n\t\t$(LIBRARY-" work-library ")\n"
  15423. "\n$(LIBRARY-" work-library ") :"
  15424. "\n\t"
  15425. (vhdl-replace-string
  15426. (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
  15427. (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
  15428. "\n")
  15429. ;; insert rule for each library unit
  15430. (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
  15431. (while prim-list
  15432. (setq second-list (sort (nth 1 (car prim-list)) 'string<))
  15433. (setq subcomp-list
  15434. (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
  15435. (setq unit-key (caar prim-list)
  15436. unit-name (or (nth 0 (aget ent-alist unit-key t))
  15437. (nth 0 (aget conf-alist unit-key t))
  15438. (nth 0 (aget pack-alist unit-key t))))
  15439. (insert "\n" unit-key)
  15440. (unless (equal unit-key unit-name)
  15441. (insert " \\\n" unit-name))
  15442. (insert " :"
  15443. " \\\n\t\tlibrary"
  15444. " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
  15445. (while second-list
  15446. (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
  15447. (setq second-list (cdr second-list)))
  15448. (while subcomp-list
  15449. (when (and (assoc (car subcomp-list) unit-list)
  15450. (not (equal unit-key (car subcomp-list))))
  15451. (insert " \\\n\t\t" (car subcomp-list)))
  15452. (setq subcomp-list (cdr subcomp-list)))
  15453. (insert "\n")
  15454. (setq prim-list (cdr prim-list)))
  15455. ;; insert rule for each library unit file
  15456. (insert "\n\n# Rules for compiling single library unit files\n")
  15457. (while rule-alist
  15458. (setq rule (car rule-alist))
  15459. ;; get compiler options for this file
  15460. (setq options
  15461. (vhdl-get-compile-options project compiler (nth 0 rule) t))
  15462. ;; insert rule if file is supposed to be compiled
  15463. (setq target-list (nth 1 rule)
  15464. depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
  15465. ;; insert targets
  15466. (setq tmp-list target-list)
  15467. (while target-list
  15468. (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
  15469. (if (cdr target-list) " \\" " :"))
  15470. (setq target-list (cdr target-list)))
  15471. (setq target-list tmp-list)
  15472. ;; insert file name as first dependency
  15473. (insert " \\\n\t\t" (nth 0 rule))
  15474. ;; insert dependencies (except if also target or unit does not exist)
  15475. (while depend-list
  15476. (when (and (not (member (car depend-list) target-list))
  15477. (assoc (car depend-list) unit-list))
  15478. (insert " \\\n\t\t"
  15479. "$(UNIT-" work-library "-" (car depend-list) ")"))
  15480. (setq depend-list (cdr depend-list)))
  15481. ;; insert compile command
  15482. (if options
  15483. (insert "\n\t$(COMPILE) "
  15484. (if (eq options 'default) "$(OPTIONS)" options) " "
  15485. (nth 0 rule) "\n")
  15486. (setq tmp-list target-list)
  15487. (while target-list
  15488. (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
  15489. (if (cdr target-list) " \\" "\n"))
  15490. (setq target-list (cdr target-list)))
  15491. (setq target-list tmp-list))
  15492. (setq rule-alist (cdr rule-alist)))
  15493. (insert "\n\n### " makefile-name " ends here\n")
  15494. ;; run Makefile generation hook
  15495. (run-hooks 'vhdl-makefile-generation-hook)
  15496. (message "Generating makefile \"%s\"...done" makefile-name)
  15497. ;; save and close file
  15498. (if (file-writable-p makefile-path-name)
  15499. (progn (save-buffer)
  15500. (kill-buffer (current-buffer))
  15501. (set-buffer orig-buffer)
  15502. (add-to-history 'file-name-history makefile-path-name))
  15503. (vhdl-warning-when-idle
  15504. (format "File not writable: \"%s\""
  15505. (abbreviate-file-name makefile-path-name)))
  15506. (switch-to-buffer (current-buffer))))))
  15507. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15508. ;;; Bug reports
  15509. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15510. ;; (using `reporter.el')
  15511. (defconst vhdl-mode-help-address
  15512. "Reto Zimmermann <reto@gnu.org>"
  15513. "Address for VHDL Mode bug reports.")
  15514. (defun vhdl-submit-bug-report ()
  15515. "Submit via mail a bug report on VHDL Mode."
  15516. (interactive)
  15517. ;; load in reporter
  15518. (and
  15519. (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
  15520. (let ((reporter-prompt-for-summary-p t))
  15521. (reporter-submit-bug-report
  15522. vhdl-mode-help-address
  15523. (concat "VHDL Mode " vhdl-version)
  15524. (list
  15525. ;; report all important user options
  15526. 'vhdl-offsets-alist
  15527. 'vhdl-comment-only-line-offset
  15528. 'tab-width
  15529. 'vhdl-electric-mode
  15530. 'vhdl-stutter-mode
  15531. 'vhdl-indent-tabs-mode
  15532. 'vhdl-project-alist
  15533. 'vhdl-project
  15534. 'vhdl-project-file-name
  15535. 'vhdl-project-auto-load
  15536. 'vhdl-project-sort
  15537. 'vhdl-compiler-alist
  15538. 'vhdl-compiler
  15539. 'vhdl-compile-use-local-error-regexp
  15540. 'vhdl-makefile-generation-hook
  15541. 'vhdl-default-library
  15542. 'vhdl-standard
  15543. 'vhdl-basic-offset
  15544. 'vhdl-upper-case-keywords
  15545. 'vhdl-upper-case-types
  15546. 'vhdl-upper-case-attributes
  15547. 'vhdl-upper-case-enum-values
  15548. 'vhdl-upper-case-constants
  15549. 'vhdl-use-direct-instantiation
  15550. 'vhdl-compose-configuration-name
  15551. 'vhdl-entity-file-name
  15552. 'vhdl-architecture-file-name
  15553. 'vhdl-configuration-file-name
  15554. 'vhdl-package-file-name
  15555. 'vhdl-file-name-case
  15556. 'vhdl-electric-keywords
  15557. 'vhdl-optional-labels
  15558. 'vhdl-insert-empty-lines
  15559. 'vhdl-argument-list-indent
  15560. 'vhdl-association-list-with-formals
  15561. 'vhdl-conditions-in-parenthesis
  15562. 'vhdl-zero-string
  15563. 'vhdl-one-string
  15564. 'vhdl-file-header
  15565. 'vhdl-file-footer
  15566. 'vhdl-company-name
  15567. 'vhdl-copyright-string
  15568. 'vhdl-platform-spec
  15569. 'vhdl-date-format
  15570. 'vhdl-modify-date-prefix-string
  15571. 'vhdl-modify-date-on-saving
  15572. 'vhdl-reset-kind
  15573. 'vhdl-reset-active-high
  15574. 'vhdl-clock-rising-edge
  15575. 'vhdl-clock-edge-condition
  15576. 'vhdl-clock-name
  15577. 'vhdl-reset-name
  15578. 'vhdl-model-alist
  15579. 'vhdl-include-port-comments
  15580. 'vhdl-include-direction-comments
  15581. 'vhdl-include-type-comments
  15582. 'vhdl-include-group-comments
  15583. 'vhdl-actual-port-name
  15584. 'vhdl-instance-name
  15585. 'vhdl-testbench-entity-name
  15586. 'vhdl-testbench-architecture-name
  15587. 'vhdl-testbench-configuration-name
  15588. 'vhdl-testbench-dut-name
  15589. 'vhdl-testbench-include-header
  15590. 'vhdl-testbench-declarations
  15591. 'vhdl-testbench-statements
  15592. 'vhdl-testbench-initialize-signals
  15593. 'vhdl-testbench-include-library
  15594. 'vhdl-testbench-include-configuration
  15595. 'vhdl-testbench-create-files
  15596. 'vhdl-testbench-entity-file-name
  15597. 'vhdl-testbench-architecture-file-name
  15598. 'vhdl-compose-create-files
  15599. 'vhdl-compose-configuration-create-file
  15600. 'vhdl-compose-configuration-hierarchical
  15601. 'vhdl-compose-configuration-use-subconfiguration
  15602. 'vhdl-compose-include-header
  15603. 'vhdl-compose-architecture-name
  15604. 'vhdl-components-package-name
  15605. 'vhdl-use-components-package
  15606. 'vhdl-self-insert-comments
  15607. 'vhdl-prompt-for-comments
  15608. 'vhdl-inline-comment-column
  15609. 'vhdl-end-comment-column
  15610. 'vhdl-auto-align
  15611. 'vhdl-align-groups
  15612. 'vhdl-align-group-separate
  15613. 'vhdl-align-same-indent
  15614. 'vhdl-highlight-keywords
  15615. 'vhdl-highlight-names
  15616. 'vhdl-highlight-special-words
  15617. 'vhdl-highlight-forbidden-words
  15618. 'vhdl-highlight-verilog-keywords
  15619. 'vhdl-highlight-translate-off
  15620. 'vhdl-highlight-case-sensitive
  15621. 'vhdl-special-syntax-alist
  15622. 'vhdl-forbidden-words
  15623. 'vhdl-forbidden-syntax
  15624. 'vhdl-directive-keywords
  15625. 'vhdl-speedbar-auto-open
  15626. 'vhdl-speedbar-display-mode
  15627. 'vhdl-speedbar-scan-limit
  15628. 'vhdl-speedbar-jump-to-unit
  15629. 'vhdl-speedbar-update-on-saving
  15630. 'vhdl-speedbar-save-cache
  15631. 'vhdl-speedbar-cache-file-name
  15632. 'vhdl-index-menu
  15633. 'vhdl-source-file-menu
  15634. 'vhdl-hideshow-menu
  15635. 'vhdl-hide-all-init
  15636. 'vhdl-print-two-column
  15637. 'vhdl-print-customize-faces
  15638. 'vhdl-intelligent-tab
  15639. 'vhdl-indent-syntax-based
  15640. 'vhdl-word-completion-case-sensitive
  15641. 'vhdl-word-completion-in-minibuffer
  15642. 'vhdl-underscore-is-part-of-word
  15643. 'vhdl-mode-hook)
  15644. (function
  15645. (lambda ()
  15646. (insert
  15647. (if vhdl-special-indent-hook
  15648. (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
  15649. "vhdl-special-indent-hook is set to '"
  15650. (format "%s" vhdl-special-indent-hook)
  15651. ".\nPerhaps this is your problem?\n"
  15652. "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
  15653. "\n"))))
  15654. nil
  15655. "Hi Reto,"))))
  15656. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15657. ;;; Documentation
  15658. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15659. (defconst vhdl-doc-release-notes nil
  15660. "\
  15661. Release Notes for VHDL Mode 3.33
  15662. ================================
  15663. - New Features
  15664. - User Options
  15665. New Features
  15666. ------------
  15667. CONFIGURATION DECLARATION GENERATION:
  15668. - Automatic generation of a configuration declaration for a design.
  15669. (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
  15670. User Options
  15671. ------------
  15672. `vhdl-configuration-file-name': (new)
  15673. Specify how the configuration file name is obtained.
  15674. `vhdl-compose-configuration-name': (new)
  15675. Specify how the configuration name is obtained.
  15676. `vhdl-compose-configuration-create-file': (new)
  15677. Specify whether a new file should be created for a configuration.
  15678. `vhdl-compose-configuration-hierarchical': (new)
  15679. Specify whether hierarchical configurations should be created.
  15680. `vhdl-compose-configuration-use-subconfiguration': (new)
  15681. Specify whether subconfigurations should be used inside configurations.
  15682. ")
  15683. (defconst vhdl-doc-keywords nil
  15684. "\
  15685. Reserved words in VHDL
  15686. ----------------------
  15687. VHDL'93 (IEEE Std 1076-1993):
  15688. `vhdl-93-keywords' : keywords
  15689. `vhdl-93-types' : standardized types
  15690. `vhdl-93-attributes' : standardized attributes
  15691. `vhdl-93-enum-values' : standardized enumeration values
  15692. `vhdl-93-functions' : standardized functions
  15693. `vhdl-93-packages' : standardized packages and libraries
  15694. VHDL-AMS (IEEE Std 1076.1):
  15695. `vhdl-ams-keywords' : keywords
  15696. `vhdl-ams-types' : standardized types
  15697. `vhdl-ams-attributes' : standardized attributes
  15698. `vhdl-ams-enum-values' : standardized enumeration values
  15699. `vhdl-ams-functions' : standardized functions
  15700. Math Packages (IEEE Std 1076.2):
  15701. `vhdl-math-types' : standardized types
  15702. `vhdl-math-constants' : standardized constants
  15703. `vhdl-math-functions' : standardized functions
  15704. `vhdl-math-packages' : standardized packages
  15705. Forbidden words:
  15706. `vhdl-verilog-keywords' : Verilog reserved words
  15707. NOTE: click `mouse-2' on variable names above (not in XEmacs).")
  15708. (defconst vhdl-doc-coding-style nil
  15709. "\
  15710. For VHDL coding style and naming convention guidelines, see the following
  15711. references:
  15712. \[1] Ben Cohen.
  15713. \"VHDL Coding Styles and Methodologies\".
  15714. Kluwer Academic Publishers, 1999.
  15715. http://members.aol.com/vhdlcohen/vhdl/
  15716. \[2] Michael Keating and Pierre Bricaud.
  15717. \"Reuse Methodology Manual, Second Edition\".
  15718. Kluwer Academic Publishers, 1999.
  15719. http://www.openmore.com/openmore/rmm2.html
  15720. \[3] European Space Agency.
  15721. \"VHDL Modelling Guidelines\".
  15722. ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
  15723. Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
  15724. to visually support naming conventions.")
  15725. (defun vhdl-version ()
  15726. "Echo the current version of VHDL Mode in the minibuffer."
  15727. (interactive)
  15728. (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
  15729. (vhdl-keep-region-active))
  15730. (defun vhdl-doc-variable (variable)
  15731. "Display VARIABLE's documentation in *Help* buffer."
  15732. (interactive)
  15733. (unless (featurep 'xemacs)
  15734. (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
  15735. (with-output-to-temp-buffer
  15736. (if (fboundp 'help-buffer) (help-buffer) "*Help*")
  15737. (princ (documentation-property variable 'variable-documentation))
  15738. (with-current-buffer standard-output
  15739. (help-mode))
  15740. (help-print-return-message)))
  15741. (defun vhdl-doc-mode ()
  15742. "Display VHDL Mode documentation in *Help* buffer."
  15743. (interactive)
  15744. (unless (featurep 'xemacs)
  15745. (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
  15746. (with-output-to-temp-buffer
  15747. (if (fboundp 'help-buffer) (help-buffer) "*Help*")
  15748. (princ mode-name)
  15749. (princ " mode:\n")
  15750. (princ (documentation 'vhdl-mode))
  15751. (with-current-buffer standard-output
  15752. (help-mode))
  15753. (help-print-return-message)))
  15754. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15755. (provide 'vhdl-mode)
  15756. ;;; vhdl-mode.el ends here