vhdl-mode.el 668 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431
  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.28"
  13. "VHDL Mode version number.")
  14. (defconst vhdl-time-stamp "2010-09-22"
  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,23.X, XEmacs 20.X/21.X
  60. ;; tested on: GNU Emacs 20.4/21.3/22.1,23.X, XEmacs 21.1 (marginally)
  61. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  62. ;; Installation
  63. ;; Prerequisites: GNU Emacs 20.X/21.X/22.X/23.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 and higher):
  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 (customization options)
  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. ("ADVance MS" "vacom" "-work \\1" "make" "-f \\1"
  168. nil "valib \\1; vamap \\2 \\1" "./" "work/" "Makefile" "adms"
  169. ("\\s-\\([0-9]+\\):" 0 1 0) ("Compiling file \\(.+\\)" 1)
  170. ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
  171. "PACK/\\1.vif" "BODY/\\1.vif" upcase))
  172. ;; Aldec
  173. ;; COMP96 ERROR COMP96_0078: "Unknown identifier "Addr_Bits"." "<filename>" 40 30
  174. ("Aldec" "vcom" "-93 -work \\1" "make" "-f \\1"
  175. nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "aldec"
  176. (".+?[ \t]+\\(?:ERROR\\)[^:]+:.+?\\(?:.+\"\\(.+?\\)\"[ \t]+\\([0-9]+\\)\\)" 1 2 0) ("" 0)
  177. nil)
  178. ;; Cadence Leapfrog: cv -file test.vhd
  179. ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
  180. ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
  181. nil "mkdir \\1" "./" "work/" "Makefile" "leapfrog"
  182. ("duluth: \\*E,[0-9]+ (\\(.+\\),\\([0-9]+\\)):" 1 2 0) ("" 0)
  183. ("\\1/entity" "\\2/\\1" "\\1/configuration"
  184. "\\1/package" "\\1/body" downcase))
  185. ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
  186. ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
  187. ;; (PLL_400X_TOP) is not declared [10.3].
  188. ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
  189. nil "mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
  190. ("ncvhdl_p: \\*E,\\w+ (\\(.+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
  191. ("\\1/entity/pc.db" "\\2/\\1/pc.db" "\\1/configuration/pc.db"
  192. "\\1/package/pc.db" "\\1/body/pc.db" downcase))
  193. ;; ghdl vhdl: ghdl test.vhd
  194. ("GHDL" "ghdl" "-i --workdir=\\1 --ieee=synopsys -fexplicit " "make" "-f \\1"
  195. nil "mkdir \\1" "./" "work/" "Makefile" "ghdl"
  196. ("ghdl_p: \\*E,\\w+ (\\(.+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
  197. ("\\1/entity" "\\2/\\1" "\\1/configuration"
  198. "\\1/package" "\\1/body" downcase))
  199. ;; Ikos Voyager: analyze test.vhd
  200. ;; analyze test.vhd
  201. ;; E L4/C5: this library unit is inaccessible
  202. ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
  203. nil "mkdir \\1" "./" "work/" "Makefile" "ikos"
  204. ("E L\\([0-9]+\\)/C\\([0-9]+\\):" 0 1 2)
  205. ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
  206. nil)
  207. ;; ModelSim, Model Technology: vcom test.vhd
  208. ;; ERROR: test.vhd(14): Unknown identifier: positiv
  209. ;; WARNING[2]: test.vhd(85): Possible infinite loop
  210. ;; ** Warning: [4] ../src/emacsvsim.vhd(43): An abstract ...
  211. ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
  212. ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
  213. nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
  214. ("\\(ERROR\\|WARNING\\|\\*\\* Error\\|\\*\\* Warning\\)[^:]*:\\( *\[[0-9]+\]\\)? \\(.+\\)(\\([0-9]+\\)):" 3 4 0) ("" 0)
  215. ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
  216. "\\1/_primary.dat" "\\1/body.dat" downcase))
  217. ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
  218. ;; test.vhd:34: error message
  219. ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
  220. nil "mkdir \\1" "./" "work/" "Makefile" "provhdl"
  221. ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
  222. ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
  223. "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase))
  224. ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
  225. ;; ERROR: test.vhd(24): near "dnd": expecting: END
  226. ;; WARNING[4]: test.vhd(30): A space is required between ...
  227. ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
  228. nil "mkdir \\1" "./" "work/" "Makefile" "quickhdl"
  229. ("\\(ERROR\\|WARNING\\)[^:]*: \\(.+\\)(\\([0-9]+\\)):" 2 3 0) ("" 0)
  230. ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
  231. "\\1/_primary.dat" "\\1/body.dat" downcase))
  232. ;; Savant: scram -publish-cc test.vhd
  233. ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
  234. ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
  235. nil "mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
  236. ("\\([^ \t\n]+\\):\\([0-9]+\\): " 1 2 0) ("" 0)
  237. ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
  238. "\\1_config.vhdl" "\\1_package.vhdl"
  239. "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase))
  240. ;; Simili: vhdlp -work test.vhd
  241. ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
  242. ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
  243. nil "mkdir \\1" "./" "work/" "Makefile" "simili"
  244. ("\\(Error\\|Warning\\): \\w+: \\(.+\\): (line \\([0-9]+\\)): " 2 3 0) ("" 0)
  245. ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
  246. "\\1/prim.var" "\\1/_body.var" downcase))
  247. ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
  248. ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
  249. ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
  250. nil "mkdir \\1" "./" "work/" "Makefile" "speedwave"
  251. ("^ *ERROR\[[0-9]+\]::File \\(.+\\) Line \\([0-9]+\\):" 1 2 0) ("" 0)
  252. nil)
  253. ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
  254. ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
  255. ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
  256. nil "mkdir \\1" "./" "work/" "Makefile" "synopsys"
  257. ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
  258. ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase))
  259. ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
  260. ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
  261. ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
  262. nil "mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
  263. ("\\*\\*Error: vhdlan,[0-9]+ \\(.+\\)(\\([0-9]+\\)):" 1 2 0) ("" 0)
  264. ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase))
  265. ;; Synplify:
  266. ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
  267. ("Synplify" "n/a" "n/a" "make" "-f \\1"
  268. nil "mkdir \\1" "./" "work/" "Makefile" "synplify"
  269. ("@[EWN]:\"\\(.+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
  270. nil)
  271. ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
  272. ;; Compiling "test.vhd" line 1...
  273. ;; **Error: LINE 49 *** No aggregate value is valid in this context.
  274. ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
  275. nil "mkdir \\1" "./" "work/" "Makefile" "vantage"
  276. ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
  277. ("^ *Compiling \"\\(.+\\)\" " 1)
  278. nil)
  279. ;; VeriBest: vc vhdl test.vhd
  280. ;; (no file name printed out!)
  281. ;; 32: Z <= A and BitA ;
  282. ;; ^^^^
  283. ;; [Error] Name BITA is unknown
  284. ("VeriBest" "vc" "vhdl" "make" "-f \\1"
  285. nil "mkdir \\1" "./" "work/" "Makefile" "veribest"
  286. ("^ +\\([0-9]+\\): +[^ ]" 0 1 0) ("" 0)
  287. nil)
  288. ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
  289. ;; Compiling "test.vhd" line 1...
  290. ;; **Error: LINE 49 *** No aggregate value is valid in this context.
  291. ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
  292. nil "mkdir \\1" "./" "work/" "Makefile" "viewlogic"
  293. ("\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" 0 1 0)
  294. ("^ *Compiling \"\\(.+\\)\" " 1)
  295. nil)
  296. ;; Xilinx XST:
  297. ;; ERROR:HDLParsers:164 - "test.vhd" Line 3. parse error
  298. ("Xilinx XST" "xflow" "" "make" "-f \\1"
  299. nil "mkdir \\1" "./" "work/" "Makefile" "xilinx"
  300. ("^ERROR:HDLParsers:[0-9]+ - \"\\(.+\\)\" Line \\([0-9]+\\)\." 1 2 0) ("" 0)
  301. nil)
  302. )
  303. "List of available VHDL compilers and their properties.
  304. Each list entry specifies the following items for a compiler:
  305. Compiler:
  306. Compiler name : name used in option `vhdl-compiler' to choose compiler
  307. Compile command : command used for source file compilation
  308. Compile options : compile options (\"\\1\" inserts library name)
  309. Make command : command used for compilation using a Makefile
  310. Make options : make options (\"\\1\" inserts Makefile name)
  311. Generate Makefile: use built-in function or command to generate a Makefile
  312. \(\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
  313. Library command : command to create library directory \(\"\\1\" inserts
  314. library directory, \"\\2\" inserts library name)
  315. Compile directory: where compilation is run and the Makefile is placed
  316. Library directory: directory of default library
  317. Makefile name : name of Makefile (default is \"Makefile\")
  318. ID string : compiler identification string (see `vhdl-project-alist')
  319. Error message:
  320. Regexp : regular expression to match error messages (*)
  321. File subexp index: index of subexpression that matches the file name
  322. Line subexp index: index of subexpression that matches the line number
  323. Column subexp idx: index of subexpression that matches the column number
  324. File message:
  325. Regexp : regular expression to match a file name message
  326. File subexp index: index of subexpression that matches the file name
  327. Unit-to-file name mapping: mapping of library unit names to names of files
  328. generated by the compiler (used for Makefile generation)
  329. To string : string a name is mapped to (\"\\1\" inserts the unit name,
  330. \"\\2\" inserts the entity name for architectures)
  331. Case adjustment : adjust case of inserted unit names
  332. \(*) The regular expression must match the error message starting from the
  333. beginning of the line (but not necessarily to the end of the line).
  334. Compile options allows insertion of the library name (see `vhdl-project-alist')
  335. in order to set the compilers library option (e.g. \"vcom -work my_lib\").
  336. For Makefile generation, the built-in function can be used (requires
  337. specification of the unit-to-file name mapping). Alternatively, an
  338. external command can be specified. Work directory allows specification of
  339. an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
  340. used for Makefile generation). To use another library name than \"work\",
  341. customize `vhdl-project-alist'. The library command is inserted in Makefiles
  342. to automatically create the library directory if not existent.
  343. Compile options, compile directory, library directory, and Makefile name are
  344. overwritten by the project settings if a project is defined (see
  345. `vhdl-project-alist'). Directory paths are relative to the source file
  346. directory.
  347. Some compilers do not include the file name in the error message, but print
  348. out a file name message in advance. In this case, set \"File Subexp Index\"
  349. under \"Error Message\" to 0 and fill out the \"File Message\" entries.
  350. If no file name at all is printed out, set both \"File Message\" entries to 0
  351. \(a default file name message will be printed out instead, does not work in
  352. XEmacs).
  353. A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
  354. assigning its name to option `vhdl-compiler'.
  355. Please send any missing or erroneous compiler properties to the maintainer for
  356. updating.
  357. NOTE: Activate new error and file message regexps and reflect the new setting
  358. in the choice list of option `vhdl-compiler' by restarting Emacs."
  359. :type '(repeat
  360. (list :tag "Compiler" :indent 2
  361. (string :tag "Compiler name ")
  362. (string :tag "Compile command ")
  363. (string :tag "Compile options " "-work \\1")
  364. (string :tag "Make command " "make")
  365. (string :tag "Make options " "-f \\1")
  366. (choice :tag "Generate Makefile "
  367. (const :tag "Built-in function" nil)
  368. (string :tag "Command" "vmake \\2 > \\1"))
  369. (string :tag "Library command " "mkdir \\1")
  370. (directory :tag "Compile directory "
  371. :validate vhdl-widget-directory-validate "./")
  372. (directory :tag "Library directory "
  373. :validate vhdl-widget-directory-validate "work/")
  374. (file :tag "Makefile name " "Makefile")
  375. (string :tag "ID string ")
  376. (list :tag "Error message" :indent 4
  377. (regexp :tag "Regexp ")
  378. (integer :tag "File subexp index")
  379. (integer :tag "Line subexp index")
  380. (integer :tag "Column subexp idx"))
  381. (list :tag "File message" :indent 4
  382. (regexp :tag "Regexp ")
  383. (integer :tag "File subexp index"))
  384. (choice :tag "Unit-to-file name mapping"
  385. :format "%t: %[Value Menu%] %v\n"
  386. (const :tag "Not defined" nil)
  387. (list :tag "To string" :indent 4
  388. (string :tag "Entity " "\\1.vhd")
  389. (string :tag "Architecture " "\\2_\\1.vhd")
  390. (string :tag "Configuration " "\\1.vhd")
  391. (string :tag "Package " "\\1.vhd")
  392. (string :tag "Package Body " "\\1_body.vhd")
  393. (choice :tag "Case adjustment "
  394. (const :tag "None" identity)
  395. (const :tag "Upcase" upcase)
  396. (const :tag "Downcase" downcase))))))
  397. :set (lambda (variable value)
  398. (vhdl-custom-set variable value 'vhdl-update-mode-menu))
  399. :group 'vhdl-compile)
  400. (defcustom vhdl-compiler "GHDL"
  401. "Specifies the VHDL compiler to be used for syntax analysis.
  402. Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
  403. :type (let ((alist vhdl-compiler-alist) list)
  404. (while alist
  405. (setq list (cons (list 'const (caar alist)) list))
  406. (setq alist (cdr alist)))
  407. (append '(choice) (nreverse list)))
  408. :group 'vhdl-compile)
  409. (defcustom vhdl-compile-use-local-error-regexp t
  410. "Non-nil means use buffer-local `compilation-error-regexp-alist'.
  411. In this case, only error message regexps for VHDL compilers are active if
  412. compilation is started from a VHDL buffer. Otherwise, the error message
  413. regexps are appended to the predefined global regexps, and all regexps are
  414. active all the time. Note that by doing that, the predefined global regexps
  415. might result in erroneous parsing of error messages for some VHDL compilers.
  416. NOTE: Activate the new setting by restarting Emacs."
  417. :type 'boolean
  418. :group 'vhdl-compile)
  419. (defcustom vhdl-makefile-default-targets '("all" "clean" "library")
  420. "List of default target names in Makefiles.
  421. Automatically generated Makefiles include three default targets to compile
  422. the entire design, clean the entire design and to create the design library.
  423. This option allows to change the names of these targets to avoid conflicts
  424. with other user Makefiles."
  425. :type '(list (string :tag "Compile entire design")
  426. (string :tag "Clean entire design ")
  427. (string :tag "Create design library"))
  428. :group 'vhdl-compile)
  429. (defcustom vhdl-makefile-generation-hook nil
  430. "Functions to run at the end of Makefile generation.
  431. Allows to insert user specific parts into a Makefile.
  432. Example:
  433. \(lambda nil
  434. \(re-search-backward \"^# Rule for compiling entire design\")
  435. \(insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
  436. :type 'hook
  437. :group 'vhdl-compile)
  438. (defcustom vhdl-default-library "work"
  439. "Name of default library.
  440. Is overwritten by project settings if a project is active."
  441. :type 'string
  442. :group 'vhdl-compile)
  443. (defgroup vhdl-project nil
  444. "Customizations for projects."
  445. :group 'vhdl)
  446. (defcustom vhdl-project-alist
  447. '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
  448. "~/example1/" ("src/system/" "src/components/") ""
  449. (("ModelSim" "-87 \\2" "-f \\1 top_level" nil)
  450. ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" . "-optimize \\3") (".*_tb\\.vhd" . nil))))
  451. "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
  452. ("Example 2" "Individual source files, multiple compilers in different directories"
  453. "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
  454. nil "\\1/" "work" "\\1/work/" "Makefile" "")
  455. ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
  456. "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
  457. nil "./" "work" "work-\\1/" "Makefile-\\1" "\
  458. -------------------------------------------------------------------------------
  459. -- This is a multi-line project description
  460. -- that can be used as a project dependent part of the file header.
  461. "))
  462. "List of projects and their properties.
  463. Name : name used in option `vhdl-project' to choose project
  464. Title : title of project (single-line string)
  465. Default directory: default project directory (absolute path)
  466. Sources : a) source files : path + \"/\" + file name
  467. b) directory : path + \"/\"
  468. c) directory tree: \"-r \" + path + \"/\"
  469. Exclude regexp : matches file/directory names to be excluded as sources
  470. Compile options : project-specific options for each compiler
  471. Compiler name : name of compiler for which these options are valid
  472. Compile options: project-specific compiler options
  473. (\"\\1\" inserts library name, \"\\2\" default options)
  474. Make options: project-specific make options
  475. (\"\\1\" inserts Makefile name, \"\\2\" default options)
  476. Exceptions : file-specific exceptions
  477. File name regexp: matches file names for which exceptions are valid
  478. - Options : file-specific compiler options string
  479. (\"\\1\" inserts library name, \"\\2\" default options,
  480. \"\\3\" project-specific options)
  481. - Do not compile: do not compile this file (in Makefile)
  482. Compile directory: where compilation is run and the Makefile is placed
  483. \(\"\\1\" inserts compiler ID string)
  484. Library name : name of library (default is \"work\")
  485. Library directory: path to library (\"\\1\" inserts compiler ID string)
  486. Makefile name : name of Makefile
  487. (\"\\1\" inserts compiler ID string, \"\\2\" library name)
  488. Description : description of project (multi-line string)
  489. Project title and description are used to insert into the file header (see
  490. option `vhdl-file-header').
  491. The default directory must have an absolute path (use `M-TAB' for completion).
  492. All other paths can be absolute or relative to the default directory. All
  493. paths must end with '/'.
  494. The design units found in the sources (files and directories) are shown in the
  495. hierarchy browser. Path and file name can contain wildcards `*' and `?' as
  496. well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
  497. Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
  498. specified, the default directory is taken as source directory. Otherwise,
  499. the default directory is only taken as source directory if there is a sources
  500. entry with the empty string or \"./\". Exclude regexp allows to filter out
  501. specific file and directory names from the list of sources (e.g. CVS
  502. directories).
  503. Files are compiled in the compile directory. Makefiles are also placed into
  504. the compile directory. Library directory specifies which directory the
  505. compiler compiles into (used to generate the Makefile).
  506. Since different compile/library directories and Makefiles may exist for
  507. different compilers within one project, these paths and names allow the
  508. insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
  509. Compile options, compile directory, library directory, and Makefile name
  510. overwrite the settings of the current compiler.
  511. File-specific compiler options (highest priority) overwrite project-specific
  512. options which overwrite default options (lowest priority). Lower priority
  513. options can be inserted in higher priority options. This allows to reuse
  514. default options (e.g. \"-file\") in project- or file-specific options (e.g.
  515. \"-93 -file\").
  516. NOTE: Reflect the new setting in the choice list of option `vhdl-project'
  517. by restarting Emacs."
  518. :type `(repeat
  519. (list :tag "Project" :indent 2
  520. (string :tag "Name ")
  521. (string :tag "Title ")
  522. (directory :tag "Default directory"
  523. :validate vhdl-widget-directory-validate
  524. ,(abbreviate-file-name default-directory))
  525. (repeat :tag "Sources " :indent 4
  526. (directory :format " %v" "./"))
  527. (regexp :tag "Exclude regexp ")
  528. (repeat
  529. :tag "Compile options " :indent 4
  530. (list :tag "Compiler" :indent 6
  531. ,(let ((alist vhdl-compiler-alist) list)
  532. (while alist
  533. (setq list (cons (list 'const (caar alist)) list))
  534. (setq alist (cdr alist)))
  535. (append '(choice :tag "Compiler name")
  536. (nreverse list)))
  537. (string :tag "Compile options" "\\2")
  538. (string :tag "Make options " "\\2")
  539. (repeat
  540. :tag "Exceptions " :indent 8
  541. (cons :format "%v"
  542. (regexp :tag "File name regexp ")
  543. (choice :format "%[Value Menu%] %v"
  544. (string :tag "Options" "\\3")
  545. (const :tag "Do not compile" nil))))))
  546. (directory :tag "Compile directory"
  547. :validate vhdl-widget-directory-validate "./")
  548. (string :tag "Library name " "work")
  549. (directory :tag "Library directory"
  550. :validate vhdl-widget-directory-validate "work/")
  551. (file :tag "Makefile name " "Makefile")
  552. (string :tag "Description: (type `C-j' for newline)"
  553. :format "%t\n%v\n")))
  554. :set (lambda (variable value)
  555. (vhdl-custom-set variable value
  556. 'vhdl-update-mode-menu
  557. 'vhdl-speedbar-refresh))
  558. :group 'vhdl-project)
  559. (defcustom vhdl-project nil
  560. "Specifies the default for the current project.
  561. Select a project name from the ones defined in option `vhdl-project-alist'.
  562. Is used to determine the project title and description to be inserted in file
  563. headers and the source files/directories to be scanned in the hierarchy
  564. browser. The current project can also be changed temporarily in the menu."
  565. :type (let ((alist vhdl-project-alist) list)
  566. (while alist
  567. (setq list (cons (list 'const (caar alist)) list))
  568. (setq alist (cdr alist)))
  569. (append '(choice (const :tag "None" nil) (const :tag "--"))
  570. (nreverse list)))
  571. :group 'vhdl-project)
  572. (defcustom vhdl-project-file-name '("\\1.prj")
  573. "List of file names/paths for importing/exporting project setups.
  574. \"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
  575. replaced by the user name (allows to have user-specific project setups).
  576. The first entry is used as file name to import/export individual project
  577. setups. All entries are used to automatically import project setups at
  578. startup (see option `vhdl-project-auto-load'). Projects loaded from the
  579. first entry are automatically made current. Hint: specify local project
  580. setups in first entry, global setups in following entries; loading a local
  581. project setup will make it current, while loading the global setups
  582. is done without changing the current project.
  583. Names can also have an absolute path (i.e. project setups can be stored
  584. in global directories)."
  585. :type '(repeat (string :tag "File name" "\\1.prj"))
  586. :group 'vhdl-project)
  587. (defcustom vhdl-project-auto-load '(startup)
  588. "Automatically load project setups from files.
  589. All project setup files that match the file names specified in option
  590. `vhdl-project-file-name' are automatically loaded. The project of the
  591. \(alphabetically) last loaded setup of the first `vhdl-project-file-name'
  592. entry is activated.
  593. A project setup file can be obtained by exporting a project (see menu).
  594. At startup: project setup file is loaded at Emacs startup"
  595. :type '(set (const :tag "At startup" startup))
  596. :group 'vhdl-project)
  597. (defcustom vhdl-project-sort t
  598. "Non-nil means projects are displayed in alphabetical order."
  599. :type 'boolean
  600. :group 'vhdl-project)
  601. (defgroup vhdl-style nil
  602. "Customizations for coding styles."
  603. :group 'vhdl
  604. :group 'vhdl-template
  605. :group 'vhdl-port
  606. :group 'vhdl-compose)
  607. (defcustom vhdl-standard '(93 nil)
  608. "VHDL standards used.
  609. Basic standard:
  610. VHDL'87 : IEEE Std 1076-1987
  611. VHDL'93/02 : IEEE Std 1076-1993/2002
  612. Additional standards:
  613. VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
  614. Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
  615. NOTE: Activate the new setting in a VHDL buffer by using the menu entry
  616. \"Activate Options\"."
  617. :type '(list (choice :tag "Basic standard"
  618. (const :tag "VHDL'87" 87)
  619. (const :tag "VHDL'93/02" 93))
  620. (set :tag "Additional standards" :indent 2
  621. (const :tag "VHDL-AMS" ams)
  622. (const :tag "Math packages" math)))
  623. :set (lambda (variable value)
  624. (vhdl-custom-set variable value
  625. 'vhdl-template-map-init
  626. 'vhdl-mode-abbrev-table-init
  627. 'vhdl-template-construct-alist-init
  628. 'vhdl-template-package-alist-init
  629. 'vhdl-update-mode-menu
  630. 'vhdl-words-init 'vhdl-font-lock-init))
  631. :group 'vhdl-style)
  632. (defcustom vhdl-basic-offset 2
  633. "Amount of basic offset used for indentation.
  634. This value is used by + and - symbols in `vhdl-offsets-alist'."
  635. :type 'integer
  636. :group 'vhdl-style)
  637. (defcustom vhdl-upper-case-keywords nil
  638. "Non-nil means convert keywords to upper case.
  639. This is done when typed or expanded or by the fix case functions."
  640. :type 'boolean
  641. :set (lambda (variable value)
  642. (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
  643. :group 'vhdl-style)
  644. (defcustom vhdl-upper-case-types nil
  645. "Non-nil means convert standardized types to upper case.
  646. This is done when expanded or by the fix case functions."
  647. :type 'boolean
  648. :set (lambda (variable value)
  649. (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
  650. :group 'vhdl-style)
  651. (defcustom vhdl-upper-case-attributes nil
  652. "Non-nil means convert standardized attributes to upper case.
  653. This is done when expanded or by the fix case functions."
  654. :type 'boolean
  655. :set (lambda (variable value)
  656. (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
  657. :group 'vhdl-style)
  658. (defcustom vhdl-upper-case-enum-values nil
  659. "Non-nil means convert standardized enumeration values to upper case.
  660. This is done when expanded or by the fix case functions."
  661. :type 'boolean
  662. :set (lambda (variable value)
  663. (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
  664. :group 'vhdl-style)
  665. (defcustom vhdl-upper-case-constants t
  666. "Non-nil means convert standardized constants to upper case.
  667. This is done when expanded."
  668. :type 'boolean
  669. :set (lambda (variable value)
  670. (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
  671. :group 'vhdl-style)
  672. (defcustom vhdl-use-direct-instantiation 'standard
  673. "Non-nil means use VHDL'93 direct component instantiation.
  674. Never : never
  675. Standard: only in VHDL standards that allow it (VHDL'93 and higher)
  676. Always : always"
  677. :type '(choice (const :tag "Never" never)
  678. (const :tag "Standard" standard)
  679. (const :tag "Always" always))
  680. :group 'vhdl-style)
  681. (defcustom vhdl-array-index-record-field-in-sensitivity-list t
  682. "Non-nil means include array indices / record fields in sensitivity list.
  683. If a signal read in a process is a record field or pointed to by an array
  684. index, the record field or array index is included with the record name in
  685. the sensitivity list (e.g. \"in1(0)\", \"in2.f0\").
  686. Otherwise, only the record name is included (e.g. \"in1\", \"in2\")."
  687. :type 'boolean
  688. :group 'vhdl-style)
  689. (defgroup vhdl-naming nil
  690. "Customizations for naming conventions."
  691. :group 'vhdl)
  692. (defcustom vhdl-entity-file-name '(".*" . "\\&")
  693. (concat
  694. "Specifies how the entity file name is obtained.
  695. The entity file name can be obtained by modifying the entity name (e.g.
  696. attaching or stripping off a substring). The file extension is automatically
  697. taken from the file name of the current buffer."
  698. vhdl-name-doc-string)
  699. :type '(cons (regexp :tag "From regexp")
  700. (string :tag "To string "))
  701. :group 'vhdl-naming
  702. :group 'vhdl-compose)
  703. (defcustom vhdl-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
  704. (concat
  705. "Specifies how the architecture file name is obtained.
  706. The architecture file name can be obtained by modifying the entity
  707. and/or architecture name (e.g. attaching or stripping off a substring). The
  708. file extension is automatically taken from the file name of the current
  709. buffer. The string that is matched against the regexp is the concatenation
  710. of the entity and the architecture name separated by a space. This gives
  711. access to both names (see default setting as example)."
  712. vhdl-name-doc-string)
  713. :type '(cons (regexp :tag "From regexp")
  714. (string :tag "To string "))
  715. :group 'vhdl-naming
  716. :group 'vhdl-compose)
  717. (defcustom vhdl-configuration-file-name '(".*" . "\\&")
  718. (concat
  719. "Specifies how the configuration file name is obtained.
  720. The configuration file name can be obtained by modifying the configuration
  721. name (e.g. attaching or stripping off a substring). The file extension is
  722. automatically taken from the file name of the current buffer."
  723. vhdl-name-doc-string)
  724. :type '(cons (regexp :tag "From regexp")
  725. (string :tag "To string "))
  726. :group 'vhdl-naming
  727. :group 'vhdl-compose)
  728. (defcustom vhdl-package-file-name '(".*" . "\\&")
  729. (concat
  730. "Specifies how the package file name is obtained.
  731. The package file name can be obtained by modifying the package name (e.g.
  732. attaching or stripping off a substring). The file extension is automatically
  733. taken from the file name of the current buffer. Package files can be created
  734. in a different directory by prepending a relative or absolute path to the
  735. file name."
  736. vhdl-name-doc-string)
  737. :type '(cons (regexp :tag "From regexp")
  738. (string :tag "To string "))
  739. :group 'vhdl-naming
  740. :group 'vhdl-compose)
  741. (defcustom vhdl-file-name-case 'identity
  742. "Specifies how to change case for obtaining file names.
  743. When deriving a file name from a VHDL unit name, case can be changed as
  744. follows:
  745. As Is: case is not changed (taken as is)
  746. Lower Case: whole name is changed to lower case
  747. Upper Case: whole name is changed to upper case
  748. Capitalize: first letter of each word in name is capitalized"
  749. :type '(choice (const :tag "As Is" identity)
  750. (const :tag "Lower Case" downcase)
  751. (const :tag "Upper Case" upcase)
  752. (const :tag "Capitalize" capitalize))
  753. :group 'vhdl-naming
  754. :group 'vhdl-compose)
  755. (defgroup vhdl-template nil
  756. "Customizations for electrification."
  757. :group 'vhdl)
  758. (defcustom vhdl-electric-keywords '(vhdl user)
  759. "Type of keywords for which electrification is enabled.
  760. VHDL keywords: invoke built-in templates
  761. User keywords: invoke user models (see option `vhdl-model-alist')"
  762. :type '(set (const :tag "VHDL keywords" vhdl)
  763. (const :tag "User model keywords" user))
  764. :set (lambda (variable value)
  765. (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
  766. :group 'vhdl-template)
  767. (defcustom vhdl-optional-labels 'process
  768. "Constructs for which labels are to be queried.
  769. Template generators prompt for optional labels for:
  770. None : no constructs
  771. Processes only: processes only (also procedurals in VHDL-AMS)
  772. All constructs: all constructs with optional labels and keyword END"
  773. :type '(choice (const :tag "None" none)
  774. (const :tag "Processes only" process)
  775. (const :tag "All constructs" all))
  776. :group 'vhdl-template)
  777. (defcustom vhdl-insert-empty-lines 'unit
  778. "Specifies whether to insert empty lines in some templates.
  779. This improves readability of code. Empty lines are inserted in:
  780. None : no constructs
  781. Design units only: entities, architectures, configurations, packages only
  782. All constructs : also all constructs with BEGIN...END parts
  783. Replaces option `vhdl-additional-empty-lines'."
  784. :type '(choice (const :tag "None" none)
  785. (const :tag "Design units only" unit)
  786. (const :tag "All constructs" all))
  787. :group 'vhdl-template
  788. :group 'vhdl-port
  789. :group 'vhdl-compose)
  790. (defcustom vhdl-argument-list-indent nil
  791. "Non-nil means indent argument lists relative to opening parenthesis.
  792. That is, argument, association, and port lists start on the same line as the
  793. opening parenthesis and subsequent lines are indented accordingly.
  794. Otherwise, lists start on a new line and are indented as normal code."
  795. :type 'boolean
  796. :group 'vhdl-template
  797. :group 'vhdl-port
  798. :group 'vhdl-compose)
  799. (defcustom vhdl-association-list-with-formals t
  800. "Non-nil means write association lists with formal parameters.
  801. Templates prompt for formal and actual parameters (ports/generics).
  802. When pasting component instantiations, formals are included.
  803. If nil, only a list of actual parameters is entered."
  804. :type 'boolean
  805. :group 'vhdl-template
  806. :group 'vhdl-port
  807. :group 'vhdl-compose)
  808. (defcustom vhdl-conditions-in-parenthesis nil
  809. "Non-nil means place parenthesis around condition expressions."
  810. :type 'boolean
  811. :group 'vhdl-template)
  812. (defcustom vhdl-zero-string "'0'"
  813. "String to use for a logic zero."
  814. :type 'string
  815. :group 'vhdl-template)
  816. (defcustom vhdl-one-string "'1'"
  817. "String to use for a logic one."
  818. :type 'string
  819. :group 'vhdl-template)
  820. (defgroup vhdl-header nil
  821. "Customizations for file header."
  822. :group 'vhdl-template
  823. :group 'vhdl-compose)
  824. (defcustom vhdl-file-header "\
  825. -------------------------------------------------------------------------------
  826. -- Title : <title string>
  827. -- Project : <project>
  828. -------------------------------------------------------------------------------
  829. -- File : <filename>
  830. -- Author : <author>
  831. -- Company : <company>
  832. -- Created : <date>
  833. -- Last update: <date>
  834. -- Platform : <platform>
  835. -- Standard : <standard>
  836. <projectdesc>-------------------------------------------------------------------------------
  837. -- Description: <cursor>
  838. <copyright>-------------------------------------------------------------------------------
  839. -- Revisions :
  840. -- Date Version Author Description
  841. -- <date> 1.0 <login>\tCreated
  842. -------------------------------------------------------------------------------
  843. "
  844. "String or file to insert as file header.
  845. If the string specifies an existing file name, the contents of the file is
  846. inserted, otherwise the string itself is inserted as file header.
  847. Type `C-j' for newlines.
  848. If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
  849. if the header needs to be version controlled.
  850. The following keywords for template generation are supported:
  851. <filename> : replaced by the name of the buffer
  852. <author> : replaced by the user name and email address
  853. \(`user-full-name',`mail-host-address', `user-mail-address')
  854. <authorfull> : replaced by the user full name (`user-full-name')
  855. <login> : replaced by user login name (`user-login-name')
  856. <company> : replaced by contents of option `vhdl-company-name'
  857. <date> : replaced by the current date
  858. <year> : replaced by the current year
  859. <project> : replaced by title of current project (`vhdl-project')
  860. <projectdesc> : replaced by description of current project (`vhdl-project')
  861. <copyright> : replaced by copyright string (`vhdl-copyright-string')
  862. <platform> : replaced by contents of option `vhdl-platform-spec'
  863. <standard> : replaced by the VHDL language standard(s) used
  864. <... string> : replaced by a queried string (\"...\" is the prompt word)
  865. <title string>: replaced by file title in automatically generated files
  866. <cursor> : final cursor position
  867. The (multi-line) project description <projectdesc> can be used as a project
  868. dependent part of the file header and can also contain the above keywords."
  869. :type 'string
  870. :group 'vhdl-header)
  871. (defcustom vhdl-file-footer ""
  872. "String or file to insert as file footer.
  873. If the string specifies an existing file name, the contents of the file is
  874. inserted, otherwise the string itself is inserted as file footer (i.e. at
  875. the end of the file).
  876. Type `C-j' for newlines.
  877. The same keywords as in option `vhdl-file-header' can be used."
  878. :type 'string
  879. :group 'vhdl-header)
  880. (defcustom vhdl-company-name ""
  881. "Name of company to insert in file header.
  882. See option `vhdl-file-header'."
  883. :type 'string
  884. :group 'vhdl-header)
  885. (defcustom vhdl-copyright-string "\
  886. -------------------------------------------------------------------------------
  887. -- Copyright (c) <year> <company>
  888. "
  889. "Copyright string to insert in file header.
  890. Can be multi-line string (type `C-j' for newline) and contain other file
  891. header keywords (see option `vhdl-file-header')."
  892. :type 'string
  893. :group 'vhdl-header)
  894. (defcustom vhdl-platform-spec ""
  895. "Specification of VHDL platform to insert in file header.
  896. The platform specification should contain names and versions of the
  897. simulation and synthesis tools used.
  898. See option `vhdl-file-header'."
  899. :type 'string
  900. :group 'vhdl-header)
  901. (defcustom vhdl-date-format "%Y-%m-%d"
  902. "Specifies the date format to use in the header.
  903. This string is passed as argument to the command `format-time-string'.
  904. For more information on format strings, see the documentation for the
  905. `format-time-string' command (C-h f `format-time-string')."
  906. :type 'string
  907. :group 'vhdl-header)
  908. (defcustom vhdl-modify-date-prefix-string "-- Last update: "
  909. "Prefix string of modification date in VHDL file header.
  910. If actualization of the modification date is called (menu,
  911. `\\[vhdl-template-modify]'), this string is searched and the rest
  912. of the line replaced by the current date."
  913. :type 'string
  914. :group 'vhdl-header)
  915. (defcustom vhdl-modify-date-on-saving t
  916. "Non-nil means update the modification date when the buffer is saved.
  917. Calls function `\\[vhdl-template-modify]').
  918. NOTE: Activate the new setting in a VHDL buffer by using the menu entry
  919. \"Activate Options\"."
  920. :type 'boolean
  921. :group 'vhdl-header)
  922. (defgroup vhdl-sequential-process nil
  923. "Customizations for sequential processes."
  924. :group 'vhdl-template)
  925. (defcustom vhdl-reset-kind 'async
  926. "Specifies which kind of reset to use in sequential processes."
  927. :type '(choice (const :tag "None" none)
  928. (const :tag "Synchronous" sync)
  929. (const :tag "Asynchronous" async)
  930. (const :tag "Query" query))
  931. :group 'vhdl-sequential-process)
  932. (defcustom vhdl-reset-active-high nil
  933. "Non-nil means reset in sequential processes is active high.
  934. Otherwise, reset is active low."
  935. :type 'boolean
  936. :group 'vhdl-sequential-process)
  937. (defcustom vhdl-clock-rising-edge t
  938. "Non-nil means rising edge of clock triggers sequential processes.
  939. Otherwise, falling edge triggers."
  940. :type 'boolean
  941. :group 'vhdl-sequential-process)
  942. (defcustom vhdl-clock-edge-condition 'standard
  943. "Syntax of the clock edge condition.
  944. Standard: \"clk'event and clk = '1'\"
  945. Function: \"rising_edge(clk)\""
  946. :type '(choice (const :tag "Standard" standard)
  947. (const :tag "Function" function))
  948. :group 'vhdl-sequential-process)
  949. (defcustom vhdl-clock-name ""
  950. "Name of clock signal to use in templates."
  951. :type 'string
  952. :group 'vhdl-sequential-process)
  953. (defcustom vhdl-reset-name ""
  954. "Name of reset signal to use in templates."
  955. :type 'string
  956. :group 'vhdl-sequential-process)
  957. (defgroup vhdl-model nil
  958. "Customizations for user models."
  959. :group 'vhdl)
  960. (defcustom vhdl-model-alist
  961. '(("Example Model"
  962. "<label> : process (<clock>, <reset>)
  963. begin -- process <label>
  964. if <reset> = '0' then -- asynchronous reset (active low)
  965. <cursor>
  966. elsif <clock>'event and <clock> = '1' then -- rising clock edge
  967. if <enable> = '1' then -- synchronous load
  968. end if;
  969. end if;
  970. end process <label>;"
  971. "e" ""))
  972. "List of user models.
  973. VHDL models (templates) can be specified by the user in this list. They can be
  974. invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
  975. electrification (i.e. overriding existing or creating new keywords, see
  976. option `vhdl-electric-keywords').
  977. Name : name of model (string of words and spaces)
  978. String : string or name of file to be inserted as model (newline: `C-j')
  979. Key Binding: key binding to invoke model, added to prefix `C-c C-m'
  980. (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
  981. Keyword : keyword to invoke model
  982. The models can contain prompts to be queried. A prompt is of the form \"<...>\".
  983. A prompt that appears several times is queried once and replaced throughout
  984. the model. Special prompts are:
  985. <clock> : name specified in `vhdl-clock-name' (if not empty)
  986. <reset> : name specified in `vhdl-reset-name' (if not empty)
  987. <cursor>: final cursor position
  988. File header prompts (see variable `vhdl-file-header') are automatically
  989. replaced, so that user models can also be used to insert different types of
  990. headers.
  991. If the string specifies an existing file name, the contents of the file is
  992. inserted, otherwise the string itself is inserted.
  993. The code within the models should be correctly indented.
  994. Type `C-j' for newlines.
  995. NOTE: Activate the new setting in a VHDL buffer by using the menu entry
  996. \"Activate Options\"."
  997. :type '(repeat (list :tag "Model" :indent 2
  998. (string :tag "Name ")
  999. (string :tag "String : (type `C-j' for newline)"
  1000. :format "%t\n%v")
  1001. (sexp :tag "Key binding" x)
  1002. (string :tag "Keyword " :format "%t: %v\n")))
  1003. :set (lambda (variable value)
  1004. (vhdl-custom-set variable value
  1005. 'vhdl-model-map-init
  1006. 'vhdl-model-defun
  1007. 'vhdl-mode-abbrev-table-init
  1008. 'vhdl-update-mode-menu))
  1009. :group 'vhdl-model)
  1010. (defgroup vhdl-compose nil
  1011. "Customizations for structural composition."
  1012. :group 'vhdl)
  1013. (defcustom vhdl-compose-architecture-name '(".*" . "str")
  1014. (concat
  1015. "Specifies how the component architecture name is obtained.
  1016. The component architecture name can be obtained by modifying the entity name
  1017. \(e.g. attaching or stripping off a substring).
  1018. If TO STRING is empty, the architecture name is queried."
  1019. vhdl-name-doc-string)
  1020. :type '(cons (regexp :tag "From regexp")
  1021. (string :tag "To string "))
  1022. :group 'vhdl-compose)
  1023. (defcustom vhdl-compose-configuration-name
  1024. '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
  1025. (concat
  1026. "Specifies how the configuration name is obtained.
  1027. The configuration name can be obtained by modifying the entity and/or
  1028. architecture name (e.g. attaching or stripping off a substring). The string
  1029. that is matched against the regexp is the concatenation of the entity and the
  1030. architecture name separated by a space. This gives access to both names (see
  1031. default setting as example)."
  1032. vhdl-name-doc-string)
  1033. :type '(cons (regexp :tag "From regexp")
  1034. (string :tag "To string "))
  1035. :group 'vhdl-compose)
  1036. (defcustom vhdl-components-package-name
  1037. '((".*" . "\\&_components") . "components")
  1038. (concat
  1039. "Specifies how the name for the components package is obtained.
  1040. The components package is a package containing all component declarations for
  1041. the current design. Its name can be obtained by modifying the project name
  1042. \(e.g. attaching or stripping off a substring). If no project is defined, the
  1043. DIRECTORY entry is chosen."
  1044. vhdl-name-doc-string)
  1045. :type '(cons (cons :tag "Project" :indent 2
  1046. (regexp :tag "From regexp")
  1047. (string :tag "To string "))
  1048. (string :tag "Directory:\n String "))
  1049. :group 'vhdl-compose)
  1050. (defcustom vhdl-use-components-package nil
  1051. "Non-nil means use a separate components package for component declarations.
  1052. Otherwise, component declarations are inserted and searched for in the
  1053. architecture declarative parts."
  1054. :type 'boolean
  1055. :group 'vhdl-compose)
  1056. (defcustom vhdl-compose-include-header t
  1057. "Non-nil means include a header in automatically generated files."
  1058. :type 'boolean
  1059. :group 'vhdl-compose)
  1060. (defcustom vhdl-compose-create-files 'single
  1061. "Specifies whether new files should be created for the new component.
  1062. The component's entity and architecture are inserted:
  1063. None : in current buffer
  1064. Single file : in new single file
  1065. Separate files: in two separate files
  1066. The file names are obtained from variables `vhdl-entity-file-name' and
  1067. `vhdl-architecture-file-name'."
  1068. :type '(choice (const :tag "None" none)
  1069. (const :tag "Single file" single)
  1070. (const :tag "Separate files" separate))
  1071. :group 'vhdl-compose)
  1072. (defcustom vhdl-compose-configuration-create-file nil
  1073. "Specifies whether a new file should be created for the configuration.
  1074. If non-nil, a new file is created for the configuration.
  1075. The file name is obtained from variable `vhdl-configuration-file-name'."
  1076. :type 'boolean
  1077. :group 'vhdl-compose)
  1078. (defcustom vhdl-compose-configuration-hierarchical t
  1079. "Specifies whether hierarchical configurations should be created.
  1080. If non-nil, automatically created configurations are hierarchical and include
  1081. the whole hierarchy of subcomponents. Otherwise the configuration only
  1082. includes one level of subcomponents."
  1083. :type 'boolean
  1084. :group 'vhdl-compose)
  1085. (defcustom vhdl-compose-configuration-use-subconfiguration t
  1086. "Specifies whether subconfigurations should be used inside configurations.
  1087. If non-nil, automatically created configurations use configurations in binding
  1088. indications for subcomponents, if such configurations exist. Otherwise,
  1089. entities are used in binding indications for subcomponents."
  1090. :type 'boolean
  1091. :group 'vhdl-compose)
  1092. (defgroup vhdl-port nil
  1093. "Customizations for port translation functions."
  1094. :group 'vhdl
  1095. :group 'vhdl-compose)
  1096. (defcustom vhdl-include-port-comments nil
  1097. "Non-nil means include port comments when a port is pasted."
  1098. :type 'boolean
  1099. :group 'vhdl-port)
  1100. (defcustom vhdl-include-direction-comments nil
  1101. "Non-nil means include port direction in instantiations as comments."
  1102. :type 'boolean
  1103. :group 'vhdl-port)
  1104. (defcustom vhdl-include-type-comments nil
  1105. "Non-nil means include generic/port type in instantiations as comments."
  1106. :type 'boolean
  1107. :group 'vhdl-port)
  1108. (defcustom vhdl-include-group-comments 'never
  1109. "Specifies whether to include group comments and spacings.
  1110. The comments and empty lines between groups of ports are pasted:
  1111. Never : never
  1112. Declarations: in entity/component/constant/signal declarations only
  1113. Always : also in generic/port maps"
  1114. :type '(choice (const :tag "Never" never)
  1115. (const :tag "Declarations" decl)
  1116. (const :tag "Always" always))
  1117. :group 'vhdl-port)
  1118. (defcustom vhdl-actual-port-name '(".*" . "\\&")
  1119. (concat
  1120. "Specifies how actual port names are obtained from formal port names.
  1121. In a component instantiation, an actual port name can be obtained by
  1122. modifying the formal port name (e.g. attaching or stripping off a substring)."
  1123. vhdl-name-doc-string)
  1124. :type '(cons (regexp :tag "From regexp")
  1125. (string :tag "To string "))
  1126. :group 'vhdl-port)
  1127. (defcustom vhdl-instance-name '(".*" . "\\&_%d")
  1128. (concat
  1129. "Specifies how an instance name is obtained.
  1130. The instance name can be obtained by modifying the name of the component to be
  1131. instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
  1132. by a unique number (starting with 1).
  1133. If TO STRING is empty, the instance name is queried."
  1134. vhdl-name-doc-string)
  1135. :type '(cons (regexp :tag "From regexp")
  1136. (string :tag "To string "))
  1137. :group 'vhdl-port)
  1138. (defgroup vhdl-testbench nil
  1139. "Customizations for testbench generation."
  1140. :group 'vhdl-port)
  1141. (defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
  1142. (concat
  1143. "Specifies how the testbench entity name is obtained.
  1144. The entity name of a testbench can be obtained by modifying the name of
  1145. the component to be tested (e.g. attaching or stripping off a substring)."
  1146. vhdl-name-doc-string)
  1147. :type '(cons (regexp :tag "From regexp")
  1148. (string :tag "To string "))
  1149. :group 'vhdl-testbench)
  1150. (defcustom vhdl-testbench-architecture-name '(".*" . "")
  1151. (concat
  1152. "Specifies how the testbench architecture name is obtained.
  1153. The testbench architecture name can be obtained by modifying the name of
  1154. the component to be tested (e.g. attaching or stripping off a substring).
  1155. If TO STRING is empty, the architecture name is queried."
  1156. vhdl-name-doc-string)
  1157. :type '(cons (regexp :tag "From regexp")
  1158. (string :tag "To string "))
  1159. :group 'vhdl-testbench)
  1160. (defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
  1161. (concat
  1162. "Specifies how the testbench configuration name is obtained.
  1163. The configuration name of a testbench can be obtained by modifying the entity
  1164. and/or architecture name (e.g. attaching or stripping off a substring). The
  1165. string that is matched against the regexp is the concatenation of the entity
  1166. and the architecture name separated by a space. This gives access to both
  1167. names (see default setting as example)."
  1168. vhdl-name-doc-string)
  1169. :type '(cons (regexp :tag "From regexp")
  1170. (string :tag "To string "))
  1171. :group 'vhdl-testbench)
  1172. (defcustom vhdl-testbench-dut-name '(".*" . "DUT")
  1173. (concat
  1174. "Specifies how a DUT instance name is obtained.
  1175. The design-under-test instance name (i.e. the component instantiated in the
  1176. testbench) can be obtained by modifying the component name (e.g. attaching
  1177. or stripping off a substring)."
  1178. vhdl-name-doc-string)
  1179. :type '(cons (regexp :tag "From regexp")
  1180. (string :tag "To string "))
  1181. :group 'vhdl-testbench)
  1182. (defcustom vhdl-testbench-include-header t
  1183. "Non-nil means include a header in automatically generated files."
  1184. :type 'boolean
  1185. :group 'vhdl-testbench)
  1186. (defcustom vhdl-testbench-declarations "\
  1187. -- clock
  1188. signal Clk : std_logic := '1';
  1189. "
  1190. "String or file to be inserted in the testbench declarative part.
  1191. If the string specifies an existing file name, the contents of the file is
  1192. inserted, otherwise the string itself is inserted in the testbench
  1193. architecture before the BEGIN keyword.
  1194. Type `C-j' for newlines."
  1195. :type 'string
  1196. :group 'vhdl-testbench)
  1197. (defcustom vhdl-testbench-statements "\
  1198. -- clock generation
  1199. Clk <= not Clk after 10 ns;
  1200. -- waveform generation
  1201. WaveGen_Proc: process
  1202. begin
  1203. -- insert signal assignments here
  1204. wait until Clk = '1';
  1205. end process WaveGen_Proc;
  1206. "
  1207. "String or file to be inserted in the testbench statement part.
  1208. If the string specifies an existing file name, the contents of the file is
  1209. inserted, otherwise the string itself is inserted in the testbench
  1210. architecture before the END keyword.
  1211. Type `C-j' for newlines."
  1212. :type 'string
  1213. :group 'vhdl-testbench)
  1214. (defcustom vhdl-testbench-initialize-signals nil
  1215. "Non-nil means initialize signals with `0' when declared in testbench."
  1216. :type 'boolean
  1217. :group 'vhdl-testbench)
  1218. (defcustom vhdl-testbench-include-library t
  1219. "Non-nil means a library/use clause for std_logic_1164 is included."
  1220. :type 'boolean
  1221. :group 'vhdl-testbench)
  1222. (defcustom vhdl-testbench-include-configuration t
  1223. "Non-nil means a testbench configuration is attached at the end."
  1224. :type 'boolean
  1225. :group 'vhdl-testbench)
  1226. (defcustom vhdl-testbench-create-files 'single
  1227. "Specifies whether new files should be created for the testbench.
  1228. testbench entity and architecture are inserted:
  1229. None : in current buffer
  1230. Single file : in new single file
  1231. Separate files: in two separate files
  1232. The file names are obtained from variables `vhdl-testbench-entity-file-name'
  1233. and `vhdl-testbench-architecture-file-name'."
  1234. :type '(choice (const :tag "None" none)
  1235. (const :tag "Single file" single)
  1236. (const :tag "Separate files" separate))
  1237. :group 'vhdl-testbench)
  1238. (defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
  1239. (concat
  1240. "Specifies how the testbench entity file name is obtained.
  1241. The entity file name can be obtained by modifying the testbench entity name
  1242. \(e.g. attaching or stripping off a substring). The file extension is
  1243. automatically taken from the file name of the current buffer. Testbench
  1244. files can be created in a different directory by prepending a relative or
  1245. absolute path to the file name."
  1246. vhdl-name-doc-string)
  1247. :type '(cons (regexp :tag "From regexp")
  1248. (string :tag "To string "))
  1249. :group 'vhdl-testbench)
  1250. (defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
  1251. (concat
  1252. "Specifies how the testbench architecture file name is obtained.
  1253. The architecture file name can be obtained by modifying the testbench entity
  1254. and/or architecture name (e.g. attaching or stripping off a substring). The
  1255. string that is matched against the regexp is the concatenation of the entity
  1256. and the architecture name separated by a space. This gives access to both
  1257. names (see default setting as example). Testbench files can be created in
  1258. a different directory by prepending a relative or absolute path to the file
  1259. name."
  1260. vhdl-name-doc-string)
  1261. :type '(cons (regexp :tag "From regexp")
  1262. (string :tag "To string "))
  1263. :group 'vhdl-testbench)
  1264. (defgroup vhdl-comment nil
  1265. "Customizations for comments."
  1266. :group 'vhdl)
  1267. (defcustom vhdl-self-insert-comments t
  1268. "Non-nil means various templates automatically insert help comments."
  1269. :type 'boolean
  1270. :group 'vhdl-comment)
  1271. (defcustom vhdl-prompt-for-comments t
  1272. "Non-nil means various templates prompt for user definable comments."
  1273. :type 'boolean
  1274. :group 'vhdl-comment)
  1275. (defcustom vhdl-inline-comment-column 40
  1276. "Column to indent and align inline comments to.
  1277. Overrides local option `comment-column'.
  1278. NOTE: Activate the new setting in a VHDL buffer by using the menu entry
  1279. \"Activate Options\"."
  1280. :type 'integer
  1281. :group 'vhdl-comment)
  1282. (defcustom vhdl-end-comment-column 79
  1283. "End of comment column.
  1284. Comments that exceed this column number are wrapped.
  1285. NOTE: Activate the new setting in a VHDL buffer by using the menu entry
  1286. \"Activate Options\"."
  1287. :type 'integer
  1288. :group 'vhdl-comment)
  1289. (defvar end-comment-column)
  1290. (defgroup vhdl-align nil
  1291. "Customizations for alignment."
  1292. :group 'vhdl)
  1293. (defcustom vhdl-auto-align t
  1294. "Non-nil means align some templates automatically after generation."
  1295. :type 'boolean
  1296. :group 'vhdl-align)
  1297. (defcustom vhdl-align-groups t
  1298. "Non-nil means align groups of code lines separately.
  1299. A group of code lines is a region of consecutive lines between two lines that
  1300. match the regexp in option `vhdl-align-group-separate'."
  1301. :type 'boolean
  1302. :group 'vhdl-align)
  1303. (defcustom vhdl-align-group-separate "^\\s-*$"
  1304. "Regexp for matching a line that separates groups of lines for alignment.
  1305. Examples:
  1306. \"^\\s-*$\": matches an empty line
  1307. \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
  1308. :type 'regexp
  1309. :group 'vhdl-align)
  1310. (defcustom vhdl-align-same-indent t
  1311. "Non-nil means align blocks with same indent separately.
  1312. When a region or the entire buffer is aligned, the code is divided into
  1313. blocks of same indent which are aligned separately (except for argument/port
  1314. lists). This gives nicer alignment in most cases.
  1315. Option `vhdl-align-groups' still applies within these blocks."
  1316. :type 'boolean
  1317. :group 'vhdl-align)
  1318. (defgroup vhdl-highlight nil
  1319. "Customizations for highlighting."
  1320. :group 'vhdl)
  1321. (defcustom vhdl-highlight-keywords t
  1322. "Non-nil means highlight VHDL keywords and other standardized words.
  1323. The following faces are used:
  1324. `font-lock-keyword-face' : keywords
  1325. `font-lock-type-face' : standardized types
  1326. `vhdl-font-lock-attribute-face': standardized attributes
  1327. `vhdl-font-lock-enumvalue-face': standardized enumeration values
  1328. `vhdl-font-lock-function-face' : standardized function and package names
  1329. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1330. entry \"Fontify Buffer\")."
  1331. :type 'boolean
  1332. :set (lambda (variable value)
  1333. (vhdl-custom-set variable value 'vhdl-font-lock-init))
  1334. :group 'vhdl-highlight)
  1335. (defcustom vhdl-highlight-names t
  1336. "Non-nil means highlight declaration names and construct labels.
  1337. The following faces are used:
  1338. `font-lock-function-name-face' : names in declarations of units,
  1339. subprograms, components, as well as labels of VHDL constructs
  1340. `font-lock-type-face' : names in type/nature declarations
  1341. `vhdl-font-lock-attribute-face': names in attribute declarations
  1342. `font-lock-variable-name-face' : names in declarations of signals,
  1343. variables, constants, subprogram parameters, generics, and ports
  1344. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1345. entry \"Fontify Buffer\")."
  1346. :type 'boolean
  1347. :set (lambda (variable value)
  1348. (vhdl-custom-set variable value 'vhdl-font-lock-init))
  1349. :group 'vhdl-highlight)
  1350. (defcustom vhdl-highlight-special-words nil
  1351. "Non-nil means highlight words with special syntax.
  1352. The words with syntax and color specified in option `vhdl-special-syntax-alist'
  1353. are highlighted accordingly.
  1354. Can be used for visual support of naming conventions.
  1355. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1356. entry \"Fontify Buffer\")."
  1357. :type 'boolean
  1358. :set (lambda (variable value)
  1359. (vhdl-custom-set variable value 'vhdl-font-lock-init))
  1360. :group 'vhdl-highlight)
  1361. (defcustom vhdl-highlight-forbidden-words nil
  1362. "Non-nil means highlight forbidden words.
  1363. The reserved words specified in option `vhdl-forbidden-words' or having the
  1364. syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
  1365. warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
  1366. use them.
  1367. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1368. entry \"Fontify Buffer\")."
  1369. :type 'boolean
  1370. :set (lambda (variable value)
  1371. (vhdl-custom-set variable value
  1372. 'vhdl-words-init 'vhdl-font-lock-init))
  1373. :group 'vhdl-highlight)
  1374. (defcustom vhdl-highlight-verilog-keywords nil
  1375. "Non-nil means highlight Verilog keywords as reserved words.
  1376. Verilog keywords are highlighted in a warning color (face
  1377. `vhdl-font-lock-reserved-words-face') to indicate not to use them.
  1378. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1379. entry \"Fontify Buffer\")."
  1380. :type 'boolean
  1381. :set (lambda (variable value)
  1382. (vhdl-custom-set variable value
  1383. 'vhdl-words-init 'vhdl-font-lock-init))
  1384. :group 'vhdl-highlight)
  1385. (defcustom vhdl-highlight-translate-off nil
  1386. "Non-nil means background-highlight code excluded from translation.
  1387. That is, all code between \"-- pragma translate_off\" and
  1388. \"-- pragma translate_on\" is highlighted using a different background color
  1389. \(face `vhdl-font-lock-translate-off-face').
  1390. Note: this might slow down on-the-fly fontification (and thus editing).
  1391. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1392. entry \"Fontify Buffer\")."
  1393. :type 'boolean
  1394. :set (lambda (variable value)
  1395. (vhdl-custom-set variable value 'vhdl-font-lock-init))
  1396. :group 'vhdl-highlight)
  1397. (defcustom vhdl-highlight-case-sensitive nil
  1398. "Non-nil means consider case for highlighting.
  1399. Possible trade-off:
  1400. non-nil also upper-case VHDL words are highlighted, but case of words with
  1401. special syntax is not considered
  1402. nil only lower-case VHDL words are highlighted, but case of words with
  1403. special syntax is considered
  1404. Overrides local option `font-lock-keywords-case-fold-search'.
  1405. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1406. entry \"Fontify Buffer\")."
  1407. :type 'boolean
  1408. :group 'vhdl-highlight)
  1409. (defcustom vhdl-special-syntax-alist
  1410. '(("generic/constant" "\\<\\w+_[cg]\\>" "Gold3" "BurlyWood1" nil)
  1411. ("type" "\\<\\w+_t\\>" "ForestGreen" "PaleGreen" nil)
  1412. ("variable" "\\<\\w+_v\\>" "Grey50" "Grey80" nil))
  1413. "List of special syntax to be highlighted.
  1414. If option `vhdl-highlight-special-words' is non-nil, words with the specified
  1415. syntax (as regular expression) are highlighted in the corresponding color.
  1416. Name : string of words and spaces
  1417. Regexp : regular expression describing word syntax
  1418. (e.g. \"\\\\=\<\\\w+_c\\\\=\>\" matches word with suffix \"_c\")
  1419. expression must start with \"\\\\=\<\" and end with \"\\\\=\>\"
  1420. if only whole words should be matched (no substrings)
  1421. Color (light): foreground color for light background
  1422. (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
  1423. LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
  1424. Color (dark) : foreground color for dark background
  1425. (matching color examples: BurlyWood1, Grey80, Green, Coral,
  1426. AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
  1427. In comments : If non-nil, words are also highlighted inside comments
  1428. Can be used for visual support of naming conventions, such as highlighting
  1429. different kinds of signals (e.g. \"Clk50\", \"Rst_n\") or objects (e.g.
  1430. \"Signal_s\", \"Variable_v\", \"Constant_c\") by distinguishing them using
  1431. common substrings or name suffices.
  1432. For each entry, a new face is generated with the specified colors and name
  1433. \"vhdl-font-lock-\" + name + \"-face\".
  1434. NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
  1435. entry \"Fontify Buffer\"). All other changes require restarting Emacs."
  1436. :type '(repeat (list :tag "Face" :indent 2
  1437. (string :tag "Name ")
  1438. (regexp :tag "Regexp " "\\w+_")
  1439. (string :tag "Color (light)")
  1440. (string :tag "Color (dark) ")
  1441. (boolean :tag "In comments ")))
  1442. :set (lambda (variable value)
  1443. (vhdl-custom-set variable value 'vhdl-font-lock-init))
  1444. :group 'vhdl-highlight)
  1445. (defcustom vhdl-forbidden-words '()
  1446. "List of forbidden words to be highlighted.
  1447. If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
  1448. words are highlighted in a warning color to indicate not to use them.
  1449. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1450. entry \"Fontify Buffer\")."
  1451. :type '(repeat (string :format "%v"))
  1452. :set (lambda (variable value)
  1453. (vhdl-custom-set variable value
  1454. 'vhdl-words-init 'vhdl-font-lock-init))
  1455. :group 'vhdl-highlight)
  1456. (defcustom vhdl-forbidden-syntax ""
  1457. "Syntax of forbidden words to be highlighted.
  1458. If option `vhdl-highlight-forbidden-words' is non-nil, words with this
  1459. syntax are highlighted in a warning color to indicate not to use them.
  1460. Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
  1461. highlights identifiers with 10 or more characters).
  1462. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1463. entry \"Fontify Buffer\")."
  1464. :type 'regexp
  1465. :set (lambda (variable value)
  1466. (vhdl-custom-set variable value
  1467. 'vhdl-words-init 'vhdl-font-lock-init))
  1468. :group 'vhdl-highlight)
  1469. (defcustom vhdl-directive-keywords '("pragma" "synopsys")
  1470. "List of compiler directive keywords recognized for highlighting.
  1471. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1472. entry \"Fontify Buffer\")."
  1473. :type '(repeat (string :format "%v"))
  1474. :set (lambda (variable value)
  1475. (vhdl-custom-set variable value
  1476. 'vhdl-words-init 'vhdl-font-lock-init))
  1477. :group 'vhdl-highlight)
  1478. (defgroup vhdl-speedbar nil
  1479. "Customizations for speedbar."
  1480. :group 'vhdl)
  1481. (defcustom vhdl-speedbar-auto-open nil
  1482. "Non-nil means automatically open speedbar at startup.
  1483. Alternatively, the speedbar can be opened from the VHDL menu."
  1484. :type 'boolean
  1485. :group 'vhdl-speedbar)
  1486. (defcustom vhdl-speedbar-display-mode 'files
  1487. "Specifies the default displaying mode when opening speedbar.
  1488. Alternatively, the displaying mode can be selected from the speedbar menu or
  1489. by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
  1490. :type '(choice (const :tag "Files" files)
  1491. (const :tag "Directory hierarchy" directory)
  1492. (const :tag "Project hierarchy" project))
  1493. :group 'vhdl-speedbar)
  1494. (defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
  1495. "Limits scanning of large files and netlists.
  1496. Design units: maximum file size to scan for design units
  1497. Hierarchy (instances of subcomponents):
  1498. File size: maximum file size to scan for instances (in bytes)
  1499. Instances per arch: maximum number of instances to scan per architecture
  1500. \"None\" always means that there is no limit.
  1501. In case of files not or incompletely scanned, a warning message and the file
  1502. names are printed out.
  1503. Background: scanning for instances is considerably slower than scanning for
  1504. design units, especially when there are many instances. These limits should
  1505. prevent the scanning of large netlists."
  1506. :type '(list (choice :tag "Design units"
  1507. :format "%t : %[Value Menu%] %v"
  1508. (const :tag "None" nil)
  1509. (integer :tag "File size"))
  1510. (list :tag "Hierarchy" :indent 2
  1511. (choice :tag "File size"
  1512. :format "%t : %[Value Menu%] %v"
  1513. (const :tag "None" nil)
  1514. (integer :tag "Size "))
  1515. (choice :tag "Instances per arch"
  1516. (const :tag "None" nil)
  1517. (integer :tag "Number "))))
  1518. :group 'vhdl-speedbar)
  1519. (defcustom vhdl-speedbar-jump-to-unit t
  1520. "Non-nil means jump to the design unit code when opened in a buffer.
  1521. The buffer cursor position is left unchanged otherwise."
  1522. :type 'boolean
  1523. :group 'vhdl-speedbar)
  1524. (defcustom vhdl-speedbar-update-on-saving t
  1525. "Automatically update design hierarchy when buffer is saved."
  1526. :type 'boolean
  1527. :group 'vhdl-speedbar)
  1528. (defcustom vhdl-speedbar-save-cache '(hierarchy display)
  1529. "Automatically save modified hierarchy caches when exiting Emacs.
  1530. Hierarchy: design hierarchy information
  1531. Display: displaying information (which design units to expand)"
  1532. :type '(set (const :tag "Hierarchy" hierarchy)
  1533. (const :tag "Display" display))
  1534. :group 'vhdl-speedbar)
  1535. (defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
  1536. "Name of file for saving hierarchy cache.
  1537. \"\\1\" is replaced by the project name if a project is specified,
  1538. \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
  1539. different users to have cache files in the same directory). Can also have
  1540. an absolute path (i.e. all caches can be stored in one global directory)."
  1541. :type 'string
  1542. :group 'vhdl-speedbar)
  1543. (defgroup vhdl-menu nil
  1544. "Customizations for menus."
  1545. :group 'vhdl)
  1546. (defcustom vhdl-index-menu nil
  1547. "Non-nil means add an index menu for a source file when loading.
  1548. Alternatively, the speedbar can be used. Note that the index menu scans a file
  1549. when it is opened, while speedbar only scans the file upon request."
  1550. :type 'boolean
  1551. :group 'vhdl-menu)
  1552. (defcustom vhdl-source-file-menu nil
  1553. "Non-nil means add a menu of all source files in current directory.
  1554. Alternatively, the speedbar can be used."
  1555. :type 'boolean
  1556. :group 'vhdl-menu)
  1557. (defcustom vhdl-hideshow-menu nil
  1558. "Non-nil means add hideshow menu and functionality at startup.
  1559. Hideshow can also be enabled from the VHDL Mode menu.
  1560. Hideshow allows hiding code of various VHDL constructs.
  1561. NOTE: Activate the new setting in a VHDL buffer by using the menu entry
  1562. \"Activate Options\"."
  1563. :type 'boolean
  1564. :group 'vhdl-menu)
  1565. (defcustom vhdl-hide-all-init nil
  1566. "Non-nil means hide all design units initially after a file is loaded."
  1567. :type 'boolean
  1568. :group 'vhdl-menu)
  1569. (defgroup vhdl-print nil
  1570. "Customizations for printing."
  1571. :group 'vhdl)
  1572. (defcustom vhdl-print-two-column t
  1573. "Non-nil means print code in two columns and landscape format.
  1574. Adjusts settings in a way that PostScript printing (\"File\" menu, `ps-print')
  1575. prints VHDL files in a nice two-column landscape style.
  1576. NOTE: Activate the new setting by restarting Emacs.
  1577. Overrides `ps-print' settings locally."
  1578. :type 'boolean
  1579. :group 'vhdl-print)
  1580. (defcustom vhdl-print-customize-faces t
  1581. "Non-nil means use an optimized set of faces for PostScript printing.
  1582. NOTE: Activate the new setting by restarting Emacs.
  1583. Overrides `ps-print' settings locally."
  1584. :type 'boolean
  1585. :group 'vhdl-print)
  1586. (defgroup vhdl-misc nil
  1587. "Miscellaneous customizations."
  1588. :group 'vhdl)
  1589. (defcustom vhdl-intelligent-tab t
  1590. "Non-nil means `TAB' does indentation, word completion and tab insertion.
  1591. That is, if preceding character is part of a word then complete word,
  1592. else if not at beginning of line then insert tab,
  1593. else if last command was a `TAB' or `RET' then dedent one step,
  1594. else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
  1595. If nil, TAB always indents current line (i.e. `TAB' is bound to
  1596. `indent-according-to-mode').
  1597. NOTE: Activate the new setting in a VHDL buffer by using the menu entry
  1598. \"Activate Options\"."
  1599. :type 'boolean
  1600. :group 'vhdl-misc)
  1601. (defcustom vhdl-indent-syntax-based t
  1602. "Non-nil means indent lines of code based on their syntactic context.
  1603. Otherwise, a line is indented like the previous nonblank line. This can be
  1604. useful in large files where syntax-based indentation gets very slow."
  1605. :type 'boolean
  1606. :group 'vhdl-misc)
  1607. (defcustom vhdl-indent-comment-like-next-code-line t
  1608. "*Non-nil means comment lines are indented like the following code line.
  1609. Otherwise, comment lines are indented like the preceding code line.
  1610. Indenting comment lines like the following code line gives nicer indentation
  1611. when comments precede the code that they refer to."
  1612. :type 'boolean
  1613. :group 'vhdl-misc)
  1614. (defcustom vhdl-word-completion-case-sensitive nil
  1615. "Non-nil means word completion using `TAB' is case sensitive.
  1616. That is, `TAB' completes words that start with the same letters and case.
  1617. Otherwise, case is ignored."
  1618. :type 'boolean
  1619. :group 'vhdl-misc)
  1620. (defcustom vhdl-word-completion-in-minibuffer t
  1621. "Non-nil enables word completion in minibuffer (for template prompts).
  1622. NOTE: Activate the new setting by restarting Emacs."
  1623. :type 'boolean
  1624. :group 'vhdl-misc)
  1625. (defcustom vhdl-underscore-is-part-of-word nil
  1626. "Non-nil means consider the underscore character `_' as part of word.
  1627. An identifier containing underscores is then treated as a single word in
  1628. select and move operations. All parts of an identifier separated by underscore
  1629. are treated as single words otherwise.
  1630. NOTE: Activate the new setting in a VHDL buffer by using the menu entry
  1631. \"Activate Options\"."
  1632. :type 'boolean
  1633. :set (lambda (variable value)
  1634. (vhdl-custom-set variable value 'vhdl-mode-syntax-table-init))
  1635. :group 'vhdl-misc)
  1636. (defgroup vhdl-related nil
  1637. "Related general customizations."
  1638. :group 'vhdl)
  1639. ;; add related general customizations
  1640. (custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
  1641. (if (featurep 'xemacs)
  1642. (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
  1643. (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
  1644. (custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
  1645. (custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
  1646. (custom-add-to-group 'vhdl-related 'comment-style 'custom-variable)
  1647. (custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
  1648. (unless (featurep 'xemacs)
  1649. (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
  1650. (custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
  1651. (custom-add-to-group 'vhdl-related 'mail-host-address 'custom-variable)
  1652. (custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
  1653. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1654. ;; Hidden user variables
  1655. (defvar vhdl-compile-absolute-path nil
  1656. "If non-nil, use absolute instead of relative path for compiled files.")
  1657. (defvar vhdl-comment-display-line-char ?-
  1658. "Character to use in comment display line.")
  1659. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1660. ;; Internal variables
  1661. (defvar vhdl-menu-max-size 20
  1662. "Specifies the maximum size of a menu before splitting it into submenus.")
  1663. (defvar vhdl-progress-interval 1
  1664. "Interval used to update progress status during long operations.
  1665. If a number, percentage complete gets updated after each interval of
  1666. that many seconds. To inhibit all messages, set this option to nil.")
  1667. (defvar vhdl-inhibit-startup-warnings-p nil
  1668. "If non-nil, inhibits start up compatibility warnings.")
  1669. (defvar vhdl-strict-syntax-p nil
  1670. "If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
  1671. If the syntactic symbol for a particular line does not match a symbol
  1672. in the offsets alist, an error is generated, otherwise no error is
  1673. reported and the syntactic symbol is ignored.")
  1674. (defvar vhdl-echo-syntactic-information-p nil
  1675. "If non-nil, syntactic info is echoed when the line is indented.")
  1676. (defconst vhdl-offsets-alist-default
  1677. '((string . -1000)
  1678. (cpp-macro . -1000)
  1679. (block-open . 0)
  1680. (block-close . 0)
  1681. (statement . 0)
  1682. (statement-cont . vhdl-lineup-statement-cont)
  1683. (statement-block-intro . +)
  1684. (statement-case-intro . +)
  1685. (case-alternative . +)
  1686. (comment . vhdl-lineup-comment)
  1687. (arglist-intro . +)
  1688. (arglist-cont . 0)
  1689. (arglist-cont-nonempty . vhdl-lineup-arglist)
  1690. (arglist-close . vhdl-lineup-arglist)
  1691. (entity . 0)
  1692. (configuration . 0)
  1693. (package . 0)
  1694. (architecture . 0)
  1695. (package-body . 0)
  1696. )
  1697. "Default settings for offsets of syntactic elements.
  1698. Do not change this constant! See the variable `vhdl-offsets-alist' for
  1699. more information.")
  1700. (defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
  1701. "Association list of syntactic element symbols and indentation offsets.
  1702. As described below, each cons cell in this list has the form:
  1703. (SYNTACTIC-SYMBOL . OFFSET)
  1704. When a line is indented, `vhdl-mode' first determines the syntactic
  1705. context of the line by generating a list of symbols called syntactic
  1706. elements. This list can contain more than one syntactic element and
  1707. the global variable `vhdl-syntactic-context' contains the context list
  1708. for the line being indented. Each element in this list is actually a
  1709. cons cell of the syntactic symbol and a buffer position. This buffer
  1710. position is call the relative indent point for the line. Some
  1711. syntactic symbols may not have a relative indent point associated with
  1712. them.
  1713. After the syntactic context list for a line is generated, `vhdl-mode'
  1714. calculates the absolute indentation for the line by looking at each
  1715. syntactic element in the list. First, it compares the syntactic
  1716. element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
  1717. finds a match, it adds the OFFSET to the column of the relative indent
  1718. point. The sum of this calculation for each element in the syntactic
  1719. list is the absolute offset for line being indented.
  1720. If the syntactic element does not match any in the `vhdl-offsets-alist',
  1721. an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
  1722. the element is ignored.
  1723. Actually, OFFSET can be an integer, a function, a variable, or one of
  1724. the following symbols: `+', `-', `++', or `--'. These latter
  1725. designate positive or negative multiples of `vhdl-basic-offset',
  1726. respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
  1727. called with a single argument containing the cons of the syntactic
  1728. element symbol and the relative indent point. The function should
  1729. return an integer offset.
  1730. Here is the current list of valid syntactic element symbols:
  1731. string -- inside multi-line string
  1732. block-open -- statement block open
  1733. block-close -- statement block close
  1734. statement -- a VHDL statement
  1735. statement-cont -- a continuation of a VHDL statement
  1736. statement-block-intro -- the first line in a new statement block
  1737. statement-case-intro -- the first line in a case alternative block
  1738. case-alternative -- a case statement alternative clause
  1739. comment -- a line containing only a comment
  1740. arglist-intro -- the first line in an argument list
  1741. arglist-cont -- subsequent argument list lines when no
  1742. arguments follow on the same line as
  1743. the arglist opening paren
  1744. arglist-cont-nonempty -- subsequent argument list lines when at
  1745. least one argument follows on the same
  1746. line as the arglist opening paren
  1747. arglist-close -- the solo close paren of an argument list
  1748. entity -- inside an entity declaration
  1749. configuration -- inside a configuration declaration
  1750. package -- inside a package declaration
  1751. architecture -- inside an architecture body
  1752. package-body -- inside a package body")
  1753. (defvar vhdl-comment-only-line-offset 0
  1754. "Extra offset for line which contains only the start of a comment.
  1755. Can contain an integer or a cons cell of the form:
  1756. (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
  1757. Where NON-ANCHORED-OFFSET is the amount of offset given to
  1758. non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
  1759. the amount of offset to give column-zero anchored comment-only lines.
  1760. Just an integer as value is equivalent to (<val> . 0)")
  1761. (defvar vhdl-special-indent-hook nil
  1762. "Hook for user defined special indentation adjustments.
  1763. This hook gets called after a line is indented by the mode.")
  1764. (defvar vhdl-style-alist
  1765. '(("IEEE"
  1766. (vhdl-basic-offset . 4)
  1767. (vhdl-offsets-alist . ())))
  1768. "Styles of Indentation.
  1769. Elements of this alist are of the form:
  1770. (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
  1771. where STYLE-STRING is a short descriptive string used to select a
  1772. style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
  1773. value for that variable when using the selected style.
  1774. There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
  1775. case, the VALUE is a list containing elements of the form:
  1776. (SYNTACTIC-SYMBOL . VALUE)
  1777. as described in `vhdl-offsets-alist'. These are passed directly to
  1778. `vhdl-set-offset' so there is no need to set every syntactic symbol in
  1779. your style, only those that are different from the default.")
  1780. ;; dynamically append the default value of most variables
  1781. (or (assoc "Default" vhdl-style-alist)
  1782. (let* ((varlist '(vhdl-inhibit-startup-warnings-p
  1783. vhdl-strict-syntax-p
  1784. vhdl-echo-syntactic-information-p
  1785. vhdl-basic-offset
  1786. vhdl-offsets-alist
  1787. vhdl-comment-only-line-offset))
  1788. (default (cons "Default"
  1789. (mapcar
  1790. (function
  1791. (lambda (var)
  1792. (cons var (symbol-value var))))
  1793. varlist))))
  1794. (setq vhdl-style-alist (cons default vhdl-style-alist))))
  1795. (defvar vhdl-mode-hook nil
  1796. "Hook called by `vhdl-mode'.")
  1797. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1798. ;;; Required packages
  1799. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1800. ;; mandatory
  1801. (require 'assoc)
  1802. (require 'compile) ; XEmacs
  1803. (require 'easymenu)
  1804. (require 'hippie-exp)
  1805. ;; optional (minimize warning messages during compile)
  1806. (eval-when-compile
  1807. (require 'font-lock)
  1808. (require 'ps-print)
  1809. (require 'speedbar))
  1810. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1811. ;;; Compatibility
  1812. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1813. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1814. ;; XEmacs compatibility
  1815. ;; active regions
  1816. (defun vhdl-keep-region-active ()
  1817. "Do whatever is necessary to keep the region active in XEmacs.
  1818. Ignore byte-compiler warnings you might see."
  1819. (and (featurep 'xemacs)
  1820. (setq zmacs-region-stays t)))
  1821. ;; `wildcard-to-regexp' is included only in XEmacs 21
  1822. (unless (fboundp 'wildcard-to-regexp)
  1823. (defun wildcard-to-regexp (wildcard)
  1824. "Simplified version of `wildcard-to-regexp' from Emacs's `files.el'."
  1825. (let* ((i (string-match "[*?]" wildcard))
  1826. (result (substring wildcard 0 i))
  1827. (len (length wildcard)))
  1828. (when i
  1829. (while (< i len)
  1830. (let ((ch (aref wildcard i)))
  1831. (setq result (concat result
  1832. (cond ((eq ch ?*) "[^\000]*")
  1833. ((eq ch ??) "[^\000]")
  1834. (t (char-to-string ch)))))
  1835. (setq i (1+ i)))))
  1836. (concat "\\`" result "\\'"))))
  1837. ;; `regexp-opt' undefined (`xemacs-devel' not installed)
  1838. ;; `regexp-opt' accelerates fontification by 10-20%
  1839. (unless (fboundp 'regexp-opt)
  1840. ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
  1841. (defun regexp-opt (strings &optional paren)
  1842. (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
  1843. (concat open (mapconcat 'regexp-quote strings "\\|") close))))
  1844. ;; `match-string-no-properties' undefined (XEmacs, what else?)
  1845. (unless (fboundp 'match-string-no-properties)
  1846. (defalias 'match-string-no-properties 'match-string))
  1847. ;; `subst-char-in-string' undefined (XEmacs)
  1848. (unless (fboundp 'subst-char-in-string)
  1849. (defun subst-char-in-string (fromchar tochar string &optional inplace)
  1850. (let ((i (length string))
  1851. (newstr (if inplace string (copy-sequence string))))
  1852. (while (> i 0)
  1853. (setq i (1- i))
  1854. (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
  1855. newstr)))
  1856. ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
  1857. (when (and (featurep 'xemacs) (string< itimer-version "1.09")
  1858. (not noninteractive))
  1859. (load "itimer")
  1860. (when (string< itimer-version "1.09")
  1861. (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
  1862. (beep) (sit-for 5)))
  1863. ;; `file-expand-wildcards' undefined (XEmacs)
  1864. (unless (fboundp 'file-expand-wildcards)
  1865. (defun file-expand-wildcards (pattern &optional full)
  1866. "Taken from Emacs's `files.el'."
  1867. (let* ((nondir (file-name-nondirectory pattern))
  1868. (dirpart (file-name-directory pattern))
  1869. (dirs (if (and dirpart (string-match "[[*?]" dirpart))
  1870. (mapcar 'file-name-as-directory
  1871. (file-expand-wildcards (directory-file-name dirpart)))
  1872. (list dirpart)))
  1873. contents)
  1874. (while dirs
  1875. (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
  1876. (file-directory-p (directory-file-name (car dirs))))
  1877. (let ((this-dir-contents
  1878. (delq nil
  1879. (mapcar #'(lambda (name)
  1880. (unless (string-match "\\`\\.\\.?\\'"
  1881. (file-name-nondirectory name))
  1882. name))
  1883. (directory-files (or (car dirs) ".") full
  1884. (wildcard-to-regexp nondir))))))
  1885. (setq contents
  1886. (nconc
  1887. (if (and (car dirs) (not full))
  1888. (mapcar (function (lambda (name) (concat (car dirs) name)))
  1889. this-dir-contents)
  1890. this-dir-contents)
  1891. contents))))
  1892. (setq dirs (cdr dirs)))
  1893. contents)))
  1894. ;; `member-ignore-case' undefined (XEmacs)
  1895. (unless (fboundp 'member-ignore-case)
  1896. (defalias 'member-ignore-case 'member))
  1897. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1898. ;; Compatibility with older VHDL Mode versions
  1899. (defvar vhdl-warnings nil
  1900. "Warnings to tell the user during start up.")
  1901. (defun vhdl-run-when-idle (secs repeat function)
  1902. "Wait until idle, then run FUNCTION."
  1903. (if (fboundp 'start-itimer)
  1904. (start-itimer "vhdl-mode" function secs repeat t)
  1905. ; (run-with-idle-timer secs repeat function)))
  1906. ;; explicitly activate timer (necessary when Emacs is already idle)
  1907. (aset (run-with-idle-timer secs repeat function) 0 nil)))
  1908. (defun vhdl-warning-when-idle (&rest args)
  1909. "Wait until idle, then print out warning STRING and beep."
  1910. (if noninteractive
  1911. (vhdl-warning (apply 'format args) t)
  1912. (unless vhdl-warnings
  1913. (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
  1914. (setq vhdl-warnings (cons (apply 'format args) vhdl-warnings))))
  1915. (defun vhdl-warning (string &optional nobeep)
  1916. "Print out warning STRING and beep."
  1917. (message "WARNING: %s" string)
  1918. (unless (or nobeep noninteractive) (beep)))
  1919. (defun vhdl-print-warnings ()
  1920. "Print out messages in variable `vhdl-warnings'."
  1921. (let ((no-warnings (length vhdl-warnings)))
  1922. (setq vhdl-warnings (nreverse vhdl-warnings))
  1923. (while vhdl-warnings
  1924. (message "WARNING: %s" (car vhdl-warnings))
  1925. (setq vhdl-warnings (cdr vhdl-warnings)))
  1926. (beep)
  1927. (when (> no-warnings 1)
  1928. (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
  1929. ;; Backward compatibility checks and fixes
  1930. ;; option `vhdl-compiler' changed format
  1931. (unless (stringp vhdl-compiler)
  1932. (setq vhdl-compiler "ModelSim")
  1933. (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
  1934. ;; option `vhdl-standard' changed format
  1935. (unless (listp vhdl-standard)
  1936. (setq vhdl-standard '(87 nil))
  1937. (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
  1938. ;; option `vhdl-model-alist' changed format
  1939. (when (= (length (car vhdl-model-alist)) 3)
  1940. (let ((old-alist vhdl-model-alist)
  1941. new-alist)
  1942. (while old-alist
  1943. (setq new-alist (cons (append (car old-alist) '("")) new-alist))
  1944. (setq old-alist (cdr old-alist)))
  1945. (setq vhdl-model-alist (nreverse new-alist)))
  1946. (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
  1947. ;; option `vhdl-project-alist' changed format
  1948. (when (= (length (car vhdl-project-alist)) 3)
  1949. (let ((old-alist vhdl-project-alist)
  1950. new-alist)
  1951. (while old-alist
  1952. (setq new-alist (cons (append (car old-alist) '("")) new-alist))
  1953. (setq old-alist (cdr old-alist)))
  1954. (setq vhdl-project-alist (nreverse new-alist)))
  1955. (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
  1956. ;; option `vhdl-project-alist' changed format (3.31.1)
  1957. (when (= (length (car vhdl-project-alist)) 4)
  1958. (let ((old-alist vhdl-project-alist)
  1959. new-alist elem)
  1960. (while old-alist
  1961. (setq elem (car old-alist))
  1962. (setq new-alist
  1963. (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
  1964. nil "./" "work" "work/" "Makefile" (nth 3 elem))
  1965. new-alist))
  1966. (setq old-alist (cdr old-alist)))
  1967. (setq vhdl-project-alist (nreverse new-alist)))
  1968. (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
  1969. ;; option `vhdl-project-alist' changed format (3.31.12)
  1970. (when (= (length (car vhdl-project-alist)) 10)
  1971. (let ((tmp-alist vhdl-project-alist))
  1972. (while tmp-alist
  1973. (setcdr (nthcdr 3 (car tmp-alist))
  1974. (cons "" (nthcdr 4 (car tmp-alist))))
  1975. (setq tmp-alist (cdr tmp-alist))))
  1976. (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
  1977. ;; option `vhdl-compiler-alist' changed format (3.31.1)
  1978. (when (= (length (car vhdl-compiler-alist)) 7)
  1979. (let ((old-alist vhdl-compiler-alist)
  1980. new-alist elem)
  1981. (while old-alist
  1982. (setq elem (car old-alist))
  1983. (setq new-alist
  1984. (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
  1985. (if (equal (nth 3 elem) "") nil (nth 3 elem))
  1986. (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
  1987. (nth 5 elem) (nth 6 elem) nil)
  1988. new-alist))
  1989. (setq old-alist (cdr old-alist)))
  1990. (setq vhdl-compiler-alist (nreverse new-alist)))
  1991. (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
  1992. ;; option `vhdl-compiler-alist' changed format (3.31.10)
  1993. (when (= (length (car vhdl-compiler-alist)) 12)
  1994. (let ((tmp-alist vhdl-compiler-alist))
  1995. (while tmp-alist
  1996. (setcdr (nthcdr 4 (car tmp-alist))
  1997. (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
  1998. (setq tmp-alist (cdr tmp-alist))))
  1999. (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
  2000. ;; option `vhdl-compiler-alist' changed format (3.31.11)
  2001. (when (= (length (car vhdl-compiler-alist)) 13)
  2002. (let ((tmp-alist vhdl-compiler-alist))
  2003. (while tmp-alist
  2004. (setcdr (nthcdr 3 (car tmp-alist))
  2005. (cons "" (nthcdr 4 (car tmp-alist))))
  2006. (setq tmp-alist (cdr tmp-alist))))
  2007. (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
  2008. ;; option `vhdl-compiler-alist' changed format (3.32.7)
  2009. (when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
  2010. (let ((tmp-alist vhdl-compiler-alist))
  2011. (while tmp-alist
  2012. (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
  2013. '(0 . nil))
  2014. (setq tmp-alist (cdr tmp-alist))))
  2015. (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
  2016. ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
  2017. (when (equal vhdl-project "")
  2018. (setq vhdl-project nil)
  2019. (customize-save-variable 'vhdl-project vhdl-project))
  2020. ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
  2021. (when (stringp vhdl-project-file-name)
  2022. (setq vhdl-project-file-name (list vhdl-project-file-name))
  2023. (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
  2024. ;; option `speedbar-indentation-width': introduced in speedbar 0.10
  2025. (if (not (boundp 'speedbar-indentation-width))
  2026. (defvar speedbar-indentation-width 2)
  2027. ;; set default to 2 if not already customized
  2028. (unless (get 'speedbar-indentation-width 'saved-value)
  2029. (setq speedbar-indentation-width 2)))
  2030. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2031. ;;; Help functions / inline substitutions / macros
  2032. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2033. (defun vhdl-standard-p (standard)
  2034. "Check if STANDARD is specified as used standard."
  2035. (or (eq standard (car vhdl-standard))
  2036. (memq standard (cadr vhdl-standard))))
  2037. (defun vhdl-project-p (&optional warning)
  2038. "Return non-nil if a project is displayed, i.e. directories or files are
  2039. specified."
  2040. (if (assoc vhdl-project vhdl-project-alist)
  2041. vhdl-project
  2042. (when (and vhdl-project warning)
  2043. (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
  2044. nil))
  2045. (defun vhdl-resolve-env-variable (string)
  2046. "Resolve environment variables in STRING."
  2047. (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
  2048. (setq string (concat (match-string 1 string)
  2049. (getenv (match-string 2 string))
  2050. (match-string 4 string))))
  2051. string)
  2052. (defun vhdl-default-directory ()
  2053. "Return the default directory of the current project or the directory of the
  2054. current buffer if no project is defined."
  2055. (if (vhdl-project-p)
  2056. (expand-file-name (vhdl-resolve-env-variable
  2057. (nth 1 (aget vhdl-project-alist vhdl-project))))
  2058. default-directory))
  2059. (defmacro vhdl-prepare-search-1 (&rest body)
  2060. "Enable case insensitive search and switch to syntax table that includes '_',
  2061. then execute BODY, and finally restore the old environment. Used for
  2062. consistent searching."
  2063. `(let ((case-fold-search t)) ; case insensitive search
  2064. ;; use extended syntax table
  2065. (with-syntax-table vhdl-mode-ext-syntax-table
  2066. ,@body)))
  2067. (defmacro vhdl-prepare-search-2 (&rest body)
  2068. "Enable case insensitive search, switch to syntax table that includes '_',
  2069. and remove `intangible' overlays, then execute BODY, and finally restore the
  2070. old environment. Used for consistent searching."
  2071. ;; FIXME: Why not just let-bind `inhibit-point-motion-hooks'? --Stef
  2072. `(let ((case-fold-search t) ; case insensitive search
  2073. (current-syntax-table (syntax-table))
  2074. overlay-all-list overlay-intangible-list overlay)
  2075. ;; use extended syntax table
  2076. (set-syntax-table vhdl-mode-ext-syntax-table)
  2077. ;; remove `intangible' overlays
  2078. (when (fboundp 'overlay-lists)
  2079. (setq overlay-all-list (overlay-lists))
  2080. (setq overlay-all-list
  2081. (append (car overlay-all-list) (cdr overlay-all-list)))
  2082. (while overlay-all-list
  2083. (setq overlay (car overlay-all-list))
  2084. (when (memq 'intangible (overlay-properties overlay))
  2085. (setq overlay-intangible-list
  2086. (cons overlay overlay-intangible-list))
  2087. (overlay-put overlay 'intangible nil))
  2088. (setq overlay-all-list (cdr overlay-all-list))))
  2089. ;; execute BODY safely
  2090. (unwind-protect
  2091. (progn ,@body)
  2092. ;; restore syntax table
  2093. (set-syntax-table current-syntax-table)
  2094. ;; restore `intangible' overlays
  2095. (when (fboundp 'overlay-lists)
  2096. (while overlay-intangible-list
  2097. (overlay-put (car overlay-intangible-list) 'intangible t)
  2098. (setq overlay-intangible-list
  2099. (cdr overlay-intangible-list)))))))
  2100. (defmacro vhdl-visit-file (file-name issue-error &rest body)
  2101. "Visit file FILE-NAME and execute BODY."
  2102. `(if (null ,file-name)
  2103. (progn ,@body)
  2104. (unless (file-directory-p ,file-name)
  2105. (let ((source-buffer (current-buffer))
  2106. (visiting-buffer (find-buffer-visiting ,file-name))
  2107. file-opened)
  2108. (when (or (and visiting-buffer (set-buffer visiting-buffer))
  2109. (condition-case ()
  2110. (progn (set-buffer (create-file-buffer ,file-name))
  2111. (setq file-opened t)
  2112. (vhdl-insert-file-contents ,file-name)
  2113. (modify-syntax-entry ?\- ". 12" (syntax-table))
  2114. (modify-syntax-entry ?\n ">" (syntax-table))
  2115. (modify-syntax-entry ?\^M ">" (syntax-table))
  2116. (modify-syntax-entry ?_ "w" (syntax-table))
  2117. t)
  2118. (error
  2119. (if ,issue-error
  2120. (progn
  2121. (when file-opened (kill-buffer (current-buffer)))
  2122. (set-buffer source-buffer)
  2123. (error "ERROR: File cannot be opened: \"%s\"" ,file-name))
  2124. (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
  2125. nil))))
  2126. (condition-case info
  2127. (progn ,@body)
  2128. (error
  2129. (if ,issue-error
  2130. (progn
  2131. (when file-opened (kill-buffer (current-buffer)))
  2132. (set-buffer source-buffer)
  2133. (error (cadr info)))
  2134. (vhdl-warning (cadr info))))))
  2135. (when file-opened (kill-buffer (current-buffer)))
  2136. (set-buffer source-buffer)))))
  2137. (defun vhdl-insert-file-contents (filename)
  2138. "Nicked from `insert-file-contents-literally', but allow coding system
  2139. conversion."
  2140. (let ((format-alist nil)
  2141. (after-insert-file-functions nil)
  2142. (jka-compr-compression-info-list nil))
  2143. (insert-file-contents filename t)))
  2144. (defun vhdl-sort-alist (alist)
  2145. "Sort ALIST."
  2146. (sort alist (function (lambda (a b) (string< (car a) (car b))))))
  2147. (defun vhdl-get-subdirs (directory)
  2148. "Recursively get subdirectories of DIRECTORY."
  2149. (let ((dir-list (list (file-name-as-directory directory)))
  2150. file-list)
  2151. (setq file-list (vhdl-directory-files directory t "\\w.*"))
  2152. (while file-list
  2153. (when (file-directory-p (car file-list))
  2154. (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
  2155. (setq file-list (cdr file-list)))
  2156. dir-list))
  2157. (defun vhdl-aput (alist-symbol key &optional value)
  2158. "As `aput', but delete key-value pair if VALUE is nil."
  2159. (if value
  2160. (aput alist-symbol key value)
  2161. (adelete alist-symbol key)))
  2162. (defun vhdl-delete (elt list)
  2163. "Delete by side effect the first occurrence of ELT as a member of LIST."
  2164. (setq list (cons nil list))
  2165. (let ((list1 list))
  2166. (while (and (cdr list1) (not (equal elt (cadr list1))))
  2167. (setq list1 (cdr list1)))
  2168. (when list
  2169. (setcdr list1 (cddr list1))))
  2170. (cdr list))
  2171. (defun vhdl-speedbar-refresh (&optional key)
  2172. "Refresh directory or project with name KEY."
  2173. (when (and (boundp 'speedbar-frame)
  2174. (frame-live-p speedbar-frame))
  2175. (let ((pos (point))
  2176. (last-frame (selected-frame)))
  2177. (if (null key)
  2178. (speedbar-refresh)
  2179. (select-frame speedbar-frame)
  2180. (when (save-excursion
  2181. (goto-char (point-min))
  2182. (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
  2183. (goto-char (match-end 1))
  2184. (speedbar-do-function-pointer)
  2185. (backward-char 2)
  2186. (speedbar-do-function-pointer)
  2187. (message "Refreshing speedbar...done"))
  2188. (select-frame last-frame)))))
  2189. (defun vhdl-show-messages ()
  2190. "Get *Messages* buffer to show recent messages."
  2191. (interactive)
  2192. (display-buffer (if (featurep 'xemacs) " *Message-Log*" "*Messages*")))
  2193. (defun vhdl-use-direct-instantiation ()
  2194. "Return whether direct instantiation is used."
  2195. (or (eq vhdl-use-direct-instantiation 'always)
  2196. (and (eq vhdl-use-direct-instantiation 'standard)
  2197. (not (vhdl-standard-p '87)))))
  2198. (defun vhdl-max-marker (marker1 marker2)
  2199. "Return larger marker."
  2200. (if (> marker1 marker2) marker1 marker2))
  2201. (defun vhdl-goto-marker (marker)
  2202. "Goto marker in appropriate buffer."
  2203. (when (markerp marker)
  2204. (set-buffer (marker-buffer marker)))
  2205. (goto-char marker))
  2206. (defun vhdl-menu-split (list title)
  2207. "Split menu LIST into several submenus, if number of
  2208. elements > `vhdl-menu-max-size'."
  2209. (if (> (length list) vhdl-menu-max-size)
  2210. (let ((remain list)
  2211. (result '())
  2212. (sublist '())
  2213. (menuno 1)
  2214. (i 0))
  2215. (while remain
  2216. (setq sublist (cons (car remain) sublist))
  2217. (setq remain (cdr remain))
  2218. (setq i (+ i 1))
  2219. (if (= i vhdl-menu-max-size)
  2220. (progn
  2221. (setq result (cons (cons (format "%s %s" title menuno)
  2222. (nreverse sublist)) result))
  2223. (setq i 0)
  2224. (setq menuno (+ menuno 1))
  2225. (setq sublist '()))))
  2226. (and sublist
  2227. (setq result (cons (cons (format "%s %s" title menuno)
  2228. (nreverse sublist)) result)))
  2229. (nreverse result))
  2230. list))
  2231. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2232. ;;; Bindings
  2233. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2234. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2235. ;; Key bindings
  2236. (defvar vhdl-template-map nil
  2237. "Keymap for VHDL templates.")
  2238. (defun vhdl-template-map-init ()
  2239. "Initialize `vhdl-template-map'."
  2240. (setq vhdl-template-map (make-sparse-keymap))
  2241. ;; key bindings for VHDL templates
  2242. (define-key vhdl-template-map "al" 'vhdl-template-alias)
  2243. (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
  2244. (define-key vhdl-template-map "at" 'vhdl-template-assert)
  2245. (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
  2246. (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
  2247. (define-key vhdl-template-map "bl" 'vhdl-template-block)
  2248. (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
  2249. (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
  2250. (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
  2251. (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
  2252. (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
  2253. (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
  2254. (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
  2255. (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
  2256. (define-key vhdl-template-map "co" 'vhdl-template-constant)
  2257. (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
  2258. (define-key vhdl-template-map "el" 'vhdl-template-else)
  2259. (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
  2260. (define-key vhdl-template-map "en" 'vhdl-template-entity)
  2261. (define-key vhdl-template-map "ex" 'vhdl-template-exit)
  2262. (define-key vhdl-template-map "fi" 'vhdl-template-file)
  2263. (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
  2264. (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
  2265. (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
  2266. (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
  2267. (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
  2268. (define-key vhdl-template-map "ge" 'vhdl-template-generic)
  2269. (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
  2270. (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
  2271. (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
  2272. (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
  2273. (define-key vhdl-template-map "it" 'vhdl-template-if-then)
  2274. (define-key vhdl-template-map "li" 'vhdl-template-library)
  2275. (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
  2276. (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
  2277. (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
  2278. (define-key vhdl-template-map "ma" 'vhdl-template-map)
  2279. (define-key vhdl-template-map "ne" 'vhdl-template-next)
  2280. (define-key vhdl-template-map "ot" 'vhdl-template-others)
  2281. (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
  2282. (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
  2283. (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
  2284. (define-key vhdl-template-map "po" 'vhdl-template-port)
  2285. (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
  2286. (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
  2287. (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
  2288. (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
  2289. (define-key vhdl-template-map "rp" 'vhdl-template-report)
  2290. (define-key vhdl-template-map "rt" 'vhdl-template-return)
  2291. (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
  2292. (define-key vhdl-template-map "si" 'vhdl-template-signal)
  2293. (define-key vhdl-template-map "su" 'vhdl-template-subtype)
  2294. (define-key vhdl-template-map "ty" 'vhdl-template-type)
  2295. (define-key vhdl-template-map "us" 'vhdl-template-use)
  2296. (define-key vhdl-template-map "va" 'vhdl-template-variable)
  2297. (define-key vhdl-template-map "wa" 'vhdl-template-wait)
  2298. (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
  2299. (define-key vhdl-template-map "wi" 'vhdl-template-with)
  2300. (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
  2301. (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
  2302. (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
  2303. (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
  2304. (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
  2305. (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
  2306. (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
  2307. (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
  2308. (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
  2309. (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
  2310. (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
  2311. (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
  2312. (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
  2313. (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
  2314. (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
  2315. (when (vhdl-standard-p 'ams)
  2316. (define-key vhdl-template-map "br" 'vhdl-template-break)
  2317. (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
  2318. (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
  2319. (define-key vhdl-template-map "lm" 'vhdl-template-limit)
  2320. (define-key vhdl-template-map "na" 'vhdl-template-nature)
  2321. (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
  2322. (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
  2323. (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
  2324. (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
  2325. (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
  2326. (define-key vhdl-template-map "te" 'vhdl-template-terminal)
  2327. )
  2328. (when (vhdl-standard-p 'math)
  2329. (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
  2330. (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
  2331. ))
  2332. ;; initialize template map for VHDL Mode
  2333. (vhdl-template-map-init)
  2334. (defun vhdl-function-name (prefix string &optional postfix)
  2335. "Generate a Lisp function name.
  2336. PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
  2337. STRING are replaced by `-' and substrings are converted to lower case."
  2338. (let ((name prefix))
  2339. (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
  2340. (setq name
  2341. (concat name "-" (downcase (substring string 0 (match-end 1)))))
  2342. (setq string (substring string (match-beginning 2))))
  2343. (when postfix (setq name (concat name "-" postfix)))
  2344. (intern name)))
  2345. (defvar vhdl-model-map nil
  2346. "Keymap for VHDL models.")
  2347. (defun vhdl-model-map-init ()
  2348. "Initialize `vhdl-model-map'."
  2349. (setq vhdl-model-map (make-sparse-keymap))
  2350. ;; key bindings for VHDL models
  2351. (let ((model-alist vhdl-model-alist) model)
  2352. (while model-alist
  2353. (setq model (car model-alist))
  2354. (define-key vhdl-model-map (nth 2 model)
  2355. (vhdl-function-name "vhdl-model" (nth 0 model)))
  2356. (setq model-alist (cdr model-alist)))))
  2357. ;; initialize user model map for VHDL Mode
  2358. (vhdl-model-map-init)
  2359. (defvar vhdl-mode-map nil
  2360. "Keymap for VHDL Mode.")
  2361. (defun vhdl-mode-map-init ()
  2362. "Initialize `vhdl-mode-map'."
  2363. (setq vhdl-mode-map (make-sparse-keymap))
  2364. ;; template key bindings
  2365. (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
  2366. ;; model key bindings
  2367. (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
  2368. ;; standard key bindings
  2369. (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
  2370. (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
  2371. (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
  2372. (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
  2373. (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
  2374. (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
  2375. (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
  2376. (unless (featurep 'xemacs) ; would override `M-backspace' in XEmacs
  2377. (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
  2378. (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
  2379. (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
  2380. ;; backspace/delete key bindings
  2381. (define-key vhdl-mode-map [backspace] 'backward-delete-char-untabify)
  2382. (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
  2383. (define-key vhdl-mode-map [delete] 'delete-char)
  2384. (define-key vhdl-mode-map [(meta delete)] 'kill-word))
  2385. ;; mode specific key bindings
  2386. (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
  2387. (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
  2388. (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
  2389. (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
  2390. (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
  2391. (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
  2392. (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
  2393. (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
  2394. (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
  2395. (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
  2396. (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
  2397. (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
  2398. (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
  2399. (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
  2400. (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
  2401. (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
  2402. (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
  2403. (if (featurep 'xemacs) ; `... C-g' not allowed in XEmacs
  2404. (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
  2405. (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
  2406. (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
  2407. (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
  2408. (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
  2409. (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
  2410. (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
  2411. (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
  2412. (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
  2413. (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
  2414. (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
  2415. (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
  2416. (define-key vhdl-mode-map "\C-c\C-m\C-n" 'vhdl-compose-new-component)
  2417. (define-key vhdl-mode-map "\C-c\C-m\C-p" 'vhdl-compose-place-component)
  2418. (define-key vhdl-mode-map "\C-c\C-m\C-w" 'vhdl-compose-wire-components)
  2419. (define-key vhdl-mode-map "\C-c\C-m\C-f" 'vhdl-compose-configuration)
  2420. (define-key vhdl-mode-map "\C-c\C-m\C-k" 'vhdl-compose-components-package)
  2421. (define-key vhdl-mode-map "\C-c\C-c" 'vhdl-comment-uncomment-region)
  2422. (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
  2423. (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
  2424. (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
  2425. (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
  2426. (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
  2427. (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
  2428. (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
  2429. (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
  2430. (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
  2431. (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
  2432. (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
  2433. (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
  2434. (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
  2435. (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
  2436. (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
  2437. (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
  2438. (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
  2439. (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
  2440. (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
  2441. (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
  2442. (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
  2443. (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
  2444. (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
  2445. (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
  2446. (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
  2447. (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
  2448. (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
  2449. (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
  2450. (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
  2451. (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
  2452. (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
  2453. (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
  2454. (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
  2455. (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
  2456. (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
  2457. (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
  2458. (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
  2459. (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
  2460. (define-key vhdl-mode-map "\C-c\C-i\C-f" 'vhdl-fontify-buffer)
  2461. (define-key vhdl-mode-map "\C-c\C-i\C-s" 'vhdl-statistics-buffer)
  2462. (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
  2463. (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
  2464. (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
  2465. (define-key vhdl-mode-map "\M-\t" 'insert-tab)
  2466. ;; insert commands bindings
  2467. (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
  2468. (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
  2469. (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
  2470. (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
  2471. ;; electric key bindings
  2472. (define-key vhdl-mode-map " " 'vhdl-electric-space)
  2473. (when vhdl-intelligent-tab
  2474. (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
  2475. (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
  2476. (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
  2477. (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
  2478. (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
  2479. (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
  2480. (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
  2481. (define-key vhdl-mode-map "," 'vhdl-electric-comma)
  2482. (define-key vhdl-mode-map "." 'vhdl-electric-period)
  2483. (when (vhdl-standard-p 'ams)
  2484. (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
  2485. ;; initialize mode map for VHDL Mode
  2486. (vhdl-mode-map-init)
  2487. ;; define special minibuffer keymap for enabling word completion in minibuffer
  2488. ;; (useful in template generator prompts)
  2489. (defvar vhdl-minibuffer-local-map
  2490. (let ((map (make-sparse-keymap)))
  2491. (set-keymap-parent map minibuffer-local-map)
  2492. (when vhdl-word-completion-in-minibuffer
  2493. (define-key map "\t" 'vhdl-minibuffer-tab))
  2494. map)
  2495. "Keymap for minibuffer used in VHDL Mode.")
  2496. ;; set up electric character functions to work with
  2497. ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
  2498. (mapc
  2499. (function
  2500. (lambda (sym)
  2501. (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
  2502. (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
  2503. '(vhdl-electric-space
  2504. vhdl-electric-tab
  2505. vhdl-electric-return
  2506. vhdl-electric-dash
  2507. vhdl-electric-open-bracket
  2508. vhdl-electric-close-bracket
  2509. vhdl-electric-quote
  2510. vhdl-electric-semicolon
  2511. vhdl-electric-comma
  2512. vhdl-electric-period
  2513. vhdl-electric-equal))
  2514. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2515. ;; Syntax table
  2516. (defvar vhdl-mode-syntax-table nil
  2517. "Syntax table used in `vhdl-mode' buffers.")
  2518. (defvar vhdl-mode-ext-syntax-table nil
  2519. "Syntax table extended by `_' used in `vhdl-mode' buffers.")
  2520. (defun vhdl-mode-syntax-table-init ()
  2521. "Initialize `vhdl-mode-syntax-table'."
  2522. (setq vhdl-mode-syntax-table (make-syntax-table))
  2523. ;; define punctuation
  2524. (modify-syntax-entry ?\# "." vhdl-mode-syntax-table)
  2525. (modify-syntax-entry ?\$ "." vhdl-mode-syntax-table)
  2526. (modify-syntax-entry ?\% "." vhdl-mode-syntax-table)
  2527. (modify-syntax-entry ?\& "." vhdl-mode-syntax-table)
  2528. (modify-syntax-entry ?\' "." vhdl-mode-syntax-table)
  2529. (modify-syntax-entry ?\* "." vhdl-mode-syntax-table)
  2530. (modify-syntax-entry ?\+ "." vhdl-mode-syntax-table)
  2531. (modify-syntax-entry ?\. "." vhdl-mode-syntax-table)
  2532. (modify-syntax-entry ?\/ "." vhdl-mode-syntax-table)
  2533. (modify-syntax-entry ?\: "." vhdl-mode-syntax-table)
  2534. (modify-syntax-entry ?\; "." vhdl-mode-syntax-table)
  2535. (modify-syntax-entry ?\< "." vhdl-mode-syntax-table)
  2536. (modify-syntax-entry ?\= "." vhdl-mode-syntax-table)
  2537. (modify-syntax-entry ?\> "." vhdl-mode-syntax-table)
  2538. (modify-syntax-entry ?\\ "." vhdl-mode-syntax-table)
  2539. (modify-syntax-entry ?\| "." vhdl-mode-syntax-table)
  2540. ;; define string
  2541. (modify-syntax-entry ?\" "\"" vhdl-mode-syntax-table)
  2542. ;; define underscore
  2543. (when vhdl-underscore-is-part-of-word
  2544. (modify-syntax-entry ?\_ "w" vhdl-mode-syntax-table))
  2545. ;; a single hyphen is punctuation, but a double hyphen starts a comment
  2546. (modify-syntax-entry ?\- ". 12" vhdl-mode-syntax-table)
  2547. ;; and \n and \^M end a comment
  2548. (modify-syntax-entry ?\n ">" vhdl-mode-syntax-table)
  2549. (modify-syntax-entry ?\^M ">" vhdl-mode-syntax-table)
  2550. ;; define parentheses to match
  2551. (modify-syntax-entry ?\( "()" vhdl-mode-syntax-table)
  2552. (modify-syntax-entry ?\) ")(" vhdl-mode-syntax-table)
  2553. (modify-syntax-entry ?\[ "(]" vhdl-mode-syntax-table)
  2554. (modify-syntax-entry ?\] ")[" vhdl-mode-syntax-table)
  2555. (modify-syntax-entry ?\{ "(}" vhdl-mode-syntax-table)
  2556. (modify-syntax-entry ?\} "){" vhdl-mode-syntax-table)
  2557. ;; extended syntax table including '_' (for simpler search regexps)
  2558. (setq vhdl-mode-ext-syntax-table (copy-syntax-table vhdl-mode-syntax-table))
  2559. (modify-syntax-entry ?_ "w" vhdl-mode-ext-syntax-table))
  2560. ;; initialize syntax table for VHDL Mode
  2561. (vhdl-mode-syntax-table-init)
  2562. (defvar vhdl-syntactic-context nil
  2563. "Buffer local variable containing syntactic analysis list.")
  2564. (make-variable-buffer-local 'vhdl-syntactic-context)
  2565. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2566. ;; Abbrev ook bindings
  2567. (defvar vhdl-mode-abbrev-table nil
  2568. "Abbrev table to use in `vhdl-mode' buffers.")
  2569. (defun vhdl-mode-abbrev-table-init ()
  2570. "Initialize `vhdl-mode-abbrev-table'."
  2571. (define-abbrev-table 'vhdl-mode-abbrev-table
  2572. (append
  2573. (when (memq 'vhdl vhdl-electric-keywords)
  2574. ;; VHDL'93 keywords
  2575. (mapcar (lambda (x) (list (car x) "" (cdr x) 0 'system))
  2576. '(
  2577. ("--" . vhdl-template-display-comment-hook)
  2578. ("abs" . vhdl-template-default-hook)
  2579. ("access" . vhdl-template-default-hook)
  2580. ("after" . vhdl-template-default-hook)
  2581. ("alias" . vhdl-template-alias-hook)
  2582. ("all" . vhdl-template-default-hook)
  2583. ("and" . vhdl-template-default-hook)
  2584. ("arch" . vhdl-template-architecture-hook)
  2585. ("architecture" . vhdl-template-architecture-hook)
  2586. ("array" . vhdl-template-default-hook)
  2587. ("assert" . vhdl-template-assert-hook)
  2588. ("attr" . vhdl-template-attribute-hook)
  2589. ("attribute" . vhdl-template-attribute-hook)
  2590. ("begin" . vhdl-template-default-indent-hook)
  2591. ("block" . vhdl-template-block-hook)
  2592. ("body" . vhdl-template-default-hook)
  2593. ("buffer" . vhdl-template-default-hook)
  2594. ("bus" . vhdl-template-default-hook)
  2595. ("case" . vhdl-template-case-hook)
  2596. ("comp" . vhdl-template-component-hook)
  2597. ("component" . vhdl-template-component-hook)
  2598. ("cond" . vhdl-template-conditional-signal-asst-hook)
  2599. ("conditional" . vhdl-template-conditional-signal-asst-hook)
  2600. ("conf" . vhdl-template-configuration-hook)
  2601. ("configuration" . vhdl-template-configuration-hook)
  2602. ("cons" . vhdl-template-constant-hook)
  2603. ("constant" . vhdl-template-constant-hook)
  2604. ("disconnect" . vhdl-template-disconnect-hook)
  2605. ("downto" . vhdl-template-default-hook)
  2606. ("else" . vhdl-template-else-hook)
  2607. ("elseif" . vhdl-template-elsif-hook)
  2608. ("elsif" . vhdl-template-elsif-hook)
  2609. ("end" . vhdl-template-default-indent-hook)
  2610. ("entity" . vhdl-template-entity-hook)
  2611. ("exit" . vhdl-template-exit-hook)
  2612. ("file" . vhdl-template-file-hook)
  2613. ("for" . vhdl-template-for-hook)
  2614. ("func" . vhdl-template-function-hook)
  2615. ("function" . vhdl-template-function-hook)
  2616. ("generic" . vhdl-template-generic-hook)
  2617. ("group" . vhdl-template-group-hook)
  2618. ("guarded" . vhdl-template-default-hook)
  2619. ("if" . vhdl-template-if-hook)
  2620. ("impure" . vhdl-template-default-hook)
  2621. ("in" . vhdl-template-default-hook)
  2622. ("inertial" . vhdl-template-default-hook)
  2623. ("inout" . vhdl-template-default-hook)
  2624. ("inst" . vhdl-template-instance-hook)
  2625. ("instance" . vhdl-template-instance-hook)
  2626. ("is" . vhdl-template-default-hook)
  2627. ("label" . vhdl-template-default-hook)
  2628. ("library" . vhdl-template-library-hook)
  2629. ("linkage" . vhdl-template-default-hook)
  2630. ("literal" . vhdl-template-default-hook)
  2631. ("loop" . vhdl-template-bare-loop-hook)
  2632. ("map" . vhdl-template-map-hook)
  2633. ("mod" . vhdl-template-default-hook)
  2634. ("nand" . vhdl-template-default-hook)
  2635. ("new" . vhdl-template-default-hook)
  2636. ("next" . vhdl-template-next-hook)
  2637. ("nor" . vhdl-template-default-hook)
  2638. ("not" . vhdl-template-default-hook)
  2639. ("null" . vhdl-template-default-hook)
  2640. ("of" . vhdl-template-default-hook)
  2641. ("on" . vhdl-template-default-hook)
  2642. ("open" . vhdl-template-default-hook)
  2643. ("or" . vhdl-template-default-hook)
  2644. ("others" . vhdl-template-others-hook)
  2645. ("out" . vhdl-template-default-hook)
  2646. ("pack" . vhdl-template-package-hook)
  2647. ("package" . vhdl-template-package-hook)
  2648. ("port" . vhdl-template-port-hook)
  2649. ("postponed" . vhdl-template-default-hook)
  2650. ("procedure" . vhdl-template-procedure-hook)
  2651. ("process" . vhdl-template-process-hook)
  2652. ("pure" . vhdl-template-default-hook)
  2653. ("range" . vhdl-template-default-hook)
  2654. ("record" . vhdl-template-default-hook)
  2655. ("register" . vhdl-template-default-hook)
  2656. ("reject" . vhdl-template-default-hook)
  2657. ("rem" . vhdl-template-default-hook)
  2658. ("report" . vhdl-template-report-hook)
  2659. ("return" . vhdl-template-return-hook)
  2660. ("rol" . vhdl-template-default-hook)
  2661. ("ror" . vhdl-template-default-hook)
  2662. ("select" . vhdl-template-selected-signal-asst-hook)
  2663. ("severity" . vhdl-template-default-hook)
  2664. ("shared" . vhdl-template-default-hook)
  2665. ("sig" . vhdl-template-signal-hook)
  2666. ("signal" . vhdl-template-signal-hook)
  2667. ("sla" . vhdl-template-default-hook)
  2668. ("sll" . vhdl-template-default-hook)
  2669. ("sra" . vhdl-template-default-hook)
  2670. ("srl" . vhdl-template-default-hook)
  2671. ("subtype" . vhdl-template-subtype-hook)
  2672. ("then" . vhdl-template-default-hook)
  2673. ("to" . vhdl-template-default-hook)
  2674. ("transport" . vhdl-template-default-hook)
  2675. ("type" . vhdl-template-type-hook)
  2676. ("unaffected" . vhdl-template-default-hook)
  2677. ("units" . vhdl-template-default-hook)
  2678. ("until" . vhdl-template-default-hook)
  2679. ("use" . vhdl-template-use-hook)
  2680. ("var" . vhdl-template-variable-hook)
  2681. ("variable" . vhdl-template-variable-hook)
  2682. ("wait" . vhdl-template-wait-hook)
  2683. ("when" . vhdl-template-when-hook)
  2684. ("while" . vhdl-template-while-loop-hook)
  2685. ("with" . vhdl-template-with-hook)
  2686. ("xnor" . vhdl-template-default-hook)
  2687. ("xor" . vhdl-template-default-hook)
  2688. )))
  2689. ;; VHDL-AMS keywords
  2690. (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
  2691. (mapcar (lambda (x) (list (car x) "" (cdr x) 0 'system))
  2692. '(
  2693. ("across" . vhdl-template-default-hook)
  2694. ("break" . vhdl-template-break-hook)
  2695. ("limit" . vhdl-template-limit-hook)
  2696. ("nature" . vhdl-template-nature-hook)
  2697. ("noise" . vhdl-template-default-hook)
  2698. ("procedural" . vhdl-template-procedural-hook)
  2699. ("quantity" . vhdl-template-quantity-hook)
  2700. ("reference" . vhdl-template-default-hook)
  2701. ("spectrum" . vhdl-template-default-hook)
  2702. ("subnature" . vhdl-template-subnature-hook)
  2703. ("terminal" . vhdl-template-terminal-hook)
  2704. ("through" . vhdl-template-default-hook)
  2705. ("tolerance" . vhdl-template-default-hook)
  2706. )))
  2707. ;; user model keywords
  2708. (when (memq 'user vhdl-electric-keywords)
  2709. (let (abbrev-list keyword)
  2710. (dolist (elem vhdl-model-alist)
  2711. (setq keyword (nth 3 elem))
  2712. (unless (equal keyword "")
  2713. (push (list keyword ""
  2714. (vhdl-function-name
  2715. "vhdl-model" (nth 0 elem) "hook") 0 'system)
  2716. abbrev-list)))
  2717. abbrev-list)))))
  2718. ;; initialize abbrev table for VHDL Mode
  2719. (vhdl-mode-abbrev-table-init)
  2720. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2721. ;; Template completion lists
  2722. (defvar vhdl-template-construct-alist nil
  2723. "List of built-in construct templates.")
  2724. (defun vhdl-template-construct-alist-init ()
  2725. "Initialize `vhdl-template-construct-alist'."
  2726. (setq
  2727. vhdl-template-construct-alist
  2728. (append
  2729. '(
  2730. ("alias declaration" vhdl-template-alias)
  2731. ("architecture body" vhdl-template-architecture)
  2732. ("assertion" vhdl-template-assert)
  2733. ("attribute declaration" vhdl-template-attribute-decl)
  2734. ("attribute specification" vhdl-template-attribute-spec)
  2735. ("block configuration" vhdl-template-block-configuration)
  2736. ("block statement" vhdl-template-block)
  2737. ("case statement" vhdl-template-case-is)
  2738. ("component configuration" vhdl-template-component-conf)
  2739. ("component declaration" vhdl-template-component-decl)
  2740. ("component instantiation statement" vhdl-template-component-inst)
  2741. ("conditional signal assignment" vhdl-template-conditional-signal-asst)
  2742. ("configuration declaration" vhdl-template-configuration-decl)
  2743. ("configuration specification" vhdl-template-configuration-spec)
  2744. ("constant declaration" vhdl-template-constant)
  2745. ("disconnection specification" vhdl-template-disconnect)
  2746. ("entity declaration" vhdl-template-entity)
  2747. ("exit statement" vhdl-template-exit)
  2748. ("file declaration" vhdl-template-file)
  2749. ("generate statement" vhdl-template-generate)
  2750. ("generic clause" vhdl-template-generic)
  2751. ("group declaration" vhdl-template-group-decl)
  2752. ("group template declaration" vhdl-template-group-template)
  2753. ("if statement" vhdl-template-if-then)
  2754. ("library clause" vhdl-template-library)
  2755. ("loop statement" vhdl-template-loop)
  2756. ("next statement" vhdl-template-next)
  2757. ("package declaration" vhdl-template-package-decl)
  2758. ("package body" vhdl-template-package-body)
  2759. ("port clause" vhdl-template-port)
  2760. ("process statement" vhdl-template-process)
  2761. ("report statement" vhdl-template-report)
  2762. ("return statement" vhdl-template-return)
  2763. ("selected signal assignment" vhdl-template-selected-signal-asst)
  2764. ("signal declaration" vhdl-template-signal)
  2765. ("subprogram declaration" vhdl-template-subprogram-decl)
  2766. ("subprogram body" vhdl-template-subprogram-body)
  2767. ("subtype declaration" vhdl-template-subtype)
  2768. ("type declaration" vhdl-template-type)
  2769. ("use clause" vhdl-template-use)
  2770. ("variable declaration" vhdl-template-variable)
  2771. ("wait statement" vhdl-template-wait)
  2772. )
  2773. (when (vhdl-standard-p 'ams)
  2774. '(
  2775. ("break statement" vhdl-template-break)
  2776. ("nature declaration" vhdl-template-nature)
  2777. ("quantity declaration" vhdl-template-quantity)
  2778. ("simultaneous case statement" vhdl-template-case-use)
  2779. ("simultaneous if statement" vhdl-template-if-use)
  2780. ("simultaneous procedural statement" vhdl-template-procedural)
  2781. ("step limit specification" vhdl-template-limit)
  2782. ("subnature declaration" vhdl-template-subnature)
  2783. ("terminal declaration" vhdl-template-terminal)
  2784. )))))
  2785. ;; initialize for VHDL Mode
  2786. (vhdl-template-construct-alist-init)
  2787. (defvar vhdl-template-package-alist nil
  2788. "List of built-in package templates.")
  2789. (defun vhdl-template-package-alist-init ()
  2790. "Initialize `vhdl-template-package-alist'."
  2791. (setq
  2792. vhdl-template-package-alist
  2793. (append
  2794. '(
  2795. ("numeric_bit" vhdl-template-package-numeric-bit)
  2796. ("numeric_std" vhdl-template-package-numeric-std)
  2797. ("std_logic_1164" vhdl-template-package-std-logic-1164)
  2798. ("std_logic_arith" vhdl-template-package-std-logic-arith)
  2799. ("std_logic_misc" vhdl-template-package-std-logic-misc)
  2800. ("std_logic_signed" vhdl-template-package-std-logic-signed)
  2801. ("std_logic_textio" vhdl-template-package-std-logic-textio)
  2802. ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
  2803. ("textio" vhdl-template-package-textio)
  2804. )
  2805. (when (vhdl-standard-p 'math)
  2806. '(
  2807. ("math_complex" vhdl-template-package-math-complex)
  2808. ("math_real" vhdl-template-package-math-real)
  2809. )))))
  2810. ;; initialize for VHDL Mode
  2811. (vhdl-template-package-alist-init)
  2812. (defvar vhdl-template-directive-alist
  2813. '(
  2814. ("translate_on" vhdl-template-directive-translate-on)
  2815. ("translate_off" vhdl-template-directive-translate-off)
  2816. ("synthesis_on" vhdl-template-directive-synthesis-on)
  2817. ("synthesis_off" vhdl-template-directive-synthesis-off)
  2818. )
  2819. "List of built-in directive templates.")
  2820. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2821. ;;; Menus
  2822. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2823. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2824. ;; VHDL menu (using `easy-menu.el')
  2825. (defun vhdl-customize ()
  2826. "Call the customize function with `vhdl' as argument."
  2827. (interactive)
  2828. (customize-browse 'vhdl))
  2829. (defun vhdl-create-mode-menu ()
  2830. "Create VHDL Mode menu."
  2831. `("VHDL"
  2832. ,(append
  2833. '("Project"
  2834. ["None" (vhdl-set-project "")
  2835. :style radio :selected (null vhdl-project)]
  2836. "--")
  2837. ;; add menu entries for defined projects
  2838. (let ((project-alist vhdl-project-alist) menu-list name)
  2839. (while project-alist
  2840. (setq name (caar project-alist))
  2841. (setq menu-list
  2842. (cons `[,name (vhdl-set-project ,name)
  2843. :style radio :selected (equal ,name vhdl-project)]
  2844. menu-list))
  2845. (setq project-alist (cdr project-alist)))
  2846. (setq menu-list
  2847. (if vhdl-project-sort
  2848. (sort menu-list
  2849. (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
  2850. (nreverse menu-list)))
  2851. (vhdl-menu-split menu-list "Project"))
  2852. '("--" "--"
  2853. ["Select Project..." vhdl-set-project t]
  2854. ["Set As Default Project" vhdl-set-default-project t]
  2855. "--"
  2856. ["Duplicate Project" vhdl-duplicate-project vhdl-project]
  2857. ["Import Project..." vhdl-import-project
  2858. :keys "C-c C-p C-m" :active t]
  2859. ["Export Project" vhdl-export-project vhdl-project]
  2860. "--"
  2861. ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
  2862. "--"
  2863. ("Compile"
  2864. ["Compile Buffer" vhdl-compile t]
  2865. ["Stop Compilation" kill-compilation t]
  2866. "--"
  2867. ["Make" vhdl-make t]
  2868. ["Generate Makefile" vhdl-generate-makefile t]
  2869. "--"
  2870. ["Next Error" next-error t]
  2871. ["Previous Error" previous-error t]
  2872. ["First Error" first-error t]
  2873. "--"
  2874. ,(append
  2875. '("Compiler")
  2876. ;; add menu entries for defined compilers
  2877. (let ((comp-alist vhdl-compiler-alist) menu-list name)
  2878. (while comp-alist
  2879. (setq name (caar comp-alist))
  2880. (setq menu-list
  2881. (cons `[,name (setq vhdl-compiler ,name)
  2882. :style radio :selected (equal ,name vhdl-compiler)]
  2883. menu-list))
  2884. (setq comp-alist (cdr comp-alist)))
  2885. (setq menu-list (nreverse menu-list))
  2886. (vhdl-menu-split menu-list "Compiler"))
  2887. '("--" "--"
  2888. ["Select Compiler..." vhdl-set-compiler t]
  2889. "--"
  2890. ["Customize Compiler..."
  2891. (customize-option 'vhdl-compiler-alist) t])))
  2892. "--"
  2893. ,(append
  2894. '("Template"
  2895. ("VHDL Construct 1"
  2896. ["Alias" vhdl-template-alias t]
  2897. ["Architecture" vhdl-template-architecture t]
  2898. ["Assert" vhdl-template-assert t]
  2899. ["Attribute (Decl)" vhdl-template-attribute-decl t]
  2900. ["Attribute (Spec)" vhdl-template-attribute-spec t]
  2901. ["Block" vhdl-template-block t]
  2902. ["Case" vhdl-template-case-is t]
  2903. ["Component (Decl)" vhdl-template-component-decl t]
  2904. ["(Component) Instance" vhdl-template-component-inst t]
  2905. ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
  2906. ["Configuration (Block)" vhdl-template-block-configuration t]
  2907. ["Configuration (Comp)" vhdl-template-component-conf t]
  2908. ["Configuration (Decl)" vhdl-template-configuration-decl t]
  2909. ["Configuration (Spec)" vhdl-template-configuration-spec t]
  2910. ["Constant" vhdl-template-constant t]
  2911. ["Disconnect" vhdl-template-disconnect t]
  2912. ["Else" vhdl-template-else t]
  2913. ["Elsif" vhdl-template-elsif t]
  2914. ["Entity" vhdl-template-entity t]
  2915. ["Exit" vhdl-template-exit t]
  2916. ["File" vhdl-template-file t]
  2917. ["For (Generate)" vhdl-template-for-generate t]
  2918. ["For (Loop)" vhdl-template-for-loop t]
  2919. ["Function (Body)" vhdl-template-function-body t]
  2920. ["Function (Decl)" vhdl-template-function-decl t]
  2921. ["Generic" vhdl-template-generic t]
  2922. ["Group (Decl)" vhdl-template-group-decl t]
  2923. ["Group (Template)" vhdl-template-group-template t])
  2924. ("VHDL Construct 2"
  2925. ["If (Generate)" vhdl-template-if-generate t]
  2926. ["If (Then)" vhdl-template-if-then t]
  2927. ["Library" vhdl-template-library t]
  2928. ["Loop" vhdl-template-bare-loop t]
  2929. ["Map" vhdl-template-map t]
  2930. ["Next" vhdl-template-next t]
  2931. ["Others (Aggregate)" vhdl-template-others t]
  2932. ["Package (Decl)" vhdl-template-package-decl t]
  2933. ["Package (Body)" vhdl-template-package-body t]
  2934. ["Port" vhdl-template-port t]
  2935. ["Procedure (Body)" vhdl-template-procedure-body t]
  2936. ["Procedure (Decl)" vhdl-template-procedure-decl t]
  2937. ["Process (Comb)" vhdl-template-process-comb t]
  2938. ["Process (Seq)" vhdl-template-process-seq t]
  2939. ["Report" vhdl-template-report t]
  2940. ["Return" vhdl-template-return t]
  2941. ["Select" vhdl-template-selected-signal-asst t]
  2942. ["Signal" vhdl-template-signal t]
  2943. ["Subtype" vhdl-template-subtype t]
  2944. ["Type" vhdl-template-type t]
  2945. ["Use" vhdl-template-use t]
  2946. ["Variable" vhdl-template-variable t]
  2947. ["Wait" vhdl-template-wait t]
  2948. ["(Clocked Wait)" vhdl-template-clocked-wait t]
  2949. ["When" vhdl-template-when t]
  2950. ["While (Loop)" vhdl-template-while-loop t]
  2951. ["With" vhdl-template-with t]))
  2952. (when (vhdl-standard-p 'ams)
  2953. '(("VHDL-AMS Construct"
  2954. ["Break" vhdl-template-break t]
  2955. ["Case (Use)" vhdl-template-case-use t]
  2956. ["If (Use)" vhdl-template-if-use t]
  2957. ["Limit" vhdl-template-limit t]
  2958. ["Nature" vhdl-template-nature t]
  2959. ["Procedural" vhdl-template-procedural t]
  2960. ["Quantity (Free)" vhdl-template-quantity-free t]
  2961. ["Quantity (Branch)" vhdl-template-quantity-branch t]
  2962. ["Quantity (Source)" vhdl-template-quantity-source t]
  2963. ["Subnature" vhdl-template-subnature t]
  2964. ["Terminal" vhdl-template-terminal t])))
  2965. '(["Insert Construct..." vhdl-template-insert-construct
  2966. :keys "C-c C-i C-t"]
  2967. "--")
  2968. (list
  2969. (append
  2970. '("Package")
  2971. '(["numeric_bit" vhdl-template-package-numeric-bit t]
  2972. ["numeric_std" vhdl-template-package-numeric-std t]
  2973. ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
  2974. ["textio" vhdl-template-package-textio t]
  2975. "--"
  2976. ["std_logic_arith" vhdl-template-package-std-logic-arith t]
  2977. ["std_logic_signed" vhdl-template-package-std-logic-signed t]
  2978. ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
  2979. ["std_logic_misc" vhdl-template-package-std-logic-misc t]
  2980. ["std_logic_textio" vhdl-template-package-std-logic-textio t]
  2981. "--")
  2982. (when (vhdl-standard-p 'ams)
  2983. '(["fundamental_constants" vhdl-template-package-fundamental-constants t]
  2984. ["material_constants" vhdl-template-package-material-constants t]
  2985. ["energy_systems" vhdl-template-package-energy-systems t]
  2986. ["electrical_systems" vhdl-template-package-electrical-systems t]
  2987. ["mechanical_systems" vhdl-template-package-mechanical-systems t]
  2988. ["radiant_systems" vhdl-template-package-radiant-systems t]
  2989. ["thermal_systems" vhdl-template-package-thermal-systems t]
  2990. ["fluidic_systems" vhdl-template-package-fluidic-systems t]
  2991. "--"))
  2992. (when (vhdl-standard-p 'math)
  2993. '(["math_complex" vhdl-template-package-math-complex t]
  2994. ["math_real" vhdl-template-package-math-real t]
  2995. "--"))
  2996. '(["Insert Package..." vhdl-template-insert-package
  2997. :keys "C-c C-i C-p"])))
  2998. '(("Directive"
  2999. ["translate_on" vhdl-template-directive-translate-on t]
  3000. ["translate_off" vhdl-template-directive-translate-off t]
  3001. ["synthesis_on" vhdl-template-directive-synthesis-on t]
  3002. ["synthesis_off" vhdl-template-directive-synthesis-off t]
  3003. "--"
  3004. ["Insert Directive..." vhdl-template-insert-directive
  3005. :keys "C-c C-i C-d"])
  3006. "--"
  3007. ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
  3008. ["Insert Footer" vhdl-template-footer t]
  3009. ["Insert Date" vhdl-template-insert-date t]
  3010. ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
  3011. "--"
  3012. ["Query Next Prompt" vhdl-template-search-prompt t]))
  3013. ,(append
  3014. '("Model")
  3015. ;; add menu entries for defined models
  3016. (let ((model-alist vhdl-model-alist) menu-list model)
  3017. (while model-alist
  3018. (setq model (car model-alist))
  3019. (setq menu-list
  3020. (cons
  3021. (vector
  3022. (nth 0 model)
  3023. (vhdl-function-name "vhdl-model" (nth 0 model))
  3024. :keys (concat "C-c C-m " (key-description (nth 2 model))))
  3025. menu-list))
  3026. (setq model-alist (cdr model-alist)))
  3027. (setq menu-list (nreverse menu-list))
  3028. (vhdl-menu-split menu-list "Model"))
  3029. '("--" "--"
  3030. ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
  3031. ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
  3032. ("Port"
  3033. ["Copy" vhdl-port-copy t]
  3034. "--"
  3035. ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
  3036. ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
  3037. ["Paste As Instance" vhdl-port-paste-instance
  3038. :keys "C-c C-p C-i" :active vhdl-port-list]
  3039. ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
  3040. ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
  3041. ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
  3042. ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
  3043. "--"
  3044. ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
  3045. "--"
  3046. ["Flatten" vhdl-port-flatten
  3047. :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
  3048. ["Reverse Direction" vhdl-port-reverse-direction
  3049. :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
  3050. ("Compose"
  3051. ["New Component" vhdl-compose-new-component t]
  3052. ["Copy Component" vhdl-port-copy t]
  3053. ["Place Component" vhdl-compose-place-component vhdl-port-list]
  3054. ["Wire Components" vhdl-compose-wire-components t]
  3055. "--"
  3056. ["Generate Configuration" vhdl-compose-configuration t]
  3057. ["Generate Components Package" vhdl-compose-components-package t])
  3058. ("Subprogram"
  3059. ["Copy" vhdl-subprog-copy t]
  3060. "--"
  3061. ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
  3062. ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
  3063. ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
  3064. "--"
  3065. ["Flatten" vhdl-subprog-flatten
  3066. :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
  3067. "--"
  3068. ("Comment"
  3069. ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
  3070. "--"
  3071. ["Insert Inline Comment" vhdl-comment-append-inline t]
  3072. ["Insert Horizontal Line" vhdl-comment-display-line t]
  3073. ["Insert Display Comment" vhdl-comment-display t]
  3074. "--"
  3075. ["Fill Comment" fill-paragraph t]
  3076. ["Fill Comment Region" fill-region (mark)]
  3077. ["Kill Comment Region" vhdl-comment-kill-region (mark)]
  3078. ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
  3079. ("Line"
  3080. ["Kill" vhdl-line-kill t]
  3081. ["Copy" vhdl-line-copy t]
  3082. ["Yank" vhdl-line-yank t]
  3083. ["Expand" vhdl-line-expand t]
  3084. "--"
  3085. ["Transpose Next" vhdl-line-transpose-next t]
  3086. ["Transpose Prev" vhdl-line-transpose-previous t]
  3087. ["Open" vhdl-line-open t]
  3088. ["Join" vhdl-delete-indentation t]
  3089. "--"
  3090. ["Goto" goto-line t]
  3091. ["(Un)Comment Out" vhdl-comment-uncomment-line t])
  3092. ("Move"
  3093. ["Forward Statement" vhdl-end-of-statement t]
  3094. ["Backward Statement" vhdl-beginning-of-statement t]
  3095. ["Forward Expression" vhdl-forward-sexp t]
  3096. ["Backward Expression" vhdl-backward-sexp t]
  3097. ["Forward Same Indent" vhdl-forward-same-indent t]
  3098. ["Backward Same Indent" vhdl-backward-same-indent t]
  3099. ["Forward Function" vhdl-end-of-defun t]
  3100. ["Backward Function" vhdl-beginning-of-defun t]
  3101. ["Mark Function" vhdl-mark-defun t])
  3102. "--"
  3103. ("Indent"
  3104. ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
  3105. ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
  3106. ["Region" vhdl-indent-region (mark)]
  3107. ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
  3108. ("Align"
  3109. ["Group" vhdl-align-group t]
  3110. ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
  3111. ["List" vhdl-align-list t]
  3112. ["Declarations" vhdl-align-declarations t]
  3113. ["Region" vhdl-align-region (mark)]
  3114. ["Buffer" vhdl-align-buffer t]
  3115. "--"
  3116. ["Inline Comment Group" vhdl-align-inline-comment-group t]
  3117. ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
  3118. ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
  3119. ("Fill"
  3120. ["List" vhdl-fill-list t]
  3121. ["Group" vhdl-fill-group t]
  3122. ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
  3123. ["Region" vhdl-fill-region (mark)])
  3124. ("Beautify"
  3125. ["Region" vhdl-beautify-region (mark)]
  3126. ["Buffer" vhdl-beautify-buffer t])
  3127. ("Fix"
  3128. ["Generic/Port Clause" vhdl-fix-clause t]
  3129. ["Generic/Port Clause Buffer" vhdl-fix-clause t]
  3130. "--"
  3131. ["Case Region" vhdl-fix-case-region (mark)]
  3132. ["Case Buffer" vhdl-fix-case-buffer t]
  3133. "--"
  3134. ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
  3135. ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
  3136. "--"
  3137. ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
  3138. ("Update"
  3139. ["Sensitivity List" vhdl-update-sensitivity-list-process t]
  3140. ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
  3141. "--"
  3142. ["Fontify Buffer" vhdl-fontify-buffer t]
  3143. ["Statistics Buffer" vhdl-statistics-buffer t]
  3144. ["Show Messages" vhdl-show-messages t]
  3145. ["Syntactic Info" vhdl-show-syntactic-information t]
  3146. "--"
  3147. ["Speedbar" vhdl-speedbar t]
  3148. ["Hide/Show" vhdl-hs-minor-mode t]
  3149. "--"
  3150. ("Documentation"
  3151. ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
  3152. ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
  3153. ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
  3154. ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
  3155. ["Version" vhdl-version t]
  3156. ["Bug Report..." vhdl-submit-bug-report t]
  3157. "--"
  3158. ("Options"
  3159. ("Mode"
  3160. ["Electric Mode"
  3161. (progn (customize-set-variable 'vhdl-electric-mode
  3162. (not vhdl-electric-mode))
  3163. (vhdl-mode-line-update))
  3164. :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
  3165. ["Stutter Mode"
  3166. (progn (customize-set-variable 'vhdl-stutter-mode
  3167. (not vhdl-stutter-mode))
  3168. (vhdl-mode-line-update))
  3169. :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
  3170. ["Indent Tabs Mode"
  3171. (progn (customize-set-variable 'vhdl-indent-tabs-mode
  3172. (not vhdl-indent-tabs-mode))
  3173. (setq indent-tabs-mode vhdl-indent-tabs-mode))
  3174. :style toggle :selected vhdl-indent-tabs-mode]
  3175. "--"
  3176. ["Customize Group..." (customize-group 'vhdl-mode) t])
  3177. ("Project"
  3178. ["Project Setup..." (customize-option 'vhdl-project-alist) t]
  3179. ,(append
  3180. '("Selected Project at Startup"
  3181. ["None" (progn (customize-set-variable 'vhdl-project nil)
  3182. (vhdl-set-project ""))
  3183. :style radio :selected (null vhdl-project)]
  3184. "--")
  3185. ;; add menu entries for defined projects
  3186. (let ((project-alist vhdl-project-alist) menu-list name)
  3187. (while project-alist
  3188. (setq name (caar project-alist))
  3189. (setq menu-list
  3190. (cons `[,name (progn (customize-set-variable
  3191. 'vhdl-project ,name)
  3192. (vhdl-set-project ,name))
  3193. :style radio :selected (equal ,name vhdl-project)]
  3194. menu-list))
  3195. (setq project-alist (cdr project-alist)))
  3196. (setq menu-list (nreverse menu-list))
  3197. (vhdl-menu-split menu-list "Project")))
  3198. ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
  3199. ("Auto Load Setup File"
  3200. ["At Startup"
  3201. (customize-set-variable 'vhdl-project-auto-load
  3202. (if (memq 'startup vhdl-project-auto-load)
  3203. (delq 'startup vhdl-project-auto-load)
  3204. (cons 'startup vhdl-project-auto-load)))
  3205. :style toggle :selected (memq 'startup vhdl-project-auto-load)])
  3206. ["Sort Projects"
  3207. (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
  3208. :style toggle :selected vhdl-project-sort]
  3209. "--"
  3210. ["Customize Group..." (customize-group 'vhdl-project) t])
  3211. ("Compiler"
  3212. ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
  3213. ,(append
  3214. '("Selected Compiler at Startup")
  3215. ;; add menu entries for defined compilers
  3216. (let ((comp-alist vhdl-compiler-alist) menu-list name)
  3217. (while comp-alist
  3218. (setq name (caar comp-alist))
  3219. (setq menu-list
  3220. (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
  3221. :style radio :selected (equal ,name vhdl-compiler)]
  3222. menu-list))
  3223. (setq comp-alist (cdr comp-alist)))
  3224. (setq menu-list (nreverse menu-list))
  3225. (vhdl-menu-split menu-list "Compiler")))
  3226. ["Use Local Error Regexp"
  3227. (customize-set-variable 'vhdl-compile-use-local-error-regexp
  3228. (not vhdl-compile-use-local-error-regexp))
  3229. :style toggle :selected vhdl-compile-use-local-error-regexp]
  3230. ["Makefile Default Targets..."
  3231. (customize-option 'vhdl-makefile-default-targets) t]
  3232. ["Makefile Generation Hook..."
  3233. (customize-option 'vhdl-makefile-generation-hook) t]
  3234. ["Default Library Name" (customize-option 'vhdl-default-library) t]
  3235. "--"
  3236. ["Customize Group..." (customize-group 'vhdl-compiler) t])
  3237. ("Style"
  3238. ("VHDL Standard"
  3239. ["VHDL'87"
  3240. (progn (customize-set-variable 'vhdl-standard
  3241. (list '87 (cadr vhdl-standard)))
  3242. (vhdl-activate-customizations))
  3243. :style radio :selected (eq '87 (car vhdl-standard))]
  3244. ["VHDL'93/02"
  3245. (progn (customize-set-variable 'vhdl-standard
  3246. (list '93 (cadr vhdl-standard)))
  3247. (vhdl-activate-customizations))
  3248. :style radio :selected (eq '93 (car vhdl-standard))]
  3249. "--"
  3250. ["VHDL-AMS"
  3251. (progn (customize-set-variable
  3252. 'vhdl-standard (list (car vhdl-standard)
  3253. (if (memq 'ams (cadr vhdl-standard))
  3254. (delq 'ams (cadr vhdl-standard))
  3255. (cons 'ams (cadr vhdl-standard)))))
  3256. (vhdl-activate-customizations))
  3257. :style toggle :selected (memq 'ams (cadr vhdl-standard))]
  3258. ["Math Packages"
  3259. (progn (customize-set-variable
  3260. 'vhdl-standard (list (car vhdl-standard)
  3261. (if (memq 'math (cadr vhdl-standard))
  3262. (delq 'math (cadr vhdl-standard))
  3263. (cons 'math (cadr vhdl-standard)))))
  3264. (vhdl-activate-customizations))
  3265. :style toggle :selected (memq 'math (cadr vhdl-standard))])
  3266. ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
  3267. ["Upper Case Keywords"
  3268. (customize-set-variable 'vhdl-upper-case-keywords
  3269. (not vhdl-upper-case-keywords))
  3270. :style toggle :selected vhdl-upper-case-keywords]
  3271. ["Upper Case Types"
  3272. (customize-set-variable 'vhdl-upper-case-types
  3273. (not vhdl-upper-case-types))
  3274. :style toggle :selected vhdl-upper-case-types]
  3275. ["Upper Case Attributes"
  3276. (customize-set-variable 'vhdl-upper-case-attributes
  3277. (not vhdl-upper-case-attributes))
  3278. :style toggle :selected vhdl-upper-case-attributes]
  3279. ["Upper Case Enumeration Values"
  3280. (customize-set-variable 'vhdl-upper-case-enum-values
  3281. (not vhdl-upper-case-enum-values))
  3282. :style toggle :selected vhdl-upper-case-enum-values]
  3283. ["Upper Case Constants"
  3284. (customize-set-variable 'vhdl-upper-case-constants
  3285. (not vhdl-upper-case-constants))
  3286. :style toggle :selected vhdl-upper-case-constants]
  3287. ("Use Direct Instantiation"
  3288. ["Never"
  3289. (customize-set-variable 'vhdl-use-direct-instantiation 'never)
  3290. :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
  3291. ["Standard"
  3292. (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
  3293. :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
  3294. ["Always"
  3295. (customize-set-variable 'vhdl-use-direct-instantiation 'always)
  3296. :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
  3297. ["Include Array Index and Record Field in Sensitivity List"
  3298. (customize-set-variable 'vhdl-array-index-record-field-in-sensitivity-list
  3299. (not vhdl-array-index-record-field-in-sensitivity-list))
  3300. :style toggle :selected vhdl-array-index-record-field-in-sensitivity-list]
  3301. "--"
  3302. ["Customize Group..." (customize-group 'vhdl-style) t])
  3303. ("Naming"
  3304. ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
  3305. ["Architecture File Name..."
  3306. (customize-option 'vhdl-architecture-file-name) t]
  3307. ["Configuration File Name..."
  3308. (customize-option 'vhdl-configuration-file-name) t]
  3309. ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
  3310. ("File Name Case"
  3311. ["As Is"
  3312. (customize-set-variable 'vhdl-file-name-case 'identity)
  3313. :style radio :selected (eq 'identity vhdl-file-name-case)]
  3314. ["Lower Case"
  3315. (customize-set-variable 'vhdl-file-name-case 'downcase)
  3316. :style radio :selected (eq 'downcase vhdl-file-name-case)]
  3317. ["Upper Case"
  3318. (customize-set-variable 'vhdl-file-name-case 'upcase)
  3319. :style radio :selected (eq 'upcase vhdl-file-name-case)]
  3320. ["Capitalize"
  3321. (customize-set-variable 'vhdl-file-name-case 'capitalize)
  3322. :style radio :selected (eq 'capitalize vhdl-file-name-case)])
  3323. "--"
  3324. ["Customize Group..." (customize-group 'vhdl-naming) t])
  3325. ("Template"
  3326. ("Electric Keywords"
  3327. ["VHDL Keywords"
  3328. (customize-set-variable 'vhdl-electric-keywords
  3329. (if (memq 'vhdl vhdl-electric-keywords)
  3330. (delq 'vhdl vhdl-electric-keywords)
  3331. (cons 'vhdl vhdl-electric-keywords)))
  3332. :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
  3333. ["User Model Keywords"
  3334. (customize-set-variable 'vhdl-electric-keywords
  3335. (if (memq 'user vhdl-electric-keywords)
  3336. (delq 'user vhdl-electric-keywords)
  3337. (cons 'user vhdl-electric-keywords)))
  3338. :style toggle :selected (memq 'user vhdl-electric-keywords)])
  3339. ("Insert Optional Labels"
  3340. ["None"
  3341. (customize-set-variable 'vhdl-optional-labels 'none)
  3342. :style radio :selected (eq 'none vhdl-optional-labels)]
  3343. ["Processes Only"
  3344. (customize-set-variable 'vhdl-optional-labels 'process)
  3345. :style radio :selected (eq 'process vhdl-optional-labels)]
  3346. ["All Constructs"
  3347. (customize-set-variable 'vhdl-optional-labels 'all)
  3348. :style radio :selected (eq 'all vhdl-optional-labels)])
  3349. ("Insert Empty Lines"
  3350. ["None"
  3351. (customize-set-variable 'vhdl-insert-empty-lines 'none)
  3352. :style radio :selected (eq 'none vhdl-insert-empty-lines)]
  3353. ["Design Units Only"
  3354. (customize-set-variable 'vhdl-insert-empty-lines 'unit)
  3355. :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
  3356. ["All Constructs"
  3357. (customize-set-variable 'vhdl-insert-empty-lines 'all)
  3358. :style radio :selected (eq 'all vhdl-insert-empty-lines)])
  3359. ["Argument List Indent"
  3360. (customize-set-variable 'vhdl-argument-list-indent
  3361. (not vhdl-argument-list-indent))
  3362. :style toggle :selected vhdl-argument-list-indent]
  3363. ["Association List with Formals"
  3364. (customize-set-variable 'vhdl-association-list-with-formals
  3365. (not vhdl-association-list-with-formals))
  3366. :style toggle :selected vhdl-association-list-with-formals]
  3367. ["Conditions in Parenthesis"
  3368. (customize-set-variable 'vhdl-conditions-in-parenthesis
  3369. (not vhdl-conditions-in-parenthesis))
  3370. :style toggle :selected vhdl-conditions-in-parenthesis]
  3371. ["Zero String..." (customize-option 'vhdl-zero-string) t]
  3372. ["One String..." (customize-option 'vhdl-one-string) t]
  3373. ("File Header"
  3374. ["Header String..." (customize-option 'vhdl-file-header) t]
  3375. ["Footer String..." (customize-option 'vhdl-file-footer) t]
  3376. ["Company Name..." (customize-option 'vhdl-company-name) t]
  3377. ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
  3378. ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
  3379. ["Date Format..." (customize-option 'vhdl-date-format) t]
  3380. ["Modify Date Prefix String..."
  3381. (customize-option 'vhdl-modify-date-prefix-string) t]
  3382. ["Modify Date on Saving"
  3383. (progn (customize-set-variable 'vhdl-modify-date-on-saving
  3384. (not vhdl-modify-date-on-saving))
  3385. (vhdl-activate-customizations))
  3386. :style toggle :selected vhdl-modify-date-on-saving])
  3387. ("Sequential Process"
  3388. ("Kind of Reset"
  3389. ["None"
  3390. (customize-set-variable 'vhdl-reset-kind 'none)
  3391. :style radio :selected (eq 'none vhdl-reset-kind)]
  3392. ["Synchronous"
  3393. (customize-set-variable 'vhdl-reset-kind 'sync)
  3394. :style radio :selected (eq 'sync vhdl-reset-kind)]
  3395. ["Asynchronous"
  3396. (customize-set-variable 'vhdl-reset-kind 'async)
  3397. :style radio :selected (eq 'async vhdl-reset-kind)]
  3398. ["Query"
  3399. (customize-set-variable 'vhdl-reset-kind 'query)
  3400. :style radio :selected (eq 'query vhdl-reset-kind)])
  3401. ["Reset is Active High"
  3402. (customize-set-variable 'vhdl-reset-active-high
  3403. (not vhdl-reset-active-high))
  3404. :style toggle :selected vhdl-reset-active-high]
  3405. ["Use Rising Clock Edge"
  3406. (customize-set-variable 'vhdl-clock-rising-edge
  3407. (not vhdl-clock-rising-edge))
  3408. :style toggle :selected vhdl-clock-rising-edge]
  3409. ("Clock Edge Condition"
  3410. ["Standard"
  3411. (customize-set-variable 'vhdl-clock-edge-condition 'standard)
  3412. :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
  3413. ["Function \"rising_edge\""
  3414. (customize-set-variable 'vhdl-clock-edge-condition 'function)
  3415. :style radio :selected (eq 'function vhdl-clock-edge-condition)])
  3416. ["Clock Name..." (customize-option 'vhdl-clock-name) t]
  3417. ["Reset Name..." (customize-option 'vhdl-reset-name) t])
  3418. "--"
  3419. ["Customize Group..." (customize-group 'vhdl-template) t])
  3420. ("Model"
  3421. ["Model Definition..." (customize-option 'vhdl-model-alist) t])
  3422. ("Port"
  3423. ["Include Port Comments"
  3424. (customize-set-variable 'vhdl-include-port-comments
  3425. (not vhdl-include-port-comments))
  3426. :style toggle :selected vhdl-include-port-comments]
  3427. ["Include Direction Comments"
  3428. (customize-set-variable 'vhdl-include-direction-comments
  3429. (not vhdl-include-direction-comments))
  3430. :style toggle :selected vhdl-include-direction-comments]
  3431. ["Include Type Comments"
  3432. (customize-set-variable 'vhdl-include-type-comments
  3433. (not vhdl-include-type-comments))
  3434. :style toggle :selected vhdl-include-type-comments]
  3435. ("Include Group Comments"
  3436. ["Never"
  3437. (customize-set-variable 'vhdl-include-group-comments 'never)
  3438. :style radio :selected (eq 'never vhdl-include-group-comments)]
  3439. ["Declarations"
  3440. (customize-set-variable 'vhdl-include-group-comments 'decl)
  3441. :style radio :selected (eq 'decl vhdl-include-group-comments)]
  3442. ["Always"
  3443. (customize-set-variable 'vhdl-include-group-comments 'always)
  3444. :style radio :selected (eq 'always vhdl-include-group-comments)])
  3445. ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
  3446. ["Instance Name..." (customize-option 'vhdl-instance-name) t]
  3447. ("Testbench"
  3448. ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
  3449. ["Architecture Name..."
  3450. (customize-option 'vhdl-testbench-architecture-name) t]
  3451. ["Configuration Name..."
  3452. (customize-option 'vhdl-testbench-configuration-name) t]
  3453. ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
  3454. ["Include Header"
  3455. (customize-set-variable 'vhdl-testbench-include-header
  3456. (not vhdl-testbench-include-header))
  3457. :style toggle :selected vhdl-testbench-include-header]
  3458. ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
  3459. ["Statements..." (customize-option 'vhdl-testbench-statements) t]
  3460. ["Initialize Signals"
  3461. (customize-set-variable 'vhdl-testbench-initialize-signals
  3462. (not vhdl-testbench-initialize-signals))
  3463. :style toggle :selected vhdl-testbench-initialize-signals]
  3464. ["Include Library Clause"
  3465. (customize-set-variable 'vhdl-testbench-include-library
  3466. (not vhdl-testbench-include-library))
  3467. :style toggle :selected vhdl-testbench-include-library]
  3468. ["Include Configuration"
  3469. (customize-set-variable 'vhdl-testbench-include-configuration
  3470. (not vhdl-testbench-include-configuration))
  3471. :style toggle :selected vhdl-testbench-include-configuration]
  3472. ("Create Files"
  3473. ["None"
  3474. (customize-set-variable 'vhdl-testbench-create-files 'none)
  3475. :style radio :selected (eq 'none vhdl-testbench-create-files)]
  3476. ["Single"
  3477. (customize-set-variable 'vhdl-testbench-create-files 'single)
  3478. :style radio :selected (eq 'single vhdl-testbench-create-files)]
  3479. ["Separate"
  3480. (customize-set-variable 'vhdl-testbench-create-files 'separate)
  3481. :style radio :selected (eq 'separate vhdl-testbench-create-files)])
  3482. ["Testbench Entity File Name..."
  3483. (customize-option 'vhdl-testbench-entity-file-name) t]
  3484. ["Testbench Architecture File Name..."
  3485. (customize-option 'vhdl-testbench-architecture-file-name) t])
  3486. "--"
  3487. ["Customize Group..." (customize-group 'vhdl-port) t])
  3488. ("Compose"
  3489. ["Architecture Name..."
  3490. (customize-option 'vhdl-compose-architecture-name) t]
  3491. ["Configuration Name..."
  3492. (customize-option 'vhdl-compose-configuration-name) t]
  3493. ["Components Package Name..."
  3494. (customize-option 'vhdl-components-package-name) t]
  3495. ["Use Components Package"
  3496. (customize-set-variable 'vhdl-use-components-package
  3497. (not vhdl-use-components-package))
  3498. :style toggle :selected vhdl-use-components-package]
  3499. ["Include Header"
  3500. (customize-set-variable 'vhdl-compose-include-header
  3501. (not vhdl-compose-include-header))
  3502. :style toggle :selected vhdl-compose-include-header]
  3503. ("Create Entity/Architecture Files"
  3504. ["None"
  3505. (customize-set-variable 'vhdl-compose-create-files 'none)
  3506. :style radio :selected (eq 'none vhdl-compose-create-files)]
  3507. ["Single"
  3508. (customize-set-variable 'vhdl-compose-create-files 'single)
  3509. :style radio :selected (eq 'single vhdl-compose-create-files)]
  3510. ["Separate"
  3511. (customize-set-variable 'vhdl-compose-create-files 'separate)
  3512. :style radio :selected (eq 'separate vhdl-compose-create-files)])
  3513. ["Create Configuration File"
  3514. (customize-set-variable 'vhdl-compose-configuration-create-file
  3515. (not vhdl-compose-configuration-create-file))
  3516. :style toggle :selected vhdl-compose-configuration-create-file]
  3517. ["Hierarchical Configuration"
  3518. (customize-set-variable 'vhdl-compose-configuration-hierarchical
  3519. (not vhdl-compose-configuration-hierarchical))
  3520. :style toggle :selected vhdl-compose-configuration-hierarchical]
  3521. ["Use Subconfiguration"
  3522. (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
  3523. (not vhdl-compose-configuration-use-subconfiguration))
  3524. :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
  3525. "--"
  3526. ["Customize Group..." (customize-group 'vhdl-compose) t])
  3527. ("Comment"
  3528. ["Self Insert Comments"
  3529. (customize-set-variable 'vhdl-self-insert-comments
  3530. (not vhdl-self-insert-comments))
  3531. :style toggle :selected vhdl-self-insert-comments]
  3532. ["Prompt for Comments"
  3533. (customize-set-variable 'vhdl-prompt-for-comments
  3534. (not vhdl-prompt-for-comments))
  3535. :style toggle :selected vhdl-prompt-for-comments]
  3536. ["Inline Comment Column..."
  3537. (customize-option 'vhdl-inline-comment-column) t]
  3538. ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
  3539. "--"
  3540. ["Customize Group..." (customize-group 'vhdl-comment) t])
  3541. ("Align"
  3542. ["Auto Align Templates"
  3543. (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
  3544. :style toggle :selected vhdl-auto-align]
  3545. ["Align Line Groups"
  3546. (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
  3547. :style toggle :selected vhdl-align-groups]
  3548. ["Group Separation String..."
  3549. (customize-set-variable 'vhdl-align-group-separate) t]
  3550. ["Align Lines with Same Indent"
  3551. (customize-set-variable 'vhdl-align-same-indent
  3552. (not vhdl-align-same-indent))
  3553. :style toggle :selected vhdl-align-same-indent]
  3554. "--"
  3555. ["Customize Group..." (customize-group 'vhdl-align) t])
  3556. ("Highlight"
  3557. ["Highlighting On/Off..."
  3558. (customize-option
  3559. (if (fboundp 'global-font-lock-mode)
  3560. 'global-font-lock-mode 'font-lock-auto-fontify)) t]
  3561. ["Highlight Keywords"
  3562. (progn (customize-set-variable 'vhdl-highlight-keywords
  3563. (not vhdl-highlight-keywords))
  3564. (vhdl-fontify-buffer))
  3565. :style toggle :selected vhdl-highlight-keywords]
  3566. ["Highlight Names"
  3567. (progn (customize-set-variable 'vhdl-highlight-names
  3568. (not vhdl-highlight-names))
  3569. (vhdl-fontify-buffer))
  3570. :style toggle :selected vhdl-highlight-names]
  3571. ["Highlight Special Words"
  3572. (progn (customize-set-variable 'vhdl-highlight-special-words
  3573. (not vhdl-highlight-special-words))
  3574. (vhdl-fontify-buffer))
  3575. :style toggle :selected vhdl-highlight-special-words]
  3576. ["Highlight Forbidden Words"
  3577. (progn (customize-set-variable 'vhdl-highlight-forbidden-words
  3578. (not vhdl-highlight-forbidden-words))
  3579. (vhdl-fontify-buffer))
  3580. :style toggle :selected vhdl-highlight-forbidden-words]
  3581. ["Highlight Verilog Keywords"
  3582. (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
  3583. (not vhdl-highlight-verilog-keywords))
  3584. (vhdl-fontify-buffer))
  3585. :style toggle :selected vhdl-highlight-verilog-keywords]
  3586. ["Highlight \"translate_off\""
  3587. (progn (customize-set-variable 'vhdl-highlight-translate-off
  3588. (not vhdl-highlight-translate-off))
  3589. (vhdl-fontify-buffer))
  3590. :style toggle :selected vhdl-highlight-translate-off]
  3591. ["Case Sensitive Highlighting"
  3592. (progn (customize-set-variable 'vhdl-highlight-case-sensitive
  3593. (not vhdl-highlight-case-sensitive))
  3594. (vhdl-fontify-buffer))
  3595. :style toggle :selected vhdl-highlight-case-sensitive]
  3596. ["Special Syntax Definition..."
  3597. (customize-option 'vhdl-special-syntax-alist) t]
  3598. ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
  3599. ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
  3600. ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
  3601. ["Colors..." (customize-group 'vhdl-highlight-faces) t]
  3602. "--"
  3603. ["Customize Group..." (customize-group 'vhdl-highlight) t])
  3604. ("Speedbar"
  3605. ["Auto Open at Startup"
  3606. (customize-set-variable 'vhdl-speedbar-auto-open
  3607. (not vhdl-speedbar-auto-open))
  3608. :style toggle :selected vhdl-speedbar-auto-open]
  3609. ("Default Displaying Mode"
  3610. ["Files"
  3611. (customize-set-variable 'vhdl-speedbar-display-mode 'files)
  3612. :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
  3613. ["Directory Hierarchy"
  3614. (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
  3615. :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
  3616. ["Project Hierarchy"
  3617. (customize-set-variable 'vhdl-speedbar-display-mode 'project)
  3618. :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
  3619. ["Indentation Offset..."
  3620. (customize-option 'speedbar-indentation-width) t]
  3621. ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
  3622. ["Jump to Unit when Opening"
  3623. (customize-set-variable 'vhdl-speedbar-jump-to-unit
  3624. (not vhdl-speedbar-jump-to-unit))
  3625. :style toggle :selected vhdl-speedbar-jump-to-unit]
  3626. ["Update Hierarchy on File Saving"
  3627. (customize-set-variable 'vhdl-speedbar-update-on-saving
  3628. (not vhdl-speedbar-update-on-saving))
  3629. :style toggle :selected vhdl-speedbar-update-on-saving]
  3630. ("Save in Cache File"
  3631. ["Hierarchy Information"
  3632. (customize-set-variable 'vhdl-speedbar-save-cache
  3633. (if (memq 'hierarchy vhdl-speedbar-save-cache)
  3634. (delq 'hierarchy vhdl-speedbar-save-cache)
  3635. (cons 'hierarchy vhdl-speedbar-save-cache)))
  3636. :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
  3637. ["Displaying Status"
  3638. (customize-set-variable 'vhdl-speedbar-save-cache
  3639. (if (memq 'display vhdl-speedbar-save-cache)
  3640. (delq 'display vhdl-speedbar-save-cache)
  3641. (cons 'display vhdl-speedbar-save-cache)))
  3642. :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
  3643. ["Cache File Name..."
  3644. (customize-option 'vhdl-speedbar-cache-file-name) t]
  3645. "--"
  3646. ["Customize Group..." (customize-group 'vhdl-speedbar) t])
  3647. ("Menu"
  3648. ["Add Index Menu when Loading File"
  3649. (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
  3650. (vhdl-index-menu-init))
  3651. :style toggle :selected vhdl-index-menu]
  3652. ["Add Source File Menu when Loading File"
  3653. (progn (customize-set-variable 'vhdl-source-file-menu
  3654. (not vhdl-source-file-menu))
  3655. (vhdl-add-source-files-menu))
  3656. :style toggle :selected vhdl-source-file-menu]
  3657. ["Add Hideshow Menu at Startup"
  3658. (progn (customize-set-variable 'vhdl-hideshow-menu
  3659. (not vhdl-hideshow-menu))
  3660. (vhdl-activate-customizations))
  3661. :style toggle :selected vhdl-hideshow-menu]
  3662. ["Hide Everything Initially"
  3663. (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
  3664. :style toggle :selected vhdl-hide-all-init]
  3665. "--"
  3666. ["Customize Group..." (customize-group 'vhdl-menu) t])
  3667. ("Print"
  3668. ["In Two Column Format"
  3669. (progn (customize-set-variable 'vhdl-print-two-column
  3670. (not vhdl-print-two-column))
  3671. (message "Activate new setting by saving options and restarting Emacs"))
  3672. :style toggle :selected vhdl-print-two-column]
  3673. ["Use Customized Faces"
  3674. (progn (customize-set-variable 'vhdl-print-customize-faces
  3675. (not vhdl-print-customize-faces))
  3676. (message "Activate new setting by saving options and restarting Emacs"))
  3677. :style toggle :selected vhdl-print-customize-faces]
  3678. "--"
  3679. ["Customize Group..." (customize-group 'vhdl-print) t])
  3680. ("Miscellaneous"
  3681. ["Use Intelligent Tab"
  3682. (progn (customize-set-variable 'vhdl-intelligent-tab
  3683. (not vhdl-intelligent-tab))
  3684. (vhdl-activate-customizations))
  3685. :style toggle :selected vhdl-intelligent-tab]
  3686. ["Indent Syntax-Based"
  3687. (customize-set-variable 'vhdl-indent-syntax-based
  3688. (not vhdl-indent-syntax-based))
  3689. :style toggle :selected vhdl-indent-syntax-based]
  3690. ["Indent Comments Like Next Code Line"
  3691. (customize-set-variable 'vhdl-indent-comment-like-next-code-line
  3692. (not vhdl-indent-comment-like-next-code-line))
  3693. :style toggle :selected vhdl-indent-comment-like-next-code-line]
  3694. ["Word Completion is Case Sensitive"
  3695. (customize-set-variable 'vhdl-word-completion-case-sensitive
  3696. (not vhdl-word-completion-case-sensitive))
  3697. :style toggle :selected vhdl-word-completion-case-sensitive]
  3698. ["Word Completion in Minibuffer"
  3699. (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
  3700. (not vhdl-word-completion-in-minibuffer))
  3701. (message "Activate new setting by saving options and restarting Emacs"))
  3702. :style toggle :selected vhdl-word-completion-in-minibuffer]
  3703. ["Underscore is Part of Word"
  3704. (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
  3705. (not vhdl-underscore-is-part-of-word))
  3706. (vhdl-activate-customizations))
  3707. :style toggle :selected vhdl-underscore-is-part-of-word]
  3708. "--"
  3709. ["Customize Group..." (customize-group 'vhdl-misc) t])
  3710. ["Related..." (customize-browse 'vhdl-related) t]
  3711. "--"
  3712. ["Save Options" customize-save-customized t]
  3713. ["Activate Options" vhdl-activate-customizations t]
  3714. ["Browse Options..." vhdl-customize t])))
  3715. (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
  3716. "VHDL Mode menu.")
  3717. (defun vhdl-update-mode-menu ()
  3718. "Update VHDL Mode menu."
  3719. (interactive)
  3720. (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
  3721. (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
  3722. (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
  3723. (easy-menu-define vhdl-mode-menu vhdl-mode-map
  3724. "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
  3725. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3726. ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
  3727. (defconst vhdl-imenu-generic-expression
  3728. '(
  3729. ("Subprogram"
  3730. "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
  3731. 4)
  3732. ("Instance"
  3733. "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(entity\\s-+\\(\\w\\|\\s_\\)+\\.\\)?\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
  3734. 1)
  3735. ("Component"
  3736. "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
  3737. 2)
  3738. ("Procedural"
  3739. "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
  3740. 1)
  3741. ("Process"
  3742. "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
  3743. 1)
  3744. ("Block"
  3745. "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
  3746. 1)
  3747. ("Package"
  3748. "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
  3749. 3)
  3750. ("Configuration"
  3751. "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
  3752. 2)
  3753. ("Architecture"
  3754. "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
  3755. 2)
  3756. ("Entity"
  3757. "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
  3758. 2)
  3759. )
  3760. "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
  3761. (defun vhdl-index-menu-init ()
  3762. "Initialize index menu."
  3763. (set (make-local-variable 'imenu-case-fold-search) t)
  3764. (set (make-local-variable 'imenu-generic-expression)
  3765. vhdl-imenu-generic-expression)
  3766. (when (and vhdl-index-menu (fboundp 'imenu))
  3767. (if (or (not (boundp 'font-lock-maximum-size))
  3768. (> font-lock-maximum-size (buffer-size)))
  3769. (imenu-add-to-menubar "Index")
  3770. (message "Scanning buffer for index...buffer too big"))))
  3771. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3772. ;; Source file menu (using `easy-menu.el')
  3773. (defvar vhdl-sources-menu nil)
  3774. (defun vhdl-directory-files (directory &optional full match)
  3775. "Call `directory-files' if DIRECTORY exists, otherwise generate error
  3776. message."
  3777. (if (not (file-directory-p directory))
  3778. (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
  3779. (let ((dir (directory-files directory full match)))
  3780. (setq dir (delete "." dir))
  3781. (setq dir (delete ".." dir))
  3782. dir)))
  3783. (defun vhdl-get-source-files (&optional full directory)
  3784. "Get list of VHDL source files in DIRECTORY or current directory."
  3785. (let ((mode-alist auto-mode-alist)
  3786. filename-regexp)
  3787. ;; create regular expressions for matching file names
  3788. (setq filename-regexp "\\`[^.].*\\(")
  3789. (while mode-alist
  3790. (when (eq (cdar mode-alist) 'vhdl-mode)
  3791. (setq filename-regexp
  3792. (concat filename-regexp (caar mode-alist) "\\|")))
  3793. (setq mode-alist (cdr mode-alist)))
  3794. (setq filename-regexp
  3795. (concat (substring filename-regexp 0
  3796. (string-match "\\\\|$" filename-regexp)) "\\)"))
  3797. ;; find files
  3798. (vhdl-directory-files
  3799. (or directory default-directory) full filename-regexp)))
  3800. (defun vhdl-add-source-files-menu ()
  3801. "Scan directory for all VHDL source files and generate menu.
  3802. The directory of the current source file is scanned."
  3803. (interactive)
  3804. (message "Scanning directory for source files ...")
  3805. (let ((newmap (current-local-map))
  3806. (file-list (vhdl-get-source-files))
  3807. menu-list found)
  3808. ;; Create list for menu
  3809. (setq found nil)
  3810. (while file-list
  3811. (setq found t)
  3812. (setq menu-list (cons (vector (car file-list)
  3813. (list 'find-file (car file-list)) t)
  3814. menu-list))
  3815. (setq file-list (cdr file-list)))
  3816. (setq menu-list (vhdl-menu-split menu-list "Sources"))
  3817. (when found (setq menu-list (cons "--" menu-list)))
  3818. (setq menu-list (cons ["*Rescan*" vhdl-add-source-files-menu t] menu-list))
  3819. (setq menu-list (cons "Sources" menu-list))
  3820. ;; Create menu
  3821. (easy-menu-add menu-list)
  3822. (easy-menu-define vhdl-sources-menu newmap
  3823. "VHDL source files menu" menu-list))
  3824. (message ""))
  3825. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3826. ;;; Mode definition
  3827. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3828. ;; performs all buffer local initializations
  3829. ;;;###autoload
  3830. (define-derived-mode vhdl-mode prog-mode
  3831. '("VHDL" (vhdl-electric-mode "/" (vhdl-stutter-mode "/"))
  3832. (vhdl-electric-mode "e")
  3833. (vhdl-stutter-mode "s"))
  3834. "Major mode for editing VHDL code.
  3835. Usage:
  3836. ------
  3837. TEMPLATE INSERTION (electrification):
  3838. After typing a VHDL keyword and entering `SPC', you are prompted for
  3839. arguments while a template is generated for that VHDL construct. Typing
  3840. `RET' or `C-g' at the first \(mandatory) prompt aborts the current
  3841. template generation. Optional arguments are indicated by square
  3842. brackets and removed if the queried string is left empty. Prompts for
  3843. mandatory arguments remain in the code if the queried string is left
  3844. empty. They can be queried again by `C-c C-t C-q'. Enabled
  3845. electrification is indicated by `/e' in the mode line.
  3846. Typing `M-SPC' after a keyword inserts a space without calling the
  3847. template generator. Automatic template generation (i.e.
  3848. electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
  3849. setting option `vhdl-electric-mode' (see OPTIONS).
  3850. Template generators can be invoked from the VHDL menu, by key
  3851. bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
  3852. the keyword (i.e. first word of menu entry not in parenthesis) and
  3853. `SPC'. The following abbreviations can also be used: arch, attr, cond,
  3854. conf, comp, cons, func, inst, pack, sig, var.
  3855. Template styles can be customized in customization group
  3856. `vhdl-template' \(see OPTIONS).
  3857. HEADER INSERTION:
  3858. A file header can be inserted by `C-c C-t C-h'. A file footer
  3859. (template at the end of the file) can be inserted by `C-c C-t C-f'.
  3860. See customization group `vhdl-header'.
  3861. STUTTERING:
  3862. Double striking of some keys inserts cumbersome VHDL syntax elements.
  3863. Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
  3864. option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
  3865. the mode line. The stuttering keys and their effects are:
  3866. ;; --> \" : \" [ --> ( -- --> comment
  3867. ;;; --> \" := \" [[ --> [ --CR --> comment-out code
  3868. .. --> \" => \" ] --> ) --- --> horizontal line
  3869. ,, --> \" <= \" ]] --> ] ---- --> display comment
  3870. == --> \" == \" '' --> \\\"
  3871. WORD COMPLETION:
  3872. Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
  3873. word in the buffer that starts alike, inserts it and adjusts case.
  3874. Re-typing `TAB' toggles through alternative word completions. This also
  3875. works in the minibuffer (i.e. in template generator prompts).
  3876. Typing `TAB' after `(' looks for and inserts complete parenthesized
  3877. expressions (e.g. for array index ranges). All keywords as well as
  3878. standard types and subprograms of VHDL have predefined abbreviations
  3879. \(e.g. type \"std\" and `TAB' will toggle through all standard types
  3880. beginning with \"std\").
  3881. Typing `TAB' after a non-word character indents the line if at the
  3882. beginning of a line (i.e. no preceding non-blank characters), and
  3883. inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
  3884. stop.
  3885. COMMENTS:
  3886. `--' puts a single comment.
  3887. `---' draws a horizontal line for separating code segments.
  3888. `----' inserts a display comment, i.e. two horizontal lines
  3889. with a comment in between.
  3890. `--CR' comments out code on that line. Re-hitting CR comments
  3891. out following lines.
  3892. `C-c C-c' comments out a region if not commented out,
  3893. uncomments a region if already commented out. Option
  3894. `comment-style' defines where the comment characters
  3895. should be placed (beginning of line, indent, etc.).
  3896. You are prompted for comments after object definitions (i.e. signals,
  3897. variables, constants, ports) and after subprogram and process
  3898. specifications if option `vhdl-prompt-for-comments' is non-nil.
  3899. Comments are automatically inserted as additional labels (e.g. after
  3900. begin statements) and as help comments if `vhdl-self-insert-comments' is
  3901. non-nil.
  3902. Inline comments (i.e. comments after a piece of code on the same line)
  3903. are indented at least to `vhdl-inline-comment-column'. Comments go at
  3904. maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
  3905. will open a new comment line. Typing beyond `vhdl-end-comment-column'
  3906. in a comment automatically opens a new comment line. `M-q' re-fills
  3907. multi-line comments.
  3908. INDENTATION:
  3909. `TAB' indents a line if at the beginning of the line. The amount of
  3910. indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
  3911. always indents the current line (is bound to `TAB' if option
  3912. `vhdl-intelligent-tab' is nil). If a region is active, `TAB' indents
  3913. the entire region.
  3914. Indentation can be done for a group of lines (`C-c C-i C-g'), a region
  3915. \(`M-C-\\') or the entire buffer (menu). Argument and port lists are
  3916. indented normally (nil) or relative to the opening parenthesis (non-nil)
  3917. according to option `vhdl-argument-list-indent'.
  3918. If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
  3919. tabs. `M-x tabify' and `M-x untabify' allow to convert spaces to tabs
  3920. and vice versa.
  3921. Syntax-based indentation can be very slow in large files. Option
  3922. `vhdl-indent-syntax-based' allows to use faster but simpler indentation.
  3923. Option `vhdl-indent-comment-like-next-code-line' controls whether
  3924. comment lines are indented like the preceding or like the following code
  3925. line.
  3926. ALIGNMENT:
  3927. The alignment functions align operators, keywords, and inline comments
  3928. to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
  3929. separated by blank lines, `C-c C-a C-i' a block of lines with same
  3930. indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
  3931. a pair of parentheses (e.g. port clause/map, argument list), and `C-c
  3932. C-a C-d' all lines within the declarative part of a design unit. `C-c
  3933. C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
  3934. for a group of lines, and `C-c C-a M-c' for a region.
  3935. If option `vhdl-align-groups' is non-nil, groups of code lines
  3936. separated by special lines (see option `vhdl-align-group-separate') are
  3937. aligned individually. If option `vhdl-align-same-indent' is non-nil,
  3938. blocks of lines with same indent are aligned separately. Some templates
  3939. are automatically aligned after generation if option `vhdl-auto-align'
  3940. is non-nil.
  3941. Alignment tries to align inline comments at
  3942. `vhdl-inline-comment-column' and tries inline comment not to exceed
  3943. `vhdl-end-comment-column'.
  3944. `C-c C-x M-w' fixes up whitespace in a region. That is, operator
  3945. symbols are surrounded by one space, and multiple spaces are eliminated.
  3946. CODE FILLING:
  3947. Code filling allows to condense code (e.g. sensitivity lists or port
  3948. maps) by removing comments and newlines and re-wrapping so that all
  3949. lines are maximally filled (block filling). `C-c C-f C-f' fills a list
  3950. enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
  3951. blank lines, `C-c C-f C-i' a block of lines with same indent, and
  3952. `C-c C-f M-f' an entire region.
  3953. CODE BEAUTIFICATION:
  3954. `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
  3955. buffer respectively. This includes indentation, alignment, and case
  3956. fixing. Code beautification can also be run non-interactively using the
  3957. command:
  3958. emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
  3959. PORT TRANSLATION:
  3960. Generic and port clauses from entity or component declarations can be
  3961. copied (`C-c C-p C-w') and pasted as entity and component declarations,
  3962. as component instantiations and corresponding internal constants and
  3963. signals, as a generic map with constants as actual generics, and as
  3964. internal signal initializations (menu).
  3965. To include formals in component instantiations, see option
  3966. `vhdl-association-list-with-formals'. To include comments in pasting,
  3967. see options `vhdl-include-...-comments'.
  3968. A clause with several generic/port names on the same line can be
  3969. flattened (`C-c C-p C-f') so that only one name per line exists. The
  3970. direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
  3971. outputs and vice versa, which can be useful in testbenches. (This
  3972. reversion is done on the internal data structure and is only reflected
  3973. in subsequent paste operations.)
  3974. Names for actual ports, instances, testbenches, and
  3975. design-under-test instances can be derived from existing names according
  3976. to options `vhdl-...-name'. See customization group `vhdl-port'.
  3977. SUBPROGRAM TRANSLATION:
  3978. Similar functionality exists for copying/pasting the interface of
  3979. subprograms (function/procedure). A subprogram interface can be copied
  3980. and then pasted as a subprogram declaration, body or call (uses
  3981. association list with formals).
  3982. TESTBENCH GENERATION:
  3983. A copied port can also be pasted as a testbench. The generated
  3984. testbench includes an entity, an architecture, and an optional
  3985. configuration. The architecture contains the component declaration and
  3986. instantiation of the DUT as well as internal constant and signal
  3987. declarations. Additional user-defined templates can be inserted. The
  3988. names used for entity/architecture/configuration/DUT as well as the file
  3989. structure to be generated can be customized. See customization group
  3990. `vhdl-testbench'.
  3991. KEY BINDINGS:
  3992. Key bindings (`C-c ...') exist for most commands (see in menu).
  3993. VHDL MENU:
  3994. All commands can be found in the VHDL menu including their key bindings.
  3995. FILE BROWSER:
  3996. The speedbar allows browsing of directories and file contents. It can
  3997. be accessed from the VHDL menu and is automatically opened if option
  3998. `vhdl-speedbar-auto-open' is non-nil.
  3999. In speedbar, open files and directories with `mouse-2' on the name and
  4000. browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
  4001. DESIGN HIERARCHY BROWSER:
  4002. The speedbar can also be used for browsing the hierarchy of design units
  4003. contained in the source files of the current directory or the specified
  4004. projects (see option `vhdl-project-alist').
  4005. The speedbar can be switched between file, directory hierarchy and
  4006. project hierarchy browsing mode in the speedbar menu or by typing `f',
  4007. `h' or `H' in speedbar.
  4008. In speedbar, open design units with `mouse-2' on the name and browse
  4009. their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
  4010. from entities and components (in packages). Individual design units and
  4011. complete designs can directly be compiled (\"Make\" menu entry).
  4012. The hierarchy is automatically updated upon saving a modified source
  4013. file when option `vhdl-speedbar-update-on-saving' is non-nil. The
  4014. hierarchy is only updated for projects that have been opened once in the
  4015. speedbar. The hierarchy is cached between Emacs sessions in a file (see
  4016. options in group `vhdl-speedbar').
  4017. Simple design consistency checks are done during scanning, such as
  4018. multiple declarations of the same unit or missing primary units that are
  4019. required by secondary units.
  4020. STRUCTURAL COMPOSITION:
  4021. Enables simple structural composition. `C-c C-m C-n' creates a skeleton
  4022. for a new component. Subcomponents (i.e. component declaration and
  4023. instantiation) can be automatically placed from a previously read port
  4024. \(`C-c C-m C-p') or directly from the hierarchy browser (`P'). Finally,
  4025. all subcomponents can be automatically connected using internal signals
  4026. and ports (`C-c C-m C-w') following these rules:
  4027. - subcomponent actual ports with same name are considered to be
  4028. connected by a signal (internal signal or port)
  4029. - signals that are only inputs to subcomponents are considered as
  4030. inputs to this component -> input port created
  4031. - signals that are only outputs from subcomponents are considered as
  4032. outputs from this component -> output port created
  4033. - signals that are inputs to AND outputs from subcomponents are
  4034. considered as internal connections -> internal signal created
  4035. Purpose: With appropriate naming conventions it is possible to
  4036. create higher design levels with only a few mouse clicks or key
  4037. strokes. A new design level can be created by simply generating a new
  4038. component, placing the required subcomponents from the hierarchy
  4039. browser, and wiring everything automatically.
  4040. Note: Automatic wiring only works reliably on templates of new
  4041. components and component instantiations that were created by VHDL mode.
  4042. Component declarations can be placed in a components package (option
  4043. `vhdl-use-components-package') which can be automatically generated for
  4044. an entire directory or project (`C-c C-m M-p'). The VHDL'93 direct
  4045. component instantiation is also supported (option
  4046. `vhdl-use-direct-instantiation').
  4047. Configuration declarations can automatically be generated either from
  4048. the menu (`C-c C-m C-f') (for the architecture the cursor is in) or from
  4049. the speedbar menu (for the architecture under the cursor). The
  4050. configurations can optionally be hierarchical (i.e. include all
  4051. component levels of a hierarchical design, option
  4052. `vhdl-compose-configuration-hierarchical') or include subconfigurations
  4053. (option `vhdl-compose-configuration-use-subconfiguration'). For
  4054. subcomponents in hierarchical configurations, the most-recently-analyzed
  4055. (mra) architecture is selected. If another architecture is desired, it
  4056. can be marked as most-recently-analyzed (speedbar menu) before
  4057. generating the configuration.
  4058. Note: Configurations of subcomponents (i.e. hierarchical configuration
  4059. declarations) are currently not considered when displaying
  4060. configurations in speedbar.
  4061. See the options group `vhdl-compose' for all relevant user options.
  4062. SOURCE FILE COMPILATION:
  4063. The syntax of the current buffer can be analyzed by calling a VHDL
  4064. compiler (menu, `C-c C-k'). The compiler to be used is specified by
  4065. option `vhdl-compiler'. The available compilers are listed in option
  4066. `vhdl-compiler-alist' including all required compilation command,
  4067. command options, compilation directory, and error message syntax
  4068. information. New compilers can be added.
  4069. All the source files of an entire design can be compiled by the `make'
  4070. command (menu, `C-c M-C-k') if an appropriate Makefile exists.
  4071. MAKEFILE GENERATION:
  4072. Makefiles can be generated automatically by an internal generation
  4073. routine (`C-c M-k'). The library unit dependency information is
  4074. obtained from the hierarchy browser. Makefile generation can be
  4075. customized for each compiler in option `vhdl-compiler-alist'.
  4076. Makefile generation can also be run non-interactively using the
  4077. command:
  4078. emacs -batch -l ~/.emacs -l vhdl-mode
  4079. [-compiler compilername] [-project projectname]
  4080. -f vhdl-generate-makefile
  4081. The Makefile's default target \"all\" compiles the entire design, the
  4082. target \"clean\" removes it and the target \"library\" creates the
  4083. library directory if not existent. These target names can be customized
  4084. by option `vhdl-makefile-default-targets'. The Makefile also includes a
  4085. target for each primary library unit which allows selective compilation
  4086. of this unit, its secondary units and its subhierarchy (example:
  4087. compilation of a design specified by a configuration). User specific
  4088. parts can be inserted into a Makefile with option
  4089. `vhdl-makefile-generation-hook'.
  4090. Limitations:
  4091. - Only library units and dependencies within the current library are
  4092. considered. Makefiles for designs that span multiple libraries are
  4093. not (yet) supported.
  4094. - Only one-level configurations are supported (also hierarchical),
  4095. but configurations that go down several levels are not.
  4096. - The \"others\" keyword in configurations is not supported.
  4097. PROJECTS:
  4098. Projects can be defined in option `vhdl-project-alist' and a current
  4099. project be selected using option `vhdl-project' (permanently) or from
  4100. the menu or speedbar (temporarily). For each project, title and
  4101. description strings (for the file headers), source files/directories
  4102. (for the hierarchy browser and Makefile generation), library name, and
  4103. compiler-dependent options, exceptions and compilation directory can be
  4104. specified. Compilation settings overwrite the settings of option
  4105. `vhdl-compiler-alist'.
  4106. Project setups can be exported (i.e. written to a file) and imported.
  4107. Imported setups are not automatically saved in `vhdl-project-alist' but
  4108. can be saved afterwards in its customization buffer. When starting
  4109. Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
  4110. vhdl-mode\") in a directory with an existing project setup file, it is
  4111. automatically loaded and its project activated if option
  4112. `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
  4113. files can be specified in option `vhdl-project-file-name'. Multiple
  4114. project setups can be automatically loaded from global directories.
  4115. This is an alternative to specifying project setups with option
  4116. `vhdl-project-alist'.
  4117. SPECIAL MENUES:
  4118. As an alternative to the speedbar, an index menu can be added (set
  4119. option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
  4120. (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
  4121. file) for browsing the file contents (is not populated if buffer is
  4122. larger than `font-lock-maximum-size'). Also, a source file menu can be
  4123. added (set option `vhdl-source-file-menu' to non-nil) for browsing the
  4124. current directory for VHDL source files.
  4125. VHDL STANDARDS:
  4126. The VHDL standards to be used are specified in option `vhdl-standard'.
  4127. Available standards are: VHDL'87/'93(02), VHDL-AMS, and Math Packages.
  4128. KEYWORD CASE:
  4129. Lower and upper case for keywords and standardized types, attributes,
  4130. and enumeration values is supported. If the option
  4131. `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
  4132. lower case and are converted into upper case automatically (not for
  4133. types, attributes, and enumeration values). The case of keywords,
  4134. types, attributes,and enumeration values can be fixed for an entire
  4135. region (menu) or buffer (`C-c C-x C-c') according to the options
  4136. `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
  4137. HIGHLIGHTING (fontification):
  4138. Keywords and standardized types, attributes, enumeration values, and
  4139. function names (controlled by option `vhdl-highlight-keywords'), as well
  4140. as comments, strings, and template prompts are highlighted using
  4141. different colors. Unit, subprogram, signal, variable, constant,
  4142. parameter and generic/port names in declarations as well as labels are
  4143. highlighted if option `vhdl-highlight-names' is non-nil.
  4144. Additional reserved words or words with a forbidden syntax (e.g. words
  4145. that should be avoided) can be specified in option
  4146. `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
  4147. a warning color (option `vhdl-highlight-forbidden-words'). Verilog
  4148. keywords are highlighted as forbidden words if option
  4149. `vhdl-highlight-verilog-keywords' is non-nil.
  4150. Words with special syntax can be highlighted by specifying their
  4151. syntax and color in option `vhdl-special-syntax-alist' and by setting
  4152. option `vhdl-highlight-special-words' to non-nil. This allows to
  4153. establish some naming conventions (e.g. to distinguish different kinds
  4154. of signals or other objects by using name suffices) and to support them
  4155. visually.
  4156. Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
  4157. to support case-sensitive highlighting. However, keywords are then only
  4158. highlighted if written in lower case.
  4159. Code between \"translate_off\" and \"translate_on\" pragmas is
  4160. highlighted using a different background color if option
  4161. `vhdl-highlight-translate-off' is non-nil.
  4162. For documentation and customization of the used colors see
  4163. customization group `vhdl-highlight-faces' (`M-x customize-group'). For
  4164. highlighting of matching parenthesis, see customization group
  4165. `paren-showing'. Automatic buffer highlighting is turned on/off by
  4166. option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
  4167. USER MODELS:
  4168. VHDL models (templates) can be specified by the user and made accessible
  4169. in the menu, through key bindings (`C-c C-m ...'), or by keyword
  4170. electrification. See option `vhdl-model-alist'.
  4171. HIDE/SHOW:
  4172. The code of blocks, processes, subprograms, component declarations and
  4173. instantiations, generic/port clauses, and configuration declarations can
  4174. be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
  4175. the code (see customization group `vhdl-menu'). XEmacs: limited
  4176. functionality due to old `hideshow.el' package.
  4177. CODE UPDATING:
  4178. - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
  4179. current process, `C-c C-u M-s' of all processes in the current buffer.
  4180. Limitations:
  4181. - Only declared local signals (ports, signals declared in
  4182. architecture and blocks) are automatically inserted.
  4183. - Global signals declared in packages are not automatically inserted.
  4184. Insert them once manually (will be kept afterwards).
  4185. - Out parameters of procedures are considered to be read.
  4186. Use option `vhdl-entity-file-name' to specify the entity file name
  4187. \(used to obtain the port names).
  4188. Use option `vhdl-array-index-record-field-in-sensitivity-list' to
  4189. specify whether to include array indices and record fields in
  4190. sensitivity lists.
  4191. CODE FIXING:
  4192. `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
  4193. \(e.g. if the closing parenthesis is on the wrong line or is missing).
  4194. PRINTING:
  4195. PostScript printing with different faces (an optimized set of faces is
  4196. used if `vhdl-print-customize-faces' is non-nil) or colors \(if
  4197. `ps-print-color-p' is non-nil) is possible using the standard Emacs
  4198. PostScript printing commands. Option `vhdl-print-two-column' defines
  4199. appropriate default settings for nice landscape two-column printing.
  4200. The paper format can be set by option `ps-paper-type'. Do not forget to
  4201. switch `ps-print-color-p' to nil for printing on black-and-white
  4202. printers.
  4203. OPTIONS:
  4204. User options allow customization of VHDL Mode. All options are
  4205. accessible from the \"Options\" menu entry. Simple options (switches
  4206. and choices) can directly be changed, while for complex options a
  4207. customization buffer is opened. Changed options can be saved for future
  4208. sessions using the \"Save Options\" menu entry.
  4209. Options and their detailed descriptions can also be accessed by using
  4210. the \"Customize\" menu entry or the command `M-x customize-option' (`M-x
  4211. customize-group' for groups). Some customizations only take effect
  4212. after some action (read the NOTE in the option documentation).
  4213. Customization can also be done globally (i.e. site-wide, read the
  4214. INSTALL file).
  4215. Not all options are described in this documentation, so go and see
  4216. what other useful user options there are (`M-x vhdl-customize' or menu)!
  4217. FILE EXTENSIONS:
  4218. As default, files with extensions \".vhd\" and \".vhdl\" are
  4219. automatically recognized as VHDL source files. To add an extension
  4220. \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
  4221. \(setq auto-mode-alist (cons '(\"\\\\.xxx\\\\'\" . vhdl-mode) auto-mode-alist))
  4222. HINTS:
  4223. - To start Emacs with open VHDL hierarchy browser without having to load
  4224. a VHDL file first, use the command:
  4225. emacs -l vhdl-mode -f speedbar-frame-mode
  4226. - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
  4227. - Some features only work on properly indented code.
  4228. RELEASE NOTES:
  4229. See also the release notes (menu) for added features in new releases.
  4230. Maintenance:
  4231. ------------
  4232. To submit a bug report, enter `M-x vhdl-submit-bug-report' within VHDL Mode.
  4233. Add a description of the problem and include a reproducible test case.
  4234. Questions and enhancement requests can be sent to <reto@gnu.org>.
  4235. The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
  4236. The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
  4237. releases. You are kindly invited to participate in beta testing. Subscribe
  4238. to above mailing lists by sending an email to <reto@gnu.org>.
  4239. VHDL Mode is officially distributed at
  4240. http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html
  4241. where the latest version can be found.
  4242. Known problems:
  4243. ---------------
  4244. - XEmacs: Incorrect start-up when automatically opening speedbar.
  4245. - XEmacs: Indentation in XEmacs 21.4 (and higher).
  4246. - Indentation incorrect for new 'postponed' VHDL keyword.
  4247. - Indentation incorrect for 'protected body' construct.
  4248. The VHDL Mode Authors
  4249. Reto Zimmermann and Rod Whitby
  4250. Key bindings:
  4251. -------------
  4252. \\{vhdl-mode-map}"
  4253. :abbrev-table vhdl-mode-abbrev-table
  4254. ;; set local variables
  4255. (set (make-local-variable 'paragraph-start)
  4256. "\\s-*\\(--+\\s-*$\\|[^ -]\\|$\\)")
  4257. (set (make-local-variable 'paragraph-separate) paragraph-start)
  4258. (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
  4259. (set (make-local-variable 'parse-sexp-ignore-comments) t)
  4260. (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
  4261. (set (make-local-variable 'comment-start) "--")
  4262. (set (make-local-variable 'comment-end) "")
  4263. (when vhdl-emacs-21
  4264. (set (make-local-variable 'comment-padding) ""))
  4265. (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
  4266. (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
  4267. (set (make-local-variable 'comment-start-skip) "--+\\s-*")
  4268. (set (make-local-variable 'comment-multi-line) nil)
  4269. (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
  4270. (set (make-local-variable 'hippie-expand-verbose) nil)
  4271. ;; setup the comment indent variable in a Emacs version portable way
  4272. ;; ignore any byte compiler warnings you might get here
  4273. (when (boundp 'comment-indent-function)
  4274. (set (make-local-variable 'comment-indent-function) 'vhdl-comment-indent))
  4275. ;; initialize font locking
  4276. (set (make-local-variable 'font-lock-defaults)
  4277. (list
  4278. '(nil vhdl-font-lock-keywords) nil
  4279. (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line))
  4280. (if (eval-when-compile (fboundp 'syntax-propertize-rules))
  4281. (set (make-local-variable 'syntax-propertize-function)
  4282. (syntax-propertize-rules
  4283. ;; Mark single quotes as having string quote syntax in
  4284. ;; 'c' instances.
  4285. ("\\(\'\\).\\(\'\\)" (1 "\"'") (2 "\"'"))))
  4286. (set (make-local-variable 'font-lock-syntactic-keywords)
  4287. vhdl-font-lock-syntactic-keywords))
  4288. (unless vhdl-emacs-21
  4289. (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
  4290. (set (make-local-variable 'lazy-lock-defer-contextually) nil)
  4291. (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
  4292. ; (set (make-local-variable 'lazy-lock-defer-time) 0.1)
  4293. (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
  4294. ; (turn-on-font-lock)
  4295. ;; variables for source file compilation
  4296. (when vhdl-compile-use-local-error-regexp
  4297. (set (make-local-variable 'compilation-error-regexp-alist) nil)
  4298. (set (make-local-variable 'compilation-file-regexp-alist) nil))
  4299. ;; add index menu
  4300. (vhdl-index-menu-init)
  4301. ;; add source file menu
  4302. (if vhdl-source-file-menu (vhdl-add-source-files-menu))
  4303. ;; add VHDL menu
  4304. (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
  4305. (easy-menu-define vhdl-mode-menu vhdl-mode-map
  4306. "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
  4307. ;; initialize hideshow and add menu
  4308. (vhdl-hideshow-init)
  4309. (run-hooks 'menu-bar-update-hook)
  4310. ;; miscellaneous
  4311. (vhdl-ps-print-init)
  4312. (vhdl-write-file-hooks-init)
  4313. (message "VHDL Mode %s.%s" vhdl-version
  4314. (if noninteractive "" " See menu for documentation and release notes.")))
  4315. (defun vhdl-activate-customizations ()
  4316. "Activate all customizations on local variables."
  4317. (interactive)
  4318. (vhdl-mode-map-init)
  4319. (use-local-map vhdl-mode-map)
  4320. (set-syntax-table vhdl-mode-syntax-table)
  4321. (setq comment-column vhdl-inline-comment-column)
  4322. (setq end-comment-column vhdl-end-comment-column)
  4323. (vhdl-write-file-hooks-init)
  4324. (vhdl-update-mode-menu)
  4325. (vhdl-hideshow-init)
  4326. (run-hooks 'menu-bar-update-hook))
  4327. (defun vhdl-write-file-hooks-init ()
  4328. "Add/remove hooks when buffer is saved."
  4329. (if vhdl-modify-date-on-saving
  4330. (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror nil t)
  4331. (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror t))
  4332. (if (featurep 'xemacs) (make-local-hook 'after-save-hook))
  4333. (add-hook 'after-save-hook 'vhdl-add-modified-file nil t))
  4334. (defun vhdl-process-command-line-option (option)
  4335. "Process command line options for VHDL Mode."
  4336. (cond
  4337. ;; set compiler
  4338. ((equal option "-compiler")
  4339. (vhdl-set-compiler (car command-line-args-left))
  4340. (setq command-line-args-left (cdr command-line-args-left)))
  4341. ;; set project
  4342. ((equal option "-project")
  4343. (vhdl-set-project (car command-line-args-left))
  4344. (setq command-line-args-left (cdr command-line-args-left)))))
  4345. ;; make Emacs process VHDL Mode options
  4346. (setq command-switch-alist
  4347. (append command-switch-alist
  4348. '(("-compiler" . vhdl-process-command-line-option)
  4349. ("-project" . vhdl-process-command-line-option))))
  4350. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4351. ;;; Keywords and standardized words
  4352. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4353. (defconst vhdl-02-keywords
  4354. '(
  4355. "abs" "access" "after" "alias" "all" "and" "architecture" "array"
  4356. "assert" "attribute"
  4357. "begin" "block" "body" "buffer" "bus"
  4358. "case" "component" "configuration" "constant"
  4359. "disconnect" "downto"
  4360. "else" "elsif" "end" "entity" "exit"
  4361. "file" "for" "function"
  4362. "generate" "generic" "group" "guarded"
  4363. "if" "impure" "in" "inertial" "inout" "is"
  4364. "label" "library" "linkage" "literal" "loop"
  4365. "map" "mod"
  4366. "nand" "new" "next" "nor" "not" "null"
  4367. "of" "on" "open" "or" "others" "out"
  4368. "package" "port" "postponed" "procedure" "process" "protected" "pure"
  4369. "range" "record" "register" "reject" "rem" "report" "return"
  4370. "rol" "ror"
  4371. "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
  4372. "then" "to" "transport" "type"
  4373. "unaffected" "units" "until" "use"
  4374. "variable"
  4375. "wait" "when" "while" "with"
  4376. "xnor" "xor"
  4377. )
  4378. "List of VHDL'02 keywords.")
  4379. (defconst vhdl-ams-keywords
  4380. '(
  4381. "across" "break" "limit" "nature" "noise" "procedural" "quantity"
  4382. "reference" "spectrum" "subnature" "terminal" "through"
  4383. "tolerance"
  4384. )
  4385. "List of VHDL-AMS keywords.")
  4386. (defconst vhdl-verilog-keywords
  4387. '(
  4388. "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
  4389. "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
  4390. "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
  4391. "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
  4392. "endprimitive" "endspecify" "endtable" "endtask" "event"
  4393. "for" "force" "forever" "fork" "function"
  4394. "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
  4395. "macromodule" "makefile" "medium" "module"
  4396. "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
  4397. "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
  4398. "pullup"
  4399. "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
  4400. "rtranif0" "rtranif1"
  4401. "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
  4402. "strong1" "supply" "supply0" "supply1"
  4403. "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
  4404. "triand" "trior" "trireg"
  4405. "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
  4406. )
  4407. "List of Verilog keywords as candidate for additional reserved words.")
  4408. (defconst vhdl-02-types
  4409. '(
  4410. "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
  4411. "real" "time" "natural" "positive" "string" "line" "text" "side"
  4412. "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
  4413. "std_logic" "std_logic_vector"
  4414. "std_ulogic" "std_ulogic_vector"
  4415. )
  4416. "List of VHDL'02 standardized types.")
  4417. (defconst vhdl-ams-types
  4418. ;; standards: IEEE Std 1076.1-2007, IEEE Std 1076.1.1-2004
  4419. '(
  4420. ;; package `standard'
  4421. "domain_type" "real_vector"
  4422. ;; package `energy_systems'
  4423. "energy" "power" "periodicity" "real_across" "real_through" "unspecified"
  4424. "unspecified_vector" "energy_vector" "power_vector" "periodicity_vector"
  4425. "real_across_vector" "real_through_vector"
  4426. ;; package `electrical_systems'
  4427. "voltage" "current" "charge" "resistance" "conductance" "capacitance"
  4428. "mmf" "electric_flux" "electric_flux_density" "electric_field_strength"
  4429. "magnetic_flux" "magnetic_flux_density" "magnetic_field_strength"
  4430. "inductance" "reluctance" "electrical" "electrical_vector" "magnetic"
  4431. "magnetic_vector" "voltage_vector" "current_vector" "mmf_vector"
  4432. "magnetic_flux_vector" "charge_vector" "resistance_vector"
  4433. "conductance_vector" "capacitance_vector" "electric_flux_vector"
  4434. "electric_flux_density_vector" "electric_field_strength_vector"
  4435. "magnetic_flux_density_vector" "magnetic_field_strength_vector"
  4436. "inductance_vector" "reluctance_vector" "ground"
  4437. ;; package `mechanical_systems'
  4438. "displacement" "force" "velocity" "acceleration" "mass" "stiffness"
  4439. "damping" "momentum" "angle" "torque" "angular_velocity"
  4440. "angular_acceleration" "moment_inertia" "angular_momentum"
  4441. "angular_stiffness" "angular_damping" "translational"
  4442. "translational_vector" "translational_velocity"
  4443. "translational_velocity_vector" "rotational" "rotational_vector"
  4444. "rotational_velocity" "rotational_velocity_vector" "displacement_vector"
  4445. "force_vector" "velocity_vector" "force_velocity_vector" "angle_vector"
  4446. "torque_vector" "angular_velocity_vector" "torque_velocity_vector"
  4447. "acceleration_vector" "mass_vector" "stiffness_vector" "damping_vector"
  4448. "momentum_vector" "angular_acceleration_vector" "moment_inertia_vector"
  4449. "angular_momentum_vector" "angular_stiffness_vector"
  4450. "angular_damping_vector" "anchor" "translational_v_ref"
  4451. "rotational_v_ref" "translational_v" "rotational_v"
  4452. ;; package `radiant_systems'
  4453. "illuminance" "luminous_flux" "luminous_intensity" "irradiance" "radiant"
  4454. "radiant_vector" "luminous_intensity_vector" "luminous_flux_vector"
  4455. "illuminance_vector" "irradiance_vector"
  4456. ;; package `thermal_systems'
  4457. "temperature" "heat_flow" "thermal_capacitance" "thermal_resistance"
  4458. "thermal_conductance" "thermal" "thermal_vector" "temperature_vector"
  4459. "heat_flow_vector" "thermal_capacitance_vector"
  4460. "thermal_resistance_vector" "thermal_conductance_vector"
  4461. ;; package `fluidic_systems'
  4462. "pressure" "vflow_rate" "mass_flow_rate" "volume" "density" "viscosity"
  4463. "fresistance" "fconductance" "fcapacitance" "inertance" "cfresistance"
  4464. "cfcapacitance" "cfinertance" "cfconductance" "fluidic" "fluidic_vector"
  4465. "compressible_fluidic" "compressible_fluidic_vector" "pressure_vector"
  4466. "vflow_rate_vector" "mass_flow_rate_vector" "volume_vector"
  4467. "density_vector" "viscosity_vector" "fresistance_vector"
  4468. "fconductance_vector" "fcapacitance_vector" "inertance_vector"
  4469. "cfresistance_vector" "cfconductance_vector" "cfcapacitance_vector"
  4470. "cfinertance_vector"
  4471. )
  4472. "List of VHDL-AMS standardized types.")
  4473. (defconst vhdl-math-types
  4474. '(
  4475. "complex" "complex_polar" "positive_real" "principal_value"
  4476. )
  4477. "List of Math Packages standardized types.")
  4478. (defconst vhdl-02-attributes
  4479. '(
  4480. "base" "left" "right" "high" "low" "pos" "val" "succ"
  4481. "pred" "leftof" "rightof" "range" "reverse_range"
  4482. "length" "delayed" "stable" "quiet" "transaction"
  4483. "event" "active" "last_event" "last_active" "last_value"
  4484. "driving" "driving_value" "ascending" "value" "image"
  4485. "simple_name" "instance_name" "path_name"
  4486. "foreign"
  4487. )
  4488. "List of VHDL'02 standardized attributes.")
  4489. (defconst vhdl-ams-attributes
  4490. '(
  4491. "across" "through"
  4492. "reference" "contribution" "tolerance"
  4493. "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
  4494. "ramp" "slew"
  4495. )
  4496. "List of VHDL-AMS standardized attributes.")
  4497. (defconst vhdl-02-enum-values
  4498. '(
  4499. "true" "false"
  4500. "note" "warning" "error" "failure"
  4501. "read_mode" "write_mode" "append_mode"
  4502. "open_ok" "status_error" "name_error" "mode_error"
  4503. "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
  4504. "right" "left"
  4505. )
  4506. "List of VHDL'02 standardized enumeration values.")
  4507. (defconst vhdl-ams-enum-values
  4508. '(
  4509. "quiescent_domain" "time_domain" "frequency_domain"
  4510. ;; from `nature_pkg' package
  4511. "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
  4512. )
  4513. "List of VHDL-AMS standardized enumeration values.")
  4514. (defconst vhdl-ams-constants
  4515. ;; standard: IEEE Std 1076.1.1-2004
  4516. '(
  4517. ;; package `fundamental_constants'
  4518. "phys_q" "phys_eps0" "phys_mu0" "phys_k" "phys_gravity" "phys_ctok"
  4519. "phys_c" "phys_h" "phys_h_over_2_pi" "yocto" "zepto" "atto" "femto"
  4520. "pico" "nano" "micro" "milli" "centi" "deci" "deka" "hecto" "kilo" "mega"
  4521. "giga" "tera" "peta" "exa" "zetta" "yotta" "deca"
  4522. ;; package `material_constants'
  4523. "phys_eps_si" "phys_eps_sio2" "phys_e_si" "phys_e_sio2" "phys_e_poly"
  4524. "phys_nu_si" "phys_nu_poly" "phys_rho_poly" "phys_rho_sio2"
  4525. "ambient_temperature" "ambient_pressure" "ambient_illuminance"
  4526. )
  4527. "List of VHDL-AMS standardized constants.")
  4528. (defconst vhdl-math-constants
  4529. ;; standard: IEEE Std 1076.2-1996
  4530. '(
  4531. "math_1_over_e" "math_1_over_pi" "math_1_over_sqrt_2" "math_2_pi"
  4532. "math_3_pi_over_2" "math_cbase_1" "math_cbase_j" "math_czero"
  4533. "math_deg_to_rad" "math_e" "math_log10_of_e" "math_log2_of_e"
  4534. "math_log_of_10" "math_log_of_2" "math_pi" "math_pi_over_2"
  4535. "math_pi_over_3" "math_pi_over_4" "math_rad_to_deg" "math_sqrt_2"
  4536. "math_sqrt_pi"
  4537. )
  4538. "List of Math Packages standardized constants.")
  4539. (defconst vhdl-02-functions
  4540. '(
  4541. "now" "resolved" "rising_edge" "falling_edge"
  4542. "read" "readline" "hread" "oread" "write" "writeline" "hwrite" "owrite"
  4543. "endfile"
  4544. "resize" "is_X" "std_match"
  4545. "shift_left" "shift_right" "rotate_left" "rotate_right"
  4546. "to_unsigned" "to_signed" "to_integer"
  4547. "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
  4548. "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
  4549. "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
  4550. "shl" "shr" "ext" "sxt"
  4551. "deallocate"
  4552. )
  4553. "List of VHDL'02 standardized functions.")
  4554. (defconst vhdl-ams-functions
  4555. '(
  4556. ;; package `standard'
  4557. "frequency"
  4558. )
  4559. "List of VHDL-AMS standardized functions.")
  4560. (defconst vhdl-math-functions
  4561. ;; standard: IEEE Std 1076.2-1996
  4562. '(
  4563. "arccos" "arccosh" "arcsin" "arcsinh" "arctan" "arctanh" "arg"
  4564. "cbrt" "ceil" "cmplx" "complex_to_polar" "conj" "cos" "cosh" "exp"
  4565. "floor" "get_principal_value" "log" "log10" "log2" "polar_to_complex"
  4566. "realmax" "realmin" "round" "sign" "sin" "sinh" "sqrt"
  4567. "tan" "tanh" "trunc" "uniform"
  4568. )
  4569. "List of Math Packages standardized functions.")
  4570. (defconst vhdl-02-packages
  4571. '(
  4572. "std_logic_1164" "numeric_std" "numeric_bit"
  4573. "standard" "textio"
  4574. "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
  4575. "std_logic_misc" "std_logic_textio"
  4576. "ieee" "std" "work"
  4577. )
  4578. "List of VHDL'02 standardized packages and libraries.")
  4579. (defconst vhdl-ams-packages
  4580. '(
  4581. "fundamental_constants" "material_constants" "energy_systems"
  4582. "electrical_systems" "mechanical_systems" "radiant_systems"
  4583. "thermal_systems" "fluidic_systems"
  4584. )
  4585. "List of VHDL-AMS standardized packages and libraries.")
  4586. (defconst vhdl-math-packages
  4587. '(
  4588. "math_real" "math_complex"
  4589. )
  4590. "List of Math Packages standardized packages and libraries.")
  4591. (defvar vhdl-keywords nil
  4592. "List of VHDL keywords.")
  4593. (defvar vhdl-types nil
  4594. "List of VHDL standardized types.")
  4595. (defvar vhdl-attributes nil
  4596. "List of VHDL standardized attributes.")
  4597. (defvar vhdl-enum-values nil
  4598. "List of VHDL standardized enumeration values.")
  4599. (defvar vhdl-constants nil
  4600. "List of VHDL standardized constants.")
  4601. (defvar vhdl-functions nil
  4602. "List of VHDL standardized functions.")
  4603. (defvar vhdl-packages nil
  4604. "List of VHDL standardized packages and libraries.")
  4605. (defvar vhdl-reserved-words nil
  4606. "List of additional reserved words.")
  4607. (defvar vhdl-keywords-regexp nil
  4608. "Regexp for VHDL keywords.")
  4609. (defvar vhdl-types-regexp nil
  4610. "Regexp for VHDL standardized types.")
  4611. (defvar vhdl-attributes-regexp nil
  4612. "Regexp for VHDL standardized attributes.")
  4613. (defvar vhdl-enum-values-regexp nil
  4614. "Regexp for VHDL standardized enumeration values.")
  4615. (defvar vhdl-constants-regexp nil
  4616. "Regexp for VHDL standardized constants.")
  4617. (defvar vhdl-functions-regexp nil
  4618. "Regexp for VHDL standardized functions.")
  4619. (defvar vhdl-packages-regexp nil
  4620. "Regexp for VHDL standardized packages and libraries.")
  4621. (defvar vhdl-reserved-words-regexp nil
  4622. "Regexp for additional reserved words.")
  4623. (defvar vhdl-directive-keywords-regexp nil
  4624. "Regexp for compiler directive keywords.")
  4625. (defun vhdl-upcase-list (condition list)
  4626. "Upcase all elements in LIST based on CONDITION."
  4627. (when condition
  4628. (let ((tmp-list list))
  4629. (while tmp-list
  4630. (setcar tmp-list (upcase (car tmp-list)))
  4631. (setq tmp-list (cdr tmp-list)))))
  4632. list)
  4633. (defun vhdl-words-init ()
  4634. "Initialize reserved words."
  4635. (setq vhdl-keywords
  4636. (vhdl-upcase-list
  4637. (and vhdl-highlight-case-sensitive vhdl-upper-case-keywords)
  4638. (append vhdl-02-keywords
  4639. (when (vhdl-standard-p 'ams) vhdl-ams-keywords))))
  4640. (setq vhdl-types
  4641. (vhdl-upcase-list
  4642. (and vhdl-highlight-case-sensitive vhdl-upper-case-types)
  4643. (append vhdl-02-types
  4644. (when (vhdl-standard-p 'ams) vhdl-ams-types)
  4645. (when (vhdl-standard-p 'math) vhdl-math-types))))
  4646. (setq vhdl-attributes
  4647. (vhdl-upcase-list
  4648. (and vhdl-highlight-case-sensitive vhdl-upper-case-attributes)
  4649. (append vhdl-02-attributes
  4650. (when (vhdl-standard-p 'ams) vhdl-ams-attributes))))
  4651. (setq vhdl-enum-values
  4652. (vhdl-upcase-list
  4653. (and vhdl-highlight-case-sensitive vhdl-upper-case-enum-values)
  4654. (append vhdl-02-enum-values
  4655. (when (vhdl-standard-p 'ams) vhdl-ams-enum-values))))
  4656. (setq vhdl-constants
  4657. (vhdl-upcase-list
  4658. (and vhdl-highlight-case-sensitive vhdl-upper-case-constants)
  4659. (append (when (vhdl-standard-p 'ams) vhdl-ams-constants)
  4660. (when (vhdl-standard-p 'math) vhdl-math-constants)
  4661. '(""))))
  4662. (setq vhdl-functions
  4663. (append vhdl-02-functions
  4664. (when (vhdl-standard-p 'ams) vhdl-ams-functions)
  4665. (when (vhdl-standard-p 'math) vhdl-math-functions)))
  4666. (setq vhdl-packages
  4667. (append vhdl-02-packages
  4668. (when (vhdl-standard-p 'ams) vhdl-ams-packages)
  4669. (when (vhdl-standard-p 'math) vhdl-math-packages)))
  4670. (setq vhdl-reserved-words
  4671. (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
  4672. (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
  4673. '("")))
  4674. (setq vhdl-keywords-regexp
  4675. (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
  4676. (setq vhdl-types-regexp
  4677. (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
  4678. (setq vhdl-attributes-regexp
  4679. (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
  4680. (setq vhdl-enum-values-regexp
  4681. (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
  4682. (setq vhdl-constants-regexp
  4683. (concat "\\<\\(" (regexp-opt vhdl-constants) "\\)\\>"))
  4684. (setq vhdl-functions-regexp
  4685. (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
  4686. (setq vhdl-packages-regexp
  4687. (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
  4688. (setq vhdl-reserved-words-regexp
  4689. (concat "\\<\\("
  4690. (unless (equal vhdl-forbidden-syntax "")
  4691. (concat vhdl-forbidden-syntax "\\|"))
  4692. (regexp-opt vhdl-reserved-words)
  4693. "\\)\\>"))
  4694. (setq vhdl-directive-keywords-regexp
  4695. (concat "\\<\\(" (mapconcat 'regexp-quote
  4696. vhdl-directive-keywords "\\|") "\\)\\>"))
  4697. (vhdl-abbrev-list-init))
  4698. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4699. ;; Words to expand
  4700. (defvar vhdl-abbrev-list nil
  4701. "Predefined abbreviations for VHDL.")
  4702. (defun vhdl-abbrev-list-init ()
  4703. (setq vhdl-abbrev-list
  4704. (append
  4705. (list vhdl-upper-case-keywords) vhdl-keywords
  4706. (list vhdl-upper-case-types) vhdl-types
  4707. (list vhdl-upper-case-attributes) vhdl-attributes
  4708. (list vhdl-upper-case-enum-values) vhdl-enum-values
  4709. (list vhdl-upper-case-constants) vhdl-constants
  4710. (list nil) vhdl-functions
  4711. (list nil) vhdl-packages)))
  4712. ;; initialize reserved words for VHDL Mode
  4713. (vhdl-words-init)
  4714. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4715. ;;; Indentation
  4716. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4717. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4718. ;; Syntax analysis
  4719. ;; constant regular expressions for looking at various constructs
  4720. (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
  4721. "Regexp describing a VHDL symbol.
  4722. We cannot use just `word' syntax class since `_' cannot be in word
  4723. class. Putting underscore in word class breaks forward word movement
  4724. behavior that users are familiar with.")
  4725. (defconst vhdl-case-header-key "case[( \t\n\r\f][^;=>]+[) \t\n\r\f]is"
  4726. "Regexp describing a case statement header key.")
  4727. (defconst vhdl-label-key
  4728. (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
  4729. "Regexp describing a VHDL label.")
  4730. ;; Macro definitions:
  4731. (defmacro vhdl-point (position)
  4732. "Return the value of point at certain commonly referenced POSITIONs.
  4733. POSITION can be one of the following symbols:
  4734. bol -- beginning of line
  4735. eol -- end of line
  4736. bod -- beginning of defun
  4737. boi -- back to indentation
  4738. eoi -- last whitespace on line
  4739. ionl -- indentation of next line
  4740. iopl -- indentation of previous line
  4741. bonl -- beginning of next line
  4742. bopl -- beginning of previous line
  4743. This function does not modify point or mark."
  4744. (or (and (eq 'quote (car-safe position))
  4745. (null (cddr position)))
  4746. (error "ERROR: Bad buffer position requested: %s" position))
  4747. (setq position (nth 1 position))
  4748. `(let ((here (point)))
  4749. ,@(cond
  4750. ((eq position 'bol) '((beginning-of-line)))
  4751. ((eq position 'eol) '((end-of-line)))
  4752. ((eq position 'bod) '((save-match-data
  4753. (vhdl-beginning-of-defun))))
  4754. ((eq position 'boi) '((back-to-indentation)))
  4755. ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
  4756. ((eq position 'bonl) '((forward-line 1)))
  4757. ((eq position 'bopl) '((forward-line -1)))
  4758. ((eq position 'iopl)
  4759. '((forward-line -1)
  4760. (back-to-indentation)))
  4761. ((eq position 'ionl)
  4762. '((forward-line 1)
  4763. (back-to-indentation)))
  4764. (t (error "ERROR: Unknown buffer position requested: %s" position))
  4765. )
  4766. (prog1
  4767. (point)
  4768. (goto-char here))
  4769. ;; workaround for an Emacs18 bug -- blech! Well, at least it
  4770. ;; doesn't hurt for v19
  4771. ,@nil
  4772. ))
  4773. (defmacro vhdl-safe (&rest body)
  4774. "Safely execute BODY, return nil if an error occurred."
  4775. `(condition-case nil
  4776. (progn ,@body)
  4777. (error nil)))
  4778. (defmacro vhdl-add-syntax (symbol &optional relpos)
  4779. "A simple macro to append the syntax in SYMBOL to the syntax list.
  4780. Try to increase performance by using this macro."
  4781. `(setq vhdl-syntactic-context
  4782. (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
  4783. (defmacro vhdl-has-syntax (symbol)
  4784. "A simple macro to return check the syntax list.
  4785. Try to increase performance by using this macro."
  4786. `(assoc ,symbol vhdl-syntactic-context))
  4787. ;; Syntactic element offset manipulation:
  4788. (defun vhdl-read-offset (langelem)
  4789. "Read new offset value for LANGELEM from minibuffer.
  4790. Return a valid value only."
  4791. (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
  4792. (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
  4793. (prompt "Offset: ")
  4794. offset input interned)
  4795. (while (not offset)
  4796. (setq input (read-string prompt oldoff)
  4797. offset (cond ((string-equal "+" input) '+)
  4798. ((string-equal "-" input) '-)
  4799. ((string-equal "++" input) '++)
  4800. ((string-equal "--" input) '--)
  4801. ((string-match "^-?[0-9]+$" input)
  4802. (string-to-number input))
  4803. ((fboundp (setq interned (intern input)))
  4804. interned)
  4805. ((boundp interned) interned)
  4806. ;; error, but don't signal one, keep trying
  4807. ;; to read an input value
  4808. (t (ding)
  4809. (setq prompt errmsg)
  4810. nil))))
  4811. offset))
  4812. (defun vhdl-set-offset (symbol offset &optional add-p)
  4813. "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
  4814. SYMBOL is the syntactic element symbol to change and OFFSET is the new
  4815. offset for that syntactic element. Optional ADD-P says to add SYMBOL to
  4816. `vhdl-offsets-alist' if it doesn't already appear there."
  4817. (interactive
  4818. (let* ((langelem
  4819. (intern (completing-read
  4820. (concat "Syntactic symbol to change"
  4821. (if current-prefix-arg " or add" "")
  4822. ": ")
  4823. (mapcar
  4824. (function
  4825. (lambda (langelem)
  4826. (cons (format "%s" (car langelem)) nil)))
  4827. vhdl-offsets-alist)
  4828. nil (not current-prefix-arg)
  4829. ;; initial contents tries to be the last element
  4830. ;; on the syntactic analysis list for the current
  4831. ;; line
  4832. (let* ((syntax (vhdl-get-syntactic-context))
  4833. (len (length syntax))
  4834. (ic (format "%s" (car (nth (1- len) syntax)))))
  4835. ic)
  4836. )))
  4837. (offset (vhdl-read-offset langelem)))
  4838. (list langelem offset current-prefix-arg)))
  4839. ;; sanity check offset
  4840. (or (eq offset '+)
  4841. (eq offset '-)
  4842. (eq offset '++)
  4843. (eq offset '--)
  4844. (integerp offset)
  4845. (fboundp offset)
  4846. (boundp offset)
  4847. (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
  4848. offset))
  4849. (let ((entry (assq symbol vhdl-offsets-alist)))
  4850. (if entry
  4851. (setcdr entry offset)
  4852. (if add-p
  4853. (setq vhdl-offsets-alist
  4854. (cons (cons symbol offset) vhdl-offsets-alist))
  4855. (error "ERROR: %s is not a valid syntactic symbol" symbol))))
  4856. (vhdl-keep-region-active))
  4857. (defun vhdl-set-style (style &optional local)
  4858. "Set `vhdl-mode' variables to use one of several different indentation styles.
  4859. STYLE is a string representing the desired style and optional LOCAL is
  4860. a flag which, if non-nil, means to make the style variables being
  4861. changed buffer local, instead of the default, which is to set the
  4862. global variables. Interactively, the flag comes from the prefix
  4863. argument. The styles are chosen from the `vhdl-style-alist' variable."
  4864. (interactive (list (completing-read "Use which VHDL indentation style? "
  4865. vhdl-style-alist nil t)
  4866. current-prefix-arg))
  4867. (let ((vars (cdr (assoc style vhdl-style-alist))))
  4868. (or vars
  4869. (error "ERROR: Invalid VHDL indentation style `%s'" style))
  4870. ;; set all the variables
  4871. (mapc
  4872. (function
  4873. (lambda (varentry)
  4874. (let ((var (car varentry))
  4875. (val (cdr varentry)))
  4876. ;; special case for vhdl-offsets-alist
  4877. (if (not (eq var 'vhdl-offsets-alist))
  4878. (set (if local (make-local-variable var) var) val)
  4879. ;; reset vhdl-offsets-alist to the default value first
  4880. (set (if local (make-local-variable var) var)
  4881. (copy-alist vhdl-offsets-alist-default))
  4882. ;; now set the langelems that are different
  4883. (mapcar
  4884. (function
  4885. (lambda (langentry)
  4886. (let ((langelem (car langentry))
  4887. (offset (cdr langentry)))
  4888. (vhdl-set-offset langelem offset)
  4889. )))
  4890. val))
  4891. )))
  4892. vars))
  4893. (vhdl-keep-region-active))
  4894. (defun vhdl-get-offset (langelem)
  4895. "Get offset from LANGELEM which is a cons cell of the form:
  4896. \(SYMBOL . RELPOS). The symbol is matched against
  4897. vhdl-offsets-alist and the offset found there is either returned,
  4898. or added to the indentation at RELPOS. If RELPOS is nil, then
  4899. the offset is simply returned."
  4900. (let* ((symbol (car langelem))
  4901. (relpos (cdr langelem))
  4902. (match (assq symbol vhdl-offsets-alist))
  4903. (offset (cdr-safe match)))
  4904. ;; offset can be a number, a function, a variable, or one of the
  4905. ;; symbols + or -
  4906. (cond
  4907. ((not match)
  4908. (if vhdl-strict-syntax-p
  4909. (error "ERROR: Don't know how to indent a %s" symbol)
  4910. (setq offset 0
  4911. relpos 0)))
  4912. ((eq offset '+) (setq offset vhdl-basic-offset))
  4913. ((eq offset '-) (setq offset (- vhdl-basic-offset)))
  4914. ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
  4915. ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
  4916. ((and (not (numberp offset))
  4917. (fboundp offset))
  4918. (setq offset (funcall offset langelem)))
  4919. ((not (numberp offset))
  4920. (setq offset (eval offset)))
  4921. )
  4922. (+ (if (and relpos
  4923. (< relpos (vhdl-point 'bol)))
  4924. (save-excursion
  4925. (goto-char relpos)
  4926. (current-column))
  4927. 0)
  4928. offset)))
  4929. ;; Syntactic support functions:
  4930. (defun vhdl-in-comment-p ()
  4931. "Check if point is in a comment."
  4932. (eq (vhdl-in-literal) 'comment))
  4933. (defun vhdl-in-string-p ()
  4934. "Check if point is in a string."
  4935. (eq (vhdl-in-literal) 'string))
  4936. (defun vhdl-in-quote-p ()
  4937. "Check if point is in a quote ('x')."
  4938. (or (and (> (point) (point-min))
  4939. (< (1+ (point)) (point-max))
  4940. (= (char-before (point)) ?\')
  4941. (= (char-after (1+ (point))) ?\'))
  4942. (and (> (1- (point)) (point-min))
  4943. (< (point) (point-max))
  4944. (= (char-before (1- (point))) ?\')
  4945. (= (char-after (point)) ?\'))))
  4946. (defun vhdl-in-literal ()
  4947. "Determine if point is in a VHDL literal."
  4948. (save-excursion
  4949. (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
  4950. (cond
  4951. ((nth 3 state) 'string)
  4952. ((nth 4 state) 'comment)
  4953. ((vhdl-beginning-of-macro) 'pound)
  4954. (t nil)))))
  4955. (defun vhdl-in-extended-identifier-p ()
  4956. "Determine if point is inside extended identifier (delimited by '\')."
  4957. (save-match-data
  4958. (and (save-excursion (re-search-backward "\\\\" (vhdl-point 'bol) t))
  4959. (save-excursion (re-search-forward "\\\\" (vhdl-point 'eol) t)))))
  4960. (defun vhdl-forward-comment (&optional direction)
  4961. "Skip all comments (including whitespace). Skip backwards if DIRECTION is
  4962. negative, skip forward otherwise."
  4963. (interactive "p")
  4964. (if (and direction (< direction 0))
  4965. ;; skip backwards
  4966. (progn
  4967. (skip-chars-backward " \t\n\r\f")
  4968. (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
  4969. (goto-char (match-beginning 3))
  4970. (skip-chars-backward " \t\n\r\f")))
  4971. ;; skip forwards
  4972. (skip-chars-forward " \t\n\r\f")
  4973. (while (looking-at "--.*")
  4974. (goto-char (match-end 0))
  4975. (skip-chars-forward " \t\n\r\f"))))
  4976. ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
  4977. (unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
  4978. (defalias 'vhdl-forward-comment 'forward-comment))
  4979. (defun vhdl-back-to-indentation ()
  4980. "Move point to the first non-whitespace character on this line."
  4981. (interactive)
  4982. (beginning-of-line 1)
  4983. (skip-syntax-forward " " (vhdl-point 'eol)))
  4984. ;; XEmacs hack: work around old `back-to-indentation' in XEmacs
  4985. (when (featurep 'xemacs)
  4986. (defalias 'back-to-indentation 'vhdl-back-to-indentation))
  4987. ;; This is the best we can do in Win-Emacs.
  4988. (defun vhdl-win-il (&optional lim)
  4989. "Determine if point is in a VHDL literal."
  4990. (save-excursion
  4991. (let* ((here (point))
  4992. (state nil)
  4993. (match nil)
  4994. (lim (or lim (vhdl-point 'bod))))
  4995. (goto-char lim )
  4996. (while (< (point) here)
  4997. (setq match
  4998. (and (re-search-forward "--\\|[\"']"
  4999. here 'move)
  5000. (buffer-substring (match-beginning 0) (match-end 0))))
  5001. (setq state
  5002. (cond
  5003. ;; no match
  5004. ((null match) nil)
  5005. ;; looking at the opening of a VHDL style comment
  5006. ((string= "--" match)
  5007. (if (<= here (progn (end-of-line) (point))) 'comment))
  5008. ;; looking at the opening of a double quote string
  5009. ((string= "\"" match)
  5010. (if (not (save-restriction
  5011. ;; this seems to be necessary since the
  5012. ;; re-search-forward will not work without it
  5013. (narrow-to-region (point) here)
  5014. (re-search-forward
  5015. ;; this regexp matches a double quote
  5016. ;; which is preceded by an even number
  5017. ;; of backslashes, including zero
  5018. "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
  5019. 'string))
  5020. ;; looking at the opening of a single quote string
  5021. ((string= "'" match)
  5022. (if (not (save-restriction
  5023. ;; see comments from above
  5024. (narrow-to-region (point) here)
  5025. (re-search-forward
  5026. ;; this matches a single quote which is
  5027. ;; preceded by zero or two backslashes.
  5028. "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
  5029. here 'move)))
  5030. 'string))
  5031. (t nil)))
  5032. ) ; end-while
  5033. state)))
  5034. (and (string-match "Win-Emacs" emacs-version)
  5035. (fset 'vhdl-in-literal 'vhdl-win-il))
  5036. ;; Skipping of "syntactic whitespace". Syntactic whitespace is
  5037. ;; defined as lexical whitespace or comments. Search no farther back
  5038. ;; or forward than optional LIM. If LIM is omitted, (point-min) is
  5039. ;; used for backward skipping, (point-max) is used for forward
  5040. ;; skipping.
  5041. (defun vhdl-forward-syntactic-ws (&optional lim)
  5042. "Forward skip of syntactic whitespace."
  5043. (let* ((here (point-max))
  5044. (hugenum (point-max)))
  5045. (while (/= here (point))
  5046. (setq here (point))
  5047. (vhdl-forward-comment hugenum)
  5048. ;; skip preprocessor directives
  5049. (when (and (eq (char-after) ?#)
  5050. (= (vhdl-point 'boi) (point)))
  5051. (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
  5052. (= (forward-line 1) 0)))
  5053. (end-of-line)))
  5054. (if lim (goto-char (min (point) lim)))))
  5055. ;; This is the best we can do in Win-Emacs.
  5056. (defun vhdl-win-fsws (&optional lim)
  5057. "Forward skip syntactic whitespace for Win-Emacs."
  5058. (let ((lim (or lim (point-max)))
  5059. stop)
  5060. (while (not stop)
  5061. (skip-chars-forward " \t\n\r\f" lim)
  5062. (cond
  5063. ;; vhdl comment
  5064. ((looking-at "--") (end-of-line))
  5065. ;; none of the above
  5066. (t (setq stop t))))))
  5067. (and (string-match "Win-Emacs" emacs-version)
  5068. (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
  5069. (defun vhdl-beginning-of-macro (&optional lim)
  5070. "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
  5071. (let ((here (point)))
  5072. (beginning-of-line)
  5073. (while (eq (char-before (1- (point))) ?\\)
  5074. (forward-line -1))
  5075. (back-to-indentation)
  5076. (if (and (<= (point) here)
  5077. (eq (char-after) ?#))
  5078. t
  5079. (goto-char here)
  5080. nil)))
  5081. (defun vhdl-backward-syntactic-ws (&optional lim)
  5082. "Backward skip over syntactic whitespace."
  5083. (let* ((here (point-min))
  5084. (hugenum (- (point-max))))
  5085. (while (/= here (point))
  5086. (setq here (point))
  5087. (vhdl-forward-comment hugenum)
  5088. (vhdl-beginning-of-macro))
  5089. (if lim (goto-char (max (point) lim)))))
  5090. ;; This is the best we can do in Win-Emacs.
  5091. (defun vhdl-win-bsws (&optional lim)
  5092. "Backward skip syntactic whitespace for Win-Emacs."
  5093. (let ((lim (or lim (vhdl-point 'bod)))
  5094. stop)
  5095. (while (not stop)
  5096. (skip-chars-backward " \t\n\r\f" lim)
  5097. (cond
  5098. ;; vhdl comment
  5099. ((eq (vhdl-in-literal) 'comment)
  5100. (skip-chars-backward "^-" lim)
  5101. (skip-chars-backward "-" lim)
  5102. (while (not (or (and (= (following-char) ?-)
  5103. (= (char-after (1+ (point))) ?-))
  5104. (<= (point) lim)))
  5105. (skip-chars-backward "^-" lim)
  5106. (skip-chars-backward "-" lim)))
  5107. ;; none of the above
  5108. (t (setq stop t))))))
  5109. (and (string-match "Win-Emacs" emacs-version)
  5110. (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
  5111. ;; Functions to help finding the correct indentation column:
  5112. (defun vhdl-first-word (point)
  5113. "If the keyword at POINT is at boi, then return (current-column) at
  5114. that point, else nil."
  5115. (save-excursion
  5116. (and (goto-char point)
  5117. (eq (point) (vhdl-point 'boi))
  5118. (current-column))))
  5119. (defun vhdl-last-word (point)
  5120. "If the keyword at POINT is at eoi, then return (current-column) at
  5121. that point, else nil."
  5122. (save-excursion
  5123. (and (goto-char point)
  5124. (save-excursion (or (eq (progn (forward-sexp) (point))
  5125. (vhdl-point 'eoi))
  5126. (looking-at "\\s-*\\(--\\)?")))
  5127. (current-column))))
  5128. ;; Core syntactic evaluation functions:
  5129. (defconst vhdl-libunit-re
  5130. "\\b\\(architecture\\|configuration\\|entity\\|package\\)\\b[^_]")
  5131. (defun vhdl-libunit-p ()
  5132. (and
  5133. (save-excursion
  5134. (forward-sexp)
  5135. (skip-chars-forward " \t\n\r\f")
  5136. (not (looking-at "is\\b[^_]")))
  5137. (save-excursion
  5138. (backward-sexp)
  5139. (and (not (looking-at "use\\b[^_]"))
  5140. (progn
  5141. (forward-sexp)
  5142. (vhdl-forward-syntactic-ws)
  5143. (/= (following-char) ?:))))
  5144. ))
  5145. (defconst vhdl-defun-re
  5146. "\\b\\(architecture\\|block\\|configuration\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
  5147. (defun vhdl-defun-p ()
  5148. (save-excursion
  5149. (if (looking-at "block\\|process\\|procedural")
  5150. ;; "block", "process", "procedural":
  5151. (save-excursion
  5152. (backward-sexp)
  5153. (not (looking-at "end\\s-+\\w")))
  5154. ;; "architecture", "configuration", "entity",
  5155. ;; "package", "procedure", "function":
  5156. t)))
  5157. (defun vhdl-corresponding-defun ()
  5158. "If the word at the current position corresponds to a \"defun\"
  5159. keyword, then return a string that can be used to find the
  5160. corresponding \"begin\" keyword, else return nil."
  5161. (save-excursion
  5162. (and (looking-at vhdl-defun-re)
  5163. (vhdl-defun-p)
  5164. (if (looking-at "block\\|process\\|procedural")
  5165. ;; "block", "process". "procedural:
  5166. (buffer-substring (match-beginning 0) (match-end 0))
  5167. ;; "architecture", "configuration", "entity", "package",
  5168. ;; "procedure", "function":
  5169. "is"))))
  5170. (defconst vhdl-begin-fwd-re
  5171. "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\(\\s-+body\\)?\\|units\\|use\\|record\\|protected\\(\\s-+body\\)?\\|for\\)\\b\\([^_]\\|\\'\\)"
  5172. "A regular expression for searching forward that matches all known
  5173. \"begin\" keywords.")
  5174. (defconst vhdl-begin-bwd-re
  5175. "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\(\\s-+body\\)?\\|units\\|use\\|record\\|protected\\(\\s-+body\\)?\\|for\\)\\b[^_]"
  5176. "A regular expression for searching backward that matches all known
  5177. \"begin\" keywords.")
  5178. (defun vhdl-begin-p (&optional lim)
  5179. "Return t if we are looking at a real \"begin\" keyword.
  5180. Assumes that the caller will make sure that we are looking at
  5181. vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
  5182. the middle of an identifier that just happens to contain a \"begin\"
  5183. keyword."
  5184. (cond
  5185. ;; "[architecture|case|configuration|entity|package|
  5186. ;; procedure|function] ... is":
  5187. ((and (looking-at "i")
  5188. (save-excursion
  5189. ;; Skip backward over first sexp (needed to skip over a
  5190. ;; procedure interface list, and is harmless in other
  5191. ;; situations). Note that we need "return" in the
  5192. ;; following search list so that we don't run into
  5193. ;; semicolons in the function interface list.
  5194. (backward-sexp)
  5195. (let (foundp)
  5196. (while (and (not foundp)
  5197. (re-search-backward
  5198. ";\\|\\b\\(architecture\\|case\\|configuration\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
  5199. lim 'move))
  5200. (if (or (= (preceding-char) ?_)
  5201. (vhdl-in-literal))
  5202. (backward-char)
  5203. (setq foundp t))))
  5204. (and (/= (following-char) ?\;)
  5205. (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
  5206. t)
  5207. ;; "begin", "then", "use":
  5208. ((looking-at "be\\|t\\|use")
  5209. t)
  5210. ;; "else":
  5211. ((and (looking-at "e")
  5212. ;; make sure that the "else" isn't inside a
  5213. ;; conditional signal assignment.
  5214. (save-excursion
  5215. (vhdl-re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
  5216. (or (eq (following-char) ?\;)
  5217. (eq (point) lim))))
  5218. t)
  5219. ;; "block", "generate", "loop", "process", "procedural",
  5220. ;; "units", "record", "protected body":
  5221. ((and (looking-at "block\\|generate\\|loop\\|process\\|procedural\\|protected\\(\\s-+body\\)?\\|units\\|record")
  5222. (save-excursion
  5223. (backward-sexp)
  5224. (not (looking-at "end\\s-+\\w"))))
  5225. t)
  5226. ;; "component":
  5227. ((and (looking-at "c")
  5228. (save-excursion
  5229. (backward-sexp)
  5230. (not (looking-at "end\\s-+\\w")))
  5231. ;; look out for the dreaded entity class in an attribute
  5232. (save-excursion
  5233. (vhdl-backward-syntactic-ws lim)
  5234. (/= (preceding-char) ?:)))
  5235. t)
  5236. ;; "for" (inside configuration declaration):
  5237. ((and (looking-at "f")
  5238. (save-excursion
  5239. (backward-sexp)
  5240. (not (looking-at "end\\s-+\\w")))
  5241. (vhdl-has-syntax 'configuration))
  5242. t)
  5243. ))
  5244. (defun vhdl-corresponding-mid (&optional lim)
  5245. (cond
  5246. ((looking-at "is\\|block\\|generate\\|process\\|procedural")
  5247. "begin")
  5248. ((looking-at "then\\|use")
  5249. "<else>")
  5250. (t
  5251. "end")))
  5252. (defun vhdl-corresponding-end (&optional lim)
  5253. "If the word at the current position corresponds to a \"begin\"
  5254. keyword, then return a vector containing enough information to find
  5255. the corresponding \"end\" keyword, else return nil. The keyword to
  5256. search forward for is aref 0. The column in which the keyword must
  5257. appear is aref 1 or nil if any column is suitable.
  5258. Assumes that the caller will make sure that we are not in the middle
  5259. of an identifier that just happens to contain a \"begin\" keyword."
  5260. (save-excursion
  5261. (and (looking-at vhdl-begin-fwd-re)
  5262. (or (not (looking-at "\\<use\\>"))
  5263. (save-excursion (back-to-indentation)
  5264. (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
  5265. (/= (preceding-char) ?_)
  5266. (not (vhdl-in-literal))
  5267. (vhdl-begin-p lim)
  5268. (cond
  5269. ;; "is", "generate", "loop":
  5270. ((looking-at "[igl]")
  5271. (vector "end"
  5272. (and (vhdl-last-word (point))
  5273. (or (vhdl-first-word (point))
  5274. (save-excursion
  5275. (vhdl-beginning-of-statement-1 lim)
  5276. (vhdl-backward-skip-label lim)
  5277. (vhdl-first-word (point)))))))
  5278. ;; "begin", "else", "for":
  5279. ((looking-at "be\\|[ef]")
  5280. (vector "end"
  5281. (and (vhdl-last-word (point))
  5282. (or (vhdl-first-word (point))
  5283. (save-excursion
  5284. (vhdl-beginning-of-statement-1 lim)
  5285. (vhdl-backward-skip-label lim)
  5286. (vhdl-first-word (point)))))))
  5287. ;; "component", "units", "record", "protected body":
  5288. ((looking-at "component\\|units\\|protected\\(\\s-+body\\)?\\|record")
  5289. ;; The first end found will close the block
  5290. (vector "end" nil))
  5291. ;; "block", "process", "procedural":
  5292. ((looking-at "bl\\|p")
  5293. (vector "end"
  5294. (or (vhdl-first-word (point))
  5295. (save-excursion
  5296. (vhdl-beginning-of-statement-1 lim)
  5297. (vhdl-backward-skip-label lim)
  5298. (vhdl-first-word (point))))))
  5299. ;; "then":
  5300. ((looking-at "t\\|use")
  5301. (vector "elsif\\|else\\|end\\s-+\\(if\\|use\\)"
  5302. (and (vhdl-last-word (point))
  5303. (or (vhdl-first-word (point))
  5304. (save-excursion
  5305. (vhdl-beginning-of-statement-1 lim)
  5306. (vhdl-backward-skip-label lim)
  5307. (vhdl-first-word (point)))))))
  5308. ))))
  5309. (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
  5310. (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
  5311. (defun vhdl-end-p (&optional lim)
  5312. "Return t if we are looking at a real \"end\" keyword.
  5313. Assumes that the caller will make sure that we are looking at
  5314. vhdl-end-fwd-re, and are not inside a literal, and that we are not in
  5315. the middle of an identifier that just happens to contain an \"end\"
  5316. keyword."
  5317. (or (not (looking-at "else"))
  5318. ;; make sure that the "else" isn't inside a conditional signal
  5319. ;; assignment.
  5320. (save-excursion
  5321. (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
  5322. (or (eq (following-char) ?\;)
  5323. (eq (point) lim)
  5324. (vhdl-in-literal)))))
  5325. (defun vhdl-corresponding-begin (&optional lim)
  5326. "If the word at the current position corresponds to an \"end\"
  5327. keyword, then return a vector containing enough information to find
  5328. the corresponding \"begin\" keyword, else return nil. The keyword to
  5329. search backward for is aref 0. The column in which the keyword must
  5330. appear is aref 1 or nil if any column is suitable. The supplementary
  5331. keyword to search forward for is aref 2 or nil if this is not
  5332. required. If aref 3 is t, then the \"begin\" keyword may be found in
  5333. the middle of a statement.
  5334. Assumes that the caller will make sure that we are not in the middle
  5335. of an identifier that just happens to contain an \"end\" keyword."
  5336. (save-excursion
  5337. (let (pos)
  5338. (if (and (looking-at vhdl-end-fwd-re)
  5339. (not (vhdl-in-literal))
  5340. (vhdl-end-p lim))
  5341. (if (looking-at "el")
  5342. ;; "else", "elsif":
  5343. (vector "if\\|elsif" (vhdl-first-word (point)) "then\\|use" nil)
  5344. ;; "end ...":
  5345. (setq pos (point))
  5346. (forward-sexp)
  5347. (skip-chars-forward " \t\n\r\f")
  5348. (cond
  5349. ;; "end if":
  5350. ((looking-at "if\\b[^_]")
  5351. (vector "else\\|elsif\\|if"
  5352. (vhdl-first-word pos)
  5353. "else\\|then\\|use" nil))
  5354. ;; "end component":
  5355. ((looking-at "component\\b[^_]")
  5356. (vector (buffer-substring (match-beginning 1)
  5357. (match-end 1))
  5358. (vhdl-first-word pos)
  5359. nil nil))
  5360. ;; "end units", "end record", "end protected":
  5361. ((looking-at "\\(units\\|record\\|protected\\(\\s-+body\\)?\\)\\b[^_]")
  5362. (vector (buffer-substring (match-beginning 1)
  5363. (match-end 1))
  5364. (vhdl-first-word pos)
  5365. nil t))
  5366. ;; "end block", "end process", "end procedural":
  5367. ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
  5368. (vector "begin" (vhdl-first-word pos) nil nil))
  5369. ;; "end case":
  5370. ((looking-at "case\\b[^_]")
  5371. (vector "case" (vhdl-first-word pos) "is" nil))
  5372. ;; "end generate":
  5373. ((looking-at "generate\\b[^_]")
  5374. (vector "generate\\|for\\|if"
  5375. (vhdl-first-word pos)
  5376. "generate" nil))
  5377. ;; "end loop":
  5378. ((looking-at "loop\\b[^_]")
  5379. (vector "loop\\|while\\|for"
  5380. (vhdl-first-word pos)
  5381. "loop" nil))
  5382. ;; "end for" (inside configuration declaration):
  5383. ((looking-at "for\\b[^_]")
  5384. (vector "for" (vhdl-first-word pos) nil nil))
  5385. ;; "end [id]":
  5386. (t
  5387. (vector "begin\\|architecture\\|configuration\\|entity\\|package\\|procedure\\|function"
  5388. (vhdl-first-word pos)
  5389. ;; return an alist of (statement . keyword) mappings
  5390. '(
  5391. ;; "begin ... end [id]":
  5392. ("begin" . nil)
  5393. ;; "architecture ... is ... begin ... end [id]":
  5394. ("architecture" . "is")
  5395. ;; "configuration ... is ... end [id]":
  5396. ("configuration" . "is")
  5397. ;; "entity ... is ... end [id]":
  5398. ("entity" . "is")
  5399. ;; "package ... is ... end [id]":
  5400. ("package" . "is")
  5401. ;; "procedure ... is ... begin ... end [id]":
  5402. ("procedure" . "is")
  5403. ;; "function ... is ... begin ... end [id]":
  5404. ("function" . "is")
  5405. )
  5406. nil))
  5407. ))) ; "end ..."
  5408. )))
  5409. (defconst vhdl-leader-re
  5410. "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
  5411. (defun vhdl-end-of-leader ()
  5412. (save-excursion
  5413. (cond ((looking-at "block\\|process\\|procedural")
  5414. (if (save-excursion
  5415. (forward-sexp)
  5416. (skip-chars-forward " \t\n\r\f")
  5417. (= (following-char) ?\())
  5418. (forward-sexp 2)
  5419. (forward-sexp))
  5420. (when (looking-at "[ \t\n\r\f]*is")
  5421. (goto-char (match-end 0)))
  5422. (point))
  5423. ((looking-at "component")
  5424. (forward-sexp 2)
  5425. (when (looking-at "[ \t\n\r\f]*is")
  5426. (goto-char (match-end 0)))
  5427. (point))
  5428. ((looking-at "for")
  5429. (forward-sexp 2)
  5430. (skip-chars-forward " \t\n\r\f")
  5431. (while (looking-at "[,:(]")
  5432. (forward-sexp)
  5433. (skip-chars-forward " \t\n\r\f"))
  5434. (point))
  5435. (t nil)
  5436. )))
  5437. (defconst vhdl-trailer-re
  5438. "\\b\\(is\\|then\\|generate\\|loop\\|record\\|protected\\(\\s-+body\\)?\\|use\\)\\b[^_]")
  5439. (defconst vhdl-statement-fwd-re
  5440. "\\b\\(if\\|for\\|while\\|loop\\)\\b\\([^_]\\|\\'\\)"
  5441. "A regular expression for searching forward that matches all known
  5442. \"statement\" keywords.")
  5443. (defconst vhdl-statement-bwd-re
  5444. "\\b\\(if\\|for\\|while\\|loop\\)\\b[^_]"
  5445. "A regular expression for searching backward that matches all known
  5446. \"statement\" keywords.")
  5447. (defun vhdl-statement-p (&optional lim)
  5448. "Return t if we are looking at a real \"statement\" keyword.
  5449. Assumes that the caller will make sure that we are looking at
  5450. vhdl-statement-fwd-re, and are not inside a literal, and that we are not
  5451. in the middle of an identifier that just happens to contain a
  5452. \"statement\" keyword."
  5453. (cond
  5454. ;; "for" ... "generate":
  5455. ((and (looking-at "f")
  5456. ;; Make sure it's the start of a parameter specification.
  5457. (save-excursion
  5458. (forward-sexp 2)
  5459. (skip-chars-forward " \t\n\r\f")
  5460. (looking-at "in\\b[^_]"))
  5461. ;; Make sure it's not an "end for".
  5462. (save-excursion
  5463. (backward-sexp)
  5464. (not (looking-at "end\\s-+\\w"))))
  5465. t)
  5466. ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
  5467. ((and (looking-at "i")
  5468. ;; Make sure it's not an "end if".
  5469. (save-excursion
  5470. (backward-sexp)
  5471. (not (looking-at "end\\s-+\\w"))))
  5472. t)
  5473. ;; "while" ... "loop":
  5474. ((looking-at "w")
  5475. t)
  5476. ))
  5477. (defconst vhdl-case-alternative-re "when[( \t\n\r\f][^;=>]+=>"
  5478. "Regexp describing a case statement alternative key.")
  5479. (defun vhdl-case-alternative-p (&optional lim)
  5480. "Return t if we are looking at a real case alternative.
  5481. Assumes that the caller will make sure that we are looking at
  5482. vhdl-case-alternative-re, and are not inside a literal, and that
  5483. we are not in the middle of an identifier that just happens to
  5484. contain a \"when\" keyword."
  5485. (save-excursion
  5486. (let (foundp)
  5487. (while (and (not foundp)
  5488. (re-search-backward ";\\|<=" lim 'move))
  5489. (if (or (= (preceding-char) ?_)
  5490. (vhdl-in-literal))
  5491. (backward-char)
  5492. (setq foundp t)))
  5493. (or (eq (following-char) ?\;)
  5494. (eq (point) lim)))
  5495. ))
  5496. ;; Core syntactic movement functions:
  5497. (defconst vhdl-b-t-b-re
  5498. (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
  5499. (defun vhdl-backward-to-block (&optional lim)
  5500. "Move backward to the previous \"begin\" or \"end\" keyword."
  5501. (let (foundp)
  5502. (while (and (not foundp)
  5503. (re-search-backward vhdl-b-t-b-re lim 'move))
  5504. (if (or (= (preceding-char) ?_)
  5505. (vhdl-in-literal))
  5506. (backward-char)
  5507. (cond
  5508. ;; "begin" keyword:
  5509. ((and (looking-at vhdl-begin-fwd-re)
  5510. (or (not (looking-at "\\<use\\>"))
  5511. (save-excursion (back-to-indentation)
  5512. (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
  5513. (/= (preceding-char) ?_)
  5514. (vhdl-begin-p lim))
  5515. (setq foundp 'begin))
  5516. ;; "end" keyword:
  5517. ((and (looking-at vhdl-end-fwd-re)
  5518. (/= (preceding-char) ?_)
  5519. (vhdl-end-p lim))
  5520. (setq foundp 'end))
  5521. ))
  5522. )
  5523. foundp
  5524. ))
  5525. (defun vhdl-forward-sexp (&optional count lim)
  5526. "Move forward across one balanced expression (sexp).
  5527. With COUNT, do it that many times."
  5528. (interactive "p")
  5529. (let ((count (or count 1))
  5530. (case-fold-search t)
  5531. end-vec target)
  5532. (save-excursion
  5533. (while (> count 0)
  5534. ;; skip whitespace
  5535. (skip-chars-forward " \t\n\r\f")
  5536. ;; Check for an unbalanced "end" keyword
  5537. (if (and (looking-at vhdl-end-fwd-re)
  5538. (/= (preceding-char) ?_)
  5539. (not (vhdl-in-literal))
  5540. (vhdl-end-p lim)
  5541. (not (looking-at "else")))
  5542. (error
  5543. "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
  5544. ;; If the current keyword is a "begin" keyword, then find the
  5545. ;; corresponding "end" keyword.
  5546. (if (setq end-vec (vhdl-corresponding-end lim))
  5547. (let (
  5548. ;; end-re is the statement keyword to search for
  5549. (end-re
  5550. (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
  5551. ;; column is either the statement keyword target column
  5552. ;; or nil
  5553. (column (aref end-vec 1))
  5554. (eol (vhdl-point 'eol))
  5555. foundp literal placeholder)
  5556. ;; Look for the statement keyword.
  5557. (while (and (not foundp)
  5558. (re-search-forward end-re nil t)
  5559. (setq placeholder (match-end 1))
  5560. (goto-char (match-beginning 0)))
  5561. ;; If we are in a literal, or not in the right target
  5562. ;; column and not on the same line as the begin, then
  5563. ;; try again.
  5564. (if (or (and column
  5565. (/= (current-indentation) column)
  5566. (> (point) eol))
  5567. (= (preceding-char) ?_)
  5568. (setq literal (vhdl-in-literal)))
  5569. (if (eq literal 'comment)
  5570. (end-of-line)
  5571. (forward-char))
  5572. ;; An "else" keyword corresponds to both the opening brace
  5573. ;; of the following sexp and the closing brace of the
  5574. ;; previous sexp.
  5575. (if (not (looking-at "else"))
  5576. (goto-char placeholder))
  5577. (setq foundp t))
  5578. )
  5579. (if (not foundp)
  5580. (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
  5581. )
  5582. ;; If the current keyword is not a "begin" keyword, then just
  5583. ;; perform the normal forward-sexp.
  5584. (forward-sexp)
  5585. )
  5586. (setq count (1- count))
  5587. )
  5588. (setq target (point)))
  5589. (goto-char target)
  5590. nil))
  5591. (defun vhdl-backward-sexp (&optional count lim)
  5592. "Move backward across one balanced expression (sexp).
  5593. With COUNT, do it that many times. LIM bounds any required backward
  5594. searches."
  5595. (interactive "p")
  5596. (let ((count (or count 1))
  5597. (case-fold-search t)
  5598. begin-vec target)
  5599. (save-excursion
  5600. (while (> count 0)
  5601. ;; Perform the normal backward-sexp, unless we are looking at
  5602. ;; "else" - an "else" keyword corresponds to both the opening brace
  5603. ;; of the following sexp and the closing brace of the previous sexp.
  5604. (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
  5605. (/= (preceding-char) ?_)
  5606. (not (vhdl-in-literal)))
  5607. nil
  5608. (backward-sexp)
  5609. (if (and (looking-at vhdl-begin-fwd-re)
  5610. (or (not (looking-at "\\<use\\>"))
  5611. (save-excursion
  5612. (back-to-indentation)
  5613. (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
  5614. (/= (preceding-char) ?_)
  5615. (not (vhdl-in-literal))
  5616. (vhdl-begin-p lim))
  5617. (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
  5618. ;; If the current keyword is an "end" keyword, then find the
  5619. ;; corresponding "begin" keyword.
  5620. (if (and (setq begin-vec (vhdl-corresponding-begin lim))
  5621. (/= (preceding-char) ?_))
  5622. (let (
  5623. ;; begin-re is the statement keyword to search for
  5624. (begin-re
  5625. (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
  5626. ;; column is either the statement keyword target column
  5627. ;; or nil
  5628. (column (aref begin-vec 1))
  5629. ;; internal-p controls where the statement keyword can
  5630. ;; be found.
  5631. (internal-p (aref begin-vec 3))
  5632. (last-backward (point)) last-forward
  5633. foundp literal keyword)
  5634. ;; Look for the statement keyword.
  5635. (while (and (not foundp)
  5636. (re-search-backward begin-re lim t)
  5637. (setq keyword
  5638. (buffer-substring (match-beginning 1)
  5639. (match-end 1))))
  5640. ;; If we are in a literal or in the wrong column,
  5641. ;; then try again.
  5642. (if (or (and column
  5643. (and (/= (current-indentation) column)
  5644. ;; possibly accept current-column as
  5645. ;; well as current-indentation.
  5646. (or (not internal-p)
  5647. (/= (current-column) column))))
  5648. (= (preceding-char) ?_)
  5649. (vhdl-in-literal))
  5650. (backward-char)
  5651. ;; If there is a supplementary keyword, then
  5652. ;; search forward for it.
  5653. (if (and (setq begin-re (aref begin-vec 2))
  5654. (or (not (listp begin-re))
  5655. ;; If begin-re is an alist, then find the
  5656. ;; element corresponding to the actual
  5657. ;; keyword that we found.
  5658. (progn
  5659. (setq begin-re
  5660. (assoc keyword begin-re))
  5661. (and begin-re
  5662. (setq begin-re (cdr begin-re))))))
  5663. (and
  5664. (setq begin-re
  5665. (concat "\\b\\(" begin-re "\\)\\b[^_]"))
  5666. (save-excursion
  5667. (setq last-forward (point))
  5668. ;; Look for the supplementary keyword
  5669. ;; (bounded by the backward search start
  5670. ;; point).
  5671. (while (and (not foundp)
  5672. (re-search-forward begin-re
  5673. last-backward t)
  5674. (goto-char (match-beginning 1)))
  5675. ;; If we are in a literal, then try again.
  5676. (if (or (= (preceding-char) ?_)
  5677. (setq literal
  5678. (vhdl-in-literal)))
  5679. (if (eq literal 'comment)
  5680. (goto-char
  5681. (min (vhdl-point 'eol) last-backward))
  5682. (forward-char))
  5683. ;; We have found the supplementary keyword.
  5684. ;; Save the position of the keyword in foundp.
  5685. (setq foundp (point)))
  5686. )
  5687. foundp)
  5688. ;; If the supplementary keyword was found, then
  5689. ;; move point to the supplementary keyword.
  5690. (goto-char foundp))
  5691. ;; If there was no supplementary keyword, then
  5692. ;; point is already at the statement keyword.
  5693. (setq foundp t)))
  5694. ) ; end of the search for the statement keyword
  5695. (if (not foundp)
  5696. (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
  5697. ))
  5698. (setq count (1- count))
  5699. )
  5700. (setq target (point)))
  5701. (goto-char target)
  5702. nil))
  5703. (defun vhdl-backward-up-list (&optional count limit)
  5704. "Move backward out of one level of blocks.
  5705. With argument, do this that many times."
  5706. (interactive "p")
  5707. (let ((count (or count 1))
  5708. target)
  5709. (save-excursion
  5710. (while (> count 0)
  5711. (if (looking-at vhdl-defun-re)
  5712. (error "ERROR: Unbalanced blocks"))
  5713. (vhdl-backward-to-block limit)
  5714. (setq count (1- count)))
  5715. (setq target (point)))
  5716. (goto-char target)))
  5717. (defun vhdl-end-of-defun (&optional count)
  5718. "Move forward to the end of a VHDL defun."
  5719. (interactive)
  5720. (let ((case-fold-search t))
  5721. (vhdl-beginning-of-defun)
  5722. (if (not (looking-at "block\\|process\\|procedural"))
  5723. (re-search-forward "\\bis\\b"))
  5724. (vhdl-forward-sexp)))
  5725. (defun vhdl-mark-defun ()
  5726. "Put mark at end of this \"defun\", point at beginning."
  5727. (interactive)
  5728. (let ((case-fold-search t))
  5729. (push-mark)
  5730. (vhdl-beginning-of-defun)
  5731. (push-mark)
  5732. (if (not (looking-at "block\\|process\\|procedural"))
  5733. (re-search-forward "\\bis\\b"))
  5734. (vhdl-forward-sexp)
  5735. (exchange-point-and-mark)))
  5736. (defun vhdl-beginning-of-libunit ()
  5737. "Move backward to the beginning of a VHDL library unit.
  5738. Returns the location of the corresponding begin keyword, unless search
  5739. stops due to beginning or end of buffer.
  5740. Note that if point is between the \"libunit\" keyword and the
  5741. corresponding \"begin\" keyword, then that libunit will not be
  5742. recognized, and the search will continue backwards. If point is
  5743. at the \"begin\" keyword, then the defun will be recognized. The
  5744. returned point is at the first character of the \"libunit\" keyword."
  5745. (let ((last-forward (point))
  5746. (last-backward
  5747. ;; Just in case we are actually sitting on the "begin"
  5748. ;; keyword, allow for the keyword and an extra character,
  5749. ;; as this will be used when looking forward for the
  5750. ;; "begin" keyword.
  5751. (save-excursion (forward-word 1) (1+ (point))))
  5752. foundp literal placeholder)
  5753. ;; Find the "libunit" keyword.
  5754. (while (and (not foundp)
  5755. (re-search-backward vhdl-libunit-re nil 'move))
  5756. ;; If we are in a literal, or not at a real libunit, then try again.
  5757. (if (or (= (preceding-char) ?_)
  5758. (vhdl-in-literal)
  5759. (not (vhdl-libunit-p)))
  5760. (backward-char)
  5761. ;; Find the corresponding "begin" keyword.
  5762. (setq last-forward (point))
  5763. (while (and (not foundp)
  5764. (re-search-forward "\\bis\\b[^_]" last-backward t)
  5765. (setq placeholder (match-beginning 0)))
  5766. (if (or (= (preceding-char) ?_)
  5767. (setq literal (vhdl-in-literal)))
  5768. ;; It wasn't a real keyword, so keep searching.
  5769. (if (eq literal 'comment)
  5770. (goto-char
  5771. (min (vhdl-point 'eol) last-backward))
  5772. (forward-char))
  5773. ;; We have found the begin keyword, loop will exit.
  5774. (setq foundp placeholder)))
  5775. ;; Go back to the libunit keyword
  5776. (goto-char last-forward)))
  5777. foundp))
  5778. (defun vhdl-beginning-of-defun (&optional count)
  5779. "Move backward to the beginning of a VHDL defun.
  5780. With argument, do it that many times.
  5781. Returns the location of the corresponding begin keyword, unless search
  5782. stops due to beginning or end of buffer."
  5783. ;; Note that if point is between the "defun" keyword and the
  5784. ;; corresponding "begin" keyword, then that defun will not be
  5785. ;; recognized, and the search will continue backwards. If point is
  5786. ;; at the "begin" keyword, then the defun will be recognized. The
  5787. ;; returned point is at the first character of the "defun" keyword.
  5788. (interactive "p")
  5789. (let ((count (or count 1))
  5790. (case-fold-search t)
  5791. (last-forward (point))
  5792. foundp)
  5793. (while (> count 0)
  5794. (setq foundp nil)
  5795. (goto-char last-forward)
  5796. (let ((last-backward
  5797. ;; Just in case we are actually sitting on the "begin"
  5798. ;; keyword, allow for the keyword and an extra character,
  5799. ;; as this will be used when looking forward for the
  5800. ;; "begin" keyword.
  5801. (save-excursion (forward-word 1) (1+ (point))))
  5802. begin-string literal)
  5803. (while (and (not foundp)
  5804. (re-search-backward vhdl-defun-re nil 'move))
  5805. ;; If we are in a literal, then try again.
  5806. (if (or (= (preceding-char) ?_)
  5807. (vhdl-in-literal))
  5808. (backward-char)
  5809. (if (setq begin-string (vhdl-corresponding-defun))
  5810. ;; This is a real defun keyword.
  5811. ;; Find the corresponding "begin" keyword.
  5812. ;; Look for the begin keyword.
  5813. (progn
  5814. ;; Save the search start point.
  5815. (setq last-forward (point))
  5816. (while (and (not foundp)
  5817. (search-forward begin-string last-backward t))
  5818. (if (or (= (preceding-char) ?_)
  5819. (save-match-data
  5820. (setq literal (vhdl-in-literal))))
  5821. ;; It wasn't a real keyword, so keep searching.
  5822. (if (eq literal 'comment)
  5823. (goto-char
  5824. (min (vhdl-point 'eol) last-backward))
  5825. (forward-char))
  5826. ;; We have found the begin keyword, loop will exit.
  5827. (setq foundp (match-beginning 0)))
  5828. )
  5829. ;; Go back to the defun keyword
  5830. (goto-char last-forward)) ; end search for begin keyword
  5831. ))
  5832. ) ; end of the search for the defun keyword
  5833. )
  5834. (setq count (1- count))
  5835. )
  5836. (vhdl-keep-region-active)
  5837. foundp))
  5838. (defun vhdl-beginning-of-statement (&optional count lim interactive)
  5839. "Go to the beginning of the innermost VHDL statement.
  5840. With prefix arg, go back N - 1 statements. If already at the
  5841. beginning of a statement then go to the beginning of the preceding
  5842. one. If within a string or comment, or next to a comment (only
  5843. whitespace between), move by sentences instead of statements.
  5844. When called from a program, this function takes 3 optional args: the
  5845. prefix arg, a buffer position limit which is the farthest back to
  5846. search, and an argument indicating an interactive call."
  5847. (interactive "p\np")
  5848. (let ((count (or count 1))
  5849. (case-fold-search t)
  5850. (lim (or lim (point-min)))
  5851. (here (point))
  5852. state)
  5853. (save-excursion
  5854. (goto-char lim)
  5855. (setq state (parse-partial-sexp (point) here nil nil)))
  5856. (if (and interactive
  5857. (or (nth 3 state)
  5858. (nth 4 state)
  5859. (looking-at (concat "[ \t]*" comment-start-skip))))
  5860. (forward-sentence (- count))
  5861. (while (> count 0)
  5862. (vhdl-beginning-of-statement-1 lim)
  5863. (setq count (1- count))))
  5864. ;; its possible we've been left up-buf of lim
  5865. (goto-char (max (point) lim))
  5866. )
  5867. (vhdl-keep-region-active))
  5868. (defconst vhdl-e-o-s-re
  5869. (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
  5870. (defun vhdl-end-of-statement ()
  5871. "Very simple implementation."
  5872. (interactive)
  5873. (re-search-forward vhdl-e-o-s-re))
  5874. (defconst vhdl-b-o-s-re
  5875. (concat ";[^_]\\|\([^_]\\|\)[^_]\\|\\bwhen\\b[^_]\\|"
  5876. vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
  5877. (defun vhdl-beginning-of-statement-1 (&optional lim)
  5878. "Move to the start of the current statement, or the previous
  5879. statement if already at the beginning of one."
  5880. (let ((lim (or lim (point-min)))
  5881. (here (point))
  5882. (pos (point))
  5883. donep)
  5884. ;; go backwards one balanced expression, but be careful of
  5885. ;; unbalanced paren being reached
  5886. (if (not (vhdl-safe (progn (backward-sexp) t)))
  5887. (progn
  5888. (backward-up-list 1)
  5889. (forward-char)
  5890. (vhdl-forward-syntactic-ws here)
  5891. (setq donep t)))
  5892. (while (and (not donep)
  5893. (not (bobp))
  5894. ;; look backwards for a statement boundary
  5895. (progn (forward-char) (re-search-backward vhdl-b-o-s-re lim 'move)))
  5896. (if (or (= (preceding-char) ?_)
  5897. (vhdl-in-literal))
  5898. (backward-char)
  5899. (cond
  5900. ;; If we are looking at an open paren, then stop after it
  5901. ((eq (following-char) ?\()
  5902. (forward-char)
  5903. (vhdl-forward-syntactic-ws here)
  5904. (setq donep t))
  5905. ;; If we are looking at a close paren, then skip it
  5906. ((eq (following-char) ?\))
  5907. (forward-char)
  5908. (setq pos (point))
  5909. (backward-sexp)
  5910. (if (< (point) lim)
  5911. (progn (goto-char pos)
  5912. (vhdl-forward-syntactic-ws here)
  5913. (setq donep t))))
  5914. ;; If we are looking at a semicolon, then stop
  5915. ((and (eq (following-char) ?\;) (not (vhdl-in-quote-p)))
  5916. (progn
  5917. (forward-char)
  5918. (vhdl-forward-syntactic-ws here)
  5919. (setq donep t)))
  5920. ;; If we are looking at a "begin", then stop
  5921. ((and (looking-at vhdl-begin-fwd-re)
  5922. (or (not (looking-at "\\<use\\>"))
  5923. (save-excursion
  5924. (back-to-indentation)
  5925. (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
  5926. (/= (preceding-char) ?_)
  5927. (vhdl-begin-p nil))
  5928. ;; If it's a leader "begin", then find the
  5929. ;; right place
  5930. (if (looking-at vhdl-leader-re)
  5931. (save-excursion
  5932. ;; set a default stop point at the begin
  5933. (setq pos (point))
  5934. ;; is the start point inside the leader area ?
  5935. (goto-char (vhdl-end-of-leader))
  5936. (vhdl-forward-syntactic-ws here)
  5937. (if (< (point) here)
  5938. ;; start point was not inside leader area
  5939. ;; set stop point at word after leader
  5940. (setq pos (point))))
  5941. (forward-word 1)
  5942. (vhdl-forward-syntactic-ws here)
  5943. (setq pos (point)))
  5944. (goto-char pos)
  5945. (setq donep t))
  5946. ;; If we are looking at a "statement", then stop
  5947. ((and (looking-at vhdl-statement-fwd-re)
  5948. (/= (preceding-char) ?_)
  5949. (vhdl-statement-p nil))
  5950. (setq donep t))
  5951. ;; If we are looking at a case alternative key, then stop
  5952. ((and (looking-at vhdl-case-alternative-re)
  5953. (vhdl-case-alternative-p lim))
  5954. (save-excursion
  5955. ;; set a default stop point at the when
  5956. (setq pos (point))
  5957. ;; is the start point inside the case alternative key ?
  5958. (looking-at vhdl-case-alternative-re)
  5959. (goto-char (match-end 0))
  5960. (vhdl-forward-syntactic-ws here)
  5961. (if (< (point) here)
  5962. ;; start point was not inside the case alternative key
  5963. ;; set stop point at word after case alternative keyleader
  5964. (setq pos (point))))
  5965. (goto-char pos)
  5966. (setq donep t))
  5967. ;; Bogus find, continue
  5968. (t
  5969. (backward-char)))))
  5970. ))
  5971. ;; Defuns for calculating the current syntactic state:
  5972. (defun vhdl-get-library-unit (bod placeholder)
  5973. "If there is an enclosing library unit at BOD, with its \"begin\"
  5974. keyword at PLACEHOLDER, then return the library unit type."
  5975. (let ((here (vhdl-point 'bol)))
  5976. (if (save-excursion
  5977. (goto-char placeholder)
  5978. (vhdl-safe (vhdl-forward-sexp 1 bod))
  5979. (<= here (point)))
  5980. (save-excursion
  5981. (goto-char bod)
  5982. (cond
  5983. ((looking-at "e") 'entity)
  5984. ((looking-at "a") 'architecture)
  5985. ((looking-at "c") 'configuration)
  5986. ((looking-at "p")
  5987. (save-excursion
  5988. (goto-char bod)
  5989. (forward-sexp)
  5990. (vhdl-forward-syntactic-ws here)
  5991. (if (looking-at "body\\b[^_]")
  5992. 'package-body 'package))))))
  5993. ))
  5994. (defun vhdl-get-block-state (&optional lim)
  5995. "Finds and records all the closest opens.
  5996. LIM is the furthest back we need to search (it should be the
  5997. previous libunit keyword)."
  5998. (let ((here (point))
  5999. (lim (or lim (point-min)))
  6000. keyword sexp-start sexp-mid sexp-end
  6001. preceding-sexp containing-sexp
  6002. containing-begin containing-mid containing-paren)
  6003. (save-excursion
  6004. ;; Find the containing-paren, and use that as the limit
  6005. (if (setq containing-paren
  6006. (save-restriction
  6007. (narrow-to-region lim (point))
  6008. (vhdl-safe (scan-lists (point) -1 1))))
  6009. (setq lim containing-paren))
  6010. ;; Look backwards for "begin" and "end" keywords.
  6011. (while (and (> (point) lim)
  6012. (not containing-sexp))
  6013. (setq keyword (vhdl-backward-to-block lim))
  6014. (cond
  6015. ((eq keyword 'begin)
  6016. ;; Found a "begin" keyword
  6017. (setq sexp-start (point))
  6018. (setq sexp-mid (vhdl-corresponding-mid lim))
  6019. (setq sexp-end (vhdl-safe
  6020. (save-excursion
  6021. (vhdl-forward-sexp 1 lim) (point))))
  6022. (if (and sexp-end (<= sexp-end here))
  6023. ;; we want to record this sexp, but we only want to
  6024. ;; record the last-most of any of them before here
  6025. (or preceding-sexp
  6026. (setq preceding-sexp sexp-start))
  6027. ;; we're contained in this sexp so put sexp-start on
  6028. ;; front of list
  6029. (setq containing-sexp sexp-start)
  6030. (setq containing-mid sexp-mid)
  6031. (setq containing-begin t)))
  6032. ((eq keyword 'end)
  6033. ;; Found an "end" keyword
  6034. (forward-sexp)
  6035. (setq sexp-end (point))
  6036. (setq sexp-mid nil)
  6037. (setq sexp-start
  6038. (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
  6039. (progn (backward-sexp) (point))))
  6040. ;; we want to record this sexp, but we only want to
  6041. ;; record the last-most of any of them before here
  6042. (or preceding-sexp
  6043. (setq preceding-sexp sexp-start)))
  6044. )))
  6045. ;; Check if the containing-paren should be the containing-sexp
  6046. (if (and containing-paren
  6047. (or (null containing-sexp)
  6048. (< containing-sexp containing-paren)))
  6049. (setq containing-sexp containing-paren
  6050. preceding-sexp nil
  6051. containing-begin nil
  6052. containing-mid nil))
  6053. (vector containing-sexp preceding-sexp containing-begin containing-mid)
  6054. ))
  6055. (defconst vhdl-s-c-a-re
  6056. (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
  6057. (defun vhdl-skip-case-alternative (&optional lim)
  6058. "Skip forward over case/when bodies, with optional maximal
  6059. limit. If no next case alternative is found, nil is returned and
  6060. point is not moved."
  6061. (let ((lim (or lim (point-max)))
  6062. (here (point))
  6063. donep foundp)
  6064. (while (and (< (point) lim)
  6065. (not donep))
  6066. (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
  6067. (save-match-data
  6068. (not (vhdl-in-literal)))
  6069. (/= (match-beginning 0) here))
  6070. (progn
  6071. (goto-char (match-beginning 0))
  6072. (cond
  6073. ((and (looking-at "case")
  6074. (re-search-forward "\\bis[^_]" lim t))
  6075. (backward-sexp)
  6076. (vhdl-forward-sexp))
  6077. (t
  6078. (setq donep t
  6079. foundp t))))))
  6080. (if (not foundp)
  6081. (goto-char here))
  6082. foundp))
  6083. (defun vhdl-backward-skip-label (&optional lim)
  6084. "Skip backward over a label, with optional maximal
  6085. limit. If label is not found, nil is returned and point
  6086. is not moved."
  6087. (let ((lim (or lim (point-min)))
  6088. placeholder)
  6089. (if (save-excursion
  6090. (vhdl-backward-syntactic-ws lim)
  6091. (and (eq (preceding-char) ?:)
  6092. (progn
  6093. (backward-sexp)
  6094. (setq placeholder (point))
  6095. (looking-at vhdl-label-key))))
  6096. (goto-char placeholder))
  6097. ))
  6098. (defun vhdl-forward-skip-label (&optional lim)
  6099. "Skip forward over a label, with optional maximal
  6100. limit. If label is not found, nil is returned and point
  6101. is not moved."
  6102. (let ((lim (or lim (point-max))))
  6103. (if (looking-at vhdl-label-key)
  6104. (progn
  6105. (goto-char (match-end 0))
  6106. (vhdl-forward-syntactic-ws lim)))
  6107. ))
  6108. (defun vhdl-get-syntactic-context ()
  6109. "Guess the syntactic description of the current line of VHDL code."
  6110. (save-excursion
  6111. (save-restriction
  6112. (beginning-of-line)
  6113. (let* ((indent-point (point))
  6114. (case-fold-search t)
  6115. vec literal containing-sexp preceding-sexp
  6116. containing-begin containing-mid containing-leader
  6117. char-before-ip char-after-ip begin-after-ip end-after-ip
  6118. placeholder lim library-unit
  6119. )
  6120. ;; Reset the syntactic context
  6121. (setq vhdl-syntactic-context nil)
  6122. (save-excursion
  6123. ;; Move to the start of the previous library unit, and
  6124. ;; record the position of the "begin" keyword.
  6125. (setq placeholder (vhdl-beginning-of-libunit))
  6126. ;; The position of the "libunit" keyword gives us a gross
  6127. ;; limit point.
  6128. (setq lim (point))
  6129. )
  6130. ;; If there is a previous library unit, and we are enclosed by
  6131. ;; it, then set the syntax accordingly.
  6132. (and placeholder
  6133. (setq library-unit (vhdl-get-library-unit lim placeholder))
  6134. (vhdl-add-syntax library-unit lim))
  6135. ;; Find the surrounding state.
  6136. (if (setq vec (vhdl-get-block-state lim))
  6137. (progn
  6138. (setq containing-sexp (aref vec 0))
  6139. (setq preceding-sexp (aref vec 1))
  6140. (setq containing-begin (aref vec 2))
  6141. (setq containing-mid (aref vec 3))
  6142. ))
  6143. ;; set the limit on the farthest back we need to search
  6144. (setq lim (if containing-sexp
  6145. (save-excursion
  6146. (goto-char containing-sexp)
  6147. ;; set containing-leader if required
  6148. (if (looking-at vhdl-leader-re)
  6149. (setq containing-leader (vhdl-end-of-leader)))
  6150. (vhdl-point 'bol))
  6151. (point-min)))
  6152. ;; cache char before and after indent point, and move point to
  6153. ;; the most likely position to perform the majority of tests
  6154. (goto-char indent-point)
  6155. (skip-chars-forward " \t")
  6156. (setq literal (vhdl-in-literal))
  6157. (setq char-after-ip (following-char))
  6158. (setq begin-after-ip (and
  6159. (not literal)
  6160. (looking-at vhdl-begin-fwd-re)
  6161. (or (not (looking-at "\\<use\\>"))
  6162. (save-excursion
  6163. (back-to-indentation)
  6164. (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
  6165. (vhdl-begin-p)))
  6166. (setq end-after-ip (and
  6167. (not literal)
  6168. (looking-at vhdl-end-fwd-re)
  6169. (vhdl-end-p)))
  6170. (vhdl-backward-syntactic-ws lim)
  6171. (setq char-before-ip (preceding-char))
  6172. (goto-char indent-point)
  6173. (skip-chars-forward " \t")
  6174. ;; now figure out syntactic qualities of the current line
  6175. (cond
  6176. ;; CASE 1: in a string or comment.
  6177. ((memq literal '(string comment))
  6178. (vhdl-add-syntax literal (vhdl-point 'bopl)))
  6179. ;; CASE 2: Line is at top level.
  6180. ((null containing-sexp)
  6181. ;; Find the point to which indentation will be relative
  6182. (save-excursion
  6183. (if (null preceding-sexp)
  6184. ;; CASE 2X.1
  6185. ;; no preceding-sexp -> use the preceding statement
  6186. (vhdl-beginning-of-statement-1 lim)
  6187. ;; CASE 2X.2
  6188. ;; if there is a preceding-sexp then indent relative to it
  6189. (goto-char preceding-sexp)
  6190. ;; if not at boi, then the block-opening keyword is
  6191. ;; probably following a label, so we need a different
  6192. ;; relpos
  6193. (if (/= (point) (vhdl-point 'boi))
  6194. ;; CASE 2X.3
  6195. (vhdl-beginning-of-statement-1 lim)))
  6196. ;; v-b-o-s could have left us at point-min
  6197. (and (bobp)
  6198. ;; CASE 2X.4
  6199. (vhdl-forward-syntactic-ws indent-point))
  6200. (setq placeholder (point)))
  6201. (cond
  6202. ;; CASE 2A : we are looking at a block-open
  6203. (begin-after-ip
  6204. (vhdl-add-syntax 'block-open placeholder))
  6205. ;; CASE 2B: we are looking at a block-close
  6206. (end-after-ip
  6207. (vhdl-add-syntax 'block-close placeholder))
  6208. ;; CASE 2C: we are looking at a top-level statement
  6209. ((progn
  6210. (vhdl-backward-syntactic-ws lim)
  6211. (or (bobp)
  6212. (and (= (preceding-char) ?\;)
  6213. (not (vhdl-in-quote-p)))))
  6214. (vhdl-add-syntax 'statement placeholder))
  6215. ;; CASE 2D: we are looking at a top-level statement-cont
  6216. (t
  6217. (vhdl-beginning-of-statement-1 lim)
  6218. ;; v-b-o-s could have left us at point-min
  6219. (and (bobp)
  6220. ;; CASE 2D.1
  6221. (vhdl-forward-syntactic-ws indent-point))
  6222. (vhdl-add-syntax 'statement-cont (point)))
  6223. )) ; end CASE 2
  6224. ;; CASE 3: line is inside parentheses. Most likely we are
  6225. ;; either in a subprogram argument (interface) list, or a
  6226. ;; continued expression containing parentheses.
  6227. ((null containing-begin)
  6228. (vhdl-backward-syntactic-ws containing-sexp)
  6229. (cond
  6230. ;; CASE 3A: we are looking at the arglist closing paren
  6231. ((eq char-after-ip ?\))
  6232. (goto-char containing-sexp)
  6233. (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
  6234. ;; CASE 3B: we are looking at the first argument in an empty
  6235. ;; argument list.
  6236. ((eq char-before-ip ?\()
  6237. (goto-char containing-sexp)
  6238. (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
  6239. ;; CASE 3C: we are looking at an arglist continuation line,
  6240. ;; but the preceding argument is on the same line as the
  6241. ;; opening paren. This case includes multi-line
  6242. ;; expression paren groupings.
  6243. ((and (save-excursion
  6244. (goto-char (1+ containing-sexp))
  6245. (skip-chars-forward " \t")
  6246. (not (eolp))
  6247. (not (looking-at "--")))
  6248. (save-excursion
  6249. (vhdl-beginning-of-statement-1 containing-sexp)
  6250. (skip-chars-backward " \t(")
  6251. (while (and (= (preceding-char) ?\;)
  6252. (not (vhdl-in-quote-p)))
  6253. (vhdl-beginning-of-statement-1 containing-sexp)
  6254. (skip-chars-backward " \t("))
  6255. (<= (point) containing-sexp)))
  6256. (goto-char containing-sexp)
  6257. (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
  6258. ;; CASE 3D: we are looking at just a normal arglist
  6259. ;; continuation line
  6260. (t (vhdl-beginning-of-statement-1 containing-sexp)
  6261. (vhdl-forward-syntactic-ws indent-point)
  6262. (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
  6263. ))
  6264. ;; CASE 4: A block mid open
  6265. ((and begin-after-ip
  6266. (looking-at containing-mid))
  6267. (goto-char containing-sexp)
  6268. ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
  6269. (if (looking-at vhdl-trailer-re)
  6270. ;; CASE 4.1
  6271. (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
  6272. (vhdl-backward-skip-label (vhdl-point 'boi))
  6273. (vhdl-add-syntax 'block-open (point)))
  6274. ;; CASE 5: block close brace
  6275. (end-after-ip
  6276. (goto-char containing-sexp)
  6277. ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
  6278. (if (looking-at vhdl-trailer-re)
  6279. ;; CASE 5.1
  6280. (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
  6281. (vhdl-backward-skip-label (vhdl-point 'boi))
  6282. (vhdl-add-syntax 'block-close (point)))
  6283. ;; CASE 6: A continued statement
  6284. ((and (/= char-before-ip ?\;)
  6285. ;; check it's not a trailer begin keyword, or a begin
  6286. ;; keyword immediately following a label.
  6287. (not (and begin-after-ip
  6288. (or (looking-at vhdl-trailer-re)
  6289. (save-excursion
  6290. (vhdl-backward-skip-label containing-sexp)))))
  6291. ;; check it's not a statement keyword
  6292. (not (and (looking-at vhdl-statement-fwd-re)
  6293. (vhdl-statement-p)))
  6294. ;; see if the b-o-s is before the indent point
  6295. (> indent-point
  6296. (save-excursion
  6297. (vhdl-beginning-of-statement-1 containing-sexp)
  6298. ;; If we ended up after a leader, then this will
  6299. ;; move us forward to the start of the first
  6300. ;; statement. Note that a containing sexp here is
  6301. ;; always a keyword, not a paren, so this will
  6302. ;; have no effect if we hit the containing-sexp.
  6303. (vhdl-forward-syntactic-ws indent-point)
  6304. (setq placeholder (point))))
  6305. ;; check it's not a block-intro
  6306. (/= placeholder containing-sexp)
  6307. ;; check it's not a case block-intro
  6308. (save-excursion
  6309. (goto-char placeholder)
  6310. (or (not (looking-at vhdl-case-alternative-re))
  6311. (> (match-end 0) indent-point))))
  6312. ;; Make placeholder skip a label, but only if it puts us
  6313. ;; before the indent point at the start of a line.
  6314. (let ((new placeholder))
  6315. (if (and (> indent-point
  6316. (save-excursion
  6317. (goto-char placeholder)
  6318. (vhdl-forward-skip-label indent-point)
  6319. (setq new (point))))
  6320. (save-excursion
  6321. (goto-char new)
  6322. (eq new (progn (back-to-indentation) (point)))))
  6323. (setq placeholder new)))
  6324. (vhdl-add-syntax 'statement-cont placeholder)
  6325. (if begin-after-ip
  6326. (vhdl-add-syntax 'block-open)))
  6327. ;; Statement. But what kind?
  6328. ;; CASE 7: A case alternative key
  6329. ((and (looking-at vhdl-case-alternative-re)
  6330. (vhdl-case-alternative-p containing-sexp))
  6331. ;; for a case alternative key, we set relpos to the first
  6332. ;; non-whitespace char on the line containing the "case"
  6333. ;; keyword.
  6334. (goto-char containing-sexp)
  6335. ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
  6336. (if (looking-at vhdl-trailer-re)
  6337. (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
  6338. (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
  6339. ;; CASE 8: statement catchall
  6340. (t
  6341. ;; we know its a statement, but we need to find out if it is
  6342. ;; the first statement in a block
  6343. (if containing-leader
  6344. (goto-char containing-leader)
  6345. (goto-char containing-sexp)
  6346. ;; Note that a containing sexp here is always a keyword,
  6347. ;; not a paren, so skip over the keyword.
  6348. (forward-sexp))
  6349. ;; move to the start of the first statement
  6350. (vhdl-forward-syntactic-ws indent-point)
  6351. (setq placeholder (point))
  6352. ;; we want to ignore case alternatives keys when skipping forward
  6353. (let (incase-p)
  6354. (while (looking-at vhdl-case-alternative-re)
  6355. (setq incase-p (point))
  6356. ;; we also want to skip over the body of the
  6357. ;; case/when statement if that doesn't put us at
  6358. ;; after the indent-point
  6359. (while (vhdl-skip-case-alternative indent-point))
  6360. ;; set up the match end
  6361. (looking-at vhdl-case-alternative-re)
  6362. (goto-char (match-end 0))
  6363. ;; move to the start of the first case alternative statement
  6364. (vhdl-forward-syntactic-ws indent-point)
  6365. (setq placeholder (point)))
  6366. (cond
  6367. ;; CASE 8A: we saw a case/when statement so we must be
  6368. ;; in a switch statement. find out if we are at the
  6369. ;; statement just after a case alternative key
  6370. ((and incase-p
  6371. (= (point) indent-point))
  6372. ;; relpos is the "when" keyword
  6373. (vhdl-add-syntax 'statement-case-intro incase-p))
  6374. ;; CASE 8B: any old statement
  6375. ((< (point) indent-point)
  6376. ;; relpos is the first statement of the block
  6377. (vhdl-add-syntax 'statement placeholder)
  6378. (if begin-after-ip
  6379. (vhdl-add-syntax 'block-open)))
  6380. ;; CASE 8C: first statement in a block
  6381. (t
  6382. (goto-char containing-sexp)
  6383. ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
  6384. (if (looking-at vhdl-trailer-re)
  6385. (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
  6386. (vhdl-backward-skip-label (vhdl-point 'boi))
  6387. (vhdl-add-syntax 'statement-block-intro (point))
  6388. (if begin-after-ip
  6389. (vhdl-add-syntax 'block-open)))
  6390. )))
  6391. )
  6392. ;; now we need to look at any modifiers
  6393. (goto-char indent-point)
  6394. (skip-chars-forward " \t")
  6395. (if (looking-at "--")
  6396. (vhdl-add-syntax 'comment))
  6397. (if (eq literal 'pound)
  6398. (vhdl-add-syntax 'cpp-macro))
  6399. ;; return the syntax
  6400. vhdl-syntactic-context))))
  6401. ;; Standard indentation line-ups:
  6402. (defun vhdl-lineup-arglist (langelem)
  6403. "Lineup the current arglist line with the arglist appearing just
  6404. after the containing paren which starts the arglist."
  6405. (save-excursion
  6406. (let* ((containing-sexp
  6407. (save-excursion
  6408. ;; arglist-cont-nonempty gives relpos ==
  6409. ;; to boi of containing-sexp paren. This
  6410. ;; is good when offset is +, but bad
  6411. ;; when it is vhdl-lineup-arglist, so we
  6412. ;; have to special case a kludge here.
  6413. (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
  6414. (progn
  6415. (beginning-of-line)
  6416. (backward-up-list 1)
  6417. (skip-chars-forward " \t" (vhdl-point 'eol)))
  6418. (goto-char (cdr langelem)))
  6419. (point)))
  6420. (cs-curcol (save-excursion
  6421. (goto-char (cdr langelem))
  6422. (current-column))))
  6423. (if (save-excursion
  6424. (beginning-of-line)
  6425. (looking-at "[ \t]*)"))
  6426. (progn (goto-char (match-end 0))
  6427. (backward-sexp)
  6428. (forward-char)
  6429. (vhdl-forward-syntactic-ws)
  6430. (- (current-column) cs-curcol))
  6431. (goto-char containing-sexp)
  6432. (or (eolp)
  6433. (let ((eol (vhdl-point 'eol))
  6434. (here (progn
  6435. (forward-char)
  6436. (skip-chars-forward " \t")
  6437. (point))))
  6438. (vhdl-forward-syntactic-ws)
  6439. (if (< (point) eol)
  6440. (goto-char here))))
  6441. (- (current-column) cs-curcol)
  6442. ))))
  6443. (defun vhdl-lineup-arglist-intro (langelem)
  6444. "Lineup an arglist-intro line to just after the open paren."
  6445. (save-excursion
  6446. (let ((cs-curcol (save-excursion
  6447. (goto-char (cdr langelem))
  6448. (current-column)))
  6449. (ce-curcol (save-excursion
  6450. (beginning-of-line)
  6451. (backward-up-list 1)
  6452. (skip-chars-forward " \t" (vhdl-point 'eol))
  6453. (current-column))))
  6454. (- ce-curcol cs-curcol -1))))
  6455. (defun vhdl-lineup-comment (langelem)
  6456. "Support old behavior for comment indentation. We look at
  6457. vhdl-comment-only-line-offset to decide how to indent comment
  6458. only-lines."
  6459. (save-excursion
  6460. (back-to-indentation)
  6461. ;; at or to the right of comment-column
  6462. (if (>= (current-column) comment-column)
  6463. (vhdl-comment-indent)
  6464. ;; otherwise, indent as specified by vhdl-comment-only-line-offset
  6465. (if (not (bolp))
  6466. (or (car-safe vhdl-comment-only-line-offset)
  6467. vhdl-comment-only-line-offset)
  6468. (or (cdr-safe vhdl-comment-only-line-offset)
  6469. (car-safe vhdl-comment-only-line-offset)
  6470. -1000 ;jam it against the left side
  6471. )))))
  6472. (defun vhdl-lineup-statement-cont (langelem)
  6473. "Line up statement-cont after the assignment operator."
  6474. (save-excursion
  6475. (let* ((relpos (cdr langelem))
  6476. (assignp (save-excursion
  6477. (goto-char (vhdl-point 'boi))
  6478. (and (re-search-forward "\\(<\\|:\\|=\\)="
  6479. (vhdl-point 'eol) t)
  6480. (- (point) (vhdl-point 'boi)))))
  6481. (curcol (progn
  6482. (goto-char relpos)
  6483. (current-column)))
  6484. foundp)
  6485. (while (and (not foundp)
  6486. (< (point) (vhdl-point 'eol)))
  6487. (re-search-forward "\\(<\\|:\\|=\\)=\\|(" (vhdl-point 'eol) 'move)
  6488. (if (vhdl-in-literal)
  6489. (forward-char)
  6490. (if (= (preceding-char) ?\()
  6491. ;; skip over any parenthesized expressions
  6492. (goto-char (min (vhdl-point 'eol)
  6493. (scan-lists (point) 1 1)))
  6494. ;; found an assignment operator (not at eol)
  6495. (setq foundp (not (looking-at "\\s-*$"))))))
  6496. (if (not foundp)
  6497. ;; there's no assignment operator on the line
  6498. vhdl-basic-offset
  6499. ;; calculate indentation column after assign and ws, unless
  6500. ;; our line contains an assignment operator
  6501. (if (not assignp)
  6502. (progn
  6503. (forward-char)
  6504. (skip-chars-forward " \t")
  6505. (setq assignp 0)))
  6506. (- (current-column) assignp curcol))
  6507. )))
  6508. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6509. ;; Progress reporting
  6510. (defvar vhdl-progress-info nil
  6511. "Array variable for progress information: 0 begin, 1 end, 2 time.")
  6512. (defun vhdl-update-progress-info (string pos)
  6513. "Update progress information."
  6514. (when (and vhdl-progress-info (not noninteractive)
  6515. (< vhdl-progress-interval
  6516. (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
  6517. (let ((delta (- (aref vhdl-progress-info 1)
  6518. (aref vhdl-progress-info 0))))
  6519. (if (= 0 delta)
  6520. (message (concat string "... (100%s)") "%")
  6521. (message (concat string "... (%2d%s)")
  6522. (/ (* 100 (- pos (aref vhdl-progress-info 0)))
  6523. delta) "%")))
  6524. (aset vhdl-progress-info 2 (nth 1 (current-time)))))
  6525. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6526. ;; Indentation commands
  6527. (defun vhdl-electric-tab (&optional prefix-arg)
  6528. "If preceding character is part of a word or a paren then hippie-expand,
  6529. else if right of non whitespace on line then insert tab,
  6530. else if last command was a tab or return then dedent one step or if a comment
  6531. toggle between normal indent and inline comment indent,
  6532. else indent `correctly'."
  6533. (interactive "*P")
  6534. (vhdl-prepare-search-2
  6535. (cond
  6536. ;; indent region if region is active
  6537. ((and (not (featurep 'xemacs)) (use-region-p))
  6538. (vhdl-indent-region (region-beginning) (region-end) nil))
  6539. ;; expand word
  6540. ((= (char-syntax (preceding-char)) ?w)
  6541. (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
  6542. (case-replace nil)
  6543. (hippie-expand-only-buffers
  6544. (or (and (boundp 'hippie-expand-only-buffers)
  6545. hippie-expand-only-buffers)
  6546. '(vhdl-mode))))
  6547. (vhdl-expand-abbrev prefix-arg)))
  6548. ;; expand parenthesis
  6549. ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
  6550. (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
  6551. (case-replace nil))
  6552. (vhdl-expand-paren prefix-arg)))
  6553. ;; insert tab
  6554. ((> (current-column) (current-indentation))
  6555. (insert-tab))
  6556. ;; toggle comment indent
  6557. ((and (looking-at "--")
  6558. (or (eq last-command 'vhdl-electric-tab)
  6559. (eq last-command 'vhdl-electric-return)))
  6560. (cond ((= (current-indentation) 0) ; no indent
  6561. (indent-to 1)
  6562. (indent-according-to-mode))
  6563. ((< (current-indentation) comment-column) ; normal indent
  6564. (indent-to comment-column)
  6565. (indent-according-to-mode))
  6566. (t ; inline comment indent
  6567. (delete-region (line-beginning-position) (point)))))
  6568. ;; dedent
  6569. ((and (>= (current-indentation) vhdl-basic-offset)
  6570. (or (eq last-command 'vhdl-electric-tab)
  6571. (eq last-command 'vhdl-electric-return)))
  6572. (backward-delete-char-untabify vhdl-basic-offset nil))
  6573. ;; indent line
  6574. (t (indent-according-to-mode)))
  6575. (setq this-command 'vhdl-electric-tab)))
  6576. (defun vhdl-electric-return ()
  6577. "newline-and-indent or indent-new-comment-line if in comment and preceding
  6578. character is a space."
  6579. (interactive)
  6580. (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
  6581. (indent-new-comment-line)
  6582. (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z)
  6583. (not (vhdl-in-comment-p)))
  6584. (vhdl-fix-case-word -1))
  6585. (newline-and-indent)))
  6586. (defun vhdl-indent-line ()
  6587. "Indent the current line as VHDL code. Returns the amount of
  6588. indentation change."
  6589. (interactive)
  6590. (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
  6591. (pos (- (point-max) (point)))
  6592. (is-comment nil)
  6593. (indent
  6594. (if syntax
  6595. ;; indent syntax-based
  6596. (if (and (eq (caar syntax) 'comment)
  6597. (>= (vhdl-get-offset (car syntax)) comment-column))
  6598. ;; special case: comments at or right of comment-column
  6599. (vhdl-get-offset (car syntax))
  6600. ;; align comments like following code line
  6601. (when vhdl-indent-comment-like-next-code-line
  6602. (save-excursion
  6603. (while (eq (caar syntax) 'comment)
  6604. (setq is-comment t)
  6605. (beginning-of-line 2)
  6606. (setq syntax (vhdl-get-syntactic-context)))))
  6607. (when is-comment
  6608. (setq syntax (cons (cons 'comment nil) syntax)))
  6609. (apply '+ (mapcar 'vhdl-get-offset syntax)))
  6610. ;; indent like previous nonblank line
  6611. (save-excursion (beginning-of-line)
  6612. (re-search-backward "^[^\n]" nil t)
  6613. (current-indentation))))
  6614. (shift-amt (- indent (current-indentation))))
  6615. (and vhdl-echo-syntactic-information-p
  6616. (message "syntax: %s, indent= %d" syntax indent))
  6617. (let ((has-formfeed
  6618. (save-excursion (beginning-of-line) (looking-at "\\s-*\f"))))
  6619. (when (or (not (zerop shift-amt)) has-formfeed)
  6620. (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
  6621. (beginning-of-line)
  6622. (when has-formfeed (insert "\f"))
  6623. (indent-to indent)))
  6624. (if (< (point) (vhdl-point 'boi))
  6625. (back-to-indentation)
  6626. ;; If initial point was within line's indentation, position after
  6627. ;; the indentation. Else stay at same point in text.
  6628. (when (> (- (point-max) pos) (point))
  6629. (goto-char (- (point-max) pos))))
  6630. (run-hooks 'vhdl-special-indent-hook)
  6631. (vhdl-update-progress-info "Indenting" (vhdl-current-line))
  6632. shift-amt))
  6633. (defun vhdl-indent-region (beg end &optional column)
  6634. "Indent region as VHDL code.
  6635. Adds progress reporting to `indent-region'."
  6636. (interactive "r\nP")
  6637. (when vhdl-progress-interval
  6638. (setq vhdl-progress-info (vector (count-lines (point-min) beg)
  6639. (count-lines (point-min) end) 0)))
  6640. (indent-region beg end column)
  6641. (when vhdl-progress-interval (message "Indenting...done"))
  6642. (setq vhdl-progress-info nil))
  6643. (defun vhdl-indent-buffer ()
  6644. "Indent whole buffer as VHDL code.
  6645. Calls `indent-region' for whole buffer and adds progress reporting."
  6646. (interactive)
  6647. (vhdl-indent-region (point-min) (point-max)))
  6648. (defun vhdl-indent-group ()
  6649. "Indent group of lines between empty lines."
  6650. (interactive)
  6651. (let ((beg (save-excursion
  6652. (if (re-search-backward vhdl-align-group-separate nil t)
  6653. (point-marker)
  6654. (point-min-marker))))
  6655. (end (save-excursion
  6656. (if (re-search-forward vhdl-align-group-separate nil t)
  6657. (point-marker)
  6658. (point-max-marker)))))
  6659. (vhdl-indent-region beg end)))
  6660. (defun vhdl-indent-sexp (&optional endpos)
  6661. "Indent each line of the list starting just after point.
  6662. If optional arg ENDPOS is given, indent each line, stopping when
  6663. ENDPOS is encountered."
  6664. (interactive)
  6665. (save-excursion
  6666. (let ((beg (point))
  6667. (end (progn (vhdl-forward-sexp nil endpos) (point))))
  6668. (indent-region beg end nil))))
  6669. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6670. ;; Miscellaneous commands
  6671. (defun vhdl-show-syntactic-information ()
  6672. "Show syntactic information for current line."
  6673. (interactive)
  6674. (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
  6675. (vhdl-keep-region-active))
  6676. ;; Verification and regression functions:
  6677. (defun vhdl-regress-line (&optional arg)
  6678. "Check syntactic information for current line."
  6679. (interactive "P")
  6680. (let ((expected (save-excursion
  6681. (end-of-line)
  6682. (when (search-backward " -- ((" (vhdl-point 'bol) t)
  6683. (forward-char 4)
  6684. (read (current-buffer)))))
  6685. (actual (vhdl-get-syntactic-context))
  6686. (expurgated))
  6687. ;; remove the library unit symbols
  6688. (mapc
  6689. (function
  6690. (lambda (elt)
  6691. (if (memq (car elt) '(entity configuration package
  6692. package-body architecture))
  6693. nil
  6694. (setq expurgated (append expurgated (list elt))))))
  6695. actual)
  6696. (if (and (not arg) expected (listp expected))
  6697. (if (not (equal expected expurgated))
  6698. (error "ERROR: Should be: %s, is: %s" expected expurgated))
  6699. (save-excursion
  6700. (beginning-of-line)
  6701. (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
  6702. (end-of-line)
  6703. (if (search-backward " -- ((" (vhdl-point 'bol) t)
  6704. (delete-region (point) (line-end-position)))
  6705. (insert " -- ")
  6706. (insert (format "%s" expurgated))))))
  6707. (vhdl-keep-region-active))
  6708. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6709. ;;; Alignment, whitespace fixup, beautifying
  6710. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6711. (defconst vhdl-align-alist
  6712. '(
  6713. ;; after some keywords
  6714. (vhdl-mode "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)[ \t]"
  6715. "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)\\([ \t]+\\)" 2)
  6716. ;; before ':'
  6717. (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
  6718. ;; after direction specifications
  6719. (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
  6720. ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
  6721. ;; before "==", ":=", "=>", and "<="
  6722. (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "<= ... =>" can occur
  6723. (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
  6724. (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "=> ... <=" can occur
  6725. ;; before some keywords
  6726. (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
  6727. (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
  6728. (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
  6729. (vhdl-mode "[ \t]across\\>" "[^ \t]\\([ \t]+\\)across\\>" 1)
  6730. (vhdl-mode "[ \t]through\\>" "[^ \t]\\([ \t]+\\)through\\>" 1)
  6731. ;; before "=>" since "when/else ... =>" can occur
  6732. (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
  6733. )
  6734. "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
  6735. It is searched in order. If REGEXP is found anywhere in the first
  6736. line of a region to be aligned, ALIGN-PATTERN will be used for that
  6737. region. ALIGN-PATTERN must include the whitespace to be expanded or
  6738. contracted. It may also provide regexps for the text surrounding the
  6739. whitespace. SUBEXP specifies which sub-expression of
  6740. ALIGN-PATTERN matches the white space to be expanded/contracted.")
  6741. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6742. ;; Align code
  6743. (defvar vhdl-align-try-all-clauses t
  6744. "If REGEXP is not found on the first line of the region that clause
  6745. is ignored. If this variable is non-nil, then the clause is tried anyway.")
  6746. (defun vhdl-do-group (function &optional spacing)
  6747. "Apply FUNCTION on group of lines between empty lines."
  6748. (let
  6749. ;; search for group beginning
  6750. ((beg (save-excursion
  6751. (if (re-search-backward vhdl-align-group-separate nil t)
  6752. (progn (beginning-of-line 2) (back-to-indentation) (point))
  6753. (point-min))))
  6754. ;; search for group end
  6755. (end (save-excursion
  6756. (if (re-search-forward vhdl-align-group-separate nil t)
  6757. (progn (beginning-of-line) (point))
  6758. (point-max)))))
  6759. ;; run FUNCTION
  6760. (funcall function beg end spacing)))
  6761. (defun vhdl-do-list (function &optional spacing)
  6762. "Apply FUNCTION to the lines of a list surrounded by a balanced group of
  6763. parentheses."
  6764. (let (beg end)
  6765. (save-excursion
  6766. ;; search for beginning of balanced group of parentheses
  6767. (setq beg (vhdl-re-search-backward "[()]" nil t))
  6768. (while (looking-at ")")
  6769. (forward-char) (backward-sexp)
  6770. (setq beg (vhdl-re-search-backward "[()]" nil t)))
  6771. ;; search for end of balanced group of parentheses
  6772. (when beg
  6773. (forward-list)
  6774. (setq end (point))
  6775. (goto-char (1+ beg))
  6776. (skip-chars-forward " \t\n\r\f")
  6777. (setq beg (point))))
  6778. ;; run FUNCTION
  6779. (if beg
  6780. (funcall function beg end spacing)
  6781. (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
  6782. (defun vhdl-do-same-indent (function &optional spacing)
  6783. "Apply FUNCTION to block of lines with same indent."
  6784. (let ((indent (current-indentation))
  6785. beg end)
  6786. ;; search for first line with same indent
  6787. (save-excursion
  6788. (while (and (not (bobp))
  6789. (or (looking-at "^\\s-*\\(--.*\\)?$")
  6790. (= (current-indentation) indent)))
  6791. (unless (looking-at "^\\s-*$")
  6792. (back-to-indentation) (setq beg (point)))
  6793. (beginning-of-line -0)))
  6794. ;; search for last line with same indent
  6795. (save-excursion
  6796. (while (and (not (eobp))
  6797. (or (looking-at "^\\s-*\\(--.*\\)?$")
  6798. (= (current-indentation) indent)))
  6799. (if (looking-at "^\\s-*$")
  6800. (beginning-of-line 2)
  6801. (beginning-of-line 2)
  6802. (setq end (point)))))
  6803. ;; run FUNCTION
  6804. (funcall function beg end spacing)))
  6805. (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
  6806. "Attempt to align a range of lines based on the content of the
  6807. lines. The definition of `alignment-list' determines the matching
  6808. order and the manner in which the lines are aligned. If ALIGNMENT-LIST
  6809. is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
  6810. indentation is done before aligning."
  6811. (interactive "r\np")
  6812. (setq alignment-list (or alignment-list vhdl-align-alist))
  6813. (setq spacing (or spacing 1))
  6814. (save-excursion
  6815. (let (bol indent)
  6816. (goto-char end)
  6817. (setq end (point-marker))
  6818. (goto-char begin)
  6819. (setq bol (setq begin (progn (beginning-of-line) (point))))
  6820. ; (untabify bol end)
  6821. (when indent
  6822. (indent-region bol end nil))))
  6823. (let ((copy (copy-alist alignment-list)))
  6824. (vhdl-prepare-search-2
  6825. (while copy
  6826. (save-excursion
  6827. (goto-char begin)
  6828. (let (element
  6829. (eol (point-at-eol)))
  6830. (setq element (nth 0 copy))
  6831. (when (and (or (and (listp (car element))
  6832. (memq major-mode (car element)))
  6833. (eq major-mode (car element)))
  6834. (or vhdl-align-try-all-clauses
  6835. (re-search-forward (car (cdr element)) eol t)))
  6836. (vhdl-align-region-2 begin end (car (cdr (cdr element)))
  6837. (car (cdr (cdr (cdr element)))) spacing))
  6838. (setq copy (cdr copy))))))))
  6839. (defun vhdl-align-region-2 (begin end match &optional substr spacing)
  6840. "Align a range of lines from BEGIN to END. The regular expression
  6841. MATCH must match exactly one field: the whitespace to be
  6842. contracted/expanded. The alignment column will equal the
  6843. rightmost column of the widest whitespace block. SPACING is
  6844. the amount of extra spaces to add to the calculated maximum required.
  6845. SPACING defaults to 1 so that at least one space is inserted after
  6846. the token in MATCH."
  6847. (setq spacing (or spacing 1))
  6848. (setq substr (or substr 1))
  6849. (save-excursion
  6850. (let (distance (max 0) (lines 0) bol eol width)
  6851. ;; Determine the greatest whitespace distance to the alignment
  6852. ;; character
  6853. (goto-char begin)
  6854. (setq eol (point-at-eol)
  6855. bol (setq begin (progn (beginning-of-line) (point))))
  6856. (while (< bol end)
  6857. (save-excursion
  6858. (when (and (vhdl-re-search-forward match eol t)
  6859. (save-excursion
  6860. (goto-char (match-beginning 0))
  6861. (forward-char)
  6862. (and (not (vhdl-in-literal))
  6863. (not (vhdl-in-quote-p))
  6864. (not (vhdl-in-extended-identifier-p))))
  6865. (not (looking-at "\\s-*$")))
  6866. (setq distance (- (match-beginning substr) bol))
  6867. (when (> distance max)
  6868. (setq max distance))))
  6869. (forward-line)
  6870. (setq bol (point)
  6871. eol (point-at-eol))
  6872. (setq lines (1+ lines)))
  6873. ;; Now insert enough maxs to push each assignment operator to
  6874. ;; the same column. We need to use 'lines' as a counter, since
  6875. ;; the location of the mark may change
  6876. (goto-char (setq bol begin))
  6877. (setq eol (point-at-eol))
  6878. (while (> lines 0)
  6879. (when (and (vhdl-re-search-forward match eol t)
  6880. (save-excursion
  6881. (goto-char (match-beginning 0))
  6882. (forward-char)
  6883. (and (not (vhdl-in-literal))
  6884. (not (vhdl-in-quote-p))
  6885. (not (vhdl-in-extended-identifier-p))))
  6886. (not (looking-at "\\s-*$"))
  6887. (> (match-beginning 0) ; not if at boi
  6888. (save-excursion (back-to-indentation) (point))))
  6889. (setq width (- (match-end substr) (match-beginning substr)))
  6890. (setq distance (- (match-beginning substr) bol))
  6891. (goto-char (match-beginning substr))
  6892. (delete-char width)
  6893. (insert-char ? (+ (- max distance) spacing)))
  6894. (beginning-of-line)
  6895. (forward-line)
  6896. (setq bol (point)
  6897. eol (point-at-eol))
  6898. (setq lines (1- lines))))))
  6899. (defun vhdl-align-region-groups (beg end &optional spacing
  6900. no-message no-comments)
  6901. "Align region, treat groups of lines separately."
  6902. (interactive "r\nP")
  6903. (save-excursion
  6904. (let (orig pos)
  6905. (goto-char beg)
  6906. (beginning-of-line)
  6907. (setq orig (point-marker))
  6908. (setq beg (point))
  6909. (goto-char end)
  6910. (setq end (point-marker))
  6911. (untabify beg end)
  6912. (unless no-message
  6913. (when vhdl-progress-interval
  6914. (setq vhdl-progress-info (vector (count-lines (point-min) beg)
  6915. (count-lines (point-min) end) 0))))
  6916. (vhdl-fixup-whitespace-region beg end t)
  6917. (goto-char beg)
  6918. (if (not vhdl-align-groups)
  6919. ;; align entire region
  6920. (progn (vhdl-align-region-1 beg end spacing)
  6921. (unless no-comments
  6922. (vhdl-align-inline-comment-region-1 beg end)))
  6923. ;; align groups
  6924. (while (and (< beg end)
  6925. (re-search-forward vhdl-align-group-separate end t))
  6926. (setq pos (point-marker))
  6927. (vhdl-align-region-1 beg pos spacing)
  6928. (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
  6929. (vhdl-update-progress-info "Aligning" (vhdl-current-line))
  6930. (setq beg (1+ pos))
  6931. (goto-char beg))
  6932. ;; align last group
  6933. (when (< beg end)
  6934. (vhdl-align-region-1 beg end spacing)
  6935. (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
  6936. (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
  6937. (when vhdl-indent-tabs-mode
  6938. (tabify orig end))
  6939. (unless no-message
  6940. (when vhdl-progress-interval (message "Aligning...done"))
  6941. (setq vhdl-progress-info nil)))))
  6942. (defun vhdl-align-region (beg end &optional spacing)
  6943. "Align region, treat blocks with same indent and argument lists separately."
  6944. (interactive "r\nP")
  6945. (if (not vhdl-align-same-indent)
  6946. ;; align entire region
  6947. (vhdl-align-region-groups beg end spacing)
  6948. ;; align blocks with same indent and argument lists
  6949. (save-excursion
  6950. (let ((cur-beg beg)
  6951. indent cur-end)
  6952. (when vhdl-progress-interval
  6953. (setq vhdl-progress-info (vector (count-lines (point-min) beg)
  6954. (count-lines (point-min) end) 0)))
  6955. (goto-char end)
  6956. (setq end (point-marker))
  6957. (goto-char cur-beg)
  6958. (while (< (point) end)
  6959. ;; is argument list opening?
  6960. (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
  6961. (point) (vhdl-point 'eol)))))
  6962. ;; determine region for argument list
  6963. (progn (goto-char cur-beg)
  6964. (forward-sexp)
  6965. (setq cur-end (point))
  6966. (beginning-of-line 2))
  6967. ;; determine region with same indent
  6968. (setq indent (current-indentation))
  6969. (setq cur-beg (point))
  6970. (setq cur-end (vhdl-point 'bonl))
  6971. (beginning-of-line 2)
  6972. (while (and (< (point) end)
  6973. (or (looking-at "^\\s-*\\(--.*\\)?$")
  6974. (= (current-indentation) indent))
  6975. (<= (save-excursion
  6976. (nth 0 (parse-partial-sexp
  6977. (point) (vhdl-point 'eol)))) 0))
  6978. (unless (looking-at "^\\s-*$")
  6979. (setq cur-end (vhdl-point 'bonl)))
  6980. (beginning-of-line 2)))
  6981. ;; align region
  6982. (vhdl-align-region-groups cur-beg cur-end spacing t t))
  6983. (vhdl-align-inline-comment-region beg end spacing noninteractive)
  6984. (when vhdl-progress-interval (message "Aligning...done"))
  6985. (setq vhdl-progress-info nil)))))
  6986. (defun vhdl-align-group (&optional spacing)
  6987. "Align group of lines between empty lines."
  6988. (interactive)
  6989. (vhdl-do-group 'vhdl-align-region spacing))
  6990. (defun vhdl-align-list (&optional spacing)
  6991. "Align the lines of a list surrounded by a balanced group of parentheses."
  6992. (interactive)
  6993. (vhdl-do-list 'vhdl-align-region-groups spacing))
  6994. (defun vhdl-align-same-indent (&optional spacing)
  6995. "Align block of lines with same indent."
  6996. (interactive)
  6997. (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
  6998. (defun vhdl-align-declarations (&optional spacing)
  6999. "Align the lines within the declarative part of a design unit."
  7000. (interactive)
  7001. (let (beg end)
  7002. (vhdl-prepare-search-2
  7003. (save-excursion
  7004. ;; search for declarative part
  7005. (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|end\\|entity\\|package\\)\\>" nil t)
  7006. (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
  7007. (setq beg (point))
  7008. (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
  7009. (setq end (point)))))
  7010. (if beg
  7011. (vhdl-align-region-groups beg end spacing)
  7012. (error "ERROR: Not within the declarative part of a design unit"))))
  7013. (defun vhdl-align-buffer ()
  7014. "Align buffer."
  7015. (interactive)
  7016. (vhdl-align-region (point-min) (point-max)))
  7017. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7018. ;; Align inline comments
  7019. (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
  7020. "Align inline comments in region."
  7021. (save-excursion
  7022. (let ((start-max comment-column)
  7023. (length-max 0)
  7024. comment-list start-list tmp-list start length
  7025. cur-start prev-start no-code)
  7026. (setq spacing (or spacing 2))
  7027. (vhdl-prepare-search-2
  7028. (goto-char beg)
  7029. ;; search for comment start positions and lengths
  7030. (while (< (point) end)
  7031. (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
  7032. (looking-at "^\\(.*[^ \t\n\r\f-]+\\)\\s-*\\(--.*\\)$")
  7033. (not (save-excursion (goto-char (match-beginning 2))
  7034. (vhdl-in-literal))))
  7035. (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
  7036. (setq length (- (match-end 2) (match-beginning 2)))
  7037. (setq start-max (max start start-max))
  7038. (setq length-max (max length length-max))
  7039. (setq comment-list (cons (cons start length) comment-list)))
  7040. (beginning-of-line 2))
  7041. (setq comment-list
  7042. (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
  7043. ;; reduce start positions
  7044. (setq start-list (list (caar comment-list)))
  7045. (setq comment-list (cdr comment-list))
  7046. (while comment-list
  7047. (unless (or (= (caar comment-list) (car start-list))
  7048. (<= (+ (car start-list) (cdar comment-list))
  7049. end-comment-column))
  7050. (setq start-list (cons (caar comment-list) start-list)))
  7051. (setq comment-list (cdr comment-list)))
  7052. ;; align lines as nicely as possible
  7053. (goto-char beg)
  7054. (while (< (point) end)
  7055. (setq cur-start nil)
  7056. (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
  7057. (or (and (looking-at "^\\(.*[^ \t\n\r\f-]+\\)\\(\\s-*\\)\\(--.*\\)$")
  7058. (not (save-excursion
  7059. (goto-char (match-beginning 3))
  7060. (vhdl-in-literal))))
  7061. (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
  7062. (>= (- (match-end 2) (match-beginning 2))
  7063. comment-column))))
  7064. (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
  7065. (setq length (- (match-end 3) (match-beginning 3)))
  7066. (setq no-code (= (match-beginning 1) (match-end 1)))
  7067. ;; insert minimum whitespace
  7068. (goto-char (match-end 2))
  7069. (delete-region (match-beginning 2) (match-end 2))
  7070. (insert-char ?\ spacing)
  7071. (setq tmp-list start-list)
  7072. ;; insert additional whitespace to align
  7073. (setq cur-start
  7074. (cond
  7075. ;; align comment-only line to inline comment of previous line
  7076. ((and no-code prev-start
  7077. (<= length (- end-comment-column prev-start)))
  7078. prev-start)
  7079. ;; align all comments at `start-max' if this is possible
  7080. ((<= (+ start-max length-max) end-comment-column)
  7081. start-max)
  7082. ;; align at `comment-column' if possible
  7083. ((and (<= start comment-column)
  7084. (<= length (- end-comment-column comment-column)))
  7085. comment-column)
  7086. ;; align at left-most possible start position otherwise
  7087. (t
  7088. (while (and tmp-list (< (car tmp-list) start))
  7089. (setq tmp-list (cdr tmp-list)))
  7090. (car tmp-list))))
  7091. (indent-to cur-start))
  7092. (setq prev-start cur-start)
  7093. (beginning-of-line 2))))))
  7094. (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
  7095. "Align inline comments within a region. Groups of code lines separated by
  7096. empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
  7097. (interactive "r\nP")
  7098. (save-excursion
  7099. (let (orig pos)
  7100. (goto-char beg)
  7101. (beginning-of-line)
  7102. (setq orig (point-marker))
  7103. (setq beg (point))
  7104. (goto-char end)
  7105. (setq end (point-marker))
  7106. (untabify beg end)
  7107. (unless no-message (message "Aligning inline comments..."))
  7108. (goto-char beg)
  7109. (if (not vhdl-align-groups)
  7110. ;; align entire region
  7111. (vhdl-align-inline-comment-region-1 beg end spacing)
  7112. ;; align groups
  7113. (while (and (< beg end)
  7114. (re-search-forward vhdl-align-group-separate end t))
  7115. (setq pos (point-marker))
  7116. (vhdl-align-inline-comment-region-1 beg pos spacing)
  7117. (setq beg (1+ pos))
  7118. (goto-char beg))
  7119. ;; align last group
  7120. (when (< beg end)
  7121. (vhdl-align-inline-comment-region-1 beg end spacing)))
  7122. (when vhdl-indent-tabs-mode
  7123. (tabify orig end))
  7124. (unless no-message (message "Aligning inline comments...done")))))
  7125. (defun vhdl-align-inline-comment-group (&optional spacing)
  7126. "Align inline comments within a group of lines between empty lines."
  7127. (interactive)
  7128. (save-excursion
  7129. (let ((start (point))
  7130. beg end)
  7131. (setq end (if (re-search-forward vhdl-align-group-separate nil t)
  7132. (point-marker) (point-max)))
  7133. (goto-char start)
  7134. (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
  7135. (point) (point-min)))
  7136. (untabify beg end)
  7137. (message "Aligning inline comments...")
  7138. (vhdl-align-inline-comment-region-1 beg end)
  7139. (when vhdl-indent-tabs-mode
  7140. (tabify beg end))
  7141. (message "Aligning inline comments...done"))))
  7142. (defun vhdl-align-inline-comment-buffer ()
  7143. "Align inline comments within buffer. Groups of code lines separated by
  7144. empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
  7145. (interactive)
  7146. (vhdl-align-inline-comment-region (point-min) (point-max)))
  7147. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7148. ;; Fixup whitespace
  7149. (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
  7150. "Fixup whitespace in region. Surround operator symbols by one space,
  7151. eliminate multiple spaces (except at beginning of line), eliminate spaces at
  7152. end of line, do nothing in comments and strings."
  7153. (interactive "r")
  7154. (unless no-message (message "Fixing up whitespace..."))
  7155. (save-excursion
  7156. (goto-char end)
  7157. (setq end (point-marker))
  7158. ;; have no space before and one space after `,' and ';'
  7159. (goto-char beg)
  7160. (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
  7161. (if (match-string 1)
  7162. (goto-char (match-end 1))
  7163. (replace-match "\\3 " nil nil nil 2)))
  7164. ;; have no space after `('
  7165. (goto-char beg)
  7166. (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\((\\)\\s-+" end t)
  7167. (if (match-string 1)
  7168. (goto-char (match-end 1))
  7169. (replace-match "\\2")))
  7170. ;; have no space before `)'
  7171. (goto-char beg)
  7172. (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
  7173. (if (match-string 1)
  7174. (goto-char (match-end 1))
  7175. (replace-match "\\2")))
  7176. ;; surround operator symbols by one space
  7177. (goto-char beg)
  7178. (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|\'.\'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\([^/:<>=]\\)\\(:\\|\\??=\\|\\??<<\\|\\??>>\\|\\??<\\|\\??>\\|:=\\|\\??<=\\|\\??>=\\|=>\\|\\??/=\\|\\?\\?\\)\\([^=>]\\|$\\)\\)" end t)
  7179. (if (or (match-string 1)
  7180. (<= (match-beginning 0) ; not if at boi
  7181. (save-excursion (back-to-indentation) (point))))
  7182. (goto-char (match-end 0))
  7183. (replace-match "\\3 \\4 \\5")
  7184. (goto-char (match-end 2))))
  7185. ;; eliminate multiple spaces and spaces at end of line
  7186. (goto-char beg)
  7187. (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
  7188. (and (looking-at "--.*") (re-search-forward "--.*" end t))
  7189. (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
  7190. (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
  7191. (progn (replace-match "" nil nil) t))
  7192. (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
  7193. (progn (replace-match ";" nil nil) t))
  7194. (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
  7195. (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
  7196. (progn (replace-match " " nil nil) t))
  7197. (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
  7198. (progn (replace-match " " nil nil) t))
  7199. (and (looking-at "-") (re-search-forward "-" end t))
  7200. ; (re-search-forward "[^ \t-]+" end t))))
  7201. (re-search-forward "[^ \t\"-]+" end t))))
  7202. (unless no-message (message "Fixing up whitespace...done")))
  7203. (defun vhdl-fixup-whitespace-buffer ()
  7204. "Fixup whitespace in buffer. Surround operator symbols by one space,
  7205. eliminate multiple spaces (except at beginning of line), eliminate spaces at
  7206. end of line, do nothing in comments."
  7207. (interactive)
  7208. (vhdl-fixup-whitespace-region (point-min) (point-max)))
  7209. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7210. ;; Beautify
  7211. (defun vhdl-beautify-region (beg end)
  7212. "Beautify region by applying indentation, whitespace fixup, alignment, and
  7213. case fixing to a region. Calls functions `vhdl-indent-buffer',
  7214. `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
  7215. `vhdl-fix-case-buffer'."
  7216. (interactive "r")
  7217. (setq end (save-excursion (goto-char end) (point-marker)))
  7218. (vhdl-indent-region beg end)
  7219. (let ((vhdl-align-groups t))
  7220. (vhdl-align-region beg end))
  7221. (vhdl-fix-case-region beg end))
  7222. (defun vhdl-beautify-buffer ()
  7223. "Beautify buffer by applying indentation, whitespace fixup, alignment, and
  7224. case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
  7225. buffer."
  7226. (interactive)
  7227. (vhdl-beautify-region (point-min) (point-max))
  7228. (when noninteractive (save-buffer)))
  7229. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7230. ;; Code filling
  7231. (defun vhdl-fill-region (beg end &optional arg)
  7232. "Fill lines for a region of code."
  7233. (interactive "r\np")
  7234. (save-excursion
  7235. (goto-char beg)
  7236. (let ((margin (if arg (current-indentation) (current-column))))
  7237. (goto-char end)
  7238. (setq end (point-marker))
  7239. ;; remove inline comments, newlines and whitespace
  7240. (vhdl-comment-kill-region beg end)
  7241. (vhdl-comment-kill-inline-region beg end)
  7242. (subst-char-in-region beg (1- end) ?\n ?\ )
  7243. (vhdl-fixup-whitespace-region beg end)
  7244. ;; wrap and end-comment-column
  7245. (goto-char beg)
  7246. (while (re-search-forward "\\s-" end t)
  7247. (when(> (current-column) vhdl-end-comment-column)
  7248. (backward-char)
  7249. (when (re-search-backward "\\s-" beg t)
  7250. (replace-match "\n")
  7251. (indent-to margin)))))))
  7252. (defun vhdl-fill-group ()
  7253. "Fill group of lines between empty lines."
  7254. (interactive)
  7255. (vhdl-do-group 'vhdl-fill-region))
  7256. (defun vhdl-fill-list ()
  7257. "Fill the lines of a list surrounded by a balanced group of parentheses."
  7258. (interactive)
  7259. (vhdl-do-list 'vhdl-fill-region))
  7260. (defun vhdl-fill-same-indent ()
  7261. "Fill the lines of block of lines with same indent."
  7262. (interactive)
  7263. (vhdl-do-same-indent 'vhdl-fill-region))
  7264. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7265. ;;; Code updating/fixing
  7266. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7267. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7268. ;; Sensitivity list update
  7269. ;; Strategy:
  7270. ;; - no sensitivity list is generated for processes with wait statements
  7271. ;; - otherwise, do the following:
  7272. ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
  7273. ;; 2. scan for all signals already in the sensitivity list (in order to catch
  7274. ;; manually entered global signals)
  7275. ;; 3. signals from 1. and 2. form the list of visible signals
  7276. ;; 4. search for if/elsif conditions containing an event (sequential code)
  7277. ;; 5. scan for strings that are within syntactical regions where signals are
  7278. ;; read but not within sequential code, and that correspond to visible
  7279. ;; signals
  7280. ;; 6. replace sensitivity list by list of signals from 5.
  7281. (defun vhdl-update-sensitivity-list-process ()
  7282. "Update sensitivity list of current process."
  7283. (interactive)
  7284. (save-excursion
  7285. (vhdl-prepare-search-2
  7286. (end-of-line)
  7287. ;; look whether in process
  7288. (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
  7289. (equal (upcase (match-string 2)) "PROCESS")
  7290. (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
  7291. (error "ERROR: Not within a process")
  7292. (message "Updating sensitivity list...")
  7293. (vhdl-update-sensitivity-list)
  7294. (message "Updating sensitivity list...done")))))
  7295. (defun vhdl-update-sensitivity-list-buffer ()
  7296. "Update sensitivity list of all processes in current buffer."
  7297. (interactive)
  7298. (save-excursion
  7299. (vhdl-prepare-search-2
  7300. (goto-char (point-min))
  7301. (message "Updating sensitivity lists...")
  7302. (while (re-search-forward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?process\\>" nil t)
  7303. (goto-char (match-beginning 0))
  7304. (condition-case nil (vhdl-update-sensitivity-list) (error "")))
  7305. (message "Updating sensitivity lists...done"))))
  7306. (defun vhdl-update-sensitivity-list ()
  7307. "Update sensitivity list."
  7308. (let ((proc-beg (point))
  7309. (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
  7310. (proc-mid (vhdl-re-search-backward
  7311. "\\(\\(\\<begin\\>\\)\\|^\\s-*process\\>\\)" nil t))
  7312. seq-region-list)
  7313. (cond
  7314. ;; error if 'begin' keyword missing
  7315. ((not (match-string 2))
  7316. (error "ERROR: No 'begin' keyword found"))
  7317. ;; search for wait statement (no sensitivity list allowed)
  7318. ((progn (goto-char proc-mid)
  7319. (vhdl-re-search-forward "\\<wait\\>" proc-end t))
  7320. (error "ERROR: Process with wait statement, sensitivity list not generated"))
  7321. ;; combinational process (update sensitivity list)
  7322. (t
  7323. (let
  7324. ;; scan for visible signals
  7325. ((visible-list (vhdl-get-visible-signals))
  7326. ;; define syntactic regions where signals are read
  7327. (scan-regions-list
  7328. '(;; right-hand side of signal/variable assignment
  7329. ;; (special case: "<=" is relational operator in a condition)
  7330. ((re-search-forward "[<:]=" proc-end t)
  7331. (re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
  7332. ;; if condition
  7333. ((re-search-forward "^\\s-*if\\>" proc-end t)
  7334. (re-search-forward "\\<then\\>" proc-end t))
  7335. ;; elsif condition
  7336. ((re-search-forward "\\<elsif\\>" proc-end t)
  7337. (re-search-forward "\\<then\\>" proc-end t))
  7338. ;; while loop condition
  7339. ((re-search-forward "^\\s-*while\\>" proc-end t)
  7340. (re-search-forward "\\<loop\\>" proc-end t))
  7341. ;; exit/next condition
  7342. ((re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
  7343. (re-search-forward ";" proc-end t))
  7344. ;; assert condition
  7345. ((re-search-forward "\\<assert\\>" proc-end t)
  7346. (re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
  7347. ;; case expression
  7348. ((re-search-forward "^\\s-*case\\>" proc-end t)
  7349. (re-search-forward "\\<is\\>" proc-end t))
  7350. ;; parameter list of procedure call, array index
  7351. ((and (re-search-forward "^\\s-*\\(\\w\\|\\.\\)+[ \t\n\r\f]*(" proc-end t)
  7352. (1- (point)))
  7353. (progn (backward-char) (forward-sexp)
  7354. (while (looking-at "(") (forward-sexp)) (point)))))
  7355. name field read-list sens-list signal-list
  7356. sens-beg sens-end beg end margin)
  7357. ;; scan for signals in old sensitivity list
  7358. (goto-char proc-beg)
  7359. (re-search-forward "\\<process\\>" proc-mid t)
  7360. (if (not (looking-at "[ \t\n\r\f]*("))
  7361. (setq sens-beg (point))
  7362. (setq sens-beg (re-search-forward "\\([ \t\n\r\f]*\\)([ \t\n\r\f]*" nil t))
  7363. (goto-char (match-end 1))
  7364. (forward-sexp)
  7365. (setq sens-end (1- (point)))
  7366. (goto-char sens-beg)
  7367. (while (and (re-search-forward "\\(\\w+\\)" sens-end t)
  7368. (setq sens-list
  7369. (cons (downcase (match-string 0)) sens-list))
  7370. (re-search-forward "\\s-*,\\s-*" sens-end t))))
  7371. (setq signal-list (append visible-list sens-list))
  7372. ;; search for sequential parts
  7373. (goto-char proc-mid)
  7374. (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
  7375. (setq end (re-search-forward "\\<then\\>" proc-end t))
  7376. (when (re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
  7377. (goto-char end)
  7378. (backward-word 1)
  7379. (vhdl-forward-sexp)
  7380. (setq seq-region-list (cons (cons end (point)) seq-region-list))
  7381. (beginning-of-line)))
  7382. ;; scan for signals read in process
  7383. (while scan-regions-list
  7384. (goto-char proc-mid)
  7385. (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
  7386. (setq end (eval (nth 1 (car scan-regions-list)))))
  7387. (goto-char beg)
  7388. (unless (or (vhdl-in-literal)
  7389. (and seq-region-list
  7390. (let ((tmp-list seq-region-list))
  7391. (while (and tmp-list
  7392. (< (point) (caar tmp-list)))
  7393. (setq tmp-list (cdr tmp-list)))
  7394. (and tmp-list (< (point) (cdar tmp-list))))))
  7395. (while (vhdl-re-search-forward "[^'\".]\\<\\([a-zA-Z]\\w*\\)\\(\\(\\.\\w+\\|[ \t\n\r\f]*([^)]*)\\)*\\)[ \t\n\r\f]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
  7396. (setq name (match-string 1))
  7397. (when vhdl-array-index-record-field-in-sensitivity-list
  7398. (setq field (match-string 2)))
  7399. (when (and (not (match-string 6)) ; not when formal parameter
  7400. (not (and (match-string 5) ; not event attribute
  7401. (not (member (downcase (match-string 5))
  7402. '("event" "last_event" "transaction")))))
  7403. (member (downcase name) signal-list))
  7404. (unless (member-ignore-case (concat name field) read-list)
  7405. (setq read-list (cons (concat name field) read-list))))
  7406. (goto-char (match-end 1)))))
  7407. (setq scan-regions-list (cdr scan-regions-list)))
  7408. ;; update sensitivity list
  7409. (goto-char sens-beg)
  7410. (if sens-end
  7411. (delete-region sens-beg sens-end)
  7412. (when read-list
  7413. (insert " ()") (backward-char)))
  7414. (setq read-list (sort read-list 'string<))
  7415. (when read-list
  7416. (setq margin (current-column))
  7417. (insert (car read-list))
  7418. (setq read-list (cdr read-list))
  7419. (while read-list
  7420. (insert ",")
  7421. (if (<= (+ (current-column) (length (car read-list)) 2)
  7422. end-comment-column)
  7423. (insert " ")
  7424. (insert "\n") (indent-to margin))
  7425. (insert (car read-list))
  7426. (setq read-list (cdr read-list)))))))))
  7427. (defun vhdl-get-visible-signals ()
  7428. "Get all signals visible in the current block."
  7429. (let (beg end signal-list entity-name file-name)
  7430. (vhdl-prepare-search-2
  7431. ;; get entity name
  7432. (save-excursion
  7433. (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
  7434. (not (equal "END" (upcase (match-string 1))))
  7435. (setq entity-name (match-string 2)))
  7436. (error "ERROR: Not within an architecture")))
  7437. ;; search for signals declared in entity port clause
  7438. (save-excursion
  7439. (goto-char (point-min))
  7440. (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
  7441. (setq file-name
  7442. (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
  7443. "." (file-name-extension (buffer-file-name)))))
  7444. (vhdl-visit-file
  7445. file-name t
  7446. (vhdl-prepare-search-2
  7447. (goto-char (point-min))
  7448. (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
  7449. (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
  7450. (when (setq beg (vhdl-re-search-forward
  7451. "\\<port[ \t\n\r\f]*("
  7452. (save-excursion
  7453. (re-search-forward "^end\\>" nil t)) t))
  7454. (setq end (save-excursion
  7455. (backward-char) (forward-sexp) (point)))
  7456. (vhdl-forward-syntactic-ws)
  7457. (while (< (point) end)
  7458. (when (looking-at "signal[ \t\n\r\f]+")
  7459. (goto-char (match-end 0)))
  7460. (while (looking-at "\\(\\w+\\)[ \t\n\r\f,]+")
  7461. (setq signal-list
  7462. (cons (downcase (match-string 1)) signal-list))
  7463. (goto-char (match-end 0))
  7464. (vhdl-forward-syntactic-ws))
  7465. (re-search-forward ";" end 1)
  7466. (vhdl-forward-syntactic-ws)))))))
  7467. ;; search for signals declared in architecture declarative part
  7468. (save-excursion
  7469. (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
  7470. (not (equal "END" (upcase (match-string 1))))
  7471. (setq end (re-search-forward "^begin\\>" nil t))))
  7472. (error "ERROR: No architecture declarative part found")
  7473. ;; scan for all declared signal and alias names
  7474. (goto-char beg)
  7475. (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
  7476. (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
  7477. (if (match-string 2)
  7478. ;; scan signal name
  7479. (while (looking-at "[ \t\n\r\f,]+\\(\\w+\\)")
  7480. (setq signal-list
  7481. (cons (downcase (match-string 1)) signal-list))
  7482. (goto-char (match-end 0)))
  7483. ;; scan alias name, check is alias of (declared) signal
  7484. (when (and (looking-at "[ \t\n\r\f]+\\(\\w+\\)[^;]*\\<is[ \t\n\r\f]+\\(\\w+\\)")
  7485. (member (downcase (match-string 2)) signal-list))
  7486. (setq signal-list
  7487. (cons (downcase (match-string 1)) signal-list))
  7488. (goto-char (match-end 0))))
  7489. (setq beg (point))))))
  7490. ;; search for signals declared in surrounding block declarative parts
  7491. (save-excursion
  7492. (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*block\\|\\(end\\)\\s-+block\\)\\>" nil t))
  7493. (match-string 2))
  7494. (goto-char (match-end 2))
  7495. (vhdl-backward-sexp)
  7496. (re-search-backward "^\\s-*\\w+\\s-*:\\s-*block\\>" nil t))
  7497. beg)
  7498. (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
  7499. ;; scan for all declared signal names
  7500. (goto-char beg)
  7501. (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
  7502. (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
  7503. (if (match-string 2)
  7504. ;; scan signal name
  7505. (while (looking-at "[ \t\n,]+\\(\\w+\\)")
  7506. (setq signal-list
  7507. (cons (downcase (match-string 1)) signal-list))
  7508. (goto-char (match-end 0)))
  7509. ;; scan alias name, check is alias of (declared) signal
  7510. (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
  7511. (member (downcase (match-string 2)) signal-list))
  7512. (setq signal-list
  7513. (cons (downcase (match-string 1)) signal-list))
  7514. (goto-char (match-end 0))))))
  7515. (goto-char beg)))
  7516. signal-list)))
  7517. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7518. ;; Generic/port clause fixing
  7519. (defun vhdl-fix-clause-buffer ()
  7520. "Fix all generic/port clauses in current buffer."
  7521. (interactive)
  7522. (save-excursion
  7523. (vhdl-prepare-search-2
  7524. (goto-char (point-min))
  7525. (message "Fixing generic/port clauses...")
  7526. (while (re-search-forward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t)
  7527. (goto-char (match-end 0))
  7528. (condition-case nil (vhdl-fix-clause) (error "")))
  7529. (message "Fixing generic/port clauses...done"))))
  7530. (defun vhdl-fix-clause ()
  7531. "Fix closing parenthesis within generic/port clause."
  7532. (interactive)
  7533. (save-excursion
  7534. (vhdl-prepare-search-2
  7535. (let ((pos (point))
  7536. beg end)
  7537. (end-of-line)
  7538. (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t))
  7539. (error "ERROR: Not within a generic/port clause")
  7540. ;; search for end of clause
  7541. (goto-char (match-end 0))
  7542. (setq beg (1- (point)))
  7543. (vhdl-forward-syntactic-ws)
  7544. (while (looking-at "\\w+\\([ \t\n\r\f]*,[ \t\n\r\f]*\\w+\\)*[ \t\n\r\f]*:[ \t\n\r\f]*\\w+[^;]*;")
  7545. (goto-char (1- (match-end 0)))
  7546. (setq end (point-marker))
  7547. (forward-char)
  7548. (vhdl-forward-syntactic-ws))
  7549. (goto-char end)
  7550. (when (> pos (point-at-eol))
  7551. (error "ERROR: Not within a generic/port clause"))
  7552. ;; delete closing parenthesis on separate line (not supported style)
  7553. (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
  7554. (vhdl-line-kill)
  7555. (vhdl-backward-syntactic-ws)
  7556. (setq end (point-marker))
  7557. (insert ";"))
  7558. ;; delete superfluous parentheses
  7559. (while (progn (goto-char beg)
  7560. (condition-case () (forward-sexp)
  7561. (error (goto-char (point-max))))
  7562. (< (point) end))
  7563. (delete-char -1))
  7564. ;; add closing parenthesis
  7565. (when (> (point) end)
  7566. (goto-char end)
  7567. (insert ")")))))))
  7568. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7569. ;; Miscellaneous
  7570. (defun vhdl-remove-trailing-spaces ()
  7571. "Remove trailing spaces in the whole buffer."
  7572. (interactive)
  7573. (save-match-data
  7574. (save-excursion
  7575. (goto-char (point-min))
  7576. (while (re-search-forward "[ \t]+$" (point-max) t)
  7577. (unless (vhdl-in-literal)
  7578. (replace-match "" nil nil))))))
  7579. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7580. ;;; Electrification
  7581. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7582. (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
  7583. "Syntax of prompt inserted by template generators.")
  7584. (defvar vhdl-template-invoked-by-hook nil
  7585. "Indicates whether a template has been invoked by a hook or by key or menu.
  7586. Used for undoing after template abortion.")
  7587. ;; correct different behavior of function `unread-command-events' in XEmacs
  7588. (defun vhdl-character-to-event (arg))
  7589. (defalias 'vhdl-character-to-event
  7590. (if (fboundp 'character-to-event) 'character-to-event 'identity))
  7591. (defun vhdl-work-library ()
  7592. "Return the working library name of the current project or \"work\" if no
  7593. project is defined."
  7594. (vhdl-resolve-env-variable
  7595. (or (nth 6 (aget vhdl-project-alist vhdl-project)) vhdl-default-library)))
  7596. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7597. ;; Enabling/disabling
  7598. (define-minor-mode vhdl-electric-mode
  7599. "Toggle VHDL electric mode.
  7600. With a prefix argument ARG, enable the mode if ARG is positive,
  7601. and disable it otherwise. If called from Lisp, enable it if ARG
  7602. is omitted or nil."
  7603. :global t)
  7604. (define-minor-mode vhdl-stutter-mode
  7605. "Toggle VHDL stuttering mode.
  7606. With a prefix argument ARG, enable the mode if ARG is positive,
  7607. and disable it otherwise. If called from Lisp, enable it if ARG
  7608. is omitted or nil."
  7609. :global t)
  7610. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7611. ;; Stuttering
  7612. (defun vhdl-electric-dash (count)
  7613. "-- starts a comment, --- draws a horizontal line,
  7614. ---- starts a display comment."
  7615. (interactive "p")
  7616. (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
  7617. (cond
  7618. ((and abbrev-start-location (= abbrev-start-location (point)))
  7619. (setq abbrev-start-location nil)
  7620. (goto-char last-abbrev-location)
  7621. (beginning-of-line nil)
  7622. (vhdl-comment-display))
  7623. ((/= (preceding-char) ?-) ; standard dash (minus)
  7624. (self-insert-command count))
  7625. (t (self-insert-command count)
  7626. (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
  7627. (let ((next-input (read-char)))
  7628. (if (= next-input ?-) ; triple dash
  7629. (progn
  7630. (vhdl-comment-display-line)
  7631. (message
  7632. "Enter '-' for display comment, else continue coding")
  7633. (let ((next-input (read-char)))
  7634. (if (= next-input ?-) ; four dashes
  7635. (vhdl-comment-display t)
  7636. (setq unread-command-events ; pushback the char
  7637. (list (vhdl-character-to-event next-input))))))
  7638. (setq unread-command-events ; pushback the char
  7639. (list (vhdl-character-to-event next-input)))
  7640. (vhdl-comment-insert)))))
  7641. (self-insert-command count)))
  7642. (defun vhdl-electric-open-bracket (count) "'[' --> '(', '([' --> '['"
  7643. (interactive "p")
  7644. (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
  7645. (if (= (preceding-char) ?\()
  7646. (progn (delete-char -1) (insert-char ?\[ 1))
  7647. (insert-char ?\( 1))
  7648. (self-insert-command count)))
  7649. (defun vhdl-electric-close-bracket (count) "']' --> ')', ')]' --> ']'"
  7650. (interactive "p")
  7651. (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
  7652. (progn
  7653. (if (= (preceding-char) ?\))
  7654. (progn (delete-char -1) (insert-char ?\] 1))
  7655. (insert-char ?\) 1))
  7656. (blink-matching-open))
  7657. (self-insert-command count)))
  7658. (defun vhdl-electric-quote (count) "'' --> \""
  7659. (interactive "p")
  7660. (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
  7661. (if (= (preceding-char) last-input-event)
  7662. (progn (delete-char -1) (insert-char ?\" 1))
  7663. (insert-char ?\' 1))
  7664. (self-insert-command count)))
  7665. (defun vhdl-electric-semicolon (count) "';;' --> ' : ', ': ;' --> ' := '"
  7666. (interactive "p")
  7667. (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
  7668. (cond ((= (preceding-char) last-input-event)
  7669. (progn (delete-char -1)
  7670. (unless (eq (preceding-char) ? ) (insert " "))
  7671. (insert ": ")
  7672. (setq this-command 'vhdl-electric-colon)))
  7673. ((and
  7674. (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
  7675. (progn (delete-char -1) (insert "= ")))
  7676. (t (insert-char ?\; 1)))
  7677. (self-insert-command count)))
  7678. (defun vhdl-electric-comma (count) "',,' --> ' <= '"
  7679. (interactive "p")
  7680. (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
  7681. (cond ((= (preceding-char) last-input-event)
  7682. (progn (delete-char -1)
  7683. (unless (eq (preceding-char) ? ) (insert " "))
  7684. (insert "<= ")))
  7685. (t (insert-char ?\, 1)))
  7686. (self-insert-command count)))
  7687. (defun vhdl-electric-period (count) "'..' --> ' => '"
  7688. (interactive "p")
  7689. (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
  7690. (cond ((= (preceding-char) last-input-event)
  7691. (progn (delete-char -1)
  7692. (unless (eq (preceding-char) ? ) (insert " "))
  7693. (insert "=> ")))
  7694. (t (insert-char ?\. 1)))
  7695. (self-insert-command count)))
  7696. (defun vhdl-electric-equal (count) "'==' --> ' == '"
  7697. (interactive "p")
  7698. (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
  7699. (cond ((= (preceding-char) last-input-event)
  7700. (progn (delete-char -1)
  7701. (unless (eq (preceding-char) ? ) (insert " "))
  7702. (insert "== ")))
  7703. (t (insert-char ?\= 1)))
  7704. (self-insert-command count)))
  7705. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7706. ;; VHDL templates
  7707. (defun vhdl-template-paired-parens ()
  7708. "Insert a pair of round parentheses, placing point between them."
  7709. (interactive)
  7710. (insert "()")
  7711. (backward-char))
  7712. (defun vhdl-template-alias ()
  7713. "Insert alias declaration."
  7714. (interactive)
  7715. (let ((start (point)))
  7716. (vhdl-insert-keyword "ALIAS ")
  7717. (when (vhdl-template-field "name" nil t start (point))
  7718. (insert " : ")
  7719. (unless (vhdl-template-field
  7720. (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
  7721. nil t)
  7722. (delete-char -3))
  7723. (vhdl-insert-keyword " IS ")
  7724. (vhdl-template-field "name" ";")
  7725. (vhdl-comment-insert-inline))))
  7726. (defun vhdl-template-architecture ()
  7727. "Insert architecture."
  7728. (interactive)
  7729. (let ((margin (current-indentation))
  7730. (start (point))
  7731. arch-name)
  7732. (vhdl-insert-keyword "ARCHITECTURE ")
  7733. (when (setq arch-name
  7734. (vhdl-template-field "name" nil t start (point)))
  7735. (vhdl-insert-keyword " OF ")
  7736. (if (save-excursion
  7737. (vhdl-prepare-search-1
  7738. (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
  7739. (insert (match-string 1))
  7740. (vhdl-template-field "entity name"))
  7741. (vhdl-insert-keyword " IS\n")
  7742. (vhdl-template-begin-end
  7743. (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
  7744. (memq vhdl-insert-empty-lines '(unit all))))))
  7745. (defun vhdl-template-array (kind &optional secondary)
  7746. "Insert array type definition."
  7747. (interactive)
  7748. (let ((start (point)))
  7749. (vhdl-insert-keyword "ARRAY (")
  7750. (when (or (vhdl-template-field "range" nil (not secondary) start (point))
  7751. secondary)
  7752. (vhdl-insert-keyword ") OF ")
  7753. (vhdl-template-field (if (eq kind 'type) "type" "nature"))
  7754. (vhdl-insert-keyword ";"))))
  7755. (defun vhdl-template-assert ()
  7756. "Insert an assertion statement."
  7757. (interactive)
  7758. (let ((start (point)))
  7759. (vhdl-insert-keyword "ASSERT ")
  7760. (when vhdl-conditions-in-parenthesis (insert "("))
  7761. (when (vhdl-template-field "condition (negated)" nil t start (point))
  7762. (when vhdl-conditions-in-parenthesis (insert ")"))
  7763. (setq start (point))
  7764. (vhdl-insert-keyword " REPORT ")
  7765. (unless (vhdl-template-field "string expression" nil nil nil nil t)
  7766. (delete-region start (point)))
  7767. (setq start (point))
  7768. (vhdl-insert-keyword " SEVERITY ")
  7769. (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
  7770. (delete-region start (point)))
  7771. (insert ";"))))
  7772. (defun vhdl-template-attribute ()
  7773. "Insert an attribute declaration or specification."
  7774. (interactive)
  7775. (if (eq (vhdl-decision-query
  7776. "attribute" "(d)eclaration or (s)pecification?" t) ?s)
  7777. (vhdl-template-attribute-spec)
  7778. (vhdl-template-attribute-decl)))
  7779. (defun vhdl-template-attribute-decl ()
  7780. "Insert an attribute declaration."
  7781. (interactive)
  7782. (let ((start (point)))
  7783. (vhdl-insert-keyword "ATTRIBUTE ")
  7784. (when (vhdl-template-field "name" " : " t start (point))
  7785. (vhdl-template-field "type" ";")
  7786. (vhdl-comment-insert-inline))))
  7787. (defun vhdl-template-attribute-spec ()
  7788. "Insert an attribute specification."
  7789. (interactive)
  7790. (let ((start (point)))
  7791. (vhdl-insert-keyword "ATTRIBUTE ")
  7792. (when (vhdl-template-field "name" nil t start (point))
  7793. (vhdl-insert-keyword " OF ")
  7794. (vhdl-template-field "entity names | OTHERS | ALL" " : ")
  7795. (vhdl-template-field "entity class")
  7796. (vhdl-insert-keyword " IS ")
  7797. (vhdl-template-field "expression" ";"))))
  7798. (defun vhdl-template-block ()
  7799. "Insert a block."
  7800. (interactive)
  7801. (let ((margin (current-indentation))
  7802. (start (point))
  7803. label)
  7804. (vhdl-insert-keyword ": BLOCK ")
  7805. (goto-char start)
  7806. (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
  7807. (forward-word 1)
  7808. (forward-char 1)
  7809. (insert "(")
  7810. (if (vhdl-template-field "[guard expression]" nil t)
  7811. (insert ")")
  7812. (delete-char -2))
  7813. (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
  7814. (insert "\n")
  7815. (vhdl-template-begin-end "BLOCK" label margin)
  7816. (vhdl-comment-block))))
  7817. (defun vhdl-template-block-configuration ()
  7818. "Insert a block configuration statement."
  7819. (interactive)
  7820. (let ((margin (current-indentation))
  7821. (start (point)))
  7822. (vhdl-insert-keyword "FOR ")
  7823. (when (vhdl-template-field "block name" nil t start (point))
  7824. (vhdl-insert-keyword "\n\n")
  7825. (indent-to margin)
  7826. (vhdl-insert-keyword "END FOR;")
  7827. (end-of-line 0)
  7828. (indent-to (+ margin vhdl-basic-offset)))))
  7829. (defun vhdl-template-break ()
  7830. "Insert a break statement."
  7831. (interactive)
  7832. (let (position)
  7833. (vhdl-insert-keyword "BREAK")
  7834. (setq position (point))
  7835. (insert " ")
  7836. (while (or
  7837. (progn (vhdl-insert-keyword "FOR ")
  7838. (if (vhdl-template-field "[quantity name]" " USE " t)
  7839. (progn (vhdl-template-field "quantity name" " => ") t)
  7840. (delete-region (point)
  7841. (progn (forward-word -1) (point)))
  7842. nil))
  7843. (vhdl-template-field "[quantity name]" " => " t))
  7844. (vhdl-template-field "expression")
  7845. (setq position (point))
  7846. (insert ", "))
  7847. (delete-region position (point))
  7848. (unless (vhdl-sequential-statement-p)
  7849. (vhdl-insert-keyword " ON ")
  7850. (if (vhdl-template-field "[sensitivity list]" nil t)
  7851. (setq position (point))
  7852. (delete-region position (point))))
  7853. (vhdl-insert-keyword " WHEN ")
  7854. (when vhdl-conditions-in-parenthesis (insert "("))
  7855. (if (vhdl-template-field "[condition]" nil t)
  7856. (when vhdl-conditions-in-parenthesis (insert ")"))
  7857. (delete-region position (point)))
  7858. (insert ";")))
  7859. (defun vhdl-template-case (&optional kind)
  7860. "Insert a case statement."
  7861. (interactive)
  7862. (let ((margin (current-indentation))
  7863. (start (point))
  7864. label)
  7865. (unless kind (setq kind (if (or (vhdl-sequential-statement-p)
  7866. (not (vhdl-standard-p 'ams))) 'is 'use)))
  7867. (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
  7868. (vhdl-insert-keyword "CASE ")
  7869. (vhdl-insert-keyword ": CASE ")
  7870. (goto-char start)
  7871. (setq label (vhdl-template-field "[label]" nil t))
  7872. (unless label (delete-char 2))
  7873. (forward-word 1)
  7874. (forward-char 1))
  7875. (when (vhdl-template-field "expression" nil t start (point))
  7876. (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
  7877. (indent-to margin)
  7878. (vhdl-insert-keyword "END CASE")
  7879. (when label (insert " " label))
  7880. (insert ";")
  7881. (forward-line -1)
  7882. (indent-to (+ margin vhdl-basic-offset))
  7883. (vhdl-insert-keyword "WHEN ")
  7884. (let ((position (point)))
  7885. (insert " => ;\n")
  7886. (indent-to (+ margin vhdl-basic-offset))
  7887. (vhdl-insert-keyword "WHEN OTHERS => null;")
  7888. (goto-char position)))))
  7889. (defun vhdl-template-case-is ()
  7890. "Insert a sequential case statement."
  7891. (interactive)
  7892. (vhdl-template-case 'is))
  7893. (defun vhdl-template-case-use ()
  7894. "Insert a simultaneous case statement."
  7895. (interactive)
  7896. (vhdl-template-case 'use))
  7897. (defun vhdl-template-component ()
  7898. "Insert a component declaration."
  7899. (interactive)
  7900. (vhdl-template-component-decl))
  7901. (defun vhdl-template-component-conf ()
  7902. "Insert a component configuration (uses `vhdl-template-configuration-spec'
  7903. since these are almost equivalent)."
  7904. (interactive)
  7905. (let ((margin (current-indentation))
  7906. (result (vhdl-template-configuration-spec t)))
  7907. (when result
  7908. (insert "\n")
  7909. (indent-to margin)
  7910. (vhdl-insert-keyword "END FOR;")
  7911. (when (eq result 'no-use)
  7912. (end-of-line -0)))))
  7913. (defun vhdl-template-component-decl ()
  7914. "Insert a component declaration."
  7915. (interactive)
  7916. (let ((margin (current-indentation))
  7917. (start (point))
  7918. name end-column)
  7919. (vhdl-insert-keyword "COMPONENT ")
  7920. (when (setq name (vhdl-template-field "name" nil t start (point)))
  7921. (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
  7922. (insert "\n\n")
  7923. (indent-to margin)
  7924. (vhdl-insert-keyword "END COMPONENT")
  7925. (unless (vhdl-standard-p '87) (insert " " name))
  7926. (insert ";")
  7927. (setq end-column (current-column))
  7928. (end-of-line -0)
  7929. (indent-to (+ margin vhdl-basic-offset))
  7930. (vhdl-template-generic-list t t)
  7931. (insert "\n")
  7932. (indent-to (+ margin vhdl-basic-offset))
  7933. (vhdl-template-port-list t)
  7934. (beginning-of-line 2)
  7935. (forward-char end-column))))
  7936. (defun vhdl-template-component-inst ()
  7937. "Insert a component instantiation statement."
  7938. (interactive)
  7939. (let ((margin (current-indentation))
  7940. (start (point))
  7941. unit position)
  7942. (when (vhdl-template-field "instance label" nil t start (point))
  7943. (insert ": ")
  7944. (if (not (vhdl-use-direct-instantiation))
  7945. (vhdl-template-field "component name")
  7946. ;; direct instantiation
  7947. (setq unit (vhdl-template-field
  7948. "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
  7949. (setq unit (upcase (or unit "")))
  7950. (cond ((equal unit "ENTITY")
  7951. (vhdl-template-field "library name" "." nil nil nil nil
  7952. (vhdl-work-library))
  7953. (vhdl-template-field "entity name" "(")
  7954. (if (vhdl-template-field "[architecture name]" nil t)
  7955. (insert ")")
  7956. (delete-char -1)))
  7957. ((equal unit "CONFIGURATION")
  7958. (vhdl-template-field "library name" "." nil nil nil nil
  7959. (vhdl-work-library))
  7960. (vhdl-template-field "configuration name"))
  7961. (t (vhdl-template-field "component name"))))
  7962. (insert "\n")
  7963. (indent-to (+ margin vhdl-basic-offset))
  7964. (setq position (point))
  7965. (vhdl-insert-keyword "GENERIC ")
  7966. (when (vhdl-template-map position t t)
  7967. (insert "\n")
  7968. (indent-to (+ margin vhdl-basic-offset)))
  7969. (setq position (point))
  7970. (vhdl-insert-keyword "PORT ")
  7971. (unless (vhdl-template-map position t t)
  7972. (delete-region (line-beginning-position) (point))
  7973. (delete-char -1))
  7974. (insert ";"))))
  7975. (defun vhdl-template-conditional-signal-asst ()
  7976. "Insert a conditional signal assignment."
  7977. (interactive)
  7978. (when (vhdl-template-field "target signal")
  7979. (insert " <= ")
  7980. ; (if (not (equal (vhdl-template-field "[GUARDED] [TRANSPORT]") ""))
  7981. ; (insert " "))
  7982. (let ((margin (current-column))
  7983. (start (point))
  7984. position)
  7985. (vhdl-template-field "waveform")
  7986. (setq position (point))
  7987. (vhdl-insert-keyword " WHEN ")
  7988. (when vhdl-conditions-in-parenthesis (insert "("))
  7989. (while (and (vhdl-template-field "[condition]" nil t)
  7990. (progn
  7991. (when vhdl-conditions-in-parenthesis (insert ")"))
  7992. (setq position (point))
  7993. (vhdl-insert-keyword " ELSE")
  7994. (insert "\n")
  7995. (indent-to margin)
  7996. (vhdl-template-field "[waveform]" nil t)))
  7997. (setq position (point))
  7998. (vhdl-insert-keyword " WHEN ")
  7999. (when vhdl-conditions-in-parenthesis (insert "(")))
  8000. (delete-region position (point))
  8001. (insert ";")
  8002. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
  8003. (defun vhdl-template-configuration ()
  8004. "Insert a configuration specification if within an architecture,
  8005. a block or component configuration if within a configuration declaration,
  8006. a configuration declaration if not within a design unit."
  8007. (interactive)
  8008. (vhdl-prepare-search-1
  8009. (cond
  8010. ((and (save-excursion ; architecture body
  8011. (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
  8012. (equal "ARCHITECTURE" (upcase (match-string 1))))
  8013. (vhdl-template-configuration-spec))
  8014. ((and (save-excursion ; configuration declaration
  8015. (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
  8016. (equal "CONFIGURATION" (upcase (match-string 1))))
  8017. (if (eq (vhdl-decision-query
  8018. "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
  8019. (vhdl-template-component-conf)
  8020. (vhdl-template-block-configuration)))
  8021. (t (vhdl-template-configuration-decl))))) ; otherwise
  8022. (defun vhdl-template-configuration-spec (&optional optional-use)
  8023. "Insert a configuration specification."
  8024. (interactive)
  8025. (let ((margin (current-indentation))
  8026. (start (point))
  8027. aspect position)
  8028. (vhdl-insert-keyword "FOR ")
  8029. (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
  8030. t start (point))
  8031. (vhdl-template-field "component name" "\n")
  8032. (indent-to (+ margin vhdl-basic-offset))
  8033. (setq start (point))
  8034. (vhdl-insert-keyword "USE ")
  8035. (if (and optional-use
  8036. (not (setq aspect (vhdl-template-field
  8037. "[ENTITY | CONFIGURATION | OPEN]" " " t))))
  8038. (progn (delete-region start (point)) 'no-use)
  8039. (unless optional-use
  8040. (setq aspect (vhdl-template-field
  8041. "ENTITY | CONFIGURATION | OPEN" " ")))
  8042. (setq aspect (upcase (or aspect "")))
  8043. (cond ((equal aspect "ENTITY")
  8044. (vhdl-template-field "library name" "." nil nil nil nil
  8045. (vhdl-work-library))
  8046. (vhdl-template-field "entity name" "(")
  8047. (if (vhdl-template-field "[architecture name]" nil t)
  8048. (insert ")")
  8049. (delete-char -1))
  8050. (insert "\n")
  8051. (indent-to (+ margin (* 2 vhdl-basic-offset)))
  8052. (setq position (point))
  8053. (vhdl-insert-keyword "GENERIC ")
  8054. (when (vhdl-template-map position t t)
  8055. (insert "\n")
  8056. (indent-to (+ margin (* 2 vhdl-basic-offset))))
  8057. (setq position (point))
  8058. (vhdl-insert-keyword "PORT ")
  8059. (unless (vhdl-template-map position t t)
  8060. (delete-region (line-beginning-position) (point))
  8061. (delete-char -1))
  8062. (insert ";")
  8063. t)
  8064. ((equal aspect "CONFIGURATION")
  8065. (vhdl-template-field "library name" "." nil nil nil nil
  8066. (vhdl-work-library))
  8067. (vhdl-template-field "configuration name" ";"))
  8068. (t (delete-char -1) (insert ";") t))))))
  8069. (defun vhdl-template-configuration-decl ()
  8070. "Insert a configuration declaration."
  8071. (interactive)
  8072. (let ((margin (current-indentation))
  8073. (start (point))
  8074. entity-exists string name position)
  8075. (vhdl-insert-keyword "CONFIGURATION ")
  8076. (when (setq name (vhdl-template-field "name" nil t start (point)))
  8077. (vhdl-insert-keyword " OF ")
  8078. (save-excursion
  8079. (vhdl-prepare-search-1
  8080. (setq entity-exists (vhdl-re-search-backward
  8081. "\\<entity \\(\\w*\\) is\\>" nil t))
  8082. (setq string (match-string 1))))
  8083. (if (and entity-exists (not (equal string "")))
  8084. (insert string)
  8085. (vhdl-template-field "entity name"))
  8086. (vhdl-insert-keyword " IS\n")
  8087. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  8088. (indent-to (+ margin vhdl-basic-offset))
  8089. (setq position (point))
  8090. (insert "\n")
  8091. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  8092. (indent-to margin)
  8093. (vhdl-insert-keyword "END ")
  8094. (unless (vhdl-standard-p '87)
  8095. (vhdl-insert-keyword "CONFIGURATION "))
  8096. (insert name ";")
  8097. (goto-char position))))
  8098. (defun vhdl-template-constant ()
  8099. "Insert a constant declaration."
  8100. (interactive)
  8101. (let ((start (point))
  8102. (in-arglist (vhdl-in-argument-list-p)))
  8103. (vhdl-insert-keyword "CONSTANT ")
  8104. (when (vhdl-template-field "name" nil t start (point))
  8105. (insert " : ")
  8106. (when in-arglist (vhdl-insert-keyword "IN "))
  8107. (vhdl-template-field "type")
  8108. (if in-arglist
  8109. (progn (insert ";")
  8110. (vhdl-comment-insert-inline))
  8111. (let ((position (point)))
  8112. (insert " := ")
  8113. (unless (vhdl-template-field "[initialization]" nil t)
  8114. (delete-region position (point)))
  8115. (insert ";")
  8116. (vhdl-comment-insert-inline))))))
  8117. (defun vhdl-template-default ()
  8118. "Insert nothing."
  8119. (interactive)
  8120. (insert " ")
  8121. (unexpand-abbrev)
  8122. (backward-word 1)
  8123. (vhdl-case-word 1)
  8124. (forward-char 1))
  8125. (defun vhdl-template-default-indent ()
  8126. "Insert nothing and indent."
  8127. (interactive)
  8128. (insert " ")
  8129. (unexpand-abbrev)
  8130. (backward-word 1)
  8131. (vhdl-case-word 1)
  8132. (forward-char 1)
  8133. (indent-according-to-mode))
  8134. (defun vhdl-template-disconnect ()
  8135. "Insert a disconnect statement."
  8136. (interactive)
  8137. (let ((start (point)))
  8138. (vhdl-insert-keyword "DISCONNECT ")
  8139. (when (vhdl-template-field "signal names | OTHERS | ALL"
  8140. " : " t start (point))
  8141. (vhdl-template-field "type")
  8142. (vhdl-insert-keyword " AFTER ")
  8143. (vhdl-template-field "time expression" ";"))))
  8144. (defun vhdl-template-else ()
  8145. "Insert an else statement."
  8146. (interactive)
  8147. (let (margin)
  8148. (vhdl-prepare-search-1
  8149. (vhdl-insert-keyword "ELSE")
  8150. (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
  8151. (equal "WHEN" (upcase (match-string 1))))
  8152. (insert " ")
  8153. (indent-according-to-mode)
  8154. (setq margin (current-indentation))
  8155. (insert "\n")
  8156. (indent-to (+ margin vhdl-basic-offset))))))
  8157. (defun vhdl-template-elsif ()
  8158. "Insert an elsif statement."
  8159. (interactive)
  8160. (let ((start (point))
  8161. margin)
  8162. (vhdl-insert-keyword "ELSIF ")
  8163. (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
  8164. (when vhdl-conditions-in-parenthesis (insert "("))
  8165. (when (vhdl-template-field "condition" nil t start (point))
  8166. (when vhdl-conditions-in-parenthesis (insert ")"))
  8167. (indent-according-to-mode)
  8168. (setq margin (current-indentation))
  8169. (vhdl-insert-keyword
  8170. (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
  8171. (indent-to (+ margin vhdl-basic-offset))))))
  8172. (defun vhdl-template-entity ()
  8173. "Insert an entity."
  8174. (interactive)
  8175. (let ((margin (current-indentation))
  8176. (start (point))
  8177. name end-column)
  8178. (vhdl-insert-keyword "ENTITY ")
  8179. (when (setq name (vhdl-template-field "name" nil t start (point)))
  8180. (vhdl-insert-keyword " IS\n\n")
  8181. (indent-to margin)
  8182. (vhdl-insert-keyword "END ")
  8183. (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
  8184. (insert name ";")
  8185. (setq end-column (current-column))
  8186. (end-of-line -0)
  8187. (indent-to (+ margin vhdl-basic-offset))
  8188. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  8189. (indent-to (+ margin vhdl-basic-offset))
  8190. (when (vhdl-template-generic-list t)
  8191. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
  8192. (insert "\n")
  8193. (indent-to (+ margin vhdl-basic-offset))
  8194. (when (vhdl-template-port-list t)
  8195. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
  8196. (beginning-of-line 2)
  8197. (forward-char end-column))))
  8198. (defun vhdl-template-exit ()
  8199. "Insert an exit statement."
  8200. (interactive)
  8201. (let ((start (point)))
  8202. (vhdl-insert-keyword "EXIT ")
  8203. (if (vhdl-template-field "[loop label]" nil t start (point))
  8204. (let ((position (point)))
  8205. (vhdl-insert-keyword " WHEN ")
  8206. (when vhdl-conditions-in-parenthesis (insert "("))
  8207. (if (vhdl-template-field "[condition]" nil t)
  8208. (when vhdl-conditions-in-parenthesis (insert ")"))
  8209. (delete-region position (point))))
  8210. (delete-char -1))
  8211. (insert ";")))
  8212. (defun vhdl-template-file ()
  8213. "Insert a file declaration."
  8214. (interactive)
  8215. (let ((start (point)))
  8216. (vhdl-insert-keyword "FILE ")
  8217. (when (vhdl-template-field "name" nil t start (point))
  8218. (insert " : ")
  8219. (vhdl-template-field "type")
  8220. (unless (vhdl-standard-p '87)
  8221. (vhdl-insert-keyword " OPEN ")
  8222. (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
  8223. nil t)
  8224. (delete-char -6)))
  8225. (vhdl-insert-keyword " IS ")
  8226. (when (vhdl-standard-p '87)
  8227. (vhdl-template-field "[IN | OUT]" " " t))
  8228. (vhdl-template-field "filename-string" nil nil nil nil t)
  8229. (insert ";")
  8230. (vhdl-comment-insert-inline))))
  8231. (defun vhdl-template-for ()
  8232. "Insert a block or component configuration if within a configuration
  8233. declaration, a configuration specification if within an architecture
  8234. declarative part (and not within a subprogram), a for-loop if within a
  8235. sequential statement part (subprogram or process), and a for-generate
  8236. otherwise."
  8237. (interactive)
  8238. (vhdl-prepare-search-1
  8239. (cond
  8240. ((vhdl-sequential-statement-p) ; sequential statement
  8241. (vhdl-template-for-loop))
  8242. ((and (save-excursion ; configuration declaration
  8243. (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
  8244. (equal "CONFIGURATION" (upcase (match-string 1))))
  8245. (if (eq (vhdl-decision-query
  8246. "for" "(b)lock or (c)omponent configuration?" t) ?c)
  8247. (vhdl-template-component-conf)
  8248. (vhdl-template-block-configuration)))
  8249. ((and (save-excursion
  8250. (re-search-backward ; architecture declarative part
  8251. "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
  8252. (equal "ARCHITECTURE" (upcase (match-string 1))))
  8253. (vhdl-template-configuration-spec))
  8254. (t (vhdl-template-for-generate))))) ; concurrent statement
  8255. (defun vhdl-template-for-generate ()
  8256. "Insert a for-generate."
  8257. (interactive)
  8258. (let ((margin (current-indentation))
  8259. (start (point))
  8260. label position)
  8261. (vhdl-insert-keyword ": FOR ")
  8262. (setq position (point-marker))
  8263. (goto-char start)
  8264. (when (setq label (vhdl-template-field "label" nil t start position))
  8265. (goto-char position)
  8266. (vhdl-template-field "loop variable")
  8267. (vhdl-insert-keyword " IN ")
  8268. (vhdl-template-field "range")
  8269. (vhdl-template-generate-body margin label))))
  8270. (defun vhdl-template-for-loop ()
  8271. "Insert a for loop."
  8272. (interactive)
  8273. (let ((margin (current-indentation))
  8274. (start (point))
  8275. label index)
  8276. (if (not (eq vhdl-optional-labels 'all))
  8277. (vhdl-insert-keyword "FOR ")
  8278. (vhdl-insert-keyword ": FOR ")
  8279. (goto-char start)
  8280. (setq label (vhdl-template-field "[label]" nil t))
  8281. (unless label (delete-char 2))
  8282. (forward-word 1)
  8283. (forward-char 1))
  8284. (when (setq index (vhdl-template-field "loop variable"
  8285. nil t start (point)))
  8286. (vhdl-insert-keyword " IN ")
  8287. (vhdl-template-field "range")
  8288. (vhdl-insert-keyword " LOOP\n\n")
  8289. (indent-to margin)
  8290. (vhdl-insert-keyword "END LOOP")
  8291. (if label
  8292. (insert " " label ";")
  8293. (insert ";")
  8294. (when vhdl-self-insert-comments (insert " -- " index)))
  8295. (forward-line -1)
  8296. (indent-to (+ margin vhdl-basic-offset)))))
  8297. (defun vhdl-template-function (&optional kind)
  8298. "Insert a function declaration or body."
  8299. (interactive)
  8300. (let ((margin (current-indentation))
  8301. (start (point))
  8302. name)
  8303. (vhdl-insert-keyword "FUNCTION ")
  8304. (when (setq name (vhdl-template-field "name" nil t start (point)))
  8305. (vhdl-template-argument-list t)
  8306. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
  8307. (end-of-line)
  8308. (insert "\n")
  8309. (indent-to (+ margin vhdl-basic-offset))
  8310. (vhdl-insert-keyword "RETURN ")
  8311. (vhdl-template-field "type")
  8312. (if (if kind (eq kind 'body)
  8313. (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
  8314. (progn (vhdl-insert-keyword " IS\n")
  8315. (vhdl-template-begin-end
  8316. (unless (vhdl-standard-p '87) "FUNCTION") name margin)
  8317. (vhdl-comment-block))
  8318. (insert ";")))))
  8319. (defun vhdl-template-function-decl ()
  8320. "Insert a function declaration."
  8321. (interactive)
  8322. (vhdl-template-function 'decl))
  8323. (defun vhdl-template-function-body ()
  8324. "Insert a function declaration."
  8325. (interactive)
  8326. (vhdl-template-function 'body))
  8327. (defun vhdl-template-generate ()
  8328. "Insert a generation scheme."
  8329. (interactive)
  8330. (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
  8331. (vhdl-template-if-generate)
  8332. (vhdl-template-for-generate)))
  8333. (defun vhdl-template-generic ()
  8334. "Insert generic declaration, or generic map in instantiation statements."
  8335. (interactive)
  8336. (let ((start (point)))
  8337. (vhdl-prepare-search-1
  8338. (cond
  8339. ((and (save-excursion ; entity declaration
  8340. (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
  8341. (equal "ENTITY" (upcase (match-string 1))))
  8342. (vhdl-template-generic-list nil))
  8343. ((or (save-excursion
  8344. (or (beginning-of-line)
  8345. (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
  8346. (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
  8347. (vhdl-insert-keyword "GENERIC ")
  8348. (vhdl-template-map start))
  8349. (t (vhdl-template-generic-list nil t))))))
  8350. (defun vhdl-template-group ()
  8351. "Insert group or group template declaration."
  8352. (interactive)
  8353. (let ((start (point)))
  8354. (if (eq (vhdl-decision-query
  8355. "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
  8356. (vhdl-template-group-template)
  8357. (vhdl-template-group-decl))))
  8358. (defun vhdl-template-group-decl ()
  8359. "Insert group declaration."
  8360. (interactive)
  8361. (let ((start (point)))
  8362. (vhdl-insert-keyword "GROUP ")
  8363. (when (vhdl-template-field "name" " : " t start (point))
  8364. (vhdl-template-field "template name" " (")
  8365. (vhdl-template-field "constituent list" ");")
  8366. (vhdl-comment-insert-inline))))
  8367. (defun vhdl-template-group-template ()
  8368. "Insert group template declaration."
  8369. (interactive)
  8370. (let ((start (point)))
  8371. (vhdl-insert-keyword "GROUP ")
  8372. (when (vhdl-template-field "template name" nil t start (point))
  8373. (vhdl-insert-keyword " IS (")
  8374. (vhdl-template-field "entity class list" ");")
  8375. (vhdl-comment-insert-inline))))
  8376. (defun vhdl-template-if ()
  8377. "Insert a sequential if statement or an if-generate statement."
  8378. (interactive)
  8379. (if (vhdl-sequential-statement-p)
  8380. (vhdl-template-if-then)
  8381. (if (and (vhdl-standard-p 'ams)
  8382. (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
  8383. (vhdl-template-if-use)
  8384. (vhdl-template-if-generate))))
  8385. (defun vhdl-template-if-generate ()
  8386. "Insert an if-generate."
  8387. (interactive)
  8388. (let ((margin (current-indentation))
  8389. (start (point))
  8390. label position)
  8391. (vhdl-insert-keyword ": IF ")
  8392. (setq position (point-marker))
  8393. (goto-char start)
  8394. (when (setq label (vhdl-template-field "label" nil t start position))
  8395. (goto-char position)
  8396. (when vhdl-conditions-in-parenthesis (insert "("))
  8397. (vhdl-template-field "condition")
  8398. (when vhdl-conditions-in-parenthesis (insert ")"))
  8399. (vhdl-template-generate-body margin label))))
  8400. (defun vhdl-template-if-then-use (kind)
  8401. "Insert a sequential if statement."
  8402. (interactive)
  8403. (let ((margin (current-indentation))
  8404. (start (point))
  8405. label)
  8406. (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
  8407. (vhdl-insert-keyword "IF ")
  8408. (vhdl-insert-keyword ": IF ")
  8409. (goto-char start)
  8410. (setq label (vhdl-template-field "[label]" nil t))
  8411. (unless label (delete-char 2))
  8412. (forward-word 1)
  8413. (forward-char 1))
  8414. (when vhdl-conditions-in-parenthesis (insert "("))
  8415. (when (vhdl-template-field "condition" nil t start (point))
  8416. (when vhdl-conditions-in-parenthesis (insert ")"))
  8417. (vhdl-insert-keyword
  8418. (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
  8419. (indent-to margin)
  8420. (vhdl-insert-keyword (concat "END " (if (eq kind 'then) "IF" "USE")))
  8421. (when label (insert " " label))
  8422. (insert ";")
  8423. (forward-line -1)
  8424. (indent-to (+ margin vhdl-basic-offset)))))
  8425. (defun vhdl-template-if-then ()
  8426. "Insert a sequential if statement."
  8427. (interactive)
  8428. (vhdl-template-if-then-use 'then))
  8429. (defun vhdl-template-if-use ()
  8430. "Insert a simultaneous if statement."
  8431. (interactive)
  8432. (vhdl-template-if-then-use 'use))
  8433. (defun vhdl-template-instance ()
  8434. "Insert a component instantiation statement."
  8435. (interactive)
  8436. (vhdl-template-component-inst))
  8437. (defun vhdl-template-library ()
  8438. "Insert a library specification."
  8439. (interactive)
  8440. (let ((margin (current-indentation))
  8441. (start (point))
  8442. name end-pos)
  8443. (vhdl-insert-keyword "LIBRARY ")
  8444. (when (setq name (vhdl-template-field "names" nil t start (point)))
  8445. (insert ";")
  8446. (unless (string-match "," name)
  8447. (setq end-pos (point))
  8448. (insert "\n")
  8449. (indent-to margin)
  8450. (vhdl-insert-keyword "USE ")
  8451. (insert name)
  8452. (vhdl-insert-keyword "..ALL;")
  8453. (backward-char 5)
  8454. (if (vhdl-template-field "package name")
  8455. (forward-char 5)
  8456. (delete-region end-pos (+ (point) 5)))))))
  8457. (defun vhdl-template-limit ()
  8458. "Insert a limit."
  8459. (interactive)
  8460. (let ((start (point)))
  8461. (vhdl-insert-keyword "LIMIT ")
  8462. (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
  8463. t start (point))
  8464. (vhdl-template-field "type")
  8465. (vhdl-insert-keyword " WITH ")
  8466. (vhdl-template-field "real expression" ";"))))
  8467. (defun vhdl-template-loop ()
  8468. "Insert a loop."
  8469. (interactive)
  8470. (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
  8471. (cond ((eq char ?w)
  8472. (vhdl-template-while-loop))
  8473. ((eq char ?f)
  8474. (vhdl-template-for-loop))
  8475. (t (vhdl-template-bare-loop)))))
  8476. (defun vhdl-template-bare-loop ()
  8477. "Insert a loop."
  8478. (interactive)
  8479. (let ((margin (current-indentation))
  8480. (start (point))
  8481. label)
  8482. (if (not (eq vhdl-optional-labels 'all))
  8483. (vhdl-insert-keyword "LOOP ")
  8484. (vhdl-insert-keyword ": LOOP ")
  8485. (goto-char start)
  8486. (setq label (vhdl-template-field "[label]" nil t))
  8487. (unless label (delete-char 2))
  8488. (forward-word 1)
  8489. (delete-char 1))
  8490. (insert "\n\n")
  8491. (indent-to margin)
  8492. (vhdl-insert-keyword "END LOOP")
  8493. (insert (if label (concat " " label ";") ";"))
  8494. (forward-line -1)
  8495. (indent-to (+ margin vhdl-basic-offset))))
  8496. (defun vhdl-template-map (&optional start optional secondary)
  8497. "Insert a map specification with association list."
  8498. (interactive)
  8499. (let ((start (or start (point)))
  8500. margin end-pos)
  8501. (vhdl-insert-keyword "MAP (")
  8502. (if (not vhdl-association-list-with-formals)
  8503. (if (vhdl-template-field
  8504. (concat (and optional "[") "association list" (and optional "]"))
  8505. ")" (or (not secondary) optional)
  8506. (and (not secondary) start) (point))
  8507. t
  8508. (if (and optional secondary) (delete-region start (point)))
  8509. nil)
  8510. (if vhdl-argument-list-indent
  8511. (setq margin (current-column))
  8512. (setq margin (+ (current-indentation) vhdl-basic-offset))
  8513. (insert "\n")
  8514. (indent-to margin))
  8515. (if (vhdl-template-field
  8516. (concat (and optional "[") "formal" (and optional "]"))
  8517. " => " (or (not secondary) optional)
  8518. (and (not secondary) start) (point))
  8519. (progn
  8520. (vhdl-template-field "actual" ",")
  8521. (setq end-pos (point))
  8522. (insert "\n")
  8523. (indent-to margin)
  8524. (while (vhdl-template-field "[formal]" " => " t)
  8525. (vhdl-template-field "actual" ",")
  8526. (setq end-pos (point))
  8527. (insert "\n")
  8528. (indent-to margin))
  8529. (delete-region end-pos (point))
  8530. (delete-char -1)
  8531. (insert ")")
  8532. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
  8533. t)
  8534. (when (and optional secondary) (delete-region start (point)))
  8535. nil))))
  8536. (defun vhdl-template-modify (&optional noerror)
  8537. "Actualize modification date."
  8538. (interactive)
  8539. (vhdl-prepare-search-2
  8540. (save-excursion
  8541. (goto-char (point-min))
  8542. (if (re-search-forward vhdl-modify-date-prefix-string nil t)
  8543. (progn (delete-region (point) (progn (end-of-line) (point)))
  8544. (vhdl-template-insert-date))
  8545. (unless noerror
  8546. (error "ERROR: Modification date prefix string \"%s\" not found"
  8547. vhdl-modify-date-prefix-string))))))
  8548. (defun vhdl-template-modify-noerror ()
  8549. "Call `vhdl-template-modify' with NOERROR non-nil."
  8550. (vhdl-template-modify t))
  8551. (defun vhdl-template-nature ()
  8552. "Insert a nature declaration."
  8553. (interactive)
  8554. (let ((start (point))
  8555. name mid-pos end-pos)
  8556. (vhdl-insert-keyword "NATURE ")
  8557. (when (setq name (vhdl-template-field "name" nil t start (point)))
  8558. (vhdl-insert-keyword " IS ")
  8559. (let ((definition
  8560. (upcase
  8561. (or (vhdl-template-field
  8562. "across type | ARRAY | RECORD")
  8563. ""))))
  8564. (cond ((equal definition "")
  8565. (insert ";"))
  8566. ((equal definition "ARRAY")
  8567. (delete-region (point) (progn (forward-word -1) (point)))
  8568. (vhdl-template-array 'nature t))
  8569. ((equal definition "RECORD")
  8570. (setq mid-pos (point-marker))
  8571. (delete-region (point) (progn (forward-word -1) (point)))
  8572. (vhdl-template-record 'nature name t))
  8573. (t
  8574. (vhdl-insert-keyword " ACROSS ")
  8575. (vhdl-template-field "through type")
  8576. (vhdl-insert-keyword " THROUGH ")
  8577. (vhdl-template-field "reference name")
  8578. (vhdl-insert-keyword " REFERENCE;")))
  8579. (when mid-pos
  8580. (setq end-pos (point-marker))
  8581. (goto-char mid-pos)
  8582. (end-of-line))
  8583. (vhdl-comment-insert-inline)
  8584. (when end-pos (goto-char end-pos))))))
  8585. (defun vhdl-template-next ()
  8586. "Insert a next statement."
  8587. (interactive)
  8588. (let ((start (point)))
  8589. (vhdl-insert-keyword "NEXT ")
  8590. (if (vhdl-template-field "[loop label]" nil t start (point))
  8591. (let ((position (point)))
  8592. (vhdl-insert-keyword " WHEN ")
  8593. (when vhdl-conditions-in-parenthesis (insert "("))
  8594. (if (vhdl-template-field "[condition]" nil t)
  8595. (when vhdl-conditions-in-parenthesis (insert ")"))
  8596. (delete-region position (point))))
  8597. (delete-char -1))
  8598. (insert ";")))
  8599. (defun vhdl-template-others ()
  8600. "Insert an others aggregate."
  8601. (interactive)
  8602. (let ((start (point)))
  8603. (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
  8604. (progn (unless vhdl-template-invoked-by-hook (insert "("))
  8605. (vhdl-insert-keyword "OTHERS => '")
  8606. (when (vhdl-template-field "value" nil t start (point))
  8607. (insert "')")))
  8608. (vhdl-insert-keyword "OTHERS "))))
  8609. (defun vhdl-template-package (&optional kind)
  8610. "Insert a package specification or body."
  8611. (interactive)
  8612. (let ((margin (current-indentation))
  8613. (start (point))
  8614. name body position)
  8615. (vhdl-insert-keyword "PACKAGE ")
  8616. (setq body (if kind (eq kind 'body)
  8617. (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
  8618. (when body
  8619. (vhdl-insert-keyword "BODY ")
  8620. (when (save-excursion
  8621. (vhdl-prepare-search-1
  8622. (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
  8623. (insert (setq name (match-string 1)))))
  8624. (when (or name
  8625. (setq name (vhdl-template-field "name" nil t start (point))))
  8626. (vhdl-insert-keyword " IS\n")
  8627. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  8628. (indent-to (+ margin vhdl-basic-offset))
  8629. (setq position (point))
  8630. (insert "\n")
  8631. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  8632. (indent-to margin)
  8633. (vhdl-insert-keyword "END ")
  8634. (unless (vhdl-standard-p '87)
  8635. (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
  8636. (insert (or name "") ";")
  8637. (goto-char position))))
  8638. (defun vhdl-template-package-decl ()
  8639. "Insert a package specification."
  8640. (interactive)
  8641. (vhdl-template-package 'decl))
  8642. (defun vhdl-template-package-body ()
  8643. "Insert a package body."
  8644. (interactive)
  8645. (vhdl-template-package 'body))
  8646. (defun vhdl-template-port ()
  8647. "Insert a port declaration, or port map in instantiation statements."
  8648. (interactive)
  8649. (let ((start (point)))
  8650. (vhdl-prepare-search-1
  8651. (cond
  8652. ((and (save-excursion ; entity declaration
  8653. (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
  8654. (equal "ENTITY" (upcase (match-string 1))))
  8655. (vhdl-template-port-list nil))
  8656. ((or (save-excursion
  8657. (or (beginning-of-line)
  8658. (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
  8659. (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
  8660. (vhdl-insert-keyword "PORT ")
  8661. (vhdl-template-map start))
  8662. (t (vhdl-template-port-list nil))))))
  8663. (defun vhdl-template-procedural ()
  8664. "Insert a procedural."
  8665. (interactive)
  8666. (let ((margin (current-indentation))
  8667. (start (point))
  8668. (case-fold-search t)
  8669. label)
  8670. (vhdl-insert-keyword "PROCEDURAL ")
  8671. (when (memq vhdl-optional-labels '(process all))
  8672. (goto-char start)
  8673. (insert ": ")
  8674. (goto-char start)
  8675. (setq label (vhdl-template-field "[label]" nil t))
  8676. (unless label (delete-char 2))
  8677. (forward-word 1)
  8678. (forward-char 1))
  8679. (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
  8680. (insert "\n")
  8681. (vhdl-template-begin-end "PROCEDURAL" label margin)
  8682. (vhdl-comment-block)))
  8683. (defun vhdl-template-procedure (&optional kind)
  8684. "Insert a procedure declaration or body."
  8685. (interactive)
  8686. (let ((margin (current-indentation))
  8687. (start (point))
  8688. name)
  8689. (vhdl-insert-keyword "PROCEDURE ")
  8690. (when (setq name (vhdl-template-field "name" nil t start (point)))
  8691. (vhdl-template-argument-list)
  8692. (if (if kind (eq kind 'body)
  8693. (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
  8694. (progn (vhdl-insert-keyword " IS")
  8695. (when vhdl-auto-align
  8696. (vhdl-align-region-groups start (point) 1))
  8697. (end-of-line) (insert "\n")
  8698. (vhdl-template-begin-end
  8699. (unless (vhdl-standard-p '87) "PROCEDURE")
  8700. name margin)
  8701. (vhdl-comment-block))
  8702. (insert ";")
  8703. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
  8704. (end-of-line)))))
  8705. (defun vhdl-template-procedure-decl ()
  8706. "Insert a procedure declaration."
  8707. (interactive)
  8708. (vhdl-template-procedure 'decl))
  8709. (defun vhdl-template-procedure-body ()
  8710. "Insert a procedure body."
  8711. (interactive)
  8712. (vhdl-template-procedure 'body))
  8713. (defun vhdl-template-process (&optional kind)
  8714. "Insert a process."
  8715. (interactive)
  8716. (let ((margin (current-indentation))
  8717. (start (point))
  8718. (reset-kind vhdl-reset-kind)
  8719. label seq input-signals clock reset final-pos)
  8720. (setq seq (if kind (eq kind 'seq)
  8721. (eq (vhdl-decision-query
  8722. "process" "(c)ombinational or (s)equential?" t) ?s)))
  8723. (vhdl-insert-keyword "PROCESS ")
  8724. (when (memq vhdl-optional-labels '(process all))
  8725. (goto-char start)
  8726. (insert ": ")
  8727. (goto-char start)
  8728. (setq label (vhdl-template-field "[label]" nil t))
  8729. (unless label (delete-char 2))
  8730. (forward-word 1)
  8731. (forward-char 1))
  8732. (insert "(")
  8733. (if (not seq)
  8734. (unless (setq input-signals
  8735. (vhdl-template-field "[sensitivity list]" ")" t))
  8736. (setq input-signals "")
  8737. (delete-char -2))
  8738. (setq clock (or (and (not (equal "" vhdl-clock-name))
  8739. (progn (insert vhdl-clock-name) vhdl-clock-name))
  8740. (vhdl-template-field "clock name") "<clock>"))
  8741. (when (eq reset-kind 'query)
  8742. (setq reset-kind
  8743. (if (eq (vhdl-decision-query
  8744. "" "(a)synchronous or (s)ynchronous reset?" t) ?a)
  8745. 'async
  8746. 'sync)))
  8747. (when (eq reset-kind 'async)
  8748. (insert ", ")
  8749. (setq reset (or (and (not (equal "" vhdl-reset-name))
  8750. (progn (insert vhdl-reset-name) vhdl-reset-name))
  8751. (vhdl-template-field "reset name") "<reset>")))
  8752. (insert ")"))
  8753. (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
  8754. (insert "\n")
  8755. (vhdl-template-begin-end "PROCESS" label margin)
  8756. (when seq (setq reset (vhdl-template-seq-process clock reset reset-kind)))
  8757. (when vhdl-prompt-for-comments
  8758. (setq final-pos (point-marker))
  8759. (vhdl-prepare-search-2
  8760. (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
  8761. (vhdl-re-search-backward "\\<process\\>" nil t))
  8762. (end-of-line -0)
  8763. (if (bobp)
  8764. (progn (insert "\n") (forward-line -1))
  8765. (insert "\n"))
  8766. (indent-to margin)
  8767. (insert "-- purpose: ")
  8768. (if (not (vhdl-template-field "[description]" nil t))
  8769. (vhdl-line-kill-entire)
  8770. (insert "\n")
  8771. (indent-to margin)
  8772. (insert "-- type : ")
  8773. (insert (if seq "sequential" "combinational") "\n")
  8774. (indent-to margin)
  8775. (insert "-- inputs : ")
  8776. (if (not seq)
  8777. (insert input-signals)
  8778. (insert clock ", ")
  8779. (when reset (insert reset ", "))
  8780. (unless (vhdl-template-field "[signal names]" nil t)
  8781. (delete-char -2)))
  8782. (insert "\n")
  8783. (indent-to margin)
  8784. (insert "-- outputs: ")
  8785. (vhdl-template-field "[signal names]" nil t))))
  8786. (goto-char final-pos))))
  8787. (defun vhdl-template-process-comb ()
  8788. "Insert a combinational process."
  8789. (interactive)
  8790. (vhdl-template-process 'comb))
  8791. (defun vhdl-template-process-seq ()
  8792. "Insert a sequential process."
  8793. (interactive)
  8794. (vhdl-template-process 'seq))
  8795. (defun vhdl-template-quantity ()
  8796. "Insert a quantity declaration."
  8797. (interactive)
  8798. (if (vhdl-in-argument-list-p)
  8799. (let ((start (point)))
  8800. (vhdl-insert-keyword "QUANTITY ")
  8801. (when (vhdl-template-field "names" nil t start (point))
  8802. (insert " : ")
  8803. (vhdl-template-field "[IN | OUT]" " " t)
  8804. (vhdl-template-field "type")
  8805. (insert ";")
  8806. (vhdl-comment-insert-inline)))
  8807. (let ((char (vhdl-decision-query
  8808. "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
  8809. (cond ((eq char ?f) (vhdl-template-quantity-free))
  8810. ((eq char ?b) (vhdl-template-quantity-branch))
  8811. ((eq char ?s) (vhdl-template-quantity-source))
  8812. (t (vhdl-template-undo (point) (point)))))))
  8813. (defun vhdl-template-quantity-free ()
  8814. "Insert a free quantity declaration."
  8815. (interactive)
  8816. (vhdl-insert-keyword "QUANTITY ")
  8817. (vhdl-template-field "names")
  8818. (insert " : ")
  8819. (vhdl-template-field "type")
  8820. (let ((position (point)))
  8821. (insert " := ")
  8822. (unless (vhdl-template-field "[initialization]" nil t)
  8823. (delete-region position (point)))
  8824. (insert ";")
  8825. (vhdl-comment-insert-inline)))
  8826. (defun vhdl-template-quantity-branch ()
  8827. "Insert a branch quantity declaration."
  8828. (interactive)
  8829. (let (position)
  8830. (vhdl-insert-keyword "QUANTITY ")
  8831. (when (vhdl-template-field "[across names]" " " t)
  8832. (vhdl-insert-keyword "ACROSS "))
  8833. (when (vhdl-template-field "[through names]" " " t)
  8834. (vhdl-insert-keyword "THROUGH "))
  8835. (vhdl-template-field "plus terminal name")
  8836. (setq position (point))
  8837. (vhdl-insert-keyword " TO ")
  8838. (unless (vhdl-template-field "[minus terminal name]" nil t)
  8839. (delete-region position (point)))
  8840. (insert ";")
  8841. (vhdl-comment-insert-inline)))
  8842. (defun vhdl-template-quantity-source ()
  8843. "Insert a source quantity declaration."
  8844. (interactive)
  8845. (vhdl-insert-keyword "QUANTITY ")
  8846. (vhdl-template-field "names")
  8847. (insert " : ")
  8848. (vhdl-template-field "type" " ")
  8849. (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
  8850. (progn (vhdl-insert-keyword "NOISE ")
  8851. (vhdl-template-field "power expression"))
  8852. (vhdl-insert-keyword "SPECTRUM ")
  8853. (vhdl-template-field "magnitude expression" ", ")
  8854. (vhdl-template-field "phase expression"))
  8855. (insert ";")
  8856. (vhdl-comment-insert-inline))
  8857. (defun vhdl-template-record (kind &optional name secondary)
  8858. "Insert a record type declaration."
  8859. (interactive)
  8860. (let ((margin (current-column))
  8861. (start (point))
  8862. (first t))
  8863. (vhdl-insert-keyword "RECORD\n")
  8864. (indent-to (+ margin vhdl-basic-offset))
  8865. (when (or (vhdl-template-field "element names"
  8866. nil (not secondary) start (point))
  8867. secondary)
  8868. (while (or first (vhdl-template-field "[element names]" nil t))
  8869. (insert " : ")
  8870. (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
  8871. (vhdl-comment-insert-inline)
  8872. (insert "\n")
  8873. (indent-to (+ margin vhdl-basic-offset))
  8874. (setq first nil))
  8875. (delete-region (line-beginning-position) (point))
  8876. (indent-to margin)
  8877. (vhdl-insert-keyword "END RECORD")
  8878. (unless (vhdl-standard-p '87) (and name (insert " " name)))
  8879. (insert ";")
  8880. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
  8881. (defun vhdl-template-report ()
  8882. "Insert a report statement."
  8883. (interactive)
  8884. (let ((start (point)))
  8885. (vhdl-insert-keyword "REPORT ")
  8886. (if (equal "\"\"" (vhdl-template-field
  8887. "string expression" nil t start (point) t))
  8888. (delete-char -2)
  8889. (setq start (point))
  8890. (vhdl-insert-keyword " SEVERITY ")
  8891. (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
  8892. (delete-region start (point)))
  8893. (insert ";"))))
  8894. (defun vhdl-template-return ()
  8895. "Insert a return statement."
  8896. (interactive)
  8897. (let ((start (point)))
  8898. (vhdl-insert-keyword "RETURN ")
  8899. (unless (vhdl-template-field "[expression]" nil t start (point))
  8900. (delete-char -1))
  8901. (insert ";")))
  8902. (defun vhdl-template-selected-signal-asst ()
  8903. "Insert a selected signal assignment."
  8904. (interactive)
  8905. (let ((margin (current-indentation))
  8906. (start (point))
  8907. (choices t))
  8908. (let ((position (point)))
  8909. (vhdl-insert-keyword " SELECT ")
  8910. (goto-char position))
  8911. (vhdl-insert-keyword "WITH ")
  8912. (when (vhdl-template-field "selector expression"
  8913. nil t start (+ (point) 7))
  8914. (forward-word 1)
  8915. (delete-char 1)
  8916. (insert "\n")
  8917. (indent-to (+ margin vhdl-basic-offset))
  8918. (vhdl-template-field "target signal" " <= ")
  8919. ; (vhdl-template-field "[GUARDED] [TRANSPORT]")
  8920. (insert "\n")
  8921. (indent-to (+ margin vhdl-basic-offset))
  8922. (vhdl-template-field "waveform")
  8923. (vhdl-insert-keyword " WHEN ")
  8924. (vhdl-template-field "choices" ",")
  8925. (insert "\n")
  8926. (indent-to (+ margin vhdl-basic-offset))
  8927. (while (and choices (vhdl-template-field "[waveform]" nil t))
  8928. (vhdl-insert-keyword " WHEN ")
  8929. (if (setq choices (vhdl-template-field "[choices]" "," t))
  8930. (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
  8931. (vhdl-insert-keyword "OTHERS")))
  8932. (when choices
  8933. (fixup-whitespace)
  8934. (delete-char -2))
  8935. (insert ";")
  8936. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
  8937. (defun vhdl-template-signal ()
  8938. "Insert a signal declaration."
  8939. (interactive)
  8940. (let ((start (point))
  8941. (in-arglist (vhdl-in-argument-list-p)))
  8942. (vhdl-insert-keyword "SIGNAL ")
  8943. (when (vhdl-template-field "names" nil t start (point))
  8944. (insert " : ")
  8945. (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
  8946. (vhdl-template-field "type")
  8947. (if in-arglist
  8948. (progn (insert ";")
  8949. (vhdl-comment-insert-inline))
  8950. (let ((position (point)))
  8951. (insert " := ")
  8952. (unless (vhdl-template-field "[initialization]" nil t)
  8953. (delete-region position (point)))
  8954. (insert ";")
  8955. (vhdl-comment-insert-inline))))))
  8956. (defun vhdl-template-subnature ()
  8957. "Insert a subnature declaration."
  8958. (interactive)
  8959. (let ((start (point))
  8960. position)
  8961. (vhdl-insert-keyword "SUBNATURE ")
  8962. (when (vhdl-template-field "name" nil t start (point))
  8963. (vhdl-insert-keyword " IS ")
  8964. (vhdl-template-field "nature" " (")
  8965. (if (vhdl-template-field "[index range]" nil t)
  8966. (insert ")")
  8967. (delete-char -2))
  8968. (setq position (point))
  8969. (vhdl-insert-keyword " TOLERANCE ")
  8970. (if (equal "\"\"" (vhdl-template-field "[string expression]"
  8971. nil t nil nil t))
  8972. (delete-region position (point))
  8973. (vhdl-insert-keyword " ACROSS ")
  8974. (vhdl-template-field "string expression" nil nil nil nil t)
  8975. (vhdl-insert-keyword " THROUGH"))
  8976. (insert ";")
  8977. (vhdl-comment-insert-inline))))
  8978. (defun vhdl-template-subprogram-body ()
  8979. "Insert a subprogram body."
  8980. (interactive)
  8981. (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
  8982. (vhdl-template-function-body)
  8983. (vhdl-template-procedure-body)))
  8984. (defun vhdl-template-subprogram-decl ()
  8985. "Insert a subprogram declaration."
  8986. (interactive)
  8987. (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
  8988. (vhdl-template-function-decl)
  8989. (vhdl-template-procedure-decl)))
  8990. (defun vhdl-template-subtype ()
  8991. "Insert a subtype declaration."
  8992. (interactive)
  8993. (let ((start (point)))
  8994. (vhdl-insert-keyword "SUBTYPE ")
  8995. (when (vhdl-template-field "name" nil t start (point))
  8996. (vhdl-insert-keyword " IS ")
  8997. (vhdl-template-field "type" " ")
  8998. (unless
  8999. (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
  9000. (delete-char -1))
  9001. (insert ";")
  9002. (vhdl-comment-insert-inline))))
  9003. (defun vhdl-template-terminal ()
  9004. "Insert a terminal declaration."
  9005. (interactive)
  9006. (let ((start (point)))
  9007. (vhdl-insert-keyword "TERMINAL ")
  9008. (when (vhdl-template-field "names" nil t start (point))
  9009. (insert " : ")
  9010. (vhdl-template-field "nature")
  9011. (insert ";")
  9012. (vhdl-comment-insert-inline))))
  9013. (defun vhdl-template-type ()
  9014. "Insert a type declaration."
  9015. (interactive)
  9016. (let ((start (point))
  9017. name mid-pos end-pos)
  9018. (vhdl-insert-keyword "TYPE ")
  9019. (when (setq name (vhdl-template-field "name" nil t start (point)))
  9020. (vhdl-insert-keyword " IS ")
  9021. (let ((definition
  9022. (upcase
  9023. (or (vhdl-template-field
  9024. "[scalar type | ARRAY | RECORD | ACCESS | FILE]" nil t)
  9025. ""))))
  9026. (cond ((equal definition "")
  9027. (delete-char -4)
  9028. (insert ";"))
  9029. ((equal definition "ARRAY")
  9030. (delete-region (point) (progn (forward-word -1) (point)))
  9031. (vhdl-template-array 'type t))
  9032. ((equal definition "RECORD")
  9033. (setq mid-pos (point-marker))
  9034. (delete-region (point) (progn (forward-word -1) (point)))
  9035. (vhdl-template-record 'type name t))
  9036. ((equal definition "ACCESS")
  9037. (insert " ")
  9038. (vhdl-template-field "type" ";"))
  9039. ((equal definition "FILE")
  9040. (vhdl-insert-keyword " OF ")
  9041. (vhdl-template-field "type" ";"))
  9042. (t (insert ";")))
  9043. (when mid-pos
  9044. (setq end-pos (point-marker))
  9045. (goto-char mid-pos)
  9046. (end-of-line))
  9047. (vhdl-comment-insert-inline)
  9048. (when end-pos (goto-char end-pos))))))
  9049. (defun vhdl-template-use ()
  9050. "Insert a use clause."
  9051. (interactive)
  9052. (let ((start (point)))
  9053. (vhdl-prepare-search-1
  9054. (vhdl-insert-keyword "USE ")
  9055. (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
  9056. (vhdl-insert-keyword "..ALL;")
  9057. (backward-char 6)
  9058. (when (vhdl-template-field "library name" nil t start (+ (point) 6))
  9059. (forward-char 1)
  9060. (vhdl-template-field "package name")
  9061. (forward-char 5))))))
  9062. (defun vhdl-template-variable ()
  9063. "Insert a variable declaration."
  9064. (interactive)
  9065. (let ((start (point))
  9066. (in-arglist (vhdl-in-argument-list-p)))
  9067. (vhdl-prepare-search-2
  9068. (if (or (save-excursion
  9069. (progn (vhdl-beginning-of-block)
  9070. (looking-at "\\s-*\\(\\w+\\s-*:\\s-*\\)?\\<\\(\\<function\\|procedure\\|process\\|procedural\\)\\>")))
  9071. (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
  9072. (vhdl-insert-keyword "VARIABLE ")
  9073. (if (vhdl-standard-p '87)
  9074. (error "ERROR: Not within sequential block")
  9075. (vhdl-insert-keyword "SHARED VARIABLE "))))
  9076. (when (vhdl-template-field "names" nil t start (point))
  9077. (insert " : ")
  9078. (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
  9079. (vhdl-template-field "type")
  9080. (if in-arglist
  9081. (progn (insert ";")
  9082. (vhdl-comment-insert-inline))
  9083. (let ((position (point)))
  9084. (insert " := ")
  9085. (unless (vhdl-template-field "[initialization]" nil t)
  9086. (delete-region position (point)))
  9087. (insert ";")
  9088. (vhdl-comment-insert-inline))))))
  9089. (defun vhdl-template-wait ()
  9090. "Insert a wait statement."
  9091. (interactive)
  9092. (vhdl-insert-keyword "WAIT ")
  9093. (unless (vhdl-template-field
  9094. "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
  9095. nil t)
  9096. (delete-char -1))
  9097. (insert ";"))
  9098. (defun vhdl-template-when ()
  9099. "Indent correctly if within a case statement."
  9100. (interactive)
  9101. (let ((position (point))
  9102. margin)
  9103. (vhdl-prepare-search-2
  9104. (if (and (= (current-column) (current-indentation))
  9105. (vhdl-re-search-forward "\\<end\\>" nil t)
  9106. (looking-at "\\s-*\\<case\\>"))
  9107. (progn
  9108. (setq margin (current-indentation))
  9109. (goto-char position)
  9110. (delete-horizontal-space)
  9111. (indent-to (+ margin vhdl-basic-offset)))
  9112. (goto-char position)))
  9113. (vhdl-insert-keyword "WHEN ")))
  9114. (defun vhdl-template-while-loop ()
  9115. "Insert a while loop."
  9116. (interactive)
  9117. (let* ((margin (current-indentation))
  9118. (start (point))
  9119. label)
  9120. (if (not (eq vhdl-optional-labels 'all))
  9121. (vhdl-insert-keyword "WHILE ")
  9122. (vhdl-insert-keyword ": WHILE ")
  9123. (goto-char start)
  9124. (setq label (vhdl-template-field "[label]" nil t))
  9125. (unless label (delete-char 2))
  9126. (forward-word 1)
  9127. (forward-char 1))
  9128. (when vhdl-conditions-in-parenthesis (insert "("))
  9129. (when (vhdl-template-field "condition" nil t start (point))
  9130. (when vhdl-conditions-in-parenthesis (insert ")"))
  9131. (vhdl-insert-keyword " LOOP\n\n")
  9132. (indent-to margin)
  9133. (vhdl-insert-keyword "END LOOP")
  9134. (insert (if label (concat " " label ";") ";"))
  9135. (forward-line -1)
  9136. (indent-to (+ margin vhdl-basic-offset)))))
  9137. (defun vhdl-template-with ()
  9138. "Insert a with statement (i.e. selected signal assignment)."
  9139. (interactive)
  9140. (vhdl-prepare-search-1
  9141. (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
  9142. (equal ";" (match-string 1)))
  9143. (vhdl-template-selected-signal-asst)
  9144. (vhdl-insert-keyword "WITH "))))
  9145. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9146. ;; Special templates
  9147. (defun vhdl-template-clocked-wait ()
  9148. "Insert a wait statement for rising/falling clock edge."
  9149. (interactive)
  9150. (let ((start (point))
  9151. clock)
  9152. (vhdl-insert-keyword "WAIT UNTIL ")
  9153. (when (setq clock
  9154. (or (and (not (equal "" vhdl-clock-name))
  9155. (progn (insert vhdl-clock-name) vhdl-clock-name))
  9156. (vhdl-template-field "clock name" nil t start (point))))
  9157. (insert "'event")
  9158. (vhdl-insert-keyword " AND ")
  9159. (insert clock)
  9160. (insert
  9161. " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
  9162. (vhdl-comment-insert-inline
  9163. (concat (if vhdl-clock-rising-edge "rising" "falling")
  9164. " clock edge")))))
  9165. (defun vhdl-template-seq-process (clock reset reset-kind)
  9166. "Insert a template for the body of a sequential process."
  9167. (let ((margin (current-indentation))
  9168. position)
  9169. (vhdl-insert-keyword "IF ")
  9170. (when vhdl-conditions-in-parenthesis (insert "("))
  9171. (when (eq reset-kind 'async)
  9172. (insert reset " = "
  9173. (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
  9174. (when vhdl-conditions-in-parenthesis (insert ")"))
  9175. (vhdl-insert-keyword " THEN")
  9176. (vhdl-comment-insert-inline
  9177. (concat "asynchronous reset (active "
  9178. (if vhdl-reset-active-high "high" "low") ")"))
  9179. (insert "\n") (indent-to (+ margin vhdl-basic-offset))
  9180. (setq position (point))
  9181. (insert "\n") (indent-to margin)
  9182. (vhdl-insert-keyword "ELSIF ")
  9183. (when vhdl-conditions-in-parenthesis (insert "(")))
  9184. (if (eq vhdl-clock-edge-condition 'function)
  9185. (insert (if vhdl-clock-rising-edge "rising" "falling")
  9186. "_edge(" clock ")")
  9187. (insert clock "'event")
  9188. (vhdl-insert-keyword " AND ")
  9189. (insert clock " = "
  9190. (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
  9191. (when vhdl-conditions-in-parenthesis (insert ")"))
  9192. (vhdl-insert-keyword " THEN")
  9193. (vhdl-comment-insert-inline
  9194. (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
  9195. (insert "\n") (indent-to (+ margin vhdl-basic-offset))
  9196. (when (eq reset-kind 'sync)
  9197. (vhdl-insert-keyword "IF ")
  9198. (when vhdl-conditions-in-parenthesis (insert "("))
  9199. (setq reset (or (and (not (equal "" vhdl-reset-name))
  9200. (progn (insert vhdl-reset-name) vhdl-reset-name))
  9201. (vhdl-template-field "reset name") "<reset>"))
  9202. (insert " = "
  9203. (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
  9204. (when vhdl-conditions-in-parenthesis (insert ")"))
  9205. (vhdl-insert-keyword " THEN")
  9206. (vhdl-comment-insert-inline
  9207. (concat "synchronous reset (active "
  9208. (if vhdl-reset-active-high "high" "low") ")"))
  9209. (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
  9210. (setq position (point))
  9211. (insert "\n") (indent-to (+ margin vhdl-basic-offset))
  9212. (vhdl-insert-keyword "ELSE")
  9213. (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
  9214. (insert "\n") (indent-to (+ margin vhdl-basic-offset))
  9215. (vhdl-insert-keyword "END IF;"))
  9216. (when (eq reset-kind 'none)
  9217. (setq position (point)))
  9218. (insert "\n") (indent-to margin)
  9219. (vhdl-insert-keyword "END IF;")
  9220. (goto-char position)
  9221. reset))
  9222. (defun vhdl-template-standard-package (library package)
  9223. "Insert specification of a standard package. Include a library
  9224. specification, if not already there."
  9225. (let ((margin (current-indentation)))
  9226. (unless (equal library "std")
  9227. (unless (or (save-excursion
  9228. (vhdl-prepare-search-1
  9229. (and (not (bobp))
  9230. (re-search-backward
  9231. (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
  9232. library "\\|end\\)\\>") nil t)
  9233. (match-string 2))))
  9234. (equal (downcase library) "work"))
  9235. (vhdl-insert-keyword "LIBRARY ")
  9236. (insert library ";")
  9237. (when package
  9238. (insert "\n")
  9239. (indent-to margin))))
  9240. (when package
  9241. (vhdl-insert-keyword "USE ")
  9242. (insert library "." package)
  9243. (vhdl-insert-keyword ".ALL;"))))
  9244. (defun vhdl-template-package-numeric-bit ()
  9245. "Insert specification of `numeric_bit' package."
  9246. (interactive)
  9247. (vhdl-template-standard-package "ieee" "numeric_bit"))
  9248. (defun vhdl-template-package-numeric-std ()
  9249. "Insert specification of `numeric_std' package."
  9250. (interactive)
  9251. (vhdl-template-standard-package "ieee" "numeric_std"))
  9252. (defun vhdl-template-package-std-logic-1164 ()
  9253. "Insert specification of `std_logic_1164' package."
  9254. (interactive)
  9255. (vhdl-template-standard-package "ieee" "std_logic_1164"))
  9256. (defun vhdl-template-package-std-logic-arith ()
  9257. "Insert specification of `std_logic_arith' package."
  9258. (interactive)
  9259. (vhdl-template-standard-package "ieee" "std_logic_arith"))
  9260. (defun vhdl-template-package-std-logic-misc ()
  9261. "Insert specification of `std_logic_misc' package."
  9262. (interactive)
  9263. (vhdl-template-standard-package "ieee" "std_logic_misc"))
  9264. (defun vhdl-template-package-std-logic-signed ()
  9265. "Insert specification of `std_logic_signed' package."
  9266. (interactive)
  9267. (vhdl-template-standard-package "ieee" "std_logic_signed"))
  9268. (defun vhdl-template-package-std-logic-textio ()
  9269. "Insert specification of `std_logic_textio' package."
  9270. (interactive)
  9271. (vhdl-template-standard-package "ieee" "std_logic_textio"))
  9272. (defun vhdl-template-package-std-logic-unsigned ()
  9273. "Insert specification of `std_logic_unsigned' package."
  9274. (interactive)
  9275. (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
  9276. (defun vhdl-template-package-textio ()
  9277. "Insert specification of `textio' package."
  9278. (interactive)
  9279. (vhdl-template-standard-package "std" "textio"))
  9280. (defun vhdl-template-package-fundamental-constants ()
  9281. "Insert specification of `fundamental_constants' package."
  9282. (interactive)
  9283. (vhdl-template-standard-package "ieee" "fundamental_constants"))
  9284. (defun vhdl-template-package-material-constants ()
  9285. "Insert specification of `material_constants' package."
  9286. (interactive)
  9287. (vhdl-template-standard-package "ieee" "material_constants"))
  9288. (defun vhdl-template-package-energy-systems ()
  9289. "Insert specification of `energy_systems' package."
  9290. (interactive)
  9291. (vhdl-template-standard-package "ieee" "energy_systems"))
  9292. (defun vhdl-template-package-electrical-systems ()
  9293. "Insert specification of `electrical_systems' package."
  9294. (interactive)
  9295. (vhdl-template-standard-package "ieee" "electrical_systems"))
  9296. (defun vhdl-template-package-mechanical-systems ()
  9297. "Insert specification of `mechanical_systems' package."
  9298. (interactive)
  9299. (vhdl-template-standard-package "ieee" "mechanical_systems"))
  9300. (defun vhdl-template-package-radiant-systems ()
  9301. "Insert specification of `radiant_systems' package."
  9302. (interactive)
  9303. (vhdl-template-standard-package "ieee" "radiant_systems"))
  9304. (defun vhdl-template-package-thermal-systems ()
  9305. "Insert specification of `thermal_systems' package."
  9306. (interactive)
  9307. (vhdl-template-standard-package "ieee" "thermal_systems"))
  9308. (defun vhdl-template-package-fluidic-systems ()
  9309. "Insert specification of `fluidic_systems' package."
  9310. (interactive)
  9311. (vhdl-template-standard-package "ieee" "fluidic_systems"))
  9312. (defun vhdl-template-package-math-complex ()
  9313. "Insert specification of `math_complex' package."
  9314. (interactive)
  9315. (vhdl-template-standard-package "ieee" "math_complex"))
  9316. (defun vhdl-template-package-math-real ()
  9317. "Insert specification of `math_real' package."
  9318. (interactive)
  9319. (vhdl-template-standard-package "ieee" "math_real"))
  9320. (defun vhdl-template-directive (directive)
  9321. "Insert directive."
  9322. (unless (= (current-indentation) (current-column))
  9323. (delete-horizontal-space)
  9324. (insert " "))
  9325. (insert "-- pragma " directive))
  9326. (defun vhdl-template-directive-translate-on ()
  9327. "Insert directive 'translate_on'."
  9328. (interactive)
  9329. (vhdl-template-directive "translate_on"))
  9330. (defun vhdl-template-directive-translate-off ()
  9331. "Insert directive 'translate_off'."
  9332. (interactive)
  9333. (vhdl-template-directive "translate_off"))
  9334. (defun vhdl-template-directive-synthesis-on ()
  9335. "Insert directive 'synthesis_on'."
  9336. (interactive)
  9337. (vhdl-template-directive "synthesis_on"))
  9338. (defun vhdl-template-directive-synthesis-off ()
  9339. "Insert directive 'synthesis_off'."
  9340. (interactive)
  9341. (vhdl-template-directive "synthesis_off"))
  9342. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9343. ;; Header and footer templates
  9344. (defun vhdl-template-header (&optional file-title)
  9345. "Insert a VHDL file header."
  9346. (interactive)
  9347. (unless (equal vhdl-file-header "")
  9348. (let (pos)
  9349. (save-excursion
  9350. (goto-char (point-min))
  9351. (vhdl-insert-string-or-file vhdl-file-header)
  9352. (setq pos (point-marker)))
  9353. (vhdl-template-replace-header-keywords
  9354. (point-min-marker) pos file-title))))
  9355. (defun vhdl-template-footer ()
  9356. "Insert a VHDL file footer."
  9357. (interactive)
  9358. (unless (equal vhdl-file-footer "")
  9359. (let (pos)
  9360. (save-excursion
  9361. (goto-char (point-max))
  9362. (setq pos (point-marker))
  9363. (vhdl-insert-string-or-file vhdl-file-footer)
  9364. (unless (= (preceding-char) ?\n)
  9365. (insert "\n")))
  9366. (vhdl-template-replace-header-keywords pos (point-max-marker)))))
  9367. (defun vhdl-template-replace-header-keywords (beg end &optional file-title
  9368. is-model)
  9369. "Replace keywords in header and footer."
  9370. (let ((project-title (or (nth 0 (aget vhdl-project-alist vhdl-project)) ""))
  9371. (project-desc (or (nth 9 (aget vhdl-project-alist vhdl-project)) ""))
  9372. pos)
  9373. (vhdl-prepare-search-2
  9374. (save-excursion
  9375. (goto-char beg)
  9376. (while (search-forward "<projectdesc>" end t)
  9377. (replace-match project-desc t t))
  9378. (goto-char beg)
  9379. (while (search-forward "<filename>" end t)
  9380. (replace-match (buffer-name) t t))
  9381. (goto-char beg)
  9382. (while (search-forward "<copyright>" end t)
  9383. (replace-match vhdl-copyright-string t t))
  9384. (goto-char beg)
  9385. (while (search-forward "<author>" end t)
  9386. (replace-match "" t t)
  9387. (insert (user-full-name))
  9388. (when user-mail-address (insert " <" user-mail-address ">")))
  9389. (goto-char beg)
  9390. (while (search-forward "<authorfull>" end t)
  9391. (replace-match (user-full-name) t t))
  9392. (goto-char beg)
  9393. (while (search-forward "<login>" end t)
  9394. (replace-match (user-login-name) t t))
  9395. (goto-char beg)
  9396. (while (search-forward "<project>" end t)
  9397. (replace-match project-title t t))
  9398. (goto-char beg)
  9399. (while (search-forward "<company>" end t)
  9400. (replace-match vhdl-company-name t t))
  9401. (goto-char beg)
  9402. (while (search-forward "<platform>" end t)
  9403. (replace-match vhdl-platform-spec t t))
  9404. (goto-char beg)
  9405. (while (search-forward "<standard>" end t)
  9406. (replace-match
  9407. (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
  9408. ((vhdl-standard-p '93) "'93/02"))
  9409. (when (vhdl-standard-p 'ams) ", VHDL-AMS")
  9410. (when (vhdl-standard-p 'math) ", Math Packages")) t t))
  9411. (goto-char beg)
  9412. ;; Replace <RCS> with $, so that RCS for the source is
  9413. ;; not over-enthusiastic with replacements
  9414. (while (search-forward "<RCS>" end t)
  9415. (replace-match "$" nil t))
  9416. (goto-char beg)
  9417. (while (search-forward "<date>" end t)
  9418. (replace-match "" t t)
  9419. (vhdl-template-insert-date))
  9420. (goto-char beg)
  9421. (while (search-forward "<year>" end t)
  9422. (replace-match (format-time-string "%Y" nil) t t))
  9423. (goto-char beg)
  9424. (when file-title
  9425. (while (search-forward "<title string>" end t)
  9426. (replace-match file-title t t))
  9427. (goto-char beg))
  9428. (let (string)
  9429. (while
  9430. (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
  9431. (setq string (read-string (concat (match-string 1) ": ")))
  9432. (replace-match string t t)))
  9433. (goto-char beg)
  9434. (when (and (not is-model) (search-forward "<cursor>" end t))
  9435. (replace-match "" t t)
  9436. (setq pos (point))))
  9437. (when pos (goto-char pos))
  9438. (unless is-model
  9439. (when (or (not project-title) (equal project-title ""))
  9440. (message "You can specify a project title in user option `vhdl-project-alist'"))
  9441. (when (or (not project-desc) (equal project-desc ""))
  9442. (message "You can specify a project description in user option `vhdl-project-alist'"))
  9443. (when (equal vhdl-platform-spec "")
  9444. (message "You can specify a platform in user option `vhdl-platform-spec'"))
  9445. (when (equal vhdl-company-name "")
  9446. (message "You can specify a company name in user option `vhdl-company-name'"))))))
  9447. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9448. ;; Comment templates and functions
  9449. (defun vhdl-comment-indent ()
  9450. "Indent comments."
  9451. (let* ((position (point))
  9452. (col
  9453. (progn
  9454. (forward-line -1)
  9455. (if (re-search-forward "--" position t)
  9456. (- (current-column) 2) ; existing comment at bol stays there
  9457. (goto-char position)
  9458. (skip-chars-backward " \t")
  9459. (max comment-column ; else indent to comment column
  9460. (1+ (current-column))))))) ; except leave at least one space
  9461. (goto-char position)
  9462. col))
  9463. (defun vhdl-comment-insert ()
  9464. "Start a comment at the end of the line.
  9465. If on line with code, indent at least `comment-column'.
  9466. If starting after end-comment-column, start a new line."
  9467. (interactive)
  9468. (when (> (current-column) end-comment-column) (newline-and-indent))
  9469. (if (or (looking-at "\\s-*$") ; end of line
  9470. (and (not unread-command-events) ; called with key binding or menu
  9471. (not (end-of-line))))
  9472. (let (margin)
  9473. (while (= (preceding-char) ?-) (delete-char -1))
  9474. (setq margin (current-column))
  9475. (delete-horizontal-space)
  9476. (if (bolp)
  9477. (progn (indent-to margin) (insert "--"))
  9478. (insert " ")
  9479. (indent-to comment-column)
  9480. (insert "--"))
  9481. (if (not unread-command-events) (insert " ")))
  9482. ;; else code following current point implies commenting out code
  9483. (let (next-input code)
  9484. (while (= (preceding-char) ?-) (delete-char -2))
  9485. (while (= (setq next-input (read-char)) 13) ; CR
  9486. (insert "--") ; or have a space after it?
  9487. (forward-char -2)
  9488. (forward-line 1)
  9489. (message "Enter CR if commenting out a line of code.")
  9490. (setq code t))
  9491. (unless code
  9492. (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
  9493. (setq unread-command-events
  9494. (list (vhdl-character-to-event next-input)))))) ; pushback the char
  9495. (defun vhdl-comment-display (&optional line-exists)
  9496. "Add 2 comment lines at the current indent, making a display comment."
  9497. (interactive)
  9498. (let ((margin (current-indentation)))
  9499. (unless line-exists (vhdl-comment-display-line))
  9500. (insert "\n") (indent-to margin)
  9501. (insert "\n") (indent-to margin)
  9502. (vhdl-comment-display-line)
  9503. (end-of-line -0)
  9504. (insert "-- ")))
  9505. (defun vhdl-comment-display-line ()
  9506. "Displays one line of dashes."
  9507. (interactive)
  9508. (while (= (preceding-char) ?-) (delete-char -2))
  9509. (insert "--")
  9510. (let* ((col (current-column))
  9511. (len (- end-comment-column col)))
  9512. (insert-char vhdl-comment-display-line-char len)))
  9513. (defun vhdl-comment-append-inline ()
  9514. "Append empty inline comment to current line."
  9515. (interactive)
  9516. (end-of-line)
  9517. (delete-horizontal-space)
  9518. (insert " ")
  9519. (indent-to comment-column)
  9520. (insert "-- "))
  9521. (defun vhdl-comment-insert-inline (&optional string always-insert)
  9522. "Insert inline comment."
  9523. (when (or (and string (or vhdl-self-insert-comments always-insert))
  9524. (and (not string) vhdl-prompt-for-comments))
  9525. (let ((position (point)))
  9526. (insert " ")
  9527. (indent-to comment-column)
  9528. (insert "-- ")
  9529. (if (not (or (and string (progn (insert string) t))
  9530. (vhdl-template-field "[comment]" nil t)))
  9531. (delete-region position (point))
  9532. (while (= (preceding-char) ?\ ) (delete-char -1))
  9533. ;; (when (> (current-column) end-comment-column)
  9534. ;; (setq position (point-marker))
  9535. ;; (re-search-backward "-- ")
  9536. ;; (insert "\n")
  9537. ;; (indent-to comment-column)
  9538. ;; (goto-char position))
  9539. ))))
  9540. (defun vhdl-comment-block ()
  9541. "Insert comment for code block."
  9542. (when vhdl-prompt-for-comments
  9543. (let ((final-pos (point-marker)))
  9544. (vhdl-prepare-search-2
  9545. (when (and (re-search-backward "^\\s-*begin\\>" nil t)
  9546. (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
  9547. (let (margin)
  9548. (back-to-indentation)
  9549. (setq margin (current-column))
  9550. (end-of-line -0)
  9551. (if (bobp)
  9552. (progn (insert "\n") (forward-line -1))
  9553. (insert "\n"))
  9554. (indent-to margin)
  9555. (insert "-- purpose: ")
  9556. (unless (vhdl-template-field "[description]" nil t)
  9557. (vhdl-line-kill-entire)))))
  9558. (goto-char final-pos))))
  9559. (defun vhdl-comment-uncomment-region (beg end &optional arg)
  9560. "Comment out region if not commented out, uncomment otherwise."
  9561. (interactive "r\nP")
  9562. (save-excursion
  9563. (goto-char (1- end))
  9564. (end-of-line)
  9565. (setq end (point-marker))
  9566. (goto-char beg)
  9567. (beginning-of-line)
  9568. (setq beg (point))
  9569. (if (looking-at (concat "\\s-*" comment-start))
  9570. (comment-region beg end '(4))
  9571. (comment-region beg end))))
  9572. (defun vhdl-comment-uncomment-line (&optional arg)
  9573. "Comment out line if not commented out, uncomment otherwise."
  9574. (interactive "p")
  9575. (save-excursion
  9576. (beginning-of-line)
  9577. (let ((position (point)))
  9578. (forward-line (or arg 1))
  9579. (vhdl-comment-uncomment-region position (point)))))
  9580. (defun vhdl-comment-kill-region (beg end)
  9581. "Kill comments in region."
  9582. (interactive "r")
  9583. (save-excursion
  9584. (goto-char end)
  9585. (setq end (point-marker))
  9586. (goto-char beg)
  9587. (beginning-of-line)
  9588. (while (< (point) end)
  9589. (if (looking-at "^\\(\\s-*--.*\n\\)")
  9590. (progn (delete-region (match-beginning 1) (match-end 1)))
  9591. (beginning-of-line 2)))))
  9592. (defun vhdl-comment-kill-inline-region (beg end)
  9593. "Kill inline comments in region."
  9594. (interactive "r")
  9595. (save-excursion
  9596. (goto-char end)
  9597. (setq end (point-marker))
  9598. (goto-char beg)
  9599. (beginning-of-line)
  9600. (while (< (point) end)
  9601. (when (looking-at "^.*[^ \t\n\r\f-]+\\(\\s-*--.*\\)$")
  9602. (delete-region (match-beginning 1) (match-end 1)))
  9603. (beginning-of-line 2))))
  9604. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9605. ;; Subtemplates
  9606. (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
  9607. "Insert a begin ... end pair with optional name after the end.
  9608. Point is left between them."
  9609. (let (position)
  9610. (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
  9611. (indent-to margin)
  9612. (vhdl-insert-keyword "BEGIN")
  9613. (when (and (or construct name) vhdl-self-insert-comments)
  9614. (insert " --")
  9615. (when construct (insert " ") (vhdl-insert-keyword construct))
  9616. (when name (insert " " name)))
  9617. (insert "\n")
  9618. (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
  9619. (indent-to (+ margin vhdl-basic-offset))
  9620. (setq position (point))
  9621. (insert "\n")
  9622. (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
  9623. (indent-to margin)
  9624. (vhdl-insert-keyword "END")
  9625. (when construct (insert " ") (vhdl-insert-keyword construct))
  9626. (insert (if name (concat " " name) "") ";")
  9627. (goto-char position)))
  9628. (defun vhdl-template-argument-list (&optional is-function)
  9629. "Read from user a procedure or function argument list."
  9630. (insert " (")
  9631. (let ((margin (current-column))
  9632. (start (point))
  9633. (end-pos (point))
  9634. not-empty interface semicolon-pos)
  9635. (unless vhdl-argument-list-indent
  9636. (setq margin (+ (current-indentation) vhdl-basic-offset))
  9637. (insert "\n")
  9638. (indent-to margin))
  9639. (setq interface (vhdl-template-field
  9640. (concat "[CONSTANT | SIGNAL"
  9641. (unless is-function " | VARIABLE") "]") " " t))
  9642. (while (vhdl-template-field "[names]" nil t)
  9643. (setq not-empty t)
  9644. (insert " : ")
  9645. (unless is-function
  9646. (if (and interface (equal (upcase interface) "CONSTANT"))
  9647. (vhdl-insert-keyword "IN ")
  9648. (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
  9649. (vhdl-template-field "type")
  9650. (setq semicolon-pos (point))
  9651. (insert ";")
  9652. (vhdl-comment-insert-inline)
  9653. (setq end-pos (point))
  9654. (insert "\n")
  9655. (indent-to margin)
  9656. (setq interface (vhdl-template-field
  9657. (concat "[CONSTANT | SIGNAL"
  9658. (unless is-function " | VARIABLE") "]") " " t)))
  9659. (delete-region end-pos (point))
  9660. (when semicolon-pos (goto-char semicolon-pos))
  9661. (if not-empty
  9662. (progn (delete-char 1) (insert ")"))
  9663. (delete-char -2))))
  9664. (defun vhdl-template-generic-list (optional &optional no-value)
  9665. "Read from user a generic spec argument list."
  9666. (let (margin
  9667. (start (point)))
  9668. (vhdl-insert-keyword "GENERIC (")
  9669. (setq margin (current-column))
  9670. (unless vhdl-argument-list-indent
  9671. (let ((position (point)))
  9672. (back-to-indentation)
  9673. (setq margin (+ (current-column) vhdl-basic-offset))
  9674. (goto-char position)
  9675. (insert "\n")
  9676. (indent-to margin)))
  9677. (let ((vhdl-generics (vhdl-template-field
  9678. (concat (and optional "[") "name"
  9679. (and no-value "s") (and optional "]"))
  9680. nil optional)))
  9681. (if (not vhdl-generics)
  9682. (if optional
  9683. (progn (vhdl-line-kill-entire) (end-of-line -0)
  9684. (unless vhdl-argument-list-indent
  9685. (vhdl-line-kill-entire) (end-of-line -0)))
  9686. (vhdl-template-undo start (point))
  9687. nil )
  9688. (insert " : ")
  9689. (let (semicolon-pos end-pos)
  9690. (while vhdl-generics
  9691. (vhdl-template-field "type")
  9692. (if no-value
  9693. (progn (setq semicolon-pos (point))
  9694. (insert ";"))
  9695. (insert " := ")
  9696. (unless (vhdl-template-field "[value]" nil t)
  9697. (delete-char -4))
  9698. (setq semicolon-pos (point))
  9699. (insert ";"))
  9700. (vhdl-comment-insert-inline)
  9701. (setq end-pos (point))
  9702. (insert "\n")
  9703. (indent-to margin)
  9704. (setq vhdl-generics (vhdl-template-field
  9705. (concat "[name" (and no-value "s") "]")
  9706. " : " t)))
  9707. (delete-region end-pos (point))
  9708. (goto-char semicolon-pos)
  9709. (insert ")")
  9710. (end-of-line)
  9711. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
  9712. t)))))
  9713. (defun vhdl-template-port-list (optional)
  9714. "Read from user a port spec argument list."
  9715. (let ((start (point))
  9716. margin vhdl-ports object)
  9717. (vhdl-insert-keyword "PORT (")
  9718. (setq margin (current-column))
  9719. (unless vhdl-argument-list-indent
  9720. (let ((position (point)))
  9721. (back-to-indentation)
  9722. (setq margin (+ (current-column) vhdl-basic-offset))
  9723. (goto-char position)
  9724. (insert "\n")
  9725. (indent-to margin)))
  9726. (when (vhdl-standard-p 'ams)
  9727. (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
  9728. " " t)))
  9729. (setq vhdl-ports (vhdl-template-field
  9730. (concat (and optional "[") "names" (and optional "]"))
  9731. nil optional))
  9732. (if (not vhdl-ports)
  9733. (if optional
  9734. (progn (vhdl-line-kill-entire) (end-of-line -0)
  9735. (unless vhdl-argument-list-indent
  9736. (vhdl-line-kill-entire) (end-of-line -0)))
  9737. (vhdl-template-undo start (point))
  9738. nil)
  9739. (insert " : ")
  9740. (let (semicolon-pos end-pos)
  9741. (while vhdl-ports
  9742. (cond ((or (null object) (equal "SIGNAL" (upcase object)))
  9743. (vhdl-template-field "IN | OUT | INOUT" " "))
  9744. ((equal "QUANTITY" (upcase object))
  9745. (vhdl-template-field "[IN | OUT]" " " t)))
  9746. (vhdl-template-field
  9747. (if (and object (equal "TERMINAL" (upcase object)))
  9748. "nature" "type"))
  9749. (setq semicolon-pos (point))
  9750. (insert ";")
  9751. (vhdl-comment-insert-inline)
  9752. (setq end-pos (point))
  9753. (insert "\n")
  9754. (indent-to margin)
  9755. (when (vhdl-standard-p 'ams)
  9756. (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
  9757. " " t)))
  9758. (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
  9759. (delete-region end-pos (point))
  9760. (goto-char semicolon-pos)
  9761. (insert ")")
  9762. (end-of-line)
  9763. (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
  9764. t))))
  9765. (defun vhdl-template-generate-body (margin label)
  9766. "Insert body for generate template."
  9767. (vhdl-insert-keyword " GENERATE")
  9768. ; (if (not (vhdl-standard-p '87))
  9769. ; (vhdl-template-begin-end "GENERATE" label margin)
  9770. (insert "\n\n")
  9771. (indent-to margin)
  9772. (vhdl-insert-keyword "END GENERATE ")
  9773. (insert label ";")
  9774. (end-of-line 0)
  9775. (indent-to (+ margin vhdl-basic-offset)))
  9776. (defun vhdl-template-insert-date ()
  9777. "Insert date in appropriate format."
  9778. (interactive)
  9779. (insert
  9780. (cond
  9781. ;; 'american, 'european, 'scientific kept for backward compatibility
  9782. ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
  9783. ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
  9784. ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
  9785. (t (format-time-string vhdl-date-format nil)))))
  9786. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9787. ;; Help functions
  9788. (defun vhdl-electric-space (count)
  9789. "Expand abbreviations and self-insert space(s), do indent-new-comment-line
  9790. if in comment and past end-comment-column."
  9791. (interactive "p")
  9792. (cond ((vhdl-in-comment-p)
  9793. (self-insert-command count)
  9794. (cond ((>= (current-column) (+ 2 end-comment-column))
  9795. (backward-char 1)
  9796. (skip-chars-backward "^ \t\n\r\f")
  9797. (indent-new-comment-line)
  9798. (skip-chars-forward "^ \t\n\r\f")
  9799. (forward-char 1))
  9800. ((>= (current-column) end-comment-column)
  9801. (indent-new-comment-line))
  9802. (t nil)))
  9803. ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
  9804. (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
  9805. (vhdl-prepare-search-1
  9806. (or (expand-abbrev) (vhdl-fix-case-word -1)))
  9807. (self-insert-command count))
  9808. (t (self-insert-command count))))
  9809. (defun vhdl-template-field (prompt &optional follow-string optional
  9810. begin end is-string default)
  9811. "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
  9812. If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
  9813. an empty string is inserted, return nil and call `vhdl-template-undo' for
  9814. the region between BEGIN and END. IS-STRING indicates whether a string
  9815. with double-quotes is to be inserted. DEFAULT specifies a default string."
  9816. (let ((position (point))
  9817. string)
  9818. (insert "<" prompt ">")
  9819. (setq string
  9820. (condition-case ()
  9821. (read-from-minibuffer (concat prompt ": ")
  9822. (or (and is-string '("\"\"" . 2)) default)
  9823. vhdl-minibuffer-local-map)
  9824. (quit (if (and optional begin end)
  9825. (progn (beep) "")
  9826. (keyboard-quit)))))
  9827. (when (or (not (equal string "")) optional)
  9828. (delete-region position (point)))
  9829. (when (and (equal string "") optional begin end)
  9830. (vhdl-template-undo begin end)
  9831. (message "Template aborted"))
  9832. (unless (equal string "")
  9833. (insert string)
  9834. (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
  9835. vhdl-keywords-regexp)
  9836. (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
  9837. vhdl-types-regexp)
  9838. (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
  9839. (concat "'" vhdl-attributes-regexp))
  9840. (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
  9841. vhdl-enum-values-regexp)
  9842. (vhdl-fix-case-region-1 position (point) vhdl-upper-case-constants
  9843. vhdl-constants-regexp))
  9844. (when (or (not (equal string "")) (not optional))
  9845. (insert (or follow-string "")))
  9846. (if (equal string "") nil string)))
  9847. (defun vhdl-decision-query (string prompt &optional optional)
  9848. "Query a decision from the user."
  9849. (let ((start (point)))
  9850. (when string (vhdl-insert-keyword (concat string " ")))
  9851. (message "%s" (or prompt ""))
  9852. (let ((char (read-char)))
  9853. (delete-region start (point))
  9854. (if (and optional (eq char ?\r))
  9855. (progn (insert " ")
  9856. (unexpand-abbrev)
  9857. (throw 'abort "ERROR: Template aborted"))
  9858. char))))
  9859. (defun vhdl-insert-keyword (keyword)
  9860. "Insert KEYWORD and adjust case."
  9861. (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
  9862. (defun vhdl-case-keyword (keyword)
  9863. "Adjust case of KEYWORD."
  9864. (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
  9865. (defun vhdl-case-word (num)
  9866. "Adjust case of following NUM words."
  9867. (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
  9868. (defun vhdl-minibuffer-tab (&optional prefix-arg)
  9869. "If preceding character is part of a word or a paren then hippie-expand,
  9870. else insert tab (used for word completion in VHDL minibuffer)."
  9871. (interactive "P")
  9872. (cond
  9873. ;; expand word
  9874. ((= (char-syntax (preceding-char)) ?w)
  9875. (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
  9876. (case-replace nil)
  9877. (hippie-expand-only-buffers
  9878. (or (and (boundp 'hippie-expand-only-buffers)
  9879. hippie-expand-only-buffers)
  9880. '(vhdl-mode))))
  9881. (vhdl-expand-abbrev prefix-arg)))
  9882. ;; expand parenthesis
  9883. ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
  9884. (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
  9885. (case-replace nil))
  9886. (vhdl-expand-paren prefix-arg)))
  9887. ;; insert tab
  9888. (t (insert-tab))))
  9889. (defun vhdl-template-search-prompt ()
  9890. "Search for left out template prompts and query again."
  9891. (interactive)
  9892. (vhdl-prepare-search-2
  9893. (when (or (re-search-forward
  9894. (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
  9895. (re-search-backward
  9896. (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
  9897. (let ((string (match-string 1)))
  9898. (replace-match "")
  9899. (vhdl-template-field string)))))
  9900. (defun vhdl-template-undo (begin end)
  9901. "Undo aborted template by deleting region and unexpanding the keyword."
  9902. (cond (vhdl-template-invoked-by-hook
  9903. (goto-char end)
  9904. (insert " ")
  9905. (delete-region begin end)
  9906. (unexpand-abbrev))
  9907. (t (delete-region begin end))))
  9908. (defun vhdl-insert-string-or-file (string)
  9909. "Insert STRING or file contents if STRING is an existing file name."
  9910. (unless (equal string "")
  9911. (let ((file-name
  9912. (progn (string-match "^\\([^\n]+\\)" string)
  9913. (vhdl-resolve-env-variable (match-string 1 string)))))
  9914. (if (file-exists-p file-name)
  9915. (forward-char (cadr (insert-file-contents file-name)))
  9916. (insert string)))))
  9917. (defun vhdl-beginning-of-block ()
  9918. "Move cursor to the beginning of the enclosing block."
  9919. (let (pos)
  9920. (vhdl-prepare-search-2
  9921. (save-excursion
  9922. (beginning-of-line)
  9923. ;; search backward for block beginning or end
  9924. (while (or (while (and (setq pos (re-search-backward "^\\s-*\\(\\(end\\)\\|\\(\\(impure\\|pure\\)[ \t\n\r\f]+\\)?\\(function\\|procedure\\)\\|\\(for\\)\\|\\(architecture\\|component\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|type[ \t\n\r\f]+\\w+[ \t\n\r\f]+is[ \t\n\r\f]+\\(record\\|protected\\(\\s-+body\\)?\\)\\|units\\)\\|\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(postponed[ \t\n\r\f]+\\)?\\(block\\|case\\|for\\|if\\|procedural\\|process\\|while\\|loop\\)\\)\\>" nil t))
  9925. ;; not consider subprogram declarations
  9926. (or (and (match-string 5)
  9927. (save-match-data
  9928. (save-excursion
  9929. (goto-char (match-end 5))
  9930. (forward-word 1)
  9931. (vhdl-forward-syntactic-ws)
  9932. (when (looking-at "(")
  9933. (forward-sexp))
  9934. (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
  9935. (match-string 1)))
  9936. ;; not consider configuration specifications
  9937. (and (match-string 6)
  9938. (save-match-data
  9939. (save-excursion
  9940. (vhdl-end-of-block)
  9941. (beginning-of-line)
  9942. (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
  9943. (match-string 2))
  9944. ;; skip subblock if block end found
  9945. (vhdl-beginning-of-block))))
  9946. (when pos (goto-char pos))))
  9947. (defun vhdl-end-of-block ()
  9948. "Move cursor to the end of the enclosing block."
  9949. (let (pos)
  9950. (vhdl-prepare-search-2
  9951. (save-excursion
  9952. (end-of-line)
  9953. ;; search forward for block beginning or end
  9954. (while (or (while (and (setq pos (re-search-forward "^\\s-*\\(\\(end\\)\\|\\(\\(impure\\|pure\\)[ \t\n\r\f]+\\)?\\(function\\|procedure\\)\\|\\(for\\)\\|\\(architecture\\|component\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|type[ \t\n\r\f]+\\w+[ \t\n\r\f]+is[ \t\n\r\f]+\\(record\\|protected\\(\\s-+body\\)?\\)\\|units\\)\\|\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(postponed[ \t\n\r\f]+\\)?\\(block\\|case\\|for\\|if\\|procedural\\|process\\|while\\|loop\\)\\)\\>" nil t))
  9955. ;; not consider subprogram declarations
  9956. (or (and (match-string 5)
  9957. (save-match-data
  9958. (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
  9959. (match-string 1)))
  9960. ;; not consider configuration specifications
  9961. (and (match-string 6)
  9962. (save-match-data
  9963. (save-excursion
  9964. (vhdl-end-of-block)
  9965. (beginning-of-line)
  9966. (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
  9967. (not (match-string 2)))
  9968. ;; skip subblock if block beginning found
  9969. (vhdl-end-of-block))))
  9970. (when pos (goto-char pos))))
  9971. (defun vhdl-sequential-statement-p ()
  9972. "Check if point is within sequential statement part."
  9973. (let ((start (point)))
  9974. (save-excursion
  9975. (vhdl-prepare-search-2
  9976. ;; is sequential statement if ...
  9977. (and (re-search-backward "^\\s-*begin\\>" nil t)
  9978. ;; ... point is between "begin" and "end" of ...
  9979. (progn (vhdl-end-of-block)
  9980. (< start (point)))
  9981. ;; ... a sequential block
  9982. (progn (vhdl-beginning-of-block)
  9983. (looking-at "^\\s-*\\(\\(\\w+[ \t\n\r\f]+\\)?\\(function\\|procedure\\)\\|\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(\\w+[ \t\n\r\f]+\\)?\\(procedural\\|process\\)\\)\\>")))))))
  9984. (defun vhdl-in-argument-list-p ()
  9985. "Check if within an argument list."
  9986. (save-excursion
  9987. (vhdl-prepare-search-2
  9988. (or (string-match "arglist"
  9989. (format "%s" (caar (vhdl-get-syntactic-context))))
  9990. (progn (beginning-of-line)
  9991. (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
  9992. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9993. ;; Abbrev hooks
  9994. (defun vhdl-hooked-abbrev (func)
  9995. "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
  9996. but not if inside a comment or quote."
  9997. (if (or (vhdl-in-literal)
  9998. (save-excursion
  9999. (forward-word -1)
  10000. (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
  10001. (progn
  10002. (insert " ")
  10003. (unexpand-abbrev)
  10004. (backward-word 1)
  10005. (vhdl-case-word 1)
  10006. (delete-char 1))
  10007. (if (not vhdl-electric-mode)
  10008. (progn
  10009. (insert " ")
  10010. (unexpand-abbrev)
  10011. (backward-word 1)
  10012. (vhdl-case-word 1)
  10013. (delete-char 1))
  10014. (let ((invoke-char last-command-event)
  10015. (abbrev-mode -1)
  10016. (vhdl-template-invoked-by-hook t))
  10017. (let ((caught (catch 'abort
  10018. (funcall func))))
  10019. (when (stringp caught) (message "%s" caught)))
  10020. (when (= invoke-char ?-) (setq abbrev-start-location (point)))
  10021. ;; delete CR which is still in event queue
  10022. (if (fboundp 'enqueue-eval-event)
  10023. (enqueue-eval-event 'delete-char -1)
  10024. (setq unread-command-events ; push back a delete char
  10025. (list (vhdl-character-to-event ?\177))))))))
  10026. (defun vhdl-template-alias-hook ()
  10027. (vhdl-hooked-abbrev 'vhdl-template-alias))
  10028. (defun vhdl-template-architecture-hook ()
  10029. (vhdl-hooked-abbrev 'vhdl-template-architecture))
  10030. (defun vhdl-template-assert-hook ()
  10031. (vhdl-hooked-abbrev 'vhdl-template-assert))
  10032. (defun vhdl-template-attribute-hook ()
  10033. (vhdl-hooked-abbrev 'vhdl-template-attribute))
  10034. (defun vhdl-template-block-hook ()
  10035. (vhdl-hooked-abbrev 'vhdl-template-block))
  10036. (defun vhdl-template-break-hook ()
  10037. (vhdl-hooked-abbrev 'vhdl-template-break))
  10038. (defun vhdl-template-case-hook ()
  10039. (vhdl-hooked-abbrev 'vhdl-template-case))
  10040. (defun vhdl-template-component-hook ()
  10041. (vhdl-hooked-abbrev 'vhdl-template-component))
  10042. (defun vhdl-template-instance-hook ()
  10043. (vhdl-hooked-abbrev 'vhdl-template-instance))
  10044. (defun vhdl-template-conditional-signal-asst-hook ()
  10045. (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
  10046. (defun vhdl-template-configuration-hook ()
  10047. (vhdl-hooked-abbrev 'vhdl-template-configuration))
  10048. (defun vhdl-template-constant-hook ()
  10049. (vhdl-hooked-abbrev 'vhdl-template-constant))
  10050. (defun vhdl-template-disconnect-hook ()
  10051. (vhdl-hooked-abbrev 'vhdl-template-disconnect))
  10052. (defun vhdl-template-display-comment-hook ()
  10053. (vhdl-hooked-abbrev 'vhdl-comment-display))
  10054. (defun vhdl-template-else-hook ()
  10055. (vhdl-hooked-abbrev 'vhdl-template-else))
  10056. (defun vhdl-template-elsif-hook ()
  10057. (vhdl-hooked-abbrev 'vhdl-template-elsif))
  10058. (defun vhdl-template-entity-hook ()
  10059. (vhdl-hooked-abbrev 'vhdl-template-entity))
  10060. (defun vhdl-template-exit-hook ()
  10061. (vhdl-hooked-abbrev 'vhdl-template-exit))
  10062. (defun vhdl-template-file-hook ()
  10063. (vhdl-hooked-abbrev 'vhdl-template-file))
  10064. (defun vhdl-template-for-hook ()
  10065. (vhdl-hooked-abbrev 'vhdl-template-for))
  10066. (defun vhdl-template-function-hook ()
  10067. (vhdl-hooked-abbrev 'vhdl-template-function))
  10068. (defun vhdl-template-generic-hook ()
  10069. (vhdl-hooked-abbrev 'vhdl-template-generic))
  10070. (defun vhdl-template-group-hook ()
  10071. (vhdl-hooked-abbrev 'vhdl-template-group))
  10072. (defun vhdl-template-library-hook ()
  10073. (vhdl-hooked-abbrev 'vhdl-template-library))
  10074. (defun vhdl-template-limit-hook ()
  10075. (vhdl-hooked-abbrev 'vhdl-template-limit))
  10076. (defun vhdl-template-if-hook ()
  10077. (vhdl-hooked-abbrev 'vhdl-template-if))
  10078. (defun vhdl-template-bare-loop-hook ()
  10079. (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
  10080. (defun vhdl-template-map-hook ()
  10081. (vhdl-hooked-abbrev 'vhdl-template-map))
  10082. (defun vhdl-template-nature-hook ()
  10083. (vhdl-hooked-abbrev 'vhdl-template-nature))
  10084. (defun vhdl-template-next-hook ()
  10085. (vhdl-hooked-abbrev 'vhdl-template-next))
  10086. (defun vhdl-template-others-hook ()
  10087. (vhdl-hooked-abbrev 'vhdl-template-others))
  10088. (defun vhdl-template-package-hook ()
  10089. (vhdl-hooked-abbrev 'vhdl-template-package))
  10090. (defun vhdl-template-port-hook ()
  10091. (vhdl-hooked-abbrev 'vhdl-template-port))
  10092. (defun vhdl-template-procedural-hook ()
  10093. (vhdl-hooked-abbrev 'vhdl-template-procedural))
  10094. (defun vhdl-template-procedure-hook ()
  10095. (vhdl-hooked-abbrev 'vhdl-template-procedure))
  10096. (defun vhdl-template-process-hook ()
  10097. (vhdl-hooked-abbrev 'vhdl-template-process))
  10098. (defun vhdl-template-quantity-hook ()
  10099. (vhdl-hooked-abbrev 'vhdl-template-quantity))
  10100. (defun vhdl-template-report-hook ()
  10101. (vhdl-hooked-abbrev 'vhdl-template-report))
  10102. (defun vhdl-template-return-hook ()
  10103. (vhdl-hooked-abbrev 'vhdl-template-return))
  10104. (defun vhdl-template-selected-signal-asst-hook ()
  10105. (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
  10106. (defun vhdl-template-signal-hook ()
  10107. (vhdl-hooked-abbrev 'vhdl-template-signal))
  10108. (defun vhdl-template-subnature-hook ()
  10109. (vhdl-hooked-abbrev 'vhdl-template-subnature))
  10110. (defun vhdl-template-subtype-hook ()
  10111. (vhdl-hooked-abbrev 'vhdl-template-subtype))
  10112. (defun vhdl-template-terminal-hook ()
  10113. (vhdl-hooked-abbrev 'vhdl-template-terminal))
  10114. (defun vhdl-template-type-hook ()
  10115. (vhdl-hooked-abbrev 'vhdl-template-type))
  10116. (defun vhdl-template-use-hook ()
  10117. (vhdl-hooked-abbrev 'vhdl-template-use))
  10118. (defun vhdl-template-variable-hook ()
  10119. (vhdl-hooked-abbrev 'vhdl-template-variable))
  10120. (defun vhdl-template-wait-hook ()
  10121. (vhdl-hooked-abbrev 'vhdl-template-wait))
  10122. (defun vhdl-template-when-hook ()
  10123. (vhdl-hooked-abbrev 'vhdl-template-when))
  10124. (defun vhdl-template-while-loop-hook ()
  10125. (vhdl-hooked-abbrev 'vhdl-template-while-loop))
  10126. (defun vhdl-template-with-hook ()
  10127. (vhdl-hooked-abbrev 'vhdl-template-with))
  10128. (defun vhdl-template-and-hook ()
  10129. (vhdl-hooked-abbrev 'vhdl-template-and))
  10130. (defun vhdl-template-or-hook ()
  10131. (vhdl-hooked-abbrev 'vhdl-template-or))
  10132. (defun vhdl-template-nand-hook ()
  10133. (vhdl-hooked-abbrev 'vhdl-template-nand))
  10134. (defun vhdl-template-nor-hook ()
  10135. (vhdl-hooked-abbrev 'vhdl-template-nor))
  10136. (defun vhdl-template-xor-hook ()
  10137. (vhdl-hooked-abbrev 'vhdl-template-xor))
  10138. (defun vhdl-template-xnor-hook ()
  10139. (vhdl-hooked-abbrev 'vhdl-template-xnor))
  10140. (defun vhdl-template-not-hook ()
  10141. (vhdl-hooked-abbrev 'vhdl-template-not))
  10142. (defun vhdl-template-default-hook ()
  10143. (vhdl-hooked-abbrev 'vhdl-template-default))
  10144. (defun vhdl-template-default-indent-hook ()
  10145. (vhdl-hooked-abbrev 'vhdl-template-default-indent))
  10146. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10147. ;; Template insertion from completion list
  10148. (defun vhdl-template-insert-construct (name)
  10149. "Insert the built-in construct template with NAME."
  10150. (interactive
  10151. (list (let ((completion-ignore-case t))
  10152. (completing-read "Construct name: "
  10153. vhdl-template-construct-alist nil t))))
  10154. (vhdl-template-insert-fun
  10155. (cadr (assoc name vhdl-template-construct-alist))))
  10156. (defun vhdl-template-insert-package (name)
  10157. "Insert the built-in package template with NAME."
  10158. (interactive
  10159. (list (let ((completion-ignore-case t))
  10160. (completing-read "Package name: "
  10161. vhdl-template-package-alist nil t))))
  10162. (vhdl-template-insert-fun
  10163. (cadr (assoc name vhdl-template-package-alist))))
  10164. (defun vhdl-template-insert-directive (name)
  10165. "Insert the built-in directive template with NAME."
  10166. (interactive
  10167. (list (let ((completion-ignore-case t))
  10168. (completing-read "Directive name: "
  10169. vhdl-template-directive-alist nil t))))
  10170. (vhdl-template-insert-fun
  10171. (cadr (assoc name vhdl-template-directive-alist))))
  10172. (defun vhdl-template-insert-fun (fun)
  10173. "Call FUN to insert a built-in template."
  10174. (let ((caught (catch 'abort (when fun (funcall fun)))))
  10175. (when (stringp caught) (message "%s" caught))))
  10176. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10177. ;;; Models
  10178. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10179. (defun vhdl-model-insert (model-name)
  10180. "Insert the user model with name MODEL-NAME."
  10181. (interactive
  10182. (let ((completion-ignore-case t))
  10183. (list (completing-read "Model name: " vhdl-model-alist))))
  10184. (indent-according-to-mode)
  10185. (let ((start (point-marker))
  10186. (margin (current-indentation))
  10187. model position prompt string end)
  10188. (vhdl-prepare-search-2
  10189. (when (setq model (assoc model-name vhdl-model-alist))
  10190. ;; insert model
  10191. (beginning-of-line)
  10192. (delete-horizontal-space)
  10193. (goto-char start)
  10194. (vhdl-insert-string-or-file (nth 1 model))
  10195. (setq end (point-marker))
  10196. ;; indent code
  10197. (goto-char start)
  10198. (beginning-of-line)
  10199. (while (< (point) end)
  10200. (unless (looking-at "^$")
  10201. (insert-char ? margin))
  10202. (beginning-of-line 2))
  10203. (goto-char start)
  10204. ;; insert clock
  10205. (unless (equal "" vhdl-clock-name)
  10206. (while (re-search-forward "<clock>" end t)
  10207. (replace-match vhdl-clock-name)))
  10208. (goto-char start)
  10209. ;; insert reset
  10210. (unless (equal "" vhdl-reset-name)
  10211. (while (re-search-forward "<reset>" end t)
  10212. (replace-match vhdl-reset-name)))
  10213. ;; replace header prompts
  10214. (vhdl-template-replace-header-keywords start end nil t)
  10215. (goto-char start)
  10216. ;; query other prompts
  10217. (while (re-search-forward
  10218. (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
  10219. (unless (equal "cursor" (match-string 1))
  10220. (setq position (match-beginning 1))
  10221. (setq prompt (match-string 1))
  10222. (replace-match "")
  10223. (setq string (vhdl-template-field prompt nil t))
  10224. ;; replace occurrences of same prompt
  10225. (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
  10226. (replace-match (or string "")))
  10227. (goto-char position)))
  10228. (goto-char start)
  10229. ;; goto final position
  10230. (if (re-search-forward "<cursor>" end t)
  10231. (replace-match "")
  10232. (goto-char end))))))
  10233. (defun vhdl-model-defun ()
  10234. "Define help and hook functions for user models."
  10235. (let ((model-alist vhdl-model-alist)
  10236. model-name model-keyword)
  10237. (while model-alist
  10238. ;; define functions for user models that can be invoked from menu and key
  10239. ;; bindings and which themselves call `vhdl-model-insert' with the model
  10240. ;; name as argument
  10241. (setq model-name (nth 0 (car model-alist)))
  10242. (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
  10243. ,(concat "Insert model for \"" model-name "\".")
  10244. (interactive)
  10245. (vhdl-model-insert ,model-name)))
  10246. ;; define hooks for user models that are invoked from keyword abbrevs
  10247. (setq model-keyword (nth 3 (car model-alist)))
  10248. (unless (equal model-keyword "")
  10249. (eval `(defun
  10250. ,(vhdl-function-name
  10251. "vhdl-model" model-name "hook") ()
  10252. (vhdl-hooked-abbrev
  10253. ',(vhdl-function-name "vhdl-model" model-name)))))
  10254. (setq model-alist (cdr model-alist)))))
  10255. (vhdl-model-defun)
  10256. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10257. ;;; Port translation
  10258. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10259. (defvar vhdl-port-list nil
  10260. "Variable to hold last port map parsed.")
  10261. ;; structure: (parenthesized expression means list of such entries)
  10262. ;; (ent-name
  10263. ;; ((generic-names) generic-type generic-init generic-comment group-comment)
  10264. ;; ((port-names) port-object port-direct port-type port-comment group-comment)
  10265. ;; (lib-name pack-key))
  10266. (defun vhdl-parse-string (string &optional optional)
  10267. "Check that the text following point matches the regexp in STRING."
  10268. (if (looking-at string)
  10269. (progn (goto-char (match-end 0))
  10270. (when (vhdl-in-literal)
  10271. (end-of-line))
  10272. (point))
  10273. (unless optional
  10274. (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
  10275. (vhdl-current-line) string)))
  10276. nil))
  10277. (defun vhdl-replace-string (regexp-cons string &optional adjust-case)
  10278. "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
  10279. (vhdl-prepare-search-1
  10280. (if (string-match (car regexp-cons) string)
  10281. (if adjust-case
  10282. (funcall vhdl-file-name-case
  10283. (replace-match (cdr regexp-cons) t nil string))
  10284. (replace-match (cdr regexp-cons) t nil string))
  10285. string)))
  10286. (defun vhdl-parse-group-comment ()
  10287. "Parse comment and empty lines between groups of lines."
  10288. (let ((start (point))
  10289. string)
  10290. (vhdl-forward-comment (point-max))
  10291. (setq string (buffer-substring-no-properties start (point)))
  10292. (vhdl-forward-syntactic-ws)
  10293. ;; strip off leading blanks and first newline
  10294. (while (string-match "^\\(\\s-+\\)" string)
  10295. (setq string (concat (substring string 0 (match-beginning 1))
  10296. (substring string (match-end 1)))))
  10297. (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
  10298. (substring string 1)
  10299. string)))
  10300. (defun vhdl-paste-group-comment (string indent)
  10301. "Paste comment and empty lines from STRING between groups of lines
  10302. with INDENT."
  10303. (let ((pos (point-marker)))
  10304. (when (> indent 0)
  10305. (while (string-match "^\\(--\\)" string)
  10306. (setq string (concat (substring string 0 (match-beginning 1))
  10307. (make-string indent ? )
  10308. (substring string (match-beginning 1))))))
  10309. (beginning-of-line)
  10310. (insert string)
  10311. (goto-char pos)))
  10312. (defvar vhdl-port-flattened nil
  10313. "Indicates whether a port has been flattened.")
  10314. (defun vhdl-port-flatten (&optional as-alist)
  10315. "Flatten port list so that only one generic/port exists per line.
  10316. This operation is performed on an internally stored port and is only
  10317. reflected in a subsequent paste operation."
  10318. (interactive)
  10319. (if (not vhdl-port-list)
  10320. (error "ERROR: No port has been read")
  10321. (message "Flattening port for next paste...")
  10322. (let ((new-vhdl-port-list (list (car vhdl-port-list)))
  10323. (old-vhdl-port-list (cdr vhdl-port-list))
  10324. old-port-list new-port-list old-port new-port names)
  10325. ;; traverse port list and flatten entries
  10326. (while (cdr old-vhdl-port-list)
  10327. (setq old-port-list (car old-vhdl-port-list))
  10328. (setq new-port-list nil)
  10329. (while old-port-list
  10330. (setq old-port (car old-port-list))
  10331. (setq names (car old-port))
  10332. (while names
  10333. (setq new-port (cons (if as-alist (car names) (list (car names)))
  10334. (cdr old-port)))
  10335. (setq new-port-list (append new-port-list (list new-port)))
  10336. (setq names (cdr names)))
  10337. (setq old-port-list (cdr old-port-list)))
  10338. (setq old-vhdl-port-list (cdr old-vhdl-port-list))
  10339. (setq new-vhdl-port-list (append new-vhdl-port-list
  10340. (list new-port-list))))
  10341. (setq vhdl-port-list
  10342. (append new-vhdl-port-list (list old-vhdl-port-list))
  10343. vhdl-port-flattened t)
  10344. (message "Flattening port for next paste...done"))))
  10345. (defvar vhdl-port-reversed-direction nil
  10346. "Indicates whether port directions are reversed.")
  10347. (defun vhdl-port-reverse-direction ()
  10348. "Reverse direction for all ports (useful in testbenches).
  10349. This operation is performed on an internally stored port and is only
  10350. reflected in a subsequent paste operation."
  10351. (interactive)
  10352. (if (not vhdl-port-list)
  10353. (error "ERROR: No port has been read")
  10354. (message "Reversing port directions for next paste...")
  10355. (let ((port-list (nth 2 vhdl-port-list))
  10356. port-dir-car port-dir)
  10357. ;; traverse port list and reverse directions
  10358. (while port-list
  10359. (setq port-dir-car (cddr (car port-list))
  10360. port-dir (car port-dir-car))
  10361. (setcar port-dir-car
  10362. (cond ((equal port-dir "in") "out")
  10363. ((equal port-dir "IN") "OUT")
  10364. ((equal port-dir "out") "in")
  10365. ((equal port-dir "OUT") "IN")
  10366. (t port-dir)))
  10367. (setq port-list (cdr port-list)))
  10368. (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
  10369. (message "Reversing port directions for next paste...done"))))
  10370. (defun vhdl-port-copy ()
  10371. "Get generic and port information from an entity or component declaration."
  10372. (interactive)
  10373. (save-excursion
  10374. (let (parse-error end-of-list
  10375. decl-type name generic-list port-list context-clause
  10376. object names direct type init comment group-comment)
  10377. (vhdl-prepare-search-2
  10378. (setq
  10379. parse-error
  10380. (catch 'parse
  10381. ;; check if within entity or component declaration
  10382. (end-of-line)
  10383. (when (or (not (re-search-backward
  10384. "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
  10385. (equal "END" (upcase (match-string 1))))
  10386. (throw 'parse "ERROR: Not within an entity or component declaration"))
  10387. (setq decl-type (downcase (match-string-no-properties 1)))
  10388. (forward-word 1)
  10389. (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
  10390. (setq name (match-string-no-properties 1))
  10391. (message "Reading port of %s \"%s\"..." decl-type name)
  10392. (vhdl-forward-syntactic-ws)
  10393. ;; parse generic clause
  10394. (when (vhdl-parse-string "generic[ \t\n\r\f]*(" t)
  10395. ;; parse group comment and spacing
  10396. (setq group-comment (vhdl-parse-group-comment))
  10397. (setq end-of-list (vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t))
  10398. (while (not end-of-list)
  10399. ;; parse names (accept extended identifiers)
  10400. (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
  10401. (setq names (list (match-string-no-properties 1)))
  10402. (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
  10403. (setq names
  10404. (append names (list (match-string-no-properties 1)))))
  10405. ;; parse type
  10406. (vhdl-parse-string ":[ \t\n\r\f]*\\([^():;\n]+\\)")
  10407. (setq type (match-string-no-properties 1))
  10408. (when (vhdl-in-comment-p) ; if stuck in comment
  10409. (setq type (concat type (and (vhdl-parse-string ".*")
  10410. (match-string-no-properties 0)))))
  10411. (setq comment nil)
  10412. (while (looking-at "(")
  10413. (setq type
  10414. (concat type
  10415. (buffer-substring-no-properties
  10416. (point) (progn (forward-sexp) (point)))
  10417. (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
  10418. (match-string-no-properties 1)))))
  10419. ;; special case: closing parenthesis is on separate line
  10420. (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
  10421. (setq comment (substring type (match-beginning 2)))
  10422. (setq type (substring type 0 (match-beginning 1))))
  10423. ;; strip of trailing group-comment
  10424. (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
  10425. (setq type (substring type 0 (match-end 1)))
  10426. ;; parse initialization expression
  10427. (setq init nil)
  10428. (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
  10429. (vhdl-parse-string "\\([^();\n]*\\)")
  10430. (setq init (match-string-no-properties 1))
  10431. (while (looking-at "(")
  10432. (setq init
  10433. (concat init
  10434. (buffer-substring-no-properties
  10435. (point) (progn (forward-sexp) (point)))
  10436. (and (vhdl-parse-string "\\([^();\n]*\\)" t)
  10437. (match-string-no-properties 1))))))
  10438. ;; special case: closing parenthesis is on separate line
  10439. (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
  10440. (setq comment (substring init (match-beginning 2)))
  10441. (setq init (substring init 0 (match-beginning 1)))
  10442. (vhdl-forward-syntactic-ws))
  10443. (skip-chars-forward " \t")
  10444. ;; parse inline comment, special case: as above, no initial.
  10445. (unless comment
  10446. (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
  10447. (match-string-no-properties 1))))
  10448. (vhdl-forward-syntactic-ws)
  10449. (setq end-of-list (vhdl-parse-string ")" t))
  10450. (vhdl-parse-string "\\s-*;\\s-*")
  10451. ;; parse inline comment
  10452. (unless comment
  10453. (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
  10454. (match-string-no-properties 1))))
  10455. ;; save everything in list
  10456. (setq generic-list (append generic-list
  10457. (list (list names type init
  10458. comment group-comment))))
  10459. ;; parse group comment and spacing
  10460. (setq group-comment (vhdl-parse-group-comment))))
  10461. ;; parse port clause
  10462. (when (vhdl-parse-string "port[ \t\n\r\f]*(" t)
  10463. ;; parse group comment and spacing
  10464. (setq group-comment (vhdl-parse-group-comment))
  10465. (setq end-of-list (vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t))
  10466. (while (not end-of-list)
  10467. ;; parse object
  10468. (setq object
  10469. (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n\r\f]*" t)
  10470. (match-string-no-properties 1)))
  10471. ;; parse names (accept extended identifiers)
  10472. (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
  10473. (setq names (list (match-string-no-properties 1)))
  10474. (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
  10475. (setq names (append names (list (match-string-no-properties 1)))))
  10476. ;; parse direction
  10477. (vhdl-parse-string ":[ \t\n\r\f]*")
  10478. (setq direct
  10479. (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n\r\f]+" t)
  10480. (match-string-no-properties 1)))
  10481. ;; parse type
  10482. (vhdl-parse-string "\\([^();\n]+\\)")
  10483. (setq type (match-string-no-properties 1))
  10484. (when (vhdl-in-comment-p) ; if stuck in comment
  10485. (setq type (concat type (and (vhdl-parse-string ".*")
  10486. (match-string-no-properties 0)))))
  10487. (setq comment nil)
  10488. (while (looking-at "(")
  10489. (setq type (concat type
  10490. (buffer-substring-no-properties
  10491. (point) (progn (forward-sexp) (point)))
  10492. (and (vhdl-parse-string "\\([^();\n]*\\)" t)
  10493. (match-string-no-properties 1)))))
  10494. ;; special case: closing parenthesis is on separate line
  10495. (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
  10496. (setq comment (substring type (match-beginning 2)))
  10497. (setq type (substring type 0 (match-beginning 1))))
  10498. ;; strip of trailing group-comment
  10499. (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
  10500. (setq type (substring type 0 (match-end 1)))
  10501. (vhdl-forward-syntactic-ws)
  10502. (setq end-of-list (vhdl-parse-string ")" t))
  10503. (vhdl-parse-string "\\s-*;\\s-*")
  10504. ;; parse inline comment
  10505. (unless comment
  10506. (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
  10507. (match-string-no-properties 1))))
  10508. ;; save everything in list
  10509. (setq port-list (append port-list
  10510. (list (list names object direct type
  10511. comment group-comment))))
  10512. ;; parse group comment and spacing
  10513. (setq group-comment (vhdl-parse-group-comment))))
  10514. ; (vhdl-parse-string "end\\>")
  10515. ;; parse context clause
  10516. (setq context-clause (vhdl-scan-context-clause))
  10517. ; ;; add surrounding package to context clause
  10518. ; (when (and (equal decl-type "component")
  10519. ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
  10520. ; (setq context-clause
  10521. ; (append context-clause
  10522. ; (list (cons (vhdl-work-library)
  10523. ; (match-string-no-properties 1))))))
  10524. (message "Reading port of %s \"%s\"...done" decl-type name)
  10525. nil)))
  10526. ;; finish parsing
  10527. (if parse-error
  10528. (error parse-error)
  10529. (setq vhdl-port-list (list name generic-list port-list context-clause)
  10530. vhdl-port-reversed-direction nil
  10531. vhdl-port-flattened nil)))))
  10532. (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
  10533. "Paste a context clause."
  10534. (let ((margin (current-indentation))
  10535. (clause-list (nth 3 vhdl-port-list))
  10536. clause)
  10537. (while clause-list
  10538. (setq clause (car clause-list))
  10539. (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
  10540. (downcase exclude-pack-name)))
  10541. (save-excursion
  10542. (re-search-backward
  10543. (concat "^\\s-*use\\s-+" (car clause)
  10544. "\." (cdr clause) "\\>") nil t)))
  10545. (vhdl-template-standard-package (car clause) (cdr clause))
  10546. (insert "\n"))
  10547. (setq clause-list (cdr clause-list)))))
  10548. (defun vhdl-port-paste-generic (&optional no-init)
  10549. "Paste a generic clause."
  10550. (let ((margin (current-indentation))
  10551. (generic-list (nth 1 vhdl-port-list))
  10552. list-margin start names generic)
  10553. ;; paste generic clause
  10554. (when generic-list
  10555. (setq start (point))
  10556. (vhdl-insert-keyword "GENERIC (")
  10557. (unless vhdl-argument-list-indent
  10558. (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
  10559. (setq list-margin (current-column))
  10560. (while generic-list
  10561. (setq generic (car generic-list))
  10562. ;; paste group comment and spacing
  10563. (when (memq vhdl-include-group-comments '(decl always))
  10564. (vhdl-paste-group-comment (nth 4 generic) list-margin))
  10565. ;; paste names
  10566. (setq names (nth 0 generic))
  10567. (while names
  10568. (insert (car names))
  10569. (setq names (cdr names))
  10570. (when names (insert ", ")))
  10571. ;; paste type
  10572. (insert " : " (nth 1 generic))
  10573. ;; paste initialization
  10574. (when (and (not no-init) (nth 2 generic))
  10575. (insert " := " (nth 2 generic)))
  10576. (unless (cdr generic-list) (insert ")"))
  10577. (insert ";")
  10578. ;; paste comment
  10579. (when (and vhdl-include-port-comments (nth 3 generic))
  10580. (vhdl-comment-insert-inline (nth 3 generic) t))
  10581. (setq generic-list (cdr generic-list))
  10582. (when generic-list (insert "\n") (indent-to list-margin)))
  10583. ;; align generic clause
  10584. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
  10585. (defun vhdl-port-paste-port ()
  10586. "Paste a port clause."
  10587. (let ((margin (current-indentation))
  10588. (port-list (nth 2 vhdl-port-list))
  10589. list-margin start names port)
  10590. ;; paste port clause
  10591. (when port-list
  10592. (setq start (point))
  10593. (vhdl-insert-keyword "PORT (")
  10594. (unless vhdl-argument-list-indent
  10595. (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
  10596. (setq list-margin (current-column))
  10597. (while port-list
  10598. (setq port (car port-list))
  10599. ;; paste group comment and spacing
  10600. (when (memq vhdl-include-group-comments '(decl always))
  10601. (vhdl-paste-group-comment (nth 5 port) list-margin))
  10602. ;; paste object
  10603. (when (nth 1 port) (insert (nth 1 port) " "))
  10604. ;; paste names
  10605. (setq names (nth 0 port))
  10606. (while names
  10607. (insert (car names))
  10608. (setq names (cdr names))
  10609. (when names (insert ", ")))
  10610. ;; paste direction
  10611. (insert " : ")
  10612. (when (nth 2 port) (insert (nth 2 port) " "))
  10613. ;; paste type
  10614. (insert (nth 3 port))
  10615. (unless (cdr port-list) (insert ")"))
  10616. (insert ";")
  10617. ;; paste comment
  10618. (when (and vhdl-include-port-comments (nth 4 port))
  10619. (vhdl-comment-insert-inline (nth 4 port) t))
  10620. (setq port-list (cdr port-list))
  10621. (when port-list (insert "\n") (indent-to list-margin)))
  10622. ;; align port clause
  10623. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
  10624. (defun vhdl-port-paste-declaration (kind &optional no-indent)
  10625. "Paste as an entity or component declaration."
  10626. (unless no-indent (indent-according-to-mode))
  10627. (let ((margin (current-indentation))
  10628. (name (nth 0 vhdl-port-list)))
  10629. (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
  10630. (insert name)
  10631. (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
  10632. (vhdl-insert-keyword " IS"))
  10633. ;; paste generic and port clause
  10634. (when (nth 1 vhdl-port-list)
  10635. (insert "\n")
  10636. (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
  10637. (insert "\n"))
  10638. (indent-to (+ margin vhdl-basic-offset))
  10639. (vhdl-port-paste-generic (eq kind 'component)))
  10640. (when (nth 2 vhdl-port-list)
  10641. (insert "\n")
  10642. (when (and (memq vhdl-insert-empty-lines '(unit all))
  10643. (eq kind 'entity))
  10644. (insert "\n"))
  10645. (indent-to (+ margin vhdl-basic-offset)))
  10646. (vhdl-port-paste-port)
  10647. (insert "\n")
  10648. (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
  10649. (insert "\n"))
  10650. (indent-to margin)
  10651. (vhdl-insert-keyword "END")
  10652. (if (eq kind 'entity)
  10653. (progn
  10654. (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
  10655. (insert " " name))
  10656. (vhdl-insert-keyword " COMPONENT")
  10657. (unless (vhdl-standard-p '87) (insert " " name)))
  10658. (insert ";")))
  10659. (defun vhdl-port-paste-entity (&optional no-indent)
  10660. "Paste as an entity declaration."
  10661. (interactive)
  10662. (if (not vhdl-port-list)
  10663. (error "ERROR: No port read")
  10664. (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
  10665. (vhdl-port-paste-declaration 'entity no-indent)
  10666. (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
  10667. (defun vhdl-port-paste-component (&optional no-indent)
  10668. "Paste as a component declaration."
  10669. (interactive)
  10670. (if (not vhdl-port-list)
  10671. (error "ERROR: No port read")
  10672. (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
  10673. (vhdl-port-paste-declaration 'component no-indent)
  10674. (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
  10675. (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
  10676. "Paste as a generic map."
  10677. (interactive)
  10678. (unless secondary (indent-according-to-mode))
  10679. (let ((margin (current-indentation))
  10680. list-margin start generic
  10681. (generic-list (nth 1 vhdl-port-list)))
  10682. (when generic-list
  10683. (setq start (point))
  10684. (vhdl-insert-keyword "GENERIC MAP (")
  10685. (if (not vhdl-association-list-with-formals)
  10686. ;; paste list of actual generics
  10687. (while generic-list
  10688. (insert (if no-constants
  10689. (car (nth 0 (car generic-list)))
  10690. (or (nth 2 (car generic-list)) " ")))
  10691. (setq generic-list (cdr generic-list))
  10692. (insert (if generic-list ", " ")"))
  10693. (when (and (not generic-list) secondary
  10694. (null (nth 2 vhdl-port-list)))
  10695. (insert ";")))
  10696. (unless vhdl-argument-list-indent
  10697. (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
  10698. (setq list-margin (current-column))
  10699. (while generic-list
  10700. (setq generic (car generic-list))
  10701. ;; paste group comment and spacing
  10702. (when (eq vhdl-include-group-comments 'always)
  10703. (vhdl-paste-group-comment (nth 4 generic) list-margin))
  10704. ;; paste formal and actual generic
  10705. (insert (car (nth 0 generic)) " => "
  10706. (if no-constants
  10707. (car (nth 0 generic))
  10708. (or (nth 2 generic) "")))
  10709. (setq generic-list (cdr generic-list))
  10710. (insert (if generic-list "," ")"))
  10711. (when (and (not generic-list) secondary
  10712. (null (nth 2 vhdl-port-list)))
  10713. (insert ";"))
  10714. ;; paste comment
  10715. (when (or vhdl-include-type-comments
  10716. (and vhdl-include-port-comments (nth 3 generic)))
  10717. (vhdl-comment-insert-inline
  10718. (concat
  10719. (when vhdl-include-type-comments
  10720. (concat "[" (nth 1 generic) "] "))
  10721. (when vhdl-include-port-comments (nth 3 generic))) t))
  10722. (when generic-list (insert "\n") (indent-to list-margin)))
  10723. ;; align generic map
  10724. (when vhdl-auto-align
  10725. (vhdl-align-region-groups start (point) 1 t))))))
  10726. (defun vhdl-port-paste-port-map ()
  10727. "Paste as a port map."
  10728. (let ((margin (current-indentation))
  10729. list-margin start port
  10730. (port-list (nth 2 vhdl-port-list)))
  10731. (when port-list
  10732. (setq start (point))
  10733. (vhdl-insert-keyword "PORT MAP (")
  10734. (if (not vhdl-association-list-with-formals)
  10735. ;; paste list of actual ports
  10736. (while port-list
  10737. (insert (vhdl-replace-string vhdl-actual-port-name
  10738. (car (nth 0 (car port-list)))))
  10739. (setq port-list (cdr port-list))
  10740. (insert (if port-list ", " ")")))
  10741. (unless vhdl-argument-list-indent
  10742. (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
  10743. (setq list-margin (current-column))
  10744. (while port-list
  10745. (setq port (car port-list))
  10746. ;; paste group comment and spacing
  10747. (when (eq vhdl-include-group-comments 'always)
  10748. (vhdl-paste-group-comment (nth 5 port) list-margin))
  10749. ;; paste formal and actual port
  10750. (insert (car (nth 0 port)) " => ")
  10751. (insert (vhdl-replace-string vhdl-actual-port-name
  10752. (car (nth 0 port))))
  10753. (setq port-list (cdr port-list))
  10754. (insert (if port-list "," ");"))
  10755. ;; paste comment
  10756. (when (or (and vhdl-include-direction-comments (nth 2 port))
  10757. vhdl-include-type-comments
  10758. (and vhdl-include-port-comments (nth 4 port)))
  10759. (vhdl-comment-insert-inline
  10760. (concat
  10761. (cond ((and vhdl-include-direction-comments
  10762. vhdl-include-type-comments)
  10763. (concat "[" (format "%-4s" (concat (nth 2 port) " "))
  10764. (nth 3 port) "] "))
  10765. ((and vhdl-include-direction-comments (nth 2 port))
  10766. (format "%-6s" (concat "[" (nth 2 port) "] ")))
  10767. (vhdl-include-direction-comments " ")
  10768. (vhdl-include-type-comments
  10769. (concat "[" (nth 3 port) "] ")))
  10770. (when vhdl-include-port-comments (nth 4 port))) t))
  10771. (when port-list (insert "\n") (indent-to list-margin)))
  10772. ;; align port clause
  10773. (when vhdl-auto-align
  10774. (vhdl-align-region-groups start (point) 1))))))
  10775. (defun vhdl-port-paste-instance (&optional name no-indent title)
  10776. "Paste as an instantiation."
  10777. (interactive)
  10778. (if (not vhdl-port-list)
  10779. (error "ERROR: No port read")
  10780. (let ((orig-vhdl-port-list vhdl-port-list))
  10781. ;; flatten local copy of port list (must be flat for port mapping)
  10782. (vhdl-port-flatten)
  10783. (unless no-indent (indent-according-to-mode))
  10784. (let ((margin (current-indentation)))
  10785. ;; paste instantiation
  10786. (cond (name
  10787. (insert name))
  10788. ((equal (cdr vhdl-instance-name) "")
  10789. (setq name (vhdl-template-field "instance name")))
  10790. ((string-match "\%d" (cdr vhdl-instance-name))
  10791. (let ((n 1))
  10792. (while (save-excursion
  10793. (setq name (format (vhdl-replace-string
  10794. vhdl-instance-name
  10795. (nth 0 vhdl-port-list)) n))
  10796. (goto-char (point-min))
  10797. (vhdl-re-search-forward name nil t))
  10798. (setq n (1+ n)))
  10799. (insert name)))
  10800. (t (insert (vhdl-replace-string vhdl-instance-name
  10801. (nth 0 vhdl-port-list)))))
  10802. (message "Pasting port as instantiation \"%s\"..." name)
  10803. (insert ": ")
  10804. (when title
  10805. (save-excursion
  10806. (beginning-of-line)
  10807. (indent-to vhdl-basic-offset)
  10808. (insert "-- instance \"" name "\"\n")))
  10809. (if (not (vhdl-use-direct-instantiation))
  10810. (insert (nth 0 vhdl-port-list))
  10811. (vhdl-insert-keyword "ENTITY ")
  10812. (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
  10813. (when (nth 1 vhdl-port-list)
  10814. (insert "\n") (indent-to (+ margin vhdl-basic-offset))
  10815. (vhdl-port-paste-generic-map t t))
  10816. (when (nth 2 vhdl-port-list)
  10817. (insert "\n") (indent-to (+ margin vhdl-basic-offset))
  10818. (vhdl-port-paste-port-map))
  10819. (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
  10820. (insert ";"))
  10821. (message "Pasting port as instantiation \"%s\"...done" name))
  10822. (setq vhdl-port-list orig-vhdl-port-list))))
  10823. (defun vhdl-port-paste-constants (&optional no-indent)
  10824. "Paste generics as constants."
  10825. (interactive)
  10826. (if (not vhdl-port-list)
  10827. (error "ERROR: No port read")
  10828. (let ((orig-vhdl-port-list vhdl-port-list))
  10829. (message "Pasting port as constants...")
  10830. ;; flatten local copy of port list (must be flat for constant initial.)
  10831. (vhdl-port-flatten)
  10832. (unless no-indent (indent-according-to-mode))
  10833. (let ((margin (current-indentation))
  10834. start generic name
  10835. (generic-list (nth 1 vhdl-port-list)))
  10836. (when generic-list
  10837. (setq start (point))
  10838. (while generic-list
  10839. (setq generic (car generic-list))
  10840. ;; paste group comment and spacing
  10841. (when (memq vhdl-include-group-comments '(decl always))
  10842. (vhdl-paste-group-comment (nth 4 generic) margin))
  10843. (vhdl-insert-keyword "CONSTANT ")
  10844. ;; paste generic constants
  10845. (setq name (nth 0 generic))
  10846. (when name
  10847. (insert (car name))
  10848. ;; paste type
  10849. (insert " : " (nth 1 generic))
  10850. ;; paste initialization
  10851. (when (nth 2 generic)
  10852. (insert " := " (nth 2 generic)))
  10853. (insert ";")
  10854. ;; paste comment
  10855. (when (and vhdl-include-port-comments (nth 3 generic))
  10856. (vhdl-comment-insert-inline (nth 3 generic) t))
  10857. (setq generic-list (cdr generic-list))
  10858. (when generic-list (insert "\n") (indent-to margin))))
  10859. ;; align signal list
  10860. (when vhdl-auto-align
  10861. (vhdl-align-region-groups start (point) 1))))
  10862. (message "Pasting port as constants...done")
  10863. (setq vhdl-port-list orig-vhdl-port-list))))
  10864. (defun vhdl-port-paste-signals (&optional initialize no-indent)
  10865. "Paste ports as internal signals."
  10866. (interactive)
  10867. (if (not vhdl-port-list)
  10868. (error "ERROR: No port read")
  10869. (message "Pasting port as signals...")
  10870. (unless no-indent (indent-according-to-mode))
  10871. (let ((margin (current-indentation))
  10872. start port names
  10873. (port-list (nth 2 vhdl-port-list)))
  10874. (when port-list
  10875. (setq start (point))
  10876. (while port-list
  10877. (setq port (car port-list))
  10878. ;; paste group comment and spacing
  10879. (when (memq vhdl-include-group-comments '(decl always))
  10880. (vhdl-paste-group-comment (nth 5 port) margin))
  10881. ;; paste object
  10882. (if (nth 1 port)
  10883. (insert (nth 1 port) " ")
  10884. (vhdl-insert-keyword "SIGNAL "))
  10885. ;; paste actual port signals
  10886. (setq names (nth 0 port))
  10887. (while names
  10888. (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
  10889. (setq names (cdr names))
  10890. (when names (insert ", ")))
  10891. ;; paste type
  10892. (insert " : " (nth 3 port))
  10893. ;; paste initialization (inputs only)
  10894. (when (and initialize (nth 2 port) (equal "IN" (upcase (nth 2 port))))
  10895. (insert " := "
  10896. (cond ((string-match "integer" (nth 3 port)) "0")
  10897. ((string-match "natural" (nth 3 port)) "0")
  10898. ((string-match "positive" (nth 3 port)) "0")
  10899. ((string-match "real" (nth 3 port)) "0.0")
  10900. ((string-match "(.+)" (nth 3 port)) "(others => '0')")
  10901. (t "'0'"))))
  10902. (insert ";")
  10903. ;; paste comment
  10904. (when (or (and vhdl-include-direction-comments (nth 2 port))
  10905. (and vhdl-include-port-comments (nth 4 port)))
  10906. (vhdl-comment-insert-inline
  10907. (concat
  10908. (cond ((and vhdl-include-direction-comments (nth 2 port))
  10909. (format "%-6s" (concat "[" (nth 2 port) "] ")))
  10910. (vhdl-include-direction-comments " "))
  10911. (when vhdl-include-port-comments (nth 4 port))) t))
  10912. (setq port-list (cdr port-list))
  10913. (when port-list (insert "\n") (indent-to margin)))
  10914. ;; align signal list
  10915. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
  10916. (message "Pasting port as signals...done")))
  10917. (defun vhdl-port-paste-initializations (&optional no-indent)
  10918. "Paste ports as signal initializations."
  10919. (interactive)
  10920. (if (not vhdl-port-list)
  10921. (error "ERROR: No port read")
  10922. (let ((orig-vhdl-port-list vhdl-port-list))
  10923. (message "Pasting port as initializations...")
  10924. ;; flatten local copy of port list (must be flat for signal initial.)
  10925. (vhdl-port-flatten)
  10926. (unless no-indent (indent-according-to-mode))
  10927. (let ((margin (current-indentation))
  10928. start port name
  10929. (port-list (nth 2 vhdl-port-list)))
  10930. (when port-list
  10931. (setq start (point))
  10932. (while port-list
  10933. (setq port (car port-list))
  10934. ;; paste actual port signal (inputs only)
  10935. (when (equal "IN" (upcase (nth 2 port)))
  10936. (setq name (car (nth 0 port)))
  10937. (insert (vhdl-replace-string vhdl-actual-port-name name))
  10938. ;; paste initialization
  10939. (insert " <= "
  10940. (cond ((string-match "integer" (nth 3 port)) "0")
  10941. ((string-match "natural" (nth 3 port)) "0")
  10942. ((string-match "positive" (nth 3 port)) "0")
  10943. ((string-match "real" (nth 3 port)) "0.0")
  10944. ((string-match "(.+)" (nth 3 port)) "(others => '0')")
  10945. (t "'0'"))
  10946. ";"))
  10947. (setq port-list (cdr port-list))
  10948. (when (and port-list
  10949. (equal "IN" (upcase (nth 2 (car port-list)))))
  10950. (insert "\n") (indent-to margin)))
  10951. ;; align signal list
  10952. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
  10953. (message "Pasting port as initializations...done")
  10954. (setq vhdl-port-list orig-vhdl-port-list))))
  10955. (defun vhdl-port-paste-testbench ()
  10956. "Paste as a bare-bones testbench."
  10957. (interactive)
  10958. (if (not vhdl-port-list)
  10959. (error "ERROR: No port read")
  10960. (let ((case-fold-search t)
  10961. (ent-name (vhdl-replace-string vhdl-testbench-entity-name
  10962. (nth 0 vhdl-port-list)))
  10963. (source-buffer (current-buffer))
  10964. arch-name config-name ent-file-name arch-file-name
  10965. ent-buffer arch-buffer position)
  10966. ;; open entity file
  10967. (unless (eq vhdl-testbench-create-files 'none)
  10968. (setq ent-file-name
  10969. (concat (vhdl-replace-string vhdl-testbench-entity-file-name
  10970. ent-name t)
  10971. "." (file-name-extension (buffer-file-name))))
  10972. (if (file-exists-p ent-file-name)
  10973. (if (y-or-n-p
  10974. (concat "File \"" ent-file-name "\" exists; overwrite? "))
  10975. (progn (find-file ent-file-name)
  10976. (erase-buffer)
  10977. (set-buffer-modified-p nil))
  10978. (if (eq vhdl-testbench-create-files 'separate)
  10979. (setq ent-file-name nil)
  10980. (error "ERROR: Pasting port as testbench...aborted")))
  10981. (find-file ent-file-name)))
  10982. (unless (and (eq vhdl-testbench-create-files 'separate)
  10983. (null ent-file-name))
  10984. ;; paste entity header
  10985. (if vhdl-testbench-include-header
  10986. (progn (vhdl-template-header
  10987. (concat "Testbench for design \""
  10988. (nth 0 vhdl-port-list) "\""))
  10989. (goto-char (point-max)))
  10990. (vhdl-comment-display-line) (insert "\n\n"))
  10991. ;; paste std_logic_1164 package
  10992. (when vhdl-testbench-include-library
  10993. (vhdl-template-package-std-logic-1164)
  10994. (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
  10995. ;; paste entity declaration
  10996. (vhdl-insert-keyword "ENTITY ")
  10997. (insert ent-name)
  10998. (vhdl-insert-keyword " IS")
  10999. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  11000. (insert "\n")
  11001. (vhdl-insert-keyword "END ")
  11002. (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
  11003. (insert ent-name ";")
  11004. (insert "\n\n")
  11005. (vhdl-comment-display-line) (insert "\n"))
  11006. ;; get architecture name
  11007. (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
  11008. (read-from-minibuffer "architecture name: "
  11009. nil vhdl-minibuffer-local-map)
  11010. (vhdl-replace-string vhdl-testbench-architecture-name
  11011. (nth 0 vhdl-port-list))))
  11012. (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
  11013. ;; open architecture file
  11014. (if (not (eq vhdl-testbench-create-files 'separate))
  11015. (insert "\n")
  11016. (setq ent-buffer (current-buffer))
  11017. (setq arch-file-name
  11018. (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
  11019. (concat ent-name " " arch-name) t)
  11020. "." (file-name-extension (buffer-file-name))))
  11021. (when (and (file-exists-p arch-file-name)
  11022. (not (y-or-n-p (concat "File \"" arch-file-name
  11023. "\" exists; overwrite? "))))
  11024. (error "ERROR: Pasting port as testbench...aborted"))
  11025. (find-file arch-file-name)
  11026. (erase-buffer)
  11027. (set-buffer-modified-p nil)
  11028. ;; paste architecture header
  11029. (if vhdl-testbench-include-header
  11030. (progn (vhdl-template-header
  11031. (concat "Testbench architecture for design \""
  11032. (nth 0 vhdl-port-list) "\""))
  11033. (goto-char (point-max)))
  11034. (vhdl-comment-display-line) (insert "\n\n")))
  11035. ;; paste architecture body
  11036. (vhdl-insert-keyword "ARCHITECTURE ")
  11037. (insert arch-name)
  11038. (vhdl-insert-keyword " OF ")
  11039. (insert ent-name)
  11040. (vhdl-insert-keyword " IS")
  11041. (insert "\n\n") (indent-to vhdl-basic-offset)
  11042. ;; paste component declaration
  11043. (unless (vhdl-use-direct-instantiation)
  11044. (vhdl-port-paste-component t)
  11045. (insert "\n\n") (indent-to vhdl-basic-offset))
  11046. ;; paste constants
  11047. (when (nth 1 vhdl-port-list)
  11048. (insert "-- component generics\n") (indent-to vhdl-basic-offset)
  11049. (vhdl-port-paste-constants t)
  11050. (insert "\n\n") (indent-to vhdl-basic-offset))
  11051. ;; paste internal signals
  11052. (insert "-- component ports\n") (indent-to vhdl-basic-offset)
  11053. (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
  11054. (insert "\n")
  11055. ;; paste custom declarations
  11056. (unless (equal "" vhdl-testbench-declarations)
  11057. (insert "\n")
  11058. (setq position (point))
  11059. (vhdl-insert-string-or-file vhdl-testbench-declarations)
  11060. (vhdl-indent-region position (point)))
  11061. (setq position (point))
  11062. (insert "\n\n")
  11063. (vhdl-comment-display-line) (insert "\n")
  11064. (when vhdl-testbench-include-configuration
  11065. (setq config-name (vhdl-replace-string
  11066. vhdl-testbench-configuration-name
  11067. (concat ent-name " " arch-name)))
  11068. (insert "\n")
  11069. (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
  11070. (vhdl-insert-keyword " OF ") (insert ent-name)
  11071. (vhdl-insert-keyword " IS\n")
  11072. (indent-to vhdl-basic-offset)
  11073. (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
  11074. (indent-to vhdl-basic-offset)
  11075. (vhdl-insert-keyword "END FOR;\n")
  11076. (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
  11077. (vhdl-comment-display-line) (insert "\n"))
  11078. (goto-char position)
  11079. (vhdl-template-begin-end
  11080. (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
  11081. ;; paste instantiation
  11082. (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
  11083. (vhdl-port-paste-instance
  11084. (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
  11085. (insert "\n")
  11086. ;; paste custom statements
  11087. (unless (equal "" vhdl-testbench-statements)
  11088. (insert "\n")
  11089. (setq position (point))
  11090. (vhdl-insert-string-or-file vhdl-testbench-statements)
  11091. (vhdl-indent-region position (point)))
  11092. (insert "\n")
  11093. (indent-to vhdl-basic-offset)
  11094. (unless (eq vhdl-testbench-create-files 'none)
  11095. (setq arch-buffer (current-buffer))
  11096. (when ent-buffer (set-buffer ent-buffer) (save-buffer))
  11097. (set-buffer arch-buffer) (save-buffer))
  11098. (message "%s"
  11099. (concat (format "Pasting port as testbench \"%s(%s)\"...done"
  11100. ent-name arch-name)
  11101. (and ent-file-name
  11102. (format "\n File created: \"%s\"" ent-file-name))
  11103. (and arch-file-name
  11104. (format "\n File created: \"%s\"" arch-file-name)))))))
  11105. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11106. ;;; Subprogram interface translation
  11107. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11108. (defvar vhdl-subprog-list nil
  11109. "Variable to hold last subprogram interface parsed.")
  11110. ;; structure: (parenthesized expression means list of such entries)
  11111. ;; (subprog-name kind
  11112. ;; ((names) object direct type init comment group-comment)
  11113. ;; return-type return-comment group-comment)
  11114. (defvar vhdl-subprog-flattened nil
  11115. "Indicates whether an subprogram interface has been flattened.")
  11116. (defun vhdl-subprog-flatten ()
  11117. "Flatten interface list so that only one parameter exists per line."
  11118. (interactive)
  11119. (if (not vhdl-subprog-list)
  11120. (error "ERROR: No subprogram interface has been read")
  11121. (message "Flattening subprogram interface...")
  11122. (let ((old-subprog-list (nth 2 vhdl-subprog-list))
  11123. new-subprog-list old-subprog new-subprog names)
  11124. ;; traverse parameter list and flatten entries
  11125. (while old-subprog-list
  11126. (setq old-subprog (car old-subprog-list))
  11127. (setq names (car old-subprog))
  11128. (while names
  11129. (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
  11130. (setq new-subprog-list (append new-subprog-list (list new-subprog)))
  11131. (setq names (cdr names)))
  11132. (setq old-subprog-list (cdr old-subprog-list)))
  11133. (setq vhdl-subprog-list
  11134. (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
  11135. new-subprog-list (nth 3 vhdl-subprog-list)
  11136. (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
  11137. vhdl-subprog-flattened t)
  11138. (message "Flattening subprogram interface...done"))))
  11139. (defun vhdl-subprog-copy ()
  11140. "Get interface information from a subprogram specification."
  11141. (interactive)
  11142. (save-excursion
  11143. (let (parse-error pos end-of-list
  11144. name kind param-list object names direct type init
  11145. comment group-comment
  11146. return-type return-comment return-group-comment)
  11147. (vhdl-prepare-search-2
  11148. (setq
  11149. parse-error
  11150. (catch 'parse
  11151. ;; check if within function declaration
  11152. (setq pos (point))
  11153. (end-of-line)
  11154. (when (looking-at "[ \t\n\r\f]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
  11155. (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n\r\f]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
  11156. (goto-char (match-end 0))
  11157. (save-excursion (backward-char)
  11158. (forward-sexp)
  11159. (<= pos (point))))
  11160. (throw 'parse "ERROR: Not within a subprogram specification"))
  11161. (setq name (match-string-no-properties 5))
  11162. (setq kind (if (match-string 2) 'procedure 'function))
  11163. (setq end-of-list (not (match-string 7)))
  11164. (message "Reading interface of subprogram \"%s\"..." name)
  11165. ;; parse parameter list
  11166. (setq group-comment (vhdl-parse-group-comment))
  11167. (setq end-of-list (or end-of-list
  11168. (vhdl-parse-string ")[ \t\n\r\f]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
  11169. (while (not end-of-list)
  11170. ;; parse object
  11171. (setq object
  11172. (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n\r\f]*" t)
  11173. (match-string-no-properties 1)))
  11174. ;; parse names (accept extended identifiers)
  11175. (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
  11176. (setq names (list (match-string-no-properties 1)))
  11177. (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
  11178. (setq names (append names (list (match-string-no-properties 1)))))
  11179. ;; parse direction
  11180. (vhdl-parse-string ":[ \t\n\r\f]*")
  11181. (setq direct
  11182. (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n\r\f]+" t)
  11183. (match-string-no-properties 1)))
  11184. ;; parse type
  11185. (vhdl-parse-string "\\([^():;\n]+\\)")
  11186. (setq type (match-string-no-properties 1))
  11187. (setq comment nil)
  11188. (while (looking-at "(")
  11189. (setq type
  11190. (concat type
  11191. (buffer-substring-no-properties
  11192. (point) (progn (forward-sexp) (point)))
  11193. (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
  11194. (match-string-no-properties 1)))))
  11195. ;; special case: closing parenthesis is on separate line
  11196. (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
  11197. (setq comment (substring type (match-beginning 2)))
  11198. (setq type (substring type 0 (match-beginning 1))))
  11199. ;; strip off trailing group-comment
  11200. (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
  11201. (setq type (substring type 0 (match-end 1)))
  11202. ;; parse initialization expression
  11203. (setq init nil)
  11204. (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
  11205. (vhdl-parse-string "\\([^();\n]*\\)")
  11206. (setq init (match-string-no-properties 1))
  11207. (while (looking-at "(")
  11208. (setq init
  11209. (concat init
  11210. (buffer-substring-no-properties
  11211. (point) (progn (forward-sexp) (point)))
  11212. (and (vhdl-parse-string "\\([^();\n]*\\)" t)
  11213. (match-string-no-properties 1))))))
  11214. ;; special case: closing parenthesis is on separate line
  11215. (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
  11216. (setq comment (substring init (match-beginning 2)))
  11217. (setq init (substring init 0 (match-beginning 1)))
  11218. (vhdl-forward-syntactic-ws))
  11219. (skip-chars-forward " \t")
  11220. ;; parse inline comment, special case: as above, no initial.
  11221. (unless comment
  11222. (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
  11223. (match-string-no-properties 1))))
  11224. (vhdl-forward-syntactic-ws)
  11225. (setq end-of-list (vhdl-parse-string ")\\s-*" t))
  11226. ;; parse inline comment
  11227. (unless comment
  11228. (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
  11229. (match-string-no-properties 1))))
  11230. (setq return-group-comment (vhdl-parse-group-comment))
  11231. (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
  11232. ;; parse return type
  11233. (when (match-string 3)
  11234. (vhdl-parse-string "[ \t\n\r\f]*\\(.+\\)[ \t\n\r\f]*\\(;\\|is\\>\\)\\s-*")
  11235. (setq return-type (match-string-no-properties 1))
  11236. (when (and return-type
  11237. (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
  11238. (setq return-comment (substring return-type (match-beginning 2)))
  11239. (setq return-type (substring return-type 0 (match-beginning 1))))
  11240. ;; strip of trailing group-comment
  11241. (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
  11242. (setq return-type (substring return-type 0 (match-end 1)))
  11243. ;; parse return comment
  11244. (unless return-comment
  11245. (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
  11246. (match-string-no-properties 1)))))
  11247. ;; parse inline comment
  11248. (unless comment
  11249. (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
  11250. (match-string-no-properties 1))))
  11251. ;; save everything in list
  11252. (setq param-list (append param-list
  11253. (list (list names object direct type init
  11254. comment group-comment))))
  11255. ;; parse group comment and spacing
  11256. (setq group-comment (vhdl-parse-group-comment)))
  11257. (message "Reading interface of subprogram \"%s\"...done" name)
  11258. nil)))
  11259. ;; finish parsing
  11260. (if parse-error
  11261. (error parse-error)
  11262. (setq vhdl-subprog-list
  11263. (list name kind param-list return-type return-comment
  11264. return-group-comment)
  11265. vhdl-subprog-flattened nil)))))
  11266. (defun vhdl-subprog-paste-specification (kind)
  11267. "Paste as a subprogram specification."
  11268. (indent-according-to-mode)
  11269. (let ((margin (current-column))
  11270. (param-list (nth 2 vhdl-subprog-list))
  11271. list-margin start names param)
  11272. ;; paste keyword and name
  11273. (vhdl-insert-keyword
  11274. (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
  11275. (insert (nth 0 vhdl-subprog-list))
  11276. (if (not param-list)
  11277. (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
  11278. (setq start (point))
  11279. ;; paste parameter list
  11280. (insert " (")
  11281. (unless vhdl-argument-list-indent
  11282. (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
  11283. (setq list-margin (current-column))
  11284. (while param-list
  11285. (setq param (car param-list))
  11286. ;; paste group comment and spacing
  11287. (when (memq vhdl-include-group-comments (list kind 'always))
  11288. (vhdl-paste-group-comment (nth 6 param) list-margin))
  11289. ;; paste object
  11290. (when (nth 1 param) (insert (nth 1 param) " "))
  11291. ;; paste names
  11292. (setq names (nth 0 param))
  11293. (while names
  11294. (insert (car names))
  11295. (setq names (cdr names))
  11296. (when names (insert ", ")))
  11297. ;; paste direction
  11298. (insert " : ")
  11299. (when (nth 2 param) (insert (nth 2 param) " "))
  11300. ;; paste type
  11301. (insert (nth 3 param))
  11302. ;; paste initialization
  11303. (when (nth 4 param) (insert " := " (nth 4 param)))
  11304. ;; terminate line
  11305. (if (cdr param-list)
  11306. (insert ";")
  11307. (insert ")")
  11308. (when (null (nth 3 vhdl-subprog-list))
  11309. (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
  11310. ;; paste comment
  11311. (when (and vhdl-include-port-comments (nth 5 param))
  11312. (vhdl-comment-insert-inline (nth 5 param) t))
  11313. (setq param-list (cdr param-list))
  11314. (when param-list (insert "\n") (indent-to list-margin)))
  11315. (when (nth 3 vhdl-subprog-list)
  11316. (insert "\n") (indent-to list-margin)
  11317. ;; paste group comment and spacing
  11318. (when (memq vhdl-include-group-comments (list kind 'always))
  11319. (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
  11320. ;; paste return type
  11321. (insert "return " (nth 3 vhdl-subprog-list))
  11322. (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
  11323. (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
  11324. (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
  11325. ;; align parameter list
  11326. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
  11327. ;; paste body
  11328. (when (eq kind 'body)
  11329. (insert "\n")
  11330. (vhdl-template-begin-end
  11331. (unless (vhdl-standard-p '87)
  11332. (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
  11333. (nth 0 vhdl-subprog-list) margin))))
  11334. (defun vhdl-subprog-paste-declaration ()
  11335. "Paste as a subprogram declaration."
  11336. (interactive)
  11337. (if (not vhdl-subprog-list)
  11338. (error "ERROR: No subprogram interface read")
  11339. (message "Pasting interface as subprogram declaration \"%s\"..."
  11340. (car vhdl-subprog-list))
  11341. ;; paste specification
  11342. (vhdl-subprog-paste-specification 'decl)
  11343. (message "Pasting interface as subprogram declaration \"%s\"...done"
  11344. (car vhdl-subprog-list))))
  11345. (defun vhdl-subprog-paste-body ()
  11346. "Paste as a subprogram body."
  11347. (interactive)
  11348. (if (not vhdl-subprog-list)
  11349. (error "ERROR: No subprogram interface read")
  11350. (message "Pasting interface as subprogram body \"%s\"..."
  11351. (car vhdl-subprog-list))
  11352. ;; paste specification and body
  11353. (vhdl-subprog-paste-specification 'body)
  11354. (message "Pasting interface as subprogram body \"%s\"...done"
  11355. (car vhdl-subprog-list))))
  11356. (defun vhdl-subprog-paste-call ()
  11357. "Paste as a subprogram call."
  11358. (interactive)
  11359. (if (not vhdl-subprog-list)
  11360. (error "ERROR: No subprogram interface read")
  11361. (let ((orig-vhdl-subprog-list vhdl-subprog-list)
  11362. param-list margin list-margin param start)
  11363. ;; flatten local copy of interface list (must be flat for parameter mapping)
  11364. (vhdl-subprog-flatten)
  11365. (setq param-list (nth 2 vhdl-subprog-list))
  11366. (indent-according-to-mode)
  11367. (setq margin (current-indentation))
  11368. (message "Pasting interface as subprogram call \"%s\"..."
  11369. (car vhdl-subprog-list))
  11370. ;; paste name
  11371. (insert (nth 0 vhdl-subprog-list))
  11372. (if (not param-list)
  11373. (insert ";")
  11374. (setq start (point))
  11375. ;; paste parameter list
  11376. (insert " (")
  11377. (unless vhdl-argument-list-indent
  11378. (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
  11379. (setq list-margin (current-column))
  11380. (while param-list
  11381. (setq param (car param-list))
  11382. ;; paste group comment and spacing
  11383. (when (eq vhdl-include-group-comments 'always)
  11384. (vhdl-paste-group-comment (nth 6 param) list-margin))
  11385. ;; paste formal port
  11386. (insert (car (nth 0 param)) " => ")
  11387. (setq param-list (cdr param-list))
  11388. (insert (if param-list "," ");"))
  11389. ;; paste comment
  11390. (when (and vhdl-include-port-comments (nth 5 param))
  11391. (vhdl-comment-insert-inline (nth 5 param)))
  11392. (when param-list (insert "\n") (indent-to list-margin)))
  11393. ;; align parameter list
  11394. (when vhdl-auto-align
  11395. (vhdl-align-region-groups start (point) 1)))
  11396. (message "Pasting interface as subprogram call \"%s\"...done"
  11397. (car vhdl-subprog-list))
  11398. (setq vhdl-subprog-list orig-vhdl-subprog-list))))
  11399. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11400. ;;; Miscellaneous
  11401. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11402. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11403. ;; Hippie expand customization
  11404. (defvar vhdl-expand-upper-case nil)
  11405. (defun vhdl-try-expand-abbrev (old)
  11406. "Try expanding abbreviations from `vhdl-abbrev-list'."
  11407. (unless old
  11408. (he-init-string (he-dabbrev-beg) (point))
  11409. (setq he-expand-list
  11410. (let ((abbrev-list vhdl-abbrev-list)
  11411. (sel-abbrev-list '()))
  11412. (while abbrev-list
  11413. (when (or (not (stringp (car abbrev-list)))
  11414. (string-match
  11415. (concat "^" he-search-string) (car abbrev-list)))
  11416. (setq sel-abbrev-list
  11417. (cons (car abbrev-list) sel-abbrev-list)))
  11418. (setq abbrev-list (cdr abbrev-list)))
  11419. (nreverse sel-abbrev-list))))
  11420. (while (and he-expand-list
  11421. (or (not (stringp (car he-expand-list)))
  11422. (he-string-member (car he-expand-list) he-tried-table t)))
  11423. ; (equal (car he-expand-list) he-search-string)))
  11424. (unless (stringp (car he-expand-list))
  11425. (setq vhdl-expand-upper-case (car he-expand-list)))
  11426. (setq he-expand-list (cdr he-expand-list)))
  11427. (if (null he-expand-list)
  11428. (progn (when old (he-reset-string))
  11429. nil)
  11430. (he-substitute-string
  11431. (if vhdl-expand-upper-case
  11432. (upcase (car he-expand-list))
  11433. (car he-expand-list))
  11434. t)
  11435. (setq he-expand-list (cdr he-expand-list))
  11436. t))
  11437. (defun vhdl-he-list-beg ()
  11438. "Also looks at the word before `(' in order to better match parenthesized
  11439. expressions (e.g. for index ranges of types and signals)."
  11440. (save-excursion
  11441. (condition-case ()
  11442. (progn (backward-up-list 1)
  11443. (skip-syntax-backward "w_")) ; crashes in `viper-mode'
  11444. (error ()))
  11445. (point)))
  11446. ;; override `he-list-beg' from `hippie-exp'
  11447. (unless (and (boundp 'viper-mode) viper-mode)
  11448. (defalias 'he-list-beg 'vhdl-he-list-beg))
  11449. ;; function for expanding abbrevs and dabbrevs
  11450. (defalias 'vhdl-expand-abbrev (make-hippie-expand-function
  11451. '(try-expand-dabbrev
  11452. try-expand-dabbrev-all-buffers
  11453. vhdl-try-expand-abbrev)))
  11454. ;; function for expanding parenthesis
  11455. (defalias 'vhdl-expand-paren (make-hippie-expand-function
  11456. '(try-expand-list
  11457. try-expand-list-all-buffers)))
  11458. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11459. ;; Case fixing
  11460. (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
  11461. "Convert all words matching WORD-REGEXP in region to lower or upper case,
  11462. depending on parameter UPPER-CASE."
  11463. (let ((case-replace nil)
  11464. (last-update 0))
  11465. (vhdl-prepare-search-2
  11466. (save-excursion
  11467. (goto-char end)
  11468. (setq end (point-marker))
  11469. (goto-char beg)
  11470. (while (re-search-forward word-regexp end t)
  11471. (or (vhdl-in-literal)
  11472. (if upper-case
  11473. (upcase-word -1)
  11474. (downcase-word -1)))
  11475. (when (and count vhdl-progress-interval (not noninteractive)
  11476. (< vhdl-progress-interval
  11477. (- (nth 1 (current-time)) last-update)))
  11478. (message "Fixing case... (%2d%s)"
  11479. (+ (* count 20) (/ (* 20 (- (point) beg)) (- end beg)))
  11480. "%")
  11481. (setq last-update (nth 1 (current-time)))))
  11482. (goto-char end)))))
  11483. (defun vhdl-fix-case-region (beg end &optional arg)
  11484. "Convert all VHDL words in region to lower or upper case, depending on
  11485. options vhdl-upper-case-{keywords,types,attributes,enum-values}."
  11486. (interactive "r\nP")
  11487. (vhdl-fix-case-region-1
  11488. beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
  11489. (vhdl-fix-case-region-1
  11490. beg end vhdl-upper-case-types vhdl-types-regexp 1)
  11491. (vhdl-fix-case-region-1
  11492. beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
  11493. (vhdl-fix-case-region-1
  11494. beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
  11495. (vhdl-fix-case-region-1
  11496. beg end vhdl-upper-case-constants vhdl-constants-regexp 4)
  11497. (when vhdl-progress-interval (message "Fixing case...done")))
  11498. (defun vhdl-fix-case-buffer ()
  11499. "Convert all VHDL words in buffer to lower or upper case, depending on
  11500. options vhdl-upper-case-{keywords,types,attributes,enum-values}."
  11501. (interactive)
  11502. (vhdl-fix-case-region (point-min) (point-max)))
  11503. (defun vhdl-fix-case-word (&optional arg)
  11504. "Convert word after cursor to upper case if necessary."
  11505. (interactive "p")
  11506. (save-excursion
  11507. (when arg (backward-word 1))
  11508. (vhdl-prepare-search-1
  11509. (when (and vhdl-upper-case-keywords
  11510. (looking-at vhdl-keywords-regexp))
  11511. (upcase-word 1))
  11512. (when (and vhdl-upper-case-types
  11513. (looking-at vhdl-types-regexp))
  11514. (upcase-word 1))
  11515. (when (and vhdl-upper-case-attributes
  11516. (looking-at vhdl-attributes-regexp))
  11517. (upcase-word 1))
  11518. (when (and vhdl-upper-case-enum-values
  11519. (looking-at vhdl-enum-values-regexp))
  11520. (upcase-word 1))
  11521. (when (and vhdl-upper-case-constants
  11522. (looking-at vhdl-constants-regexp))
  11523. (upcase-word 1)))))
  11524. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11525. ;; Line handling functions
  11526. (defun vhdl-current-line ()
  11527. "Return the line number of the line containing point."
  11528. (save-restriction
  11529. (widen)
  11530. (1+ (count-lines (point-min) (point-at-bol)))))
  11531. (defun vhdl-line-kill-entire (&optional arg)
  11532. "Delete entire line."
  11533. (interactive "p")
  11534. (beginning-of-line)
  11535. (kill-line (or arg 1)))
  11536. (defun vhdl-line-kill (&optional arg)
  11537. "Kill current line."
  11538. (interactive "p")
  11539. (vhdl-line-kill-entire arg))
  11540. (defun vhdl-line-copy (&optional arg)
  11541. "Copy current line."
  11542. (interactive "p")
  11543. (save-excursion
  11544. (let ((position (point-at-bol)))
  11545. (forward-line (or arg 1))
  11546. (copy-region-as-kill position (point)))))
  11547. (defun vhdl-line-yank ()
  11548. "Yank entire line."
  11549. (interactive)
  11550. (beginning-of-line)
  11551. (yank))
  11552. (defun vhdl-line-expand (&optional prefix-arg)
  11553. "Hippie-expand current line."
  11554. (interactive "P")
  11555. (let ((case-fold-search t) (case-replace nil)
  11556. (hippie-expand-try-functions-list
  11557. '(try-expand-line try-expand-line-all-buffers)))
  11558. (hippie-expand prefix-arg)))
  11559. (defun vhdl-line-transpose-next (&optional arg)
  11560. "Interchange this line with next line."
  11561. (interactive "p")
  11562. (forward-line 1)
  11563. (transpose-lines (or arg 1))
  11564. (forward-line -1))
  11565. (defun vhdl-line-transpose-previous (&optional arg)
  11566. "Interchange this line with previous line."
  11567. (interactive "p")
  11568. (forward-line 1)
  11569. (transpose-lines (- 0 (or arg 0)))
  11570. (forward-line -1))
  11571. (defun vhdl-line-open ()
  11572. "Open a new line and indent."
  11573. (interactive)
  11574. (end-of-line -0)
  11575. (newline-and-indent))
  11576. (defun vhdl-delete-indentation ()
  11577. "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
  11578. it works within comments too."
  11579. (interactive)
  11580. (let ((fill-prefix "-- "))
  11581. (delete-indentation)))
  11582. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11583. ;; Move functions
  11584. (defun vhdl-forward-same-indent ()
  11585. "Move forward to next line with same indent."
  11586. (interactive)
  11587. (let ((pos (point))
  11588. (indent (current-indentation)))
  11589. (beginning-of-line 2)
  11590. (while (and (not (eobp))
  11591. (or (looking-at "^\\s-*\\(--.*\\)?$")
  11592. (> (current-indentation) indent)))
  11593. (beginning-of-line 2))
  11594. (if (= (current-indentation) indent)
  11595. (back-to-indentation)
  11596. (message "No following line with same indent found in this block")
  11597. (goto-char pos)
  11598. nil)))
  11599. (defun vhdl-backward-same-indent ()
  11600. "Move backward to previous line with same indent."
  11601. (interactive)
  11602. (let ((pos (point))
  11603. (indent (current-indentation)))
  11604. (beginning-of-line -0)
  11605. (while (and (not (bobp))
  11606. (or (looking-at "^\\s-*\\(--.*\\)?$")
  11607. (> (current-indentation) indent)))
  11608. (beginning-of-line -0))
  11609. (if (= (current-indentation) indent)
  11610. (back-to-indentation)
  11611. (message "No preceding line with same indent found in this block")
  11612. (goto-char pos)
  11613. nil)))
  11614. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11615. ;; Statistics
  11616. (defun vhdl-statistics-buffer ()
  11617. "Get some file statistics."
  11618. (interactive)
  11619. (let ((no-stats 0)
  11620. (no-code-lines 0)
  11621. (no-empty-lines 0)
  11622. (no-comm-lines 0)
  11623. (no-comments 0)
  11624. (no-lines (count-lines (point-min) (point-max))))
  11625. (save-excursion
  11626. ;; count statements
  11627. (goto-char (point-min))
  11628. (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
  11629. (if (match-string 1)
  11630. (goto-char (match-end 1))
  11631. (setq no-stats (1+ no-stats))))
  11632. ;; count code lines
  11633. (goto-char (point-min))
  11634. (while (not (eobp))
  11635. (unless (looking-at "^\\s-*\\(--.*\\)?$")
  11636. (setq no-code-lines (1+ no-code-lines)))
  11637. (beginning-of-line 2))
  11638. ;; count empty lines
  11639. (goto-char (point-min))
  11640. (while (and (re-search-forward "^\\s-*$" nil t)
  11641. (not (eq (point) (point-max))))
  11642. (if (match-string 1)
  11643. (goto-char (match-end 1))
  11644. (setq no-empty-lines (1+ no-empty-lines))
  11645. (unless (eq (point) (point-max))
  11646. (forward-char))))
  11647. ;; count comment-only lines
  11648. (goto-char (point-min))
  11649. (while (re-search-forward "^\\s-*--.*" nil t)
  11650. (if (match-string 1)
  11651. (goto-char (match-end 1))
  11652. (setq no-comm-lines (1+ no-comm-lines))))
  11653. ;; count comments
  11654. (goto-char (point-min))
  11655. (while (re-search-forward "--.*" nil t)
  11656. (if (match-string 1)
  11657. (goto-char (match-end 1))
  11658. (setq no-comments (1+ no-comments)))))
  11659. ;; print results
  11660. (message "\n\
  11661. File statistics: \"%s\"\n\
  11662. ---------------------\n\
  11663. # statements : %5d\n\
  11664. # code lines : %5d\n\
  11665. # empty lines : %5d\n\
  11666. # comment lines : %5d\n\
  11667. # comments : %5d\n\
  11668. # total lines : %5d\n\ "
  11669. (buffer-file-name) no-stats no-code-lines no-empty-lines
  11670. no-comm-lines no-comments no-lines)
  11671. (unless vhdl-emacs-21 (vhdl-show-messages))))
  11672. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11673. ;; Help functions
  11674. (defun vhdl-re-search-forward (regexp &optional bound noerror count)
  11675. "Like `re-search-forward', but does not match within literals."
  11676. (let (pos)
  11677. (save-excursion
  11678. (while (and (setq pos (re-search-forward regexp bound noerror count))
  11679. (vhdl-in-literal))))
  11680. (when pos (goto-char pos))
  11681. pos))
  11682. (defun vhdl-re-search-backward (regexp &optional bound noerror count)
  11683. "Like `re-search-backward', but does not match within literals."
  11684. (let (pos)
  11685. (save-excursion
  11686. (while (and (setq pos (re-search-backward regexp bound noerror count))
  11687. (vhdl-in-literal))))
  11688. (when pos (goto-char pos))
  11689. pos))
  11690. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11691. ;;; Project
  11692. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11693. (defun vhdl-set-project (name)
  11694. "Set current project to NAME."
  11695. (interactive
  11696. (list (let ((completion-ignore-case t))
  11697. (completing-read "Project name: " vhdl-project-alist nil t))))
  11698. (cond ((equal name "")
  11699. (setq vhdl-project nil)
  11700. (message "Current VHDL project: None"))
  11701. ((assoc name vhdl-project-alist)
  11702. (setq vhdl-project name)
  11703. (message "Current VHDL project: \"%s\"" name))
  11704. (t
  11705. (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
  11706. (vhdl-speedbar-update-current-project))
  11707. (defun vhdl-set-default-project ()
  11708. "Set current project as default on startup."
  11709. (interactive)
  11710. (customize-set-variable 'vhdl-project vhdl-project)
  11711. (customize-save-customized))
  11712. (defun vhdl-toggle-project (name token indent)
  11713. "Set current project to NAME or unset if NAME is current project."
  11714. (vhdl-set-project (if (equal name vhdl-project) "" name)))
  11715. (defun vhdl-export-project (file-name)
  11716. "Write project setup for current project."
  11717. (interactive
  11718. (let ((name (vhdl-resolve-env-variable
  11719. (vhdl-replace-string
  11720. (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
  11721. (concat (subst-char-in-string
  11722. ? ?_ (or (vhdl-project-p)
  11723. (error "ERROR: No current project")))
  11724. " " (user-login-name))))))
  11725. (list (read-file-name
  11726. "Write project file: "
  11727. (when (file-name-absolute-p name) "") nil nil name))))
  11728. (setq file-name (abbreviate-file-name file-name))
  11729. (let ((orig-buffer (current-buffer)))
  11730. (unless (file-exists-p (file-name-directory file-name))
  11731. (make-directory (file-name-directory file-name) t))
  11732. (if (not (file-writable-p file-name))
  11733. (error "ERROR: File not writable: \"%s\"" file-name)
  11734. (set-buffer (find-file-noselect file-name t t))
  11735. (erase-buffer)
  11736. (insert ";; -*- Emacs-Lisp -*-\n\n"
  11737. ";;; " (file-name-nondirectory file-name)
  11738. " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
  11739. ";; Project : " vhdl-project "\n"
  11740. ";; Saved : " (format-time-string "%Y-%m-%d %T ")
  11741. (user-login-name) "\n\n\n"
  11742. ";; project name\n"
  11743. "(setq vhdl-project \"" vhdl-project "\")\n\n"
  11744. ";; project setup\n"
  11745. "(aput 'vhdl-project-alist vhdl-project\n'")
  11746. (pp (aget vhdl-project-alist vhdl-project) (current-buffer))
  11747. (insert ")\n")
  11748. (save-buffer)
  11749. (kill-buffer (current-buffer))
  11750. (set-buffer orig-buffer))))
  11751. (defun vhdl-import-project (file-name &optional auto not-make-current)
  11752. "Read project setup and set current project."
  11753. (interactive
  11754. (let ((name (vhdl-resolve-env-variable
  11755. (vhdl-replace-string
  11756. (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
  11757. (concat "" " " (user-login-name))))))
  11758. (list (read-file-name
  11759. "Read project file: " (when (file-name-absolute-p name) "") nil t
  11760. (file-name-directory name)))))
  11761. (when (file-exists-p file-name)
  11762. (condition-case ()
  11763. (let ((current-project vhdl-project))
  11764. (load-file file-name)
  11765. (when (/= (length (aget vhdl-project-alist vhdl-project t)) 10)
  11766. (adelete 'vhdl-project-alist vhdl-project)
  11767. (error ""))
  11768. (when not-make-current
  11769. (setq vhdl-project current-project))
  11770. (vhdl-update-mode-menu)
  11771. (vhdl-speedbar-refresh)
  11772. (unless not-make-current
  11773. (message "Current VHDL project: \"%s\"%s"
  11774. vhdl-project (if auto " (auto-loaded)" ""))))
  11775. (error (vhdl-warning
  11776. (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
  11777. (defun vhdl-duplicate-project ()
  11778. "Duplicate setup of current project."
  11779. (interactive)
  11780. (let ((new-name (read-from-minibuffer "New project name: "))
  11781. (project-entry (aget vhdl-project-alist vhdl-project t)))
  11782. (setq vhdl-project-alist
  11783. (append vhdl-project-alist
  11784. (list (cons new-name project-entry))))
  11785. (vhdl-update-mode-menu)))
  11786. (defun vhdl-auto-load-project ()
  11787. "Automatically load project setup at startup."
  11788. (let ((file-name-list vhdl-project-file-name)
  11789. file-list list-length)
  11790. (while file-name-list
  11791. (setq file-list
  11792. (append file-list
  11793. (file-expand-wildcards
  11794. (vhdl-resolve-env-variable
  11795. (vhdl-replace-string
  11796. (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
  11797. (concat "\*" " " (user-login-name)))))))
  11798. (setq list-length (or list-length (length file-list)))
  11799. (setq file-name-list (cdr file-name-list)))
  11800. (while file-list
  11801. (vhdl-import-project (expand-file-name (car file-list)) t
  11802. (not (> list-length 0)))
  11803. (setq list-length (1- list-length))
  11804. (setq file-list (cdr file-list)))))
  11805. ;; automatically load project setup when idle after startup
  11806. (when (memq 'startup vhdl-project-auto-load)
  11807. (if noninteractive
  11808. (vhdl-auto-load-project)
  11809. (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
  11810. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11811. ;;; Hideshow
  11812. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11813. ;; (using `hideshow.el')
  11814. (defconst vhdl-hs-start-regexp
  11815. (concat
  11816. "\\(^\\)\\s-*\\("
  11817. ;; generic/port clause
  11818. "\\(generic\\|port\\)[ \t\n\r\f]*(\\|"
  11819. ;; component
  11820. "component\\>\\|"
  11821. ;; component instantiation
  11822. "\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*"
  11823. "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
  11824. "\\(\\w\\|\\s_\\)+\\([ \t\n\r\f]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n\r\f]*"
  11825. "\\(generic\\|port\\)[ \t\n\r\f]+map[ \t\n\r\f]*(\\|"
  11826. ;; subprogram
  11827. "\\(function\\|procedure\\)\\>\\|"
  11828. ;; process, block
  11829. "\\(\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|block\\)\\>\\|"
  11830. ;; configuration declaration
  11831. "configuration\\>"
  11832. "\\)")
  11833. "Regexp to match start of construct to hide.")
  11834. (defun vhdl-hs-forward-sexp-func (count)
  11835. "Find end of construct to hide (for hideshow). Only searches forward."
  11836. (let ((pos (point)))
  11837. (vhdl-prepare-search-2
  11838. (beginning-of-line)
  11839. (cond
  11840. ;; generic/port clause
  11841. ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(")
  11842. (goto-char (match-end 0))
  11843. (backward-char)
  11844. (forward-sexp))
  11845. ;; component declaration
  11846. ((looking-at "^\\s-*component\\>")
  11847. (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
  11848. ;; component instantiation
  11849. ((looking-at
  11850. (concat
  11851. "^\\s-*\\w+\\s-*:[ \t\n\r\f]*"
  11852. "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
  11853. "\\w+\\(\\s-*(\\w+)\\)?[ \t\n\r\f]*"
  11854. "\\(generic\\|port\\)\\s-+map[ \t\n\r\f]*("))
  11855. (goto-char (match-end 0))
  11856. (backward-char)
  11857. (forward-sexp)
  11858. (setq pos (point))
  11859. (vhdl-forward-syntactic-ws)
  11860. (when (looking-at "port\\s-+map[ \t\n\r\f]*(")
  11861. (goto-char (match-end 0))
  11862. (backward-char)
  11863. (forward-sexp)
  11864. (setq pos (point)))
  11865. (goto-char pos))
  11866. ;; subprogram declaration/body
  11867. ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
  11868. (goto-char (match-end 0))
  11869. (vhdl-forward-syntactic-ws)
  11870. (when (looking-at "(")
  11871. (forward-sexp))
  11872. (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
  11873. (vhdl-in-literal)))
  11874. ;; subprogram body
  11875. (when (match-string 2)
  11876. (re-search-forward "^\\s-*\\<begin\\>" nil t)
  11877. (backward-word 1)
  11878. (vhdl-forward-sexp)))
  11879. ;; block (recursive)
  11880. ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
  11881. (goto-char (match-end 0))
  11882. (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
  11883. (match-beginning 2))
  11884. (vhdl-hs-forward-sexp-func count)))
  11885. ;; process
  11886. ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
  11887. (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
  11888. ;; configuration declaration
  11889. ((looking-at "^\\s-*configuration\\>")
  11890. (forward-word 4)
  11891. (vhdl-forward-sexp))
  11892. (t (goto-char pos))))))
  11893. (defun vhdl-hideshow-init ()
  11894. "Initialize `hideshow'."
  11895. (when vhdl-hideshow-menu
  11896. (vhdl-hs-minor-mode 1)))
  11897. (defun vhdl-hs-minor-mode (&optional arg)
  11898. "Toggle hideshow minor mode and update menu bar."
  11899. (interactive "P")
  11900. (require 'hideshow)
  11901. ;; check for hideshow version 5.x
  11902. (if (not (boundp 'hs-block-start-mdata-select))
  11903. (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
  11904. ;; initialize hideshow
  11905. (unless (assoc 'vhdl-mode hs-special-modes-alist)
  11906. (setq hs-special-modes-alist
  11907. (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
  11908. 'vhdl-hs-forward-sexp-func nil)
  11909. hs-special-modes-alist)))
  11910. (if (featurep 'xemacs) (make-local-hook 'hs-minor-mode-hook))
  11911. (if vhdl-hide-all-init
  11912. (add-hook 'hs-minor-mode-hook 'hs-hide-all nil t)
  11913. (remove-hook 'hs-minor-mode-hook 'hs-hide-all t))
  11914. (hs-minor-mode arg)
  11915. (force-mode-line-update))) ; hack to update menu bar
  11916. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11917. ;;; Font locking
  11918. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11919. ;; (using `font-lock.el')
  11920. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11921. ;; Help functions
  11922. (defun vhdl-within-translate-off ()
  11923. "Return point if within translate-off region, else nil."
  11924. (and (save-excursion
  11925. (re-search-backward
  11926. "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
  11927. (equal "off" (match-string 1))
  11928. (point)))
  11929. (defun vhdl-start-translate-off (limit)
  11930. "Return point before translate-off pragma if before LIMIT, else nil."
  11931. (when (re-search-forward
  11932. "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
  11933. (match-beginning 0)))
  11934. (defun vhdl-end-translate-off (limit)
  11935. "Return point after translate-on pragma if before LIMIT, else nil."
  11936. (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
  11937. (defun vhdl-match-translate-off (limit)
  11938. "Match a translate-off block, setting match-data and returning t, else nil."
  11939. (when (< (point) limit)
  11940. (let ((start (or (vhdl-within-translate-off)
  11941. (vhdl-start-translate-off limit)))
  11942. (case-fold-search t))
  11943. (when start
  11944. (let ((end (or (vhdl-end-translate-off limit) limit)))
  11945. (set-match-data (list start end))
  11946. (goto-char end))))))
  11947. (defun vhdl-font-lock-match-item (limit)
  11948. "Match, and move over, any declaration item after point. Adapted from
  11949. `font-lock-match-c-style-declaration-item-and-skip-to-next'."
  11950. (condition-case nil
  11951. (save-restriction
  11952. (narrow-to-region (point-min) limit)
  11953. ;; match item
  11954. (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
  11955. (save-match-data
  11956. (goto-char (match-end 1))
  11957. ;; move to next item
  11958. (if (looking-at "\\(\\s-*,\\)")
  11959. (goto-char (match-end 1))
  11960. (end-of-line) t))))
  11961. (error t)))
  11962. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11963. ;; Syntax definitions
  11964. (defconst vhdl-font-lock-syntactic-keywords
  11965. '(("\\(\'\\).\\(\'\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
  11966. "Mark single quotes as having string quote syntax in 'c' instances.")
  11967. (defvar vhdl-font-lock-keywords nil
  11968. "Regular expressions to highlight in VHDL Mode.")
  11969. (defvar vhdl-font-lock-keywords-0
  11970. ;; set in `vhdl-font-lock-init' because dependent on user options
  11971. "For consideration as a value of `vhdl-font-lock-keywords'.
  11972. This does highlighting of template prompts and directives (pragmas).")
  11973. (defvar vhdl-font-lock-keywords-1 nil
  11974. ;; set in `vhdl-font-lock-init' because dependent on user options
  11975. "For consideration as a value of `vhdl-font-lock-keywords'.
  11976. This does highlighting of keywords and standard identifiers.")
  11977. (defconst vhdl-font-lock-keywords-2
  11978. (list
  11979. ;; highlight names of units, subprograms, and components when declared
  11980. (list
  11981. (concat
  11982. "^\\s-*\\("
  11983. "architecture\\|configuration\\|entity\\|package\\(\\s-+body\\)?\\|"
  11984. "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
  11985. "\\)\\s-+\\(\\w+\\)")
  11986. 5 'font-lock-function-name-face)
  11987. ;; highlight entity names of architectures and configurations
  11988. (list
  11989. "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
  11990. 2 'font-lock-function-name-face)
  11991. ;; highlight labels of common constructs
  11992. (list
  11993. (concat
  11994. "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\("
  11995. "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
  11996. "postponed\\|process\\|"
  11997. (when (vhdl-standard-p 'ams) "procedural\\|")
  11998. "with\\|while"
  11999. "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
  12000. 1 'font-lock-function-name-face)
  12001. ;; highlight label and component name of component instantiations
  12002. (list
  12003. (concat
  12004. "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\w+\\)[ \t\n\r\f]*"
  12005. "\\(--[^\n]*[ \t\n\r\f]+\\)*\\(generic\\|port\\)\\s-+map\\>")
  12006. '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
  12007. ;; highlight label and instantiated unit of component instantiations
  12008. (list
  12009. (concat
  12010. "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*"
  12011. "\\(component\\|configuration\\|entity\\)\\s-+"
  12012. "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
  12013. '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
  12014. '(5 font-lock-function-name-face nil t)
  12015. '(7 font-lock-function-name-face nil t))
  12016. ;; highlight names and labels at end of constructs
  12017. (list
  12018. (concat
  12019. "^\\s-*end\\s-+\\(\\("
  12020. "architecture\\|block\\|case\\|component\\|configuration\\|entity\\|"
  12021. "for\\|function\\|generate\\|if\\|loop\\|package\\(\\s-+body\\)?\\|"
  12022. "procedure\\|\\(postponed\\s-+\\)?process\\|"
  12023. (when (vhdl-standard-p 'ams) "procedural\\|")
  12024. "units"
  12025. "\\)\\s-+\\)?\\(\\w*\\)")
  12026. 5 'font-lock-function-name-face)
  12027. ;; highlight labels in exit and next statements
  12028. (list
  12029. (concat
  12030. "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
  12031. 3 'font-lock-function-name-face)
  12032. ;; highlight entity name in attribute specifications
  12033. (list
  12034. (concat
  12035. "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
  12036. 1 'font-lock-function-name-face)
  12037. ;; highlight labels in block and component specifications
  12038. (list
  12039. (concat
  12040. "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
  12041. "\\(:[ \t\n\r\f]*\\(\\w+\\)\\|[^i \t]\\)")
  12042. '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
  12043. ;; highlight names in library clauses
  12044. (list "^\\s-*library\\>"
  12045. '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
  12046. ;; highlight names in use clauses
  12047. (list
  12048. (concat
  12049. "\\<use\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
  12050. "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
  12051. '(3 font-lock-function-name-face) '(5 font-lock-function-name-face nil t)
  12052. '(7 font-lock-function-name-face nil t))
  12053. ;; highlight attribute name in attribute declarations/specifications
  12054. (list
  12055. (concat
  12056. "^\\s-*attribute\\s-+\\(\\w+\\)")
  12057. 1 'vhdl-font-lock-attribute-face)
  12058. ;; highlight type/nature name in (sub)type/(sub)nature declarations
  12059. (list
  12060. (concat
  12061. "^\\s-*\\(\\(sub\\)?\\(nature\\|type\\)\\|end\\s-+\\(record\\|protected\\)\\)\\s-+\\(\\w+\\)")
  12062. 5 'font-lock-type-face)
  12063. ;; highlight signal/variable/constant declaration names
  12064. (list "\\(:[^=]\\)"
  12065. '(vhdl-font-lock-match-item
  12066. (progn (goto-char (match-beginning 1))
  12067. (skip-syntax-backward " ")
  12068. (skip-syntax-backward "w_")
  12069. (skip-syntax-backward " ")
  12070. (while (= (preceding-char) ?,)
  12071. (backward-char 1)
  12072. (skip-syntax-backward " ")
  12073. (skip-syntax-backward "w_")
  12074. (skip-syntax-backward " ")))
  12075. ; (skip-chars-backward "^-(\n\";")
  12076. (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
  12077. ;; highlight formal parameters in component instantiations and subprogram
  12078. ;; calls
  12079. (list "\\(=>\\)"
  12080. '(vhdl-font-lock-match-item
  12081. (progn (goto-char (match-beginning 1))
  12082. (skip-syntax-backward " ")
  12083. (while (= (preceding-char) ?\)) (backward-sexp))
  12084. (skip-syntax-backward "w_")
  12085. (skip-syntax-backward " ")
  12086. (when (memq (preceding-char) '(?n ?N ?|))
  12087. (goto-char (point-max))))
  12088. (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
  12089. ;; highlight alias/group/quantity declaration names and for-loop/-generate
  12090. ;; variables
  12091. (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
  12092. '(vhdl-font-lock-match-item
  12093. (progn (goto-char (match-end 1)) (match-beginning 2))
  12094. nil (1 font-lock-variable-name-face)))
  12095. )
  12096. "For consideration as a value of `vhdl-font-lock-keywords'.
  12097. This does context sensitive highlighting of names and labels.")
  12098. (defvar vhdl-font-lock-keywords-3 nil
  12099. ;; set in `vhdl-font-lock-init' because dependent on user options
  12100. "For consideration as a value of `vhdl-font-lock-keywords'.
  12101. This does highlighting of words with special syntax.")
  12102. (defvar vhdl-font-lock-keywords-4 nil
  12103. ;; set in `vhdl-font-lock-init' because dependent on user options
  12104. "For consideration as a value of `vhdl-font-lock-keywords'.
  12105. This does highlighting of additional reserved words.")
  12106. (defconst vhdl-font-lock-keywords-5
  12107. ;; background highlight translate-off regions
  12108. '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
  12109. "For consideration as a value of `vhdl-font-lock-keywords'.
  12110. This does background highlighting of translate-off regions.")
  12111. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12112. ;; Font and color definitions
  12113. (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
  12114. "Face name to use for prompts.")
  12115. (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
  12116. "Face name to use for standardized attributes.")
  12117. (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
  12118. "Face name to use for standardized enumeration values.")
  12119. (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
  12120. "Face name to use for standardized functions and packages.")
  12121. (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
  12122. "Face name to use for directives.")
  12123. (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
  12124. "Face name to use for additional reserved words.")
  12125. (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
  12126. "Face name to use for translate-off regions.")
  12127. ;; face names to use for words with special syntax.
  12128. (let ((syntax-alist vhdl-special-syntax-alist)
  12129. name)
  12130. (while syntax-alist
  12131. (setq name (vhdl-function-name
  12132. "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
  12133. (eval `(defvar ,name ',name
  12134. ,(concat "Face name to use for "
  12135. (nth 0 (car syntax-alist)) ".")))
  12136. (setq syntax-alist (cdr syntax-alist))))
  12137. (defgroup vhdl-highlight-faces nil
  12138. "Faces for highlighting."
  12139. :group 'vhdl-highlight)
  12140. ;; add faces used from `font-lock'
  12141. (custom-add-to-group
  12142. 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
  12143. (custom-add-to-group
  12144. 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
  12145. (custom-add-to-group
  12146. 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
  12147. (custom-add-to-group
  12148. 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
  12149. (custom-add-to-group
  12150. 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
  12151. (custom-add-to-group
  12152. 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
  12153. (defface vhdl-font-lock-prompt-face
  12154. '((((min-colors 88) (class color) (background light))
  12155. (:foreground "Red1" :bold t))
  12156. (((class color) (background light)) (:foreground "Red" :bold t))
  12157. (((class color) (background dark)) (:foreground "Pink" :bold t))
  12158. (t (:inverse-video t)))
  12159. "Font lock mode face used to highlight prompts."
  12160. :group 'vhdl-highlight-faces)
  12161. (defface vhdl-font-lock-attribute-face
  12162. '((((class color) (background light)) (:foreground "Orchid"))
  12163. (((class color) (background dark)) (:foreground "LightSteelBlue"))
  12164. (t (:italic t :bold t)))
  12165. "Font lock mode face used to highlight standardized attributes."
  12166. :group 'vhdl-highlight-faces)
  12167. (defface vhdl-font-lock-enumvalue-face
  12168. '((((class color) (background light)) (:foreground "SaddleBrown"))
  12169. (((class color) (background dark)) (:foreground "BurlyWood"))
  12170. (t (:italic t :bold t)))
  12171. "Font lock mode face used to highlight standardized enumeration values."
  12172. :group 'vhdl-highlight-faces)
  12173. (defface vhdl-font-lock-function-face
  12174. '((((class color) (background light)) (:foreground "Cyan4"))
  12175. (((class color) (background dark)) (:foreground "Orchid1"))
  12176. (t (:italic t :bold t)))
  12177. "Font lock mode face used to highlight standardized functions and packages."
  12178. :group 'vhdl-highlight-faces)
  12179. (defface vhdl-font-lock-directive-face
  12180. '((((class color) (background light)) (:foreground "CadetBlue"))
  12181. (((class color) (background dark)) (:foreground "Aquamarine"))
  12182. (t (:italic t :bold t)))
  12183. "Font lock mode face used to highlight directives."
  12184. :group 'vhdl-highlight-faces)
  12185. (defface vhdl-font-lock-reserved-words-face
  12186. '((((class color) (background light)) (:foreground "Orange" :bold t))
  12187. (((min-colors 88) (class color) (background dark))
  12188. (:foreground "Yellow1" :bold t))
  12189. (((class color) (background dark)) (:foreground "Yellow" :bold t))
  12190. (t ()))
  12191. "Font lock mode face used to highlight additional reserved words."
  12192. :group 'vhdl-highlight-faces)
  12193. (defface vhdl-font-lock-translate-off-face
  12194. '((((class color) (background light)) (:background "LightGray"))
  12195. (((class color) (background dark)) (:background "DimGray"))
  12196. (t ()))
  12197. "Font lock mode face used to background highlight translate-off regions."
  12198. :group 'vhdl-highlight-faces)
  12199. ;; font lock mode faces used to highlight words with special syntax.
  12200. (let ((syntax-alist vhdl-special-syntax-alist))
  12201. (while syntax-alist
  12202. (eval `(defface ,(vhdl-function-name
  12203. "vhdl-font-lock" (caar syntax-alist) "face")
  12204. '((((class color) (background light))
  12205. (:foreground ,(nth 2 (car syntax-alist))))
  12206. (((class color) (background dark))
  12207. (:foreground ,(nth 3 (car syntax-alist))))
  12208. (t ()))
  12209. ,(concat "Font lock mode face used to highlight "
  12210. (nth 0 (car syntax-alist)) ".")
  12211. :group 'vhdl-highlight-faces))
  12212. (setq syntax-alist (cdr syntax-alist))))
  12213. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12214. ;; Font lock initialization
  12215. (defun vhdl-font-lock-init ()
  12216. "Initialize fontification."
  12217. ;; highlight template prompts and directives
  12218. (setq vhdl-font-lock-keywords-0
  12219. (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
  12220. vhdl-template-prompt-syntax ">\\)")
  12221. 2 'vhdl-font-lock-prompt-face t)
  12222. (list (concat "--\\s-*"
  12223. vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
  12224. 2 'vhdl-font-lock-directive-face t)
  12225. ;; highlight c-preprocessor directives
  12226. (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
  12227. '(1 font-lock-builtin-face)
  12228. '(3 font-lock-variable-name-face nil t))))
  12229. ;; highlight keywords and standardized types, attributes, enumeration
  12230. ;; values, and subprograms
  12231. (setq vhdl-font-lock-keywords-1
  12232. (list
  12233. (list (concat "'" vhdl-attributes-regexp)
  12234. 1 'vhdl-font-lock-attribute-face)
  12235. (list vhdl-types-regexp 1 'font-lock-type-face)
  12236. (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
  12237. (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
  12238. (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
  12239. (list vhdl-constants-regexp 1 'font-lock-constant-face)
  12240. (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
  12241. ;; highlight words with special syntax.
  12242. (setq vhdl-font-lock-keywords-3
  12243. (let ((syntax-alist vhdl-special-syntax-alist)
  12244. keywords)
  12245. (while syntax-alist
  12246. (setq keywords
  12247. (cons
  12248. (list (concat "\\(" (nth 1 (car syntax-alist)) "\\)") 1
  12249. (vhdl-function-name
  12250. "vhdl-font-lock" (nth 0 (car syntax-alist)) "face")
  12251. (nth 4 (car syntax-alist)))
  12252. keywords))
  12253. (setq syntax-alist (cdr syntax-alist)))
  12254. keywords))
  12255. ;; highlight additional reserved words
  12256. (setq vhdl-font-lock-keywords-4
  12257. (list (list vhdl-reserved-words-regexp 1
  12258. 'vhdl-font-lock-reserved-words-face)))
  12259. ;; highlight everything together
  12260. (setq vhdl-font-lock-keywords
  12261. (append
  12262. vhdl-font-lock-keywords-0
  12263. (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
  12264. (when (or vhdl-highlight-forbidden-words
  12265. vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
  12266. (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
  12267. (when vhdl-highlight-names vhdl-font-lock-keywords-2)
  12268. (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
  12269. ;; initialize fontification for VHDL Mode
  12270. (vhdl-font-lock-init)
  12271. (defun vhdl-fontify-buffer ()
  12272. "Re-initialize fontification and fontify buffer."
  12273. (interactive)
  12274. (setq font-lock-defaults
  12275. `(vhdl-font-lock-keywords
  12276. nil ,(not vhdl-highlight-case-sensitive) ((?\_ . "w"))
  12277. beginning-of-line))
  12278. (when (fboundp 'font-lock-unset-defaults)
  12279. (font-lock-unset-defaults)) ; not implemented in XEmacs
  12280. (font-lock-set-defaults)
  12281. (font-lock-mode nil)
  12282. (font-lock-mode t))
  12283. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12284. ;; Initialization for PostScript printing
  12285. (defun vhdl-ps-print-settings ()
  12286. "Initialize custom face and page settings for PostScript printing."
  12287. ;; define custom face settings
  12288. (unless (or (not vhdl-print-customize-faces)
  12289. ps-print-color-p)
  12290. (set (make-local-variable 'ps-bold-faces)
  12291. '(font-lock-keyword-face
  12292. font-lock-type-face
  12293. vhdl-font-lock-attribute-face
  12294. vhdl-font-lock-enumvalue-face
  12295. vhdl-font-lock-directive-face))
  12296. (set (make-local-variable 'ps-italic-faces)
  12297. '(font-lock-comment-face
  12298. font-lock-function-name-face
  12299. font-lock-type-face
  12300. vhdl-font-lock-attribute-face
  12301. vhdl-font-lock-enumvalue-face
  12302. vhdl-font-lock-directive-face))
  12303. (set (make-local-variable 'ps-underlined-faces)
  12304. '(font-lock-string-face))
  12305. (setq ps-always-build-face-reference t))
  12306. ;; define page settings, so that a line containing 79 characters (default)
  12307. ;; fits into one column
  12308. (when vhdl-print-two-column
  12309. (set (make-local-variable 'ps-landscape-mode) t)
  12310. (set (make-local-variable 'ps-number-of-columns) 2)
  12311. (set (make-local-variable 'ps-font-size) 7.0)
  12312. (set (make-local-variable 'ps-header-title-font-size) 10.0)
  12313. (set (make-local-variable 'ps-header-font-size) 9.0)
  12314. (set (make-local-variable 'ps-header-offset) 12.0)
  12315. (when (eq ps-paper-type 'letter)
  12316. (set (make-local-variable 'ps-inter-column) 40.0)
  12317. (set (make-local-variable 'ps-left-margin) 40.0)
  12318. (set (make-local-variable 'ps-right-margin) 40.0))))
  12319. (defun vhdl-ps-print-init ()
  12320. "Initialize PostScript printing."
  12321. (if (featurep 'xemacs)
  12322. (when (boundp 'ps-print-color-p)
  12323. (vhdl-ps-print-settings))
  12324. (if (featurep 'xemacs) (make-local-hook 'ps-print-hook))
  12325. (add-hook 'ps-print-hook 'vhdl-ps-print-settings nil t)))
  12326. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12327. ;;; Hierarchy browser (using `speedbar.el')
  12328. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12329. ;; Allows displaying the hierarchy of all VHDL design units contained in a
  12330. ;; directory by using the speedbar.
  12331. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12332. ;; Variables
  12333. (defvar vhdl-entity-alist nil
  12334. "Cache with entities and corresponding architectures for each
  12335. project/directory.")
  12336. ;; structure: (parenthesized expression means list of such entries)
  12337. ;; (cache-key
  12338. ;; (ent-key ent-name ent-file ent-line
  12339. ;; (arch-key arch-name arch-file arch-line
  12340. ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
  12341. ;; inst-arch-key inst-conf-key inst-lib-key inst-path)
  12342. ;; (lib-name pack-key))
  12343. ;; mra-key (lib-name pack-key))
  12344. (defvar vhdl-config-alist nil
  12345. "Cache with configurations for each project/directory.")
  12346. ;; structure: (parenthesized expression means list of such entries)
  12347. ;; (cache-key
  12348. ;; (conf-key conf-name conf-file conf-line ent-key arch-key
  12349. ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
  12350. ;; inst-conf-key inst-lib-key)
  12351. ;; (lib-name pack-key)))
  12352. (defvar vhdl-package-alist nil
  12353. "Cache with packages for each project/directory.")
  12354. ;; structure: (parenthesized expression means list of such entries)
  12355. ;; (cache-key
  12356. ;; (pack-key pack-name pack-file pack-line
  12357. ;; (comp-key comp-name comp-file comp-line)
  12358. ;; (func-key func-name func-file func-line)
  12359. ;; (lib-name pack-key)
  12360. ;; pack-body-file pack-body-line
  12361. ;; (func-key func-name func-body-file func-body-line)
  12362. ;; (lib-name pack-key)))
  12363. (defvar vhdl-ent-inst-alist nil
  12364. "Cache with instantiated entities for each project/directory.")
  12365. ;; structure: (parenthesized expression means list of such entries)
  12366. ;; (cache-key (inst-ent-key))
  12367. (defvar vhdl-file-alist nil
  12368. "Cache with design units in each file for each project/directory.")
  12369. ;; structure: (parenthesized expression means list of such entries)
  12370. ;; (cache-key
  12371. ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
  12372. ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
  12373. (defvar vhdl-directory-alist nil
  12374. "Cache with source directories for each project.")
  12375. ;; structure: (parenthesized expression means list of such entries)
  12376. ;; (cache-key (directory))
  12377. (defvar vhdl-speedbar-shown-unit-alist nil
  12378. "Alist of design units simultaneously open in the current speedbar for each
  12379. directory and project.")
  12380. (defvar vhdl-speedbar-shown-project-list nil
  12381. "List of projects simultaneously open in the current speedbar.")
  12382. (defvar vhdl-updated-project-list nil
  12383. "List of projects and directories with updated files.")
  12384. (defvar vhdl-modified-file-list nil
  12385. "List of modified files to be rescanned for hierarchy updating.")
  12386. (defvar vhdl-speedbar-hierarchy-depth 0
  12387. "Depth of instantiation hierarchy to display.")
  12388. (defvar vhdl-speedbar-show-projects nil
  12389. "Non-nil means project hierarchy is displayed in speedbar, directory
  12390. hierarchy otherwise.")
  12391. (defun vhdl-get-end-of-unit ()
  12392. "Return position of end of current unit."
  12393. (let ((pos (point)))
  12394. (save-excursion
  12395. (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil 1)
  12396. (save-excursion
  12397. (goto-char (match-beginning 0))
  12398. (vhdl-backward-syntactic-ws)
  12399. (and (/= (preceding-char) ?\;) (not (bobp))))))
  12400. (re-search-backward "^[ \t]*end\\>" pos 1)
  12401. (point))))
  12402. (defun vhdl-match-string-downcase (num &optional string)
  12403. "Like `match-string-no-properties' with down-casing."
  12404. (let ((match (match-string-no-properties num string)))
  12405. (and match (downcase match))))
  12406. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12407. ;; Scan functions
  12408. (defun vhdl-scan-context-clause ()
  12409. "Scan the context clause that precedes a design unit."
  12410. (let (lib-alist)
  12411. (save-excursion
  12412. (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|entity\\|package\\)\\>" nil t)
  12413. (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
  12414. (equal "USE" (upcase (match-string 1))))
  12415. (when (looking-at "^[ \t]*use[ \t\n\r\f]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
  12416. (setq lib-alist (cons (cons (match-string-no-properties 1)
  12417. (vhdl-match-string-downcase 2))
  12418. lib-alist))))))
  12419. lib-alist))
  12420. (defun vhdl-scan-directory-contents (name &optional project update num-string
  12421. non-final)
  12422. "Scan contents of VHDL files in directory or file pattern NAME."
  12423. (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
  12424. ; (unless (file-directory-p (match-string 1 name))
  12425. ; (message "No such directory: \"%s\"" (match-string 1 name)))
  12426. (let* ((dir-name (match-string 1 name))
  12427. (file-pattern (match-string 2 name))
  12428. (is-directory (= 0 (length file-pattern)))
  12429. (file-list
  12430. (if update
  12431. (list name)
  12432. (if is-directory
  12433. (vhdl-get-source-files t dir-name)
  12434. (vhdl-directory-files
  12435. dir-name t (wildcard-to-regexp file-pattern)))))
  12436. (key (or project dir-name))
  12437. (file-exclude-regexp
  12438. (or (nth 3 (aget vhdl-project-alist project)) ""))
  12439. (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
  12440. (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
  12441. (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
  12442. ent-alist conf-alist pack-alist ent-inst-list file-alist
  12443. tmp-list tmp-entry no-files files-exist big-files)
  12444. (when (or project update)
  12445. (setq ent-alist (aget vhdl-entity-alist key t)
  12446. conf-alist (aget vhdl-config-alist key t)
  12447. pack-alist (aget vhdl-package-alist key t)
  12448. ent-inst-list (car (aget vhdl-ent-inst-alist key t))
  12449. file-alist (aget vhdl-file-alist key t)))
  12450. (when (and (not is-directory) (null file-list))
  12451. (message "No such file: \"%s\"" name))
  12452. (setq files-exist file-list)
  12453. (when file-list
  12454. (setq no-files (length file-list))
  12455. (message "Scanning %s %s\"%s\"..."
  12456. (if is-directory "directory" "files") (or num-string "") name)
  12457. ;; exclude files
  12458. (unless (equal file-exclude-regexp "")
  12459. (let ((case-fold-search nil)
  12460. file-tmp-list)
  12461. (while file-list
  12462. (unless (string-match file-exclude-regexp (car file-list))
  12463. (setq file-tmp-list (cons (car file-list) file-tmp-list)))
  12464. (setq file-list (cdr file-list)))
  12465. (setq file-list (nreverse file-tmp-list))))
  12466. ;; do for all files
  12467. (while file-list
  12468. (unless noninteractive
  12469. (message "Scanning %s %s\"%s\"... (%2d%s)"
  12470. (if is-directory "directory" "files")
  12471. (or num-string "") name
  12472. (/ (* 100 (- no-files (length file-list))) no-files) "%"))
  12473. (let ((file-name (abbreviate-file-name (car file-list)))
  12474. ent-list arch-list arch-ent-list conf-list
  12475. pack-list pack-body-list inst-list inst-ent-list)
  12476. ;; scan file
  12477. (vhdl-visit-file
  12478. file-name nil
  12479. (vhdl-prepare-search-2
  12480. (save-excursion
  12481. ;; scan for design units
  12482. (if (and limit-design-file-size
  12483. (< limit-design-file-size (buffer-size)))
  12484. (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
  12485. (setq big-files t))
  12486. ;; scan for entities
  12487. (goto-char (point-min))
  12488. (while (re-search-forward "^[ \t]*entity[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
  12489. (let* ((ent-name (match-string-no-properties 1))
  12490. (ent-key (downcase ent-name))
  12491. (ent-entry (aget ent-alist ent-key t))
  12492. (lib-alist (vhdl-scan-context-clause)))
  12493. (if (nth 1 ent-entry)
  12494. (vhdl-warning-when-idle
  12495. "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
  12496. ent-name (nth 1 ent-entry) (nth 2 ent-entry)
  12497. file-name (vhdl-current-line))
  12498. (setq ent-list (cons ent-key ent-list))
  12499. (aput 'ent-alist ent-key
  12500. (list ent-name file-name (vhdl-current-line)
  12501. (nth 3 ent-entry) (nth 4 ent-entry)
  12502. lib-alist)))))
  12503. ;; scan for architectures
  12504. (goto-char (point-min))
  12505. (while (re-search-forward "^[ \t]*architecture[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
  12506. (let* ((arch-name (match-string-no-properties 1))
  12507. (arch-key (downcase arch-name))
  12508. (ent-name (match-string-no-properties 2))
  12509. (ent-key (downcase ent-name))
  12510. (ent-entry (aget ent-alist ent-key t))
  12511. (arch-alist (nth 3 ent-entry))
  12512. (arch-entry (aget arch-alist arch-key t))
  12513. (lib-arch-alist (vhdl-scan-context-clause)))
  12514. (if arch-entry
  12515. (vhdl-warning-when-idle
  12516. "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
  12517. arch-name ent-name (nth 1 arch-entry)
  12518. (nth 2 arch-entry) file-name (vhdl-current-line))
  12519. (setq arch-list (cons arch-key arch-list)
  12520. arch-ent-list (cons ent-key arch-ent-list))
  12521. (aput 'arch-alist arch-key
  12522. (list arch-name file-name (vhdl-current-line) nil
  12523. lib-arch-alist))
  12524. (aput 'ent-alist ent-key
  12525. (list (or (nth 0 ent-entry) ent-name)
  12526. (nth 1 ent-entry) (nth 2 ent-entry)
  12527. (vhdl-sort-alist arch-alist)
  12528. arch-key (nth 5 ent-entry))))))
  12529. ;; scan for configurations
  12530. (goto-char (point-min))
  12531. (while (re-search-forward "^[ \t]*configuration[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
  12532. (let* ((conf-name (match-string-no-properties 1))
  12533. (conf-key (downcase conf-name))
  12534. (conf-entry (aget conf-alist conf-key t))
  12535. (ent-name (match-string-no-properties 2))
  12536. (ent-key (downcase ent-name))
  12537. (lib-alist (vhdl-scan-context-clause))
  12538. (conf-line (vhdl-current-line))
  12539. (end-of-unit (vhdl-get-end-of-unit))
  12540. arch-key comp-conf-list inst-key-list
  12541. inst-comp-key inst-ent-key inst-arch-key
  12542. inst-conf-key inst-lib-key)
  12543. (when (vhdl-re-search-forward "\\<for[ \t\n\r\f]+\\(\\w+\\)")
  12544. (setq arch-key (vhdl-match-string-downcase 1)))
  12545. (if conf-entry
  12546. (vhdl-warning-when-idle
  12547. "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
  12548. conf-name ent-name (nth 1 conf-entry)
  12549. (nth 2 conf-entry) file-name conf-line)
  12550. (setq conf-list (cons conf-key conf-list))
  12551. ;; scan for subconfigurations and subentities
  12552. (while (re-search-forward "^[ \t]*for[ \t\n\r\f]+\\(\\w+\\([ \t\n\r\f]*,[ \t\n\r\f]*\\w+\\)*\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\(\\w+\\)[ \t\n\r\f]+" end-of-unit t)
  12553. (setq inst-comp-key (vhdl-match-string-downcase 3)
  12554. inst-key-list (split-string
  12555. (vhdl-match-string-downcase 1)
  12556. "[ \t\n\r\f]*,[ \t\n\r\f]*"))
  12557. (vhdl-forward-syntactic-ws)
  12558. (when (looking-at "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n\r\f]*\\((\\(\\w+\\))\\)?")
  12559. (setq
  12560. inst-lib-key (vhdl-match-string-downcase 3)
  12561. inst-ent-key (and (match-string 2)
  12562. (vhdl-match-string-downcase 4))
  12563. inst-arch-key (and (match-string 2)
  12564. (vhdl-match-string-downcase 6))
  12565. inst-conf-key (and (not (match-string 2))
  12566. (vhdl-match-string-downcase 4)))
  12567. (while inst-key-list
  12568. (setq comp-conf-list
  12569. (cons (list (car inst-key-list)
  12570. inst-comp-key inst-ent-key
  12571. inst-arch-key inst-conf-key
  12572. inst-lib-key)
  12573. comp-conf-list))
  12574. (setq inst-key-list (cdr inst-key-list)))))
  12575. (aput 'conf-alist conf-key
  12576. (list conf-name file-name conf-line ent-key
  12577. arch-key comp-conf-list lib-alist)))))
  12578. ;; scan for packages
  12579. (goto-char (point-min))
  12580. (while (re-search-forward "^[ \t]*package[ \t\n\r\f]+\\(body[ \t\n\r\f]+\\)?\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
  12581. (let* ((pack-name (match-string-no-properties 2))
  12582. (pack-key (downcase pack-name))
  12583. (is-body (match-string-no-properties 1))
  12584. (pack-entry (aget pack-alist pack-key t))
  12585. (pack-line (vhdl-current-line))
  12586. (end-of-unit (vhdl-get-end-of-unit))
  12587. comp-name func-name comp-alist func-alist lib-alist)
  12588. (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
  12589. (vhdl-warning-when-idle
  12590. "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
  12591. (if is-body " body" "") pack-name
  12592. (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
  12593. (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
  12594. file-name (vhdl-current-line))
  12595. ;; scan for context clauses
  12596. (setq lib-alist (vhdl-scan-context-clause))
  12597. ;; scan for component and subprogram declarations/bodies
  12598. (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n\r\f]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
  12599. (if (equal (upcase (match-string 1)) "COMPONENT")
  12600. (setq comp-name (match-string-no-properties 2)
  12601. comp-alist
  12602. (cons (list (downcase comp-name) comp-name
  12603. file-name (vhdl-current-line))
  12604. comp-alist))
  12605. (setq func-name (match-string-no-properties 2)
  12606. func-alist
  12607. (cons (list (downcase func-name) func-name
  12608. file-name (vhdl-current-line))
  12609. func-alist))))
  12610. (setq func-alist (nreverse func-alist))
  12611. (setq comp-alist (nreverse comp-alist))
  12612. (if is-body
  12613. (setq pack-body-list (cons pack-key pack-body-list))
  12614. (setq pack-list (cons pack-key pack-list)))
  12615. (aput
  12616. 'pack-alist pack-key
  12617. (if is-body
  12618. (list (or (nth 0 pack-entry) pack-name)
  12619. (nth 1 pack-entry) (nth 2 pack-entry)
  12620. (nth 3 pack-entry) (nth 4 pack-entry)
  12621. (nth 5 pack-entry)
  12622. file-name pack-line func-alist lib-alist)
  12623. (list pack-name file-name pack-line
  12624. comp-alist func-alist lib-alist
  12625. (nth 6 pack-entry) (nth 7 pack-entry)
  12626. (nth 8 pack-entry) (nth 9 pack-entry))))))))
  12627. ;; scan for hierarchy
  12628. (if (and limit-hier-file-size
  12629. (< limit-hier-file-size (buffer-size)))
  12630. (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
  12631. (setq big-files t))
  12632. ;; scan for architectures
  12633. (goto-char (point-min))
  12634. (while (re-search-forward "^[ \t]*architecture[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
  12635. (let* ((ent-name (match-string-no-properties 2))
  12636. (ent-key (downcase ent-name))
  12637. (arch-name (match-string-no-properties 1))
  12638. (arch-key (downcase arch-name))
  12639. (ent-entry (aget ent-alist ent-key t))
  12640. (arch-alist (nth 3 ent-entry))
  12641. (arch-entry (aget arch-alist arch-key t))
  12642. (beg-of-unit (point))
  12643. (end-of-unit (vhdl-get-end-of-unit))
  12644. (inst-no 0)
  12645. inst-alist inst-path)
  12646. ;; scan for contained instantiations
  12647. (while (and (re-search-forward
  12648. (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
  12649. "\\(\\w+\\)[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(generic\\|port\\)[ \t\n\r\f]+map\\>\\|"
  12650. "component[ \t\n\r\f]+\\(\\w+\\)\\|"
  12651. "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?\\|"
  12652. "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
  12653. "\\(^[ \t]*end[ \t\n\r\f]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
  12654. (or (not limit-hier-inst-no)
  12655. (<= (setq inst-no (1+ inst-no))
  12656. limit-hier-inst-no)))
  12657. (cond
  12658. ;; block/generate beginning found
  12659. ((match-string 14)
  12660. (setq inst-path
  12661. (cons (match-string-no-properties 1) inst-path)))
  12662. ;; block/generate end found
  12663. ((match-string 16)
  12664. (setq inst-path (cdr inst-path)))
  12665. ;; instantiation found
  12666. (t
  12667. (let* ((inst-name (match-string-no-properties 1))
  12668. (inst-key (downcase inst-name))
  12669. (inst-comp-name
  12670. (or (match-string-no-properties 3)
  12671. (match-string-no-properties 6)))
  12672. (inst-ent-key
  12673. (or (and (match-string 8)
  12674. (vhdl-match-string-downcase 11))
  12675. (and inst-comp-name
  12676. (downcase inst-comp-name))))
  12677. (inst-arch-key (vhdl-match-string-downcase 13))
  12678. (inst-conf-key
  12679. (and (not (match-string 8))
  12680. (vhdl-match-string-downcase 11)))
  12681. (inst-lib-key (vhdl-match-string-downcase 10)))
  12682. (goto-char (match-end 1))
  12683. (setq inst-list (cons inst-key inst-list)
  12684. inst-ent-list
  12685. (cons inst-ent-key inst-ent-list))
  12686. (setq inst-alist
  12687. (append
  12688. inst-alist
  12689. (list (list inst-key inst-name file-name
  12690. (vhdl-current-line) inst-comp-name
  12691. inst-ent-key inst-arch-key
  12692. inst-conf-key inst-lib-key
  12693. (reverse inst-path)))))))))
  12694. ;; scan for contained configuration specifications
  12695. (goto-char beg-of-unit)
  12696. (while (re-search-forward
  12697. (concat "^[ \t]*for[ \t\n\r\f]+\\(\\w+\\([ \t\n\r\f]*,[ \t\n\r\f]*\\w+\\)*\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\(\\w+\\)[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*"
  12698. "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?") end-of-unit t)
  12699. (let* ((inst-comp-name (match-string-no-properties 3))
  12700. (inst-ent-key
  12701. (and (match-string 6)
  12702. (vhdl-match-string-downcase 9)))
  12703. (inst-arch-key (vhdl-match-string-downcase 11))
  12704. (inst-conf-key
  12705. (and (not (match-string 6))
  12706. (vhdl-match-string-downcase 9)))
  12707. (inst-lib-key (vhdl-match-string-downcase 8))
  12708. (inst-key-list
  12709. (split-string (vhdl-match-string-downcase 1)
  12710. "[ \t\n\r\f]*,[ \t\n\r\f]*"))
  12711. (tmp-inst-alist inst-alist)
  12712. inst-entry)
  12713. (while tmp-inst-alist
  12714. (when (and (or (equal "all" (car inst-key-list))
  12715. (member (nth 0 (car tmp-inst-alist))
  12716. inst-key-list))
  12717. (equal
  12718. (downcase
  12719. (or (nth 4 (car tmp-inst-alist)) ""))
  12720. (downcase inst-comp-name)))
  12721. (setq inst-entry (car tmp-inst-alist))
  12722. (setq inst-ent-list
  12723. (cons (or inst-ent-key (nth 5 inst-entry))
  12724. (vhdl-delete
  12725. (nth 5 inst-entry) inst-ent-list)))
  12726. (setq inst-entry
  12727. (list (nth 0 inst-entry) (nth 1 inst-entry)
  12728. (nth 2 inst-entry) (nth 3 inst-entry)
  12729. (nth 4 inst-entry)
  12730. (or inst-ent-key (nth 5 inst-entry))
  12731. (or inst-arch-key (nth 6 inst-entry))
  12732. inst-conf-key inst-lib-key))
  12733. (setcar tmp-inst-alist inst-entry))
  12734. (setq tmp-inst-alist (cdr tmp-inst-alist)))))
  12735. ;; save in cache
  12736. (aput 'arch-alist arch-key
  12737. (list (nth 0 arch-entry) (nth 1 arch-entry)
  12738. (nth 2 arch-entry) inst-alist
  12739. (nth 4 arch-entry)))
  12740. (aput 'ent-alist ent-key
  12741. (list (nth 0 ent-entry) (nth 1 ent-entry)
  12742. (nth 2 ent-entry) (vhdl-sort-alist arch-alist)
  12743. (nth 4 ent-entry) (nth 5 ent-entry)))
  12744. (when (and limit-hier-inst-no
  12745. (> inst-no limit-hier-inst-no))
  12746. (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
  12747. (setq big-files t))
  12748. (goto-char end-of-unit))))
  12749. ;; remember design units for this file
  12750. (aput 'file-alist file-name
  12751. (list ent-list arch-list arch-ent-list conf-list
  12752. pack-list pack-body-list inst-list inst-ent-list))
  12753. (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
  12754. (setq file-list (cdr file-list))))
  12755. (when (or (and (not project) files-exist)
  12756. (and project (not non-final)))
  12757. ;; consistency checks:
  12758. ;; check whether each architecture has a corresponding entity
  12759. (setq tmp-list ent-alist)
  12760. (while tmp-list
  12761. (when (null (nth 2 (car tmp-list)))
  12762. (setq tmp-entry (car (nth 4 (car tmp-list))))
  12763. (vhdl-warning-when-idle
  12764. "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
  12765. (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
  12766. (nth 3 tmp-entry)))
  12767. (setq tmp-list (cdr tmp-list)))
  12768. ;; check whether configuration has a corresponding entity/architecture
  12769. (setq tmp-list conf-alist)
  12770. (while tmp-list
  12771. (if (setq tmp-entry (aget ent-alist (nth 4 (car tmp-list)) t))
  12772. (unless (aget (nth 3 tmp-entry) (nth 5 (car tmp-list)) t)
  12773. (setq tmp-entry (car tmp-list))
  12774. (vhdl-warning-when-idle
  12775. "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
  12776. (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
  12777. (nth 2 tmp-entry) (nth 3 tmp-entry)))
  12778. (setq tmp-entry (car tmp-list))
  12779. (vhdl-warning-when-idle
  12780. "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
  12781. (nth 1 tmp-entry) (nth 4 tmp-entry)
  12782. (nth 2 tmp-entry) (nth 3 tmp-entry)))
  12783. (setq tmp-list (cdr tmp-list)))
  12784. ;; check whether each package body has a package declaration
  12785. (setq tmp-list pack-alist)
  12786. (while tmp-list
  12787. (when (null (nth 2 (car tmp-list)))
  12788. (setq tmp-entry (car tmp-list))
  12789. (vhdl-warning-when-idle
  12790. "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
  12791. (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
  12792. (setq tmp-list (cdr tmp-list)))
  12793. ;; sort lists
  12794. (setq ent-alist (vhdl-sort-alist ent-alist))
  12795. (setq conf-alist (vhdl-sort-alist conf-alist))
  12796. (setq pack-alist (vhdl-sort-alist pack-alist))
  12797. ;; remember updated directory/project
  12798. (add-to-list 'vhdl-updated-project-list (or project dir-name)))
  12799. ;; clear directory alists
  12800. (unless project
  12801. (adelete 'vhdl-entity-alist key)
  12802. (adelete 'vhdl-config-alist key)
  12803. (adelete 'vhdl-package-alist key)
  12804. (adelete 'vhdl-ent-inst-alist key)
  12805. (adelete 'vhdl-file-alist key))
  12806. ;; put directory contents into cache
  12807. (aput 'vhdl-entity-alist key ent-alist)
  12808. (aput 'vhdl-config-alist key conf-alist)
  12809. (aput 'vhdl-package-alist key pack-alist)
  12810. (aput 'vhdl-ent-inst-alist key (list ent-inst-list))
  12811. (aput 'vhdl-file-alist key file-alist)
  12812. ;; final messages
  12813. (message "Scanning %s %s\"%s\"...done"
  12814. (if is-directory "directory" "files") (or num-string "") name)
  12815. (unless project (message "Scanning directory...done"))
  12816. (when big-files
  12817. (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
  12818. ;; save cache when scanned non-interactively
  12819. (when (or (not project) (not non-final))
  12820. (when (and noninteractive vhdl-speedbar-save-cache)
  12821. (vhdl-save-cache key)))
  12822. t))
  12823. (defun vhdl-scan-project-contents (project)
  12824. "Scan the contents of all VHDL files found in the directories and files
  12825. of PROJECT."
  12826. (let ((dir-list (or (nth 2 (aget vhdl-project-alist project)) '("")))
  12827. (default-dir (vhdl-resolve-env-variable
  12828. (nth 1 (aget vhdl-project-alist project))))
  12829. (file-exclude-regexp
  12830. (or (nth 3 (aget vhdl-project-alist project)) ""))
  12831. dir-list-tmp dir dir-name num-dir act-dir recursive)
  12832. ;; clear project alists
  12833. (adelete 'vhdl-entity-alist project)
  12834. (adelete 'vhdl-config-alist project)
  12835. (adelete 'vhdl-package-alist project)
  12836. (adelete 'vhdl-ent-inst-alist project)
  12837. (adelete 'vhdl-file-alist project)
  12838. ;; expand directory names by default-directory
  12839. (message "Collecting source files...")
  12840. (while dir-list
  12841. (setq dir (vhdl-resolve-env-variable (car dir-list)))
  12842. (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
  12843. (setq recursive (match-string 1 dir)
  12844. dir-name (match-string 3 dir))
  12845. (setq dir-list-tmp
  12846. (cons (concat recursive
  12847. (if (file-name-absolute-p dir-name) "" default-dir)
  12848. dir-name)
  12849. dir-list-tmp))
  12850. (setq dir-list (cdr dir-list)))
  12851. ;; resolve path wildcards
  12852. (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
  12853. ;; expand directories
  12854. (while dir-list-tmp
  12855. (setq dir (car dir-list-tmp))
  12856. ;; get subdirectories
  12857. (if (string-match "-r \\(.*[/\\]\\)" dir)
  12858. (setq dir-list (append dir-list (vhdl-get-subdirs
  12859. (match-string 1 dir))))
  12860. (setq dir-list (append dir-list (list dir))))
  12861. (setq dir-list-tmp (cdr dir-list-tmp)))
  12862. ;; exclude files
  12863. (unless (equal file-exclude-regexp "")
  12864. (let ((case-fold-search nil))
  12865. (while dir-list
  12866. (unless (string-match file-exclude-regexp (car dir-list))
  12867. (setq dir-list-tmp (cons (car dir-list) dir-list-tmp)))
  12868. (setq dir-list (cdr dir-list)))
  12869. (setq dir-list (nreverse dir-list-tmp))))
  12870. (message "Collecting source files...done")
  12871. ;; scan for design units for each directory in DIR-LIST
  12872. (setq dir-list-tmp nil
  12873. num-dir (length dir-list)
  12874. act-dir 1)
  12875. (while dir-list
  12876. (setq dir-name (abbreviate-file-name
  12877. (expand-file-name (car dir-list))))
  12878. (vhdl-scan-directory-contents dir-name project nil
  12879. (format "(%s/%s) " act-dir num-dir)
  12880. (cdr dir-list))
  12881. (add-to-list 'dir-list-tmp (file-name-directory dir-name))
  12882. (setq dir-list (cdr dir-list)
  12883. act-dir (1+ act-dir)))
  12884. (aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
  12885. (message "Scanning project \"%s\"...done" project)))
  12886. (defun vhdl-update-file-contents (file-name)
  12887. "Update hierarchy information by contents of current buffer."
  12888. (setq file-name (abbreviate-file-name file-name))
  12889. (let* ((dir-name (file-name-directory file-name))
  12890. (directory-alist vhdl-directory-alist)
  12891. updated)
  12892. (while directory-alist
  12893. (when (member dir-name (nth 1 (car directory-alist)))
  12894. (let* ((vhdl-project (nth 0 (car directory-alist)))
  12895. (project (vhdl-project-p))
  12896. (ent-alist (aget vhdl-entity-alist (or project dir-name) t))
  12897. (conf-alist (aget vhdl-config-alist (or project dir-name) t))
  12898. (pack-alist (aget vhdl-package-alist (or project dir-name) t))
  12899. (ent-inst-list (car (aget vhdl-ent-inst-alist
  12900. (or project dir-name) t)))
  12901. (file-alist (aget vhdl-file-alist (or project dir-name) t))
  12902. (file-entry (aget file-alist file-name t))
  12903. (ent-list (nth 0 file-entry))
  12904. (arch-list (nth 1 file-entry))
  12905. (arch-ent-list (nth 2 file-entry))
  12906. (conf-list (nth 3 file-entry))
  12907. (pack-list (nth 4 file-entry))
  12908. (pack-body-list (nth 5 file-entry))
  12909. (inst-ent-list (nth 7 file-entry))
  12910. (cache-key (or project dir-name))
  12911. arch-alist key ent-key entry)
  12912. ;; delete design units previously contained in this file:
  12913. ;; entities
  12914. (while ent-list
  12915. (setq key (car ent-list)
  12916. entry (aget ent-alist key t))
  12917. (when (equal file-name (nth 1 entry))
  12918. (if (nth 3 entry)
  12919. (aput 'ent-alist key
  12920. (list (nth 0 entry) nil nil (nth 3 entry) nil))
  12921. (adelete 'ent-alist key)))
  12922. (setq ent-list (cdr ent-list)))
  12923. ;; architectures
  12924. (while arch-list
  12925. (setq key (car arch-list)
  12926. ent-key (car arch-ent-list)
  12927. entry (aget ent-alist ent-key t)
  12928. arch-alist (nth 3 entry))
  12929. (when (equal file-name (nth 1 (aget arch-alist key t)))
  12930. (adelete 'arch-alist key)
  12931. (if (or (nth 1 entry) arch-alist)
  12932. (aput 'ent-alist ent-key
  12933. (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
  12934. arch-alist (nth 4 entry) (nth 5 entry)))
  12935. (adelete 'ent-alist ent-key)))
  12936. (setq arch-list (cdr arch-list)
  12937. arch-ent-list (cdr arch-ent-list)))
  12938. ;; configurations
  12939. (while conf-list
  12940. (setq key (car conf-list))
  12941. (when (equal file-name (nth 1 (aget conf-alist key t)))
  12942. (adelete 'conf-alist key))
  12943. (setq conf-list (cdr conf-list)))
  12944. ;; package declarations
  12945. (while pack-list
  12946. (setq key (car pack-list)
  12947. entry (aget pack-alist key t))
  12948. (when (equal file-name (nth 1 entry))
  12949. (if (nth 6 entry)
  12950. (aput 'pack-alist key
  12951. (list (nth 0 entry) nil nil nil nil nil
  12952. (nth 6 entry) (nth 7 entry) (nth 8 entry)
  12953. (nth 9 entry)))
  12954. (adelete 'pack-alist key)))
  12955. (setq pack-list (cdr pack-list)))
  12956. ;; package bodies
  12957. (while pack-body-list
  12958. (setq key (car pack-body-list)
  12959. entry (aget pack-alist key t))
  12960. (when (equal file-name (nth 6 entry))
  12961. (if (nth 1 entry)
  12962. (aput 'pack-alist key
  12963. (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
  12964. (nth 3 entry) (nth 4 entry) (nth 5 entry)
  12965. nil nil nil nil))
  12966. (adelete 'pack-alist key)))
  12967. (setq pack-body-list (cdr pack-body-list)))
  12968. ;; instantiated entities
  12969. (while inst-ent-list
  12970. (setq ent-inst-list
  12971. (vhdl-delete (car inst-ent-list) ent-inst-list))
  12972. (setq inst-ent-list (cdr inst-ent-list)))
  12973. ;; update caches
  12974. (vhdl-aput 'vhdl-entity-alist cache-key ent-alist)
  12975. (vhdl-aput 'vhdl-config-alist cache-key conf-alist)
  12976. (vhdl-aput 'vhdl-package-alist cache-key pack-alist)
  12977. (vhdl-aput 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
  12978. ;; scan file
  12979. (vhdl-scan-directory-contents file-name project t)
  12980. (when (or (and vhdl-speedbar-show-projects project)
  12981. (and (not vhdl-speedbar-show-projects) (not project)))
  12982. (vhdl-speedbar-refresh project))
  12983. (setq updated t)))
  12984. (setq directory-alist (cdr directory-alist)))
  12985. updated))
  12986. (defun vhdl-update-hierarchy ()
  12987. "Update directory and hierarchy information in speedbar."
  12988. (let ((file-list (reverse vhdl-modified-file-list))
  12989. updated)
  12990. (when (and vhdl-speedbar-update-on-saving file-list)
  12991. (while file-list
  12992. (setq updated
  12993. (or (vhdl-update-file-contents (car file-list))
  12994. updated))
  12995. (setq file-list (cdr file-list)))
  12996. (setq vhdl-modified-file-list nil)
  12997. (vhdl-speedbar-update-current-unit)
  12998. (when updated (message "Updating hierarchy...done")))))
  12999. ;; structure (parenthesized expression means list of such entries)
  13000. ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
  13001. ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
  13002. ;; comp-lib-name level)
  13003. (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
  13004. conf-inst-alist level indent
  13005. &optional include-top ent-hier)
  13006. "Get instantiation hierarchy beginning in architecture ARCH-KEY of
  13007. entity ENT-KEY."
  13008. (let* ((ent-entry (aget ent-alist ent-key t))
  13009. (arch-entry (if arch-key (aget (nth 3 ent-entry) arch-key t)
  13010. (cdar (last (nth 3 ent-entry)))))
  13011. (inst-alist (nth 3 arch-entry))
  13012. inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
  13013. hier-list subcomp-list tmp-list inst-key inst-comp-name
  13014. inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
  13015. (when (= level 0) (message "Extract design hierarchy..."))
  13016. (when include-top
  13017. (setq level (1+ level)))
  13018. (when (member ent-key ent-hier)
  13019. (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
  13020. ;; check configured architecture (already checked during scanning)
  13021. ; (unless (or (null conf-inst-alist) (assoc arch-key (nth 3 ent-entry)))
  13022. ; (vhdl-warning-when-idle "Configuration for non-existing architecture used: \"%s\"" conf-key))
  13023. ;; process all instances
  13024. (while inst-alist
  13025. (setq inst-entry (car inst-alist)
  13026. inst-key (nth 0 inst-entry)
  13027. inst-comp-name (nth 4 inst-entry)
  13028. inst-conf-key (nth 7 inst-entry))
  13029. ;; search entry in configuration's instantiations list
  13030. (setq tmp-list conf-inst-alist)
  13031. (while (and tmp-list
  13032. (not (and (member (nth 0 (car tmp-list))
  13033. (list "all" inst-key))
  13034. (equal (nth 1 (car tmp-list))
  13035. (downcase (or inst-comp-name ""))))))
  13036. (setq tmp-list (cdr tmp-list)))
  13037. (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
  13038. (setq inst-conf-entry (aget conf-alist inst-conf-key t))
  13039. (when (and inst-conf-key (not inst-conf-entry))
  13040. (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
  13041. ;; determine entity
  13042. (setq inst-ent-key
  13043. (or (nth 2 (car tmp-list)) ; from configuration
  13044. (nth 3 inst-conf-entry) ; from subconfiguration
  13045. (nth 3 (aget conf-alist (nth 7 inst-entry) t))
  13046. ; from configuration spec.
  13047. (nth 5 inst-entry))) ; from direct instantiation
  13048. (setq inst-ent-entry (aget ent-alist inst-ent-key t))
  13049. ;; determine architecture
  13050. (setq inst-arch-key
  13051. (or (nth 3 (car tmp-list)) ; from configuration
  13052. (nth 4 inst-conf-entry) ; from subconfiguration
  13053. (nth 6 inst-entry) ; from direct instantiation
  13054. (nth 4 (aget conf-alist (nth 7 inst-entry)))
  13055. ; from configuration spec.
  13056. (nth 4 inst-ent-entry) ; MRA
  13057. (caar (nth 3 inst-ent-entry)))) ; first alphabetically
  13058. (setq inst-arch-entry (aget (nth 3 inst-ent-entry) inst-arch-key t))
  13059. ;; set library
  13060. (setq inst-lib-key
  13061. (or (nth 5 (car tmp-list)) ; from configuration
  13062. (nth 8 inst-entry))) ; from direct instantiation
  13063. ;; gather information for this instance
  13064. (setq comp-entry
  13065. (list (nth 1 inst-entry)
  13066. (cons (nth 2 inst-entry) (nth 3 inst-entry))
  13067. (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
  13068. (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
  13069. (or (nth 0 inst-arch-entry) inst-arch-key)
  13070. (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
  13071. (or (nth 0 inst-conf-entry) inst-conf-key)
  13072. (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
  13073. inst-lib-key level))
  13074. ;; get subcomponent hierarchy
  13075. (setq subcomp-list (vhdl-get-hierarchy
  13076. ent-alist conf-alist
  13077. inst-ent-key inst-arch-key inst-conf-key
  13078. (nth 5 inst-conf-entry)
  13079. (1+ level) indent nil (cons ent-key ent-hier)))
  13080. ;; add to list
  13081. (setq hier-list (append hier-list (list comp-entry) subcomp-list))
  13082. (setq inst-alist (cdr inst-alist)))
  13083. (when include-top
  13084. (setq hier-list
  13085. (cons (list nil nil (nth 0 ent-entry)
  13086. (cons (nth 1 ent-entry) (nth 2 ent-entry))
  13087. (nth 0 arch-entry)
  13088. (cons (nth 1 arch-entry) (nth 2 arch-entry))
  13089. nil nil
  13090. nil (1- level))
  13091. hier-list)))
  13092. (when (or (= level 0) (and include-top (= level 1))) (message ""))
  13093. hier-list))
  13094. (defun vhdl-get-instantiations (ent-key indent)
  13095. "Get all instantiations of entity ENT-KEY."
  13096. (let ((ent-alist (aget vhdl-entity-alist (vhdl-speedbar-line-key indent) t))
  13097. arch-alist inst-alist ent-inst-list
  13098. ent-entry arch-entry inst-entry)
  13099. (while ent-alist
  13100. (setq ent-entry (car ent-alist))
  13101. (setq arch-alist (nth 4 ent-entry))
  13102. (while arch-alist
  13103. (setq arch-entry (car arch-alist))
  13104. (setq inst-alist (nth 4 arch-entry))
  13105. (while inst-alist
  13106. (setq inst-entry (car inst-alist))
  13107. (when (equal ent-key (nth 5 inst-entry))
  13108. (setq ent-inst-list
  13109. (cons (list (nth 1 inst-entry)
  13110. (cons (nth 2 inst-entry) (nth 3 inst-entry))
  13111. (nth 1 ent-entry)
  13112. (cons (nth 2 ent-entry) (nth 3 ent-entry))
  13113. (nth 1 arch-entry)
  13114. (cons (nth 2 arch-entry) (nth 3 arch-entry)))
  13115. ent-inst-list)))
  13116. (setq inst-alist (cdr inst-alist)))
  13117. (setq arch-alist (cdr arch-alist)))
  13118. (setq ent-alist (cdr ent-alist)))
  13119. (nreverse ent-inst-list)))
  13120. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  13121. ;; Caching in file
  13122. (defun vhdl-save-caches ()
  13123. "Save all updated hierarchy caches to file."
  13124. (interactive)
  13125. (condition-case nil
  13126. (when vhdl-speedbar-save-cache
  13127. ;; update hierarchy
  13128. (vhdl-update-hierarchy)
  13129. (let ((project-list vhdl-updated-project-list))
  13130. (message "Saving hierarchy caches...")
  13131. ;; write updated project caches
  13132. (while project-list
  13133. (vhdl-save-cache (car project-list))
  13134. (setq project-list (cdr project-list)))
  13135. (message "Saving hierarchy caches...done")))
  13136. (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
  13137. (sit-for 2)))))
  13138. (defun vhdl-save-cache (key)
  13139. "Save current hierarchy cache to file."
  13140. (let* ((orig-buffer (current-buffer))
  13141. (vhdl-project key)
  13142. (project (vhdl-project-p))
  13143. (default-directory key)
  13144. (directory (abbreviate-file-name (vhdl-default-directory)))
  13145. (file-name (vhdl-resolve-env-variable
  13146. (vhdl-replace-string
  13147. (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
  13148. (concat
  13149. (subst-char-in-string ? ?_ (or project "dir"))
  13150. " " (user-login-name)))))
  13151. (file-dir-name (expand-file-name file-name directory))
  13152. (cache-key (or project directory))
  13153. (key (if project "project" "directory")))
  13154. (unless (file-exists-p (file-name-directory file-dir-name))
  13155. (make-directory (file-name-directory file-dir-name) t))
  13156. (if (not (file-writable-p file-dir-name))
  13157. (progn (vhdl-warning (format "File not writable: \"%s\""
  13158. (abbreviate-file-name file-dir-name)))
  13159. (sit-for 2))
  13160. (message "Saving cache: \"%s\"" file-dir-name)
  13161. (set-buffer (find-file-noselect file-dir-name t t))
  13162. (erase-buffer)
  13163. (insert ";; -*- Emacs-Lisp -*-\n\n"
  13164. ";;; " (file-name-nondirectory file-name)
  13165. " - design hierarchy cache file for Emacs VHDL Mode "
  13166. vhdl-version "\n")
  13167. (insert "\n;; " (if project "Project " "Directory") " : ")
  13168. (if project (insert project) (prin1 directory (current-buffer)))
  13169. (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
  13170. (user-login-name) "\n\n"
  13171. "\n;; version number\n"
  13172. "(setq vhdl-cache-version \"" vhdl-version "\")\n"
  13173. "\n;; " (if project "project" "directory") " name"
  13174. "\n(setq " key " ")
  13175. (prin1 (or project directory) (current-buffer))
  13176. (insert ")\n")
  13177. (when (member 'hierarchy vhdl-speedbar-save-cache)
  13178. (insert "\n;; entity and architecture cache\n"
  13179. "(aput 'vhdl-entity-alist " key " '")
  13180. (print (aget vhdl-entity-alist cache-key t) (current-buffer))
  13181. (insert ")\n\n;; configuration cache\n"
  13182. "(aput 'vhdl-config-alist " key " '")
  13183. (print (aget vhdl-config-alist cache-key t) (current-buffer))
  13184. (insert ")\n\n;; package cache\n"
  13185. "(aput 'vhdl-package-alist " key " '")
  13186. (print (aget vhdl-package-alist cache-key t) (current-buffer))
  13187. (insert ")\n\n;; instantiated entities cache\n"
  13188. "(aput 'vhdl-ent-inst-alist " key " '")
  13189. (print (aget vhdl-ent-inst-alist cache-key t) (current-buffer))
  13190. (insert ")\n\n;; design units per file cache\n"
  13191. "(aput 'vhdl-file-alist " key " '")
  13192. (print (aget vhdl-file-alist cache-key t) (current-buffer))
  13193. (when project
  13194. (insert ")\n\n;; source directories in project cache\n"
  13195. "(aput 'vhdl-directory-alist " key " '")
  13196. (print (aget vhdl-directory-alist cache-key t) (current-buffer)))
  13197. (insert ")\n"))
  13198. (when (member 'display vhdl-speedbar-save-cache)
  13199. (insert "\n;; shown design units cache\n"
  13200. "(aput 'vhdl-speedbar-shown-unit-alist " key " '")
  13201. (print (aget vhdl-speedbar-shown-unit-alist cache-key t)
  13202. (current-buffer))
  13203. (insert ")\n"))
  13204. (setq vhdl-updated-project-list
  13205. (delete cache-key vhdl-updated-project-list))
  13206. (save-buffer)
  13207. (kill-buffer (current-buffer))
  13208. (set-buffer orig-buffer))))
  13209. (defun vhdl-load-cache (key)
  13210. "Load hierarchy cache information from file."
  13211. (let* ((vhdl-project key)
  13212. (default-directory key)
  13213. (directory (vhdl-default-directory))
  13214. (file-name (vhdl-resolve-env-variable
  13215. (vhdl-replace-string
  13216. (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
  13217. (concat
  13218. (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
  13219. " " (user-login-name)))))
  13220. (file-dir-name (expand-file-name file-name directory))
  13221. vhdl-cache-version)
  13222. (unless (memq 'vhdl-save-caches kill-emacs-hook)
  13223. (add-hook 'kill-emacs-hook 'vhdl-save-caches))
  13224. (when (file-exists-p file-dir-name)
  13225. (condition-case ()
  13226. (progn (load-file file-dir-name)
  13227. (string< (mapconcat
  13228. (lambda (a) (format "%3d" (string-to-number a)))
  13229. (split-string "3.33" "\\.") "")
  13230. (mapconcat
  13231. (lambda (a) (format "%3d" (string-to-number a)))
  13232. (split-string vhdl-cache-version "\\.") "")))
  13233. (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
  13234. nil))))))
  13235. (defun vhdl-require-hierarchy-info ()
  13236. "Make sure that hierarchy information is available. Load cache or scan files
  13237. if required."
  13238. (if (vhdl-project-p)
  13239. (unless (or (assoc vhdl-project vhdl-file-alist)
  13240. (vhdl-load-cache vhdl-project))
  13241. (vhdl-scan-project-contents vhdl-project))
  13242. (let ((directory (abbreviate-file-name default-directory)))
  13243. (unless (or (assoc directory vhdl-file-alist)
  13244. (vhdl-load-cache directory))
  13245. (vhdl-scan-directory-contents directory)))))
  13246. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  13247. ;; Add hierarchy browser functionality to speedbar
  13248. (defvar vhdl-speedbar-key-map nil
  13249. "Keymap used when in the VHDL hierarchy browser mode.")
  13250. (defvar vhdl-speedbar-menu-items nil
  13251. "Additional menu-items to add to speedbar frame.")
  13252. (defun vhdl-speedbar-initialize ()
  13253. "Initialize speedbar."
  13254. ;; general settings
  13255. ; (set (make-local-variable 'speedbar-tag-hierarchy-method) nil)
  13256. ;; VHDL file extensions (extracted from `auto-mode-alist')
  13257. (let ((mode-alist auto-mode-alist))
  13258. (while mode-alist
  13259. (when (eq (cdar mode-alist) 'vhdl-mode)
  13260. (speedbar-add-supported-extension (caar mode-alist)))
  13261. (setq mode-alist (cdr mode-alist))))
  13262. ;; hierarchy browser settings
  13263. (when (boundp 'speedbar-mode-functions-list)
  13264. ;; special functions
  13265. (speedbar-add-mode-functions-list
  13266. '("vhdl directory"
  13267. (speedbar-item-info . vhdl-speedbar-item-info)
  13268. (speedbar-line-directory . speedbar-files-line-path)))
  13269. (speedbar-add-mode-functions-list
  13270. '("vhdl project"
  13271. (speedbar-item-info . vhdl-speedbar-item-info)
  13272. (speedbar-line-directory . vhdl-speedbar-line-project)))
  13273. ;; keymap
  13274. (unless vhdl-speedbar-key-map
  13275. (setq vhdl-speedbar-key-map (speedbar-make-specialized-keymap))
  13276. (define-key vhdl-speedbar-key-map "e" 'speedbar-edit-line)
  13277. (define-key vhdl-speedbar-key-map "\C-m" 'speedbar-edit-line)
  13278. (define-key vhdl-speedbar-key-map "+" 'speedbar-expand-line)
  13279. (define-key vhdl-speedbar-key-map "=" 'speedbar-expand-line)
  13280. (define-key vhdl-speedbar-key-map "-" 'vhdl-speedbar-contract-level)
  13281. (define-key vhdl-speedbar-key-map "_" 'vhdl-speedbar-contract-all)
  13282. (define-key vhdl-speedbar-key-map "C" 'vhdl-speedbar-port-copy)
  13283. (define-key vhdl-speedbar-key-map "P" 'vhdl-speedbar-place-component)
  13284. (define-key vhdl-speedbar-key-map "F" 'vhdl-speedbar-configuration)
  13285. (define-key vhdl-speedbar-key-map "A" 'vhdl-speedbar-select-mra)
  13286. (define-key vhdl-speedbar-key-map "K" 'vhdl-speedbar-make-design)
  13287. (define-key vhdl-speedbar-key-map "R" 'vhdl-speedbar-rescan-hierarchy)
  13288. (define-key vhdl-speedbar-key-map "S" 'vhdl-save-caches)
  13289. (let ((key 0))
  13290. (while (<= key 9)
  13291. (define-key vhdl-speedbar-key-map (int-to-string key)
  13292. `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
  13293. (setq key (1+ key)))))
  13294. (define-key speedbar-key-map "h"
  13295. (lambda () (interactive)
  13296. (speedbar-change-initial-expansion-list "vhdl directory")))
  13297. (define-key speedbar-key-map "H"
  13298. (lambda () (interactive)
  13299. (speedbar-change-initial-expansion-list "vhdl project")))
  13300. ;; menu
  13301. (unless vhdl-speedbar-menu-items
  13302. (setq
  13303. vhdl-speedbar-menu-items
  13304. `(["Edit" speedbar-edit-line t]
  13305. ["Expand" speedbar-expand-line
  13306. (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
  13307. ["Contract" vhdl-speedbar-contract-level t]
  13308. ["Expand All" vhdl-speedbar-expand-all t]
  13309. ["Contract All" vhdl-speedbar-contract-all t]
  13310. ,(let ((key 0) (menu-list '("Hierarchy Depth")))
  13311. (while (<= key 9)
  13312. (setq menu-list
  13313. (cons `[,(if (= key 0) "All" (int-to-string key))
  13314. (vhdl-speedbar-set-depth ,key)
  13315. :style radio
  13316. :selected (= vhdl-speedbar-hierarchy-depth ,key)
  13317. :keys ,(int-to-string key)]
  13318. menu-list))
  13319. (setq key (1+ key)))
  13320. (nreverse menu-list))
  13321. "--"
  13322. ["Copy Port/Subprogram" vhdl-speedbar-port-copy
  13323. (or (vhdl-speedbar-check-unit 'entity)
  13324. (vhdl-speedbar-check-unit 'subprogram))]
  13325. ["Place Component" vhdl-speedbar-place-component
  13326. (vhdl-speedbar-check-unit 'entity)]
  13327. ["Generate Configuration" vhdl-speedbar-configuration
  13328. (vhdl-speedbar-check-unit 'architecture)]
  13329. ["Select as MRA" vhdl-speedbar-select-mra
  13330. (vhdl-speedbar-check-unit 'architecture)]
  13331. ["Make" vhdl-speedbar-make-design
  13332. (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
  13333. ["Generate Makefile" vhdl-speedbar-generate-makefile
  13334. (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
  13335. ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
  13336. :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
  13337. ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
  13338. ["Rescan Project" vhdl-speedbar-rescan-hierarchy
  13339. :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
  13340. ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
  13341. ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
  13342. ;; hook-ups
  13343. (speedbar-add-expansion-list
  13344. '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-key-map
  13345. vhdl-speedbar-display-directory))
  13346. (speedbar-add-expansion-list
  13347. '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-key-map
  13348. vhdl-speedbar-display-projects))
  13349. (setq speedbar-stealthy-function-list
  13350. (append
  13351. '(("vhdl directory" vhdl-speedbar-update-current-unit)
  13352. ("vhdl project" vhdl-speedbar-update-current-project
  13353. vhdl-speedbar-update-current-unit)
  13354. ; ("files" (lambda () (setq speedbar-ignored-path-regexp
  13355. ; (speedbar-extension-list-to-regex
  13356. ; speedbar-ignored-path-expressions))))
  13357. )
  13358. speedbar-stealthy-function-list))
  13359. (when (eq vhdl-speedbar-display-mode 'directory)
  13360. (setq speedbar-initial-expansion-list-name "vhdl directory"))
  13361. (when (eq vhdl-speedbar-display-mode 'project)
  13362. (setq speedbar-initial-expansion-list-name "vhdl project"))
  13363. (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
  13364. (defun vhdl-speedbar (&optional arg)
  13365. "Open/close speedbar."
  13366. (interactive)
  13367. (if (not (fboundp 'speedbar))
  13368. (error "WARNING: Speedbar is not available or not installed")
  13369. (condition-case ()
  13370. (speedbar-frame-mode arg)
  13371. (error (error "WARNING: An error occurred while opening speedbar")))))
  13372. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  13373. ;; Display functions
  13374. (defvar vhdl-speedbar-last-selected-project nil
  13375. "Name of last selected project.")
  13376. ;; macros must be defined in the file they are used (copied from `speedbar.el')
  13377. (defmacro speedbar-with-writable (&rest forms)
  13378. "Allow the buffer to be writable and evaluate FORMS."
  13379. (list 'let '((inhibit-read-only t))
  13380. (cons 'progn forms)))
  13381. (put 'speedbar-with-writable 'lisp-indent-function 0)
  13382. (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
  13383. "Display directory and hierarchy information in speedbar."
  13384. (setq vhdl-speedbar-show-projects nil)
  13385. (setq speedbar-ignored-directory-regexp
  13386. (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
  13387. (setq directory (abbreviate-file-name (file-name-as-directory directory)))
  13388. (setq speedbar-last-selected-file nil)
  13389. (speedbar-with-writable
  13390. (condition-case nil
  13391. (progn
  13392. ;; insert directory path
  13393. (speedbar-directory-buttons directory depth)
  13394. ;; insert subdirectories
  13395. (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
  13396. ;; scan and insert hierarchy of current directory
  13397. (vhdl-speedbar-insert-dir-hierarchy directory depth
  13398. speedbar-power-click)
  13399. ;; expand subdirectories
  13400. (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
  13401. (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
  13402. (defun vhdl-speedbar-display-projects (project depth &optional rescan)
  13403. "Display projects and hierarchy information in speedbar."
  13404. (setq vhdl-speedbar-show-projects t)
  13405. (setq speedbar-ignored-directory-regexp ".")
  13406. (setq speedbar-last-selected-file nil)
  13407. (setq vhdl-speedbar-last-selected-project nil)
  13408. (speedbar-with-writable
  13409. (condition-case nil
  13410. ;; insert projects
  13411. (vhdl-speedbar-insert-projects)
  13412. (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
  13413. (setq speedbar-full-text-cache nil)) ; prevent caching
  13414. (defun vhdl-speedbar-insert-projects ()
  13415. "Insert all projects in speedbar."
  13416. (vhdl-speedbar-make-title-line "Projects:")
  13417. (let ((project-alist (if vhdl-project-sort
  13418. (vhdl-sort-alist (copy-alist vhdl-project-alist))
  13419. vhdl-project-alist))
  13420. (vhdl-speedbar-update-current-unit nil))
  13421. ;; insert projects
  13422. (while project-alist
  13423. (speedbar-make-tag-line
  13424. 'angle ?+ 'vhdl-speedbar-expand-project
  13425. (caar project-alist) (caar project-alist)
  13426. 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
  13427. (setq project-alist (cdr project-alist)))
  13428. (setq project-alist vhdl-project-alist)
  13429. ;; expand projects
  13430. (while project-alist
  13431. (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
  13432. (goto-char (point-min))
  13433. (when (re-search-forward
  13434. (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
  13435. (goto-char (match-end 1))
  13436. (speedbar-do-function-pointer)))
  13437. (setq project-alist (cdr project-alist))))
  13438. ; (vhdl-speedbar-update-current-project)
  13439. ; (vhdl-speedbar-update-current-unit nil t)
  13440. )
  13441. (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
  13442. "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
  13443. otherwise use cached data."
  13444. (when (or rescan (and (not (assoc project vhdl-file-alist))
  13445. (not (vhdl-load-cache project))))
  13446. (vhdl-scan-project-contents project))
  13447. ;; insert design hierarchy
  13448. (vhdl-speedbar-insert-hierarchy
  13449. (aget vhdl-entity-alist project t)
  13450. (aget vhdl-config-alist project t)
  13451. (aget vhdl-package-alist project t)
  13452. (car (aget vhdl-ent-inst-alist project t)) indent)
  13453. (insert (int-to-string indent) ":\n")
  13454. (put-text-property (- (point) 3) (1- (point)) 'invisible t)
  13455. (put-text-property (1- (point)) (point) 'invisible nil)
  13456. ;; expand design units
  13457. (vhdl-speedbar-expand-units project))
  13458. (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
  13459. "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
  13460. otherwise use cached data."
  13461. (when (or rescan (and (not (assoc directory vhdl-file-alist))
  13462. (not (vhdl-load-cache directory))))
  13463. (vhdl-scan-directory-contents directory))
  13464. ;; insert design hierarchy
  13465. (vhdl-speedbar-insert-hierarchy
  13466. (aget vhdl-entity-alist directory t)
  13467. (aget vhdl-config-alist directory t)
  13468. (aget vhdl-package-alist directory t)
  13469. (car (aget vhdl-ent-inst-alist directory t)) depth)
  13470. ;; expand design units
  13471. (vhdl-speedbar-expand-units directory)
  13472. (aput 'vhdl-directory-alist directory (list (list directory))))
  13473. (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
  13474. ent-inst-list depth)
  13475. "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
  13476. (if (not (or ent-alist conf-alist pack-alist))
  13477. (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
  13478. (let (ent-entry conf-entry pack-entry)
  13479. ;; insert entities
  13480. (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
  13481. (while ent-alist
  13482. (setq ent-entry (car ent-alist))
  13483. (speedbar-make-tag-line
  13484. 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
  13485. (nth 1 ent-entry) 'vhdl-speedbar-find-file
  13486. (cons (nth 2 ent-entry) (nth 3 ent-entry))
  13487. 'vhdl-speedbar-entity-face depth)
  13488. (unless (nth 2 ent-entry)
  13489. (end-of-line 0) (insert "!") (forward-char 1))
  13490. (unless (member (nth 0 ent-entry) ent-inst-list)
  13491. (end-of-line 0) (insert " (top)") (forward-char 1))
  13492. (setq ent-alist (cdr ent-alist)))
  13493. ;; insert configurations
  13494. (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
  13495. (while conf-alist
  13496. (setq conf-entry (car conf-alist))
  13497. (speedbar-make-tag-line
  13498. 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
  13499. (nth 1 conf-entry) 'vhdl-speedbar-find-file
  13500. (cons (nth 2 conf-entry) (nth 3 conf-entry))
  13501. 'vhdl-speedbar-configuration-face depth)
  13502. (setq conf-alist (cdr conf-alist)))
  13503. ;; insert packages
  13504. (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
  13505. (while pack-alist
  13506. (setq pack-entry (car pack-alist))
  13507. (vhdl-speedbar-make-pack-line
  13508. (nth 0 pack-entry) (nth 1 pack-entry)
  13509. (cons (nth 2 pack-entry) (nth 3 pack-entry))
  13510. (cons (nth 7 pack-entry) (nth 8 pack-entry))
  13511. depth)
  13512. (setq pack-alist (cdr pack-alist))))))
  13513. (defun vhdl-speedbar-rescan-hierarchy ()
  13514. "Rescan hierarchy for the directory or project under the cursor."
  13515. (interactive)
  13516. (let (key path)
  13517. (cond
  13518. ;; current project
  13519. (vhdl-speedbar-show-projects
  13520. (setq key (vhdl-speedbar-line-project))
  13521. (vhdl-scan-project-contents key))
  13522. ;; top-level directory
  13523. ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
  13524. (re-search-forward "[0-9]+:" nil t)
  13525. (vhdl-scan-directory-contents
  13526. (abbreviate-file-name (speedbar-line-directory))))
  13527. ;; current directory
  13528. (t (setq path (speedbar-line-directory))
  13529. (string-match "^\\(.+[/\\]\\)" path)
  13530. (vhdl-scan-directory-contents
  13531. (abbreviate-file-name (match-string 1 path)))))
  13532. (vhdl-speedbar-refresh key)))
  13533. (defun vhdl-speedbar-expand-dirs (directory)
  13534. "Expand subdirectories in DIRECTORY according to
  13535. `speedbar-shown-directories'."
  13536. ;; (nicked from `speedbar-default-directory-list')
  13537. (let ((sf (cdr (reverse speedbar-shown-directories)))
  13538. (vhdl-speedbar-update-current-unit nil))
  13539. (setq speedbar-shown-directories
  13540. (list (expand-file-name default-directory)))
  13541. (while sf
  13542. (when (speedbar-goto-this-file (car sf))
  13543. (beginning-of-line)
  13544. (when (looking-at "[0-9]+:\\s-*<")
  13545. (goto-char (match-end 0))
  13546. (speedbar-do-function-pointer)))
  13547. (setq sf (cdr sf))))
  13548. (vhdl-speedbar-update-current-unit nil t))
  13549. (defun vhdl-speedbar-expand-units (key)
  13550. "Expand design units in directory/project KEY according to
  13551. `vhdl-speedbar-shown-unit-alist'."
  13552. (let ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
  13553. (vhdl-speedbar-update-current-unit nil)
  13554. vhdl-updated-project-list)
  13555. (adelete 'vhdl-speedbar-shown-unit-alist key)
  13556. (vhdl-prepare-search-1
  13557. (while unit-alist ; expand units
  13558. (vhdl-speedbar-goto-this-unit key (caar unit-alist))
  13559. (beginning-of-line)
  13560. (let ((arch-alist (nth 1 (car unit-alist)))
  13561. position)
  13562. (when (looking-at "^[0-9]+:\\s-*\\[")
  13563. (goto-char (match-end 0))
  13564. (setq position (point))
  13565. (speedbar-do-function-pointer)
  13566. (select-frame speedbar-frame)
  13567. (while arch-alist ; expand architectures
  13568. (goto-char position)
  13569. (when (re-search-forward
  13570. (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
  13571. (car arch-alist) "\\>\\)") nil t)
  13572. (beginning-of-line)
  13573. (when (looking-at "^[0-9]+:\\s-*{")
  13574. (goto-char (match-end 0))
  13575. (speedbar-do-function-pointer)
  13576. (select-frame speedbar-frame)))
  13577. (setq arch-alist (cdr arch-alist))))
  13578. (setq unit-alist (cdr unit-alist))))))
  13579. (vhdl-speedbar-update-current-unit nil t))
  13580. (defun vhdl-speedbar-contract-level ()
  13581. "Contract current level in current directory/project."
  13582. (interactive)
  13583. (when (or (save-excursion
  13584. (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
  13585. (and (save-excursion
  13586. (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
  13587. (re-search-backward
  13588. (format "^[0-%d]:\\s-*[[{<]-"
  13589. (max (1- (string-to-number (match-string 1))) 0)) nil t)))
  13590. (goto-char (match-end 0))
  13591. (speedbar-do-function-pointer)
  13592. (speedbar-center-buffer-smartly)))
  13593. (defun vhdl-speedbar-contract-all ()
  13594. "Contract all expanded design units in current directory/project."
  13595. (interactive)
  13596. (if (and vhdl-speedbar-show-projects
  13597. (save-excursion (beginning-of-line) (looking-at "^0:")))
  13598. (progn (setq vhdl-speedbar-shown-project-list nil)
  13599. (vhdl-speedbar-refresh))
  13600. (let ((key (vhdl-speedbar-line-key)))
  13601. (adelete 'vhdl-speedbar-shown-unit-alist key)
  13602. (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
  13603. (when (memq 'display vhdl-speedbar-save-cache)
  13604. (add-to-list 'vhdl-updated-project-list key)))))
  13605. (defun vhdl-speedbar-expand-all ()
  13606. "Expand all design units in current directory/project."
  13607. (interactive)
  13608. (let* ((key (vhdl-speedbar-line-key))
  13609. (ent-alist (aget vhdl-entity-alist key t))
  13610. (conf-alist (aget vhdl-config-alist key t))
  13611. (pack-alist (aget vhdl-package-alist key t))
  13612. arch-alist unit-alist subunit-alist)
  13613. (add-to-list 'vhdl-speedbar-shown-project-list key)
  13614. (while ent-alist
  13615. (setq arch-alist (nth 4 (car ent-alist)))
  13616. (setq subunit-alist nil)
  13617. (while arch-alist
  13618. (setq subunit-alist (cons (caar arch-alist) subunit-alist))
  13619. (setq arch-alist (cdr arch-alist)))
  13620. (setq unit-alist (cons (list (caar ent-alist) subunit-alist) unit-alist))
  13621. (setq ent-alist (cdr ent-alist)))
  13622. (while conf-alist
  13623. (setq unit-alist (cons (list (caar conf-alist)) unit-alist))
  13624. (setq conf-alist (cdr conf-alist)))
  13625. (while pack-alist
  13626. (setq unit-alist (cons (list (caar pack-alist)) unit-alist))
  13627. (setq pack-alist (cdr pack-alist)))
  13628. (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
  13629. (vhdl-speedbar-refresh)
  13630. (when (memq 'display vhdl-speedbar-save-cache)
  13631. (add-to-list 'vhdl-updated-project-list key))))
  13632. (defun vhdl-speedbar-expand-project (text token indent)
  13633. "Expand/contract the project under the cursor."
  13634. (cond
  13635. ((string-match "+" text) ; expand project
  13636. (speedbar-change-expand-button-char ?-)
  13637. (unless (member token vhdl-speedbar-shown-project-list)
  13638. (setq vhdl-speedbar-shown-project-list
  13639. (cons token vhdl-speedbar-shown-project-list)))
  13640. (speedbar-with-writable
  13641. (save-excursion
  13642. (end-of-line) (forward-char 1)
  13643. (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
  13644. speedbar-power-click))))
  13645. ((string-match "-" text) ; contract project
  13646. (speedbar-change-expand-button-char ?+)
  13647. (setq vhdl-speedbar-shown-project-list
  13648. (delete token vhdl-speedbar-shown-project-list))
  13649. (speedbar-delete-subblock indent))
  13650. (t (error "Nothing to display")))
  13651. (when (equal (selected-frame) speedbar-frame)
  13652. (speedbar-center-buffer-smartly)))
  13653. (defun vhdl-speedbar-expand-entity (text token indent)
  13654. "Expand/contract the entity under the cursor."
  13655. (cond
  13656. ((string-match "+" text) ; expand entity
  13657. (let* ((key (vhdl-speedbar-line-key indent))
  13658. (ent-alist (aget vhdl-entity-alist key t))
  13659. (ent-entry (aget ent-alist token t))
  13660. (arch-alist (nth 3 ent-entry))
  13661. (inst-alist (vhdl-get-instantiations token indent))
  13662. (subpack-alist (nth 5 ent-entry))
  13663. (multiple-arch (> (length arch-alist) 1))
  13664. arch-entry inst-entry)
  13665. (if (not (or arch-alist inst-alist subpack-alist))
  13666. (speedbar-change-expand-button-char ??)
  13667. (speedbar-change-expand-button-char ?-)
  13668. ;; add entity to `vhdl-speedbar-shown-unit-alist'
  13669. (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
  13670. (aput 'unit-alist token nil)
  13671. (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
  13672. (speedbar-with-writable
  13673. (save-excursion
  13674. (end-of-line) (forward-char 1)
  13675. ;; insert architectures
  13676. (when arch-alist
  13677. (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
  13678. (while arch-alist
  13679. (setq arch-entry (car arch-alist))
  13680. (speedbar-make-tag-line
  13681. 'curly ?+ 'vhdl-speedbar-expand-architecture
  13682. (cons token (nth 0 arch-entry))
  13683. (nth 1 arch-entry) 'vhdl-speedbar-find-file
  13684. (cons (nth 2 arch-entry) (nth 3 arch-entry))
  13685. 'vhdl-speedbar-architecture-face (1+ indent))
  13686. (when (and multiple-arch
  13687. (equal (nth 0 arch-entry) (nth 4 ent-entry)))
  13688. (end-of-line 0) (insert " (mra)") (forward-char 1))
  13689. (setq arch-alist (cdr arch-alist)))
  13690. ;; insert instantiations
  13691. (when inst-alist
  13692. (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
  13693. (while inst-alist
  13694. (setq inst-entry (car inst-alist))
  13695. (vhdl-speedbar-make-inst-line
  13696. (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
  13697. (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
  13698. nil nil nil (1+ indent) 0 " in ")
  13699. (setq inst-alist (cdr inst-alist)))
  13700. ;; insert required packages
  13701. (vhdl-speedbar-insert-subpackages
  13702. subpack-alist (1+ indent) indent)))
  13703. (when (memq 'display vhdl-speedbar-save-cache)
  13704. (add-to-list 'vhdl-updated-project-list key))
  13705. (vhdl-speedbar-update-current-unit t t))))
  13706. ((string-match "-" text) ; contract entity
  13707. (speedbar-change-expand-button-char ?+)
  13708. ;; remove entity from `vhdl-speedbar-shown-unit-alist'
  13709. (let* ((key (vhdl-speedbar-line-key indent))
  13710. (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
  13711. (adelete 'unit-alist token)
  13712. (if unit-alist
  13713. (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
  13714. (adelete 'vhdl-speedbar-shown-unit-alist key))
  13715. (speedbar-delete-subblock indent)
  13716. (when (memq 'display vhdl-speedbar-save-cache)
  13717. (add-to-list 'vhdl-updated-project-list key))))
  13718. (t (error "Nothing to display")))
  13719. (when (equal (selected-frame) speedbar-frame)
  13720. (speedbar-center-buffer-smartly)))
  13721. (defun vhdl-speedbar-expand-architecture (text token indent)
  13722. "Expand/contract the architecture under the cursor."
  13723. (cond
  13724. ((string-match "+" text) ; expand architecture
  13725. (let* ((key (vhdl-speedbar-line-key (1- indent)))
  13726. (ent-alist (aget vhdl-entity-alist key t))
  13727. (conf-alist (aget vhdl-config-alist key t))
  13728. (hier-alist (vhdl-get-hierarchy
  13729. ent-alist conf-alist (car token) (cdr token) nil nil
  13730. 0 (1- indent)))
  13731. (ent-entry (aget ent-alist (car token) t))
  13732. (arch-entry (aget (nth 3 ent-entry) (cdr token) t))
  13733. (subpack-alist (nth 4 arch-entry))
  13734. entry)
  13735. (if (not (or hier-alist subpack-alist))
  13736. (speedbar-change-expand-button-char ??)
  13737. (speedbar-change-expand-button-char ?-)
  13738. ;; add architecture to `vhdl-speedbar-shown-unit-alist'
  13739. (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
  13740. (arch-alist (nth 0 (aget unit-alist (car token) t))))
  13741. (aput 'unit-alist (car token) (list (cons (cdr token) arch-alist)))
  13742. (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
  13743. (speedbar-with-writable
  13744. (save-excursion
  13745. (end-of-line) (forward-char 1)
  13746. ;; insert instance hierarchy
  13747. (when hier-alist
  13748. (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
  13749. (1+ indent)))
  13750. (while hier-alist
  13751. (setq entry (car hier-alist))
  13752. (when (or (= vhdl-speedbar-hierarchy-depth 0)
  13753. (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
  13754. (vhdl-speedbar-make-inst-line
  13755. (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
  13756. (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
  13757. (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
  13758. (setq hier-alist (cdr hier-alist)))
  13759. ;; insert required packages
  13760. (vhdl-speedbar-insert-subpackages
  13761. subpack-alist (1+ indent) (1- indent))))
  13762. (when (memq 'display vhdl-speedbar-save-cache)
  13763. (add-to-list 'vhdl-updated-project-list key))
  13764. (vhdl-speedbar-update-current-unit t t))))
  13765. ((string-match "-" text) ; contract architecture
  13766. (speedbar-change-expand-button-char ?+)
  13767. ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
  13768. (let* ((key (vhdl-speedbar-line-key (1- indent)))
  13769. (unit-alist (aget vhdl-speedbar-shown-unit-alist key t))
  13770. (arch-alist (nth 0 (aget unit-alist (car token) t))))
  13771. (aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
  13772. (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
  13773. (speedbar-delete-subblock indent)
  13774. (when (memq 'display vhdl-speedbar-save-cache)
  13775. (add-to-list 'vhdl-updated-project-list key))))
  13776. (t (error "Nothing to display")))
  13777. (when (equal (selected-frame) speedbar-frame)
  13778. (speedbar-center-buffer-smartly)))
  13779. (defun vhdl-speedbar-expand-config (text token indent)
  13780. "Expand/contract the configuration under the cursor."
  13781. (cond
  13782. ((string-match "+" text) ; expand configuration
  13783. (let* ((key (vhdl-speedbar-line-key indent))
  13784. (conf-alist (aget vhdl-config-alist key t))
  13785. (conf-entry (aget conf-alist token))
  13786. (ent-alist (aget vhdl-entity-alist key t))
  13787. (hier-alist (vhdl-get-hierarchy
  13788. ent-alist conf-alist (nth 3 conf-entry)
  13789. (nth 4 conf-entry) token (nth 5 conf-entry)
  13790. 0 indent t))
  13791. (subpack-alist (nth 6 conf-entry))
  13792. entry)
  13793. (if (not (or hier-alist subpack-alist))
  13794. (speedbar-change-expand-button-char ??)
  13795. (speedbar-change-expand-button-char ?-)
  13796. ;; add configuration to `vhdl-speedbar-shown-unit-alist'
  13797. (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
  13798. (aput 'unit-alist token nil)
  13799. (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
  13800. (speedbar-with-writable
  13801. (save-excursion
  13802. (end-of-line) (forward-char 1)
  13803. ;; insert instance hierarchy
  13804. (when hier-alist
  13805. (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
  13806. (while hier-alist
  13807. (setq entry (car hier-alist))
  13808. (when (or (= vhdl-speedbar-hierarchy-depth 0)
  13809. (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
  13810. (vhdl-speedbar-make-inst-line
  13811. (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
  13812. (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
  13813. (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
  13814. (setq hier-alist (cdr hier-alist)))
  13815. ;; insert required packages
  13816. (vhdl-speedbar-insert-subpackages
  13817. subpack-alist (1+ indent) indent)))
  13818. (when (memq 'display vhdl-speedbar-save-cache)
  13819. (add-to-list 'vhdl-updated-project-list key))
  13820. (vhdl-speedbar-update-current-unit t t))))
  13821. ((string-match "-" text) ; contract configuration
  13822. (speedbar-change-expand-button-char ?+)
  13823. ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
  13824. (let* ((key (vhdl-speedbar-line-key indent))
  13825. (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
  13826. (adelete 'unit-alist token)
  13827. (if unit-alist
  13828. (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
  13829. (adelete 'vhdl-speedbar-shown-unit-alist key))
  13830. (speedbar-delete-subblock indent)
  13831. (when (memq 'display vhdl-speedbar-save-cache)
  13832. (add-to-list 'vhdl-updated-project-list key))))
  13833. (t (error "Nothing to display")))
  13834. (when (equal (selected-frame) speedbar-frame)
  13835. (speedbar-center-buffer-smartly)))
  13836. (defun vhdl-speedbar-expand-package (text token indent)
  13837. "Expand/contract the package under the cursor."
  13838. (cond
  13839. ((string-match "+" text) ; expand package
  13840. (let* ((key (vhdl-speedbar-line-key indent))
  13841. (pack-alist (aget vhdl-package-alist key t))
  13842. (pack-entry (aget pack-alist token t))
  13843. (comp-alist (nth 3 pack-entry))
  13844. (func-alist (nth 4 pack-entry))
  13845. (func-body-alist (nth 8 pack-entry))
  13846. (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
  13847. comp-entry func-entry func-body-entry)
  13848. (if (not (or comp-alist func-alist subpack-alist))
  13849. (speedbar-change-expand-button-char ??)
  13850. (speedbar-change-expand-button-char ?-)
  13851. ;; add package to `vhdl-speedbar-shown-unit-alist'
  13852. (let* ((unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
  13853. (aput 'unit-alist token nil)
  13854. (aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
  13855. (speedbar-with-writable
  13856. (save-excursion
  13857. (end-of-line) (forward-char 1)
  13858. ;; insert components
  13859. (when comp-alist
  13860. (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
  13861. (while comp-alist
  13862. (setq comp-entry (car comp-alist))
  13863. (speedbar-make-tag-line
  13864. nil nil nil
  13865. (cons token (nth 0 comp-entry))
  13866. (nth 1 comp-entry) 'vhdl-speedbar-find-file
  13867. (cons (nth 2 comp-entry) (nth 3 comp-entry))
  13868. 'vhdl-speedbar-entity-face (1+ indent))
  13869. (setq comp-alist (cdr comp-alist)))
  13870. ;; insert subprograms
  13871. (when func-alist
  13872. (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
  13873. (while func-alist
  13874. (setq func-entry (car func-alist)
  13875. func-body-entry (aget func-body-alist (car func-entry) t))
  13876. (when (nth 2 func-entry)
  13877. (vhdl-speedbar-make-subprogram-line
  13878. (nth 1 func-entry)
  13879. (cons (nth 2 func-entry) (nth 3 func-entry))
  13880. (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
  13881. (1+ indent)))
  13882. (setq func-alist (cdr func-alist)))
  13883. ;; insert required packages
  13884. (vhdl-speedbar-insert-subpackages
  13885. subpack-alist (1+ indent) indent)))
  13886. (when (memq 'display vhdl-speedbar-save-cache)
  13887. (add-to-list 'vhdl-updated-project-list key))
  13888. (vhdl-speedbar-update-current-unit t t))))
  13889. ((string-match "-" text) ; contract package
  13890. (speedbar-change-expand-button-char ?+)
  13891. ;; remove package from `vhdl-speedbar-shown-unit-alist'
  13892. (let* ((key (vhdl-speedbar-line-key indent))
  13893. (unit-alist (aget vhdl-speedbar-shown-unit-alist key t)))
  13894. (adelete 'unit-alist token)
  13895. (if unit-alist
  13896. (aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
  13897. (adelete 'vhdl-speedbar-shown-unit-alist key))
  13898. (speedbar-delete-subblock indent)
  13899. (when (memq 'display vhdl-speedbar-save-cache)
  13900. (add-to-list 'vhdl-updated-project-list key))))
  13901. (t (error "Nothing to display")))
  13902. (when (equal (selected-frame) speedbar-frame)
  13903. (speedbar-center-buffer-smartly)))
  13904. (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
  13905. "Insert required packages."
  13906. (let* ((pack-alist (aget vhdl-package-alist
  13907. (vhdl-speedbar-line-key dir-indent) t))
  13908. pack-key lib-name pack-entry)
  13909. (when subpack-alist
  13910. (vhdl-speedbar-make-title-line "Packages Used:" indent))
  13911. (while subpack-alist
  13912. (setq pack-key (cdar subpack-alist)
  13913. lib-name (caar subpack-alist))
  13914. (setq pack-entry (aget pack-alist pack-key t))
  13915. (vhdl-speedbar-make-subpack-line
  13916. (or (nth 0 pack-entry) pack-key) lib-name
  13917. (cons (nth 1 pack-entry) (nth 2 pack-entry))
  13918. (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
  13919. (setq subpack-alist (cdr subpack-alist)))))
  13920. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  13921. ;; Display help functions
  13922. (defvar vhdl-speedbar-update-current-unit t
  13923. "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
  13924. (defun vhdl-speedbar-update-current-project ()
  13925. "Highlight project that is currently active."
  13926. (when (and vhdl-speedbar-show-projects
  13927. (not (equal vhdl-speedbar-last-selected-project vhdl-project))
  13928. (and (boundp 'speedbar-frame)
  13929. (frame-live-p speedbar-frame)))
  13930. (let ((last-frame (selected-frame))
  13931. (project-alist vhdl-project-alist)
  13932. pos)
  13933. (select-frame speedbar-frame)
  13934. (speedbar-with-writable
  13935. (save-excursion
  13936. (while project-alist
  13937. (goto-char (point-min))
  13938. (when (re-search-forward
  13939. (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
  13940. (put-text-property (match-beginning 1) (match-end 1) 'face
  13941. (if (equal (caar project-alist) vhdl-project)
  13942. 'speedbar-selected-face
  13943. 'speedbar-directory-face))
  13944. (when (equal (caar project-alist) vhdl-project)
  13945. (setq pos (1- (match-beginning 1)))))
  13946. (setq project-alist (cdr project-alist))))
  13947. (when pos (goto-char pos)))
  13948. (select-frame last-frame)
  13949. (setq vhdl-speedbar-last-selected-project vhdl-project)))
  13950. t)
  13951. (defun vhdl-speedbar-update-current-unit (&optional no-position always)
  13952. "Highlight all design units that are contained in the current file.
  13953. NO-POSITION non-nil means do not re-position cursor."
  13954. (let ((last-frame (selected-frame))
  13955. (project-list vhdl-speedbar-shown-project-list)
  13956. file-alist pos file-name)
  13957. ;; get current file name
  13958. (if (fboundp 'speedbar-select-attached-frame)
  13959. (speedbar-select-attached-frame)
  13960. (select-frame speedbar-attached-frame))
  13961. (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
  13962. (when (and vhdl-speedbar-update-current-unit
  13963. (or always (not (equal file-name speedbar-last-selected-file))))
  13964. (if vhdl-speedbar-show-projects
  13965. (while project-list
  13966. (setq file-alist (append file-alist (aget vhdl-file-alist
  13967. (car project-list) t)))
  13968. (setq project-list (cdr project-list)))
  13969. (setq file-alist (aget vhdl-file-alist
  13970. (abbreviate-file-name default-directory) t)))
  13971. (select-frame speedbar-frame)
  13972. (set-buffer speedbar-buffer)
  13973. (speedbar-with-writable
  13974. (vhdl-prepare-search-1
  13975. (save-excursion
  13976. ;; unhighlight last units
  13977. (let* ((file-entry (aget file-alist speedbar-last-selected-file t)))
  13978. (vhdl-speedbar-update-units
  13979. "\\[.\\] " (nth 0 file-entry)
  13980. speedbar-last-selected-file 'vhdl-speedbar-entity-face)
  13981. (vhdl-speedbar-update-units
  13982. "{.} " (nth 1 file-entry)
  13983. speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
  13984. (vhdl-speedbar-update-units
  13985. "\\[.\\] " (nth 3 file-entry)
  13986. speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
  13987. (vhdl-speedbar-update-units
  13988. "[]>] " (nth 4 file-entry)
  13989. speedbar-last-selected-file 'vhdl-speedbar-package-face)
  13990. (vhdl-speedbar-update-units
  13991. "\\[.\\].+(" '("body")
  13992. speedbar-last-selected-file 'vhdl-speedbar-package-face)
  13993. (vhdl-speedbar-update-units
  13994. "> " (nth 6 file-entry)
  13995. speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
  13996. ;; highlight current units
  13997. (let* ((file-entry (aget file-alist file-name t)))
  13998. (setq
  13999. pos (vhdl-speedbar-update-units
  14000. "\\[.\\] " (nth 0 file-entry)
  14001. file-name 'vhdl-speedbar-entity-selected-face pos)
  14002. pos (vhdl-speedbar-update-units
  14003. "{.} " (nth 1 file-entry)
  14004. file-name 'vhdl-speedbar-architecture-selected-face pos)
  14005. pos (vhdl-speedbar-update-units
  14006. "\\[.\\] " (nth 3 file-entry)
  14007. file-name 'vhdl-speedbar-configuration-selected-face pos)
  14008. pos (vhdl-speedbar-update-units
  14009. "[]>] " (nth 4 file-entry)
  14010. file-name 'vhdl-speedbar-package-selected-face pos)
  14011. pos (vhdl-speedbar-update-units
  14012. "\\[.\\].+(" '("body")
  14013. file-name 'vhdl-speedbar-package-selected-face pos)
  14014. pos (vhdl-speedbar-update-units
  14015. "> " (nth 6 file-entry)
  14016. file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
  14017. ;; move speedbar so the first highlighted unit is visible
  14018. (when (and pos (not no-position))
  14019. (goto-char pos)
  14020. (speedbar-center-buffer-smartly)
  14021. (speedbar-position-cursor-on-line))
  14022. (setq speedbar-last-selected-file file-name))
  14023. (select-frame last-frame)
  14024. t))
  14025. (defun vhdl-speedbar-update-units (text unit-list file-name face
  14026. &optional pos)
  14027. "Help function to highlight design units."
  14028. (while unit-list
  14029. (goto-char (point-min))
  14030. (while (re-search-forward
  14031. (concat text "\\(" (car unit-list) "\\)\\>") nil t)
  14032. (when (equal file-name (car (get-text-property
  14033. (match-beginning 1) 'speedbar-token)))
  14034. (setq pos (or pos (point-marker)))
  14035. (put-text-property (match-beginning 1) (match-end 1) 'face face)))
  14036. (setq unit-list (cdr unit-list)))
  14037. pos)
  14038. (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
  14039. ent-name ent-file-marker
  14040. arch-name arch-file-marker
  14041. conf-name conf-file-marker
  14042. lib-name depth offset delimiter)
  14043. "Insert instantiation entry."
  14044. (let ((start (point))
  14045. visible-start)
  14046. (insert (int-to-string depth) ":")
  14047. (put-text-property start (point) 'invisible t)
  14048. (setq visible-start (point))
  14049. (insert-char ? (* depth speedbar-indentation-width))
  14050. (while (> offset 0)
  14051. (insert "|")
  14052. (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
  14053. (setq offset (1- offset)))
  14054. (put-text-property visible-start (point) 'invisible nil)
  14055. (setq start (point))
  14056. (insert ">")
  14057. (speedbar-make-button start (point) nil nil nil)
  14058. (setq visible-start (point))
  14059. (insert " ")
  14060. (setq start (point))
  14061. (if (not inst-name)
  14062. (insert "(top)")
  14063. (insert inst-name)
  14064. (speedbar-make-button
  14065. start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
  14066. 'vhdl-speedbar-find-file inst-file-marker))
  14067. (insert delimiter)
  14068. (when ent-name
  14069. (setq start (point))
  14070. (insert ent-name)
  14071. (speedbar-make-button
  14072. start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
  14073. 'vhdl-speedbar-find-file ent-file-marker)
  14074. (when arch-name
  14075. (insert " (")
  14076. (setq start (point))
  14077. (insert arch-name)
  14078. (speedbar-make-button
  14079. start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
  14080. 'vhdl-speedbar-find-file arch-file-marker)
  14081. (insert ")"))
  14082. (when conf-name
  14083. (insert " (")
  14084. (setq start (point))
  14085. (insert conf-name)
  14086. (speedbar-make-button
  14087. start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
  14088. 'vhdl-speedbar-find-file conf-file-marker)
  14089. (insert ")")))
  14090. (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
  14091. (setq start (point))
  14092. (insert " (" lib-name ")")
  14093. (put-text-property (+ 2 start) (1- (point)) 'face
  14094. 'vhdl-speedbar-library-face))
  14095. (insert-char ?\n 1)
  14096. (put-text-property visible-start (point) 'invisible nil)))
  14097. (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
  14098. body-file-marker depth)
  14099. "Insert package entry."
  14100. (let ((start (point))
  14101. visible-start)
  14102. (insert (int-to-string depth) ":")
  14103. (put-text-property start (point) 'invisible t)
  14104. (setq visible-start (point))
  14105. (insert-char ? (* depth speedbar-indentation-width))
  14106. (put-text-property visible-start (point) 'invisible nil)
  14107. (setq start (point))
  14108. (insert "[+]")
  14109. (speedbar-make-button
  14110. start (point) 'speedbar-button-face 'speedbar-highlight-face
  14111. 'vhdl-speedbar-expand-package pack-key)
  14112. (setq visible-start (point))
  14113. (insert-char ? 1 nil)
  14114. (setq start (point))
  14115. (insert pack-name)
  14116. (speedbar-make-button
  14117. start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
  14118. 'vhdl-speedbar-find-file pack-file-marker)
  14119. (unless (car pack-file-marker)
  14120. (insert "!"))
  14121. (when (car body-file-marker)
  14122. (insert " (")
  14123. (setq start (point))
  14124. (insert "body")
  14125. (speedbar-make-button
  14126. start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
  14127. 'vhdl-speedbar-find-file body-file-marker)
  14128. (insert ")"))
  14129. (insert-char ?\n 1)
  14130. (put-text-property visible-start (point) 'invisible nil)))
  14131. (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
  14132. pack-body-file-marker depth)
  14133. "Insert used package entry."
  14134. (let ((start (point))
  14135. visible-start)
  14136. (insert (int-to-string depth) ":")
  14137. (put-text-property start (point) 'invisible t)
  14138. (setq visible-start (point))
  14139. (insert-char ? (* depth speedbar-indentation-width))
  14140. (put-text-property visible-start (point) 'invisible nil)
  14141. (setq start (point))
  14142. (insert ">")
  14143. (speedbar-make-button start (point) nil nil nil)
  14144. (setq visible-start (point))
  14145. (insert " ")
  14146. (setq start (point))
  14147. (insert pack-name)
  14148. (speedbar-make-button
  14149. start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
  14150. 'vhdl-speedbar-find-file pack-file-marker)
  14151. (when (car pack-body-file-marker)
  14152. (insert " (")
  14153. (setq start (point))
  14154. (insert "body")
  14155. (speedbar-make-button
  14156. start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
  14157. 'vhdl-speedbar-find-file pack-body-file-marker)
  14158. (insert ")"))
  14159. (setq start (point))
  14160. (insert " (" lib-name ")")
  14161. (put-text-property (+ 2 start) (1- (point)) 'face
  14162. 'vhdl-speedbar-library-face)
  14163. (insert-char ?\n 1)
  14164. (put-text-property visible-start (point) 'invisible nil)))
  14165. (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
  14166. func-body-file-marker
  14167. depth)
  14168. "Insert subprogram entry."
  14169. (let ((start (point))
  14170. visible-start)
  14171. (insert (int-to-string depth) ":")
  14172. (put-text-property start (point) 'invisible t)
  14173. (setq visible-start (point))
  14174. (insert-char ? (* depth speedbar-indentation-width))
  14175. (put-text-property visible-start (point) 'invisible nil)
  14176. (setq start (point))
  14177. (insert ">")
  14178. (speedbar-make-button start (point) nil nil nil)
  14179. (setq visible-start (point))
  14180. (insert " ")
  14181. (setq start (point))
  14182. (insert func-name)
  14183. (speedbar-make-button
  14184. start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
  14185. 'vhdl-speedbar-find-file func-file-marker)
  14186. (when (car func-body-file-marker)
  14187. (insert " (")
  14188. (setq start (point))
  14189. (insert "body")
  14190. (speedbar-make-button
  14191. start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
  14192. 'vhdl-speedbar-find-file func-body-file-marker)
  14193. (insert ")"))
  14194. (insert-char ?\n 1)
  14195. (put-text-property visible-start (point) 'invisible nil)))
  14196. (defun vhdl-speedbar-make-title-line (text &optional depth)
  14197. "Insert design unit title entry."
  14198. (let ((start (point))
  14199. visible-start)
  14200. (when depth
  14201. (insert (int-to-string depth) ":")
  14202. (put-text-property start (point) 'invisible t))
  14203. (setq visible-start (point))
  14204. (insert-char ? (* (or depth 0) speedbar-indentation-width))
  14205. (setq start (point))
  14206. (insert text)
  14207. (speedbar-make-button start (point) nil nil nil nil)
  14208. (insert-char ?\n 1)
  14209. (put-text-property visible-start (point) 'invisible nil)))
  14210. (defun vhdl-speedbar-insert-dirs (files level)
  14211. "Insert subdirectories."
  14212. (let ((dirs (car files)))
  14213. (while dirs
  14214. (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
  14215. (car dirs) 'speedbar-dir-follow nil
  14216. 'speedbar-directory-face level)
  14217. (setq dirs (cdr dirs)))))
  14218. (defun vhdl-speedbar-dired (text token indent)
  14219. "Speedbar click handler for directory expand button in hierarchy mode."
  14220. (cond ((string-match "+" text) ; we have to expand this dir
  14221. (setq speedbar-shown-directories
  14222. (cons (expand-file-name
  14223. (concat (speedbar-line-directory indent) token "/"))
  14224. speedbar-shown-directories))
  14225. (speedbar-change-expand-button-char ?-)
  14226. (speedbar-reset-scanners)
  14227. (speedbar-with-writable
  14228. (save-excursion
  14229. (end-of-line) (forward-char 1)
  14230. (vhdl-speedbar-insert-dirs
  14231. (speedbar-file-lists
  14232. (concat (speedbar-line-directory indent) token "/"))
  14233. (1+ indent))
  14234. (speedbar-reset-scanners)
  14235. (vhdl-speedbar-insert-dir-hierarchy
  14236. (abbreviate-file-name
  14237. (concat (speedbar-line-directory indent) token "/"))
  14238. (1+ indent) speedbar-power-click)))
  14239. (vhdl-speedbar-update-current-unit t t))
  14240. ((string-match "-" text) ; we have to contract this node
  14241. (speedbar-reset-scanners)
  14242. (let ((oldl speedbar-shown-directories)
  14243. (newl nil)
  14244. (td (expand-file-name
  14245. (concat (speedbar-line-directory indent) token))))
  14246. (while oldl
  14247. (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
  14248. (setq newl (cons (car oldl) newl)))
  14249. (setq oldl (cdr oldl)))
  14250. (setq speedbar-shown-directories (nreverse newl)))
  14251. (speedbar-change-expand-button-char ?+)
  14252. (speedbar-delete-subblock indent))
  14253. (t (error "Nothing to display")))
  14254. (when (equal (selected-frame) speedbar-frame)
  14255. (speedbar-center-buffer-smartly)))
  14256. (defun vhdl-speedbar-item-info ()
  14257. "Derive and display information about this line item."
  14258. (save-excursion
  14259. (beginning-of-line)
  14260. ;; skip invisible number info
  14261. (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
  14262. (cond
  14263. ;; project/directory entry
  14264. ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
  14265. (if vhdl-speedbar-show-projects
  14266. (message "Project \"%s\"" (match-string-no-properties 1))
  14267. (speedbar-files-item-info)))
  14268. ;; design unit entry
  14269. ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
  14270. (goto-char (match-end 1))
  14271. (let ((face (get-text-property (point) 'face)))
  14272. (message
  14273. "%s \"%s\" in \"%s\""
  14274. ;; design unit kind
  14275. (cond ((or (eq face 'vhdl-speedbar-entity-face)
  14276. (eq face 'vhdl-speedbar-entity-selected-face))
  14277. (if (equal (match-string 2) ">") "Component" "Entity"))
  14278. ((or (eq face 'vhdl-speedbar-architecture-face)
  14279. (eq face 'vhdl-speedbar-architecture-selected-face))
  14280. "Architecture")
  14281. ((or (eq face 'vhdl-speedbar-configuration-face)
  14282. (eq face 'vhdl-speedbar-configuration-selected-face))
  14283. "Configuration")
  14284. ((or (eq face 'vhdl-speedbar-package-face)
  14285. (eq face 'vhdl-speedbar-package-selected-face))
  14286. "Package")
  14287. ((or (eq face 'vhdl-speedbar-instantiation-face)
  14288. (eq face 'vhdl-speedbar-instantiation-selected-face))
  14289. "Instantiation")
  14290. ((eq face 'vhdl-speedbar-subprogram-face)
  14291. "Subprogram")
  14292. (t ""))
  14293. ;; design unit name
  14294. (buffer-substring-no-properties
  14295. (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
  14296. (match-end 1))
  14297. ;; file name
  14298. (file-relative-name
  14299. (or (car (get-text-property (point) 'speedbar-token))
  14300. "?")
  14301. (vhdl-default-directory)))))
  14302. (t (message "")))))
  14303. (defun vhdl-speedbar-line-text ()
  14304. "Calls `speedbar-line-text' and removes text properties."
  14305. (let ((string (speedbar-line-text)))
  14306. (set-text-properties 0 (length string) nil string)
  14307. string))
  14308. (defun vhdl-speedbar-higher-text ()
  14309. "Get speedbar-line-text of higher level."
  14310. (let (depth string)
  14311. (save-excursion
  14312. (beginning-of-line)
  14313. (looking-at "^\\([0-9]+\\):")
  14314. (setq depth (string-to-number (match-string 1)))
  14315. (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
  14316. (setq string (match-string 1))
  14317. (set-text-properties 0 (length string) nil string)
  14318. string))))
  14319. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14320. ;; Help functions
  14321. (defun vhdl-speedbar-line-key (&optional indent)
  14322. "Get currently displayed directory of project name."
  14323. (if vhdl-speedbar-show-projects
  14324. (vhdl-speedbar-line-project)
  14325. (abbreviate-file-name
  14326. (file-name-as-directory (speedbar-line-directory indent)))))
  14327. (defun vhdl-speedbar-line-project (&optional indent)
  14328. "Get currently displayed project name."
  14329. (and vhdl-speedbar-show-projects
  14330. (save-excursion
  14331. (end-of-line)
  14332. (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
  14333. (match-string-no-properties 1))))
  14334. (defun vhdl-add-modified-file ()
  14335. "Add file to `vhdl-modified-file-list'."
  14336. (when vhdl-file-alist
  14337. (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
  14338. nil)
  14339. (defun vhdl-resolve-paths (path-list)
  14340. "Resolve path wildcards in PATH-LIST."
  14341. (let (path-list-1 path-list-2 path-beg path-end dir)
  14342. ;; eliminate non-existent directories
  14343. (while path-list
  14344. (setq dir (car path-list))
  14345. (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
  14346. (if (file-directory-p (match-string 2 dir))
  14347. (setq path-list-1 (cons dir path-list-1))
  14348. (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
  14349. (setq path-list (cdr path-list)))
  14350. ;; resolve path wildcards
  14351. (while path-list-1
  14352. (setq dir (car path-list-1))
  14353. (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
  14354. (progn
  14355. (setq path-beg (match-string 1 dir)
  14356. path-end (match-string 5 dir))
  14357. (setq path-list-1
  14358. (append
  14359. (mapcar
  14360. (function
  14361. (lambda (var) (concat path-beg var path-end)))
  14362. (let ((all-list (vhdl-directory-files
  14363. (match-string 2 dir) t
  14364. (concat "\\<" (wildcard-to-regexp
  14365. (match-string 4 dir)))))
  14366. dir-list)
  14367. (while all-list
  14368. (when (file-directory-p (car all-list))
  14369. (setq dir-list (cons (car all-list) dir-list)))
  14370. (setq all-list (cdr all-list)))
  14371. dir-list))
  14372. (cdr path-list-1))))
  14373. (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
  14374. (when (file-directory-p (match-string 2 dir))
  14375. (setq path-list-2 (cons dir path-list-2)))
  14376. (setq path-list-1 (cdr path-list-1))))
  14377. (nreverse path-list-2)))
  14378. (defun vhdl-speedbar-goto-this-unit (directory unit)
  14379. "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
  14380. (let ((dest (point)))
  14381. (if (and (if vhdl-speedbar-show-projects
  14382. (progn (goto-char (point-min)) t)
  14383. (speedbar-goto-this-file directory))
  14384. (re-search-forward (concat "[]}] " unit "\\>") nil t))
  14385. (progn (speedbar-position-cursor-on-line)
  14386. t)
  14387. (goto-char dest)
  14388. nil)))
  14389. (defun vhdl-speedbar-find-file (text token indent)
  14390. "When user clicks on TEXT, load file with name and position in TOKEN.
  14391. Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
  14392. is already shown in a buffer."
  14393. (if (not (car token))
  14394. (error "ERROR: File cannot be found")
  14395. (let ((buffer (get-file-buffer (car token))))
  14396. (speedbar-find-file-in-frame (car token))
  14397. (when (or vhdl-speedbar-jump-to-unit buffer)
  14398. (goto-char (point-min))
  14399. (forward-line (1- (cdr token)))
  14400. (recenter))
  14401. (vhdl-speedbar-update-current-unit t t)
  14402. (speedbar-set-timer dframe-update-speed)
  14403. (speedbar-maybee-jump-to-attached-frame))))
  14404. (defun vhdl-speedbar-port-copy ()
  14405. "Copy the port of the entity/component or subprogram under the cursor."
  14406. (interactive)
  14407. (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
  14408. (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
  14409. (error "ERROR: No entity/component or subprogram under cursor")
  14410. (beginning-of-line)
  14411. (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]\\]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
  14412. (condition-case info
  14413. (let ((token (get-text-property
  14414. (match-beginning 3) 'speedbar-token)))
  14415. (vhdl-visit-file (car token) t
  14416. (progn (goto-char (point-min))
  14417. (forward-line (1- (cdr token)))
  14418. (end-of-line)
  14419. (if is-entity
  14420. (vhdl-port-copy)
  14421. (vhdl-subprog-copy)))))
  14422. (error (error "ERROR: %s not scanned successfully\n (%s)"
  14423. (if is-entity "Port" "Interface") (cadr info))))
  14424. (error "ERROR: No entity/component or subprogram on current line")))))
  14425. (defun vhdl-speedbar-place-component ()
  14426. "Place the entity/component under the cursor as component."
  14427. (interactive)
  14428. (if (not (vhdl-speedbar-check-unit 'entity))
  14429. (error "ERROR: No entity/component under cursor")
  14430. (vhdl-speedbar-port-copy)
  14431. (if (fboundp 'speedbar-select-attached-frame)
  14432. (speedbar-select-attached-frame)
  14433. (select-frame speedbar-attached-frame))
  14434. (vhdl-compose-place-component)
  14435. (select-frame speedbar-frame)))
  14436. (defun vhdl-speedbar-configuration ()
  14437. "Generate configuration for the architecture under the cursor."
  14438. (interactive)
  14439. (if (not (vhdl-speedbar-check-unit 'architecture))
  14440. (error "ERROR: No architecture under cursor")
  14441. (let ((arch-name (vhdl-speedbar-line-text))
  14442. (ent-name (vhdl-speedbar-higher-text)))
  14443. (if (fboundp 'speedbar-select-attached-frame)
  14444. (speedbar-select-attached-frame)
  14445. (select-frame speedbar-attached-frame))
  14446. (vhdl-compose-configuration ent-name arch-name))))
  14447. (defun vhdl-speedbar-select-mra ()
  14448. "Select the architecture under the cursor as MRA."
  14449. (interactive)
  14450. (if (not (vhdl-speedbar-check-unit 'architecture))
  14451. (error "ERROR: No architecture under cursor")
  14452. (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
  14453. (ent-key (downcase (vhdl-speedbar-higher-text)))
  14454. (ent-alist (aget vhdl-entity-alist
  14455. (or (vhdl-project-p) default-directory) t))
  14456. (ent-entry (aget ent-alist ent-key t)))
  14457. (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
  14458. (speedbar-refresh))))
  14459. (defun vhdl-speedbar-make-design ()
  14460. "Make (compile) design unit or directory/project under the cursor."
  14461. (interactive)
  14462. (if (not (save-excursion (beginning-of-line)
  14463. (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
  14464. (error "ERROR: No primary design unit or directory/project under cursor")
  14465. (let ((is-unit (match-string 2))
  14466. (unit-name (vhdl-speedbar-line-text))
  14467. (vhdl-project (vhdl-speedbar-line-project))
  14468. (directory (file-name-as-directory
  14469. (or (speedbar-line-file) (speedbar-line-directory)))))
  14470. (if (fboundp 'speedbar-select-attached-frame)
  14471. (speedbar-select-attached-frame)
  14472. (select-frame speedbar-attached-frame))
  14473. (let ((default-directory directory))
  14474. (vhdl-make (and is-unit unit-name))))))
  14475. (defun vhdl-speedbar-generate-makefile ()
  14476. "Generate Makefile for directory/project under the cursor."
  14477. (interactive)
  14478. (let ((vhdl-project (vhdl-speedbar-line-project))
  14479. (default-directory (file-name-as-directory
  14480. (or (speedbar-line-file) (speedbar-line-directory)))))
  14481. (vhdl-generate-makefile)))
  14482. (defun vhdl-speedbar-check-unit (design-unit)
  14483. "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
  14484. expansion function)."
  14485. (save-excursion
  14486. (speedbar-position-cursor-on-line)
  14487. (cond ((eq design-unit 'entity)
  14488. (memq (get-text-property (match-end 0) 'face)
  14489. '(vhdl-speedbar-entity-face
  14490. vhdl-speedbar-entity-selected-face)))
  14491. ((eq design-unit 'architecture)
  14492. (memq (get-text-property (match-end 0) 'face)
  14493. '(vhdl-speedbar-architecture-face
  14494. vhdl-speedbar-architecture-selected-face)))
  14495. ((eq design-unit 'subprogram)
  14496. (eq (get-text-property (match-end 0) 'face)
  14497. 'vhdl-speedbar-subprogram-face))
  14498. (t nil))))
  14499. (defun vhdl-speedbar-set-depth (depth)
  14500. "Set hierarchy display depth to DEPTH and refresh speedbar."
  14501. (setq vhdl-speedbar-hierarchy-depth depth)
  14502. (speedbar-refresh))
  14503. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14504. ;; Fontification
  14505. (defface vhdl-speedbar-entity-face
  14506. '((((class color) (background light)) (:foreground "ForestGreen"))
  14507. (((class color) (background dark)) (:foreground "PaleGreen")))
  14508. "Face used for displaying entity names."
  14509. :group 'speedbar-faces)
  14510. (defface vhdl-speedbar-architecture-face
  14511. '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
  14512. (((class color) (background light)) (:foreground "Blue"))
  14513. (((class color) (background dark)) (:foreground "LightSkyBlue")))
  14514. "Face used for displaying architecture names."
  14515. :group 'speedbar-faces)
  14516. (defface vhdl-speedbar-configuration-face
  14517. '((((class color) (background light)) (:foreground "DarkGoldenrod"))
  14518. (((class color) (background dark)) (:foreground "Salmon")))
  14519. "Face used for displaying configuration names."
  14520. :group 'speedbar-faces)
  14521. (defface vhdl-speedbar-package-face
  14522. '((((class color) (background light)) (:foreground "Grey50"))
  14523. (((class color) (background dark)) (:foreground "Grey80")))
  14524. "Face used for displaying package names."
  14525. :group 'speedbar-faces)
  14526. (defface vhdl-speedbar-library-face
  14527. '((((class color) (background light)) (:foreground "Purple"))
  14528. (((class color) (background dark)) (:foreground "Orchid1")))
  14529. "Face used for displaying library names."
  14530. :group 'speedbar-faces)
  14531. (defface vhdl-speedbar-instantiation-face
  14532. '((((class color) (background light)) (:foreground "Brown"))
  14533. (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
  14534. (((class color) (background dark)) (:foreground "Yellow")))
  14535. "Face used for displaying instantiation names."
  14536. :group 'speedbar-faces)
  14537. (defface vhdl-speedbar-subprogram-face
  14538. '((((class color) (background light)) (:foreground "Orchid4"))
  14539. (((class color) (background dark)) (:foreground "BurlyWood2")))
  14540. "Face used for displaying subprogram names."
  14541. :group 'speedbar-faces)
  14542. (defface vhdl-speedbar-entity-selected-face
  14543. '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
  14544. (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
  14545. "Face used for displaying entity names."
  14546. :group 'speedbar-faces)
  14547. (defface vhdl-speedbar-architecture-selected-face
  14548. '((((min-colors 88) (class color) (background light)) (:foreground
  14549. "Blue1" :underline t))
  14550. (((class color) (background light)) (:foreground "Blue" :underline t))
  14551. (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
  14552. "Face used for displaying architecture names."
  14553. :group 'speedbar-faces)
  14554. (defface vhdl-speedbar-configuration-selected-face
  14555. '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
  14556. (((class color) (background dark)) (:foreground "Salmon" :underline t)))
  14557. "Face used for displaying configuration names."
  14558. :group 'speedbar-faces)
  14559. (defface vhdl-speedbar-package-selected-face
  14560. '((((class color) (background light)) (:foreground "Grey50" :underline t))
  14561. (((class color) (background dark)) (:foreground "Grey80" :underline t)))
  14562. "Face used for displaying package names."
  14563. :group 'speedbar-faces)
  14564. (defface vhdl-speedbar-instantiation-selected-face
  14565. '((((class color) (background light)) (:foreground "Brown" :underline t))
  14566. (((class color) (background dark)) (:foreground "Yellow" :underline t)))
  14567. "Face used for displaying instantiation names."
  14568. :group 'speedbar-faces)
  14569. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14570. ;; Initialization
  14571. ;; add speedbar
  14572. (when (fboundp 'speedbar)
  14573. (condition-case ()
  14574. (when (and vhdl-speedbar-auto-open
  14575. (not (and (boundp 'speedbar-frame)
  14576. (frame-live-p speedbar-frame))))
  14577. (speedbar-frame-mode 1)
  14578. (if (fboundp 'speedbar-select-attached-frame)
  14579. (speedbar-select-attached-frame)
  14580. (select-frame speedbar-attached-frame)))
  14581. (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar"))))
  14582. ;; initialize speedbar
  14583. (if (not (boundp 'speedbar-frame))
  14584. (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
  14585. (vhdl-speedbar-initialize)
  14586. (when speedbar-frame (vhdl-speedbar-refresh)))
  14587. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14588. ;;; Structural composition
  14589. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14590. (defun vhdl-get-components-package-name ()
  14591. "Return the name of the components package."
  14592. (let ((project (vhdl-project-p)))
  14593. (if project
  14594. (vhdl-replace-string (car vhdl-components-package-name)
  14595. (subst-char-in-string ? ?_ project))
  14596. (cdr vhdl-components-package-name))))
  14597. (defun vhdl-compose-new-component ()
  14598. "Create entity and architecture for new component."
  14599. (interactive)
  14600. (let* ((case-fold-search t)
  14601. (ent-name (read-from-minibuffer "entity name: "
  14602. nil vhdl-minibuffer-local-map))
  14603. (arch-name
  14604. (if (equal (cdr vhdl-compose-architecture-name) "")
  14605. (read-from-minibuffer "architecture name: "
  14606. nil vhdl-minibuffer-local-map)
  14607. (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
  14608. ent-file-name arch-file-name ent-buffer arch-buffer project end-pos)
  14609. (message "Creating component \"%s(%s)\"..." ent-name arch-name)
  14610. ;; open entity file
  14611. (unless (eq vhdl-compose-create-files 'none)
  14612. (setq ent-file-name
  14613. (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
  14614. "." (file-name-extension (buffer-file-name))))
  14615. (when (and (file-exists-p ent-file-name)
  14616. (not (y-or-n-p (concat "File \"" ent-file-name
  14617. "\" exists; overwrite? "))))
  14618. (error "ERROR: Creating component...aborted"))
  14619. (find-file ent-file-name)
  14620. (erase-buffer)
  14621. (set-buffer-modified-p nil))
  14622. ;; insert header
  14623. (if vhdl-compose-include-header
  14624. (progn (vhdl-template-header)
  14625. (setq end-pos (point))
  14626. (goto-char (point-max)))
  14627. (vhdl-comment-display-line) (insert "\n\n"))
  14628. ;; insert library clause
  14629. (vhdl-template-package-std-logic-1164)
  14630. (when vhdl-use-components-package
  14631. (insert "\n")
  14632. (vhdl-template-standard-package (vhdl-work-library)
  14633. (vhdl-get-components-package-name)))
  14634. (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
  14635. ;; insert entity declaration
  14636. (vhdl-insert-keyword "ENTITY ") (insert ent-name)
  14637. (vhdl-insert-keyword " IS\n")
  14638. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  14639. (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
  14640. (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
  14641. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  14642. (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
  14643. (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
  14644. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  14645. (vhdl-insert-keyword "END ")
  14646. (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
  14647. (insert ent-name ";\n\n")
  14648. (vhdl-comment-display-line) (insert "\n")
  14649. ;; open architecture file
  14650. (if (not (eq vhdl-compose-create-files 'separate))
  14651. (insert "\n")
  14652. (goto-char (or end-pos (point-min)))
  14653. (setq ent-buffer (current-buffer))
  14654. (setq arch-file-name
  14655. (concat (vhdl-replace-string vhdl-architecture-file-name
  14656. (concat ent-name " " arch-name) t)
  14657. "." (file-name-extension (buffer-file-name))))
  14658. (when (and (file-exists-p arch-file-name)
  14659. (not (y-or-n-p (concat "File \"" arch-file-name
  14660. "\" exists; overwrite? "))))
  14661. (error "ERROR: Creating component...aborted"))
  14662. (find-file arch-file-name)
  14663. (erase-buffer)
  14664. (set-buffer-modified-p nil)
  14665. ;; insert header
  14666. (if vhdl-compose-include-header
  14667. (progn (vhdl-template-header)
  14668. (goto-char (point-max)))
  14669. (vhdl-comment-display-line) (insert "\n\n")))
  14670. ;; insert architecture body
  14671. (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
  14672. (vhdl-insert-keyword " OF ") (insert ent-name)
  14673. (vhdl-insert-keyword " IS\n\n")
  14674. (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
  14675. (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
  14676. (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
  14677. (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
  14678. (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
  14679. (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
  14680. (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
  14681. (vhdl-insert-keyword "BEGIN")
  14682. (when vhdl-self-insert-comments
  14683. (insert " -- ")
  14684. (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
  14685. (insert arch-name))
  14686. (insert "\n\n")
  14687. (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
  14688. (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
  14689. (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
  14690. (vhdl-insert-keyword "END ")
  14691. (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
  14692. (insert arch-name ";\n\n")
  14693. ;; insert footer and save
  14694. (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
  14695. (vhdl-template-footer)
  14696. (vhdl-comment-display-line) (insert "\n"))
  14697. (goto-char (or end-pos (point-min)))
  14698. (setq arch-buffer (current-buffer))
  14699. (when ent-buffer (set-buffer ent-buffer) (save-buffer))
  14700. (set-buffer arch-buffer) (save-buffer)
  14701. (message "%s"
  14702. (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
  14703. (and ent-file-name
  14704. (format "\n File created: \"%s\"" ent-file-name))
  14705. (and arch-file-name
  14706. (format "\n File created: \"%s\"" arch-file-name))))))
  14707. (defun vhdl-compose-place-component ()
  14708. "Place new component by pasting current port as component declaration and
  14709. component instantiation."
  14710. (interactive)
  14711. (if (not vhdl-port-list)
  14712. (error "ERROR: No port has been read")
  14713. (save-excursion
  14714. (vhdl-prepare-search-2
  14715. (unless (or (re-search-backward "^architecture[ \t\n\r\f]+\\w+[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
  14716. (re-search-forward "^architecture[ \t\n\r\f]+\\w+[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t))
  14717. (error "ERROR: No architecture found"))
  14718. (let* ((ent-name (match-string 1))
  14719. (ent-file-name
  14720. (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
  14721. "." (file-name-extension (buffer-file-name))))
  14722. (orig-buffer (current-buffer)))
  14723. (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
  14724. ;; place component declaration
  14725. (unless (or vhdl-use-components-package
  14726. (vhdl-use-direct-instantiation)
  14727. (save-excursion
  14728. (re-search-forward
  14729. (concat "^\\s-*component\\s-+"
  14730. (car vhdl-port-list) "\\>") nil t)))
  14731. (re-search-forward "^begin\\>" nil)
  14732. (beginning-of-line)
  14733. (skip-chars-backward " \t\n\r\f")
  14734. (insert "\n\n") (indent-to vhdl-basic-offset)
  14735. (vhdl-port-paste-component t))
  14736. ;; place component instantiation
  14737. (re-search-forward "^end\\>" nil)
  14738. (beginning-of-line)
  14739. (skip-chars-backward " \t\n\r\f")
  14740. (insert "\n\n") (indent-to vhdl-basic-offset)
  14741. (vhdl-port-paste-instance nil t t)
  14742. ;; place use clause for used packages
  14743. (when (nth 3 vhdl-port-list)
  14744. ;; open entity file
  14745. (when (file-exists-p ent-file-name)
  14746. (find-file ent-file-name))
  14747. (goto-char (point-min))
  14748. (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name "[ \t\n\r\f]+is\\>") nil t)
  14749. (error "ERROR: Entity not found: \"%s\"" ent-name))
  14750. (goto-char (match-beginning 0))
  14751. (if (and (save-excursion
  14752. (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
  14753. (match-string 1))
  14754. (progn (goto-char (match-end 0))
  14755. (beginning-of-line 2))
  14756. (insert "\n")
  14757. (backward-char))
  14758. (vhdl-port-paste-context-clause)
  14759. (switch-to-buffer orig-buffer))
  14760. (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
  14761. (defun vhdl-compose-wire-components ()
  14762. "Connect components."
  14763. (interactive)
  14764. (save-excursion
  14765. (vhdl-prepare-search-2
  14766. (unless (or (re-search-backward "^architecture[ \t\n\r\f]+\\w+[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
  14767. (re-search-forward "^architecture[ \t\n\r\f]+\\w+[ \t\n\r\f]+of[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t))
  14768. (error "ERROR: No architecture found"))
  14769. (let* ((ent-name (match-string 1))
  14770. (ent-file-name
  14771. (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
  14772. "." (file-name-extension (buffer-file-name))))
  14773. (arch-decl-pos (point-marker))
  14774. (arch-stat-pos (re-search-forward "^begin\\>" nil))
  14775. (arch-end-pos (re-search-forward "^end\\>" nil))
  14776. (pack-name (vhdl-get-components-package-name))
  14777. (pack-file-name
  14778. (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
  14779. "." (file-name-extension (buffer-file-name))))
  14780. inst-name comp-name comp-ent-name comp-ent-file-name has-generic
  14781. port-alist generic-alist inst-alist
  14782. signal-name signal-entry signal-alist local-list written-list
  14783. single-in-list multi-in-list single-out-list multi-out-list
  14784. constant-name constant-entry constant-alist single-list multi-list
  14785. port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
  14786. generic-beg-pos generic-pos generic-inst-pos generic-end-pos
  14787. signal-beg-pos signal-pos
  14788. constant-temp-pos port-temp-pos signal-temp-pos)
  14789. (message "Wiring components...")
  14790. ;; process all instances
  14791. (goto-char arch-stat-pos)
  14792. (while (re-search-forward
  14793. (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
  14794. "\\(component[ \t\n\r\f]+\\)?\\(\\w+\\)"
  14795. "[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n\r\f]+map\\|"
  14796. "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?"
  14797. "[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n\r\f]+map\\)[ \t\n\r\f]*(") arch-end-pos t)
  14798. (setq inst-name (match-string-no-properties 1)
  14799. comp-name (match-string-no-properties 4)
  14800. comp-ent-name (match-string-no-properties 12)
  14801. has-generic (or (match-string 7) (match-string 17)))
  14802. ;; get port ...
  14803. (if comp-name
  14804. ;; ... from component declaration
  14805. (vhdl-visit-file
  14806. (when vhdl-use-components-package pack-file-name) t
  14807. (save-excursion
  14808. (goto-char (point-min))
  14809. (unless (re-search-forward (concat "^\\s-*component[ \t\n\r\f]+" comp-name "\\>") nil t)
  14810. (error "ERROR: Component declaration not found: \"%s\"" comp-name))
  14811. (vhdl-port-copy)))
  14812. ;; ... from entity declaration (direct instantiation)
  14813. (setq comp-ent-file-name
  14814. (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
  14815. "." (file-name-extension (buffer-file-name))))
  14816. (vhdl-visit-file
  14817. comp-ent-file-name t
  14818. (save-excursion
  14819. (goto-char (point-min))
  14820. (unless (re-search-forward (concat "^\\s-*entity[ \t\n\r\f]+" comp-ent-name "\\>") nil t)
  14821. (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
  14822. (vhdl-port-copy))))
  14823. (vhdl-port-flatten t)
  14824. (setq generic-alist (nth 1 vhdl-port-list)
  14825. port-alist (nth 2 vhdl-port-list)
  14826. vhdl-port-list nil)
  14827. (setq constant-alist nil
  14828. signal-alist nil)
  14829. (when has-generic
  14830. ;; process all constants in generic map
  14831. (vhdl-forward-syntactic-ws)
  14832. (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t)
  14833. (setq constant-name (match-string-no-properties 3))
  14834. (setq constant-entry
  14835. (cons constant-name
  14836. (if (match-string 1)
  14837. (or (aget generic-alist (match-string 2) t)
  14838. (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
  14839. (cdar generic-alist))))
  14840. (setq constant-alist (cons constant-entry constant-alist))
  14841. (setq constant-name (downcase constant-name))
  14842. (if (or (member constant-name single-list)
  14843. (member constant-name multi-list))
  14844. (progn (setq single-list (delete constant-name single-list))
  14845. (add-to-list 'multi-list constant-name))
  14846. (add-to-list 'single-list constant-name))
  14847. (unless (match-string 1)
  14848. (setq generic-alist (cdr generic-alist)))
  14849. (vhdl-forward-syntactic-ws))
  14850. (vhdl-re-search-forward "\\<port\\s-+map[ \t\n\r\f]*(" nil t))
  14851. ;; process all signals in port map
  14852. (vhdl-forward-syntactic-ws)
  14853. (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t)
  14854. (setq signal-name (match-string-no-properties 3))
  14855. (setq signal-entry (cons signal-name
  14856. (if (match-string 1)
  14857. (or (aget port-alist (match-string 2) t)
  14858. (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
  14859. (cdar port-alist))))
  14860. (setq signal-alist (cons signal-entry signal-alist))
  14861. (setq signal-name (downcase signal-name))
  14862. (if (equal (upcase (nth 2 signal-entry)) "IN")
  14863. ;; input signal
  14864. (cond
  14865. ((member signal-name local-list)
  14866. nil)
  14867. ((or (member signal-name single-out-list)
  14868. (member signal-name multi-out-list))
  14869. (setq single-out-list (delete signal-name single-out-list))
  14870. (setq multi-out-list (delete signal-name multi-out-list))
  14871. (add-to-list 'local-list signal-name))
  14872. ((member signal-name single-in-list)
  14873. (setq single-in-list (delete signal-name single-in-list))
  14874. (add-to-list 'multi-in-list signal-name))
  14875. ((not (member signal-name multi-in-list))
  14876. (add-to-list 'single-in-list signal-name)))
  14877. ;; output signal
  14878. (cond
  14879. ((member signal-name local-list)
  14880. nil)
  14881. ((or (member signal-name single-in-list)
  14882. (member signal-name multi-in-list))
  14883. (setq single-in-list (delete signal-name single-in-list))
  14884. (setq multi-in-list (delete signal-name multi-in-list))
  14885. (add-to-list 'local-list signal-name))
  14886. ((member signal-name single-out-list)
  14887. (setq single-out-list (delete signal-name single-out-list))
  14888. (add-to-list 'multi-out-list signal-name))
  14889. ((not (member signal-name multi-out-list))
  14890. (add-to-list 'single-out-list signal-name))))
  14891. (unless (match-string 1)
  14892. (setq port-alist (cdr port-alist)))
  14893. (vhdl-forward-syntactic-ws))
  14894. (setq inst-alist (cons (list inst-name (nreverse constant-alist)
  14895. (nreverse signal-alist)) inst-alist)))
  14896. ;; prepare signal insertion
  14897. (vhdl-goto-marker arch-decl-pos)
  14898. (forward-line 1)
  14899. (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n\r\f]*-*\n" arch-stat-pos t)
  14900. (setq signal-pos (point-marker))
  14901. (while (progn (vhdl-forward-syntactic-ws)
  14902. (looking-at "signal\\>"))
  14903. (beginning-of-line 2)
  14904. (delete-region signal-pos (point)))
  14905. (setq signal-beg-pos signal-pos)
  14906. ;; open entity file
  14907. (when (file-exists-p ent-file-name)
  14908. (find-file ent-file-name))
  14909. (goto-char (point-min))
  14910. (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name "[ \t\n\r\f]+is\\>") nil t)
  14911. (error "ERROR: Entity not found: \"%s\"" ent-name))
  14912. ;; prepare generic clause insertion
  14913. (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n\r\f]*(\\)\\|^end\\>" nil t)
  14914. (match-string 1))
  14915. (goto-char (match-beginning 0))
  14916. (indent-to vhdl-basic-offset)
  14917. (insert "generic ();\n\n")
  14918. (backward-char 4))
  14919. (backward-char)
  14920. (setq generic-pos (point-marker))
  14921. (forward-sexp) (end-of-line)
  14922. (delete-region generic-pos (point)) (delete-char 1)
  14923. (insert "(\n")
  14924. (when multi-list
  14925. (insert "\n")
  14926. (indent-to (* 2 vhdl-basic-offset))
  14927. (insert "-- global generics\n"))
  14928. (setq generic-beg-pos (point-marker) generic-pos (point-marker)
  14929. generic-inst-pos (point-marker) generic-end-pos (point-marker))
  14930. ;; prepare port clause insertion
  14931. (unless (and (re-search-forward "\\(^\\s-*port[ \t\n\r\f]*(\\)\\|^end\\>" nil t)
  14932. (match-string 1))
  14933. (goto-char (match-beginning 0))
  14934. (indent-to vhdl-basic-offset)
  14935. (insert "port ();\n\n")
  14936. (backward-char 4))
  14937. (backward-char)
  14938. (setq port-in-pos (point-marker))
  14939. (forward-sexp) (end-of-line)
  14940. (delete-region port-in-pos (point)) (delete-char 1)
  14941. (insert "(\n")
  14942. (when (or multi-in-list multi-out-list)
  14943. (insert "\n")
  14944. (indent-to (* 2 vhdl-basic-offset))
  14945. (insert "-- global ports\n"))
  14946. (setq port-beg-pos (point-marker) port-in-pos (point-marker)
  14947. port-out-pos (point-marker) port-inst-pos (point-marker)
  14948. port-end-pos (point-marker))
  14949. ;; insert generics, ports and signals
  14950. (setq inst-alist (nreverse inst-alist))
  14951. (while inst-alist
  14952. (setq inst-name (nth 0 (car inst-alist))
  14953. constant-alist (nth 1 (car inst-alist))
  14954. signal-alist (nth 2 (car inst-alist))
  14955. constant-temp-pos generic-inst-pos
  14956. port-temp-pos port-inst-pos
  14957. signal-temp-pos signal-pos)
  14958. ;; generics
  14959. (while constant-alist
  14960. (setq constant-name (downcase (caar constant-alist))
  14961. constant-entry (car constant-alist))
  14962. (cond ((member constant-name written-list)
  14963. nil)
  14964. ((member constant-name multi-list)
  14965. (vhdl-goto-marker generic-pos)
  14966. (setq generic-end-pos
  14967. (vhdl-max-marker
  14968. generic-end-pos
  14969. (vhdl-compose-insert-generic constant-entry)))
  14970. (setq generic-pos (point-marker))
  14971. (add-to-list 'written-list constant-name))
  14972. (t
  14973. (vhdl-goto-marker
  14974. (vhdl-max-marker generic-inst-pos generic-pos))
  14975. (setq generic-end-pos
  14976. (vhdl-compose-insert-generic constant-entry))
  14977. (setq generic-inst-pos (point-marker))
  14978. (add-to-list 'written-list constant-name)))
  14979. (setq constant-alist (cdr constant-alist)))
  14980. (when (/= constant-temp-pos generic-inst-pos)
  14981. (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
  14982. (insert "\n") (indent-to (* 2 vhdl-basic-offset))
  14983. (insert "-- generics for \"" inst-name "\"\n")
  14984. (vhdl-goto-marker generic-inst-pos))
  14985. ;; ports and signals
  14986. (while signal-alist
  14987. (setq signal-name (downcase (caar signal-alist))
  14988. signal-entry (car signal-alist))
  14989. (cond ((member signal-name written-list)
  14990. nil)
  14991. ((member signal-name multi-in-list)
  14992. (vhdl-goto-marker port-in-pos)
  14993. (setq port-end-pos
  14994. (vhdl-max-marker
  14995. port-end-pos (vhdl-compose-insert-port signal-entry)))
  14996. (setq port-in-pos (point-marker))
  14997. (add-to-list 'written-list signal-name))
  14998. ((member signal-name multi-out-list)
  14999. (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
  15000. (setq port-end-pos
  15001. (vhdl-max-marker
  15002. port-end-pos (vhdl-compose-insert-port signal-entry)))
  15003. (setq port-out-pos (point-marker))
  15004. (add-to-list 'written-list signal-name))
  15005. ((or (member signal-name single-in-list)
  15006. (member signal-name single-out-list))
  15007. (vhdl-goto-marker
  15008. (vhdl-max-marker
  15009. port-inst-pos
  15010. (vhdl-max-marker port-out-pos port-in-pos)))
  15011. (setq port-end-pos (vhdl-compose-insert-port signal-entry))
  15012. (setq port-inst-pos (point-marker))
  15013. (add-to-list 'written-list signal-name))
  15014. ((equal (upcase (nth 2 signal-entry)) "OUT")
  15015. (vhdl-goto-marker signal-pos)
  15016. (vhdl-compose-insert-signal signal-entry)
  15017. (setq signal-pos (point-marker))
  15018. (add-to-list 'written-list signal-name)))
  15019. (setq signal-alist (cdr signal-alist)))
  15020. (when (/= port-temp-pos port-inst-pos)
  15021. (vhdl-goto-marker
  15022. (vhdl-max-marker port-temp-pos
  15023. (vhdl-max-marker port-in-pos port-out-pos)))
  15024. (insert "\n") (indent-to (* 2 vhdl-basic-offset))
  15025. (insert "-- ports to \"" inst-name "\"\n")
  15026. (vhdl-goto-marker port-inst-pos))
  15027. (when (/= signal-temp-pos signal-pos)
  15028. (vhdl-goto-marker signal-temp-pos)
  15029. (insert "\n") (indent-to vhdl-basic-offset)
  15030. (insert "-- outputs of \"" inst-name "\"\n")
  15031. (vhdl-goto-marker signal-pos))
  15032. (setq inst-alist (cdr inst-alist)))
  15033. ;; finalize generic/port clause
  15034. (vhdl-goto-marker generic-end-pos) (backward-char)
  15035. (when (= generic-beg-pos generic-end-pos)
  15036. (insert "\n") (indent-to (* 2 vhdl-basic-offset))
  15037. (insert ";") (backward-char))
  15038. (insert ")")
  15039. (vhdl-goto-marker port-end-pos) (backward-char)
  15040. (when (= port-beg-pos port-end-pos)
  15041. (insert "\n") (indent-to (* 2 vhdl-basic-offset))
  15042. (insert ";") (backward-char))
  15043. (insert ")")
  15044. ;; align everything
  15045. (when vhdl-auto-align
  15046. (vhdl-goto-marker generic-beg-pos)
  15047. (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
  15048. (vhdl-align-region-groups port-beg-pos port-end-pos 1)
  15049. (vhdl-goto-marker signal-beg-pos)
  15050. (vhdl-align-region-groups signal-beg-pos signal-pos))
  15051. (switch-to-buffer (marker-buffer signal-beg-pos))
  15052. (message "Wiring components...done")))))
  15053. (defun vhdl-compose-insert-generic (entry)
  15054. "Insert ENTRY as generic declaration."
  15055. (let (pos)
  15056. (indent-to (* 2 vhdl-basic-offset))
  15057. (insert (nth 0 entry) " : " (nth 1 entry))
  15058. (when (nth 2 entry)
  15059. (insert " := " (nth 2 entry)))
  15060. (insert ";")
  15061. (setq pos (point-marker))
  15062. (when (and vhdl-include-port-comments (nth 3 entry))
  15063. (vhdl-comment-insert-inline (nth 3 entry) t))
  15064. (insert "\n")
  15065. pos))
  15066. (defun vhdl-compose-insert-port (entry)
  15067. "Insert ENTRY as port declaration."
  15068. (let (pos)
  15069. (indent-to (* 2 vhdl-basic-offset))
  15070. (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
  15071. (setq pos (point-marker))
  15072. (when (and vhdl-include-port-comments (nth 4 entry))
  15073. (vhdl-comment-insert-inline (nth 4 entry) t))
  15074. (insert "\n")
  15075. pos))
  15076. (defun vhdl-compose-insert-signal (entry)
  15077. "Insert ENTRY as signal declaration."
  15078. (indent-to vhdl-basic-offset)
  15079. (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
  15080. (when (and vhdl-include-port-comments (nth 4 entry))
  15081. (vhdl-comment-insert-inline (nth 4 entry) t))
  15082. (insert "\n"))
  15083. (defun vhdl-compose-components-package ()
  15084. "Generate a package containing component declarations for all entities in the
  15085. current project/directory."
  15086. (interactive)
  15087. (vhdl-require-hierarchy-info)
  15088. (let* ((project (vhdl-project-p))
  15089. (pack-name (vhdl-get-components-package-name))
  15090. (pack-file-name
  15091. (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
  15092. "." (file-name-extension (buffer-file-name))))
  15093. (ent-alist (aget vhdl-entity-alist
  15094. (or project default-directory) t))
  15095. (lazy-lock-minimum-size 0)
  15096. clause-pos component-pos)
  15097. (message "Generating components package \"%s\"..." pack-name)
  15098. ;; open package file
  15099. (when (and (file-exists-p pack-file-name)
  15100. (not (y-or-n-p (concat "File \"" pack-file-name
  15101. "\" exists; overwrite? "))))
  15102. (error "ERROR: Generating components package...aborted"))
  15103. (find-file pack-file-name)
  15104. (erase-buffer)
  15105. ;; insert header
  15106. (if vhdl-compose-include-header
  15107. (progn (vhdl-template-header
  15108. (concat "Components package (generated by Emacs VHDL Mode "
  15109. vhdl-version ")"))
  15110. (goto-char (point-max)))
  15111. (vhdl-comment-display-line) (insert "\n\n"))
  15112. ;; insert std_logic_1164 package
  15113. (vhdl-template-package-std-logic-1164)
  15114. (insert "\n") (setq clause-pos (point-marker))
  15115. (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
  15116. ;; insert package declaration
  15117. (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
  15118. (vhdl-insert-keyword " IS\n\n")
  15119. (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
  15120. (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
  15121. (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
  15122. (indent-to vhdl-basic-offset)
  15123. (setq component-pos (point-marker))
  15124. (insert "\n\n") (vhdl-insert-keyword "END ")
  15125. (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
  15126. (insert pack-name ";\n\n")
  15127. ;; insert footer
  15128. (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
  15129. (vhdl-template-footer)
  15130. (vhdl-comment-display-line) (insert "\n"))
  15131. ;; insert component declarations
  15132. (while ent-alist
  15133. (vhdl-visit-file (nth 2 (car ent-alist)) nil
  15134. (progn (goto-char (point-min))
  15135. (forward-line (1- (nth 3 (car ent-alist))))
  15136. (end-of-line)
  15137. (vhdl-port-copy)))
  15138. (goto-char component-pos)
  15139. (vhdl-port-paste-component t)
  15140. (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
  15141. (setq component-pos (point-marker))
  15142. (goto-char clause-pos)
  15143. (vhdl-port-paste-context-clause pack-name)
  15144. (setq clause-pos (point-marker))
  15145. (setq ent-alist (cdr ent-alist)))
  15146. (goto-char (point-min))
  15147. (save-buffer)
  15148. (message "Generating components package \"%s\"...done\n File created: \"%s\""
  15149. pack-name pack-file-name)))
  15150. (defun vhdl-compose-configuration-architecture (ent-name arch-name ent-alist
  15151. conf-alist inst-alist
  15152. &optional insert-conf)
  15153. "Generate block configuration for architecture."
  15154. (let ((margin (current-indentation))
  15155. (beg (point-at-bol))
  15156. ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
  15157. ;; insert block configuration (for architecture)
  15158. (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
  15159. (setq margin (+ margin vhdl-basic-offset))
  15160. ;; process all instances
  15161. (while inst-alist
  15162. (setq inst-entry (car inst-alist))
  15163. ;; is component?
  15164. (when (nth 4 inst-entry)
  15165. (setq insert-conf t)
  15166. (setq inst-path (nth 9 inst-entry))
  15167. ;; skip common path with previous instance
  15168. (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
  15169. (setq inst-path (cdr inst-path)
  15170. inst-prev-path (cdr inst-prev-path)))
  15171. ;; insert block configuration end (for previous block/generate)
  15172. (while inst-prev-path
  15173. (setq margin (- margin vhdl-basic-offset))
  15174. (indent-to margin)
  15175. (vhdl-insert-keyword "END FOR;\n")
  15176. (setq inst-prev-path (cdr inst-prev-path)))
  15177. ;; insert block configuration beginning (for current block/generate)
  15178. (indent-to margin)
  15179. (while inst-path
  15180. (setq margin (+ margin vhdl-basic-offset))
  15181. (vhdl-insert-keyword "FOR ")
  15182. (insert (car inst-path) "\n")
  15183. (indent-to margin)
  15184. (setq inst-path (cdr inst-path)))
  15185. ;; insert component configuration beginning
  15186. (vhdl-insert-keyword "FOR ")
  15187. (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
  15188. ;; find subconfiguration
  15189. (setq conf-key (nth 7 inst-entry))
  15190. (setq tmp-alist conf-alist)
  15191. ;; use first configuration found for instance's entity
  15192. (while (and tmp-alist (null conf-key))
  15193. (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
  15194. (setq conf-key (nth 0 (car tmp-alist))))
  15195. (setq tmp-alist (cdr tmp-alist)))
  15196. (setq conf-entry (aget conf-alist conf-key t))
  15197. ;; insert binding indication ...
  15198. ;; ... with subconfiguration (if exists)
  15199. (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
  15200. (progn
  15201. (indent-to (+ margin vhdl-basic-offset))
  15202. (vhdl-insert-keyword "USE CONFIGURATION ")
  15203. (insert (vhdl-work-library) "." (nth 0 conf-entry))
  15204. (insert ";\n"))
  15205. ;; ... with entity (if exists)
  15206. (setq ent-entry (aget ent-alist (nth 5 inst-entry) t))
  15207. (when ent-entry
  15208. (indent-to (+ margin vhdl-basic-offset))
  15209. (vhdl-insert-keyword "USE ENTITY ")
  15210. (insert (vhdl-work-library) "." (nth 0 ent-entry))
  15211. ;; insert architecture name (if architecture exists)
  15212. (when (nth 3 ent-entry)
  15213. (setq arch-name
  15214. ;; choose architecture name a) from configuration,
  15215. ;; b) from mra, or c) from first architecture
  15216. (or (nth 0 (aget (nth 3 ent-entry)
  15217. (or (nth 6 inst-entry)
  15218. (nth 4 ent-entry)) t))
  15219. (nth 1 (car (nth 3 ent-entry)))))
  15220. (insert "(" arch-name ")"))
  15221. (insert ";\n")
  15222. ;; insert block configuration (for architecture of subcomponent)
  15223. (when (and vhdl-compose-configuration-hierarchical
  15224. (nth 3 ent-entry))
  15225. (indent-to (+ margin vhdl-basic-offset))
  15226. (vhdl-compose-configuration-architecture
  15227. (nth 0 ent-entry) arch-name ent-alist conf-alist
  15228. (nth 3 (aget (nth 3 ent-entry) (downcase arch-name) t))))))
  15229. ;; insert component configuration end
  15230. (indent-to margin)
  15231. (vhdl-insert-keyword "END FOR;\n")
  15232. (setq inst-prev-path (nth 9 inst-entry)))
  15233. (setq inst-alist (cdr inst-alist)))
  15234. ;; insert block configuration end (for block/generate)
  15235. (while inst-prev-path
  15236. (setq margin (- margin vhdl-basic-offset))
  15237. (indent-to margin)
  15238. (vhdl-insert-keyword "END FOR;\n")
  15239. (setq inst-prev-path (cdr inst-prev-path)))
  15240. (indent-to (- margin vhdl-basic-offset))
  15241. ;; insert block configuration end or remove beginning (for architecture)
  15242. (if insert-conf
  15243. (vhdl-insert-keyword "END FOR;\n")
  15244. (delete-region beg (point)))))
  15245. (defun vhdl-compose-configuration (&optional ent-name arch-name)
  15246. "Generate configuration declaration."
  15247. (interactive)
  15248. (vhdl-require-hierarchy-info)
  15249. (let ((ent-alist (aget vhdl-entity-alist
  15250. (or (vhdl-project-p) default-directory) t))
  15251. (conf-alist (aget vhdl-config-alist
  15252. (or (vhdl-project-p) default-directory) t))
  15253. (from-speedbar ent-name)
  15254. inst-alist conf-name conf-file-name pos)
  15255. (vhdl-prepare-search-2
  15256. ;; get entity and architecture name
  15257. (unless ent-name
  15258. (save-excursion
  15259. (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
  15260. (not (equal "END" (upcase (match-string 1))))
  15261. (setq ent-name (match-string-no-properties 3))
  15262. (setq arch-name (match-string-no-properties 2)))
  15263. (error "ERROR: Not within an architecture"))))
  15264. (setq conf-name (vhdl-replace-string
  15265. vhdl-compose-configuration-name
  15266. (concat ent-name " " arch-name)))
  15267. (setq inst-alist
  15268. (nth 3 (aget (nth 3 (aget ent-alist (downcase ent-name) t))
  15269. (downcase arch-name) t))))
  15270. (message "Generating configuration \"%s\"..." conf-name)
  15271. (if vhdl-compose-configuration-create-file
  15272. ;; open configuration file
  15273. (progn
  15274. (setq conf-file-name
  15275. (concat (vhdl-replace-string vhdl-configuration-file-name
  15276. conf-name t)
  15277. "." (file-name-extension (buffer-file-name))))
  15278. (when (and (file-exists-p conf-file-name)
  15279. (not (y-or-n-p (concat "File \"" conf-file-name
  15280. "\" exists; overwrite? "))))
  15281. (error "ERROR: Creating configuration...aborted"))
  15282. (find-file conf-file-name)
  15283. (erase-buffer)
  15284. (set-buffer-modified-p nil)
  15285. ;; insert header
  15286. (if vhdl-compose-include-header
  15287. (progn (vhdl-template-header
  15288. (concat "Configuration declaration for design \""
  15289. ent-name "(" arch-name ")\""))
  15290. (goto-char (point-max)))
  15291. (vhdl-comment-display-line) (insert "\n\n")))
  15292. ;; goto end of architecture
  15293. (unless from-speedbar
  15294. (re-search-forward "^end\\>" nil)
  15295. (end-of-line) (insert "\n\n")
  15296. (vhdl-comment-display-line) (insert "\n\n")))
  15297. ;; insert library clause
  15298. (setq pos (point))
  15299. (vhdl-template-standard-package (vhdl-work-library) nil)
  15300. (when (/= pos (point))
  15301. (insert "\n\n"))
  15302. ;; insert configuration
  15303. (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
  15304. (vhdl-insert-keyword " OF ") (insert ent-name)
  15305. (vhdl-insert-keyword " IS\n")
  15306. (indent-to vhdl-basic-offset)
  15307. ;; insert block configuration (for architecture)
  15308. (vhdl-compose-configuration-architecture
  15309. ent-name arch-name ent-alist conf-alist inst-alist t)
  15310. (vhdl-insert-keyword "END ") (insert conf-name ";")
  15311. (when conf-file-name
  15312. ;; insert footer and save
  15313. (insert "\n\n")
  15314. (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
  15315. (vhdl-template-footer)
  15316. (vhdl-comment-display-line) (insert "\n"))
  15317. (save-buffer))
  15318. (message "%s"
  15319. (concat (format "Generating configuration \"%s\"...done" conf-name)
  15320. (and conf-file-name
  15321. (format "\n File created: \"%s\"" conf-file-name))))))
  15322. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15323. ;;; Compilation / Makefile generation
  15324. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15325. ;; (using `compile.el')
  15326. (defvar vhdl-compile-post-command ""
  15327. "String appended to compile command after file name.")
  15328. (defun vhdl-makefile-name ()
  15329. "Return the Makefile name of the current project or the current compiler if
  15330. no project is defined."
  15331. (let ((project-alist (aget vhdl-project-alist vhdl-project))
  15332. (compiler-alist (aget vhdl-compiler-alist vhdl-compiler)))
  15333. (vhdl-replace-string
  15334. (cons "\\(.*\\)\n\\(.*\\)"
  15335. (or (nth 8 project-alist) (nth 8 compiler-alist)))
  15336. (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
  15337. (defun vhdl-compile-directory ()
  15338. "Return the directory where compilation/make should be run."
  15339. (let* ((project (aget vhdl-project-alist (vhdl-project-p t)))
  15340. (compiler (aget vhdl-compiler-alist vhdl-compiler))
  15341. (directory (vhdl-resolve-env-variable
  15342. (if project
  15343. (vhdl-replace-string
  15344. (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
  15345. (nth 6 compiler)))))
  15346. (file-name-as-directory
  15347. (if (file-name-absolute-p directory)
  15348. directory
  15349. (expand-file-name directory (vhdl-default-directory))))))
  15350. (defun vhdl-uniquify (in-list)
  15351. "Remove duplicate elements from IN-LIST."
  15352. (let (out-list)
  15353. (while in-list
  15354. (add-to-list 'out-list (car in-list))
  15355. (setq in-list (cdr in-list)))
  15356. out-list))
  15357. (defun vhdl-set-compiler (name)
  15358. "Set current compiler to NAME."
  15359. (interactive
  15360. (list (let ((completion-ignore-case t))
  15361. (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
  15362. (if (assoc name vhdl-compiler-alist)
  15363. (progn (setq vhdl-compiler name)
  15364. (message "Current compiler: \"%s\"" vhdl-compiler))
  15365. (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
  15366. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15367. ;; Compilation
  15368. (defun vhdl-compile-init ()
  15369. "Initialize for compilation."
  15370. (when (or (null compilation-error-regexp-alist)
  15371. (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
  15372. compilation-error-regexp-alist)))
  15373. ;; `compilation-error-regexp-alist'
  15374. (let ((commands-alist vhdl-compiler-alist)
  15375. regexp-alist sublist)
  15376. (while commands-alist
  15377. (setq sublist (nth 11 (car commands-alist)))
  15378. (unless (or (equal "" (car sublist))
  15379. (assoc (car sublist) regexp-alist))
  15380. (setq regexp-alist (cons (list (nth 0 sublist)
  15381. (if (= 0 (nth 1 sublist))
  15382. (if (featurep 'xemacs) 9 nil)
  15383. (nth 1 sublist))
  15384. (nth 2 sublist) (nth 3 sublist))
  15385. regexp-alist)))
  15386. (setq commands-alist (cdr commands-alist)))
  15387. (setq compilation-error-regexp-alist
  15388. (append compilation-error-regexp-alist (nreverse regexp-alist))))
  15389. ;; `compilation-file-regexp-alist'
  15390. (let ((commands-alist vhdl-compiler-alist)
  15391. regexp-alist sublist)
  15392. ;; matches vhdl-mode file name output
  15393. (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
  15394. (while commands-alist
  15395. (setq sublist (nth 12 (car commands-alist)))
  15396. (unless (or (equal "" (car sublist))
  15397. (assoc (car sublist) regexp-alist))
  15398. (setq regexp-alist (cons sublist regexp-alist)))
  15399. (setq commands-alist (cdr commands-alist)))
  15400. (setq compilation-file-regexp-alist
  15401. (append compilation-file-regexp-alist (nreverse regexp-alist))))))
  15402. (defvar vhdl-compile-file-name nil
  15403. "Name of file to be compiled.")
  15404. (defun vhdl-compile-print-file-name ()
  15405. "Function called within `compile' to print out file name for compilers that
  15406. do not print any file names."
  15407. (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
  15408. (defun vhdl-get-compile-options (project compiler file-name
  15409. &optional file-options-only)
  15410. "Get compiler options. Returning nil means do not compile this file."
  15411. (let* ((compiler-options (nth 1 compiler))
  15412. (project-entry (aget (nth 4 project) vhdl-compiler))
  15413. (project-options (nth 0 project-entry))
  15414. (exception-list (and file-name (nth 2 project-entry)))
  15415. (work-library (vhdl-work-library))
  15416. (case-fold-search nil)
  15417. file-options)
  15418. (while (and exception-list
  15419. (not (string-match (caar exception-list) file-name)))
  15420. (setq exception-list (cdr exception-list)))
  15421. (if (and exception-list (not (cdar exception-list)))
  15422. nil
  15423. (if (and file-options-only (not exception-list))
  15424. 'default
  15425. (setq file-options (cdar exception-list))
  15426. ;; insert library name in compiler-specific options
  15427. (setq compiler-options
  15428. (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
  15429. work-library))
  15430. ;; insert compiler-specific options in project-specific options
  15431. (when project-options
  15432. (setq project-options
  15433. (vhdl-replace-string
  15434. (cons "\\(.*\\)\n\\(.*\\)" project-options)
  15435. (concat work-library "\n" compiler-options))))
  15436. ;; insert project-specific options in file-specific options
  15437. (when file-options
  15438. (setq file-options
  15439. (vhdl-replace-string
  15440. (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
  15441. (concat work-library "\n" compiler-options "\n"
  15442. project-options))))
  15443. ;; return options
  15444. (or file-options project-options compiler-options)))))
  15445. (defun vhdl-get-make-options (project compiler)
  15446. "Get make options."
  15447. (let* ((compiler-options (nth 3 compiler))
  15448. (project-entry (aget (nth 4 project) vhdl-compiler))
  15449. (project-options (nth 1 project-entry))
  15450. (makefile-name (vhdl-makefile-name)))
  15451. ;; insert Makefile name in compiler-specific options
  15452. (setq compiler-options
  15453. (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
  15454. makefile-name))
  15455. ;; insert compiler-specific options in project-specific options
  15456. (when project-options
  15457. (setq project-options
  15458. (vhdl-replace-string
  15459. (cons "\\(.*\\)\n\\(.*\\)" project-options)
  15460. (concat makefile-name "\n" compiler-options))))
  15461. ;; return options
  15462. (or project-options compiler-options)))
  15463. (defun vhdl-compile ()
  15464. "Compile current buffer using the VHDL compiler specified in
  15465. `vhdl-compiler'."
  15466. (interactive)
  15467. (vhdl-compile-init)
  15468. (let* ((project (aget vhdl-project-alist vhdl-project))
  15469. (compiler (or (aget vhdl-compiler-alist vhdl-compiler nil)
  15470. (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
  15471. (command (nth 0 compiler))
  15472. (default-directory (vhdl-compile-directory))
  15473. (file-name (if vhdl-compile-absolute-path
  15474. (buffer-file-name)
  15475. (file-relative-name (buffer-file-name))))
  15476. (options (vhdl-get-compile-options project compiler file-name))
  15477. compilation-process-setup-function)
  15478. (unless (file-directory-p default-directory)
  15479. (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
  15480. ;; put file name into quotes if it contains spaces
  15481. (when (string-match " " file-name)
  15482. (setq file-name (concat "\"" file-name "\"")))
  15483. ;; print out file name if compiler does not
  15484. (setq vhdl-compile-file-name (if vhdl-compile-absolute-path
  15485. (buffer-file-name)
  15486. (file-relative-name (buffer-file-name))))
  15487. (when (and (= 0 (nth 1 (nth 10 compiler)))
  15488. (= 0 (nth 1 (nth 11 compiler))))
  15489. (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
  15490. ;; run compilation
  15491. (if options
  15492. (when command
  15493. (compile (concat command " " options " " file-name
  15494. (unless (equal vhdl-compile-post-command "")
  15495. (concat " " vhdl-compile-post-command)))))
  15496. (vhdl-warning "Your project settings tell me not to compile this file"))))
  15497. (defvar vhdl-make-target "all"
  15498. "Default target for `vhdl-make' command.")
  15499. (defun vhdl-make (&optional target)
  15500. "Call make command for compilation of all updated source files (requires
  15501. `Makefile'). Optional argument TARGET allows to compile the design
  15502. specified by a target."
  15503. (interactive)
  15504. (setq vhdl-make-target
  15505. (or target (read-from-minibuffer "Target: " vhdl-make-target
  15506. vhdl-minibuffer-local-map)))
  15507. (vhdl-compile-init)
  15508. (let* ((project (aget vhdl-project-alist vhdl-project))
  15509. (compiler (or (aget vhdl-compiler-alist vhdl-compiler)
  15510. (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
  15511. (command (nth 2 compiler))
  15512. (options (vhdl-get-make-options project compiler))
  15513. (default-directory (vhdl-compile-directory)))
  15514. (unless (file-directory-p default-directory)
  15515. (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
  15516. ;; run make
  15517. (compile (concat (if (equal command "") "make" command)
  15518. " " options " " vhdl-make-target))))
  15519. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15520. ;; Makefile generation
  15521. (defun vhdl-generate-makefile ()
  15522. "Generate `Makefile'."
  15523. (interactive)
  15524. (let* ((compiler (or (aget vhdl-compiler-alist vhdl-compiler)
  15525. (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
  15526. (command (nth 4 compiler)))
  15527. ;; generate makefile
  15528. (if command
  15529. (let ((default-directory (vhdl-compile-directory)))
  15530. (compile (vhdl-replace-string
  15531. (cons "\\(.*\\) \\(.*\\)" command)
  15532. (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
  15533. (vhdl-generate-makefile-1))))
  15534. (defun vhdl-get-packages (lib-alist work-library)
  15535. "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
  15536. (let (pack-list)
  15537. (while lib-alist
  15538. (when (equal (downcase (caar lib-alist)) (downcase work-library))
  15539. (setq pack-list (cons (cdar lib-alist) pack-list)))
  15540. (setq lib-alist (cdr lib-alist)))
  15541. pack-list))
  15542. (defun vhdl-generate-makefile-1 ()
  15543. "Generate Makefile for current project or directory."
  15544. ;; scan hierarchy if required
  15545. (if (vhdl-project-p)
  15546. (unless (or (assoc vhdl-project vhdl-file-alist)
  15547. (vhdl-load-cache vhdl-project))
  15548. (vhdl-scan-project-contents vhdl-project))
  15549. (let ((directory (abbreviate-file-name default-directory)))
  15550. (unless (or (assoc directory vhdl-file-alist)
  15551. (vhdl-load-cache directory))
  15552. (vhdl-scan-directory-contents directory))))
  15553. (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
  15554. (project (vhdl-project-p))
  15555. (ent-alist (aget vhdl-entity-alist (or project directory) t))
  15556. (conf-alist (aget vhdl-config-alist (or project directory) t))
  15557. (pack-alist (aget vhdl-package-alist (or project directory) t))
  15558. (regexp-list (nth 12 (aget vhdl-compiler-alist vhdl-compiler)))
  15559. (ent-regexp (cons "\\(.*\\)" (nth 0 regexp-list)))
  15560. (arch-regexp (cons "\\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
  15561. (conf-regexp (cons "\\(.*\\)" (nth 2 regexp-list)))
  15562. (pack-regexp (cons "\\(.*\\)" (nth 3 regexp-list)))
  15563. (pack-body-regexp (cons "\\(.*\\)" (nth 4 regexp-list)))
  15564. (adjust-case (nth 5 regexp-list))
  15565. (work-library (downcase (vhdl-work-library)))
  15566. (compile-directory (expand-file-name (vhdl-compile-directory)
  15567. default-directory))
  15568. (makefile-name (vhdl-makefile-name))
  15569. rule-alist arch-alist inst-alist
  15570. target-list depend-list unit-list prim-list second-list subcomp-list
  15571. lib-alist lib-body-alist pack-list all-pack-list
  15572. ent-key ent-file-name arch-key arch-file-name ent-arch-key
  15573. conf-key conf-file-name pack-key pack-file-name
  15574. ent-entry arch-entry conf-entry pack-entry inst-entry
  15575. pack-body-key pack-body-file-name inst-ent-key inst-conf-key
  15576. tmp-key tmp-list rule)
  15577. ;; check prerequisites
  15578. (unless (file-exists-p compile-directory)
  15579. (make-directory compile-directory t))
  15580. (unless regexp-list
  15581. (error "Please contact the VHDL Mode maintainer for support of \"%s\""
  15582. vhdl-compiler))
  15583. (message "Generating makefile \"%s\"..." makefile-name)
  15584. ;; rules for all entities
  15585. (setq tmp-list ent-alist)
  15586. (while ent-alist
  15587. (setq ent-entry (car ent-alist)
  15588. ent-key (nth 0 ent-entry))
  15589. (when (nth 2 ent-entry)
  15590. (setq ent-file-name (file-relative-name
  15591. (nth 2 ent-entry) compile-directory)
  15592. arch-alist (nth 4 ent-entry)
  15593. lib-alist (nth 6 ent-entry)
  15594. rule (aget rule-alist ent-file-name)
  15595. target-list (nth 0 rule)
  15596. depend-list (nth 1 rule)
  15597. second-list nil
  15598. subcomp-list nil)
  15599. (setq tmp-key (vhdl-replace-string
  15600. ent-regexp (funcall adjust-case ent-key)))
  15601. (setq unit-list (cons (cons ent-key tmp-key) unit-list))
  15602. ;; rule target for this entity
  15603. (setq target-list (cons ent-key target-list))
  15604. ;; rule dependencies for all used packages
  15605. (setq pack-list (vhdl-get-packages lib-alist work-library))
  15606. (setq depend-list (append depend-list pack-list))
  15607. (setq all-pack-list pack-list)
  15608. ;; add rule
  15609. (aput 'rule-alist ent-file-name (list target-list depend-list))
  15610. ;; rules for all corresponding architectures
  15611. (while arch-alist
  15612. (setq arch-entry (car arch-alist)
  15613. arch-key (nth 0 arch-entry)
  15614. ent-arch-key (concat ent-key "-" arch-key)
  15615. arch-file-name (file-relative-name (nth 2 arch-entry)
  15616. compile-directory)
  15617. inst-alist (nth 4 arch-entry)
  15618. lib-alist (nth 5 arch-entry)
  15619. rule (aget rule-alist arch-file-name)
  15620. target-list (nth 0 rule)
  15621. depend-list (nth 1 rule))
  15622. (setq tmp-key (vhdl-replace-string
  15623. arch-regexp
  15624. (funcall adjust-case (concat arch-key " " ent-key))))
  15625. (setq unit-list
  15626. (cons (cons ent-arch-key tmp-key) unit-list))
  15627. (setq second-list (cons ent-arch-key second-list))
  15628. ;; rule target for this architecture
  15629. (setq target-list (cons ent-arch-key target-list))
  15630. ;; rule dependency for corresponding entity
  15631. (setq depend-list (cons ent-key depend-list))
  15632. ;; rule dependencies for contained component instantiations
  15633. (while inst-alist
  15634. (setq inst-entry (car inst-alist))
  15635. (when (or (null (nth 8 inst-entry))
  15636. (equal (downcase (nth 8 inst-entry)) work-library))
  15637. (setq inst-ent-key (or (nth 7 inst-entry)
  15638. (nth 5 inst-entry)))
  15639. (setq depend-list (cons inst-ent-key depend-list)
  15640. subcomp-list (cons inst-ent-key subcomp-list)))
  15641. (setq inst-alist (cdr inst-alist)))
  15642. ;; rule dependencies for all used packages
  15643. (setq pack-list (vhdl-get-packages lib-alist work-library))
  15644. (setq depend-list (append depend-list pack-list))
  15645. (setq all-pack-list (append all-pack-list pack-list))
  15646. ;; add rule
  15647. (aput 'rule-alist arch-file-name (list target-list depend-list))
  15648. (setq arch-alist (cdr arch-alist)))
  15649. (setq prim-list (cons (list ent-key second-list
  15650. (append subcomp-list all-pack-list))
  15651. prim-list)))
  15652. (setq ent-alist (cdr ent-alist)))
  15653. (setq ent-alist tmp-list)
  15654. ;; rules for all configurations
  15655. (setq tmp-list conf-alist)
  15656. (while conf-alist
  15657. (setq conf-entry (car conf-alist)
  15658. conf-key (nth 0 conf-entry)
  15659. conf-file-name (file-relative-name
  15660. (nth 2 conf-entry) compile-directory)
  15661. ent-key (nth 4 conf-entry)
  15662. arch-key (nth 5 conf-entry)
  15663. inst-alist (nth 6 conf-entry)
  15664. lib-alist (nth 7 conf-entry)
  15665. rule (aget rule-alist conf-file-name)
  15666. target-list (nth 0 rule)
  15667. depend-list (nth 1 rule)
  15668. subcomp-list (list ent-key))
  15669. (setq tmp-key (vhdl-replace-string
  15670. conf-regexp (funcall adjust-case conf-key)))
  15671. (setq unit-list (cons (cons conf-key tmp-key) unit-list))
  15672. ;; rule target for this configuration
  15673. (setq target-list (cons conf-key target-list))
  15674. ;; rule dependency for corresponding entity and architecture
  15675. (setq depend-list
  15676. (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
  15677. ;; rule dependencies for used packages
  15678. (setq pack-list (vhdl-get-packages lib-alist work-library))
  15679. (setq depend-list (append depend-list pack-list))
  15680. ;; rule dependencies for contained component configurations
  15681. (while inst-alist
  15682. (setq inst-entry (car inst-alist))
  15683. (setq inst-ent-key (nth 2 inst-entry)
  15684. ; comp-arch-key (nth 2 inst-entry))
  15685. inst-conf-key (nth 4 inst-entry))
  15686. (when (equal (downcase (nth 5 inst-entry)) work-library)
  15687. (when inst-ent-key
  15688. (setq depend-list (cons inst-ent-key depend-list)
  15689. subcomp-list (cons inst-ent-key subcomp-list)))
  15690. ; (when comp-arch-key
  15691. ; (setq depend-list (cons (concat comp-ent-key "-" comp-arch-key)
  15692. ; depend-list)))
  15693. (when inst-conf-key
  15694. (setq depend-list (cons inst-conf-key depend-list)
  15695. subcomp-list (cons inst-conf-key subcomp-list))))
  15696. (setq inst-alist (cdr inst-alist)))
  15697. ;; add rule
  15698. (aput 'rule-alist conf-file-name (list target-list depend-list))
  15699. (setq prim-list (cons (list conf-key nil (append subcomp-list pack-list))
  15700. prim-list))
  15701. (setq conf-alist (cdr conf-alist)))
  15702. (setq conf-alist tmp-list)
  15703. ;; rules for all packages
  15704. (setq tmp-list pack-alist)
  15705. (while pack-alist
  15706. (setq pack-entry (car pack-alist)
  15707. pack-key (nth 0 pack-entry)
  15708. pack-body-key nil)
  15709. (when (nth 2 pack-entry)
  15710. (setq pack-file-name (file-relative-name (nth 2 pack-entry)
  15711. compile-directory)
  15712. lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
  15713. rule (aget rule-alist pack-file-name)
  15714. target-list (nth 0 rule) depend-list (nth 1 rule))
  15715. (setq tmp-key (vhdl-replace-string
  15716. pack-regexp (funcall adjust-case pack-key)))
  15717. (setq unit-list (cons (cons pack-key tmp-key) unit-list))
  15718. ;; rule target for this package
  15719. (setq target-list (cons pack-key target-list))
  15720. ;; rule dependencies for all used packages
  15721. (setq pack-list (vhdl-get-packages lib-alist work-library))
  15722. (setq depend-list (append depend-list pack-list))
  15723. (setq all-pack-list pack-list)
  15724. ;; add rule
  15725. (aput 'rule-alist pack-file-name (list target-list depend-list))
  15726. ;; rules for this package's body
  15727. (when (nth 7 pack-entry)
  15728. (setq pack-body-key (concat pack-key "-body")
  15729. pack-body-file-name (file-relative-name (nth 7 pack-entry)
  15730. compile-directory)
  15731. rule (aget rule-alist pack-body-file-name)
  15732. target-list (nth 0 rule)
  15733. depend-list (nth 1 rule))
  15734. (setq tmp-key (vhdl-replace-string
  15735. pack-body-regexp (funcall adjust-case pack-key)))
  15736. (setq unit-list
  15737. (cons (cons pack-body-key tmp-key) unit-list))
  15738. ;; rule target for this package's body
  15739. (setq target-list (cons pack-body-key target-list))
  15740. ;; rule dependency for corresponding package declaration
  15741. (setq depend-list (cons pack-key depend-list))
  15742. ;; rule dependencies for all used packages
  15743. (setq pack-list (vhdl-get-packages lib-body-alist work-library))
  15744. (setq depend-list (append depend-list pack-list))
  15745. (setq all-pack-list (append all-pack-list pack-list))
  15746. ;; add rule
  15747. (aput 'rule-alist pack-body-file-name
  15748. (list target-list depend-list)))
  15749. (setq prim-list
  15750. (cons (list pack-key (when pack-body-key (list pack-body-key))
  15751. all-pack-list)
  15752. prim-list)))
  15753. (setq pack-alist (cdr pack-alist)))
  15754. (setq pack-alist tmp-list)
  15755. ;; generate Makefile
  15756. (let* ((project (aget vhdl-project-alist project))
  15757. (compiler (aget vhdl-compiler-alist vhdl-compiler))
  15758. (compiler-id (nth 9 compiler))
  15759. (library-directory
  15760. (vhdl-resolve-env-variable
  15761. (vhdl-replace-string
  15762. (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
  15763. compiler-id)))
  15764. (makefile-path-name (expand-file-name
  15765. makefile-name compile-directory))
  15766. (orig-buffer (current-buffer))
  15767. cell second-list subcomp-list options unit-key unit-name)
  15768. ;; sort lists
  15769. (setq unit-list (vhdl-sort-alist unit-list))
  15770. (setq prim-list (vhdl-sort-alist prim-list))
  15771. (setq tmp-list rule-alist)
  15772. (while tmp-list ; pre-sort rule targets
  15773. (setq cell (cdar tmp-list))
  15774. (setcar cell (sort (car cell) 'string<))
  15775. (setq tmp-list (cdr tmp-list)))
  15776. (setq rule-alist ; sort by first rule target
  15777. (sort rule-alist
  15778. (function (lambda (a b)
  15779. (string< (car (cadr a)) (car (cadr b)))))))
  15780. ;; open and clear Makefile
  15781. (set-buffer (find-file-noselect makefile-path-name t t))
  15782. (erase-buffer)
  15783. (insert "# -*- Makefile -*-\n"
  15784. "### " (file-name-nondirectory makefile-name)
  15785. " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
  15786. "\n")
  15787. (if project
  15788. (insert "\n# Project : " (nth 0 project))
  15789. (insert "\n# Directory : \"" directory "\""))
  15790. (insert "\n# Platform : " vhdl-compiler
  15791. "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
  15792. (user-login-name) "\n")
  15793. ;; insert compile and option variable settings
  15794. (insert "\n\n# Define compilation command and options\n"
  15795. "\nCOMPILE = " (nth 0 compiler)
  15796. "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
  15797. (if (equal vhdl-compile-post-command "") ""
  15798. (concat "\nPOST-COMPILE = " vhdl-compile-post-command))
  15799. "\n")
  15800. ;; insert library paths
  15801. (setq library-directory
  15802. (directory-file-name
  15803. (if (file-name-absolute-p library-directory)
  15804. library-directory
  15805. (file-relative-name
  15806. (expand-file-name library-directory directory)
  15807. compile-directory))))
  15808. (insert "\n\n# Define library paths\n"
  15809. "\nLIBRARY-" work-library " = " library-directory "\n")
  15810. ;; insert variable definitions for all library unit files
  15811. (insert "\n\n# Define library unit files\n")
  15812. (setq tmp-list unit-list)
  15813. (while unit-list
  15814. (insert "\nUNIT-" work-library "-" (caar unit-list)
  15815. " = \\\n\t$(LIBRARY-" work-library ")/" (cdar unit-list))
  15816. (setq unit-list (cdr unit-list)))
  15817. ;; insert variable definition for list of all library unit files
  15818. (insert "\n\n\n# Define list of all library unit files\n"
  15819. "\nALL_UNITS =")
  15820. (setq unit-list tmp-list)
  15821. (while unit-list
  15822. (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
  15823. (setq unit-list (cdr unit-list)))
  15824. (insert "\n")
  15825. (setq unit-list tmp-list)
  15826. ;; insert `make all' rule
  15827. (insert "\n\n\n# Rule for compiling entire design\n"
  15828. "\n" (nth 0 vhdl-makefile-default-targets) " :"
  15829. " \\\n\t\t" (nth 2 vhdl-makefile-default-targets)
  15830. " \\\n\t\t$(ALL_UNITS)\n")
  15831. ;; insert `make clean' rule
  15832. (insert "\n\n# Rule for cleaning entire design\n"
  15833. "\n" (nth 1 vhdl-makefile-default-targets) " : "
  15834. "\n\t-rm -f $(ALL_UNITS)\n")
  15835. ;; insert `make library' rule
  15836. (insert "\n\n# Rule for creating library directory\n"
  15837. "\n" (nth 2 vhdl-makefile-default-targets) " :"
  15838. " \\\n\t\t$(LIBRARY-" work-library ")\n"
  15839. "\n$(LIBRARY-" work-library ") :"
  15840. "\n\t"
  15841. (vhdl-replace-string
  15842. (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
  15843. (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
  15844. "\n")
  15845. ;; insert '.PHONY' declaration
  15846. (insert "\n\n.PHONY : "
  15847. (nth 0 vhdl-makefile-default-targets) " "
  15848. (nth 1 vhdl-makefile-default-targets) " "
  15849. (nth 2 vhdl-makefile-default-targets) "\n")
  15850. ;; insert rule for each library unit
  15851. (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
  15852. (while prim-list
  15853. (setq second-list (sort (nth 1 (car prim-list)) 'string<))
  15854. (setq subcomp-list
  15855. (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
  15856. (setq unit-key (caar prim-list)
  15857. unit-name (or (nth 0 (aget ent-alist unit-key t))
  15858. (nth 0 (aget conf-alist unit-key t))
  15859. (nth 0 (aget pack-alist unit-key t))))
  15860. (insert "\n" unit-key)
  15861. (unless (equal unit-key unit-name)
  15862. (insert " \\\n" unit-name))
  15863. (insert " :"
  15864. " \\\n\t\t" (nth 2 vhdl-makefile-default-targets)
  15865. " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
  15866. (while second-list
  15867. (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
  15868. (setq second-list (cdr second-list)))
  15869. (while subcomp-list
  15870. (when (and (assoc (car subcomp-list) unit-list)
  15871. (not (equal unit-key (car subcomp-list))))
  15872. (insert " \\\n\t\t" (car subcomp-list)))
  15873. (setq subcomp-list (cdr subcomp-list)))
  15874. (insert "\n")
  15875. (setq prim-list (cdr prim-list)))
  15876. ;; insert rule for each library unit file
  15877. (insert "\n\n# Rules for compiling single library unit files\n")
  15878. (while rule-alist
  15879. (setq rule (car rule-alist))
  15880. ;; get compiler options for this file
  15881. (setq options
  15882. (vhdl-get-compile-options project compiler (nth 0 rule) t))
  15883. ;; insert rule if file is supposed to be compiled
  15884. (setq target-list (nth 1 rule)
  15885. depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
  15886. ;; insert targets
  15887. (setq tmp-list target-list)
  15888. (while target-list
  15889. (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
  15890. (if (cdr target-list) " \\" " :"))
  15891. (setq target-list (cdr target-list)))
  15892. (setq target-list tmp-list)
  15893. ;; insert file name as first dependency
  15894. (insert " \\\n\t\t" (nth 0 rule))
  15895. ;; insert dependencies (except if also target or unit does not exist)
  15896. (while depend-list
  15897. (when (and (not (member (car depend-list) target-list))
  15898. (assoc (car depend-list) unit-list))
  15899. (insert " \\\n\t\t"
  15900. "$(UNIT-" work-library "-" (car depend-list) ")"))
  15901. (setq depend-list (cdr depend-list)))
  15902. ;; insert compile command
  15903. (if options
  15904. (insert "\n\t$(COMPILE) "
  15905. (if (eq options 'default) "$(OPTIONS)" options) " "
  15906. (nth 0 rule)
  15907. (if (equal vhdl-compile-post-command "") ""
  15908. " $(POST-COMPILE)") "\n")
  15909. (setq tmp-list target-list)
  15910. (while target-list
  15911. (insert "\n\t@touch $(UNIT-" work-library "-" (car target-list) ")"
  15912. (if (cdr target-list) " \\" "\n"))
  15913. (setq target-list (cdr target-list)))
  15914. (setq target-list tmp-list))
  15915. (setq rule-alist (cdr rule-alist)))
  15916. (insert "\n\n### " makefile-name " ends here\n")
  15917. ;; run Makefile generation hook
  15918. (run-hooks 'vhdl-makefile-generation-hook)
  15919. (message "Generating makefile \"%s\"...done" makefile-name)
  15920. ;; save and close file
  15921. (if (file-writable-p makefile-path-name)
  15922. (progn (save-buffer)
  15923. (kill-buffer (current-buffer))
  15924. (set-buffer orig-buffer)
  15925. (add-to-history 'file-name-history makefile-path-name))
  15926. (vhdl-warning-when-idle
  15927. (format "File not writable: \"%s\""
  15928. (abbreviate-file-name makefile-path-name)))
  15929. (switch-to-buffer (current-buffer))))))
  15930. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15931. ;;; Bug reports
  15932. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15933. ;; (using `reporter.el')
  15934. (defconst vhdl-mode-help-address
  15935. "Reto Zimmermann <reto@gnu.org>"
  15936. "Address for VHDL Mode bug reports.")
  15937. (defun vhdl-submit-bug-report ()
  15938. "Submit via mail a bug report on VHDL Mode."
  15939. (interactive)
  15940. ;; load in reporter
  15941. (and
  15942. (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
  15943. (let ((reporter-prompt-for-summary-p t))
  15944. (reporter-submit-bug-report
  15945. vhdl-mode-help-address
  15946. (concat "VHDL Mode " vhdl-version)
  15947. (list
  15948. ;; report all important user options
  15949. 'vhdl-offsets-alist
  15950. 'vhdl-comment-only-line-offset
  15951. 'tab-width
  15952. 'vhdl-electric-mode
  15953. 'vhdl-stutter-mode
  15954. 'vhdl-indent-tabs-mode
  15955. 'vhdl-project-alist
  15956. 'vhdl-project
  15957. 'vhdl-project-file-name
  15958. 'vhdl-project-auto-load
  15959. 'vhdl-project-sort
  15960. 'vhdl-compiler-alist
  15961. 'vhdl-compiler
  15962. 'vhdl-compile-use-local-error-regexp
  15963. 'vhdl-makefile-default-targets
  15964. 'vhdl-makefile-generation-hook
  15965. 'vhdl-default-library
  15966. 'vhdl-standard
  15967. 'vhdl-basic-offset
  15968. 'vhdl-upper-case-keywords
  15969. 'vhdl-upper-case-types
  15970. 'vhdl-upper-case-attributes
  15971. 'vhdl-upper-case-enum-values
  15972. 'vhdl-upper-case-constants
  15973. 'vhdl-use-direct-instantiation
  15974. 'vhdl-array-index-record-field-in-sensitivity-list
  15975. 'vhdl-compose-configuration-name
  15976. 'vhdl-entity-file-name
  15977. 'vhdl-architecture-file-name
  15978. 'vhdl-configuration-file-name
  15979. 'vhdl-package-file-name
  15980. 'vhdl-file-name-case
  15981. 'vhdl-electric-keywords
  15982. 'vhdl-optional-labels
  15983. 'vhdl-insert-empty-lines
  15984. 'vhdl-argument-list-indent
  15985. 'vhdl-association-list-with-formals
  15986. 'vhdl-conditions-in-parenthesis
  15987. 'vhdl-zero-string
  15988. 'vhdl-one-string
  15989. 'vhdl-file-header
  15990. 'vhdl-file-footer
  15991. 'vhdl-company-name
  15992. 'vhdl-copyright-string
  15993. 'vhdl-platform-spec
  15994. 'vhdl-date-format
  15995. 'vhdl-modify-date-prefix-string
  15996. 'vhdl-modify-date-on-saving
  15997. 'vhdl-reset-kind
  15998. 'vhdl-reset-active-high
  15999. 'vhdl-clock-rising-edge
  16000. 'vhdl-clock-edge-condition
  16001. 'vhdl-clock-name
  16002. 'vhdl-reset-name
  16003. 'vhdl-model-alist
  16004. 'vhdl-include-port-comments
  16005. 'vhdl-include-direction-comments
  16006. 'vhdl-include-type-comments
  16007. 'vhdl-include-group-comments
  16008. 'vhdl-actual-port-name
  16009. 'vhdl-instance-name
  16010. 'vhdl-testbench-entity-name
  16011. 'vhdl-testbench-architecture-name
  16012. 'vhdl-testbench-configuration-name
  16013. 'vhdl-testbench-dut-name
  16014. 'vhdl-testbench-include-header
  16015. 'vhdl-testbench-declarations
  16016. 'vhdl-testbench-statements
  16017. 'vhdl-testbench-initialize-signals
  16018. 'vhdl-testbench-include-library
  16019. 'vhdl-testbench-include-configuration
  16020. 'vhdl-testbench-create-files
  16021. 'vhdl-testbench-entity-file-name
  16022. 'vhdl-testbench-architecture-file-name
  16023. 'vhdl-compose-create-files
  16024. 'vhdl-compose-configuration-create-file
  16025. 'vhdl-compose-configuration-hierarchical
  16026. 'vhdl-compose-configuration-use-subconfiguration
  16027. 'vhdl-compose-include-header
  16028. 'vhdl-compose-architecture-name
  16029. 'vhdl-components-package-name
  16030. 'vhdl-use-components-package
  16031. 'vhdl-self-insert-comments
  16032. 'vhdl-prompt-for-comments
  16033. 'vhdl-inline-comment-column
  16034. 'vhdl-end-comment-column
  16035. 'vhdl-auto-align
  16036. 'vhdl-align-groups
  16037. 'vhdl-align-group-separate
  16038. 'vhdl-align-same-indent
  16039. 'vhdl-highlight-keywords
  16040. 'vhdl-highlight-names
  16041. 'vhdl-highlight-special-words
  16042. 'vhdl-highlight-forbidden-words
  16043. 'vhdl-highlight-verilog-keywords
  16044. 'vhdl-highlight-translate-off
  16045. 'vhdl-highlight-case-sensitive
  16046. 'vhdl-special-syntax-alist
  16047. 'vhdl-forbidden-words
  16048. 'vhdl-forbidden-syntax
  16049. 'vhdl-directive-keywords
  16050. 'vhdl-speedbar-auto-open
  16051. 'vhdl-speedbar-display-mode
  16052. 'vhdl-speedbar-scan-limit
  16053. 'vhdl-speedbar-jump-to-unit
  16054. 'vhdl-speedbar-update-on-saving
  16055. 'vhdl-speedbar-save-cache
  16056. 'vhdl-speedbar-cache-file-name
  16057. 'vhdl-index-menu
  16058. 'vhdl-source-file-menu
  16059. 'vhdl-hideshow-menu
  16060. 'vhdl-hide-all-init
  16061. 'vhdl-print-two-column
  16062. 'vhdl-print-customize-faces
  16063. 'vhdl-intelligent-tab
  16064. 'vhdl-indent-syntax-based
  16065. 'vhdl-indent-comment-like-next-code-line
  16066. 'vhdl-word-completion-case-sensitive
  16067. 'vhdl-word-completion-in-minibuffer
  16068. 'vhdl-underscore-is-part-of-word
  16069. 'vhdl-mode-hook)
  16070. (function
  16071. (lambda ()
  16072. (insert
  16073. (if vhdl-special-indent-hook
  16074. (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
  16075. "vhdl-special-indent-hook is set to '"
  16076. (format "%s" vhdl-special-indent-hook)
  16077. ".\nPerhaps this is your problem?\n"
  16078. "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
  16079. "\n"))))
  16080. nil
  16081. "Hi Reto,"))))
  16082. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  16083. ;;; Documentation
  16084. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  16085. (defconst vhdl-doc-release-notes nil
  16086. "\
  16087. Release Notes for VHDL Mode 3.33
  16088. ================================
  16089. - New Features
  16090. - User Options
  16091. New Features
  16092. ------------
  16093. CONFIGURATION DECLARATION GENERATION:
  16094. - Automatic generation of a configuration declaration for a design.
  16095. (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
  16096. Key Bindings
  16097. ------------
  16098. For Emacs compliance the following key bindings have been changed:
  16099. - `C-c c' -> `C-c C-c' `vhdl-comment-uncomment-region'
  16100. - `C-c f' -> `C-c C-i C-f' `vhdl-fontify-buffer'
  16101. - `C-c s' -> `C-c C-i C-s' `vhdl-statistics-buffer'
  16102. - `C-c C-c ...' -> `C-c C-m ...' `vhdl-compose-...'
  16103. User Options
  16104. ------------
  16105. `vhdl-configuration-file-name': (new)
  16106. Specify how the configuration file name is obtained.
  16107. `vhdl-compose-configuration-name': (new)
  16108. Specify how the configuration name is obtained.
  16109. `vhdl-compose-configuration-create-file': (new)
  16110. Specify whether a new file should be created for a configuration.
  16111. `vhdl-compose-configuration-hierarchical': (new)
  16112. Specify whether hierarchical configurations should be created.
  16113. `vhdl-compose-configuration-use-subconfiguration': (new)
  16114. Specify whether subconfigurations should be used inside configurations.
  16115. `vhdl-makefile-default-targets': (new)
  16116. Customize names of Makefile default targets.
  16117. `vhdl-indent-comment-like-next-code-line': (new)
  16118. Specify whether comment lines are indented like following code line.
  16119. `vhdl-array-index-record-field-in-sensitivity-list': (new)
  16120. Specify whether to include array indices / record fields in sensitivity list.
  16121. ")
  16122. (defconst vhdl-doc-keywords nil
  16123. "\
  16124. Reserved words in VHDL
  16125. ----------------------
  16126. VHDL'93/02 (IEEE Std 1076-1993/2002):
  16127. `vhdl-02-keywords' : keywords
  16128. `vhdl-02-types' : standardized types
  16129. `vhdl-02-attributes' : standardized attributes
  16130. `vhdl-02-enum-values' : standardized enumeration values
  16131. `vhdl-02-functions' : standardized functions
  16132. `vhdl-02-packages' : standardized packages and libraries
  16133. VHDL-AMS (IEEE Std 1076.1 / 1076.1.1):
  16134. `vhdl-ams-keywords' : keywords
  16135. `vhdl-ams-types' : standardized types
  16136. `vhdl-ams-attributes' : standardized attributes
  16137. `vhdl-ams-enum-values' : standardized enumeration values
  16138. `vhdl-ams-constants' : standardized constants
  16139. `vhdl-ams-functions' : standardized functions
  16140. Math Packages (IEEE Std 1076.2):
  16141. `vhdl-math-types' : standardized types
  16142. `vhdl-math-constants' : standardized constants
  16143. `vhdl-math-functions' : standardized functions
  16144. `vhdl-math-packages' : standardized packages
  16145. Forbidden words:
  16146. `vhdl-verilog-keywords' : Verilog reserved words
  16147. NOTE: click `mouse-2' on variable names above (not in XEmacs).")
  16148. (defconst vhdl-doc-coding-style nil
  16149. "\
  16150. For VHDL coding style and naming convention guidelines, see the following
  16151. references:
  16152. \[1] Ben Cohen.
  16153. \"VHDL Coding Styles and Methodologies\".
  16154. Kluwer Academic Publishers, 1999.
  16155. http://members.aol.com/vhdlcohen/vhdl/
  16156. \[2] Michael Keating and Pierre Bricaud.
  16157. \"Reuse Methodology Manual, Second Edition\".
  16158. Kluwer Academic Publishers, 1999.
  16159. http://www.openmore.com/openmore/rmm2.html
  16160. \[3] European Space Agency.
  16161. \"VHDL Modelling Guidelines\".
  16162. ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
  16163. Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
  16164. to visually support naming conventions.")
  16165. (defun vhdl-version ()
  16166. "Echo the current version of VHDL Mode in the minibuffer."
  16167. (interactive)
  16168. (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
  16169. (vhdl-keep-region-active))
  16170. (defun vhdl-doc-variable (variable)
  16171. "Display VARIABLE's documentation in *Help* buffer."
  16172. (interactive)
  16173. (unless (featurep 'xemacs)
  16174. (help-setup-xref (list #'vhdl-doc-variable variable) (interactive-p)))
  16175. (with-output-to-temp-buffer
  16176. (if (fboundp 'help-buffer) (help-buffer) "*Help*")
  16177. (princ (documentation-property variable 'variable-documentation))
  16178. (with-current-buffer standard-output
  16179. (help-mode))
  16180. (help-print-return-message)))
  16181. (defun vhdl-doc-mode ()
  16182. "Display VHDL Mode documentation in *Help* buffer."
  16183. (interactive)
  16184. (unless (featurep 'xemacs)
  16185. (help-setup-xref (list #'vhdl-doc-mode) (interactive-p)))
  16186. (with-output-to-temp-buffer
  16187. (if (fboundp 'help-buffer) (help-buffer) "*Help*")
  16188. (princ mode-name)
  16189. (princ " mode:\n")
  16190. (princ (documentation 'vhdl-mode))
  16191. (with-current-buffer standard-output
  16192. (help-mode))
  16193. (help-print-return-message)))
  16194. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  16195. (provide 'vhdl-mode)
  16196. ;;; vhdl-mode.el ends here