vhdl-mode.el 685 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925
  1. ;;; vhdl-mode.el --- major mode for editing VHDL code
  2. ;; Copyright (C) 1992-2015 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.37.1"
  13. "VHDL Mode version number.")
  14. (defconst vhdl-time-stamp "2015-01-15"
  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/'02/'08 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. ;; this updated version was only tested on: GNU Emacs 24.1
  60. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  61. ;; Installation
  62. ;; Prerequisites: GNU Emacs 20/21/22/23/24, XEmacs 20/21.
  63. ;; Put `vhdl-mode.el' into the `site-lisp' directory of your Emacs installation
  64. ;; or into an arbitrary directory that is added to the load path by the
  65. ;; following line in your Emacs start-up file `.emacs':
  66. ;; (push (expand-file-name "<directory-name>") load-path)
  67. ;; If you already have the compiled `vhdl-mode.elc' file, put it in the same
  68. ;; directory. Otherwise, byte-compile the source file:
  69. ;; Emacs: M-x byte-compile-file RET vhdl-mode.el RET
  70. ;; Unix: emacs -batch -q -no-site-file -f batch-byte-compile vhdl-mode.el
  71. ;; Add the following lines to the `site-start.el' file in the `site-lisp'
  72. ;; directory of your Emacs installation or to your Emacs start-up file `.emacs'
  73. ;; (not required in Emacs 20 and higher):
  74. ;; (autoload 'vhdl-mode "vhdl-mode" "VHDL Mode" t)
  75. ;; (push '("\\.vhdl?\\'" . vhdl-mode) auto-mode-alist)
  76. ;; More detailed installation instructions are included in the official
  77. ;; VHDL Mode distribution.
  78. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  79. ;; Acknowledgments
  80. ;; Electrification ideas by Bob Pack <rlpst@cislabs.pitt.edu>
  81. ;; and Steve Grout.
  82. ;; Fontification approach suggested by Ken Wood <ken@eda.com.au>.
  83. ;; Ideas about alignment from John Wiegley <johnw@gnu.org>.
  84. ;; Many thanks to all the users who sent me bug reports and enhancement
  85. ;; requests.
  86. ;; Thanks to Colin Marquardt for his serious beta testing, his innumerable
  87. ;; enhancement suggestions and the fruitful discussions.
  88. ;; Thanks to Dan Nicolaescu for reviewing the code and for his valuable hints.
  89. ;; Thanks to Ulf Klaperski for the indentation speedup hint.
  90. ;; Special thanks go to Wolfgang Fichtner and the crew from the Integrated
  91. ;; Systems Laboratory, Swiss Federal Institute of Technology Zurich, for
  92. ;; giving me the opportunity to develop this code.
  93. ;; This work has been funded in part by MICROSWISS, a Microelectronics Program
  94. ;; of the Swiss Government.
  95. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  96. ;;; Code:
  97. ;; Emacs 21+ handling
  98. (defconst vhdl-emacs-21 (and (<= 21 emacs-major-version) (not (featurep 'xemacs)))
  99. "Non-nil if GNU Emacs 21, 22, ... is used.")
  100. ;; Emacs 22+ handling
  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. ;; 60: docal <= false;
  168. ;; ^^^^^
  169. ;; [Error] Assignment error: variable is illegal target of signal assignment
  170. ("ADVance MS" "vacom" "-work \\1" "make" "-f \\1"
  171. nil "valib \\1; vamap \\2 \\1" "./" "work/" "Makefile" "adms"
  172. ("^\\s-+\\([0-9]+\\):\\s-+" nil 1 nil) ("^Compiling file \\(.+\\)" 1)
  173. ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
  174. "PACK/\\1.vif" "BODY/\\1.vif" upcase))
  175. ;; Aldec
  176. ;; COMP96 ERROR COMP96_0018: "Identifier expected." "test.vhd" 66 3
  177. ("Aldec" "vcom" "-work \\1" "make" "-f \\1"
  178. nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "aldec"
  179. ("^.* ERROR [^:]+: \".*\" \"\\([^ \t\n]+\\)\" \\([0-9]+\\) \\([0-9]+\\)" 1 2 3) ("" 0)
  180. nil)
  181. ;; Cadence Leapfrog: cv -file test.vhd
  182. ;; duluth: *E,430 (test.vhd,13): identifier (POSITIV) is not declared
  183. ("Cadence Leapfrog" "cv" "-work \\1 -file" "make" "-f \\1"
  184. nil "mkdir \\1" "./" "work/" "Makefile" "leapfrog"
  185. ("^duluth: \\*E,[0-9]+ (\\([^ \t\n]+\\),\\([0-9]+\\)):" 1 2 nil) ("" 0)
  186. ("\\1/entity" "\\2/\\1" "\\1/configuration"
  187. "\\1/package" "\\1/body" downcase))
  188. ;; Cadence Affirma NC vhdl: ncvhdl test.vhd
  189. ;; ncvhdl_p: *E,IDENTU (test.vhd,13|25): identifier
  190. ;; (PLL_400X_TOP) is not declared [10.3].
  191. ("Cadence NC" "ncvhdl" "-work \\1" "make" "-f \\1"
  192. nil "mkdir \\1" "./" "work/" "Makefile" "ncvhdl"
  193. ("^ncvhdl_p: \\*E,\\w+ (\\([^ \t\n]+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
  194. ("\\1/entity/pc.db" "\\2/\\1/pc.db" "\\1/configuration/pc.db"
  195. "\\1/package/pc.db" "\\1/body/pc.db" downcase))
  196. ;; ghdl vhdl
  197. ;; ghdl -a bad_counter.vhdl
  198. ;; bad_counter.vhdl:13:14: operator "=" is overloaded
  199. ("GHDL" "ghdl" "-i --workdir=\\1 --ieee=synopsys -fexplicit " "make" "-f \\1"
  200. nil "mkdir \\1" "./" "work/" "Makefile" "ghdl"
  201. ("^ghdl_p: \\*E,\\w+ (\\([^ \t\n]+\\),\\([0-9]+\\)|\\([0-9]+\\)):" 1 2 3) ("" 0)
  202. ("\\1/entity" "\\2/\\1" "\\1/configuration"
  203. "\\1/package" "\\1/body" downcase))
  204. ;; IBM Compiler
  205. ;; 00 COACHDL* | [CCHDL-1]: File: adder.vhd, line.column: 120.6
  206. ("IBM Compiler" "g2tvc" "-src" "precomp" "\\1"
  207. nil "mkdir \\1" "./" "work/" "Makefile" "ibm"
  208. ("^[0-9]+ COACHDL.*: File: \\([^ \t\n]+\\), *line.column: \\([0-9]+\\).\\([0-9]+\\)" 1 2 3) (" " 0)
  209. nil)
  210. ;; Ikos Voyager: analyze test.vhd
  211. ;; analyze test.vhd
  212. ;; E L4/C5: this library unit is inaccessible
  213. ("Ikos" "analyze" "-l \\1" "make" "-f \\1"
  214. nil "mkdir \\1" "./" "work/" "Makefile" "ikos"
  215. ("^E L\\([0-9]+\\)/C\\([0-9]+\\):" nil 1 2)
  216. ("^analyze +\\(.+ +\\)*\\(.+\\)$" 2)
  217. nil)
  218. ;; ModelSim, Model Technology: vcom test.vhd
  219. ;; ERROR: test.vhd(14): Unknown identifier: positiv
  220. ;; WARNING[2]: test.vhd(85): Possible infinite loop
  221. ;; ** Warning: [4] ../src/emacsvsim.vhd(43): An abstract ...
  222. ;; ** Error: adder.vhd(190): Unknown identifier: ctl_numb
  223. ("ModelSim" "vcom" "-93 -work \\1" "make" "-f \\1"
  224. nil "vlib \\1; vmap \\2 \\1" "./" "work/" "Makefile" "modelsim"
  225. ("^\\(ERROR\\|WARNING\\|\\*\\* Error\\|\\*\\* Warning\\)[^:]*:\\( *\\[[0-9]+]\\)? \\([^ \t\n]+\\)(\\([0-9]+\\)):" 3 4 nil) ("" 0)
  226. ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
  227. "\\1/_primary.dat" "\\1/body.dat" downcase))
  228. ;; ProVHDL, Synopsys LEDA: provhdl -w work -f test.vhd
  229. ;; test.vhd:34: error message
  230. ("LEDA ProVHDL" "provhdl" "-w \\1 -f" "make" "-f \\1"
  231. nil "mkdir \\1" "./" "work/" "Makefile" "provhdl"
  232. ("^\\([^ \t\n:]+\\):\\([0-9]+\\): " 1 2 nil) ("" 0)
  233. ("ENTI/\\1.vif" "ARCH/\\1-\\2.vif" "CONF/\\1.vif"
  234. "PACK/\\1.vif" "BODY/BODY-\\1.vif" upcase))
  235. ;; Quartus compiler
  236. ;; Error: VHDL error at dvi2sdi.vhd(473): object k2_alto_out_lvl is used
  237. ;; Error: Verilog HDL syntax error at otsuif_v1_top.vhd(147) near text
  238. ;; Error: VHDL syntax error at otsuif_v1_top.vhd(147): clk_ is an illegal
  239. ;; Error: VHDL Use Clause error at otsuif_v1_top.vhd(455): design library
  240. ;; Warning: VHDL Process Statement warning at dvi2sdi_tst.vhd(172): ...
  241. ("Quartus" "make" "-work \\1" "make" "-f \\1"
  242. nil "mkdir \\1" "./" "work/" "Makefile" "quartus"
  243. ("^\\(Error\\|Warning\\): .* \\([^ \t\n]+\\)(\\([0-9]+\\))" 2 3 nil) ("" 0)
  244. nil)
  245. ;; QuickHDL, Mentor Graphics: qvhcom test.vhd
  246. ;; ERROR: test.vhd(24): near "dnd": expecting: END
  247. ;; WARNING[4]: test.vhd(30): A space is required between ...
  248. ("QuickHDL" "qvhcom" "-work \\1" "make" "-f \\1"
  249. nil "mkdir \\1" "./" "work/" "Makefile" "quickhdl"
  250. ("^\\(ERROR\\|WARNING\\)[^:]*: \\([^ \t\n]+\\)(\\([0-9]+\\)):" 2 3 nil) ("" 0)
  251. ("\\1/_primary.dat" "\\2/\\1.dat" "\\1/_primary.dat"
  252. "\\1/_primary.dat" "\\1/body.dat" downcase))
  253. ;; Savant: scram -publish-cc test.vhd
  254. ;; test.vhd:87: _set_passed_through_out_port(IIR_Boolean) not defined for
  255. ("Savant" "scram" "-publish-cc -design-library-name \\1" "make" "-f \\1"
  256. nil "mkdir \\1" "./" "work._savant_lib/" "Makefile" "savant"
  257. ("^\\([^ \t\n:]+\\):\\([0-9]+\\): " 1 2 nil) ("" 0)
  258. ("\\1_entity.vhdl" "\\2_secondary_units._savant_lib/\\2_\\1.vhdl"
  259. "\\1_config.vhdl" "\\1_package.vhdl"
  260. "\\1_secondary_units._savant_lib/\\1_package_body.vhdl" downcase))
  261. ;; Simili: vhdlp -work test.vhd
  262. ;; Error: CSVHDL0002: test.vhd: (line 97): Invalid prefix
  263. ("Simili" "vhdlp" "-work \\1" "make" "-f \\1"
  264. nil "mkdir \\1" "./" "work/" "Makefile" "simili"
  265. ("^\\(Error\\|Warning\\): \\w+: \\([^ \t\n]+\\): (line \\([0-9]+\\)): " 2 3 nil) ("" 0)
  266. ("\\1/prim.var" "\\2/_\\1.var" "\\1/prim.var"
  267. "\\1/prim.var" "\\1/_body.var" downcase))
  268. ;; Speedwave (Innoveda): analyze -libfile vsslib.ini -src test.vhd
  269. ;; ERROR[11]::File test.vhd Line 100: Use of undeclared identifier
  270. ("Speedwave" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
  271. nil "mkdir \\1" "./" "work/" "Makefile" "speedwave"
  272. ("^ *ERROR\\[[0-9]+]::File \\([^ \t\n]+\\) Line \\([0-9]+\\):" 1 2 nil) ("" 0)
  273. nil)
  274. ;; Synopsys, VHDL Analyzer (sim): vhdlan -nc test.vhd
  275. ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
  276. ("Synopsys" "vhdlan" "-nc -work \\1" "make" "-f \\1"
  277. nil "mkdir \\1" "./" "work/" "Makefile" "synopsys"
  278. ("^\\*\\*Error: vhdlan,[0-9]+ \\([^ \t\n]+\\)(\\([0-9]+\\)):" 1 2 nil) ("" 0)
  279. ("\\1.sim" "\\2__\\1.sim" "\\1.sim" "\\1.sim" "\\1__.sim" upcase))
  280. ;; Synopsys, VHDL Analyzer (syn): vhdlan -nc -spc test.vhd
  281. ;; **Error: vhdlan,703 test.vhd(22): OTHERS is not legal in this context.
  282. ("Synopsys Design Compiler" "vhdlan" "-nc -spc -work \\1" "make" "-f \\1"
  283. nil "mkdir \\1" "./" "work/" "Makefile" "synopsys_dc"
  284. ("^\\*\\*Error: vhdlan,[0-9]+ \\([^ \t\n]+\\)(\\([0-9]+\\)):" 1 2 nil) ("" 0)
  285. ("\\1.syn" "\\2__\\1.syn" "\\1.syn" "\\1.syn" "\\1__.syn" upcase))
  286. ;; Synplify:
  287. ;; @W:"test.vhd":57:8:57:9|Optimizing register bit count_x(5) to a constant 0
  288. ("Synplify" "n/a" "n/a" "make" "-f \\1"
  289. nil "mkdir \\1" "./" "work/" "Makefile" "synplify"
  290. ("^@[EWN]:\"\\([^ \t\n]+\\)\":\\([0-9]+\\):\\([0-9]+\\):" 1 2 3) ("" 0)
  291. nil)
  292. ;; Vantage: analyze -libfile vsslib.ini -src test.vhd
  293. ;; Compiling "test.vhd" line 1...
  294. ;; **Error: LINE 49 *** No aggregate value is valid in this context.
  295. ("Vantage" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
  296. nil "mkdir \\1" "./" "work/" "Makefile" "vantage"
  297. ("^\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" nil 1 nil)
  298. ("^ *Compiling \"\\(.+\\)\" " 1)
  299. nil)
  300. ;; VeriBest: vc vhdl test.vhd
  301. ;; (no file name printed out!)
  302. ;; 32: Z <= A and BitA ;
  303. ;; ^^^^
  304. ;; [Error] Name BITA is unknown
  305. ("VeriBest" "vc" "vhdl" "make" "-f \\1"
  306. nil "mkdir \\1" "./" "work/" "Makefile" "veribest"
  307. ("^ +\\([0-9]+\\): +[^ ]" nil 1 nil) ("" 0)
  308. nil)
  309. ;; Viewlogic: analyze -libfile vsslib.ini -src test.vhd
  310. ;; Compiling "test.vhd" line 1...
  311. ;; **Error: LINE 49 *** No aggregate value is valid in this context.
  312. ("Viewlogic" "analyze" "-libfile vsslib.ini -src" "make" "-f \\1"
  313. nil "mkdir \\1" "./" "work/" "Makefile" "viewlogic"
  314. ("^\\*\\*Error: LINE \\([0-9]+\\) \\*\\*\\*" nil 1 nil)
  315. ("^ *Compiling \"\\(.+\\)\" " 1)
  316. nil)
  317. ;; Xilinx XST:
  318. ;; ERROR:HDLParsers:164 - "test.vhd" Line 3. parse error
  319. ("Xilinx XST" "xflow" "" "make" "-f \\1"
  320. nil "mkdir \\1" "./" "work/" "Makefile" "xilinx"
  321. ("^ERROR:HDLParsers:[0-9]+ - \"\\([^ \t\n]+\\)\" Line \\([0-9]+\\)\\." 1 2 nil) ("" 0)
  322. nil)
  323. )
  324. "List of available VHDL compilers and their properties.
  325. Each list entry specifies the following items for a compiler:
  326. Compiler:
  327. Compiler name : name used in option `vhdl-compiler' to choose compiler
  328. Compile command : command used for source file compilation
  329. Compile options : compile options (\"\\1\" inserts library name)
  330. Make command : command used for compilation using a Makefile
  331. Make options : make options (\"\\1\" inserts Makefile name)
  332. Generate Makefile: use built-in function or command to generate a Makefile
  333. (\"\\1\" inserts Makefile name, \"\\2\" inserts library name)
  334. Library command : command to create library directory (\"\\1\" inserts
  335. library directory, \"\\2\" inserts library name)
  336. Compile directory: where compilation is run and the Makefile is placed
  337. Library directory: directory of default library
  338. Makefile name : name of Makefile (default is \"Makefile\")
  339. ID string : compiler identification string (see `vhdl-project-alist')
  340. Error message:
  341. Regexp : regular expression to match error messages (*)
  342. File subexp index: index of subexpression that matches the file name
  343. Line subexp index: index of subexpression that matches the line number
  344. Column subexp idx: index of subexpression that matches the column number
  345. File message:
  346. Regexp : regular expression to match a file name message
  347. File subexp index: index of subexpression that matches the file name
  348. Unit-to-file name mapping: mapping of library unit names to names of files
  349. generated by the compiler (used for Makefile generation)
  350. To string : string a name is mapped to (\"\\1\" inserts the unit name,
  351. \"\\2\" inserts the entity name for architectures,
  352. \"\\3\" inserts the library name)
  353. Case adjustment : adjust case of inserted unit names
  354. \(*) The regular expression must match the error message starting from the
  355. beginning of the line (but not necessarily to the end of the line).
  356. Compile options allows insertion of the library name (see `vhdl-project-alist')
  357. in order to set the compilers library option (e.g. \"vcom -work my_lib\").
  358. For Makefile generation, the built-in function can be used (requires
  359. specification of the unit-to-file name mapping). Alternatively, an
  360. external command can be specified. Work directory allows specification of
  361. an alternative \"work\" library path (e.g. \"WORK/\" instead of \"work/\",
  362. used for Makefile generation). To use another library name than \"work\",
  363. customize `vhdl-project-alist'. The library command is inserted in Makefiles
  364. to automatically create the library directory if not existent.
  365. Compile options, compile directory, library directory, and Makefile name are
  366. overwritten by the project settings if a project is defined (see
  367. `vhdl-project-alist'). Directory paths are relative to the source file
  368. directory.
  369. Some compilers do not include the file name in the error message, but print
  370. out a file name message in advance. In this case, set \"File Subexp Index\"
  371. under \"Error Message\" to 0 and fill out the \"File Message\" entries.
  372. If no file name at all is printed out, set both \"File Message\" entries to 0
  373. \(a default file name message will be printed out instead, does not work in
  374. XEmacs).
  375. A compiler is selected for syntax analysis (`\\[vhdl-compile]') by
  376. assigning its name to option `vhdl-compiler'.
  377. Please send any missing or erroneous compiler properties to the maintainer for
  378. updating.
  379. NOTE: Activate new error and file message regexps and reflect the new setting
  380. in the choice list of option `vhdl-compiler' by restarting Emacs."
  381. :type '(repeat
  382. (list :tag "Compiler" :indent 2
  383. (string :tag "Compiler name ")
  384. (string :tag "Compile command ")
  385. (string :tag "Compile options " "-work \\1")
  386. (string :tag "Make command " "make")
  387. (string :tag "Make options " "-f \\1")
  388. (choice :tag "Generate Makefile "
  389. (const :tag "Built-in function" nil)
  390. (string :tag "Command" "vmake \\2 > \\1"))
  391. (string :tag "Library command " "mkdir \\1")
  392. (directory :tag "Compile directory "
  393. :validate vhdl-widget-directory-validate "./")
  394. (directory :tag "Library directory "
  395. :validate vhdl-widget-directory-validate "work/")
  396. (file :tag "Makefile name " "Makefile")
  397. (string :tag "ID string ")
  398. (list :tag "Error message" :indent 4
  399. (regexp :tag "Regexp ")
  400. (choice :tag "File subexp "
  401. (integer :tag "Index")
  402. (const :tag "No file name" nil))
  403. (integer :tag "Line subexp index")
  404. (choice :tag "Column subexp "
  405. (integer :tag "Index")
  406. (const :tag "No column number" nil)))
  407. (list :tag "File message" :indent 4
  408. (regexp :tag "Regexp ")
  409. (integer :tag "File subexp index"))
  410. (choice :tag "Unit-to-file name mapping"
  411. :format "%t: %[Value Menu%] %v\n"
  412. (const :tag "Not defined" nil)
  413. (list :tag "To string" :indent 4
  414. (string :tag "Entity " "\\1.vhd")
  415. (string :tag "Architecture " "\\2_\\1.vhd")
  416. (string :tag "Configuration " "\\1.vhd")
  417. (string :tag "Package " "\\1.vhd")
  418. (string :tag "Package Body " "\\1_body.vhd")
  419. (choice :tag "Case adjustment "
  420. (const :tag "None" identity)
  421. (const :tag "Upcase" upcase)
  422. (const :tag "Downcase" downcase))))))
  423. :set (lambda (variable value)
  424. (vhdl-custom-set variable value 'vhdl-update-mode-menu))
  425. :version "24.4"
  426. :group 'vhdl-compile)
  427. (defcustom vhdl-compiler "GHDL"
  428. "Specifies the VHDL compiler to be used for syntax analysis.
  429. Select a compiler name from the ones defined in option `vhdl-compiler-alist'."
  430. :type (let ((alist vhdl-compiler-alist) list)
  431. (while alist
  432. (push (list 'const (caar alist)) list)
  433. (setq alist (cdr alist)))
  434. (append '(choice) (nreverse list)))
  435. :group 'vhdl-compile)
  436. (defcustom vhdl-compile-use-local-error-regexp nil
  437. "Non-nil means use buffer-local `compilation-error-regexp-alist'.
  438. In this case, only error message regexps for VHDL compilers are active if
  439. compilation is started from a VHDL buffer. Otherwise, the error message
  440. regexps are appended to the predefined global regexps, and all regexps are
  441. active all the time. Note that by doing that, the predefined global regexps
  442. might result in erroneous parsing of error messages for some VHDL compilers.
  443. NOTE: Activate the new setting by restarting Emacs."
  444. :version "25.1" ; t -> nil
  445. :type 'boolean
  446. :group 'vhdl-compile)
  447. (defcustom vhdl-makefile-default-targets '("all" "clean" "library")
  448. "List of default target names in Makefiles.
  449. Automatically generated Makefiles include three default targets to compile
  450. the entire design, clean the entire design and to create the design library.
  451. This option allows you to change the names of these targets to avoid conflicts
  452. with other user Makefiles."
  453. :type '(list (string :tag "Compile entire design")
  454. (string :tag "Clean entire design ")
  455. (string :tag "Create design library"))
  456. :version "24.3"
  457. :group 'vhdl-compile)
  458. (defcustom vhdl-makefile-generation-hook nil
  459. "Functions to run at the end of Makefile generation.
  460. Allows you to insert user specific parts into a Makefile.
  461. Example:
  462. (lambda nil
  463. (re-search-backward \"^# Rule for compiling entire design\")
  464. (insert \"# My target\\n\\n.MY_TARGET :\\n\\n\\n\"))"
  465. :type 'hook
  466. :group 'vhdl-compile)
  467. (defcustom vhdl-default-library "work"
  468. "Name of default library.
  469. Is overwritten by project settings if a project is active."
  470. :type 'string
  471. :group 'vhdl-compile)
  472. (defgroup vhdl-project nil
  473. "Customizations for projects."
  474. :group 'vhdl)
  475. (defcustom vhdl-project-alist
  476. '(("Example 1" "Source files in two directories, custom library name, VHDL'87"
  477. "~/example1/" ("src/system/" "src/components/") ""
  478. (("ModelSim" "-87 \\2" "-f \\1 top_level" nil)
  479. ("Synopsys" "-vhdl87 \\2" "-f \\1 top_level" ((".*/datapath/.*" . "-optimize \\3") (".*_tb\\.vhd" . nil))))
  480. "lib/" "example3_lib" "lib/example3/" "Makefile_\\2" "")
  481. ("Example 2" "Individual source files, multiple compilers in different directories"
  482. "$EXAMPLE2/" ("vhdl/system.vhd" "vhdl/component_*.vhd") ""
  483. nil "\\1/" "work" "\\1/work/" "Makefile" "")
  484. ("Example 3" "Source files in a directory tree, multiple compilers in same directory"
  485. "/home/me/example3/" ("-r ./*/vhdl/") "/CVS/"
  486. nil "./" "work" "work-\\1/" "Makefile-\\1" "\
  487. -------------------------------------------------------------------------------
  488. -- This is a multi-line project description
  489. -- that can be used as a project dependent part of the file header.
  490. "))
  491. "List of projects and their properties.
  492. Name : name used in option `vhdl-project' to choose project
  493. Title : title of project (single-line string)
  494. Default directory: default project directory (absolute path)
  495. Sources : a) source files : path + \"/\" + file name
  496. b) directory : path + \"/\"
  497. c) directory tree: \"-r \" + path + \"/\"
  498. Exclude regexp : matches file/directory names to be excluded as sources
  499. Compile options : project-specific options for each compiler
  500. Compiler name : name of compiler for which these options are valid
  501. Compile options: project-specific compiler options
  502. (\"\\1\" inserts library name, \"\\2\" default options)
  503. Make options: project-specific make options
  504. (\"\\1\" inserts Makefile name, \"\\2\" default options)
  505. Exceptions : file-specific exceptions
  506. File name regexp: matches file names for which exceptions are valid
  507. - Options : file-specific compiler options string
  508. (\"\\1\" inserts library name, \"\\2\" default options,
  509. \"\\3\" project-specific options)
  510. - Do not compile: do not compile this file (in Makefile)
  511. Compile directory: where compilation is run and the Makefile is placed
  512. (\"\\1\" inserts compiler ID string)
  513. Library name : name of library (default is \"work\")
  514. Library directory: path to library (\"\\1\" inserts compiler ID string)
  515. Makefile name : name of Makefile
  516. (\"\\1\" inserts compiler ID string, \"\\2\" library name)
  517. Description : description of project (multi-line string)
  518. Project title and description are used to insert into the file header (see
  519. option `vhdl-file-header').
  520. The default directory must have an absolute path (use `M-TAB' for completion).
  521. All other paths can be absolute or relative to the default directory. All
  522. paths must end with '/'.
  523. The design units found in the sources (files and directories) are shown in the
  524. hierarchy browser. Path and file name can contain wildcards `*' and `?' as
  525. well as \"./\" and \"../\" (\"sh\" syntax). Paths can also be absolute.
  526. Environment variables (e.g. \"$EXAMPLE2\") are resolved. If no sources are
  527. specified, the default directory is taken as source directory. Otherwise,
  528. the default directory is only taken as source directory if there is a sources
  529. entry with the empty string or \"./\". Exclude regexp allows you to filter
  530. out specific file and directory names from the list of sources (e.g. CVS
  531. directories).
  532. Files are compiled in the compile directory. Makefiles are also placed into
  533. the compile directory. Library directory specifies which directory the
  534. compiler compiles into (used to generate the Makefile).
  535. Since different compile/library directories and Makefiles may exist for
  536. different compilers within one project, these paths and names allow the
  537. insertion of a compiler-dependent ID string (defined in `vhdl-compiler-alist').
  538. Compile options, compile directory, library directory, and Makefile name
  539. overwrite the settings of the current compiler.
  540. File-specific compiler options (highest priority) overwrite project-specific
  541. options which overwrite default options (lowest priority). Lower priority
  542. options can be inserted in higher priority options. This allows you to reuse
  543. default options (e.g. \"-file\") in project- or file-specific options (e.g.
  544. \"-93 -file\").
  545. NOTE: Reflect the new setting in the choice list of option `vhdl-project'
  546. by restarting Emacs."
  547. :type `(repeat
  548. (list :tag "Project" :indent 2
  549. (string :tag "Name ")
  550. (string :tag "Title ")
  551. (directory :tag "Default directory"
  552. :validate vhdl-widget-directory-validate
  553. ,(abbreviate-file-name default-directory))
  554. (repeat :tag "Sources " :indent 4
  555. (directory :format " %v" "./"))
  556. (regexp :tag "Exclude regexp ")
  557. (repeat
  558. :tag "Compile options " :indent 4
  559. (list :tag "Compiler" :indent 6
  560. ,(let ((alist vhdl-compiler-alist) list)
  561. (while alist
  562. (push (list 'const (caar alist)) list)
  563. (setq alist (cdr alist)))
  564. (append '(choice :tag "Compiler name")
  565. (nreverse list)))
  566. (string :tag "Compile options" "\\2")
  567. (string :tag "Make options " "\\2")
  568. (repeat
  569. :tag "Exceptions " :indent 8
  570. (cons :format "%v"
  571. (regexp :tag "File name regexp ")
  572. (choice :format "%[Value Menu%] %v"
  573. (string :tag "Options" "\\3")
  574. (const :tag "Do not compile" nil))))))
  575. (directory :tag "Compile directory"
  576. :validate vhdl-widget-directory-validate "./")
  577. (string :tag "Library name " "work")
  578. (directory :tag "Library directory"
  579. :validate vhdl-widget-directory-validate "work/")
  580. (file :tag "Makefile name " "Makefile")
  581. (string :tag "Description: (type `C-j' for newline)"
  582. :format "%t\n%v\n")))
  583. :set (lambda (variable value)
  584. (vhdl-custom-set variable value
  585. 'vhdl-update-mode-menu
  586. 'vhdl-speedbar-refresh))
  587. :group 'vhdl-project)
  588. (defcustom vhdl-project nil
  589. "Specifies the default for the current project.
  590. Select a project name from the ones defined in option `vhdl-project-alist'.
  591. Is used to determine the project title and description to be inserted in file
  592. headers and the source files/directories to be scanned in the hierarchy
  593. browser. The current project can also be changed temporarily in the menu."
  594. :type (let ((alist vhdl-project-alist) list)
  595. (while alist
  596. (push (list 'const (caar alist)) list)
  597. (setq alist (cdr alist)))
  598. (append '(choice (const :tag "None" nil) (const :tag "--"))
  599. (nreverse list)))
  600. :group 'vhdl-project)
  601. (defcustom vhdl-project-file-name '("\\1.prj")
  602. "List of file names/paths for importing/exporting project setups.
  603. \"\\1\" is replaced by the project name (SPC is replaced by `_'), \"\\2\" is
  604. replaced by the user name (allows you to have user-specific project setups).
  605. The first entry is used as file name to import/export individual project
  606. setups. All entries are used to automatically import project setups at
  607. startup (see option `vhdl-project-auto-load'). Projects loaded from the
  608. first entry are automatically made current. Hint: specify local project
  609. setups in first entry, global setups in following entries; loading a local
  610. project setup will make it current, while loading the global setups
  611. is done without changing the current project.
  612. Names can also have an absolute path (i.e. project setups can be stored
  613. in global directories)."
  614. :type '(repeat (string :tag "File name" "\\1.prj"))
  615. :group 'vhdl-project)
  616. (defcustom vhdl-project-auto-load '(startup)
  617. "Automatically load project setups from files.
  618. All project setup files that match the file names specified in option
  619. `vhdl-project-file-name' are automatically loaded. The project of the
  620. \(alphabetically) last loaded setup of the first `vhdl-project-file-name'
  621. entry is activated.
  622. A project setup file can be obtained by exporting a project (see menu).
  623. At startup: project setup file is loaded at Emacs startup"
  624. :type '(set (const :tag "At startup" startup))
  625. :group 'vhdl-project)
  626. (defcustom vhdl-project-sort t
  627. "Non-nil means projects are displayed in alphabetical order."
  628. :type 'boolean
  629. :group 'vhdl-project)
  630. (defgroup vhdl-style nil
  631. "Customizations for coding styles."
  632. :group 'vhdl
  633. :group 'vhdl-template
  634. :group 'vhdl-port
  635. :group 'vhdl-compose)
  636. (defcustom vhdl-standard '(93 nil)
  637. "VHDL standards used.
  638. Basic standard:
  639. VHDL'87 : IEEE Std 1076-1987
  640. VHDL'93/02 : IEEE Std 1076-1993/2002
  641. VHDL'08 : IEEE Std 1076-2008
  642. Additional standards:
  643. VHDL-AMS : IEEE Std 1076.1 (analog-mixed-signal)
  644. Math packages: IEEE Std 1076.2 (`math_real', `math_complex')
  645. NOTE: Activate the new setting in a VHDL buffer by using the menu entry
  646. \"Activate Options\"."
  647. :type '(list (choice :tag "Basic standard"
  648. (const :tag "VHDL'87" 87)
  649. (const :tag "VHDL'93/02" 93)
  650. (const :tag "VHDL'08" 08))
  651. (set :tag "Additional standards" :indent 2
  652. (const :tag "VHDL-AMS" ams)
  653. (const :tag "Math packages" math)))
  654. :set (lambda (variable value)
  655. (vhdl-custom-set variable value
  656. 'vhdl-template-map-init
  657. 'vhdl-mode-abbrev-table-init
  658. 'vhdl-template-construct-alist-init
  659. 'vhdl-template-package-alist-init
  660. 'vhdl-update-mode-menu
  661. 'vhdl-words-init 'vhdl-font-lock-init))
  662. :group 'vhdl-style)
  663. (defcustom vhdl-basic-offset 2
  664. "Amount of basic offset used for indentation.
  665. This value is used by + and - symbols in `vhdl-offsets-alist'."
  666. :type 'integer
  667. :group 'vhdl-style)
  668. (defcustom vhdl-upper-case-keywords nil
  669. "Non-nil means convert keywords to upper case.
  670. This is done when typed or expanded or by the fix case functions."
  671. :type 'boolean
  672. :set (lambda (variable value)
  673. (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
  674. :group 'vhdl-style)
  675. (defcustom vhdl-upper-case-types nil
  676. "Non-nil means convert standardized types to upper case.
  677. This is done when expanded or by the fix case functions."
  678. :type 'boolean
  679. :set (lambda (variable value)
  680. (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
  681. :group 'vhdl-style)
  682. (defcustom vhdl-upper-case-attributes nil
  683. "Non-nil means convert standardized attributes to upper case.
  684. This is done when expanded or by the fix case functions."
  685. :type 'boolean
  686. :set (lambda (variable value)
  687. (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
  688. :group 'vhdl-style)
  689. (defcustom vhdl-upper-case-enum-values nil
  690. "Non-nil means convert standardized enumeration values to upper case.
  691. This is done when expanded or by the fix case functions."
  692. :type 'boolean
  693. :set (lambda (variable value)
  694. (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
  695. :group 'vhdl-style)
  696. (defcustom vhdl-upper-case-constants t
  697. "Non-nil means convert standardized constants to upper case.
  698. This is done when expanded."
  699. :type 'boolean
  700. :set (lambda (variable value)
  701. (vhdl-custom-set variable value 'vhdl-abbrev-list-init))
  702. :group 'vhdl-style)
  703. (defcustom vhdl-use-direct-instantiation 'standard
  704. "Non-nil means use VHDL'93 direct component instantiation.
  705. Never : never
  706. Standard: only in VHDL standards that allow it (VHDL'93 and higher)
  707. Always : always"
  708. :type '(choice (const :tag "Never" never)
  709. (const :tag "Standard" standard)
  710. (const :tag "Always" always))
  711. :group 'vhdl-style)
  712. (defcustom vhdl-array-index-record-field-in-sensitivity-list t
  713. "Non-nil means include array indices / record fields in sensitivity list.
  714. If a signal read in a process is a record field or pointed to by an array
  715. index, the record field or array index is included with the record name in
  716. the sensitivity list (e.g. \"in1(0)\", \"in2.f0\").
  717. Otherwise, only the record name is included (e.g. \"in1\", \"in2\")."
  718. :type 'boolean
  719. :version "24.3"
  720. :group 'vhdl-style)
  721. (defgroup vhdl-naming nil
  722. "Customizations for naming conventions."
  723. :group 'vhdl)
  724. (defcustom vhdl-entity-file-name '(".*" . "\\&")
  725. (concat
  726. "Specifies how the entity file name is obtained.
  727. The entity file name can be obtained by modifying the entity name (e.g.
  728. attaching or stripping off a substring). The file extension is automatically
  729. taken from the file name of the current buffer."
  730. vhdl-name-doc-string)
  731. :type '(cons (regexp :tag "From regexp")
  732. (string :tag "To string "))
  733. :group 'vhdl-naming
  734. :group 'vhdl-compose)
  735. (defcustom vhdl-architecture-file-name '("\\(.*\\) \\(.*\\)" . "\\1_\\2")
  736. (concat
  737. "Specifies how the architecture file name is obtained.
  738. The architecture file name can be obtained by modifying the entity
  739. and/or architecture name (e.g. attaching or stripping off a substring). The
  740. file extension is automatically taken from the file name of the current
  741. buffer. The string that is matched against the regexp is the concatenation
  742. of the entity and the architecture name separated by a space. This gives
  743. access to both names (see default setting as example)."
  744. vhdl-name-doc-string)
  745. :type '(cons (regexp :tag "From regexp")
  746. (string :tag "To string "))
  747. :group 'vhdl-naming
  748. :group 'vhdl-compose)
  749. (defcustom vhdl-configuration-file-name '(".*" . "\\&")
  750. (concat
  751. "Specifies how the configuration file name is obtained.
  752. The configuration file name can be obtained by modifying the configuration
  753. name (e.g. attaching or stripping off a substring). The file extension is
  754. automatically taken from the file name of the current buffer."
  755. vhdl-name-doc-string)
  756. :type '(cons (regexp :tag "From regexp")
  757. (string :tag "To string "))
  758. :group 'vhdl-naming
  759. :group 'vhdl-compose)
  760. (defcustom vhdl-package-file-name '(".*" . "\\&")
  761. (concat
  762. "Specifies how the package file name is obtained.
  763. The package file name can be obtained by modifying the package name (e.g.
  764. attaching or stripping off a substring). The file extension is automatically
  765. taken from the file name of the current buffer. Package files can be created
  766. in a different directory by prepending a relative or absolute path to the
  767. file name."
  768. vhdl-name-doc-string)
  769. :type '(cons (regexp :tag "From regexp")
  770. (string :tag "To string "))
  771. :group 'vhdl-naming
  772. :group 'vhdl-compose)
  773. (defcustom vhdl-file-name-case 'identity
  774. "Specifies how to change case for obtaining file names.
  775. When deriving a file name from a VHDL unit name, case can be changed as
  776. follows:
  777. As Is: case is not changed (taken as is)
  778. Lower Case: whole name is changed to lower case
  779. Upper Case: whole name is changed to upper case
  780. Capitalize: first letter of each word in name is capitalized"
  781. :type '(choice (const :tag "As Is" identity)
  782. (const :tag "Lower Case" downcase)
  783. (const :tag "Upper Case" upcase)
  784. (const :tag "Capitalize" capitalize))
  785. :group 'vhdl-naming
  786. :group 'vhdl-compose)
  787. (defgroup vhdl-template nil
  788. "Customizations for electrification."
  789. :group 'vhdl)
  790. (defcustom vhdl-electric-keywords '(vhdl user)
  791. "Type of keywords for which electrification is enabled.
  792. VHDL keywords: invoke built-in templates
  793. User keywords: invoke user models (see option `vhdl-model-alist')"
  794. :type '(set (const :tag "VHDL keywords" vhdl)
  795. (const :tag "User model keywords" user))
  796. :set (lambda (variable value)
  797. (vhdl-custom-set variable value 'vhdl-mode-abbrev-table-init))
  798. :group 'vhdl-template)
  799. (defcustom vhdl-optional-labels 'process
  800. "Constructs for which labels are to be queried.
  801. Template generators prompt for optional labels for:
  802. None : no constructs
  803. Processes only: processes only (also procedurals in VHDL-AMS)
  804. All constructs: all constructs with optional labels and keyword END"
  805. :type '(choice (const :tag "None" none)
  806. (const :tag "Processes only" process)
  807. (const :tag "All constructs" all))
  808. :group 'vhdl-template)
  809. (defcustom vhdl-insert-empty-lines 'unit
  810. "Specifies whether to insert empty lines in some templates.
  811. This improves readability of code. Empty lines are inserted in:
  812. None : no constructs
  813. Design units only: entities, architectures, configurations, packages only
  814. All constructs : also all constructs with BEGIN...END parts
  815. Replaces option `vhdl-additional-empty-lines'."
  816. :type '(choice (const :tag "None" none)
  817. (const :tag "Design units only" unit)
  818. (const :tag "All constructs" all))
  819. :group 'vhdl-template
  820. :group 'vhdl-port
  821. :group 'vhdl-compose)
  822. (defcustom vhdl-argument-list-indent nil
  823. "Non-nil means indent argument lists relative to opening parenthesis.
  824. That is, argument, association, and port lists start on the same line as the
  825. opening parenthesis and subsequent lines are indented accordingly.
  826. Otherwise, lists start on a new line and are indented as normal code."
  827. :type 'boolean
  828. :group 'vhdl-template
  829. :group 'vhdl-port
  830. :group 'vhdl-compose)
  831. (defcustom vhdl-association-list-with-formals t
  832. "Non-nil means write association lists with formal parameters.
  833. Templates prompt for formal and actual parameters (ports/generics).
  834. When pasting component instantiations, formals are included.
  835. If nil, only a list of actual parameters is entered."
  836. :type 'boolean
  837. :group 'vhdl-template
  838. :group 'vhdl-port
  839. :group 'vhdl-compose)
  840. (defcustom vhdl-conditions-in-parenthesis nil
  841. "Non-nil means place parenthesis around condition expressions."
  842. :type 'boolean
  843. :group 'vhdl-template)
  844. (defcustom vhdl-sensitivity-list-all t
  845. "Non-nil means use 'all' keyword in sensitivity list."
  846. :version "25.1"
  847. :type 'boolean
  848. :group 'vhdl-template)
  849. (defcustom vhdl-zero-string "'0'"
  850. "String to use for a logic zero."
  851. :type 'string
  852. :group 'vhdl-template)
  853. (defcustom vhdl-one-string "'1'"
  854. "String to use for a logic one."
  855. :type 'string
  856. :group 'vhdl-template)
  857. (defgroup vhdl-header nil
  858. "Customizations for file header."
  859. :group 'vhdl-template
  860. :group 'vhdl-compose)
  861. (defcustom vhdl-file-header "\
  862. -------------------------------------------------------------------------------
  863. -- Title : <title string>
  864. -- Project : <project>
  865. -------------------------------------------------------------------------------
  866. -- File : <filename>
  867. -- Author : <author>
  868. -- Company : <company>
  869. -- Created : <date>
  870. -- Last update: <date>
  871. -- Platform : <platform>
  872. -- Standard : <standard>
  873. <projectdesc>-------------------------------------------------------------------------------
  874. -- Description: <cursor>
  875. <copyright>-------------------------------------------------------------------------------
  876. -- Revisions :
  877. -- Date Version Author Description
  878. -- <date> 1.0 <login>\tCreated
  879. -------------------------------------------------------------------------------
  880. "
  881. "String or file to insert as file header.
  882. If the string specifies an existing file name, the contents of the file is
  883. inserted, otherwise the string itself is inserted as file header.
  884. Type `C-j' for newlines.
  885. If the header contains RCS keywords, they may be written as <RCS>Keyword<RCS>
  886. if the header needs to be version controlled.
  887. The following keywords for template generation are supported:
  888. <filename> : replaced by the name of the buffer
  889. <author> : replaced by the user name and email address
  890. (`user-full-name',`mail-host-address', `user-mail-address')
  891. <authorfull> : replaced by the user full name (`user-full-name')
  892. <login> : replaced by user login name (`user-login-name')
  893. <company> : replaced by contents of option `vhdl-company-name'
  894. <date> : replaced by the current date
  895. <year> : replaced by the current year
  896. <project> : replaced by title of current project (`vhdl-project')
  897. <projectdesc> : replaced by description of current project (`vhdl-project')
  898. <copyright> : replaced by copyright string (`vhdl-copyright-string')
  899. <platform> : replaced by contents of option `vhdl-platform-spec'
  900. <standard> : replaced by the VHDL language standard(s) used
  901. <... string> : replaced by a queried string (\"...\" is the prompt word)
  902. <title string>: replaced by file title in automatically generated files
  903. <cursor> : final cursor position
  904. The (multi-line) project description <projectdesc> can be used as a project
  905. dependent part of the file header and can also contain the above keywords."
  906. :type 'string
  907. :group 'vhdl-header)
  908. (defcustom vhdl-file-footer ""
  909. "String or file to insert as file footer.
  910. If the string specifies an existing file name, the contents of the file is
  911. inserted, otherwise the string itself is inserted as file footer (i.e. at
  912. the end of the file).
  913. Type `C-j' for newlines.
  914. The same keywords as in option `vhdl-file-header' can be used."
  915. :type 'string
  916. :group 'vhdl-header)
  917. (defcustom vhdl-company-name ""
  918. "Name of company to insert in file header.
  919. See option `vhdl-file-header'."
  920. :type 'string
  921. :group 'vhdl-header)
  922. (defcustom vhdl-copyright-string "\
  923. -------------------------------------------------------------------------------
  924. -- Copyright (c) <year> <company>
  925. "
  926. "Copyright string to insert in file header.
  927. Can be multi-line string (type `C-j' for newline) and contain other file
  928. header keywords (see option `vhdl-file-header')."
  929. :type 'string
  930. :group 'vhdl-header)
  931. (defcustom vhdl-platform-spec ""
  932. "Specification of VHDL platform to insert in file header.
  933. The platform specification should contain names and versions of the
  934. simulation and synthesis tools used.
  935. See option `vhdl-file-header'."
  936. :type 'string
  937. :group 'vhdl-header)
  938. (defcustom vhdl-date-format "%Y-%m-%d"
  939. "Specifies the date format to use in the header.
  940. This string is passed as argument to the command `format-time-string'.
  941. For more information on format strings, see the documentation for the
  942. `format-time-string' command (C-h f `format-time-string')."
  943. :type 'string
  944. :group 'vhdl-header)
  945. (defcustom vhdl-modify-date-prefix-string "-- Last update: "
  946. "Prefix string of modification date in VHDL file header.
  947. If actualization of the modification date is called (menu,
  948. `\\[vhdl-template-modify]'), this string is searched and the rest
  949. of the line replaced by the current date."
  950. :type 'string
  951. :group 'vhdl-header)
  952. (defcustom vhdl-modify-date-on-saving t
  953. "Non-nil means update the modification date when the buffer is saved.
  954. Calls function `\\[vhdl-template-modify]').
  955. NOTE: Activate the new setting in a VHDL buffer by using the menu entry
  956. \"Activate Options\"."
  957. :type 'boolean
  958. :group 'vhdl-header)
  959. (defgroup vhdl-sequential-process nil
  960. "Customizations for sequential processes."
  961. :group 'vhdl-template)
  962. (defcustom vhdl-reset-kind 'async
  963. "Specifies which kind of reset to use in sequential processes."
  964. :type '(choice (const :tag "None" none)
  965. (const :tag "Synchronous" sync)
  966. (const :tag "Asynchronous" async)
  967. (const :tag "Query" query))
  968. :group 'vhdl-sequential-process)
  969. (defcustom vhdl-reset-active-high nil
  970. "Non-nil means reset in sequential processes is active high.
  971. Otherwise, reset is active low."
  972. :type 'boolean
  973. :group 'vhdl-sequential-process)
  974. (defcustom vhdl-clock-rising-edge t
  975. "Non-nil means rising edge of clock triggers sequential processes.
  976. Otherwise, falling edge triggers."
  977. :type 'boolean
  978. :group 'vhdl-sequential-process)
  979. (defcustom vhdl-clock-edge-condition 'standard
  980. "Syntax of the clock edge condition.
  981. Standard: \"clk'event and clk = '1'\"
  982. Function: \"rising_edge(clk)\""
  983. :type '(choice (const :tag "Standard" standard)
  984. (const :tag "Function" function))
  985. :group 'vhdl-sequential-process)
  986. (defcustom vhdl-clock-name ""
  987. "Name of clock signal to use in templates."
  988. :type 'string
  989. :group 'vhdl-sequential-process)
  990. (defcustom vhdl-reset-name ""
  991. "Name of reset signal to use in templates."
  992. :type 'string
  993. :group 'vhdl-sequential-process)
  994. (defgroup vhdl-model nil
  995. "Customizations for user models."
  996. :group 'vhdl)
  997. (defcustom vhdl-model-alist
  998. '(("Example Model"
  999. "<label> : process (<clock>, <reset>)
  1000. begin -- process <label>
  1001. if <reset> = '0' then -- asynchronous reset (active low)
  1002. <cursor>
  1003. elsif <clock>'event and <clock> = '1' then -- rising clock edge
  1004. if <enable> = '1' then -- synchronous load
  1005. end if;
  1006. end if;
  1007. end process <label>;"
  1008. "e" ""))
  1009. "List of user models.
  1010. VHDL models (templates) can be specified by the user in this list. They can be
  1011. invoked from the menu, through key bindings (`C-c C-m ...'), or by keyword
  1012. electrification (i.e. overriding existing or creating new keywords, see
  1013. option `vhdl-electric-keywords').
  1014. Name : name of model (string of words and spaces)
  1015. String : string or name of file to be inserted as model (newline: `C-j')
  1016. Key Binding: key binding to invoke model, added to prefix `C-c C-m'
  1017. (must be in double-quotes, examples: \"i\", \"\\C-p\", \"\\M-s\")
  1018. Keyword : keyword to invoke model
  1019. The models can contain prompts to be queried. A prompt is of the form \"<...>\".
  1020. A prompt that appears several times is queried once and replaced throughout
  1021. the model. Special prompts are:
  1022. <clock> : name specified in `vhdl-clock-name' (if not empty)
  1023. <reset> : name specified in `vhdl-reset-name' (if not empty)
  1024. <cursor>: final cursor position
  1025. File header prompts (see variable `vhdl-file-header') are automatically
  1026. replaced, so that user models can also be used to insert different types of
  1027. headers.
  1028. If the string specifies an existing file name, the contents of the file is
  1029. inserted, otherwise the string itself is inserted.
  1030. The code within the models should be correctly indented.
  1031. Type `C-j' for newlines.
  1032. NOTE: Activate the new setting in a VHDL buffer by using the menu entry
  1033. \"Activate Options\"."
  1034. :type '(repeat (list :tag "Model" :indent 2
  1035. (string :tag "Name ")
  1036. (string :tag "String : (type `C-j' for newline)"
  1037. :format "%t\n%v")
  1038. (sexp :tag "Key binding" x)
  1039. (string :tag "Keyword " :format "%t: %v\n")))
  1040. :set (lambda (variable value)
  1041. (vhdl-custom-set variable value
  1042. 'vhdl-model-map-init
  1043. 'vhdl-model-defun
  1044. 'vhdl-mode-abbrev-table-init
  1045. 'vhdl-update-mode-menu))
  1046. :group 'vhdl-model)
  1047. (defgroup vhdl-compose nil
  1048. "Customizations for structural composition."
  1049. :group 'vhdl)
  1050. (defcustom vhdl-compose-architecture-name '(".*" . "str")
  1051. (concat
  1052. "Specifies how the component architecture name is obtained.
  1053. The component architecture name can be obtained by modifying the entity name
  1054. \(e.g. attaching or stripping off a substring).
  1055. If TO STRING is empty, the architecture name is queried."
  1056. vhdl-name-doc-string)
  1057. :type '(cons (regexp :tag "From regexp")
  1058. (string :tag "To string "))
  1059. :group 'vhdl-compose)
  1060. (defcustom vhdl-compose-configuration-name
  1061. '("\\(.*\\) \\(.*\\)" . "\\1_\\2_cfg")
  1062. (concat
  1063. "Specifies how the configuration name is obtained.
  1064. The configuration name can be obtained by modifying the entity and/or
  1065. architecture name (e.g. attaching or stripping off a substring). The string
  1066. that is matched against the regexp is the concatenation of the entity and the
  1067. architecture name separated by a space. This gives access to both names (see
  1068. default setting as example)."
  1069. vhdl-name-doc-string)
  1070. :type '(cons (regexp :tag "From regexp")
  1071. (string :tag "To string "))
  1072. :group 'vhdl-compose)
  1073. (defcustom vhdl-components-package-name
  1074. '((".*" . "\\&_components") . "components")
  1075. (concat
  1076. "Specifies how the name for the components package is obtained.
  1077. The components package is a package containing all component declarations for
  1078. the current design. Its name can be obtained by modifying the project name
  1079. \(e.g. attaching or stripping off a substring). If no project is defined, the
  1080. DIRECTORY entry is chosen."
  1081. vhdl-name-doc-string)
  1082. :type '(cons (cons :tag "Project" :indent 2
  1083. (regexp :tag "From regexp")
  1084. (string :tag "To string "))
  1085. (string :tag "Directory:\n String "))
  1086. :group 'vhdl-compose)
  1087. (defcustom vhdl-use-components-package nil
  1088. "Non-nil means use a separate components package for component declarations.
  1089. Otherwise, component declarations are inserted and searched for in the
  1090. architecture declarative parts."
  1091. :type 'boolean
  1092. :group 'vhdl-compose)
  1093. (defcustom vhdl-compose-include-header t
  1094. "Non-nil means include a header in automatically generated files."
  1095. :type 'boolean
  1096. :group 'vhdl-compose)
  1097. (defcustom vhdl-compose-create-files 'single
  1098. "Specifies whether new files should be created for the new component.
  1099. The component's entity and architecture are inserted:
  1100. None : in current buffer
  1101. Single file : in new single file
  1102. Separate files: in two separate files
  1103. The file names are obtained from variables `vhdl-entity-file-name' and
  1104. `vhdl-architecture-file-name'."
  1105. :type '(choice (const :tag "None" none)
  1106. (const :tag "Single file" single)
  1107. (const :tag "Separate files" separate))
  1108. :group 'vhdl-compose)
  1109. (defcustom vhdl-compose-configuration-create-file nil
  1110. "Specifies whether a new file should be created for the configuration.
  1111. If non-nil, a new file is created for the configuration.
  1112. The file name is obtained from variable `vhdl-configuration-file-name'."
  1113. :type 'boolean
  1114. :group 'vhdl-compose)
  1115. (defcustom vhdl-compose-configuration-hierarchical t
  1116. "Specifies whether hierarchical configurations should be created.
  1117. If non-nil, automatically created configurations are hierarchical and include
  1118. the whole hierarchy of subcomponents. Otherwise the configuration only
  1119. includes one level of subcomponents."
  1120. :type 'boolean
  1121. :group 'vhdl-compose)
  1122. (defcustom vhdl-compose-configuration-use-subconfiguration t
  1123. "Specifies whether subconfigurations should be used inside configurations.
  1124. If non-nil, automatically created configurations use configurations in binding
  1125. indications for subcomponents, if such configurations exist. Otherwise,
  1126. entities are used in binding indications for subcomponents."
  1127. :type 'boolean
  1128. :group 'vhdl-compose)
  1129. (defgroup vhdl-port nil
  1130. "Customizations for port translation functions."
  1131. :group 'vhdl
  1132. :group 'vhdl-compose)
  1133. (defcustom vhdl-include-port-comments nil
  1134. "Non-nil means include port comments when a port is pasted."
  1135. :type 'boolean
  1136. :group 'vhdl-port)
  1137. (defcustom vhdl-include-direction-comments nil
  1138. "Non-nil means include port direction in instantiations as comments."
  1139. :type 'boolean
  1140. :group 'vhdl-port)
  1141. (defcustom vhdl-include-type-comments nil
  1142. "Non-nil means include generic/port type in instantiations as comments."
  1143. :type 'boolean
  1144. :group 'vhdl-port)
  1145. (defcustom vhdl-include-group-comments 'never
  1146. "Specifies whether to include group comments and spacings.
  1147. The comments and empty lines between groups of ports are pasted:
  1148. Never : never
  1149. Declarations: in entity/component/constant/signal declarations only
  1150. Always : also in generic/port maps"
  1151. :type '(choice (const :tag "Never" never)
  1152. (const :tag "Declarations" decl)
  1153. (const :tag "Always" always))
  1154. :group 'vhdl-port)
  1155. (defcustom vhdl-actual-generic-name '(".*" . "\\&")
  1156. (concat
  1157. "Specifies how actual generic names are obtained from formal generic names.
  1158. In a component instantiation, an actual generic name can be
  1159. obtained by modifying the formal generic name (e.g. attaching or stripping
  1160. off a substring)."
  1161. vhdl-name-doc-string)
  1162. :type '(cons (regexp :tag "From regexp")
  1163. (string :tag "To string "))
  1164. :group 'vhdl-port
  1165. :version "24.4")
  1166. (defcustom vhdl-actual-port-name '(".*" . "\\&")
  1167. (concat
  1168. "Specifies how actual port names are obtained from formal port names.
  1169. In a component instantiation, an actual port name can be obtained by
  1170. modifying the formal port name (e.g. attaching or stripping off a substring)."
  1171. vhdl-name-doc-string)
  1172. :type '(cons (regexp :tag "From regexp")
  1173. (string :tag "To string "))
  1174. :group 'vhdl-port)
  1175. (defcustom vhdl-instance-name '(".*" . "\\&_%d")
  1176. (concat
  1177. "Specifies how an instance name is obtained.
  1178. The instance name can be obtained by modifying the name of the component to be
  1179. instantiated (e.g. attaching or stripping off a substring). \"%d\" is replaced
  1180. by a unique number (starting with 1).
  1181. If TO STRING is empty, the instance name is queried."
  1182. vhdl-name-doc-string)
  1183. :type '(cons (regexp :tag "From regexp")
  1184. (string :tag "To string "))
  1185. :group 'vhdl-port)
  1186. (defgroup vhdl-testbench nil
  1187. "Customizations for testbench generation."
  1188. :group 'vhdl-port)
  1189. (defcustom vhdl-testbench-entity-name '(".*" . "\\&_tb")
  1190. (concat
  1191. "Specifies how the testbench entity name is obtained.
  1192. The entity name of a testbench can be obtained by modifying the name of
  1193. the component to be tested (e.g. attaching or stripping off a substring)."
  1194. vhdl-name-doc-string)
  1195. :type '(cons (regexp :tag "From regexp")
  1196. (string :tag "To string "))
  1197. :group 'vhdl-testbench)
  1198. (defcustom vhdl-testbench-architecture-name '(".*" . "")
  1199. (concat
  1200. "Specifies how the testbench architecture name is obtained.
  1201. The testbench architecture name can be obtained by modifying the name of
  1202. the component to be tested (e.g. attaching or stripping off a substring).
  1203. If TO STRING is empty, the architecture name is queried."
  1204. vhdl-name-doc-string)
  1205. :type '(cons (regexp :tag "From regexp")
  1206. (string :tag "To string "))
  1207. :group 'vhdl-testbench)
  1208. (defcustom vhdl-testbench-configuration-name vhdl-compose-configuration-name
  1209. (concat
  1210. "Specifies how the testbench configuration name is obtained.
  1211. The configuration name of a testbench can be obtained by modifying the entity
  1212. and/or architecture name (e.g. attaching or stripping off a substring). The
  1213. string that is matched against the regexp is the concatenation of the entity
  1214. and the architecture name separated by a space. This gives access to both
  1215. names (see default setting as example)."
  1216. vhdl-name-doc-string)
  1217. :type '(cons (regexp :tag "From regexp")
  1218. (string :tag "To string "))
  1219. :group 'vhdl-testbench)
  1220. (defcustom vhdl-testbench-dut-name '(".*" . "DUT")
  1221. (concat
  1222. "Specifies how a DUT instance name is obtained.
  1223. The design-under-test instance name (i.e. the component instantiated in the
  1224. testbench) can be obtained by modifying the component name (e.g. attaching
  1225. or stripping off a substring)."
  1226. vhdl-name-doc-string)
  1227. :type '(cons (regexp :tag "From regexp")
  1228. (string :tag "To string "))
  1229. :group 'vhdl-testbench)
  1230. (defcustom vhdl-testbench-include-header t
  1231. "Non-nil means include a header in automatically generated files."
  1232. :type 'boolean
  1233. :group 'vhdl-testbench)
  1234. (defcustom vhdl-testbench-declarations "\
  1235. -- clock
  1236. signal Clk : std_logic := '1';
  1237. "
  1238. "String or file to be inserted in the testbench declarative part.
  1239. If the string specifies an existing file name, the contents of the file is
  1240. inserted, otherwise the string itself is inserted in the testbench
  1241. architecture before the BEGIN keyword.
  1242. Type `C-j' for newlines."
  1243. :type 'string
  1244. :group 'vhdl-testbench)
  1245. (defcustom vhdl-testbench-statements "\
  1246. -- clock generation
  1247. Clk <= not Clk after 10 ns;
  1248. -- waveform generation
  1249. WaveGen_Proc: process
  1250. begin
  1251. -- insert signal assignments here
  1252. wait until Clk = '1';
  1253. end process WaveGen_Proc;
  1254. "
  1255. "String or file to be inserted in the testbench statement part.
  1256. If the string specifies an existing file name, the contents of the file is
  1257. inserted, otherwise the string itself is inserted in the testbench
  1258. architecture before the END keyword.
  1259. Type `C-j' for newlines."
  1260. :type 'string
  1261. :group 'vhdl-testbench)
  1262. (defcustom vhdl-testbench-initialize-signals nil
  1263. "Non-nil means initialize signals with `0' when declared in testbench."
  1264. :type 'boolean
  1265. :group 'vhdl-testbench)
  1266. (defcustom vhdl-testbench-include-library t
  1267. "Non-nil means a library/use clause for std_logic_1164 is included."
  1268. :type 'boolean
  1269. :group 'vhdl-testbench)
  1270. (defcustom vhdl-testbench-include-configuration t
  1271. "Non-nil means a testbench configuration is attached at the end."
  1272. :type 'boolean
  1273. :group 'vhdl-testbench)
  1274. (defcustom vhdl-testbench-create-files 'single
  1275. "Specifies whether new files should be created for the testbench.
  1276. testbench entity and architecture are inserted:
  1277. None : in current buffer
  1278. Single file : in new single file
  1279. Separate files: in two separate files
  1280. The file names are obtained from variables `vhdl-testbench-entity-file-name'
  1281. and `vhdl-testbench-architecture-file-name'."
  1282. :type '(choice (const :tag "None" none)
  1283. (const :tag "Single file" single)
  1284. (const :tag "Separate files" separate))
  1285. :group 'vhdl-testbench)
  1286. (defcustom vhdl-testbench-entity-file-name vhdl-entity-file-name
  1287. (concat
  1288. "Specifies how the testbench entity file name is obtained.
  1289. The entity file name can be obtained by modifying the testbench entity name
  1290. \(e.g. attaching or stripping off a substring). The file extension is
  1291. automatically taken from the file name of the current buffer. Testbench
  1292. files can be created in a different directory by prepending a relative or
  1293. absolute path to the file name."
  1294. vhdl-name-doc-string)
  1295. :type '(cons (regexp :tag "From regexp")
  1296. (string :tag "To string "))
  1297. :group 'vhdl-testbench)
  1298. (defcustom vhdl-testbench-architecture-file-name vhdl-architecture-file-name
  1299. (concat
  1300. "Specifies how the testbench architecture file name is obtained.
  1301. The architecture file name can be obtained by modifying the testbench entity
  1302. and/or architecture name (e.g. attaching or stripping off a substring). The
  1303. string that is matched against the regexp is the concatenation of the entity
  1304. and the architecture name separated by a space. This gives access to both
  1305. names (see default setting as example). Testbench files can be created in
  1306. a different directory by prepending a relative or absolute path to the file
  1307. name."
  1308. vhdl-name-doc-string)
  1309. :type '(cons (regexp :tag "From regexp")
  1310. (string :tag "To string "))
  1311. :group 'vhdl-testbench)
  1312. (defgroup vhdl-comment nil
  1313. "Customizations for comments."
  1314. :group 'vhdl)
  1315. (defcustom vhdl-self-insert-comments t
  1316. "Non-nil means various templates automatically insert help comments."
  1317. :type 'boolean
  1318. :group 'vhdl-comment)
  1319. (defcustom vhdl-prompt-for-comments t
  1320. "Non-nil means various templates prompt for user definable comments."
  1321. :type 'boolean
  1322. :group 'vhdl-comment)
  1323. (defcustom vhdl-inline-comment-column 40
  1324. "Column to indent and align inline comments to.
  1325. Overrides local option `comment-column'.
  1326. NOTE: Activate the new setting in a VHDL buffer by using the menu entry
  1327. \"Activate Options\"."
  1328. :type 'integer
  1329. :group 'vhdl-comment)
  1330. (defcustom vhdl-end-comment-column 79
  1331. "End of comment column.
  1332. Comments that exceed this column number are wrapped.
  1333. NOTE: Activate the new setting in a VHDL buffer by using the menu entry
  1334. \"Activate Options\"."
  1335. :type 'integer
  1336. :group 'vhdl-comment)
  1337. (defvar end-comment-column)
  1338. (defgroup vhdl-beautify nil
  1339. "Customizations for beautification."
  1340. :group 'vhdl)
  1341. (defcustom vhdl-auto-align t
  1342. "Non-nil means align some templates automatically after generation."
  1343. :type 'boolean
  1344. :group 'vhdl-beautify)
  1345. (defcustom vhdl-align-groups t
  1346. "Non-nil means align groups of code lines separately.
  1347. A group of code lines is a region of consecutive lines between two lines that
  1348. match the regexp in option `vhdl-align-group-separate'."
  1349. :type 'boolean
  1350. :group 'vhdl-beautify)
  1351. (defcustom vhdl-align-group-separate "^\\s-*$"
  1352. "Regexp for matching a line that separates groups of lines for alignment.
  1353. Examples:
  1354. \"^\\s-*$\": matches an empty line
  1355. \"^\\s-*\\(--.*\\)?$\": matches an empty line or a comment-only line"
  1356. :type 'regexp
  1357. :group 'vhdl-beautify)
  1358. (defcustom vhdl-align-same-indent t
  1359. "Non-nil means align blocks with same indent separately.
  1360. When a region or the entire buffer is aligned, the code is divided into
  1361. blocks of same indent which are aligned separately (except for argument/port
  1362. lists). This gives nicer alignment in most cases.
  1363. Option `vhdl-align-groups' still applies within these blocks."
  1364. :type 'boolean
  1365. :group 'vhdl-beautify)
  1366. (defcustom vhdl-beautify-options '(t t t t t)
  1367. "List of options for beautifying code.
  1368. Allows you to disable individual features of code beautification."
  1369. :type '(list (boolean :tag "Whitespace cleanup ")
  1370. (boolean :tag "Single statement per line")
  1371. (boolean :tag "Indentation ")
  1372. (boolean :tag "Alignment ")
  1373. (boolean :tag "Case fixing "))
  1374. :group 'vhdl-beautify
  1375. :version "24.4")
  1376. (defgroup vhdl-highlight nil
  1377. "Customizations for highlighting."
  1378. :group 'vhdl)
  1379. (defcustom vhdl-highlight-keywords t
  1380. "Non-nil means highlight VHDL keywords and other standardized words.
  1381. The following faces are used:
  1382. `font-lock-keyword-face' : keywords
  1383. `font-lock-type-face' : standardized types
  1384. `vhdl-font-lock-attribute-face': standardized attributes
  1385. `vhdl-font-lock-enumvalue-face': standardized enumeration values
  1386. `vhdl-font-lock-function-face' : standardized function and package names
  1387. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1388. entry \"Fontify Buffer\")."
  1389. :type 'boolean
  1390. :set (lambda (variable value)
  1391. (vhdl-custom-set variable value 'vhdl-font-lock-init))
  1392. :group 'vhdl-highlight)
  1393. (defcustom vhdl-highlight-names t
  1394. "Non-nil means highlight declaration names and construct labels.
  1395. The following faces are used:
  1396. `font-lock-function-name-face' : names in declarations of units,
  1397. subprograms, components, as well as labels of VHDL constructs
  1398. `font-lock-type-face' : names in type/nature declarations
  1399. `vhdl-font-lock-attribute-face': names in attribute declarations
  1400. `font-lock-variable-name-face' : names in declarations of signals,
  1401. variables, constants, subprogram parameters, generics, and ports
  1402. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1403. entry \"Fontify Buffer\")."
  1404. :type 'boolean
  1405. :set (lambda (variable value)
  1406. (vhdl-custom-set variable value 'vhdl-font-lock-init))
  1407. :group 'vhdl-highlight)
  1408. (defcustom vhdl-highlight-special-words nil
  1409. "Non-nil means highlight words with special syntax.
  1410. The words with syntax and color specified in option `vhdl-special-syntax-alist'
  1411. are highlighted accordingly.
  1412. Can be used for visual support of naming conventions.
  1413. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1414. entry \"Fontify Buffer\")."
  1415. :type 'boolean
  1416. :set (lambda (variable value)
  1417. (vhdl-custom-set variable value 'vhdl-font-lock-init))
  1418. :group 'vhdl-highlight)
  1419. (defcustom vhdl-highlight-forbidden-words nil
  1420. "Non-nil means highlight forbidden words.
  1421. The reserved words specified in option `vhdl-forbidden-words' or having the
  1422. syntax specified in option `vhdl-forbidden-syntax' are highlighted in a
  1423. warning color (face `vhdl-font-lock-reserved-words-face') to indicate not to
  1424. use them.
  1425. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1426. entry \"Fontify Buffer\")."
  1427. :type 'boolean
  1428. :set (lambda (variable value)
  1429. (vhdl-custom-set variable value
  1430. 'vhdl-words-init 'vhdl-font-lock-init))
  1431. :group 'vhdl-highlight)
  1432. (defcustom vhdl-highlight-verilog-keywords nil
  1433. "Non-nil means highlight Verilog keywords as reserved words.
  1434. Verilog keywords are highlighted in a warning color (face
  1435. `vhdl-font-lock-reserved-words-face') to indicate not to use them.
  1436. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1437. entry \"Fontify Buffer\")."
  1438. :type 'boolean
  1439. :set (lambda (variable value)
  1440. (vhdl-custom-set variable value
  1441. 'vhdl-words-init 'vhdl-font-lock-init))
  1442. :group 'vhdl-highlight)
  1443. (defcustom vhdl-highlight-translate-off nil
  1444. "Non-nil means background-highlight code excluded from translation.
  1445. That is, all code between \"-- pragma translate_off\" and
  1446. \"-- pragma translate_on\" is highlighted using a different background color
  1447. \(face `vhdl-font-lock-translate-off-face').
  1448. Note: this might slow down on-the-fly fontification (and thus editing).
  1449. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1450. entry \"Fontify Buffer\")."
  1451. :type 'boolean
  1452. :set (lambda (variable value)
  1453. (vhdl-custom-set variable value 'vhdl-font-lock-init))
  1454. :group 'vhdl-highlight)
  1455. (defcustom vhdl-highlight-case-sensitive nil
  1456. "Non-nil means consider case for highlighting.
  1457. Possible trade-off:
  1458. non-nil also upper-case VHDL words are highlighted, but case of words with
  1459. special syntax is not considered
  1460. nil only lower-case VHDL words are highlighted, but case of words with
  1461. special syntax is considered
  1462. Overrides local option `font-lock-keywords-case-fold-search'.
  1463. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1464. entry \"Fontify Buffer\")."
  1465. :type 'boolean
  1466. :group 'vhdl-highlight)
  1467. (defcustom vhdl-special-syntax-alist
  1468. '(("generic/constant" "\\<\\w+_[cg]\\>" "Gold3" "BurlyWood1" nil)
  1469. ("type" "\\<\\w+_t\\>" "ForestGreen" "PaleGreen" nil)
  1470. ("variable" "\\<\\w+_v\\>" "Grey50" "Grey80" nil))
  1471. "List of special syntax to be highlighted.
  1472. If option `vhdl-highlight-special-words' is non-nil, words with the specified
  1473. syntax (as regular expression) are highlighted in the corresponding color.
  1474. Name : string of words and spaces
  1475. Regexp : regular expression describing word syntax
  1476. (e.g., `\\=\\<\\w+_c\\>' matches word with suffix `_c')
  1477. expression must start with `\\=\\<' and end with `\\>'
  1478. if only whole words should be matched (no substrings)
  1479. Color (light): foreground color for light background
  1480. (matching color examples: Gold3, Grey50, LimeGreen, Tomato,
  1481. LightSeaGreen, DodgerBlue, Gold, PaleVioletRed)
  1482. Color (dark) : foreground color for dark background
  1483. (matching color examples: BurlyWood1, Grey80, Green, Coral,
  1484. AquaMarine2, LightSkyBlue1, Yellow, PaleVioletRed1)
  1485. In comments : If non-nil, words are also highlighted inside comments
  1486. Can be used for visual support of naming conventions, such as highlighting
  1487. different kinds of signals (e.g. `Clk50', `Rst_n') or objects (e.g.
  1488. `Signal_s', `Variable_v', `Constant_c') by distinguishing them using
  1489. common substrings or name suffices.
  1490. For each entry, a new face is generated with the specified colors and name
  1491. `vhdl-font-lock-' + name + `-face'.
  1492. NOTE: Activate a changed regexp in a VHDL buffer by re-fontifying it (menu
  1493. entry `Fontify Buffer'). All other changes require restarting Emacs."
  1494. :type '(repeat (list :tag "Face" :indent 2
  1495. (string :tag "Name ")
  1496. (regexp :tag "Regexp " "\\w+_")
  1497. (string :tag "Color (light)")
  1498. (string :tag "Color (dark) ")
  1499. (boolean :tag "In comments ")))
  1500. :set (lambda (variable value)
  1501. (vhdl-custom-set variable value 'vhdl-font-lock-init))
  1502. :group 'vhdl-highlight)
  1503. (defcustom vhdl-forbidden-words '()
  1504. "List of forbidden words to be highlighted.
  1505. If option `vhdl-highlight-forbidden-words' is non-nil, these reserved
  1506. words are highlighted in a warning color to indicate not to use them.
  1507. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1508. entry \"Fontify Buffer\")."
  1509. :type '(repeat (string :format "%v"))
  1510. :set (lambda (variable value)
  1511. (vhdl-custom-set variable value
  1512. 'vhdl-words-init 'vhdl-font-lock-init))
  1513. :group 'vhdl-highlight)
  1514. (defcustom vhdl-forbidden-syntax ""
  1515. "Syntax of forbidden words to be highlighted.
  1516. If option `vhdl-highlight-forbidden-words' is non-nil, words with this
  1517. syntax are highlighted in a warning color to indicate not to use them.
  1518. Can be used to highlight too long identifiers (e.g. \"\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w+\"
  1519. highlights identifiers with 10 or more characters).
  1520. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1521. entry \"Fontify Buffer\")."
  1522. :type 'regexp
  1523. :set (lambda (variable value)
  1524. (vhdl-custom-set variable value
  1525. 'vhdl-words-init 'vhdl-font-lock-init))
  1526. :group 'vhdl-highlight)
  1527. (defcustom vhdl-directive-keywords '("psl" "pragma" "synopsys")
  1528. "List of compiler directive keywords recognized for highlighting.
  1529. NOTE: Activate the new setting in a VHDL buffer by re-fontifying it (menu
  1530. entry \"Fontify Buffer\")."
  1531. :type '(repeat (string :format "%v"))
  1532. :set (lambda (variable value)
  1533. (vhdl-custom-set variable value
  1534. 'vhdl-words-init 'vhdl-font-lock-init))
  1535. :group 'vhdl-highlight)
  1536. (defgroup vhdl-speedbar nil
  1537. "Customizations for speedbar."
  1538. :group 'vhdl)
  1539. (defcustom vhdl-speedbar-auto-open nil
  1540. "Non-nil means automatically open speedbar at startup.
  1541. Alternatively, the speedbar can be opened from the VHDL menu."
  1542. :type 'boolean
  1543. :group 'vhdl-speedbar)
  1544. (defcustom vhdl-speedbar-display-mode 'files
  1545. "Specifies the default displaying mode when opening speedbar.
  1546. Alternatively, the displaying mode can be selected from the speedbar menu or
  1547. by typing `f' (files), `h' (directory hierarchy) or `H' (project hierarchy)."
  1548. :type '(choice (const :tag "Files" files)
  1549. (const :tag "Directory hierarchy" directory)
  1550. (const :tag "Project hierarchy" project))
  1551. :group 'vhdl-speedbar)
  1552. (defcustom vhdl-speedbar-scan-limit '(10000000 (1000000 50))
  1553. "Limits scanning of large files and netlists.
  1554. Design units: maximum file size to scan for design units
  1555. Hierarchy (instances of subcomponents):
  1556. File size: maximum file size to scan for instances (in bytes)
  1557. Instances per arch: maximum number of instances to scan per architecture
  1558. \"None\" always means that there is no limit.
  1559. In case of files not or incompletely scanned, a warning message and the file
  1560. names are printed out.
  1561. Background: scanning for instances is considerably slower than scanning for
  1562. design units, especially when there are many instances. These limits should
  1563. prevent the scanning of large netlists."
  1564. :type '(list (choice :tag "Design units"
  1565. :format "%t : %[Value Menu%] %v"
  1566. (const :tag "None" nil)
  1567. (integer :tag "File size"))
  1568. (list :tag "Hierarchy" :indent 2
  1569. (choice :tag "File size"
  1570. :format "%t : %[Value Menu%] %v"
  1571. (const :tag "None" nil)
  1572. (integer :tag "Size "))
  1573. (choice :tag "Instances per arch"
  1574. (const :tag "None" nil)
  1575. (integer :tag "Number "))))
  1576. :group 'vhdl-speedbar)
  1577. (defcustom vhdl-speedbar-jump-to-unit t
  1578. "Non-nil means jump to the design unit code when opened in a buffer.
  1579. The buffer cursor position is left unchanged otherwise."
  1580. :type 'boolean
  1581. :group 'vhdl-speedbar)
  1582. (defcustom vhdl-speedbar-update-on-saving t
  1583. "Automatically update design hierarchy when buffer is saved."
  1584. :type 'boolean
  1585. :group 'vhdl-speedbar)
  1586. (defcustom vhdl-speedbar-save-cache '(hierarchy display)
  1587. "Automatically save modified hierarchy caches when exiting Emacs.
  1588. Hierarchy: design hierarchy information
  1589. Display: displaying information (which design units to expand)"
  1590. :type '(set (const :tag "Hierarchy" hierarchy)
  1591. (const :tag "Display" display))
  1592. :group 'vhdl-speedbar)
  1593. (defcustom vhdl-speedbar-cache-file-name ".emacs-vhdl-cache-\\1-\\2"
  1594. "Name of file for saving hierarchy cache.
  1595. \"\\1\" is replaced by the project name if a project is specified,
  1596. \"directory\" otherwise. \"\\2\" is replaced by the user name (allows for
  1597. different users to have cache files in the same directory). Can also have
  1598. an absolute path (i.e. all caches can be stored in one global directory)."
  1599. :type 'string
  1600. :group 'vhdl-speedbar)
  1601. (defgroup vhdl-menu nil
  1602. "Customizations for menus."
  1603. :group 'vhdl)
  1604. (defcustom vhdl-index-menu nil
  1605. "Non-nil means add an index menu for a source file when loading.
  1606. Alternatively, the speedbar can be used. Note that the index menu scans a file
  1607. when it is opened, while speedbar only scans the file upon request."
  1608. :type 'boolean
  1609. :group 'vhdl-menu)
  1610. (defcustom vhdl-source-file-menu nil
  1611. "Non-nil means add a menu of all source files in current directory.
  1612. Alternatively, the speedbar can be used."
  1613. :type 'boolean
  1614. :group 'vhdl-menu)
  1615. (defcustom vhdl-hideshow-menu nil
  1616. "Non-nil means add hideshow menu and functionality at startup.
  1617. Hideshow can also be enabled from the VHDL Mode menu.
  1618. Hideshow allows hiding code of various VHDL constructs.
  1619. NOTE: Activate the new setting in a VHDL buffer by using the menu entry
  1620. \"Activate Options\"."
  1621. :type 'boolean
  1622. :group 'vhdl-menu)
  1623. (defcustom vhdl-hide-all-init nil
  1624. "Non-nil means hide all design units initially after a file is loaded."
  1625. :type 'boolean
  1626. :group 'vhdl-menu)
  1627. (defgroup vhdl-print nil
  1628. "Customizations for printing."
  1629. :group 'vhdl)
  1630. (defcustom vhdl-print-two-column t
  1631. "Non-nil means print code in two columns and landscape format.
  1632. Adjusts settings in a way that PostScript printing (\"File\" menu, `ps-print')
  1633. prints VHDL files in a nice two-column landscape style.
  1634. NOTE: Activate the new setting by restarting Emacs.
  1635. Overrides `ps-print' settings locally."
  1636. :type 'boolean
  1637. :group 'vhdl-print)
  1638. (defcustom vhdl-print-customize-faces t
  1639. "Non-nil means use an optimized set of faces for PostScript printing.
  1640. NOTE: Activate the new setting by restarting Emacs.
  1641. Overrides `ps-print' settings locally."
  1642. :type 'boolean
  1643. :group 'vhdl-print)
  1644. (defgroup vhdl-misc nil
  1645. "Miscellaneous customizations."
  1646. :group 'vhdl)
  1647. (defcustom vhdl-intelligent-tab t
  1648. "Non-nil means `TAB' does indentation, word completion and tab insertion.
  1649. That is, if preceding character is part of a word then complete word,
  1650. else if not at beginning of line then insert tab,
  1651. else if last command was a `TAB' or `RET' then dedent one step,
  1652. else indent current line (i.e. `TAB' is bound to `vhdl-electric-tab').
  1653. If nil, TAB always indents current line (i.e. `TAB' is bound to
  1654. `indent-according-to-mode').
  1655. NOTE: Activate the new setting in a VHDL buffer by using the menu entry
  1656. \"Activate Options\"."
  1657. :type 'boolean
  1658. :group 'vhdl-misc)
  1659. (defcustom vhdl-indent-syntax-based t
  1660. "Non-nil means indent lines of code based on their syntactic context.
  1661. Otherwise, a line is indented like the previous nonblank line. This can be
  1662. useful in large files where syntax-based indentation gets very slow."
  1663. :type 'boolean
  1664. :group 'vhdl-misc)
  1665. (defcustom vhdl-indent-comment-like-next-code-line t
  1666. "Non-nil means comment lines are indented like the following code line.
  1667. Otherwise, comment lines are indented like the preceding code line.
  1668. Indenting comment lines like the following code line gives nicer indentation
  1669. when comments precede the code that they refer to."
  1670. :type 'boolean
  1671. :version "24.3"
  1672. :group 'vhdl-misc)
  1673. (defcustom vhdl-word-completion-case-sensitive nil
  1674. "Non-nil means word completion using `TAB' is case sensitive.
  1675. That is, `TAB' completes words that start with the same letters and case.
  1676. Otherwise, case is ignored."
  1677. :type 'boolean
  1678. :group 'vhdl-misc)
  1679. (defcustom vhdl-word-completion-in-minibuffer t
  1680. "Non-nil enables word completion in minibuffer (for template prompts).
  1681. NOTE: Activate the new setting by restarting Emacs."
  1682. :type 'boolean
  1683. :group 'vhdl-misc)
  1684. (defcustom vhdl-underscore-is-part-of-word nil
  1685. "Non-nil means consider the underscore character `_' as part of word.
  1686. An identifier containing underscores is then treated as a single word in
  1687. select and move operations. All parts of an identifier separated by underscore
  1688. are treated as single words otherwise."
  1689. :type 'boolean
  1690. :group 'vhdl-misc)
  1691. (make-obsolete-variable 'vhdl-underscore-is-part-of-word
  1692. 'superword-mode "24.4")
  1693. (defgroup vhdl-related nil
  1694. "Related general customizations."
  1695. :group 'vhdl)
  1696. ;; add related general customizations
  1697. (custom-add-to-group 'vhdl-related 'hideshow 'custom-group)
  1698. (if (featurep 'xemacs)
  1699. (custom-add-to-group 'vhdl-related 'paren-mode 'custom-variable)
  1700. (custom-add-to-group 'vhdl-related 'paren-showing 'custom-group))
  1701. (custom-add-to-group 'vhdl-related 'ps-print 'custom-group)
  1702. (custom-add-to-group 'vhdl-related 'speedbar 'custom-group)
  1703. (custom-add-to-group 'vhdl-related 'comment-style 'custom-variable)
  1704. (custom-add-to-group 'vhdl-related 'line-number-mode 'custom-variable)
  1705. (unless (featurep 'xemacs)
  1706. (custom-add-to-group 'vhdl-related 'transient-mark-mode 'custom-variable))
  1707. (custom-add-to-group 'vhdl-related 'user-full-name 'custom-variable)
  1708. (custom-add-to-group 'vhdl-related 'mail-host-address 'custom-variable)
  1709. (custom-add-to-group 'vhdl-related 'user-mail-address 'custom-variable)
  1710. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1711. ;; Hidden user variables
  1712. (defvar vhdl-compile-absolute-path nil
  1713. "If non-nil, use absolute instead of relative path for compiled files.")
  1714. (defvar vhdl-comment-display-line-char ?-
  1715. "Character to use in comment display line.")
  1716. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1717. ;; Internal variables
  1718. (defvar vhdl-menu-max-size 20
  1719. "Specifies the maximum size of a menu before splitting it into submenus.")
  1720. (defvar vhdl-progress-interval 1
  1721. "Interval used to update progress status during long operations.
  1722. If a number, percentage complete gets updated after each interval of
  1723. that many seconds. To inhibit all messages, set this option to nil.")
  1724. (defvar vhdl-inhibit-startup-warnings-p nil
  1725. "If non-nil, inhibits start up compatibility warnings.")
  1726. (defvar vhdl-strict-syntax-p nil
  1727. "If non-nil, all syntactic symbols must be found in `vhdl-offsets-alist'.
  1728. If the syntactic symbol for a particular line does not match a symbol
  1729. in the offsets alist, an error is generated, otherwise no error is
  1730. reported and the syntactic symbol is ignored.")
  1731. (defvar vhdl-echo-syntactic-information-p nil
  1732. "If non-nil, syntactic info is echoed when the line is indented.")
  1733. (defconst vhdl-offsets-alist-default
  1734. '((string . -1000)
  1735. (cpp-macro . -1000)
  1736. (block-open . 0)
  1737. (block-close . 0)
  1738. (statement . 0)
  1739. (statement-cont . vhdl-lineup-statement-cont)
  1740. (statement-block-intro . +)
  1741. (statement-case-intro . +)
  1742. (case-alternative . +)
  1743. (comment . vhdl-lineup-comment)
  1744. (arglist-intro . +)
  1745. (arglist-cont . 0)
  1746. (arglist-cont-nonempty . vhdl-lineup-arglist)
  1747. (arglist-close . vhdl-lineup-arglist)
  1748. (entity . 0)
  1749. (configuration . 0)
  1750. (package . 0)
  1751. (architecture . 0)
  1752. (package-body . 0)
  1753. (context . 0)
  1754. (directive . 0)
  1755. )
  1756. "Default settings for offsets of syntactic elements.
  1757. Do not change this constant! See the variable `vhdl-offsets-alist' for
  1758. more information.")
  1759. (defvar vhdl-offsets-alist (copy-alist vhdl-offsets-alist-default)
  1760. "Association list of syntactic element symbols and indentation offsets.
  1761. As described below, each cons cell in this list has the form:
  1762. (SYNTACTIC-SYMBOL . OFFSET)
  1763. When a line is indented, `vhdl-mode' first determines the syntactic
  1764. context of the line by generating a list of symbols called syntactic
  1765. elements. This list can contain more than one syntactic element and
  1766. the global variable `vhdl-syntactic-context' contains the context list
  1767. for the line being indented. Each element in this list is actually a
  1768. cons cell of the syntactic symbol and a buffer position. This buffer
  1769. position is call the relative indent point for the line. Some
  1770. syntactic symbols may not have a relative indent point associated with
  1771. them.
  1772. After the syntactic context list for a line is generated, `vhdl-mode'
  1773. calculates the absolute indentation for the line by looking at each
  1774. syntactic element in the list. First, it compares the syntactic
  1775. element against the SYNTACTIC-SYMBOL's in `vhdl-offsets-alist'. When it
  1776. finds a match, it adds the OFFSET to the column of the relative indent
  1777. point. The sum of this calculation for each element in the syntactic
  1778. list is the absolute offset for line being indented.
  1779. If the syntactic element does not match any in the `vhdl-offsets-alist',
  1780. an error is generated if `vhdl-strict-syntax-p' is non-nil, otherwise
  1781. the element is ignored.
  1782. Actually, OFFSET can be an integer, a function, a variable, or one of
  1783. the following symbols: `+', `-', `++', or `--'. These latter
  1784. designate positive or negative multiples of `vhdl-basic-offset',
  1785. respectively: *1, *-1, *2, and *-2. If OFFSET is a function, it is
  1786. called with a single argument containing the cons of the syntactic
  1787. element symbol and the relative indent point. The function should
  1788. return an integer offset.
  1789. Here is the current list of valid syntactic element symbols:
  1790. string -- inside multi-line string
  1791. block-open -- statement block open
  1792. block-close -- statement block close
  1793. statement -- a VHDL statement
  1794. statement-cont -- a continuation of a VHDL statement
  1795. statement-block-intro -- the first line in a new statement block
  1796. statement-case-intro -- the first line in a case alternative block
  1797. case-alternative -- a case statement alternative clause
  1798. comment -- a line containing only a comment
  1799. arglist-intro -- the first line in an argument list
  1800. arglist-cont -- subsequent argument list lines when no
  1801. arguments follow on the same line as
  1802. the arglist opening paren
  1803. arglist-cont-nonempty -- subsequent argument list lines when at
  1804. least one argument follows on the same
  1805. line as the arglist opening paren
  1806. arglist-close -- the solo close paren of an argument list
  1807. entity -- inside an entity declaration
  1808. configuration -- inside a configuration declaration
  1809. package -- inside a package declaration
  1810. architecture -- inside an architecture body
  1811. package-body -- inside a package body
  1812. context -- inside a context declaration")
  1813. (defvar vhdl-comment-only-line-offset 0
  1814. "Extra offset for line which contains only the start of a comment.
  1815. Can contain an integer or a cons cell of the form:
  1816. (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
  1817. Where NON-ANCHORED-OFFSET is the amount of offset given to
  1818. non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
  1819. the amount of offset to give column-zero anchored comment-only lines.
  1820. Just an integer as value is equivalent to (<val> . 0)")
  1821. (defvar vhdl-special-indent-hook nil
  1822. "Hook for user defined special indentation adjustments.
  1823. This hook gets called after a line is indented by the mode.")
  1824. (defvar vhdl-style-alist
  1825. '(("IEEE"
  1826. (vhdl-basic-offset . 4)
  1827. (vhdl-offsets-alist . ())))
  1828. "Styles of Indentation.
  1829. Elements of this alist are of the form:
  1830. (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
  1831. where STYLE-STRING is a short descriptive string used to select a
  1832. style, VARIABLE is any `vhdl-mode' variable, and VALUE is the intended
  1833. value for that variable when using the selected style.
  1834. There is one special case when VARIABLE is `vhdl-offsets-alist'. In this
  1835. case, the VALUE is a list containing elements of the form:
  1836. (SYNTACTIC-SYMBOL . VALUE)
  1837. as described in `vhdl-offsets-alist'. These are passed directly to
  1838. `vhdl-set-offset' so there is no need to set every syntactic symbol in
  1839. your style, only those that are different from the default.")
  1840. ;; dynamically append the default value of most variables
  1841. (or (assoc "Default" vhdl-style-alist)
  1842. (let* ((varlist '(vhdl-inhibit-startup-warnings-p
  1843. vhdl-strict-syntax-p
  1844. vhdl-echo-syntactic-information-p
  1845. vhdl-basic-offset
  1846. vhdl-offsets-alist
  1847. vhdl-comment-only-line-offset))
  1848. (default (cons "Default"
  1849. (mapcar
  1850. (function
  1851. (lambda (var)
  1852. (cons var (symbol-value var))))
  1853. varlist))))
  1854. (push default vhdl-style-alist)))
  1855. (defvar vhdl-mode-hook nil
  1856. "Hook called by `vhdl-mode'.")
  1857. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1858. ;;; Required packages
  1859. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1860. ;; mandatory
  1861. (require 'compile) ; XEmacs
  1862. (require 'easymenu)
  1863. (require 'hippie-exp)
  1864. ;; optional (minimize warning messages during compile)
  1865. (unless (featurep 'xemacs)
  1866. (eval-when-compile
  1867. (require 'font-lock)
  1868. (require 'ps-print)
  1869. (require 'speedbar))) ; for speedbar-with-writable
  1870. (defun vhdl-aput (alist-symbol key &optional value)
  1871. "Insert a key-value pair into an alist.
  1872. The alist is referenced by ALIST-SYMBOL. The key-value pair is made
  1873. from KEY and VALUE. If the key-value pair referenced by KEY can be
  1874. found in the alist, the value of KEY will be set to VALUE. If the
  1875. key-value pair cannot be found in the alist, it will be inserted into
  1876. the head of the alist."
  1877. (let* ((alist (symbol-value alist-symbol))
  1878. (elem (assoc key alist)))
  1879. (if elem
  1880. (setcdr elem value)
  1881. (set alist-symbol (cons (cons key value) alist)))))
  1882. (defun vhdl-adelete (alist-symbol key)
  1883. "Delete a key-value pair from the alist.
  1884. Alist is referenced by ALIST-SYMBOL and the key-value pair to remove
  1885. is pair matching KEY."
  1886. (let ((alist (symbol-value alist-symbol)) alist-cdr)
  1887. (while (equal key (caar alist))
  1888. (setq alist (cdr alist))
  1889. (set alist-symbol alist))
  1890. (while (setq alist-cdr (cdr alist))
  1891. (if (equal key (caar alist-cdr))
  1892. (setcdr alist (cdr alist-cdr))
  1893. (setq alist alist-cdr)))))
  1894. (defun vhdl-aget (alist key)
  1895. "Return the value in ALIST that is associated with KEY. If KEY is
  1896. not found, then nil is returned."
  1897. (cdr (assoc key alist)))
  1898. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1899. ;;; Compatibility
  1900. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1901. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1902. ;; XEmacs compatibility
  1903. ;; active regions
  1904. (defun vhdl-keep-region-active ()
  1905. "Do whatever is necessary to keep the region active in XEmacs.
  1906. Ignore byte-compiler warnings you might see."
  1907. (and (featurep 'xemacs)
  1908. (setq zmacs-region-stays t)))
  1909. ;; `wildcard-to-regexp' is included only in XEmacs 21
  1910. (unless (fboundp 'wildcard-to-regexp)
  1911. (defun wildcard-to-regexp (wildcard)
  1912. "Simplified version of `wildcard-to-regexp' from Emacs's `files.el'."
  1913. (let* ((i (string-match "[*?]" wildcard))
  1914. (result (substring wildcard 0 i))
  1915. (len (length wildcard)))
  1916. (when i
  1917. (while (< i len)
  1918. (let ((ch (aref wildcard i)))
  1919. (setq result (concat result
  1920. (cond ((eq ch ?*) "[^\000]*")
  1921. ((eq ch ??) "[^\000]")
  1922. (t (char-to-string ch)))))
  1923. (setq i (1+ i)))))
  1924. (concat "\\`" result "\\'"))))
  1925. ;; `regexp-opt' undefined (`xemacs-devel' not installed)
  1926. ;; `regexp-opt' accelerates fontification by 10-20%
  1927. (unless (fboundp 'regexp-opt)
  1928. ; (vhdl-warning-when-idle "Please install `xemacs-devel' package.")
  1929. (defun regexp-opt (strings &optional paren)
  1930. (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
  1931. (concat open (mapconcat 'regexp-quote strings "\\|") close))))
  1932. ;; `match-string-no-properties' undefined (XEmacs, what else?)
  1933. (unless (fboundp 'match-string-no-properties)
  1934. (defalias 'match-string-no-properties 'match-string))
  1935. ;; `subst-char-in-string' undefined (XEmacs)
  1936. (unless (fboundp 'subst-char-in-string)
  1937. (defun subst-char-in-string (fromchar tochar string &optional inplace)
  1938. (let ((i (length string))
  1939. (newstr (if inplace string (copy-sequence string))))
  1940. (while (> i 0)
  1941. (setq i (1- i))
  1942. (if (eq (aref newstr i) fromchar) (aset newstr i tochar)))
  1943. newstr)))
  1944. ;; `itimer.el': idle timer bug fix in version 1.09 (XEmacs 21.1.9)
  1945. (when (and (featurep 'xemacs) (string< itimer-version "1.09")
  1946. (not noninteractive))
  1947. (load "itimer")
  1948. (when (string< itimer-version "1.09")
  1949. (message "WARNING: Install included `itimer.el' patch first (see INSTALL file)")
  1950. (beep) (sit-for 5)))
  1951. ;; `file-expand-wildcards' undefined (XEmacs)
  1952. (unless (fboundp 'file-expand-wildcards)
  1953. (defun file-expand-wildcards (pattern &optional full)
  1954. "Taken from Emacs's `files.el'."
  1955. (let* ((nondir (file-name-nondirectory pattern))
  1956. (dirpart (file-name-directory pattern))
  1957. (dirs (if (and dirpart (string-match "[[*?]" dirpart))
  1958. (mapcar 'file-name-as-directory
  1959. (file-expand-wildcards (directory-file-name dirpart)))
  1960. (list dirpart)))
  1961. contents)
  1962. (while dirs
  1963. (when (or (null (car dirs)) ; Possible if DIRPART is not wild.
  1964. (file-directory-p (directory-file-name (car dirs))))
  1965. (let ((this-dir-contents
  1966. (delq nil
  1967. (mapcar #'(lambda (name)
  1968. (unless (string-match "\\`\\.\\.?\\'"
  1969. (file-name-nondirectory name))
  1970. name))
  1971. (directory-files (or (car dirs) ".") full
  1972. (wildcard-to-regexp nondir))))))
  1973. (setq contents
  1974. (nconc
  1975. (if (and (car dirs) (not full))
  1976. (mapcar (function (lambda (name) (concat (car dirs) name)))
  1977. this-dir-contents)
  1978. this-dir-contents)
  1979. contents))))
  1980. (setq dirs (cdr dirs)))
  1981. contents)))
  1982. ;; `member-ignore-case' undefined (XEmacs)
  1983. (unless (fboundp 'member-ignore-case)
  1984. (defalias 'member-ignore-case 'member))
  1985. ;; `last-input-char' obsolete in Emacs 24, `last-input-event' different
  1986. ;; behavior in XEmacs
  1987. (defvar vhdl-last-input-event)
  1988. (if (featurep 'xemacs)
  1989. (defvaralias 'vhdl-last-input-event 'last-input-char)
  1990. (defvaralias 'vhdl-last-input-event 'last-input-event))
  1991. ;; `help-print-return-message' changed to `print-help-return-message' in Emacs
  1992. ;;;(unless (fboundp 'help-print-return-message)
  1993. ;;; (defalias 'help-print-return-message 'print-help-return-message))
  1994. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1995. ;; Compatibility with older VHDL Mode versions
  1996. (defvar vhdl-warnings nil
  1997. "Warnings to tell the user during start up.")
  1998. (defun vhdl-run-when-idle (secs repeat function)
  1999. "Wait until idle, then run FUNCTION."
  2000. (if (fboundp 'start-itimer)
  2001. (start-itimer "vhdl-mode" function secs repeat t)
  2002. ;; explicitly activate timer (necessary when Emacs is already idle)
  2003. (aset (run-with-idle-timer secs repeat function) 0 nil)))
  2004. (defun vhdl-warning-when-idle (&rest args)
  2005. "Wait until idle, then print out warning STRING and beep."
  2006. (let ((message (apply #'format-message args)))
  2007. (if noninteractive
  2008. (vhdl-warning message t)
  2009. (unless vhdl-warnings
  2010. (vhdl-run-when-idle .1 nil 'vhdl-print-warnings))
  2011. (push message vhdl-warnings))))
  2012. (defun vhdl-warning (string &optional nobeep)
  2013. "Print out warning STRING and beep."
  2014. (message "WARNING: %s" string)
  2015. (unless (or nobeep noninteractive) (beep)))
  2016. (defun vhdl-print-warnings ()
  2017. "Print out messages in variable `vhdl-warnings'."
  2018. (let ((no-warnings (length vhdl-warnings)))
  2019. (setq vhdl-warnings (nreverse vhdl-warnings))
  2020. (while vhdl-warnings
  2021. (message "WARNING: %s" (car vhdl-warnings))
  2022. (setq vhdl-warnings (cdr vhdl-warnings)))
  2023. (beep)
  2024. (when (> no-warnings 1)
  2025. (message "WARNING: See warnings in message buffer (type `C-c M-m')."))))
  2026. ;; Backward compatibility checks and fixes
  2027. ;; option `vhdl-compiler' changed format
  2028. (unless (stringp vhdl-compiler)
  2029. (setq vhdl-compiler "ModelSim")
  2030. (vhdl-warning-when-idle "Option `vhdl-compiler' has changed format; customize again"))
  2031. ;; option `vhdl-standard' changed format
  2032. (unless (listp vhdl-standard)
  2033. (setq vhdl-standard '(87 nil))
  2034. (vhdl-warning-when-idle "Option `vhdl-standard' has changed format; customize again"))
  2035. ;; option `vhdl-model-alist' changed format
  2036. (when (= (length (car vhdl-model-alist)) 3)
  2037. (let ((old-alist vhdl-model-alist)
  2038. new-alist)
  2039. (while old-alist
  2040. (push (append (car old-alist) '("")) new-alist)
  2041. (setq old-alist (cdr old-alist)))
  2042. (setq vhdl-model-alist (nreverse new-alist)))
  2043. (customize-save-variable 'vhdl-model-alist vhdl-model-alist))
  2044. ;; option `vhdl-project-alist' changed format
  2045. (when (= (length (car vhdl-project-alist)) 3)
  2046. (let ((old-alist vhdl-project-alist)
  2047. new-alist)
  2048. (while old-alist
  2049. (push (append (car old-alist) '("")) new-alist)
  2050. (setq old-alist (cdr old-alist)))
  2051. (setq vhdl-project-alist (nreverse new-alist)))
  2052. (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
  2053. ;; option `vhdl-project-alist' changed format (3.31.1)
  2054. (when (= (length (car vhdl-project-alist)) 4)
  2055. (let ((old-alist vhdl-project-alist)
  2056. new-alist elem)
  2057. (while old-alist
  2058. (setq elem (car old-alist))
  2059. (setq new-alist
  2060. (cons (list (nth 0 elem) (nth 1 elem) "" (nth 2 elem)
  2061. nil "./" "work" "work/" "Makefile" (nth 3 elem))
  2062. new-alist))
  2063. (setq old-alist (cdr old-alist)))
  2064. (setq vhdl-project-alist (nreverse new-alist)))
  2065. (vhdl-warning-when-idle "Option `vhdl-project-alist' changed format; please re-customize"))
  2066. ;; option `vhdl-project-alist' changed format (3.31.12)
  2067. (when (= (length (car vhdl-project-alist)) 10)
  2068. (let ((tmp-alist vhdl-project-alist))
  2069. (while tmp-alist
  2070. (setcdr (nthcdr 3 (car tmp-alist))
  2071. (cons "" (nthcdr 4 (car tmp-alist))))
  2072. (setq tmp-alist (cdr tmp-alist))))
  2073. (customize-save-variable 'vhdl-project-alist vhdl-project-alist))
  2074. ;; option `vhdl-compiler-alist' changed format (3.31.1)
  2075. (when (= (length (car vhdl-compiler-alist)) 7)
  2076. (let ((old-alist vhdl-compiler-alist)
  2077. new-alist elem)
  2078. (while old-alist
  2079. (setq elem (car old-alist))
  2080. (setq new-alist
  2081. (cons (list (nth 0 elem) (nth 1 elem) "" "make -f \\1"
  2082. (if (equal (nth 3 elem) "") nil (nth 3 elem))
  2083. (nth 4 elem) "work/" "Makefile" (downcase (nth 0 elem))
  2084. (nth 5 elem) (nth 6 elem) nil)
  2085. new-alist))
  2086. (setq old-alist (cdr old-alist)))
  2087. (setq vhdl-compiler-alist (nreverse new-alist)))
  2088. (vhdl-warning-when-idle "Option `vhdl-compiler-alist' changed; please reset and re-customize"))
  2089. ;; option `vhdl-compiler-alist' changed format (3.31.10)
  2090. (when (= (length (car vhdl-compiler-alist)) 12)
  2091. (let ((tmp-alist vhdl-compiler-alist))
  2092. (while tmp-alist
  2093. (setcdr (nthcdr 4 (car tmp-alist))
  2094. (cons "mkdir \\1" (nthcdr 5 (car tmp-alist))))
  2095. (setq tmp-alist (cdr tmp-alist))))
  2096. (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
  2097. ;; option `vhdl-compiler-alist' changed format (3.31.11)
  2098. (when (= (length (car vhdl-compiler-alist)) 13)
  2099. (let ((tmp-alist vhdl-compiler-alist))
  2100. (while tmp-alist
  2101. (setcdr (nthcdr 3 (car tmp-alist))
  2102. (cons "" (nthcdr 4 (car tmp-alist))))
  2103. (setq tmp-alist (cdr tmp-alist))))
  2104. (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
  2105. ;; option `vhdl-compiler-alist' changed format (3.32.7)
  2106. (when (= (length (nth 11 (car vhdl-compiler-alist))) 3)
  2107. (let ((tmp-alist vhdl-compiler-alist))
  2108. (while tmp-alist
  2109. (setcdr (nthcdr 2 (nth 11 (car tmp-alist)))
  2110. '(0 . nil))
  2111. (setq tmp-alist (cdr tmp-alist))))
  2112. (customize-save-variable 'vhdl-compiler-alist vhdl-compiler-alist))
  2113. ;; option `vhdl-project': empty value changed from "" to nil (3.31.1)
  2114. (when (equal vhdl-project "")
  2115. (setq vhdl-project nil)
  2116. (customize-save-variable 'vhdl-project vhdl-project))
  2117. ;; option `vhdl-project-file-name': changed format (3.31.17 beta)
  2118. (when (stringp vhdl-project-file-name)
  2119. (setq vhdl-project-file-name (list vhdl-project-file-name))
  2120. (customize-save-variable 'vhdl-project-file-name vhdl-project-file-name))
  2121. ;; option `speedbar-indentation-width': introduced in speedbar 0.10
  2122. (if (not (boundp 'speedbar-indentation-width))
  2123. (defvar speedbar-indentation-width 2)
  2124. ;; set default to 2 if not already customized
  2125. (unless (get 'speedbar-indentation-width 'saved-value)
  2126. (setq speedbar-indentation-width 2)))
  2127. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2128. ;;; Help functions / inline substitutions / macros
  2129. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2130. (defun vhdl-standard-p (standard)
  2131. "Check if STANDARD is specified as used standard."
  2132. (or (eq standard (car vhdl-standard))
  2133. (memq standard (cadr vhdl-standard))))
  2134. (defun vhdl-project-p (&optional warning)
  2135. "Return non-nil if a project is displayed, i.e. directories or files are
  2136. specified."
  2137. (if (assoc vhdl-project vhdl-project-alist)
  2138. vhdl-project
  2139. (when (and vhdl-project warning)
  2140. (vhdl-warning-when-idle "Project does not exist: \"%s\"" vhdl-project))
  2141. nil))
  2142. (defun vhdl-resolve-env-variable (string)
  2143. "Resolve environment variables in STRING."
  2144. (while (string-match "\\(.*\\)${?\\(\\(\\w\\|_\\)+\\)}?\\(.*\\)" string)
  2145. (setq string (concat (match-string 1 string)
  2146. (getenv (match-string 2 string))
  2147. (match-string 4 string))))
  2148. string)
  2149. (defun vhdl-default-directory ()
  2150. "Return the default directory of the current project or the directory of the
  2151. current buffer if no project is defined."
  2152. (if (vhdl-project-p)
  2153. (expand-file-name (vhdl-resolve-env-variable
  2154. (nth 1 (vhdl-aget vhdl-project-alist vhdl-project))))
  2155. default-directory))
  2156. (defmacro vhdl-prepare-search-1 (&rest body)
  2157. "Enable case insensitive search and switch to syntax table that includes '_',
  2158. then execute BODY, and finally restore the old environment. Used for
  2159. consistent searching."
  2160. `(let ((case-fold-search t)) ; case insensitive search
  2161. ;; use extended syntax table
  2162. (with-syntax-table vhdl-mode-ext-syntax-table
  2163. ,@body)))
  2164. (defmacro vhdl-prepare-search-2 (&rest body)
  2165. "Enable case insensitive search, switch to syntax table that includes '_',
  2166. arrange to ignore `intangible' overlays, then execute BODY, and finally restore
  2167. the old environment. Used for consistent searching."
  2168. `(let ((case-fold-search t) ; case insensitive search
  2169. (current-syntax-table (syntax-table))
  2170. (inhibit-point-motion-hooks t))
  2171. ;; use extended syntax table
  2172. (set-syntax-table vhdl-mode-ext-syntax-table)
  2173. ;; execute BODY safely
  2174. (unwind-protect
  2175. (progn ,@body)
  2176. ;; restore syntax table
  2177. (set-syntax-table current-syntax-table))))
  2178. (defmacro vhdl-visit-file (file-name issue-error &rest body)
  2179. "Visit file FILE-NAME and execute BODY."
  2180. `(if (null ,file-name)
  2181. (progn ,@body)
  2182. (unless (file-directory-p ,file-name)
  2183. (let ((source-buffer (current-buffer))
  2184. (visiting-buffer (find-buffer-visiting ,file-name))
  2185. file-opened)
  2186. (when (or (and visiting-buffer (set-buffer visiting-buffer))
  2187. (condition-case ()
  2188. (progn (set-buffer (create-file-buffer ,file-name))
  2189. (setq file-opened t)
  2190. (vhdl-insert-file-contents ,file-name)
  2191. ;; FIXME: This modifies a global syntax-table!
  2192. (modify-syntax-entry ?\- ". 12" (syntax-table))
  2193. (modify-syntax-entry ?\n ">" (syntax-table))
  2194. (modify-syntax-entry ?\^M ">" (syntax-table))
  2195. (modify-syntax-entry ?_ "w" (syntax-table))
  2196. t)
  2197. (error
  2198. (if ,issue-error
  2199. (progn
  2200. (when file-opened (kill-buffer (current-buffer)))
  2201. (set-buffer source-buffer)
  2202. (error "ERROR: File cannot be opened: \"%s\"" ,file-name))
  2203. (vhdl-warning (format "File cannot be opened: \"%s\"" ,file-name) t)
  2204. nil))))
  2205. (condition-case info
  2206. (progn ,@body)
  2207. (error
  2208. (if ,issue-error
  2209. (progn
  2210. (when file-opened (kill-buffer (current-buffer)))
  2211. (set-buffer source-buffer)
  2212. (error (cadr info)))
  2213. (vhdl-warning (cadr info))))))
  2214. (when file-opened (kill-buffer (current-buffer)))
  2215. (set-buffer source-buffer)))))
  2216. (defun vhdl-insert-file-contents (filename)
  2217. "Nicked from `insert-file-contents-literally', but allow coding system
  2218. conversion."
  2219. (let ((format-alist nil)
  2220. (after-insert-file-functions nil)
  2221. (jka-compr-compression-info-list nil))
  2222. (insert-file-contents filename t)))
  2223. (defun vhdl-sort-alist (alist)
  2224. "Sort ALIST."
  2225. (sort alist (function (lambda (a b) (string< (car a) (car b))))))
  2226. (defun vhdl-get-subdirs (directory)
  2227. "Recursively get subdirectories of DIRECTORY."
  2228. (let ((dir-list (list (file-name-as-directory directory)))
  2229. file-list)
  2230. (setq file-list (vhdl-directory-files directory t "\\w.*"))
  2231. (while file-list
  2232. (when (file-directory-p (car file-list))
  2233. (setq dir-list (append dir-list (vhdl-get-subdirs (car file-list)))))
  2234. (setq file-list (cdr file-list)))
  2235. dir-list))
  2236. (defun vhdl-aput-delete-if-nil (alist-symbol key &optional value)
  2237. "As `aput', but delete key-value pair if VALUE is nil."
  2238. (if value
  2239. (vhdl-aput alist-symbol key value)
  2240. (vhdl-adelete alist-symbol key)))
  2241. (defun vhdl-delete (elt list)
  2242. "Delete by side effect the first occurrence of ELT as a member of LIST."
  2243. (push nil list)
  2244. (let ((list1 list))
  2245. (while (and (cdr list1) (not (equal elt (cadr list1))))
  2246. (setq list1 (cdr list1)))
  2247. (when list
  2248. (setcdr list1 (cddr list1))))
  2249. (cdr list))
  2250. (declare-function speedbar-refresh "speedbar" (&optional arg))
  2251. (declare-function speedbar-do-function-pointer "speedbar" ())
  2252. (defun vhdl-speedbar-refresh (&optional key)
  2253. "Refresh directory or project with name KEY."
  2254. (when (and (boundp 'speedbar-frame)
  2255. (frame-live-p speedbar-frame))
  2256. (let ((pos (point))
  2257. (last-frame (selected-frame)))
  2258. (if (null key)
  2259. (speedbar-refresh)
  2260. (select-frame speedbar-frame)
  2261. (when (save-excursion
  2262. (goto-char (point-min))
  2263. (re-search-forward (concat "^\\([0-9]+:\\s-*<\\)->\\s-+" key "$") nil t))
  2264. (goto-char (match-end 1))
  2265. (speedbar-do-function-pointer)
  2266. (backward-char 2)
  2267. (speedbar-do-function-pointer)
  2268. (message "Refreshing speedbar...done"))
  2269. (select-frame last-frame)))))
  2270. (defun vhdl-show-messages ()
  2271. "Get *Messages* buffer to show recent messages."
  2272. (interactive)
  2273. (display-buffer (if (featurep 'xemacs) " *Message-Log*" "*Messages*")))
  2274. (defun vhdl-use-direct-instantiation ()
  2275. "Return whether direct instantiation is used."
  2276. (or (eq vhdl-use-direct-instantiation 'always)
  2277. (and (eq vhdl-use-direct-instantiation 'standard)
  2278. (not (vhdl-standard-p '87)))))
  2279. (defun vhdl-max-marker (marker1 marker2)
  2280. "Return larger marker."
  2281. (if (> marker1 marker2) marker1 marker2))
  2282. (defun vhdl-goto-marker (marker)
  2283. "Goto marker in appropriate buffer."
  2284. (when (markerp marker)
  2285. (set-buffer (marker-buffer marker)))
  2286. (goto-char marker))
  2287. (defun vhdl-menu-split (list title)
  2288. "Split menu LIST into several submenus, if number of
  2289. elements > `vhdl-menu-max-size'."
  2290. (if (> (length list) vhdl-menu-max-size)
  2291. (let ((remain list)
  2292. (result '())
  2293. (sublist '())
  2294. (menuno 1)
  2295. (i 0))
  2296. (while remain
  2297. (push (car remain) sublist)
  2298. (setq remain (cdr remain))
  2299. (setq i (+ i 1))
  2300. (if (= i vhdl-menu-max-size)
  2301. (progn
  2302. (push (cons (format "%s %s" title menuno)
  2303. (nreverse sublist)) result)
  2304. (setq i 0)
  2305. (setq menuno (+ menuno 1))
  2306. (setq sublist '()))))
  2307. (and sublist
  2308. (push (cons (format "%s %s" title menuno)
  2309. (nreverse sublist)) result))
  2310. (nreverse result))
  2311. list))
  2312. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2313. ;;; Bindings
  2314. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2315. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2316. ;; Key bindings
  2317. (defvar vhdl-template-map nil
  2318. "Keymap for VHDL templates.")
  2319. (defun vhdl-template-map-init ()
  2320. "Initialize `vhdl-template-map'."
  2321. (setq vhdl-template-map (make-sparse-keymap))
  2322. ;; key bindings for VHDL templates
  2323. (define-key vhdl-template-map "al" 'vhdl-template-alias)
  2324. (define-key vhdl-template-map "ar" 'vhdl-template-architecture)
  2325. (define-key vhdl-template-map "at" 'vhdl-template-assert)
  2326. (define-key vhdl-template-map "ad" 'vhdl-template-attribute-decl)
  2327. (define-key vhdl-template-map "as" 'vhdl-template-attribute-spec)
  2328. (define-key vhdl-template-map "bl" 'vhdl-template-block)
  2329. (define-key vhdl-template-map "ca" 'vhdl-template-case-is)
  2330. (define-key vhdl-template-map "cd" 'vhdl-template-component-decl)
  2331. (define-key vhdl-template-map "ci" 'vhdl-template-component-inst)
  2332. (define-key vhdl-template-map "cs" 'vhdl-template-conditional-signal-asst)
  2333. (define-key vhdl-template-map "Cb" 'vhdl-template-block-configuration)
  2334. (define-key vhdl-template-map "Cc" 'vhdl-template-component-conf)
  2335. (define-key vhdl-template-map "Cd" 'vhdl-template-configuration-decl)
  2336. (define-key vhdl-template-map "Cs" 'vhdl-template-configuration-spec)
  2337. (define-key vhdl-template-map "co" 'vhdl-template-constant)
  2338. (define-key vhdl-template-map "ct" 'vhdl-template-context)
  2339. (define-key vhdl-template-map "di" 'vhdl-template-disconnect)
  2340. (define-key vhdl-template-map "el" 'vhdl-template-else)
  2341. (define-key vhdl-template-map "ei" 'vhdl-template-elsif)
  2342. (define-key vhdl-template-map "en" 'vhdl-template-entity)
  2343. (define-key vhdl-template-map "ex" 'vhdl-template-exit)
  2344. (define-key vhdl-template-map "fi" 'vhdl-template-file)
  2345. (define-key vhdl-template-map "fg" 'vhdl-template-for-generate)
  2346. (define-key vhdl-template-map "fl" 'vhdl-template-for-loop)
  2347. (define-key vhdl-template-map "\C-f" 'vhdl-template-footer)
  2348. (define-key vhdl-template-map "fb" 'vhdl-template-function-body)
  2349. (define-key vhdl-template-map "fd" 'vhdl-template-function-decl)
  2350. (define-key vhdl-template-map "ge" 'vhdl-template-generic)
  2351. (define-key vhdl-template-map "gd" 'vhdl-template-group-decl)
  2352. (define-key vhdl-template-map "gt" 'vhdl-template-group-template)
  2353. (define-key vhdl-template-map "\C-h" 'vhdl-template-header)
  2354. (define-key vhdl-template-map "ig" 'vhdl-template-if-generate)
  2355. (define-key vhdl-template-map "it" 'vhdl-template-if-then)
  2356. (define-key vhdl-template-map "li" 'vhdl-template-library)
  2357. (define-key vhdl-template-map "lo" 'vhdl-template-bare-loop)
  2358. (define-key vhdl-template-map "\C-m" 'vhdl-template-modify)
  2359. (define-key vhdl-template-map "\C-t" 'vhdl-template-insert-date)
  2360. (define-key vhdl-template-map "ma" 'vhdl-template-map)
  2361. (define-key vhdl-template-map "ne" 'vhdl-template-next)
  2362. (define-key vhdl-template-map "ot" 'vhdl-template-others)
  2363. (define-key vhdl-template-map "Pd" 'vhdl-template-package-decl)
  2364. (define-key vhdl-template-map "Pb" 'vhdl-template-package-body)
  2365. (define-key vhdl-template-map "(" 'vhdl-template-paired-parens)
  2366. (define-key vhdl-template-map "po" 'vhdl-template-port)
  2367. (define-key vhdl-template-map "pb" 'vhdl-template-procedure-body)
  2368. (define-key vhdl-template-map "pd" 'vhdl-template-procedure-decl)
  2369. (define-key vhdl-template-map "pc" 'vhdl-template-process-comb)
  2370. (define-key vhdl-template-map "ps" 'vhdl-template-process-seq)
  2371. (define-key vhdl-template-map "rp" 'vhdl-template-report)
  2372. (define-key vhdl-template-map "rt" 'vhdl-template-return)
  2373. (define-key vhdl-template-map "ss" 'vhdl-template-selected-signal-asst)
  2374. (define-key vhdl-template-map "si" 'vhdl-template-signal)
  2375. (define-key vhdl-template-map "su" 'vhdl-template-subtype)
  2376. (define-key vhdl-template-map "ty" 'vhdl-template-type)
  2377. (define-key vhdl-template-map "us" 'vhdl-template-use)
  2378. (define-key vhdl-template-map "va" 'vhdl-template-variable)
  2379. (define-key vhdl-template-map "wa" 'vhdl-template-wait)
  2380. (define-key vhdl-template-map "wl" 'vhdl-template-while-loop)
  2381. (define-key vhdl-template-map "wi" 'vhdl-template-with)
  2382. (define-key vhdl-template-map "wc" 'vhdl-template-clocked-wait)
  2383. (define-key vhdl-template-map "\C-pb" 'vhdl-template-package-numeric-bit)
  2384. (define-key vhdl-template-map "\C-pn" 'vhdl-template-package-numeric-std)
  2385. (define-key vhdl-template-map "\C-ps" 'vhdl-template-package-std-logic-1164)
  2386. (define-key vhdl-template-map "\C-pA" 'vhdl-template-package-std-logic-arith)
  2387. (define-key vhdl-template-map "\C-pM" 'vhdl-template-package-std-logic-misc)
  2388. (define-key vhdl-template-map "\C-pS" 'vhdl-template-package-std-logic-signed)
  2389. (define-key vhdl-template-map "\C-pT" 'vhdl-template-package-std-logic-textio)
  2390. (define-key vhdl-template-map "\C-pU" 'vhdl-template-package-std-logic-unsigned)
  2391. (define-key vhdl-template-map "\C-pt" 'vhdl-template-package-textio)
  2392. (define-key vhdl-template-map "\C-dn" 'vhdl-template-directive-translate-on)
  2393. (define-key vhdl-template-map "\C-df" 'vhdl-template-directive-translate-off)
  2394. (define-key vhdl-template-map "\C-dN" 'vhdl-template-directive-synthesis-on)
  2395. (define-key vhdl-template-map "\C-dF" 'vhdl-template-directive-synthesis-off)
  2396. (define-key vhdl-template-map "\C-q" 'vhdl-template-search-prompt)
  2397. (when (vhdl-standard-p 'ams)
  2398. (define-key vhdl-template-map "br" 'vhdl-template-break)
  2399. (define-key vhdl-template-map "cu" 'vhdl-template-case-use)
  2400. (define-key vhdl-template-map "iu" 'vhdl-template-if-use)
  2401. (define-key vhdl-template-map "lm" 'vhdl-template-limit)
  2402. (define-key vhdl-template-map "na" 'vhdl-template-nature)
  2403. (define-key vhdl-template-map "pa" 'vhdl-template-procedural)
  2404. (define-key vhdl-template-map "qf" 'vhdl-template-quantity-free)
  2405. (define-key vhdl-template-map "qb" 'vhdl-template-quantity-branch)
  2406. (define-key vhdl-template-map "qs" 'vhdl-template-quantity-source)
  2407. (define-key vhdl-template-map "sn" 'vhdl-template-subnature)
  2408. (define-key vhdl-template-map "te" 'vhdl-template-terminal)
  2409. )
  2410. (when (vhdl-standard-p 'math)
  2411. (define-key vhdl-template-map "\C-pc" 'vhdl-template-package-math-complex)
  2412. (define-key vhdl-template-map "\C-pr" 'vhdl-template-package-math-real)
  2413. ))
  2414. ;; initialize template map for VHDL Mode
  2415. (vhdl-template-map-init)
  2416. (defun vhdl-function-name (prefix string &optional postfix)
  2417. "Generate a Lisp function name.
  2418. PREFIX, STRING and optional POSTFIX are concatenated by '-' and spaces in
  2419. STRING are replaced by `-' and substrings are converted to lower case."
  2420. (let ((name prefix))
  2421. (while (string-match "\\(\\w+\\)\\s-*\\(.*\\)" string)
  2422. (setq name
  2423. (concat name "-" (downcase (substring string 0 (match-end 1)))))
  2424. (setq string (substring string (match-beginning 2))))
  2425. (when postfix (setq name (concat name "-" postfix)))
  2426. (intern name)))
  2427. (defvar vhdl-model-map nil
  2428. "Keymap for VHDL models.")
  2429. (defun vhdl-model-map-init ()
  2430. "Initialize `vhdl-model-map'."
  2431. (setq vhdl-model-map (make-sparse-keymap))
  2432. ;; key bindings for VHDL models
  2433. (let ((model-alist vhdl-model-alist) model)
  2434. (while model-alist
  2435. (setq model (car model-alist))
  2436. (define-key vhdl-model-map (nth 2 model)
  2437. (vhdl-function-name "vhdl-model" (nth 0 model)))
  2438. (setq model-alist (cdr model-alist)))))
  2439. ;; initialize user model map for VHDL Mode
  2440. (vhdl-model-map-init)
  2441. (defvar vhdl-mode-map nil
  2442. "Keymap for VHDL Mode.")
  2443. (defun vhdl-mode-map-init ()
  2444. "Initialize `vhdl-mode-map'."
  2445. (setq vhdl-mode-map (make-sparse-keymap))
  2446. ;; template key bindings
  2447. (define-key vhdl-mode-map "\C-c\C-t" vhdl-template-map)
  2448. ;; model key bindings
  2449. (define-key vhdl-mode-map "\C-c\C-m" vhdl-model-map)
  2450. ;; standard key bindings
  2451. (define-key vhdl-mode-map "\M-a" 'vhdl-beginning-of-statement)
  2452. (define-key vhdl-mode-map "\M-e" 'vhdl-end-of-statement)
  2453. (define-key vhdl-mode-map "\M-\C-f" 'vhdl-forward-sexp)
  2454. (define-key vhdl-mode-map "\M-\C-b" 'vhdl-backward-sexp)
  2455. (define-key vhdl-mode-map "\M-\C-u" 'vhdl-backward-up-list)
  2456. (define-key vhdl-mode-map "\M-\C-a" 'vhdl-backward-same-indent)
  2457. (define-key vhdl-mode-map "\M-\C-e" 'vhdl-forward-same-indent)
  2458. (unless (featurep 'xemacs) ; would override `M-backspace' in XEmacs
  2459. (define-key vhdl-mode-map "\M-\C-h" 'vhdl-mark-defun))
  2460. (define-key vhdl-mode-map "\M-\C-q" 'vhdl-indent-sexp)
  2461. (define-key vhdl-mode-map "\M-^" 'vhdl-delete-indentation)
  2462. ;; mode specific key bindings
  2463. (define-key vhdl-mode-map "\C-c\C-m\C-e" 'vhdl-electric-mode)
  2464. (define-key vhdl-mode-map "\C-c\C-m\C-s" 'vhdl-stutter-mode)
  2465. (define-key vhdl-mode-map "\C-c\C-s\C-p" 'vhdl-set-project)
  2466. (define-key vhdl-mode-map "\C-c\C-p\C-d" 'vhdl-duplicate-project)
  2467. (define-key vhdl-mode-map "\C-c\C-p\C-m" 'vhdl-import-project)
  2468. (define-key vhdl-mode-map "\C-c\C-p\C-x" 'vhdl-export-project)
  2469. (define-key vhdl-mode-map "\C-c\C-s\C-k" 'vhdl-set-compiler)
  2470. (define-key vhdl-mode-map "\C-c\C-k" 'vhdl-compile)
  2471. (define-key vhdl-mode-map "\C-c\M-\C-k" 'vhdl-make)
  2472. (define-key vhdl-mode-map "\C-c\M-k" 'vhdl-generate-makefile)
  2473. (define-key vhdl-mode-map "\C-c\C-p\C-w" 'vhdl-port-copy)
  2474. (define-key vhdl-mode-map "\C-c\C-p\M-w" 'vhdl-port-copy)
  2475. (define-key vhdl-mode-map "\C-c\C-p\C-e" 'vhdl-port-paste-entity)
  2476. (define-key vhdl-mode-map "\C-c\C-p\C-c" 'vhdl-port-paste-component)
  2477. (define-key vhdl-mode-map "\C-c\C-p\C-i" 'vhdl-port-paste-instance)
  2478. (define-key vhdl-mode-map "\C-c\C-p\C-s" 'vhdl-port-paste-signals)
  2479. (define-key vhdl-mode-map "\C-c\C-p\M-c" 'vhdl-port-paste-constants)
  2480. (if (featurep 'xemacs) ; `... C-g' not allowed in XEmacs
  2481. (define-key vhdl-mode-map "\C-c\C-p\M-g" 'vhdl-port-paste-generic-map)
  2482. (define-key vhdl-mode-map "\C-c\C-p\C-g" 'vhdl-port-paste-generic-map))
  2483. (define-key vhdl-mode-map "\C-c\C-p\C-z" 'vhdl-port-paste-initializations)
  2484. (define-key vhdl-mode-map "\C-c\C-p\C-t" 'vhdl-port-paste-testbench)
  2485. (define-key vhdl-mode-map "\C-c\C-p\C-f" 'vhdl-port-flatten)
  2486. (define-key vhdl-mode-map "\C-c\C-p\C-r" 'vhdl-port-reverse-direction)
  2487. (define-key vhdl-mode-map "\C-c\C-s\C-w" 'vhdl-subprog-copy)
  2488. (define-key vhdl-mode-map "\C-c\C-s\M-w" 'vhdl-subprog-copy)
  2489. (define-key vhdl-mode-map "\C-c\C-s\C-d" 'vhdl-subprog-paste-declaration)
  2490. (define-key vhdl-mode-map "\C-c\C-s\C-b" 'vhdl-subprog-paste-body)
  2491. (define-key vhdl-mode-map "\C-c\C-s\C-c" 'vhdl-subprog-paste-call)
  2492. (define-key vhdl-mode-map "\C-c\C-s\C-f" 'vhdl-subprog-flatten)
  2493. (define-key vhdl-mode-map "\C-c\C-m\C-n" 'vhdl-compose-new-component)
  2494. (define-key vhdl-mode-map "\C-c\C-m\C-p" 'vhdl-compose-place-component)
  2495. (define-key vhdl-mode-map "\C-c\C-m\C-w" 'vhdl-compose-wire-components)
  2496. (define-key vhdl-mode-map "\C-c\C-m\C-f" 'vhdl-compose-configuration)
  2497. (define-key vhdl-mode-map "\C-c\C-m\C-k" 'vhdl-compose-components-package)
  2498. (define-key vhdl-mode-map "\C-c\C-c" 'vhdl-comment-uncomment-region)
  2499. (define-key vhdl-mode-map "\C-c-" 'vhdl-comment-append-inline)
  2500. (define-key vhdl-mode-map "\C-c\M--" 'vhdl-comment-display-line)
  2501. (define-key vhdl-mode-map "\C-c\C-i\C-l" 'indent-according-to-mode)
  2502. (define-key vhdl-mode-map "\C-c\C-i\C-g" 'vhdl-indent-group)
  2503. (define-key vhdl-mode-map "\M-\C-\\" 'vhdl-indent-region)
  2504. (define-key vhdl-mode-map "\C-c\C-i\C-b" 'vhdl-indent-buffer)
  2505. (define-key vhdl-mode-map "\C-c\C-a\C-g" 'vhdl-align-group)
  2506. (define-key vhdl-mode-map "\C-c\C-a\C-a" 'vhdl-align-group)
  2507. (define-key vhdl-mode-map "\C-c\C-a\C-i" 'vhdl-align-same-indent)
  2508. (define-key vhdl-mode-map "\C-c\C-a\C-l" 'vhdl-align-list)
  2509. (define-key vhdl-mode-map "\C-c\C-a\C-d" 'vhdl-align-declarations)
  2510. (define-key vhdl-mode-map "\C-c\C-a\M-a" 'vhdl-align-region)
  2511. (define-key vhdl-mode-map "\C-c\C-a\C-b" 'vhdl-align-buffer)
  2512. (define-key vhdl-mode-map "\C-c\C-a\C-c" 'vhdl-align-inline-comment-group)
  2513. (define-key vhdl-mode-map "\C-c\C-a\M-c" 'vhdl-align-inline-comment-region)
  2514. (define-key vhdl-mode-map "\C-c\C-f\C-l" 'vhdl-fill-list)
  2515. (define-key vhdl-mode-map "\C-c\C-f\C-f" 'vhdl-fill-list)
  2516. (define-key vhdl-mode-map "\C-c\C-f\C-g" 'vhdl-fill-group)
  2517. (define-key vhdl-mode-map "\C-c\C-f\C-i" 'vhdl-fill-same-indent)
  2518. (define-key vhdl-mode-map "\C-c\C-f\M-f" 'vhdl-fill-region)
  2519. (define-key vhdl-mode-map "\C-c\C-l\C-w" 'vhdl-line-kill)
  2520. (define-key vhdl-mode-map "\C-c\C-l\M-w" 'vhdl-line-copy)
  2521. (define-key vhdl-mode-map "\C-c\C-l\C-y" 'vhdl-line-yank)
  2522. (define-key vhdl-mode-map "\C-c\C-l\t" 'vhdl-line-expand)
  2523. (define-key vhdl-mode-map "\C-c\C-l\C-n" 'vhdl-line-transpose-next)
  2524. (define-key vhdl-mode-map "\C-c\C-l\C-p" 'vhdl-line-transpose-previous)
  2525. (define-key vhdl-mode-map "\C-c\C-l\C-o" 'vhdl-line-open)
  2526. (define-key vhdl-mode-map "\C-c\C-l\C-g" 'goto-line)
  2527. (define-key vhdl-mode-map "\C-c\C-l\C-c" 'vhdl-comment-uncomment-line)
  2528. (define-key vhdl-mode-map "\C-c\C-x\C-s" 'vhdl-fix-statement-region)
  2529. (define-key vhdl-mode-map "\C-c\C-x\M-s" 'vhdl-fix-statement-buffer)
  2530. (define-key vhdl-mode-map "\C-c\C-x\C-p" 'vhdl-fix-clause)
  2531. (define-key vhdl-mode-map "\C-c\C-x\M-c" 'vhdl-fix-case-region)
  2532. (define-key vhdl-mode-map "\C-c\C-x\C-c" 'vhdl-fix-case-buffer)
  2533. (define-key vhdl-mode-map "\C-c\C-x\M-w" 'vhdl-fixup-whitespace-region)
  2534. (define-key vhdl-mode-map "\C-c\C-x\C-w" 'vhdl-fixup-whitespace-buffer)
  2535. (define-key vhdl-mode-map "\C-c\M-b" 'vhdl-beautify-region)
  2536. (define-key vhdl-mode-map "\C-c\C-b" 'vhdl-beautify-buffer)
  2537. (define-key vhdl-mode-map "\C-c\C-u\C-s" 'vhdl-update-sensitivity-list-process)
  2538. (define-key vhdl-mode-map "\C-c\C-u\M-s" 'vhdl-update-sensitivity-list-buffer)
  2539. (define-key vhdl-mode-map "\C-c\C-i\C-f" 'vhdl-fontify-buffer)
  2540. (define-key vhdl-mode-map "\C-c\C-i\C-s" 'vhdl-statistics-buffer)
  2541. (define-key vhdl-mode-map "\C-c\M-m" 'vhdl-show-messages)
  2542. (define-key vhdl-mode-map "\C-c\C-h" 'vhdl-doc-mode)
  2543. (define-key vhdl-mode-map "\C-c\C-v" 'vhdl-version)
  2544. (define-key vhdl-mode-map "\M-\t" 'insert-tab)
  2545. ;; insert commands bindings
  2546. (define-key vhdl-mode-map "\C-c\C-i\C-t" 'vhdl-template-insert-construct)
  2547. (define-key vhdl-mode-map "\C-c\C-i\C-p" 'vhdl-template-insert-package)
  2548. (define-key vhdl-mode-map "\C-c\C-i\C-d" 'vhdl-template-insert-directive)
  2549. (define-key vhdl-mode-map "\C-c\C-i\C-m" 'vhdl-model-insert)
  2550. ;; electric key bindings
  2551. (define-key vhdl-mode-map " " 'vhdl-electric-space)
  2552. (when vhdl-intelligent-tab
  2553. (define-key vhdl-mode-map "\t" 'vhdl-electric-tab))
  2554. (define-key vhdl-mode-map "\r" 'vhdl-electric-return)
  2555. (define-key vhdl-mode-map "-" 'vhdl-electric-dash)
  2556. (define-key vhdl-mode-map "[" 'vhdl-electric-open-bracket)
  2557. (define-key vhdl-mode-map "]" 'vhdl-electric-close-bracket)
  2558. (define-key vhdl-mode-map "'" 'vhdl-electric-quote)
  2559. (define-key vhdl-mode-map ";" 'vhdl-electric-semicolon)
  2560. (define-key vhdl-mode-map "," 'vhdl-electric-comma)
  2561. (define-key vhdl-mode-map "." 'vhdl-electric-period)
  2562. (when (vhdl-standard-p 'ams)
  2563. (define-key vhdl-mode-map "=" 'vhdl-electric-equal)))
  2564. ;; initialize mode map for VHDL Mode
  2565. (vhdl-mode-map-init)
  2566. ;; define special minibuffer keymap for enabling word completion in minibuffer
  2567. ;; (useful in template generator prompts)
  2568. (defvar vhdl-minibuffer-local-map
  2569. (let ((map (make-sparse-keymap)))
  2570. (set-keymap-parent map minibuffer-local-map)
  2571. (when vhdl-word-completion-in-minibuffer
  2572. (define-key map "\t" 'vhdl-minibuffer-tab))
  2573. map)
  2574. "Keymap for minibuffer used in VHDL Mode.")
  2575. ;; set up electric character functions to work with
  2576. ;; `delete-selection-mode' (Emacs) and `pending-delete-mode' (XEmacs)
  2577. (mapc
  2578. (function
  2579. (lambda (sym)
  2580. (put sym 'delete-selection t) ; for `delete-selection-mode' (Emacs)
  2581. (put sym 'pending-delete t))) ; for `pending-delete-mode' (XEmacs)
  2582. '(vhdl-electric-space
  2583. vhdl-electric-tab
  2584. vhdl-electric-return
  2585. vhdl-electric-dash
  2586. vhdl-electric-open-bracket
  2587. vhdl-electric-close-bracket
  2588. vhdl-electric-quote
  2589. vhdl-electric-semicolon
  2590. vhdl-electric-comma
  2591. vhdl-electric-period
  2592. vhdl-electric-equal))
  2593. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2594. ;; Syntax table
  2595. (defvar vhdl-mode-syntax-table
  2596. (let ((st (make-syntax-table)))
  2597. ;; define punctuation
  2598. (modify-syntax-entry ?\# "." st)
  2599. (modify-syntax-entry ?\$ "." st)
  2600. (modify-syntax-entry ?\% "." st)
  2601. (modify-syntax-entry ?\& "." st)
  2602. (modify-syntax-entry ?\' "." st)
  2603. (modify-syntax-entry ?\* "." st)
  2604. (modify-syntax-entry ?\+ "." st)
  2605. (modify-syntax-entry ?\. "." st)
  2606. ;;; (modify-syntax-entry ?\/ "." st)
  2607. (modify-syntax-entry ?\: "." st)
  2608. (modify-syntax-entry ?\; "." st)
  2609. (modify-syntax-entry ?\< "." st)
  2610. (modify-syntax-entry ?\= "." st)
  2611. (modify-syntax-entry ?\> "." st)
  2612. (modify-syntax-entry ?\\ "." st)
  2613. (modify-syntax-entry ?\| "." st)
  2614. ;; define string
  2615. (modify-syntax-entry ?\" "\"" st)
  2616. ;; define underscore
  2617. (modify-syntax-entry ?\_ (if vhdl-underscore-is-part-of-word "w" "_") st)
  2618. ;; single-line comments
  2619. (modify-syntax-entry ?\- ". 12b" st)
  2620. ;; multi-line comments
  2621. (modify-syntax-entry ?\/ ". 14b" st)
  2622. (modify-syntax-entry ?* ". 23" st)
  2623. (modify-syntax-entry ?\n "> b" st)
  2624. (modify-syntax-entry ?\^M "> b" st)
  2625. ;; define parentheses to match
  2626. (modify-syntax-entry ?\( "()" st)
  2627. (modify-syntax-entry ?\) ")(" st)
  2628. (modify-syntax-entry ?\[ "(]" st)
  2629. (modify-syntax-entry ?\] ")[" st)
  2630. (modify-syntax-entry ?\{ "(}" st)
  2631. (modify-syntax-entry ?\} "){" st)
  2632. st)
  2633. "Syntax table used in `vhdl-mode' buffers.")
  2634. (defvar vhdl-mode-ext-syntax-table
  2635. ;; Extended syntax table including '_' (for simpler search regexps).
  2636. (let ((st (copy-syntax-table vhdl-mode-syntax-table)))
  2637. (modify-syntax-entry ?_ "w" st)
  2638. st)
  2639. "Syntax table extended by `_' used in `vhdl-mode' buffers.")
  2640. (defvar vhdl-syntactic-context nil
  2641. "Buffer local variable containing syntactic analysis list.")
  2642. (make-variable-buffer-local 'vhdl-syntactic-context)
  2643. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2644. ;; Abbrev hook bindings
  2645. (defvar vhdl-mode-abbrev-table nil
  2646. "Abbrev table to use in `vhdl-mode' buffers.")
  2647. (defun vhdl-mode-abbrev-table-init ()
  2648. "Initialize `vhdl-mode-abbrev-table'."
  2649. (define-abbrev-table 'vhdl-mode-abbrev-table
  2650. (append
  2651. (when (memq 'vhdl vhdl-electric-keywords)
  2652. ;; VHDL'02 keywords
  2653. (mapcar (if (featurep 'xemacs)
  2654. (lambda (x) (list (car x) "" (cdr x) 0))
  2655. (lambda (x) (list (car x) "" (cdr x) 0 'system)))
  2656. '(
  2657. ("--" . vhdl-template-display-comment-hook)
  2658. ("abs" . vhdl-template-default-hook)
  2659. ("access" . vhdl-template-default-hook)
  2660. ("after" . vhdl-template-default-hook)
  2661. ("alias" . vhdl-template-alias-hook)
  2662. ("all" . vhdl-template-default-hook)
  2663. ("and" . vhdl-template-default-hook)
  2664. ("arch" . vhdl-template-architecture-hook)
  2665. ("architecture" . vhdl-template-architecture-hook)
  2666. ("array" . vhdl-template-default-hook)
  2667. ("assert" . vhdl-template-assert-hook)
  2668. ("attr" . vhdl-template-attribute-hook)
  2669. ("attribute" . vhdl-template-attribute-hook)
  2670. ("begin" . vhdl-template-default-indent-hook)
  2671. ("block" . vhdl-template-block-hook)
  2672. ("body" . vhdl-template-default-hook)
  2673. ("buffer" . vhdl-template-default-hook)
  2674. ("bus" . vhdl-template-default-hook)
  2675. ("case" . vhdl-template-case-hook)
  2676. ("comp" . vhdl-template-component-hook)
  2677. ("component" . vhdl-template-component-hook)
  2678. ("cond" . vhdl-template-conditional-signal-asst-hook)
  2679. ("conditional" . vhdl-template-conditional-signal-asst-hook)
  2680. ("conf" . vhdl-template-configuration-hook)
  2681. ("configuration" . vhdl-template-configuration-hook)
  2682. ("cons" . vhdl-template-constant-hook)
  2683. ("constant" . vhdl-template-constant-hook)
  2684. ("context" . vhdl-template-context-hook)
  2685. ("disconnect" . vhdl-template-disconnect-hook)
  2686. ("downto" . vhdl-template-default-hook)
  2687. ("else" . vhdl-template-else-hook)
  2688. ("elseif" . vhdl-template-elsif-hook)
  2689. ("elsif" . vhdl-template-elsif-hook)
  2690. ("end" . vhdl-template-default-indent-hook)
  2691. ("entity" . vhdl-template-entity-hook)
  2692. ("exit" . vhdl-template-exit-hook)
  2693. ("file" . vhdl-template-file-hook)
  2694. ("for" . vhdl-template-for-hook)
  2695. ("func" . vhdl-template-function-hook)
  2696. ("function" . vhdl-template-function-hook)
  2697. ("generic" . vhdl-template-generic-hook)
  2698. ("group" . vhdl-template-group-hook)
  2699. ("guarded" . vhdl-template-default-hook)
  2700. ("if" . vhdl-template-if-hook)
  2701. ("impure" . vhdl-template-default-hook)
  2702. ("in" . vhdl-template-default-hook)
  2703. ("inertial" . vhdl-template-default-hook)
  2704. ("inout" . vhdl-template-default-hook)
  2705. ("inst" . vhdl-template-instance-hook)
  2706. ("instance" . vhdl-template-instance-hook)
  2707. ("is" . vhdl-template-default-hook)
  2708. ("label" . vhdl-template-default-hook)
  2709. ("library" . vhdl-template-library-hook)
  2710. ("linkage" . vhdl-template-default-hook)
  2711. ("literal" . vhdl-template-default-hook)
  2712. ("loop" . vhdl-template-bare-loop-hook)
  2713. ("map" . vhdl-template-map-hook)
  2714. ("mod" . vhdl-template-default-hook)
  2715. ("nand" . vhdl-template-default-hook)
  2716. ("new" . vhdl-template-default-hook)
  2717. ("next" . vhdl-template-next-hook)
  2718. ("nor" . vhdl-template-default-hook)
  2719. ("not" . vhdl-template-default-hook)
  2720. ("null" . vhdl-template-default-hook)
  2721. ("of" . vhdl-template-default-hook)
  2722. ("on" . vhdl-template-default-hook)
  2723. ("open" . vhdl-template-default-hook)
  2724. ("or" . vhdl-template-default-hook)
  2725. ("others" . vhdl-template-others-hook)
  2726. ("out" . vhdl-template-default-hook)
  2727. ("pack" . vhdl-template-package-hook)
  2728. ("package" . vhdl-template-package-hook)
  2729. ("port" . vhdl-template-port-hook)
  2730. ("postponed" . vhdl-template-default-hook)
  2731. ("procedure" . vhdl-template-procedure-hook)
  2732. ("process" . vhdl-template-process-hook)
  2733. ("pure" . vhdl-template-default-hook)
  2734. ("range" . vhdl-template-default-hook)
  2735. ("record" . vhdl-template-default-hook)
  2736. ("register" . vhdl-template-default-hook)
  2737. ("reject" . vhdl-template-default-hook)
  2738. ("rem" . vhdl-template-default-hook)
  2739. ("report" . vhdl-template-report-hook)
  2740. ("return" . vhdl-template-return-hook)
  2741. ("rol" . vhdl-template-default-hook)
  2742. ("ror" . vhdl-template-default-hook)
  2743. ("select" . vhdl-template-selected-signal-asst-hook)
  2744. ("severity" . vhdl-template-default-hook)
  2745. ("shared" . vhdl-template-default-hook)
  2746. ("sig" . vhdl-template-signal-hook)
  2747. ("signal" . vhdl-template-signal-hook)
  2748. ("sla" . vhdl-template-default-hook)
  2749. ("sll" . vhdl-template-default-hook)
  2750. ("sra" . vhdl-template-default-hook)
  2751. ("srl" . vhdl-template-default-hook)
  2752. ("subtype" . vhdl-template-subtype-hook)
  2753. ("then" . vhdl-template-default-hook)
  2754. ("to" . vhdl-template-default-hook)
  2755. ("transport" . vhdl-template-default-hook)
  2756. ("type" . vhdl-template-type-hook)
  2757. ("unaffected" . vhdl-template-default-hook)
  2758. ("units" . vhdl-template-default-hook)
  2759. ("until" . vhdl-template-default-hook)
  2760. ("use" . vhdl-template-use-hook)
  2761. ("var" . vhdl-template-variable-hook)
  2762. ("variable" . vhdl-template-variable-hook)
  2763. ("wait" . vhdl-template-wait-hook)
  2764. ("when" . vhdl-template-when-hook)
  2765. ("while" . vhdl-template-while-loop-hook)
  2766. ("with" . vhdl-template-with-hook)
  2767. ("xnor" . vhdl-template-default-hook)
  2768. ("xor" . vhdl-template-default-hook)
  2769. )))
  2770. ;; VHDL-AMS keywords
  2771. (when (and (memq 'vhdl vhdl-electric-keywords) (vhdl-standard-p 'ams))
  2772. (mapcar (if (featurep 'xemacs)
  2773. (lambda (x) (list (car x) "" (cdr x) 0))
  2774. (lambda (x) (list (car x) "" (cdr x) 0 'system)))
  2775. '(
  2776. ("across" . vhdl-template-default-hook)
  2777. ("break" . vhdl-template-break-hook)
  2778. ("limit" . vhdl-template-limit-hook)
  2779. ("nature" . vhdl-template-nature-hook)
  2780. ("noise" . vhdl-template-default-hook)
  2781. ("procedural" . vhdl-template-procedural-hook)
  2782. ("quantity" . vhdl-template-quantity-hook)
  2783. ("reference" . vhdl-template-default-hook)
  2784. ("spectrum" . vhdl-template-default-hook)
  2785. ("subnature" . vhdl-template-subnature-hook)
  2786. ("terminal" . vhdl-template-terminal-hook)
  2787. ("through" . vhdl-template-default-hook)
  2788. ("tolerance" . vhdl-template-default-hook)
  2789. )))
  2790. ;; user model keywords
  2791. (when (memq 'user vhdl-electric-keywords)
  2792. (let (abbrev-list keyword)
  2793. (dolist (elem vhdl-model-alist)
  2794. (setq keyword (nth 3 elem))
  2795. (unless (equal keyword "")
  2796. (push (list keyword ""
  2797. (vhdl-function-name
  2798. "vhdl-model" (nth 0 elem) "hook") 0 'system)
  2799. abbrev-list)))
  2800. abbrev-list)))))
  2801. ;; initialize abbrev table for VHDL Mode
  2802. (vhdl-mode-abbrev-table-init)
  2803. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2804. ;; Template completion lists
  2805. (defvar vhdl-template-construct-alist nil
  2806. "List of built-in construct templates.")
  2807. (defun vhdl-template-construct-alist-init ()
  2808. "Initialize `vhdl-template-construct-alist'."
  2809. (setq
  2810. vhdl-template-construct-alist
  2811. (append
  2812. '(
  2813. ("alias declaration" vhdl-template-alias)
  2814. ("architecture body" vhdl-template-architecture)
  2815. ("assertion" vhdl-template-assert)
  2816. ("attribute declaration" vhdl-template-attribute-decl)
  2817. ("attribute specification" vhdl-template-attribute-spec)
  2818. ("block configuration" vhdl-template-block-configuration)
  2819. ("block statement" vhdl-template-block)
  2820. ("case statement" vhdl-template-case-is)
  2821. ("component configuration" vhdl-template-component-conf)
  2822. ("component declaration" vhdl-template-component-decl)
  2823. ("component instantiation statement" vhdl-template-component-inst)
  2824. ("conditional signal assignment" vhdl-template-conditional-signal-asst)
  2825. ("configuration declaration" vhdl-template-configuration-decl)
  2826. ("configuration specification" vhdl-template-configuration-spec)
  2827. ("constant declaration" vhdl-template-constant)
  2828. ("context declaration" vhdl-template-context)
  2829. ("disconnection specification" vhdl-template-disconnect)
  2830. ("entity declaration" vhdl-template-entity)
  2831. ("exit statement" vhdl-template-exit)
  2832. ("file declaration" vhdl-template-file)
  2833. ("generate statement" vhdl-template-generate)
  2834. ("generic clause" vhdl-template-generic)
  2835. ("group declaration" vhdl-template-group-decl)
  2836. ("group template declaration" vhdl-template-group-template)
  2837. ("if statement" vhdl-template-if-then)
  2838. ("library clause" vhdl-template-library)
  2839. ("loop statement" vhdl-template-loop)
  2840. ("next statement" vhdl-template-next)
  2841. ("package declaration" vhdl-template-package-decl)
  2842. ("package body" vhdl-template-package-body)
  2843. ("port clause" vhdl-template-port)
  2844. ("process statement" vhdl-template-process)
  2845. ("report statement" vhdl-template-report)
  2846. ("return statement" vhdl-template-return)
  2847. ("selected signal assignment" vhdl-template-selected-signal-asst)
  2848. ("signal declaration" vhdl-template-signal)
  2849. ("subprogram declaration" vhdl-template-subprogram-decl)
  2850. ("subprogram body" vhdl-template-subprogram-body)
  2851. ("subtype declaration" vhdl-template-subtype)
  2852. ("type declaration" vhdl-template-type)
  2853. ("use clause" vhdl-template-use)
  2854. ("variable declaration" vhdl-template-variable)
  2855. ("wait statement" vhdl-template-wait)
  2856. )
  2857. (when (vhdl-standard-p 'ams)
  2858. '(
  2859. ("break statement" vhdl-template-break)
  2860. ("nature declaration" vhdl-template-nature)
  2861. ("quantity declaration" vhdl-template-quantity)
  2862. ("simultaneous case statement" vhdl-template-case-use)
  2863. ("simultaneous if statement" vhdl-template-if-use)
  2864. ("simultaneous procedural statement" vhdl-template-procedural)
  2865. ("step limit specification" vhdl-template-limit)
  2866. ("subnature declaration" vhdl-template-subnature)
  2867. ("terminal declaration" vhdl-template-terminal)
  2868. )))))
  2869. ;; initialize for VHDL Mode
  2870. (vhdl-template-construct-alist-init)
  2871. (defvar vhdl-template-package-alist nil
  2872. "List of built-in package templates.")
  2873. (defun vhdl-template-package-alist-init ()
  2874. "Initialize `vhdl-template-package-alist'."
  2875. (setq
  2876. vhdl-template-package-alist
  2877. (append
  2878. '(
  2879. ("numeric_bit" vhdl-template-package-numeric-bit)
  2880. ("numeric_std" vhdl-template-package-numeric-std)
  2881. ("std_logic_1164" vhdl-template-package-std-logic-1164)
  2882. ("std_logic_arith" vhdl-template-package-std-logic-arith)
  2883. ("std_logic_misc" vhdl-template-package-std-logic-misc)
  2884. ("std_logic_signed" vhdl-template-package-std-logic-signed)
  2885. ("std_logic_textio" vhdl-template-package-std-logic-textio)
  2886. ("std_logic_unsigned" vhdl-template-package-std-logic-unsigned)
  2887. ("textio" vhdl-template-package-textio)
  2888. )
  2889. (when (vhdl-standard-p 'math)
  2890. '(
  2891. ("math_complex" vhdl-template-package-math-complex)
  2892. ("math_real" vhdl-template-package-math-real)
  2893. )))))
  2894. ;; initialize for VHDL Mode
  2895. (vhdl-template-package-alist-init)
  2896. (defvar vhdl-template-directive-alist
  2897. '(
  2898. ("translate_on" vhdl-template-directive-translate-on)
  2899. ("translate_off" vhdl-template-directive-translate-off)
  2900. ("synthesis_on" vhdl-template-directive-synthesis-on)
  2901. ("synthesis_off" vhdl-template-directive-synthesis-off)
  2902. )
  2903. "List of built-in directive templates.")
  2904. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2905. ;;; Menus
  2906. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2907. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2908. ;; VHDL menu (using `easy-menu.el')
  2909. (defun vhdl-customize ()
  2910. "Call the customize function with `vhdl' as argument."
  2911. (interactive)
  2912. (customize-browse 'vhdl))
  2913. (defun vhdl-create-mode-menu ()
  2914. "Create VHDL Mode menu."
  2915. `("VHDL"
  2916. ,(append
  2917. '("Project"
  2918. ["None" (vhdl-set-project "")
  2919. :style radio :selected (null vhdl-project)]
  2920. "--")
  2921. ;; add menu entries for defined projects
  2922. (let ((project-alist vhdl-project-alist) menu-list name)
  2923. (while project-alist
  2924. (setq name (caar project-alist))
  2925. (setq menu-list
  2926. (cons `[,name (vhdl-set-project ,name)
  2927. :style radio :selected (equal ,name vhdl-project)]
  2928. menu-list))
  2929. (setq project-alist (cdr project-alist)))
  2930. (setq menu-list
  2931. (if vhdl-project-sort
  2932. (sort menu-list
  2933. (function (lambda (a b) (string< (elt a 0) (elt b 0)))))
  2934. (nreverse menu-list)))
  2935. (vhdl-menu-split menu-list "Project"))
  2936. '("--" "--"
  2937. ["Select Project..." vhdl-set-project t]
  2938. ["Set As Default Project" vhdl-set-default-project t]
  2939. "--"
  2940. ["Duplicate Project" vhdl-duplicate-project vhdl-project]
  2941. ["Import Project..." vhdl-import-project
  2942. :keys "C-c C-p C-m" :active t]
  2943. ["Export Project" vhdl-export-project vhdl-project]
  2944. "--"
  2945. ["Customize Project..." (customize-option 'vhdl-project-alist) t]))
  2946. "--"
  2947. ("Compile"
  2948. ["Compile Buffer" vhdl-compile t]
  2949. ["Stop Compilation" kill-compilation t]
  2950. "--"
  2951. ["Make" vhdl-make t]
  2952. ["Generate Makefile" vhdl-generate-makefile t]
  2953. "--"
  2954. ["Next Error" next-error t]
  2955. ["Previous Error" previous-error t]
  2956. ["First Error" first-error t]
  2957. "--"
  2958. ,(append
  2959. '("Compiler")
  2960. ;; add menu entries for defined compilers
  2961. (let ((comp-alist vhdl-compiler-alist) menu-list name)
  2962. (while comp-alist
  2963. (setq name (caar comp-alist))
  2964. (setq menu-list
  2965. (cons `[,name (setq vhdl-compiler ,name)
  2966. :style radio :selected (equal ,name vhdl-compiler)]
  2967. menu-list))
  2968. (setq comp-alist (cdr comp-alist)))
  2969. (setq menu-list (nreverse menu-list))
  2970. (vhdl-menu-split menu-list "Compiler"))
  2971. '("--" "--"
  2972. ["Select Compiler..." vhdl-set-compiler t]
  2973. "--"
  2974. ["Customize Compiler..."
  2975. (customize-option 'vhdl-compiler-alist) t])))
  2976. "--"
  2977. ,(append
  2978. '("Template"
  2979. ("VHDL Construct 1"
  2980. ["Alias" vhdl-template-alias t]
  2981. ["Architecture" vhdl-template-architecture t]
  2982. ["Assert" vhdl-template-assert t]
  2983. ["Attribute (Decl)" vhdl-template-attribute-decl t]
  2984. ["Attribute (Spec)" vhdl-template-attribute-spec t]
  2985. ["Block" vhdl-template-block t]
  2986. ["Case" vhdl-template-case-is t]
  2987. ["Component (Decl)" vhdl-template-component-decl t]
  2988. ["(Component) Instance" vhdl-template-component-inst t]
  2989. ["Conditional (Signal Asst)" vhdl-template-conditional-signal-asst t]
  2990. ["Configuration (Block)" vhdl-template-block-configuration t]
  2991. ["Configuration (Comp)" vhdl-template-component-conf t]
  2992. ["Configuration (Decl)" vhdl-template-configuration-decl t]
  2993. ["Configuration (Spec)" vhdl-template-configuration-spec t]
  2994. ["Constant" vhdl-template-constant t]
  2995. ["Context" vhdl-template-context t]
  2996. ["Disconnect" vhdl-template-disconnect t]
  2997. ["Else" vhdl-template-else t]
  2998. ["Elsif" vhdl-template-elsif t]
  2999. ["Entity" vhdl-template-entity t]
  3000. ["Exit" vhdl-template-exit t]
  3001. ["File" vhdl-template-file t]
  3002. ["For (Generate)" vhdl-template-for-generate t]
  3003. ["For (Loop)" vhdl-template-for-loop t]
  3004. ["Function (Body)" vhdl-template-function-body t]
  3005. ["Function (Decl)" vhdl-template-function-decl t]
  3006. ["Generic" vhdl-template-generic t]
  3007. ["Group (Decl)" vhdl-template-group-decl t]
  3008. ["Group (Template)" vhdl-template-group-template t])
  3009. ("VHDL Construct 2"
  3010. ["If (Generate)" vhdl-template-if-generate t]
  3011. ["If (Then)" vhdl-template-if-then t]
  3012. ["Library" vhdl-template-library t]
  3013. ["Loop" vhdl-template-bare-loop t]
  3014. ["Map" vhdl-template-map t]
  3015. ["Next" vhdl-template-next t]
  3016. ["Others (Aggregate)" vhdl-template-others t]
  3017. ["Package (Decl)" vhdl-template-package-decl t]
  3018. ["Package (Body)" vhdl-template-package-body t]
  3019. ["Port" vhdl-template-port t]
  3020. ["Procedure (Body)" vhdl-template-procedure-body t]
  3021. ["Procedure (Decl)" vhdl-template-procedure-decl t]
  3022. ["Process (Comb)" vhdl-template-process-comb t]
  3023. ["Process (Seq)" vhdl-template-process-seq t]
  3024. ["Report" vhdl-template-report t]
  3025. ["Return" vhdl-template-return t]
  3026. ["Select" vhdl-template-selected-signal-asst t]
  3027. ["Signal" vhdl-template-signal t]
  3028. ["Subtype" vhdl-template-subtype t]
  3029. ["Type" vhdl-template-type t]
  3030. ["Use" vhdl-template-use t]
  3031. ["Variable" vhdl-template-variable t]
  3032. ["Wait" vhdl-template-wait t]
  3033. ["(Clocked Wait)" vhdl-template-clocked-wait t]
  3034. ["When" vhdl-template-when t]
  3035. ["While (Loop)" vhdl-template-while-loop t]
  3036. ["With" vhdl-template-with t]))
  3037. (when (vhdl-standard-p 'ams)
  3038. '(("VHDL-AMS Construct"
  3039. ["Break" vhdl-template-break t]
  3040. ["Case (Use)" vhdl-template-case-use t]
  3041. ["If (Use)" vhdl-template-if-use t]
  3042. ["Limit" vhdl-template-limit t]
  3043. ["Nature" vhdl-template-nature t]
  3044. ["Procedural" vhdl-template-procedural t]
  3045. ["Quantity (Free)" vhdl-template-quantity-free t]
  3046. ["Quantity (Branch)" vhdl-template-quantity-branch t]
  3047. ["Quantity (Source)" vhdl-template-quantity-source t]
  3048. ["Subnature" vhdl-template-subnature t]
  3049. ["Terminal" vhdl-template-terminal t])))
  3050. '(["Insert Construct..." vhdl-template-insert-construct
  3051. :keys "C-c C-i C-t"]
  3052. "--")
  3053. (list
  3054. (append
  3055. '("Package")
  3056. '(["numeric_bit" vhdl-template-package-numeric-bit t]
  3057. ["numeric_std" vhdl-template-package-numeric-std t]
  3058. ["std_logic_1164" vhdl-template-package-std-logic-1164 t]
  3059. ["textio" vhdl-template-package-textio t]
  3060. "--"
  3061. ["std_logic_arith" vhdl-template-package-std-logic-arith t]
  3062. ["std_logic_signed" vhdl-template-package-std-logic-signed t]
  3063. ["std_logic_unsigned" vhdl-template-package-std-logic-unsigned t]
  3064. ["std_logic_misc" vhdl-template-package-std-logic-misc t]
  3065. ["std_logic_textio" vhdl-template-package-std-logic-textio t]
  3066. "--")
  3067. (when (vhdl-standard-p 'ams)
  3068. '(["fundamental_constants" vhdl-template-package-fundamental-constants t]
  3069. ["material_constants" vhdl-template-package-material-constants t]
  3070. ["energy_systems" vhdl-template-package-energy-systems t]
  3071. ["electrical_systems" vhdl-template-package-electrical-systems t]
  3072. ["mechanical_systems" vhdl-template-package-mechanical-systems t]
  3073. ["radiant_systems" vhdl-template-package-radiant-systems t]
  3074. ["thermal_systems" vhdl-template-package-thermal-systems t]
  3075. ["fluidic_systems" vhdl-template-package-fluidic-systems t]
  3076. "--"))
  3077. (when (vhdl-standard-p 'math)
  3078. '(["math_complex" vhdl-template-package-math-complex t]
  3079. ["math_real" vhdl-template-package-math-real t]
  3080. "--"))
  3081. '(["Insert Package..." vhdl-template-insert-package
  3082. :keys "C-c C-i C-p"])))
  3083. '(("Directive"
  3084. ["translate_on" vhdl-template-directive-translate-on t]
  3085. ["translate_off" vhdl-template-directive-translate-off t]
  3086. ["synthesis_on" vhdl-template-directive-synthesis-on t]
  3087. ["synthesis_off" vhdl-template-directive-synthesis-off t]
  3088. "--"
  3089. ["Insert Directive..." vhdl-template-insert-directive
  3090. :keys "C-c C-i C-d"])
  3091. "--"
  3092. ["Insert Header" vhdl-template-header :keys "C-c C-t C-h"]
  3093. ["Insert Footer" vhdl-template-footer t]
  3094. ["Insert Date" vhdl-template-insert-date t]
  3095. ["Modify Date" vhdl-template-modify :keys "C-c C-t C-m"]
  3096. "--"
  3097. ["Query Next Prompt" vhdl-template-search-prompt t]))
  3098. ,(append
  3099. '("Model")
  3100. ;; add menu entries for defined models
  3101. (let ((model-alist vhdl-model-alist) menu-list model)
  3102. (while model-alist
  3103. (setq model (car model-alist))
  3104. (setq menu-list
  3105. (cons
  3106. (vector
  3107. (nth 0 model)
  3108. (vhdl-function-name "vhdl-model" (nth 0 model))
  3109. :keys (concat "C-c C-m " (key-description (nth 2 model))))
  3110. menu-list))
  3111. (setq model-alist (cdr model-alist)))
  3112. (setq menu-list (nreverse menu-list))
  3113. (vhdl-menu-split menu-list "Model"))
  3114. '("--" "--"
  3115. ["Insert Model..." vhdl-model-insert :keys "C-c C-i C-m"]
  3116. ["Customize Model..." (customize-option 'vhdl-model-alist) t]))
  3117. ("Port"
  3118. ["Copy" vhdl-port-copy t]
  3119. "--"
  3120. ["Paste As Entity" vhdl-port-paste-entity vhdl-port-list]
  3121. ["Paste As Component" vhdl-port-paste-component vhdl-port-list]
  3122. ["Paste As Instance" vhdl-port-paste-instance
  3123. :keys "C-c C-p C-i" :active vhdl-port-list]
  3124. ["Paste As Signals" vhdl-port-paste-signals vhdl-port-list]
  3125. ["Paste As Constants" vhdl-port-paste-constants vhdl-port-list]
  3126. ["Paste As Generic Map" vhdl-port-paste-generic-map vhdl-port-list]
  3127. ["Paste As Initializations" vhdl-port-paste-initializations vhdl-port-list]
  3128. "--"
  3129. ["Paste As Testbench" vhdl-port-paste-testbench vhdl-port-list]
  3130. "--"
  3131. ["Flatten" vhdl-port-flatten
  3132. :style toggle :selected vhdl-port-flattened :active vhdl-port-list]
  3133. ["Reverse Direction" vhdl-port-reverse-direction
  3134. :style toggle :selected vhdl-port-reversed-direction :active vhdl-port-list])
  3135. ("Compose"
  3136. ["New Component" vhdl-compose-new-component t]
  3137. ["Copy Component" vhdl-port-copy t]
  3138. ["Place Component" vhdl-compose-place-component vhdl-port-list]
  3139. ["Wire Components" vhdl-compose-wire-components t]
  3140. "--"
  3141. ["Generate Configuration" vhdl-compose-configuration t]
  3142. ["Generate Components Package" vhdl-compose-components-package t])
  3143. ("Subprogram"
  3144. ["Copy" vhdl-subprog-copy t]
  3145. "--"
  3146. ["Paste As Declaration" vhdl-subprog-paste-declaration vhdl-subprog-list]
  3147. ["Paste As Body" vhdl-subprog-paste-body vhdl-subprog-list]
  3148. ["Paste As Call" vhdl-subprog-paste-call vhdl-subprog-list]
  3149. "--"
  3150. ["Flatten" vhdl-subprog-flatten
  3151. :style toggle :selected vhdl-subprog-flattened :active vhdl-subprog-list])
  3152. "--"
  3153. ("Comment"
  3154. ["(Un)Comment Out Region" vhdl-comment-uncomment-region (mark)]
  3155. "--"
  3156. ["Insert Inline Comment" vhdl-comment-append-inline t]
  3157. ["Insert Horizontal Line" vhdl-comment-display-line t]
  3158. ["Insert Display Comment" vhdl-comment-display t]
  3159. "--"
  3160. ["Fill Comment" fill-paragraph t]
  3161. ["Fill Comment Region" fill-region (mark)]
  3162. ["Kill Comment Region" vhdl-comment-kill-region (mark)]
  3163. ["Kill Inline Comment Region" vhdl-comment-kill-inline-region (mark)])
  3164. ("Line"
  3165. ["Kill" vhdl-line-kill t]
  3166. ["Copy" vhdl-line-copy t]
  3167. ["Yank" vhdl-line-yank t]
  3168. ["Expand" vhdl-line-expand t]
  3169. "--"
  3170. ["Transpose Next" vhdl-line-transpose-next t]
  3171. ["Transpose Prev" vhdl-line-transpose-previous t]
  3172. ["Open" vhdl-line-open t]
  3173. ["Join" vhdl-delete-indentation t]
  3174. "--"
  3175. ["Goto" goto-line t]
  3176. ["(Un)Comment Out" vhdl-comment-uncomment-line t])
  3177. ("Move"
  3178. ["Forward Statement" vhdl-end-of-statement t]
  3179. ["Backward Statement" vhdl-beginning-of-statement t]
  3180. ["Forward Expression" vhdl-forward-sexp t]
  3181. ["Backward Expression" vhdl-backward-sexp t]
  3182. ["Forward Same Indent" vhdl-forward-same-indent t]
  3183. ["Backward Same Indent" vhdl-backward-same-indent t]
  3184. ["Forward Function" vhdl-end-of-defun t]
  3185. ["Backward Function" vhdl-beginning-of-defun t]
  3186. ["Mark Function" vhdl-mark-defun t])
  3187. "--"
  3188. ("Indent"
  3189. ["Line" indent-according-to-mode :keys "C-c C-i C-l"]
  3190. ["Group" vhdl-indent-group :keys "C-c C-i C-g"]
  3191. ["Region" vhdl-indent-region (mark)]
  3192. ["Buffer" vhdl-indent-buffer :keys "C-c C-i C-b"])
  3193. ("Align"
  3194. ["Group" vhdl-align-group t]
  3195. ["Same Indent" vhdl-align-same-indent :keys "C-c C-a C-i"]
  3196. ["List" vhdl-align-list t]
  3197. ["Declarations" vhdl-align-declarations t]
  3198. ["Region" vhdl-align-region (mark)]
  3199. ["Buffer" vhdl-align-buffer t]
  3200. "--"
  3201. ["Inline Comment Group" vhdl-align-inline-comment-group t]
  3202. ["Inline Comment Region" vhdl-align-inline-comment-region (mark)]
  3203. ["Inline Comment Buffer" vhdl-align-inline-comment-buffer t])
  3204. ("Fill"
  3205. ["List" vhdl-fill-list t]
  3206. ["Group" vhdl-fill-group t]
  3207. ["Same Indent" vhdl-fill-same-indent :keys "C-c C-f C-i"]
  3208. ["Region" vhdl-fill-region (mark)])
  3209. ("Beautify"
  3210. ["Region" vhdl-beautify-region (mark)]
  3211. ["Buffer" vhdl-beautify-buffer t])
  3212. ("Fix"
  3213. ["Generic/Port Clause" vhdl-fix-clause t]
  3214. ["Generic/Port Clause Buffer" vhdl-fix-clause t]
  3215. "--"
  3216. ["Case Region" vhdl-fix-case-region (mark)]
  3217. ["Case Buffer" vhdl-fix-case-buffer t]
  3218. "--"
  3219. ["Whitespace Region" vhdl-fixup-whitespace-region (mark)]
  3220. ["Whitespace Buffer" vhdl-fixup-whitespace-buffer t]
  3221. "--"
  3222. ["Statement Region" vhdl-fix-statement-region (mark)]
  3223. ["Statement Buffer" vhdl-fix-statement-buffer t]
  3224. "--"
  3225. ["Trailing Spaces Buffer" vhdl-remove-trailing-spaces t])
  3226. ("Update"
  3227. ["Sensitivity List" vhdl-update-sensitivity-list-process t]
  3228. ["Sensitivity List Buffer" vhdl-update-sensitivity-list-buffer t])
  3229. "--"
  3230. ["Fontify Buffer" vhdl-fontify-buffer t]
  3231. ["Statistics Buffer" vhdl-statistics-buffer t]
  3232. ["Show Messages" vhdl-show-messages t]
  3233. ["Syntactic Info" vhdl-show-syntactic-information t]
  3234. "--"
  3235. ["Speedbar" vhdl-speedbar t]
  3236. ["Hide/Show" vhdl-hs-minor-mode t]
  3237. "--"
  3238. ("Documentation"
  3239. ["VHDL Mode" vhdl-doc-mode :keys "C-c C-h"]
  3240. ["Release Notes" (vhdl-doc-variable 'vhdl-doc-release-notes) t]
  3241. ["Reserved Words" (vhdl-doc-variable 'vhdl-doc-keywords) t]
  3242. ["Coding Style" (vhdl-doc-variable 'vhdl-doc-coding-style) t])
  3243. ["Version" vhdl-version t]
  3244. ["Bug Report..." vhdl-submit-bug-report t]
  3245. "--"
  3246. ("Options"
  3247. ("Mode"
  3248. ["Electric Mode"
  3249. (progn (customize-set-variable 'vhdl-electric-mode
  3250. (not vhdl-electric-mode))
  3251. (vhdl-mode-line-update))
  3252. :style toggle :selected vhdl-electric-mode :keys "C-c C-m C-e"]
  3253. ["Stutter Mode"
  3254. (progn (customize-set-variable 'vhdl-stutter-mode
  3255. (not vhdl-stutter-mode))
  3256. (vhdl-mode-line-update))
  3257. :style toggle :selected vhdl-stutter-mode :keys "C-c C-m C-s"]
  3258. ["Indent Tabs Mode"
  3259. (progn (customize-set-variable 'vhdl-indent-tabs-mode
  3260. (not vhdl-indent-tabs-mode))
  3261. (setq indent-tabs-mode vhdl-indent-tabs-mode))
  3262. :style toggle :selected vhdl-indent-tabs-mode]
  3263. "--"
  3264. ["Customize Group..." (customize-group 'vhdl-mode) t])
  3265. ("Project"
  3266. ["Project Setup..." (customize-option 'vhdl-project-alist) t]
  3267. ,(append
  3268. '("Selected Project at Startup"
  3269. ["None" (progn (customize-set-variable 'vhdl-project nil)
  3270. (vhdl-set-project ""))
  3271. :style radio :selected (null vhdl-project)]
  3272. "--")
  3273. ;; add menu entries for defined projects
  3274. (let ((project-alist vhdl-project-alist) menu-list name)
  3275. (while project-alist
  3276. (setq name (caar project-alist))
  3277. (setq menu-list
  3278. (cons `[,name (progn (customize-set-variable
  3279. 'vhdl-project ,name)
  3280. (vhdl-set-project ,name))
  3281. :style radio :selected (equal ,name vhdl-project)]
  3282. menu-list))
  3283. (setq project-alist (cdr project-alist)))
  3284. (setq menu-list (nreverse menu-list))
  3285. (vhdl-menu-split menu-list "Project")))
  3286. ["Setup File Name..." (customize-option 'vhdl-project-file-name) t]
  3287. ("Auto Load Setup File"
  3288. ["At Startup"
  3289. (customize-set-variable 'vhdl-project-auto-load
  3290. (if (memq 'startup vhdl-project-auto-load)
  3291. (delq 'startup vhdl-project-auto-load)
  3292. (cons 'startup vhdl-project-auto-load)))
  3293. :style toggle :selected (memq 'startup vhdl-project-auto-load)])
  3294. ["Sort Projects"
  3295. (customize-set-variable 'vhdl-project-sort (not vhdl-project-sort))
  3296. :style toggle :selected vhdl-project-sort]
  3297. "--"
  3298. ["Customize Group..." (customize-group 'vhdl-project) t])
  3299. ("Compiler"
  3300. ["Compiler Setup..." (customize-option 'vhdl-compiler-alist) t]
  3301. ,(append
  3302. '("Selected Compiler at Startup")
  3303. ;; add menu entries for defined compilers
  3304. (let ((comp-alist vhdl-compiler-alist) menu-list name)
  3305. (while comp-alist
  3306. (setq name (caar comp-alist))
  3307. (setq menu-list
  3308. (cons `[,name (customize-set-variable 'vhdl-compiler ,name)
  3309. :style radio :selected (equal ,name vhdl-compiler)]
  3310. menu-list))
  3311. (setq comp-alist (cdr comp-alist)))
  3312. (setq menu-list (nreverse menu-list))
  3313. (vhdl-menu-split menu-list "Compiler")))
  3314. ["Use Local Error Regexp"
  3315. (customize-set-variable 'vhdl-compile-use-local-error-regexp
  3316. (not vhdl-compile-use-local-error-regexp))
  3317. :style toggle :selected vhdl-compile-use-local-error-regexp]
  3318. ["Makefile Default Targets..."
  3319. (customize-option 'vhdl-makefile-default-targets) t]
  3320. ["Makefile Generation Hook..."
  3321. (customize-option 'vhdl-makefile-generation-hook) t]
  3322. ["Default Library Name" (customize-option 'vhdl-default-library) t]
  3323. "--"
  3324. ["Customize Group..." (customize-group 'vhdl-compiler) t])
  3325. ("Style"
  3326. ("VHDL Standard"
  3327. ["VHDL'87"
  3328. (progn (customize-set-variable 'vhdl-standard
  3329. (list '87 (cadr vhdl-standard)))
  3330. (vhdl-activate-customizations))
  3331. :style radio :selected (eq '87 (car vhdl-standard))]
  3332. ["VHDL'93/02"
  3333. (progn (customize-set-variable 'vhdl-standard
  3334. (list '93 (cadr vhdl-standard)))
  3335. (vhdl-activate-customizations))
  3336. :style radio :selected (eq '93 (car vhdl-standard))]
  3337. ["VHDL'08"
  3338. (progn (customize-set-variable 'vhdl-standard
  3339. (list '08 (cadr vhdl-standard)))
  3340. (vhdl-activate-customizations))
  3341. :style radio :selected (eq '08 (car vhdl-standard))]
  3342. "--"
  3343. ["VHDL-AMS"
  3344. (progn (customize-set-variable
  3345. 'vhdl-standard (list (car vhdl-standard)
  3346. (if (memq 'ams (cadr vhdl-standard))
  3347. (delq 'ams (cadr vhdl-standard))
  3348. (cons 'ams (cadr vhdl-standard)))))
  3349. (vhdl-activate-customizations))
  3350. :style toggle :selected (memq 'ams (cadr vhdl-standard))]
  3351. ["Math Packages"
  3352. (progn (customize-set-variable
  3353. 'vhdl-standard (list (car vhdl-standard)
  3354. (if (memq 'math (cadr vhdl-standard))
  3355. (delq 'math (cadr vhdl-standard))
  3356. (cons 'math (cadr vhdl-standard)))))
  3357. (vhdl-activate-customizations))
  3358. :style toggle :selected (memq 'math (cadr vhdl-standard))])
  3359. ["Indentation Offset..." (customize-option 'vhdl-basic-offset) t]
  3360. ["Upper Case Keywords"
  3361. (customize-set-variable 'vhdl-upper-case-keywords
  3362. (not vhdl-upper-case-keywords))
  3363. :style toggle :selected vhdl-upper-case-keywords]
  3364. ["Upper Case Types"
  3365. (customize-set-variable 'vhdl-upper-case-types
  3366. (not vhdl-upper-case-types))
  3367. :style toggle :selected vhdl-upper-case-types]
  3368. ["Upper Case Attributes"
  3369. (customize-set-variable 'vhdl-upper-case-attributes
  3370. (not vhdl-upper-case-attributes))
  3371. :style toggle :selected vhdl-upper-case-attributes]
  3372. ["Upper Case Enumeration Values"
  3373. (customize-set-variable 'vhdl-upper-case-enum-values
  3374. (not vhdl-upper-case-enum-values))
  3375. :style toggle :selected vhdl-upper-case-enum-values]
  3376. ["Upper Case Constants"
  3377. (customize-set-variable 'vhdl-upper-case-constants
  3378. (not vhdl-upper-case-constants))
  3379. :style toggle :selected vhdl-upper-case-constants]
  3380. ("Use Direct Instantiation"
  3381. ["Never"
  3382. (customize-set-variable 'vhdl-use-direct-instantiation 'never)
  3383. :style radio :selected (eq 'never vhdl-use-direct-instantiation)]
  3384. ["Standard"
  3385. (customize-set-variable 'vhdl-use-direct-instantiation 'standard)
  3386. :style radio :selected (eq 'standard vhdl-use-direct-instantiation)]
  3387. ["Always"
  3388. (customize-set-variable 'vhdl-use-direct-instantiation 'always)
  3389. :style radio :selected (eq 'always vhdl-use-direct-instantiation)])
  3390. ["Include Array Index and Record Field in Sensitivity List"
  3391. (customize-set-variable 'vhdl-array-index-record-field-in-sensitivity-list
  3392. (not vhdl-array-index-record-field-in-sensitivity-list))
  3393. :style toggle :selected vhdl-array-index-record-field-in-sensitivity-list]
  3394. "--"
  3395. ["Customize Group..." (customize-group 'vhdl-style) t])
  3396. ("Naming"
  3397. ["Entity File Name..." (customize-option 'vhdl-entity-file-name) t]
  3398. ["Architecture File Name..."
  3399. (customize-option 'vhdl-architecture-file-name) t]
  3400. ["Configuration File Name..."
  3401. (customize-option 'vhdl-configuration-file-name) t]
  3402. ["Package File Name..." (customize-option 'vhdl-package-file-name) t]
  3403. ("File Name Case"
  3404. ["As Is"
  3405. (customize-set-variable 'vhdl-file-name-case 'identity)
  3406. :style radio :selected (eq 'identity vhdl-file-name-case)]
  3407. ["Lower Case"
  3408. (customize-set-variable 'vhdl-file-name-case 'downcase)
  3409. :style radio :selected (eq 'downcase vhdl-file-name-case)]
  3410. ["Upper Case"
  3411. (customize-set-variable 'vhdl-file-name-case 'upcase)
  3412. :style radio :selected (eq 'upcase vhdl-file-name-case)]
  3413. ["Capitalize"
  3414. (customize-set-variable 'vhdl-file-name-case 'capitalize)
  3415. :style radio :selected (eq 'capitalize vhdl-file-name-case)])
  3416. "--"
  3417. ["Customize Group..." (customize-group 'vhdl-naming) t])
  3418. ("Template"
  3419. ("Electric Keywords"
  3420. ["VHDL Keywords"
  3421. (customize-set-variable 'vhdl-electric-keywords
  3422. (if (memq 'vhdl vhdl-electric-keywords)
  3423. (delq 'vhdl vhdl-electric-keywords)
  3424. (cons 'vhdl vhdl-electric-keywords)))
  3425. :style toggle :selected (memq 'vhdl vhdl-electric-keywords)]
  3426. ["User Model Keywords"
  3427. (customize-set-variable 'vhdl-electric-keywords
  3428. (if (memq 'user vhdl-electric-keywords)
  3429. (delq 'user vhdl-electric-keywords)
  3430. (cons 'user vhdl-electric-keywords)))
  3431. :style toggle :selected (memq 'user vhdl-electric-keywords)])
  3432. ("Insert Optional Labels"
  3433. ["None"
  3434. (customize-set-variable 'vhdl-optional-labels 'none)
  3435. :style radio :selected (eq 'none vhdl-optional-labels)]
  3436. ["Processes Only"
  3437. (customize-set-variable 'vhdl-optional-labels 'process)
  3438. :style radio :selected (eq 'process vhdl-optional-labels)]
  3439. ["All Constructs"
  3440. (customize-set-variable 'vhdl-optional-labels 'all)
  3441. :style radio :selected (eq 'all vhdl-optional-labels)])
  3442. ("Insert Empty Lines"
  3443. ["None"
  3444. (customize-set-variable 'vhdl-insert-empty-lines 'none)
  3445. :style radio :selected (eq 'none vhdl-insert-empty-lines)]
  3446. ["Design Units Only"
  3447. (customize-set-variable 'vhdl-insert-empty-lines 'unit)
  3448. :style radio :selected (eq 'unit vhdl-insert-empty-lines)]
  3449. ["All Constructs"
  3450. (customize-set-variable 'vhdl-insert-empty-lines 'all)
  3451. :style radio :selected (eq 'all vhdl-insert-empty-lines)])
  3452. ["Argument List Indent"
  3453. (customize-set-variable 'vhdl-argument-list-indent
  3454. (not vhdl-argument-list-indent))
  3455. :style toggle :selected vhdl-argument-list-indent]
  3456. ["Association List with Formals"
  3457. (customize-set-variable 'vhdl-association-list-with-formals
  3458. (not vhdl-association-list-with-formals))
  3459. :style toggle :selected vhdl-association-list-with-formals]
  3460. ["Conditions in Parenthesis"
  3461. (customize-set-variable 'vhdl-conditions-in-parenthesis
  3462. (not vhdl-conditions-in-parenthesis))
  3463. :style toggle :selected vhdl-conditions-in-parenthesis]
  3464. ["Sensitivity List uses 'all'"
  3465. (customize-set-variable 'vhdl-sensitivity-list-all
  3466. (not vhdl-sensitivity-list-all))
  3467. :style toggle :selected vhdl-sensitivity-list-all]
  3468. ["Zero String..." (customize-option 'vhdl-zero-string) t]
  3469. ["One String..." (customize-option 'vhdl-one-string) t]
  3470. ("File Header"
  3471. ["Header String..." (customize-option 'vhdl-file-header) t]
  3472. ["Footer String..." (customize-option 'vhdl-file-footer) t]
  3473. ["Company Name..." (customize-option 'vhdl-company-name) t]
  3474. ["Copyright String..." (customize-option 'vhdl-copyright-string) t]
  3475. ["Platform Specification..." (customize-option 'vhdl-platform-spec) t]
  3476. ["Date Format..." (customize-option 'vhdl-date-format) t]
  3477. ["Modify Date Prefix String..."
  3478. (customize-option 'vhdl-modify-date-prefix-string) t]
  3479. ["Modify Date on Saving"
  3480. (progn (customize-set-variable 'vhdl-modify-date-on-saving
  3481. (not vhdl-modify-date-on-saving))
  3482. (vhdl-activate-customizations))
  3483. :style toggle :selected vhdl-modify-date-on-saving])
  3484. ("Sequential Process"
  3485. ("Kind of Reset"
  3486. ["None"
  3487. (customize-set-variable 'vhdl-reset-kind 'none)
  3488. :style radio :selected (eq 'none vhdl-reset-kind)]
  3489. ["Synchronous"
  3490. (customize-set-variable 'vhdl-reset-kind 'sync)
  3491. :style radio :selected (eq 'sync vhdl-reset-kind)]
  3492. ["Asynchronous"
  3493. (customize-set-variable 'vhdl-reset-kind 'async)
  3494. :style radio :selected (eq 'async vhdl-reset-kind)]
  3495. ["Query"
  3496. (customize-set-variable 'vhdl-reset-kind 'query)
  3497. :style radio :selected (eq 'query vhdl-reset-kind)])
  3498. ["Reset is Active High"
  3499. (customize-set-variable 'vhdl-reset-active-high
  3500. (not vhdl-reset-active-high))
  3501. :style toggle :selected vhdl-reset-active-high]
  3502. ["Use Rising Clock Edge"
  3503. (customize-set-variable 'vhdl-clock-rising-edge
  3504. (not vhdl-clock-rising-edge))
  3505. :style toggle :selected vhdl-clock-rising-edge]
  3506. ("Clock Edge Condition"
  3507. ["Standard"
  3508. (customize-set-variable 'vhdl-clock-edge-condition 'standard)
  3509. :style radio :selected (eq 'standard vhdl-clock-edge-condition)]
  3510. ["Function \"rising_edge\""
  3511. (customize-set-variable 'vhdl-clock-edge-condition 'function)
  3512. :style radio :selected (eq 'function vhdl-clock-edge-condition)])
  3513. ["Clock Name..." (customize-option 'vhdl-clock-name) t]
  3514. ["Reset Name..." (customize-option 'vhdl-reset-name) t])
  3515. "--"
  3516. ["Customize Group..." (customize-group 'vhdl-template) t])
  3517. ("Model"
  3518. ["Model Definition..." (customize-option 'vhdl-model-alist) t])
  3519. ("Port"
  3520. ["Include Port Comments"
  3521. (customize-set-variable 'vhdl-include-port-comments
  3522. (not vhdl-include-port-comments))
  3523. :style toggle :selected vhdl-include-port-comments]
  3524. ["Include Direction Comments"
  3525. (customize-set-variable 'vhdl-include-direction-comments
  3526. (not vhdl-include-direction-comments))
  3527. :style toggle :selected vhdl-include-direction-comments]
  3528. ["Include Type Comments"
  3529. (customize-set-variable 'vhdl-include-type-comments
  3530. (not vhdl-include-type-comments))
  3531. :style toggle :selected vhdl-include-type-comments]
  3532. ("Include Group Comments"
  3533. ["Never"
  3534. (customize-set-variable 'vhdl-include-group-comments 'never)
  3535. :style radio :selected (eq 'never vhdl-include-group-comments)]
  3536. ["Declarations"
  3537. (customize-set-variable 'vhdl-include-group-comments 'decl)
  3538. :style radio :selected (eq 'decl vhdl-include-group-comments)]
  3539. ["Always"
  3540. (customize-set-variable 'vhdl-include-group-comments 'always)
  3541. :style radio :selected (eq 'always vhdl-include-group-comments)])
  3542. ["Actual Generic Name..." (customize-option 'vhdl-actual-generic-name) t]
  3543. ["Actual Port Name..." (customize-option 'vhdl-actual-port-name) t]
  3544. ["Instance Name..." (customize-option 'vhdl-instance-name) t]
  3545. ("Testbench"
  3546. ["Entity Name..." (customize-option 'vhdl-testbench-entity-name) t]
  3547. ["Architecture Name..."
  3548. (customize-option 'vhdl-testbench-architecture-name) t]
  3549. ["Configuration Name..."
  3550. (customize-option 'vhdl-testbench-configuration-name) t]
  3551. ["DUT Name..." (customize-option 'vhdl-testbench-dut-name) t]
  3552. ["Include Header"
  3553. (customize-set-variable 'vhdl-testbench-include-header
  3554. (not vhdl-testbench-include-header))
  3555. :style toggle :selected vhdl-testbench-include-header]
  3556. ["Declarations..." (customize-option 'vhdl-testbench-declarations) t]
  3557. ["Statements..." (customize-option 'vhdl-testbench-statements) t]
  3558. ["Initialize Signals"
  3559. (customize-set-variable 'vhdl-testbench-initialize-signals
  3560. (not vhdl-testbench-initialize-signals))
  3561. :style toggle :selected vhdl-testbench-initialize-signals]
  3562. ["Include Library Clause"
  3563. (customize-set-variable 'vhdl-testbench-include-library
  3564. (not vhdl-testbench-include-library))
  3565. :style toggle :selected vhdl-testbench-include-library]
  3566. ["Include Configuration"
  3567. (customize-set-variable 'vhdl-testbench-include-configuration
  3568. (not vhdl-testbench-include-configuration))
  3569. :style toggle :selected vhdl-testbench-include-configuration]
  3570. ("Create Files"
  3571. ["None"
  3572. (customize-set-variable 'vhdl-testbench-create-files 'none)
  3573. :style radio :selected (eq 'none vhdl-testbench-create-files)]
  3574. ["Single"
  3575. (customize-set-variable 'vhdl-testbench-create-files 'single)
  3576. :style radio :selected (eq 'single vhdl-testbench-create-files)]
  3577. ["Separate"
  3578. (customize-set-variable 'vhdl-testbench-create-files 'separate)
  3579. :style radio :selected (eq 'separate vhdl-testbench-create-files)])
  3580. ["Testbench Entity File Name..."
  3581. (customize-option 'vhdl-testbench-entity-file-name) t]
  3582. ["Testbench Architecture File Name..."
  3583. (customize-option 'vhdl-testbench-architecture-file-name) t])
  3584. "--"
  3585. ["Customize Group..." (customize-group 'vhdl-port) t])
  3586. ("Compose"
  3587. ["Architecture Name..."
  3588. (customize-option 'vhdl-compose-architecture-name) t]
  3589. ["Configuration Name..."
  3590. (customize-option 'vhdl-compose-configuration-name) t]
  3591. ["Components Package Name..."
  3592. (customize-option 'vhdl-components-package-name) t]
  3593. ["Use Components Package"
  3594. (customize-set-variable 'vhdl-use-components-package
  3595. (not vhdl-use-components-package))
  3596. :style toggle :selected vhdl-use-components-package]
  3597. ["Include Header"
  3598. (customize-set-variable 'vhdl-compose-include-header
  3599. (not vhdl-compose-include-header))
  3600. :style toggle :selected vhdl-compose-include-header]
  3601. ("Create Entity/Architecture Files"
  3602. ["None"
  3603. (customize-set-variable 'vhdl-compose-create-files 'none)
  3604. :style radio :selected (eq 'none vhdl-compose-create-files)]
  3605. ["Single"
  3606. (customize-set-variable 'vhdl-compose-create-files 'single)
  3607. :style radio :selected (eq 'single vhdl-compose-create-files)]
  3608. ["Separate"
  3609. (customize-set-variable 'vhdl-compose-create-files 'separate)
  3610. :style radio :selected (eq 'separate vhdl-compose-create-files)])
  3611. ["Create Configuration File"
  3612. (customize-set-variable 'vhdl-compose-configuration-create-file
  3613. (not vhdl-compose-configuration-create-file))
  3614. :style toggle :selected vhdl-compose-configuration-create-file]
  3615. ["Hierarchical Configuration"
  3616. (customize-set-variable 'vhdl-compose-configuration-hierarchical
  3617. (not vhdl-compose-configuration-hierarchical))
  3618. :style toggle :selected vhdl-compose-configuration-hierarchical]
  3619. ["Use Subconfiguration"
  3620. (customize-set-variable 'vhdl-compose-configuration-use-subconfiguration
  3621. (not vhdl-compose-configuration-use-subconfiguration))
  3622. :style toggle :selected vhdl-compose-configuration-use-subconfiguration]
  3623. "--"
  3624. ["Customize Group..." (customize-group 'vhdl-compose) t])
  3625. ("Comment"
  3626. ["Self Insert Comments"
  3627. (customize-set-variable 'vhdl-self-insert-comments
  3628. (not vhdl-self-insert-comments))
  3629. :style toggle :selected vhdl-self-insert-comments]
  3630. ["Prompt for Comments"
  3631. (customize-set-variable 'vhdl-prompt-for-comments
  3632. (not vhdl-prompt-for-comments))
  3633. :style toggle :selected vhdl-prompt-for-comments]
  3634. ["Inline Comment Column..."
  3635. (customize-option 'vhdl-inline-comment-column) t]
  3636. ["End Comment Column..." (customize-option 'vhdl-end-comment-column) t]
  3637. "--"
  3638. ["Customize Group..." (customize-group 'vhdl-comment) t])
  3639. ("Beautify"
  3640. ["Auto Align Templates"
  3641. (customize-set-variable 'vhdl-auto-align (not vhdl-auto-align))
  3642. :style toggle :selected vhdl-auto-align]
  3643. ["Align Line Groups"
  3644. (customize-set-variable 'vhdl-align-groups (not vhdl-align-groups))
  3645. :style toggle :selected vhdl-align-groups]
  3646. ["Group Separation String..."
  3647. (customize-option 'vhdl-align-group-separate) t]
  3648. ["Align Lines with Same Indent"
  3649. (customize-set-variable 'vhdl-align-same-indent
  3650. (not vhdl-align-same-indent))
  3651. :style toggle :selected vhdl-align-same-indent]
  3652. ["Beautify Options..." (customize-option 'vhdl-beautify-options) t]
  3653. "--"
  3654. ["Customize Group..." (customize-group 'vhdl-beautify) t])
  3655. ("Highlight"
  3656. ["Highlighting On/Off..."
  3657. (customize-option
  3658. (if (fboundp 'global-font-lock-mode)
  3659. 'global-font-lock-mode 'font-lock-auto-fontify)) t]
  3660. ["Highlight Keywords"
  3661. (progn (customize-set-variable 'vhdl-highlight-keywords
  3662. (not vhdl-highlight-keywords))
  3663. (vhdl-fontify-buffer))
  3664. :style toggle :selected vhdl-highlight-keywords]
  3665. ["Highlight Names"
  3666. (progn (customize-set-variable 'vhdl-highlight-names
  3667. (not vhdl-highlight-names))
  3668. (vhdl-fontify-buffer))
  3669. :style toggle :selected vhdl-highlight-names]
  3670. ["Highlight Special Words"
  3671. (progn (customize-set-variable 'vhdl-highlight-special-words
  3672. (not vhdl-highlight-special-words))
  3673. (vhdl-fontify-buffer))
  3674. :style toggle :selected vhdl-highlight-special-words]
  3675. ["Highlight Forbidden Words"
  3676. (progn (customize-set-variable 'vhdl-highlight-forbidden-words
  3677. (not vhdl-highlight-forbidden-words))
  3678. (vhdl-fontify-buffer))
  3679. :style toggle :selected vhdl-highlight-forbidden-words]
  3680. ["Highlight Verilog Keywords"
  3681. (progn (customize-set-variable 'vhdl-highlight-verilog-keywords
  3682. (not vhdl-highlight-verilog-keywords))
  3683. (vhdl-fontify-buffer))
  3684. :style toggle :selected vhdl-highlight-verilog-keywords]
  3685. ["Highlight \"translate_off\""
  3686. (progn (customize-set-variable 'vhdl-highlight-translate-off
  3687. (not vhdl-highlight-translate-off))
  3688. (vhdl-fontify-buffer))
  3689. :style toggle :selected vhdl-highlight-translate-off]
  3690. ["Case Sensitive Highlighting"
  3691. (progn (customize-set-variable 'vhdl-highlight-case-sensitive
  3692. (not vhdl-highlight-case-sensitive))
  3693. (vhdl-fontify-buffer))
  3694. :style toggle :selected vhdl-highlight-case-sensitive]
  3695. ["Special Syntax Definition..."
  3696. (customize-option 'vhdl-special-syntax-alist) t]
  3697. ["Forbidden Words..." (customize-option 'vhdl-forbidden-words) t]
  3698. ["Forbidden Syntax..." (customize-option 'vhdl-forbidden-syntax) t]
  3699. ["Directive Keywords..." (customize-option 'vhdl-directive-keywords) t]
  3700. ["Colors..." (customize-group 'vhdl-highlight-faces) t]
  3701. "--"
  3702. ["Customize Group..." (customize-group 'vhdl-highlight) t])
  3703. ("Speedbar"
  3704. ["Auto Open at Startup"
  3705. (customize-set-variable 'vhdl-speedbar-auto-open
  3706. (not vhdl-speedbar-auto-open))
  3707. :style toggle :selected vhdl-speedbar-auto-open]
  3708. ("Default Displaying Mode"
  3709. ["Files"
  3710. (customize-set-variable 'vhdl-speedbar-display-mode 'files)
  3711. :style radio :selected (eq 'files vhdl-speedbar-display-mode)]
  3712. ["Directory Hierarchy"
  3713. (customize-set-variable 'vhdl-speedbar-display-mode 'directory)
  3714. :style radio :selected (eq 'directory vhdl-speedbar-display-mode)]
  3715. ["Project Hierarchy"
  3716. (customize-set-variable 'vhdl-speedbar-display-mode 'project)
  3717. :style radio :selected (eq 'project vhdl-speedbar-display-mode)])
  3718. ["Indentation Offset..."
  3719. (customize-option 'speedbar-indentation-width) t]
  3720. ["Scan Size Limits..." (customize-option 'vhdl-speedbar-scan-limit) t]
  3721. ["Jump to Unit when Opening"
  3722. (customize-set-variable 'vhdl-speedbar-jump-to-unit
  3723. (not vhdl-speedbar-jump-to-unit))
  3724. :style toggle :selected vhdl-speedbar-jump-to-unit]
  3725. ["Update Hierarchy on File Saving"
  3726. (customize-set-variable 'vhdl-speedbar-update-on-saving
  3727. (not vhdl-speedbar-update-on-saving))
  3728. :style toggle :selected vhdl-speedbar-update-on-saving]
  3729. ("Save in Cache File"
  3730. ["Hierarchy Information"
  3731. (customize-set-variable 'vhdl-speedbar-save-cache
  3732. (if (memq 'hierarchy vhdl-speedbar-save-cache)
  3733. (delq 'hierarchy vhdl-speedbar-save-cache)
  3734. (cons 'hierarchy vhdl-speedbar-save-cache)))
  3735. :style toggle :selected (memq 'hierarchy vhdl-speedbar-save-cache)]
  3736. ["Displaying Status"
  3737. (customize-set-variable 'vhdl-speedbar-save-cache
  3738. (if (memq 'display vhdl-speedbar-save-cache)
  3739. (delq 'display vhdl-speedbar-save-cache)
  3740. (cons 'display vhdl-speedbar-save-cache)))
  3741. :style toggle :selected (memq 'display vhdl-speedbar-save-cache)])
  3742. ["Cache File Name..."
  3743. (customize-option 'vhdl-speedbar-cache-file-name) t]
  3744. "--"
  3745. ["Customize Group..." (customize-group 'vhdl-speedbar) t])
  3746. ("Menu"
  3747. ["Add Index Menu when Loading File"
  3748. (progn (customize-set-variable 'vhdl-index-menu (not vhdl-index-menu))
  3749. (vhdl-index-menu-init))
  3750. :style toggle :selected vhdl-index-menu]
  3751. ["Add Source File Menu when Loading File"
  3752. (progn (customize-set-variable 'vhdl-source-file-menu
  3753. (not vhdl-source-file-menu))
  3754. (vhdl-add-source-files-menu))
  3755. :style toggle :selected vhdl-source-file-menu]
  3756. ["Add Hideshow Menu at Startup"
  3757. (progn (customize-set-variable 'vhdl-hideshow-menu
  3758. (not vhdl-hideshow-menu))
  3759. (vhdl-activate-customizations))
  3760. :style toggle :selected vhdl-hideshow-menu]
  3761. ["Hide Everything Initially"
  3762. (customize-set-variable 'vhdl-hide-all-init (not vhdl-hide-all-init))
  3763. :style toggle :selected vhdl-hide-all-init]
  3764. "--"
  3765. ["Customize Group..." (customize-group 'vhdl-menu) t])
  3766. ("Print"
  3767. ["In Two Column Format"
  3768. (progn (customize-set-variable 'vhdl-print-two-column
  3769. (not vhdl-print-two-column))
  3770. (message "Activate new setting by saving options and restarting Emacs"))
  3771. :style toggle :selected vhdl-print-two-column]
  3772. ["Use Customized Faces"
  3773. (progn (customize-set-variable 'vhdl-print-customize-faces
  3774. (not vhdl-print-customize-faces))
  3775. (message "Activate new setting by saving options and restarting Emacs"))
  3776. :style toggle :selected vhdl-print-customize-faces]
  3777. "--"
  3778. ["Customize Group..." (customize-group 'vhdl-print) t])
  3779. ("Miscellaneous"
  3780. ["Use Intelligent Tab"
  3781. (progn (customize-set-variable 'vhdl-intelligent-tab
  3782. (not vhdl-intelligent-tab))
  3783. (vhdl-activate-customizations))
  3784. :style toggle :selected vhdl-intelligent-tab]
  3785. ["Indent Syntax-Based"
  3786. (customize-set-variable 'vhdl-indent-syntax-based
  3787. (not vhdl-indent-syntax-based))
  3788. :style toggle :selected vhdl-indent-syntax-based]
  3789. ["Indent Comments Like Next Code Line"
  3790. (customize-set-variable 'vhdl-indent-comment-like-next-code-line
  3791. (not vhdl-indent-comment-like-next-code-line))
  3792. :style toggle :selected vhdl-indent-comment-like-next-code-line]
  3793. ["Word Completion is Case Sensitive"
  3794. (customize-set-variable 'vhdl-word-completion-case-sensitive
  3795. (not vhdl-word-completion-case-sensitive))
  3796. :style toggle :selected vhdl-word-completion-case-sensitive]
  3797. ["Word Completion in Minibuffer"
  3798. (progn (customize-set-variable 'vhdl-word-completion-in-minibuffer
  3799. (not vhdl-word-completion-in-minibuffer))
  3800. (message "Activate new setting by saving options and restarting Emacs"))
  3801. :style toggle :selected vhdl-word-completion-in-minibuffer]
  3802. ["Underscore is Part of Word"
  3803. (progn (customize-set-variable 'vhdl-underscore-is-part-of-word
  3804. (not vhdl-underscore-is-part-of-word))
  3805. (vhdl-activate-customizations))
  3806. :style toggle :selected vhdl-underscore-is-part-of-word]
  3807. "--"
  3808. ["Customize Group..." (customize-group 'vhdl-misc) t])
  3809. ["Related..." (customize-browse 'vhdl-related) t]
  3810. "--"
  3811. ["Save Options" customize-save-customized t]
  3812. ["Activate Options" vhdl-activate-customizations t]
  3813. ["Browse Options..." vhdl-customize t])))
  3814. (defvar vhdl-mode-menu-list (vhdl-create-mode-menu)
  3815. "VHDL Mode menu.")
  3816. (defun vhdl-update-mode-menu ()
  3817. "Update VHDL Mode menu."
  3818. (interactive)
  3819. (easy-menu-remove vhdl-mode-menu-list) ; for XEmacs
  3820. (setq vhdl-mode-menu-list (vhdl-create-mode-menu))
  3821. (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
  3822. (easy-menu-define vhdl-mode-menu vhdl-mode-map
  3823. "Menu keymap for VHDL Mode." vhdl-mode-menu-list))
  3824. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3825. ;; Index menu (using `imenu.el'), also used for speedbar (using `speedbar.el')
  3826. (defconst vhdl-imenu-generic-expression
  3827. '(
  3828. ("Subprogram"
  3829. "^\\s-*\\(\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\s-+\\(\"?\\(\\w\\|\\s_\\)+\"?\\)"
  3830. 4)
  3831. ("Instance"
  3832. "^\\s-*\\(\\(\\w\\|\\s_\\)+\\s-*:\\(\\s-\\|\n\\)*\\(entity\\s-+\\(\\w\\|\\s_\\)+\\.\\)?\\(\\w\\|\\s_\\)+\\)\\(\\s-\\|\n\\)+\\(generic\\|port\\)\\s-+map\\>"
  3833. 1)
  3834. ("Component"
  3835. "^\\s-*\\(component\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
  3836. 2)
  3837. ("Procedural"
  3838. "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(procedural\\)"
  3839. 1)
  3840. ("Process"
  3841. "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(\\(postponed\\s-+\\|\\)process\\)"
  3842. 1)
  3843. ("Block"
  3844. "^\\s-*\\(\\(\\w\\|\\s_\\)+\\)\\s-*:\\(\\s-\\|\n\\)*\\(block\\)"
  3845. 1)
  3846. ("Package"
  3847. "^\\s-*\\(package\\( body\\|\\)\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
  3848. 3)
  3849. ("Configuration"
  3850. "^\\s-*\\(configuration\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
  3851. 2)
  3852. ("Architecture"
  3853. "^\\s-*\\(architecture\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\s-+of\\s-+\\(\\w\\|\\s_\\)+\\)"
  3854. 2)
  3855. ("Entity"
  3856. "^\\s-*\\(entity\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
  3857. 2)
  3858. ("Context"
  3859. "^\\s-*\\(context\\)\\s-+\\(\\(\\w\\|\\s_\\)+\\)"
  3860. 2)
  3861. )
  3862. "Imenu generic expression for VHDL Mode. See `imenu-generic-expression'.")
  3863. (defun vhdl-index-menu-init ()
  3864. "Initialize index menu."
  3865. (set (make-local-variable 'imenu-case-fold-search) t)
  3866. (set (make-local-variable 'imenu-generic-expression)
  3867. vhdl-imenu-generic-expression)
  3868. (when (and vhdl-index-menu (fboundp 'imenu))
  3869. (imenu-add-to-menubar "Index")))
  3870. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3871. ;; Source file menu (using `easy-menu.el')
  3872. (defvar vhdl-sources-menu nil)
  3873. (defun vhdl-directory-files (directory &optional full match)
  3874. "Call `directory-files' if DIRECTORY exists, otherwise generate error
  3875. message."
  3876. (if (not (file-directory-p directory))
  3877. (vhdl-warning-when-idle "No such directory: \"%s\"" directory)
  3878. (let ((dir (directory-files directory full match)))
  3879. (setq dir (delete "." dir))
  3880. (setq dir (delete ".." dir))
  3881. dir)))
  3882. (defun vhdl-get-source-files (&optional full directory)
  3883. "Get list of VHDL source files in DIRECTORY or current directory."
  3884. (let ((mode-alist auto-mode-alist)
  3885. filename-regexp)
  3886. ;; create regular expressions for matching file names
  3887. (setq filename-regexp "\\`[^.].*\\(")
  3888. (while mode-alist
  3889. (when (eq (cdar mode-alist) 'vhdl-mode)
  3890. (setq filename-regexp
  3891. (concat filename-regexp (caar mode-alist) "\\|")))
  3892. (setq mode-alist (cdr mode-alist)))
  3893. (setq filename-regexp
  3894. (concat (substring filename-regexp 0
  3895. (string-match "\\\\|$" filename-regexp)) "\\)"))
  3896. ;; find files
  3897. (vhdl-directory-files
  3898. (or directory default-directory) full filename-regexp)))
  3899. (defun vhdl-add-source-files-menu ()
  3900. "Scan directory for all VHDL source files and generate menu.
  3901. The directory of the current source file is scanned."
  3902. (interactive)
  3903. (message "Scanning directory for source files ...")
  3904. (let ((newmap (current-local-map))
  3905. (file-list (vhdl-get-source-files))
  3906. menu-list found)
  3907. ;; Create list for menu
  3908. (setq found nil)
  3909. (while file-list
  3910. (setq found t)
  3911. (push (vector (car file-list) (list 'find-file (car file-list)) t)
  3912. menu-list)
  3913. (setq file-list (cdr file-list)))
  3914. (setq menu-list (vhdl-menu-split menu-list "Sources"))
  3915. (when found (push "--" menu-list))
  3916. (push ["*Rescan*" vhdl-add-source-files-menu t] menu-list)
  3917. (push "Sources" menu-list)
  3918. ;; Create menu
  3919. (easy-menu-add menu-list)
  3920. (easy-menu-define vhdl-sources-menu newmap
  3921. "VHDL source files menu" menu-list))
  3922. (message ""))
  3923. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3924. ;;; Mode definition
  3925. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3926. ;; performs all buffer local initializations
  3927. ;;;###autoload
  3928. (define-derived-mode vhdl-mode prog-mode
  3929. '("VHDL" (vhdl-electric-mode "/" (vhdl-stutter-mode "/"))
  3930. (vhdl-electric-mode "e")
  3931. (vhdl-stutter-mode "s"))
  3932. "Major mode for editing VHDL code.
  3933. Usage:
  3934. ------
  3935. TEMPLATE INSERTION (electrification):
  3936. After typing a VHDL keyword and entering `SPC', you are prompted for
  3937. arguments while a template is generated for that VHDL construct. Typing
  3938. `RET' or `C-g' at the first (mandatory) prompt aborts the current
  3939. template generation. Optional arguments are indicated by square
  3940. brackets and removed if the queried string is left empty. Prompts for
  3941. mandatory arguments remain in the code if the queried string is left
  3942. empty. They can be queried again by `C-c C-t C-q'. Enabled
  3943. electrification is indicated by `/e' in the mode line.
  3944. Typing `M-SPC' after a keyword inserts a space without calling the
  3945. template generator. Automatic template generation (i.e.
  3946. electrification) can be disabled (enabled) by typing `C-c C-m C-e' or by
  3947. setting option `vhdl-electric-mode' (see OPTIONS).
  3948. Template generators can be invoked from the VHDL menu, by key
  3949. bindings, by typing `C-c C-i C-c' and choosing a construct, or by typing
  3950. the keyword (i.e. first word of menu entry not in parenthesis) and
  3951. `SPC'. The following abbreviations can also be used: arch, attr, cond,
  3952. conf, comp, cons, func, inst, pack, sig, var.
  3953. Template styles can be customized in customization group
  3954. `vhdl-template' (see OPTIONS).
  3955. HEADER INSERTION:
  3956. A file header can be inserted by `C-c C-t C-h'. A file footer
  3957. (template at the end of the file) can be inserted by `C-c C-t C-f'.
  3958. See customization group `vhdl-header'.
  3959. STUTTERING:
  3960. Double striking of some keys inserts cumbersome VHDL syntax elements.
  3961. Stuttering can be disabled (enabled) by typing `C-c C-m C-s' or by
  3962. option `vhdl-stutter-mode'. Enabled stuttering is indicated by `/s' in
  3963. the mode line. The stuttering keys and their effects are:
  3964. ;; --> \" : \" [ --> ( -- --> comment
  3965. ;;; --> \" := \" [[ --> [ --CR --> comment-out code
  3966. .. --> \" => \" ] --> ) --- --> horizontal line
  3967. ,, --> \" <= \" ]] --> ] ---- --> display comment
  3968. == --> \" == \" \\='\\=' --> \\\"
  3969. WORD COMPLETION:
  3970. Typing `TAB' after a (not completed) word looks for a VHDL keyword or a
  3971. word in the buffer that starts alike, inserts it and adjusts case.
  3972. Re-typing `TAB' toggles through alternative word completions. This also
  3973. works in the minibuffer (i.e. in template generator prompts).
  3974. Typing `TAB' after `(' looks for and inserts complete parenthesized
  3975. expressions (e.g. for array index ranges). All keywords as well as
  3976. standard types and subprograms of VHDL have predefined abbreviations
  3977. (e.g., type \"std\" and `TAB' will toggle through all standard types
  3978. beginning with \"std\").
  3979. Typing `TAB' after a non-word character indents the line if at the
  3980. beginning of a line (i.e. no preceding non-blank characters), and
  3981. inserts a tabulator stop otherwise. `M-TAB' always inserts a tabulator
  3982. stop.
  3983. COMMENTS:
  3984. `--' puts a single comment.
  3985. `---' draws a horizontal line for separating code segments.
  3986. `----' inserts a display comment, i.e. two horizontal lines
  3987. with a comment in between.
  3988. `--CR' comments out code on that line. Re-hitting CR comments
  3989. out following lines.
  3990. `C-c C-c' comments out a region if not commented out,
  3991. uncomments a region if already commented out. Option
  3992. `comment-style' defines where the comment characters
  3993. should be placed (beginning of line, indent, etc.).
  3994. You are prompted for comments after object definitions (i.e. signals,
  3995. variables, constants, ports) and after subprogram and process
  3996. specifications if option `vhdl-prompt-for-comments' is non-nil.
  3997. Comments are automatically inserted as additional labels (e.g. after
  3998. begin statements) and as help comments if `vhdl-self-insert-comments' is
  3999. non-nil.
  4000. Inline comments (i.e. comments after a piece of code on the same line)
  4001. are indented at least to `vhdl-inline-comment-column'. Comments go at
  4002. maximum to `vhdl-end-comment-column'. `RET' after a space in a comment
  4003. will open a new comment line. Typing beyond `vhdl-end-comment-column'
  4004. in a comment automatically opens a new comment line. `M-q' re-fills
  4005. multi-line comments.
  4006. INDENTATION:
  4007. `TAB' indents a line if at the beginning of the line. The amount of
  4008. indentation is specified by option `vhdl-basic-offset'. `C-c C-i C-l'
  4009. always indents the current line (is bound to `TAB' if option
  4010. `vhdl-intelligent-tab' is nil). If a region is active, `TAB' indents
  4011. the entire region.
  4012. Indentation can be done for a group of lines (`C-c C-i C-g'), a region
  4013. (`M-C-\\') or the entire buffer (menu). Argument and port lists are
  4014. indented normally (nil) or relative to the opening parenthesis (non-nil)
  4015. according to option `vhdl-argument-list-indent'.
  4016. If option `vhdl-indent-tabs-mode' is nil, spaces are used instead of
  4017. tabs. `\\[tabify]' and `\\[untabify]' allow to convert spaces to tabs
  4018. and vice versa.
  4019. Syntax-based indentation can be very slow in large files. Option
  4020. `vhdl-indent-syntax-based' allows you to use faster but simpler indentation.
  4021. Option `vhdl-indent-comment-like-next-code-line' controls whether
  4022. comment lines are indented like the preceding or like the following code
  4023. line.
  4024. ALIGNMENT:
  4025. The alignment functions align operators, keywords, and inline comments
  4026. to beautify the code. `C-c C-a C-a' aligns a group of consecutive lines
  4027. separated by blank lines, `C-c C-a C-i' a block of lines with same
  4028. indent. `C-c C-a C-l' aligns all lines belonging to a list enclosed by
  4029. a pair of parentheses (e.g. port clause/map, argument list), and `C-c
  4030. C-a C-d' all lines within the declarative part of a design unit. `C-c
  4031. C-a M-a' aligns an entire region. `C-c C-a C-c' aligns inline comments
  4032. for a group of lines, and `C-c C-a M-c' for a region.
  4033. If option `vhdl-align-groups' is non-nil, groups of code lines
  4034. separated by special lines (see option `vhdl-align-group-separate') are
  4035. aligned individually. If option `vhdl-align-same-indent' is non-nil,
  4036. blocks of lines with same indent are aligned separately. Some templates
  4037. are automatically aligned after generation if option `vhdl-auto-align'
  4038. is non-nil.
  4039. Alignment tries to align inline comments at
  4040. `vhdl-inline-comment-column' and tries inline comment not to exceed
  4041. `vhdl-end-comment-column'.
  4042. `C-c C-x M-w' fixes up whitespace in a region. That is, operator
  4043. symbols are surrounded by one space, and multiple spaces are eliminated.
  4044. CODE FILLING:
  4045. Code filling allows you to condense code (e.g. sensitivity lists or port
  4046. maps) by removing comments and newlines and re-wrapping so that all
  4047. lines are maximally filled (block filling). `C-c C-f C-f' fills a list
  4048. enclosed by parenthesis, `C-c C-f C-g' a group of lines separated by
  4049. blank lines, `C-c C-f C-i' a block of lines with same indent, and
  4050. `C-c C-f M-f' an entire region.
  4051. CODE BEAUTIFICATION:
  4052. `C-c M-b' and `C-c C-b' beautify the code of a region or of the entire
  4053. buffer respectively. This includes indentation, alignment, and case
  4054. fixing. Code beautification can also be run non-interactively using the
  4055. command:
  4056. emacs -batch -l ~/.emacs filename.vhd -f vhdl-beautify-buffer
  4057. PORT TRANSLATION:
  4058. Generic and port clauses from entity or component declarations can be
  4059. copied (`C-c C-p C-w') and pasted as entity and component declarations,
  4060. as component instantiations and corresponding internal constants and
  4061. signals, as a generic map with constants as actual generics, and as
  4062. internal signal initializations (menu).
  4063. To include formals in component instantiations, see option
  4064. `vhdl-association-list-with-formals'. To include comments in pasting,
  4065. see options `vhdl-include-...-comments'.
  4066. A clause with several generic/port names on the same line can be
  4067. flattened (`C-c C-p C-f') so that only one name per line exists. The
  4068. direction of ports can be reversed (`C-c C-p C-r'), i.e., inputs become
  4069. outputs and vice versa, which can be useful in testbenches. (This
  4070. reversion is done on the internal data structure and is only reflected
  4071. in subsequent paste operations.)
  4072. Names for actual ports, instances, testbenches, and
  4073. design-under-test instances can be derived from existing names according
  4074. to options `vhdl-...-name'. See customization group `vhdl-port'.
  4075. SUBPROGRAM TRANSLATION:
  4076. Similar functionality exists for copying/pasting the interface of
  4077. subprograms (function/procedure). A subprogram interface can be copied
  4078. and then pasted as a subprogram declaration, body or call (uses
  4079. association list with formals).
  4080. TESTBENCH GENERATION:
  4081. A copied port can also be pasted as a testbench. The generated
  4082. testbench includes an entity, an architecture, and an optional
  4083. configuration. The architecture contains the component declaration and
  4084. instantiation of the DUT as well as internal constant and signal
  4085. declarations. Additional user-defined templates can be inserted. The
  4086. names used for entity/architecture/configuration/DUT as well as the file
  4087. structure to be generated can be customized. See customization group
  4088. `vhdl-testbench'.
  4089. KEY BINDINGS:
  4090. Key bindings (`C-c ...') exist for most commands (see in menu).
  4091. VHDL MENU:
  4092. All commands can be found in the VHDL menu including their key bindings.
  4093. FILE BROWSER:
  4094. The speedbar allows browsing of directories and file contents. It can
  4095. be accessed from the VHDL menu and is automatically opened if option
  4096. `vhdl-speedbar-auto-open' is non-nil.
  4097. In speedbar, open files and directories with `mouse-2' on the name and
  4098. browse/rescan their contents with `mouse-2'/`S-mouse-2' on the `+'.
  4099. DESIGN HIERARCHY BROWSER:
  4100. The speedbar can also be used for browsing the hierarchy of design units
  4101. contained in the source files of the current directory or the specified
  4102. projects (see option `vhdl-project-alist').
  4103. The speedbar can be switched between file, directory hierarchy and
  4104. project hierarchy browsing mode in the speedbar menu or by typing `f',
  4105. `h' or `H' in speedbar.
  4106. In speedbar, open design units with `mouse-2' on the name and browse
  4107. their hierarchy with `mouse-2' on the `+'. Ports can directly be copied
  4108. from entities and components (in packages). Individual design units and
  4109. complete designs can directly be compiled (\"Make\" menu entry).
  4110. The hierarchy is automatically updated upon saving a modified source
  4111. file when option `vhdl-speedbar-update-on-saving' is non-nil. The
  4112. hierarchy is only updated for projects that have been opened once in the
  4113. speedbar. The hierarchy is cached between Emacs sessions in a file (see
  4114. options in group `vhdl-speedbar').
  4115. Simple design consistency checks are done during scanning, such as
  4116. multiple declarations of the same unit or missing primary units that are
  4117. required by secondary units.
  4118. STRUCTURAL COMPOSITION:
  4119. Enables simple structural composition. `C-c C-m C-n' creates a skeleton
  4120. for a new component. Subcomponents (i.e. component declaration and
  4121. instantiation) can be automatically placed from a previously read port
  4122. (`C-c C-m C-p') or directly from the hierarchy browser (`P'). Finally,
  4123. all subcomponents can be automatically connected using internal signals
  4124. and ports (`C-c C-m C-w') following these rules:
  4125. - subcomponent actual ports with same name are considered to be
  4126. connected by a signal (internal signal or port)
  4127. - signals that are only inputs to subcomponents are considered as
  4128. inputs to this component -> input port created
  4129. - signals that are only outputs from subcomponents are considered as
  4130. outputs from this component -> output port created
  4131. - signals that are inputs to AND outputs from subcomponents are
  4132. considered as internal connections -> internal signal created
  4133. Purpose: With appropriate naming conventions it is possible to
  4134. create higher design levels with only a few mouse clicks or key
  4135. strokes. A new design level can be created by simply generating a new
  4136. component, placing the required subcomponents from the hierarchy
  4137. browser, and wiring everything automatically.
  4138. Note: Automatic wiring only works reliably on templates of new
  4139. components and component instantiations that were created by VHDL mode.
  4140. Component declarations can be placed in a components package (option
  4141. `vhdl-use-components-package') which can be automatically generated for
  4142. an entire directory or project (`C-c C-m M-p'). The VHDL'93 direct
  4143. component instantiation is also supported (option
  4144. `vhdl-use-direct-instantiation').
  4145. Configuration declarations can automatically be generated either from
  4146. the menu (`C-c C-m C-f') (for the architecture the cursor is in) or from
  4147. the speedbar menu (for the architecture under the cursor). The
  4148. configurations can optionally be hierarchical (i.e. include all
  4149. component levels of a hierarchical design, option
  4150. `vhdl-compose-configuration-hierarchical') or include subconfigurations
  4151. (option `vhdl-compose-configuration-use-subconfiguration'). For
  4152. subcomponents in hierarchical configurations, the most-recently-analyzed
  4153. (mra) architecture is selected. If another architecture is desired, it
  4154. can be marked as most-recently-analyzed (speedbar menu) before
  4155. generating the configuration.
  4156. Note: Configurations of subcomponents (i.e. hierarchical configuration
  4157. declarations) are currently not considered when displaying
  4158. configurations in speedbar.
  4159. See the options group `vhdl-compose' for all relevant user options.
  4160. SOURCE FILE COMPILATION:
  4161. The syntax of the current buffer can be analyzed by calling a VHDL
  4162. compiler (menu, `C-c C-k'). The compiler to be used is specified by
  4163. option `vhdl-compiler'. The available compilers are listed in option
  4164. `vhdl-compiler-alist' including all required compilation command,
  4165. command options, compilation directory, and error message syntax
  4166. information. New compilers can be added.
  4167. All the source files of an entire design can be compiled by the `make'
  4168. command (menu, `C-c M-C-k') if an appropriate Makefile exists.
  4169. MAKEFILE GENERATION:
  4170. Makefiles can be generated automatically by an internal generation
  4171. routine (`C-c M-k'). The library unit dependency information is
  4172. obtained from the hierarchy browser. Makefile generation can be
  4173. customized for each compiler in option `vhdl-compiler-alist'.
  4174. Makefile generation can also be run non-interactively using the
  4175. command:
  4176. emacs -batch -l ~/.emacs -l vhdl-mode
  4177. [-compiler compilername] [-project projectname]
  4178. -f vhdl-generate-makefile
  4179. The Makefile's default target \"all\" compiles the entire design, the
  4180. target \"clean\" removes it and the target \"library\" creates the
  4181. library directory if not existent. These target names can be customized
  4182. by option `vhdl-makefile-default-targets'. The Makefile also includes a
  4183. target for each primary library unit which allows selective compilation
  4184. of this unit, its secondary units and its subhierarchy (example:
  4185. compilation of a design specified by a configuration). User specific
  4186. parts can be inserted into a Makefile with option
  4187. `vhdl-makefile-generation-hook'.
  4188. Limitations:
  4189. - Only library units and dependencies within the current library are
  4190. considered. Makefiles for designs that span multiple libraries are
  4191. not (yet) supported.
  4192. - Only one-level configurations are supported (also hierarchical),
  4193. but configurations that go down several levels are not.
  4194. - The \"others\" keyword in configurations is not supported.
  4195. PROJECTS:
  4196. Projects can be defined in option `vhdl-project-alist' and a current
  4197. project be selected using option `vhdl-project' (permanently) or from
  4198. the menu or speedbar (temporarily). For each project, title and
  4199. description strings (for the file headers), source files/directories
  4200. (for the hierarchy browser and Makefile generation), library name, and
  4201. compiler-dependent options, exceptions and compilation directory can be
  4202. specified. Compilation settings overwrite the settings of option
  4203. `vhdl-compiler-alist'.
  4204. Project setups can be exported (i.e. written to a file) and imported.
  4205. Imported setups are not automatically saved in `vhdl-project-alist' but
  4206. can be saved afterwards in its customization buffer. When starting
  4207. Emacs with VHDL Mode (i.e. load a VHDL file or use \"emacs -l
  4208. vhdl-mode\") in a directory with an existing project setup file, it is
  4209. automatically loaded and its project activated if option
  4210. `vhdl-project-auto-load' is non-nil. Names/paths of the project setup
  4211. files can be specified in option `vhdl-project-file-name'. Multiple
  4212. project setups can be automatically loaded from global directories.
  4213. This is an alternative to specifying project setups with option
  4214. `vhdl-project-alist'.
  4215. SPECIAL MENUES:
  4216. As an alternative to the speedbar, an index menu can be added (set
  4217. option `vhdl-index-menu' to non-nil) or made accessible as a mouse menu
  4218. (e.g. add \"(global-set-key '[S-down-mouse-3] 'imenu)\" to your start-up
  4219. file) for browsing the file contents (is not populated if buffer is
  4220. larger than 256000). Also, a source file menu can be
  4221. added (set option `vhdl-source-file-menu' to non-nil) for browsing the
  4222. current directory for VHDL source files.
  4223. VHDL STANDARDS:
  4224. The VHDL standards to be used are specified in option `vhdl-standard'.
  4225. Available standards are: VHDL'87/'93(02)/'08, VHDL-AMS, and Math Packages.
  4226. KEYWORD CASE:
  4227. Lower and upper case for keywords and standardized types, attributes,
  4228. and enumeration values is supported. If the option
  4229. `vhdl-upper-case-keywords' is set to non-nil, keywords can be typed in
  4230. lower case and are converted into upper case automatically (not for
  4231. types, attributes, and enumeration values). The case of keywords,
  4232. types, attributes,and enumeration values can be fixed for an entire
  4233. region (menu) or buffer (`C-c C-x C-c') according to the options
  4234. `vhdl-upper-case-{keywords,types,attributes,enum-values}'.
  4235. HIGHLIGHTING (fontification):
  4236. Keywords and standardized types, attributes, enumeration values, and
  4237. function names (controlled by option `vhdl-highlight-keywords'), as well
  4238. as comments, strings, and template prompts are highlighted using
  4239. different colors. Unit, subprogram, signal, variable, constant,
  4240. parameter and generic/port names in declarations as well as labels are
  4241. highlighted if option `vhdl-highlight-names' is non-nil.
  4242. Additional reserved words or words with a forbidden syntax (e.g. words
  4243. that should be avoided) can be specified in option
  4244. `vhdl-forbidden-words' or `vhdl-forbidden-syntax' and be highlighted in
  4245. a warning color (option `vhdl-highlight-forbidden-words'). Verilog
  4246. keywords are highlighted as forbidden words if option
  4247. `vhdl-highlight-verilog-keywords' is non-nil.
  4248. Words with special syntax can be highlighted by specifying their
  4249. syntax and color in option `vhdl-special-syntax-alist' and by setting
  4250. option `vhdl-highlight-special-words' to non-nil. This allows you to
  4251. establish some naming conventions (e.g. to distinguish different kinds
  4252. of signals or other objects by using name suffices) and to support them
  4253. visually.
  4254. Option `vhdl-highlight-case-sensitive' can be set to non-nil in order
  4255. to support case-sensitive highlighting. However, keywords are then only
  4256. highlighted if written in lower case.
  4257. Code between \"translate_off\" and \"translate_on\" pragmas is
  4258. highlighted using a different background color if option
  4259. `vhdl-highlight-translate-off' is non-nil.
  4260. For documentation and customization of the used colors see
  4261. customization group `vhdl-highlight-faces' (`\\[customize-group]'). For
  4262. highlighting of matching parenthesis, see customization group
  4263. `paren-showing'. Automatic buffer highlighting is turned on/off by
  4264. option `global-font-lock-mode' (`font-lock-auto-fontify' in XEmacs).
  4265. USER MODELS:
  4266. VHDL models (templates) can be specified by the user and made accessible
  4267. in the menu, through key bindings (`C-c C-m ...'), or by keyword
  4268. electrification. See option `vhdl-model-alist'.
  4269. HIDE/SHOW:
  4270. The code of blocks, processes, subprograms, component declarations and
  4271. instantiations, generic/port clauses, and configuration declarations can
  4272. be hidden using the `Hide/Show' menu or by pressing `S-mouse-2' within
  4273. the code (see customization group `vhdl-menu'). XEmacs: limited
  4274. functionality due to old `hideshow.el' package.
  4275. CODE UPDATING:
  4276. - Sensitivity List: `C-c C-u C-s' updates the sensitivity list of the
  4277. current process, `C-c C-u M-s' of all processes in the current buffer.
  4278. Limitations:
  4279. - Only declared local signals (ports, signals declared in
  4280. architecture and blocks) are automatically inserted.
  4281. - Global signals declared in packages are not automatically inserted.
  4282. Insert them once manually (will be kept afterwards).
  4283. - Out parameters of procedures are considered to be read.
  4284. Use option `vhdl-entity-file-name' to specify the entity file name
  4285. (used to obtain the port names).
  4286. Use option `vhdl-array-index-record-field-in-sensitivity-list' to
  4287. specify whether to include array indices and record fields in
  4288. sensitivity lists.
  4289. CODE FIXING:
  4290. `C-c C-x C-p' fixes the closing parenthesis of a generic/port clause
  4291. (e.g., if the closing parenthesis is on the wrong line or is missing).
  4292. PRINTING:
  4293. PostScript printing with different faces (an optimized set of faces is
  4294. used if `vhdl-print-customize-faces' is non-nil) or colors (if
  4295. `ps-print-color-p' is non-nil) is possible using the standard Emacs
  4296. PostScript printing commands. Option `vhdl-print-two-column' defines
  4297. appropriate default settings for nice landscape two-column printing.
  4298. The paper format can be set by option `ps-paper-type'. Do not forget to
  4299. switch `ps-print-color-p' to nil for printing on black-and-white
  4300. printers.
  4301. OPTIONS:
  4302. User options allow customization of VHDL Mode. All options are
  4303. accessible from the \"Options\" menu entry. Simple options (switches
  4304. and choices) can directly be changed, while for complex options a
  4305. customization buffer is opened. Changed options can be saved for future
  4306. sessions using the \"Save Options\" menu entry.
  4307. Options and their detailed descriptions can also be accessed by using
  4308. the \"Customize\" menu entry or the command `\\[customize-option]'
  4309. (`\\[customize-group]' for groups). Some customizations only take effect
  4310. after some action (read the NOTE in the option documentation).
  4311. Customization can also be done globally (i.e. site-wide, read the
  4312. INSTALL file).
  4313. Not all options are described in this documentation, so go and see
  4314. what other useful user options there are (`\\[vhdl-customize]' or menu)!
  4315. FILE EXTENSIONS:
  4316. As default, files with extensions \".vhd\" and \".vhdl\" are
  4317. automatically recognized as VHDL source files. To add an extension
  4318. \".xxx\", add the following line to your Emacs start-up file (`.emacs'):
  4319. (push \\='(\"\\\\.xxx\\\\\\='\" . vhdl-mode) auto-mode-alist)
  4320. HINTS:
  4321. - To start Emacs with open VHDL hierarchy browser without having to load
  4322. a VHDL file first, use the command:
  4323. emacs -l vhdl-mode -f speedbar-frame-mode
  4324. - Type `C-g C-g' to interrupt long operations or if Emacs hangs.
  4325. - Some features only work on properly indented code.
  4326. RELEASE NOTES:
  4327. See also the release notes (menu) for added features in new releases.
  4328. Maintenance:
  4329. ------------
  4330. To submit a bug report, enter `\\[vhdl-submit-bug-report]' within VHDL Mode.
  4331. Add a description of the problem and include a reproducible test case.
  4332. Questions and enhancement requests can be sent to <reto@gnu.org>.
  4333. The `vhdl-mode-announce' mailing list informs about new VHDL Mode releases.
  4334. The `vhdl-mode-victims' mailing list informs about new VHDL Mode beta
  4335. releases. You are kindly invited to participate in beta testing. Subscribe
  4336. to above mailing lists by sending an email to <reto@gnu.org>.
  4337. VHDL Mode is officially distributed at
  4338. http://www.iis.ee.ethz.ch/~zimmi/emacs/vhdl-mode.html
  4339. where the latest version can be found.
  4340. Known problems:
  4341. ---------------
  4342. - XEmacs: Incorrect start-up when automatically opening speedbar.
  4343. - XEmacs: Indentation in XEmacs 21.4 (and higher).
  4344. - Indentation incorrect for new 'postponed' VHDL keyword.
  4345. - Indentation incorrect for 'protected body' construct.
  4346. The VHDL Mode Authors
  4347. Reto Zimmermann and Rod Whitby
  4348. Key bindings:
  4349. -------------
  4350. \\{vhdl-mode-map}"
  4351. :abbrev-table vhdl-mode-abbrev-table
  4352. ;; set local variables
  4353. (set (make-local-variable 'paragraph-start)
  4354. "\\s-*\\(--+\\s-*$\\|$\\)")
  4355. (set (make-local-variable 'paragraph-separate) paragraph-start)
  4356. (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
  4357. (set (make-local-variable 'parse-sexp-ignore-comments) t)
  4358. (set (make-local-variable 'indent-line-function) 'vhdl-indent-line)
  4359. (set (make-local-variable 'comment-start) "--")
  4360. (set (make-local-variable 'comment-end) "")
  4361. (when vhdl-emacs-21
  4362. (set (make-local-variable 'comment-padding) ""))
  4363. (set (make-local-variable 'comment-column) vhdl-inline-comment-column)
  4364. (set (make-local-variable 'end-comment-column) vhdl-end-comment-column)
  4365. (set (make-local-variable 'comment-start-skip) "--+\\s-*")
  4366. (set (make-local-variable 'comment-multi-line) nil)
  4367. (set (make-local-variable 'indent-tabs-mode) vhdl-indent-tabs-mode)
  4368. (set (make-local-variable 'hippie-expand-verbose) nil)
  4369. ;; setup the comment indent variable in a Emacs version portable way
  4370. ;; ignore any byte compiler warnings you might get here
  4371. (when (boundp 'comment-indent-function)
  4372. (set (make-local-variable 'comment-indent-function) 'vhdl-comment-indent))
  4373. ;; initialize font locking
  4374. (set (make-local-variable 'font-lock-defaults)
  4375. (list
  4376. '(nil vhdl-font-lock-keywords) nil
  4377. (not vhdl-highlight-case-sensitive) '((?\_ . "w")) 'beginning-of-line))
  4378. (if (eval-when-compile (fboundp 'syntax-propertize-rules))
  4379. (set (make-local-variable 'syntax-propertize-function)
  4380. (syntax-propertize-rules
  4381. ;; Mark single quotes as having string quote syntax in
  4382. ;; 'c' instances.
  4383. ("\\('\\).\\('\\)" (1 "\"'") (2 "\"'"))))
  4384. (set (make-local-variable 'font-lock-syntactic-keywords)
  4385. vhdl-font-lock-syntactic-keywords))
  4386. (unless vhdl-emacs-21
  4387. (set (make-local-variable 'font-lock-support-mode) 'lazy-lock-mode)
  4388. (set (make-local-variable 'lazy-lock-defer-contextually) nil)
  4389. (set (make-local-variable 'lazy-lock-defer-on-the-fly) t)
  4390. (set (make-local-variable 'lazy-lock-defer-on-scrolling) t))
  4391. ;; variables for source file compilation
  4392. (when vhdl-compile-use-local-error-regexp
  4393. (set (make-local-variable 'compilation-error-regexp-alist) nil)
  4394. (set (make-local-variable 'compilation-file-regexp-alist) nil))
  4395. ;; add index menu
  4396. (vhdl-index-menu-init)
  4397. ;; add source file menu
  4398. (if vhdl-source-file-menu (vhdl-add-source-files-menu))
  4399. ;; add VHDL menu
  4400. (easy-menu-add vhdl-mode-menu-list) ; for XEmacs
  4401. (easy-menu-define vhdl-mode-menu vhdl-mode-map
  4402. "Menu keymap for VHDL Mode." vhdl-mode-menu-list)
  4403. ;; initialize hideshow and add menu
  4404. (vhdl-hideshow-init)
  4405. (run-hooks 'menu-bar-update-hook)
  4406. ;; miscellaneous
  4407. (vhdl-ps-print-init)
  4408. (vhdl-write-file-hooks-init)
  4409. (message "VHDL Mode %s.%s" vhdl-version
  4410. (if noninteractive "" " See menu for documentation and release notes.")))
  4411. (defun vhdl-activate-customizations ()
  4412. "Activate all customizations on local variables."
  4413. (interactive)
  4414. (vhdl-mode-map-init)
  4415. (use-local-map vhdl-mode-map)
  4416. (set-syntax-table vhdl-mode-syntax-table)
  4417. (setq comment-column vhdl-inline-comment-column)
  4418. (setq end-comment-column vhdl-end-comment-column)
  4419. (vhdl-write-file-hooks-init)
  4420. (vhdl-update-mode-menu)
  4421. (vhdl-hideshow-init)
  4422. (run-hooks 'menu-bar-update-hook))
  4423. (defun vhdl-write-file-hooks-init ()
  4424. "Add/remove hooks when buffer is saved."
  4425. (if vhdl-modify-date-on-saving
  4426. (add-hook 'local-write-file-hooks 'vhdl-template-modify-noerror nil t)
  4427. (remove-hook 'local-write-file-hooks 'vhdl-template-modify-noerror t))
  4428. (if (featurep 'xemacs) (make-local-hook 'after-save-hook))
  4429. (add-hook 'after-save-hook 'vhdl-add-modified-file nil t))
  4430. (defun vhdl-process-command-line-option (option)
  4431. "Process command line options for VHDL Mode."
  4432. (cond
  4433. ;; set compiler
  4434. ((equal option "-compiler")
  4435. (vhdl-set-compiler (car command-line-args-left))
  4436. (setq command-line-args-left (cdr command-line-args-left)))
  4437. ;; set project
  4438. ((equal option "-project")
  4439. (vhdl-set-project (car command-line-args-left))
  4440. (setq command-line-args-left (cdr command-line-args-left)))))
  4441. ;; make Emacs process VHDL Mode options
  4442. (setq command-switch-alist
  4443. (append command-switch-alist
  4444. '(("-compiler" . vhdl-process-command-line-option)
  4445. ("-project" . vhdl-process-command-line-option))))
  4446. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4447. ;;; Keywords and standardized words
  4448. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4449. (defconst vhdl-02-keywords
  4450. '(
  4451. "abs" "access" "after" "alias" "all" "and" "architecture" "array"
  4452. "assert" "attribute"
  4453. "begin" "block" "body" "buffer" "bus"
  4454. "case" "component" "configuration" "constant"
  4455. "disconnect" "downto"
  4456. "else" "elsif" "end" "entity" "exit"
  4457. "file" "for" "function"
  4458. "generate" "generic" "group" "guarded"
  4459. "if" "impure" "in" "inertial" "inout" "is"
  4460. "label" "library" "linkage" "literal" "loop"
  4461. "map" "mod"
  4462. "nand" "new" "next" "nor" "not" "null"
  4463. "of" "on" "open" "or" "others" "out"
  4464. "package" "port" "postponed" "procedure" "process" "protected" "pure"
  4465. "range" "record" "register" "reject" "rem" "report" "return"
  4466. "rol" "ror"
  4467. "select" "severity" "shared" "signal" "sla" "sll" "sra" "srl" "subtype"
  4468. "then" "to" "transport" "type"
  4469. "unaffected" "units" "until" "use"
  4470. "variable"
  4471. "wait" "when" "while" "with"
  4472. "xnor" "xor"
  4473. )
  4474. "List of VHDL'02 keywords.")
  4475. (defconst vhdl-08-keywords
  4476. '(
  4477. "context" "force" "property" "release" "sequence"
  4478. )
  4479. "List of VHDL'08 keywords.")
  4480. (defconst vhdl-ams-keywords
  4481. '(
  4482. "across" "break" "limit" "nature" "noise" "procedural" "quantity"
  4483. "reference" "spectrum" "subnature" "terminal" "through"
  4484. "tolerance"
  4485. )
  4486. "List of VHDL-AMS keywords.")
  4487. (defconst vhdl-verilog-keywords
  4488. '(
  4489. "`define" "`else" "`endif" "`ifdef" "`include" "`timescale" "`undef"
  4490. "always" "and" "assign" "begin" "buf" "bufif0" "bufif1"
  4491. "case" "casex" "casez" "cmos" "deassign" "default" "defparam" "disable"
  4492. "edge" "else" "end" "endattribute" "endcase" "endfunction" "endmodule"
  4493. "endprimitive" "endspecify" "endtable" "endtask" "event"
  4494. "for" "force" "forever" "fork" "function"
  4495. "highz0" "highz1" "if" "initial" "inout" "input" "integer" "join" "large"
  4496. "macromodule" "makefile" "medium" "module"
  4497. "nand" "negedge" "nmos" "nor" "not" "notif0" "notif1" "or" "output"
  4498. "parameter" "pmos" "posedge" "primitive" "pull0" "pull1" "pulldown"
  4499. "pullup"
  4500. "rcmos" "real" "realtime" "reg" "release" "repeat" "rnmos" "rpmos" "rtran"
  4501. "rtranif0" "rtranif1"
  4502. "scalared" "signed" "small" "specify" "specparam" "strength" "strong0"
  4503. "strong1" "supply" "supply0" "supply1"
  4504. "table" "task" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
  4505. "triand" "trior" "trireg"
  4506. "vectored" "wait" "wand" "weak0" "weak1" "while" "wire" "wor" "xnor" "xor"
  4507. )
  4508. "List of Verilog keywords as candidate for additional reserved words.")
  4509. (defconst vhdl-02-types
  4510. '(
  4511. "boolean" "bit" "bit_vector" "character" "severity_level" "integer"
  4512. "real" "time" "natural" "positive" "string" "line" "text" "side"
  4513. "unsigned" "signed" "delay_length" "file_open_kind" "file_open_status"
  4514. "std_logic" "std_logic_vector"
  4515. "std_ulogic" "std_ulogic_vector"
  4516. )
  4517. "List of VHDL'02 standardized types.")
  4518. (defconst vhdl-08-types
  4519. '(
  4520. "boolean_vector" "integer_vector" "real_vector" "time_vector"
  4521. )
  4522. "List of VHDL'08 standardized types.")
  4523. (defconst vhdl-ams-types
  4524. ;; standards: IEEE Std 1076.1-2007, IEEE Std 1076.1.1-2004
  4525. '(
  4526. ;; package `standard'
  4527. "domain_type" "real_vector"
  4528. ;; package `energy_systems'
  4529. "energy" "power" "periodicity" "real_across" "real_through" "unspecified"
  4530. "unspecified_vector" "energy_vector" "power_vector" "periodicity_vector"
  4531. "real_across_vector" "real_through_vector"
  4532. ;; package `electrical_systems'
  4533. "voltage" "current" "charge" "resistance" "conductance" "capacitance"
  4534. "mmf" "electric_flux" "electric_flux_density" "electric_field_strength"
  4535. "magnetic_flux" "magnetic_flux_density" "magnetic_field_strength"
  4536. "inductance" "reluctance" "electrical" "electrical_vector" "magnetic"
  4537. "magnetic_vector" "voltage_vector" "current_vector" "mmf_vector"
  4538. "magnetic_flux_vector" "charge_vector" "resistance_vector"
  4539. "conductance_vector" "capacitance_vector" "electric_flux_vector"
  4540. "electric_flux_density_vector" "electric_field_strength_vector"
  4541. "magnetic_flux_density_vector" "magnetic_field_strength_vector"
  4542. "inductance_vector" "reluctance_vector" "ground"
  4543. ;; package `mechanical_systems'
  4544. "displacement" "force" "velocity" "acceleration" "mass" "stiffness"
  4545. "damping" "momentum" "angle" "torque" "angular_velocity"
  4546. "angular_acceleration" "moment_inertia" "angular_momentum"
  4547. "angular_stiffness" "angular_damping" "translational"
  4548. "translational_vector" "translational_velocity"
  4549. "translational_velocity_vector" "rotational" "rotational_vector"
  4550. "rotational_velocity" "rotational_velocity_vector" "displacement_vector"
  4551. "force_vector" "velocity_vector" "force_velocity_vector" "angle_vector"
  4552. "torque_vector" "angular_velocity_vector" "torque_velocity_vector"
  4553. "acceleration_vector" "mass_vector" "stiffness_vector" "damping_vector"
  4554. "momentum_vector" "angular_acceleration_vector" "moment_inertia_vector"
  4555. "angular_momentum_vector" "angular_stiffness_vector"
  4556. "angular_damping_vector" "anchor" "translational_v_ref"
  4557. "rotational_v_ref" "translational_v" "rotational_v"
  4558. ;; package `radiant_systems'
  4559. "illuminance" "luminous_flux" "luminous_intensity" "irradiance" "radiant"
  4560. "radiant_vector" "luminous_intensity_vector" "luminous_flux_vector"
  4561. "illuminance_vector" "irradiance_vector"
  4562. ;; package `thermal_systems'
  4563. "temperature" "heat_flow" "thermal_capacitance" "thermal_resistance"
  4564. "thermal_conductance" "thermal" "thermal_vector" "temperature_vector"
  4565. "heat_flow_vector" "thermal_capacitance_vector"
  4566. "thermal_resistance_vector" "thermal_conductance_vector"
  4567. ;; package `fluidic_systems'
  4568. "pressure" "vflow_rate" "mass_flow_rate" "volume" "density" "viscosity"
  4569. "fresistance" "fconductance" "fcapacitance" "inertance" "cfresistance"
  4570. "cfcapacitance" "cfinertance" "cfconductance" "fluidic" "fluidic_vector"
  4571. "compressible_fluidic" "compressible_fluidic_vector" "pressure_vector"
  4572. "vflow_rate_vector" "mass_flow_rate_vector" "volume_vector"
  4573. "density_vector" "viscosity_vector" "fresistance_vector"
  4574. "fconductance_vector" "fcapacitance_vector" "inertance_vector"
  4575. "cfresistance_vector" "cfconductance_vector" "cfcapacitance_vector"
  4576. "cfinertance_vector"
  4577. )
  4578. "List of VHDL-AMS standardized types.")
  4579. (defconst vhdl-math-types
  4580. '(
  4581. "complex" "complex_polar" "positive_real" "principal_value"
  4582. )
  4583. "List of Math Packages standardized types.")
  4584. (defconst vhdl-02-attributes
  4585. '(
  4586. "base" "left" "right" "high" "low" "pos" "val" "succ"
  4587. "pred" "leftof" "rightof" "range" "reverse_range"
  4588. "length" "delayed" "stable" "quiet" "transaction"
  4589. "event" "active" "last_event" "last_active" "last_value"
  4590. "driving" "driving_value" "ascending" "value" "image"
  4591. "simple_name" "instance_name" "path_name"
  4592. "foreign"
  4593. )
  4594. "List of VHDL'02 standardized attributes.")
  4595. (defconst vhdl-08-attributes
  4596. '(
  4597. "instance_name" "path_name"
  4598. )
  4599. "List of VHDL'08 standardized attributes.")
  4600. (defconst vhdl-ams-attributes
  4601. '(
  4602. "across" "through"
  4603. "reference" "contribution" "tolerance"
  4604. "dot" "integ" "delayed" "above" "zoh" "ltf" "ztf"
  4605. "ramp" "slew"
  4606. )
  4607. "List of VHDL-AMS standardized attributes.")
  4608. (defconst vhdl-02-enum-values
  4609. '(
  4610. "true" "false"
  4611. "note" "warning" "error" "failure"
  4612. "read_mode" "write_mode" "append_mode"
  4613. "open_ok" "status_error" "name_error" "mode_error"
  4614. "fs" "ps" "ns" "us" "ms" "sec" "min" "hr"
  4615. "right" "left"
  4616. )
  4617. "List of VHDL'02 standardized enumeration values.")
  4618. (defconst vhdl-ams-enum-values
  4619. '(
  4620. "quiescent_domain" "time_domain" "frequency_domain"
  4621. ;; from `nature_pkg' package
  4622. "eps0" "mu0" "ground" "mecvf_gnd" "mecpf_gnd" "rot_gnd" "fld_gnd"
  4623. )
  4624. "List of VHDL-AMS standardized enumeration values.")
  4625. (defconst vhdl-ams-constants
  4626. ;; standard: IEEE Std 1076.1.1-2004
  4627. '(
  4628. ;; package `fundamental_constants'
  4629. "phys_q" "phys_eps0" "phys_mu0" "phys_k" "phys_gravity" "phys_ctok"
  4630. "phys_c" "phys_h" "phys_h_over_2_pi" "yocto" "zepto" "atto" "femto"
  4631. "pico" "nano" "micro" "milli" "centi" "deci" "deka" "hecto" "kilo" "mega"
  4632. "giga" "tera" "peta" "exa" "zetta" "yotta" "deca"
  4633. ;; package `material_constants'
  4634. "phys_eps_si" "phys_eps_sio2" "phys_e_si" "phys_e_sio2" "phys_e_poly"
  4635. "phys_nu_si" "phys_nu_poly" "phys_rho_poly" "phys_rho_sio2"
  4636. "ambient_temperature" "ambient_pressure" "ambient_illuminance"
  4637. )
  4638. "List of VHDL-AMS standardized constants.")
  4639. (defconst vhdl-math-constants
  4640. ;; standard: IEEE Std 1076.2-1996
  4641. '(
  4642. "math_1_over_e" "math_1_over_pi" "math_1_over_sqrt_2" "math_2_pi"
  4643. "math_3_pi_over_2" "math_cbase_1" "math_cbase_j" "math_czero"
  4644. "math_deg_to_rad" "math_e" "math_log10_of_e" "math_log2_of_e"
  4645. "math_log_of_10" "math_log_of_2" "math_pi" "math_pi_over_2"
  4646. "math_pi_over_3" "math_pi_over_4" "math_rad_to_deg" "math_sqrt_2"
  4647. "math_sqrt_pi"
  4648. )
  4649. "List of Math Packages standardized constants.")
  4650. (defconst vhdl-02-functions
  4651. '(
  4652. "now" "resolved" "rising_edge" "falling_edge"
  4653. "read" "readline" "hread" "oread" "write" "writeline" "hwrite" "owrite"
  4654. "endfile"
  4655. "resize" "is_X" "std_match"
  4656. "shift_left" "shift_right" "rotate_left" "rotate_right"
  4657. "to_unsigned" "to_signed" "to_integer"
  4658. "to_stdLogicVector" "to_stdULogic" "to_stdULogicVector"
  4659. "to_bit" "to_bitVector" "to_X01" "to_X01Z" "to_UX01" "to_01"
  4660. "conv_unsigned" "conv_signed" "conv_integer" "conv_std_logic_vector"
  4661. "shl" "shr" "ext" "sxt"
  4662. "deallocate"
  4663. )
  4664. "List of VHDL'02 standardized functions.")
  4665. (defconst vhdl-08-functions
  4666. '(
  4667. "finish" "flush" "justify" "maximum" "minimum"
  4668. "resolution_limit" "rising_edge" "stop" "swrite"
  4669. "tee" "to_binarystring" "to_bstring" "to_hexstring" "to_hstring"
  4670. "to_octalstring" "to_ostring" "to_string"
  4671. )
  4672. "List of VHDL'08 standardized functions.")
  4673. (defconst vhdl-ams-functions
  4674. '(
  4675. ;; package `standard'
  4676. "frequency"
  4677. )
  4678. "List of VHDL-AMS standardized functions.")
  4679. (defconst vhdl-math-functions
  4680. ;; standard: IEEE Std 1076.2-1996
  4681. '(
  4682. "arccos" "arccosh" "arcsin" "arcsinh" "arctan" "arctanh" "arg"
  4683. "cbrt" "ceil" "cmplx" "complex_to_polar" "conj" "cos" "cosh" "exp"
  4684. "floor" "get_principal_value" "log" "log10" "log2" "polar_to_complex"
  4685. "realmax" "realmin" "round" "sign" "sin" "sinh" "sqrt"
  4686. "tan" "tanh" "trunc" "uniform"
  4687. )
  4688. "List of Math Packages standardized functions.")
  4689. (defconst vhdl-02-packages
  4690. '(
  4691. "std_logic_1164" "numeric_std" "numeric_bit"
  4692. "standard" "textio"
  4693. "std_logic_arith" "std_logic_signed" "std_logic_unsigned"
  4694. "std_logic_misc" "std_logic_textio"
  4695. "ieee" "std" "work"
  4696. )
  4697. "List of VHDL'02 standardized packages and libraries.")
  4698. (defconst vhdl-08-packages
  4699. '(
  4700. "env" "numeric_std_signed" "numeric_std_unsigned"
  4701. "ieee_bit_context" "ieee_std_context" ;; contexts
  4702. )
  4703. "List of VHDL'08 standardized packages and libraries.")
  4704. (defconst vhdl-ams-packages
  4705. '(
  4706. "fundamental_constants" "material_constants" "energy_systems"
  4707. "electrical_systems" "mechanical_systems" "radiant_systems"
  4708. "thermal_systems" "fluidic_systems"
  4709. )
  4710. "List of VHDL-AMS standardized packages and libraries.")
  4711. (defconst vhdl-math-packages
  4712. '(
  4713. "math_real" "math_complex"
  4714. )
  4715. "List of Math Packages standardized packages and libraries.")
  4716. (defconst vhdl-08-directives
  4717. '(
  4718. "author" "author_info" "begin" "begin_protected" "comment"
  4719. "data_block" "data_keyname" "data_keyowner" "data_method"
  4720. "decrypt_license" "digest_block" "digest_key_method" "digest_keyname"
  4721. "digest_keyowner" "digest_method"
  4722. "encoding" "encrypt_agent" "encrypt_agent_info" "end" "end_protected"
  4723. "key_block" "key_keyname" "key_keyowner" "key_method"
  4724. "runtime_license" "viewport"
  4725. )
  4726. "List of VHDL'08 standardized tool directives.")
  4727. (defvar vhdl-keywords nil
  4728. "List of VHDL keywords.")
  4729. (defvar vhdl-types nil
  4730. "List of VHDL standardized types.")
  4731. (defvar vhdl-attributes nil
  4732. "List of VHDL standardized attributes.")
  4733. (defvar vhdl-enum-values nil
  4734. "List of VHDL standardized enumeration values.")
  4735. (defvar vhdl-constants nil
  4736. "List of VHDL standardized constants.")
  4737. (defvar vhdl-functions nil
  4738. "List of VHDL standardized functions.")
  4739. (defvar vhdl-packages nil
  4740. "List of VHDL standardized packages and libraries.")
  4741. (defvar vhdl-directives nil
  4742. "List of VHDL standardized packages and libraries.")
  4743. (defvar vhdl-reserved-words nil
  4744. "List of additional reserved words.")
  4745. (defvar vhdl-keywords-regexp nil
  4746. "Regexp for VHDL keywords.")
  4747. (defvar vhdl-types-regexp nil
  4748. "Regexp for VHDL standardized types.")
  4749. (defvar vhdl-attributes-regexp nil
  4750. "Regexp for VHDL standardized attributes.")
  4751. (defvar vhdl-enum-values-regexp nil
  4752. "Regexp for VHDL standardized enumeration values.")
  4753. (defvar vhdl-constants-regexp nil
  4754. "Regexp for VHDL standardized constants.")
  4755. (defvar vhdl-functions-regexp nil
  4756. "Regexp for VHDL standardized functions.")
  4757. (defvar vhdl-packages-regexp nil
  4758. "Regexp for VHDL standardized packages and libraries.")
  4759. (defvar vhdl-reserved-words-regexp nil
  4760. "Regexp for additional reserved words.")
  4761. (defvar vhdl-directive-keywords-regexp nil
  4762. "Regexp for compiler directive keywords.")
  4763. (defun vhdl-upcase-list (condition list)
  4764. "Upcase all elements in LIST based on CONDITION."
  4765. (when condition
  4766. (let ((tmp-list list))
  4767. (while tmp-list
  4768. (setcar tmp-list (upcase (car tmp-list)))
  4769. (setq tmp-list (cdr tmp-list)))))
  4770. list)
  4771. (defun vhdl-words-init ()
  4772. "Initialize reserved words."
  4773. (setq vhdl-keywords
  4774. (vhdl-upcase-list
  4775. (and vhdl-highlight-case-sensitive vhdl-upper-case-keywords)
  4776. (append vhdl-02-keywords
  4777. (when (vhdl-standard-p '08) vhdl-08-keywords)
  4778. (when (vhdl-standard-p 'ams) vhdl-ams-keywords))))
  4779. (setq vhdl-types
  4780. (vhdl-upcase-list
  4781. (and vhdl-highlight-case-sensitive vhdl-upper-case-types)
  4782. (append vhdl-02-types
  4783. (when (vhdl-standard-p '08) vhdl-08-types)
  4784. (when (vhdl-standard-p 'ams) vhdl-ams-types)
  4785. (when (vhdl-standard-p 'math) vhdl-math-types))))
  4786. (setq vhdl-attributes
  4787. (vhdl-upcase-list
  4788. (and vhdl-highlight-case-sensitive vhdl-upper-case-attributes)
  4789. (append vhdl-02-attributes
  4790. (when (vhdl-standard-p '08) vhdl-08-attributes)
  4791. (when (vhdl-standard-p 'ams) vhdl-ams-attributes))))
  4792. (setq vhdl-enum-values
  4793. (vhdl-upcase-list
  4794. (and vhdl-highlight-case-sensitive vhdl-upper-case-enum-values)
  4795. (append vhdl-02-enum-values
  4796. (when (vhdl-standard-p 'ams) vhdl-ams-enum-values))))
  4797. (setq vhdl-constants
  4798. (vhdl-upcase-list
  4799. (and vhdl-highlight-case-sensitive vhdl-upper-case-constants)
  4800. (append (when (vhdl-standard-p 'ams) vhdl-ams-constants)
  4801. (when (vhdl-standard-p 'math) vhdl-math-constants)
  4802. '(""))))
  4803. (setq vhdl-functions
  4804. (append vhdl-02-functions
  4805. (when (vhdl-standard-p '08) vhdl-08-functions)
  4806. (when (vhdl-standard-p 'ams) vhdl-ams-functions)
  4807. (when (vhdl-standard-p 'math) vhdl-math-functions)))
  4808. (setq vhdl-packages
  4809. (append vhdl-02-packages
  4810. (when (vhdl-standard-p '08) vhdl-08-packages)
  4811. (when (vhdl-standard-p 'ams) vhdl-ams-packages)
  4812. (when (vhdl-standard-p 'math) vhdl-math-packages)))
  4813. (setq vhdl-directives
  4814. (append (when (vhdl-standard-p '08) vhdl-08-directives)))
  4815. (setq vhdl-reserved-words
  4816. (append (when vhdl-highlight-forbidden-words vhdl-forbidden-words)
  4817. (when vhdl-highlight-verilog-keywords vhdl-verilog-keywords)
  4818. '("")))
  4819. (setq vhdl-keywords-regexp
  4820. (concat "\\<\\(" (regexp-opt vhdl-keywords) "\\)\\>"))
  4821. (setq vhdl-types-regexp
  4822. (concat "\\<\\(" (regexp-opt vhdl-types) "\\)\\>"))
  4823. (setq vhdl-attributes-regexp
  4824. (concat "\\<\\(" (regexp-opt vhdl-attributes) "\\)\\>"))
  4825. (setq vhdl-enum-values-regexp
  4826. (concat "\\<\\(" (regexp-opt vhdl-enum-values) "\\)\\>"))
  4827. (setq vhdl-constants-regexp
  4828. (concat "\\<\\(" (regexp-opt vhdl-constants) "\\)\\>"))
  4829. (setq vhdl-functions-regexp
  4830. (concat "\\<\\(" (regexp-opt vhdl-functions) "\\)\\>"))
  4831. (setq vhdl-packages-regexp
  4832. (concat "\\<\\(" (regexp-opt vhdl-packages) "\\)\\>"))
  4833. (setq vhdl-reserved-words-regexp
  4834. (concat "\\<\\("
  4835. (unless (equal vhdl-forbidden-syntax "")
  4836. (concat vhdl-forbidden-syntax "\\|"))
  4837. (regexp-opt vhdl-reserved-words)
  4838. "\\)\\>"))
  4839. (setq vhdl-directive-keywords-regexp
  4840. (concat "\\<\\(" (mapconcat 'regexp-quote
  4841. vhdl-directive-keywords "\\|") "\\)\\>"))
  4842. (vhdl-abbrev-list-init))
  4843. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4844. ;; Words to expand
  4845. (defvar vhdl-abbrev-list nil
  4846. "Predefined abbreviations for VHDL.")
  4847. (defun vhdl-abbrev-list-init ()
  4848. (setq vhdl-abbrev-list
  4849. (append
  4850. (list vhdl-upper-case-keywords) vhdl-keywords
  4851. (list vhdl-upper-case-types) vhdl-types
  4852. (list vhdl-upper-case-attributes) vhdl-attributes
  4853. (list vhdl-upper-case-enum-values) vhdl-enum-values
  4854. (list vhdl-upper-case-constants) vhdl-constants
  4855. (list nil) vhdl-functions
  4856. (list nil) vhdl-packages
  4857. (list nil) vhdl-directives)))
  4858. ;; initialize reserved words for VHDL Mode
  4859. (vhdl-words-init)
  4860. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4861. ;;; Indentation
  4862. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4863. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4864. ;; Syntax analysis
  4865. ;; constant regular expressions for looking at various constructs
  4866. (defconst vhdl-symbol-key "\\(\\w\\|\\s_\\)+"
  4867. "Regexp describing a VHDL symbol.
  4868. We cannot use just `word' syntax class since `_' cannot be in word
  4869. class. Putting underscore in word class breaks forward word movement
  4870. behavior that users are familiar with.")
  4871. (defconst vhdl-case-header-key "case[( \t\n\r\f][^;=>]+[) \t\n\r\f]is"
  4872. "Regexp describing a case statement header key.")
  4873. (defconst vhdl-label-key
  4874. (concat "\\(" vhdl-symbol-key "\\s-*:\\)[^=]")
  4875. "Regexp describing a VHDL label.")
  4876. ;; Macro definitions:
  4877. (defmacro vhdl-point (position)
  4878. "Return the value of point at certain commonly referenced POSITIONs.
  4879. POSITION can be one of the following symbols:
  4880. bol -- beginning of line
  4881. eol -- end of line
  4882. bod -- beginning of defun
  4883. boi -- back to indentation
  4884. eoi -- last whitespace on line
  4885. ionl -- indentation of next line
  4886. iopl -- indentation of previous line
  4887. bonl -- beginning of next line
  4888. bopl -- beginning of previous line
  4889. This function does not modify point or mark."
  4890. (or (and (eq 'quote (car-safe position))
  4891. (null (cddr position)))
  4892. (error "ERROR: Bad buffer position requested: %s" position))
  4893. (setq position (nth 1 position))
  4894. `(let ((here (point)))
  4895. ,@(cond
  4896. ((eq position 'bol) '((beginning-of-line)))
  4897. ((eq position 'eol) '((end-of-line)))
  4898. ((eq position 'bod) '((save-match-data
  4899. (vhdl-beginning-of-defun))))
  4900. ((eq position 'boi) '((back-to-indentation)))
  4901. ((eq position 'eoi) '((end-of-line) (skip-chars-backward " \t")))
  4902. ((eq position 'bonl) '((forward-line 1)))
  4903. ((eq position 'bopl) '((forward-line -1)))
  4904. ((eq position 'iopl)
  4905. '((forward-line -1)
  4906. (back-to-indentation)))
  4907. ((eq position 'ionl)
  4908. '((forward-line 1)
  4909. (back-to-indentation)))
  4910. (t (error "ERROR: Unknown buffer position requested: %s" position))
  4911. )
  4912. (prog1
  4913. (point)
  4914. (goto-char here))
  4915. ;; workaround for an Emacs18 bug -- blech! Well, at least it
  4916. ;; doesn't hurt for v19
  4917. ,@nil
  4918. ))
  4919. (defmacro vhdl-safe (&rest body)
  4920. "Safely execute BODY, return nil if an error occurred."
  4921. `(condition-case nil
  4922. (progn ,@body)
  4923. (error nil)))
  4924. (defmacro vhdl-add-syntax (symbol &optional relpos)
  4925. "A simple macro to append the syntax in SYMBOL to the syntax list.
  4926. Try to increase performance by using this macro."
  4927. `(setq vhdl-syntactic-context
  4928. (cons (cons ,symbol ,relpos) vhdl-syntactic-context)))
  4929. (defmacro vhdl-has-syntax (symbol)
  4930. "A simple macro to return check the syntax list.
  4931. Try to increase performance by using this macro."
  4932. `(assoc ,symbol vhdl-syntactic-context))
  4933. ;; Syntactic element offset manipulation:
  4934. (defun vhdl-read-offset (langelem)
  4935. "Read new offset value for LANGELEM from minibuffer.
  4936. Return a valid value only."
  4937. (let ((oldoff (format "%s" (cdr-safe (assq langelem vhdl-offsets-alist))))
  4938. (errmsg "Offset must be int, func, var, or one of +, -, ++, --: ")
  4939. (prompt "Offset: ")
  4940. offset input interned)
  4941. (while (not offset)
  4942. (setq input (read-string prompt oldoff)
  4943. offset (cond ((string-equal "+" input) '+)
  4944. ((string-equal "-" input) '-)
  4945. ((string-equal "++" input) '++)
  4946. ((string-equal "--" input) '--)
  4947. ((string-match "^-?[0-9]+$" input)
  4948. (string-to-number input))
  4949. ((fboundp (setq interned (intern input)))
  4950. interned)
  4951. ((boundp interned) interned)
  4952. ;; error, but don't signal one, keep trying
  4953. ;; to read an input value
  4954. (t (ding)
  4955. (setq prompt errmsg)
  4956. nil))))
  4957. offset))
  4958. (defun vhdl-set-offset (symbol offset &optional add-p)
  4959. "Change the value of a syntactic element symbol in `vhdl-offsets-alist'.
  4960. SYMBOL is the syntactic element symbol to change and OFFSET is the new
  4961. offset for that syntactic element. Optional ADD-P says to add SYMBOL to
  4962. `vhdl-offsets-alist' if it doesn't already appear there."
  4963. (interactive
  4964. (let* ((langelem
  4965. (intern (completing-read
  4966. (concat "Syntactic symbol to change"
  4967. (if current-prefix-arg " or add" "")
  4968. ": ")
  4969. (mapcar
  4970. (function
  4971. (lambda (langelem)
  4972. (cons (format "%s" (car langelem)) nil)))
  4973. vhdl-offsets-alist)
  4974. nil (not current-prefix-arg)
  4975. ;; initial contents tries to be the last element
  4976. ;; on the syntactic analysis list for the current
  4977. ;; line
  4978. (let* ((syntax (vhdl-get-syntactic-context))
  4979. (len (length syntax))
  4980. (ic (format "%s" (car (nth (1- len) syntax)))))
  4981. ic)
  4982. )))
  4983. (offset (vhdl-read-offset langelem)))
  4984. (list langelem offset current-prefix-arg)))
  4985. ;; sanity check offset
  4986. (or (eq offset '+)
  4987. (eq offset '-)
  4988. (eq offset '++)
  4989. (eq offset '--)
  4990. (integerp offset)
  4991. (fboundp offset)
  4992. (boundp offset)
  4993. (error "ERROR: Offset must be int, func, var, or one of +, -, ++, --: %s"
  4994. offset))
  4995. (let ((entry (assq symbol vhdl-offsets-alist)))
  4996. (if entry
  4997. (setcdr entry offset)
  4998. (if add-p
  4999. (setq vhdl-offsets-alist
  5000. (cons (cons symbol offset) vhdl-offsets-alist))
  5001. (error "ERROR: %s is not a valid syntactic symbol" symbol))))
  5002. (vhdl-keep-region-active))
  5003. (defun vhdl-set-style (style &optional local)
  5004. "Set `vhdl-mode' variables to use one of several different indentation styles.
  5005. STYLE is a string representing the desired style and optional LOCAL is
  5006. a flag which, if non-nil, means to make the style variables being
  5007. changed buffer local, instead of the default, which is to set the
  5008. global variables. Interactively, the flag comes from the prefix
  5009. argument. The styles are chosen from the `vhdl-style-alist' variable."
  5010. (interactive (list (completing-read "Use which VHDL indentation style? "
  5011. vhdl-style-alist nil t)
  5012. current-prefix-arg))
  5013. (let ((vars (cdr (assoc style vhdl-style-alist))))
  5014. (or vars
  5015. (error "ERROR: Invalid VHDL indentation style `%s'" style))
  5016. ;; set all the variables
  5017. (mapc
  5018. (function
  5019. (lambda (varentry)
  5020. (let ((var (car varentry))
  5021. (val (cdr varentry)))
  5022. ;; special case for vhdl-offsets-alist
  5023. (if (not (eq var 'vhdl-offsets-alist))
  5024. (set (if local (make-local-variable var) var) val)
  5025. ;; reset vhdl-offsets-alist to the default value first
  5026. (set (if local (make-local-variable var) var)
  5027. (copy-alist vhdl-offsets-alist-default))
  5028. ;; now set the langelems that are different
  5029. (mapcar
  5030. (function
  5031. (lambda (langentry)
  5032. (let ((langelem (car langentry))
  5033. (offset (cdr langentry)))
  5034. (vhdl-set-offset langelem offset)
  5035. )))
  5036. val))
  5037. )))
  5038. vars))
  5039. (vhdl-keep-region-active))
  5040. (defun vhdl-get-offset (langelem)
  5041. "Get offset from LANGELEM which is a cons cell of the form:
  5042. \(SYMBOL . RELPOS). The symbol is matched against
  5043. vhdl-offsets-alist and the offset found there is either returned,
  5044. or added to the indentation at RELPOS. If RELPOS is nil, then
  5045. the offset is simply returned."
  5046. (let* ((symbol (car langelem))
  5047. (relpos (cdr langelem))
  5048. (match (assq symbol vhdl-offsets-alist))
  5049. (offset (cdr-safe match)))
  5050. ;; offset can be a number, a function, a variable, or one of the
  5051. ;; symbols + or -
  5052. (cond
  5053. ((not match)
  5054. (if vhdl-strict-syntax-p
  5055. (error "ERROR: Don't know how to indent a %s" symbol)
  5056. (setq offset 0
  5057. relpos 0)))
  5058. ((eq offset '+) (setq offset vhdl-basic-offset))
  5059. ((eq offset '-) (setq offset (- vhdl-basic-offset)))
  5060. ((eq offset '++) (setq offset (* 2 vhdl-basic-offset)))
  5061. ((eq offset '--) (setq offset (* 2 (- vhdl-basic-offset))))
  5062. ((and (not (numberp offset))
  5063. (fboundp offset))
  5064. (setq offset (funcall offset langelem)))
  5065. ((not (numberp offset))
  5066. (setq offset (eval offset)))
  5067. )
  5068. (+ (if (and relpos
  5069. (< relpos (vhdl-point 'bol)))
  5070. (save-excursion
  5071. (goto-char relpos)
  5072. (current-column))
  5073. 0)
  5074. offset)))
  5075. ;; Syntactic support functions:
  5076. (defun vhdl-in-comment-p (&optional pos)
  5077. "Check if point is in a comment (include multi-line comments)."
  5078. (let ((parse (lambda (p)
  5079. (let ((c (char-after p)))
  5080. (or (and c (eq (char-syntax c) ?<))
  5081. (nth 4 (parse-partial-sexp
  5082. (save-excursion
  5083. (beginning-of-defun)
  5084. (point)) p)))))))
  5085. (save-excursion
  5086. (goto-char (or pos (point)))
  5087. (or (funcall parse (point))
  5088. ;; `parse-partial-sexp's notion of comments doesn't span lines
  5089. (progn
  5090. (back-to-indentation)
  5091. (unless (eolp)
  5092. (forward-char)
  5093. (funcall parse (point))))))))
  5094. (defun vhdl-in-string-p ()
  5095. "Check if point is in a string."
  5096. (eq (vhdl-in-literal) 'string))
  5097. (defun vhdl-in-quote-p ()
  5098. "Check if point is in a quote ('x')."
  5099. (or (and (> (point) (point-min))
  5100. (< (1+ (point)) (point-max))
  5101. (= (char-before (point)) ?\')
  5102. (= (char-after (1+ (point))) ?\'))
  5103. (and (> (1- (point)) (point-min))
  5104. (< (point) (point-max))
  5105. (= (char-before (1- (point))) ?\')
  5106. (= (char-after (point)) ?\'))))
  5107. (defun vhdl-in-literal ()
  5108. "Determine if point is in a VHDL literal."
  5109. (save-excursion
  5110. (let ((state (parse-partial-sexp (vhdl-point 'bol) (point))))
  5111. (cond
  5112. ((nth 3 state) 'string)
  5113. ((nth 4 state) 'comment)
  5114. ((vhdl-beginning-of-macro) 'pound)
  5115. ((vhdl-beginning-of-directive) 'directive)
  5116. ;; for multi-line comments
  5117. ((and (vhdl-standard-p '08) (vhdl-in-comment-p)) 'comment)
  5118. (t nil)))))
  5119. (defun vhdl-in-extended-identifier-p ()
  5120. "Determine if point is inside extended identifier (delimited by `\\')."
  5121. (save-match-data
  5122. (and (save-excursion (re-search-backward "\\\\" (vhdl-point 'bol) t))
  5123. (save-excursion (re-search-forward "\\\\" (vhdl-point 'eol) t)))))
  5124. (defun vhdl-forward-comment (&optional direction)
  5125. "Skip all comments (including whitespace). Skip backwards if DIRECTION is
  5126. negative, skip forward otherwise."
  5127. (interactive "p")
  5128. (if (and direction (< direction 0))
  5129. ;; skip backwards
  5130. (progn
  5131. (skip-chars-backward " \t\n\r\f")
  5132. (while (re-search-backward "^[^\"-]*\\(\\(-?\"[^\"]*\"\\|-[^\"-]\\)[^\"-]*\\)*\\(--\\)" (vhdl-point 'bol) t)
  5133. (goto-char (match-beginning 3))
  5134. (skip-chars-backward " \t\n\r\f")))
  5135. ;; skip forwards
  5136. (skip-chars-forward " \t\n\r\f")
  5137. (while (looking-at "--.*")
  5138. (goto-char (match-end 0))
  5139. (skip-chars-forward " \t\n\r\f"))))
  5140. ;; XEmacs hack: work around buggy `forward-comment' in XEmacs 21.4+
  5141. (unless (and (featurep 'xemacs) (string< "21.2" emacs-version))
  5142. (defalias 'vhdl-forward-comment 'forward-comment))
  5143. (defun vhdl-back-to-indentation ()
  5144. "Move point to the first non-whitespace character on this line."
  5145. (interactive)
  5146. (beginning-of-line 1)
  5147. (skip-syntax-forward " " (vhdl-point 'eol)))
  5148. ;; XEmacs hack: work around old `back-to-indentation' in XEmacs
  5149. (when (featurep 'xemacs)
  5150. (defalias 'back-to-indentation 'vhdl-back-to-indentation))
  5151. ;; This is the best we can do in Win-Emacs.
  5152. (defun vhdl-win-il (&optional lim)
  5153. "Determine if point is in a VHDL literal."
  5154. (save-excursion
  5155. (let* ((here (point))
  5156. (state nil)
  5157. (match nil)
  5158. (lim (or lim (vhdl-point 'bod))))
  5159. (goto-char lim )
  5160. (while (< (point) here)
  5161. (setq match
  5162. (and (re-search-forward "--\\|[\"']\\|`"
  5163. here 'move)
  5164. (buffer-substring (match-beginning 0) (match-end 0))))
  5165. (setq state
  5166. (cond
  5167. ;; no match
  5168. ((null match) nil)
  5169. ;; looking at the opening of a VHDL style comment
  5170. ((string= "--" match)
  5171. (if (<= here (progn (end-of-line) (point))) 'comment))
  5172. ;; looking at a directive
  5173. ((string= "`" match)
  5174. (if (<= here (progn (end-of-line) (point))) 'directive))
  5175. ;; looking at the opening of a double quote string
  5176. ((string= "\"" match)
  5177. (if (not (save-restriction
  5178. ;; this seems to be necessary since the
  5179. ;; re-search-forward will not work without it
  5180. (narrow-to-region (point) here)
  5181. (re-search-forward
  5182. ;; this regexp matches a double quote
  5183. ;; which is preceded by an even number
  5184. ;; of backslashes, including zero
  5185. "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
  5186. 'string))
  5187. ;; looking at the opening of a single quote string
  5188. ((string= "'" match)
  5189. (if (not (save-restriction
  5190. ;; see comments from above
  5191. (narrow-to-region (point) here)
  5192. (re-search-forward
  5193. ;; this matches a single quote which is
  5194. ;; preceded by zero or two backslashes.
  5195. "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
  5196. here 'move)))
  5197. 'string))
  5198. (t nil)))
  5199. ) ; end-while
  5200. state)))
  5201. (and (string-match "Win-Emacs" emacs-version)
  5202. (fset 'vhdl-in-literal 'vhdl-win-il))
  5203. ;; Skipping of "syntactic whitespace". Syntactic whitespace is
  5204. ;; defined as lexical whitespace or comments. Search no farther back
  5205. ;; or forward than optional LIM. If LIM is omitted, (point-min) is
  5206. ;; used for backward skipping, (point-max) is used for forward
  5207. ;; skipping.
  5208. (defun vhdl-forward-syntactic-ws (&optional lim)
  5209. "Forward skip of syntactic whitespace."
  5210. (let* ((here (point-max))
  5211. (hugenum (point-max)))
  5212. (while (/= here (point))
  5213. (setq here (point))
  5214. (vhdl-forward-comment hugenum)
  5215. ;; skip preprocessor directives
  5216. (when (and (or (eq (char-after) ?#) (eq (char-after) ?`))
  5217. (= (vhdl-point 'boi) (point)))
  5218. (while (and (eq (char-before (vhdl-point 'eol)) ?\\)
  5219. (= (forward-line 1) 0)))
  5220. (end-of-line)))
  5221. (if lim (goto-char (min (point) lim)))))
  5222. ;; This is the best we can do in Win-Emacs.
  5223. (defun vhdl-win-fsws (&optional lim)
  5224. "Forward skip syntactic whitespace for Win-Emacs."
  5225. (let ((lim (or lim (point-max)))
  5226. stop)
  5227. (while (not stop)
  5228. (skip-chars-forward " \t\n\r\f" lim)
  5229. (cond
  5230. ;; vhdl comment
  5231. ((looking-at "--") (end-of-line))
  5232. ;; none of the above
  5233. (t (setq stop t))))))
  5234. (and (string-match "Win-Emacs" emacs-version)
  5235. (fset 'vhdl-forward-syntactic-ws 'vhdl-win-fsws))
  5236. (defun vhdl-beginning-of-macro (&optional lim)
  5237. "Go to the beginning of a cpp macro definition (nicked from `cc-engine')."
  5238. (let ((here (point)))
  5239. (beginning-of-line)
  5240. (while (eq (char-before (1- (point))) ?\\)
  5241. (forward-line -1))
  5242. (back-to-indentation)
  5243. (if (and (<= (point) here)
  5244. (eq (char-after) ?#))
  5245. t
  5246. (goto-char here)
  5247. nil)))
  5248. (defun vhdl-beginning-of-directive (&optional lim)
  5249. "Go to the beginning of a directive (nicked from `cc-engine')."
  5250. (let ((here (point)))
  5251. (beginning-of-line)
  5252. (while (eq (char-before (1- (point))) ?\\)
  5253. (forward-line -1))
  5254. (back-to-indentation)
  5255. (if (and (<= (point) here)
  5256. (eq (char-after) ?`))
  5257. t
  5258. (goto-char here)
  5259. nil)))
  5260. (defun vhdl-backward-syntactic-ws (&optional lim)
  5261. "Backward skip over syntactic whitespace."
  5262. (let* ((here (point-min))
  5263. (hugenum (- (point-max))))
  5264. (while (/= here (point))
  5265. (setq here (point))
  5266. (vhdl-forward-comment hugenum)
  5267. (vhdl-beginning-of-macro))
  5268. (if lim (goto-char (max (point) lim)))))
  5269. ;; This is the best we can do in Win-Emacs.
  5270. (defun vhdl-win-bsws (&optional lim)
  5271. "Backward skip syntactic whitespace for Win-Emacs."
  5272. (let ((lim (or lim (vhdl-point 'bod)))
  5273. stop)
  5274. (while (not stop)
  5275. (skip-chars-backward " \t\n\r\f" lim)
  5276. (cond
  5277. ;; vhdl comment
  5278. ((eq (vhdl-in-literal) 'comment)
  5279. (skip-chars-backward "^-" lim)
  5280. (skip-chars-backward "-" lim)
  5281. (while (not (or (and (= (following-char) ?-)
  5282. (= (char-after (1+ (point))) ?-))
  5283. (<= (point) lim)))
  5284. (skip-chars-backward "^-" lim)
  5285. (skip-chars-backward "-" lim)))
  5286. ;; none of the above
  5287. (t (setq stop t))))))
  5288. (and (string-match "Win-Emacs" emacs-version)
  5289. (fset 'vhdl-backward-syntactic-ws 'vhdl-win-bsws))
  5290. ;; Functions to help finding the correct indentation column:
  5291. (defun vhdl-first-word (point)
  5292. "If the keyword at POINT is at boi, then return (current-column) at
  5293. that point, else nil."
  5294. (save-excursion
  5295. (and (goto-char point)
  5296. (eq (point) (vhdl-point 'boi))
  5297. (current-column))))
  5298. (defun vhdl-last-word (point)
  5299. "If the keyword at POINT is at eoi, then return (current-column) at
  5300. that point, else nil."
  5301. (save-excursion
  5302. (and (goto-char point)
  5303. (save-excursion (or (eq (progn (forward-sexp) (point))
  5304. (vhdl-point 'eoi))
  5305. (looking-at "\\s-*\\(--\\)?")))
  5306. (current-column))))
  5307. ;; Core syntactic evaluation functions:
  5308. (defconst vhdl-libunit-re
  5309. "\\b\\(architecture\\|configuration\\|context\\|entity\\|package\\)\\b[^_]")
  5310. (defun vhdl-libunit-p ()
  5311. (and
  5312. (save-excursion
  5313. (forward-sexp)
  5314. (skip-chars-forward " \t\n\r\f")
  5315. (not (looking-at "is\\b[^_]")))
  5316. (save-excursion
  5317. (backward-sexp)
  5318. (and (not (looking-at "use\\b[^_]"))
  5319. (progn
  5320. (forward-sexp)
  5321. (vhdl-forward-syntactic-ws)
  5322. (/= (following-char) ?:))))
  5323. ))
  5324. (defconst vhdl-defun-re
  5325. "\\b\\(architecture\\|block\\|configuration\\|context\\|entity\\|package\\|process\\|procedural\\|procedure\\|function\\)\\b[^_]")
  5326. (defun vhdl-defun-p ()
  5327. (save-excursion
  5328. (if (looking-at "block\\|process\\|procedural")
  5329. ;; "block", "process", "procedural":
  5330. (save-excursion
  5331. (backward-sexp)
  5332. (not (looking-at "end\\s-+\\w")))
  5333. ;; "architecture", "configuration", "context", "entity",
  5334. ;; "package", "procedure", "function":
  5335. t)))
  5336. (defun vhdl-corresponding-defun ()
  5337. "If the word at the current position corresponds to a \"defun\"
  5338. keyword, then return a string that can be used to find the
  5339. corresponding \"begin\" keyword, else return nil."
  5340. (save-excursion
  5341. (and (looking-at vhdl-defun-re)
  5342. (vhdl-defun-p)
  5343. (if (looking-at "block\\|process\\|procedural")
  5344. ;; "block", "process". "procedural:
  5345. (buffer-substring (match-beginning 0) (match-end 0))
  5346. ;; "architecture", "configuration", "context", "entity", "package",
  5347. ;; "procedure", "function":
  5348. "is"))))
  5349. (defconst vhdl-begin-fwd-re
  5350. "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\(\\s-+body\\)?\\|units\\|use\\|record\\|protected\\(\\s-+body\\)?\\|for\\)\\b\\([^_]\\|\\'\\)"
  5351. "A regular expression for searching forward that matches all known
  5352. \"begin\" keywords.")
  5353. (defconst vhdl-begin-bwd-re
  5354. "\\b\\(is\\|begin\\|block\\|component\\|generate\\|then\\|else\\|loop\\|process\\|procedural\\(\\s-+body\\)?\\|units\\|use\\|record\\|protected\\(\\s-+body\\)?\\|for\\)\\b[^_]"
  5355. "A regular expression for searching backward that matches all known
  5356. \"begin\" keywords.")
  5357. (defun vhdl-begin-p (&optional lim)
  5358. "Return t if we are looking at a real \"begin\" keyword.
  5359. Assumes that the caller will make sure that we are looking at
  5360. vhdl-begin-fwd-re, and are not inside a literal, and that we are not in
  5361. the middle of an identifier that just happens to contain a \"begin\"
  5362. keyword."
  5363. (cond
  5364. ;; "[architecture|case|configuration|context|entity|package|
  5365. ;; procedure|function] ... is":
  5366. ((and (looking-at "i")
  5367. (save-excursion
  5368. ;; Skip backward over first sexp (needed to skip over a
  5369. ;; procedure interface list, and is harmless in other
  5370. ;; situations). Note that we need "return" in the
  5371. ;; following search list so that we don't run into
  5372. ;; semicolons in the function interface list.
  5373. (backward-sexp)
  5374. (let (foundp)
  5375. (while (and (not foundp)
  5376. (re-search-backward
  5377. ";\\|\\b\\(architecture\\|case\\|configuration\\|context\\|entity\\|package\\|procedure\\|return\\|is\\|begin\\|process\\|procedural\\|block\\)\\b[^_]"
  5378. lim 'move))
  5379. (if (or (= (preceding-char) ?_)
  5380. (vhdl-in-literal))
  5381. (backward-char)
  5382. (setq foundp t))))
  5383. (and (/= (following-char) ?\;)
  5384. (not (looking-at "is\\|begin\\|process\\|procedural\\|block")))))
  5385. t)
  5386. ;; "begin", "then", "use":
  5387. ((looking-at "be\\|t\\|use")
  5388. t)
  5389. ;; "else":
  5390. ((and (looking-at "e")
  5391. ;; make sure that the "else" isn't inside a
  5392. ;; conditional signal assignment.
  5393. (save-excursion
  5394. (vhdl-re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
  5395. (or (eq (following-char) ?\;)
  5396. (eq (point) lim))))
  5397. t)
  5398. ;; "block", "generate", "loop", "process", "procedural",
  5399. ;; "units", "record", "protected body":
  5400. ((and (looking-at "block\\|generate\\|loop\\|process\\|procedural\\|protected\\(\\s-+body\\)?\\|units\\|record")
  5401. (save-excursion
  5402. (backward-sexp)
  5403. (not (looking-at "end\\s-+\\w"))))
  5404. t)
  5405. ;; "component":
  5406. ((and (looking-at "c")
  5407. (save-excursion
  5408. (backward-sexp)
  5409. (not (looking-at "end\\s-+\\w")))
  5410. ;; look out for the dreaded entity class in an attribute
  5411. (save-excursion
  5412. (vhdl-backward-syntactic-ws lim)
  5413. (/= (preceding-char) ?:)))
  5414. t)
  5415. ;; "for" (inside configuration declaration):
  5416. ((and (looking-at "f")
  5417. (save-excursion
  5418. (backward-sexp)
  5419. (not (looking-at "end\\s-+\\w")))
  5420. (vhdl-has-syntax 'configuration))
  5421. t)
  5422. ))
  5423. (defun vhdl-corresponding-mid (&optional lim)
  5424. (cond
  5425. ((looking-at "is\\|block\\|generate\\|process\\|procedural")
  5426. "begin")
  5427. ((looking-at "then\\|use")
  5428. "<else>")
  5429. (t
  5430. "end")))
  5431. (defun vhdl-corresponding-end (&optional lim)
  5432. "If the word at the current position corresponds to a \"begin\"
  5433. keyword, then return a vector containing enough information to find
  5434. the corresponding \"end\" keyword, else return nil. The keyword to
  5435. search forward for is aref 0. The column in which the keyword must
  5436. appear is aref 1 or nil if any column is suitable.
  5437. Assumes that the caller will make sure that we are not in the middle
  5438. of an identifier that just happens to contain a \"begin\" keyword."
  5439. (save-excursion
  5440. (and (looking-at vhdl-begin-fwd-re)
  5441. (or (not (looking-at "\\<use\\>"))
  5442. (save-excursion (back-to-indentation)
  5443. (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
  5444. (/= (preceding-char) ?_)
  5445. (not (vhdl-in-literal))
  5446. (vhdl-begin-p lim)
  5447. (cond
  5448. ;; "is", "generate", "loop":
  5449. ((looking-at "[igl]")
  5450. (vector "end"
  5451. (and (vhdl-last-word (point))
  5452. (or (vhdl-first-word (point))
  5453. (save-excursion
  5454. (vhdl-beginning-of-statement-1 lim)
  5455. (vhdl-backward-skip-label lim)
  5456. (vhdl-first-word (point)))))))
  5457. ;; "begin", "else", "for":
  5458. ((looking-at "be\\|[ef]")
  5459. (vector "end"
  5460. (and (vhdl-last-word (point))
  5461. (or (vhdl-first-word (point))
  5462. (save-excursion
  5463. (vhdl-beginning-of-statement-1 lim)
  5464. (vhdl-backward-skip-label lim)
  5465. (vhdl-first-word (point)))))))
  5466. ;; "component", "units", "record", "protected body":
  5467. ((looking-at "component\\|units\\|protected\\(\\s-+body\\)?\\|record")
  5468. ;; The first end found will close the block
  5469. (vector "end" nil))
  5470. ;; "block", "process", "procedural":
  5471. ((looking-at "bl\\|p")
  5472. (vector "end"
  5473. (or (vhdl-first-word (point))
  5474. (save-excursion
  5475. (vhdl-beginning-of-statement-1 lim)
  5476. (vhdl-backward-skip-label lim)
  5477. (vhdl-first-word (point))))))
  5478. ;; "then":
  5479. ((looking-at "t\\|use")
  5480. (vector "elsif\\|else\\|end\\s-+\\(if\\|use\\)"
  5481. (and (vhdl-last-word (point))
  5482. (or (vhdl-first-word (point))
  5483. (save-excursion
  5484. (vhdl-beginning-of-statement-1 lim)
  5485. (vhdl-backward-skip-label lim)
  5486. (vhdl-first-word (point)))))))
  5487. ))))
  5488. (defconst vhdl-end-fwd-re "\\b\\(end\\|else\\|elsif\\)\\b\\([^_]\\|\\'\\)")
  5489. (defconst vhdl-end-bwd-re "\\b\\(end\\|else\\|elsif\\)\\b[^_]")
  5490. (defun vhdl-end-p (&optional lim)
  5491. "Return t if we are looking at a real \"end\" keyword.
  5492. Assumes that the caller will make sure that we are looking at
  5493. vhdl-end-fwd-re, and are not inside a literal, and that we are not in
  5494. the middle of an identifier that just happens to contain an \"end\"
  5495. keyword."
  5496. (or (not (looking-at "else"))
  5497. ;; make sure that the "else" isn't inside a conditional signal
  5498. ;; assignment.
  5499. (save-excursion
  5500. (re-search-backward ";\\|\\bwhen\\b[^_]" lim 'move)
  5501. (or (eq (following-char) ?\;)
  5502. (eq (point) lim)
  5503. (vhdl-in-literal)))))
  5504. (defun vhdl-corresponding-begin (&optional lim)
  5505. "If the word at the current position corresponds to an \"end\"
  5506. keyword, then return a vector containing enough information to find
  5507. the corresponding \"begin\" keyword, else return nil. The keyword to
  5508. search backward for is aref 0. The column in which the keyword must
  5509. appear is aref 1 or nil if any column is suitable. The supplementary
  5510. keyword to search forward for is aref 2 or nil if this is not
  5511. required. If aref 3 is t, then the \"begin\" keyword may be found in
  5512. the middle of a statement.
  5513. Assumes that the caller will make sure that we are not in the middle
  5514. of an identifier that just happens to contain an \"end\" keyword."
  5515. (save-excursion
  5516. (let (pos)
  5517. (if (and (looking-at vhdl-end-fwd-re)
  5518. (not (vhdl-in-literal))
  5519. (vhdl-end-p lim))
  5520. (if (looking-at "el")
  5521. ;; "else", "elsif":
  5522. (vector "if\\|elsif" (vhdl-first-word (point)) "then\\|use" nil)
  5523. ;; "end ...":
  5524. (setq pos (point))
  5525. (forward-sexp)
  5526. (skip-chars-forward " \t\n\r\f")
  5527. (cond
  5528. ;; "end if":
  5529. ((looking-at "if\\b[^_]")
  5530. (vector "else\\|elsif\\|if"
  5531. (vhdl-first-word pos)
  5532. "else\\|then\\|use" nil))
  5533. ;; "end component":
  5534. ((looking-at "component\\b[^_]")
  5535. (vector (buffer-substring (match-beginning 1)
  5536. (match-end 1))
  5537. (vhdl-first-word pos)
  5538. nil nil))
  5539. ;; "end units", "end record", "end protected":
  5540. ((looking-at "\\(units\\|record\\|protected\\(\\s-+body\\)?\\)\\b[^_]")
  5541. (vector (buffer-substring (match-beginning 1)
  5542. (match-end 1))
  5543. (vhdl-first-word pos)
  5544. nil t))
  5545. ;; "end block", "end process", "end procedural":
  5546. ((looking-at "\\(block\\|process\\|procedural\\)\\b[^_]")
  5547. (vector "begin" (vhdl-first-word pos) nil nil))
  5548. ;; "end case":
  5549. ((looking-at "case\\b[^_]")
  5550. (vector "case" (vhdl-first-word pos) "is" nil))
  5551. ;; "end generate":
  5552. ((looking-at "generate\\b[^_]")
  5553. (vector "generate\\|for\\|if"
  5554. (vhdl-first-word pos)
  5555. "generate" nil))
  5556. ;; "end loop":
  5557. ((looking-at "loop\\b[^_]")
  5558. (vector "loop\\|while\\|for"
  5559. (vhdl-first-word pos)
  5560. "loop" nil))
  5561. ;; "end for" (inside configuration declaration):
  5562. ((looking-at "for\\b[^_]")
  5563. (vector "for" (vhdl-first-word pos) nil nil))
  5564. ;; "end [id]":
  5565. (t
  5566. (vector "begin\\|architecture\\|configuration\\|context\\|entity\\|package\\|procedure\\|function"
  5567. (vhdl-first-word pos)
  5568. ;; return an alist of (statement . keyword) mappings
  5569. '(
  5570. ;; "begin ... end [id]":
  5571. ("begin" . nil)
  5572. ;; "architecture ... is ... begin ... end [id]":
  5573. ("architecture" . "is")
  5574. ;; "configuration ... is ... end [id]":
  5575. ("configuration" . "is")
  5576. ;; "context ... is ... end [id]":
  5577. ("context" . "is")
  5578. ;; "entity ... is ... end [id]":
  5579. ("entity" . "is")
  5580. ;; "package ... is ... end [id]":
  5581. ("package" . "is")
  5582. ;; "procedure ... is ... begin ... end [id]":
  5583. ("procedure" . "is")
  5584. ;; "function ... is ... begin ... end [id]":
  5585. ("function" . "is")
  5586. )
  5587. nil))
  5588. ))) ; "end ..."
  5589. )))
  5590. (defconst vhdl-leader-re
  5591. "\\b\\(block\\|component\\|process\\|procedural\\|for\\)\\b[^_]")
  5592. (defun vhdl-end-of-leader ()
  5593. (save-excursion
  5594. (cond ((looking-at "block\\|process\\|procedural")
  5595. (if (save-excursion
  5596. (forward-sexp)
  5597. (skip-chars-forward " \t\n\r\f")
  5598. (= (following-char) ?\())
  5599. (forward-sexp 2)
  5600. (forward-sexp))
  5601. (when (looking-at "[ \t\n\r\f]*is")
  5602. (goto-char (match-end 0)))
  5603. (point))
  5604. ((looking-at "component")
  5605. (forward-sexp 2)
  5606. (when (looking-at "[ \t\n\r\f]*is")
  5607. (goto-char (match-end 0)))
  5608. (point))
  5609. ((looking-at "for")
  5610. (forward-sexp 2)
  5611. (skip-chars-forward " \t\n\r\f")
  5612. (while (looking-at "[,:(]")
  5613. (forward-sexp)
  5614. (skip-chars-forward " \t\n\r\f"))
  5615. (point))
  5616. (t nil)
  5617. )))
  5618. (defconst vhdl-trailer-re
  5619. "\\b\\(is\\|then\\|generate\\|loop\\|record\\|protected\\(\\s-+body\\)?\\|use\\)\\b[^_]")
  5620. (defconst vhdl-statement-fwd-re
  5621. "\\b\\(if\\|for\\|while\\|loop\\)\\b\\([^_]\\|\\'\\)"
  5622. "A regular expression for searching forward that matches all known
  5623. \"statement\" keywords.")
  5624. (defconst vhdl-statement-bwd-re
  5625. "\\b\\(if\\|for\\|while\\|loop\\)\\b[^_]"
  5626. "A regular expression for searching backward that matches all known
  5627. \"statement\" keywords.")
  5628. (defun vhdl-statement-p (&optional lim)
  5629. "Return t if we are looking at a real \"statement\" keyword.
  5630. Assumes that the caller will make sure that we are looking at
  5631. vhdl-statement-fwd-re, and are not inside a literal, and that we are not
  5632. in the middle of an identifier that just happens to contain a
  5633. \"statement\" keyword."
  5634. (cond
  5635. ;; "for" ... "generate":
  5636. ((and (looking-at "f")
  5637. ;; Make sure it's the start of a parameter specification.
  5638. (save-excursion
  5639. (forward-sexp 2)
  5640. (skip-chars-forward " \t\n\r\f")
  5641. (looking-at "in\\b[^_]"))
  5642. ;; Make sure it's not an "end for".
  5643. (save-excursion
  5644. (backward-sexp)
  5645. (not (looking-at "end\\s-+\\w"))))
  5646. t)
  5647. ;; "if" ... "then", "if" ... "generate", "if" ... "loop":
  5648. ((and (looking-at "i")
  5649. ;; Make sure it's not an "end if".
  5650. (save-excursion
  5651. (backward-sexp)
  5652. (not (looking-at "end\\s-+\\w"))))
  5653. t)
  5654. ;; "while" ... "loop":
  5655. ((looking-at "w")
  5656. t)
  5657. ))
  5658. (defconst vhdl-case-alternative-re "when[( \t\n\r\f][^;=>]+=>"
  5659. "Regexp describing a case statement alternative key.")
  5660. (defun vhdl-case-alternative-p (&optional lim)
  5661. "Return t if we are looking at a real case alternative.
  5662. Assumes that the caller will make sure that we are looking at
  5663. vhdl-case-alternative-re, and are not inside a literal, and that
  5664. we are not in the middle of an identifier that just happens to
  5665. contain a \"when\" keyword."
  5666. (save-excursion
  5667. (let (foundp)
  5668. (while (and (not foundp)
  5669. (re-search-backward ";\\|<=" lim 'move))
  5670. (if (or (= (preceding-char) ?_)
  5671. (vhdl-in-literal))
  5672. (backward-char)
  5673. (setq foundp t)))
  5674. (or (eq (following-char) ?\;)
  5675. (eq (point) lim)))
  5676. ))
  5677. ;; Core syntactic movement functions:
  5678. (defconst vhdl-b-t-b-re
  5679. (concat vhdl-begin-bwd-re "\\|" vhdl-end-bwd-re))
  5680. (defun vhdl-backward-to-block (&optional lim)
  5681. "Move backward to the previous \"begin\" or \"end\" keyword."
  5682. (let (foundp)
  5683. (while (and (not foundp)
  5684. (re-search-backward vhdl-b-t-b-re lim 'move))
  5685. (if (or (= (preceding-char) ?_)
  5686. (vhdl-in-literal))
  5687. (backward-char)
  5688. (cond
  5689. ;; "begin" keyword:
  5690. ((and (looking-at vhdl-begin-fwd-re)
  5691. (or (not (looking-at "\\<use\\>"))
  5692. (save-excursion (back-to-indentation)
  5693. (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
  5694. (/= (preceding-char) ?_)
  5695. (vhdl-begin-p lim))
  5696. (setq foundp 'begin))
  5697. ;; "end" keyword:
  5698. ((and (looking-at vhdl-end-fwd-re)
  5699. (/= (preceding-char) ?_)
  5700. (vhdl-end-p lim))
  5701. (setq foundp 'end))
  5702. ))
  5703. )
  5704. foundp
  5705. ))
  5706. (defun vhdl-forward-sexp (&optional count lim)
  5707. "Move forward across one balanced expression (sexp).
  5708. With COUNT, do it that many times."
  5709. (interactive "p")
  5710. (let ((count (or count 1))
  5711. (case-fold-search t)
  5712. end-vec target)
  5713. (save-excursion
  5714. (while (> count 0)
  5715. ;; skip whitespace
  5716. (skip-chars-forward " \t\n\r\f")
  5717. ;; Check for an unbalanced "end" keyword
  5718. (if (and (looking-at vhdl-end-fwd-re)
  5719. (/= (preceding-char) ?_)
  5720. (not (vhdl-in-literal))
  5721. (vhdl-end-p lim)
  5722. (not (looking-at "else")))
  5723. (error
  5724. "ERROR: Containing expression ends prematurely in vhdl-forward-sexp"))
  5725. ;; If the current keyword is a "begin" keyword, then find the
  5726. ;; corresponding "end" keyword.
  5727. (if (setq end-vec (vhdl-corresponding-end lim))
  5728. (let (
  5729. ;; end-re is the statement keyword to search for
  5730. (end-re
  5731. (concat "\\b\\(" (aref end-vec 0) "\\)\\b\\([^_]\\|\\'\\)"))
  5732. ;; column is either the statement keyword target column
  5733. ;; or nil
  5734. (column (aref end-vec 1))
  5735. (eol (vhdl-point 'eol))
  5736. foundp literal placeholder)
  5737. ;; Look for the statement keyword.
  5738. (while (and (not foundp)
  5739. (re-search-forward end-re nil t)
  5740. (setq placeholder (match-end 1))
  5741. (goto-char (match-beginning 0)))
  5742. ;; If we are in a literal, or not in the right target
  5743. ;; column and not on the same line as the begin, then
  5744. ;; try again.
  5745. (if (or (and column
  5746. (/= (current-indentation) column)
  5747. (> (point) eol))
  5748. (= (preceding-char) ?_)
  5749. (setq literal (vhdl-in-literal)))
  5750. (if (eq literal 'comment)
  5751. (end-of-line)
  5752. (forward-char))
  5753. ;; An "else" keyword corresponds to both the opening brace
  5754. ;; of the following sexp and the closing brace of the
  5755. ;; previous sexp.
  5756. (if (not (looking-at "else"))
  5757. (goto-char placeholder))
  5758. (setq foundp t))
  5759. )
  5760. (if (not foundp)
  5761. (error "ERROR: Unbalanced keywords in vhdl-forward-sexp"))
  5762. )
  5763. ;; If the current keyword is not a "begin" keyword, then just
  5764. ;; perform the normal forward-sexp.
  5765. (forward-sexp)
  5766. )
  5767. (setq count (1- count))
  5768. )
  5769. (setq target (point)))
  5770. (goto-char target)
  5771. nil))
  5772. (defun vhdl-backward-sexp (&optional count lim)
  5773. "Move backward across one balanced expression (sexp).
  5774. With COUNT, do it that many times. LIM bounds any required backward
  5775. searches."
  5776. (interactive "p")
  5777. (let ((count (or count 1))
  5778. (case-fold-search t)
  5779. begin-vec target)
  5780. (save-excursion
  5781. (while (> count 0)
  5782. ;; Perform the normal backward-sexp, unless we are looking at
  5783. ;; "else" - an "else" keyword corresponds to both the opening brace
  5784. ;; of the following sexp and the closing brace of the previous sexp.
  5785. (if (and (looking-at "else\\b\\([^_]\\|\\'\\)")
  5786. (/= (preceding-char) ?_)
  5787. (not (vhdl-in-literal)))
  5788. nil
  5789. (backward-sexp)
  5790. (if (and (looking-at vhdl-begin-fwd-re)
  5791. (or (not (looking-at "\\<use\\>"))
  5792. (save-excursion
  5793. (back-to-indentation)
  5794. (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
  5795. (/= (preceding-char) ?_)
  5796. (not (vhdl-in-literal))
  5797. (vhdl-begin-p lim))
  5798. (error "ERROR: Containing expression ends prematurely in vhdl-backward-sexp")))
  5799. ;; If the current keyword is an "end" keyword, then find the
  5800. ;; corresponding "begin" keyword.
  5801. (if (and (setq begin-vec (vhdl-corresponding-begin lim))
  5802. (/= (preceding-char) ?_))
  5803. (let (
  5804. ;; begin-re is the statement keyword to search for
  5805. (begin-re
  5806. (concat "\\b\\(" (aref begin-vec 0) "\\)\\b[^_]"))
  5807. ;; column is either the statement keyword target column
  5808. ;; or nil
  5809. (column (aref begin-vec 1))
  5810. ;; internal-p controls where the statement keyword can
  5811. ;; be found.
  5812. (internal-p (aref begin-vec 3))
  5813. (last-backward (point)) last-forward
  5814. foundp literal keyword)
  5815. ;; Look for the statement keyword.
  5816. (while (and (not foundp)
  5817. (re-search-backward begin-re lim t)
  5818. (setq keyword
  5819. (buffer-substring (match-beginning 1)
  5820. (match-end 1))))
  5821. ;; If we are in a literal or in the wrong column,
  5822. ;; then try again.
  5823. (if (or (and column
  5824. (and (/= (current-indentation) column)
  5825. ;; possibly accept current-column as
  5826. ;; well as current-indentation.
  5827. (or (not internal-p)
  5828. (/= (current-column) column))))
  5829. (= (preceding-char) ?_)
  5830. (vhdl-in-literal))
  5831. (backward-char)
  5832. ;; If there is a supplementary keyword, then
  5833. ;; search forward for it.
  5834. (if (and (setq begin-re (aref begin-vec 2))
  5835. (or (not (listp begin-re))
  5836. ;; If begin-re is an alist, then find the
  5837. ;; element corresponding to the actual
  5838. ;; keyword that we found.
  5839. (progn
  5840. (setq begin-re
  5841. (assoc keyword begin-re))
  5842. (and begin-re
  5843. (setq begin-re (cdr begin-re))))))
  5844. (and
  5845. (setq begin-re
  5846. (concat "\\b\\(" begin-re "\\)\\b[^_]"))
  5847. (save-excursion
  5848. (setq last-forward (point))
  5849. ;; Look for the supplementary keyword
  5850. ;; (bounded by the backward search start
  5851. ;; point).
  5852. (while (and (not foundp)
  5853. (re-search-forward begin-re
  5854. last-backward t)
  5855. (goto-char (match-beginning 1)))
  5856. ;; If we are in a literal, then try again.
  5857. (if (or (= (preceding-char) ?_)
  5858. (setq literal
  5859. (vhdl-in-literal)))
  5860. (if (eq literal 'comment)
  5861. (goto-char
  5862. (min (vhdl-point 'eol) last-backward))
  5863. (forward-char))
  5864. ;; We have found the supplementary keyword.
  5865. ;; Save the position of the keyword in foundp.
  5866. (setq foundp (point)))
  5867. )
  5868. foundp)
  5869. ;; If the supplementary keyword was found, then
  5870. ;; move point to the supplementary keyword.
  5871. (goto-char foundp))
  5872. ;; If there was no supplementary keyword, then
  5873. ;; point is already at the statement keyword.
  5874. (setq foundp t)))
  5875. ) ; end of the search for the statement keyword
  5876. (if (not foundp)
  5877. (error "ERROR: Unbalanced keywords in vhdl-backward-sexp"))
  5878. ))
  5879. (setq count (1- count))
  5880. )
  5881. (setq target (point)))
  5882. (goto-char target)
  5883. nil))
  5884. (defun vhdl-backward-up-list (&optional count limit)
  5885. "Move backward out of one level of blocks.
  5886. With argument, do this that many times."
  5887. (interactive "p")
  5888. (let ((count (or count 1))
  5889. target)
  5890. (save-excursion
  5891. (while (> count 0)
  5892. (if (looking-at vhdl-defun-re)
  5893. (error "ERROR: Unbalanced blocks"))
  5894. (vhdl-backward-to-block limit)
  5895. (setq count (1- count)))
  5896. (setq target (point)))
  5897. (goto-char target)))
  5898. (defun vhdl-end-of-defun (&optional count)
  5899. "Move forward to the end of a VHDL defun."
  5900. (interactive)
  5901. (let ((case-fold-search t))
  5902. (vhdl-beginning-of-defun)
  5903. (if (not (looking-at "block\\|process\\|procedural"))
  5904. (re-search-forward "\\bis\\b"))
  5905. (vhdl-forward-sexp)))
  5906. (defun vhdl-mark-defun ()
  5907. "Put mark at end of this \"defun\", point at beginning."
  5908. (interactive)
  5909. (let ((case-fold-search t))
  5910. (push-mark)
  5911. (vhdl-beginning-of-defun)
  5912. (push-mark)
  5913. (if (not (looking-at "block\\|process\\|procedural"))
  5914. (re-search-forward "\\bis\\b"))
  5915. (vhdl-forward-sexp)
  5916. (exchange-point-and-mark)))
  5917. (defun vhdl-beginning-of-libunit ()
  5918. "Move backward to the beginning of a VHDL library unit.
  5919. Returns the location of the corresponding begin keyword, unless search
  5920. stops due to beginning or end of buffer.
  5921. Note that if point is between the \"libunit\" keyword and the
  5922. corresponding \"begin\" keyword, then that libunit will not be
  5923. recognized, and the search will continue backwards. If point is
  5924. at the \"begin\" keyword, then the defun will be recognized. The
  5925. returned point is at the first character of the \"libunit\" keyword."
  5926. (let ((last-forward (point))
  5927. (last-backward
  5928. ;; Just in case we are actually sitting on the "begin"
  5929. ;; keyword, allow for the keyword and an extra character,
  5930. ;; as this will be used when looking forward for the
  5931. ;; "begin" keyword.
  5932. (save-excursion (forward-word 1) (1+ (point))))
  5933. foundp literal placeholder)
  5934. ;; Find the "libunit" keyword.
  5935. (while (and (not foundp)
  5936. (re-search-backward vhdl-libunit-re nil 'move))
  5937. ;; If we are in a literal, or not at a real libunit, then try again.
  5938. (if (or (= (preceding-char) ?_)
  5939. (vhdl-in-literal)
  5940. (not (vhdl-libunit-p)))
  5941. (backward-char)
  5942. ;; Find the corresponding "begin" keyword.
  5943. (setq last-forward (point))
  5944. (while (and (not foundp)
  5945. (re-search-forward "\\bis\\b[^_]" last-backward t)
  5946. (setq placeholder (match-beginning 0)))
  5947. (if (or (= (preceding-char) ?_)
  5948. (setq literal (vhdl-in-literal)))
  5949. ;; It wasn't a real keyword, so keep searching.
  5950. (if (eq literal 'comment)
  5951. (goto-char
  5952. (min (vhdl-point 'eol) last-backward))
  5953. (forward-char))
  5954. ;; We have found the begin keyword, loop will exit.
  5955. (setq foundp placeholder)))
  5956. ;; Go back to the libunit keyword
  5957. (goto-char last-forward)))
  5958. foundp))
  5959. (defun vhdl-beginning-of-defun (&optional count)
  5960. "Move backward to the beginning of a VHDL defun.
  5961. With argument, do it that many times.
  5962. Returns the location of the corresponding begin keyword, unless search
  5963. stops due to beginning or end of buffer."
  5964. ;; Note that if point is between the "defun" keyword and the
  5965. ;; corresponding "begin" keyword, then that defun will not be
  5966. ;; recognized, and the search will continue backwards. If point is
  5967. ;; at the "begin" keyword, then the defun will be recognized. The
  5968. ;; returned point is at the first character of the "defun" keyword.
  5969. (interactive "p")
  5970. (let ((count (or count 1))
  5971. (case-fold-search t)
  5972. (last-forward (point))
  5973. foundp)
  5974. (while (> count 0)
  5975. (setq foundp nil)
  5976. (goto-char last-forward)
  5977. (let ((last-backward
  5978. ;; Just in case we are actually sitting on the "begin"
  5979. ;; keyword, allow for the keyword and an extra character,
  5980. ;; as this will be used when looking forward for the
  5981. ;; "begin" keyword.
  5982. (save-excursion (forward-word 1) (1+ (point))))
  5983. begin-string literal)
  5984. (while (and (not foundp)
  5985. (re-search-backward vhdl-defun-re nil 'move))
  5986. ;; If we are in a literal, then try again.
  5987. (if (or (= (preceding-char) ?_)
  5988. (vhdl-in-literal))
  5989. (backward-char)
  5990. (if (setq begin-string (vhdl-corresponding-defun))
  5991. ;; This is a real defun keyword.
  5992. ;; Find the corresponding "begin" keyword.
  5993. ;; Look for the begin keyword.
  5994. (progn
  5995. ;; Save the search start point.
  5996. (setq last-forward (point))
  5997. (while (and (not foundp)
  5998. (search-forward begin-string last-backward t))
  5999. (if (or (= (preceding-char) ?_)
  6000. (save-match-data
  6001. (setq literal (vhdl-in-literal))))
  6002. ;; It wasn't a real keyword, so keep searching.
  6003. (if (eq literal 'comment)
  6004. (goto-char
  6005. (min (vhdl-point 'eol) last-backward))
  6006. (forward-char))
  6007. ;; We have found the begin keyword, loop will exit.
  6008. (setq foundp (match-beginning 0)))
  6009. )
  6010. ;; Go back to the defun keyword
  6011. (goto-char last-forward)) ; end search for begin keyword
  6012. ))
  6013. ) ; end of the search for the defun keyword
  6014. )
  6015. (setq count (1- count))
  6016. )
  6017. (vhdl-keep-region-active)
  6018. foundp))
  6019. (defun vhdl-beginning-of-statement (&optional count lim interactive)
  6020. "Go to the beginning of the innermost VHDL statement.
  6021. With prefix arg, go back N - 1 statements. If already at the
  6022. beginning of a statement then go to the beginning of the preceding
  6023. one. If within a string or comment, or next to a comment (only
  6024. whitespace between), move by sentences instead of statements.
  6025. When called from a program, this function takes 3 optional args: the
  6026. prefix arg, a buffer position limit which is the farthest back to
  6027. search, and an argument indicating an interactive call."
  6028. (interactive "p\np")
  6029. (let ((count (or count 1))
  6030. (case-fold-search t)
  6031. (lim (or lim (point-min)))
  6032. (here (point))
  6033. state)
  6034. (save-excursion
  6035. (goto-char lim)
  6036. (setq state (parse-partial-sexp (point) here nil nil)))
  6037. (if (and interactive
  6038. (or (nth 3 state)
  6039. (nth 4 state)
  6040. (looking-at (concat "[ \t]*" comment-start-skip))))
  6041. (forward-sentence (- count))
  6042. (while (> count 0)
  6043. (vhdl-beginning-of-statement-1 lim)
  6044. (setq count (1- count))))
  6045. ;; its possible we've been left up-buf of lim
  6046. (goto-char (max (point) lim))
  6047. )
  6048. (vhdl-keep-region-active))
  6049. (defconst vhdl-e-o-s-re
  6050. (concat ";\\|" vhdl-begin-fwd-re "\\|" vhdl-statement-fwd-re))
  6051. (defun vhdl-end-of-statement ()
  6052. "Very simple implementation."
  6053. (interactive)
  6054. (re-search-forward vhdl-e-o-s-re))
  6055. (defconst vhdl-b-o-s-re
  6056. (concat ";[^_]\\|([^_]\\|)[^_]\\|\\bwhen\\b[^_]\\|"
  6057. vhdl-begin-bwd-re "\\|" vhdl-statement-bwd-re))
  6058. (defun vhdl-beginning-of-statement-1 (&optional lim)
  6059. "Move to the start of the current statement, or the previous
  6060. statement if already at the beginning of one."
  6061. (let ((lim (or lim (point-min)))
  6062. (here (point))
  6063. (pos (point))
  6064. donep)
  6065. ;; go backwards one balanced expression, but be careful of
  6066. ;; unbalanced paren being reached
  6067. (if (not (vhdl-safe (progn (backward-sexp) t)))
  6068. (progn
  6069. (backward-up-list 1)
  6070. (forward-char)
  6071. (vhdl-forward-syntactic-ws here)
  6072. (setq donep t)))
  6073. (while (and (not donep)
  6074. (not (bobp))
  6075. ;; look backwards for a statement boundary
  6076. (progn (forward-char) (re-search-backward vhdl-b-o-s-re lim 'move)))
  6077. (if (or (= (preceding-char) ?_)
  6078. (vhdl-in-literal))
  6079. (backward-char)
  6080. (cond
  6081. ;; If we are looking at an open paren, then stop after it
  6082. ((eq (following-char) ?\()
  6083. (forward-char)
  6084. (vhdl-forward-syntactic-ws here)
  6085. (setq donep t))
  6086. ;; If we are looking at a close paren, then skip it
  6087. ((eq (following-char) ?\))
  6088. (forward-char)
  6089. (setq pos (point))
  6090. (backward-sexp)
  6091. (if (< (point) lim)
  6092. (progn (goto-char pos)
  6093. (vhdl-forward-syntactic-ws here)
  6094. (setq donep t))))
  6095. ;; If we are looking at a semicolon, then stop
  6096. ((and (eq (following-char) ?\;) (not (vhdl-in-quote-p)))
  6097. (progn
  6098. (forward-char)
  6099. (vhdl-forward-syntactic-ws here)
  6100. (setq donep t)))
  6101. ;; If we are looking at a "begin", then stop
  6102. ((and (looking-at vhdl-begin-fwd-re)
  6103. (or (not (looking-at "\\<use\\>"))
  6104. (save-excursion
  6105. (back-to-indentation)
  6106. (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
  6107. (/= (preceding-char) ?_)
  6108. (vhdl-begin-p nil))
  6109. ;; If it's a leader "begin", then find the
  6110. ;; right place
  6111. (if (looking-at vhdl-leader-re)
  6112. (save-excursion
  6113. ;; set a default stop point at the begin
  6114. (setq pos (point))
  6115. ;; is the start point inside the leader area ?
  6116. (goto-char (vhdl-end-of-leader))
  6117. (vhdl-forward-syntactic-ws here)
  6118. (if (< (point) here)
  6119. ;; start point was not inside leader area
  6120. ;; set stop point at word after leader
  6121. (setq pos (point))))
  6122. (forward-word 1)
  6123. (vhdl-forward-syntactic-ws here)
  6124. (setq pos (point)))
  6125. (goto-char pos)
  6126. (setq donep t))
  6127. ;; If we are looking at a "statement", then stop
  6128. ((and (looking-at vhdl-statement-fwd-re)
  6129. (/= (preceding-char) ?_)
  6130. (vhdl-statement-p nil))
  6131. (setq donep t))
  6132. ;; If we are looking at a case alternative key, then stop
  6133. ((and (looking-at vhdl-case-alternative-re)
  6134. (vhdl-case-alternative-p lim))
  6135. (save-excursion
  6136. ;; set a default stop point at the when
  6137. (setq pos (point))
  6138. ;; is the start point inside the case alternative key ?
  6139. (looking-at vhdl-case-alternative-re)
  6140. (goto-char (match-end 0))
  6141. (vhdl-forward-syntactic-ws here)
  6142. (if (< (point) here)
  6143. ;; start point was not inside the case alternative key
  6144. ;; set stop point at word after case alternative keyleader
  6145. (setq pos (point))))
  6146. (goto-char pos)
  6147. (setq donep t))
  6148. ;; Bogus find, continue
  6149. (t
  6150. (backward-char)))))
  6151. ))
  6152. ;; Defuns for calculating the current syntactic state:
  6153. (defun vhdl-get-library-unit (bod placeholder)
  6154. "If there is an enclosing library unit at BOD, with its \"begin\"
  6155. keyword at PLACEHOLDER, then return the library unit type."
  6156. (let ((here (vhdl-point 'bol)))
  6157. (if (save-excursion
  6158. (goto-char placeholder)
  6159. (vhdl-safe (vhdl-forward-sexp 1 bod))
  6160. (<= here (point)))
  6161. (save-excursion
  6162. (goto-char bod)
  6163. (cond
  6164. ((looking-at "e") 'entity)
  6165. ((looking-at "a") 'architecture)
  6166. ((looking-at "conf") 'configuration)
  6167. ((looking-at "cont") 'context)
  6168. ((looking-at "p")
  6169. (save-excursion
  6170. (goto-char bod)
  6171. (forward-sexp)
  6172. (vhdl-forward-syntactic-ws here)
  6173. (if (looking-at "body\\b[^_]")
  6174. 'package-body 'package))))))
  6175. ))
  6176. (defun vhdl-get-block-state (&optional lim)
  6177. "Finds and records all the closest opens.
  6178. LIM is the furthest back we need to search (it should be the
  6179. previous libunit keyword)."
  6180. (let ((here (point))
  6181. (lim (or lim (point-min)))
  6182. keyword sexp-start sexp-mid sexp-end
  6183. preceding-sexp containing-sexp
  6184. containing-begin containing-mid containing-paren)
  6185. (save-excursion
  6186. ;; Find the containing-paren, and use that as the limit
  6187. (if (setq containing-paren
  6188. (save-restriction
  6189. (narrow-to-region lim (point))
  6190. (vhdl-safe (scan-lists (point) -1 1))))
  6191. (setq lim containing-paren))
  6192. ;; Look backwards for "begin" and "end" keywords.
  6193. (while (and (> (point) lim)
  6194. (not containing-sexp))
  6195. (setq keyword (vhdl-backward-to-block lim))
  6196. (cond
  6197. ((eq keyword 'begin)
  6198. ;; Found a "begin" keyword
  6199. (setq sexp-start (point))
  6200. (setq sexp-mid (vhdl-corresponding-mid lim))
  6201. (setq sexp-end (vhdl-safe
  6202. (save-excursion
  6203. (vhdl-forward-sexp 1 lim) (point))))
  6204. (if (and sexp-end (<= sexp-end here))
  6205. ;; we want to record this sexp, but we only want to
  6206. ;; record the last-most of any of them before here
  6207. (or preceding-sexp
  6208. (setq preceding-sexp sexp-start))
  6209. ;; we're contained in this sexp so put sexp-start on
  6210. ;; front of list
  6211. (setq containing-sexp sexp-start)
  6212. (setq containing-mid sexp-mid)
  6213. (setq containing-begin t)))
  6214. ((eq keyword 'end)
  6215. ;; Found an "end" keyword
  6216. (forward-sexp)
  6217. (setq sexp-end (point))
  6218. (setq sexp-mid nil)
  6219. (setq sexp-start
  6220. (or (vhdl-safe (vhdl-backward-sexp 1 lim) (point))
  6221. (progn (backward-sexp) (point))))
  6222. ;; we want to record this sexp, but we only want to
  6223. ;; record the last-most of any of them before here
  6224. (or preceding-sexp
  6225. (setq preceding-sexp sexp-start)))
  6226. )))
  6227. ;; Check if the containing-paren should be the containing-sexp
  6228. (if (and containing-paren
  6229. (or (null containing-sexp)
  6230. (< containing-sexp containing-paren)))
  6231. (setq containing-sexp containing-paren
  6232. preceding-sexp nil
  6233. containing-begin nil
  6234. containing-mid nil))
  6235. (vector containing-sexp preceding-sexp containing-begin containing-mid)
  6236. ))
  6237. (defconst vhdl-s-c-a-re
  6238. (concat vhdl-case-alternative-re "\\|" vhdl-case-header-key))
  6239. (defun vhdl-skip-case-alternative (&optional lim)
  6240. "Skip forward over case/when bodies, with optional maximal
  6241. limit. If no next case alternative is found, nil is returned and
  6242. point is not moved."
  6243. (let ((lim (or lim (point-max)))
  6244. (here (point))
  6245. donep foundp)
  6246. (while (and (< (point) lim)
  6247. (not donep))
  6248. (if (and (re-search-forward vhdl-s-c-a-re lim 'move)
  6249. (save-match-data
  6250. (not (vhdl-in-literal)))
  6251. (/= (match-beginning 0) here))
  6252. (progn
  6253. (goto-char (match-beginning 0))
  6254. (cond
  6255. ((and (looking-at "case")
  6256. (re-search-forward "\\bis[^_]" lim t))
  6257. (backward-sexp)
  6258. (vhdl-forward-sexp))
  6259. (t
  6260. (setq donep t
  6261. foundp t))))))
  6262. (if (not foundp)
  6263. (goto-char here))
  6264. foundp))
  6265. (defun vhdl-backward-skip-label (&optional lim)
  6266. "Skip backward over a label, with optional maximal
  6267. limit. If label is not found, nil is returned and point
  6268. is not moved."
  6269. (let ((lim (or lim (point-min)))
  6270. placeholder)
  6271. (if (save-excursion
  6272. (vhdl-backward-syntactic-ws lim)
  6273. (and (eq (preceding-char) ?:)
  6274. (progn
  6275. (backward-sexp)
  6276. (setq placeholder (point))
  6277. (looking-at vhdl-label-key))))
  6278. (goto-char placeholder))
  6279. ))
  6280. (defun vhdl-forward-skip-label (&optional lim)
  6281. "Skip forward over a label, with optional maximal
  6282. limit. If label is not found, nil is returned and point
  6283. is not moved."
  6284. (let ((lim (or lim (point-max))))
  6285. (if (looking-at vhdl-label-key)
  6286. (progn
  6287. (goto-char (match-end 0))
  6288. (vhdl-forward-syntactic-ws lim)))
  6289. ))
  6290. (defun vhdl-get-syntactic-context ()
  6291. "Guess the syntactic description of the current line of VHDL code."
  6292. (save-excursion
  6293. (save-restriction
  6294. (beginning-of-line)
  6295. (let* ((indent-point (point))
  6296. (case-fold-search t)
  6297. vec literal containing-sexp preceding-sexp
  6298. containing-begin containing-mid containing-leader
  6299. char-before-ip char-after-ip begin-after-ip end-after-ip
  6300. placeholder lim library-unit
  6301. )
  6302. ;; Reset the syntactic context
  6303. (setq vhdl-syntactic-context nil)
  6304. (save-excursion
  6305. ;; Move to the start of the previous library unit, and
  6306. ;; record the position of the "begin" keyword.
  6307. (setq placeholder (vhdl-beginning-of-libunit))
  6308. ;; The position of the "libunit" keyword gives us a gross
  6309. ;; limit point.
  6310. (setq lim (point))
  6311. )
  6312. ;; If there is a previous library unit, and we are enclosed by
  6313. ;; it, then set the syntax accordingly.
  6314. (and placeholder
  6315. (setq library-unit (vhdl-get-library-unit lim placeholder))
  6316. (vhdl-add-syntax library-unit lim))
  6317. ;; Find the surrounding state.
  6318. (if (setq vec (vhdl-get-block-state lim))
  6319. (progn
  6320. (setq containing-sexp (aref vec 0))
  6321. (setq preceding-sexp (aref vec 1))
  6322. (setq containing-begin (aref vec 2))
  6323. (setq containing-mid (aref vec 3))
  6324. ))
  6325. ;; set the limit on the farthest back we need to search
  6326. (setq lim (if containing-sexp
  6327. (save-excursion
  6328. (goto-char containing-sexp)
  6329. ;; set containing-leader if required
  6330. (if (looking-at vhdl-leader-re)
  6331. (setq containing-leader (vhdl-end-of-leader)))
  6332. (vhdl-point 'bol))
  6333. (point-min)))
  6334. ;; cache char before and after indent point, and move point to
  6335. ;; the most likely position to perform the majority of tests
  6336. (goto-char indent-point)
  6337. (skip-chars-forward " \t")
  6338. (setq literal (vhdl-in-literal))
  6339. (setq char-after-ip (following-char))
  6340. (setq begin-after-ip (and
  6341. (not literal)
  6342. (looking-at vhdl-begin-fwd-re)
  6343. (or (not (looking-at "\\<use\\>"))
  6344. (save-excursion
  6345. (back-to-indentation)
  6346. (looking-at "\\(\\w+\\s-*:\\s-*\\)?\\<\\(case\\|elsif\\|if\\)\\>")))
  6347. (vhdl-begin-p)))
  6348. (setq end-after-ip (and
  6349. (not literal)
  6350. (looking-at vhdl-end-fwd-re)
  6351. (vhdl-end-p)))
  6352. (vhdl-backward-syntactic-ws lim)
  6353. (setq char-before-ip (preceding-char))
  6354. (goto-char indent-point)
  6355. (skip-chars-forward " \t")
  6356. ;; now figure out syntactic qualities of the current line
  6357. (cond
  6358. ;; CASE 1: in a string or comment.
  6359. ((memq literal '(string comment))
  6360. (vhdl-add-syntax literal (vhdl-point 'bopl)))
  6361. ;; CASE 2: Line is at top level.
  6362. ((null containing-sexp)
  6363. ;; Find the point to which indentation will be relative
  6364. (save-excursion
  6365. (if (null preceding-sexp)
  6366. ;; CASE 2X.1
  6367. ;; no preceding-sexp -> use the preceding statement
  6368. (vhdl-beginning-of-statement-1 lim)
  6369. ;; CASE 2X.2
  6370. ;; if there is a preceding-sexp then indent relative to it
  6371. (goto-char preceding-sexp)
  6372. ;; if not at boi, then the block-opening keyword is
  6373. ;; probably following a label, so we need a different
  6374. ;; relpos
  6375. (if (/= (point) (vhdl-point 'boi))
  6376. ;; CASE 2X.3
  6377. (vhdl-beginning-of-statement-1 lim)))
  6378. ;; v-b-o-s could have left us at point-min
  6379. (and (bobp)
  6380. ;; CASE 2X.4
  6381. (vhdl-forward-syntactic-ws indent-point))
  6382. (setq placeholder (point)))
  6383. (cond
  6384. ;; CASE 2A : we are looking at a block-open
  6385. (begin-after-ip
  6386. (vhdl-add-syntax 'block-open placeholder))
  6387. ;; CASE 2B: we are looking at a block-close
  6388. (end-after-ip
  6389. (vhdl-add-syntax 'block-close placeholder))
  6390. ;; CASE 2C: we are looking at a top-level statement
  6391. ((progn
  6392. (vhdl-backward-syntactic-ws lim)
  6393. (or (bobp)
  6394. (and (= (preceding-char) ?\;)
  6395. (not (vhdl-in-quote-p)))))
  6396. (vhdl-add-syntax 'statement placeholder))
  6397. ;; CASE 2D: we are looking at a top-level statement-cont
  6398. (t
  6399. (vhdl-beginning-of-statement-1 lim)
  6400. ;; v-b-o-s could have left us at point-min
  6401. (and (bobp)
  6402. ;; CASE 2D.1
  6403. (vhdl-forward-syntactic-ws indent-point))
  6404. (vhdl-add-syntax 'statement-cont (point)))
  6405. )) ; end CASE 2
  6406. ;; CASE 3: line is inside parentheses. Most likely we are
  6407. ;; either in a subprogram argument (interface) list, or a
  6408. ;; continued expression containing parentheses.
  6409. ((null containing-begin)
  6410. (vhdl-backward-syntactic-ws containing-sexp)
  6411. (cond
  6412. ;; CASE 3A: we are looking at the arglist closing paren
  6413. ((eq char-after-ip ?\))
  6414. (goto-char containing-sexp)
  6415. (vhdl-add-syntax 'arglist-close (vhdl-point 'boi)))
  6416. ;; CASE 3B: we are looking at the first argument in an empty
  6417. ;; argument list.
  6418. ((eq char-before-ip ?\()
  6419. (goto-char containing-sexp)
  6420. (vhdl-add-syntax 'arglist-intro (vhdl-point 'boi)))
  6421. ;; CASE 3C: we are looking at an arglist continuation line,
  6422. ;; but the preceding argument is on the same line as the
  6423. ;; opening paren. This case includes multi-line
  6424. ;; expression paren groupings.
  6425. ((and (save-excursion
  6426. (goto-char (1+ containing-sexp))
  6427. (skip-chars-forward " \t")
  6428. (not (eolp))
  6429. (not (looking-at "--\\|`")))
  6430. (save-excursion
  6431. (vhdl-beginning-of-statement-1 containing-sexp)
  6432. (skip-chars-backward " \t(")
  6433. (while (and (= (preceding-char) ?\;)
  6434. (not (vhdl-in-quote-p)))
  6435. (vhdl-beginning-of-statement-1 containing-sexp)
  6436. (skip-chars-backward " \t("))
  6437. (<= (point) containing-sexp)))
  6438. (goto-char containing-sexp)
  6439. (vhdl-add-syntax 'arglist-cont-nonempty (vhdl-point 'boi)))
  6440. ;; CASE 3D: we are looking at just a normal arglist
  6441. ;; continuation line
  6442. (t (vhdl-beginning-of-statement-1 containing-sexp)
  6443. (vhdl-forward-syntactic-ws indent-point)
  6444. (vhdl-add-syntax 'arglist-cont (vhdl-point 'boi)))
  6445. ))
  6446. ;; CASE 4: A block mid open
  6447. ((and begin-after-ip
  6448. (looking-at containing-mid))
  6449. (goto-char containing-sexp)
  6450. ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
  6451. (if (looking-at vhdl-trailer-re)
  6452. ;; CASE 4.1
  6453. (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
  6454. (vhdl-backward-skip-label (vhdl-point 'boi))
  6455. (vhdl-add-syntax 'block-open (point)))
  6456. ;; CASE 5: block close brace
  6457. (end-after-ip
  6458. (goto-char containing-sexp)
  6459. ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
  6460. (if (looking-at vhdl-trailer-re)
  6461. ;; CASE 5.1
  6462. (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
  6463. (vhdl-backward-skip-label (vhdl-point 'boi))
  6464. (vhdl-add-syntax 'block-close (point)))
  6465. ;; CASE 6: A continued statement
  6466. ((and (/= char-before-ip ?\;)
  6467. ;; check it's not a trailer begin keyword, or a begin
  6468. ;; keyword immediately following a label.
  6469. (not (and begin-after-ip
  6470. (or (looking-at vhdl-trailer-re)
  6471. (save-excursion
  6472. (vhdl-backward-skip-label containing-sexp)))))
  6473. ;; check it's not a statement keyword
  6474. (not (and (looking-at vhdl-statement-fwd-re)
  6475. (vhdl-statement-p)))
  6476. ;; see if the b-o-s is before the indent point
  6477. (> indent-point
  6478. (save-excursion
  6479. (vhdl-beginning-of-statement-1 containing-sexp)
  6480. ;; If we ended up after a leader, then this will
  6481. ;; move us forward to the start of the first
  6482. ;; statement. Note that a containing sexp here is
  6483. ;; always a keyword, not a paren, so this will
  6484. ;; have no effect if we hit the containing-sexp.
  6485. (vhdl-forward-syntactic-ws indent-point)
  6486. (setq placeholder (point))))
  6487. ;; check it's not a block-intro
  6488. (/= placeholder containing-sexp)
  6489. ;; check it's not a case block-intro
  6490. (save-excursion
  6491. (goto-char placeholder)
  6492. (or (not (looking-at vhdl-case-alternative-re))
  6493. (> (match-end 0) indent-point))))
  6494. ;; Make placeholder skip a label, but only if it puts us
  6495. ;; before the indent point at the start of a line.
  6496. (let ((new placeholder))
  6497. (if (and (> indent-point
  6498. (save-excursion
  6499. (goto-char placeholder)
  6500. (vhdl-forward-skip-label indent-point)
  6501. (setq new (point))))
  6502. (save-excursion
  6503. (goto-char new)
  6504. (eq new (progn (back-to-indentation) (point)))))
  6505. (setq placeholder new)))
  6506. (vhdl-add-syntax 'statement-cont placeholder)
  6507. (if begin-after-ip
  6508. (vhdl-add-syntax 'block-open)))
  6509. ;; Statement. But what kind?
  6510. ;; CASE 7: A case alternative key
  6511. ((and (looking-at vhdl-case-alternative-re)
  6512. (vhdl-case-alternative-p containing-sexp))
  6513. ;; for a case alternative key, we set relpos to the first
  6514. ;; non-whitespace char on the line containing the "case"
  6515. ;; keyword.
  6516. (goto-char containing-sexp)
  6517. ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
  6518. (if (looking-at vhdl-trailer-re)
  6519. (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
  6520. (vhdl-add-syntax 'case-alternative (vhdl-point 'boi)))
  6521. ;; CASE 8: statement catchall
  6522. (t
  6523. ;; we know its a statement, but we need to find out if it is
  6524. ;; the first statement in a block
  6525. (if containing-leader
  6526. (goto-char containing-leader)
  6527. (goto-char containing-sexp)
  6528. ;; Note that a containing sexp here is always a keyword,
  6529. ;; not a paren, so skip over the keyword.
  6530. (forward-sexp))
  6531. ;; move to the start of the first statement
  6532. (vhdl-forward-syntactic-ws indent-point)
  6533. (setq placeholder (point))
  6534. ;; we want to ignore case alternatives keys when skipping forward
  6535. (let (incase-p)
  6536. (while (looking-at vhdl-case-alternative-re)
  6537. (setq incase-p (point))
  6538. ;; we also want to skip over the body of the
  6539. ;; case/when statement if that doesn't put us at
  6540. ;; after the indent-point
  6541. (while (vhdl-skip-case-alternative indent-point))
  6542. ;; set up the match end
  6543. (looking-at vhdl-case-alternative-re)
  6544. (goto-char (match-end 0))
  6545. ;; move to the start of the first case alternative statement
  6546. (vhdl-forward-syntactic-ws indent-point)
  6547. (setq placeholder (point)))
  6548. (cond
  6549. ;; CASE 8A: we saw a case/when statement so we must be
  6550. ;; in a switch statement. find out if we are at the
  6551. ;; statement just after a case alternative key
  6552. ((and incase-p
  6553. (= (point) indent-point))
  6554. ;; relpos is the "when" keyword
  6555. (vhdl-add-syntax 'statement-case-intro incase-p))
  6556. ;; CASE 8B: any old statement
  6557. ((< (point) indent-point)
  6558. ;; relpos is the first statement of the block
  6559. (vhdl-add-syntax 'statement placeholder)
  6560. (if begin-after-ip
  6561. (vhdl-add-syntax 'block-open)))
  6562. ;; CASE 8C: first statement in a block
  6563. (t
  6564. (goto-char containing-sexp)
  6565. ;; If the \"begin\" keyword is a trailer, then find v-b-o-s
  6566. (if (looking-at vhdl-trailer-re)
  6567. (progn (forward-sexp) (vhdl-beginning-of-statement-1 nil)))
  6568. (vhdl-backward-skip-label (vhdl-point 'boi))
  6569. (vhdl-add-syntax 'statement-block-intro (point))
  6570. (if begin-after-ip
  6571. (vhdl-add-syntax 'block-open)))
  6572. )))
  6573. )
  6574. ;; now we need to look at any modifiers
  6575. (goto-char indent-point)
  6576. (skip-chars-forward " \t")
  6577. (if (or (looking-at "--") (looking-at "/\\*"))
  6578. (vhdl-add-syntax 'comment))
  6579. (if (looking-at "`")
  6580. (vhdl-add-syntax 'directive))
  6581. (if (eq literal 'pound)
  6582. (vhdl-add-syntax 'cpp-macro))
  6583. ;; return the syntax
  6584. vhdl-syntactic-context))))
  6585. ;; Standard indentation line-ups:
  6586. (defun vhdl-lineup-arglist (langelem)
  6587. "Lineup the current arglist line with the arglist appearing just
  6588. after the containing paren which starts the arglist."
  6589. (save-excursion
  6590. (let* ((containing-sexp
  6591. (save-excursion
  6592. ;; arglist-cont-nonempty gives relpos ==
  6593. ;; to boi of containing-sexp paren. This
  6594. ;; is good when offset is +, but bad
  6595. ;; when it is vhdl-lineup-arglist, so we
  6596. ;; have to special case a kludge here.
  6597. (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
  6598. (progn
  6599. (beginning-of-line)
  6600. (backward-up-list 1)
  6601. (skip-chars-forward " \t" (vhdl-point 'eol)))
  6602. (goto-char (cdr langelem)))
  6603. (point)))
  6604. (cs-curcol (save-excursion
  6605. (goto-char (cdr langelem))
  6606. (current-column))))
  6607. (if (save-excursion
  6608. (beginning-of-line)
  6609. (looking-at "[ \t]*)"))
  6610. (progn (goto-char (match-end 0))
  6611. (backward-sexp)
  6612. (forward-char)
  6613. (vhdl-forward-syntactic-ws)
  6614. (- (current-column) cs-curcol))
  6615. (goto-char containing-sexp)
  6616. (or (eolp)
  6617. (let ((eol (vhdl-point 'eol))
  6618. (here (progn
  6619. (forward-char)
  6620. (skip-chars-forward " \t")
  6621. (point))))
  6622. (vhdl-forward-syntactic-ws)
  6623. (if (< (point) eol)
  6624. (goto-char here))))
  6625. (- (current-column) cs-curcol)
  6626. ))))
  6627. (defun vhdl-lineup-arglist-intro (langelem)
  6628. "Lineup an arglist-intro line to just after the open paren."
  6629. (save-excursion
  6630. (let ((cs-curcol (save-excursion
  6631. (goto-char (cdr langelem))
  6632. (current-column)))
  6633. (ce-curcol (save-excursion
  6634. (beginning-of-line)
  6635. (backward-up-list 1)
  6636. (skip-chars-forward " \t" (vhdl-point 'eol))
  6637. (current-column))))
  6638. (- ce-curcol cs-curcol -1))))
  6639. (defun vhdl-lineup-comment (langelem)
  6640. "Support old behavior for comment indentation. We look at
  6641. vhdl-comment-only-line-offset to decide how to indent comment
  6642. only-lines."
  6643. (save-excursion
  6644. (back-to-indentation)
  6645. ;; at or to the right of comment-column
  6646. (if (>= (current-column) comment-column)
  6647. (vhdl-comment-indent)
  6648. ;; otherwise, indent as specified by vhdl-comment-only-line-offset
  6649. (if (not (bolp))
  6650. ;; inside multi-line comment
  6651. (if (looking-at "\\*")
  6652. 1
  6653. ;; otherwise
  6654. (or (car-safe vhdl-comment-only-line-offset)
  6655. vhdl-comment-only-line-offset))
  6656. (or (cdr-safe vhdl-comment-only-line-offset)
  6657. (car-safe vhdl-comment-only-line-offset)
  6658. -1000 ;jam it against the left side
  6659. )))))
  6660. (defun vhdl-lineup-statement-cont (langelem)
  6661. "Line up statement-cont after the assignment operator."
  6662. (save-excursion
  6663. (let* ((relpos (cdr langelem))
  6664. (assignp (save-excursion
  6665. (goto-char (vhdl-point 'boi))
  6666. (and (re-search-forward "\\(<\\|:\\|=\\)="
  6667. (vhdl-point 'eol) t)
  6668. (- (point) (vhdl-point 'boi)))))
  6669. (curcol (progn
  6670. (goto-char relpos)
  6671. (current-column)))
  6672. foundp)
  6673. (while (and (not foundp)
  6674. (< (point) (vhdl-point 'eol)))
  6675. (re-search-forward "\\(<\\|:\\|=\\)=\\|(" (vhdl-point 'eol) 'move)
  6676. (if (vhdl-in-literal)
  6677. (forward-char)
  6678. (if (= (preceding-char) ?\()
  6679. ;; skip over any parenthesized expressions
  6680. (goto-char (min (vhdl-point 'eol)
  6681. (scan-lists (point) 1 1)))
  6682. ;; found an assignment operator (not at eol)
  6683. (setq foundp (not (looking-at "\\s-*$"))))))
  6684. (if (not foundp)
  6685. ;; there's no assignment operator on the line
  6686. vhdl-basic-offset
  6687. ;; calculate indentation column after assign and ws, unless
  6688. ;; our line contains an assignment operator
  6689. (if (not assignp)
  6690. (progn
  6691. (forward-char)
  6692. (skip-chars-forward " \t")
  6693. (setq assignp 0)))
  6694. (- (current-column) assignp curcol))
  6695. )))
  6696. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6697. ;; Progress reporting
  6698. (defvar vhdl-progress-info nil
  6699. "Array variable for progress information: 0 begin, 1 end, 2 time.")
  6700. (defun vhdl-update-progress-info (string pos)
  6701. "Update progress information."
  6702. (when (and vhdl-progress-info (not noninteractive)
  6703. (< vhdl-progress-interval
  6704. (- (nth 1 (current-time)) (aref vhdl-progress-info 2))))
  6705. (let ((delta (- (aref vhdl-progress-info 1)
  6706. (aref vhdl-progress-info 0))))
  6707. (message "%s... (%2d%%)" string
  6708. (if (= 0 delta)
  6709. 100
  6710. (floor (* 100.0 (- pos (aref vhdl-progress-info 0)))
  6711. delta))))
  6712. (aset vhdl-progress-info 2 (nth 1 (current-time)))))
  6713. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6714. ;; Indentation commands
  6715. (defun vhdl-electric-tab (&optional prefix-arg)
  6716. "If preceding character is part of a word or a paren then hippie-expand,
  6717. else if right of non whitespace on line then insert tab,
  6718. else if last command was a tab or return then dedent one step or if a comment
  6719. toggle between normal indent and inline comment indent,
  6720. else indent `correctly'."
  6721. (interactive "*P")
  6722. (vhdl-prepare-search-2
  6723. (cond
  6724. ;; indent region if region is active
  6725. ((and (not (featurep 'xemacs)) (use-region-p))
  6726. (vhdl-indent-region (region-beginning) (region-end) nil))
  6727. ;; expand word
  6728. ((= (char-syntax (preceding-char)) ?w)
  6729. (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
  6730. (case-replace nil)
  6731. (hippie-expand-only-buffers
  6732. (or (and (boundp 'hippie-expand-only-buffers)
  6733. hippie-expand-only-buffers)
  6734. '(vhdl-mode))))
  6735. (vhdl-expand-abbrev prefix-arg)))
  6736. ;; expand parenthesis
  6737. ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
  6738. (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
  6739. (case-replace nil))
  6740. (vhdl-expand-paren prefix-arg)))
  6741. ;; insert tab
  6742. ((> (current-column) (current-indentation))
  6743. (insert-tab))
  6744. ;; toggle comment indent
  6745. ((and (looking-at "--")
  6746. (or (eq last-command 'vhdl-electric-tab)
  6747. (eq last-command 'vhdl-electric-return)))
  6748. (cond ((= (current-indentation) 0) ; no indent
  6749. (indent-to 1)
  6750. (indent-according-to-mode))
  6751. ((< (current-indentation) comment-column) ; normal indent
  6752. (indent-to comment-column)
  6753. (indent-according-to-mode))
  6754. (t ; inline comment indent
  6755. (delete-region (line-beginning-position) (point)))))
  6756. ;; dedent
  6757. ((and (>= (current-indentation) vhdl-basic-offset)
  6758. (or (eq last-command 'vhdl-electric-tab)
  6759. (eq last-command 'vhdl-electric-return)))
  6760. (backward-delete-char-untabify vhdl-basic-offset nil))
  6761. ;; indent line
  6762. (t (indent-according-to-mode)))
  6763. (setq this-command 'vhdl-electric-tab)))
  6764. (defun vhdl-electric-return ()
  6765. "newline-and-indent or indent-new-comment-line if in comment and preceding
  6766. character is a space."
  6767. (interactive)
  6768. (if (and (= (preceding-char) ? ) (vhdl-in-comment-p))
  6769. (indent-new-comment-line)
  6770. (when (and (>= (preceding-char) ?a) (<= (preceding-char) ?z)
  6771. (not (vhdl-in-comment-p)))
  6772. (vhdl-fix-case-word -1))
  6773. (newline-and-indent)))
  6774. (defun vhdl-indent-line ()
  6775. "Indent the current line as VHDL code. Returns the amount of
  6776. indentation change."
  6777. (interactive)
  6778. (let* ((syntax (and vhdl-indent-syntax-based (vhdl-get-syntactic-context)))
  6779. (pos (- (point-max) (point)))
  6780. (is-comment nil)
  6781. (indent
  6782. (if syntax
  6783. ;; indent syntax-based
  6784. (if (and (eq (caar syntax) 'comment)
  6785. (>= (vhdl-get-offset (car syntax)) comment-column))
  6786. ;; special case: comments at or right of comment-column
  6787. (vhdl-get-offset (car syntax))
  6788. ;; align comments like following code line
  6789. (when vhdl-indent-comment-like-next-code-line
  6790. (save-excursion
  6791. (while (eq (caar syntax) 'comment)
  6792. (setq is-comment t)
  6793. (beginning-of-line 2)
  6794. (setq syntax (vhdl-get-syntactic-context)))))
  6795. (when is-comment
  6796. (push (cons 'comment nil) syntax))
  6797. (apply '+ (mapcar 'vhdl-get-offset syntax)))
  6798. ;; indent like previous nonblank line
  6799. (save-excursion (beginning-of-line)
  6800. (re-search-backward "^[^\n]" nil t)
  6801. (current-indentation))))
  6802. (shift-amt (- indent (current-indentation))))
  6803. (and vhdl-echo-syntactic-information-p
  6804. (message "syntax: %s, indent= %d" syntax indent))
  6805. (let ((has-formfeed
  6806. (save-excursion (beginning-of-line) (looking-at "\\s-*\f"))))
  6807. (when (or (not (zerop shift-amt)) has-formfeed)
  6808. (delete-region (vhdl-point 'bol) (vhdl-point 'boi))
  6809. (beginning-of-line)
  6810. (when has-formfeed (insert "\f"))
  6811. (indent-to indent)))
  6812. (if (< (point) (vhdl-point 'boi))
  6813. (back-to-indentation)
  6814. ;; If initial point was within line's indentation, position after
  6815. ;; the indentation. Else stay at same point in text.
  6816. (when (> (- (point-max) pos) (point))
  6817. (goto-char (- (point-max) pos))))
  6818. (run-hooks 'vhdl-special-indent-hook)
  6819. (vhdl-update-progress-info "Indenting" (vhdl-current-line))
  6820. shift-amt))
  6821. (defun vhdl-indent-region (beg end &optional column)
  6822. "Indent region as VHDL code.
  6823. Adds progress reporting to `indent-region'."
  6824. (interactive "r\nP")
  6825. (when vhdl-progress-interval
  6826. (setq vhdl-progress-info (vector (count-lines (point-min) beg)
  6827. (count-lines (point-min) end) 0)))
  6828. (indent-region beg end column)
  6829. (when vhdl-progress-interval (message "Indenting...done"))
  6830. (setq vhdl-progress-info nil))
  6831. (defun vhdl-indent-buffer ()
  6832. "Indent whole buffer as VHDL code.
  6833. Calls `indent-region' for whole buffer and adds progress reporting."
  6834. (interactive)
  6835. (vhdl-indent-region (point-min) (point-max)))
  6836. (defun vhdl-indent-group ()
  6837. "Indent group of lines between empty lines."
  6838. (interactive)
  6839. (let ((beg (save-excursion
  6840. (if (re-search-backward vhdl-align-group-separate nil t)
  6841. (point-marker)
  6842. (point-min-marker))))
  6843. (end (save-excursion
  6844. (if (re-search-forward vhdl-align-group-separate nil t)
  6845. (point-marker)
  6846. (point-max-marker)))))
  6847. (vhdl-indent-region beg end)))
  6848. (defun vhdl-indent-sexp (&optional endpos)
  6849. "Indent each line of the list starting just after point.
  6850. If optional arg ENDPOS is given, indent each line, stopping when
  6851. ENDPOS is encountered."
  6852. (interactive)
  6853. (save-excursion
  6854. (let ((beg (point))
  6855. (end (progn (vhdl-forward-sexp nil endpos) (point))))
  6856. (indent-region beg end nil))))
  6857. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6858. ;; Miscellaneous commands
  6859. (defun vhdl-show-syntactic-information ()
  6860. "Show syntactic information for current line."
  6861. (interactive)
  6862. (message "Syntactic analysis: %s" (vhdl-get-syntactic-context))
  6863. (vhdl-keep-region-active))
  6864. ;; Verification and regression functions:
  6865. (defun vhdl-regress-line (&optional arg)
  6866. "Check syntactic information for current line."
  6867. (interactive "P")
  6868. (let ((expected (save-excursion
  6869. (end-of-line)
  6870. (when (search-backward " -- ((" (vhdl-point 'bol) t)
  6871. (forward-char 4)
  6872. (read (current-buffer)))))
  6873. (actual (vhdl-get-syntactic-context))
  6874. (expurgated))
  6875. ;; remove the library unit symbols
  6876. (mapc
  6877. (function
  6878. (lambda (elt)
  6879. (if (memq (car elt) '(entity configuration context package
  6880. package-body architecture))
  6881. nil
  6882. (setq expurgated (append expurgated (list elt))))))
  6883. actual)
  6884. (if (and (not arg) expected (listp expected))
  6885. (if (not (equal expected expurgated))
  6886. (error "ERROR: Should be: %s, is: %s" expected expurgated))
  6887. (save-excursion
  6888. (beginning-of-line)
  6889. (when (not (looking-at "^\\s-*\\(--.*\\)?$"))
  6890. (end-of-line)
  6891. (if (search-backward " -- ((" (vhdl-point 'bol) t)
  6892. (delete-region (point) (line-end-position)))
  6893. (insert " -- ")
  6894. (insert (format "%s" expurgated))))))
  6895. (vhdl-keep-region-active))
  6896. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6897. ;;; Alignment, beautifying
  6898. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6899. (defconst vhdl-align-alist
  6900. '(
  6901. ;; after some keywords
  6902. (vhdl-mode "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)[ \t]"
  6903. "^\\s-*\\(across\\|constant\\|quantity\\|signal\\|subtype\\|terminal\\|through\\|type\\|variable\\)\\([ \t]+\\)" 2)
  6904. ;; before ':'
  6905. (vhdl-mode ":[^=]" "\\([ \t]*\\):[^=]")
  6906. ;; after direction specifications
  6907. (vhdl-mode ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\>"
  6908. ":[ \t]*\\(in\\|out\\|inout\\|buffer\\|\\)\\([ \t]+\\)" 2)
  6909. ;; before "==", ":=", "=>", and "<="
  6910. (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "<= ... =>" can occur
  6911. (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
  6912. (vhdl-mode "[<:=]=" "\\([ \t]*\\)\\??[<:=]=" 1) ; since "=> ... <=" can occur
  6913. ;; before some keywords
  6914. (vhdl-mode "[ \t]after\\>" "[^ \t]\\([ \t]+\\)after\\>" 1)
  6915. (vhdl-mode "[ \t]when\\>" "[^ \t]\\([ \t]+\\)when\\>" 1)
  6916. (vhdl-mode "[ \t]else\\>" "[^ \t]\\([ \t]+\\)else\\>" 1)
  6917. (vhdl-mode "[ \t]across\\>" "[^ \t]\\([ \t]+\\)across\\>" 1)
  6918. (vhdl-mode "[ \t]through\\>" "[^ \t]\\([ \t]+\\)through\\>" 1)
  6919. ;; before "=>" since "when/else ... =>" can occur
  6920. (vhdl-mode "=>" "\\([ \t]*\\)=>" 1)
  6921. )
  6922. "The format of this alist is (MODES [or MODE] REGEXP ALIGN-PATTERN SUBEXP).
  6923. It is searched in order. If REGEXP is found anywhere in the first
  6924. line of a region to be aligned, ALIGN-PATTERN will be used for that
  6925. region. ALIGN-PATTERN must include the whitespace to be expanded or
  6926. contracted. It may also provide regexps for the text surrounding the
  6927. whitespace. SUBEXP specifies which sub-expression of
  6928. ALIGN-PATTERN matches the white space to be expanded/contracted.")
  6929. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6930. ;; Align code
  6931. (defvar vhdl-align-try-all-clauses t
  6932. "If REGEXP is not found on the first line of the region that clause
  6933. is ignored. If this variable is non-nil, then the clause is tried anyway.")
  6934. (defun vhdl-do-group (function &optional spacing)
  6935. "Apply FUNCTION on group of lines between empty lines."
  6936. (let
  6937. ;; search for group beginning
  6938. ((beg (save-excursion
  6939. (if (re-search-backward vhdl-align-group-separate nil t)
  6940. (progn (beginning-of-line 2) (back-to-indentation) (point))
  6941. (point-min))))
  6942. ;; search for group end
  6943. (end (save-excursion
  6944. (if (re-search-forward vhdl-align-group-separate nil t)
  6945. (progn (beginning-of-line) (point))
  6946. (point-max)))))
  6947. ;; run FUNCTION
  6948. (funcall function beg end spacing)))
  6949. (defun vhdl-do-list (function &optional spacing)
  6950. "Apply FUNCTION to the lines of a list surrounded by a balanced group of
  6951. parentheses."
  6952. (let (beg end)
  6953. (save-excursion
  6954. ;; search for beginning of balanced group of parentheses
  6955. (setq beg (vhdl-re-search-backward "[()]" nil t))
  6956. (while (looking-at ")")
  6957. (forward-char) (backward-sexp)
  6958. (setq beg (vhdl-re-search-backward "[()]" nil t)))
  6959. ;; search for end of balanced group of parentheses
  6960. (when beg
  6961. (forward-list)
  6962. (setq end (point))
  6963. (goto-char (1+ beg))
  6964. (skip-chars-forward " \t\n\r\f")
  6965. (setq beg (point))))
  6966. ;; run FUNCTION
  6967. (if beg
  6968. (funcall function beg end spacing)
  6969. (error "ERROR: Not within a list enclosed by a pair of parentheses"))))
  6970. (defun vhdl-do-same-indent (function &optional spacing)
  6971. "Apply FUNCTION to block of lines with same indent."
  6972. (let ((indent (current-indentation))
  6973. beg end)
  6974. ;; search for first line with same indent
  6975. (save-excursion
  6976. (while (and (not (bobp))
  6977. (or (looking-at "^\\s-*\\(--.*\\)?$")
  6978. (= (current-indentation) indent)))
  6979. (unless (looking-at "^\\s-*$")
  6980. (back-to-indentation) (setq beg (point)))
  6981. (beginning-of-line -0)))
  6982. ;; search for last line with same indent
  6983. (save-excursion
  6984. (while (and (not (eobp))
  6985. (or (looking-at "^\\s-*\\(--.*\\)?$")
  6986. (= (current-indentation) indent)))
  6987. (if (looking-at "^\\s-*$")
  6988. (beginning-of-line 2)
  6989. (beginning-of-line 2)
  6990. (setq end (point)))))
  6991. ;; run FUNCTION
  6992. (funcall function beg end spacing)))
  6993. (defun vhdl-align-region-1 (begin end &optional spacing alignment-list indent)
  6994. "Attempt to align a range of lines based on the content of the
  6995. lines. The definition of `alignment-list' determines the matching
  6996. order and the manner in which the lines are aligned. If ALIGNMENT-LIST
  6997. is not specified `vhdl-align-alist' is used. If INDENT is non-nil,
  6998. indentation is done before aligning."
  6999. (interactive "r\np")
  7000. (setq alignment-list (or alignment-list vhdl-align-alist))
  7001. (setq spacing (or spacing 1))
  7002. (save-excursion
  7003. (let (bol indent)
  7004. (goto-char end)
  7005. (setq end (point-marker))
  7006. (goto-char begin)
  7007. (setq bol (setq begin (progn (beginning-of-line) (point))))
  7008. (when indent
  7009. (indent-region bol end nil))))
  7010. (let ((copy (copy-alist alignment-list)))
  7011. (vhdl-prepare-search-2
  7012. (while copy
  7013. (save-excursion
  7014. (goto-char begin)
  7015. (let (element
  7016. (eol (point-at-eol)))
  7017. (setq element (nth 0 copy))
  7018. (when (and (or (and (listp (car element))
  7019. (memq major-mode (car element)))
  7020. (eq major-mode (car element)))
  7021. (or vhdl-align-try-all-clauses
  7022. (re-search-forward (car (cdr element)) eol t)))
  7023. (vhdl-align-region-2 begin end (car (cdr (cdr element)))
  7024. (car (cdr (cdr (cdr element)))) spacing))
  7025. (setq copy (cdr copy))))))))
  7026. (defun vhdl-align-region-2 (begin end match &optional substr spacing)
  7027. "Align a range of lines from BEGIN to END. The regular expression
  7028. MATCH must match exactly one field: the whitespace to be
  7029. contracted/expanded. The alignment column will equal the
  7030. rightmost column of the widest whitespace block. SPACING is
  7031. the amount of extra spaces to add to the calculated maximum required.
  7032. SPACING defaults to 1 so that at least one space is inserted after
  7033. the token in MATCH."
  7034. (setq spacing (or spacing 1))
  7035. (setq substr (or substr 1))
  7036. (save-excursion
  7037. (let (distance (max 0) (lines 0) bol eol width)
  7038. ;; Determine the greatest whitespace distance to the alignment
  7039. ;; character
  7040. (goto-char begin)
  7041. (setq eol (point-at-eol)
  7042. bol (setq begin (progn (beginning-of-line) (point))))
  7043. (while (< bol end)
  7044. (save-excursion
  7045. (when (and (vhdl-re-search-forward match eol t)
  7046. (save-excursion
  7047. (goto-char (match-beginning 0))
  7048. (forward-char)
  7049. (and (not (vhdl-in-literal))
  7050. (not (vhdl-in-quote-p))
  7051. (not (vhdl-in-extended-identifier-p))))
  7052. (not (looking-at "\\s-*$")))
  7053. (setq distance (- (match-beginning substr) bol))
  7054. (when (> distance max)
  7055. (setq max distance))))
  7056. (forward-line)
  7057. (setq bol (point)
  7058. eol (point-at-eol))
  7059. (setq lines (1+ lines)))
  7060. ;; Now insert enough maxs to push each assignment operator to
  7061. ;; the same column. We need to use 'lines' as a counter, since
  7062. ;; the location of the mark may change
  7063. (goto-char (setq bol begin))
  7064. (setq eol (point-at-eol))
  7065. (while (> lines 0)
  7066. (when (and (vhdl-re-search-forward match eol t)
  7067. (save-excursion
  7068. (goto-char (match-beginning 0))
  7069. (forward-char)
  7070. (and (not (vhdl-in-literal))
  7071. (not (vhdl-in-quote-p))
  7072. (not (vhdl-in-extended-identifier-p))))
  7073. (not (looking-at "\\s-*$"))
  7074. (> (match-beginning 0) ; not if at boi
  7075. (save-excursion (back-to-indentation) (point))))
  7076. (setq width (- (match-end substr) (match-beginning substr)))
  7077. (setq distance (- (match-beginning substr) bol))
  7078. (goto-char (match-beginning substr))
  7079. (delete-char width)
  7080. (insert-char ? (+ (- max distance) spacing)))
  7081. (beginning-of-line)
  7082. (forward-line)
  7083. (setq bol (point)
  7084. eol (point-at-eol))
  7085. (setq lines (1- lines))))))
  7086. (defun vhdl-align-region-groups (beg end &optional spacing
  7087. no-message no-comments)
  7088. "Align region, treat groups of lines separately."
  7089. (interactive "r\nP")
  7090. (save-excursion
  7091. (let (orig pos)
  7092. (goto-char beg)
  7093. (beginning-of-line)
  7094. (setq orig (point-marker))
  7095. (setq beg (point))
  7096. (goto-char end)
  7097. (setq end (point-marker))
  7098. (untabify beg end)
  7099. (unless no-message
  7100. (when vhdl-progress-interval
  7101. (setq vhdl-progress-info (vector (count-lines (point-min) beg)
  7102. (count-lines (point-min) end) 0))))
  7103. (when (nth 0 vhdl-beautify-options)
  7104. (vhdl-fixup-whitespace-region beg end t))
  7105. (goto-char beg)
  7106. (if (not vhdl-align-groups)
  7107. ;; align entire region
  7108. (progn (vhdl-align-region-1 beg end spacing)
  7109. (unless no-comments
  7110. (vhdl-align-inline-comment-region-1 beg end)))
  7111. ;; align groups
  7112. (while (and (< beg end)
  7113. (re-search-forward vhdl-align-group-separate end t))
  7114. (setq pos (point-marker))
  7115. (vhdl-align-region-1 beg pos spacing)
  7116. (unless no-comments (vhdl-align-inline-comment-region-1 beg pos))
  7117. (vhdl-update-progress-info "Aligning" (vhdl-current-line))
  7118. (setq beg (1+ pos))
  7119. (goto-char beg))
  7120. ;; align last group
  7121. (when (< beg end)
  7122. (vhdl-align-region-1 beg end spacing)
  7123. (unless no-comments (vhdl-align-inline-comment-region-1 beg end))
  7124. (vhdl-update-progress-info "Aligning" (vhdl-current-line))))
  7125. (when vhdl-indent-tabs-mode
  7126. (tabify orig end))
  7127. (unless no-message
  7128. (when vhdl-progress-interval (message "Aligning...done"))
  7129. (setq vhdl-progress-info nil)))))
  7130. (defun vhdl-align-region (beg end &optional spacing)
  7131. "Align region, treat blocks with same indent and argument lists separately."
  7132. (interactive "r\nP")
  7133. (if (not vhdl-align-same-indent)
  7134. ;; align entire region
  7135. (vhdl-align-region-groups beg end spacing)
  7136. ;; align blocks with same indent and argument lists
  7137. (save-excursion
  7138. (let ((cur-beg beg)
  7139. indent cur-end)
  7140. (when vhdl-progress-interval
  7141. (setq vhdl-progress-info (vector (count-lines (point-min) beg)
  7142. (count-lines (point-min) end) 0)))
  7143. (goto-char end)
  7144. (setq end (point-marker))
  7145. (goto-char cur-beg)
  7146. (while (< (point) end)
  7147. ;; is argument list opening?
  7148. (if (setq cur-beg (nth 1 (save-excursion (parse-partial-sexp
  7149. (point) (vhdl-point 'eol)))))
  7150. ;; determine region for argument list
  7151. (progn (goto-char cur-beg)
  7152. (forward-sexp)
  7153. (setq cur-end (point))
  7154. (beginning-of-line 2))
  7155. ;; determine region with same indent
  7156. (setq indent (current-indentation))
  7157. (setq cur-beg (point))
  7158. (setq cur-end (vhdl-point 'bonl))
  7159. (beginning-of-line 2)
  7160. (while (and (< (point) end)
  7161. (or (looking-at "^\\s-*\\(--.*\\)?$")
  7162. (= (current-indentation) indent))
  7163. (<= (save-excursion
  7164. (nth 0 (parse-partial-sexp
  7165. (point) (vhdl-point 'eol)))) 0))
  7166. (unless (looking-at "^\\s-*$")
  7167. (setq cur-end (vhdl-point 'bonl)))
  7168. (beginning-of-line 2)))
  7169. ;; align region
  7170. (vhdl-align-region-groups cur-beg cur-end spacing t t))
  7171. (vhdl-align-inline-comment-region beg end spacing noninteractive)
  7172. (when vhdl-progress-interval (message "Aligning...done"))
  7173. (setq vhdl-progress-info nil)))))
  7174. (defun vhdl-align-group (&optional spacing)
  7175. "Align group of lines between empty lines."
  7176. (interactive)
  7177. (vhdl-do-group 'vhdl-align-region spacing))
  7178. (defun vhdl-align-list (&optional spacing)
  7179. "Align the lines of a list surrounded by a balanced group of parentheses."
  7180. (interactive)
  7181. (vhdl-do-list 'vhdl-align-region-groups spacing))
  7182. (defun vhdl-align-same-indent (&optional spacing)
  7183. "Align block of lines with same indent."
  7184. (interactive)
  7185. (vhdl-do-same-indent 'vhdl-align-region-groups spacing))
  7186. (defun vhdl-align-declarations (&optional spacing)
  7187. "Align the lines within the declarative part of a design unit."
  7188. (interactive)
  7189. (let (beg end)
  7190. (vhdl-prepare-search-2
  7191. (save-excursion
  7192. ;; search for declarative part
  7193. (when (and (re-search-backward "^\\(architecture\\|begin\\|configuration\\|context\\|end\\|entity\\|package\\)\\>" nil t)
  7194. (not (member (upcase (match-string 1)) '("BEGIN" "END"))))
  7195. (setq beg (point))
  7196. (re-search-forward "^\\(begin\\|end\\)\\>" nil t)
  7197. (setq end (point)))))
  7198. (if beg
  7199. (vhdl-align-region-groups beg end spacing)
  7200. (error "ERROR: Not within the declarative part of a design unit"))))
  7201. (defun vhdl-align-buffer ()
  7202. "Align buffer."
  7203. (interactive)
  7204. (vhdl-align-region (point-min) (point-max)))
  7205. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7206. ;; Align inline comments
  7207. (defun vhdl-align-inline-comment-region-1 (beg end &optional spacing)
  7208. "Align inline comments in region."
  7209. (save-excursion
  7210. (let ((start-max comment-column)
  7211. (length-max 0)
  7212. comment-list start-list tmp-list start length
  7213. cur-start prev-start no-code)
  7214. (setq spacing (or spacing 2))
  7215. (vhdl-prepare-search-2
  7216. (goto-char beg)
  7217. ;; search for comment start positions and lengths
  7218. (while (< (point) end)
  7219. (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
  7220. (looking-at "^\\(.*?[^ \t\n\r\f-]+\\)\\s-*\\(--.*\\)$")
  7221. (not (save-excursion (goto-char (match-beginning 2))
  7222. (vhdl-in-literal))))
  7223. (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
  7224. (setq length (- (match-end 2) (match-beginning 2)))
  7225. (setq start-max (max start start-max))
  7226. (setq length-max (max length length-max))
  7227. (push (cons start length) comment-list))
  7228. (beginning-of-line 2))
  7229. (setq comment-list
  7230. (sort comment-list (function (lambda (a b) (> (car a) (car b))))))
  7231. ;; reduce start positions
  7232. (setq start-list (list (caar comment-list)))
  7233. (setq comment-list (cdr comment-list))
  7234. (while comment-list
  7235. (unless (or (= (caar comment-list) (car start-list))
  7236. (<= (+ (car start-list) (cdar comment-list))
  7237. end-comment-column))
  7238. (push (caar comment-list) start-list))
  7239. (setq comment-list (cdr comment-list)))
  7240. ;; align lines as nicely as possible
  7241. (goto-char beg)
  7242. (while (< (point) end)
  7243. (setq cur-start nil)
  7244. (when (and (not (looking-at "^\\s-*\\(begin\\|end\\)\\>"))
  7245. (or (and (looking-at "^\\(.*?[^ \t\n\r\f-]+\\)\\(\\s-*\\)\\(--.*\\)$")
  7246. (not (save-excursion
  7247. (goto-char (match-beginning 3))
  7248. (vhdl-in-literal))))
  7249. (and (looking-at "^\\(\\)\\(\\s-*\\)\\(--.*\\)$")
  7250. (>= (- (match-end 2) (match-beginning 2))
  7251. comment-column))))
  7252. (setq start (+ (- (match-end 1) (match-beginning 1)) spacing))
  7253. (setq length (- (match-end 3) (match-beginning 3)))
  7254. (setq no-code (= (match-beginning 1) (match-end 1)))
  7255. ;; insert minimum whitespace
  7256. (goto-char (match-end 2))
  7257. (delete-region (match-beginning 2) (match-end 2))
  7258. (insert-char ?\ spacing)
  7259. (setq tmp-list start-list)
  7260. ;; insert additional whitespace to align
  7261. (setq cur-start
  7262. (cond
  7263. ;; align comment-only line to inline comment of previous line
  7264. ((and no-code prev-start
  7265. (<= length (- end-comment-column prev-start)))
  7266. prev-start)
  7267. ;; align all comments at `start-max' if this is possible
  7268. ((<= (+ start-max length-max) end-comment-column)
  7269. start-max)
  7270. ;; align at `comment-column' if possible
  7271. ((and (<= start comment-column)
  7272. (<= length (- end-comment-column comment-column)))
  7273. comment-column)
  7274. ;; align at left-most possible start position otherwise
  7275. (t
  7276. (while (and tmp-list (< (car tmp-list) start))
  7277. (setq tmp-list (cdr tmp-list)))
  7278. (car tmp-list))))
  7279. (indent-to cur-start))
  7280. (setq prev-start cur-start)
  7281. (beginning-of-line 2))))))
  7282. (defun vhdl-align-inline-comment-region (beg end &optional spacing no-message)
  7283. "Align inline comments within a region. Groups of code lines separated by
  7284. empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
  7285. (interactive "r\nP")
  7286. (save-excursion
  7287. (let (orig pos)
  7288. (goto-char beg)
  7289. (beginning-of-line)
  7290. (setq orig (point-marker))
  7291. (setq beg (point))
  7292. (goto-char end)
  7293. (setq end (point-marker))
  7294. (untabify beg end)
  7295. (unless no-message (message "Aligning inline comments..."))
  7296. (goto-char beg)
  7297. (if (not vhdl-align-groups)
  7298. ;; align entire region
  7299. (vhdl-align-inline-comment-region-1 beg end spacing)
  7300. ;; align groups
  7301. (while (and (< beg end)
  7302. (re-search-forward vhdl-align-group-separate end t))
  7303. (setq pos (point-marker))
  7304. (vhdl-align-inline-comment-region-1 beg pos spacing)
  7305. (setq beg (1+ pos))
  7306. (goto-char beg))
  7307. ;; align last group
  7308. (when (< beg end)
  7309. (vhdl-align-inline-comment-region-1 beg end spacing)))
  7310. (when vhdl-indent-tabs-mode
  7311. (tabify orig end))
  7312. (unless no-message (message "Aligning inline comments...done")))))
  7313. (defun vhdl-align-inline-comment-group (&optional spacing)
  7314. "Align inline comments within a group of lines between empty lines."
  7315. (interactive)
  7316. (save-excursion
  7317. (let ((start (point))
  7318. beg end)
  7319. (setq end (if (re-search-forward vhdl-align-group-separate nil t)
  7320. (point-marker) (point-max)))
  7321. (goto-char start)
  7322. (setq beg (if (re-search-backward vhdl-align-group-separate nil t)
  7323. (point) (point-min)))
  7324. (untabify beg end)
  7325. (message "Aligning inline comments...")
  7326. (vhdl-align-inline-comment-region-1 beg end)
  7327. (when vhdl-indent-tabs-mode
  7328. (tabify beg end))
  7329. (message "Aligning inline comments...done"))))
  7330. (defun vhdl-align-inline-comment-buffer ()
  7331. "Align inline comments within buffer. Groups of code lines separated by
  7332. empty lines are aligned individually, if `vhdl-align-groups' is non-nil."
  7333. (interactive)
  7334. (vhdl-align-inline-comment-region (point-min) (point-max)))
  7335. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7336. ;; Fixup whitespace
  7337. (defun vhdl-fixup-whitespace-region (beg end &optional no-message)
  7338. "Fixup whitespace in region. Surround operator symbols by one space,
  7339. eliminate multiple spaces (except at beginning of line), eliminate spaces at
  7340. end of line, do nothing in comments and strings."
  7341. (interactive "r")
  7342. (unless no-message (message "Fixing up whitespace..."))
  7343. (save-excursion
  7344. (goto-char end)
  7345. (setq end (point-marker))
  7346. ;; have no space before and one space after `,' and ';'
  7347. (goto-char beg)
  7348. (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|'.'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\s-*\\([,;]\\)\\)" end t)
  7349. (if (match-string 1)
  7350. (goto-char (match-end 1))
  7351. (replace-match "\\3 " nil nil nil 2)))
  7352. ;; have no space after `('
  7353. (goto-char beg)
  7354. (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|'.'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\((\\)\\s-+" end t)
  7355. (if (match-string 1)
  7356. (goto-char (match-end 1))
  7357. (replace-match "\\2")))
  7358. ;; have no space before `)'
  7359. (goto-char beg)
  7360. (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|'.'\\|\\\\[^\\\n]*[\\\n]\\|^\\s-+\\)\\|\\s-+\\()\\)" end t)
  7361. (if (match-string 1)
  7362. (goto-char (match-end 1))
  7363. (replace-match "\\2")))
  7364. ;; surround operator symbols by one space
  7365. (goto-char beg)
  7366. (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\|'.'\\|\\\\[^\\\n]*[\\\n]\\)\\|\\(\\([^/:<>=\n]\\)\\(:\\|\\??=\\|\\??<<\\|\\??>>\\|\\??<\\|\\??>\\|:=\\|\\??<=\\|\\??>=\\|=>\\|\\??/=\\|\\?\\?\\)\\([^=>\n]\\|$\\)\\)" end t)
  7367. (if (or (match-string 1)
  7368. (<= (match-beginning 0) ; not if at boi
  7369. (save-excursion (back-to-indentation) (point))))
  7370. (goto-char (match-end 0))
  7371. (replace-match "\\3 \\4 \\5")
  7372. (goto-char (match-end 2))))
  7373. ;; eliminate multiple spaces and spaces at end of line
  7374. (goto-char beg)
  7375. (while (or (and (looking-at "--.*\n") (re-search-forward "--.*\n" end t))
  7376. (and (looking-at "--.*") (re-search-forward "--.*" end t))
  7377. (and (looking-at "\"") (re-search-forward "\"[^\"\n]*[\"\n]" end t))
  7378. (and (looking-at "\\s-+$") (re-search-forward "\\s-+$" end t)
  7379. (progn (replace-match "" nil nil) t))
  7380. (and (looking-at "\\s-+;") (re-search-forward "\\s-+;" end t)
  7381. (progn (replace-match ";" nil nil) t))
  7382. (and (looking-at "^\\s-+") (re-search-forward "^\\s-+" end t))
  7383. (and (looking-at "\\s-+--") (re-search-forward "\\s-+" end t)
  7384. (progn (replace-match " " nil nil) t))
  7385. (and (looking-at "\\s-+") (re-search-forward "\\s-+" end t)
  7386. (progn (replace-match " " nil nil) t))
  7387. (and (looking-at "-") (re-search-forward "-" end t))
  7388. (re-search-forward "[^ \t\"-]+" end t))))
  7389. (unless no-message (message "Fixing up whitespace...done")))
  7390. (defun vhdl-fixup-whitespace-buffer ()
  7391. "Fixup whitespace in buffer. Surround operator symbols by one space,
  7392. eliminate multiple spaces (except at beginning of line), eliminate spaces at
  7393. end of line, do nothing in comments."
  7394. (interactive)
  7395. (vhdl-fixup-whitespace-region (point-min) (point-max)))
  7396. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7397. ;; Case fixing
  7398. (defun vhdl-fix-case-region-1 (beg end upper-case word-regexp &optional count)
  7399. "Convert all words matching WORD-REGEXP in region to lower or upper case,
  7400. depending on parameter UPPER-CASE."
  7401. (let ((case-replace nil)
  7402. (last-update 0))
  7403. (vhdl-prepare-search-2
  7404. (save-excursion
  7405. (goto-char end)
  7406. (setq end (point-marker))
  7407. (goto-char beg)
  7408. (while (re-search-forward word-regexp end t)
  7409. (or (vhdl-in-literal)
  7410. (if upper-case
  7411. (upcase-word -1)
  7412. (downcase-word -1)))
  7413. (when (and count vhdl-progress-interval (not noninteractive)
  7414. (< vhdl-progress-interval
  7415. (- (nth 1 (current-time)) last-update)))
  7416. (message "Fixing case... (%2d%s)"
  7417. (+ (* count 20) (/ (* 20 (- (point) beg)) (- end beg)))
  7418. "%")
  7419. (setq last-update (nth 1 (current-time)))))
  7420. (goto-char end)))))
  7421. (defun vhdl-fix-case-region (beg end &optional arg)
  7422. "Convert all VHDL words in region to lower or upper case, depending on
  7423. options vhdl-upper-case-{keywords,types,attributes,enum-values}."
  7424. (interactive "r\nP")
  7425. (vhdl-fix-case-region-1
  7426. beg end vhdl-upper-case-keywords vhdl-keywords-regexp 0)
  7427. (vhdl-fix-case-region-1
  7428. beg end vhdl-upper-case-types vhdl-types-regexp 1)
  7429. (vhdl-fix-case-region-1
  7430. beg end vhdl-upper-case-attributes (concat "'" vhdl-attributes-regexp) 2)
  7431. (vhdl-fix-case-region-1
  7432. beg end vhdl-upper-case-enum-values vhdl-enum-values-regexp 3)
  7433. (vhdl-fix-case-region-1
  7434. beg end vhdl-upper-case-constants vhdl-constants-regexp 4)
  7435. (when vhdl-progress-interval (message "Fixing case...done")))
  7436. (defun vhdl-fix-case-buffer ()
  7437. "Convert all VHDL words in buffer to lower or upper case, depending on
  7438. options vhdl-upper-case-{keywords,types,attributes,enum-values}."
  7439. (interactive)
  7440. (vhdl-fix-case-region (point-min) (point-max)))
  7441. (defun vhdl-fix-case-word (&optional arg)
  7442. "Convert word after cursor to upper case if necessary."
  7443. (interactive "p")
  7444. (save-excursion
  7445. (when arg (backward-word 1))
  7446. (vhdl-prepare-search-1
  7447. (when (and vhdl-upper-case-keywords
  7448. (looking-at vhdl-keywords-regexp))
  7449. (upcase-word 1))
  7450. (when (and vhdl-upper-case-types
  7451. (looking-at vhdl-types-regexp))
  7452. (upcase-word 1))
  7453. (when (and vhdl-upper-case-attributes
  7454. (looking-at vhdl-attributes-regexp))
  7455. (upcase-word 1))
  7456. (when (and vhdl-upper-case-enum-values
  7457. (looking-at vhdl-enum-values-regexp))
  7458. (upcase-word 1))
  7459. (when (and vhdl-upper-case-constants
  7460. (looking-at vhdl-constants-regexp))
  7461. (upcase-word 1)))))
  7462. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7463. ;; Fix statements
  7464. ;; - force each statement to be on a separate line except when on same line
  7465. ;; with 'end' keyword
  7466. (defun vhdl-fix-statement-region (beg end &optional arg)
  7467. "Force statements in region on separate line except when on same line
  7468. with 'end' keyword (necessary for correct indentation).
  7469. Currently supported keywords: 'begin', 'if'."
  7470. (interactive "r\nP")
  7471. (vhdl-prepare-search-2
  7472. (let (point)
  7473. (save-excursion
  7474. (goto-char end)
  7475. (setq end (point-marker))
  7476. (goto-char beg)
  7477. ;; `begin' keyword
  7478. (while (re-search-forward
  7479. "^\\s-*[^ \t\n].*?\\(\\<begin\\>\\)\\(.*\\<end\\>\\)?" end t)
  7480. (goto-char (match-end 0))
  7481. (setq point (point-marker))
  7482. (when (and (match-string 1)
  7483. (or (not (match-string 2))
  7484. (save-excursion (goto-char (match-end 2))
  7485. (vhdl-in-literal)))
  7486. (not (save-excursion (goto-char (match-beginning 1))
  7487. (vhdl-in-literal))))
  7488. (goto-char (match-beginning 1))
  7489. (insert "\n")
  7490. (indent-according-to-mode))
  7491. (goto-char point))
  7492. (goto-char beg)
  7493. ;; `for', `if' keywords
  7494. (while (re-search-forward "\\<\\(for\\|if\\)\\>" end t)
  7495. (goto-char (match-end 1))
  7496. (setq point (point-marker))
  7497. ;; exception: in literal or preceded by `end', `wait' or label
  7498. (when (and (not (save-excursion (goto-char (match-beginning 1))
  7499. (vhdl-in-literal)))
  7500. (save-excursion
  7501. (beginning-of-line 1)
  7502. (save-match-data
  7503. (and (re-search-forward "^\\s-*\\([^ \t\n].*\\)"
  7504. (match-beginning 1) t)
  7505. (not (string-match
  7506. "\\(\\<end\\>\\|\\<wait .*\\|\\w+\\s-*:\\)\\s-*$"
  7507. (match-string 1)))))))
  7508. (goto-char (match-beginning 1))
  7509. (insert "\n")
  7510. (indent-according-to-mode))
  7511. (goto-char point))))))
  7512. (defun vhdl-fix-statement-buffer ()
  7513. "Force statements in buffer on separate line except when on same line
  7514. with 'end' keyword (necessary for correct indentation)."
  7515. (interactive)
  7516. (vhdl-fix-statement-region (point-min) (point-max)))
  7517. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7518. ;; Trailing spaces
  7519. (defun vhdl-remove-trailing-spaces-region (beg end &optional arg)
  7520. "Remove trailing spaces in region."
  7521. (interactive "r\nP")
  7522. (save-excursion
  7523. (goto-char end)
  7524. (setq end (point-marker))
  7525. (goto-char beg)
  7526. (while (re-search-forward "[ \t]+$" end t)
  7527. (unless (vhdl-in-literal)
  7528. (replace-match "" nil nil)))))
  7529. (defun vhdl-remove-trailing-spaces ()
  7530. "Remove trailing spaces in buffer."
  7531. (interactive)
  7532. (vhdl-remove-trailing-spaces-region (point-min) (point-max)))
  7533. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7534. ;; Beautify
  7535. (defun vhdl-beautify-region (beg end)
  7536. "Beautify region by applying indentation, whitespace fixup, alignment, and
  7537. case fixing to a region. Calls functions `vhdl-indent-buffer',
  7538. `vhdl-align-buffer' (option `vhdl-align-groups' set to non-nil), and
  7539. `vhdl-fix-case-buffer'."
  7540. (interactive "r")
  7541. (setq end (save-excursion (goto-char end) (point-marker)))
  7542. (save-excursion ; remove DOS EOL characters in UNIX file
  7543. (goto-char beg)
  7544. (while (search-forward "\r" nil t)
  7545. (replace-match "" nil t)))
  7546. (when (nth 0 vhdl-beautify-options) (vhdl-fixup-whitespace-region beg end t))
  7547. (when (nth 1 vhdl-beautify-options) (vhdl-fix-statement-region beg end))
  7548. (when (nth 2 vhdl-beautify-options) (vhdl-indent-region beg end))
  7549. (when (nth 3 vhdl-beautify-options)
  7550. (let ((vhdl-align-groups t)) (vhdl-align-region beg end)))
  7551. (when (nth 4 vhdl-beautify-options) (vhdl-fix-case-region beg end))
  7552. (when (nth 0 vhdl-beautify-options)
  7553. (vhdl-remove-trailing-spaces-region beg end)
  7554. (if vhdl-indent-tabs-mode (tabify beg end) (untabify beg end))))
  7555. (defun vhdl-beautify-buffer ()
  7556. "Beautify buffer by applying indentation, whitespace fixup, alignment, and
  7557. case fixing to entire buffer. Calls `vhdl-beautify-region' for the entire
  7558. buffer."
  7559. (interactive)
  7560. (vhdl-beautify-region (point-min) (point-max))
  7561. (when noninteractive (save-buffer)))
  7562. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7563. ;; Code filling
  7564. (defun vhdl-fill-region (beg end &optional arg)
  7565. "Fill lines for a region of code."
  7566. (interactive "r\np")
  7567. (save-excursion
  7568. (goto-char beg)
  7569. (let ((margin (if arg (current-indentation) (current-column))))
  7570. (goto-char end)
  7571. (setq end (point-marker))
  7572. ;; remove inline comments, newlines and whitespace
  7573. (vhdl-comment-kill-region beg end)
  7574. (vhdl-comment-kill-inline-region beg end)
  7575. (subst-char-in-region beg (1- end) ?\n ?\ )
  7576. (vhdl-fixup-whitespace-region beg end)
  7577. ;; wrap and end-comment-column
  7578. (goto-char beg)
  7579. (while (re-search-forward "\\s-" end t)
  7580. (when(> (current-column) vhdl-end-comment-column)
  7581. (backward-char)
  7582. (when (re-search-backward "\\s-" beg t)
  7583. (replace-match "\n")
  7584. (indent-to margin)))))))
  7585. (defun vhdl-fill-group ()
  7586. "Fill group of lines between empty lines."
  7587. (interactive)
  7588. (vhdl-do-group 'vhdl-fill-region))
  7589. (defun vhdl-fill-list ()
  7590. "Fill the lines of a list surrounded by a balanced group of parentheses."
  7591. (interactive)
  7592. (vhdl-do-list 'vhdl-fill-region))
  7593. (defun vhdl-fill-same-indent ()
  7594. "Fill the lines of block of lines with same indent."
  7595. (interactive)
  7596. (vhdl-do-same-indent 'vhdl-fill-region))
  7597. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7598. ;;; Code updating/fixing
  7599. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7600. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7601. ;; Sensitivity list update
  7602. ;; Strategy:
  7603. ;; - no sensitivity list is generated for processes with wait statements
  7604. ;; - otherwise, do the following:
  7605. ;; 1. scan for all local signals (ports, signals declared in arch./blocks)
  7606. ;; 2. scan for all signals already in the sensitivity list (in order to catch
  7607. ;; manually entered global signals)
  7608. ;; 3. signals from 1. and 2. form the list of visible signals
  7609. ;; 4. search for if/elsif conditions containing an event (sequential code)
  7610. ;; 5. scan for strings that are within syntactical regions where signals are
  7611. ;; read but not within sequential code, and that correspond to visible
  7612. ;; signals
  7613. ;; 6. replace sensitivity list by list of signals from 5.
  7614. (defun vhdl-update-sensitivity-list-process ()
  7615. "Update sensitivity list of current process."
  7616. (interactive)
  7617. (save-excursion
  7618. (vhdl-prepare-search-2
  7619. (end-of-line)
  7620. ;; look whether in process
  7621. (if (not (and (re-search-backward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|end\\s-+process\\)\\>" nil t)
  7622. (equal (upcase (match-string 2)) "PROCESS")
  7623. (save-excursion (re-search-forward "^\\s-*end\\s-+process\\>" nil t))))
  7624. (error "ERROR: Not within a process")
  7625. (message "Updating sensitivity list...")
  7626. (vhdl-update-sensitivity-list)
  7627. (message "Updating sensitivity list...done")))))
  7628. (defun vhdl-update-sensitivity-list-buffer ()
  7629. "Update sensitivity list of all processes in current buffer."
  7630. (interactive)
  7631. (save-excursion
  7632. (vhdl-prepare-search-2
  7633. (goto-char (point-min))
  7634. (message "Updating sensitivity lists...")
  7635. (while (re-search-forward "^\\s-*\\(\\w+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?process\\>" nil t)
  7636. (goto-char (match-beginning 0))
  7637. (condition-case nil (vhdl-update-sensitivity-list) (error "")))
  7638. (message "Updating sensitivity lists...done")))
  7639. (when noninteractive (save-buffer)))
  7640. (defun vhdl-update-sensitivity-list ()
  7641. "Update sensitivity list."
  7642. (let ((proc-beg (point))
  7643. (proc-end (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
  7644. (proc-mid (vhdl-re-search-backward
  7645. "\\(\\(\\<begin\\>\\)\\|^\\s-*process\\>\\)" nil t))
  7646. seq-region-list)
  7647. (cond
  7648. ;; error if 'begin' keyword missing
  7649. ((not (match-string 2))
  7650. (error "ERROR: No 'begin' keyword found"))
  7651. ;; search for wait statement (no sensitivity list allowed)
  7652. ((progn (goto-char proc-mid)
  7653. (vhdl-re-search-forward "\\<wait\\>" proc-end t))
  7654. (error "ERROR: Process with wait statement, sensitivity list not generated"))
  7655. ;; combinational process (update sensitivity list)
  7656. (t
  7657. (let
  7658. ;; scan for visible signals
  7659. ((visible-list (vhdl-get-visible-signals))
  7660. ;; define syntactic regions where signals are read
  7661. (scan-regions-list
  7662. '(;; right-hand side of signal/variable assignment
  7663. ;; (special case: "<=" is relational operator in a condition)
  7664. ((vhdl-re-search-forward "[<:]=" proc-end t)
  7665. (vhdl-re-search-forward ";\\|\\<\\(then\\|loop\\|report\\|severity\\|is\\)\\>" proc-end t))
  7666. ;; if condition
  7667. ((vhdl-re-search-forward "^\\s-*if\\>" proc-end t)
  7668. (vhdl-re-search-forward "\\<then\\>" proc-end t))
  7669. ;; elsif condition
  7670. ((vhdl-re-search-forward "\\<elsif\\>" proc-end t)
  7671. (vhdl-re-search-forward "\\<then\\>" proc-end t))
  7672. ;; while loop condition
  7673. ((vhdl-re-search-forward "^\\s-*while\\>" proc-end t)
  7674. (vhdl-re-search-forward "\\<loop\\>" proc-end t))
  7675. ;; exit/next condition
  7676. ((vhdl-re-search-forward "\\<\\(exit\\|next\\)\\s-+\\w+\\s-+when\\>" proc-end t)
  7677. (vhdl-re-search-forward ";" proc-end t))
  7678. ;; assert condition
  7679. ((vhdl-re-search-forward "\\<assert\\>" proc-end t)
  7680. (vhdl-re-search-forward "\\(\\<report\\>\\|\\<severity\\>\\|;\\)" proc-end t))
  7681. ;; case expression
  7682. ((vhdl-re-search-forward "^\\s-*case\\>" proc-end t)
  7683. (vhdl-re-search-forward "\\<is\\>" proc-end t))
  7684. ;; parameter list of procedure call, array index
  7685. ((and (re-search-forward "^\\s-*\\(\\w\\|\\.\\)+[ \t\n\r\f]*(" proc-end t)
  7686. (1- (point)))
  7687. (progn (backward-char) (forward-sexp)
  7688. (while (looking-at "(") (forward-sexp)) (point)))))
  7689. name field read-list sens-list signal-list tmp-list
  7690. sens-beg sens-end beg end margin)
  7691. ;; scan for signals in old sensitivity list
  7692. (goto-char proc-beg)
  7693. (vhdl-re-search-forward "\\<process\\>" proc-mid t)
  7694. (if (not (looking-at "[ \t\n\r\f]*("))
  7695. (setq sens-beg (point))
  7696. (setq sens-beg (vhdl-re-search-forward "\\([ \t\n\r\f]*\\)([ \t\n\r\f]*" nil t))
  7697. (goto-char (match-end 1))
  7698. (forward-sexp)
  7699. (setq sens-end (1- (point)))
  7700. (goto-char sens-beg)
  7701. (while (and (vhdl-re-search-forward "\\(\\w+\\)" sens-end t)
  7702. (setq sens-list
  7703. (cons (downcase (match-string 0)) sens-list))
  7704. (vhdl-re-search-forward "\\s-*,\\s-*" sens-end t))))
  7705. (setq signal-list (append visible-list sens-list))
  7706. ;; search for sequential parts
  7707. (goto-char proc-mid)
  7708. (while (setq beg (re-search-forward "^\\s-*\\(els\\)?if\\>" proc-end t))
  7709. (setq end (vhdl-re-search-forward "\\<then\\>" proc-end t))
  7710. (when (vhdl-re-search-backward "\\('event\\|\\<\\(falling\\|rising\\)_edge\\)\\>" beg t)
  7711. (goto-char end)
  7712. (backward-word 1)
  7713. (vhdl-forward-sexp)
  7714. (push (cons end (point)) seq-region-list)
  7715. (beginning-of-line)))
  7716. ;; scan for signals read in process
  7717. (while scan-regions-list
  7718. (goto-char proc-mid)
  7719. (while (and (setq beg (eval (nth 0 (car scan-regions-list))))
  7720. (setq end (eval (nth 1 (car scan-regions-list)))))
  7721. (goto-char beg)
  7722. (unless (or (vhdl-in-literal)
  7723. (and seq-region-list
  7724. (let ((tmp-list seq-region-list))
  7725. (while (and tmp-list
  7726. (< (point) (caar tmp-list)))
  7727. (setq tmp-list (cdr tmp-list)))
  7728. (and tmp-list (< (point) (cdar tmp-list))))))
  7729. (while (vhdl-re-search-forward "[^'\".]\\<\\([a-zA-Z]\\w*\\)\\(\\(\\.\\w+\\|[ \t\n\r\f]*([^)]*)\\)*\\)[ \t\n\r\f]*\\('\\(\\w+\\)\\|\\(=>\\)\\)?" end t)
  7730. (setq name (match-string 1))
  7731. ;; get array index range
  7732. (when vhdl-array-index-record-field-in-sensitivity-list
  7733. (setq field (match-string 2))
  7734. ;; not use if it includes a variable name
  7735. (save-match-data
  7736. (setq tmp-list visible-list)
  7737. (while (and field tmp-list)
  7738. (when (string-match
  7739. (concat "\\<" (car tmp-list) "\\>") field)
  7740. (setq field nil))
  7741. (setq tmp-list (cdr tmp-list)))))
  7742. (when (and (not (match-string 6)) ; not when formal parameter
  7743. (not (and (match-string 5) ; not event attribute
  7744. (not (member (downcase (match-string 5))
  7745. '("event" "last_event" "transaction")))))
  7746. (member (downcase name) signal-list))
  7747. ;; not add if name or name+field already exists
  7748. (unless
  7749. (or (member-ignore-case name read-list)
  7750. (member-ignore-case (concat name field) read-list))
  7751. (push (concat name field) read-list))
  7752. (setq tmp-list read-list)
  7753. ;; remove existing name+field if name is added
  7754. (save-match-data
  7755. (while tmp-list
  7756. (when (string-match (concat "^" name field "[(.]")
  7757. (car tmp-list))
  7758. (setq read-list (delete (car tmp-list) read-list)))
  7759. (setq tmp-list (cdr tmp-list)))))
  7760. (goto-char (match-end 1)))))
  7761. (setq scan-regions-list (cdr scan-regions-list)))
  7762. ;; update sensitivity list
  7763. (goto-char sens-beg)
  7764. (if sens-end
  7765. (delete-region sens-beg sens-end)
  7766. (when read-list
  7767. (insert " ()") (backward-char)))
  7768. (setq read-list (sort read-list 'string<))
  7769. (when read-list
  7770. (setq margin (current-column))
  7771. (insert (car read-list))
  7772. (setq read-list (cdr read-list))
  7773. (while read-list
  7774. (insert ",")
  7775. (if (<= (+ (current-column) (length (car read-list)) 2)
  7776. end-comment-column)
  7777. (insert " ")
  7778. (insert "\n") (indent-to margin))
  7779. (insert (car read-list))
  7780. (setq read-list (cdr read-list)))))))))
  7781. (defun vhdl-get-visible-signals ()
  7782. "Get all signals visible in the current block."
  7783. (let (beg end signal-list entity-name file-name)
  7784. (vhdl-prepare-search-2
  7785. ;; get entity name
  7786. (save-excursion
  7787. (unless (and (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
  7788. (not (equal "END" (upcase (match-string 1))))
  7789. (setq entity-name (match-string 2)))
  7790. (error "ERROR: Not within an architecture")))
  7791. ;; search for signals declared in entity port clause
  7792. (save-excursion
  7793. (goto-char (point-min))
  7794. (unless (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t)
  7795. (setq file-name
  7796. (concat (vhdl-replace-string vhdl-entity-file-name entity-name t)
  7797. "." (file-name-extension (buffer-file-name)))))
  7798. (vhdl-visit-file
  7799. file-name t
  7800. (vhdl-prepare-search-2
  7801. (goto-char (point-min))
  7802. (if (not (re-search-forward (concat "^entity\\s-+" entity-name "\\>") nil t))
  7803. (error "ERROR: Entity \"%s\" not found:\n --> see option `vhdl-entity-file-name'" entity-name)
  7804. (when (setq beg (vhdl-re-search-forward
  7805. "\\<port[ \t\n\r\f]*("
  7806. (save-excursion
  7807. (re-search-forward "^end\\>" nil t)) t))
  7808. (setq end (save-excursion
  7809. (backward-char) (forward-sexp) (point)))
  7810. (vhdl-forward-syntactic-ws)
  7811. (while (< (point) end)
  7812. (when (looking-at "signal[ \t\n\r\f]+")
  7813. (goto-char (match-end 0)))
  7814. (while (looking-at "\\([a-zA-Z]\\w*\\)[ \t\n\r\f,]+")
  7815. (setq signal-list
  7816. (cons (downcase (match-string 1)) signal-list))
  7817. (goto-char (match-end 0))
  7818. (vhdl-forward-syntactic-ws))
  7819. (re-search-forward ";" end 1)
  7820. (vhdl-forward-syntactic-ws)))))))
  7821. ;; search for signals declared in architecture declarative part
  7822. (save-excursion
  7823. (if (not (and (setq beg (re-search-backward "^\\(architecture\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t))
  7824. (not (equal "END" (upcase (match-string 1))))
  7825. (setq end (re-search-forward "^begin\\>" nil t))))
  7826. (error "ERROR: No architecture declarative part found")
  7827. ;; scan for all declared signal and alias names
  7828. (goto-char beg)
  7829. (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
  7830. (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
  7831. (if (match-string 2)
  7832. ;; scan signal name
  7833. (while (looking-at "[ \t\n\r\f,]+\\([a-zA-Z]\\w*\\)")
  7834. (setq signal-list
  7835. (cons (downcase (match-string 1)) signal-list))
  7836. (goto-char (match-end 0)))
  7837. ;; scan alias name, check is alias of (declared) signal
  7838. (when (and (looking-at "[ \t\n\r\f]+\\([a-zA-Z]\\w*\\)[^;]*\\<is[ \t\n\r\f]+\\([a-zA-Z]\\w*\\)")
  7839. (member (downcase (match-string 2)) signal-list))
  7840. (setq signal-list
  7841. (cons (downcase (match-string 1)) signal-list))
  7842. (goto-char (match-end 0))))
  7843. (setq beg (point))))))
  7844. ;; search for signals declared in surrounding block declarative parts
  7845. (save-excursion
  7846. (while (and (progn (while (and (setq beg (re-search-backward "^\\s-*\\(\\w+\\s-*:\\s-*\\(block\\|\\(for\\|if\\).*\\<generate\\>\\)\\|\\(end\\)\\s-+block\\)\\>" nil t))
  7847. (match-string 4))
  7848. (goto-char (match-end 4))
  7849. (vhdl-backward-sexp)
  7850. (re-search-backward "^\\s-*\\w+\\s-*:\\s-*\\(block\\|generate\\)\\>" nil t))
  7851. beg)
  7852. (setq end (re-search-forward "^\\s-*begin\\>" nil t)))
  7853. ;; scan for all declared signal names
  7854. (goto-char beg)
  7855. (while (re-search-forward "^\\s-*\\(\\(signal\\)\\|alias\\)\\>" end t)
  7856. (when (= 0 (nth 0 (parse-partial-sexp beg (point))))
  7857. (if (match-string 2)
  7858. ;; scan signal name
  7859. (while (looking-at "[ \t\n,]+\\(\\w+\\)")
  7860. (setq signal-list
  7861. (cons (downcase (match-string 1)) signal-list))
  7862. (goto-char (match-end 0)))
  7863. ;; scan alias name, check is alias of (declared) signal
  7864. (when (and (looking-at "[ \t\n]+\\(\\w+\\)[^;]*\\<is[ \t\n]+\\(\\w+\\)")
  7865. (member (downcase (match-string 2)) signal-list))
  7866. (setq signal-list
  7867. (cons (downcase (match-string 1)) signal-list))
  7868. (goto-char (match-end 0))))))
  7869. (goto-char beg)))
  7870. signal-list)))
  7871. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7872. ;; Generic/port clause fixing
  7873. (defun vhdl-fix-clause-buffer ()
  7874. "Fix all generic/port clauses in current buffer."
  7875. (interactive)
  7876. (save-excursion
  7877. (vhdl-prepare-search-2
  7878. (goto-char (point-min))
  7879. (message "Fixing generic/port clauses...")
  7880. (while (re-search-forward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t)
  7881. (goto-char (match-end 0))
  7882. (condition-case nil (vhdl-fix-clause) (error "")))
  7883. (message "Fixing generic/port clauses...done"))))
  7884. (defun vhdl-fix-clause ()
  7885. "Fix closing parenthesis within generic/port clause."
  7886. (interactive)
  7887. (save-excursion
  7888. (vhdl-prepare-search-2
  7889. (let ((pos (point))
  7890. beg end)
  7891. (end-of-line)
  7892. (if (not (re-search-backward "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(" nil t))
  7893. (error "ERROR: Not within a generic/port clause")
  7894. ;; search for end of clause
  7895. (goto-char (match-end 0))
  7896. (setq beg (1- (point)))
  7897. (vhdl-forward-syntactic-ws)
  7898. (while (looking-at "\\w+\\([ \t\n\r\f]*,[ \t\n\r\f]*\\w+\\)*[ \t\n\r\f]*:[ \t\n\r\f]*\\w+[^;]*;")
  7899. (goto-char (1- (match-end 0)))
  7900. (setq end (point-marker))
  7901. (forward-char)
  7902. (vhdl-forward-syntactic-ws))
  7903. (goto-char end)
  7904. (when (> pos (point-at-eol))
  7905. (error "ERROR: Not within a generic/port clause"))
  7906. ;; delete closing parenthesis on separate line (not supported style)
  7907. (when (save-excursion (beginning-of-line) (looking-at "^\\s-*);"))
  7908. (vhdl-line-kill)
  7909. (vhdl-backward-syntactic-ws)
  7910. (setq end (point-marker))
  7911. (insert ";"))
  7912. ;; delete superfluous parentheses
  7913. (while (progn (goto-char beg)
  7914. (condition-case () (forward-sexp)
  7915. (error (goto-char (point-max))))
  7916. (< (point) end))
  7917. (delete-char -1))
  7918. ;; add closing parenthesis
  7919. (when (> (point) end)
  7920. (goto-char end)
  7921. (insert ")")))))))
  7922. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7923. ;;; Electrification
  7924. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7925. (defconst vhdl-template-prompt-syntax "[^ =<>][^<>@.\n]*[^ =<>]"
  7926. "Syntax of prompt inserted by template generators.")
  7927. (defvar vhdl-template-invoked-by-hook nil
  7928. "Indicates whether a template has been invoked by a hook or by key or menu.
  7929. Used for undoing after template abortion.")
  7930. ;; correct different behavior of function `unread-command-events' in XEmacs
  7931. (defun vhdl-character-to-event (arg))
  7932. (defalias 'vhdl-character-to-event
  7933. (if (fboundp 'character-to-event) 'character-to-event 'identity))
  7934. (defun vhdl-work-library ()
  7935. "Return the working library name of the current project or \"work\" if no
  7936. project is defined."
  7937. (vhdl-resolve-env-variable
  7938. (or (nth 6 (vhdl-aget vhdl-project-alist vhdl-project))
  7939. vhdl-default-library)))
  7940. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7941. ;; Enabling/disabling
  7942. (define-minor-mode vhdl-electric-mode
  7943. "Toggle VHDL electric mode.
  7944. With a prefix argument ARG, enable the mode if ARG is positive,
  7945. and disable it otherwise. If called from Lisp, enable it if ARG
  7946. is omitted or nil."
  7947. :global t :group 'vhdl-mode)
  7948. (define-minor-mode vhdl-stutter-mode
  7949. "Toggle VHDL stuttering mode.
  7950. With a prefix argument ARG, enable the mode if ARG is positive,
  7951. and disable it otherwise. If called from Lisp, enable it if ARG
  7952. is omitted or nil."
  7953. :global t :group 'vhdl-mode)
  7954. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7955. ;; Stuttering
  7956. (defun vhdl-electric-dash (count)
  7957. "-- starts a comment, --- draws a horizontal line,
  7958. ---- starts a display comment."
  7959. (interactive "p")
  7960. (if (and vhdl-stutter-mode (not (vhdl-in-literal)))
  7961. (cond
  7962. ((and abbrev-start-location (= abbrev-start-location (point)))
  7963. (setq abbrev-start-location nil)
  7964. (goto-char last-abbrev-location)
  7965. (beginning-of-line nil)
  7966. (vhdl-comment-display))
  7967. ((/= (preceding-char) ?-) ; standard dash (minus)
  7968. (self-insert-command count))
  7969. (t (self-insert-command count)
  7970. (message "Enter '-' for horiz. line, 'CR' for commenting-out code, else enter comment")
  7971. (let ((next-input (read-char)))
  7972. (if (= next-input ?-) ; triple dash
  7973. (progn
  7974. (vhdl-comment-display-line)
  7975. (message
  7976. "Enter '-' for display comment, else continue coding")
  7977. (let ((next-input (read-char)))
  7978. (if (= next-input ?-) ; four dashes
  7979. (vhdl-comment-display t)
  7980. (push (vhdl-character-to-event next-input)
  7981. ; pushback the char
  7982. unread-command-events))))
  7983. (push (vhdl-character-to-event next-input) ; pushback the char
  7984. unread-command-events)
  7985. (vhdl-comment-insert)))))
  7986. (self-insert-command count)))
  7987. (defun vhdl-electric-open-bracket (count) "`[' --> `(', `([' --> `['"
  7988. (interactive "p")
  7989. (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
  7990. (if (= (preceding-char) ?\()
  7991. (progn (delete-char -1) (insert-char ?\[ 1))
  7992. (insert-char ?\( 1))
  7993. (self-insert-command count)))
  7994. (defun vhdl-electric-close-bracket (count) "`]' --> `)', `)]' --> `]'"
  7995. (interactive "p")
  7996. (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
  7997. (progn
  7998. (if (= (preceding-char) ?\))
  7999. (progn (delete-char -1) (insert-char ?\] 1))
  8000. (insert-char ?\) 1))
  8001. (blink-matching-open))
  8002. (self-insert-command count)))
  8003. (defun vhdl-electric-quote (count) "\\='\\=' --> \""
  8004. (interactive "p")
  8005. (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
  8006. (if (= (preceding-char) vhdl-last-input-event)
  8007. (progn (delete-char -1) (insert-char ?\" 1))
  8008. (insert-char ?\' 1))
  8009. (self-insert-command count)))
  8010. (defun vhdl-electric-semicolon (count) "`;;' --> ` : ', `: ;' --> ` := '"
  8011. (interactive "p")
  8012. (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
  8013. (cond ((= (preceding-char) vhdl-last-input-event)
  8014. (progn (delete-char -1)
  8015. (unless (eq (preceding-char) ? ) (insert " "))
  8016. (insert ": ")
  8017. (setq this-command 'vhdl-electric-colon)))
  8018. ((and
  8019. (eq last-command 'vhdl-electric-colon) (= (preceding-char) ? ))
  8020. (progn (delete-char -1) (insert "= ")))
  8021. (t (insert-char ?\; 1)))
  8022. (self-insert-command count)))
  8023. (defun vhdl-electric-comma (count) "`,,' --> ` <= '"
  8024. (interactive "p")
  8025. (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
  8026. (cond ((= (preceding-char) vhdl-last-input-event)
  8027. (progn (delete-char -1)
  8028. (unless (eq (preceding-char) ? ) (insert " "))
  8029. (insert "<= ")))
  8030. (t (insert-char ?\, 1)))
  8031. (self-insert-command count)))
  8032. (defun vhdl-electric-period (count) "`..' --> ` => '"
  8033. (interactive "p")
  8034. (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
  8035. (cond ((= (preceding-char) vhdl-last-input-event)
  8036. (progn (delete-char -1)
  8037. (unless (eq (preceding-char) ? ) (insert " "))
  8038. (insert "=> ")))
  8039. (t (insert-char ?\. 1)))
  8040. (self-insert-command count)))
  8041. (defun vhdl-electric-equal (count) "`==' --> ` == '"
  8042. (interactive "p")
  8043. (if (and vhdl-stutter-mode (= count 1) (not (vhdl-in-literal)))
  8044. (cond ((= (preceding-char) vhdl-last-input-event)
  8045. (progn (delete-char -1)
  8046. (unless (eq (preceding-char) ? ) (insert " "))
  8047. (insert "== ")))
  8048. (t (insert-char ?\= 1)))
  8049. (self-insert-command count)))
  8050. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8051. ;; VHDL templates
  8052. (defun vhdl-template-paired-parens ()
  8053. "Insert a pair of round parentheses, placing point between them."
  8054. (interactive)
  8055. (insert "()")
  8056. (backward-char))
  8057. (defun vhdl-template-alias ()
  8058. "Insert alias declaration."
  8059. (interactive)
  8060. (let ((start (point)))
  8061. (vhdl-insert-keyword "ALIAS ")
  8062. (when (vhdl-template-field "name" nil t start (point))
  8063. (insert " : ")
  8064. (unless (vhdl-template-field
  8065. (concat "[type" (and (vhdl-standard-p 'ams) " or nature") "]")
  8066. nil t)
  8067. (delete-char -3))
  8068. (vhdl-insert-keyword " IS ")
  8069. (vhdl-template-field "name" ";")
  8070. (vhdl-comment-insert-inline))))
  8071. (defun vhdl-template-architecture ()
  8072. "Insert architecture."
  8073. (interactive)
  8074. (let ((margin (current-indentation))
  8075. (start (point))
  8076. arch-name)
  8077. (vhdl-insert-keyword "ARCHITECTURE ")
  8078. (when (setq arch-name
  8079. (vhdl-template-field "name" nil t start (point)))
  8080. (vhdl-insert-keyword " OF ")
  8081. (if (save-excursion
  8082. (vhdl-prepare-search-1
  8083. (vhdl-re-search-backward "\\<entity \\(\\w+\\) is\\>" nil t)))
  8084. (insert (match-string 1))
  8085. (vhdl-template-field "entity name"))
  8086. (vhdl-insert-keyword " IS\n")
  8087. (vhdl-template-begin-end
  8088. (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name margin
  8089. (memq vhdl-insert-empty-lines '(unit all))))))
  8090. (defun vhdl-template-array (kind &optional secondary)
  8091. "Insert array type definition."
  8092. (interactive)
  8093. (let ((start (point)))
  8094. (vhdl-insert-keyword "ARRAY (")
  8095. (when (or (vhdl-template-field "range" nil (not secondary) start (point))
  8096. secondary)
  8097. (vhdl-insert-keyword ") OF ")
  8098. (vhdl-template-field (if (eq kind 'type) "type" "nature"))
  8099. (vhdl-insert-keyword ";"))))
  8100. (defun vhdl-template-assert ()
  8101. "Insert an assertion statement."
  8102. (interactive)
  8103. (let ((start (point)))
  8104. (vhdl-insert-keyword "ASSERT ")
  8105. (when vhdl-conditions-in-parenthesis (insert "("))
  8106. (when (vhdl-template-field "condition (negated)" nil t start (point))
  8107. (when vhdl-conditions-in-parenthesis (insert ")"))
  8108. (setq start (point))
  8109. (vhdl-insert-keyword " REPORT ")
  8110. (unless (vhdl-template-field "string expression" nil nil nil nil t)
  8111. (delete-region start (point)))
  8112. (setq start (point))
  8113. (vhdl-insert-keyword " SEVERITY ")
  8114. (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
  8115. (delete-region start (point)))
  8116. (insert ";"))))
  8117. (defun vhdl-template-attribute ()
  8118. "Insert an attribute declaration or specification."
  8119. (interactive)
  8120. (if (eq (vhdl-decision-query
  8121. "attribute" "(d)eclaration or (s)pecification?" t) ?s)
  8122. (vhdl-template-attribute-spec)
  8123. (vhdl-template-attribute-decl)))
  8124. (defun vhdl-template-attribute-decl ()
  8125. "Insert an attribute declaration."
  8126. (interactive)
  8127. (let ((start (point)))
  8128. (vhdl-insert-keyword "ATTRIBUTE ")
  8129. (when (vhdl-template-field "name" " : " t start (point))
  8130. (vhdl-template-field "type" ";")
  8131. (vhdl-comment-insert-inline))))
  8132. (defun vhdl-template-attribute-spec ()
  8133. "Insert an attribute specification."
  8134. (interactive)
  8135. (let ((start (point)))
  8136. (vhdl-insert-keyword "ATTRIBUTE ")
  8137. (when (vhdl-template-field "name" nil t start (point))
  8138. (vhdl-insert-keyword " OF ")
  8139. (vhdl-template-field "entity names | OTHERS | ALL" " : ")
  8140. (vhdl-template-field "entity class")
  8141. (vhdl-insert-keyword " IS ")
  8142. (vhdl-template-field "expression" ";"))))
  8143. (defun vhdl-template-block ()
  8144. "Insert a block."
  8145. (interactive)
  8146. (let ((margin (current-indentation))
  8147. (start (point))
  8148. label)
  8149. (vhdl-insert-keyword ": BLOCK ")
  8150. (goto-char start)
  8151. (when (setq label (vhdl-template-field "label" nil t start (+ (point) 8)))
  8152. (forward-word 1)
  8153. (forward-char 1)
  8154. (insert "(")
  8155. (if (vhdl-template-field "[guard expression]" nil t)
  8156. (insert ")")
  8157. (delete-char -2))
  8158. (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
  8159. (insert "\n")
  8160. (vhdl-template-begin-end "BLOCK" label margin)
  8161. (vhdl-comment-block))))
  8162. (defun vhdl-template-block-configuration ()
  8163. "Insert a block configuration statement."
  8164. (interactive)
  8165. (let ((margin (current-indentation))
  8166. (start (point)))
  8167. (vhdl-insert-keyword "FOR ")
  8168. (when (vhdl-template-field "block name" nil t start (point))
  8169. (vhdl-insert-keyword "\n\n")
  8170. (indent-to margin)
  8171. (vhdl-insert-keyword "END FOR;")
  8172. (end-of-line 0)
  8173. (indent-to (+ margin vhdl-basic-offset)))))
  8174. (defun vhdl-template-break ()
  8175. "Insert a break statement."
  8176. (interactive)
  8177. (let (position)
  8178. (vhdl-insert-keyword "BREAK")
  8179. (setq position (point))
  8180. (insert " ")
  8181. (while (or
  8182. (progn (vhdl-insert-keyword "FOR ")
  8183. (if (vhdl-template-field "[quantity name]" " USE " t)
  8184. (progn (vhdl-template-field "quantity name" " => ") t)
  8185. (delete-region (point)
  8186. (progn (forward-word -1) (point)))
  8187. nil))
  8188. (vhdl-template-field "[quantity name]" " => " t))
  8189. (vhdl-template-field "expression")
  8190. (setq position (point))
  8191. (insert ", "))
  8192. (delete-region position (point))
  8193. (unless (vhdl-sequential-statement-p)
  8194. (vhdl-insert-keyword " ON ")
  8195. (if (vhdl-template-field "[sensitivity list]" nil t)
  8196. (setq position (point))
  8197. (delete-region position (point))))
  8198. (vhdl-insert-keyword " WHEN ")
  8199. (when vhdl-conditions-in-parenthesis (insert "("))
  8200. (if (vhdl-template-field "[condition]" nil t)
  8201. (when vhdl-conditions-in-parenthesis (insert ")"))
  8202. (delete-region position (point)))
  8203. (insert ";")))
  8204. (defun vhdl-template-case (&optional kind)
  8205. "Insert a case statement."
  8206. (interactive)
  8207. (let ((margin (current-indentation))
  8208. (start (point))
  8209. label)
  8210. (unless kind (setq kind (if (or (vhdl-sequential-statement-p)
  8211. (not (vhdl-standard-p 'ams))) 'is 'use)))
  8212. (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
  8213. (vhdl-insert-keyword "CASE ")
  8214. (vhdl-insert-keyword ": CASE ")
  8215. (goto-char start)
  8216. (setq label (vhdl-template-field "[label]" nil t))
  8217. (unless label (delete-char 2))
  8218. (forward-word 1)
  8219. (forward-char 1))
  8220. (when (vhdl-template-field "expression" nil t start (point))
  8221. (vhdl-insert-keyword (concat " " (if (eq kind 'is) "IS" "USE") "\n\n"))
  8222. (indent-to margin)
  8223. (vhdl-insert-keyword "END CASE")
  8224. (when label (insert " " label))
  8225. (insert ";")
  8226. (forward-line -1)
  8227. (indent-to (+ margin vhdl-basic-offset))
  8228. (vhdl-insert-keyword "WHEN ")
  8229. (let ((position (point)))
  8230. (insert " => ;\n")
  8231. (indent-to (+ margin vhdl-basic-offset))
  8232. (vhdl-insert-keyword "WHEN OTHERS => null;")
  8233. (goto-char position)))))
  8234. (defun vhdl-template-case-is ()
  8235. "Insert a sequential case statement."
  8236. (interactive)
  8237. (vhdl-template-case 'is))
  8238. (defun vhdl-template-case-use ()
  8239. "Insert a simultaneous case statement."
  8240. (interactive)
  8241. (vhdl-template-case 'use))
  8242. (defun vhdl-template-component ()
  8243. "Insert a component declaration."
  8244. (interactive)
  8245. (vhdl-template-component-decl))
  8246. (defun vhdl-template-component-conf ()
  8247. "Insert a component configuration (uses `vhdl-template-configuration-spec'
  8248. since these are almost equivalent)."
  8249. (interactive)
  8250. (let ((margin (current-indentation))
  8251. (result (vhdl-template-configuration-spec t)))
  8252. (when result
  8253. (insert "\n")
  8254. (indent-to margin)
  8255. (vhdl-insert-keyword "END FOR;")
  8256. (when (eq result 'no-use)
  8257. (end-of-line -0)))))
  8258. (defun vhdl-template-component-decl ()
  8259. "Insert a component declaration."
  8260. (interactive)
  8261. (let ((margin (current-indentation))
  8262. (start (point))
  8263. name end-column)
  8264. (vhdl-insert-keyword "COMPONENT ")
  8265. (when (setq name (vhdl-template-field "name" nil t start (point)))
  8266. (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
  8267. (insert "\n\n")
  8268. (indent-to margin)
  8269. (vhdl-insert-keyword "END COMPONENT")
  8270. (unless (vhdl-standard-p '87) (insert " " name))
  8271. (insert ";")
  8272. (setq end-column (current-column))
  8273. (end-of-line -0)
  8274. (indent-to (+ margin vhdl-basic-offset))
  8275. (vhdl-template-generic-list t t)
  8276. (insert "\n")
  8277. (indent-to (+ margin vhdl-basic-offset))
  8278. (vhdl-template-port-list t)
  8279. (beginning-of-line 2)
  8280. (forward-char end-column))))
  8281. (defun vhdl-template-component-inst ()
  8282. "Insert a component instantiation statement."
  8283. (interactive)
  8284. (let ((margin (current-indentation))
  8285. (start (point))
  8286. unit position)
  8287. (when (vhdl-template-field "instance label" nil t start (point))
  8288. (insert ": ")
  8289. (if (not (vhdl-use-direct-instantiation))
  8290. (vhdl-template-field "component name")
  8291. ;; direct instantiation
  8292. (setq unit (vhdl-template-field
  8293. "[COMPONENT | ENTITY | CONFIGURATION]" " " t))
  8294. (setq unit (upcase (or unit "")))
  8295. (cond ((equal unit "ENTITY")
  8296. (let ((begin (point)))
  8297. (vhdl-template-field "library name" "." t begin (point) nil
  8298. (vhdl-work-library))
  8299. (vhdl-template-field "entity name" "(")
  8300. (if (vhdl-template-field "[architecture name]" nil t)
  8301. (insert ")")
  8302. (delete-char -1))))
  8303. ((equal unit "CONFIGURATION")
  8304. (vhdl-template-field "library name" "." nil nil nil nil
  8305. (vhdl-work-library))
  8306. (vhdl-template-field "configuration name"))
  8307. (t (vhdl-template-field "component name"))))
  8308. (insert "\n")
  8309. (indent-to (+ margin vhdl-basic-offset))
  8310. (setq position (point))
  8311. (vhdl-insert-keyword "GENERIC ")
  8312. (when (vhdl-template-map position t t)
  8313. (insert "\n")
  8314. (indent-to (+ margin vhdl-basic-offset)))
  8315. (setq position (point))
  8316. (vhdl-insert-keyword "PORT ")
  8317. (unless (vhdl-template-map position t t)
  8318. (delete-region (line-beginning-position) (point))
  8319. (delete-char -1))
  8320. (insert ";"))))
  8321. (defun vhdl-template-conditional-signal-asst ()
  8322. "Insert a conditional signal assignment."
  8323. (interactive)
  8324. (when (vhdl-template-field "target signal")
  8325. (insert " <= ")
  8326. (let ((margin (current-column))
  8327. (start (point))
  8328. position)
  8329. (vhdl-template-field "waveform")
  8330. (setq position (point))
  8331. (vhdl-insert-keyword " WHEN ")
  8332. (when vhdl-conditions-in-parenthesis (insert "("))
  8333. (while (and (vhdl-template-field "[condition]" nil t)
  8334. (progn
  8335. (when vhdl-conditions-in-parenthesis (insert ")"))
  8336. (setq position (point))
  8337. (vhdl-insert-keyword " ELSE")
  8338. (insert "\n")
  8339. (indent-to margin)
  8340. (vhdl-template-field "[waveform]" nil t)))
  8341. (setq position (point))
  8342. (vhdl-insert-keyword " WHEN ")
  8343. (when vhdl-conditions-in-parenthesis (insert "(")))
  8344. (delete-region position (point))
  8345. (insert ";")
  8346. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
  8347. (defun vhdl-template-configuration ()
  8348. "Insert a configuration specification if within an architecture,
  8349. a block or component configuration if within a configuration declaration,
  8350. a configuration declaration if not within a design unit."
  8351. (interactive)
  8352. (vhdl-prepare-search-1
  8353. (cond
  8354. ((and (save-excursion ; architecture body
  8355. (re-search-backward "^\\(architecture\\|end\\)\\>" nil t))
  8356. (equal "ARCHITECTURE" (upcase (match-string 1))))
  8357. (vhdl-template-configuration-spec))
  8358. ((and (save-excursion ; configuration declaration
  8359. (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
  8360. (equal "CONFIGURATION" (upcase (match-string 1))))
  8361. (if (eq (vhdl-decision-query
  8362. "configuration" "(b)lock or (c)omponent configuration?" t) ?c)
  8363. (vhdl-template-component-conf)
  8364. (vhdl-template-block-configuration)))
  8365. (t (vhdl-template-configuration-decl))))) ; otherwise
  8366. (defun vhdl-template-configuration-spec (&optional optional-use)
  8367. "Insert a configuration specification."
  8368. (interactive)
  8369. (let ((margin (current-indentation))
  8370. (start (point))
  8371. aspect position)
  8372. (vhdl-insert-keyword "FOR ")
  8373. (when (vhdl-template-field "instance names | OTHERS | ALL" " : "
  8374. t start (point))
  8375. (vhdl-template-field "component name" "\n")
  8376. (indent-to (+ margin vhdl-basic-offset))
  8377. (setq start (point))
  8378. (vhdl-insert-keyword "USE ")
  8379. (if (and optional-use
  8380. (not (setq aspect (vhdl-template-field
  8381. "[ENTITY | CONFIGURATION | OPEN]" " " t))))
  8382. (progn (delete-region start (point)) 'no-use)
  8383. (unless optional-use
  8384. (setq aspect (vhdl-template-field
  8385. "ENTITY | CONFIGURATION | OPEN" " ")))
  8386. (setq aspect (upcase (or aspect "")))
  8387. (cond ((equal aspect "ENTITY")
  8388. (vhdl-template-field "library name" "." nil nil nil nil
  8389. (vhdl-work-library))
  8390. (vhdl-template-field "entity name" "(")
  8391. (if (vhdl-template-field "[architecture name]" nil t)
  8392. (insert ")")
  8393. (delete-char -1))
  8394. (insert "\n")
  8395. (indent-to (+ margin (* 2 vhdl-basic-offset)))
  8396. (setq position (point))
  8397. (vhdl-insert-keyword "GENERIC ")
  8398. (when (vhdl-template-map position t t)
  8399. (insert "\n")
  8400. (indent-to (+ margin (* 2 vhdl-basic-offset))))
  8401. (setq position (point))
  8402. (vhdl-insert-keyword "PORT ")
  8403. (unless (vhdl-template-map position t t)
  8404. (delete-region (line-beginning-position) (point))
  8405. (delete-char -1))
  8406. (insert ";")
  8407. t)
  8408. ((equal aspect "CONFIGURATION")
  8409. (vhdl-template-field "library name" "." nil nil nil nil
  8410. (vhdl-work-library))
  8411. (vhdl-template-field "configuration name" ";"))
  8412. (t (delete-char -1) (insert ";") t))))))
  8413. (defun vhdl-template-configuration-decl ()
  8414. "Insert a configuration declaration."
  8415. (interactive)
  8416. (let ((margin (current-indentation))
  8417. (start (point))
  8418. entity-exists string name position)
  8419. (vhdl-insert-keyword "CONFIGURATION ")
  8420. (when (setq name (vhdl-template-field "name" nil t start (point)))
  8421. (vhdl-insert-keyword " OF ")
  8422. (save-excursion
  8423. (vhdl-prepare-search-1
  8424. (setq entity-exists (vhdl-re-search-backward
  8425. "\\<entity \\(\\w*\\) is\\>" nil t))
  8426. (setq string (match-string 1))))
  8427. (if (and entity-exists (not (equal string "")))
  8428. (insert string)
  8429. (vhdl-template-field "entity name"))
  8430. (vhdl-insert-keyword " IS\n")
  8431. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  8432. (indent-to (+ margin vhdl-basic-offset))
  8433. (setq position (point))
  8434. (insert "\n")
  8435. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  8436. (indent-to margin)
  8437. (vhdl-insert-keyword "END ")
  8438. (unless (vhdl-standard-p '87)
  8439. (vhdl-insert-keyword "CONFIGURATION "))
  8440. (insert name ";")
  8441. (goto-char position))))
  8442. (defun vhdl-template-constant ()
  8443. "Insert a constant declaration."
  8444. (interactive)
  8445. (let ((start (point))
  8446. (in-arglist (vhdl-in-argument-list-p)))
  8447. (vhdl-insert-keyword "CONSTANT ")
  8448. (when (vhdl-template-field "name" nil t start (point))
  8449. (insert " : ")
  8450. (when in-arglist (vhdl-insert-keyword "IN "))
  8451. (vhdl-template-field "type")
  8452. (if in-arglist
  8453. (progn (insert ";")
  8454. (vhdl-comment-insert-inline))
  8455. (let ((position (point)))
  8456. (insert " := ")
  8457. (unless (vhdl-template-field "[initialization]" nil t)
  8458. (delete-region position (point)))
  8459. (insert ";")
  8460. (vhdl-comment-insert-inline))))))
  8461. (defun vhdl-template-context ()
  8462. "Insert a context declaration."
  8463. (interactive)
  8464. (let ((margin (current-indentation))
  8465. (start (point))
  8466. entity-exists string name position)
  8467. (vhdl-insert-keyword "CONTEXT ")
  8468. (when (setq name (vhdl-template-field "name" nil t start (point)))
  8469. (vhdl-insert-keyword " IS\n")
  8470. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  8471. (indent-to (+ margin vhdl-basic-offset))
  8472. (setq position (point))
  8473. (insert "\n")
  8474. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  8475. (indent-to margin)
  8476. (vhdl-insert-keyword "END ")
  8477. (unless (vhdl-standard-p '87)
  8478. (vhdl-insert-keyword "CONTEXT "))
  8479. (insert name ";")
  8480. (goto-char position))))
  8481. (defun vhdl-template-default ()
  8482. "Insert nothing."
  8483. (interactive)
  8484. (insert " ")
  8485. (unexpand-abbrev)
  8486. (backward-word 1)
  8487. (vhdl-case-word 1)
  8488. (forward-char 1))
  8489. (defun vhdl-template-default-indent ()
  8490. "Insert nothing and indent."
  8491. (interactive)
  8492. (insert " ")
  8493. (unexpand-abbrev)
  8494. (backward-word 1)
  8495. (vhdl-case-word 1)
  8496. (forward-char 1)
  8497. (indent-according-to-mode))
  8498. (defun vhdl-template-disconnect ()
  8499. "Insert a disconnect statement."
  8500. (interactive)
  8501. (let ((start (point)))
  8502. (vhdl-insert-keyword "DISCONNECT ")
  8503. (when (vhdl-template-field "signal names | OTHERS | ALL"
  8504. " : " t start (point))
  8505. (vhdl-template-field "type")
  8506. (vhdl-insert-keyword " AFTER ")
  8507. (vhdl-template-field "time expression" ";"))))
  8508. (defun vhdl-template-else ()
  8509. "Insert an else statement."
  8510. (interactive)
  8511. (let (margin)
  8512. (vhdl-prepare-search-1
  8513. (vhdl-insert-keyword "ELSE")
  8514. (if (and (save-excursion (vhdl-re-search-backward "\\(\\<when\\>\\|;\\)" nil t))
  8515. (equal "WHEN" (upcase (match-string 1))))
  8516. (insert " ")
  8517. (indent-according-to-mode)
  8518. (setq margin (current-indentation))
  8519. (insert "\n")
  8520. (indent-to (+ margin vhdl-basic-offset))))))
  8521. (defun vhdl-template-elsif ()
  8522. "Insert an elsif statement."
  8523. (interactive)
  8524. (let ((start (point))
  8525. margin)
  8526. (vhdl-insert-keyword "ELSIF ")
  8527. (when (or (vhdl-sequential-statement-p) (vhdl-standard-p 'ams))
  8528. (when vhdl-conditions-in-parenthesis (insert "("))
  8529. (when (vhdl-template-field "condition" nil t start (point))
  8530. (when vhdl-conditions-in-parenthesis (insert ")"))
  8531. (indent-according-to-mode)
  8532. (setq margin (current-indentation))
  8533. (vhdl-insert-keyword
  8534. (concat " " (if (vhdl-sequential-statement-p) "THEN" "USE") "\n"))
  8535. (indent-to (+ margin vhdl-basic-offset))))))
  8536. (defun vhdl-template-entity ()
  8537. "Insert an entity."
  8538. (interactive)
  8539. (let ((margin (current-indentation))
  8540. (start (point))
  8541. name end-column)
  8542. (vhdl-insert-keyword "ENTITY ")
  8543. (when (setq name (vhdl-template-field "name" nil t start (point)))
  8544. (vhdl-insert-keyword " IS\n\n")
  8545. (indent-to margin)
  8546. (vhdl-insert-keyword "END ")
  8547. (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
  8548. (insert name ";")
  8549. (setq end-column (current-column))
  8550. (end-of-line -0)
  8551. (indent-to (+ margin vhdl-basic-offset))
  8552. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  8553. (indent-to (+ margin vhdl-basic-offset))
  8554. (when (vhdl-template-generic-list t)
  8555. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
  8556. (insert "\n")
  8557. (indent-to (+ margin vhdl-basic-offset))
  8558. (when (vhdl-template-port-list t)
  8559. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n")))
  8560. (beginning-of-line 2)
  8561. (forward-char end-column))))
  8562. (defun vhdl-template-exit ()
  8563. "Insert an exit statement."
  8564. (interactive)
  8565. (let ((start (point)))
  8566. (vhdl-insert-keyword "EXIT ")
  8567. (if (vhdl-template-field "[loop label]" nil t start (point))
  8568. (let ((position (point)))
  8569. (vhdl-insert-keyword " WHEN ")
  8570. (when vhdl-conditions-in-parenthesis (insert "("))
  8571. (if (vhdl-template-field "[condition]" nil t)
  8572. (when vhdl-conditions-in-parenthesis (insert ")"))
  8573. (delete-region position (point))))
  8574. (delete-char -1))
  8575. (insert ";")))
  8576. (defun vhdl-template-file ()
  8577. "Insert a file declaration."
  8578. (interactive)
  8579. (let ((start (point)))
  8580. (vhdl-insert-keyword "FILE ")
  8581. (when (vhdl-template-field "name" nil t start (point))
  8582. (insert " : ")
  8583. (vhdl-template-field "type")
  8584. (unless (vhdl-standard-p '87)
  8585. (vhdl-insert-keyword " OPEN ")
  8586. (unless (vhdl-template-field "[READ_MODE | WRITE_MODE | APPEND_MODE]"
  8587. nil t)
  8588. (delete-char -6)))
  8589. (vhdl-insert-keyword " IS ")
  8590. (when (vhdl-standard-p '87)
  8591. (vhdl-template-field "[IN | OUT]" " " t))
  8592. (vhdl-template-field "filename-string" nil nil nil nil t)
  8593. (insert ";")
  8594. (vhdl-comment-insert-inline))))
  8595. (defun vhdl-template-for ()
  8596. "Insert a block or component configuration if within a configuration
  8597. declaration, a configuration specification if within an architecture
  8598. declarative part (and not within a subprogram), a for-loop if within a
  8599. sequential statement part (subprogram or process), and a for-generate
  8600. otherwise."
  8601. (interactive)
  8602. (vhdl-prepare-search-1
  8603. (cond
  8604. ((vhdl-sequential-statement-p) ; sequential statement
  8605. (vhdl-template-for-loop))
  8606. ((and (save-excursion ; configuration declaration
  8607. (re-search-backward "^\\(configuration\\|end\\)\\>" nil t))
  8608. (equal "CONFIGURATION" (upcase (match-string 1))))
  8609. (if (eq (vhdl-decision-query
  8610. "for" "(b)lock or (c)omponent configuration?" t) ?c)
  8611. (vhdl-template-component-conf)
  8612. (vhdl-template-block-configuration)))
  8613. ((and (save-excursion
  8614. (re-search-backward ; architecture declarative part
  8615. "^\\(architecture\\|entity\\|begin\\|end\\)\\>" nil t))
  8616. (equal "ARCHITECTURE" (upcase (match-string 1))))
  8617. (vhdl-template-configuration-spec))
  8618. (t (vhdl-template-for-generate))))) ; concurrent statement
  8619. (defun vhdl-template-for-generate ()
  8620. "Insert a for-generate."
  8621. (interactive)
  8622. (let ((margin (current-indentation))
  8623. (start (point))
  8624. label position)
  8625. (vhdl-insert-keyword ": FOR ")
  8626. (setq position (point-marker))
  8627. (goto-char start)
  8628. (when (setq label (vhdl-template-field "label" nil t start position))
  8629. (goto-char position)
  8630. (vhdl-template-field "loop variable")
  8631. (vhdl-insert-keyword " IN ")
  8632. (vhdl-template-field "range")
  8633. (vhdl-template-generate-body margin label))))
  8634. (defun vhdl-template-for-loop ()
  8635. "Insert a for loop."
  8636. (interactive)
  8637. (let ((margin (current-indentation))
  8638. (start (point))
  8639. label index)
  8640. (if (not (eq vhdl-optional-labels 'all))
  8641. (vhdl-insert-keyword "FOR ")
  8642. (vhdl-insert-keyword ": FOR ")
  8643. (goto-char start)
  8644. (setq label (vhdl-template-field "[label]" nil t))
  8645. (unless label (delete-char 2))
  8646. (forward-word 1)
  8647. (forward-char 1))
  8648. (when (setq index (vhdl-template-field "loop variable"
  8649. nil t start (point)))
  8650. (vhdl-insert-keyword " IN ")
  8651. (vhdl-template-field "range")
  8652. (vhdl-insert-keyword " LOOP\n\n")
  8653. (indent-to margin)
  8654. (vhdl-insert-keyword "END LOOP")
  8655. (if label
  8656. (insert " " label ";")
  8657. (insert ";")
  8658. (when vhdl-self-insert-comments (insert " -- " index)))
  8659. (forward-line -1)
  8660. (indent-to (+ margin vhdl-basic-offset)))))
  8661. (defun vhdl-template-function (&optional kind)
  8662. "Insert a function declaration or body."
  8663. (interactive)
  8664. (let ((margin (current-indentation))
  8665. (start (point))
  8666. name)
  8667. (vhdl-insert-keyword "FUNCTION ")
  8668. (when (setq name (vhdl-template-field "name" nil t start (point)))
  8669. (vhdl-template-argument-list t)
  8670. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
  8671. (end-of-line)
  8672. (insert "\n")
  8673. (indent-to (+ margin vhdl-basic-offset))
  8674. (vhdl-insert-keyword "RETURN ")
  8675. (vhdl-template-field "type")
  8676. (if (if kind (eq kind 'body)
  8677. (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
  8678. (progn (vhdl-insert-keyword " IS\n")
  8679. (vhdl-template-begin-end
  8680. (unless (vhdl-standard-p '87) "FUNCTION") name margin)
  8681. (vhdl-comment-block))
  8682. (insert ";")))))
  8683. (defun vhdl-template-function-decl ()
  8684. "Insert a function declaration."
  8685. (interactive)
  8686. (vhdl-template-function 'decl))
  8687. (defun vhdl-template-function-body ()
  8688. "Insert a function declaration."
  8689. (interactive)
  8690. (vhdl-template-function 'body))
  8691. (defun vhdl-template-generate ()
  8692. "Insert a generation scheme."
  8693. (interactive)
  8694. (if (eq (vhdl-decision-query nil "(f)or or (i)f?" t) ?i)
  8695. (vhdl-template-if-generate)
  8696. (vhdl-template-for-generate)))
  8697. (defun vhdl-template-generic ()
  8698. "Insert generic declaration, or generic map in instantiation statements."
  8699. (interactive)
  8700. (let ((start (point)))
  8701. (vhdl-prepare-search-1
  8702. (cond
  8703. ((and (save-excursion ; entity declaration
  8704. (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
  8705. (equal "ENTITY" (upcase (match-string 1))))
  8706. (vhdl-template-generic-list nil))
  8707. ((or (save-excursion
  8708. (or (beginning-of-line)
  8709. (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
  8710. (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
  8711. (vhdl-insert-keyword "GENERIC ")
  8712. (vhdl-template-map start))
  8713. (t (vhdl-template-generic-list nil t))))))
  8714. (defun vhdl-template-group ()
  8715. "Insert group or group template declaration."
  8716. (interactive)
  8717. (let ((start (point)))
  8718. (if (eq (vhdl-decision-query
  8719. "group" "(d)eclaration or (t)emplate declaration?" t) ?t)
  8720. (vhdl-template-group-template)
  8721. (vhdl-template-group-decl))))
  8722. (defun vhdl-template-group-decl ()
  8723. "Insert group declaration."
  8724. (interactive)
  8725. (let ((start (point)))
  8726. (vhdl-insert-keyword "GROUP ")
  8727. (when (vhdl-template-field "name" " : " t start (point))
  8728. (vhdl-template-field "template name" " (")
  8729. (vhdl-template-field "constituent list" ");")
  8730. (vhdl-comment-insert-inline))))
  8731. (defun vhdl-template-group-template ()
  8732. "Insert group template declaration."
  8733. (interactive)
  8734. (let ((start (point)))
  8735. (vhdl-insert-keyword "GROUP ")
  8736. (when (vhdl-template-field "template name" nil t start (point))
  8737. (vhdl-insert-keyword " IS (")
  8738. (vhdl-template-field "entity class list" ");")
  8739. (vhdl-comment-insert-inline))))
  8740. (defun vhdl-template-if ()
  8741. "Insert a sequential if statement or an if-generate statement."
  8742. (interactive)
  8743. (if (vhdl-sequential-statement-p)
  8744. (vhdl-template-if-then)
  8745. (if (and (vhdl-standard-p 'ams)
  8746. (eq (vhdl-decision-query "if" "(g)enerate or (u)se?" t) ?u))
  8747. (vhdl-template-if-use)
  8748. (vhdl-template-if-generate))))
  8749. (defun vhdl-template-if-generate ()
  8750. "Insert an if-generate."
  8751. (interactive)
  8752. (let ((margin (current-indentation))
  8753. (start (point))
  8754. label position)
  8755. (vhdl-insert-keyword ": IF ")
  8756. (setq position (point-marker))
  8757. (goto-char start)
  8758. (when (setq label (vhdl-template-field "label" nil t start position))
  8759. (goto-char position)
  8760. (when vhdl-conditions-in-parenthesis (insert "("))
  8761. (vhdl-template-field "condition")
  8762. (when vhdl-conditions-in-parenthesis (insert ")"))
  8763. (vhdl-template-generate-body margin label))))
  8764. (defun vhdl-template-if-then-use (kind)
  8765. "Insert a sequential if statement."
  8766. (interactive)
  8767. (let ((margin (current-indentation))
  8768. (start (point))
  8769. label)
  8770. (if (or (not (eq vhdl-optional-labels 'all)) (vhdl-standard-p '87))
  8771. (vhdl-insert-keyword "IF ")
  8772. (vhdl-insert-keyword ": IF ")
  8773. (goto-char start)
  8774. (setq label (vhdl-template-field "[label]" nil t))
  8775. (unless label (delete-char 2))
  8776. (forward-word 1)
  8777. (forward-char 1))
  8778. (when vhdl-conditions-in-parenthesis (insert "("))
  8779. (when (vhdl-template-field "condition" nil t start (point))
  8780. (when vhdl-conditions-in-parenthesis (insert ")"))
  8781. (vhdl-insert-keyword
  8782. (concat " " (if (eq kind 'then) "THEN" "USE") "\n\n"))
  8783. (indent-to margin)
  8784. (vhdl-insert-keyword (concat "END " (if (eq kind 'then) "IF" "USE")))
  8785. (when label (insert " " label))
  8786. (insert ";")
  8787. (forward-line -1)
  8788. (indent-to (+ margin vhdl-basic-offset)))))
  8789. (defun vhdl-template-if-then ()
  8790. "Insert a sequential if statement."
  8791. (interactive)
  8792. (vhdl-template-if-then-use 'then))
  8793. (defun vhdl-template-if-use ()
  8794. "Insert a simultaneous if statement."
  8795. (interactive)
  8796. (vhdl-template-if-then-use 'use))
  8797. (defun vhdl-template-instance ()
  8798. "Insert a component instantiation statement."
  8799. (interactive)
  8800. (vhdl-template-component-inst))
  8801. (defun vhdl-template-library ()
  8802. "Insert a library specification."
  8803. (interactive)
  8804. (let ((margin (current-indentation))
  8805. (start (point))
  8806. name end-pos)
  8807. (vhdl-insert-keyword "LIBRARY ")
  8808. (when (setq name (vhdl-template-field "names" nil t start (point)))
  8809. (insert ";")
  8810. (unless (string-match "," name)
  8811. (setq end-pos (point))
  8812. (insert "\n")
  8813. (indent-to margin)
  8814. (vhdl-insert-keyword "USE ")
  8815. (insert name)
  8816. (vhdl-insert-keyword "..ALL;")
  8817. (backward-char 5)
  8818. (if (vhdl-template-field "package name")
  8819. (forward-char 5)
  8820. (delete-region end-pos (+ (point) 5)))))))
  8821. (defun vhdl-template-limit ()
  8822. "Insert a limit."
  8823. (interactive)
  8824. (let ((start (point)))
  8825. (vhdl-insert-keyword "LIMIT ")
  8826. (when (vhdl-template-field "quantity names | OTHERS | ALL" " : "
  8827. t start (point))
  8828. (vhdl-template-field "type")
  8829. (vhdl-insert-keyword " WITH ")
  8830. (vhdl-template-field "real expression" ";"))))
  8831. (defun vhdl-template-loop ()
  8832. "Insert a loop."
  8833. (interactive)
  8834. (let ((char (vhdl-decision-query nil "(w)hile, (f)or, or (b)are?" t)))
  8835. (cond ((eq char ?w)
  8836. (vhdl-template-while-loop))
  8837. ((eq char ?f)
  8838. (vhdl-template-for-loop))
  8839. (t (vhdl-template-bare-loop)))))
  8840. (defun vhdl-template-bare-loop ()
  8841. "Insert a loop."
  8842. (interactive)
  8843. (let ((margin (current-indentation))
  8844. (start (point))
  8845. label)
  8846. (if (not (eq vhdl-optional-labels 'all))
  8847. (vhdl-insert-keyword "LOOP ")
  8848. (vhdl-insert-keyword ": LOOP ")
  8849. (goto-char start)
  8850. (setq label (vhdl-template-field "[label]" nil t))
  8851. (unless label (delete-char 2))
  8852. (forward-word 1)
  8853. (delete-char 1))
  8854. (insert "\n\n")
  8855. (indent-to margin)
  8856. (vhdl-insert-keyword "END LOOP")
  8857. (insert (if label (concat " " label ";") ";"))
  8858. (forward-line -1)
  8859. (indent-to (+ margin vhdl-basic-offset))))
  8860. (defun vhdl-template-map (&optional start optional secondary)
  8861. "Insert a map specification with association list."
  8862. (interactive)
  8863. (let ((start (or start (point)))
  8864. margin end-pos)
  8865. (vhdl-insert-keyword "MAP (")
  8866. (if (not vhdl-association-list-with-formals)
  8867. (if (vhdl-template-field
  8868. (concat (and optional "[") "association list" (and optional "]"))
  8869. ")" (or (not secondary) optional)
  8870. (and (not secondary) start) (point))
  8871. t
  8872. (if (and optional secondary) (delete-region start (point)))
  8873. nil)
  8874. (if vhdl-argument-list-indent
  8875. (setq margin (current-column))
  8876. (setq margin (+ (current-indentation) vhdl-basic-offset))
  8877. (insert "\n")
  8878. (indent-to margin))
  8879. (if (vhdl-template-field
  8880. (concat (and optional "[") "formal" (and optional "]"))
  8881. " => " (or (not secondary) optional)
  8882. (and (not secondary) start) (point))
  8883. (progn
  8884. (vhdl-template-field "actual" ",")
  8885. (setq end-pos (point))
  8886. (insert "\n")
  8887. (indent-to margin)
  8888. (while (vhdl-template-field "[formal]" " => " t)
  8889. (vhdl-template-field "actual" ",")
  8890. (setq end-pos (point))
  8891. (insert "\n")
  8892. (indent-to margin))
  8893. (delete-region end-pos (point))
  8894. (delete-char -1)
  8895. (insert ")")
  8896. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
  8897. t)
  8898. (when (and optional secondary) (delete-region start (point)))
  8899. nil))))
  8900. (defun vhdl-template-modify (&optional noerror)
  8901. "Actualize modification date."
  8902. (interactive)
  8903. (vhdl-prepare-search-2
  8904. (save-excursion
  8905. (goto-char (point-min))
  8906. (if (re-search-forward vhdl-modify-date-prefix-string nil t)
  8907. (progn (delete-region (point) (progn (end-of-line) (point)))
  8908. (vhdl-template-insert-date))
  8909. (unless noerror
  8910. (error "ERROR: Modification date prefix string \"%s\" not found"
  8911. vhdl-modify-date-prefix-string))))))
  8912. (defun vhdl-template-modify-noerror ()
  8913. "Call `vhdl-template-modify' with NOERROR non-nil."
  8914. (vhdl-template-modify t))
  8915. (defun vhdl-template-nature ()
  8916. "Insert a nature declaration."
  8917. (interactive)
  8918. (let ((start (point))
  8919. name mid-pos end-pos)
  8920. (vhdl-insert-keyword "NATURE ")
  8921. (when (setq name (vhdl-template-field "name" nil t start (point)))
  8922. (vhdl-insert-keyword " IS ")
  8923. (let ((definition
  8924. (upcase
  8925. (or (vhdl-template-field
  8926. "across type | ARRAY | RECORD")
  8927. ""))))
  8928. (cond ((equal definition "")
  8929. (insert ";"))
  8930. ((equal definition "ARRAY")
  8931. (delete-region (point) (progn (forward-word -1) (point)))
  8932. (vhdl-template-array 'nature t))
  8933. ((equal definition "RECORD")
  8934. (setq mid-pos (point-marker))
  8935. (delete-region (point) (progn (forward-word -1) (point)))
  8936. (vhdl-template-record 'nature name t))
  8937. (t
  8938. (vhdl-insert-keyword " ACROSS ")
  8939. (vhdl-template-field "through type")
  8940. (vhdl-insert-keyword " THROUGH ")
  8941. (vhdl-template-field "reference name")
  8942. (vhdl-insert-keyword " REFERENCE;")))
  8943. (when mid-pos
  8944. (setq end-pos (point-marker))
  8945. (goto-char mid-pos)
  8946. (end-of-line))
  8947. (vhdl-comment-insert-inline)
  8948. (when end-pos (goto-char end-pos))))))
  8949. (defun vhdl-template-next ()
  8950. "Insert a next statement."
  8951. (interactive)
  8952. (let ((start (point)))
  8953. (vhdl-insert-keyword "NEXT ")
  8954. (if (vhdl-template-field "[loop label]" nil t start (point))
  8955. (let ((position (point)))
  8956. (vhdl-insert-keyword " WHEN ")
  8957. (when vhdl-conditions-in-parenthesis (insert "("))
  8958. (if (vhdl-template-field "[condition]" nil t)
  8959. (when vhdl-conditions-in-parenthesis (insert ")"))
  8960. (delete-region position (point))))
  8961. (delete-char -1))
  8962. (insert ";")))
  8963. (defun vhdl-template-others ()
  8964. "Insert an others aggregate."
  8965. (interactive)
  8966. (let ((start (point)))
  8967. (if (or (= (preceding-char) ?\() (not vhdl-template-invoked-by-hook))
  8968. (progn (unless vhdl-template-invoked-by-hook (insert "("))
  8969. (vhdl-insert-keyword "OTHERS => '")
  8970. (when (vhdl-template-field "value" nil t start (point))
  8971. (insert "')")))
  8972. (vhdl-insert-keyword "OTHERS "))))
  8973. (defun vhdl-template-package (&optional kind)
  8974. "Insert a package specification or body."
  8975. (interactive)
  8976. (let ((margin (current-indentation))
  8977. (start (point))
  8978. name body position)
  8979. (vhdl-insert-keyword "PACKAGE ")
  8980. (setq body (if kind (eq kind 'body)
  8981. (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b)))
  8982. (when body
  8983. (vhdl-insert-keyword "BODY ")
  8984. (when (save-excursion
  8985. (vhdl-prepare-search-1
  8986. (vhdl-re-search-backward "\\<package \\(\\w+\\) is\\>" nil t)))
  8987. (insert (setq name (match-string 1)))))
  8988. (when (or name
  8989. (setq name (vhdl-template-field "name" nil t start (point))))
  8990. (vhdl-insert-keyword " IS\n")
  8991. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  8992. (indent-to (+ margin vhdl-basic-offset))
  8993. (setq position (point))
  8994. (insert "\n")
  8995. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  8996. (indent-to margin)
  8997. (vhdl-insert-keyword "END ")
  8998. (unless (vhdl-standard-p '87)
  8999. (vhdl-insert-keyword (concat "PACKAGE " (and body "BODY "))))
  9000. (insert (or name "") ";")
  9001. (goto-char position))))
  9002. (defun vhdl-template-package-decl ()
  9003. "Insert a package specification."
  9004. (interactive)
  9005. (vhdl-template-package 'decl))
  9006. (defun vhdl-template-package-body ()
  9007. "Insert a package body."
  9008. (interactive)
  9009. (vhdl-template-package 'body))
  9010. (defun vhdl-template-port ()
  9011. "Insert a port declaration, or port map in instantiation statements."
  9012. (interactive)
  9013. (let ((start (point)))
  9014. (vhdl-prepare-search-1
  9015. (cond
  9016. ((and (save-excursion ; entity declaration
  9017. (re-search-backward "^\\(entity\\|end\\)\\>" nil t))
  9018. (equal "ENTITY" (upcase (match-string 1))))
  9019. (vhdl-template-port-list nil))
  9020. ((or (save-excursion
  9021. (or (beginning-of-line)
  9022. (looking-at "^\\s-*\\w+\\s-*:\\s-*\\w+")))
  9023. (equal 'statement-cont (caar (vhdl-get-syntactic-context))))
  9024. (vhdl-insert-keyword "PORT ")
  9025. (vhdl-template-map start))
  9026. (t (vhdl-template-port-list nil))))))
  9027. (defun vhdl-template-procedural ()
  9028. "Insert a procedural."
  9029. (interactive)
  9030. (let ((margin (current-indentation))
  9031. (start (point))
  9032. (case-fold-search t)
  9033. label)
  9034. (vhdl-insert-keyword "PROCEDURAL ")
  9035. (when (memq vhdl-optional-labels '(process all))
  9036. (goto-char start)
  9037. (insert ": ")
  9038. (goto-char start)
  9039. (setq label (vhdl-template-field "[label]" nil t))
  9040. (unless label (delete-char 2))
  9041. (forward-word 1)
  9042. (forward-char 1))
  9043. (unless (vhdl-standard-p '87) (vhdl-insert-keyword "IS"))
  9044. (insert "\n")
  9045. (vhdl-template-begin-end "PROCEDURAL" label margin)
  9046. (vhdl-comment-block)))
  9047. (defun vhdl-template-procedure (&optional kind)
  9048. "Insert a procedure declaration or body."
  9049. (interactive)
  9050. (let ((margin (current-indentation))
  9051. (start (point))
  9052. name)
  9053. (vhdl-insert-keyword "PROCEDURE ")
  9054. (when (setq name (vhdl-template-field "name" nil t start (point)))
  9055. (vhdl-template-argument-list)
  9056. (if (if kind (eq kind 'body)
  9057. (eq (vhdl-decision-query nil "(d)eclaration or (b)ody?") ?b))
  9058. (progn (vhdl-insert-keyword " IS")
  9059. (when vhdl-auto-align
  9060. (vhdl-align-region-groups start (point) 1))
  9061. (end-of-line) (insert "\n")
  9062. (vhdl-template-begin-end
  9063. (unless (vhdl-standard-p '87) "PROCEDURE")
  9064. name margin)
  9065. (vhdl-comment-block))
  9066. (insert ";")
  9067. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
  9068. (end-of-line)))))
  9069. (defun vhdl-template-procedure-decl ()
  9070. "Insert a procedure declaration."
  9071. (interactive)
  9072. (vhdl-template-procedure 'decl))
  9073. (defun vhdl-template-procedure-body ()
  9074. "Insert a procedure body."
  9075. (interactive)
  9076. (vhdl-template-procedure 'body))
  9077. (defun vhdl-template-process (&optional kind)
  9078. "Insert a process."
  9079. (interactive)
  9080. (let ((margin (current-indentation))
  9081. (start (point))
  9082. (reset-kind vhdl-reset-kind)
  9083. label seq input-signals clock reset final-pos)
  9084. (setq seq (if kind (eq kind 'seq)
  9085. (eq (vhdl-decision-query
  9086. "process" "(c)ombinational or (s)equential?" t) ?s)))
  9087. (vhdl-insert-keyword "PROCESS ")
  9088. (when (memq vhdl-optional-labels '(process all))
  9089. (goto-char start)
  9090. (insert ": ")
  9091. (goto-char start)
  9092. (setq label (vhdl-template-field "[label]" nil t))
  9093. (unless label (delete-char 2))
  9094. (forward-word 1)
  9095. (forward-char 1))
  9096. (insert "(")
  9097. (if (not seq)
  9098. (unless (or (and (vhdl-standard-p '08) vhdl-sensitivity-list-all
  9099. (progn (insert "all)") (setq input-signals "all")))
  9100. (setq input-signals
  9101. (vhdl-template-field "[sensitivity list]" ")" t)))
  9102. (setq input-signals "")
  9103. (delete-char -2))
  9104. (setq clock (or (and (not (equal "" vhdl-clock-name))
  9105. (progn (insert vhdl-clock-name) vhdl-clock-name))
  9106. (vhdl-template-field "clock name") "<clock>"))
  9107. (when (eq reset-kind 'query)
  9108. (setq reset-kind
  9109. (if (eq (vhdl-decision-query
  9110. "" "(a)synchronous or (s)ynchronous reset?" t) ?a)
  9111. 'async
  9112. 'sync)))
  9113. (when (eq reset-kind 'async)
  9114. (insert ", ")
  9115. (setq reset (or (and (not (equal "" vhdl-reset-name))
  9116. (progn (insert vhdl-reset-name) vhdl-reset-name))
  9117. (vhdl-template-field "reset name") "<reset>")))
  9118. (insert ")"))
  9119. (unless (vhdl-standard-p '87) (vhdl-insert-keyword " IS"))
  9120. (insert "\n")
  9121. (vhdl-template-begin-end "PROCESS" label margin)
  9122. (when seq (setq reset (vhdl-template-seq-process clock reset reset-kind)))
  9123. (when vhdl-prompt-for-comments
  9124. (setq final-pos (point-marker))
  9125. (vhdl-prepare-search-2
  9126. (when (and (vhdl-re-search-backward "\\<begin\\>" nil t)
  9127. (vhdl-re-search-backward "\\<process\\>" nil t))
  9128. (end-of-line -0)
  9129. (if (bobp)
  9130. (progn (insert "\n") (forward-line -1))
  9131. (insert "\n"))
  9132. (indent-to margin)
  9133. (insert "-- purpose: ")
  9134. (if (not (vhdl-template-field "[description]" nil t))
  9135. (vhdl-line-kill-entire)
  9136. (insert "\n")
  9137. (indent-to margin)
  9138. (insert "-- type : ")
  9139. (insert (if seq "sequential" "combinational") "\n")
  9140. (indent-to margin)
  9141. (insert "-- inputs : ")
  9142. (if (not seq)
  9143. (insert input-signals)
  9144. (insert clock ", ")
  9145. (when reset (insert reset ", "))
  9146. (unless (vhdl-template-field "[signal names]" nil t)
  9147. (delete-char -2)))
  9148. (insert "\n")
  9149. (indent-to margin)
  9150. (insert "-- outputs: ")
  9151. (vhdl-template-field "[signal names]" nil t))))
  9152. (goto-char final-pos))))
  9153. (defun vhdl-template-process-comb ()
  9154. "Insert a combinational process."
  9155. (interactive)
  9156. (vhdl-template-process 'comb))
  9157. (defun vhdl-template-process-seq ()
  9158. "Insert a sequential process."
  9159. (interactive)
  9160. (vhdl-template-process 'seq))
  9161. (defun vhdl-template-quantity ()
  9162. "Insert a quantity declaration."
  9163. (interactive)
  9164. (if (vhdl-in-argument-list-p)
  9165. (let ((start (point)))
  9166. (vhdl-insert-keyword "QUANTITY ")
  9167. (when (vhdl-template-field "names" nil t start (point))
  9168. (insert " : ")
  9169. (vhdl-template-field "[IN | OUT]" " " t)
  9170. (vhdl-template-field "type")
  9171. (insert ";")
  9172. (vhdl-comment-insert-inline)))
  9173. (let ((char (vhdl-decision-query
  9174. "quantity" "(f)ree, (b)ranch, or (s)ource quantity?" t)))
  9175. (cond ((eq char ?f) (vhdl-template-quantity-free))
  9176. ((eq char ?b) (vhdl-template-quantity-branch))
  9177. ((eq char ?s) (vhdl-template-quantity-source))
  9178. (t (vhdl-template-undo (point) (point)))))))
  9179. (defun vhdl-template-quantity-free ()
  9180. "Insert a free quantity declaration."
  9181. (interactive)
  9182. (vhdl-insert-keyword "QUANTITY ")
  9183. (vhdl-template-field "names")
  9184. (insert " : ")
  9185. (vhdl-template-field "type")
  9186. (let ((position (point)))
  9187. (insert " := ")
  9188. (unless (vhdl-template-field "[initialization]" nil t)
  9189. (delete-region position (point)))
  9190. (insert ";")
  9191. (vhdl-comment-insert-inline)))
  9192. (defun vhdl-template-quantity-branch ()
  9193. "Insert a branch quantity declaration."
  9194. (interactive)
  9195. (let (position)
  9196. (vhdl-insert-keyword "QUANTITY ")
  9197. (when (vhdl-template-field "[across names]" " " t)
  9198. (vhdl-insert-keyword "ACROSS "))
  9199. (when (vhdl-template-field "[through names]" " " t)
  9200. (vhdl-insert-keyword "THROUGH "))
  9201. (vhdl-template-field "plus terminal name")
  9202. (setq position (point))
  9203. (vhdl-insert-keyword " TO ")
  9204. (unless (vhdl-template-field "[minus terminal name]" nil t)
  9205. (delete-region position (point)))
  9206. (insert ";")
  9207. (vhdl-comment-insert-inline)))
  9208. (defun vhdl-template-quantity-source ()
  9209. "Insert a source quantity declaration."
  9210. (interactive)
  9211. (vhdl-insert-keyword "QUANTITY ")
  9212. (vhdl-template-field "names")
  9213. (insert " : ")
  9214. (vhdl-template-field "type" " ")
  9215. (if (eq (vhdl-decision-query nil "(s)pectrum or (n)oise?") ?n)
  9216. (progn (vhdl-insert-keyword "NOISE ")
  9217. (vhdl-template-field "power expression"))
  9218. (vhdl-insert-keyword "SPECTRUM ")
  9219. (vhdl-template-field "magnitude expression" ", ")
  9220. (vhdl-template-field "phase expression"))
  9221. (insert ";")
  9222. (vhdl-comment-insert-inline))
  9223. (defun vhdl-template-record (kind &optional name secondary)
  9224. "Insert a record type declaration."
  9225. (interactive)
  9226. (let ((margin (current-indentation))
  9227. (start (point))
  9228. (first t))
  9229. (vhdl-insert-keyword "RECORD\n")
  9230. (indent-to (+ margin vhdl-basic-offset))
  9231. (when (or (vhdl-template-field "element names"
  9232. nil (not secondary) start (point))
  9233. secondary)
  9234. (while (or first (vhdl-template-field "[element names]" nil t))
  9235. (insert " : ")
  9236. (vhdl-template-field (if (eq kind 'type) "type" "nature") ";")
  9237. (vhdl-comment-insert-inline)
  9238. (insert "\n")
  9239. (indent-to (+ margin vhdl-basic-offset))
  9240. (setq first nil))
  9241. (delete-region (line-beginning-position) (point))
  9242. (indent-to margin)
  9243. (vhdl-insert-keyword "END RECORD")
  9244. (unless (vhdl-standard-p '87) (and name (insert " " name)))
  9245. (insert ";")
  9246. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
  9247. (defun vhdl-template-report ()
  9248. "Insert a report statement."
  9249. (interactive)
  9250. (let ((start (point)))
  9251. (vhdl-insert-keyword "REPORT ")
  9252. (if (equal "\"\"" (vhdl-template-field
  9253. "string expression" nil t start (point) t))
  9254. (delete-char -2)
  9255. (setq start (point))
  9256. (vhdl-insert-keyword " SEVERITY ")
  9257. (unless (vhdl-template-field "[NOTE | WARNING | ERROR | FAILURE]" nil t)
  9258. (delete-region start (point)))
  9259. (insert ";"))))
  9260. (defun vhdl-template-return ()
  9261. "Insert a return statement."
  9262. (interactive)
  9263. (let ((start (point)))
  9264. (vhdl-insert-keyword "RETURN ")
  9265. (unless (vhdl-template-field "[expression]" nil t start (point))
  9266. (delete-char -1))
  9267. (insert ";")))
  9268. (defun vhdl-template-selected-signal-asst ()
  9269. "Insert a selected signal assignment."
  9270. (interactive)
  9271. (let ((margin (current-indentation))
  9272. (start (point))
  9273. (choices t))
  9274. (let ((position (point)))
  9275. (vhdl-insert-keyword " SELECT ")
  9276. (goto-char position))
  9277. (vhdl-insert-keyword "WITH ")
  9278. (when (vhdl-template-field "selector expression"
  9279. nil t start (+ (point) 7))
  9280. (forward-word 1)
  9281. (delete-char 1)
  9282. (insert "\n")
  9283. (indent-to (+ margin vhdl-basic-offset))
  9284. (vhdl-template-field "target signal" " <= ")
  9285. (insert "\n")
  9286. (indent-to (+ margin vhdl-basic-offset))
  9287. (vhdl-template-field "waveform")
  9288. (vhdl-insert-keyword " WHEN ")
  9289. (vhdl-template-field "choices" ",")
  9290. (insert "\n")
  9291. (indent-to (+ margin vhdl-basic-offset))
  9292. (while (and choices (vhdl-template-field "[waveform]" nil t))
  9293. (vhdl-insert-keyword " WHEN ")
  9294. (if (setq choices (vhdl-template-field "[choices]" "," t))
  9295. (progn (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
  9296. (vhdl-insert-keyword "OTHERS")))
  9297. (when choices
  9298. (fixup-whitespace)
  9299. (delete-char -2))
  9300. (insert ";")
  9301. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
  9302. (defun vhdl-template-signal ()
  9303. "Insert a signal declaration."
  9304. (interactive)
  9305. (let ((start (point))
  9306. (in-arglist (vhdl-in-argument-list-p)))
  9307. (vhdl-insert-keyword "SIGNAL ")
  9308. (when (vhdl-template-field "names" nil t start (point))
  9309. (insert " : ")
  9310. (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
  9311. (vhdl-template-field "type")
  9312. (if in-arglist
  9313. (progn (insert ";")
  9314. (vhdl-comment-insert-inline))
  9315. (let ((position (point)))
  9316. (insert " := ")
  9317. (unless (vhdl-template-field "[initialization]" nil t)
  9318. (delete-region position (point)))
  9319. (insert ";")
  9320. (vhdl-comment-insert-inline))))))
  9321. (defun vhdl-template-subnature ()
  9322. "Insert a subnature declaration."
  9323. (interactive)
  9324. (let ((start (point))
  9325. position)
  9326. (vhdl-insert-keyword "SUBNATURE ")
  9327. (when (vhdl-template-field "name" nil t start (point))
  9328. (vhdl-insert-keyword " IS ")
  9329. (vhdl-template-field "nature" " (")
  9330. (if (vhdl-template-field "[index range]" nil t)
  9331. (insert ")")
  9332. (delete-char -2))
  9333. (setq position (point))
  9334. (vhdl-insert-keyword " TOLERANCE ")
  9335. (if (equal "\"\"" (vhdl-template-field "[string expression]"
  9336. nil t nil nil t))
  9337. (delete-region position (point))
  9338. (vhdl-insert-keyword " ACROSS ")
  9339. (vhdl-template-field "string expression" nil nil nil nil t)
  9340. (vhdl-insert-keyword " THROUGH"))
  9341. (insert ";")
  9342. (vhdl-comment-insert-inline))))
  9343. (defun vhdl-template-subprogram-body ()
  9344. "Insert a subprogram body."
  9345. (interactive)
  9346. (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
  9347. (vhdl-template-function-body)
  9348. (vhdl-template-procedure-body)))
  9349. (defun vhdl-template-subprogram-decl ()
  9350. "Insert a subprogram declaration."
  9351. (interactive)
  9352. (if (eq (vhdl-decision-query nil "(p)rocedure or (f)unction?" t) ?f)
  9353. (vhdl-template-function-decl)
  9354. (vhdl-template-procedure-decl)))
  9355. (defun vhdl-template-subtype ()
  9356. "Insert a subtype declaration."
  9357. (interactive)
  9358. (let ((start (point)))
  9359. (vhdl-insert-keyword "SUBTYPE ")
  9360. (when (vhdl-template-field "name" nil t start (point))
  9361. (vhdl-insert-keyword " IS ")
  9362. (vhdl-template-field "type" " ")
  9363. (unless
  9364. (vhdl-template-field "[RANGE value range | ( index range )]" nil t)
  9365. (delete-char -1))
  9366. (insert ";")
  9367. (vhdl-comment-insert-inline))))
  9368. (defun vhdl-template-terminal ()
  9369. "Insert a terminal declaration."
  9370. (interactive)
  9371. (let ((start (point)))
  9372. (vhdl-insert-keyword "TERMINAL ")
  9373. (when (vhdl-template-field "names" nil t start (point))
  9374. (insert " : ")
  9375. (vhdl-template-field "nature")
  9376. (insert ";")
  9377. (vhdl-comment-insert-inline))))
  9378. (defun vhdl-template-type ()
  9379. "Insert a type declaration."
  9380. (interactive)
  9381. (let ((start (point))
  9382. name mid-pos end-pos)
  9383. (vhdl-insert-keyword "TYPE ")
  9384. (when (setq name (vhdl-template-field "name" nil t start (point)))
  9385. (vhdl-insert-keyword " IS ")
  9386. (let ((definition
  9387. (upcase
  9388. (or (vhdl-template-field
  9389. "[scalar type | ARRAY | RECORD | ACCESS | FILE | ENUM]" nil t)
  9390. ""))))
  9391. (cond ((equal definition "")
  9392. (delete-char -4)
  9393. (insert ";"))
  9394. ((equal definition "ARRAY")
  9395. (delete-region (point) (progn (forward-word -1) (point)))
  9396. (vhdl-template-array 'type t))
  9397. ((equal definition "RECORD")
  9398. (setq mid-pos (point-marker))
  9399. (delete-region (point) (progn (forward-word -1) (point)))
  9400. (vhdl-template-record 'type name t))
  9401. ((equal definition "ACCESS")
  9402. (insert " ")
  9403. (vhdl-template-field "type" ";"))
  9404. ((equal definition "FILE")
  9405. (vhdl-insert-keyword " OF ")
  9406. (vhdl-template-field "type" ";"))
  9407. ((equal definition "ENUM")
  9408. (kill-word -1)
  9409. (insert "(")
  9410. (setq end-pos (point-marker))
  9411. (insert ");"))
  9412. (t (insert ";")))
  9413. (when mid-pos
  9414. (setq end-pos (point-marker))
  9415. (goto-char mid-pos)
  9416. (end-of-line))
  9417. (vhdl-comment-insert-inline)
  9418. (when end-pos (goto-char end-pos))))))
  9419. (defun vhdl-template-use ()
  9420. "Insert a use clause."
  9421. (interactive)
  9422. (let ((start (point)))
  9423. (vhdl-prepare-search-1
  9424. (vhdl-insert-keyword "USE ")
  9425. (when (save-excursion (beginning-of-line) (looking-at "^\\s-*use\\>"))
  9426. (vhdl-insert-keyword "..ALL;")
  9427. (backward-char 6)
  9428. (when (vhdl-template-field "library name" nil t start (+ (point) 6))
  9429. (forward-char 1)
  9430. (vhdl-template-field "package name")
  9431. (forward-char 5))))))
  9432. (defun vhdl-template-variable ()
  9433. "Insert a variable declaration."
  9434. (interactive)
  9435. (let ((start (point))
  9436. (in-arglist (vhdl-in-argument-list-p)))
  9437. (vhdl-prepare-search-2
  9438. (if (or (save-excursion
  9439. (progn (vhdl-beginning-of-block)
  9440. (looking-at "\\s-*\\(\\w+\\s-*:\\s-*\\)?\\<\\(\\<function\\|procedure\\|process\\|procedural\\)\\>")))
  9441. (save-excursion (backward-word 1) (looking-at "\\<shared\\>")))
  9442. (vhdl-insert-keyword "VARIABLE ")
  9443. (if (vhdl-standard-p '87)
  9444. (error "ERROR: Not within sequential block")
  9445. (vhdl-insert-keyword "SHARED VARIABLE "))))
  9446. (when (vhdl-template-field "names" nil t start (point))
  9447. (insert " : ")
  9448. (when in-arglist (vhdl-template-field "[IN | OUT | INOUT]" " " t))
  9449. (vhdl-template-field "type")
  9450. (if in-arglist
  9451. (progn (insert ";")
  9452. (vhdl-comment-insert-inline))
  9453. (let ((position (point)))
  9454. (insert " := ")
  9455. (unless (vhdl-template-field "[initialization]" nil t)
  9456. (delete-region position (point)))
  9457. (insert ";")
  9458. (vhdl-comment-insert-inline))))))
  9459. (defun vhdl-template-wait ()
  9460. "Insert a wait statement."
  9461. (interactive)
  9462. (vhdl-insert-keyword "WAIT ")
  9463. (unless (vhdl-template-field
  9464. "[ON sensitivity list] [UNTIL condition] [FOR time expression]"
  9465. nil t)
  9466. (delete-char -1))
  9467. (insert ";"))
  9468. (defun vhdl-template-when ()
  9469. "Indent correctly if within a case statement."
  9470. (interactive)
  9471. (let ((position (point))
  9472. margin)
  9473. (vhdl-prepare-search-2
  9474. (if (and (= (current-column) (current-indentation))
  9475. (vhdl-re-search-forward "\\<end\\>" nil t)
  9476. (looking-at "\\s-*\\<case\\>"))
  9477. (progn
  9478. (setq margin (current-indentation))
  9479. (goto-char position)
  9480. (delete-horizontal-space)
  9481. (indent-to (+ margin vhdl-basic-offset)))
  9482. (goto-char position)))
  9483. (vhdl-insert-keyword "WHEN ")))
  9484. (defun vhdl-template-while-loop ()
  9485. "Insert a while loop."
  9486. (interactive)
  9487. (let* ((margin (current-indentation))
  9488. (start (point))
  9489. label)
  9490. (if (not (eq vhdl-optional-labels 'all))
  9491. (vhdl-insert-keyword "WHILE ")
  9492. (vhdl-insert-keyword ": WHILE ")
  9493. (goto-char start)
  9494. (setq label (vhdl-template-field "[label]" nil t))
  9495. (unless label (delete-char 2))
  9496. (forward-word 1)
  9497. (forward-char 1))
  9498. (when vhdl-conditions-in-parenthesis (insert "("))
  9499. (when (vhdl-template-field "condition" nil t start (point))
  9500. (when vhdl-conditions-in-parenthesis (insert ")"))
  9501. (vhdl-insert-keyword " LOOP\n\n")
  9502. (indent-to margin)
  9503. (vhdl-insert-keyword "END LOOP")
  9504. (insert (if label (concat " " label ";") ";"))
  9505. (forward-line -1)
  9506. (indent-to (+ margin vhdl-basic-offset)))))
  9507. (defun vhdl-template-with ()
  9508. "Insert a with statement (i.e. selected signal assignment)."
  9509. (interactive)
  9510. (vhdl-prepare-search-1
  9511. (if (and (save-excursion (vhdl-re-search-backward "\\(\\<limit\\>\\|;\\)"))
  9512. (equal ";" (match-string 1)))
  9513. (vhdl-template-selected-signal-asst)
  9514. (vhdl-insert-keyword "WITH "))))
  9515. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9516. ;; Special templates
  9517. (defun vhdl-template-clocked-wait ()
  9518. "Insert a wait statement for rising/falling clock edge."
  9519. (interactive)
  9520. (let ((start (point))
  9521. clock)
  9522. (vhdl-insert-keyword "WAIT UNTIL ")
  9523. (when (setq clock
  9524. (or (and (not (equal "" vhdl-clock-name))
  9525. (progn (insert vhdl-clock-name) vhdl-clock-name))
  9526. (vhdl-template-field "clock name" nil t start (point))))
  9527. (insert "'event")
  9528. (vhdl-insert-keyword " AND ")
  9529. (insert clock)
  9530. (insert
  9531. " = " (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string) ";")
  9532. (vhdl-comment-insert-inline
  9533. (concat (if vhdl-clock-rising-edge "rising" "falling")
  9534. " clock edge")))))
  9535. (defun vhdl-template-seq-process (clock reset reset-kind)
  9536. "Insert a template for the body of a sequential process."
  9537. (let ((margin (current-indentation))
  9538. position)
  9539. (vhdl-insert-keyword "IF ")
  9540. (when vhdl-conditions-in-parenthesis (insert "("))
  9541. (when (eq reset-kind 'async)
  9542. (insert reset " = "
  9543. (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
  9544. (when vhdl-conditions-in-parenthesis (insert ")"))
  9545. (vhdl-insert-keyword " THEN")
  9546. (vhdl-comment-insert-inline
  9547. (concat "asynchronous reset (active "
  9548. (if vhdl-reset-active-high "high" "low") ")"))
  9549. (insert "\n") (indent-to (+ margin vhdl-basic-offset))
  9550. (setq position (point))
  9551. (insert "\n") (indent-to margin)
  9552. (vhdl-insert-keyword "ELSIF ")
  9553. (when vhdl-conditions-in-parenthesis (insert "(")))
  9554. (if (eq vhdl-clock-edge-condition 'function)
  9555. (insert (if vhdl-clock-rising-edge "rising" "falling")
  9556. "_edge(" clock ")")
  9557. (insert clock "'event")
  9558. (vhdl-insert-keyword " AND ")
  9559. (insert clock " = "
  9560. (if vhdl-clock-rising-edge vhdl-one-string vhdl-zero-string)))
  9561. (when vhdl-conditions-in-parenthesis (insert ")"))
  9562. (vhdl-insert-keyword " THEN")
  9563. (vhdl-comment-insert-inline
  9564. (concat (if vhdl-clock-rising-edge "rising" "falling") " clock edge"))
  9565. (insert "\n") (indent-to (+ margin vhdl-basic-offset))
  9566. (when (eq reset-kind 'sync)
  9567. (vhdl-insert-keyword "IF ")
  9568. (when vhdl-conditions-in-parenthesis (insert "("))
  9569. (setq reset (or (and (not (equal "" vhdl-reset-name))
  9570. (progn (insert vhdl-reset-name) vhdl-reset-name))
  9571. (vhdl-template-field "reset name") "<reset>"))
  9572. (insert " = "
  9573. (if vhdl-reset-active-high vhdl-one-string vhdl-zero-string))
  9574. (when vhdl-conditions-in-parenthesis (insert ")"))
  9575. (vhdl-insert-keyword " THEN")
  9576. (vhdl-comment-insert-inline
  9577. (concat "synchronous reset (active "
  9578. (if vhdl-reset-active-high "high" "low") ")"))
  9579. (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
  9580. (setq position (point))
  9581. (insert "\n") (indent-to (+ margin vhdl-basic-offset))
  9582. (vhdl-insert-keyword "ELSE")
  9583. (insert "\n") (indent-to (+ margin (* 2 vhdl-basic-offset)))
  9584. (insert "\n") (indent-to (+ margin vhdl-basic-offset))
  9585. (vhdl-insert-keyword "END IF;"))
  9586. (when (eq reset-kind 'none)
  9587. (setq position (point)))
  9588. (insert "\n") (indent-to margin)
  9589. (vhdl-insert-keyword "END IF;")
  9590. (goto-char position)
  9591. reset))
  9592. (defun vhdl-template-standard-package (library package)
  9593. "Insert specification of a standard package. Include a library
  9594. specification, if not already there."
  9595. (let ((margin (current-indentation)))
  9596. (unless (equal library "std")
  9597. (unless (or (save-excursion
  9598. (vhdl-prepare-search-1
  9599. (and (not (bobp))
  9600. (re-search-backward
  9601. (concat "^\\s-*\\(\\(library\\)\\s-+\\(\\w+\\s-*,\\s-*\\)*"
  9602. library "\\|end\\)\\>") nil t)
  9603. (match-string 2))))
  9604. (equal (downcase library) "work"))
  9605. (vhdl-insert-keyword "LIBRARY ")
  9606. (insert library ";")
  9607. (when package
  9608. (insert "\n")
  9609. (indent-to margin))))
  9610. (when package
  9611. (vhdl-insert-keyword "USE ")
  9612. (insert library "." package)
  9613. (vhdl-insert-keyword ".ALL;"))))
  9614. (defun vhdl-template-package-numeric-bit ()
  9615. "Insert specification of `numeric_bit' package."
  9616. (interactive)
  9617. (vhdl-template-standard-package "ieee" "numeric_bit"))
  9618. (defun vhdl-template-package-numeric-std ()
  9619. "Insert specification of `numeric_std' package."
  9620. (interactive)
  9621. (vhdl-template-standard-package "ieee" "numeric_std"))
  9622. (defun vhdl-template-package-std-logic-1164 ()
  9623. "Insert specification of `std_logic_1164' package."
  9624. (interactive)
  9625. (vhdl-template-standard-package "ieee" "std_logic_1164"))
  9626. (defun vhdl-template-package-std-logic-arith ()
  9627. "Insert specification of `std_logic_arith' package."
  9628. (interactive)
  9629. (vhdl-template-standard-package "ieee" "std_logic_arith"))
  9630. (defun vhdl-template-package-std-logic-misc ()
  9631. "Insert specification of `std_logic_misc' package."
  9632. (interactive)
  9633. (vhdl-template-standard-package "ieee" "std_logic_misc"))
  9634. (defun vhdl-template-package-std-logic-signed ()
  9635. "Insert specification of `std_logic_signed' package."
  9636. (interactive)
  9637. (vhdl-template-standard-package "ieee" "std_logic_signed"))
  9638. (defun vhdl-template-package-std-logic-textio ()
  9639. "Insert specification of `std_logic_textio' package."
  9640. (interactive)
  9641. (vhdl-template-standard-package "ieee" "std_logic_textio"))
  9642. (defun vhdl-template-package-std-logic-unsigned ()
  9643. "Insert specification of `std_logic_unsigned' package."
  9644. (interactive)
  9645. (vhdl-template-standard-package "ieee" "std_logic_unsigned"))
  9646. (defun vhdl-template-package-textio ()
  9647. "Insert specification of `textio' package."
  9648. (interactive)
  9649. (vhdl-template-standard-package "std" "textio"))
  9650. (defun vhdl-template-package-fundamental-constants ()
  9651. "Insert specification of `fundamental_constants' package."
  9652. (interactive)
  9653. (vhdl-template-standard-package "ieee" "fundamental_constants"))
  9654. (defun vhdl-template-package-material-constants ()
  9655. "Insert specification of `material_constants' package."
  9656. (interactive)
  9657. (vhdl-template-standard-package "ieee" "material_constants"))
  9658. (defun vhdl-template-package-energy-systems ()
  9659. "Insert specification of `energy_systems' package."
  9660. (interactive)
  9661. (vhdl-template-standard-package "ieee" "energy_systems"))
  9662. (defun vhdl-template-package-electrical-systems ()
  9663. "Insert specification of `electrical_systems' package."
  9664. (interactive)
  9665. (vhdl-template-standard-package "ieee" "electrical_systems"))
  9666. (defun vhdl-template-package-mechanical-systems ()
  9667. "Insert specification of `mechanical_systems' package."
  9668. (interactive)
  9669. (vhdl-template-standard-package "ieee" "mechanical_systems"))
  9670. (defun vhdl-template-package-radiant-systems ()
  9671. "Insert specification of `radiant_systems' package."
  9672. (interactive)
  9673. (vhdl-template-standard-package "ieee" "radiant_systems"))
  9674. (defun vhdl-template-package-thermal-systems ()
  9675. "Insert specification of `thermal_systems' package."
  9676. (interactive)
  9677. (vhdl-template-standard-package "ieee" "thermal_systems"))
  9678. (defun vhdl-template-package-fluidic-systems ()
  9679. "Insert specification of `fluidic_systems' package."
  9680. (interactive)
  9681. (vhdl-template-standard-package "ieee" "fluidic_systems"))
  9682. (defun vhdl-template-package-math-complex ()
  9683. "Insert specification of `math_complex' package."
  9684. (interactive)
  9685. (vhdl-template-standard-package "ieee" "math_complex"))
  9686. (defun vhdl-template-package-math-real ()
  9687. "Insert specification of `math_real' package."
  9688. (interactive)
  9689. (vhdl-template-standard-package "ieee" "math_real"))
  9690. (defun vhdl-template-directive (directive)
  9691. "Insert directive."
  9692. (unless (= (current-indentation) (current-column))
  9693. (delete-horizontal-space)
  9694. (insert " "))
  9695. (insert "-- pragma " directive))
  9696. (defun vhdl-template-directive-translate-on ()
  9697. "Insert directive 'translate_on'."
  9698. (interactive)
  9699. (vhdl-template-directive "translate_on"))
  9700. (defun vhdl-template-directive-translate-off ()
  9701. "Insert directive 'translate_off'."
  9702. (interactive)
  9703. (vhdl-template-directive "translate_off"))
  9704. (defun vhdl-template-directive-synthesis-on ()
  9705. "Insert directive 'synthesis_on'."
  9706. (interactive)
  9707. (vhdl-template-directive "synthesis_on"))
  9708. (defun vhdl-template-directive-synthesis-off ()
  9709. "Insert directive 'synthesis_off'."
  9710. (interactive)
  9711. (vhdl-template-directive "synthesis_off"))
  9712. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9713. ;; Header and footer templates
  9714. (defun vhdl-template-header (&optional file-title)
  9715. "Insert a VHDL file header."
  9716. (interactive)
  9717. (unless (equal vhdl-file-header "")
  9718. (let (pos)
  9719. (save-excursion
  9720. (goto-char (point-min))
  9721. (vhdl-insert-string-or-file vhdl-file-header)
  9722. (setq pos (point-marker)))
  9723. (vhdl-template-replace-header-keywords
  9724. (point-min-marker) pos file-title))))
  9725. (defun vhdl-template-footer ()
  9726. "Insert a VHDL file footer."
  9727. (interactive)
  9728. (unless (equal vhdl-file-footer "")
  9729. (let (pos)
  9730. (save-excursion
  9731. (goto-char (point-max))
  9732. (setq pos (point-marker))
  9733. (vhdl-insert-string-or-file vhdl-file-footer)
  9734. (unless (= (preceding-char) ?\n)
  9735. (insert "\n")))
  9736. (vhdl-template-replace-header-keywords pos (point-max-marker)))))
  9737. (defun vhdl-template-replace-header-keywords (beg end &optional file-title
  9738. is-model)
  9739. "Replace keywords in header and footer."
  9740. (let ((project-title (or (nth 0 (vhdl-aget vhdl-project-alist vhdl-project))
  9741. ""))
  9742. (project-desc (or (nth 9 (vhdl-aget vhdl-project-alist vhdl-project))
  9743. ""))
  9744. pos)
  9745. (vhdl-prepare-search-2
  9746. (save-excursion
  9747. (goto-char beg)
  9748. (while (search-forward "<projectdesc>" end t)
  9749. (replace-match project-desc t t))
  9750. (goto-char beg)
  9751. (while (search-forward "<filename>" end t)
  9752. (replace-match (buffer-name) t t))
  9753. (goto-char beg)
  9754. (while (search-forward "<copyright>" end t)
  9755. (replace-match vhdl-copyright-string t t))
  9756. (goto-char beg)
  9757. (while (search-forward "<author>" end t)
  9758. (replace-match "" t t)
  9759. (insert (user-full-name))
  9760. (when user-mail-address (insert " <" user-mail-address ">")))
  9761. (goto-char beg)
  9762. (while (search-forward "<authorfull>" end t)
  9763. (replace-match (user-full-name) t t))
  9764. (goto-char beg)
  9765. (while (search-forward "<login>" end t)
  9766. (replace-match (user-login-name) t t))
  9767. (goto-char beg)
  9768. (while (search-forward "<project>" end t)
  9769. (replace-match project-title t t))
  9770. (goto-char beg)
  9771. (while (search-forward "<company>" end t)
  9772. (replace-match vhdl-company-name t t))
  9773. (goto-char beg)
  9774. (while (search-forward "<platform>" end t)
  9775. (replace-match vhdl-platform-spec t t))
  9776. (goto-char beg)
  9777. (while (search-forward "<standard>" end t)
  9778. (replace-match
  9779. (concat "VHDL" (cond ((vhdl-standard-p '87) "'87")
  9780. ((vhdl-standard-p '93) "'93/02")
  9781. ((vhdl-standard-p '08) "'08"))
  9782. (when (vhdl-standard-p 'ams) ", VHDL-AMS")
  9783. (when (vhdl-standard-p 'math) ", Math Packages")) t t))
  9784. (goto-char beg)
  9785. ;; Replace <RCS> with $, so that RCS for the source is
  9786. ;; not over-enthusiastic with replacements
  9787. (while (search-forward "<RCS>" end t)
  9788. (replace-match "$" nil t))
  9789. (goto-char beg)
  9790. (while (search-forward "<date>" end t)
  9791. (replace-match "" t t)
  9792. (vhdl-template-insert-date))
  9793. (goto-char beg)
  9794. (while (search-forward "<year>" end t)
  9795. (replace-match (format-time-string "%Y" nil) t t))
  9796. (goto-char beg)
  9797. (when file-title
  9798. (while (search-forward "<title string>" end t)
  9799. (replace-match file-title t t))
  9800. (goto-char beg))
  9801. (let (string)
  9802. (while (re-search-forward "<\\(\\(\\w\\|\\s_\\)*\\) string>" end t)
  9803. (save-match-data
  9804. (setq string (read-string (concat (match-string 1) ": "))))
  9805. (replace-match string t t)))
  9806. (goto-char beg)
  9807. (when (and (not is-model) (search-forward "<cursor>" end t))
  9808. (replace-match "" t t)
  9809. (setq pos (point))))
  9810. (when pos (goto-char pos))
  9811. (unless is-model
  9812. (when (or (not project-title) (equal project-title ""))
  9813. (message "You can specify a project title in user option `vhdl-project-alist'"))
  9814. (when (or (not project-desc) (equal project-desc ""))
  9815. (message "You can specify a project description in user option `vhdl-project-alist'"))
  9816. (when (equal vhdl-platform-spec "")
  9817. (message "You can specify a platform in user option `vhdl-platform-spec'"))
  9818. (when (equal vhdl-company-name "")
  9819. (message "You can specify a company name in user option `vhdl-company-name'"))))))
  9820. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9821. ;; Comment templates and functions
  9822. (defun vhdl-comment-indent ()
  9823. "Indent comments."
  9824. (let* ((position (point))
  9825. (col
  9826. (progn
  9827. (forward-line -1)
  9828. (if (re-search-forward "--" position t)
  9829. (- (current-column) 2) ; existing comment at bol stays there
  9830. (goto-char position)
  9831. (skip-chars-backward " \t")
  9832. (max comment-column ; else indent to comment column
  9833. (1+ (current-column))))))) ; except leave at least one space
  9834. (goto-char position)
  9835. col))
  9836. (defun vhdl-comment-insert ()
  9837. "Start a comment at the end of the line.
  9838. If on line with code, indent at least `comment-column'.
  9839. If starting after end-comment-column, start a new line."
  9840. (interactive)
  9841. (when (> (current-column) end-comment-column) (newline-and-indent))
  9842. (if (or (looking-at "\\s-*$") ; end of line
  9843. (and (not unread-command-events) ; called with key binding or menu
  9844. (not (end-of-line))))
  9845. (let (margin)
  9846. (while (= (preceding-char) ?-) (delete-char -1))
  9847. (setq margin (current-column))
  9848. (delete-horizontal-space)
  9849. (if (bolp)
  9850. (progn (indent-to margin) (insert "--"))
  9851. (insert " ")
  9852. (indent-to comment-column)
  9853. (insert "--"))
  9854. (if (not unread-command-events) (insert " ")))
  9855. ;; else code following current point implies commenting out code
  9856. (let (next-input code)
  9857. (while (= (preceding-char) ?-) (delete-char -2))
  9858. (while (= (setq next-input (read-char)) 13) ; CR
  9859. (insert "--") ; or have a space after it?
  9860. (forward-char -2)
  9861. (forward-line 1)
  9862. (message "Enter CR if commenting out a line of code.")
  9863. (setq code t))
  9864. (unless code
  9865. (insert "--")) ; hardwire to 1 space or use vhdl-basic-offset?
  9866. (push (vhdl-character-to-event next-input) ; pushback the char
  9867. unread-command-events))))
  9868. (defun vhdl-comment-display (&optional line-exists)
  9869. "Add 2 comment lines at the current indent, making a display comment."
  9870. (interactive)
  9871. (let ((margin (current-indentation)))
  9872. (unless line-exists (vhdl-comment-display-line))
  9873. (insert "\n") (indent-to margin)
  9874. (insert "\n") (indent-to margin)
  9875. (vhdl-comment-display-line)
  9876. (end-of-line -0)
  9877. (insert "-- ")))
  9878. (defun vhdl-comment-display-line ()
  9879. "Displays one line of dashes."
  9880. (interactive)
  9881. (while (= (preceding-char) ?-) (delete-char -2))
  9882. (insert "--")
  9883. (let* ((col (current-column))
  9884. (len (- end-comment-column col)))
  9885. (insert-char vhdl-comment-display-line-char len)))
  9886. (defun vhdl-comment-append-inline ()
  9887. "Append empty inline comment to current line."
  9888. (interactive)
  9889. (end-of-line)
  9890. (delete-horizontal-space)
  9891. (insert " ")
  9892. (indent-to comment-column)
  9893. (insert "-- "))
  9894. (defun vhdl-comment-insert-inline (&optional string always-insert)
  9895. "Insert inline comment."
  9896. (when (or (and string (or vhdl-self-insert-comments always-insert))
  9897. (and (not string) vhdl-prompt-for-comments))
  9898. (let ((position (point)))
  9899. (insert " ")
  9900. (indent-to comment-column)
  9901. (insert "-- ")
  9902. (if (not (or (and string (progn (insert string) t))
  9903. (vhdl-template-field "[comment]" nil t)))
  9904. (delete-region position (point))
  9905. (while (= (preceding-char) ?\ ) (delete-char -1))))))
  9906. (defun vhdl-comment-block ()
  9907. "Insert comment for code block."
  9908. (when vhdl-prompt-for-comments
  9909. (let ((final-pos (point-marker)))
  9910. (vhdl-prepare-search-2
  9911. (when (and (re-search-backward "^\\s-*begin\\>" nil t)
  9912. (re-search-backward "\\<\\(architecture\\|block\\|function\\|procedure\\|process\\|procedural\\)\\>" nil t))
  9913. (let (margin)
  9914. (back-to-indentation)
  9915. (setq margin (current-column))
  9916. (end-of-line -0)
  9917. (if (bobp)
  9918. (progn (insert "\n") (forward-line -1))
  9919. (insert "\n"))
  9920. (indent-to margin)
  9921. (insert "-- purpose: ")
  9922. (unless (vhdl-template-field "[description]" nil t)
  9923. (vhdl-line-kill-entire)))))
  9924. (goto-char final-pos))))
  9925. (defun vhdl-comment-uncomment-region (beg end &optional arg)
  9926. "Comment out region if not commented out, uncomment otherwise."
  9927. (interactive "r\nP")
  9928. (save-excursion
  9929. (goto-char (1- end))
  9930. (end-of-line)
  9931. (setq end (point-marker))
  9932. (goto-char beg)
  9933. (beginning-of-line)
  9934. (setq beg (point))
  9935. (if (looking-at (concat "\\s-*" comment-start))
  9936. (comment-region beg end '(4))
  9937. (comment-region beg end))))
  9938. (defun vhdl-comment-uncomment-line (&optional arg)
  9939. "Comment out line if not commented out, uncomment otherwise."
  9940. (interactive "p")
  9941. (save-excursion
  9942. (beginning-of-line)
  9943. (let ((position (point)))
  9944. (forward-line (or arg 1))
  9945. (vhdl-comment-uncomment-region position (point)))))
  9946. (defun vhdl-comment-kill-region (beg end)
  9947. "Kill comments in region."
  9948. (interactive "r")
  9949. (save-excursion
  9950. (goto-char end)
  9951. (setq end (point-marker))
  9952. (goto-char beg)
  9953. (beginning-of-line)
  9954. (while (< (point) end)
  9955. (if (looking-at "^\\(\\s-*--.*\n\\)")
  9956. (progn (delete-region (match-beginning 1) (match-end 1)))
  9957. (beginning-of-line 2)))))
  9958. (defun vhdl-comment-kill-inline-region (beg end)
  9959. "Kill inline comments in region."
  9960. (interactive "r")
  9961. (save-excursion
  9962. (goto-char end)
  9963. (setq end (point-marker))
  9964. (goto-char beg)
  9965. (beginning-of-line)
  9966. (while (< (point) end)
  9967. (when (looking-at "^.*[^ \t\n\r\f-]+\\(\\s-*--.*\\)$")
  9968. (delete-region (match-beginning 1) (match-end 1)))
  9969. (beginning-of-line 2))))
  9970. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9971. ;; Subtemplates
  9972. (defun vhdl-template-begin-end (construct name margin &optional empty-lines)
  9973. "Insert a begin ... end pair with optional name after the end.
  9974. Point is left between them."
  9975. (let (position)
  9976. (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
  9977. (indent-to margin)
  9978. (vhdl-insert-keyword "BEGIN")
  9979. (when (and (or construct name) vhdl-self-insert-comments)
  9980. (insert " --")
  9981. (when construct (insert " ") (vhdl-insert-keyword construct))
  9982. (when name (insert " " name)))
  9983. (insert "\n")
  9984. (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
  9985. (indent-to (+ margin vhdl-basic-offset))
  9986. (setq position (point))
  9987. (insert "\n")
  9988. (when (or empty-lines (eq vhdl-insert-empty-lines 'all)) (insert "\n"))
  9989. (indent-to margin)
  9990. (vhdl-insert-keyword "END")
  9991. (when construct (insert " ") (vhdl-insert-keyword construct))
  9992. (insert (if name (concat " " name) "") ";")
  9993. (goto-char position)))
  9994. (defun vhdl-template-argument-list (&optional is-function)
  9995. "Read from user a procedure or function argument list."
  9996. (insert " (")
  9997. (let ((margin (current-column))
  9998. (start (point))
  9999. (end-pos (point))
  10000. not-empty interface semicolon-pos)
  10001. (unless vhdl-argument-list-indent
  10002. (setq margin (+ (current-indentation) vhdl-basic-offset))
  10003. (insert "\n")
  10004. (indent-to margin))
  10005. (setq interface (vhdl-template-field
  10006. (concat "[CONSTANT | SIGNAL"
  10007. (unless is-function " | VARIABLE") "]") " " t))
  10008. (while (vhdl-template-field "[names]" nil t)
  10009. (setq not-empty t)
  10010. (insert " : ")
  10011. (unless is-function
  10012. (if (and interface (equal (upcase interface) "CONSTANT"))
  10013. (vhdl-insert-keyword "IN ")
  10014. (vhdl-template-field "[IN | OUT | INOUT]" " " t)))
  10015. (vhdl-template-field "type")
  10016. (setq semicolon-pos (point))
  10017. (insert ";")
  10018. (vhdl-comment-insert-inline)
  10019. (setq end-pos (point))
  10020. (insert "\n")
  10021. (indent-to margin)
  10022. (setq interface (vhdl-template-field
  10023. (concat "[CONSTANT | SIGNAL"
  10024. (unless is-function " | VARIABLE") "]") " " t)))
  10025. (delete-region end-pos (point))
  10026. (when semicolon-pos (goto-char semicolon-pos))
  10027. (if not-empty
  10028. (progn (delete-char 1) (insert ")"))
  10029. (delete-char -2))))
  10030. (defun vhdl-template-generic-list (optional &optional no-value)
  10031. "Read from user a generic spec argument list."
  10032. (let (margin
  10033. (start (point)))
  10034. (vhdl-insert-keyword "GENERIC (")
  10035. (setq margin (current-column))
  10036. (unless vhdl-argument-list-indent
  10037. (let ((position (point)))
  10038. (back-to-indentation)
  10039. (setq margin (+ (current-column) vhdl-basic-offset))
  10040. (goto-char position)
  10041. (insert "\n")
  10042. (indent-to margin)))
  10043. (let ((vhdl-generics (vhdl-template-field
  10044. (concat (and optional "[") "name"
  10045. (and no-value "s") (and optional "]"))
  10046. nil optional)))
  10047. (if (not vhdl-generics)
  10048. (if optional
  10049. (progn (vhdl-line-kill-entire) (end-of-line -0)
  10050. (unless vhdl-argument-list-indent
  10051. (vhdl-line-kill-entire) (end-of-line -0)))
  10052. (vhdl-template-undo start (point))
  10053. nil )
  10054. (insert " : ")
  10055. (let (semicolon-pos end-pos)
  10056. (while vhdl-generics
  10057. (vhdl-template-field "type")
  10058. (if no-value
  10059. (progn (setq semicolon-pos (point))
  10060. (insert ";"))
  10061. (insert " := ")
  10062. (unless (vhdl-template-field "[value]" nil t)
  10063. (delete-char -4))
  10064. (setq semicolon-pos (point))
  10065. (insert ";"))
  10066. (vhdl-comment-insert-inline)
  10067. (setq end-pos (point))
  10068. (insert "\n")
  10069. (indent-to margin)
  10070. (setq vhdl-generics (vhdl-template-field
  10071. (concat "[name" (and no-value "s") "]")
  10072. " : " t)))
  10073. (delete-region end-pos (point))
  10074. (goto-char semicolon-pos)
  10075. (insert ")")
  10076. (end-of-line)
  10077. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))
  10078. t)))))
  10079. (defun vhdl-template-port-list (optional)
  10080. "Read from user a port spec argument list."
  10081. (let ((start (point))
  10082. margin vhdl-ports object)
  10083. (vhdl-insert-keyword "PORT (")
  10084. (setq margin (current-column))
  10085. (unless vhdl-argument-list-indent
  10086. (let ((position (point)))
  10087. (back-to-indentation)
  10088. (setq margin (+ (current-column) vhdl-basic-offset))
  10089. (goto-char position)
  10090. (insert "\n")
  10091. (indent-to margin)))
  10092. (when (vhdl-standard-p 'ams)
  10093. (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
  10094. " " t)))
  10095. (setq vhdl-ports (vhdl-template-field
  10096. (concat (and optional "[") "names" (and optional "]"))
  10097. nil optional))
  10098. (if (not vhdl-ports)
  10099. (if optional
  10100. (progn (vhdl-line-kill-entire) (end-of-line -0)
  10101. (unless vhdl-argument-list-indent
  10102. (vhdl-line-kill-entire) (end-of-line -0)))
  10103. (vhdl-template-undo start (point))
  10104. nil)
  10105. (insert " : ")
  10106. (let (semicolon-pos end-pos)
  10107. (while vhdl-ports
  10108. (cond ((or (null object) (equal "SIGNAL" (upcase object)))
  10109. (vhdl-template-field "IN | OUT | INOUT" " "))
  10110. ((equal "QUANTITY" (upcase object))
  10111. (vhdl-template-field "[IN | OUT]" " " t)))
  10112. (vhdl-template-field
  10113. (if (and object (equal "TERMINAL" (upcase object)))
  10114. "nature" "type"))
  10115. (setq semicolon-pos (point))
  10116. (insert ";")
  10117. (vhdl-comment-insert-inline)
  10118. (setq end-pos (point))
  10119. (insert "\n")
  10120. (indent-to margin)
  10121. (when (vhdl-standard-p 'ams)
  10122. (setq object (vhdl-template-field "[SIGNAL | TERMINAL | QUANTITY]"
  10123. " " t)))
  10124. (setq vhdl-ports (vhdl-template-field "[names]" " : " t)))
  10125. (delete-region end-pos (point))
  10126. (goto-char semicolon-pos)
  10127. (insert ")")
  10128. (end-of-line)
  10129. (when vhdl-auto-align (vhdl-align-region-groups start end-pos 1))
  10130. t))))
  10131. (defun vhdl-template-generate-body (margin label)
  10132. "Insert body for generate template."
  10133. (vhdl-insert-keyword " GENERATE")
  10134. (insert "\n\n")
  10135. (indent-to margin)
  10136. (vhdl-insert-keyword "END GENERATE ")
  10137. (insert label ";")
  10138. (end-of-line 0)
  10139. (indent-to (+ margin vhdl-basic-offset)))
  10140. (defun vhdl-template-insert-date ()
  10141. "Insert date in appropriate format."
  10142. (interactive)
  10143. (insert
  10144. (cond
  10145. ;; 'american, 'european, 'scientific kept for backward compatibility
  10146. ((eq vhdl-date-format 'american) (format-time-string "%m/%d/%Y" nil))
  10147. ((eq vhdl-date-format 'european) (format-time-string "%d.%m.%Y" nil))
  10148. ((eq vhdl-date-format 'scientific) (format-time-string "%Y/%m/%d" nil))
  10149. (t (format-time-string vhdl-date-format nil)))))
  10150. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10151. ;; Help functions
  10152. (defun vhdl-electric-space (count)
  10153. "Expand abbreviations and self-insert space(s), do indent-new-comment-line
  10154. if in comment and past end-comment-column."
  10155. (interactive "p")
  10156. (cond ((vhdl-in-comment-p)
  10157. (self-insert-command count)
  10158. (cond ((>= (current-column) (+ 2 end-comment-column))
  10159. (backward-char 1)
  10160. (skip-chars-backward "^ \t\n\r\f")
  10161. (indent-new-comment-line)
  10162. (skip-chars-forward "^ \t\n\r\f")
  10163. (forward-char 1))
  10164. ((>= (current-column) end-comment-column)
  10165. (indent-new-comment-line))
  10166. (t nil)))
  10167. ((or (and (>= (preceding-char) ?a) (<= (preceding-char) ?z))
  10168. (and (>= (preceding-char) ?A) (<= (preceding-char) ?Z)))
  10169. (vhdl-prepare-search-1
  10170. (or (expand-abbrev) (vhdl-fix-case-word -1)))
  10171. (self-insert-command count))
  10172. (t (self-insert-command count))))
  10173. (defun vhdl-template-field (prompt &optional follow-string optional
  10174. begin end is-string default)
  10175. "Prompt for string and insert it in buffer with optional FOLLOW-STRING.
  10176. If OPTIONAL is nil, the prompt is left if an empty string is inserted. If
  10177. an empty string is inserted, return nil and call `vhdl-template-undo' for
  10178. the region between BEGIN and END. IS-STRING indicates whether a string
  10179. with double-quotes is to be inserted. DEFAULT specifies a default string."
  10180. (let ((position (point))
  10181. string)
  10182. (insert "<" prompt ">")
  10183. (setq string
  10184. (condition-case ()
  10185. (read-from-minibuffer (concat prompt ": ")
  10186. (or (and is-string '("\"\"" . 2)) default)
  10187. vhdl-minibuffer-local-map)
  10188. (quit (if (and optional begin end)
  10189. (progn (beep) "")
  10190. (keyboard-quit)))))
  10191. (when (or (not (equal string "")) optional)
  10192. (delete-region position (point)))
  10193. (when (and (equal string "") optional begin end)
  10194. (vhdl-template-undo begin end)
  10195. (message "Template aborted"))
  10196. (unless (equal string "")
  10197. (insert string)
  10198. (vhdl-fix-case-region-1 position (point) vhdl-upper-case-keywords
  10199. vhdl-keywords-regexp)
  10200. (vhdl-fix-case-region-1 position (point) vhdl-upper-case-types
  10201. vhdl-types-regexp)
  10202. (vhdl-fix-case-region-1 position (point) vhdl-upper-case-attributes
  10203. (concat "'" vhdl-attributes-regexp))
  10204. (vhdl-fix-case-region-1 position (point) vhdl-upper-case-enum-values
  10205. vhdl-enum-values-regexp)
  10206. (vhdl-fix-case-region-1 position (point) vhdl-upper-case-constants
  10207. vhdl-constants-regexp))
  10208. (when (or (not (equal string "")) (not optional))
  10209. (insert (or follow-string "")))
  10210. (if (equal string "") nil string)))
  10211. (defun vhdl-decision-query (string prompt &optional optional)
  10212. "Query a decision from the user."
  10213. (let ((start (point)))
  10214. (when string (vhdl-insert-keyword (concat string " ")))
  10215. (message "%s" (or prompt ""))
  10216. (let ((char (read-char)))
  10217. (delete-region start (point))
  10218. (if (and optional (eq char ?\r))
  10219. (progn (insert " ")
  10220. (unexpand-abbrev)
  10221. (throw 'abort "ERROR: Template aborted"))
  10222. char))))
  10223. (defun vhdl-insert-keyword (keyword)
  10224. "Insert KEYWORD and adjust case."
  10225. (insert (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword))))
  10226. (defun vhdl-case-keyword (keyword)
  10227. "Adjust case of KEYWORD."
  10228. (if vhdl-upper-case-keywords (upcase keyword) (downcase keyword)))
  10229. (defun vhdl-case-word (num)
  10230. "Adjust case of following NUM words."
  10231. (if vhdl-upper-case-keywords (upcase-word num) (downcase-word num)))
  10232. (defun vhdl-minibuffer-tab (&optional prefix-arg)
  10233. "If preceding character is part of a word or a paren then hippie-expand,
  10234. else insert tab (used for word completion in VHDL minibuffer)."
  10235. (interactive "P")
  10236. (cond
  10237. ;; expand word
  10238. ((= (char-syntax (preceding-char)) ?w)
  10239. (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
  10240. (case-replace nil)
  10241. (hippie-expand-only-buffers
  10242. (or (and (boundp 'hippie-expand-only-buffers)
  10243. hippie-expand-only-buffers)
  10244. '(vhdl-mode))))
  10245. (vhdl-expand-abbrev prefix-arg)))
  10246. ;; expand parenthesis
  10247. ((or (= (preceding-char) ?\() (= (preceding-char) ?\)))
  10248. (let ((case-fold-search (not vhdl-word-completion-case-sensitive))
  10249. (case-replace nil))
  10250. (vhdl-expand-paren prefix-arg)))
  10251. ;; insert tab
  10252. (t (insert-tab))))
  10253. (defun vhdl-template-search-prompt ()
  10254. "Search for left out template prompts and query again."
  10255. (interactive)
  10256. (vhdl-prepare-search-2
  10257. (when (or (re-search-forward
  10258. (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t)
  10259. (re-search-backward
  10260. (concat "<\\(" vhdl-template-prompt-syntax "\\)>") nil t))
  10261. (let ((string (match-string 1)))
  10262. (replace-match "")
  10263. (vhdl-template-field string)))))
  10264. (defun vhdl-template-undo (begin end)
  10265. "Undo aborted template by deleting region and unexpanding the keyword."
  10266. (cond (vhdl-template-invoked-by-hook
  10267. (goto-char end)
  10268. (insert " ")
  10269. (delete-region begin end)
  10270. (unexpand-abbrev))
  10271. (t (delete-region begin end))))
  10272. (defun vhdl-insert-string-or-file (string)
  10273. "Insert STRING or file contents if STRING is an existing file name."
  10274. (unless (equal string "")
  10275. (let ((file-name
  10276. (progn (string-match "^\\([^\n]+\\)" string)
  10277. (vhdl-resolve-env-variable (match-string 1 string)))))
  10278. (if (file-exists-p file-name)
  10279. (forward-char (cadr (insert-file-contents file-name)))
  10280. (insert string)))))
  10281. (defun vhdl-beginning-of-block ()
  10282. "Move cursor to the beginning of the enclosing block."
  10283. (let (pos)
  10284. (vhdl-prepare-search-2
  10285. (save-excursion
  10286. (beginning-of-line)
  10287. ;; search backward for block beginning or end
  10288. (while (or (while (and (setq pos (re-search-backward "^\\s-*\\(\\(end\\)\\|\\(\\(impure\\|pure\\)[ \t\n\r\f]+\\)?\\(function\\|procedure\\)\\|\\(for\\)\\|\\(architecture\\|component\\|configuration\\|context\\|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))
  10289. ;; not consider subprogram declarations
  10290. (or (and (match-string 5)
  10291. (save-match-data
  10292. (save-excursion
  10293. (goto-char (match-end 5))
  10294. (forward-word 1)
  10295. (vhdl-forward-syntactic-ws)
  10296. (when (looking-at "(")
  10297. (forward-sexp))
  10298. (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
  10299. (match-string 1)))
  10300. ;; not consider configuration specifications
  10301. (and (match-string 6)
  10302. (save-match-data
  10303. (save-excursion
  10304. (vhdl-end-of-block)
  10305. (beginning-of-line)
  10306. (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
  10307. (match-string 2))
  10308. ;; skip subblock if block end found
  10309. (vhdl-beginning-of-block))))
  10310. (when pos (goto-char pos))))
  10311. (defun vhdl-end-of-block ()
  10312. "Move cursor to the end of the enclosing block."
  10313. (let (pos)
  10314. (vhdl-prepare-search-2
  10315. (save-excursion
  10316. (end-of-line)
  10317. ;; search forward for block beginning or end
  10318. (while (or (while (and (setq pos (re-search-forward "^\\s-*\\(\\(end\\)\\|\\(\\(impure\\|pure\\)[ \t\n\r\f]+\\)?\\(function\\|procedure\\)\\|\\(for\\)\\|\\(architecture\\|component\\|configuration\\|context\\|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))
  10319. ;; not consider subprogram declarations
  10320. (or (and (match-string 5)
  10321. (save-match-data
  10322. (save-excursion (re-search-forward "\\<is\\>\\|\\(;\\)" nil t))
  10323. (match-string 1)))
  10324. ;; not consider configuration specifications
  10325. (and (match-string 6)
  10326. (save-match-data
  10327. (save-excursion
  10328. (vhdl-end-of-block)
  10329. (beginning-of-line)
  10330. (not (looking-at "^\\s-*end\\s-+\\(for\\|generate\\|loop\\)\\>"))))))))
  10331. (not (match-string 2)))
  10332. ;; skip subblock if block beginning found
  10333. (vhdl-end-of-block))))
  10334. (when pos (goto-char pos))))
  10335. (defun vhdl-sequential-statement-p ()
  10336. "Check if point is within sequential statement part."
  10337. (let ((start (point)))
  10338. (save-excursion
  10339. (vhdl-prepare-search-2
  10340. ;; is sequential statement if ...
  10341. (and (re-search-backward "^\\s-*begin\\>" nil t)
  10342. ;; ... point is between "begin" and "end" of ...
  10343. (progn (vhdl-end-of-block)
  10344. (< start (point)))
  10345. ;; ... a sequential block
  10346. (progn (vhdl-beginning-of-block)
  10347. (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\\)\\)\\>")))))))
  10348. (defun vhdl-in-argument-list-p ()
  10349. "Check if within an argument list."
  10350. (save-excursion
  10351. (vhdl-prepare-search-2
  10352. (or (string-match "arglist"
  10353. (format "%s" (caar (vhdl-get-syntactic-context))))
  10354. (progn (beginning-of-line)
  10355. (looking-at "^\\s-*\\(generic\\|port\\|\\(\\(impure\\|pure\\)\\s-+\\|\\)function\\|procedure\\)\\>\\s-*\\(\\w+\\s-*\\)?("))))))
  10356. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10357. ;; Abbrev hooks
  10358. (defun vhdl-hooked-abbrev (func)
  10359. "Do function, if syntax says abbrev is a keyword, invoked by hooked abbrev,
  10360. but not if inside a comment or quote."
  10361. (if (or (vhdl-in-literal)
  10362. (save-excursion
  10363. (forward-word -1)
  10364. (and (looking-at "\\<end\\>") (not (looking-at "\\<end;")))))
  10365. (progn
  10366. (insert " ")
  10367. (unexpand-abbrev)
  10368. (backward-word 1)
  10369. (vhdl-case-word 1)
  10370. (delete-char 1))
  10371. (if (not vhdl-electric-mode)
  10372. (progn
  10373. (insert " ")
  10374. (unexpand-abbrev)
  10375. (backward-word 1)
  10376. (vhdl-case-word 1)
  10377. (delete-char 1))
  10378. (let ((invoke-char vhdl-last-input-event)
  10379. (abbrev-mode -1)
  10380. (vhdl-template-invoked-by-hook t))
  10381. (let ((caught (catch 'abort
  10382. (funcall func))))
  10383. (when (stringp caught) (message "%s" caught)))
  10384. (when (= invoke-char ?-) (setq abbrev-start-location (point)))
  10385. ;; delete CR which is still in event queue
  10386. (if (fboundp 'enqueue-eval-event)
  10387. (enqueue-eval-event 'delete-char -1)
  10388. (push (vhdl-character-to-event ?\177) ; push back a delete char
  10389. unread-command-events))))))
  10390. (defun vhdl-template-alias-hook ()
  10391. (vhdl-hooked-abbrev 'vhdl-template-alias))
  10392. (defun vhdl-template-architecture-hook ()
  10393. (vhdl-hooked-abbrev 'vhdl-template-architecture))
  10394. (defun vhdl-template-assert-hook ()
  10395. (vhdl-hooked-abbrev 'vhdl-template-assert))
  10396. (defun vhdl-template-attribute-hook ()
  10397. (vhdl-hooked-abbrev 'vhdl-template-attribute))
  10398. (defun vhdl-template-block-hook ()
  10399. (vhdl-hooked-abbrev 'vhdl-template-block))
  10400. (defun vhdl-template-break-hook ()
  10401. (vhdl-hooked-abbrev 'vhdl-template-break))
  10402. (defun vhdl-template-case-hook ()
  10403. (vhdl-hooked-abbrev 'vhdl-template-case))
  10404. (defun vhdl-template-component-hook ()
  10405. (vhdl-hooked-abbrev 'vhdl-template-component))
  10406. (defun vhdl-template-instance-hook ()
  10407. (vhdl-hooked-abbrev 'vhdl-template-instance))
  10408. (defun vhdl-template-conditional-signal-asst-hook ()
  10409. (vhdl-hooked-abbrev 'vhdl-template-conditional-signal-asst))
  10410. (defun vhdl-template-configuration-hook ()
  10411. (vhdl-hooked-abbrev 'vhdl-template-configuration))
  10412. (defun vhdl-template-constant-hook ()
  10413. (vhdl-hooked-abbrev 'vhdl-template-constant))
  10414. (defun vhdl-template-context-hook ()
  10415. (vhdl-hooked-abbrev 'vhdl-template-context))
  10416. (defun vhdl-template-disconnect-hook ()
  10417. (vhdl-hooked-abbrev 'vhdl-template-disconnect))
  10418. (defun vhdl-template-display-comment-hook ()
  10419. (vhdl-hooked-abbrev 'vhdl-comment-display))
  10420. (defun vhdl-template-else-hook ()
  10421. (vhdl-hooked-abbrev 'vhdl-template-else))
  10422. (defun vhdl-template-elsif-hook ()
  10423. (vhdl-hooked-abbrev 'vhdl-template-elsif))
  10424. (defun vhdl-template-entity-hook ()
  10425. (vhdl-hooked-abbrev 'vhdl-template-entity))
  10426. (defun vhdl-template-exit-hook ()
  10427. (vhdl-hooked-abbrev 'vhdl-template-exit))
  10428. (defun vhdl-template-file-hook ()
  10429. (vhdl-hooked-abbrev 'vhdl-template-file))
  10430. (defun vhdl-template-for-hook ()
  10431. (vhdl-hooked-abbrev 'vhdl-template-for))
  10432. (defun vhdl-template-function-hook ()
  10433. (vhdl-hooked-abbrev 'vhdl-template-function))
  10434. (defun vhdl-template-generic-hook ()
  10435. (vhdl-hooked-abbrev 'vhdl-template-generic))
  10436. (defun vhdl-template-group-hook ()
  10437. (vhdl-hooked-abbrev 'vhdl-template-group))
  10438. (defun vhdl-template-library-hook ()
  10439. (vhdl-hooked-abbrev 'vhdl-template-library))
  10440. (defun vhdl-template-limit-hook ()
  10441. (vhdl-hooked-abbrev 'vhdl-template-limit))
  10442. (defun vhdl-template-if-hook ()
  10443. (vhdl-hooked-abbrev 'vhdl-template-if))
  10444. (defun vhdl-template-bare-loop-hook ()
  10445. (vhdl-hooked-abbrev 'vhdl-template-bare-loop))
  10446. (defun vhdl-template-map-hook ()
  10447. (vhdl-hooked-abbrev 'vhdl-template-map))
  10448. (defun vhdl-template-nature-hook ()
  10449. (vhdl-hooked-abbrev 'vhdl-template-nature))
  10450. (defun vhdl-template-next-hook ()
  10451. (vhdl-hooked-abbrev 'vhdl-template-next))
  10452. (defun vhdl-template-others-hook ()
  10453. (vhdl-hooked-abbrev 'vhdl-template-others))
  10454. (defun vhdl-template-package-hook ()
  10455. (vhdl-hooked-abbrev 'vhdl-template-package))
  10456. (defun vhdl-template-port-hook ()
  10457. (vhdl-hooked-abbrev 'vhdl-template-port))
  10458. (defun vhdl-template-procedural-hook ()
  10459. (vhdl-hooked-abbrev 'vhdl-template-procedural))
  10460. (defun vhdl-template-procedure-hook ()
  10461. (vhdl-hooked-abbrev 'vhdl-template-procedure))
  10462. (defun vhdl-template-process-hook ()
  10463. (vhdl-hooked-abbrev 'vhdl-template-process))
  10464. (defun vhdl-template-quantity-hook ()
  10465. (vhdl-hooked-abbrev 'vhdl-template-quantity))
  10466. (defun vhdl-template-report-hook ()
  10467. (vhdl-hooked-abbrev 'vhdl-template-report))
  10468. (defun vhdl-template-return-hook ()
  10469. (vhdl-hooked-abbrev 'vhdl-template-return))
  10470. (defun vhdl-template-selected-signal-asst-hook ()
  10471. (vhdl-hooked-abbrev 'vhdl-template-selected-signal-asst))
  10472. (defun vhdl-template-signal-hook ()
  10473. (vhdl-hooked-abbrev 'vhdl-template-signal))
  10474. (defun vhdl-template-subnature-hook ()
  10475. (vhdl-hooked-abbrev 'vhdl-template-subnature))
  10476. (defun vhdl-template-subtype-hook ()
  10477. (vhdl-hooked-abbrev 'vhdl-template-subtype))
  10478. (defun vhdl-template-terminal-hook ()
  10479. (vhdl-hooked-abbrev 'vhdl-template-terminal))
  10480. (defun vhdl-template-type-hook ()
  10481. (vhdl-hooked-abbrev 'vhdl-template-type))
  10482. (defun vhdl-template-use-hook ()
  10483. (vhdl-hooked-abbrev 'vhdl-template-use))
  10484. (defun vhdl-template-variable-hook ()
  10485. (vhdl-hooked-abbrev 'vhdl-template-variable))
  10486. (defun vhdl-template-wait-hook ()
  10487. (vhdl-hooked-abbrev 'vhdl-template-wait))
  10488. (defun vhdl-template-when-hook ()
  10489. (vhdl-hooked-abbrev 'vhdl-template-when))
  10490. (defun vhdl-template-while-loop-hook ()
  10491. (vhdl-hooked-abbrev 'vhdl-template-while-loop))
  10492. (defun vhdl-template-with-hook ()
  10493. (vhdl-hooked-abbrev 'vhdl-template-with))
  10494. (defun vhdl-template-and-hook ()
  10495. (vhdl-hooked-abbrev 'vhdl-template-and))
  10496. (defun vhdl-template-or-hook ()
  10497. (vhdl-hooked-abbrev 'vhdl-template-or))
  10498. (defun vhdl-template-nand-hook ()
  10499. (vhdl-hooked-abbrev 'vhdl-template-nand))
  10500. (defun vhdl-template-nor-hook ()
  10501. (vhdl-hooked-abbrev 'vhdl-template-nor))
  10502. (defun vhdl-template-xor-hook ()
  10503. (vhdl-hooked-abbrev 'vhdl-template-xor))
  10504. (defun vhdl-template-xnor-hook ()
  10505. (vhdl-hooked-abbrev 'vhdl-template-xnor))
  10506. (defun vhdl-template-not-hook ()
  10507. (vhdl-hooked-abbrev 'vhdl-template-not))
  10508. (defun vhdl-template-default-hook ()
  10509. (vhdl-hooked-abbrev 'vhdl-template-default))
  10510. (defun vhdl-template-default-indent-hook ()
  10511. (vhdl-hooked-abbrev 'vhdl-template-default-indent))
  10512. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10513. ;; Template insertion from completion list
  10514. (defun vhdl-template-insert-construct (name)
  10515. "Insert the built-in construct template with NAME."
  10516. (interactive
  10517. (list (let ((completion-ignore-case t))
  10518. (completing-read "Construct name: "
  10519. vhdl-template-construct-alist nil t))))
  10520. (vhdl-template-insert-fun
  10521. (cadr (assoc name vhdl-template-construct-alist))))
  10522. (defun vhdl-template-insert-package (name)
  10523. "Insert the built-in package template with NAME."
  10524. (interactive
  10525. (list (let ((completion-ignore-case t))
  10526. (completing-read "Package name: "
  10527. vhdl-template-package-alist nil t))))
  10528. (vhdl-template-insert-fun
  10529. (cadr (assoc name vhdl-template-package-alist))))
  10530. (defun vhdl-template-insert-directive (name)
  10531. "Insert the built-in directive template with NAME."
  10532. (interactive
  10533. (list (let ((completion-ignore-case t))
  10534. (completing-read "Directive name: "
  10535. vhdl-template-directive-alist nil t))))
  10536. (vhdl-template-insert-fun
  10537. (cadr (assoc name vhdl-template-directive-alist))))
  10538. (defun vhdl-template-insert-fun (fun)
  10539. "Call FUN to insert a built-in template."
  10540. (let ((caught (catch 'abort (when fun (funcall fun)))))
  10541. (when (stringp caught) (message "%s" caught))))
  10542. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10543. ;;; Models
  10544. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10545. (defun vhdl-model-insert (model-name)
  10546. "Insert the user model with name MODEL-NAME."
  10547. (interactive
  10548. (let ((completion-ignore-case t))
  10549. (list (completing-read "Model name: " vhdl-model-alist))))
  10550. (indent-according-to-mode)
  10551. (let ((start (point-marker))
  10552. (margin (current-indentation))
  10553. model position prompt string end)
  10554. (vhdl-prepare-search-2
  10555. (when (setq model (assoc model-name vhdl-model-alist))
  10556. ;; insert model
  10557. (beginning-of-line)
  10558. (delete-horizontal-space)
  10559. (goto-char start)
  10560. (vhdl-insert-string-or-file (nth 1 model))
  10561. (setq end (point-marker))
  10562. ;; indent code
  10563. (goto-char start)
  10564. (beginning-of-line)
  10565. (while (< (point) end)
  10566. (unless (looking-at "^$")
  10567. (insert-char ? margin))
  10568. (beginning-of-line 2))
  10569. (goto-char start)
  10570. ;; insert clock
  10571. (unless (equal "" vhdl-clock-name)
  10572. (while (re-search-forward "<clock>" end t)
  10573. (replace-match vhdl-clock-name)))
  10574. (goto-char start)
  10575. ;; insert reset
  10576. (unless (equal "" vhdl-reset-name)
  10577. (while (re-search-forward "<reset>" end t)
  10578. (replace-match vhdl-reset-name)))
  10579. ;; replace header prompts
  10580. (vhdl-template-replace-header-keywords start end nil t)
  10581. (goto-char start)
  10582. ;; query other prompts
  10583. (while (re-search-forward
  10584. (concat "<\\(" vhdl-template-prompt-syntax "\\)>") end t)
  10585. (unless (equal "cursor" (match-string 1))
  10586. (setq position (match-beginning 1))
  10587. (setq prompt (match-string 1))
  10588. (replace-match "")
  10589. (setq string (vhdl-template-field prompt nil t))
  10590. ;; replace occurrences of same prompt
  10591. (while (re-search-forward (concat "<\\(" prompt "\\)>") end t)
  10592. (replace-match (or string "")))
  10593. (goto-char position)))
  10594. (goto-char start)
  10595. ;; goto final position
  10596. (if (re-search-forward "<cursor>" end t)
  10597. (replace-match "")
  10598. (goto-char end))))))
  10599. (defun vhdl-model-defun ()
  10600. "Define help and hook functions for user models."
  10601. (let ((model-alist vhdl-model-alist)
  10602. model-name model-keyword)
  10603. (while model-alist
  10604. ;; define functions for user models that can be invoked from menu and key
  10605. ;; bindings and which themselves call `vhdl-model-insert' with the model
  10606. ;; name as argument
  10607. (setq model-name (nth 0 (car model-alist)))
  10608. (eval `(defun ,(vhdl-function-name "vhdl-model" model-name) ()
  10609. ,(concat "Insert model for \"" model-name "\".")
  10610. (interactive)
  10611. (vhdl-model-insert ,model-name)))
  10612. ;; define hooks for user models that are invoked from keyword abbrevs
  10613. (setq model-keyword (nth 3 (car model-alist)))
  10614. (unless (equal model-keyword "")
  10615. (eval `(defun
  10616. ,(vhdl-function-name
  10617. "vhdl-model" model-name "hook") ()
  10618. (vhdl-hooked-abbrev
  10619. ',(vhdl-function-name "vhdl-model" model-name)))))
  10620. (setq model-alist (cdr model-alist)))))
  10621. (vhdl-model-defun)
  10622. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10623. ;;; Port translation
  10624. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10625. (defvar vhdl-port-list nil
  10626. "Variable to hold last port map parsed.")
  10627. ;; structure: (parenthesized expression means list of such entries)
  10628. ;; (ent-name
  10629. ;; ((generic-names) generic-type generic-init generic-comment group-comment)
  10630. ;; ((port-names) port-object port-direct port-type port-comment group-comment)
  10631. ;; (lib-name pack-key))
  10632. (defun vhdl-parse-string (string &optional optional)
  10633. "Check that the text following point matches the regexp in STRING."
  10634. (if (looking-at string)
  10635. (progn (goto-char (match-end 0))
  10636. (when (vhdl-in-literal)
  10637. (end-of-line))
  10638. (point))
  10639. (unless optional
  10640. (throw 'parse (format "ERROR: Syntax error near line %s, expecting \"%s\""
  10641. (vhdl-current-line) string)))
  10642. nil))
  10643. (defun vhdl-replace-string (regexp-cons string &optional adjust-case)
  10644. "Replace STRING from car of REGEXP-CONS to cdr of REGEXP-CONS."
  10645. (vhdl-prepare-search-1
  10646. (if (string-match (car regexp-cons) string)
  10647. (if adjust-case
  10648. (funcall vhdl-file-name-case
  10649. (replace-match (cdr regexp-cons) t nil string))
  10650. (replace-match (cdr regexp-cons) t nil string))
  10651. string)))
  10652. (defun vhdl-parse-group-comment ()
  10653. "Parse comment and empty lines between groups of lines."
  10654. (let ((start (point))
  10655. string)
  10656. (vhdl-forward-comment (point-max))
  10657. (setq string (buffer-substring-no-properties start (point)))
  10658. (vhdl-forward-syntactic-ws)
  10659. ;; strip off leading blanks and first newline
  10660. (while (string-match "^\\(\\s-+\\)" string)
  10661. (setq string (concat (substring string 0 (match-beginning 1))
  10662. (substring string (match-end 1)))))
  10663. (if (and (not (equal string "")) (equal (substring string 0 1) "\n"))
  10664. (substring string 1)
  10665. string)))
  10666. (defun vhdl-paste-group-comment (string indent)
  10667. "Paste comment and empty lines from STRING between groups of lines
  10668. with INDENT."
  10669. (let ((pos (point-marker)))
  10670. (when (> indent 0)
  10671. (while (string-match "^\\(--\\)" string)
  10672. (setq string (concat (substring string 0 (match-beginning 1))
  10673. (make-string indent ? )
  10674. (substring string (match-beginning 1))))))
  10675. (beginning-of-line)
  10676. (insert string)
  10677. (goto-char pos)))
  10678. (defvar vhdl-port-flattened nil
  10679. "Indicates whether a port has been flattened.")
  10680. (defun vhdl-port-flatten (&optional as-alist)
  10681. "Flatten port list so that only one generic/port exists per line.
  10682. This operation is performed on an internally stored port and is only
  10683. reflected in a subsequent paste operation."
  10684. (interactive)
  10685. (if (not vhdl-port-list)
  10686. (error "ERROR: No port has been read")
  10687. (message "Flattening port for next paste...")
  10688. (let ((new-vhdl-port-list (list (car vhdl-port-list)))
  10689. (old-vhdl-port-list (cdr vhdl-port-list))
  10690. old-port-list new-port-list old-port new-port names)
  10691. ;; traverse port list and flatten entries
  10692. (while (cdr old-vhdl-port-list)
  10693. (setq old-port-list (car old-vhdl-port-list))
  10694. (setq new-port-list nil)
  10695. (while old-port-list
  10696. (setq old-port (car old-port-list))
  10697. (setq names (car old-port))
  10698. (while names
  10699. (setq new-port (cons (if as-alist (car names) (list (car names)))
  10700. (cdr old-port)))
  10701. (setq new-port-list (append new-port-list (list new-port)))
  10702. (setq names (cdr names)))
  10703. (setq old-port-list (cdr old-port-list)))
  10704. (setq old-vhdl-port-list (cdr old-vhdl-port-list))
  10705. (setq new-vhdl-port-list (append new-vhdl-port-list
  10706. (list new-port-list))))
  10707. (setq vhdl-port-list
  10708. (append new-vhdl-port-list (list old-vhdl-port-list))
  10709. vhdl-port-flattened t)
  10710. (message "Flattening port for next paste...done"))))
  10711. (defvar vhdl-port-reversed-direction nil
  10712. "Indicates whether port directions are reversed.")
  10713. (defun vhdl-port-reverse-direction ()
  10714. "Reverse direction for all ports (useful in testbenches).
  10715. This operation is performed on an internally stored port and is only
  10716. reflected in a subsequent paste operation."
  10717. (interactive)
  10718. (if (not vhdl-port-list)
  10719. (error "ERROR: No port has been read")
  10720. (message "Reversing port directions for next paste...")
  10721. (let ((port-list (nth 2 vhdl-port-list))
  10722. port-dir-car port-dir)
  10723. ;; traverse port list and reverse directions
  10724. (while port-list
  10725. (setq port-dir-car (cddr (car port-list))
  10726. port-dir (car port-dir-car))
  10727. (setcar port-dir-car
  10728. (cond ((equal port-dir "in") "out")
  10729. ((equal port-dir "IN") "OUT")
  10730. ((equal port-dir "out") "in")
  10731. ((equal port-dir "OUT") "IN")
  10732. (t port-dir)))
  10733. (setq port-list (cdr port-list)))
  10734. (setq vhdl-port-reversed-direction (not vhdl-port-reversed-direction))
  10735. (message "Reversing port directions for next paste...done"))))
  10736. (defun vhdl-port-copy ()
  10737. "Get generic and port information from an entity or component declaration."
  10738. (interactive)
  10739. (save-excursion
  10740. (let (parse-error end-of-list
  10741. decl-type name generic-list port-list context-clause
  10742. object names direct type init comment group-comment)
  10743. (vhdl-prepare-search-2
  10744. (setq
  10745. parse-error
  10746. (catch 'parse
  10747. ;; check if within entity or component declaration
  10748. (end-of-line)
  10749. (when (or (not (re-search-backward
  10750. "^\\s-*\\(component\\|entity\\|end\\)\\>" nil t))
  10751. (equal "END" (upcase (match-string 1))))
  10752. (throw 'parse "ERROR: Not within an entity or component declaration"))
  10753. (setq decl-type (downcase (match-string-no-properties 1)))
  10754. (forward-word 1)
  10755. (vhdl-parse-string "\\s-+\\(\\w+\\)\\(\\s-+is\\>\\)?")
  10756. (setq name (match-string-no-properties 1))
  10757. (message "Reading port of %s \"%s\"..." decl-type name)
  10758. (vhdl-forward-syntactic-ws)
  10759. ;; parse generic clause
  10760. (when (vhdl-parse-string "generic[ \t\n\r\f]*(" t)
  10761. ;; parse group comment and spacing
  10762. (setq group-comment (vhdl-parse-group-comment))
  10763. (setq end-of-list (vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t))
  10764. (while (not end-of-list)
  10765. ;; parse names (accept extended identifiers)
  10766. (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
  10767. (setq names (list (match-string-no-properties 1)))
  10768. (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
  10769. (setq names
  10770. (append names (list (match-string-no-properties 1)))))
  10771. ;; parse type
  10772. (vhdl-parse-string ":[ \t\n\r\f]*\\([^():;\n]+\\)")
  10773. (setq type (match-string-no-properties 1))
  10774. (when (vhdl-in-comment-p) ; if stuck in comment
  10775. (setq type (concat type (and (vhdl-parse-string ".*")
  10776. (match-string-no-properties 0)))))
  10777. (setq comment nil)
  10778. (while (looking-at "(")
  10779. (setq type
  10780. (concat type
  10781. (buffer-substring-no-properties
  10782. (point) (progn (forward-sexp) (point)))
  10783. (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
  10784. (match-string-no-properties 1)))))
  10785. ;; special case: closing parenthesis is on separate line
  10786. (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
  10787. (setq comment (substring type (match-beginning 2)))
  10788. (setq type (substring type 0 (match-beginning 1))))
  10789. ;; strip of trailing group-comment
  10790. (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
  10791. (setq type (substring type 0 (match-end 1)))
  10792. ;; parse initialization expression
  10793. (setq init nil)
  10794. (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
  10795. (vhdl-parse-string "\\([^();\n]*\\)")
  10796. (setq init (match-string-no-properties 1))
  10797. (while (looking-at "(")
  10798. (setq init
  10799. (concat init
  10800. (buffer-substring-no-properties
  10801. (point) (progn (forward-sexp) (point)))
  10802. (and (vhdl-parse-string "\\([^();\n]*\\)" t)
  10803. (match-string-no-properties 1))))))
  10804. ;; special case: closing parenthesis is on separate line
  10805. (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
  10806. (setq comment (substring init (match-beginning 2)))
  10807. (setq init (substring init 0 (match-beginning 1)))
  10808. (vhdl-forward-syntactic-ws))
  10809. (skip-chars-forward " \t")
  10810. ;; parse inline comment, special case: as above, no initial.
  10811. (unless comment
  10812. (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
  10813. (match-string-no-properties 1))))
  10814. (vhdl-forward-syntactic-ws)
  10815. (setq end-of-list (vhdl-parse-string ")" t))
  10816. (vhdl-parse-string "\\s-*;\\s-*")
  10817. ;; parse inline comment
  10818. (unless comment
  10819. (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
  10820. (match-string-no-properties 1))))
  10821. ;; save everything in list
  10822. (setq generic-list (append generic-list
  10823. (list (list names type init
  10824. comment group-comment))))
  10825. ;; parse group comment and spacing
  10826. (setq group-comment (vhdl-parse-group-comment))))
  10827. ;; parse port clause
  10828. (when (vhdl-parse-string "port[ \t\n\r\f]*(" t)
  10829. ;; parse group comment and spacing
  10830. (setq group-comment (vhdl-parse-group-comment))
  10831. (setq end-of-list (vhdl-parse-string ")[ \t\n\r\f]*;[ \t\n\r\f]*" t))
  10832. (while (not end-of-list)
  10833. ;; parse object
  10834. (setq object
  10835. (and (vhdl-parse-string "\\<\\(signal\\|quantity\\|terminal\\)\\>[ \t\n\r\f]*" t)
  10836. (match-string-no-properties 1)))
  10837. ;; parse names (accept extended identifiers)
  10838. (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
  10839. (setq names (list (match-string-no-properties 1)))
  10840. (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
  10841. (setq names (append names (list (match-string-no-properties 1)))))
  10842. ;; parse direction
  10843. (vhdl-parse-string ":[ \t\n\r\f]*")
  10844. (setq direct
  10845. (and (vhdl-parse-string "\\<\\(in\\|out\\|inout\\|buffer\\|linkage\\)\\>[ \t\n\r\f]+" t)
  10846. (match-string-no-properties 1)))
  10847. ;; parse type
  10848. (vhdl-parse-string "\\([^();\n]+\\)")
  10849. (setq type (match-string-no-properties 1))
  10850. (when (vhdl-in-comment-p) ; if stuck in comment
  10851. (setq type (concat type (and (vhdl-parse-string ".*")
  10852. (match-string-no-properties 0)))))
  10853. (setq comment nil)
  10854. (while (looking-at "(")
  10855. (setq type (concat type
  10856. (buffer-substring-no-properties
  10857. (point) (progn (forward-sexp) (point)))
  10858. (and (vhdl-parse-string "\\([^();\n]*\\)" t)
  10859. (match-string-no-properties 1)))))
  10860. ;; special case: closing parenthesis is on separate line
  10861. (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
  10862. (setq comment (substring type (match-beginning 2)))
  10863. (setq type (substring type 0 (match-beginning 1))))
  10864. ;; strip of trailing group-comment
  10865. (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
  10866. (setq type (substring type 0 (match-end 1)))
  10867. (vhdl-forward-syntactic-ws)
  10868. (setq end-of-list (vhdl-parse-string ")" t))
  10869. (vhdl-parse-string "\\s-*;\\s-*")
  10870. ;; parse inline comment
  10871. (unless comment
  10872. (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
  10873. (match-string-no-properties 1))))
  10874. ;; save everything in list
  10875. (setq port-list (append port-list
  10876. (list (list names object direct type
  10877. comment group-comment))))
  10878. ;; parse group comment and spacing
  10879. (setq group-comment (vhdl-parse-group-comment))))
  10880. ;; parse context clause
  10881. (setq context-clause (vhdl-scan-context-clause))
  10882. ; ;; add surrounding package to context clause
  10883. ; (when (and (equal decl-type "component")
  10884. ; (re-search-backward "^\\s-*package\\s-+\\(\\w+\\)" nil t))
  10885. ; (setq context-clause
  10886. ; (append context-clause
  10887. ; (list (cons (vhdl-work-library)
  10888. ; (match-string-no-properties 1))))))
  10889. (message "Reading port of %s \"%s\"...done" decl-type name)
  10890. nil)))
  10891. ;; finish parsing
  10892. (if parse-error
  10893. (error parse-error)
  10894. (setq vhdl-port-list (list name generic-list port-list context-clause)
  10895. vhdl-port-reversed-direction nil
  10896. vhdl-port-flattened nil)))))
  10897. (defun vhdl-port-paste-context-clause (&optional exclude-pack-name)
  10898. "Paste a context clause."
  10899. (let ((margin (current-indentation))
  10900. (clause-list (nth 3 vhdl-port-list))
  10901. clause)
  10902. (while clause-list
  10903. (setq clause (car clause-list))
  10904. (unless (or (and exclude-pack-name (equal (downcase (cdr clause))
  10905. (downcase exclude-pack-name)))
  10906. (save-excursion
  10907. (re-search-backward
  10908. (concat "^\\s-*use\\s-+" (car clause)
  10909. "." (cdr clause) "\\>") nil t)))
  10910. (vhdl-template-standard-package (car clause) (cdr clause))
  10911. (insert "\n"))
  10912. (setq clause-list (cdr clause-list)))))
  10913. (defun vhdl-port-paste-generic (&optional no-init)
  10914. "Paste a generic clause."
  10915. (let ((margin (current-indentation))
  10916. (generic-list (nth 1 vhdl-port-list))
  10917. list-margin start names generic)
  10918. ;; paste generic clause
  10919. (when generic-list
  10920. (setq start (point))
  10921. (vhdl-insert-keyword "GENERIC (")
  10922. (unless vhdl-argument-list-indent
  10923. (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
  10924. (setq list-margin (current-column))
  10925. (while generic-list
  10926. (setq generic (car generic-list))
  10927. ;; paste group comment and spacing
  10928. (when (memq vhdl-include-group-comments '(decl always))
  10929. (vhdl-paste-group-comment (nth 4 generic) list-margin))
  10930. ;; paste names
  10931. (setq names (nth 0 generic))
  10932. (while names
  10933. (insert (car names))
  10934. (setq names (cdr names))
  10935. (when names (insert ", ")))
  10936. ;; paste type
  10937. (insert " : " (nth 1 generic))
  10938. ;; paste initialization
  10939. (when (and (not no-init) (nth 2 generic))
  10940. (insert " := " (nth 2 generic)))
  10941. (unless (cdr generic-list) (insert ")"))
  10942. (insert ";")
  10943. ;; paste comment
  10944. (when (and vhdl-include-port-comments (nth 3 generic))
  10945. (vhdl-comment-insert-inline (nth 3 generic) t))
  10946. (setq generic-list (cdr generic-list))
  10947. (when generic-list (insert "\n") (indent-to list-margin)))
  10948. ;; align generic clause
  10949. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))))
  10950. (defun vhdl-port-paste-port ()
  10951. "Paste a port clause."
  10952. (let ((margin (current-indentation))
  10953. (port-list (nth 2 vhdl-port-list))
  10954. list-margin start names port)
  10955. ;; paste port clause
  10956. (when port-list
  10957. (setq start (point))
  10958. (vhdl-insert-keyword "PORT (")
  10959. (unless vhdl-argument-list-indent
  10960. (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
  10961. (setq list-margin (current-column))
  10962. (while port-list
  10963. (setq port (car port-list))
  10964. ;; paste group comment and spacing
  10965. (when (memq vhdl-include-group-comments '(decl always))
  10966. (vhdl-paste-group-comment (nth 5 port) list-margin))
  10967. ;; paste object
  10968. (when (nth 1 port) (insert (nth 1 port) " "))
  10969. ;; paste names
  10970. (setq names (nth 0 port))
  10971. (while names
  10972. (insert (car names))
  10973. (setq names (cdr names))
  10974. (when names (insert ", ")))
  10975. ;; paste direction
  10976. (insert " : ")
  10977. (when (nth 2 port) (insert (nth 2 port) " "))
  10978. ;; paste type
  10979. (insert (nth 3 port))
  10980. (unless (cdr port-list) (insert ")"))
  10981. (insert ";")
  10982. ;; paste comment
  10983. (when (and vhdl-include-port-comments (nth 4 port))
  10984. (vhdl-comment-insert-inline (nth 4 port) t))
  10985. (setq port-list (cdr port-list))
  10986. (when port-list (insert "\n") (indent-to list-margin)))
  10987. ;; align port clause
  10988. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1)))))
  10989. (defun vhdl-port-paste-declaration (kind &optional no-indent)
  10990. "Paste as an entity or component declaration."
  10991. (unless no-indent (indent-according-to-mode))
  10992. (let ((margin (current-indentation))
  10993. (name (nth 0 vhdl-port-list)))
  10994. (vhdl-insert-keyword (if (eq kind 'entity) "ENTITY " "COMPONENT "))
  10995. (insert name)
  10996. (when (or (eq kind 'entity) (not (vhdl-standard-p '87)))
  10997. (vhdl-insert-keyword " IS"))
  10998. ;; paste generic and port clause
  10999. (when (nth 1 vhdl-port-list)
  11000. (insert "\n")
  11001. (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
  11002. (insert "\n"))
  11003. (indent-to (+ margin vhdl-basic-offset))
  11004. (vhdl-port-paste-generic (eq kind 'component)))
  11005. (when (nth 2 vhdl-port-list)
  11006. (insert "\n")
  11007. (when (and (memq vhdl-insert-empty-lines '(unit all))
  11008. (eq kind 'entity))
  11009. (insert "\n"))
  11010. (indent-to (+ margin vhdl-basic-offset)))
  11011. (vhdl-port-paste-port)
  11012. (insert "\n")
  11013. (when (and (memq vhdl-insert-empty-lines '(unit all)) (eq kind 'entity))
  11014. (insert "\n"))
  11015. (indent-to margin)
  11016. (vhdl-insert-keyword "END")
  11017. (if (eq kind 'entity)
  11018. (progn
  11019. (unless (vhdl-standard-p '87) (vhdl-insert-keyword " ENTITY"))
  11020. (insert " " name))
  11021. (vhdl-insert-keyword " COMPONENT")
  11022. (unless (vhdl-standard-p '87) (insert " " name)))
  11023. (insert ";")))
  11024. (defun vhdl-port-paste-entity (&optional no-indent)
  11025. "Paste as an entity declaration."
  11026. (interactive)
  11027. (if (not vhdl-port-list)
  11028. (error "ERROR: No port read")
  11029. (message "Pasting port as entity \"%s\"..." (car vhdl-port-list))
  11030. (vhdl-port-paste-declaration 'entity no-indent)
  11031. (message "Pasting port as entity \"%s\"...done" (car vhdl-port-list))))
  11032. (defun vhdl-port-paste-component (&optional no-indent)
  11033. "Paste as a component declaration."
  11034. (interactive)
  11035. (if (not vhdl-port-list)
  11036. (error "ERROR: No port read")
  11037. (message "Pasting port as component \"%s\"..." (car vhdl-port-list))
  11038. (vhdl-port-paste-declaration 'component no-indent)
  11039. (message "Pasting port as component \"%s\"...done" (car vhdl-port-list))))
  11040. (defun vhdl-port-paste-generic-map (&optional secondary no-constants)
  11041. "Paste as a generic map."
  11042. (interactive)
  11043. (unless secondary (indent-according-to-mode))
  11044. (let ((margin (current-indentation))
  11045. list-margin start generic
  11046. (generic-list (nth 1 vhdl-port-list)))
  11047. (when generic-list
  11048. (setq start (point))
  11049. (vhdl-insert-keyword "GENERIC MAP (")
  11050. (if (not vhdl-association-list-with-formals)
  11051. ;; paste list of actual generics
  11052. (while generic-list
  11053. (insert (if no-constants
  11054. (car (nth 0 (car generic-list)))
  11055. (or (nth 2 (car generic-list)) " ")))
  11056. (setq generic-list (cdr generic-list))
  11057. (insert (if generic-list ", " ")"))
  11058. (when (and (not generic-list) secondary
  11059. (null (nth 2 vhdl-port-list)))
  11060. (insert ";")))
  11061. (unless vhdl-argument-list-indent
  11062. (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
  11063. (setq list-margin (current-column))
  11064. (while generic-list
  11065. (setq generic (car generic-list))
  11066. ;; paste group comment and spacing
  11067. (when (eq vhdl-include-group-comments 'always)
  11068. (vhdl-paste-group-comment (nth 4 generic) list-margin))
  11069. ;; paste formal and actual generic
  11070. (insert (car (nth 0 generic)) " => "
  11071. (if no-constants
  11072. (vhdl-replace-string vhdl-actual-generic-name
  11073. (car (nth 0 generic)))
  11074. (or (nth 2 generic) "")))
  11075. (setq generic-list (cdr generic-list))
  11076. (insert (if generic-list "," ")"))
  11077. (when (and (not generic-list) secondary
  11078. (null (nth 2 vhdl-port-list)))
  11079. (insert ";"))
  11080. ;; paste comment
  11081. (when (or vhdl-include-type-comments
  11082. (and vhdl-include-port-comments (nth 3 generic)))
  11083. (vhdl-comment-insert-inline
  11084. (concat
  11085. (when vhdl-include-type-comments
  11086. (concat "[" (nth 1 generic) "] "))
  11087. (when vhdl-include-port-comments (nth 3 generic))) t))
  11088. (when generic-list (insert "\n") (indent-to list-margin)))
  11089. ;; align generic map
  11090. (when vhdl-auto-align
  11091. (vhdl-align-region-groups start (point) 1 t))))))
  11092. (defun vhdl-port-paste-port-map ()
  11093. "Paste as a port map."
  11094. (let ((margin (current-indentation))
  11095. list-margin start port
  11096. (port-list (nth 2 vhdl-port-list)))
  11097. (when port-list
  11098. (setq start (point))
  11099. (vhdl-insert-keyword "PORT MAP (")
  11100. (if (not vhdl-association-list-with-formals)
  11101. ;; paste list of actual ports
  11102. (while port-list
  11103. (insert (vhdl-replace-string vhdl-actual-port-name
  11104. (car (nth 0 (car port-list)))))
  11105. (setq port-list (cdr port-list))
  11106. (insert (if port-list ", " ")")))
  11107. (unless vhdl-argument-list-indent
  11108. (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
  11109. (setq list-margin (current-column))
  11110. (while port-list
  11111. (setq port (car port-list))
  11112. ;; paste group comment and spacing
  11113. (when (eq vhdl-include-group-comments 'always)
  11114. (vhdl-paste-group-comment (nth 5 port) list-margin))
  11115. ;; paste formal and actual port
  11116. (insert (car (nth 0 port)) " => ")
  11117. (insert (vhdl-replace-string vhdl-actual-port-name
  11118. (car (nth 0 port))))
  11119. (setq port-list (cdr port-list))
  11120. (insert (if port-list "," ");"))
  11121. ;; paste comment
  11122. (when (or (and vhdl-include-direction-comments (nth 2 port))
  11123. vhdl-include-type-comments
  11124. (and vhdl-include-port-comments (nth 4 port)))
  11125. (vhdl-comment-insert-inline
  11126. (concat
  11127. (cond ((and vhdl-include-direction-comments
  11128. vhdl-include-type-comments)
  11129. (concat "[" (format "%-4s" (concat (nth 2 port) " "))
  11130. (nth 3 port) "] "))
  11131. ((and vhdl-include-direction-comments (nth 2 port))
  11132. (format "%-6s" (concat "[" (nth 2 port) "] ")))
  11133. (vhdl-include-direction-comments " ")
  11134. (vhdl-include-type-comments
  11135. (concat "[" (nth 3 port) "] ")))
  11136. (when vhdl-include-port-comments (nth 4 port))) t))
  11137. (when port-list (insert "\n") (indent-to list-margin)))
  11138. ;; align port clause
  11139. (when vhdl-auto-align
  11140. (vhdl-align-region-groups start (point) 1))))))
  11141. (defun vhdl-port-paste-instance (&optional name no-indent title)
  11142. "Paste as an instantiation."
  11143. (interactive)
  11144. (if (not vhdl-port-list)
  11145. (error "ERROR: No port read")
  11146. (let ((orig-vhdl-port-list vhdl-port-list))
  11147. ;; flatten local copy of port list (must be flat for port mapping)
  11148. (vhdl-port-flatten)
  11149. (unless no-indent (indent-according-to-mode))
  11150. (let ((margin (current-indentation)))
  11151. ;; paste instantiation
  11152. (cond (name
  11153. (insert name))
  11154. ((equal (cdr vhdl-instance-name) "")
  11155. (setq name (vhdl-template-field "instance name")))
  11156. ((string-match "%d" (cdr vhdl-instance-name))
  11157. (let ((n 1))
  11158. (while (save-excursion
  11159. (setq name (format (vhdl-replace-string
  11160. vhdl-instance-name
  11161. (nth 0 vhdl-port-list)) n))
  11162. (goto-char (point-min))
  11163. (vhdl-re-search-forward name nil t))
  11164. (setq n (1+ n)))
  11165. (insert name)))
  11166. (t (insert (vhdl-replace-string vhdl-instance-name
  11167. (nth 0 vhdl-port-list)))))
  11168. (message "Pasting port as instantiation \"%s\"..." name)
  11169. (insert ": ")
  11170. (when title
  11171. (save-excursion
  11172. (beginning-of-line)
  11173. (indent-to vhdl-basic-offset)
  11174. (insert "-- instance \"" name "\"\n")))
  11175. (if (not (vhdl-use-direct-instantiation))
  11176. (insert (nth 0 vhdl-port-list))
  11177. (vhdl-insert-keyword "ENTITY ")
  11178. (insert (vhdl-work-library) "." (nth 0 vhdl-port-list)))
  11179. (when (nth 1 vhdl-port-list)
  11180. (insert "\n") (indent-to (+ margin vhdl-basic-offset))
  11181. (vhdl-port-paste-generic-map t t))
  11182. (when (nth 2 vhdl-port-list)
  11183. (insert "\n") (indent-to (+ margin vhdl-basic-offset))
  11184. (vhdl-port-paste-port-map))
  11185. (unless (or (nth 1 vhdl-port-list) (nth 2 vhdl-port-list))
  11186. (insert ";"))
  11187. (message "Pasting port as instantiation \"%s\"...done" name))
  11188. (setq vhdl-port-list orig-vhdl-port-list))))
  11189. (defun vhdl-port-paste-constants (&optional no-indent)
  11190. "Paste generics as constants."
  11191. (interactive)
  11192. (if (not vhdl-port-list)
  11193. (error "ERROR: No port read")
  11194. (let ((orig-vhdl-port-list vhdl-port-list))
  11195. (message "Pasting port as constants...")
  11196. ;; flatten local copy of port list (must be flat for constant initial.)
  11197. (vhdl-port-flatten)
  11198. (unless no-indent (indent-according-to-mode))
  11199. (let ((margin (current-indentation))
  11200. start generic name
  11201. (generic-list (nth 1 vhdl-port-list)))
  11202. (when generic-list
  11203. (setq start (point))
  11204. (while generic-list
  11205. (setq generic (car generic-list))
  11206. ;; paste group comment and spacing
  11207. (when (memq vhdl-include-group-comments '(decl always))
  11208. (vhdl-paste-group-comment (nth 4 generic) margin))
  11209. (vhdl-insert-keyword "CONSTANT ")
  11210. ;; paste generic constants
  11211. (setq name (nth 0 generic))
  11212. (when name
  11213. (insert (vhdl-replace-string vhdl-actual-generic-name (car name)))
  11214. ;; paste type
  11215. (insert " : " (nth 1 generic))
  11216. ;; paste initialization
  11217. (when (nth 2 generic)
  11218. (insert " := " (nth 2 generic)))
  11219. (insert ";")
  11220. ;; paste comment
  11221. (when (and vhdl-include-port-comments (nth 3 generic))
  11222. (vhdl-comment-insert-inline (nth 3 generic) t))
  11223. (setq generic-list (cdr generic-list))
  11224. (when generic-list (insert "\n") (indent-to margin))))
  11225. ;; align signal list
  11226. (when vhdl-auto-align
  11227. (vhdl-align-region-groups start (point) 1))))
  11228. (message "Pasting port as constants...done")
  11229. (setq vhdl-port-list orig-vhdl-port-list))))
  11230. (defun vhdl-port-paste-signals (&optional initialize no-indent)
  11231. "Paste ports as internal signals."
  11232. (interactive)
  11233. (if (not vhdl-port-list)
  11234. (error "ERROR: No port read")
  11235. (message "Pasting port as signals...")
  11236. (unless no-indent (indent-according-to-mode))
  11237. (let ((margin (current-indentation))
  11238. start port names type generic-list port-name constant-name pos
  11239. (port-list (nth 2 vhdl-port-list)))
  11240. (when port-list
  11241. (setq start (point))
  11242. (while port-list
  11243. (setq port (car port-list))
  11244. ;; paste group comment and spacing
  11245. (when (memq vhdl-include-group-comments '(decl always))
  11246. (vhdl-paste-group-comment (nth 5 port) margin))
  11247. ;; paste object
  11248. (if (nth 1 port)
  11249. (insert (nth 1 port) " ")
  11250. (vhdl-insert-keyword "SIGNAL "))
  11251. ;; paste actual port signals
  11252. (setq names (nth 0 port))
  11253. (while names
  11254. (insert (vhdl-replace-string vhdl-actual-port-name (car names)))
  11255. (setq names (cdr names))
  11256. (when names (insert ", ")))
  11257. ;; paste type
  11258. (setq type (nth 3 port))
  11259. (setq generic-list (nth 1 vhdl-port-list))
  11260. (vhdl-prepare-search-1
  11261. (setq pos 0)
  11262. ;; replace formal by actual generics
  11263. (while generic-list
  11264. (setq port-name (car (nth 0 (car generic-list))))
  11265. (while (string-match (concat "\\<" port-name "\\>") type pos)
  11266. (setq constant-name
  11267. (save-match-data (vhdl-replace-string
  11268. vhdl-actual-generic-name port-name)))
  11269. (setq type (replace-match constant-name t nil type))
  11270. (setq pos (match-end 0)))
  11271. (setq generic-list (cdr generic-list))))
  11272. (insert " : " type)
  11273. ;; paste initialization (inputs only)
  11274. (when (and initialize (nth 2 port) (equal "IN" (upcase (nth 2 port))))
  11275. (insert " := "
  11276. (cond ((string-match "integer" (nth 3 port)) "0")
  11277. ((string-match "natural" (nth 3 port)) "0")
  11278. ((string-match "positive" (nth 3 port)) "0")
  11279. ((string-match "real" (nth 3 port)) "0.0")
  11280. ((string-match "(.+)" (nth 3 port)) "(others => '0')")
  11281. (t "'0'"))))
  11282. (insert ";")
  11283. ;; paste comment
  11284. (when (or (and vhdl-include-direction-comments (nth 2 port))
  11285. (and vhdl-include-port-comments (nth 4 port)))
  11286. (vhdl-comment-insert-inline
  11287. (concat
  11288. (cond ((and vhdl-include-direction-comments (nth 2 port))
  11289. (format "%-6s" (concat "[" (nth 2 port) "] ")))
  11290. (vhdl-include-direction-comments " "))
  11291. (when vhdl-include-port-comments (nth 4 port))) t))
  11292. (setq port-list (cdr port-list))
  11293. (when port-list (insert "\n") (indent-to margin)))
  11294. ;; align signal list
  11295. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
  11296. (message "Pasting port as signals...done")))
  11297. (defun vhdl-port-paste-initializations (&optional no-indent)
  11298. "Paste ports as signal initializations."
  11299. (interactive)
  11300. (if (not vhdl-port-list)
  11301. (error "ERROR: No port read")
  11302. (let ((orig-vhdl-port-list vhdl-port-list))
  11303. (message "Pasting port as initializations...")
  11304. ;; flatten local copy of port list (must be flat for signal initial.)
  11305. (vhdl-port-flatten)
  11306. (unless no-indent (indent-according-to-mode))
  11307. (let ((margin (current-indentation))
  11308. start port name
  11309. (port-list (nth 2 vhdl-port-list)))
  11310. (when port-list
  11311. (setq start (point))
  11312. (while port-list
  11313. (setq port (car port-list))
  11314. ;; paste actual port signal (inputs only)
  11315. (when (equal "IN" (upcase (nth 2 port)))
  11316. (setq name (car (nth 0 port)))
  11317. (insert (vhdl-replace-string vhdl-actual-port-name name))
  11318. ;; paste initialization
  11319. (insert " <= "
  11320. (cond ((string-match "integer" (nth 3 port)) "0")
  11321. ((string-match "natural" (nth 3 port)) "0")
  11322. ((string-match "positive" (nth 3 port)) "0")
  11323. ((string-match "real" (nth 3 port)) "0.0")
  11324. ((string-match "(.+)" (nth 3 port)) "(others => '0')")
  11325. (t "'0'"))
  11326. ";"))
  11327. (setq port-list (cdr port-list))
  11328. (when (and port-list
  11329. (equal "IN" (upcase (nth 2 (car port-list)))))
  11330. (insert "\n") (indent-to margin)))
  11331. ;; align signal list
  11332. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1))))
  11333. (message "Pasting port as initializations...done")
  11334. (setq vhdl-port-list orig-vhdl-port-list))))
  11335. (defun vhdl-port-paste-testbench ()
  11336. "Paste as a bare-bones testbench."
  11337. (interactive)
  11338. (if (not vhdl-port-list)
  11339. (error "ERROR: No port read")
  11340. (let ((case-fold-search t)
  11341. (ent-name (vhdl-replace-string vhdl-testbench-entity-name
  11342. (nth 0 vhdl-port-list)))
  11343. (source-buffer (current-buffer))
  11344. arch-name config-name ent-file-name arch-file-name
  11345. ent-buffer arch-buffer position)
  11346. ;; open entity file
  11347. (unless (eq vhdl-testbench-create-files 'none)
  11348. (setq ent-file-name
  11349. (concat (vhdl-replace-string vhdl-testbench-entity-file-name
  11350. ent-name t)
  11351. "." (file-name-extension (buffer-file-name))))
  11352. (if (file-exists-p ent-file-name)
  11353. (if (y-or-n-p
  11354. (concat "File \"" ent-file-name "\" exists; overwrite? "))
  11355. (progn (find-file ent-file-name)
  11356. (erase-buffer)
  11357. (set-buffer-modified-p nil))
  11358. (if (eq vhdl-testbench-create-files 'separate)
  11359. (setq ent-file-name nil)
  11360. (error "ERROR: Pasting port as testbench...aborted")))
  11361. (find-file ent-file-name)))
  11362. (unless (and (eq vhdl-testbench-create-files 'separate)
  11363. (null ent-file-name))
  11364. ;; paste entity header
  11365. (if vhdl-testbench-include-header
  11366. (progn (vhdl-template-header
  11367. (concat "Testbench for design \""
  11368. (nth 0 vhdl-port-list) "\""))
  11369. (goto-char (point-max)))
  11370. (vhdl-comment-display-line) (insert "\n\n"))
  11371. ;; paste std_logic_1164 package
  11372. (when vhdl-testbench-include-library
  11373. (vhdl-template-package-std-logic-1164)
  11374. (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n"))
  11375. ;; paste entity declaration
  11376. (vhdl-insert-keyword "ENTITY ")
  11377. (insert ent-name)
  11378. (vhdl-insert-keyword " IS")
  11379. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  11380. (insert "\n")
  11381. (vhdl-insert-keyword "END ")
  11382. (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
  11383. (insert ent-name ";")
  11384. (insert "\n\n")
  11385. (vhdl-comment-display-line) (insert "\n"))
  11386. ;; get architecture name
  11387. (setq arch-name (if (equal (cdr vhdl-testbench-architecture-name) "")
  11388. (read-from-minibuffer "architecture name: "
  11389. nil vhdl-minibuffer-local-map)
  11390. (vhdl-replace-string vhdl-testbench-architecture-name
  11391. (nth 0 vhdl-port-list))))
  11392. (message "Pasting port as testbench \"%s(%s)\"..." ent-name arch-name)
  11393. ;; open architecture file
  11394. (if (not (eq vhdl-testbench-create-files 'separate))
  11395. (insert "\n")
  11396. (setq ent-buffer (current-buffer))
  11397. (setq arch-file-name
  11398. (concat (vhdl-replace-string vhdl-testbench-architecture-file-name
  11399. (concat ent-name " " arch-name) t)
  11400. "." (file-name-extension (buffer-file-name))))
  11401. (when (and (file-exists-p arch-file-name)
  11402. (not (y-or-n-p (concat "File \"" arch-file-name
  11403. "\" exists; overwrite? "))))
  11404. (error "ERROR: Pasting port as testbench...aborted"))
  11405. (find-file arch-file-name)
  11406. (erase-buffer)
  11407. (set-buffer-modified-p nil)
  11408. ;; paste architecture header
  11409. (if vhdl-testbench-include-header
  11410. (progn (vhdl-template-header
  11411. (concat "Testbench architecture for design \""
  11412. (nth 0 vhdl-port-list) "\""))
  11413. (goto-char (point-max)))
  11414. (vhdl-comment-display-line) (insert "\n\n")))
  11415. ;; paste architecture body
  11416. (vhdl-insert-keyword "ARCHITECTURE ")
  11417. (insert arch-name)
  11418. (vhdl-insert-keyword " OF ")
  11419. (insert ent-name)
  11420. (vhdl-insert-keyword " IS")
  11421. (insert "\n\n") (indent-to vhdl-basic-offset)
  11422. ;; paste component declaration
  11423. (unless (vhdl-use-direct-instantiation)
  11424. (vhdl-port-paste-component t)
  11425. (insert "\n\n") (indent-to vhdl-basic-offset))
  11426. ;; paste constants
  11427. (when (nth 1 vhdl-port-list)
  11428. (insert "-- component generics\n") (indent-to vhdl-basic-offset)
  11429. (vhdl-port-paste-constants t)
  11430. (insert "\n\n") (indent-to vhdl-basic-offset))
  11431. ;; paste internal signals
  11432. (insert "-- component ports\n") (indent-to vhdl-basic-offset)
  11433. (vhdl-port-paste-signals vhdl-testbench-initialize-signals t)
  11434. (insert "\n")
  11435. ;; paste custom declarations
  11436. (unless (equal "" vhdl-testbench-declarations)
  11437. (insert "\n")
  11438. (setq position (point))
  11439. (vhdl-insert-string-or-file vhdl-testbench-declarations)
  11440. (vhdl-indent-region position (point)))
  11441. (setq position (point))
  11442. (insert "\n\n")
  11443. (vhdl-comment-display-line) (insert "\n")
  11444. (when vhdl-testbench-include-configuration
  11445. (setq config-name (vhdl-replace-string
  11446. vhdl-testbench-configuration-name
  11447. (concat ent-name " " arch-name)))
  11448. (insert "\n")
  11449. (vhdl-insert-keyword "CONFIGURATION ") (insert config-name)
  11450. (vhdl-insert-keyword " OF ") (insert ent-name)
  11451. (vhdl-insert-keyword " IS\n")
  11452. (indent-to vhdl-basic-offset)
  11453. (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
  11454. (indent-to vhdl-basic-offset)
  11455. (vhdl-insert-keyword "END FOR;\n")
  11456. (vhdl-insert-keyword "END ") (insert config-name ";\n\n")
  11457. (vhdl-comment-display-line) (insert "\n"))
  11458. (goto-char position)
  11459. (vhdl-template-begin-end
  11460. (unless (vhdl-standard-p '87) "ARCHITECTURE") arch-name 0 t)
  11461. ;; paste instantiation
  11462. (insert "-- component instantiation\n") (indent-to vhdl-basic-offset)
  11463. (vhdl-port-paste-instance
  11464. (vhdl-replace-string vhdl-testbench-dut-name (nth 0 vhdl-port-list)) t)
  11465. (insert "\n")
  11466. ;; paste custom statements
  11467. (unless (equal "" vhdl-testbench-statements)
  11468. (insert "\n")
  11469. (setq position (point))
  11470. (vhdl-insert-string-or-file vhdl-testbench-statements)
  11471. (vhdl-indent-region position (point)))
  11472. (insert "\n")
  11473. (indent-to vhdl-basic-offset)
  11474. (unless (eq vhdl-testbench-create-files 'none)
  11475. (setq arch-buffer (current-buffer))
  11476. (when ent-buffer (set-buffer ent-buffer) (save-buffer))
  11477. (set-buffer arch-buffer) (save-buffer))
  11478. (message "%s"
  11479. (concat (format "Pasting port as testbench \"%s(%s)\"...done"
  11480. ent-name arch-name)
  11481. (and ent-file-name
  11482. (format "\n File created: \"%s\"" ent-file-name))
  11483. (and arch-file-name
  11484. (format "\n File created: \"%s\"" arch-file-name)))))))
  11485. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11486. ;;; Subprogram interface translation
  11487. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11488. (defvar vhdl-subprog-list nil
  11489. "Variable to hold last subprogram interface parsed.")
  11490. ;; structure: (parenthesized expression means list of such entries)
  11491. ;; (subprog-name kind
  11492. ;; ((names) object direct type init comment group-comment)
  11493. ;; return-type return-comment group-comment)
  11494. (defvar vhdl-subprog-flattened nil
  11495. "Indicates whether an subprogram interface has been flattened.")
  11496. (defun vhdl-subprog-flatten ()
  11497. "Flatten interface list so that only one parameter exists per line."
  11498. (interactive)
  11499. (if (not vhdl-subprog-list)
  11500. (error "ERROR: No subprogram interface has been read")
  11501. (message "Flattening subprogram interface...")
  11502. (let ((old-subprog-list (nth 2 vhdl-subprog-list))
  11503. new-subprog-list old-subprog new-subprog names)
  11504. ;; traverse parameter list and flatten entries
  11505. (while old-subprog-list
  11506. (setq old-subprog (car old-subprog-list))
  11507. (setq names (car old-subprog))
  11508. (while names
  11509. (setq new-subprog (cons (list (car names)) (cdr old-subprog)))
  11510. (setq new-subprog-list (append new-subprog-list (list new-subprog)))
  11511. (setq names (cdr names)))
  11512. (setq old-subprog-list (cdr old-subprog-list)))
  11513. (setq vhdl-subprog-list
  11514. (list (nth 0 vhdl-subprog-list) (nth 1 vhdl-subprog-list)
  11515. new-subprog-list (nth 3 vhdl-subprog-list)
  11516. (nth 4 vhdl-subprog-list) (nth 5 vhdl-subprog-list))
  11517. vhdl-subprog-flattened t)
  11518. (message "Flattening subprogram interface...done"))))
  11519. (defun vhdl-subprog-copy ()
  11520. "Get interface information from a subprogram specification."
  11521. (interactive)
  11522. (save-excursion
  11523. (let (parse-error pos end-of-list
  11524. name kind param-list object names direct type init
  11525. comment group-comment
  11526. return-type return-comment return-group-comment)
  11527. (vhdl-prepare-search-2
  11528. (setq
  11529. parse-error
  11530. (catch 'parse
  11531. ;; check if within function declaration
  11532. (setq pos (point))
  11533. (end-of-line)
  11534. (when (looking-at "[ \t\n\r\f]*\\((\\|;\\|is\\>\\)") (goto-char (match-end 0)))
  11535. (unless (and (re-search-backward "^\\s-*\\(\\(procedure\\)\\|\\(\\(pure\\|impure\\)\\s-+\\)?function\\)\\s-+\\(\"?\\w+\"?\\)[ \t\n\r\f]*\\(\\((\\)\\|;\\|is\\>\\)" nil t)
  11536. (goto-char (match-end 0))
  11537. (save-excursion (backward-char)
  11538. (forward-sexp)
  11539. (<= pos (point))))
  11540. (throw 'parse "ERROR: Not within a subprogram specification"))
  11541. (setq name (match-string-no-properties 5))
  11542. (setq kind (if (match-string 2) 'procedure 'function))
  11543. (setq end-of-list (not (match-string 7)))
  11544. (message "Reading interface of subprogram \"%s\"..." name)
  11545. ;; parse parameter list
  11546. (setq group-comment (vhdl-parse-group-comment))
  11547. (setq end-of-list (or end-of-list
  11548. (vhdl-parse-string ")[ \t\n\r\f]*\\(;\\|\\(is\\|return\\)\\>\\)" t)))
  11549. (while (not end-of-list)
  11550. ;; parse object
  11551. (setq object
  11552. (and (vhdl-parse-string "\\(constant\\|signal\\|variable\\|file\\|quantity\\|terminal\\)[ \t\n\r\f]*" t)
  11553. (match-string-no-properties 1)))
  11554. ;; parse names (accept extended identifiers)
  11555. (vhdl-parse-string "\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*")
  11556. (setq names (list (match-string-no-properties 1)))
  11557. (while (vhdl-parse-string ",[ \t\n\r\f]*\\(\\\\[^\\]+\\\\\\|\\w+\\)[ \t\n\r\f]*" t)
  11558. (setq names (append names (list (match-string-no-properties 1)))))
  11559. ;; parse direction
  11560. (vhdl-parse-string ":[ \t\n\r\f]*")
  11561. (setq direct
  11562. (and (vhdl-parse-string "\\(in\\|out\\|inout\\|buffer\\|linkage\\)[ \t\n\r\f]+" t)
  11563. (match-string-no-properties 1)))
  11564. ;; parse type
  11565. (vhdl-parse-string "\\([^():;\n]+\\)")
  11566. (setq type (match-string-no-properties 1))
  11567. (setq comment nil)
  11568. (while (looking-at "(")
  11569. (setq type
  11570. (concat type
  11571. (buffer-substring-no-properties
  11572. (point) (progn (forward-sexp) (point)))
  11573. (and (vhdl-parse-string "\\([^():;\n]*\\)" t)
  11574. (match-string-no-properties 1)))))
  11575. ;; special case: closing parenthesis is on separate line
  11576. (when (and type (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" type))
  11577. (setq comment (substring type (match-beginning 2)))
  11578. (setq type (substring type 0 (match-beginning 1))))
  11579. ;; strip off trailing group-comment
  11580. (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" type)
  11581. (setq type (substring type 0 (match-end 1)))
  11582. ;; parse initialization expression
  11583. (setq init nil)
  11584. (when (vhdl-parse-string ":=[ \t\n\r\f]*" t)
  11585. (vhdl-parse-string "\\([^();\n]*\\)")
  11586. (setq init (match-string-no-properties 1))
  11587. (while (looking-at "(")
  11588. (setq init
  11589. (concat init
  11590. (buffer-substring-no-properties
  11591. (point) (progn (forward-sexp) (point)))
  11592. (and (vhdl-parse-string "\\([^();\n]*\\)" t)
  11593. (match-string-no-properties 1))))))
  11594. ;; special case: closing parenthesis is on separate line
  11595. (when (and init (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" init))
  11596. (setq comment (substring init (match-beginning 2)))
  11597. (setq init (substring init 0 (match-beginning 1)))
  11598. (vhdl-forward-syntactic-ws))
  11599. (skip-chars-forward " \t")
  11600. ;; parse inline comment, special case: as above, no initial.
  11601. (unless comment
  11602. (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
  11603. (match-string-no-properties 1))))
  11604. (vhdl-forward-syntactic-ws)
  11605. (setq end-of-list (vhdl-parse-string ")\\s-*" t))
  11606. ;; parse inline comment
  11607. (unless comment
  11608. (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
  11609. (match-string-no-properties 1))))
  11610. (setq return-group-comment (vhdl-parse-group-comment))
  11611. (vhdl-parse-string "\\(;\\|\\(is\\|\\(return\\)\\)\\>\\)\\s-*")
  11612. ;; parse return type
  11613. (when (match-string 3)
  11614. (vhdl-parse-string "[ \t\n\r\f]*\\(.+\\)[ \t\n\r\f]*\\(;\\|is\\>\\)\\s-*")
  11615. (setq return-type (match-string-no-properties 1))
  11616. (when (and return-type
  11617. (string-match "\\(\\s-*--\\s-*\\)\\(.*\\)" return-type))
  11618. (setq return-comment (substring return-type (match-beginning 2)))
  11619. (setq return-type (substring return-type 0 (match-beginning 1))))
  11620. ;; strip of trailing group-comment
  11621. (string-match "\\(\\(\\s-*\\S-+\\)+\\)\\s-*" return-type)
  11622. (setq return-type (substring return-type 0 (match-end 1)))
  11623. ;; parse return comment
  11624. (unless return-comment
  11625. (setq return-comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
  11626. (match-string-no-properties 1)))))
  11627. ;; parse inline comment
  11628. (unless comment
  11629. (setq comment (and (vhdl-parse-string "--\\s-*\\([^\n]*\\)" t)
  11630. (match-string-no-properties 1))))
  11631. ;; save everything in list
  11632. (setq param-list (append param-list
  11633. (list (list names object direct type init
  11634. comment group-comment))))
  11635. ;; parse group comment and spacing
  11636. (setq group-comment (vhdl-parse-group-comment)))
  11637. (message "Reading interface of subprogram \"%s\"...done" name)
  11638. nil)))
  11639. ;; finish parsing
  11640. (if parse-error
  11641. (error parse-error)
  11642. (setq vhdl-subprog-list
  11643. (list name kind param-list return-type return-comment
  11644. return-group-comment)
  11645. vhdl-subprog-flattened nil)))))
  11646. (defun vhdl-subprog-paste-specification (kind)
  11647. "Paste as a subprogram specification."
  11648. (indent-according-to-mode)
  11649. (let ((margin (current-column))
  11650. (param-list (nth 2 vhdl-subprog-list))
  11651. list-margin start names param)
  11652. ;; paste keyword and name
  11653. (vhdl-insert-keyword
  11654. (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE " "FUNCTION "))
  11655. (insert (nth 0 vhdl-subprog-list))
  11656. (if (not param-list)
  11657. (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
  11658. (setq start (point))
  11659. ;; paste parameter list
  11660. (insert " (")
  11661. (unless vhdl-argument-list-indent
  11662. (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
  11663. (setq list-margin (current-column))
  11664. (while param-list
  11665. (setq param (car param-list))
  11666. ;; paste group comment and spacing
  11667. (when (memq vhdl-include-group-comments (list kind 'always))
  11668. (vhdl-paste-group-comment (nth 6 param) list-margin))
  11669. ;; paste object
  11670. (when (nth 1 param) (insert (nth 1 param) " "))
  11671. ;; paste names
  11672. (setq names (nth 0 param))
  11673. (while names
  11674. (insert (car names))
  11675. (setq names (cdr names))
  11676. (when names (insert ", ")))
  11677. ;; paste direction
  11678. (insert " : ")
  11679. (when (nth 2 param) (insert (nth 2 param) " "))
  11680. ;; paste type
  11681. (insert (nth 3 param))
  11682. ;; paste initialization
  11683. (when (nth 4 param) (insert " := " (nth 4 param)))
  11684. ;; terminate line
  11685. (if (cdr param-list)
  11686. (insert ";")
  11687. (insert ")")
  11688. (when (null (nth 3 vhdl-subprog-list))
  11689. (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))))
  11690. ;; paste comment
  11691. (when (and vhdl-include-port-comments (nth 5 param))
  11692. (vhdl-comment-insert-inline (nth 5 param) t))
  11693. (setq param-list (cdr param-list))
  11694. (when param-list (insert "\n") (indent-to list-margin)))
  11695. (when (nth 3 vhdl-subprog-list)
  11696. (insert "\n") (indent-to list-margin)
  11697. ;; paste group comment and spacing
  11698. (when (memq vhdl-include-group-comments (list kind 'always))
  11699. (vhdl-paste-group-comment (nth 5 vhdl-subprog-list) list-margin))
  11700. ;; paste return type
  11701. (insert "return " (nth 3 vhdl-subprog-list))
  11702. (if (eq kind 'decl) (insert ";") (vhdl-insert-keyword " is"))
  11703. (when (and vhdl-include-port-comments (nth 4 vhdl-subprog-list))
  11704. (vhdl-comment-insert-inline (nth 4 vhdl-subprog-list) t)))
  11705. ;; align parameter list
  11706. (when vhdl-auto-align (vhdl-align-region-groups start (point) 1 t)))
  11707. ;; paste body
  11708. (when (eq kind 'body)
  11709. (insert "\n")
  11710. (vhdl-template-begin-end
  11711. (unless (vhdl-standard-p '87)
  11712. (if (eq (nth 1 vhdl-subprog-list) 'procedure) "PROCEDURE" "FUNCTION"))
  11713. (nth 0 vhdl-subprog-list) margin))))
  11714. (defun vhdl-subprog-paste-declaration ()
  11715. "Paste as a subprogram declaration."
  11716. (interactive)
  11717. (if (not vhdl-subprog-list)
  11718. (error "ERROR: No subprogram interface read")
  11719. (message "Pasting interface as subprogram declaration \"%s\"..."
  11720. (car vhdl-subprog-list))
  11721. ;; paste specification
  11722. (vhdl-subprog-paste-specification 'decl)
  11723. (message "Pasting interface as subprogram declaration \"%s\"...done"
  11724. (car vhdl-subprog-list))))
  11725. (defun vhdl-subprog-paste-body ()
  11726. "Paste as a subprogram body."
  11727. (interactive)
  11728. (if (not vhdl-subprog-list)
  11729. (error "ERROR: No subprogram interface read")
  11730. (message "Pasting interface as subprogram body \"%s\"..."
  11731. (car vhdl-subprog-list))
  11732. ;; paste specification and body
  11733. (vhdl-subprog-paste-specification 'body)
  11734. (message "Pasting interface as subprogram body \"%s\"...done"
  11735. (car vhdl-subprog-list))))
  11736. (defun vhdl-subprog-paste-call ()
  11737. "Paste as a subprogram call."
  11738. (interactive)
  11739. (if (not vhdl-subprog-list)
  11740. (error "ERROR: No subprogram interface read")
  11741. (let ((orig-vhdl-subprog-list vhdl-subprog-list)
  11742. param-list margin list-margin param start)
  11743. ;; flatten local copy of interface list (must be flat for parameter mapping)
  11744. (vhdl-subprog-flatten)
  11745. (setq param-list (nth 2 vhdl-subprog-list))
  11746. (indent-according-to-mode)
  11747. (setq margin (current-indentation))
  11748. (message "Pasting interface as subprogram call \"%s\"..."
  11749. (car vhdl-subprog-list))
  11750. ;; paste name
  11751. (insert (nth 0 vhdl-subprog-list))
  11752. (if (not param-list)
  11753. (insert ";")
  11754. (setq start (point))
  11755. ;; paste parameter list
  11756. (insert " (")
  11757. (unless vhdl-argument-list-indent
  11758. (insert "\n") (indent-to (+ margin vhdl-basic-offset)))
  11759. (setq list-margin (current-column))
  11760. (while param-list
  11761. (setq param (car param-list))
  11762. ;; paste group comment and spacing
  11763. (when (eq vhdl-include-group-comments 'always)
  11764. (vhdl-paste-group-comment (nth 6 param) list-margin))
  11765. ;; paste formal port
  11766. (insert (car (nth 0 param)) " => ")
  11767. (setq param-list (cdr param-list))
  11768. (insert (if param-list "," ");"))
  11769. ;; paste comment
  11770. (when (and vhdl-include-port-comments (nth 5 param))
  11771. (vhdl-comment-insert-inline (nth 5 param)))
  11772. (when param-list (insert "\n") (indent-to list-margin)))
  11773. ;; align parameter list
  11774. (when vhdl-auto-align
  11775. (vhdl-align-region-groups start (point) 1)))
  11776. (message "Pasting interface as subprogram call \"%s\"...done"
  11777. (car vhdl-subprog-list))
  11778. (setq vhdl-subprog-list orig-vhdl-subprog-list))))
  11779. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11780. ;;; Miscellaneous
  11781. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11782. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11783. ;; Hippie expand customization
  11784. (defvar vhdl-expand-upper-case nil)
  11785. (defun vhdl-try-expand-abbrev (old)
  11786. "Try expanding abbreviations from `vhdl-abbrev-list'."
  11787. (unless old
  11788. (he-init-string (he-dabbrev-beg) (point))
  11789. (setq he-expand-list
  11790. (let ((abbrev-list vhdl-abbrev-list)
  11791. (sel-abbrev-list '()))
  11792. (while abbrev-list
  11793. (when (or (not (stringp (car abbrev-list)))
  11794. (string-match
  11795. (concat "^" he-search-string) (car abbrev-list)))
  11796. (setq sel-abbrev-list
  11797. (cons (car abbrev-list) sel-abbrev-list)))
  11798. (setq abbrev-list (cdr abbrev-list)))
  11799. (nreverse sel-abbrev-list))))
  11800. (while (and he-expand-list
  11801. (or (not (stringp (car he-expand-list)))
  11802. (he-string-member (car he-expand-list) he-tried-table t)))
  11803. (unless (stringp (car he-expand-list))
  11804. (setq vhdl-expand-upper-case (car he-expand-list)))
  11805. (setq he-expand-list (cdr he-expand-list)))
  11806. (if (null he-expand-list)
  11807. (progn (when old (he-reset-string))
  11808. nil)
  11809. (he-substitute-string
  11810. (if vhdl-expand-upper-case
  11811. (upcase (car he-expand-list))
  11812. (car he-expand-list))
  11813. t)
  11814. (setq he-expand-list (cdr he-expand-list))
  11815. t))
  11816. (defun vhdl-he-list-beg ()
  11817. "Also looks at the word before `(' in order to better match parenthesized
  11818. expressions (e.g. for index ranges of types and signals)."
  11819. (save-excursion
  11820. (condition-case ()
  11821. (progn (backward-up-list 1)
  11822. (skip-syntax-backward "w_")) ; crashes in `viper-mode'
  11823. (error ()))
  11824. (point)))
  11825. ;; override `he-list-beg' from `hippie-exp'
  11826. (unless (and (boundp 'viper-mode) viper-mode)
  11827. (defalias 'he-list-beg 'vhdl-he-list-beg))
  11828. ;; function for expanding abbrevs and dabbrevs
  11829. (defalias 'vhdl-expand-abbrev (make-hippie-expand-function
  11830. '(try-expand-dabbrev
  11831. try-expand-dabbrev-all-buffers
  11832. vhdl-try-expand-abbrev)))
  11833. ;; function for expanding parenthesis
  11834. (defalias 'vhdl-expand-paren (make-hippie-expand-function
  11835. '(try-expand-list
  11836. try-expand-list-all-buffers)))
  11837. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11838. ;; Line handling functions
  11839. (defun vhdl-current-line ()
  11840. "Return the line number of the line containing point."
  11841. (save-restriction
  11842. (widen)
  11843. (1+ (count-lines (point-min) (point-at-bol)))))
  11844. (defun vhdl-line-kill-entire (&optional arg)
  11845. "Delete entire line."
  11846. (interactive "p")
  11847. (beginning-of-line)
  11848. (kill-line (or arg 1)))
  11849. (defun vhdl-line-kill (&optional arg)
  11850. "Kill current line."
  11851. (interactive "p")
  11852. (vhdl-line-kill-entire arg))
  11853. (defun vhdl-line-copy (&optional arg)
  11854. "Copy current line."
  11855. (interactive "p")
  11856. (save-excursion
  11857. (let ((position (point-at-bol)))
  11858. (forward-line (or arg 1))
  11859. (copy-region-as-kill position (point)))))
  11860. (defun vhdl-line-yank ()
  11861. "Yank entire line."
  11862. (interactive)
  11863. (beginning-of-line)
  11864. (yank))
  11865. (defun vhdl-line-expand (&optional prefix-arg)
  11866. "Hippie-expand current line."
  11867. (interactive "P")
  11868. (require 'hippie-exp)
  11869. (let ((case-fold-search t) (case-replace nil)
  11870. (hippie-expand-try-functions-list
  11871. '(try-expand-line try-expand-line-all-buffers)))
  11872. (hippie-expand prefix-arg)))
  11873. (defun vhdl-line-transpose-next (&optional arg)
  11874. "Interchange this line with next line."
  11875. (interactive "p")
  11876. (forward-line 1)
  11877. (transpose-lines (or arg 1))
  11878. (forward-line -1))
  11879. (defun vhdl-line-transpose-previous (&optional arg)
  11880. "Interchange this line with previous line."
  11881. (interactive "p")
  11882. (forward-line 1)
  11883. (transpose-lines (- 0 (or arg 0)))
  11884. (forward-line -1))
  11885. (defun vhdl-line-open ()
  11886. "Open a new line and indent."
  11887. (interactive)
  11888. (end-of-line -0)
  11889. (newline-and-indent))
  11890. (defun vhdl-delete-indentation ()
  11891. "Join lines. That is, call `delete-indentation' with `fill-prefix' so that
  11892. it works within comments too."
  11893. (interactive)
  11894. (let ((fill-prefix "-- "))
  11895. (delete-indentation)))
  11896. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11897. ;; Move functions
  11898. (defun vhdl-forward-same-indent ()
  11899. "Move forward to next line with same indent."
  11900. (interactive)
  11901. (let ((pos (point))
  11902. (indent (current-indentation)))
  11903. (beginning-of-line 2)
  11904. (while (and (not (eobp))
  11905. (or (looking-at "^\\s-*\\(--.*\\)?$")
  11906. (> (current-indentation) indent)))
  11907. (beginning-of-line 2))
  11908. (if (= (current-indentation) indent)
  11909. (back-to-indentation)
  11910. (message "No following line with same indent found in this block")
  11911. (goto-char pos)
  11912. nil)))
  11913. (defun vhdl-backward-same-indent ()
  11914. "Move backward to previous line with same indent."
  11915. (interactive)
  11916. (let ((pos (point))
  11917. (indent (current-indentation)))
  11918. (beginning-of-line -0)
  11919. (while (and (not (bobp))
  11920. (or (looking-at "^\\s-*\\(--.*\\)?$")
  11921. (> (current-indentation) indent)))
  11922. (beginning-of-line -0))
  11923. (if (= (current-indentation) indent)
  11924. (back-to-indentation)
  11925. (message "No preceding line with same indent found in this block")
  11926. (goto-char pos)
  11927. nil)))
  11928. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11929. ;; Statistics
  11930. (defun vhdl-statistics-buffer ()
  11931. "Get some file statistics."
  11932. (interactive)
  11933. (let ((no-stats 0)
  11934. (no-code-lines 0)
  11935. (no-empty-lines 0)
  11936. (no-comm-lines 0)
  11937. (no-comments 0)
  11938. (no-lines (count-lines (point-min) (point-max))))
  11939. (save-excursion
  11940. ;; count statements
  11941. (goto-char (point-min))
  11942. (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
  11943. (if (match-string 1)
  11944. (goto-char (match-end 1))
  11945. (setq no-stats (1+ no-stats))))
  11946. ;; count code lines
  11947. (goto-char (point-min))
  11948. (while (not (eobp))
  11949. (unless (looking-at "^\\s-*\\(--.*\\)?$")
  11950. (setq no-code-lines (1+ no-code-lines)))
  11951. (beginning-of-line 2))
  11952. ;; count empty lines
  11953. (goto-char (point-min))
  11954. (while (and (re-search-forward "^\\s-*$" nil t)
  11955. (not (eq (point) (point-max))))
  11956. (if (match-string 1)
  11957. (goto-char (match-end 1))
  11958. (setq no-empty-lines (1+ no-empty-lines))
  11959. (unless (eq (point) (point-max))
  11960. (forward-char))))
  11961. ;; count comment-only lines
  11962. (goto-char (point-min))
  11963. (while (re-search-forward "^\\s-*--.*" nil t)
  11964. (if (match-string 1)
  11965. (goto-char (match-end 1))
  11966. (setq no-comm-lines (1+ no-comm-lines))))
  11967. ;; count comments
  11968. (goto-char (point-min))
  11969. (while (re-search-forward "--.*" nil t)
  11970. (if (match-string 1)
  11971. (goto-char (match-end 1))
  11972. (setq no-comments (1+ no-comments)))))
  11973. ;; print results
  11974. (message "\n\
  11975. File statistics: \"%s\"\n\
  11976. -----------------------\n\
  11977. # statements : %5d\n\
  11978. # code lines : %5d\n\
  11979. # empty lines : %5d\n\
  11980. # comment lines : %5d\n\
  11981. # comments : %5d\n\
  11982. # total lines : %5d\n"
  11983. (buffer-file-name) no-stats no-code-lines no-empty-lines
  11984. no-comm-lines no-comments no-lines)
  11985. (unless vhdl-emacs-21 (vhdl-show-messages))))
  11986. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11987. ;; Help functions
  11988. (defun vhdl-re-search-forward (regexp &optional bound noerror count)
  11989. "Like `re-search-forward', but does not match within literals."
  11990. (let (pos)
  11991. (save-excursion
  11992. (while (and (setq pos (re-search-forward regexp bound noerror count))
  11993. (vhdl-in-literal))))
  11994. (when pos (goto-char pos))
  11995. pos))
  11996. (defun vhdl-re-search-backward (regexp &optional bound noerror count)
  11997. "Like `re-search-backward', but does not match within literals."
  11998. (let (pos)
  11999. (save-excursion
  12000. (while (and (setq pos (re-search-backward regexp bound noerror count))
  12001. (vhdl-in-literal))))
  12002. (when pos (goto-char pos))
  12003. pos))
  12004. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12005. ;;; Project
  12006. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12007. (defun vhdl-set-project (name)
  12008. "Set current project to NAME."
  12009. (interactive
  12010. (list (let ((completion-ignore-case t))
  12011. (completing-read "Project name: " vhdl-project-alist nil t))))
  12012. (cond ((equal name "")
  12013. (setq vhdl-project nil)
  12014. (message "Current VHDL project: None"))
  12015. ((assoc name vhdl-project-alist)
  12016. (setq vhdl-project name)
  12017. (message "Current VHDL project: \"%s\"" name))
  12018. (t
  12019. (vhdl-warning (format "Unknown VHDL project: \"%s\"" name))))
  12020. (vhdl-speedbar-update-current-project))
  12021. (defun vhdl-set-default-project ()
  12022. "Set current project as default on startup."
  12023. (interactive)
  12024. (customize-set-variable 'vhdl-project vhdl-project)
  12025. (customize-save-customized))
  12026. (defun vhdl-toggle-project (name token indent)
  12027. "Set current project to NAME or unset if NAME is current project."
  12028. (vhdl-set-project (if (equal name vhdl-project) "" name)))
  12029. (defun vhdl-export-project (file-name)
  12030. "Write project setup for current project."
  12031. (interactive
  12032. (let ((name (vhdl-resolve-env-variable
  12033. (vhdl-replace-string
  12034. (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
  12035. (concat (subst-char-in-string
  12036. ? ?_ (or (vhdl-project-p)
  12037. (error "ERROR: No current project")))
  12038. " " (user-login-name))))))
  12039. (list (read-file-name
  12040. "Write project file: "
  12041. (when (file-name-absolute-p name) "") nil nil name))))
  12042. (setq file-name (abbreviate-file-name file-name))
  12043. (let ((orig-buffer (current-buffer)))
  12044. (unless (file-exists-p (file-name-directory file-name))
  12045. (make-directory (file-name-directory file-name) t))
  12046. (if (not (file-writable-p file-name))
  12047. (error "ERROR: File not writable: \"%s\"" file-name)
  12048. (set-buffer (find-file-noselect file-name t t))
  12049. (erase-buffer)
  12050. (insert ";; -*- Emacs-Lisp -*-\n\n"
  12051. ";;; " (file-name-nondirectory file-name)
  12052. " - project setup file for Emacs VHDL Mode " vhdl-version "\n\n"
  12053. ";; Project : " vhdl-project "\n"
  12054. ";; Saved : " (format-time-string "%Y-%m-%d %T ")
  12055. (user-login-name) "\n\n\n"
  12056. ";; project name\n"
  12057. "(setq vhdl-project \"" vhdl-project "\")\n\n"
  12058. ";; project setup\n"
  12059. "(vhdl-aput 'vhdl-project-alist vhdl-project\n'")
  12060. (pp (vhdl-aget vhdl-project-alist vhdl-project) (current-buffer))
  12061. (insert ")\n")
  12062. (save-buffer)
  12063. (kill-buffer (current-buffer))
  12064. (set-buffer orig-buffer))))
  12065. (defun vhdl-import-project (file-name &optional auto not-make-current)
  12066. "Read project setup and set current project."
  12067. (interactive
  12068. (let ((name (vhdl-resolve-env-variable
  12069. (vhdl-replace-string
  12070. (cons "\\(.*\\) \\(.*\\)" (car vhdl-project-file-name))
  12071. (concat "" " " (user-login-name))))))
  12072. (list (read-file-name
  12073. "Read project file: " (when (file-name-absolute-p name) "") nil t
  12074. (file-name-directory name)))))
  12075. (when (file-exists-p file-name)
  12076. (condition-case ()
  12077. (let ((current-project vhdl-project))
  12078. (load-file file-name)
  12079. (when (/= (length (vhdl-aget vhdl-project-alist vhdl-project)) 10)
  12080. (vhdl-adelete 'vhdl-project-alist vhdl-project)
  12081. (error ""))
  12082. (if not-make-current
  12083. (setq vhdl-project current-project)
  12084. (setq vhdl-compiler
  12085. (caar (nth 4 (vhdl-aget vhdl-project-alist vhdl-project)))))
  12086. (vhdl-update-mode-menu)
  12087. (vhdl-speedbar-refresh)
  12088. (unless not-make-current
  12089. (message "Current VHDL project: \"%s\"; compiler: \"%s\"%s"
  12090. vhdl-project vhdl-compiler (if auto " (auto-loaded)" ""))))
  12091. (error (vhdl-warning
  12092. (format "ERROR: Invalid project setup file: \"%s\"" file-name))))))
  12093. (defun vhdl-duplicate-project ()
  12094. "Duplicate setup of current project."
  12095. (interactive)
  12096. (let ((new-name (read-from-minibuffer "New project name: "))
  12097. (project-entry (vhdl-aget vhdl-project-alist vhdl-project)))
  12098. (setq vhdl-project-alist
  12099. (append vhdl-project-alist
  12100. (list (cons new-name project-entry))))
  12101. (vhdl-update-mode-menu)))
  12102. (defun vhdl-auto-load-project ()
  12103. "Automatically load project setup at startup."
  12104. (let ((file-name-list vhdl-project-file-name)
  12105. file-list list-length)
  12106. (while file-name-list
  12107. (setq file-list
  12108. (append file-list
  12109. (file-expand-wildcards
  12110. (vhdl-resolve-env-variable
  12111. (vhdl-replace-string
  12112. (cons "\\(.*\\) \\(.*\\)" (car file-name-list))
  12113. (concat "* " (user-login-name)))))))
  12114. (setq list-length (or list-length (length file-list)))
  12115. (setq file-name-list (cdr file-name-list)))
  12116. (while file-list
  12117. (vhdl-import-project (expand-file-name (car file-list)) t
  12118. (not (> list-length 0)))
  12119. (setq list-length (1- list-length))
  12120. (setq file-list (cdr file-list)))))
  12121. ;; automatically load project setup when idle after startup
  12122. (when (memq 'startup vhdl-project-auto-load)
  12123. (if noninteractive
  12124. (vhdl-auto-load-project)
  12125. (vhdl-run-when-idle .1 nil 'vhdl-auto-load-project)))
  12126. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12127. ;;; Hideshow
  12128. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12129. ;; (using `hideshow.el')
  12130. (defconst vhdl-hs-start-regexp
  12131. (concat
  12132. "\\(^\\)\\s-*\\("
  12133. ;; generic/port clause
  12134. "\\(generic\\|port\\)[ \t\n\r\f]*(\\|"
  12135. ;; component
  12136. "component\\>\\|"
  12137. ;; component instantiation
  12138. "\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*"
  12139. "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
  12140. "\\(\\w\\|\\s_\\)+\\([ \t\n\r\f]*(\\(\\w\\|\\s_\\)+)\\)?[ \t\n\r\f]*"
  12141. "\\(generic\\|port\\)[ \t\n\r\f]+map[ \t\n\r\f]*(\\|"
  12142. ;; subprogram
  12143. "\\(function\\|procedure\\)\\>\\|"
  12144. ;; process, block
  12145. "\\(\\(\\w\\|\\s_\\)+[ \t\n\r\f]*:[ \t\n\r\f]*\\)?\\(process\\|block\\)\\>\\|"
  12146. ;; configuration declaration
  12147. "configuration\\>"
  12148. "\\)")
  12149. "Regexp to match start of construct to hide.")
  12150. (defun vhdl-hs-forward-sexp-func (count)
  12151. "Find end of construct to hide (for hideshow). Only searches forward."
  12152. (let ((pos (point)))
  12153. (vhdl-prepare-search-2
  12154. (beginning-of-line)
  12155. (cond
  12156. ;; generic/port clause
  12157. ((looking-at "^\\s-*\\(generic\\|port\\)[ \t\n\r\f]*(")
  12158. (goto-char (match-end 0))
  12159. (backward-char)
  12160. (forward-sexp))
  12161. ;; component declaration
  12162. ((looking-at "^\\s-*component\\>")
  12163. (re-search-forward "^\\s-*end\\s-+component\\>" nil t))
  12164. ;; component instantiation
  12165. ((looking-at
  12166. (concat
  12167. "^\\s-*\\w+\\s-*:[ \t\n\r\f]*"
  12168. "\\(\\(component\\|configuration\\|entity\\)[ \t\n\r\f]+\\)?"
  12169. "\\w+\\(\\s-*(\\w+)\\)?[ \t\n\r\f]*"
  12170. "\\(generic\\|port\\)\\s-+map[ \t\n\r\f]*("))
  12171. (goto-char (match-end 0))
  12172. (backward-char)
  12173. (forward-sexp)
  12174. (setq pos (point))
  12175. (vhdl-forward-syntactic-ws)
  12176. (when (looking-at "port\\s-+map[ \t\n\r\f]*(")
  12177. (goto-char (match-end 0))
  12178. (backward-char)
  12179. (forward-sexp)
  12180. (setq pos (point)))
  12181. (goto-char pos))
  12182. ;; subprogram declaration/body
  12183. ((looking-at "^\\s-*\\(function\\|procedure\\)\\s-+\\(\\w+\\|\".+\"\\)")
  12184. (goto-char (match-end 0))
  12185. (vhdl-forward-syntactic-ws)
  12186. (when (looking-at "(")
  12187. (forward-sexp))
  12188. (while (and (re-search-forward "\\(;\\)\\|\\(\\<is\\>\\)" nil t)
  12189. (vhdl-in-literal)))
  12190. ;; subprogram body
  12191. (when (match-string 2)
  12192. (re-search-forward "^\\s-*\\<begin\\>" nil t)
  12193. (backward-word 1)
  12194. (vhdl-forward-sexp)))
  12195. ;; block (recursive)
  12196. ((looking-at "^\\s-*\\w+\\s-*:\\s-*block\\>")
  12197. (goto-char (match-end 0))
  12198. (while (and (re-search-forward "^\\s-*\\(\\(\\w+\\s-*:\\s-*block\\>\\)\\|\\(end\\s-+block\\>\\)\\)" nil t)
  12199. (match-beginning 2))
  12200. (vhdl-hs-forward-sexp-func count)))
  12201. ;; process
  12202. ((looking-at "^\\s-*\\(\\w+\\s-*:\\s-*\\)?process\\>")
  12203. (re-search-forward "^\\s-*end\\s-+process\\>" nil t))
  12204. ;; configuration declaration
  12205. ((looking-at "^\\s-*configuration\\>")
  12206. (forward-word 4)
  12207. (vhdl-forward-sexp))
  12208. (t (goto-char pos))))))
  12209. (defun vhdl-hideshow-init ()
  12210. "Initialize `hideshow'."
  12211. (when vhdl-hideshow-menu
  12212. (vhdl-hs-minor-mode 1)))
  12213. (defun vhdl-hs-minor-mode (&optional arg)
  12214. "Toggle hideshow minor mode and update menu bar."
  12215. (interactive "P")
  12216. (require 'hideshow)
  12217. ;; check for hideshow version 5.x
  12218. (if (not (boundp 'hs-block-start-mdata-select))
  12219. (vhdl-warning-when-idle "Install included `hideshow.el' patch first (see INSTALL file)")
  12220. ;; initialize hideshow
  12221. (unless (assoc 'vhdl-mode hs-special-modes-alist)
  12222. (setq hs-special-modes-alist
  12223. (cons (list 'vhdl-mode vhdl-hs-start-regexp nil "--\\( \\|$\\)"
  12224. 'vhdl-hs-forward-sexp-func nil)
  12225. hs-special-modes-alist)))
  12226. (if (featurep 'xemacs) (make-local-hook 'hs-minor-mode-hook))
  12227. (if vhdl-hide-all-init
  12228. (add-hook 'hs-minor-mode-hook 'hs-hide-all nil t)
  12229. (remove-hook 'hs-minor-mode-hook 'hs-hide-all t))
  12230. (hs-minor-mode arg)
  12231. (force-mode-line-update))) ; hack to update menu bar
  12232. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12233. ;;; Font locking
  12234. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12235. ;; (using `font-lock.el')
  12236. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12237. ;; Help functions
  12238. (defun vhdl-within-translate-off ()
  12239. "Return point if within translate-off region, else nil."
  12240. (and (save-excursion
  12241. (re-search-backward
  12242. "^\\s-*--\\s-*pragma\\s-*translate_\\(on\\|off\\)\\s-*\n" nil t))
  12243. (equal "off" (match-string 1))
  12244. (point)))
  12245. (defun vhdl-start-translate-off (limit)
  12246. "Return point before translate-off pragma if before LIMIT, else nil."
  12247. (when (re-search-forward
  12248. "^\\s-*--\\s-*pragma\\s-*translate_off\\s-*\n" limit t)
  12249. (match-beginning 0)))
  12250. (defun vhdl-end-translate-off (limit)
  12251. "Return point after translate-on pragma if before LIMIT, else nil."
  12252. (re-search-forward "^\\s-*--\\s-*pragma\\s-*translate_on\\s-*\n" limit t))
  12253. (defun vhdl-match-translate-off (limit)
  12254. "Match a translate-off block, setting match-data and returning t, else nil."
  12255. (when (< (point) limit)
  12256. (let ((start (or (vhdl-within-translate-off)
  12257. (vhdl-start-translate-off limit)))
  12258. (case-fold-search t))
  12259. (when start
  12260. (let ((end (or (vhdl-end-translate-off limit) limit)))
  12261. (set-match-data (list start end))
  12262. (goto-char end))))))
  12263. (defun vhdl-font-lock-match-item (limit)
  12264. "Match, and move over, any declaration item after point. Adapted from
  12265. `font-lock-match-c-style-declaration-item-and-skip-to-next'."
  12266. (condition-case nil
  12267. (save-restriction
  12268. (narrow-to-region (point-min) limit)
  12269. ;; match item
  12270. (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
  12271. (save-match-data
  12272. (goto-char (match-end 1))
  12273. ;; move to next item
  12274. (if (looking-at "\\(\\s-*,\\)")
  12275. (goto-char (match-end 1))
  12276. (end-of-line) t))))
  12277. (error t)))
  12278. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12279. ;; Syntax definitions
  12280. (defconst vhdl-font-lock-syntactic-keywords
  12281. '(("\\('\\).\\('\\)" (1 (7 . ?\')) (2 (7 . ?\'))))
  12282. "Mark single quotes as having string quote syntax in 'c' instances.")
  12283. (defvar vhdl-font-lock-keywords nil
  12284. "Regular expressions to highlight in VHDL Mode.")
  12285. (defvar vhdl-font-lock-keywords-0
  12286. ;; set in `vhdl-font-lock-init' because dependent on user options
  12287. "For consideration as a value of `vhdl-font-lock-keywords'.
  12288. This does highlighting of template prompts and directives (pragmas).")
  12289. (defvar vhdl-font-lock-keywords-1 nil
  12290. ;; set in `vhdl-font-lock-init' because dependent on user options
  12291. "For consideration as a value of `vhdl-font-lock-keywords'.
  12292. This does highlighting of keywords and standard identifiers.")
  12293. (defconst vhdl-font-lock-keywords-2
  12294. (list
  12295. ;; highlight names of units, subprograms, and components when declared
  12296. (list
  12297. (concat
  12298. "^\\s-*\\("
  12299. "architecture\\|configuration\\|context\\|entity\\|package"
  12300. "\\(\\s-+body\\)?\\|"
  12301. "\\(\\(impure\\|pure\\)\\s-+\\)?function\\|procedure\\|component"
  12302. "\\)\\s-+\\(\\w+\\)")
  12303. 5 'font-lock-function-name-face)
  12304. ;; highlight entity names of architectures and configurations
  12305. (list
  12306. "^\\s-*\\(architecture\\|configuration\\)\\s-+\\w+\\s-+of\\s-+\\(\\w+\\)"
  12307. 2 'font-lock-function-name-face)
  12308. ;; highlight labels of common constructs
  12309. (list
  12310. (concat
  12311. "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\("
  12312. "assert\\|block\\|case\\|exit\\|for\\|if\\|loop\\|next\\|null\\|"
  12313. "postponed\\|process\\|"
  12314. (when (vhdl-standard-p 'ams) "procedural\\|")
  12315. "with\\|while"
  12316. "\\)\\>\\|\\w+\\s-*\\(([^\n]*)\\|\\.\\w+\\)*\\s-*<=\\)")
  12317. 1 'font-lock-function-name-face)
  12318. ;; highlight label and component name of component instantiations
  12319. (list
  12320. (concat
  12321. "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*\\(\\w+\\)[ \t\n\r\f]*"
  12322. "\\(--[^\n]*[ \t\n\r\f]+\\)*\\(generic\\|port\\)\\s-+map\\>")
  12323. '(1 font-lock-function-name-face) '(2 font-lock-function-name-face))
  12324. ;; highlight label and instantiated unit of component instantiations
  12325. (list
  12326. (concat
  12327. "^\\s-*\\(\\w+\\)\\s-*:[ \t\n\r\f]*"
  12328. "\\(component\\|configuration\\|entity\\)\\s-+"
  12329. "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\(\\s-*(\\(\\w+\\))\\)?")
  12330. '(1 font-lock-function-name-face) '(3 font-lock-function-name-face)
  12331. '(5 font-lock-function-name-face nil t)
  12332. '(7 font-lock-function-name-face nil t))
  12333. ;; highlight names and labels at end of constructs
  12334. (list
  12335. (concat
  12336. "^\\s-*end\\s-+\\(\\("
  12337. "architecture\\|block\\|case\\|component\\|configuration\\|context\\|"
  12338. "entity\\|for\\|function\\|generate\\|if\\|loop\\|package"
  12339. "\\(\\s-+body\\)?\\|procedure\\|\\(postponed\\s-+\\)?process\\|"
  12340. (when (vhdl-standard-p 'ams) "procedural\\|")
  12341. "units"
  12342. "\\)\\s-+\\)?\\(\\w*\\)")
  12343. 5 'font-lock-function-name-face)
  12344. ;; highlight labels in exit and next statements
  12345. (list
  12346. (concat
  12347. "^\\s-*\\(\\w+\\s-*:\\s-*\\)?\\(exit\\|next\\)\\s-+\\(\\w*\\)")
  12348. 3 'font-lock-function-name-face)
  12349. ;; highlight entity name in attribute specifications
  12350. (list
  12351. (concat
  12352. "^\\s-*attribute\\s-+\\w+\\s-+of\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\s-*:")
  12353. 1 'font-lock-function-name-face)
  12354. ;; highlight labels in block and component specifications
  12355. (list
  12356. (concat
  12357. "^\\s-*for\\s-+\\(\\w+\\(,\\s-*\\w+\\)*\\)\\>\\s-*"
  12358. "\\(:[ \t\n\r\f]*\\(\\w+\\)\\|[^i \t]\\)")
  12359. '(1 font-lock-function-name-face) '(4 font-lock-function-name-face nil t))
  12360. ;; highlight names in library clauses
  12361. (list "^\\s-*library\\>"
  12362. '(vhdl-font-lock-match-item nil nil (1 font-lock-function-name-face)))
  12363. ;; highlight names in use clauses
  12364. (list
  12365. (concat
  12366. "\\<\\(context\\|use\\)\\s-+\\(\\(entity\\|configuration\\)\\s-+\\)?"
  12367. "\\(\\w+\\)\\(\\.\\(\\w+\\)\\)?\\((\\(\\w+\\))\\)?")
  12368. '(4 font-lock-function-name-face) '(6 font-lock-function-name-face nil t)
  12369. '(8 font-lock-function-name-face nil t))
  12370. ;; highlight attribute name in attribute declarations/specifications
  12371. (list
  12372. (concat
  12373. "^\\s-*attribute\\s-+\\(\\w+\\)")
  12374. 1 'vhdl-font-lock-attribute-face)
  12375. ;; highlight type/nature name in (sub)type/(sub)nature declarations
  12376. (list
  12377. (concat
  12378. "^\\s-*\\(\\(sub\\)?\\(nature\\|type\\)\\|end\\s-+\\(record\\|protected\\)\\)\\s-+\\(\\w+\\)")
  12379. 5 'font-lock-type-face)
  12380. ;; highlight signal/variable/constant declaration names
  12381. (list "\\(:[^=]\\)"
  12382. '(vhdl-font-lock-match-item
  12383. (progn (goto-char (match-beginning 1))
  12384. (skip-syntax-backward " ")
  12385. (skip-syntax-backward "w_")
  12386. (skip-syntax-backward " ")
  12387. (while (= (preceding-char) ?,)
  12388. (backward-char 1)
  12389. (skip-syntax-backward " ")
  12390. (skip-syntax-backward "w_")
  12391. (skip-syntax-backward " ")))
  12392. (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
  12393. ;; highlight formal parameters in component instantiations and subprogram
  12394. ;; calls
  12395. (list "\\(=>\\)"
  12396. '(vhdl-font-lock-match-item
  12397. (progn (goto-char (match-beginning 1))
  12398. (skip-syntax-backward " ")
  12399. (while (= (preceding-char) ?\)) (backward-sexp))
  12400. (skip-syntax-backward "w_")
  12401. (skip-syntax-backward " ")
  12402. (when (memq (preceding-char) '(?n ?N ?|))
  12403. (goto-char (point-max))))
  12404. (goto-char (match-end 1)) (1 font-lock-variable-name-face)))
  12405. ;; highlight alias/group/quantity declaration names and for-loop/-generate
  12406. ;; variables
  12407. (list "\\<\\(alias\\|for\\|group\\|quantity\\)\\s-+\\w+\\s-+\\(across\\|in\\|is\\)\\>"
  12408. '(vhdl-font-lock-match-item
  12409. (progn (goto-char (match-end 1)) (match-beginning 2))
  12410. nil (1 font-lock-variable-name-face)))
  12411. ;; highlight tool directives
  12412. (list
  12413. (concat
  12414. "^\\s-*\\(`\\w+\\)")
  12415. 1 'font-lock-preprocessor-face)
  12416. )
  12417. "For consideration as a value of `vhdl-font-lock-keywords'.
  12418. This does context sensitive highlighting of names and labels.")
  12419. (defvar vhdl-font-lock-keywords-3 nil
  12420. ;; set in `vhdl-font-lock-init' because dependent on user options
  12421. "For consideration as a value of `vhdl-font-lock-keywords'.
  12422. This does highlighting of words with special syntax.")
  12423. (defvar vhdl-font-lock-keywords-4 nil
  12424. ;; set in `vhdl-font-lock-init' because dependent on user options
  12425. "For consideration as a value of `vhdl-font-lock-keywords'.
  12426. This does highlighting of additional reserved words.")
  12427. (defconst vhdl-font-lock-keywords-5
  12428. ;; background highlight translate-off regions
  12429. '((vhdl-match-translate-off (0 vhdl-font-lock-translate-off-face append)))
  12430. "For consideration as a value of `vhdl-font-lock-keywords'.
  12431. This does background highlighting of translate-off regions.")
  12432. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12433. ;; Font and color definitions
  12434. (defvar vhdl-font-lock-prompt-face 'vhdl-font-lock-prompt-face
  12435. "Face name to use for prompts.")
  12436. (defvar vhdl-font-lock-attribute-face 'vhdl-font-lock-attribute-face
  12437. "Face name to use for standardized attributes.")
  12438. (defvar vhdl-font-lock-enumvalue-face 'vhdl-font-lock-enumvalue-face
  12439. "Face name to use for standardized enumeration values.")
  12440. (defvar vhdl-font-lock-function-face 'vhdl-font-lock-function-face
  12441. "Face name to use for standardized functions and packages.")
  12442. (defvar vhdl-font-lock-directive-face 'vhdl-font-lock-directive-face
  12443. "Face name to use for directives.")
  12444. (defvar vhdl-font-lock-reserved-words-face 'vhdl-font-lock-reserved-words-face
  12445. "Face name to use for additional reserved words.")
  12446. (defvar vhdl-font-lock-translate-off-face 'vhdl-font-lock-translate-off-face
  12447. "Face name to use for translate-off regions.")
  12448. ;; face names to use for words with special syntax.
  12449. (let ((syntax-alist vhdl-special-syntax-alist)
  12450. name)
  12451. (while syntax-alist
  12452. (setq name (vhdl-function-name
  12453. "vhdl-font-lock" (nth 0 (car syntax-alist)) "face"))
  12454. (eval `(defvar ,name ',name
  12455. ,(concat "Face name to use for "
  12456. (nth 0 (car syntax-alist)) ".")))
  12457. (setq syntax-alist (cdr syntax-alist))))
  12458. (defgroup vhdl-highlight-faces nil
  12459. "Faces for highlighting."
  12460. :group 'vhdl-highlight)
  12461. ;; add faces used from `font-lock'
  12462. (custom-add-to-group
  12463. 'vhdl-highlight-faces 'font-lock-comment-face 'custom-face)
  12464. (custom-add-to-group
  12465. 'vhdl-highlight-faces 'font-lock-string-face 'custom-face)
  12466. (custom-add-to-group
  12467. 'vhdl-highlight-faces 'font-lock-keyword-face 'custom-face)
  12468. (custom-add-to-group
  12469. 'vhdl-highlight-faces 'font-lock-type-face 'custom-face)
  12470. (custom-add-to-group
  12471. 'vhdl-highlight-faces 'font-lock-function-name-face 'custom-face)
  12472. (custom-add-to-group
  12473. 'vhdl-highlight-faces 'font-lock-variable-name-face 'custom-face)
  12474. (defface vhdl-font-lock-prompt-face
  12475. '((((min-colors 88) (class color) (background light))
  12476. (:foreground "Red1" :bold t))
  12477. (((class color) (background light)) (:foreground "Red" :bold t))
  12478. (((class color) (background dark)) (:foreground "Pink" :bold t))
  12479. (t (:inverse-video t)))
  12480. "Font lock mode face used to highlight prompts."
  12481. :group 'vhdl-highlight-faces)
  12482. (defface vhdl-font-lock-attribute-face
  12483. '((((class color) (background light)) (:foreground "Orchid"))
  12484. (((class color) (background dark)) (:foreground "LightSteelBlue"))
  12485. (t (:italic t :bold t)))
  12486. "Font lock mode face used to highlight standardized attributes."
  12487. :group 'vhdl-highlight-faces)
  12488. (defface vhdl-font-lock-enumvalue-face
  12489. '((((class color) (background light)) (:foreground "SaddleBrown"))
  12490. (((class color) (background dark)) (:foreground "BurlyWood"))
  12491. (t (:italic t :bold t)))
  12492. "Font lock mode face used to highlight standardized enumeration values."
  12493. :group 'vhdl-highlight-faces)
  12494. (defface vhdl-font-lock-function-face
  12495. '((((class color) (background light)) (:foreground "Cyan4"))
  12496. (((class color) (background dark)) (:foreground "Orchid1"))
  12497. (t (:italic t :bold t)))
  12498. "Font lock mode face used to highlight standardized functions and packages."
  12499. :group 'vhdl-highlight-faces)
  12500. (defface vhdl-font-lock-directive-face
  12501. '((((class color) (background light)) (:foreground "CadetBlue"))
  12502. (((class color) (background dark)) (:foreground "Aquamarine"))
  12503. (t (:italic t :bold t)))
  12504. "Font lock mode face used to highlight directives."
  12505. :group 'vhdl-highlight-faces)
  12506. (defface vhdl-font-lock-reserved-words-face
  12507. '((((class color) (background light)) (:foreground "Orange" :bold t))
  12508. (((min-colors 88) (class color) (background dark))
  12509. (:foreground "Yellow1" :bold t))
  12510. (((class color) (background dark)) (:foreground "Yellow" :bold t))
  12511. (t ()))
  12512. "Font lock mode face used to highlight additional reserved words."
  12513. :group 'vhdl-highlight-faces)
  12514. (defface vhdl-font-lock-translate-off-face
  12515. '((((class color) (background light)) (:background "LightGray"))
  12516. (((class color) (background dark)) (:background "DimGray"))
  12517. (t ()))
  12518. "Font lock mode face used to background highlight translate-off regions."
  12519. :group 'vhdl-highlight-faces)
  12520. ;; font lock mode faces used to highlight words with special syntax.
  12521. (let ((syntax-alist vhdl-special-syntax-alist))
  12522. (while syntax-alist
  12523. (eval `(defface ,(vhdl-function-name
  12524. "vhdl-font-lock" (caar syntax-alist) "face")
  12525. '((((class color) (background light))
  12526. (:foreground ,(nth 2 (car syntax-alist))))
  12527. (((class color) (background dark))
  12528. (:foreground ,(nth 3 (car syntax-alist))))
  12529. (t ()))
  12530. ,(concat "Font lock mode face used to highlight "
  12531. (nth 0 (car syntax-alist)) ".")
  12532. :group 'vhdl-highlight-faces))
  12533. (setq syntax-alist (cdr syntax-alist))))
  12534. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12535. ;; Font lock initialization
  12536. (defun vhdl-font-lock-init ()
  12537. "Initialize fontification."
  12538. ;; highlight template prompts and directives
  12539. (setq vhdl-font-lock-keywords-0
  12540. (list (list (concat "\\(^\\|[ \t(.']\\)\\(<"
  12541. vhdl-template-prompt-syntax ">\\)")
  12542. 2 'vhdl-font-lock-prompt-face t)
  12543. (list (concat "--\\s-*"
  12544. vhdl-directive-keywords-regexp "\\s-+\\(.*\\)$")
  12545. 2 'vhdl-font-lock-directive-face t)
  12546. ;; highlight c-preprocessor directives
  12547. (list "^#[ \t]*\\(\\w+\\)\\([ \t]+\\(\\w+\\)\\)?"
  12548. '(1 font-lock-builtin-face)
  12549. '(3 font-lock-variable-name-face nil t))))
  12550. ;; highlight keywords and standardized types, attributes, enumeration
  12551. ;; values, and subprograms
  12552. (setq vhdl-font-lock-keywords-1
  12553. (list
  12554. (list (concat "'" vhdl-attributes-regexp)
  12555. 1 'vhdl-font-lock-attribute-face)
  12556. (list vhdl-types-regexp 1 'font-lock-type-face)
  12557. (list vhdl-functions-regexp 1 'vhdl-font-lock-function-face)
  12558. (list vhdl-packages-regexp 1 'vhdl-font-lock-function-face)
  12559. (list vhdl-enum-values-regexp 1 'vhdl-font-lock-enumvalue-face)
  12560. (list vhdl-constants-regexp 1 'font-lock-constant-face)
  12561. (list vhdl-keywords-regexp 1 'font-lock-keyword-face)))
  12562. ;; highlight words with special syntax.
  12563. (setq vhdl-font-lock-keywords-3
  12564. (let ((syntax-alist vhdl-special-syntax-alist)
  12565. keywords)
  12566. (while syntax-alist
  12567. (setq keywords
  12568. (cons
  12569. (list (concat "\\(" (nth 1 (car syntax-alist)) "\\)") 1
  12570. (vhdl-function-name
  12571. "vhdl-font-lock" (nth 0 (car syntax-alist)) "face")
  12572. (nth 4 (car syntax-alist)))
  12573. keywords))
  12574. (setq syntax-alist (cdr syntax-alist)))
  12575. keywords))
  12576. ;; highlight additional reserved words
  12577. (setq vhdl-font-lock-keywords-4
  12578. (list (list vhdl-reserved-words-regexp 1
  12579. 'vhdl-font-lock-reserved-words-face)))
  12580. ;; highlight everything together
  12581. (setq vhdl-font-lock-keywords
  12582. (append
  12583. vhdl-font-lock-keywords-0
  12584. (when vhdl-highlight-keywords vhdl-font-lock-keywords-1)
  12585. (when (or vhdl-highlight-forbidden-words
  12586. vhdl-highlight-verilog-keywords) vhdl-font-lock-keywords-4)
  12587. (when vhdl-highlight-special-words vhdl-font-lock-keywords-3)
  12588. (when vhdl-highlight-names vhdl-font-lock-keywords-2)
  12589. (when vhdl-highlight-translate-off vhdl-font-lock-keywords-5))))
  12590. ;; initialize fontification for VHDL Mode
  12591. (vhdl-font-lock-init)
  12592. (defun vhdl-fontify-buffer ()
  12593. "Re-initialize fontification and fontify buffer."
  12594. (interactive)
  12595. (setq font-lock-defaults
  12596. `(vhdl-font-lock-keywords
  12597. nil ,(not vhdl-highlight-case-sensitive) ((?\_ . "w"))
  12598. beginning-of-line))
  12599. (when (fboundp 'font-lock-unset-defaults)
  12600. (font-lock-unset-defaults)) ; not implemented in XEmacs
  12601. (font-lock-set-defaults)
  12602. (font-lock-mode nil)
  12603. (font-lock-mode t))
  12604. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12605. ;; Initialization for PostScript printing
  12606. (defun vhdl-ps-print-settings ()
  12607. "Initialize custom face and page settings for PostScript printing."
  12608. ;; define custom face settings
  12609. (unless (or (not vhdl-print-customize-faces)
  12610. ps-print-color-p)
  12611. (set (make-local-variable 'ps-bold-faces)
  12612. '(font-lock-keyword-face
  12613. font-lock-type-face
  12614. vhdl-font-lock-attribute-face
  12615. vhdl-font-lock-enumvalue-face
  12616. vhdl-font-lock-directive-face))
  12617. (set (make-local-variable 'ps-italic-faces)
  12618. '(font-lock-comment-face
  12619. font-lock-function-name-face
  12620. font-lock-type-face
  12621. vhdl-font-lock-attribute-face
  12622. vhdl-font-lock-enumvalue-face
  12623. vhdl-font-lock-directive-face))
  12624. (set (make-local-variable 'ps-underlined-faces)
  12625. '(font-lock-string-face))
  12626. (setq ps-always-build-face-reference t))
  12627. ;; define page settings, so that a line containing 79 characters (default)
  12628. ;; fits into one column
  12629. (when vhdl-print-two-column
  12630. (set (make-local-variable 'ps-landscape-mode) t)
  12631. (set (make-local-variable 'ps-number-of-columns) 2)
  12632. (set (make-local-variable 'ps-font-size) 7.0)
  12633. (set (make-local-variable 'ps-header-title-font-size) 10.0)
  12634. (set (make-local-variable 'ps-header-font-size) 9.0)
  12635. (set (make-local-variable 'ps-header-offset) 12.0)
  12636. (when (eq ps-paper-type 'letter)
  12637. (set (make-local-variable 'ps-inter-column) 40.0)
  12638. (set (make-local-variable 'ps-left-margin) 40.0)
  12639. (set (make-local-variable 'ps-right-margin) 40.0))))
  12640. (defun vhdl-ps-print-init ()
  12641. "Initialize PostScript printing."
  12642. (if (featurep 'xemacs)
  12643. (when (boundp 'ps-print-color-p)
  12644. (vhdl-ps-print-settings))
  12645. (if (featurep 'xemacs) (make-local-hook 'ps-print-hook))
  12646. (add-hook 'ps-print-hook 'vhdl-ps-print-settings nil t)))
  12647. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12648. ;;; Hierarchy browser (using `speedbar.el')
  12649. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12650. ;; Allows displaying the hierarchy of all VHDL design units contained in a
  12651. ;; directory by using the speedbar.
  12652. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12653. ;; Variables
  12654. (defvar vhdl-entity-alist nil
  12655. "Cache with entities and corresponding architectures for each
  12656. project/directory.")
  12657. ;; structure: (parenthesized expression means list of such entries)
  12658. ;; (cache-key
  12659. ;; (ent-key ent-name ent-file ent-line
  12660. ;; (arch-key arch-name arch-file arch-line
  12661. ;; (inst-key inst-name inst-file inst-line inst-comp-name inst-ent-key
  12662. ;; inst-arch-key inst-conf-key inst-lib-key inst-path)
  12663. ;; (lib-name pack-key))
  12664. ;; mra-key (lib-name pack-key))
  12665. (defvar vhdl-config-alist nil
  12666. "Cache with configurations for each project/directory.")
  12667. ;; structure: (parenthesized expression means list of such entries)
  12668. ;; (cache-key
  12669. ;; (conf-key conf-name conf-file conf-line ent-key arch-key
  12670. ;; (inst-key inst-comp-name inst-ent-key inst-arch-key
  12671. ;; inst-conf-key inst-lib-key)
  12672. ;; (lib-name pack-key)))
  12673. (defvar vhdl-package-alist nil
  12674. "Cache with packages for each project/directory.")
  12675. ;; structure: (parenthesized expression means list of such entries)
  12676. ;; (cache-key
  12677. ;; (pack-key pack-name pack-file pack-line
  12678. ;; (comp-key comp-name comp-file comp-line)
  12679. ;; (func-key func-name func-file func-line)
  12680. ;; (lib-name pack-key)
  12681. ;; pack-body-file pack-body-line
  12682. ;; (func-key func-name func-body-file func-body-line)
  12683. ;; (lib-name pack-key)))
  12684. (defvar vhdl-ent-inst-alist nil
  12685. "Cache with instantiated entities for each project/directory.")
  12686. ;; structure: (parenthesized expression means list of such entries)
  12687. ;; (cache-key (inst-ent-key))
  12688. (defvar vhdl-file-alist nil
  12689. "Cache with design units in each file for each project/directory.")
  12690. ;; structure: (parenthesized expression means list of such entries)
  12691. ;; (cache-key
  12692. ;; (file-name (ent-list) (arch-list) (arch-ent-list) (conf-list)
  12693. ;; (pack-list) (pack-body-list) (inst-list) (inst-ent-list))
  12694. (defvar vhdl-directory-alist nil
  12695. "Cache with source directories for each project.")
  12696. ;; structure: (parenthesized expression means list of such entries)
  12697. ;; (cache-key (directory))
  12698. (defvar vhdl-speedbar-shown-unit-alist nil
  12699. "Alist of design units simultaneously open in the current speedbar for each
  12700. directory and project.")
  12701. (defvar vhdl-speedbar-shown-project-list nil
  12702. "List of projects simultaneously open in the current speedbar.")
  12703. (defvar vhdl-updated-project-list nil
  12704. "List of projects and directories with updated files.")
  12705. (defvar vhdl-modified-file-list nil
  12706. "List of modified files to be rescanned for hierarchy updating.")
  12707. (defvar vhdl-speedbar-hierarchy-depth 0
  12708. "Depth of instantiation hierarchy to display.")
  12709. (defvar vhdl-speedbar-show-projects nil
  12710. "Non-nil means project hierarchy is displayed in speedbar, directory
  12711. hierarchy otherwise.")
  12712. (defun vhdl-get-end-of-unit ()
  12713. "Return position of end of current unit."
  12714. (let ((pos (point)))
  12715. (save-excursion
  12716. (while (and (re-search-forward "^[ \t]*\\(architecture\\|configuration\\|context\\|entity\\|package\\)\\>" nil 1)
  12717. (save-excursion
  12718. (goto-char (match-beginning 0))
  12719. (vhdl-backward-syntactic-ws)
  12720. (and (/= (preceding-char) ?\;) (not (bobp))))))
  12721. (re-search-backward "^[ \t]*end\\>" pos 1)
  12722. (point))))
  12723. (defun vhdl-match-string-downcase (num &optional string)
  12724. "Like `match-string-no-properties' with down-casing."
  12725. (let ((match (match-string-no-properties num string)))
  12726. (and match (downcase match))))
  12727. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12728. ;; Scan functions
  12729. (defun vhdl-scan-context-clause ()
  12730. "Scan the context clause that precedes a design unit."
  12731. (let (lib-alist)
  12732. (save-excursion
  12733. (when (re-search-backward "^[ \t]*\\(architecture\\|configuration\\|context\\|entity\\|package\\)\\>" nil t)
  12734. (while (and (re-search-backward "^[ \t]*\\(end\\|use\\)\\>" nil t)
  12735. (equal "USE" (upcase (match-string 1))))
  12736. (when (looking-at "^[ \t]*use[ \t\n\r\f]*\\(\\w+\\)\\.\\(\\w+\\)\\.\\w+")
  12737. (push (cons (match-string-no-properties 1)
  12738. (vhdl-match-string-downcase 2))
  12739. lib-alist)))))
  12740. lib-alist))
  12741. (defun vhdl-scan-directory-contents (name &optional project update num-string
  12742. non-final)
  12743. "Scan contents of VHDL files in directory or file pattern NAME."
  12744. (string-match "\\(.*[/\\]\\)\\(.*\\)" name)
  12745. (let* ((dir-name (match-string 1 name))
  12746. (file-pattern (match-string 2 name))
  12747. (is-directory (= 0 (length file-pattern)))
  12748. (file-list
  12749. (if update
  12750. (list name)
  12751. (if is-directory
  12752. (vhdl-get-source-files t dir-name)
  12753. (vhdl-directory-files
  12754. dir-name t (wildcard-to-regexp file-pattern)))))
  12755. (key (or project dir-name))
  12756. (file-exclude-regexp
  12757. (or (nth 3 (vhdl-aget vhdl-project-alist project)) ""))
  12758. (limit-design-file-size (nth 0 vhdl-speedbar-scan-limit))
  12759. (limit-hier-file-size (nth 0 (nth 1 vhdl-speedbar-scan-limit)))
  12760. (limit-hier-inst-no (nth 1 (nth 1 vhdl-speedbar-scan-limit)))
  12761. ent-alist conf-alist pack-alist ent-inst-list file-alist
  12762. tmp-list tmp-entry no-files files-exist big-files)
  12763. (when (or project update)
  12764. (setq ent-alist (vhdl-aget vhdl-entity-alist key)
  12765. conf-alist (vhdl-aget vhdl-config-alist key)
  12766. pack-alist (vhdl-aget vhdl-package-alist key)
  12767. ent-inst-list (car (vhdl-aget vhdl-ent-inst-alist key))
  12768. file-alist (vhdl-aget vhdl-file-alist key)))
  12769. (when (and (not is-directory) (null file-list))
  12770. (message "No such file: \"%s\"" name))
  12771. (setq files-exist file-list)
  12772. (when file-list
  12773. (setq no-files (length file-list))
  12774. (message "Scanning %s %s\"%s\"..."
  12775. (if is-directory "directory" "files") (or num-string "") name)
  12776. ;; exclude files
  12777. (unless (equal file-exclude-regexp "")
  12778. (let ((case-fold-search nil)
  12779. file-tmp-list)
  12780. (while file-list
  12781. (unless (string-match file-exclude-regexp (car file-list))
  12782. (push (car file-list) file-tmp-list))
  12783. (setq file-list (cdr file-list)))
  12784. (setq file-list (nreverse file-tmp-list))))
  12785. ;; do for all files
  12786. (while file-list
  12787. (unless noninteractive
  12788. (message "Scanning %s %s\"%s\"... (%2d%%)"
  12789. (if is-directory "directory" "files")
  12790. (or num-string "") name
  12791. (floor (* 100.0 (- no-files (length file-list))) no-files)))
  12792. (let ((file-name (abbreviate-file-name (car file-list)))
  12793. ent-list arch-list arch-ent-list conf-list
  12794. pack-list pack-body-list inst-list inst-ent-list)
  12795. ;; scan file
  12796. (vhdl-visit-file
  12797. file-name nil
  12798. (vhdl-prepare-search-2
  12799. (save-excursion
  12800. ;; scan for design units
  12801. (if (and limit-design-file-size
  12802. (< limit-design-file-size (buffer-size)))
  12803. (progn (message "WARNING: Scan limit (design units: file size) reached in file:\n \"%s\"" file-name)
  12804. (setq big-files t))
  12805. ;; scan for entities
  12806. (goto-char (point-min))
  12807. (while (re-search-forward "^[ \t]*entity[ \t\n\r\f]+\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
  12808. (let* ((ent-name (match-string-no-properties 1))
  12809. (ent-key (downcase ent-name))
  12810. (ent-entry (vhdl-aget ent-alist ent-key))
  12811. (lib-alist (vhdl-scan-context-clause)))
  12812. (if (nth 1 ent-entry)
  12813. (vhdl-warning-when-idle
  12814. "Entity declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
  12815. ent-name (nth 1 ent-entry) (nth 2 ent-entry)
  12816. file-name (vhdl-current-line))
  12817. (push ent-key ent-list)
  12818. (vhdl-aput 'ent-alist ent-key
  12819. (list ent-name file-name (vhdl-current-line)
  12820. (nth 3 ent-entry) (nth 4 ent-entry)
  12821. lib-alist)))))
  12822. ;; scan for architectures
  12823. (goto-char (point-min))
  12824. (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)
  12825. (let* ((arch-name (match-string-no-properties 1))
  12826. (arch-key (downcase arch-name))
  12827. (ent-name (match-string-no-properties 2))
  12828. (ent-key (downcase ent-name))
  12829. (ent-entry (vhdl-aget ent-alist ent-key))
  12830. (arch-alist (nth 3 ent-entry))
  12831. (arch-entry (vhdl-aget arch-alist arch-key))
  12832. (lib-arch-alist (vhdl-scan-context-clause)))
  12833. (if arch-entry
  12834. (vhdl-warning-when-idle
  12835. "Architecture declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
  12836. arch-name ent-name (nth 1 arch-entry)
  12837. (nth 2 arch-entry) file-name (vhdl-current-line))
  12838. (setq arch-list (cons arch-key arch-list)
  12839. arch-ent-list (cons ent-key arch-ent-list))
  12840. (vhdl-aput 'arch-alist arch-key
  12841. (list arch-name file-name (vhdl-current-line)
  12842. nil lib-arch-alist))
  12843. (vhdl-aput 'ent-alist ent-key
  12844. (list (or (nth 0 ent-entry) ent-name)
  12845. (nth 1 ent-entry) (nth 2 ent-entry)
  12846. (vhdl-sort-alist arch-alist)
  12847. arch-key (nth 5 ent-entry))))))
  12848. ;; scan for configurations
  12849. (goto-char (point-min))
  12850. (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)
  12851. (let* ((conf-name (match-string-no-properties 1))
  12852. (conf-key (downcase conf-name))
  12853. (conf-entry (vhdl-aget conf-alist conf-key))
  12854. (ent-name (match-string-no-properties 2))
  12855. (ent-key (downcase ent-name))
  12856. (lib-alist (vhdl-scan-context-clause))
  12857. (conf-line (vhdl-current-line))
  12858. (end-of-unit (vhdl-get-end-of-unit))
  12859. arch-key comp-conf-list inst-key-list
  12860. inst-comp-key inst-ent-key inst-arch-key
  12861. inst-conf-key inst-lib-key)
  12862. (when (vhdl-re-search-forward "\\<for[ \t\n\r\f]+\\(\\w+\\)")
  12863. (setq arch-key (vhdl-match-string-downcase 1)))
  12864. (if conf-entry
  12865. (vhdl-warning-when-idle
  12866. "Configuration declared twice (used 1.): \"%s\" of \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
  12867. conf-name ent-name (nth 1 conf-entry)
  12868. (nth 2 conf-entry) file-name conf-line)
  12869. (push conf-key conf-list)
  12870. ;; scan for subconfigurations and subentities
  12871. (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)
  12872. (setq inst-comp-key (vhdl-match-string-downcase 3)
  12873. inst-key-list (split-string
  12874. (vhdl-match-string-downcase 1)
  12875. "[ \t\n\r\f]*,[ \t\n\r\f]*"))
  12876. (vhdl-forward-syntactic-ws)
  12877. (when (looking-at "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\w+\\)\\.\\(\\w+\\)[ \t\n\r\f]*\\((\\(\\w+\\))\\)?")
  12878. (setq
  12879. inst-lib-key (vhdl-match-string-downcase 3)
  12880. inst-ent-key (and (match-string 2)
  12881. (vhdl-match-string-downcase 4))
  12882. inst-arch-key (and (match-string 2)
  12883. (vhdl-match-string-downcase 6))
  12884. inst-conf-key (and (not (match-string 2))
  12885. (vhdl-match-string-downcase 4)))
  12886. (while inst-key-list
  12887. (setq comp-conf-list
  12888. (cons (list (car inst-key-list)
  12889. inst-comp-key inst-ent-key
  12890. inst-arch-key inst-conf-key
  12891. inst-lib-key)
  12892. comp-conf-list))
  12893. (setq inst-key-list (cdr inst-key-list)))))
  12894. (vhdl-aput 'conf-alist conf-key
  12895. (list conf-name file-name conf-line ent-key
  12896. arch-key comp-conf-list lib-alist)))))
  12897. ;; scan for packages
  12898. (goto-char (point-min))
  12899. (while (re-search-forward "^[ \t]*package[ \t\n\r\f]+\\(body[ \t\n\r\f]+\\)?\\(\\w+\\)[ \t\n\r\f]+is\\>" nil t)
  12900. (let* ((pack-name (match-string-no-properties 2))
  12901. (pack-key (downcase pack-name))
  12902. (is-body (match-string-no-properties 1))
  12903. (pack-entry (vhdl-aget pack-alist pack-key))
  12904. (pack-line (vhdl-current-line))
  12905. (end-of-unit (vhdl-get-end-of-unit))
  12906. comp-name func-name comp-alist func-alist lib-alist)
  12907. (if (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
  12908. (vhdl-warning-when-idle
  12909. "Package%s declared twice (used 1.): \"%s\"\n 1. in \"%s\" (line %d)\n 2. in \"%s\" (line %d)"
  12910. (if is-body " body" "") pack-name
  12911. (if is-body (nth 6 pack-entry) (nth 1 pack-entry))
  12912. (if is-body (nth 7 pack-entry) (nth 2 pack-entry))
  12913. file-name (vhdl-current-line))
  12914. ;; scan for context clauses
  12915. (setq lib-alist (vhdl-scan-context-clause))
  12916. ;; scan for component and subprogram declarations/bodies
  12917. (while (re-search-forward "^[ \t]*\\(component\\|function\\|procedure\\)[ \t\n\r\f]+\\(\\w+\\|\".*\"\\)" end-of-unit t)
  12918. (if (equal (upcase (match-string 1)) "COMPONENT")
  12919. (setq comp-name (match-string-no-properties 2)
  12920. comp-alist
  12921. (cons (list (downcase comp-name) comp-name
  12922. file-name (vhdl-current-line))
  12923. comp-alist))
  12924. (setq func-name (match-string-no-properties 2)
  12925. func-alist
  12926. (cons (list (downcase func-name) func-name
  12927. file-name (vhdl-current-line))
  12928. func-alist))))
  12929. (setq func-alist (nreverse func-alist))
  12930. (setq comp-alist (nreverse comp-alist))
  12931. (if is-body
  12932. (push pack-key pack-body-list)
  12933. (push pack-key pack-list))
  12934. (vhdl-aput
  12935. 'pack-alist pack-key
  12936. (if is-body
  12937. (list (or (nth 0 pack-entry) pack-name)
  12938. (nth 1 pack-entry) (nth 2 pack-entry)
  12939. (nth 3 pack-entry) (nth 4 pack-entry)
  12940. (nth 5 pack-entry)
  12941. file-name pack-line func-alist lib-alist)
  12942. (list pack-name file-name pack-line
  12943. comp-alist func-alist lib-alist
  12944. (nth 6 pack-entry) (nth 7 pack-entry)
  12945. (nth 8 pack-entry) (nth 9 pack-entry))))))))
  12946. ;; scan for hierarchy
  12947. (if (and limit-hier-file-size
  12948. (< limit-hier-file-size (buffer-size)))
  12949. (progn (message "WARNING: Scan limit (hierarchy: file size) reached in file:\n \"%s\"" file-name)
  12950. (setq big-files t))
  12951. ;; scan for architectures
  12952. (goto-char (point-min))
  12953. (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)
  12954. (let* ((ent-name (match-string-no-properties 2))
  12955. (ent-key (downcase ent-name))
  12956. (arch-name (match-string-no-properties 1))
  12957. (arch-key (downcase arch-name))
  12958. (ent-entry (vhdl-aget ent-alist ent-key))
  12959. (arch-alist (nth 3 ent-entry))
  12960. (arch-entry (vhdl-aget arch-alist arch-key))
  12961. (beg-of-unit (point))
  12962. (end-of-unit (vhdl-get-end-of-unit))
  12963. (inst-no 0)
  12964. inst-alist inst-path)
  12965. ;; scan for contained instantiations
  12966. (while (and (re-search-forward
  12967. (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
  12968. "\\(\\w+\\)[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(generic\\|port\\)[ \t\n\r\f]+map\\>\\|"
  12969. "component[ \t\n\r\f]+\\(\\w+\\)\\|"
  12970. "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?\\|"
  12971. "\\(\\(for\\|if\\)\\>[^;:]+\\<generate\\>\\|block\\>\\)\\)\\|"
  12972. "\\(^[ \t]*end[ \t\n\r\f]+\\(generate\\|block\\)\\>\\)") end-of-unit t)
  12973. (or (not limit-hier-inst-no)
  12974. (<= (if (or (match-string 14)
  12975. (match-string 16))
  12976. inst-no
  12977. (setq inst-no (1+ inst-no)))
  12978. limit-hier-inst-no)))
  12979. (cond
  12980. ;; block/generate beginning found
  12981. ((match-string 14)
  12982. (setq inst-path
  12983. (cons (match-string-no-properties 1) inst-path)))
  12984. ;; block/generate end found
  12985. ((match-string 16)
  12986. (setq inst-path (cdr inst-path)))
  12987. ;; instantiation found
  12988. (t
  12989. (let* ((inst-name (match-string-no-properties 1))
  12990. (inst-key (downcase inst-name))
  12991. (inst-comp-name
  12992. (or (match-string-no-properties 3)
  12993. (match-string-no-properties 6)))
  12994. (inst-ent-key
  12995. (or (and (match-string 8)
  12996. (vhdl-match-string-downcase 11))
  12997. (and inst-comp-name
  12998. (downcase inst-comp-name))))
  12999. (inst-arch-key (vhdl-match-string-downcase 13))
  13000. (inst-conf-key
  13001. (and (not (match-string 8))
  13002. (vhdl-match-string-downcase 11)))
  13003. (inst-lib-key (vhdl-match-string-downcase 10)))
  13004. (goto-char (match-end 1))
  13005. (setq inst-list (cons inst-key inst-list)
  13006. inst-ent-list
  13007. (cons inst-ent-key inst-ent-list))
  13008. (setq inst-alist
  13009. (append
  13010. inst-alist
  13011. (list (list inst-key inst-name file-name
  13012. (vhdl-current-line) inst-comp-name
  13013. inst-ent-key inst-arch-key
  13014. inst-conf-key inst-lib-key
  13015. (reverse inst-path)))))))))
  13016. ;; scan for contained configuration specifications
  13017. (goto-char beg-of-unit)
  13018. (while (re-search-forward
  13019. (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]*\\)*"
  13020. "use[ \t\n\r\f]+\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?") end-of-unit t)
  13021. (let* ((inst-comp-name (match-string-no-properties 3))
  13022. (inst-ent-key
  13023. (and (match-string 6)
  13024. (vhdl-match-string-downcase 9)))
  13025. (inst-arch-key (vhdl-match-string-downcase 11))
  13026. (inst-conf-key
  13027. (and (not (match-string 6))
  13028. (vhdl-match-string-downcase 9)))
  13029. (inst-lib-key (vhdl-match-string-downcase 8))
  13030. (inst-key-list
  13031. (split-string (vhdl-match-string-downcase 1)
  13032. "[ \t\n\r\f]*,[ \t\n\r\f]*"))
  13033. (tmp-inst-alist inst-alist)
  13034. inst-entry)
  13035. (while tmp-inst-alist
  13036. (when (and (or (equal "all" (car inst-key-list))
  13037. (member (nth 0 (car tmp-inst-alist))
  13038. inst-key-list))
  13039. (equal
  13040. (downcase
  13041. (or (nth 4 (car tmp-inst-alist)) ""))
  13042. (downcase inst-comp-name)))
  13043. (setq inst-entry (car tmp-inst-alist))
  13044. (setq inst-ent-list
  13045. (cons (or inst-ent-key (nth 5 inst-entry))
  13046. (vhdl-delete
  13047. (nth 5 inst-entry) inst-ent-list)))
  13048. (setq inst-entry
  13049. (list (nth 0 inst-entry) (nth 1 inst-entry)
  13050. (nth 2 inst-entry) (nth 3 inst-entry)
  13051. (nth 4 inst-entry)
  13052. (or inst-ent-key (nth 5 inst-entry))
  13053. (or inst-arch-key (nth 6 inst-entry))
  13054. inst-conf-key inst-lib-key))
  13055. (setcar tmp-inst-alist inst-entry))
  13056. (setq tmp-inst-alist (cdr tmp-inst-alist)))))
  13057. ;; save in cache
  13058. (vhdl-aput 'arch-alist arch-key
  13059. (list (nth 0 arch-entry) (nth 1 arch-entry)
  13060. (nth 2 arch-entry) inst-alist
  13061. (nth 4 arch-entry)))
  13062. (vhdl-aput 'ent-alist ent-key
  13063. (list (nth 0 ent-entry) (nth 1 ent-entry)
  13064. (nth 2 ent-entry)
  13065. (vhdl-sort-alist arch-alist)
  13066. (nth 4 ent-entry) (nth 5 ent-entry)))
  13067. (when (and limit-hier-inst-no
  13068. (> inst-no limit-hier-inst-no))
  13069. (message "WARNING: Scan limit (hierarchy: instances per architecture) reached in file:\n \"%s\"" file-name)
  13070. (setq big-files t))
  13071. (goto-char end-of-unit))))
  13072. ;; remember design units for this file
  13073. (vhdl-aput 'file-alist file-name
  13074. (list ent-list arch-list arch-ent-list conf-list
  13075. pack-list pack-body-list
  13076. inst-list inst-ent-list))
  13077. (setq ent-inst-list (append inst-ent-list ent-inst-list))))))
  13078. (setq file-list (cdr file-list))))
  13079. (when (or (and (not project) files-exist)
  13080. (and project (not non-final)))
  13081. ;; consistency checks:
  13082. ;; check whether each architecture has a corresponding entity
  13083. (setq tmp-list ent-alist)
  13084. (while tmp-list
  13085. (when (null (nth 2 (car tmp-list)))
  13086. (setq tmp-entry (car (nth 4 (car tmp-list))))
  13087. (vhdl-warning-when-idle
  13088. "Architecture of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
  13089. (nth 1 tmp-entry) (nth 1 (car tmp-list)) (nth 2 tmp-entry)
  13090. (nth 3 tmp-entry)))
  13091. (setq tmp-list (cdr tmp-list)))
  13092. ;; check whether configuration has a corresponding entity/architecture
  13093. (setq tmp-list conf-alist)
  13094. (while tmp-list
  13095. (if (setq tmp-entry (vhdl-aget ent-alist (nth 4 (car tmp-list))))
  13096. (unless (vhdl-aget (nth 3 tmp-entry) (nth 5 (car tmp-list)))
  13097. (setq tmp-entry (car tmp-list))
  13098. (vhdl-warning-when-idle
  13099. "Configuration of non-existing architecture: \"%s\" of \"%s(%s)\"\n in \"%s\" (line %d)"
  13100. (nth 1 tmp-entry) (nth 4 tmp-entry) (nth 5 tmp-entry)
  13101. (nth 2 tmp-entry) (nth 3 tmp-entry)))
  13102. (setq tmp-entry (car tmp-list))
  13103. (vhdl-warning-when-idle
  13104. "Configuration of non-existing entity: \"%s\" of \"%s\"\n in \"%s\" (line %d)"
  13105. (nth 1 tmp-entry) (nth 4 tmp-entry)
  13106. (nth 2 tmp-entry) (nth 3 tmp-entry)))
  13107. (setq tmp-list (cdr tmp-list)))
  13108. ;; check whether each package body has a package declaration
  13109. (setq tmp-list pack-alist)
  13110. (while tmp-list
  13111. (when (null (nth 2 (car tmp-list)))
  13112. (setq tmp-entry (car tmp-list))
  13113. (vhdl-warning-when-idle
  13114. "Package body of non-existing package: \"%s\"\n in \"%s\" (line %d)"
  13115. (nth 1 tmp-entry) (nth 7 tmp-entry) (nth 8 tmp-entry)))
  13116. (setq tmp-list (cdr tmp-list)))
  13117. ;; sort lists
  13118. (setq ent-alist (vhdl-sort-alist ent-alist))
  13119. (setq conf-alist (vhdl-sort-alist conf-alist))
  13120. (setq pack-alist (vhdl-sort-alist pack-alist))
  13121. ;; remember updated directory/project
  13122. (add-to-list 'vhdl-updated-project-list (or project dir-name)))
  13123. ;; clear directory alists
  13124. (unless project
  13125. (vhdl-adelete 'vhdl-entity-alist key)
  13126. (vhdl-adelete 'vhdl-config-alist key)
  13127. (vhdl-adelete 'vhdl-package-alist key)
  13128. (vhdl-adelete 'vhdl-ent-inst-alist key)
  13129. (vhdl-adelete 'vhdl-file-alist key))
  13130. ;; put directory contents into cache
  13131. (vhdl-aput 'vhdl-entity-alist key ent-alist)
  13132. (vhdl-aput 'vhdl-config-alist key conf-alist)
  13133. (vhdl-aput 'vhdl-package-alist key pack-alist)
  13134. (vhdl-aput 'vhdl-ent-inst-alist key (list ent-inst-list))
  13135. (vhdl-aput 'vhdl-file-alist key file-alist)
  13136. ;; final messages
  13137. (message "Scanning %s %s\"%s\"...done"
  13138. (if is-directory "directory" "files") (or num-string "") name)
  13139. (unless project (message "Scanning directory...done"))
  13140. (when big-files
  13141. (vhdl-warning-when-idle "Scanning is incomplete.\n --> see user option `vhdl-speedbar-scan-limit'"))
  13142. ;; save cache when scanned non-interactively
  13143. (when (or (not project) (not non-final))
  13144. (when (and noninteractive vhdl-speedbar-save-cache)
  13145. (vhdl-save-cache key)))
  13146. t))
  13147. (defun vhdl-scan-project-contents (project)
  13148. "Scan the contents of all VHDL files found in the directories and files
  13149. of PROJECT."
  13150. (let ((dir-list (or (nth 2 (vhdl-aget vhdl-project-alist project)) '("")))
  13151. (default-dir (vhdl-resolve-env-variable
  13152. (nth 1 (vhdl-aget vhdl-project-alist project))))
  13153. (file-exclude-regexp
  13154. (or (nth 3 (vhdl-aget vhdl-project-alist project)) ""))
  13155. dir-list-tmp dir dir-name num-dir act-dir recursive)
  13156. ;; clear project alists
  13157. (vhdl-adelete 'vhdl-entity-alist project)
  13158. (vhdl-adelete 'vhdl-config-alist project)
  13159. (vhdl-adelete 'vhdl-package-alist project)
  13160. (vhdl-adelete 'vhdl-ent-inst-alist project)
  13161. (vhdl-adelete 'vhdl-file-alist project)
  13162. ;; expand directory names by default-directory
  13163. (message "Collecting source files...")
  13164. (while dir-list
  13165. (setq dir (vhdl-resolve-env-variable (car dir-list)))
  13166. (string-match "\\(\\(-r \\)?\\)\\(.*\\)" dir)
  13167. (setq recursive (match-string 1 dir)
  13168. dir-name (match-string 3 dir))
  13169. (setq dir-list-tmp
  13170. (cons (concat recursive
  13171. (if (file-name-absolute-p dir-name) "" default-dir)
  13172. dir-name)
  13173. dir-list-tmp))
  13174. (setq dir-list (cdr dir-list)))
  13175. ;; resolve path wildcards
  13176. (setq dir-list-tmp (vhdl-resolve-paths dir-list-tmp))
  13177. ;; expand directories
  13178. (while dir-list-tmp
  13179. (setq dir (car dir-list-tmp))
  13180. ;; get subdirectories
  13181. (if (string-match "-r \\(.*[/\\]\\)" dir)
  13182. (setq dir-list (append dir-list (vhdl-get-subdirs
  13183. (match-string 1 dir))))
  13184. (setq dir-list (append dir-list (list dir))))
  13185. (setq dir-list-tmp (cdr dir-list-tmp)))
  13186. ;; exclude files
  13187. (unless (equal file-exclude-regexp "")
  13188. (let ((case-fold-search nil))
  13189. (while dir-list
  13190. (unless (string-match file-exclude-regexp (car dir-list))
  13191. (push (car dir-list) dir-list-tmp))
  13192. (setq dir-list (cdr dir-list)))
  13193. (setq dir-list (nreverse dir-list-tmp))))
  13194. (message "Collecting source files...done")
  13195. ;; scan for design units for each directory in DIR-LIST
  13196. (setq dir-list-tmp nil
  13197. num-dir (length dir-list)
  13198. act-dir 1)
  13199. (while dir-list
  13200. (setq dir-name (abbreviate-file-name
  13201. (expand-file-name (car dir-list))))
  13202. (vhdl-scan-directory-contents dir-name project nil
  13203. (format "(%s/%s) " act-dir num-dir)
  13204. (cdr dir-list))
  13205. (add-to-list 'dir-list-tmp (file-name-directory dir-name))
  13206. (setq dir-list (cdr dir-list)
  13207. act-dir (1+ act-dir)))
  13208. (vhdl-aput 'vhdl-directory-alist project (list (nreverse dir-list-tmp)))
  13209. (message "Scanning project \"%s\"...done" project)))
  13210. (defun vhdl-update-file-contents (file-name)
  13211. "Update hierarchy information by contents of current buffer."
  13212. (setq file-name (abbreviate-file-name file-name))
  13213. (let* ((dir-name (file-name-directory file-name))
  13214. (directory-alist vhdl-directory-alist)
  13215. updated)
  13216. (while directory-alist
  13217. (when (member dir-name (nth 1 (car directory-alist)))
  13218. (let* ((vhdl-project (nth 0 (car directory-alist)))
  13219. (project (vhdl-project-p))
  13220. (ent-alist (vhdl-aget vhdl-entity-alist
  13221. (or project dir-name)))
  13222. (conf-alist (vhdl-aget vhdl-config-alist
  13223. (or project dir-name)))
  13224. (pack-alist (vhdl-aget vhdl-package-alist
  13225. (or project dir-name)))
  13226. (ent-inst-list (car (vhdl-aget vhdl-ent-inst-alist
  13227. (or project dir-name))))
  13228. (file-alist (vhdl-aget vhdl-file-alist (or project dir-name)))
  13229. (file-entry (vhdl-aget file-alist file-name))
  13230. (ent-list (nth 0 file-entry))
  13231. (arch-list (nth 1 file-entry))
  13232. (arch-ent-list (nth 2 file-entry))
  13233. (conf-list (nth 3 file-entry))
  13234. (pack-list (nth 4 file-entry))
  13235. (pack-body-list (nth 5 file-entry))
  13236. (inst-ent-list (nth 7 file-entry))
  13237. (cache-key (or project dir-name))
  13238. arch-alist key ent-key entry)
  13239. ;; delete design units previously contained in this file:
  13240. ;; entities
  13241. (while ent-list
  13242. (setq key (car ent-list)
  13243. entry (vhdl-aget ent-alist key))
  13244. (when (equal file-name (nth 1 entry))
  13245. (if (nth 3 entry)
  13246. (vhdl-aput 'ent-alist key
  13247. (list (nth 0 entry) nil nil (nth 3 entry) nil))
  13248. (vhdl-adelete 'ent-alist key)))
  13249. (setq ent-list (cdr ent-list)))
  13250. ;; architectures
  13251. (while arch-list
  13252. (setq key (car arch-list)
  13253. ent-key (car arch-ent-list)
  13254. entry (vhdl-aget ent-alist ent-key)
  13255. arch-alist (nth 3 entry))
  13256. (when (equal file-name (nth 1 (vhdl-aget arch-alist key)))
  13257. (vhdl-adelete 'arch-alist key)
  13258. (if (or (nth 1 entry) arch-alist)
  13259. (vhdl-aput 'ent-alist ent-key
  13260. (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
  13261. arch-alist (nth 4 entry) (nth 5 entry)))
  13262. (vhdl-adelete 'ent-alist ent-key)))
  13263. (setq arch-list (cdr arch-list)
  13264. arch-ent-list (cdr arch-ent-list)))
  13265. ;; configurations
  13266. (while conf-list
  13267. (setq key (car conf-list))
  13268. (when (equal file-name (nth 1 (vhdl-aget conf-alist key)))
  13269. (vhdl-adelete 'conf-alist key))
  13270. (setq conf-list (cdr conf-list)))
  13271. ;; package declarations
  13272. (while pack-list
  13273. (setq key (car pack-list)
  13274. entry (vhdl-aget pack-alist key))
  13275. (when (equal file-name (nth 1 entry))
  13276. (if (nth 6 entry)
  13277. (vhdl-aput 'pack-alist key
  13278. (list (nth 0 entry) nil nil nil nil nil
  13279. (nth 6 entry) (nth 7 entry) (nth 8 entry)
  13280. (nth 9 entry)))
  13281. (vhdl-adelete 'pack-alist key)))
  13282. (setq pack-list (cdr pack-list)))
  13283. ;; package bodies
  13284. (while pack-body-list
  13285. (setq key (car pack-body-list)
  13286. entry (vhdl-aget pack-alist key))
  13287. (when (equal file-name (nth 6 entry))
  13288. (if (nth 1 entry)
  13289. (vhdl-aput 'pack-alist key
  13290. (list (nth 0 entry) (nth 1 entry) (nth 2 entry)
  13291. (nth 3 entry) (nth 4 entry) (nth 5 entry)
  13292. nil nil nil nil))
  13293. (vhdl-adelete 'pack-alist key)))
  13294. (setq pack-body-list (cdr pack-body-list)))
  13295. ;; instantiated entities
  13296. (while inst-ent-list
  13297. (setq ent-inst-list
  13298. (vhdl-delete (car inst-ent-list) ent-inst-list))
  13299. (setq inst-ent-list (cdr inst-ent-list)))
  13300. ;; update caches
  13301. (vhdl-aput-delete-if-nil 'vhdl-entity-alist cache-key ent-alist)
  13302. (vhdl-aput-delete-if-nil 'vhdl-config-alist cache-key conf-alist)
  13303. (vhdl-aput-delete-if-nil 'vhdl-package-alist cache-key pack-alist)
  13304. (vhdl-aput-delete-if-nil 'vhdl-ent-inst-alist cache-key (list ent-inst-list))
  13305. ;; scan file
  13306. (vhdl-scan-directory-contents file-name project t)
  13307. (when (or (and vhdl-speedbar-show-projects project)
  13308. (and (not vhdl-speedbar-show-projects) (not project)))
  13309. (vhdl-speedbar-refresh project))
  13310. (setq updated t)))
  13311. (setq directory-alist (cdr directory-alist)))
  13312. updated))
  13313. (defun vhdl-update-hierarchy ()
  13314. "Update directory and hierarchy information in speedbar."
  13315. (let ((file-list (reverse vhdl-modified-file-list))
  13316. updated)
  13317. (when (and vhdl-speedbar-update-on-saving file-list)
  13318. (while file-list
  13319. (setq updated
  13320. (or (vhdl-update-file-contents (car file-list))
  13321. updated))
  13322. (setq file-list (cdr file-list)))
  13323. (setq vhdl-modified-file-list nil)
  13324. (vhdl-speedbar-update-current-unit)
  13325. (when updated (message "Updating hierarchy...done")))))
  13326. ;; structure (parenthesized expression means list of such entries)
  13327. ;; (inst-key inst-file-marker comp-ent-key comp-ent-file-marker
  13328. ;; comp-arch-key comp-arch-file-marker comp-conf-key comp-conf-file-marker
  13329. ;; comp-lib-name level)
  13330. (defun vhdl-get-hierarchy (ent-alist conf-alist ent-key arch-key conf-key
  13331. conf-inst-alist level indent
  13332. &optional include-top ent-hier)
  13333. "Get instantiation hierarchy beginning in architecture ARCH-KEY of
  13334. entity ENT-KEY."
  13335. (let* ((ent-entry (vhdl-aget ent-alist ent-key))
  13336. (arch-entry (if arch-key (vhdl-aget (nth 3 ent-entry) arch-key)
  13337. (cdar (last (nth 3 ent-entry)))))
  13338. (inst-alist (nth 3 arch-entry))
  13339. inst-entry inst-ent-entry inst-arch-entry inst-conf-entry comp-entry
  13340. hier-list subcomp-list tmp-list inst-key inst-comp-name
  13341. inst-ent-key inst-arch-key inst-conf-key inst-lib-key)
  13342. (when (= level 0) (message "Extract design hierarchy..."))
  13343. (when include-top
  13344. (setq level (1+ level)))
  13345. (when (member ent-key ent-hier)
  13346. (error "ERROR: Instantiation loop detected, component instantiates itself: \"%s\"" ent-key))
  13347. ;; process all instances
  13348. (while inst-alist
  13349. (setq inst-entry (car inst-alist)
  13350. inst-key (nth 0 inst-entry)
  13351. inst-comp-name (nth 4 inst-entry)
  13352. inst-conf-key (nth 7 inst-entry))
  13353. ;; search entry in configuration's instantiations list
  13354. (setq tmp-list conf-inst-alist)
  13355. (while (and tmp-list
  13356. (not (and (member (nth 0 (car tmp-list))
  13357. (list "all" inst-key))
  13358. (equal (nth 1 (car tmp-list))
  13359. (downcase (or inst-comp-name ""))))))
  13360. (setq tmp-list (cdr tmp-list)))
  13361. (setq inst-conf-key (or (nth 4 (car tmp-list)) inst-conf-key))
  13362. (setq inst-conf-entry (vhdl-aget conf-alist inst-conf-key))
  13363. (when (and inst-conf-key (not inst-conf-entry))
  13364. (vhdl-warning-when-idle "Configuration not found: \"%s\"" inst-conf-key))
  13365. ;; determine entity
  13366. (setq inst-ent-key
  13367. (or (nth 2 (car tmp-list)) ; from configuration
  13368. (nth 3 inst-conf-entry) ; from subconfiguration
  13369. (nth 3 (vhdl-aget conf-alist (nth 7 inst-entry)))
  13370. ; from configuration spec.
  13371. (nth 5 inst-entry))) ; from direct instantiation
  13372. (setq inst-ent-entry (vhdl-aget ent-alist inst-ent-key))
  13373. ;; determine architecture
  13374. (setq inst-arch-key
  13375. (or (nth 3 (car tmp-list)) ; from configuration
  13376. (nth 4 inst-conf-entry) ; from subconfiguration
  13377. (nth 6 inst-entry) ; from direct instantiation
  13378. (nth 4 (vhdl-aget conf-alist (nth 7 inst-entry)))
  13379. ; from configuration spec.
  13380. (nth 4 inst-ent-entry) ; MRA
  13381. (caar (nth 3 inst-ent-entry)))) ; first alphabetically
  13382. (setq inst-arch-entry (vhdl-aget (nth 3 inst-ent-entry) inst-arch-key))
  13383. ;; set library
  13384. (setq inst-lib-key
  13385. (or (nth 5 (car tmp-list)) ; from configuration
  13386. (nth 8 inst-entry))) ; from direct instantiation
  13387. ;; gather information for this instance
  13388. (setq comp-entry
  13389. (list (nth 1 inst-entry)
  13390. (cons (nth 2 inst-entry) (nth 3 inst-entry))
  13391. (or (nth 0 inst-ent-entry) (nth 4 inst-entry))
  13392. (cons (nth 1 inst-ent-entry) (nth 2 inst-ent-entry))
  13393. (or (nth 0 inst-arch-entry) inst-arch-key)
  13394. (cons (nth 1 inst-arch-entry) (nth 2 inst-arch-entry))
  13395. (or (nth 0 inst-conf-entry) inst-conf-key)
  13396. (cons (nth 1 inst-conf-entry) (nth 2 inst-conf-entry))
  13397. inst-lib-key level))
  13398. ;; get subcomponent hierarchy
  13399. (setq subcomp-list (vhdl-get-hierarchy
  13400. ent-alist conf-alist
  13401. inst-ent-key inst-arch-key inst-conf-key
  13402. (nth 5 inst-conf-entry)
  13403. (1+ level) indent nil (cons ent-key ent-hier)))
  13404. ;; add to list
  13405. (setq hier-list (append hier-list (list comp-entry) subcomp-list))
  13406. (setq inst-alist (cdr inst-alist)))
  13407. (when include-top
  13408. (setq hier-list
  13409. (cons (list nil nil (nth 0 ent-entry)
  13410. (cons (nth 1 ent-entry) (nth 2 ent-entry))
  13411. (nth 0 arch-entry)
  13412. (cons (nth 1 arch-entry) (nth 2 arch-entry))
  13413. nil nil
  13414. nil (1- level))
  13415. hier-list)))
  13416. (when (or (= level 0) (and include-top (= level 1))) (message ""))
  13417. hier-list))
  13418. (defun vhdl-get-instantiations (ent-key indent)
  13419. "Get all instantiations of entity ENT-KEY."
  13420. (let ((ent-alist (vhdl-aget vhdl-entity-alist
  13421. (vhdl-speedbar-line-key indent)))
  13422. arch-alist inst-alist ent-inst-list
  13423. ent-entry arch-entry inst-entry)
  13424. (while ent-alist
  13425. (setq ent-entry (car ent-alist))
  13426. (setq arch-alist (nth 4 ent-entry))
  13427. (while arch-alist
  13428. (setq arch-entry (car arch-alist))
  13429. (setq inst-alist (nth 4 arch-entry))
  13430. (while inst-alist
  13431. (setq inst-entry (car inst-alist))
  13432. (when (equal ent-key (nth 5 inst-entry))
  13433. (setq ent-inst-list
  13434. (cons (list (nth 1 inst-entry)
  13435. (cons (nth 2 inst-entry) (nth 3 inst-entry))
  13436. (nth 1 ent-entry)
  13437. (cons (nth 2 ent-entry) (nth 3 ent-entry))
  13438. (nth 1 arch-entry)
  13439. (cons (nth 2 arch-entry) (nth 3 arch-entry)))
  13440. ent-inst-list)))
  13441. (setq inst-alist (cdr inst-alist)))
  13442. (setq arch-alist (cdr arch-alist)))
  13443. (setq ent-alist (cdr ent-alist)))
  13444. (nreverse ent-inst-list)))
  13445. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  13446. ;; Caching in file
  13447. (defun vhdl-save-caches ()
  13448. "Save all updated hierarchy caches to file."
  13449. (interactive)
  13450. (condition-case nil
  13451. (when vhdl-speedbar-save-cache
  13452. ;; update hierarchy
  13453. (vhdl-update-hierarchy)
  13454. (let ((project-list vhdl-updated-project-list))
  13455. (message "Saving hierarchy caches...")
  13456. ;; write updated project caches
  13457. (while project-list
  13458. (vhdl-save-cache (car project-list))
  13459. (setq project-list (cdr project-list)))
  13460. (message "Saving hierarchy caches...done")))
  13461. (error (progn (vhdl-warning "ERROR: An error occurred while saving the hierarchy caches")
  13462. (sit-for 2)))))
  13463. (defun vhdl-save-cache (key)
  13464. "Save current hierarchy cache to file."
  13465. (let* ((orig-buffer (current-buffer))
  13466. (vhdl-project key)
  13467. (project (vhdl-project-p))
  13468. (default-directory key)
  13469. (directory (abbreviate-file-name (vhdl-default-directory)))
  13470. (file-name (vhdl-resolve-env-variable
  13471. (vhdl-replace-string
  13472. (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
  13473. (concat
  13474. (subst-char-in-string ? ?_ (or project "dir"))
  13475. " " (user-login-name)))))
  13476. (file-dir-name (expand-file-name file-name directory))
  13477. (cache-key (or project directory))
  13478. (key (if project "project" "directory")))
  13479. (unless (file-exists-p (file-name-directory file-dir-name))
  13480. (make-directory (file-name-directory file-dir-name) t))
  13481. (if (not (file-writable-p file-dir-name))
  13482. (progn (vhdl-warning (format "File not writable: \"%s\""
  13483. (abbreviate-file-name file-dir-name)))
  13484. (sit-for 2))
  13485. (message "Saving cache: \"%s\"" file-dir-name)
  13486. (set-buffer (find-file-noselect file-dir-name t t))
  13487. (erase-buffer)
  13488. (insert ";; -*- Emacs-Lisp -*-\n\n"
  13489. ";;; " (file-name-nondirectory file-name)
  13490. " - design hierarchy cache file for Emacs VHDL Mode "
  13491. vhdl-version "\n")
  13492. (insert "\n;; " (if project "Project " "Directory") " : ")
  13493. (if project (insert project) (prin1 directory (current-buffer)))
  13494. (insert "\n;; Saved : " (format-time-string "%Y-%m-%d %T ")
  13495. (user-login-name) "\n\n"
  13496. "\n;; version number\n"
  13497. "(setq vhdl-cache-version \"" vhdl-version "\")\n"
  13498. "\n;; " (if project "project" "directory") " name"
  13499. "\n(setq " key " ")
  13500. (prin1 (or project directory) (current-buffer))
  13501. (insert ")\n")
  13502. (when (member 'hierarchy vhdl-speedbar-save-cache)
  13503. (insert "\n;; entity and architecture cache\n"
  13504. "(vhdl-aput 'vhdl-entity-alist " key " '")
  13505. (print (vhdl-aget vhdl-entity-alist cache-key) (current-buffer))
  13506. (insert ")\n\n;; configuration cache\n"
  13507. "(vhdl-aput 'vhdl-config-alist " key " '")
  13508. (print (vhdl-aget vhdl-config-alist cache-key) (current-buffer))
  13509. (insert ")\n\n;; package cache\n"
  13510. "(vhdl-aput 'vhdl-package-alist " key " '")
  13511. (print (vhdl-aget vhdl-package-alist cache-key) (current-buffer))
  13512. (insert ")\n\n;; instantiated entities cache\n"
  13513. "(vhdl-aput 'vhdl-ent-inst-alist " key " '")
  13514. (print (vhdl-aget vhdl-ent-inst-alist cache-key) (current-buffer))
  13515. (insert ")\n\n;; design units per file cache\n"
  13516. "(vhdl-aput 'vhdl-file-alist " key " '")
  13517. (print (vhdl-aget vhdl-file-alist cache-key) (current-buffer))
  13518. (when project
  13519. (insert ")\n\n;; source directories in project cache\n"
  13520. "(vhdl-aput 'vhdl-directory-alist " key " '")
  13521. (print (vhdl-aget vhdl-directory-alist cache-key) (current-buffer)))
  13522. (insert ")\n"))
  13523. (when (member 'display vhdl-speedbar-save-cache)
  13524. (insert "\n;; shown design units cache\n"
  13525. "(vhdl-aput 'vhdl-speedbar-shown-unit-alist " key " '")
  13526. (print (vhdl-aget vhdl-speedbar-shown-unit-alist cache-key)
  13527. (current-buffer))
  13528. (insert ")\n"))
  13529. (setq vhdl-updated-project-list
  13530. (delete cache-key vhdl-updated-project-list))
  13531. (save-buffer)
  13532. (kill-buffer (current-buffer))
  13533. (set-buffer orig-buffer))))
  13534. (defun vhdl-load-cache (key)
  13535. "Load hierarchy cache information from file."
  13536. (let* ((vhdl-project key)
  13537. (default-directory key)
  13538. (directory (vhdl-default-directory))
  13539. (file-name (vhdl-resolve-env-variable
  13540. (vhdl-replace-string
  13541. (cons "\\(.*\\) \\(.*\\)" vhdl-speedbar-cache-file-name)
  13542. (concat
  13543. (subst-char-in-string ? ?_ (or (vhdl-project-p) "dir"))
  13544. " " (user-login-name)))))
  13545. (file-dir-name (expand-file-name file-name directory))
  13546. vhdl-cache-version)
  13547. (unless (memq 'vhdl-save-caches kill-emacs-hook)
  13548. (add-hook 'kill-emacs-hook 'vhdl-save-caches))
  13549. (when (file-exists-p file-dir-name)
  13550. (condition-case ()
  13551. (progn (load-file file-dir-name)
  13552. (string< (mapconcat
  13553. (lambda (a) (format "%3d" (string-to-number a)))
  13554. (split-string "3.33" "\\.") "")
  13555. (mapconcat
  13556. (lambda (a) (format "%3d" (string-to-number a)))
  13557. (split-string vhdl-cache-version "\\.") "")))
  13558. (error (progn (vhdl-warning (format "ERROR: Corrupted cache file: \"%s\"" file-dir-name))
  13559. nil))))))
  13560. (defun vhdl-require-hierarchy-info ()
  13561. "Make sure that hierarchy information is available. Load cache or scan files
  13562. if required."
  13563. (if (vhdl-project-p)
  13564. (unless (or (assoc vhdl-project vhdl-file-alist)
  13565. (vhdl-load-cache vhdl-project))
  13566. (vhdl-scan-project-contents vhdl-project))
  13567. (let ((directory (abbreviate-file-name default-directory)))
  13568. (unless (or (assoc directory vhdl-file-alist)
  13569. (vhdl-load-cache directory))
  13570. (vhdl-scan-directory-contents directory)))))
  13571. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  13572. ;; Add hierarchy browser functionality to speedbar
  13573. (defvar vhdl-speedbar-mode-map nil
  13574. "Keymap used when in the VHDL hierarchy browser mode.")
  13575. (defvar vhdl-speedbar-menu-items nil
  13576. "Additional menu-items to add to speedbar frame.")
  13577. (declare-function speedbar-add-supported-extension "speedbar" (extension))
  13578. (declare-function speedbar-add-mode-functions-list "speedbar" (new-list))
  13579. (declare-function speedbar-make-specialized-keymap "speedbar" ())
  13580. (declare-function speedbar-change-initial-expansion-list "speedbar"
  13581. (new-default))
  13582. (declare-function speedbar-add-expansion-list "speedbar" (new-list))
  13583. (defun vhdl-speedbar-initialize ()
  13584. "Initialize speedbar."
  13585. ;; general settings
  13586. ;; VHDL file extensions (extracted from `auto-mode-alist')
  13587. (let ((mode-alist auto-mode-alist))
  13588. (while mode-alist
  13589. (when (eq (cdar mode-alist) 'vhdl-mode)
  13590. (speedbar-add-supported-extension (caar mode-alist)))
  13591. (setq mode-alist (cdr mode-alist))))
  13592. ;; hierarchy browser settings
  13593. (when (boundp 'speedbar-mode-functions-list)
  13594. ;; special functions
  13595. (speedbar-add-mode-functions-list
  13596. '("vhdl directory"
  13597. (speedbar-item-info . vhdl-speedbar-item-info)
  13598. (speedbar-line-directory . speedbar-files-line-path)))
  13599. (speedbar-add-mode-functions-list
  13600. '("vhdl project"
  13601. (speedbar-item-info . vhdl-speedbar-item-info)
  13602. (speedbar-line-directory . vhdl-speedbar-line-project)))
  13603. ;; keymap
  13604. (unless vhdl-speedbar-mode-map
  13605. (setq vhdl-speedbar-mode-map (speedbar-make-specialized-keymap))
  13606. (define-key vhdl-speedbar-mode-map "e" 'speedbar-edit-line)
  13607. (define-key vhdl-speedbar-mode-map "\C-m" 'speedbar-edit-line)
  13608. (define-key vhdl-speedbar-mode-map "+" 'speedbar-expand-line)
  13609. (define-key vhdl-speedbar-mode-map "=" 'speedbar-expand-line)
  13610. (define-key vhdl-speedbar-mode-map "-" 'vhdl-speedbar-contract-level)
  13611. (define-key vhdl-speedbar-mode-map "_" 'vhdl-speedbar-contract-all)
  13612. (define-key vhdl-speedbar-mode-map "C" 'vhdl-speedbar-port-copy)
  13613. (define-key vhdl-speedbar-mode-map "P" 'vhdl-speedbar-place-component)
  13614. (define-key vhdl-speedbar-mode-map "F" 'vhdl-speedbar-configuration)
  13615. (define-key vhdl-speedbar-mode-map "A" 'vhdl-speedbar-select-mra)
  13616. (define-key vhdl-speedbar-mode-map "K" 'vhdl-speedbar-make-design)
  13617. (define-key vhdl-speedbar-mode-map "R" 'vhdl-speedbar-rescan-hierarchy)
  13618. (define-key vhdl-speedbar-mode-map "S" 'vhdl-save-caches)
  13619. (let ((key 0))
  13620. (while (<= key 9)
  13621. (define-key vhdl-speedbar-mode-map (int-to-string key)
  13622. `(lambda () (interactive) (vhdl-speedbar-set-depth ,key)))
  13623. (setq key (1+ key)))))
  13624. (define-key speedbar-mode-map "h"
  13625. (lambda () (interactive)
  13626. (speedbar-change-initial-expansion-list "vhdl directory")))
  13627. (define-key speedbar-mode-map "H"
  13628. (lambda () (interactive)
  13629. (speedbar-change-initial-expansion-list "vhdl project")))
  13630. ;; menu
  13631. (unless vhdl-speedbar-menu-items
  13632. (setq
  13633. vhdl-speedbar-menu-items
  13634. `(["Edit" speedbar-edit-line t]
  13635. ["Expand" speedbar-expand-line
  13636. (save-excursion (beginning-of-line) (looking-at "[0-9]+: *.\\+. "))]
  13637. ["Contract" vhdl-speedbar-contract-level t]
  13638. ["Expand All" vhdl-speedbar-expand-all t]
  13639. ["Contract All" vhdl-speedbar-contract-all t]
  13640. ,(let ((key 0) (menu-list '("Hierarchy Depth")))
  13641. (while (<= key 9)
  13642. (setq menu-list
  13643. (cons `[,(if (= key 0) "All" (int-to-string key))
  13644. (vhdl-speedbar-set-depth ,key)
  13645. :style radio
  13646. :selected (= vhdl-speedbar-hierarchy-depth ,key)
  13647. :keys ,(int-to-string key)]
  13648. menu-list))
  13649. (setq key (1+ key)))
  13650. (nreverse menu-list))
  13651. "--"
  13652. ["Copy Port/Subprogram" vhdl-speedbar-port-copy
  13653. (or (vhdl-speedbar-check-unit 'entity)
  13654. (vhdl-speedbar-check-unit 'subprogram))]
  13655. ["Place Component" vhdl-speedbar-place-component
  13656. (vhdl-speedbar-check-unit 'entity)]
  13657. ["Generate Configuration" vhdl-speedbar-configuration
  13658. (vhdl-speedbar-check-unit 'architecture)]
  13659. ["Select as MRA" vhdl-speedbar-select-mra
  13660. (vhdl-speedbar-check-unit 'architecture)]
  13661. ["Make" vhdl-speedbar-make-design
  13662. (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
  13663. ["Generate Makefile" vhdl-speedbar-generate-makefile
  13664. (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))]
  13665. ["Rescan Directory" vhdl-speedbar-rescan-hierarchy
  13666. :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
  13667. ,(if (featurep 'xemacs) :active :visible) (not vhdl-speedbar-show-projects)]
  13668. ["Rescan Project" vhdl-speedbar-rescan-hierarchy
  13669. :active (save-excursion (beginning-of-line) (looking-at "[0-9]+:"))
  13670. ,(if (featurep 'xemacs) :active :visible) vhdl-speedbar-show-projects]
  13671. ["Save Caches" vhdl-save-caches vhdl-updated-project-list])))
  13672. ;; hook-ups
  13673. (speedbar-add-expansion-list
  13674. '("vhdl directory" vhdl-speedbar-menu-items vhdl-speedbar-mode-map
  13675. vhdl-speedbar-display-directory))
  13676. (speedbar-add-expansion-list
  13677. '("vhdl project" vhdl-speedbar-menu-items vhdl-speedbar-mode-map
  13678. vhdl-speedbar-display-projects))
  13679. (setq speedbar-stealthy-function-list
  13680. (append
  13681. '(("vhdl directory" vhdl-speedbar-update-current-unit)
  13682. ("vhdl project" vhdl-speedbar-update-current-project
  13683. vhdl-speedbar-update-current-unit))
  13684. speedbar-stealthy-function-list))
  13685. (when (eq vhdl-speedbar-display-mode 'directory)
  13686. (setq speedbar-initial-expansion-list-name "vhdl directory"))
  13687. (when (eq vhdl-speedbar-display-mode 'project)
  13688. (setq speedbar-initial-expansion-list-name "vhdl project"))
  13689. (add-hook 'speedbar-timer-hook 'vhdl-update-hierarchy)))
  13690. (defun vhdl-speedbar (&optional arg)
  13691. "Open/close speedbar."
  13692. (interactive)
  13693. (if (not (fboundp 'speedbar))
  13694. (error "WARNING: Speedbar is not available or not installed")
  13695. (condition-case ()
  13696. (speedbar-frame-mode arg)
  13697. (error (error "WARNING: An error occurred while opening speedbar")))))
  13698. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  13699. ;; Display functions
  13700. (defvar vhdl-speedbar-last-selected-project nil
  13701. "Name of last selected project.")
  13702. ;; macros must be defined in the file they are used (copied from `speedbar.el')
  13703. ;;; (defmacro speedbar-with-writable (&rest forms)
  13704. ;;; "Allow the buffer to be writable and evaluate FORMS."
  13705. ;;; (list 'let '((inhibit-read-only t))
  13706. ;;; (cons 'progn forms)))
  13707. ;;; (put 'speedbar-with-writable 'lisp-indent-function 0)
  13708. (declare-function speedbar-extension-list-to-regex "speedbar" (extlist))
  13709. (declare-function speedbar-directory-buttons "speedbar" (directory _index))
  13710. (declare-function speedbar-file-lists "speedbar" (directory))
  13711. (defun vhdl-speedbar-display-directory (directory depth &optional rescan)
  13712. "Display directory and hierarchy information in speedbar."
  13713. (setq vhdl-speedbar-show-projects nil)
  13714. (setq speedbar-ignored-directory-regexp
  13715. (speedbar-extension-list-to-regex speedbar-ignored-directory-expressions))
  13716. (setq directory (abbreviate-file-name (file-name-as-directory directory)))
  13717. (setq speedbar-last-selected-file nil)
  13718. (speedbar-with-writable
  13719. (condition-case nil
  13720. (progn
  13721. ;; insert directory path
  13722. (speedbar-directory-buttons directory depth)
  13723. ;; insert subdirectories
  13724. (vhdl-speedbar-insert-dirs (speedbar-file-lists directory) depth)
  13725. ;; scan and insert hierarchy of current directory
  13726. (vhdl-speedbar-insert-dir-hierarchy directory depth
  13727. speedbar-power-click)
  13728. ;; expand subdirectories
  13729. (when (= depth 0) (vhdl-speedbar-expand-dirs directory)))
  13730. (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly")))))
  13731. (defun vhdl-speedbar-display-projects (project depth &optional rescan)
  13732. "Display projects and hierarchy information in speedbar."
  13733. (setq vhdl-speedbar-show-projects t)
  13734. (setq speedbar-ignored-directory-regexp ".")
  13735. (setq speedbar-last-selected-file nil)
  13736. (setq vhdl-speedbar-last-selected-project nil)
  13737. (speedbar-with-writable
  13738. (condition-case nil
  13739. ;; insert projects
  13740. (vhdl-speedbar-insert-projects)
  13741. (error (vhdl-warning-when-idle "ERROR: Invalid hierarchy information, unable to display correctly"))))
  13742. (setq speedbar-full-text-cache nil)) ; prevent caching
  13743. (declare-function speedbar-make-tag-line "speedbar"
  13744. (type char func data tag tfunc tdata tface depth))
  13745. (defun vhdl-speedbar-insert-projects ()
  13746. "Insert all projects in speedbar."
  13747. (vhdl-speedbar-make-title-line "Projects:")
  13748. (let ((project-alist (if vhdl-project-sort
  13749. (vhdl-sort-alist (copy-alist vhdl-project-alist))
  13750. vhdl-project-alist))
  13751. (vhdl-speedbar-update-current-unit nil))
  13752. ;; insert projects
  13753. (while project-alist
  13754. (speedbar-make-tag-line
  13755. 'angle ?+ 'vhdl-speedbar-expand-project
  13756. (caar project-alist) (caar project-alist)
  13757. 'vhdl-toggle-project (caar project-alist) 'speedbar-directory-face 0)
  13758. (setq project-alist (cdr project-alist)))
  13759. (setq project-alist vhdl-project-alist)
  13760. ;; expand projects
  13761. (while project-alist
  13762. (when (member (caar project-alist) vhdl-speedbar-shown-project-list)
  13763. (goto-char (point-min))
  13764. (when (re-search-forward
  13765. (concat "^\\([0-9]+:\\s-*<\\)[+]>\\s-+" (caar project-alist) "$") nil t)
  13766. (goto-char (match-end 1))
  13767. (speedbar-do-function-pointer)))
  13768. (setq project-alist (cdr project-alist)))))
  13769. (defun vhdl-speedbar-insert-project-hierarchy (project indent &optional rescan)
  13770. "Insert hierarchy of PROJECT. Rescan directories if RESCAN is non-nil,
  13771. otherwise use cached data."
  13772. (when (or rescan (and (not (assoc project vhdl-file-alist))
  13773. (not (vhdl-load-cache project))))
  13774. (vhdl-scan-project-contents project))
  13775. ;; insert design hierarchy
  13776. (vhdl-speedbar-insert-hierarchy
  13777. (vhdl-aget vhdl-entity-alist project)
  13778. (vhdl-aget vhdl-config-alist project)
  13779. (vhdl-aget vhdl-package-alist project)
  13780. (car (vhdl-aget vhdl-ent-inst-alist project)) indent)
  13781. (insert (int-to-string indent) ":\n")
  13782. (put-text-property (- (point) 3) (1- (point)) 'invisible t)
  13783. (put-text-property (1- (point)) (point) 'invisible nil)
  13784. ;; expand design units
  13785. (vhdl-speedbar-expand-units project))
  13786. (defun vhdl-speedbar-insert-dir-hierarchy (directory depth &optional rescan)
  13787. "Insert hierarchy of DIRECTORY. Rescan directory if RESCAN is non-nil,
  13788. otherwise use cached data."
  13789. (when (or rescan (and (not (assoc directory vhdl-file-alist))
  13790. (not (vhdl-load-cache directory))))
  13791. (vhdl-scan-directory-contents directory))
  13792. ;; insert design hierarchy
  13793. (vhdl-speedbar-insert-hierarchy
  13794. (vhdl-aget vhdl-entity-alist directory)
  13795. (vhdl-aget vhdl-config-alist directory)
  13796. (vhdl-aget vhdl-package-alist directory)
  13797. (car (vhdl-aget vhdl-ent-inst-alist directory)) depth)
  13798. ;; expand design units
  13799. (vhdl-speedbar-expand-units directory)
  13800. (vhdl-aput 'vhdl-directory-alist directory (list (list directory))))
  13801. (defun vhdl-speedbar-insert-hierarchy (ent-alist conf-alist pack-alist
  13802. ent-inst-list depth)
  13803. "Insert hierarchy of ENT-ALIST, CONF-ALIST, and PACK-ALIST."
  13804. (if (not (or ent-alist conf-alist pack-alist))
  13805. (vhdl-speedbar-make-title-line "No VHDL design units!" depth)
  13806. (let (ent-entry conf-entry pack-entry)
  13807. ;; insert entities
  13808. (when ent-alist (vhdl-speedbar-make-title-line "Entities:" depth))
  13809. (while ent-alist
  13810. (setq ent-entry (car ent-alist))
  13811. (speedbar-make-tag-line
  13812. 'bracket ?+ 'vhdl-speedbar-expand-entity (nth 0 ent-entry)
  13813. (nth 1 ent-entry) 'vhdl-speedbar-find-file
  13814. (cons (nth 2 ent-entry) (nth 3 ent-entry))
  13815. 'vhdl-speedbar-entity-face depth)
  13816. (unless (nth 2 ent-entry)
  13817. (end-of-line 0) (insert "!") (forward-char 1))
  13818. (unless (member (nth 0 ent-entry) ent-inst-list)
  13819. (end-of-line 0) (insert " (top)") (forward-char 1))
  13820. (setq ent-alist (cdr ent-alist)))
  13821. ;; insert configurations
  13822. (when conf-alist (vhdl-speedbar-make-title-line "Configurations:" depth))
  13823. (while conf-alist
  13824. (setq conf-entry (car conf-alist))
  13825. (speedbar-make-tag-line
  13826. 'bracket ?+ 'vhdl-speedbar-expand-config (nth 0 conf-entry)
  13827. (nth 1 conf-entry) 'vhdl-speedbar-find-file
  13828. (cons (nth 2 conf-entry) (nth 3 conf-entry))
  13829. 'vhdl-speedbar-configuration-face depth)
  13830. (setq conf-alist (cdr conf-alist)))
  13831. ;; insert packages
  13832. (when pack-alist (vhdl-speedbar-make-title-line "Packages:" depth))
  13833. (while pack-alist
  13834. (setq pack-entry (car pack-alist))
  13835. (vhdl-speedbar-make-pack-line
  13836. (nth 0 pack-entry) (nth 1 pack-entry)
  13837. (cons (nth 2 pack-entry) (nth 3 pack-entry))
  13838. (cons (nth 7 pack-entry) (nth 8 pack-entry))
  13839. depth)
  13840. (setq pack-alist (cdr pack-alist))))))
  13841. (declare-function speedbar-line-directory "speedbar" (&optional depth))
  13842. (defun vhdl-speedbar-rescan-hierarchy ()
  13843. "Rescan hierarchy for the directory or project under the cursor."
  13844. (interactive)
  13845. (let (key path)
  13846. (cond
  13847. ;; current project
  13848. (vhdl-speedbar-show-projects
  13849. (setq key (vhdl-speedbar-line-project))
  13850. (vhdl-scan-project-contents key))
  13851. ;; top-level directory
  13852. ((save-excursion (beginning-of-line) (looking-at "[^0-9]"))
  13853. (re-search-forward "[0-9]+:" nil t)
  13854. (vhdl-scan-directory-contents
  13855. (abbreviate-file-name (speedbar-line-directory))))
  13856. ;; current directory
  13857. (t (setq path (speedbar-line-directory))
  13858. (string-match "^\\(.+[/\\]\\)" path)
  13859. (vhdl-scan-directory-contents
  13860. (abbreviate-file-name (match-string 1 path)))))
  13861. (vhdl-speedbar-refresh key)))
  13862. (declare-function speedbar-goto-this-file "speedbar" (file))
  13863. (defun vhdl-speedbar-expand-dirs (directory)
  13864. "Expand subdirectories in DIRECTORY according to
  13865. `speedbar-shown-directories'."
  13866. ;; (nicked from `speedbar-default-directory-list')
  13867. (let ((sf (cdr (reverse speedbar-shown-directories)))
  13868. (vhdl-speedbar-update-current-unit nil))
  13869. (setq speedbar-shown-directories
  13870. (list (expand-file-name default-directory)))
  13871. (while sf
  13872. (when (speedbar-goto-this-file (car sf))
  13873. (beginning-of-line)
  13874. (when (looking-at "[0-9]+:\\s-*<")
  13875. (goto-char (match-end 0))
  13876. (speedbar-do-function-pointer)))
  13877. (setq sf (cdr sf))))
  13878. (vhdl-speedbar-update-current-unit nil t))
  13879. (defun vhdl-speedbar-expand-units (key)
  13880. "Expand design units in directory/project KEY according to
  13881. `vhdl-speedbar-shown-unit-alist'."
  13882. (let ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key))
  13883. (vhdl-speedbar-update-current-unit nil)
  13884. vhdl-updated-project-list)
  13885. (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key)
  13886. (vhdl-prepare-search-1
  13887. (while unit-alist ; expand units
  13888. (vhdl-speedbar-goto-this-unit key (caar unit-alist))
  13889. (beginning-of-line)
  13890. (let ((arch-alist (nth 1 (car unit-alist)))
  13891. position)
  13892. (when (looking-at "^[0-9]+:\\s-*\\[")
  13893. (goto-char (match-end 0))
  13894. (setq position (point))
  13895. (speedbar-do-function-pointer)
  13896. (select-frame speedbar-frame)
  13897. (while arch-alist ; expand architectures
  13898. (goto-char position)
  13899. (when (re-search-forward
  13900. (concat "^[0-9]+:\\s-*\\(\\[\\|{.}\\s-+"
  13901. (car arch-alist) "\\>\\)") nil t)
  13902. (beginning-of-line)
  13903. (when (looking-at "^[0-9]+:\\s-*{")
  13904. (goto-char (match-end 0))
  13905. (speedbar-do-function-pointer)
  13906. (select-frame speedbar-frame)))
  13907. (setq arch-alist (cdr arch-alist))))
  13908. (setq unit-alist (cdr unit-alist))))))
  13909. (vhdl-speedbar-update-current-unit nil t))
  13910. (declare-function speedbar-center-buffer-smartly "speedbar" ())
  13911. (defun vhdl-speedbar-contract-level ()
  13912. "Contract current level in current directory/project."
  13913. (interactive)
  13914. (when (or (save-excursion
  13915. (beginning-of-line) (looking-at "^[0-9]:\\s-*[[{<]-"))
  13916. (and (save-excursion
  13917. (beginning-of-line) (looking-at "^\\([0-9]+\\):"))
  13918. (re-search-backward
  13919. (format "^[0-%d]:\\s-*[[{<]-"
  13920. (max (1- (string-to-number (match-string 1))) 0)) nil t)))
  13921. (goto-char (match-end 0))
  13922. (speedbar-do-function-pointer)
  13923. (speedbar-center-buffer-smartly)))
  13924. (defun vhdl-speedbar-contract-all ()
  13925. "Contract all expanded design units in current directory/project."
  13926. (interactive)
  13927. (if (and vhdl-speedbar-show-projects
  13928. (save-excursion (beginning-of-line) (looking-at "^0:")))
  13929. (progn (setq vhdl-speedbar-shown-project-list nil)
  13930. (vhdl-speedbar-refresh))
  13931. (let ((key (vhdl-speedbar-line-key)))
  13932. (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key)
  13933. (vhdl-speedbar-refresh (and vhdl-speedbar-show-projects key))
  13934. (when (memq 'display vhdl-speedbar-save-cache)
  13935. (add-to-list 'vhdl-updated-project-list key)))))
  13936. (defun vhdl-speedbar-expand-all ()
  13937. "Expand all design units in current directory/project."
  13938. (interactive)
  13939. (let* ((key (vhdl-speedbar-line-key))
  13940. (ent-alist (vhdl-aget vhdl-entity-alist key))
  13941. (conf-alist (vhdl-aget vhdl-config-alist key))
  13942. (pack-alist (vhdl-aget vhdl-package-alist key))
  13943. arch-alist unit-alist subunit-alist)
  13944. (add-to-list 'vhdl-speedbar-shown-project-list key)
  13945. (while ent-alist
  13946. (setq arch-alist (nth 4 (car ent-alist)))
  13947. (setq subunit-alist nil)
  13948. (while arch-alist
  13949. (push (caar arch-alist) subunit-alist)
  13950. (setq arch-alist (cdr arch-alist)))
  13951. (push (list (caar ent-alist) subunit-alist) unit-alist)
  13952. (setq ent-alist (cdr ent-alist)))
  13953. (while conf-alist
  13954. (push (list (caar conf-alist)) unit-alist)
  13955. (setq conf-alist (cdr conf-alist)))
  13956. (while pack-alist
  13957. (push (list (caar pack-alist)) unit-alist)
  13958. (setq pack-alist (cdr pack-alist)))
  13959. (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
  13960. (vhdl-speedbar-refresh)
  13961. (when (memq 'display vhdl-speedbar-save-cache)
  13962. (add-to-list 'vhdl-updated-project-list key))))
  13963. (declare-function speedbar-change-expand-button-char "speedbar" (char))
  13964. (declare-function speedbar-delete-subblock "speedbar" (indent))
  13965. (defun vhdl-speedbar-expand-project (text token indent)
  13966. "Expand/contract the project under the cursor."
  13967. (cond
  13968. ((string-match "+" text) ; expand project
  13969. (speedbar-change-expand-button-char ?-)
  13970. (unless (member token vhdl-speedbar-shown-project-list)
  13971. (setq vhdl-speedbar-shown-project-list
  13972. (cons token vhdl-speedbar-shown-project-list)))
  13973. (speedbar-with-writable
  13974. (save-excursion
  13975. (end-of-line) (forward-char 1)
  13976. (vhdl-speedbar-insert-project-hierarchy token (1+ indent)
  13977. speedbar-power-click))))
  13978. ((string-match "-" text) ; contract project
  13979. (speedbar-change-expand-button-char ?+)
  13980. (setq vhdl-speedbar-shown-project-list
  13981. (delete token vhdl-speedbar-shown-project-list))
  13982. (speedbar-delete-subblock indent))
  13983. (t (error "Nothing to display")))
  13984. (when (equal (selected-frame) speedbar-frame)
  13985. (speedbar-center-buffer-smartly)))
  13986. (defun vhdl-speedbar-expand-entity (text token indent)
  13987. "Expand/contract the entity under the cursor."
  13988. (cond
  13989. ((string-match "+" text) ; expand entity
  13990. (let* ((key (vhdl-speedbar-line-key indent))
  13991. (ent-alist (vhdl-aget vhdl-entity-alist key))
  13992. (ent-entry (vhdl-aget ent-alist token))
  13993. (arch-alist (nth 3 ent-entry))
  13994. (inst-alist (vhdl-get-instantiations token indent))
  13995. (subpack-alist (nth 5 ent-entry))
  13996. (multiple-arch (> (length arch-alist) 1))
  13997. arch-entry inst-entry)
  13998. (if (not (or arch-alist inst-alist subpack-alist))
  13999. (speedbar-change-expand-button-char ??)
  14000. (speedbar-change-expand-button-char ?-)
  14001. ;; add entity to `vhdl-speedbar-shown-unit-alist'
  14002. (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
  14003. (vhdl-aput 'unit-alist token nil)
  14004. (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
  14005. (speedbar-with-writable
  14006. (save-excursion
  14007. (end-of-line) (forward-char 1)
  14008. ;; insert architectures
  14009. (when arch-alist
  14010. (vhdl-speedbar-make-title-line "Architectures:" (1+ indent)))
  14011. (while arch-alist
  14012. (setq arch-entry (car arch-alist))
  14013. (speedbar-make-tag-line
  14014. 'curly ?+ 'vhdl-speedbar-expand-architecture
  14015. (cons token (nth 0 arch-entry))
  14016. (nth 1 arch-entry) 'vhdl-speedbar-find-file
  14017. (cons (nth 2 arch-entry) (nth 3 arch-entry))
  14018. 'vhdl-speedbar-architecture-face (1+ indent))
  14019. (when (and multiple-arch
  14020. (equal (nth 0 arch-entry) (nth 4 ent-entry)))
  14021. (end-of-line 0) (insert " (mra)") (forward-char 1))
  14022. (setq arch-alist (cdr arch-alist)))
  14023. ;; insert instantiations
  14024. (when inst-alist
  14025. (vhdl-speedbar-make-title-line "Instantiated as:" (1+ indent)))
  14026. (while inst-alist
  14027. (setq inst-entry (car inst-alist))
  14028. (vhdl-speedbar-make-inst-line
  14029. (nth 0 inst-entry) (nth 1 inst-entry) (nth 2 inst-entry)
  14030. (nth 3 inst-entry) (nth 4 inst-entry) (nth 5 inst-entry)
  14031. nil nil nil (1+ indent) 0 " in ")
  14032. (setq inst-alist (cdr inst-alist)))
  14033. ;; insert required packages
  14034. (vhdl-speedbar-insert-subpackages
  14035. subpack-alist (1+ indent) indent)))
  14036. (when (memq 'display vhdl-speedbar-save-cache)
  14037. (add-to-list 'vhdl-updated-project-list key))
  14038. (vhdl-speedbar-update-current-unit t t))))
  14039. ((string-match "-" text) ; contract entity
  14040. (speedbar-change-expand-button-char ?+)
  14041. ;; remove entity from `vhdl-speedbar-shown-unit-alist'
  14042. (let* ((key (vhdl-speedbar-line-key indent))
  14043. (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
  14044. (vhdl-adelete 'unit-alist token)
  14045. (if unit-alist
  14046. (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
  14047. (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key))
  14048. (speedbar-delete-subblock indent)
  14049. (when (memq 'display vhdl-speedbar-save-cache)
  14050. (add-to-list 'vhdl-updated-project-list key))))
  14051. (t (error "Nothing to display")))
  14052. (when (equal (selected-frame) speedbar-frame)
  14053. (speedbar-center-buffer-smartly)))
  14054. (defun vhdl-speedbar-expand-architecture (text token indent)
  14055. "Expand/contract the architecture under the cursor."
  14056. (cond
  14057. ((string-match "+" text) ; expand architecture
  14058. (let* ((key (vhdl-speedbar-line-key (1- indent)))
  14059. (ent-alist (vhdl-aget vhdl-entity-alist key))
  14060. (conf-alist (vhdl-aget vhdl-config-alist key))
  14061. (hier-alist (vhdl-get-hierarchy
  14062. ent-alist conf-alist (car token) (cdr token) nil nil
  14063. 0 (1- indent)))
  14064. (ent-entry (vhdl-aget ent-alist (car token)))
  14065. (arch-entry (vhdl-aget (nth 3 ent-entry) (cdr token)))
  14066. (subpack-alist (nth 4 arch-entry))
  14067. entry)
  14068. (if (not (or hier-alist subpack-alist))
  14069. (speedbar-change-expand-button-char ??)
  14070. (speedbar-change-expand-button-char ?-)
  14071. ;; add architecture to `vhdl-speedbar-shown-unit-alist'
  14072. (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key))
  14073. (arch-alist (nth 0 (vhdl-aget unit-alist (car token)))))
  14074. (vhdl-aput 'unit-alist (car token)
  14075. (list (cons (cdr token) arch-alist)))
  14076. (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
  14077. (speedbar-with-writable
  14078. (save-excursion
  14079. (end-of-line) (forward-char 1)
  14080. ;; insert instance hierarchy
  14081. (when hier-alist
  14082. (vhdl-speedbar-make-title-line "Subcomponent hierarchy:"
  14083. (1+ indent)))
  14084. (while hier-alist
  14085. (setq entry (car hier-alist))
  14086. (when (or (= vhdl-speedbar-hierarchy-depth 0)
  14087. (< (nth 9 entry) vhdl-speedbar-hierarchy-depth))
  14088. (vhdl-speedbar-make-inst-line
  14089. (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
  14090. (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
  14091. (nth 8 entry) (1+ indent) (1+ (nth 9 entry)) ": "))
  14092. (setq hier-alist (cdr hier-alist)))
  14093. ;; insert required packages
  14094. (vhdl-speedbar-insert-subpackages
  14095. subpack-alist (1+ indent) (1- indent))))
  14096. (when (memq 'display vhdl-speedbar-save-cache)
  14097. (add-to-list 'vhdl-updated-project-list key))
  14098. (vhdl-speedbar-update-current-unit t t))))
  14099. ((string-match "-" text) ; contract architecture
  14100. (speedbar-change-expand-button-char ?+)
  14101. ;; remove architecture from `vhdl-speedbar-shown-unit-alist'
  14102. (let* ((key (vhdl-speedbar-line-key (1- indent)))
  14103. (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key))
  14104. (arch-alist (nth 0 (vhdl-aget unit-alist (car token)))))
  14105. (vhdl-aput 'unit-alist (car token) (list (delete (cdr token) arch-alist)))
  14106. (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
  14107. (speedbar-delete-subblock indent)
  14108. (when (memq 'display vhdl-speedbar-save-cache)
  14109. (add-to-list 'vhdl-updated-project-list key))))
  14110. (t (error "Nothing to display")))
  14111. (when (equal (selected-frame) speedbar-frame)
  14112. (speedbar-center-buffer-smartly)))
  14113. (defun vhdl-speedbar-expand-config (text token indent)
  14114. "Expand/contract the configuration under the cursor."
  14115. (cond
  14116. ((string-match "+" text) ; expand configuration
  14117. (let* ((key (vhdl-speedbar-line-key indent))
  14118. (conf-alist (vhdl-aget vhdl-config-alist key))
  14119. (conf-entry (vhdl-aget conf-alist token))
  14120. (ent-alist (vhdl-aget vhdl-entity-alist key))
  14121. (hier-alist (vhdl-get-hierarchy
  14122. ent-alist conf-alist (nth 3 conf-entry)
  14123. (nth 4 conf-entry) token (nth 5 conf-entry)
  14124. 0 indent t))
  14125. (subpack-alist (nth 6 conf-entry))
  14126. entry)
  14127. (if (not (or hier-alist subpack-alist))
  14128. (speedbar-change-expand-button-char ??)
  14129. (speedbar-change-expand-button-char ?-)
  14130. ;; add configuration to `vhdl-speedbar-shown-unit-alist'
  14131. (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
  14132. (vhdl-aput 'unit-alist token nil)
  14133. (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
  14134. (speedbar-with-writable
  14135. (save-excursion
  14136. (end-of-line) (forward-char 1)
  14137. ;; insert instance hierarchy
  14138. (when hier-alist
  14139. (vhdl-speedbar-make-title-line "Design hierarchy:" (1+ indent)))
  14140. (while hier-alist
  14141. (setq entry (car hier-alist))
  14142. (when (or (= vhdl-speedbar-hierarchy-depth 0)
  14143. (<= (nth 9 entry) vhdl-speedbar-hierarchy-depth))
  14144. (vhdl-speedbar-make-inst-line
  14145. (nth 0 entry) (nth 1 entry) (nth 2 entry) (nth 3 entry)
  14146. (nth 4 entry) (nth 5 entry) (nth 6 entry) (nth 7 entry)
  14147. (nth 8 entry) (1+ indent) (nth 9 entry) ": "))
  14148. (setq hier-alist (cdr hier-alist)))
  14149. ;; insert required packages
  14150. (vhdl-speedbar-insert-subpackages
  14151. subpack-alist (1+ indent) indent)))
  14152. (when (memq 'display vhdl-speedbar-save-cache)
  14153. (add-to-list 'vhdl-updated-project-list key))
  14154. (vhdl-speedbar-update-current-unit t t))))
  14155. ((string-match "-" text) ; contract configuration
  14156. (speedbar-change-expand-button-char ?+)
  14157. ;; remove configuration from `vhdl-speedbar-shown-unit-alist'
  14158. (let* ((key (vhdl-speedbar-line-key indent))
  14159. (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
  14160. (vhdl-adelete 'unit-alist token)
  14161. (if unit-alist
  14162. (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
  14163. (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key))
  14164. (speedbar-delete-subblock indent)
  14165. (when (memq 'display vhdl-speedbar-save-cache)
  14166. (add-to-list 'vhdl-updated-project-list key))))
  14167. (t (error "Nothing to display")))
  14168. (when (equal (selected-frame) speedbar-frame)
  14169. (speedbar-center-buffer-smartly)))
  14170. (defun vhdl-speedbar-expand-package (text token indent)
  14171. "Expand/contract the package under the cursor."
  14172. (cond
  14173. ((string-match "+" text) ; expand package
  14174. (let* ((key (vhdl-speedbar-line-key indent))
  14175. (pack-alist (vhdl-aget vhdl-package-alist key))
  14176. (pack-entry (vhdl-aget pack-alist token))
  14177. (comp-alist (nth 3 pack-entry))
  14178. (func-alist (nth 4 pack-entry))
  14179. (func-body-alist (nth 8 pack-entry))
  14180. (subpack-alist (append (nth 5 pack-entry) (nth 9 pack-entry)))
  14181. comp-entry func-entry func-body-entry)
  14182. (if (not (or comp-alist func-alist subpack-alist))
  14183. (speedbar-change-expand-button-char ??)
  14184. (speedbar-change-expand-button-char ?-)
  14185. ;; add package to `vhdl-speedbar-shown-unit-alist'
  14186. (let* ((unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
  14187. (vhdl-aput 'unit-alist token nil)
  14188. (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist))
  14189. (speedbar-with-writable
  14190. (save-excursion
  14191. (end-of-line) (forward-char 1)
  14192. ;; insert components
  14193. (when comp-alist
  14194. (vhdl-speedbar-make-title-line "Components:" (1+ indent)))
  14195. (while comp-alist
  14196. (setq comp-entry (car comp-alist))
  14197. (speedbar-make-tag-line
  14198. nil nil nil
  14199. (cons token (nth 0 comp-entry))
  14200. (nth 1 comp-entry) 'vhdl-speedbar-find-file
  14201. (cons (nth 2 comp-entry) (nth 3 comp-entry))
  14202. 'vhdl-speedbar-entity-face (1+ indent))
  14203. (setq comp-alist (cdr comp-alist)))
  14204. ;; insert subprograms
  14205. (when func-alist
  14206. (vhdl-speedbar-make-title-line "Subprograms:" (1+ indent)))
  14207. (while func-alist
  14208. (setq func-entry (car func-alist)
  14209. func-body-entry (vhdl-aget func-body-alist
  14210. (car func-entry)))
  14211. (when (nth 2 func-entry)
  14212. (vhdl-speedbar-make-subprogram-line
  14213. (nth 1 func-entry)
  14214. (cons (nth 2 func-entry) (nth 3 func-entry))
  14215. (cons (nth 1 func-body-entry) (nth 2 func-body-entry))
  14216. (1+ indent)))
  14217. (setq func-alist (cdr func-alist)))
  14218. ;; insert required packages
  14219. (vhdl-speedbar-insert-subpackages
  14220. subpack-alist (1+ indent) indent)))
  14221. (when (memq 'display vhdl-speedbar-save-cache)
  14222. (add-to-list 'vhdl-updated-project-list key))
  14223. (vhdl-speedbar-update-current-unit t t))))
  14224. ((string-match "-" text) ; contract package
  14225. (speedbar-change-expand-button-char ?+)
  14226. ;; remove package from `vhdl-speedbar-shown-unit-alist'
  14227. (let* ((key (vhdl-speedbar-line-key indent))
  14228. (unit-alist (vhdl-aget vhdl-speedbar-shown-unit-alist key)))
  14229. (vhdl-adelete 'unit-alist token)
  14230. (if unit-alist
  14231. (vhdl-aput 'vhdl-speedbar-shown-unit-alist key unit-alist)
  14232. (vhdl-adelete 'vhdl-speedbar-shown-unit-alist key))
  14233. (speedbar-delete-subblock indent)
  14234. (when (memq 'display vhdl-speedbar-save-cache)
  14235. (add-to-list 'vhdl-updated-project-list key))))
  14236. (t (error "Nothing to display")))
  14237. (when (equal (selected-frame) speedbar-frame)
  14238. (speedbar-center-buffer-smartly)))
  14239. (defun vhdl-speedbar-insert-subpackages (subpack-alist indent dir-indent)
  14240. "Insert required packages."
  14241. (let* ((pack-alist (vhdl-aget vhdl-package-alist
  14242. (vhdl-speedbar-line-key dir-indent)))
  14243. pack-key lib-name pack-entry)
  14244. (when subpack-alist
  14245. (vhdl-speedbar-make-title-line "Packages Used:" indent))
  14246. (while subpack-alist
  14247. (setq pack-key (cdar subpack-alist)
  14248. lib-name (caar subpack-alist))
  14249. (setq pack-entry (vhdl-aget pack-alist pack-key))
  14250. (vhdl-speedbar-make-subpack-line
  14251. (or (nth 0 pack-entry) pack-key) lib-name
  14252. (cons (nth 1 pack-entry) (nth 2 pack-entry))
  14253. (cons (nth 6 pack-entry) (nth 7 pack-entry)) indent)
  14254. (setq subpack-alist (cdr subpack-alist)))))
  14255. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14256. ;; Display help functions
  14257. (defvar vhdl-speedbar-update-current-unit t
  14258. "Non-nil means to run `vhdl-speedbar-update-current-unit'.")
  14259. (defun vhdl-speedbar-update-current-project ()
  14260. "Highlight project that is currently active."
  14261. (when (and vhdl-speedbar-show-projects
  14262. (not (equal vhdl-speedbar-last-selected-project vhdl-project))
  14263. (and (boundp 'speedbar-frame)
  14264. (frame-live-p speedbar-frame)))
  14265. (let ((last-frame (selected-frame))
  14266. (project-alist vhdl-project-alist)
  14267. pos)
  14268. (select-frame speedbar-frame)
  14269. (speedbar-with-writable
  14270. (save-excursion
  14271. (while project-alist
  14272. (goto-char (point-min))
  14273. (when (re-search-forward
  14274. (concat "<.> \\(" (caar project-alist) "\\)$") nil t)
  14275. (put-text-property (match-beginning 1) (match-end 1) 'face
  14276. (if (equal (caar project-alist) vhdl-project)
  14277. 'speedbar-selected-face
  14278. 'speedbar-directory-face))
  14279. (when (equal (caar project-alist) vhdl-project)
  14280. (setq pos (1- (match-beginning 1)))))
  14281. (setq project-alist (cdr project-alist))))
  14282. (when pos (goto-char pos)))
  14283. (select-frame last-frame)
  14284. (setq vhdl-speedbar-last-selected-project vhdl-project)))
  14285. t)
  14286. (declare-function speedbar-position-cursor-on-line "speedbar" ())
  14287. (defun vhdl-speedbar-update-current-unit (&optional no-position always)
  14288. "Highlight all design units that are contained in the current file.
  14289. NO-POSITION non-nil means do not re-position cursor."
  14290. (let ((last-frame (selected-frame))
  14291. (project-list vhdl-speedbar-shown-project-list)
  14292. file-alist pos file-name)
  14293. ;; get current file name
  14294. (if (fboundp 'speedbar-select-attached-frame)
  14295. (speedbar-select-attached-frame)
  14296. (select-frame speedbar-attached-frame))
  14297. (setq file-name (abbreviate-file-name (or (buffer-file-name) "")))
  14298. (when (and vhdl-speedbar-update-current-unit
  14299. (or always (not (equal file-name speedbar-last-selected-file))))
  14300. (if vhdl-speedbar-show-projects
  14301. (while project-list
  14302. (setq file-alist (append file-alist
  14303. (vhdl-aget vhdl-file-alist
  14304. (car project-list))))
  14305. (setq project-list (cdr project-list)))
  14306. (setq file-alist
  14307. (vhdl-aget vhdl-file-alist
  14308. (abbreviate-file-name default-directory))))
  14309. (select-frame speedbar-frame)
  14310. (set-buffer speedbar-buffer)
  14311. (speedbar-with-writable
  14312. (vhdl-prepare-search-1
  14313. (save-excursion
  14314. ;; unhighlight last units
  14315. (let* ((file-entry (vhdl-aget file-alist
  14316. speedbar-last-selected-file)))
  14317. (vhdl-speedbar-update-units
  14318. "\\[.] " (nth 0 file-entry)
  14319. speedbar-last-selected-file 'vhdl-speedbar-entity-face)
  14320. (vhdl-speedbar-update-units
  14321. "{.} " (nth 1 file-entry)
  14322. speedbar-last-selected-file 'vhdl-speedbar-architecture-face)
  14323. (vhdl-speedbar-update-units
  14324. "\\[.] " (nth 3 file-entry)
  14325. speedbar-last-selected-file 'vhdl-speedbar-configuration-face)
  14326. (vhdl-speedbar-update-units
  14327. "[]>] " (nth 4 file-entry)
  14328. speedbar-last-selected-file 'vhdl-speedbar-package-face)
  14329. (vhdl-speedbar-update-units
  14330. "\\[.].+(" '("body")
  14331. speedbar-last-selected-file 'vhdl-speedbar-package-face)
  14332. (vhdl-speedbar-update-units
  14333. "> " (nth 6 file-entry)
  14334. speedbar-last-selected-file 'vhdl-speedbar-instantiation-face))
  14335. ;; highlight current units
  14336. (let* ((file-entry (vhdl-aget file-alist file-name)))
  14337. (setq
  14338. pos (vhdl-speedbar-update-units
  14339. "\\[.] " (nth 0 file-entry)
  14340. file-name 'vhdl-speedbar-entity-selected-face pos)
  14341. pos (vhdl-speedbar-update-units
  14342. "{.} " (nth 1 file-entry)
  14343. file-name 'vhdl-speedbar-architecture-selected-face pos)
  14344. pos (vhdl-speedbar-update-units
  14345. "\\[.] " (nth 3 file-entry)
  14346. file-name 'vhdl-speedbar-configuration-selected-face pos)
  14347. pos (vhdl-speedbar-update-units
  14348. "[]>] " (nth 4 file-entry)
  14349. file-name 'vhdl-speedbar-package-selected-face pos)
  14350. pos (vhdl-speedbar-update-units
  14351. "\\[.].+(" '("body")
  14352. file-name 'vhdl-speedbar-package-selected-face pos)
  14353. pos (vhdl-speedbar-update-units
  14354. "> " (nth 6 file-entry)
  14355. file-name 'vhdl-speedbar-instantiation-selected-face pos))))))
  14356. ;; move speedbar so the first highlighted unit is visible
  14357. (when (and pos (not no-position))
  14358. (goto-char pos)
  14359. (speedbar-center-buffer-smartly)
  14360. (speedbar-position-cursor-on-line))
  14361. (setq speedbar-last-selected-file file-name))
  14362. (select-frame last-frame)
  14363. t))
  14364. (defun vhdl-speedbar-update-units (text unit-list file-name face
  14365. &optional pos)
  14366. "Help function to highlight design units."
  14367. (while unit-list
  14368. (goto-char (point-min))
  14369. (while (re-search-forward
  14370. (concat text "\\(" (car unit-list) "\\)\\>") nil t)
  14371. (when (equal file-name (car (get-text-property
  14372. (match-beginning 1) 'speedbar-token)))
  14373. (setq pos (or pos (point-marker)))
  14374. (put-text-property (match-beginning 1) (match-end 1) 'face face)))
  14375. (setq unit-list (cdr unit-list)))
  14376. pos)
  14377. (declare-function speedbar-make-button "speedbar"
  14378. (start end face mouse function &optional token))
  14379. (defun vhdl-speedbar-make-inst-line (inst-name inst-file-marker
  14380. ent-name ent-file-marker
  14381. arch-name arch-file-marker
  14382. conf-name conf-file-marker
  14383. lib-name depth offset delimiter)
  14384. "Insert instantiation entry."
  14385. (let ((start (point))
  14386. visible-start)
  14387. (insert (int-to-string depth) ":")
  14388. (put-text-property start (point) 'invisible t)
  14389. (setq visible-start (point))
  14390. (insert-char ? (* depth speedbar-indentation-width))
  14391. (while (> offset 0)
  14392. (insert "|")
  14393. (insert-char (if (= offset 1) ?- ? ) (1- speedbar-indentation-width))
  14394. (setq offset (1- offset)))
  14395. (put-text-property visible-start (point) 'invisible nil)
  14396. (setq start (point))
  14397. (insert ">")
  14398. (speedbar-make-button start (point) nil nil nil)
  14399. (setq visible-start (point))
  14400. (insert " ")
  14401. (setq start (point))
  14402. (if (not inst-name)
  14403. (insert "(top)")
  14404. (insert inst-name)
  14405. (speedbar-make-button
  14406. start (point) 'vhdl-speedbar-instantiation-face 'speedbar-highlight-face
  14407. 'vhdl-speedbar-find-file inst-file-marker))
  14408. (insert delimiter)
  14409. (when ent-name
  14410. (setq start (point))
  14411. (insert ent-name)
  14412. (speedbar-make-button
  14413. start (point) 'vhdl-speedbar-entity-face 'speedbar-highlight-face
  14414. 'vhdl-speedbar-find-file ent-file-marker)
  14415. (when arch-name
  14416. (insert " (")
  14417. (setq start (point))
  14418. (insert arch-name)
  14419. (speedbar-make-button
  14420. start (point) 'vhdl-speedbar-architecture-face 'speedbar-highlight-face
  14421. 'vhdl-speedbar-find-file arch-file-marker)
  14422. (insert ")"))
  14423. (when conf-name
  14424. (insert " (")
  14425. (setq start (point))
  14426. (insert conf-name)
  14427. (speedbar-make-button
  14428. start (point) 'vhdl-speedbar-configuration-face 'speedbar-highlight-face
  14429. 'vhdl-speedbar-find-file conf-file-marker)
  14430. (insert ")")))
  14431. (when (and lib-name (not (equal lib-name (downcase (vhdl-work-library)))))
  14432. (setq start (point))
  14433. (insert " (" lib-name ")")
  14434. (put-text-property (+ 2 start) (1- (point)) 'face
  14435. 'vhdl-speedbar-library-face))
  14436. (insert-char ?\n 1)
  14437. (put-text-property visible-start (point) 'invisible nil)))
  14438. (defun vhdl-speedbar-make-pack-line (pack-key pack-name pack-file-marker
  14439. body-file-marker depth)
  14440. "Insert package entry."
  14441. (let ((start (point))
  14442. visible-start)
  14443. (insert (int-to-string depth) ":")
  14444. (put-text-property start (point) 'invisible t)
  14445. (setq visible-start (point))
  14446. (insert-char ? (* depth speedbar-indentation-width))
  14447. (put-text-property visible-start (point) 'invisible nil)
  14448. (setq start (point))
  14449. (insert "[+]")
  14450. (speedbar-make-button
  14451. start (point) 'speedbar-button-face 'speedbar-highlight-face
  14452. 'vhdl-speedbar-expand-package pack-key)
  14453. (setq visible-start (point))
  14454. (insert-char ? 1 nil)
  14455. (setq start (point))
  14456. (insert pack-name)
  14457. (speedbar-make-button
  14458. start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
  14459. 'vhdl-speedbar-find-file pack-file-marker)
  14460. (unless (car pack-file-marker)
  14461. (insert "!"))
  14462. (when (car body-file-marker)
  14463. (insert " (")
  14464. (setq start (point))
  14465. (insert "body")
  14466. (speedbar-make-button
  14467. start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
  14468. 'vhdl-speedbar-find-file body-file-marker)
  14469. (insert ")"))
  14470. (insert-char ?\n 1)
  14471. (put-text-property visible-start (point) 'invisible nil)))
  14472. (defun vhdl-speedbar-make-subpack-line (pack-name lib-name pack-file-marker
  14473. pack-body-file-marker depth)
  14474. "Insert used package entry."
  14475. (let ((start (point))
  14476. visible-start)
  14477. (insert (int-to-string depth) ":")
  14478. (put-text-property start (point) 'invisible t)
  14479. (setq visible-start (point))
  14480. (insert-char ? (* depth speedbar-indentation-width))
  14481. (put-text-property visible-start (point) 'invisible nil)
  14482. (setq start (point))
  14483. (insert ">")
  14484. (speedbar-make-button start (point) nil nil nil)
  14485. (setq visible-start (point))
  14486. (insert " ")
  14487. (setq start (point))
  14488. (insert pack-name)
  14489. (speedbar-make-button
  14490. start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
  14491. 'vhdl-speedbar-find-file pack-file-marker)
  14492. (when (car pack-body-file-marker)
  14493. (insert " (")
  14494. (setq start (point))
  14495. (insert "body")
  14496. (speedbar-make-button
  14497. start (point) 'vhdl-speedbar-package-face 'speedbar-highlight-face
  14498. 'vhdl-speedbar-find-file pack-body-file-marker)
  14499. (insert ")"))
  14500. (setq start (point))
  14501. (insert " (" lib-name ")")
  14502. (put-text-property (+ 2 start) (1- (point)) 'face
  14503. 'vhdl-speedbar-library-face)
  14504. (insert-char ?\n 1)
  14505. (put-text-property visible-start (point) 'invisible nil)))
  14506. (defun vhdl-speedbar-make-subprogram-line (func-name func-file-marker
  14507. func-body-file-marker
  14508. depth)
  14509. "Insert subprogram entry."
  14510. (let ((start (point))
  14511. visible-start)
  14512. (insert (int-to-string depth) ":")
  14513. (put-text-property start (point) 'invisible t)
  14514. (setq visible-start (point))
  14515. (insert-char ? (* depth speedbar-indentation-width))
  14516. (put-text-property visible-start (point) 'invisible nil)
  14517. (setq start (point))
  14518. (insert ">")
  14519. (speedbar-make-button start (point) nil nil nil)
  14520. (setq visible-start (point))
  14521. (insert " ")
  14522. (setq start (point))
  14523. (insert func-name)
  14524. (speedbar-make-button
  14525. start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
  14526. 'vhdl-speedbar-find-file func-file-marker)
  14527. (when (car func-body-file-marker)
  14528. (insert " (")
  14529. (setq start (point))
  14530. (insert "body")
  14531. (speedbar-make-button
  14532. start (point) 'vhdl-speedbar-subprogram-face 'speedbar-highlight-face
  14533. 'vhdl-speedbar-find-file func-body-file-marker)
  14534. (insert ")"))
  14535. (insert-char ?\n 1)
  14536. (put-text-property visible-start (point) 'invisible nil)))
  14537. (defun vhdl-speedbar-make-title-line (text &optional depth)
  14538. "Insert design unit title entry."
  14539. (let ((start (point))
  14540. visible-start)
  14541. (when depth
  14542. (insert (int-to-string depth) ":")
  14543. (put-text-property start (point) 'invisible t))
  14544. (setq visible-start (point))
  14545. (insert-char ? (* (or depth 0) speedbar-indentation-width))
  14546. (setq start (point))
  14547. (insert text)
  14548. (speedbar-make-button start (point) nil nil nil nil)
  14549. (insert-char ?\n 1)
  14550. (put-text-property visible-start (point) 'invisible nil)))
  14551. (defun vhdl-speedbar-insert-dirs (files level)
  14552. "Insert subdirectories."
  14553. (let ((dirs (car files)))
  14554. (while dirs
  14555. (speedbar-make-tag-line 'angle ?+ 'vhdl-speedbar-dired (car dirs)
  14556. (car dirs) 'speedbar-dir-follow nil
  14557. 'speedbar-directory-face level)
  14558. (setq dirs (cdr dirs)))))
  14559. (declare-function speedbar-reset-scanners "speedbar" ())
  14560. (defun vhdl-speedbar-dired (text token indent)
  14561. "Speedbar click handler for directory expand button in hierarchy mode."
  14562. (cond ((string-match "+" text) ; we have to expand this dir
  14563. (setq speedbar-shown-directories
  14564. (cons (expand-file-name
  14565. (concat (speedbar-line-directory indent) token "/"))
  14566. speedbar-shown-directories))
  14567. (speedbar-change-expand-button-char ?-)
  14568. (speedbar-reset-scanners)
  14569. (speedbar-with-writable
  14570. (save-excursion
  14571. (end-of-line) (forward-char 1)
  14572. (vhdl-speedbar-insert-dirs
  14573. (speedbar-file-lists
  14574. (concat (speedbar-line-directory indent) token "/"))
  14575. (1+ indent))
  14576. (speedbar-reset-scanners)
  14577. (vhdl-speedbar-insert-dir-hierarchy
  14578. (abbreviate-file-name
  14579. (concat (speedbar-line-directory indent) token "/"))
  14580. (1+ indent) speedbar-power-click)))
  14581. (vhdl-speedbar-update-current-unit t t))
  14582. ((string-match "-" text) ; we have to contract this node
  14583. (speedbar-reset-scanners)
  14584. (let ((oldl speedbar-shown-directories)
  14585. (newl nil)
  14586. (td (expand-file-name
  14587. (concat (speedbar-line-directory indent) token))))
  14588. (while oldl
  14589. (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
  14590. (push (car oldl) newl))
  14591. (setq oldl (cdr oldl)))
  14592. (setq speedbar-shown-directories (nreverse newl)))
  14593. (speedbar-change-expand-button-char ?+)
  14594. (speedbar-delete-subblock indent))
  14595. (t (error "Nothing to display")))
  14596. (when (equal (selected-frame) speedbar-frame)
  14597. (speedbar-center-buffer-smartly)))
  14598. (declare-function speedbar-files-item-info "speedbar" ())
  14599. (defun vhdl-speedbar-item-info ()
  14600. "Derive and display information about this line item."
  14601. (save-excursion
  14602. (beginning-of-line)
  14603. ;; skip invisible number info
  14604. (when (looking-at "^[0-9]+:") (goto-char (match-end 0)))
  14605. (cond
  14606. ;; project/directory entry
  14607. ((looking-at "\\s-*<[-+?]>\\s-+\\([^\n]+\\)$")
  14608. (if vhdl-speedbar-show-projects
  14609. (message "Project \"%s\"" (match-string-no-properties 1))
  14610. (speedbar-files-item-info)))
  14611. ;; design unit entry
  14612. ((looking-at "\\(\\s-*\\([[{][-+?][]}]\\|[| -]*>\\) \\)\"?\\w")
  14613. (goto-char (match-end 1))
  14614. (let ((face (get-text-property (point) 'face)))
  14615. (message
  14616. "%s \"%s\" in \"%s\""
  14617. ;; design unit kind
  14618. (cond ((or (eq face 'vhdl-speedbar-entity-face)
  14619. (eq face 'vhdl-speedbar-entity-selected-face))
  14620. (if (equal (match-string 2) ">") "Component" "Entity"))
  14621. ((or (eq face 'vhdl-speedbar-architecture-face)
  14622. (eq face 'vhdl-speedbar-architecture-selected-face))
  14623. "Architecture")
  14624. ((or (eq face 'vhdl-speedbar-configuration-face)
  14625. (eq face 'vhdl-speedbar-configuration-selected-face))
  14626. "Configuration")
  14627. ((or (eq face 'vhdl-speedbar-package-face)
  14628. (eq face 'vhdl-speedbar-package-selected-face))
  14629. "Package")
  14630. ((or (eq face 'vhdl-speedbar-instantiation-face)
  14631. (eq face 'vhdl-speedbar-instantiation-selected-face))
  14632. "Instantiation")
  14633. ((eq face 'vhdl-speedbar-subprogram-face)
  14634. "Subprogram")
  14635. (t ""))
  14636. ;; design unit name
  14637. (buffer-substring-no-properties
  14638. (progn (looking-at "\"?\\(\\(\\w\\|_\\)+\\)\"?") (match-beginning 1))
  14639. (match-end 1))
  14640. ;; file name
  14641. (file-relative-name
  14642. (or (car (get-text-property (point) 'speedbar-token))
  14643. "?")
  14644. (vhdl-default-directory)))))
  14645. (t (message "")))))
  14646. (declare-function speedbar-line-text "speedbar" (&optional p))
  14647. (defun vhdl-speedbar-line-text ()
  14648. "Calls `speedbar-line-text' and removes text properties."
  14649. (let ((string (speedbar-line-text)))
  14650. (set-text-properties 0 (length string) nil string)
  14651. string))
  14652. (defun vhdl-speedbar-higher-text ()
  14653. "Get speedbar-line-text of higher level."
  14654. (let (depth string)
  14655. (save-excursion
  14656. (beginning-of-line)
  14657. (looking-at "^\\([0-9]+\\):")
  14658. (setq depth (string-to-number (match-string 1)))
  14659. (when (re-search-backward (format "^%d: *[[<{][-+?][]>}] \\([^ \n]+\\)" (1- depth)) nil t)
  14660. (setq string (match-string 1))
  14661. (set-text-properties 0 (length string) nil string)
  14662. string))))
  14663. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14664. ;; Help functions
  14665. (defun vhdl-speedbar-line-key (&optional indent)
  14666. "Get currently displayed directory of project name."
  14667. (if vhdl-speedbar-show-projects
  14668. (vhdl-speedbar-line-project)
  14669. (abbreviate-file-name
  14670. (file-name-as-directory (speedbar-line-directory indent)))))
  14671. (defun vhdl-speedbar-line-project (&optional indent)
  14672. "Get currently displayed project name."
  14673. (and vhdl-speedbar-show-projects
  14674. (save-excursion
  14675. (end-of-line)
  14676. (re-search-backward "^[0-9]+:\\s-*<[-+?]>\\s-+\\([^\n]+\\)$" nil t)
  14677. (match-string-no-properties 1))))
  14678. (defun vhdl-add-modified-file ()
  14679. "Add file to `vhdl-modified-file-list'."
  14680. (when vhdl-file-alist
  14681. (add-to-list 'vhdl-modified-file-list (buffer-file-name)))
  14682. nil)
  14683. (defun vhdl-resolve-paths (path-list)
  14684. "Resolve path wildcards in PATH-LIST."
  14685. (let (path-list-1 path-list-2 path-beg path-end dir)
  14686. ;; eliminate non-existent directories
  14687. (while path-list
  14688. (setq dir (car path-list))
  14689. (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)" dir)
  14690. (if (file-directory-p (match-string 2 dir))
  14691. (push dir path-list-1)
  14692. (vhdl-warning-when-idle "No such directory: \"%s\"" (match-string 2 dir)))
  14693. (setq path-list (cdr path-list)))
  14694. ;; resolve path wildcards
  14695. (while path-list-1
  14696. (setq dir (car path-list-1))
  14697. (if (string-match "\\(-r \\)?\\(\\([^?*]*[/\\]\\)*\\)\\([^/\\]*[?*][^/\\]*\\)\\([/\\].*\\)" dir)
  14698. (progn
  14699. (setq path-beg (match-string 1 dir)
  14700. path-end (match-string 5 dir))
  14701. (setq path-list-1
  14702. (append
  14703. (mapcar
  14704. (function
  14705. (lambda (var) (concat path-beg var path-end)))
  14706. (let ((all-list (vhdl-directory-files
  14707. (match-string 2 dir) t
  14708. (concat "\\<" (wildcard-to-regexp
  14709. (match-string 4 dir)))))
  14710. dir-list)
  14711. (while all-list
  14712. (when (file-directory-p (car all-list))
  14713. (push (car all-list) dir-list))
  14714. (setq all-list (cdr all-list)))
  14715. dir-list))
  14716. (cdr path-list-1))))
  14717. (string-match "\\(-r \\)?\\(.*\\)[/\\].*" dir)
  14718. (when (file-directory-p (match-string 2 dir))
  14719. (push dir path-list-2))
  14720. (setq path-list-1 (cdr path-list-1))))
  14721. (nreverse path-list-2)))
  14722. (defun vhdl-speedbar-goto-this-unit (directory unit)
  14723. "If UNIT is displayed in DIRECTORY, goto this line and return t, else nil."
  14724. (let ((dest (point)))
  14725. (if (and (if vhdl-speedbar-show-projects
  14726. (progn (goto-char (point-min)) t)
  14727. (speedbar-goto-this-file directory))
  14728. (re-search-forward (concat "[]}] " unit "\\>") nil t))
  14729. (progn (speedbar-position-cursor-on-line)
  14730. t)
  14731. (goto-char dest)
  14732. nil)))
  14733. (declare-function speedbar-find-file-in-frame "speedbar" (file))
  14734. (declare-function speedbar-set-timer "speedbar" (timeout))
  14735. ;; speedbar loads dframe at runtime.
  14736. (declare-function dframe-maybee-jump-to-attached-frame "dframe" ())
  14737. (defun vhdl-speedbar-find-file (text token indent)
  14738. "When user clicks on TEXT, load file with name and position in TOKEN.
  14739. Jump to the design unit if `vhdl-speedbar-jump-to-unit' is t or if the file
  14740. is already shown in a buffer."
  14741. (if (not (car token))
  14742. (error "ERROR: File cannot be found")
  14743. (let ((buffer (get-file-buffer (car token))))
  14744. (speedbar-find-file-in-frame (car token))
  14745. (when (or vhdl-speedbar-jump-to-unit buffer)
  14746. (goto-char (point-min))
  14747. (forward-line (1- (cdr token)))
  14748. (recenter))
  14749. (vhdl-speedbar-update-current-unit t t)
  14750. (speedbar-set-timer dframe-update-speed)
  14751. (dframe-maybee-jump-to-attached-frame))))
  14752. (defun vhdl-speedbar-port-copy ()
  14753. "Copy the port of the entity/component or subprogram under the cursor."
  14754. (interactive)
  14755. (let ((is-entity (vhdl-speedbar-check-unit 'entity)))
  14756. (if (not (or is-entity (vhdl-speedbar-check-unit 'subprogram)))
  14757. (error "ERROR: No entity/component or subprogram under cursor")
  14758. (beginning-of-line)
  14759. (if (looking-at "\\([0-9]\\)+:\\s-*\\(\\[[-+?]]\\|>\\) \\(\\(\\w\\|\\s_\\)+\\)")
  14760. (condition-case info
  14761. (let ((token (get-text-property
  14762. (match-beginning 3) 'speedbar-token)))
  14763. (vhdl-visit-file (car token) t
  14764. (progn (goto-char (point-min))
  14765. (forward-line (1- (cdr token)))
  14766. (end-of-line)
  14767. (if is-entity
  14768. (vhdl-port-copy)
  14769. (vhdl-subprog-copy)))))
  14770. (error (error "ERROR: %s not scanned successfully\n (%s)"
  14771. (if is-entity "Port" "Interface") (cadr info))))
  14772. (error "ERROR: No entity/component or subprogram on current line")))))
  14773. (defun vhdl-speedbar-place-component ()
  14774. "Place the entity/component under the cursor as component."
  14775. (interactive)
  14776. (if (not (vhdl-speedbar-check-unit 'entity))
  14777. (error "ERROR: No entity/component under cursor")
  14778. (vhdl-speedbar-port-copy)
  14779. (if (fboundp 'speedbar-select-attached-frame)
  14780. (speedbar-select-attached-frame)
  14781. (select-frame speedbar-attached-frame))
  14782. (vhdl-compose-place-component)
  14783. (select-frame speedbar-frame)))
  14784. (defun vhdl-speedbar-configuration ()
  14785. "Generate configuration for the architecture under the cursor."
  14786. (interactive)
  14787. (if (not (vhdl-speedbar-check-unit 'architecture))
  14788. (error "ERROR: No architecture under cursor")
  14789. (let ((arch-name (vhdl-speedbar-line-text))
  14790. (ent-name (vhdl-speedbar-higher-text)))
  14791. (if (fboundp 'speedbar-select-attached-frame)
  14792. (speedbar-select-attached-frame)
  14793. (select-frame speedbar-attached-frame))
  14794. (vhdl-compose-configuration ent-name arch-name))))
  14795. (defun vhdl-speedbar-select-mra ()
  14796. "Select the architecture under the cursor as MRA."
  14797. (interactive)
  14798. (if (not (vhdl-speedbar-check-unit 'architecture))
  14799. (error "ERROR: No architecture under cursor")
  14800. (let* ((arch-key (downcase (vhdl-speedbar-line-text)))
  14801. (ent-key (downcase (vhdl-speedbar-higher-text)))
  14802. (ent-alist (vhdl-aget
  14803. vhdl-entity-alist
  14804. (or (vhdl-project-p)
  14805. (abbreviate-file-name default-directory))))
  14806. (ent-entry (vhdl-aget ent-alist ent-key)))
  14807. (setcar (cddr (cddr ent-entry)) arch-key) ; (nth 4 ent-entry)
  14808. (speedbar-refresh))))
  14809. (declare-function speedbar-line-file "speedbar" (&optional p))
  14810. (defun vhdl-speedbar-make-design ()
  14811. "Make (compile) design unit or directory/project under the cursor."
  14812. (interactive)
  14813. (if (not (save-excursion (beginning-of-line)
  14814. (looking-at "[0-9]+: *\\(\\(\\[\\)\\|<\\)")))
  14815. (error "ERROR: No primary design unit or directory/project under cursor")
  14816. (let ((is-unit (match-string 2))
  14817. (unit-name (vhdl-speedbar-line-text))
  14818. (vhdl-project (vhdl-speedbar-line-project))
  14819. (directory (file-name-as-directory
  14820. (or (speedbar-line-file) (speedbar-line-directory)))))
  14821. (if (fboundp 'speedbar-select-attached-frame)
  14822. (speedbar-select-attached-frame)
  14823. (select-frame speedbar-attached-frame))
  14824. (let ((default-directory directory))
  14825. (vhdl-make (and is-unit unit-name))))))
  14826. (defun vhdl-speedbar-generate-makefile ()
  14827. "Generate Makefile for directory/project under the cursor."
  14828. (interactive)
  14829. (let ((vhdl-project (vhdl-speedbar-line-project))
  14830. (default-directory (file-name-as-directory
  14831. (or (speedbar-line-file) (speedbar-line-directory)))))
  14832. (vhdl-generate-makefile)))
  14833. (defun vhdl-speedbar-check-unit (design-unit)
  14834. "Check whether design unit under cursor corresponds to DESIGN-UNIT (or its
  14835. expansion function)."
  14836. (save-excursion
  14837. (speedbar-position-cursor-on-line)
  14838. (cond ((eq design-unit 'entity)
  14839. (memq (get-text-property (match-end 0) 'face)
  14840. '(vhdl-speedbar-entity-face
  14841. vhdl-speedbar-entity-selected-face)))
  14842. ((eq design-unit 'architecture)
  14843. (memq (get-text-property (match-end 0) 'face)
  14844. '(vhdl-speedbar-architecture-face
  14845. vhdl-speedbar-architecture-selected-face)))
  14846. ((eq design-unit 'subprogram)
  14847. (eq (get-text-property (match-end 0) 'face)
  14848. 'vhdl-speedbar-subprogram-face))
  14849. (t nil))))
  14850. (defun vhdl-speedbar-set-depth (depth)
  14851. "Set hierarchy display depth to DEPTH and refresh speedbar."
  14852. (setq vhdl-speedbar-hierarchy-depth depth)
  14853. (speedbar-refresh))
  14854. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14855. ;; Fontification
  14856. (defface vhdl-speedbar-entity-face
  14857. '((((class color) (background light)) (:foreground "ForestGreen"))
  14858. (((class color) (background dark)) (:foreground "PaleGreen")))
  14859. "Face used for displaying entity names."
  14860. :group 'speedbar-faces)
  14861. (defface vhdl-speedbar-architecture-face
  14862. '((((min-colors 88) (class color) (background light)) (:foreground "Blue1"))
  14863. (((class color) (background light)) (:foreground "Blue"))
  14864. (((class color) (background dark)) (:foreground "LightSkyBlue")))
  14865. "Face used for displaying architecture names."
  14866. :group 'speedbar-faces)
  14867. (defface vhdl-speedbar-configuration-face
  14868. '((((class color) (background light)) (:foreground "DarkGoldenrod"))
  14869. (((class color) (background dark)) (:foreground "Salmon")))
  14870. "Face used for displaying configuration names."
  14871. :group 'speedbar-faces)
  14872. (defface vhdl-speedbar-package-face
  14873. '((((class color) (background light)) (:foreground "Grey50"))
  14874. (((class color) (background dark)) (:foreground "Grey80")))
  14875. "Face used for displaying package names."
  14876. :group 'speedbar-faces)
  14877. (defface vhdl-speedbar-library-face
  14878. '((((class color) (background light)) (:foreground "Purple"))
  14879. (((class color) (background dark)) (:foreground "Orchid1")))
  14880. "Face used for displaying library names."
  14881. :group 'speedbar-faces)
  14882. (defface vhdl-speedbar-instantiation-face
  14883. '((((class color) (background light)) (:foreground "Brown"))
  14884. (((min-colors 88) (class color) (background dark)) (:foreground "Yellow1"))
  14885. (((class color) (background dark)) (:foreground "Yellow")))
  14886. "Face used for displaying instantiation names."
  14887. :group 'speedbar-faces)
  14888. (defface vhdl-speedbar-subprogram-face
  14889. '((((class color) (background light)) (:foreground "Orchid4"))
  14890. (((class color) (background dark)) (:foreground "BurlyWood2")))
  14891. "Face used for displaying subprogram names."
  14892. :group 'speedbar-faces)
  14893. (defface vhdl-speedbar-entity-selected-face
  14894. '((((class color) (background light)) (:foreground "ForestGreen" :underline t))
  14895. (((class color) (background dark)) (:foreground "PaleGreen" :underline t)))
  14896. "Face used for displaying entity names."
  14897. :group 'speedbar-faces)
  14898. (defface vhdl-speedbar-architecture-selected-face
  14899. '((((min-colors 88) (class color) (background light)) (:foreground
  14900. "Blue1" :underline t))
  14901. (((class color) (background light)) (:foreground "Blue" :underline t))
  14902. (((class color) (background dark)) (:foreground "LightSkyBlue" :underline t)))
  14903. "Face used for displaying architecture names."
  14904. :group 'speedbar-faces)
  14905. (defface vhdl-speedbar-configuration-selected-face
  14906. '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
  14907. (((class color) (background dark)) (:foreground "Salmon" :underline t)))
  14908. "Face used for displaying configuration names."
  14909. :group 'speedbar-faces)
  14910. (defface vhdl-speedbar-package-selected-face
  14911. '((((class color) (background light)) (:foreground "Grey50" :underline t))
  14912. (((class color) (background dark)) (:foreground "Grey80" :underline t)))
  14913. "Face used for displaying package names."
  14914. :group 'speedbar-faces)
  14915. (defface vhdl-speedbar-instantiation-selected-face
  14916. '((((class color) (background light)) (:foreground "Brown" :underline t))
  14917. (((class color) (background dark)) (:foreground "Yellow" :underline t)))
  14918. "Face used for displaying instantiation names."
  14919. :group 'speedbar-faces)
  14920. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14921. ;; Initialization
  14922. ;; add speedbar
  14923. (when (fboundp 'speedbar)
  14924. (let ((current-frame (selected-frame)))
  14925. (condition-case ()
  14926. (when (and vhdl-speedbar-auto-open
  14927. (not (and (boundp 'speedbar-frame)
  14928. (frame-live-p speedbar-frame))))
  14929. (speedbar-frame-mode 1))
  14930. (error (vhdl-warning-when-idle "ERROR: An error occurred while opening speedbar")))
  14931. (select-frame current-frame)))
  14932. ;; initialize speedbar
  14933. (if (not (boundp 'speedbar-frame))
  14934. (add-hook 'speedbar-load-hook 'vhdl-speedbar-initialize)
  14935. (vhdl-speedbar-initialize)
  14936. (when speedbar-frame (vhdl-speedbar-refresh)))
  14937. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14938. ;;; Structural composition
  14939. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14940. (defun vhdl-get-components-package-name ()
  14941. "Return the name of the components package."
  14942. (let ((project (vhdl-project-p)))
  14943. (if project
  14944. (vhdl-replace-string (car vhdl-components-package-name)
  14945. (subst-char-in-string ? ?_ project))
  14946. (cdr vhdl-components-package-name))))
  14947. (defun vhdl-compose-new-component ()
  14948. "Create entity and architecture for new component."
  14949. (interactive)
  14950. (let* ((case-fold-search t)
  14951. (ent-name (read-from-minibuffer "entity name: "
  14952. nil vhdl-minibuffer-local-map))
  14953. (arch-name
  14954. (if (equal (cdr vhdl-compose-architecture-name) "")
  14955. (read-from-minibuffer "architecture name: "
  14956. nil vhdl-minibuffer-local-map)
  14957. (vhdl-replace-string vhdl-compose-architecture-name ent-name)))
  14958. ent-file-name arch-file-name ent-buffer arch-buffer project end-pos)
  14959. (message "Creating component \"%s(%s)\"..." ent-name arch-name)
  14960. ;; open entity file
  14961. (unless (eq vhdl-compose-create-files 'none)
  14962. (setq ent-file-name
  14963. (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
  14964. "." (file-name-extension (buffer-file-name))))
  14965. (when (and (file-exists-p ent-file-name)
  14966. (not (y-or-n-p (concat "File \"" ent-file-name
  14967. "\" exists; overwrite? "))))
  14968. (error "ERROR: Creating component...aborted"))
  14969. (find-file ent-file-name)
  14970. (erase-buffer)
  14971. (set-buffer-modified-p nil))
  14972. ;; insert header
  14973. (if vhdl-compose-include-header
  14974. (progn (vhdl-template-header)
  14975. (setq end-pos (point))
  14976. (goto-char (point-max)))
  14977. (vhdl-comment-display-line) (insert "\n\n"))
  14978. ;; insert library clause
  14979. (vhdl-template-package-std-logic-1164)
  14980. (when vhdl-use-components-package
  14981. (insert "\n")
  14982. (vhdl-template-standard-package (vhdl-work-library)
  14983. (vhdl-get-components-package-name)))
  14984. (insert "\n\n") (vhdl-comment-display-line) (insert "\n\n")
  14985. ;; insert entity declaration
  14986. (vhdl-insert-keyword "ENTITY ") (insert ent-name)
  14987. (vhdl-insert-keyword " IS\n")
  14988. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  14989. (indent-to vhdl-basic-offset) (vhdl-insert-keyword "GENERIC (\n")
  14990. (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
  14991. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  14992. (indent-to vhdl-basic-offset) (vhdl-insert-keyword "PORT (\n")
  14993. (indent-to (* 2 vhdl-basic-offset)) (insert ");\n")
  14994. (when (memq vhdl-insert-empty-lines '(unit all)) (insert "\n"))
  14995. (vhdl-insert-keyword "END ")
  14996. (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ENTITY "))
  14997. (insert ent-name ";\n\n")
  14998. (vhdl-comment-display-line) (insert "\n")
  14999. ;; open architecture file
  15000. (if (not (eq vhdl-compose-create-files 'separate))
  15001. (insert "\n")
  15002. (goto-char (or end-pos (point-min)))
  15003. (setq ent-buffer (current-buffer))
  15004. (setq arch-file-name
  15005. (concat (vhdl-replace-string vhdl-architecture-file-name
  15006. (concat ent-name " " arch-name) t)
  15007. "." (file-name-extension (buffer-file-name))))
  15008. (when (and (file-exists-p arch-file-name)
  15009. (not (y-or-n-p (concat "File \"" arch-file-name
  15010. "\" exists; overwrite? "))))
  15011. (error "ERROR: Creating component...aborted"))
  15012. (find-file arch-file-name)
  15013. (erase-buffer)
  15014. (set-buffer-modified-p nil)
  15015. ;; insert header
  15016. (if vhdl-compose-include-header
  15017. (progn (vhdl-template-header)
  15018. (goto-char (point-max)))
  15019. (vhdl-comment-display-line) (insert "\n\n")))
  15020. ;; insert architecture body
  15021. (vhdl-insert-keyword "ARCHITECTURE ") (insert arch-name)
  15022. (vhdl-insert-keyword " OF ") (insert ent-name)
  15023. (vhdl-insert-keyword " IS\n\n")
  15024. (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
  15025. (indent-to vhdl-basic-offset) (insert "-- Internal signal declarations\n")
  15026. (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
  15027. (unless (or vhdl-use-components-package (vhdl-use-direct-instantiation))
  15028. (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
  15029. (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
  15030. (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n"))
  15031. (vhdl-insert-keyword "BEGIN")
  15032. (when vhdl-self-insert-comments
  15033. (insert " -- ")
  15034. (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
  15035. (insert arch-name))
  15036. (insert "\n\n")
  15037. (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
  15038. (indent-to vhdl-basic-offset) (insert "-- Component instantiations\n")
  15039. (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
  15040. (vhdl-insert-keyword "END ")
  15041. (unless (vhdl-standard-p '87) (vhdl-insert-keyword "ARCHITECTURE "))
  15042. (insert arch-name ";\n\n")
  15043. ;; insert footer and save
  15044. (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
  15045. (vhdl-template-footer)
  15046. (vhdl-comment-display-line) (insert "\n"))
  15047. (goto-char (or end-pos (point-min)))
  15048. (setq arch-buffer (current-buffer))
  15049. (when ent-buffer (set-buffer ent-buffer) (save-buffer))
  15050. (set-buffer arch-buffer) (save-buffer)
  15051. (message "%s"
  15052. (concat (format "Creating component \"%s(%s)\"...done" ent-name arch-name)
  15053. (and ent-file-name
  15054. (format "\n File created: \"%s\"" ent-file-name))
  15055. (and arch-file-name
  15056. (format "\n File created: \"%s\"" arch-file-name))))))
  15057. (defun vhdl-compose-place-component ()
  15058. "Place new component by pasting current port as component declaration and
  15059. component instantiation."
  15060. (interactive)
  15061. (if (not vhdl-port-list)
  15062. (error "ERROR: No port has been read")
  15063. (save-excursion
  15064. (vhdl-prepare-search-2
  15065. (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)
  15066. (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))
  15067. (error "ERROR: No architecture found"))
  15068. (let* ((ent-name (match-string 1))
  15069. (ent-file-name
  15070. (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
  15071. "." (file-name-extension (buffer-file-name))))
  15072. (orig-buffer (current-buffer)))
  15073. (message "Placing component \"%s\"..." (nth 0 vhdl-port-list))
  15074. ;; place component declaration
  15075. (unless (or vhdl-use-components-package
  15076. (vhdl-use-direct-instantiation)
  15077. (save-excursion
  15078. (re-search-forward
  15079. (concat "^\\s-*component\\s-+"
  15080. (car vhdl-port-list) "\\>") nil t)))
  15081. (re-search-forward "^begin\\>" nil)
  15082. (beginning-of-line)
  15083. (skip-chars-backward " \t\n\r\f")
  15084. (insert "\n\n") (indent-to vhdl-basic-offset)
  15085. (vhdl-port-paste-component t))
  15086. ;; place component instantiation
  15087. (re-search-forward "^end\\>" nil)
  15088. (beginning-of-line)
  15089. (skip-chars-backward " \t\n\r\f")
  15090. (insert "\n\n") (indent-to vhdl-basic-offset)
  15091. (vhdl-port-paste-instance nil t t)
  15092. ;; place use clause for used packages
  15093. (when (nth 3 vhdl-port-list)
  15094. ;; open entity file
  15095. (when (file-exists-p ent-file-name)
  15096. (find-file ent-file-name))
  15097. (goto-char (point-min))
  15098. (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name "[ \t\n\r\f]+is\\>") nil t)
  15099. (error "ERROR: Entity not found: \"%s\"" ent-name))
  15100. (goto-char (match-beginning 0))
  15101. (if (and (save-excursion
  15102. (re-search-backward "^\\(library\\|use\\)\\|end\\>" nil t))
  15103. (match-string 1))
  15104. (progn (goto-char (match-end 0))
  15105. (beginning-of-line 2))
  15106. (insert "\n")
  15107. (backward-char))
  15108. (vhdl-port-paste-context-clause)
  15109. (switch-to-buffer orig-buffer))
  15110. (message "Placing component \"%s\"...done" (nth 0 vhdl-port-list)))))))
  15111. (defun vhdl-compose-wire-components ()
  15112. "Connect components."
  15113. (interactive)
  15114. (save-excursion
  15115. (vhdl-prepare-search-2
  15116. (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)
  15117. (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))
  15118. (error "ERROR: No architecture found"))
  15119. (let* ((ent-name (match-string 1))
  15120. (ent-file-name
  15121. (concat (vhdl-replace-string vhdl-entity-file-name ent-name t)
  15122. "." (file-name-extension (buffer-file-name))))
  15123. (arch-decl-pos (point-marker))
  15124. (arch-stat-pos (re-search-forward "^begin\\>" nil))
  15125. (arch-end-pos (re-search-forward "^end\\>" nil))
  15126. (pack-name (vhdl-get-components-package-name))
  15127. (pack-file-name
  15128. (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
  15129. "." (file-name-extension (buffer-file-name))))
  15130. inst-name comp-name comp-ent-name comp-ent-file-name has-generic
  15131. port-alist generic-alist inst-alist
  15132. signal-name signal-entry signal-alist local-list written-list
  15133. single-in-list multi-in-list single-out-list multi-out-list
  15134. constant-name constant-entry constant-alist single-list multi-list
  15135. port-beg-pos port-in-pos port-out-pos port-inst-pos port-end-pos
  15136. generic-beg-pos generic-pos generic-inst-pos generic-end-pos
  15137. signal-beg-pos signal-pos
  15138. constant-temp-pos port-temp-pos signal-temp-pos)
  15139. (message "Wiring components...")
  15140. ;; process all instances
  15141. (goto-char arch-stat-pos)
  15142. (while (re-search-forward
  15143. (concat "^[ \t]*\\(\\w+\\)[ \t\n\r\f]*:[ \t\n\r\f]*\\("
  15144. "\\(component[ \t\n\r\f]+\\)?\\(\\w+\\)"
  15145. "[ \t\n\r\f]+\\(--[^\n]*\n[ \t\n\r\f]*\\)*\\(\\(generic\\)\\|port\\)[ \t\n\r\f]+map\\|"
  15146. "\\(\\(entity\\)\\|configuration\\)[ \t\n\r\f]+\\(\\(\\w+\\)\\.\\)?\\(\\w+\\)\\([ \t\n\r\f]*(\\(\\w+\\))\\)?"
  15147. "[ \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)
  15148. (setq inst-name (match-string-no-properties 1)
  15149. comp-name (match-string-no-properties 4)
  15150. comp-ent-name (match-string-no-properties 12)
  15151. has-generic (or (match-string 7) (match-string 17)))
  15152. ;; get port ...
  15153. (if comp-name
  15154. ;; ... from component declaration
  15155. (vhdl-visit-file
  15156. (when vhdl-use-components-package pack-file-name) t
  15157. (save-excursion
  15158. (goto-char (point-min))
  15159. (unless (re-search-forward (concat "^\\s-*component[ \t\n\r\f]+" comp-name "\\>") nil t)
  15160. (error "ERROR: Component declaration not found: \"%s\"" comp-name))
  15161. (vhdl-port-copy)))
  15162. ;; ... from entity declaration (direct instantiation)
  15163. (setq comp-ent-file-name
  15164. (concat (vhdl-replace-string vhdl-entity-file-name comp-ent-name t)
  15165. "." (file-name-extension (buffer-file-name))))
  15166. (vhdl-visit-file
  15167. comp-ent-file-name t
  15168. (save-excursion
  15169. (goto-char (point-min))
  15170. (unless (re-search-forward (concat "^\\s-*entity[ \t\n\r\f]+" comp-ent-name "\\>") nil t)
  15171. (error "ERROR: Entity declaration not found: \"%s\"" comp-ent-name))
  15172. (vhdl-port-copy))))
  15173. (vhdl-port-flatten t)
  15174. (setq generic-alist (nth 1 vhdl-port-list)
  15175. port-alist (nth 2 vhdl-port-list)
  15176. vhdl-port-list nil)
  15177. (setq constant-alist nil
  15178. signal-alist nil)
  15179. (when has-generic
  15180. ;; process all constants in generic map
  15181. (vhdl-forward-syntactic-ws)
  15182. (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t)
  15183. (setq constant-name (match-string-no-properties 3))
  15184. (setq constant-entry
  15185. (cons constant-name
  15186. (if (match-string 1)
  15187. (or (vhdl-aget generic-alist (match-string 2))
  15188. (error "ERROR: Formal generic \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
  15189. (cdar generic-alist))))
  15190. (push constant-entry constant-alist)
  15191. (setq constant-name (downcase constant-name))
  15192. (if (or (member constant-name single-list)
  15193. (member constant-name multi-list))
  15194. (progn (setq single-list (delete constant-name single-list))
  15195. (add-to-list 'multi-list constant-name))
  15196. (add-to-list 'single-list constant-name))
  15197. (unless (match-string 1)
  15198. (setq generic-alist (cdr generic-alist)))
  15199. (vhdl-forward-syntactic-ws))
  15200. (vhdl-re-search-forward "\\<port\\s-+map[ \t\n\r\f]*(" nil t))
  15201. ;; process all signals in port map
  15202. (vhdl-forward-syntactic-ws)
  15203. (while (vhdl-parse-string "\\(\\(\\w+\\)[ \t\n\r\f]*=>[ \t\n\r\f]*\\)?\\(\\w+\\),?" t)
  15204. (setq signal-name (match-string-no-properties 3))
  15205. (setq signal-entry
  15206. (cons signal-name
  15207. (if (match-string 1)
  15208. (or (vhdl-aget port-alist (match-string 2))
  15209. (error "ERROR: Formal port \"%s\" mismatch for instance \"%s\"" (match-string 2) inst-name))
  15210. (cdar port-alist))))
  15211. (push signal-entry signal-alist)
  15212. (setq signal-name (downcase signal-name))
  15213. (if (equal (upcase (nth 2 signal-entry)) "IN")
  15214. ;; input signal
  15215. (cond
  15216. ((member signal-name local-list)
  15217. nil)
  15218. ((or (member signal-name single-out-list)
  15219. (member signal-name multi-out-list))
  15220. (setq single-out-list (delete signal-name single-out-list))
  15221. (setq multi-out-list (delete signal-name multi-out-list))
  15222. (add-to-list 'local-list signal-name))
  15223. ((member signal-name single-in-list)
  15224. (setq single-in-list (delete signal-name single-in-list))
  15225. (add-to-list 'multi-in-list signal-name))
  15226. ((not (member signal-name multi-in-list))
  15227. (add-to-list 'single-in-list signal-name)))
  15228. ;; output signal
  15229. (cond
  15230. ((member signal-name local-list)
  15231. nil)
  15232. ((or (member signal-name single-in-list)
  15233. (member signal-name multi-in-list))
  15234. (setq single-in-list (delete signal-name single-in-list))
  15235. (setq multi-in-list (delete signal-name multi-in-list))
  15236. (add-to-list 'local-list signal-name))
  15237. ((member signal-name single-out-list)
  15238. (setq single-out-list (delete signal-name single-out-list))
  15239. (add-to-list 'multi-out-list signal-name))
  15240. ((not (member signal-name multi-out-list))
  15241. (add-to-list 'single-out-list signal-name))))
  15242. (unless (match-string 1)
  15243. (setq port-alist (cdr port-alist)))
  15244. (vhdl-forward-syntactic-ws))
  15245. (push (list inst-name (nreverse constant-alist)
  15246. (nreverse signal-alist)) inst-alist))
  15247. ;; prepare signal insertion
  15248. (vhdl-goto-marker arch-decl-pos)
  15249. (forward-line 1)
  15250. (re-search-forward "^\\s-*-- Internal signal declarations[ \t\n\r\f]*-*\n" arch-stat-pos t)
  15251. (setq signal-pos (point-marker))
  15252. (while (progn (vhdl-forward-syntactic-ws)
  15253. (looking-at "signal\\>"))
  15254. (beginning-of-line 2)
  15255. (delete-region signal-pos (point)))
  15256. (setq signal-beg-pos signal-pos)
  15257. ;; open entity file
  15258. (when (file-exists-p ent-file-name)
  15259. (find-file ent-file-name))
  15260. (goto-char (point-min))
  15261. (unless (re-search-forward (concat "^entity[ \t\n\r\f]+" ent-name "[ \t\n\r\f]+is\\>") nil t)
  15262. (error "ERROR: Entity not found: \"%s\"" ent-name))
  15263. ;; prepare generic clause insertion
  15264. (unless (and (re-search-forward "\\(^\\s-*generic[ \t\n\r\f]*(\\)\\|^end\\>" nil t)
  15265. (match-string 1))
  15266. (goto-char (match-beginning 0))
  15267. (indent-to vhdl-basic-offset)
  15268. (insert "generic ();\n\n")
  15269. (backward-char 4))
  15270. (backward-char)
  15271. (setq generic-pos (point-marker))
  15272. (forward-sexp) (end-of-line)
  15273. (delete-region generic-pos (point)) (delete-char 1)
  15274. (insert "(\n")
  15275. (when multi-list
  15276. (insert "\n")
  15277. (indent-to (* 2 vhdl-basic-offset))
  15278. (insert "-- global generics\n"))
  15279. (setq generic-beg-pos (point-marker) generic-pos (point-marker)
  15280. generic-inst-pos (point-marker) generic-end-pos (point-marker))
  15281. ;; prepare port clause insertion
  15282. (unless (and (re-search-forward "\\(^\\s-*port[ \t\n\r\f]*(\\)\\|^end\\>" nil t)
  15283. (match-string 1))
  15284. (goto-char (match-beginning 0))
  15285. (indent-to vhdl-basic-offset)
  15286. (insert "port ();\n\n")
  15287. (backward-char 4))
  15288. (backward-char)
  15289. (setq port-in-pos (point-marker))
  15290. (forward-sexp) (end-of-line)
  15291. (delete-region port-in-pos (point)) (delete-char 1)
  15292. (insert "(\n")
  15293. (when (or multi-in-list multi-out-list)
  15294. (insert "\n")
  15295. (indent-to (* 2 vhdl-basic-offset))
  15296. (insert "-- global ports\n"))
  15297. (setq port-beg-pos (point-marker) port-in-pos (point-marker)
  15298. port-out-pos (point-marker) port-inst-pos (point-marker)
  15299. port-end-pos (point-marker))
  15300. ;; insert generics, ports and signals
  15301. (setq inst-alist (nreverse inst-alist))
  15302. (while inst-alist
  15303. (setq inst-name (nth 0 (car inst-alist))
  15304. constant-alist (nth 1 (car inst-alist))
  15305. signal-alist (nth 2 (car inst-alist))
  15306. constant-temp-pos generic-inst-pos
  15307. port-temp-pos port-inst-pos
  15308. signal-temp-pos signal-pos)
  15309. ;; generics
  15310. (while constant-alist
  15311. (setq constant-name (downcase (caar constant-alist))
  15312. constant-entry (car constant-alist))
  15313. (unless (string-match "^[0-9]+" constant-name)
  15314. (cond ((member constant-name written-list)
  15315. nil)
  15316. ((member constant-name multi-list)
  15317. (vhdl-goto-marker generic-pos)
  15318. (setq generic-end-pos
  15319. (vhdl-max-marker
  15320. generic-end-pos
  15321. (vhdl-compose-insert-generic constant-entry)))
  15322. (setq generic-pos (point-marker))
  15323. (add-to-list 'written-list constant-name))
  15324. (t
  15325. (vhdl-goto-marker
  15326. (vhdl-max-marker generic-inst-pos generic-pos))
  15327. (setq generic-end-pos
  15328. (vhdl-compose-insert-generic constant-entry))
  15329. (setq generic-inst-pos (point-marker))
  15330. (add-to-list 'written-list constant-name))))
  15331. (setq constant-alist (cdr constant-alist)))
  15332. (when (/= constant-temp-pos generic-inst-pos)
  15333. (vhdl-goto-marker (vhdl-max-marker constant-temp-pos generic-pos))
  15334. (insert "\n") (indent-to (* 2 vhdl-basic-offset))
  15335. (insert "-- generics for \"" inst-name "\"\n")
  15336. (vhdl-goto-marker generic-inst-pos))
  15337. ;; ports and signals
  15338. (while signal-alist
  15339. (setq signal-name (downcase (caar signal-alist))
  15340. signal-entry (car signal-alist))
  15341. (cond ((member signal-name written-list)
  15342. nil)
  15343. ((member signal-name multi-in-list)
  15344. (vhdl-goto-marker port-in-pos)
  15345. (setq port-end-pos
  15346. (vhdl-max-marker
  15347. port-end-pos (vhdl-compose-insert-port signal-entry)))
  15348. (setq port-in-pos (point-marker))
  15349. (add-to-list 'written-list signal-name))
  15350. ((member signal-name multi-out-list)
  15351. (vhdl-goto-marker (vhdl-max-marker port-out-pos port-in-pos))
  15352. (setq port-end-pos
  15353. (vhdl-max-marker
  15354. port-end-pos (vhdl-compose-insert-port signal-entry)))
  15355. (setq port-out-pos (point-marker))
  15356. (add-to-list 'written-list signal-name))
  15357. ((or (member signal-name single-in-list)
  15358. (member signal-name single-out-list))
  15359. (vhdl-goto-marker
  15360. (vhdl-max-marker
  15361. port-inst-pos
  15362. (vhdl-max-marker port-out-pos port-in-pos)))
  15363. (setq port-end-pos (vhdl-compose-insert-port signal-entry))
  15364. (setq port-inst-pos (point-marker))
  15365. (add-to-list 'written-list signal-name))
  15366. ((equal (upcase (nth 2 signal-entry)) "OUT")
  15367. (vhdl-goto-marker signal-pos)
  15368. (vhdl-compose-insert-signal signal-entry)
  15369. (setq signal-pos (point-marker))
  15370. (add-to-list 'written-list signal-name)))
  15371. (setq signal-alist (cdr signal-alist)))
  15372. (when (/= port-temp-pos port-inst-pos)
  15373. (vhdl-goto-marker
  15374. (vhdl-max-marker port-temp-pos
  15375. (vhdl-max-marker port-in-pos port-out-pos)))
  15376. (insert "\n") (indent-to (* 2 vhdl-basic-offset))
  15377. (insert "-- ports to \"" inst-name "\"\n")
  15378. (vhdl-goto-marker port-inst-pos))
  15379. (when (/= signal-temp-pos signal-pos)
  15380. (vhdl-goto-marker signal-temp-pos)
  15381. (insert "\n") (indent-to vhdl-basic-offset)
  15382. (insert "-- outputs of \"" inst-name "\"\n")
  15383. (vhdl-goto-marker signal-pos))
  15384. (setq inst-alist (cdr inst-alist)))
  15385. ;; finalize generic/port clause
  15386. (vhdl-goto-marker generic-end-pos) (backward-char)
  15387. (when (= generic-beg-pos generic-end-pos)
  15388. (insert "\n") (indent-to (* 2 vhdl-basic-offset))
  15389. (insert ";") (backward-char))
  15390. (insert ")")
  15391. (vhdl-goto-marker port-end-pos) (backward-char)
  15392. (when (= port-beg-pos port-end-pos)
  15393. (insert "\n") (indent-to (* 2 vhdl-basic-offset))
  15394. (insert ";") (backward-char))
  15395. (insert ")")
  15396. ;; align everything
  15397. (when vhdl-auto-align
  15398. (vhdl-goto-marker generic-beg-pos)
  15399. (vhdl-align-region-groups generic-beg-pos generic-end-pos 1)
  15400. (vhdl-align-region-groups port-beg-pos port-end-pos 1)
  15401. (vhdl-goto-marker signal-beg-pos)
  15402. (vhdl-align-region-groups signal-beg-pos signal-pos))
  15403. (switch-to-buffer (marker-buffer signal-beg-pos))
  15404. (message "Wiring components...done")))))
  15405. (defun vhdl-compose-insert-generic (entry)
  15406. "Insert ENTRY as generic declaration."
  15407. (let (pos)
  15408. (indent-to (* 2 vhdl-basic-offset))
  15409. (insert (nth 0 entry) " : " (nth 1 entry))
  15410. (when (nth 2 entry)
  15411. (insert " := " (nth 2 entry)))
  15412. (insert ";")
  15413. (setq pos (point-marker))
  15414. (when (and vhdl-include-port-comments (nth 3 entry))
  15415. (vhdl-comment-insert-inline (nth 3 entry) t))
  15416. (insert "\n")
  15417. pos))
  15418. (defun vhdl-compose-insert-port (entry)
  15419. "Insert ENTRY as port declaration."
  15420. (let (pos)
  15421. (indent-to (* 2 vhdl-basic-offset))
  15422. (insert (nth 0 entry) " : " (nth 2 entry) " " (nth 3 entry) ";")
  15423. (setq pos (point-marker))
  15424. (when (and vhdl-include-port-comments (nth 4 entry))
  15425. (vhdl-comment-insert-inline (nth 4 entry) t))
  15426. (insert "\n")
  15427. pos))
  15428. (defun vhdl-compose-insert-signal (entry)
  15429. "Insert ENTRY as signal declaration."
  15430. (indent-to vhdl-basic-offset)
  15431. (insert "signal " (nth 0 entry) " : " (nth 3 entry) ";")
  15432. (when (and vhdl-include-port-comments (nth 4 entry))
  15433. (vhdl-comment-insert-inline (nth 4 entry) t))
  15434. (insert "\n"))
  15435. (defun vhdl-compose-components-package ()
  15436. "Generate a package containing component declarations for all entities in the
  15437. current project/directory."
  15438. (interactive)
  15439. (vhdl-require-hierarchy-info)
  15440. (let* ((project (vhdl-project-p))
  15441. (pack-name (vhdl-get-components-package-name))
  15442. (pack-file-name
  15443. (concat (vhdl-replace-string vhdl-package-file-name pack-name t)
  15444. "." (file-name-extension (buffer-file-name))))
  15445. (ent-alist (vhdl-aget vhdl-entity-alist
  15446. (or project
  15447. (abbreviate-file-name default-directory))))
  15448. (lazy-lock-minimum-size 0)
  15449. clause-pos component-pos)
  15450. (message "Generating components package \"%s\"..." pack-name)
  15451. ;; open package file
  15452. (when (and (file-exists-p pack-file-name)
  15453. (not (y-or-n-p (concat "File \"" pack-file-name
  15454. "\" exists; overwrite? "))))
  15455. (error "ERROR: Generating components package...aborted"))
  15456. (find-file pack-file-name)
  15457. (erase-buffer)
  15458. ;; insert header
  15459. (if vhdl-compose-include-header
  15460. (progn (vhdl-template-header
  15461. (concat "Components package (generated by Emacs VHDL Mode "
  15462. vhdl-version ")"))
  15463. (goto-char (point-max)))
  15464. (vhdl-comment-display-line) (insert "\n\n"))
  15465. ;; insert std_logic_1164 package
  15466. (vhdl-template-package-std-logic-1164)
  15467. (insert "\n") (setq clause-pos (point-marker))
  15468. (insert "\n") (vhdl-comment-display-line) (insert "\n\n")
  15469. ;; insert package declaration
  15470. (vhdl-insert-keyword "PACKAGE ") (insert pack-name)
  15471. (vhdl-insert-keyword " IS\n\n")
  15472. (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n")
  15473. (indent-to vhdl-basic-offset) (insert "-- Component declarations\n")
  15474. (indent-to vhdl-basic-offset) (vhdl-comment-display-line) (insert "\n\n")
  15475. (indent-to vhdl-basic-offset)
  15476. (setq component-pos (point-marker))
  15477. (insert "\n\n") (vhdl-insert-keyword "END ")
  15478. (unless (vhdl-standard-p '87) (vhdl-insert-keyword "PACKAGE "))
  15479. (insert pack-name ";\n\n")
  15480. ;; insert footer
  15481. (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
  15482. (vhdl-template-footer)
  15483. (vhdl-comment-display-line) (insert "\n"))
  15484. ;; insert component declarations
  15485. (while ent-alist
  15486. (vhdl-visit-file (nth 2 (car ent-alist)) nil
  15487. (progn (goto-char (point-min))
  15488. (forward-line (1- (nth 3 (car ent-alist))))
  15489. (end-of-line)
  15490. (vhdl-port-copy)))
  15491. (goto-char component-pos)
  15492. (vhdl-port-paste-component t)
  15493. (when (cdr ent-alist) (insert "\n\n") (indent-to vhdl-basic-offset))
  15494. (setq component-pos (point-marker))
  15495. (goto-char clause-pos)
  15496. (vhdl-port-paste-context-clause pack-name)
  15497. (setq clause-pos (point-marker))
  15498. (setq ent-alist (cdr ent-alist)))
  15499. (goto-char (point-min))
  15500. (save-buffer)
  15501. (message "Generating components package \"%s\"...done\n File created: \"%s\""
  15502. pack-name pack-file-name)))
  15503. (defun vhdl-compose-configuration-architecture (ent-name arch-name ent-alist
  15504. conf-alist inst-alist
  15505. &optional insert-conf)
  15506. "Generate block configuration for architecture."
  15507. (let ((margin (current-indentation))
  15508. (beg (point-at-bol))
  15509. ent-entry inst-entry inst-path inst-prev-path cons-key tmp-alist)
  15510. ;; insert block configuration (for architecture)
  15511. (vhdl-insert-keyword "FOR ") (insert arch-name "\n")
  15512. (setq margin (+ margin vhdl-basic-offset))
  15513. ;; process all instances
  15514. (while inst-alist
  15515. (setq inst-entry (car inst-alist))
  15516. ;; is component?
  15517. (when (nth 4 inst-entry)
  15518. (setq insert-conf t)
  15519. (setq inst-path (nth 9 inst-entry))
  15520. ;; skip common path with previous instance
  15521. (while (and inst-path (equal (car inst-path) (car inst-prev-path)))
  15522. (setq inst-path (cdr inst-path)
  15523. inst-prev-path (cdr inst-prev-path)))
  15524. ;; insert block configuration end (for previous block/generate)
  15525. (while inst-prev-path
  15526. (setq margin (- margin vhdl-basic-offset))
  15527. (indent-to margin)
  15528. (vhdl-insert-keyword "END FOR;\n")
  15529. (setq inst-prev-path (cdr inst-prev-path)))
  15530. ;; insert block configuration beginning (for current block/generate)
  15531. (indent-to margin)
  15532. (while inst-path
  15533. (setq margin (+ margin vhdl-basic-offset))
  15534. (vhdl-insert-keyword "FOR ")
  15535. (insert (car inst-path) "\n")
  15536. (indent-to margin)
  15537. (setq inst-path (cdr inst-path)))
  15538. ;; insert component configuration beginning
  15539. (vhdl-insert-keyword "FOR ")
  15540. (insert (nth 1 inst-entry) " : " (nth 4 inst-entry) "\n")
  15541. ;; find subconfiguration
  15542. (setq conf-key (nth 7 inst-entry))
  15543. (setq tmp-alist conf-alist)
  15544. ;; use first configuration found for instance's entity
  15545. (while (and tmp-alist (null conf-key))
  15546. (when (equal (nth 5 inst-entry) (nth 4 (car tmp-alist)))
  15547. (setq conf-key (nth 0 (car tmp-alist))))
  15548. (setq tmp-alist (cdr tmp-alist)))
  15549. (setq conf-entry (vhdl-aget conf-alist conf-key))
  15550. ;; insert binding indication ...
  15551. ;; ... with subconfiguration (if exists)
  15552. (if (and vhdl-compose-configuration-use-subconfiguration conf-entry)
  15553. (progn
  15554. (indent-to (+ margin vhdl-basic-offset))
  15555. (vhdl-insert-keyword "USE CONFIGURATION ")
  15556. (insert (vhdl-work-library) "." (nth 0 conf-entry))
  15557. (insert ";\n"))
  15558. ;; ... with entity (if exists)
  15559. (setq ent-entry (vhdl-aget ent-alist (nth 5 inst-entry)))
  15560. (when ent-entry
  15561. (indent-to (+ margin vhdl-basic-offset))
  15562. (vhdl-insert-keyword "USE ENTITY ")
  15563. (insert (vhdl-work-library) "." (nth 0 ent-entry))
  15564. ;; insert architecture name (if architecture exists)
  15565. (when (nth 3 ent-entry)
  15566. (setq arch-name
  15567. ;; choose architecture name a) from configuration,
  15568. ;; b) from mra, or c) from first architecture
  15569. (or (nth 0 (vhdl-aget (nth 3 ent-entry)
  15570. (or (nth 6 inst-entry)
  15571. (nth 4 ent-entry))))
  15572. (nth 1 (car (nth 3 ent-entry)))))
  15573. (insert "(" arch-name ")"))
  15574. (insert ";\n")
  15575. ;; insert block configuration (for architecture of subcomponent)
  15576. (when (and vhdl-compose-configuration-hierarchical
  15577. (nth 3 ent-entry))
  15578. (indent-to (+ margin vhdl-basic-offset))
  15579. (vhdl-compose-configuration-architecture
  15580. (nth 0 ent-entry) arch-name ent-alist conf-alist
  15581. (nth 3 (vhdl-aget (nth 3 ent-entry) (downcase arch-name)))))))
  15582. ;; insert component configuration end
  15583. (indent-to margin)
  15584. (vhdl-insert-keyword "END FOR;\n")
  15585. (setq inst-prev-path (nth 9 inst-entry)))
  15586. (setq inst-alist (cdr inst-alist)))
  15587. ;; insert block configuration end (for block/generate)
  15588. (while inst-prev-path
  15589. (setq margin (- margin vhdl-basic-offset))
  15590. (indent-to margin)
  15591. (vhdl-insert-keyword "END FOR;\n")
  15592. (setq inst-prev-path (cdr inst-prev-path)))
  15593. (indent-to (- margin vhdl-basic-offset))
  15594. ;; insert block configuration end or remove beginning (for architecture)
  15595. (if insert-conf
  15596. (vhdl-insert-keyword "END FOR;\n")
  15597. (delete-region beg (point)))))
  15598. (defun vhdl-compose-configuration (&optional ent-name arch-name)
  15599. "Generate configuration declaration."
  15600. (interactive)
  15601. (vhdl-require-hierarchy-info)
  15602. (let ((ent-alist (vhdl-aget vhdl-entity-alist
  15603. (or (vhdl-project-p)
  15604. (abbreviate-file-name default-directory))))
  15605. (conf-alist (vhdl-aget vhdl-config-alist
  15606. (or (vhdl-project-p)
  15607. (abbreviate-file-name default-directory))))
  15608. (from-speedbar ent-name)
  15609. inst-alist conf-name conf-file-name pos)
  15610. (vhdl-prepare-search-2
  15611. ;; get entity and architecture name
  15612. (unless ent-name
  15613. (save-excursion
  15614. (unless (and (re-search-backward "^\\(architecture\\s-+\\(\\w+\\)\\s-+of\\s-+\\(\\w+\\)\\|end\\)\\>" nil t)
  15615. (not (equal "END" (upcase (match-string 1))))
  15616. (setq ent-name (match-string-no-properties 3))
  15617. (setq arch-name (match-string-no-properties 2)))
  15618. (error "ERROR: Not within an architecture"))))
  15619. (setq conf-name (vhdl-replace-string
  15620. vhdl-compose-configuration-name
  15621. (concat ent-name " " arch-name)))
  15622. (setq inst-alist
  15623. (nth 3 (vhdl-aget (nth 3 (vhdl-aget ent-alist (downcase ent-name)))
  15624. (downcase arch-name)))))
  15625. (message "Generating configuration \"%s\"..." conf-name)
  15626. (if vhdl-compose-configuration-create-file
  15627. ;; open configuration file
  15628. (progn
  15629. (setq conf-file-name
  15630. (concat (vhdl-replace-string vhdl-configuration-file-name
  15631. conf-name t)
  15632. "." (file-name-extension (buffer-file-name))))
  15633. (when (and (file-exists-p conf-file-name)
  15634. (not (y-or-n-p (concat "File \"" conf-file-name
  15635. "\" exists; overwrite? "))))
  15636. (error "ERROR: Creating configuration...aborted"))
  15637. (find-file conf-file-name)
  15638. (erase-buffer)
  15639. (set-buffer-modified-p nil)
  15640. ;; insert header
  15641. (if vhdl-compose-include-header
  15642. (progn (vhdl-template-header
  15643. (concat "Configuration declaration for design \""
  15644. ent-name "(" arch-name ")\""))
  15645. (goto-char (point-max)))
  15646. (vhdl-comment-display-line) (insert "\n\n")))
  15647. ;; goto end of architecture
  15648. (unless from-speedbar
  15649. (re-search-forward "^end\\>" nil)
  15650. (end-of-line) (insert "\n\n")
  15651. (vhdl-comment-display-line) (insert "\n\n")))
  15652. ;; insert library clause
  15653. (setq pos (point))
  15654. (vhdl-template-standard-package (vhdl-work-library) nil)
  15655. (when (/= pos (point))
  15656. (insert "\n\n"))
  15657. ;; insert configuration
  15658. (vhdl-insert-keyword "CONFIGURATION ") (insert conf-name)
  15659. (vhdl-insert-keyword " OF ") (insert ent-name)
  15660. (vhdl-insert-keyword " IS\n")
  15661. (indent-to vhdl-basic-offset)
  15662. ;; insert block configuration (for architecture)
  15663. (vhdl-compose-configuration-architecture
  15664. ent-name arch-name ent-alist conf-alist inst-alist t)
  15665. (vhdl-insert-keyword "END ") (insert conf-name ";")
  15666. (when conf-file-name
  15667. ;; insert footer and save
  15668. (insert "\n\n")
  15669. (if (and vhdl-compose-include-header (not (equal vhdl-file-footer "")))
  15670. (vhdl-template-footer)
  15671. (vhdl-comment-display-line) (insert "\n"))
  15672. (save-buffer))
  15673. (message "%s"
  15674. (concat (format "Generating configuration \"%s\"...done" conf-name)
  15675. (and conf-file-name
  15676. (format "\n File created: \"%s\"" conf-file-name))))))
  15677. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15678. ;;; Compilation / Makefile generation
  15679. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15680. ;; (using `compile.el')
  15681. (defvar vhdl-compile-post-command ""
  15682. "String appended to compile command after file name.")
  15683. (defun vhdl-makefile-name ()
  15684. "Return the Makefile name of the current project or the current compiler if
  15685. no project is defined."
  15686. (let ((project-alist (vhdl-aget vhdl-project-alist vhdl-project))
  15687. (compiler-alist (vhdl-aget vhdl-compiler-alist vhdl-compiler)))
  15688. (vhdl-replace-string
  15689. (cons "\\(.*\\)\n\\(.*\\)"
  15690. (or (nth 8 project-alist) (nth 8 compiler-alist)))
  15691. (concat (nth 9 compiler-alist) "\n" (nth 6 project-alist)))))
  15692. (defun vhdl-compile-directory ()
  15693. "Return the directory where compilation/make should be run."
  15694. (let* ((project (vhdl-aget vhdl-project-alist (vhdl-project-p t)))
  15695. (compiler (vhdl-aget vhdl-compiler-alist vhdl-compiler))
  15696. (directory (vhdl-resolve-env-variable
  15697. (if project
  15698. (vhdl-replace-string
  15699. (cons "\\(.*\\)" (nth 5 project)) (nth 9 compiler))
  15700. (nth 6 compiler)))))
  15701. (file-name-as-directory
  15702. (if (file-name-absolute-p directory)
  15703. directory
  15704. (expand-file-name directory (vhdl-default-directory))))))
  15705. (defun vhdl-uniquify (in-list)
  15706. "Remove duplicate elements from IN-LIST."
  15707. (let (out-list)
  15708. (while in-list
  15709. (add-to-list 'out-list (car in-list))
  15710. (setq in-list (cdr in-list)))
  15711. out-list))
  15712. (defun vhdl-set-compiler (name)
  15713. "Set current compiler to NAME."
  15714. (interactive
  15715. (list (let ((completion-ignore-case t))
  15716. (completing-read "Compiler name: " vhdl-compiler-alist nil t))))
  15717. (if (assoc name vhdl-compiler-alist)
  15718. (progn (setq vhdl-compiler name)
  15719. (message "Current compiler: \"%s\"" vhdl-compiler))
  15720. (vhdl-warning (format "Unknown compiler: \"%s\"" name))))
  15721. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15722. ;; Compilation
  15723. (defun vhdl-compile-init ()
  15724. "Initialize for compilation."
  15725. (when (and (not vhdl-emacs-22)
  15726. (or (null compilation-error-regexp-alist)
  15727. (not (assoc (car (nth 11 (car vhdl-compiler-alist)))
  15728. compilation-error-regexp-alist))))
  15729. ;; `compilation-error-regexp-alist'
  15730. (let ((commands-alist vhdl-compiler-alist)
  15731. regexp-alist sublist)
  15732. (while commands-alist
  15733. (setq sublist (nth 11 (car commands-alist)))
  15734. (unless (or (equal "" (car sublist))
  15735. (assoc (car sublist) regexp-alist))
  15736. (push (list (nth 0 sublist)
  15737. (if (and (featurep 'xemacs) (not (nth 1 sublist)))
  15738. 9
  15739. (nth 1 sublist))
  15740. (nth 2 sublist) (nth 3 sublist))
  15741. regexp-alist))
  15742. (setq commands-alist (cdr commands-alist)))
  15743. (setq compilation-error-regexp-alist
  15744. (append compilation-error-regexp-alist (nreverse regexp-alist))))
  15745. ;; `compilation-file-regexp-alist'
  15746. (let ((commands-alist vhdl-compiler-alist)
  15747. regexp-alist sublist)
  15748. ;; matches vhdl-mode file name output
  15749. (setq regexp-alist '(("^Compiling \"\\(.+\\)\"" 1)))
  15750. (while commands-alist
  15751. (setq sublist (nth 12 (car commands-alist)))
  15752. (unless (or (equal "" (car sublist))
  15753. (assoc (car sublist) regexp-alist))
  15754. (push sublist regexp-alist))
  15755. (setq commands-alist (cdr commands-alist)))
  15756. (setq compilation-file-regexp-alist
  15757. (append compilation-file-regexp-alist (nreverse regexp-alist))))))
  15758. (defvar vhdl-compile-file-name nil
  15759. "Name of file to be compiled.")
  15760. (defun vhdl-compile-print-file-name ()
  15761. "Function called within `compile' to print out file name for compilers that
  15762. do not print any file names."
  15763. (insert "Compiling \"" vhdl-compile-file-name "\"\n"))
  15764. (defun vhdl-get-compile-options (project compiler file-name
  15765. &optional file-options-only)
  15766. "Get compiler options. Returning nil means do not compile this file."
  15767. (let* ((compiler-options (nth 1 compiler))
  15768. (project-entry (vhdl-aget (nth 4 project) vhdl-compiler))
  15769. (project-options (nth 0 project-entry))
  15770. (exception-list (and file-name (nth 2 project-entry)))
  15771. (work-library (vhdl-work-library))
  15772. (case-fold-search nil)
  15773. file-options)
  15774. (while (and exception-list
  15775. (not (string-match (caar exception-list) file-name)))
  15776. (setq exception-list (cdr exception-list)))
  15777. (if (and exception-list (not (cdar exception-list)))
  15778. nil
  15779. (if (and file-options-only (not exception-list))
  15780. 'default
  15781. (setq file-options (cdar exception-list))
  15782. ;; insert library name in compiler-specific options
  15783. (setq compiler-options
  15784. (vhdl-replace-string (cons "\\(.*\\)" compiler-options)
  15785. work-library))
  15786. ;; insert compiler-specific options in project-specific options
  15787. (when project-options
  15788. (setq project-options
  15789. (vhdl-replace-string
  15790. (cons "\\(.*\\)\n\\(.*\\)" project-options)
  15791. (concat work-library "\n" compiler-options))))
  15792. ;; insert project-specific options in file-specific options
  15793. (when file-options
  15794. (setq file-options
  15795. (vhdl-replace-string
  15796. (cons "\\(.*\\)\n\\(.*\\)\n\\(.*\\)" file-options)
  15797. (concat work-library "\n" compiler-options "\n"
  15798. project-options))))
  15799. ;; return options
  15800. (or file-options project-options compiler-options)))))
  15801. (defun vhdl-get-make-options (project compiler)
  15802. "Get make options."
  15803. (let* ((compiler-options (nth 3 compiler))
  15804. (project-entry (vhdl-aget (nth 4 project) vhdl-compiler))
  15805. (project-options (nth 1 project-entry))
  15806. (makefile-name (vhdl-makefile-name)))
  15807. ;; insert Makefile name in compiler-specific options
  15808. (setq compiler-options
  15809. (vhdl-replace-string (cons "\\(.*\\)" (nth 3 compiler))
  15810. makefile-name))
  15811. ;; insert compiler-specific options in project-specific options
  15812. (when project-options
  15813. (setq project-options
  15814. (vhdl-replace-string
  15815. (cons "\\(.*\\)\n\\(.*\\)" project-options)
  15816. (concat makefile-name "\n" compiler-options))))
  15817. ;; return options
  15818. (or project-options compiler-options)))
  15819. (defun vhdl-compile ()
  15820. "Compile current buffer using the VHDL compiler specified in
  15821. `vhdl-compiler'."
  15822. (interactive)
  15823. (vhdl-compile-init)
  15824. (let* ((project (vhdl-aget vhdl-project-alist vhdl-project))
  15825. (compiler (or (vhdl-aget vhdl-compiler-alist vhdl-compiler)
  15826. (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
  15827. (command (nth 0 compiler))
  15828. (default-directory (vhdl-compile-directory))
  15829. (file-name (if vhdl-compile-absolute-path
  15830. (buffer-file-name)
  15831. (file-relative-name (buffer-file-name))))
  15832. (options (vhdl-get-compile-options project compiler file-name))
  15833. compilation-process-setup-function)
  15834. (unless (file-directory-p default-directory)
  15835. (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
  15836. ;; put file name into quotes if it contains spaces
  15837. (when (string-match " " file-name)
  15838. (setq file-name (concat "\"" file-name "\"")))
  15839. ;; print out file name if compiler does not
  15840. (setq vhdl-compile-file-name (if vhdl-compile-absolute-path
  15841. (buffer-file-name)
  15842. (file-relative-name (buffer-file-name))))
  15843. (when (and (= 0 (nth 1 (nth 10 compiler)))
  15844. (= 0 (nth 1 (nth 11 compiler))))
  15845. (setq compilation-process-setup-function 'vhdl-compile-print-file-name))
  15846. ;; run compilation
  15847. (if options
  15848. (when command
  15849. (compile (concat command " " options " " file-name
  15850. (unless (equal vhdl-compile-post-command "")
  15851. (concat " " vhdl-compile-post-command)))))
  15852. (vhdl-warning "Your project settings tell me not to compile this file"))))
  15853. (defvar vhdl-make-target "all"
  15854. "Default target for `vhdl-make' command.")
  15855. (defun vhdl-make (&optional target)
  15856. "Call make command for compilation of all updated source files (requires
  15857. `Makefile'). Optional argument TARGET allows you to compile the design
  15858. specified by a target."
  15859. (interactive)
  15860. (setq vhdl-make-target
  15861. (or target (read-from-minibuffer "Target: " vhdl-make-target
  15862. vhdl-minibuffer-local-map)))
  15863. (vhdl-compile-init)
  15864. (let* ((project (vhdl-aget vhdl-project-alist vhdl-project))
  15865. (compiler (or (vhdl-aget vhdl-compiler-alist vhdl-compiler)
  15866. (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
  15867. (command (nth 2 compiler))
  15868. (options (vhdl-get-make-options project compiler))
  15869. (default-directory (vhdl-compile-directory)))
  15870. (unless (file-directory-p default-directory)
  15871. (error "ERROR: Compile directory does not exist: \"%s\"" default-directory))
  15872. ;; run make
  15873. (compile (concat (if (equal command "") "make" command)
  15874. " " options " " vhdl-make-target))))
  15875. ;; Emacs 22+ setup
  15876. (defvar vhdl-error-regexp-emacs-alist
  15877. ;; Get regexps from `vhdl-compiler-alist'
  15878. (let ((compiler-alist vhdl-compiler-alist)
  15879. (error-regexp-alist '((vhdl-directory "^ *Compiling \"\\(.+\\)\"" 1))))
  15880. (while compiler-alist
  15881. ;; only add regexps for currently selected compiler
  15882. (when (or (not vhdl-compile-use-local-error-regexp)
  15883. (equal vhdl-compiler (nth 0 (car compiler-alist))))
  15884. ;; add error message regexps
  15885. (setq error-regexp-alist
  15886. (cons (append (list (make-symbol (concat "vhdl-" (subst-char-in-string ? ?- (downcase (nth 0 (car compiler-alist)))))))
  15887. (nth 11 (car compiler-alist)))
  15888. error-regexp-alist))
  15889. ;; add filename regexps
  15890. (when (/= 0 (nth 1 (nth 12 (car compiler-alist))))
  15891. (setq error-regexp-alist
  15892. (cons (append (list (make-symbol (concat "vhdl-" (subst-char-in-string ? ?- (downcase (nth 0 (car compiler-alist)))) "-file")))
  15893. (nth 12 (car compiler-alist)))
  15894. error-regexp-alist))))
  15895. (setq compiler-alist (cdr compiler-alist)))
  15896. error-regexp-alist)
  15897. "List of regexps for VHDL compilers. For Emacs 22+.")
  15898. ;; Add error regexps using compilation-mode-hook.
  15899. (defun vhdl-error-regexp-add-emacs ()
  15900. "Set up Emacs compile for VHDL."
  15901. (interactive)
  15902. (when (and (boundp 'compilation-error-regexp-alist-alist)
  15903. (not (assoc 'vhdl-modelsim compilation-error-regexp-alist-alist)))
  15904. ;; remove all other compilers
  15905. (when vhdl-compile-use-local-error-regexp
  15906. (setq compilation-error-regexp-alist nil))
  15907. ;; add VHDL compilers
  15908. (mapcar
  15909. (lambda (item)
  15910. (push (car item) compilation-error-regexp-alist)
  15911. (push item compilation-error-regexp-alist-alist))
  15912. vhdl-error-regexp-emacs-alist)))
  15913. (when vhdl-emacs-22
  15914. (add-hook 'compilation-mode-hook 'vhdl-error-regexp-add-emacs))
  15915. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15916. ;; Makefile generation
  15917. (defun vhdl-generate-makefile ()
  15918. "Generate `Makefile'."
  15919. (interactive)
  15920. (let* ((compiler (or (vhdl-aget vhdl-compiler-alist vhdl-compiler)
  15921. (error "ERROR: No such compiler: \"%s\"" vhdl-compiler)))
  15922. (command (nth 4 compiler)))
  15923. ;; generate makefile
  15924. (if command
  15925. (let ((default-directory (vhdl-compile-directory)))
  15926. (compile (vhdl-replace-string
  15927. (cons "\\(.*\\) \\(.*\\)" command)
  15928. (concat (vhdl-makefile-name) " " (vhdl-work-library)))))
  15929. (vhdl-generate-makefile-1))))
  15930. (defun vhdl-get-packages (lib-alist work-library)
  15931. "Get packages from LIB-ALIST that belong to WORK-LIBRARY."
  15932. (let (pack-list)
  15933. (while lib-alist
  15934. (when (equal (downcase (caar lib-alist)) (downcase work-library))
  15935. (push (cdar lib-alist) pack-list))
  15936. (setq lib-alist (cdr lib-alist)))
  15937. pack-list))
  15938. (defun vhdl-generate-makefile-1 ()
  15939. "Generate Makefile for current project or directory."
  15940. ;; scan hierarchy if required
  15941. (if (vhdl-project-p)
  15942. (unless (or (assoc vhdl-project vhdl-file-alist)
  15943. (vhdl-load-cache vhdl-project))
  15944. (vhdl-scan-project-contents vhdl-project))
  15945. (let ((directory (abbreviate-file-name default-directory)))
  15946. (unless (or (assoc directory vhdl-file-alist)
  15947. (vhdl-load-cache directory))
  15948. (vhdl-scan-directory-contents directory))))
  15949. (let* ((directory (abbreviate-file-name (vhdl-default-directory)))
  15950. (project (vhdl-project-p))
  15951. (ent-alist (vhdl-aget vhdl-entity-alist (or project directory)))
  15952. (conf-alist (vhdl-aget vhdl-config-alist (or project directory)))
  15953. (pack-alist (vhdl-aget vhdl-package-alist (or project directory)))
  15954. (regexp-list (or (nth 12 (vhdl-aget vhdl-compiler-alist vhdl-compiler))
  15955. '("\\1.vhd" "\\2_\\1.vhd" "\\1.vhd"
  15956. "\\1.vhd" "\\1_body.vhd" identity)))
  15957. (mapping-exist
  15958. (if (nth 12 (vhdl-aget vhdl-compiler-alist vhdl-compiler)) t nil))
  15959. (ent-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 0 regexp-list)))
  15960. (arch-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 1 regexp-list)))
  15961. (conf-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 2 regexp-list)))
  15962. (pack-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 3 regexp-list)))
  15963. (pack-body-regexp (cons "\\(.*\\) \\(.*\\) \\(.*\\)" (nth 4 regexp-list)))
  15964. (adjust-case (nth 5 regexp-list))
  15965. (work-library (downcase (vhdl-work-library)))
  15966. (compile-directory (expand-file-name (vhdl-compile-directory)
  15967. default-directory))
  15968. (makefile-name (vhdl-makefile-name))
  15969. rule-alist arch-alist inst-alist
  15970. target-list depend-list unit-list prim-list second-list subcomp-list
  15971. lib-alist lib-body-alist pack-list all-pack-list
  15972. ent-key ent-file-name arch-key arch-file-name ent-arch-key
  15973. conf-key conf-file-name pack-key pack-file-name
  15974. ent-entry arch-entry conf-entry pack-entry inst-entry
  15975. pack-body-key pack-body-file-name inst-ent-key inst-conf-key
  15976. tmp-key tmp-list rule)
  15977. ;; check prerequisites
  15978. (unless (file-exists-p compile-directory)
  15979. (make-directory compile-directory t))
  15980. (unless mapping-exist
  15981. (vhdl-warning
  15982. (format "No unit-to-file name mapping found for compiler \"%s\".\n Directory of dummy files is created instead (to be used as dependencies).\n Please contact the VHDL Mode maintainer for full support of \"%s\""
  15983. vhdl-compiler vhdl-compiler) t))
  15984. (message "Generating makefile \"%s\"..." makefile-name)
  15985. ;; rules for all entities
  15986. (setq tmp-list ent-alist)
  15987. (while ent-alist
  15988. (setq ent-entry (car ent-alist)
  15989. ent-key (nth 0 ent-entry))
  15990. (when (nth 2 ent-entry)
  15991. (setq ent-file-name (if vhdl-compile-absolute-path
  15992. (nth 2 ent-entry)
  15993. (file-relative-name (nth 2 ent-entry)
  15994. compile-directory))
  15995. arch-alist (nth 4 ent-entry)
  15996. lib-alist (nth 6 ent-entry)
  15997. rule (vhdl-aget rule-alist ent-file-name)
  15998. target-list (nth 0 rule)
  15999. depend-list (nth 1 rule)
  16000. second-list nil
  16001. subcomp-list nil)
  16002. (setq tmp-key (vhdl-replace-string
  16003. ent-regexp
  16004. (funcall adjust-case
  16005. (concat ent-key " " work-library))))
  16006. (push (cons ent-key tmp-key) unit-list)
  16007. ;; rule target for this entity
  16008. (push ent-key target-list)
  16009. ;; rule dependencies for all used packages
  16010. (setq pack-list (vhdl-get-packages lib-alist work-library))
  16011. (setq depend-list (append depend-list pack-list))
  16012. (setq all-pack-list pack-list)
  16013. ;; add rule
  16014. (vhdl-aput 'rule-alist ent-file-name (list target-list depend-list))
  16015. ;; rules for all corresponding architectures
  16016. (while arch-alist
  16017. (setq arch-entry (car arch-alist)
  16018. arch-key (nth 0 arch-entry)
  16019. ent-arch-key (concat ent-key "-" arch-key)
  16020. arch-file-name (if vhdl-compile-absolute-path
  16021. (nth 2 arch-entry)
  16022. (file-relative-name (nth 2 arch-entry)
  16023. compile-directory))
  16024. inst-alist (nth 4 arch-entry)
  16025. lib-alist (nth 5 arch-entry)
  16026. rule (vhdl-aget rule-alist arch-file-name)
  16027. target-list (nth 0 rule)
  16028. depend-list (nth 1 rule))
  16029. (setq tmp-key (vhdl-replace-string
  16030. arch-regexp
  16031. (funcall adjust-case
  16032. (concat arch-key " " ent-key " "
  16033. work-library))))
  16034. (setq unit-list
  16035. (cons (cons ent-arch-key tmp-key) unit-list))
  16036. (push ent-arch-key second-list)
  16037. ;; rule target for this architecture
  16038. (push ent-arch-key target-list)
  16039. ;; rule dependency for corresponding entity
  16040. (push ent-key depend-list)
  16041. ;; rule dependencies for contained component instantiations
  16042. (while inst-alist
  16043. (setq inst-entry (car inst-alist))
  16044. (when (or (null (nth 8 inst-entry))
  16045. (equal (downcase (nth 8 inst-entry)) work-library))
  16046. (setq inst-ent-key (or (nth 7 inst-entry)
  16047. (nth 5 inst-entry)))
  16048. (setq depend-list (cons inst-ent-key depend-list)
  16049. subcomp-list (cons inst-ent-key subcomp-list)))
  16050. (setq inst-alist (cdr inst-alist)))
  16051. ;; rule dependencies for all used packages
  16052. (setq pack-list (vhdl-get-packages lib-alist work-library))
  16053. (setq depend-list (append depend-list pack-list))
  16054. (setq all-pack-list (append all-pack-list pack-list))
  16055. ;; add rule
  16056. (vhdl-aput 'rule-alist arch-file-name (list target-list depend-list))
  16057. (setq arch-alist (cdr arch-alist)))
  16058. (push (list ent-key second-list (append subcomp-list all-pack-list))
  16059. prim-list))
  16060. (setq ent-alist (cdr ent-alist)))
  16061. (setq ent-alist tmp-list)
  16062. ;; rules for all configurations
  16063. (setq tmp-list conf-alist)
  16064. (while conf-alist
  16065. (setq conf-entry (car conf-alist)
  16066. conf-key (nth 0 conf-entry)
  16067. conf-file-name (if vhdl-compile-absolute-path
  16068. (nth 2 conf-entry)
  16069. (file-relative-name (nth 2 conf-entry)
  16070. compile-directory))
  16071. ent-key (nth 4 conf-entry)
  16072. arch-key (nth 5 conf-entry)
  16073. inst-alist (nth 6 conf-entry)
  16074. lib-alist (nth 7 conf-entry)
  16075. rule (vhdl-aget rule-alist conf-file-name)
  16076. target-list (nth 0 rule)
  16077. depend-list (nth 1 rule)
  16078. subcomp-list (list ent-key))
  16079. (setq tmp-key (vhdl-replace-string
  16080. conf-regexp
  16081. (funcall adjust-case
  16082. (concat conf-key " " work-library))))
  16083. (push (cons conf-key tmp-key) unit-list)
  16084. ;; rule target for this configuration
  16085. (push conf-key target-list)
  16086. ;; rule dependency for corresponding entity and architecture
  16087. (setq depend-list
  16088. (cons ent-key (cons (concat ent-key "-" arch-key) depend-list)))
  16089. ;; rule dependencies for used packages
  16090. (setq pack-list (vhdl-get-packages lib-alist work-library))
  16091. (setq depend-list (append depend-list pack-list))
  16092. ;; rule dependencies for contained component configurations
  16093. (while inst-alist
  16094. (setq inst-entry (car inst-alist))
  16095. (setq inst-ent-key (nth 2 inst-entry)
  16096. inst-conf-key (nth 4 inst-entry))
  16097. (when (equal (downcase (nth 5 inst-entry)) work-library)
  16098. (when inst-ent-key
  16099. (setq depend-list (cons inst-ent-key depend-list)
  16100. subcomp-list (cons inst-ent-key subcomp-list)))
  16101. (when inst-conf-key
  16102. (setq depend-list (cons inst-conf-key depend-list)
  16103. subcomp-list (cons inst-conf-key subcomp-list))))
  16104. (setq inst-alist (cdr inst-alist)))
  16105. ;; add rule
  16106. (vhdl-aput 'rule-alist conf-file-name (list target-list depend-list))
  16107. (push (list conf-key nil (append subcomp-list pack-list)) prim-list)
  16108. (setq conf-alist (cdr conf-alist)))
  16109. (setq conf-alist tmp-list)
  16110. ;; rules for all packages
  16111. (setq tmp-list pack-alist)
  16112. (while pack-alist
  16113. (setq pack-entry (car pack-alist)
  16114. pack-key (nth 0 pack-entry)
  16115. pack-body-key nil)
  16116. (when (nth 2 pack-entry)
  16117. (setq pack-file-name (if vhdl-compile-absolute-path
  16118. (nth 2 pack-entry)
  16119. (file-relative-name (nth 2 pack-entry)
  16120. compile-directory))
  16121. lib-alist (nth 6 pack-entry) lib-body-alist (nth 10 pack-entry)
  16122. rule (vhdl-aget rule-alist pack-file-name)
  16123. target-list (nth 0 rule) depend-list (nth 1 rule))
  16124. (setq tmp-key (vhdl-replace-string
  16125. pack-regexp
  16126. (funcall adjust-case
  16127. (concat pack-key " " work-library))))
  16128. (push (cons pack-key tmp-key) unit-list)
  16129. ;; rule target for this package
  16130. (push pack-key target-list)
  16131. ;; rule dependencies for all used packages
  16132. (setq pack-list (vhdl-get-packages lib-alist work-library))
  16133. (setq depend-list (append depend-list pack-list))
  16134. (setq all-pack-list pack-list)
  16135. ;; add rule
  16136. (vhdl-aput 'rule-alist pack-file-name (list target-list depend-list))
  16137. ;; rules for this package's body
  16138. (when (nth 7 pack-entry)
  16139. (setq pack-body-key (concat pack-key "-body")
  16140. pack-body-file-name (if vhdl-compile-absolute-path
  16141. (nth 7 pack-entry)
  16142. (file-relative-name (nth 7 pack-entry)
  16143. compile-directory))
  16144. rule (vhdl-aget rule-alist pack-body-file-name)
  16145. target-list (nth 0 rule)
  16146. depend-list (nth 1 rule))
  16147. (setq tmp-key (vhdl-replace-string
  16148. pack-body-regexp
  16149. (funcall adjust-case
  16150. (concat pack-key " " work-library))))
  16151. (setq unit-list
  16152. (cons (cons pack-body-key tmp-key) unit-list))
  16153. ;; rule target for this package's body
  16154. (push pack-body-key target-list)
  16155. ;; rule dependency for corresponding package declaration
  16156. (push pack-key depend-list)
  16157. ;; rule dependencies for all used packages
  16158. (setq pack-list (vhdl-get-packages lib-body-alist work-library))
  16159. (setq depend-list (append depend-list pack-list))
  16160. (setq all-pack-list (append all-pack-list pack-list))
  16161. ;; add rule
  16162. (vhdl-aput 'rule-alist pack-body-file-name
  16163. (list target-list depend-list)))
  16164. (setq prim-list
  16165. (cons (list pack-key (when pack-body-key (list pack-body-key))
  16166. all-pack-list)
  16167. prim-list)))
  16168. (setq pack-alist (cdr pack-alist)))
  16169. (setq pack-alist tmp-list)
  16170. ;; generate Makefile
  16171. (let* ((project (vhdl-aget vhdl-project-alist project))
  16172. (compiler (vhdl-aget vhdl-compiler-alist vhdl-compiler))
  16173. (compiler-id (nth 9 compiler))
  16174. (library-directory
  16175. (vhdl-resolve-env-variable
  16176. (vhdl-replace-string
  16177. (cons "\\(.*\\)" (or (nth 7 project) (nth 7 compiler)))
  16178. compiler-id)))
  16179. (makefile-path-name (expand-file-name
  16180. makefile-name compile-directory))
  16181. (orig-buffer (current-buffer))
  16182. cell second-list subcomp-list options unit-key unit-name)
  16183. ;; sort lists
  16184. (setq unit-list (vhdl-sort-alist unit-list))
  16185. (setq prim-list (vhdl-sort-alist prim-list))
  16186. (setq tmp-list rule-alist)
  16187. (while tmp-list ; pre-sort rule targets
  16188. (setq cell (cdar tmp-list))
  16189. (setcar cell (sort (car cell) 'string<))
  16190. (setq tmp-list (cdr tmp-list)))
  16191. (setq rule-alist ; sort by first rule target
  16192. (sort rule-alist
  16193. (function (lambda (a b)
  16194. (string< (car (cadr a)) (car (cadr b)))))))
  16195. ;; open and clear Makefile
  16196. (set-buffer (find-file-noselect makefile-path-name t t))
  16197. (erase-buffer)
  16198. (insert "# -*- Makefile -*-\n"
  16199. "### " (file-name-nondirectory makefile-name)
  16200. " - VHDL Makefile generated by Emacs VHDL Mode " vhdl-version
  16201. "\n")
  16202. (if project
  16203. (insert "\n# Project : " (nth 0 project))
  16204. (insert "\n# Directory : \"" directory "\""))
  16205. (insert "\n# Platform : " vhdl-compiler
  16206. "\n# Generated : " (format-time-string "%Y-%m-%d %T ")
  16207. (user-login-name) "\n")
  16208. ;; insert compile and option variable settings
  16209. (insert "\n\n# Define compilation command and options\n"
  16210. "\nCOMPILE = " (nth 0 compiler)
  16211. "\nOPTIONS = " (vhdl-get-compile-options project compiler nil)
  16212. (if (equal vhdl-compile-post-command "") ""
  16213. (concat "\nPOST-COMPILE = " vhdl-compile-post-command))
  16214. "\n")
  16215. ;; insert library paths
  16216. (setq library-directory
  16217. (directory-file-name
  16218. (if (file-name-absolute-p library-directory)
  16219. library-directory
  16220. (file-relative-name
  16221. (expand-file-name library-directory directory)
  16222. compile-directory))))
  16223. (insert "\n\n# Define library paths\n"
  16224. "\nLIBRARY-" work-library " = " library-directory "\n")
  16225. (unless mapping-exist
  16226. (insert "LIBRARY-" work-library "-make = " "$(LIBRARY-" work-library
  16227. ")/make" "\n"))
  16228. ;; insert variable definitions for all library unit files
  16229. (insert "\n\n# Define library unit files\n")
  16230. (setq tmp-list unit-list)
  16231. (while unit-list
  16232. (insert "\nUNIT-" work-library "-" (caar unit-list)
  16233. " = \\\n\t$(LIBRARY-" work-library
  16234. (if mapping-exist "" "-make") ")/" (cdar unit-list))
  16235. (setq unit-list (cdr unit-list)))
  16236. ;; insert variable definition for list of all library unit files
  16237. (insert "\n\n\n# Define list of all library unit files\n"
  16238. "\nALL_UNITS =")
  16239. (setq unit-list tmp-list)
  16240. (while unit-list
  16241. (insert " \\\n\t" "$(UNIT-" work-library "-" (caar unit-list) ")")
  16242. (setq unit-list (cdr unit-list)))
  16243. (insert "\n")
  16244. (setq unit-list tmp-list)
  16245. ;; insert `make all' rule
  16246. (insert "\n\n\n# Rule for compiling entire design\n"
  16247. "\n" (nth 0 vhdl-makefile-default-targets) " :"
  16248. " \\\n\t\t" (nth 2 vhdl-makefile-default-targets)
  16249. " \\\n\t\t$(ALL_UNITS)\n")
  16250. ;; insert `make clean' rule
  16251. (insert "\n\n# Rule for cleaning entire design\n"
  16252. "\n" (nth 1 vhdl-makefile-default-targets) " : "
  16253. "\n\t-rm -f $(ALL_UNITS)\n")
  16254. ;; insert `make library' rule
  16255. (insert "\n\n# Rule for creating library directory\n"
  16256. "\n" (nth 2 vhdl-makefile-default-targets) " :"
  16257. " \\\n\t\t$(LIBRARY-" work-library ")"
  16258. (if mapping-exist ""
  16259. (concat " \\\n\t\t$(LIBRARY-" work-library "-make)\n"))
  16260. "\n"
  16261. "\n$(LIBRARY-" work-library ") :"
  16262. "\n\t"
  16263. (vhdl-replace-string
  16264. (cons "\\(.*\\)\n\\(.*\\)" (nth 5 compiler))
  16265. (concat "$(LIBRARY-" work-library ")\n" (vhdl-work-library)))
  16266. "\n")
  16267. (unless mapping-exist
  16268. (insert "\n$(LIBRARY-" work-library "-make) :"
  16269. "\n\t"
  16270. "mkdir -p $(LIBRARY-" work-library "-make)\n"))
  16271. ;; insert '.PHONY' declaration
  16272. (insert "\n\n.PHONY : "
  16273. (nth 0 vhdl-makefile-default-targets) " "
  16274. (nth 1 vhdl-makefile-default-targets) " "
  16275. (nth 2 vhdl-makefile-default-targets) "\n")
  16276. ;; insert rule for each library unit
  16277. (insert "\n\n# Rules for compiling single library units and their subhierarchy\n")
  16278. (while prim-list
  16279. (setq second-list (sort (nth 1 (car prim-list)) 'string<))
  16280. (setq subcomp-list
  16281. (sort (vhdl-uniquify (nth 2 (car prim-list))) 'string<))
  16282. (setq unit-key (caar prim-list)
  16283. unit-name (or (nth 0 (vhdl-aget ent-alist unit-key))
  16284. (nth 0 (vhdl-aget conf-alist unit-key))
  16285. (nth 0 (vhdl-aget pack-alist unit-key))))
  16286. (insert "\n" unit-key)
  16287. (unless (equal unit-key unit-name)
  16288. (insert " \\\n" unit-name))
  16289. (insert " :"
  16290. " \\\n\t\t" (nth 2 vhdl-makefile-default-targets))
  16291. (while subcomp-list
  16292. (when (and (assoc (car subcomp-list) unit-list)
  16293. (not (equal unit-key (car subcomp-list))))
  16294. (insert " \\\n\t\t" (car subcomp-list)))
  16295. (setq subcomp-list (cdr subcomp-list)))
  16296. (insert " \\\n\t\t$(UNIT-" work-library "-" unit-key ")")
  16297. (while second-list
  16298. (insert " \\\n\t\t$(UNIT-" work-library "-" (car second-list) ")")
  16299. (setq second-list (cdr second-list)))
  16300. (insert "\n")
  16301. (setq prim-list (cdr prim-list)))
  16302. ;; insert rule for each library unit file
  16303. (insert "\n\n# Rules for compiling single library unit files\n")
  16304. (while rule-alist
  16305. (setq rule (car rule-alist))
  16306. ;; get compiler options for this file
  16307. (setq options
  16308. (vhdl-get-compile-options project compiler (nth 0 rule) t))
  16309. ;; insert rule if file is supposed to be compiled
  16310. (setq target-list (nth 1 rule)
  16311. depend-list (sort (vhdl-uniquify (nth 2 rule)) 'string<))
  16312. ;; insert targets
  16313. (setq tmp-list target-list)
  16314. (while target-list
  16315. (insert "\n$(UNIT-" work-library "-" (car target-list) ")"
  16316. (if (cdr target-list) " \\" " :"))
  16317. (setq target-list (cdr target-list)))
  16318. (setq target-list tmp-list)
  16319. ;; insert file name as first dependency
  16320. (insert " \\\n\t\t" (nth 0 rule))
  16321. ;; insert dependencies (except if also target or unit does not exist)
  16322. (while depend-list
  16323. (when (and (not (member (car depend-list) target-list))
  16324. (assoc (car depend-list) unit-list))
  16325. (insert " \\\n\t\t"
  16326. "$(UNIT-" work-library "-" (car depend-list) ")"))
  16327. (setq depend-list (cdr depend-list)))
  16328. ;; insert compile command
  16329. (if options
  16330. (insert "\n\t$(COMPILE) "
  16331. (if (eq options 'default) "$(OPTIONS)" options) " "
  16332. (nth 0 rule)
  16333. (if (equal vhdl-compile-post-command "") ""
  16334. " $(POST-COMPILE)") "\n")
  16335. (insert "\n"))
  16336. (unless (and options mapping-exist)
  16337. (setq tmp-list target-list)
  16338. (while target-list
  16339. (insert "\t@touch $(UNIT-" work-library "-" (car target-list) ")\n")
  16340. (setq target-list (cdr target-list)))
  16341. (setq target-list tmp-list))
  16342. (setq rule-alist (cdr rule-alist)))
  16343. (insert "\n\n### " makefile-name " ends here\n")
  16344. ;; run Makefile generation hook
  16345. (run-hooks 'vhdl-makefile-generation-hook)
  16346. (message "Generating makefile \"%s\"...done" makefile-name)
  16347. ;; save and close file
  16348. (if (file-writable-p makefile-path-name)
  16349. (progn (save-buffer)
  16350. (kill-buffer (current-buffer))
  16351. (set-buffer orig-buffer)
  16352. (when (fboundp 'add-to-history)
  16353. (add-to-history 'file-name-history makefile-path-name)))
  16354. (vhdl-warning-when-idle
  16355. (format "File not writable: \"%s\""
  16356. (abbreviate-file-name makefile-path-name)))
  16357. (switch-to-buffer (current-buffer))))))
  16358. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  16359. ;;; Bug reports
  16360. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  16361. ;; (using `reporter.el')
  16362. (defconst vhdl-mode-help-address
  16363. "Reto Zimmermann <reto@gnu.org>"
  16364. "Address for VHDL Mode bug reports.")
  16365. (defun vhdl-submit-bug-report ()
  16366. "Submit via mail a bug report on VHDL Mode."
  16367. (interactive)
  16368. ;; load in reporter
  16369. (and
  16370. (y-or-n-p "Do you want to submit a report on VHDL Mode? ")
  16371. (let ((reporter-prompt-for-summary-p t))
  16372. (reporter-submit-bug-report
  16373. vhdl-mode-help-address
  16374. (concat "VHDL Mode " vhdl-version)
  16375. (list
  16376. ;; report all important user options
  16377. 'vhdl-offsets-alist
  16378. 'vhdl-comment-only-line-offset
  16379. 'tab-width
  16380. 'vhdl-electric-mode
  16381. 'vhdl-stutter-mode
  16382. 'vhdl-indent-tabs-mode
  16383. 'vhdl-project-alist
  16384. 'vhdl-project
  16385. 'vhdl-project-file-name
  16386. 'vhdl-project-auto-load
  16387. 'vhdl-project-sort
  16388. 'vhdl-compiler-alist
  16389. 'vhdl-compiler
  16390. 'vhdl-compile-use-local-error-regexp
  16391. 'vhdl-makefile-default-targets
  16392. 'vhdl-makefile-generation-hook
  16393. 'vhdl-default-library
  16394. 'vhdl-standard
  16395. 'vhdl-basic-offset
  16396. 'vhdl-upper-case-keywords
  16397. 'vhdl-upper-case-types
  16398. 'vhdl-upper-case-attributes
  16399. 'vhdl-upper-case-enum-values
  16400. 'vhdl-upper-case-constants
  16401. 'vhdl-use-direct-instantiation
  16402. 'vhdl-array-index-record-field-in-sensitivity-list
  16403. 'vhdl-compose-configuration-name
  16404. 'vhdl-entity-file-name
  16405. 'vhdl-architecture-file-name
  16406. 'vhdl-configuration-file-name
  16407. 'vhdl-package-file-name
  16408. 'vhdl-file-name-case
  16409. 'vhdl-electric-keywords
  16410. 'vhdl-optional-labels
  16411. 'vhdl-insert-empty-lines
  16412. 'vhdl-argument-list-indent
  16413. 'vhdl-association-list-with-formals
  16414. 'vhdl-conditions-in-parenthesis
  16415. 'vhdl-sensitivity-list-all
  16416. 'vhdl-zero-string
  16417. 'vhdl-one-string
  16418. 'vhdl-file-header
  16419. 'vhdl-file-footer
  16420. 'vhdl-company-name
  16421. 'vhdl-copyright-string
  16422. 'vhdl-platform-spec
  16423. 'vhdl-date-format
  16424. 'vhdl-modify-date-prefix-string
  16425. 'vhdl-modify-date-on-saving
  16426. 'vhdl-reset-kind
  16427. 'vhdl-reset-active-high
  16428. 'vhdl-clock-rising-edge
  16429. 'vhdl-clock-edge-condition
  16430. 'vhdl-clock-name
  16431. 'vhdl-reset-name
  16432. 'vhdl-model-alist
  16433. 'vhdl-include-port-comments
  16434. 'vhdl-include-direction-comments
  16435. 'vhdl-include-type-comments
  16436. 'vhdl-include-group-comments
  16437. 'vhdl-actual-generic-name
  16438. 'vhdl-actual-port-name
  16439. 'vhdl-instance-name
  16440. 'vhdl-testbench-entity-name
  16441. 'vhdl-testbench-architecture-name
  16442. 'vhdl-testbench-configuration-name
  16443. 'vhdl-testbench-dut-name
  16444. 'vhdl-testbench-include-header
  16445. 'vhdl-testbench-declarations
  16446. 'vhdl-testbench-statements
  16447. 'vhdl-testbench-initialize-signals
  16448. 'vhdl-testbench-include-library
  16449. 'vhdl-testbench-include-configuration
  16450. 'vhdl-testbench-create-files
  16451. 'vhdl-testbench-entity-file-name
  16452. 'vhdl-testbench-architecture-file-name
  16453. 'vhdl-compose-create-files
  16454. 'vhdl-compose-configuration-create-file
  16455. 'vhdl-compose-configuration-hierarchical
  16456. 'vhdl-compose-configuration-use-subconfiguration
  16457. 'vhdl-compose-include-header
  16458. 'vhdl-compose-architecture-name
  16459. 'vhdl-components-package-name
  16460. 'vhdl-use-components-package
  16461. 'vhdl-self-insert-comments
  16462. 'vhdl-prompt-for-comments
  16463. 'vhdl-inline-comment-column
  16464. 'vhdl-end-comment-column
  16465. 'vhdl-auto-align
  16466. 'vhdl-align-groups
  16467. 'vhdl-align-group-separate
  16468. 'vhdl-align-same-indent
  16469. 'vhdl-highlight-keywords
  16470. 'vhdl-highlight-names
  16471. 'vhdl-highlight-special-words
  16472. 'vhdl-highlight-forbidden-words
  16473. 'vhdl-highlight-verilog-keywords
  16474. 'vhdl-highlight-translate-off
  16475. 'vhdl-highlight-case-sensitive
  16476. 'vhdl-special-syntax-alist
  16477. 'vhdl-forbidden-words
  16478. 'vhdl-forbidden-syntax
  16479. 'vhdl-directive-keywords
  16480. 'vhdl-speedbar-auto-open
  16481. 'vhdl-speedbar-display-mode
  16482. 'vhdl-speedbar-scan-limit
  16483. 'vhdl-speedbar-jump-to-unit
  16484. 'vhdl-speedbar-update-on-saving
  16485. 'vhdl-speedbar-save-cache
  16486. 'vhdl-speedbar-cache-file-name
  16487. 'vhdl-index-menu
  16488. 'vhdl-source-file-menu
  16489. 'vhdl-hideshow-menu
  16490. 'vhdl-hide-all-init
  16491. 'vhdl-print-two-column
  16492. 'vhdl-print-customize-faces
  16493. 'vhdl-intelligent-tab
  16494. 'vhdl-indent-syntax-based
  16495. 'vhdl-indent-comment-like-next-code-line
  16496. 'vhdl-word-completion-case-sensitive
  16497. 'vhdl-word-completion-in-minibuffer
  16498. 'vhdl-underscore-is-part-of-word
  16499. 'vhdl-mode-hook)
  16500. (function
  16501. (lambda ()
  16502. (insert
  16503. (if vhdl-special-indent-hook
  16504. (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
  16505. "vhdl-special-indent-hook is set to '"
  16506. (format "%s" vhdl-special-indent-hook)
  16507. ".\nPerhaps this is your problem?\n"
  16508. "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
  16509. "\n"))))
  16510. nil
  16511. "Hi Reto,"))))
  16512. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  16513. ;;; Documentation
  16514. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  16515. (defconst vhdl-doc-release-notes nil
  16516. "\
  16517. Release Notes for VHDL Mode 3.37
  16518. ================================
  16519. - Added support for VHDL'08:
  16520. - New keywords, types, functions, attributes, operators, packages
  16521. - Context declaration
  16522. - Block comments
  16523. - Directives
  16524. - 'all' keyword in sensitivity list
  16525. Release Notes for VHDL Mode 3.34
  16526. ================================
  16527. - Added support for GNU Emacs 22/23/24:
  16528. - Compilation error parsing fixed for new `compile.el' package.
  16529. - Port translation: Derive actual generic name from formal generic name.
  16530. - New user options:
  16531. `vhdl-actual-generic-name': Specify how actual generic names are obtained.
  16532. Release Notes for VHDL Mode 3.33
  16533. ================================
  16534. New Features
  16535. ------------
  16536. CONFIGURATION DECLARATION GENERATION:
  16537. - Automatic generation of a configuration declaration for a design.
  16538. (See documentation (`C-c C-h') in section on STRUCTURAL COMPOSITION.)
  16539. Key Bindings
  16540. ------------
  16541. For Emacs compliance the following key bindings have been changed:
  16542. - `C-c c' -> `C-c C-c' `vhdl-comment-uncomment-region'
  16543. - `C-c f' -> `C-c C-i C-f' `vhdl-fontify-buffer'
  16544. - `C-c s' -> `C-c C-i C-s' `vhdl-statistics-buffer'
  16545. - `C-c C-c ...' -> `C-c C-m ...' `vhdl-compose-...'
  16546. User Options
  16547. ------------
  16548. `vhdl-configuration-file-name': (new)
  16549. Specify how the configuration file name is obtained.
  16550. `vhdl-compose-configuration-name': (new)
  16551. Specify how the configuration name is obtained.
  16552. `vhdl-compose-configuration-create-file': (new)
  16553. Specify whether a new file should be created for a configuration.
  16554. `vhdl-compose-configuration-hierarchical': (new)
  16555. Specify whether hierarchical configurations should be created.
  16556. `vhdl-compose-configuration-use-subconfiguration': (new)
  16557. Specify whether subconfigurations should be used inside configurations.
  16558. `vhdl-makefile-default-targets': (new)
  16559. Customize names of Makefile default targets.
  16560. `vhdl-indent-comment-like-next-code-line': (new)
  16561. Specify whether comment lines are indented like following code line.
  16562. `vhdl-array-index-record-field-in-sensitivity-list': (new)
  16563. Specify whether to include array indices / record fields in sensitivity list.
  16564. ")
  16565. (defconst vhdl-doc-keywords nil
  16566. "\
  16567. Reserved words in VHDL
  16568. ----------------------
  16569. VHDL'08 (IEEE Std 1076-2008):
  16570. `vhdl-08-keywords' : keywords
  16571. `vhdl-08-types' : standardized types
  16572. `vhdl-08-attributes' : standardized attributes
  16573. `vhdl-08-functions' : standardized functions
  16574. `vhdl-08-packages' : standardized packages and libraries
  16575. VHDL'93/02 (IEEE Std 1076-1993/2002):
  16576. `vhdl-02-keywords' : keywords
  16577. `vhdl-02-types' : standardized types
  16578. `vhdl-02-attributes' : standardized attributes
  16579. `vhdl-02-enum-values' : standardized enumeration values
  16580. `vhdl-02-functions' : standardized functions
  16581. `vhdl-02-packages' : standardized packages and libraries
  16582. VHDL-AMS (IEEE Std 1076.1 / 1076.1.1):
  16583. `vhdl-ams-keywords' : keywords
  16584. `vhdl-ams-types' : standardized types
  16585. `vhdl-ams-attributes' : standardized attributes
  16586. `vhdl-ams-enum-values' : standardized enumeration values
  16587. `vhdl-ams-constants' : standardized constants
  16588. `vhdl-ams-functions' : standardized functions
  16589. Math Packages (IEEE Std 1076.2):
  16590. `vhdl-math-types' : standardized types
  16591. `vhdl-math-constants' : standardized constants
  16592. `vhdl-math-functions' : standardized functions
  16593. `vhdl-math-packages' : standardized packages
  16594. Forbidden words:
  16595. `vhdl-verilog-keywords' : Verilog reserved words
  16596. NOTE: click `mouse-2' on variable names above (not in XEmacs).")
  16597. (defconst vhdl-doc-coding-style nil
  16598. "\
  16599. For VHDL coding style and naming convention guidelines, see the following
  16600. references:
  16601. [1] Ben Cohen.
  16602. \"VHDL Coding Styles and Methodologies\".
  16603. Kluwer Academic Publishers, 1999.
  16604. http://members.aol.com/vhdlcohen/vhdl/
  16605. [2] Michael Keating and Pierre Bricaud.
  16606. \"Reuse Methodology Manual, Second Edition\".
  16607. Kluwer Academic Publishers, 1999.
  16608. http://www.openmore.com/openmore/rmm2.html
  16609. [3] European Space Agency.
  16610. \"VHDL Modelling Guidelines\".
  16611. ftp://ftp.estec.esa.nl/pub/vhdl/doc/ModelGuide.{pdf,ps}
  16612. Use user options `vhdl-highlight-special-words' and `vhdl-special-syntax-alist'
  16613. to visually support naming conventions.")
  16614. (defun vhdl-version ()
  16615. "Echo the current version of VHDL Mode in the minibuffer."
  16616. (interactive)
  16617. (message "VHDL Mode %s (%s)" vhdl-version vhdl-time-stamp)
  16618. (vhdl-keep-region-active))
  16619. (defun vhdl-doc-variable (variable)
  16620. "Display VARIABLE's documentation in *Help* buffer."
  16621. (interactive)
  16622. (unless (featurep 'xemacs)
  16623. (help-setup-xref (list #'vhdl-doc-variable variable)
  16624. (called-interactively-p 'interactive)))
  16625. (with-output-to-temp-buffer
  16626. (if (fboundp 'help-buffer) (help-buffer) "*Help*")
  16627. (princ (documentation-property variable 'variable-documentation))
  16628. (with-current-buffer standard-output
  16629. (help-mode))
  16630. (help-print-return-message)))
  16631. (defun vhdl-doc-mode ()
  16632. "Display VHDL Mode documentation in *Help* buffer."
  16633. (interactive)
  16634. (unless (featurep 'xemacs)
  16635. (help-setup-xref (list #'vhdl-doc-mode)
  16636. (called-interactively-p 'interactive)))
  16637. (with-output-to-temp-buffer
  16638. (if (fboundp 'help-buffer) (help-buffer) "*Help*")
  16639. (princ mode-name)
  16640. (princ " mode:\n")
  16641. (princ (documentation 'vhdl-mode))
  16642. (with-current-buffer standard-output
  16643. (help-mode))
  16644. (help-print-return-message)))
  16645. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  16646. (provide 'vhdl-mode)
  16647. ;;; vhdl-mode.el ends here