speedbar.el 150 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118
  1. ;;; speedbar --- quick access to files and tags in a frame
  2. ;; Copyright (C) 1996-2012 Free Software Foundation, Inc.
  3. ;; Author: Eric M. Ludlam <zappo@gnu.org>
  4. ;; Keywords: file, tags, tools
  5. (defvar speedbar-version "1.0"
  6. "The current version of speedbar.")
  7. (defvar speedbar-incompatible-version "0.14beta4"
  8. "This version of speedbar is incompatible with this version.
  9. Due to massive API changes (removing the use of the word PATH)
  10. this version is not backward compatible to 0.14 or earlier.")
  11. ;; This file is part of GNU Emacs.
  12. ;; GNU Emacs is free software: you can redistribute it and/or modify
  13. ;; it under the terms of the GNU General Public License as published by
  14. ;; the Free Software Foundation, either version 3 of the License, or
  15. ;; (at your option) any later version.
  16. ;; GNU Emacs is distributed in the hope that it will be useful,
  17. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. ;; GNU General Public License for more details.
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  22. ;;; Commentary:
  23. ;;
  24. ;; The speedbar provides a frame in which files, and locations in
  25. ;; files are displayed. These items can be clicked on with mouse-2 in
  26. ;; to display that file location.
  27. ;;
  28. ;;; Customizing and Developing for speedbar
  29. ;;
  30. ;; Please see the speedbar manual for information.
  31. ;;
  32. ;;; Notes:
  33. ;;
  34. ;; Users of really old emacsen without the need timer functions
  35. ;; will not have speedbar updating automatically. Use "g" to refresh
  36. ;; the display after changing directories. Remember, do not interrupt
  37. ;; the stealthy updates or your display may not be completely
  38. ;; refreshed.
  39. ;;
  40. ;; AUC-TEX users: The imenu tags for AUC-TEX mode don't work very
  41. ;; well. Use the imenu keywords from tex-mode.el for better results.
  42. ;;
  43. ;; This file requires the library package assoc (association lists)
  44. ;; assoc should be available in all modern versions of Emacs.
  45. ;; The custom package is optional (for easy configuration of speedbar)
  46. ;; http://www.dina.kvl.dk/~abraham/custom/
  47. ;; custom is available in all versions of Emacs version 20 or better.
  48. ;;
  49. ;;; Developing for speedbar
  50. ;;
  51. ;; Adding a speedbar specialized display mode:
  52. ;;
  53. ;; Speedbar can be configured to create a special display for certain
  54. ;; modes that do not display traditional file/tag data. Rmail, Info,
  55. ;; and the debugger are examples. These modes can, however, benefit
  56. ;; from a speedbar style display in their own way.
  57. ;;
  58. ;; If your `major-mode' is `foo-mode', the only requirement is to
  59. ;; create a function called `foo-speedbar-buttons' which takes one
  60. ;; argument, BUFFER. BUFFER will be the buffer speedbar wants filled.
  61. ;; In `foo-speedbar-buttons' there are several functions that make
  62. ;; building a speedbar display easy. See the documentation for
  63. ;; `speedbar-with-writable' (needed because the buffer is usually
  64. ;; read-only) `speedbar-make-tag-line', `speedbar-insert-button', and
  65. ;; `speedbar-insert-generic-list'. If you use
  66. ;; `speedbar-insert-generic-list', also read the doc for
  67. ;; `speedbar-tag-hierarchy-method' in case you wish to override it.
  68. ;; The macro `speedbar-with-attached-buffer' brings you back to the
  69. ;; buffer speedbar is displaying for.
  70. ;;
  71. ;; For those functions that make buttons, the "function" should be a
  72. ;; symbol that is the function to call when clicked on. The "token"
  73. ;; is extra data you can pass along. The "function" must take three
  74. ;; parameters. They are (TEXT TOKEN INDENT). TEXT is the text of the
  75. ;; button clicked on. TOKEN is the data passed in when you create the
  76. ;; button. INDENT is an indentation level, or 0. You can store
  77. ;; indentation levels with `speedbar-make-tag-line' which creates a
  78. ;; line with an expander (eg. [+]) and a text button.
  79. ;;
  80. ;; Some useful functions when writing expand functions, and click
  81. ;; functions are `speedbar-change-expand-button-char',
  82. ;; `speedbar-delete-subblock', and `speedbar-center-buffer-smartly'.
  83. ;; The variable `speedbar-power-click' is set to t in your functions
  84. ;; when the user shift-clicks. This is an indication of anything from
  85. ;; refreshing cached data to making a buffer appear in a new frame.
  86. ;;
  87. ;; If you wish to add to the default speedbar menu for the case of
  88. ;; `foo-mode', create a variable `foo-speedbar-menu-items'. This
  89. ;; should be a list compatible with the `easymenu' package. It will
  90. ;; be spliced into the main menu. (Available with click-mouse-3). If
  91. ;; you wish to have extra key bindings in your special mode, create a
  92. ;; variable `foo-speedbar-key-map'. Instead of using `make-keymap',
  93. ;; or `make-sparse-keymap', use the function
  94. ;; `speedbar-make-specialized-keymap'. This lets you inherit all of
  95. ;; speedbar's default bindings with low overhead.
  96. ;;
  97. ;; Adding a speedbar top-level display mode:
  98. ;;
  99. ;; Unlike the specialized modes, there are no name requirements,
  100. ;; however the methods for writing a button display, menu, and keymap
  101. ;; are the same. Once you create these items, you can call the
  102. ;; function `speedbar-add-expansion-list'. It takes one parameter
  103. ;; which is a list element of the form (NAME MENU KEYMAP &rest
  104. ;; BUTTON-FUNCTIONS). NAME is a string that will show up in the
  105. ;; Displays menu item. MENU is a symbol containing the menu items to
  106. ;; splice in. KEYMAP is a symbol holding the keymap to use, and
  107. ;; BUTTON-FUNCTIONS are the function names to call, in order, to create
  108. ;; the display.
  109. ;; Another tweakable variable is `speedbar-stealthy-function-list'
  110. ;; which is of the form (NAME &rest FUNCTION ...). NAME is the string
  111. ;; name matching `speedbar-add-expansion-list'. (It does not need to
  112. ;; exist.). This provides additional display info which might be
  113. ;; time-consuming to calculate.
  114. ;; Lastly, `speedbar-mode-functions-list' allows you to set special
  115. ;; function overrides.
  116. ;;; TODO:
  117. ;; - Timeout directories we haven't visited in a while.
  118. (require 'assoc)
  119. (require 'easymenu)
  120. (require 'dframe)
  121. (require 'sb-image)
  122. ;; customization stuff
  123. (defgroup speedbar nil
  124. "File and tag browser frame."
  125. :group 'etags
  126. :group 'tools
  127. :group 'convenience
  128. ; :version "20.3"
  129. )
  130. (defgroup speedbar-faces nil
  131. "Faces used in speedbar."
  132. :prefix "speedbar-"
  133. :group 'speedbar
  134. :group 'faces)
  135. (defgroup speedbar-vc nil
  136. "Version control display in speedbar."
  137. :prefix "speedbar-"
  138. :group 'speedbar)
  139. ;;; Code:
  140. ;; Note: `inversion-test' requires parts of the CEDET package that are
  141. ;; not included with Emacs.
  142. ;;
  143. ;; (defun speedbar-require-version (major minor &optional beta)
  144. ;; "Non-nil if this version of SPEEDBAR does not satisfy a specific version.
  145. ;; Arguments can be:
  146. ;;
  147. ;; (MAJOR MINOR &optional BETA)
  148. ;;
  149. ;; Values MAJOR and MINOR must be integers. BETA can be an integer, or
  150. ;; excluded if a released version is required.
  151. ;;
  152. ;; It is assumed that if the current version is newer than that specified,
  153. ;; everything passes. Exceptions occur when known incompatibilities are
  154. ;; introduced."
  155. ;; (inversion-test 'speedbar
  156. ;; (concat major "." minor
  157. ;; (when beta (concat "beta" beta)))))
  158. (defvar speedbar-initial-expansion-mode-alist
  159. '(("buffers" speedbar-buffer-easymenu-definition speedbar-buffers-key-map
  160. speedbar-buffer-buttons)
  161. ("quick buffers" speedbar-buffer-easymenu-definition speedbar-buffers-key-map
  162. speedbar-buffer-buttons-temp)
  163. ;; Files last, means first in the Displays menu
  164. ("files" speedbar-easymenu-definition-special speedbar-file-key-map
  165. speedbar-directory-buttons speedbar-default-directory-list)
  166. )
  167. "List of named expansion elements for filling the speedbar frame.
  168. These expansion lists are only valid for regular files. Special modes
  169. still get to override this list on a mode-by-mode basis. This list of
  170. lists is of the form (NAME MENU KEYMAP FN1 FN2 ...). NAME is a string
  171. representing the types of things to be displayed. MENU is an easymenu
  172. structure used when in this mode. KEYMAP is a local keymap to install
  173. over the regular speedbar keymap. FN1 ... are functions that will be
  174. called in order. These functions will always get the default
  175. directory to use passed in as the first parameter, and a 0 as the
  176. second parameter. The 0 indicates the uppermost indentation level.
  177. They must assume that the cursor is at the position where they start
  178. inserting buttons.")
  179. (defvar speedbar-initial-expansion-list-name "files"
  180. "A symbol name representing the expansion list to use.
  181. The expansion list `speedbar-initial-expansion-mode-alist' contains
  182. the names and associated functions to use for buttons in speedbar.")
  183. (defvar speedbar-previously-used-expansion-list-name "files"
  184. "Save the last expansion list method.
  185. This is used for returning to a previous expansion list method when
  186. the user is done with the current expansion list.")
  187. (defvar speedbar-stealthy-function-list
  188. '(("files"
  189. speedbar-update-current-file
  190. speedbar-check-read-only
  191. speedbar-check-vc
  192. speedbar-check-objects)
  193. )
  194. "List of functions to periodically call stealthily.
  195. This list is of the form:
  196. '( (\"NAME\" FUNCTION ...)
  197. ...)
  198. where NAME is the name of the major display mode these functions are
  199. for, and the remaining elements FUNCTION are functions to call in order.
  200. Each function must return nil if interrupted, or t if completed.
  201. Stealthy functions which have a single operation should always return t.
  202. Functions which take a long time should maintain a state (where they
  203. are in their speedbar related calculations) and permit interruption.
  204. See `speedbar-check-vc' as a good example.")
  205. (defvar speedbar-mode-functions-list
  206. '(("files" (speedbar-item-info . speedbar-files-item-info)
  207. (speedbar-line-directory . speedbar-files-line-directory))
  208. ("buffers" (speedbar-item-info . speedbar-buffers-item-info)
  209. (speedbar-line-directory . speedbar-buffers-line-directory))
  210. ("quick buffers" (speedbar-item-info . speedbar-buffers-item-info)
  211. (speedbar-line-directory . speedbar-buffers-line-directory))
  212. )
  213. "List of function tables to use for different major display modes.
  214. It is not necessary to define any functions for a specialized mode.
  215. This just provides a simple way of adding lots of customizations.
  216. Each sublist is of the form:
  217. (\"NAME\" (FUNCTIONSYMBOL . REPLACEMENTFUNCTION) ...)
  218. Where NAME is the name of the specialized mode. The rest of the list
  219. is a set of dotted pairs of the form FUNCTIONSYMBOL, which is the name
  220. of a function you would like to replace, and REPLACEMENTFUNCTION,
  221. which is a function you can call instead. Not all functions can be
  222. replaced this way. Replaceable functions must provide that
  223. functionality individually.")
  224. (defcustom speedbar-mode-specific-contents-flag t
  225. "Non-nil means speedbar will show special mode contents.
  226. This permits some modes to create customized contents for the speedbar
  227. frame."
  228. :group 'speedbar
  229. :type 'boolean)
  230. (defcustom speedbar-query-confirmation-method 'all
  231. "Query control for file operations.
  232. The 'always flag means to always query before file operations.
  233. The 'none-but-delete flag means to not query before any file
  234. operations, except before a file deletion."
  235. :group 'speedbar
  236. :type '(radio (const :tag "Always Query before some file operations."
  237. all)
  238. (const :tag "Never Query before file operations, except for deletions."
  239. none-but-delete)
  240. ;;;; (const :tag "Never Every Query."
  241. ;;;; none)
  242. ))
  243. (defvar speedbar-special-mode-expansion-list nil
  244. "Default function list for creating specialized button lists.
  245. This list is set by modes that wish to have special speedbar displays.
  246. The list is of function names. Each function is called with one
  247. parameter BUFFER, the originating buffer. The current buffer is the
  248. speedbar buffer.")
  249. (defvar speedbar-special-mode-key-map nil
  250. "Default keymap used when identifying a specialized display mode.
  251. This keymap is local to each buffer that wants to define special keybindings
  252. effective when its display is shown.")
  253. (defcustom speedbar-before-visiting-file-hook '(push-mark)
  254. "Hooks run before speedbar visits a file in the selected frame.
  255. The default buffer is the buffer in the selected window in the attached frame."
  256. :group 'speedbar
  257. :type 'hook)
  258. (defcustom speedbar-visiting-file-hook nil
  259. "Hooks run when speedbar visits a file in the selected frame."
  260. :group 'speedbar
  261. :type 'hook)
  262. (defcustom speedbar-before-visiting-tag-hook '(push-mark)
  263. "Hooks run before speedbar visits a tag in the selected frame.
  264. The default buffer is the buffer in the selected window in the attached frame."
  265. :group 'speedbar
  266. :type 'hook)
  267. (defcustom speedbar-visiting-tag-hook '(speedbar-highlight-one-tag-line)
  268. "Hooks run when speedbar visits a tag in the selected frame."
  269. :group 'speedbar
  270. :type 'hook
  271. :options '(speedbar-highlight-one-tag-line
  272. speedbar-recenter-to-top
  273. speedbar-recenter
  274. ))
  275. (defcustom speedbar-load-hook nil
  276. "Hooks run when speedbar is loaded."
  277. :group 'speedbar
  278. :type 'hook)
  279. (defcustom speedbar-reconfigure-keymaps-hook nil
  280. "Hooks run when the keymaps are regenerated."
  281. :group 'speedbar
  282. :type 'hook)
  283. (defcustom speedbar-show-unknown-files nil
  284. "Non-nil show files we can't expand with a ? in the expand button.
  285. A nil value means don't show the file in the list."
  286. :group 'speedbar
  287. :type 'boolean)
  288. ;;; EVENTUALLY REMOVE THESE
  289. ;; When I moved to a repeating timer, I had the horrible misfortune
  290. ;; of losing the ability for adaptive speed choice. This update
  291. ;; speed currently causes long delays when it should have been turned off.
  292. (defvar speedbar-update-speed dframe-update-speed)
  293. (make-obsolete-variable 'speedbar-update-speed
  294. 'dframe-update-speed
  295. "speedbar 1.0pre3 (Emacs 23.1)")
  296. (defvar speedbar-navigating-speed dframe-update-speed)
  297. (make-obsolete-variable 'speedbar-navigating-speed
  298. 'dframe-update-speed
  299. "speedbar 1.0pre3 (Emacs 23.1)")
  300. ;;; END REMOVE THESE
  301. (defcustom speedbar-frame-parameters '((minibuffer . nil)
  302. (width . 20)
  303. (border-width . 0)
  304. (menu-bar-lines . 0)
  305. (tool-bar-lines . 0)
  306. (unsplittable . t)
  307. (left-fringe . 0)
  308. )
  309. "Parameters to use when creating the speedbar frame in Emacs.
  310. Any parameter supported by a frame may be added. The parameter `height'
  311. will be initialized to the height of the frame speedbar is
  312. attached to and added to this list before the new frame is initialized."
  313. :group 'speedbar
  314. :type '(repeat (cons :format "%v"
  315. (symbol :tag "Parameter")
  316. (sexp :tag "Value"))))
  317. ;; These values by Hrvoje Niksic <hniksic@srce.hr>
  318. (defcustom speedbar-frame-plist
  319. '(minibuffer nil width 20 border-width 0
  320. internal-border-width 0 unsplittable t
  321. default-toolbar-visible-p nil has-modeline-p nil
  322. menubar-visible-p nil
  323. default-gutter-visible-p nil
  324. )
  325. "Parameters to use when creating the speedbar frame in XEmacs.
  326. Parameters not listed here which will be added automatically are
  327. `height' which will be initialized to the height of the frame speedbar
  328. is attached to."
  329. :group 'speedbar
  330. :type '(repeat (group :inline t
  331. (symbol :tag "Property")
  332. (sexp :tag "Value"))))
  333. (defcustom speedbar-use-imenu-flag (fboundp 'imenu)
  334. "Non-nil means use imenu for file parsing, nil to use etags.
  335. XEmacs prior to 20.4 doesn't support imenu, therefore the default is to
  336. use etags instead. Etags support is not as robust as imenu support."
  337. :tag "Use Imenu for tags"
  338. :group 'speedbar
  339. :type 'boolean)
  340. (defvar speedbar-dynamic-tags-function-list
  341. '((speedbar-fetch-dynamic-imenu . speedbar-insert-imenu-list)
  342. (speedbar-fetch-dynamic-etags . speedbar-insert-etags-list))
  343. "Set to a list of functions which will return and insert a list of tags.
  344. Each element is of the form ( FETCH . INSERT ) where FETCH
  345. is a function which takes one parameter (the file to tag) and returns a
  346. list of tags. The tag list can be of any form as long as the
  347. corresponding insert method can handle it. If it returns t, then an
  348. error occurred, and the next fetch routine is tried.
  349. INSERT is a function which takes an INDENTation level, and a LIST of
  350. tags to insert. It will then create the speedbar buttons.")
  351. (defcustom speedbar-use-tool-tips-flag (fboundp 'tooltip-mode)
  352. "Non-nil means to use tool tips if they are available.
  353. When tooltips are not available, mouse-tracking and minibuffer
  354. display is used instead."
  355. :group 'speedbar
  356. :type 'boolean)
  357. (defcustom speedbar-track-mouse-flag (not speedbar-use-tool-tips-flag)
  358. "Non-nil means to display info about the line under the mouse."
  359. :group 'speedbar
  360. :type 'boolean)
  361. (defcustom speedbar-default-position 'left-right
  362. "Default position of the speedbar frame.
  363. Possible values are 'left, 'right or 'left-right.
  364. If value is 'left-right, the most suitable location is
  365. determined automatically."
  366. :group 'speedbar
  367. :type '(radio (const :tag "Automatic" left-right)
  368. (const :tag "Left" left)
  369. (const :tag "Right" right)))
  370. (defcustom speedbar-sort-tags nil
  371. "If non-nil, sort tags in the speedbar display. *Obsolete*.
  372. Use `semantic-tag-hierarchy-method' instead."
  373. :group 'speedbar
  374. :type 'boolean)
  375. (defcustom speedbar-tag-hierarchy-method
  376. '(speedbar-prefix-group-tag-hierarchy
  377. speedbar-trim-words-tag-hierarchy)
  378. "List of hooks which speedbar will use to organize tags into groups.
  379. Groups are defined as expandable meta-tags. Imenu supports
  380. such things in some languages, such as separating variables from
  381. functions. Each hook takes one argument LST, and may destructively
  382. create a new list of the same form. LST is a list of elements of the
  383. form:
  384. (ELT1 ELT2 ... ELTn)
  385. where each ELT is of the form
  386. (TAG-NAME-STRING . NUMBER-OR-MARKER)
  387. or
  388. (GROUP-NAME-STRING ELT1 ELT2... ELTn)"
  389. :group 'speedbar
  390. :type 'hook
  391. :options '(speedbar-prefix-group-tag-hierarchy
  392. speedbar-trim-words-tag-hierarchy
  393. speedbar-simple-group-tag-hierarchy
  394. speedbar-sort-tag-hierarchy)
  395. )
  396. (defcustom speedbar-tag-group-name-minimum-length 4
  397. "The minimum length of a prefix group name before expanding.
  398. Thus, if the `speedbar-tag-hierarchy-method' includes `prefix-group'
  399. and one such groups common characters is less than this number of
  400. characters, then the group name will be changed to the form of:
  401. worda to wordb
  402. instead of just
  403. word
  404. This way we won't get silly looking listings."
  405. :group 'speedbar
  406. :type 'integer)
  407. (defcustom speedbar-tag-split-minimum-length 20
  408. "Minimum length before we stop trying to create sub-lists in tags.
  409. This is used by all tag-hierarchy methods that break large lists into
  410. sub-lists."
  411. :group 'speedbar
  412. :type 'integer)
  413. (defcustom speedbar-tag-regroup-maximum-length 10
  414. "Maximum length of submenus that are regrouped.
  415. If the regrouping option is used, then if two or more short subgroups
  416. are next to each other, then they are combined until this number of
  417. items is reached."
  418. :group 'speedbar
  419. :type 'integer)
  420. (defcustom speedbar-directory-button-trim-method 'span
  421. "Indicates how the directory button will be displayed.
  422. Possible values are:
  423. 'span - span large directories over multiple lines.
  424. 'trim - trim large directories to only show the last few.
  425. nil - no trimming."
  426. :group 'speedbar
  427. :type '(radio (const :tag "Span large directories over multiple lines."
  428. span)
  429. (const :tag "Trim large directories to only show the last few."
  430. trim)
  431. (const :tag "No trimming." nil)))
  432. (defcustom speedbar-smart-directory-expand-flag t
  433. "Non-nil means speedbar should use smart expansion.
  434. Smart expansion only affects when speedbar wants to display a
  435. directory for a file in the attached frame. When smart expansion is
  436. enabled, new directories which are children of a displayed directory
  437. are expanded in the current framework. If nil, then the current
  438. hierarchy would be replaced with the new directory."
  439. :group 'speedbar
  440. :type 'boolean)
  441. (defcustom speedbar-indentation-width 1
  442. "When sub-nodes are expanded, the number of spaces used for indentation."
  443. :group 'speedbar
  444. :type 'integer)
  445. (defcustom speedbar-hide-button-brackets-flag nil
  446. "Non-nil means speedbar will hide the brackets around the + or -."
  447. :group 'speedbar
  448. :type 'boolean)
  449. (defcustom speedbar-before-popup-hook nil
  450. "Hooks called before popping up the speedbar frame."
  451. :group 'speedbar
  452. :type 'hook)
  453. (defcustom speedbar-after-create-hook '(speedbar-frame-reposition-smartly)
  454. "Hooks called after popping up the speedbar frame."
  455. :group 'speedbar
  456. :type 'hook)
  457. (defcustom speedbar-before-delete-hook nil
  458. "Hooks called before deleting the speedbar frame."
  459. :group 'speedbar
  460. :type 'hook)
  461. (defcustom speedbar-mode-hook nil
  462. "Hook run after creating a speedbar buffer."
  463. :group 'speedbar
  464. :type 'hook)
  465. (defcustom speedbar-timer-hook nil
  466. "Hooks called after running the speedbar timer function."
  467. :group 'speedbar
  468. :type 'hook)
  469. (defcustom speedbar-verbosity-level 1
  470. "Verbosity level of the speedbar.
  471. 0 means say nothing.
  472. 1 means medium level verbosity.
  473. 2 and higher are higher levels of verbosity."
  474. :group 'speedbar
  475. :type 'integer)
  476. (defvar speedbar-indicator-separator " "
  477. "String separating file text from indicator characters.")
  478. (defcustom speedbar-vc-do-check t
  479. "Non-nil check all files in speedbar to see if they have been checked out.
  480. Any file checked out is marked with `speedbar-vc-indicator'."
  481. :group 'speedbar-vc
  482. :type 'boolean)
  483. (defvar speedbar-vc-indicator "*"
  484. "Text used to mark files which are currently checked out.
  485. Other version control systems can be added by examining the function
  486. `speedbar-vc-directory-enable-hook' and `speedbar-vc-in-control-hook'.")
  487. (defcustom speedbar-vc-directory-enable-hook nil
  488. "Return non-nil if the current directory should be checked for Version Control.
  489. Functions in this hook must accept one parameter which is the directory
  490. being checked."
  491. :group 'speedbar-vc
  492. :type 'hook)
  493. (defcustom speedbar-vc-in-control-hook nil
  494. "Return non-nil if the specified file is under Version Control.
  495. Functions in this hook must accept two parameters. The DIRECTORY of the
  496. current file, and the FILENAME of the file being checked."
  497. :group 'speedbar-vc
  498. :type 'hook)
  499. (defvar speedbar-vc-to-do-point nil
  500. "Local variable maintaining the current version control check position.")
  501. (defcustom speedbar-obj-do-check t
  502. "Non-nil check all files in speedbar to see if they have an object file.
  503. Any file checked out is marked with `speedbar-obj-indicator', and the
  504. marking is based on `speedbar-obj-alist'"
  505. :group 'speedbar-vc
  506. :type 'boolean)
  507. (defvar speedbar-obj-to-do-point nil
  508. "Local variable maintaining the current version control check position.")
  509. (defvar speedbar-obj-indicator '("#" . "!")
  510. "Text used to mark files that have a corresponding hidden object file.
  511. The car is for an up-to-date object. The cdr is for an out of date object.
  512. The expression `speedbar-obj-alist' defines who gets tagged.")
  513. (defvar speedbar-obj-alist
  514. '(("\\.\\([cpC]\\|cpp\\|cc\\|cxx\\)$" . ".o")
  515. ("\\.el$" . ".elc")
  516. ("\\.java$" . ".class")
  517. ("\\.f\\(or\\|90\\|77\\)?$" . ".o")
  518. ("\\.tex$" . ".dvi")
  519. ("\\.texi$" . ".info"))
  520. "Alist of file extensions, and their corresponding object file type.")
  521. (defvar speedbar-ro-to-do-point nil
  522. "Local variable maintaining the current read only check position.")
  523. (defvar speedbar-object-read-only-indicator "%"
  524. "Indicator to append onto a line if that item is Read Only.")
  525. ;; Note: Look for addition place to add indicator lists that
  526. ;; use skip-chars instead of a regular expression.
  527. (defvar speedbar-indicator-regex
  528. (concat (regexp-quote speedbar-indicator-separator)
  529. "\\("
  530. (regexp-quote speedbar-vc-indicator)
  531. "\\|"
  532. (regexp-quote (car speedbar-obj-indicator))
  533. "\\|"
  534. (regexp-quote (cdr speedbar-obj-indicator))
  535. "\\|"
  536. (regexp-quote speedbar-object-read-only-indicator)
  537. "\\)*")
  538. "Regular expression used when identifying files.
  539. Permits stripping of indicator characters from a line.")
  540. (defcustom speedbar-scanner-reset-hook nil
  541. "Hook called whenever generic scanners are reset.
  542. Set this to implement your own scanning / rescan safe functions with
  543. state data."
  544. :group 'speedbar
  545. :type 'hook)
  546. (defcustom speedbar-ignored-modes '(fundamental-mode)
  547. "List of major modes which speedbar will not switch directories for."
  548. :group 'speedbar
  549. :type '(choice (const nil)
  550. (repeat :tag "List of modes" (symbol :tag "Major mode"))))
  551. (defun speedbar-extension-list-to-regex (extlist)
  552. "Takes EXTLIST, a list of extensions and transforms it into regexp.
  553. All the preceding `.' are stripped for an optimized expression starting
  554. with `.' followed by extensions, followed by full-filenames."
  555. (let ((regex1 nil) (regex2 nil))
  556. (while extlist
  557. (if (= (string-to-char (car extlist)) ?.)
  558. (setq regex1 (concat regex1 (if regex1 "\\|" "")
  559. (substring (car extlist) 1)))
  560. (setq regex2 (concat regex2 (if regex2 "\\|" "") (car extlist))))
  561. (setq extlist (cdr extlist)))
  562. ;; Concatenate all the subexpressions together, making sure all types
  563. ;; of parts exist during concatenation.
  564. (concat "\\("
  565. (if regex1 (concat "\\(\\.\\(" regex1 "\\)\\)") "")
  566. (if (and regex1 regex2) "\\|" "")
  567. (if regex2 (concat "\\(" regex2 "\\)") "")
  568. "\\)$")))
  569. (defvar speedbar-ignored-directory-regexp nil
  570. "Regular expression matching directories speedbar will not switch to.
  571. Created from `speedbar-ignored-directory-expressions' with the function
  572. `speedbar-extension-list-to-regex' (a misnamed function in this case.)
  573. Use the function `speedbar-add-ignored-directory-regexp', or customize the
  574. variable `speedbar-ignored-directory-expressions' to modify this variable.")
  575. (define-obsolete-variable-alias 'speedbar-ignored-path-expressions
  576. 'speedbar-ignored-directory-expressions "22.1")
  577. (defcustom speedbar-ignored-directory-expressions
  578. '("[/\\]logs?[/\\]\\'")
  579. "List of regular expressions matching directories speedbar will ignore.
  580. They should included directories which are notoriously very large
  581. and take a long time to load in. Use the function
  582. `speedbar-add-ignored-directory-regexp' to add new items to this list after
  583. speedbar is loaded. You may place anything you like in this list
  584. before speedbar has been loaded."
  585. :group 'speedbar
  586. :type '(repeat (regexp :tag "Directory Regexp"))
  587. :set (lambda (_sym val)
  588. (setq speedbar-ignored-directory-expressions val
  589. speedbar-ignored-directory-regexp
  590. (speedbar-extension-list-to-regex val))))
  591. (defcustom speedbar-directory-unshown-regexp "^\\(\\..*\\)\\'"
  592. "Regular expression matching directories not to show in speedbar.
  593. They should include commonly existing directories which are not
  594. useful. It is no longer necessary to include version-control
  595. directories here; see `vc-directory-exclusion-list'."
  596. :group 'speedbar
  597. :type 'string)
  598. (defcustom speedbar-file-unshown-regexp
  599. (let ((nstr "") (noext completion-ignored-extensions))
  600. (while noext
  601. (setq nstr (concat nstr (regexp-quote (car noext)) "\\'"
  602. (if (cdr noext) "\\|" ""))
  603. noext (cdr noext)))
  604. ;; backup refdir lockfile
  605. (concat nstr "\\|#[^#]+#$\\|\\.\\.?\\'\\|\\.#"))
  606. "Regexp matching files we don't want displayed in a speedbar buffer.
  607. It is generated from the variable `completion-ignored-extensions'."
  608. :group 'speedbar
  609. :type 'string)
  610. (defvar speedbar-file-regexp nil
  611. "Regular expression matching files we know how to expand.
  612. Created from `speedbar-supported-extension-expressions' with the
  613. function `speedbar-extension-list-to-regex'.")
  614. ;; this is dangerous to customize, because the defaults will probably
  615. ;; change in the future.
  616. (defcustom speedbar-supported-extension-expressions
  617. (append '(".[ch]\\(\\+\\+\\|pp\\|c\\|h\\|xx\\)?" ".tex\\(i\\(nfo\\)?\\)?"
  618. ".el" ".emacs" ".l" ".lsp" ".p" ".java" ".js" ".f\\(90\\|77\\|or\\)?")
  619. (if speedbar-use-imenu-flag
  620. '(".ad[abs]" ".p[lm]" ".tcl" ".m" ".scm" ".pm" ".py" ".g"
  621. ;; html is not supported by default, but an imenu tags package
  622. ;; is available. Also, html files are nice to be able to see.
  623. ".s?html"
  624. ".ma?k" "[Mm]akefile\\(\\.in\\)?")))
  625. "List of regular expressions which will match files supported by tagging.
  626. Do not prefix the `.' char with a double \\ to quote it, as the period
  627. will be stripped by a simplified optimizer when compiled into a
  628. singular expression. This variable will be turned into
  629. `speedbar-file-regexp' for use with speedbar. You should use the
  630. function `speedbar-add-supported-extension' to add a new extension at
  631. runtime, or use the configuration dialog to set it in your .emacs file.
  632. If you add an extension to this list, and it does not appear, you may
  633. need to also modify `completion-ignored-extension' which will also help
  634. file completion."
  635. :group 'speedbar
  636. :type '(repeat (regexp :tag "Extension Regexp"))
  637. :set (lambda (_sym val)
  638. (set 'speedbar-supported-extension-expressions val)
  639. (set 'speedbar-file-regexp (speedbar-extension-list-to-regex val))))
  640. (setq speedbar-file-regexp
  641. (speedbar-extension-list-to-regex speedbar-supported-extension-expressions))
  642. (defun speedbar-add-supported-extension (extension)
  643. "Add EXTENSION as a new supported extension for speedbar tagging.
  644. This should start with a `.' if it is not a complete file name, and
  645. the dot should NOT be quoted in with \\. Other regular expression
  646. matchers are allowed however. EXTENSION may be a single string or a
  647. list of strings."
  648. (interactive "sExtension: ")
  649. (if (not (listp extension)) (setq extension (list extension)))
  650. (while extension
  651. (if (member (car extension) speedbar-supported-extension-expressions)
  652. nil
  653. (setq speedbar-supported-extension-expressions
  654. (cons (car extension) speedbar-supported-extension-expressions)))
  655. (setq extension (cdr extension)))
  656. (setq speedbar-file-regexp (speedbar-extension-list-to-regex
  657. speedbar-supported-extension-expressions)))
  658. (defun speedbar-add-ignored-directory-regexp (directory-expression)
  659. "Add DIRECTORY-EXPRESSION as a new ignored directory for speedbar tracking.
  660. This function will modify `speedbar-ignored-directory-regexp' and add
  661. DIRECTORY-EXPRESSION to `speedbar-ignored-directory-expressions'."
  662. (interactive "sDirectory regex: ")
  663. (if (not (listp directory-expression))
  664. (setq directory-expression (list directory-expression)))
  665. (while directory-expression
  666. (if (member (car directory-expression) speedbar-ignored-directory-expressions)
  667. nil
  668. (setq speedbar-ignored-directory-expressions
  669. (cons (car directory-expression) speedbar-ignored-directory-expressions)))
  670. (setq directory-expression (cdr directory-expression)))
  671. (setq speedbar-ignored-directory-regexp (speedbar-extension-list-to-regex
  672. speedbar-ignored-directory-expressions)))
  673. ;; If we don't have custom, then we set it here by hand.
  674. (if (not (fboundp 'custom-declare-variable))
  675. (setq speedbar-file-regexp (speedbar-extension-list-to-regex
  676. speedbar-supported-extension-expressions)
  677. speedbar-ignored-directory-regexp (speedbar-extension-list-to-regex
  678. speedbar-ignored-directory-expressions)))
  679. (defcustom speedbar-update-flag dframe-have-timer-flag
  680. "Non-nil means to automatically update the display.
  681. When this is nil then speedbar will not follow the attached frame's directory.
  682. If you want to change this while speedbar is active, either use
  683. \\[customize] or call \\<speedbar-key-map> `\\[speedbar-toggle-updates]'."
  684. :group 'speedbar
  685. :initialize 'custom-initialize-default
  686. :set (lambda (sym val)
  687. (set sym val)
  688. (speedbar-toggle-updates))
  689. :type 'boolean)
  690. (defvar speedbar-update-flag-disable nil
  691. "Permanently disable changing of the update flag.")
  692. (defvar speedbar-mode-syntax-table
  693. (let ((st (make-syntax-table)))
  694. ;; Turn off paren matching around here.
  695. (modify-syntax-entry ?\' " " st)
  696. (modify-syntax-entry ?\" " " st)
  697. (modify-syntax-entry ?\( " " st)
  698. (modify-syntax-entry ?\) " " st)
  699. (modify-syntax-entry ?\{ " " st)
  700. (modify-syntax-entry ?\} " " st)
  701. (modify-syntax-entry ?\[ " " st)
  702. (modify-syntax-entry ?\] " " st)
  703. st)
  704. "Syntax-table used on the speedbar.")
  705. (define-obsolete-variable-alias
  706. 'speedbar-syntax-table 'speedbar-mode-syntax-table "24.1")
  707. (defvar speedbar-mode-map
  708. (let ((map (make-keymap)))
  709. (suppress-keymap map t)
  710. ;; Control.
  711. (define-key map "t" 'speedbar-toggle-updates)
  712. (define-key map "g" 'speedbar-refresh)
  713. ;; Navigation.
  714. (define-key map "n" 'speedbar-next)
  715. (define-key map "p" 'speedbar-prev)
  716. (define-key map "\M-n" 'speedbar-restricted-next)
  717. (define-key map "\M-p" 'speedbar-restricted-prev)
  718. (define-key map "\C-\M-n" 'speedbar-forward-list)
  719. (define-key map "\C-\M-p" 'speedbar-backward-list)
  720. ;; These commands never seemed useful.
  721. ;; (define-key map " " 'speedbar-scroll-up)
  722. ;; (define-key map [delete] 'speedbar-scroll-down)
  723. ;; Short cuts I happen to find useful.
  724. (define-key map "r"
  725. (lambda () (interactive)
  726. (speedbar-change-initial-expansion-list
  727. speedbar-previously-used-expansion-list-name)))
  728. (define-key map "b"
  729. (lambda () (interactive)
  730. (speedbar-change-initial-expansion-list "quick buffers")))
  731. (define-key map "f"
  732. (lambda () (interactive)
  733. (speedbar-change-initial-expansion-list "files")))
  734. (dframe-update-keymap map)
  735. map)
  736. "Keymap used in speedbar buffer.")
  737. (define-obsolete-variable-alias 'speedbar-key-map 'speedbar-mode-map "24.1")
  738. (defun speedbar-make-specialized-keymap ()
  739. "Create a keymap for use with a speedbar major or minor display mode.
  740. This basically creates a sparse keymap, and makes its parent be
  741. `speedbar-mode-map'."
  742. (let ((k (make-sparse-keymap)))
  743. (set-keymap-parent k speedbar-mode-map)
  744. k))
  745. (defvar speedbar-file-key-map
  746. (let ((map (speedbar-make-specialized-keymap)))
  747. ;; Basic tree features.
  748. (define-key map "e" 'speedbar-edit-line)
  749. (define-key map "\C-m" 'speedbar-edit-line)
  750. (define-key map "+" 'speedbar-expand-line)
  751. (define-key map "=" 'speedbar-expand-line)
  752. (define-key map "-" 'speedbar-contract-line)
  753. (define-key map "[" 'speedbar-expand-line-descendants)
  754. (define-key map "]" 'speedbar-contract-line-descendants)
  755. (define-key map " " 'speedbar-toggle-line-expansion)
  756. ;; File based commands.
  757. (define-key map "U" 'speedbar-up-directory)
  758. (define-key map "I" 'speedbar-item-info)
  759. (define-key map "B" 'speedbar-item-byte-compile)
  760. (define-key map "L" 'speedbar-item-load)
  761. (define-key map "C" 'speedbar-item-copy)
  762. (define-key map "D" 'speedbar-item-delete)
  763. (define-key map "O" 'speedbar-item-object-delete)
  764. (define-key map "R" 'speedbar-item-rename)
  765. (define-key map "M" 'speedbar-create-directory)
  766. map)
  767. "Keymap used in speedbar buffer while files are displayed.")
  768. (defvar speedbar-easymenu-definition-base
  769. (append
  770. '("Speedbar"
  771. ["Update" speedbar-refresh t]
  772. ["Auto Update" speedbar-toggle-updates
  773. :active (not speedbar-update-flag-disable)
  774. :style toggle :selected speedbar-update-flag])
  775. (if (and (or (fboundp 'defimage)
  776. (fboundp 'make-image-specifier))
  777. (if (fboundp 'display-graphic-p)
  778. (display-graphic-p)
  779. window-system))
  780. (list
  781. ["Use Images" speedbar-toggle-images
  782. :style toggle :selected speedbar-use-images]))
  783. )
  784. "Base part of the speedbar menu.")
  785. (defvar speedbar-easymenu-definition-special
  786. '(["Edit Item On Line" speedbar-edit-line t]
  787. ["Show All Files" speedbar-toggle-show-all-files
  788. :style toggle :selected speedbar-show-unknown-files]
  789. ["Expand File Tags" speedbar-expand-line
  790. (save-excursion (beginning-of-line)
  791. (looking-at "[0-9]+: *.\\+. "))]
  792. ["Flush Cache & Expand" speedbar-flush-expand-line
  793. (save-excursion (beginning-of-line)
  794. (looking-at "[0-9]+: *.\\+. "))]
  795. ["Expand All Descendants" speedbar-expand-line-descendants
  796. (save-excursion (beginning-of-line)
  797. (looking-at "[0-9]+: *.\\+. ")) ]
  798. ["Contract File Tags" speedbar-contract-line
  799. (save-excursion (beginning-of-line)
  800. (looking-at "[0-9]+: *.-. "))]
  801. ; ["Sort Tags" speedbar-toggle-sorting
  802. ; :style toggle :selected speedbar-sort-tags]
  803. "----"
  804. ["File/Tag Information" speedbar-item-info t]
  805. ["Load Lisp File" speedbar-item-load
  806. (save-excursion
  807. (beginning-of-line)
  808. (looking-at "[0-9]+: *\\[[+-]\\] .+\\(\\.el\\)\\( \\|$\\)"))]
  809. ["Byte Compile File" speedbar-item-byte-compile
  810. (save-excursion
  811. (beginning-of-line)
  812. (looking-at "[0-9]+: *\\[[+-]\\] .+\\(\\.el\\)\\( \\|$\\)"))]
  813. ["Copy File" speedbar-item-copy
  814. (save-excursion (beginning-of-line) (looking-at "[0-9]+: *\\["))]
  815. ["Rename File" speedbar-item-rename
  816. (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
  817. ["Create Directory" speedbar-create-directory
  818. (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
  819. ["Delete File" speedbar-item-delete
  820. (save-excursion (beginning-of-line) (looking-at "[0-9]+: *[[<]"))]
  821. ["Delete Object" speedbar-item-object-delete
  822. (save-excursion (beginning-of-line)
  823. (looking-at "[0-9]+: *\\[[+-]\\] [^ \n]+ \\*?[!#]$"))]
  824. )
  825. "Additional menu items while in file-mode.")
  826. (defvar speedbar-easymenu-definition-trailer
  827. (append
  828. (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
  829. (list ["Customize..." speedbar-customize t]))
  830. (list
  831. ["Close" dframe-close-frame t]
  832. ["Quit" delete-frame t] ))
  833. "Menu items appearing at the end of the speedbar menu.")
  834. (defvar speedbar-desired-buffer nil
  835. "Non-nil when speedbar is showing buttons specific to a special mode.
  836. In this case it is the originating buffer.")
  837. (defvar speedbar-buffer nil
  838. "The buffer displaying the speedbar.")
  839. (defvar speedbar-frame nil
  840. "The frame displaying speedbar.")
  841. (defvar speedbar-cached-frame nil
  842. "The frame that was last created, then removed from the display.")
  843. (defvar speedbar-full-text-cache nil
  844. "The last open directory is saved in its entirety for ultra-fast switching.")
  845. (defvar speedbar-last-selected-file nil
  846. "The last file which was selected in speedbar buffer.")
  847. (defvar speedbar-shown-directories nil
  848. "Maintain list of directories simultaneously open in the current speedbar.")
  849. (defvar speedbar-directory-contents-alist nil
  850. "An association list of directories and their contents.
  851. Each sublist was returned by `speedbar-file-lists'. This list is
  852. maintained to speed up the refresh rate when switching between
  853. directories.")
  854. (defvar speedbar-power-click nil
  855. "Never set this by hand. Value is t when S-mouse activity occurs.")
  856. ;;; Compatibility
  857. ;;
  858. (defalias 'speedbar-make-overlay
  859. (if (featurep 'xemacs) 'make-extent 'make-overlay))
  860. (defalias 'speedbar-overlay-put
  861. (if (featurep 'xemacs) 'set-extent-property 'overlay-put))
  862. (defalias 'speedbar-delete-overlay
  863. (if (featurep 'xemacs) 'delete-extent 'delete-overlay))
  864. (defalias 'speedbar-mode-line-update
  865. (if (featurep 'xemacs) 'redraw-modeline 'force-mode-line-update))
  866. ;;; Mode definitions/ user commands
  867. ;;
  868. ;;;###autoload
  869. (defalias 'speedbar 'speedbar-frame-mode)
  870. ;;;###autoload
  871. (defun speedbar-frame-mode (&optional arg)
  872. "Enable or disable speedbar. Positive ARG means turn on, negative turn off.
  873. A nil ARG means toggle. Once the speedbar frame is activated, a buffer in
  874. `speedbar-mode' will be displayed. Currently, only one speedbar is
  875. supported at a time.
  876. `speedbar-before-popup-hook' is called before popping up the speedbar frame.
  877. `speedbar-before-delete-hook' is called before the frame is deleted."
  878. (interactive "P")
  879. ;; Get the buffer to play with
  880. (if (not (buffer-live-p speedbar-buffer))
  881. (save-excursion
  882. (setq speedbar-buffer (get-buffer-create " SPEEDBAR"))
  883. (set-buffer speedbar-buffer)
  884. (speedbar-mode)))
  885. ;; Do the frame thing
  886. (dframe-frame-mode arg
  887. 'speedbar-frame
  888. 'speedbar-cached-frame
  889. 'speedbar-buffer
  890. "Speedbar"
  891. #'speedbar-frame-mode
  892. (if (featurep 'xemacs)
  893. (append speedbar-frame-plist
  894. ;; This is a hack to get speedbar to iconify
  895. ;; with the selected frame.
  896. (list 'parent (selected-frame)))
  897. speedbar-frame-parameters)
  898. speedbar-before-delete-hook
  899. speedbar-before-popup-hook
  900. speedbar-after-create-hook)
  901. ;; Start up the timer
  902. (if (not speedbar-frame)
  903. (speedbar-set-timer nil)
  904. (speedbar-reconfigure-keymaps)
  905. (speedbar-update-contents)
  906. (speedbar-set-timer dframe-update-speed)
  907. )
  908. ;; Frame modifications
  909. (set (make-local-variable 'dframe-delete-frame-function)
  910. 'speedbar-handle-delete-frame)
  911. ;; hscroll
  912. (set (make-local-variable 'automatic-hscrolling) nil) ; Emacs 21
  913. ;; reset the selection variable
  914. (setq speedbar-last-selected-file nil))
  915. (defun speedbar-frame-reposition-smartly ()
  916. "Reposition the speedbar frame to be next to the attached frame."
  917. (cond ((and (featurep 'xemacs)
  918. (or (member 'left speedbar-frame-plist)
  919. (member 'top speedbar-frame-plist)))
  920. (dframe-reposition-frame
  921. speedbar-frame
  922. (dframe-attached-frame speedbar-frame)
  923. (cons (car (cdr (member 'left speedbar-frame-plist)))
  924. (car (cdr (member 'top speedbar-frame-plist)))))
  925. )
  926. ((and (not (featurep 'xemacs))
  927. (or (assoc 'left speedbar-frame-parameters)
  928. (assoc 'top speedbar-frame-parameters)))
  929. ;; if left/top were specified in the parameters, pass them
  930. ;; down to the reposition function
  931. (dframe-reposition-frame
  932. speedbar-frame
  933. (dframe-attached-frame speedbar-frame)
  934. (cons (cdr (assoc 'left speedbar-frame-parameters))
  935. (cdr (assoc 'top speedbar-frame-parameters))))
  936. )
  937. (t
  938. (dframe-reposition-frame speedbar-frame
  939. (dframe-attached-frame speedbar-frame)
  940. speedbar-default-position))))
  941. (defsubst speedbar-current-frame ()
  942. "Return the frame to use for speedbar based on current context."
  943. (dframe-current-frame 'speedbar-frame 'speedbar-mode))
  944. (defun speedbar-handle-delete-frame (e)
  945. "Handle a delete frame event E.
  946. If the deleted frame is the frame speedbar is attached to,
  947. we need to delete speedbar also."
  948. (when (and speedbar-frame
  949. (eq (car (car (cdr e))) ;; frame to be deleted
  950. dframe-attached-frame))
  951. (delete-frame speedbar-frame)))
  952. ;;;###autoload
  953. (defun speedbar-get-focus ()
  954. "Change frame focus to or from the speedbar frame.
  955. If the selected frame is not speedbar, then speedbar frame is
  956. selected. If the speedbar frame is active, then select the attached frame."
  957. (interactive)
  958. (speedbar-reset-scanners)
  959. (dframe-get-focus 'speedbar-frame 'speedbar-frame-mode
  960. (lambda () (let ((speedbar-update-flag t))
  961. (speedbar-timer-fn)))))
  962. (defsubst speedbar-frame-width ()
  963. "Return the width of the speedbar frame in characters.
  964. Return nil if it doesn't exist."
  965. (frame-width speedbar-frame))
  966. (define-derived-mode speedbar-mode fundamental-mode "Speedbar"
  967. "Major mode for managing a display of directories and tags.
  968. \\<speedbar-key-map>
  969. The first line represents the default directory of the speedbar frame.
  970. Each directory segment is a button which jumps speedbar's default
  971. directory to that directory. Buttons are activated by clicking `\\[speedbar-click]'.
  972. In some situations using `\\[dframe-power-click]' is a `power click' which will
  973. rescan cached items, or pop up new frames.
  974. Each line starting with <+> represents a directory. Click on the <+>
  975. to insert the directory listing into the current tree. Click on the
  976. <-> to retract that list. Click on the directory name to go to that
  977. directory as the default.
  978. Each line starting with [+] is a file. If the variable
  979. `speedbar-show-unknown-files' is t, the lines starting with [?] are
  980. files which don't have imenu support, but are not expressly ignored.
  981. Files are completely ignored if they match `speedbar-file-unshown-regexp'
  982. which is generated from `completion-ignored-extensions'.
  983. Files with a `*' character after their name are files checked out of a
  984. version control system. (Currently only RCS is supported.) New
  985. version control systems can be added by examining the documentation
  986. for `speedbar-this-file-in-vc' and `speedbar-vc-check-dir-p'.
  987. Files with a `#' or `!' character after them are source files that
  988. have an object file associated with them. The `!' indicates that the
  989. files is out of date. You can control what source/object associations
  990. exist through the variable `speedbar-obj-alist'.
  991. Click on the [+] to display a list of tags from that file. Click on
  992. the [-] to retract the list. Click on the file name to edit the file
  993. in the attached frame.
  994. If you open tags, you might find a node starting with {+}, which is a
  995. category of tags. Click the {+} to expand the category. Jump-able
  996. tags start with >. Click the name of the tag to go to that position
  997. in the selected file.
  998. \\{speedbar-key-map}"
  999. (save-excursion
  1000. (setq font-lock-keywords nil) ;; no font-locking please
  1001. (setq truncate-lines t)
  1002. (make-local-variable 'frame-title-format)
  1003. (setq frame-title-format (concat "Speedbar " speedbar-version)
  1004. case-fold-search nil
  1005. buffer-read-only t)
  1006. (speedbar-set-mode-line-format)
  1007. ;; Add in our dframe hooks.
  1008. (if speedbar-track-mouse-flag
  1009. (setq dframe-track-mouse-function #'speedbar-track-mouse))
  1010. (setq dframe-help-echo-function #'speedbar-item-info
  1011. dframe-mouse-click-function #'speedbar-click
  1012. dframe-mouse-position-function #'speedbar-position-cursor-on-line))
  1013. speedbar-buffer)
  1014. (defmacro speedbar-message (fmt &rest args)
  1015. "Like `message', but for use in the speedbar frame.
  1016. Argument FMT is the format string, and ARGS are the arguments for message."
  1017. `(dframe-message ,fmt ,@args))
  1018. (defsubst speedbar-y-or-n-p (prompt &optional deleting)
  1019. "Like `y-or-n-p', but for use in the speedbar frame.
  1020. Argument PROMPT is the prompt to use.
  1021. Optional argument DELETING means this is a query that will delete something.
  1022. The variable `speedbar-query-confirmation-method' can cause this to
  1023. return true without a query."
  1024. (or (and (not deleting)
  1025. (eq speedbar-query-confirmation-method 'none-but-delete))
  1026. (dframe-y-or-n-p prompt)))
  1027. (defsubst speedbar-select-attached-frame ()
  1028. "Select the frame attached to this speedbar."
  1029. (dframe-select-attached-frame (speedbar-current-frame)))
  1030. ;; Backwards compatibility
  1031. (defalias 'speedbar-with-attached-buffer 'dframe-with-attached-buffer)
  1032. (defalias 'speedbar-maybee-jump-to-attached-frame 'dframe-maybee-jump-to-attached-frame)
  1033. (defun speedbar-set-mode-line-format ()
  1034. "Set the format of the mode line based on the current speedbar environment.
  1035. This gives visual indications of what is up. It EXPECTS the speedbar
  1036. frame and window to be the currently active frame and window."
  1037. (if (and (frame-live-p (speedbar-current-frame))
  1038. (or (not (featurep 'xemacs))
  1039. (with-no-warnings
  1040. (specifier-instance has-modeline-p)))
  1041. speedbar-buffer)
  1042. (with-current-buffer speedbar-buffer
  1043. (let* ((w (or (speedbar-frame-width) 20))
  1044. (p1 "<<")
  1045. (p5 ">>")
  1046. (p3 (if speedbar-update-flag "#" "!"))
  1047. (p35 (capitalize speedbar-initial-expansion-list-name))
  1048. (blank (- w (length p1) (length p3) (length p5) (length p35)
  1049. (if line-number-mode 5 1)))
  1050. (p2 (if (> blank 0)
  1051. (make-string (/ blank 2) ? )
  1052. ""))
  1053. (p4 (if (> blank 0)
  1054. (make-string (+ (/ blank 2) (% blank 2)) ? )
  1055. ""))
  1056. (tf
  1057. (if line-number-mode
  1058. (list (concat p1 p2 p3 " " p35) '(line-number-mode " %3l")
  1059. (concat p4 p5))
  1060. (list (concat p1 p2 p3 p4 p5)))))
  1061. (if (not (equal mode-line-format tf))
  1062. (progn
  1063. (setq mode-line-format tf)
  1064. (speedbar-mode-line-update)))))))
  1065. (defvar speedbar-previous-menu nil
  1066. "The menu before the last `speedbar-reconfigure-keymaps' was called.")
  1067. (defun speedbar-reconfigure-keymaps ()
  1068. "Reconfigure the menu-bar in a speedbar frame.
  1069. Different menu items are displayed depending on the current display mode
  1070. and the existence of packages."
  1071. (let ((md (append
  1072. speedbar-easymenu-definition-base
  1073. (if speedbar-shown-directories
  1074. ;; file display mode version
  1075. (speedbar-initial-menu)
  1076. (save-excursion
  1077. (dframe-select-attached-frame speedbar-frame)
  1078. (eval (nth 1 (assoc speedbar-initial-expansion-list-name
  1079. speedbar-initial-expansion-mode-alist)))))
  1080. ;; Dynamic menu stuff
  1081. '("-")
  1082. (list (cons "Displays"
  1083. (let ((displays nil)
  1084. (alist speedbar-initial-expansion-mode-alist))
  1085. (while alist
  1086. (setq displays
  1087. (cons
  1088. (vector
  1089. (capitalize (car (car alist)))
  1090. (list
  1091. 'speedbar-change-initial-expansion-list
  1092. (car (car alist)))
  1093. :style 'radio
  1094. :selected
  1095. `(string= ,(car (car alist))
  1096. speedbar-initial-expansion-list-name)
  1097. )
  1098. displays))
  1099. (setq alist (cdr alist)))
  1100. displays)))
  1101. ;; The trailer
  1102. speedbar-easymenu-definition-trailer))
  1103. (localmap (save-excursion
  1104. (let ((cf (selected-frame)))
  1105. (prog2
  1106. (dframe-select-attached-frame speedbar-frame)
  1107. (if (local-variable-p
  1108. 'speedbar-special-mode-key-map
  1109. (current-buffer))
  1110. speedbar-special-mode-key-map)
  1111. (select-frame cf))))))
  1112. (with-current-buffer speedbar-buffer
  1113. (use-local-map (or localmap
  1114. (speedbar-initial-keymap)
  1115. ;; This creates a small keymap we can glom the
  1116. ;; menu adjustments into.
  1117. (speedbar-make-specialized-keymap)))
  1118. ;; Delete the old menu if applicable.
  1119. (if speedbar-previous-menu (easy-menu-remove speedbar-previous-menu))
  1120. (setq speedbar-previous-menu md)
  1121. ;; Now add the new menu
  1122. (if (not (featurep 'xemacs))
  1123. (easy-menu-define speedbar-menu-map (current-local-map)
  1124. "Speedbar menu" md)
  1125. (easy-menu-add md (current-local-map))
  1126. ;; XEmacs-specific:
  1127. (if (fboundp 'set-buffer-menubar)
  1128. (set-buffer-menubar (list md)))))
  1129. (run-hooks 'speedbar-reconfigure-keymaps-hook)))
  1130. ;;; User Input stuff
  1131. ;;
  1132. (defun speedbar-customize ()
  1133. "Customize speedbar using the Custom package."
  1134. (interactive)
  1135. (let ((sf (selected-frame)))
  1136. (dframe-select-attached-frame speedbar-frame)
  1137. (customize-group 'speedbar)
  1138. (select-frame sf))
  1139. (dframe-maybee-jump-to-attached-frame))
  1140. (defun speedbar-track-mouse (event)
  1141. "For motion EVENT, display info about the current line."
  1142. (if (not speedbar-track-mouse-flag)
  1143. nil
  1144. (save-excursion
  1145. (save-window-excursion
  1146. (condition-case nil
  1147. (progn
  1148. (mouse-set-point event)
  1149. (if (eq major-mode 'speedbar-mode)
  1150. ;; XEmacs may let us get in here in other mode buffers.
  1151. (speedbar-item-info)))
  1152. (error (speedbar-message nil)))))))
  1153. (defun speedbar-show-info-under-mouse ()
  1154. "Call the info function for the line under the mouse."
  1155. (let ((pos (mouse-position))) ; we ignore event until I use it later.
  1156. (if (equal (car pos) speedbar-frame)
  1157. (save-excursion
  1158. (save-window-excursion
  1159. (apply 'set-mouse-position pos)
  1160. (speedbar-item-info))))))
  1161. (defun speedbar-next (arg)
  1162. "Move to the next ARGth line in a speedbar buffer."
  1163. (interactive "p")
  1164. (forward-line (or arg 1))
  1165. (speedbar-item-info)
  1166. (speedbar-position-cursor-on-line))
  1167. (defun speedbar-prev (arg)
  1168. "Move to the previous ARGth line in a speedbar buffer."
  1169. (interactive "p")
  1170. (speedbar-next (if arg (- arg) -1)))
  1171. (defun speedbar-restricted-move (arg)
  1172. "Move to the next ARGth line in a speedbar buffer at the same depth.
  1173. This means that movement is restricted to a subnode, and that siblings
  1174. of intermediate nodes are skipped."
  1175. (if (not (numberp arg)) (signal 'wrong-type-argument (list 'numberp arg)))
  1176. ;; First find the extent for which we are allowed to move.
  1177. (let ((depth (save-excursion (beginning-of-line)
  1178. (if (looking-at "[0-9]+:")
  1179. (string-to-number (match-string 0))
  1180. 0)))
  1181. (crement (if (< arg 0) 1 -1)) ; decrement or increment
  1182. (lastmatch (point)))
  1183. (while (/= arg 0)
  1184. (forward-line (- crement))
  1185. (let ((subdepth (save-excursion (beginning-of-line)
  1186. (if (looking-at "[0-9]+:")
  1187. (string-to-number (match-string 0))
  1188. 0))))
  1189. (cond ((or (< subdepth depth)
  1190. (progn (end-of-line) (eobp))
  1191. (progn (beginning-of-line) (bobp)))
  1192. ;; We have reached the end of this block.
  1193. (goto-char lastmatch)
  1194. (setq arg 0)
  1195. (error "End of sub-list"))
  1196. ((= subdepth depth)
  1197. (setq lastmatch (point)
  1198. arg (+ arg crement))))))
  1199. (speedbar-position-cursor-on-line)))
  1200. (defun speedbar-restricted-next (arg)
  1201. "Move to the next ARGth line in a speedbar buffer at the same depth.
  1202. This means that movement is restricted to a subnode, and that siblings
  1203. of intermediate nodes are skipped."
  1204. (interactive "p")
  1205. (speedbar-restricted-move (or arg 1))
  1206. (speedbar-item-info))
  1207. (defun speedbar-restricted-prev (arg)
  1208. "Move to the previous ARGth line in a speedbar buffer at the same depth.
  1209. This means that movement is restricted to a subnode, and that siblings
  1210. of intermediate nodes are skipped."
  1211. (interactive "p")
  1212. (speedbar-restricted-move (if arg (- arg) -1))
  1213. (speedbar-item-info))
  1214. (defun speedbar-navigate-list (arg)
  1215. "Move across ARG groups of similarly typed items in speedbar.
  1216. Stop on the first line of the next type of item, or on the last or first item
  1217. if we reach a buffer boundary."
  1218. (interactive "p")
  1219. (beginning-of-line)
  1220. (if (looking-at "[0-9]+: *[[<{][-+?][]>}] ")
  1221. (let ((str (regexp-quote (match-string 0))))
  1222. (while (looking-at str)
  1223. (speedbar-restricted-move arg)
  1224. (beginning-of-line))))
  1225. (speedbar-position-cursor-on-line))
  1226. (defun speedbar-forward-list ()
  1227. "Move forward over the current list.
  1228. A LIST in speedbar is a group of similarly typed items, such as directories,
  1229. files, or the directory button."
  1230. (interactive)
  1231. (speedbar-navigate-list 1)
  1232. (speedbar-item-info))
  1233. (defun speedbar-backward-list ()
  1234. "Move backward over the current list.
  1235. A LIST in speedbar is a group of similarly typed items, such as directories,
  1236. files, or the directory button."
  1237. (interactive)
  1238. (speedbar-navigate-list -1)
  1239. (speedbar-item-info))
  1240. (defun speedbar-scroll-up (&optional arg)
  1241. "Page down one screen-full of the speedbar, or ARG lines."
  1242. (interactive "P")
  1243. (scroll-up arg)
  1244. (speedbar-position-cursor-on-line))
  1245. (defun speedbar-scroll-down (&optional arg)
  1246. "Page up one screen-full of the speedbar, or ARG lines."
  1247. (interactive "P")
  1248. (scroll-down arg)
  1249. (speedbar-position-cursor-on-line))
  1250. (defun speedbar-up-directory ()
  1251. "Keyboard accelerator for moving the default directory up one.
  1252. Assumes that the current buffer is the speedbar buffer."
  1253. (interactive)
  1254. (setq default-directory (expand-file-name (concat default-directory "../")))
  1255. (speedbar-update-contents))
  1256. ;;; Speedbar file activity (aka creeping featurism)
  1257. ;;
  1258. (defun speedbar-refresh (&optional arg)
  1259. "Refresh the current speedbar display, disposing of any cached data.
  1260. Argument ARG represents to force a refresh past any caches that may exist."
  1261. (interactive "P")
  1262. (let ((dl speedbar-shown-directories)
  1263. (dframe-power-click arg)
  1264. deactivate-mark)
  1265. ;; We need to hack something so this works in detached frames.
  1266. (while dl
  1267. (adelete 'speedbar-directory-contents-alist (car dl))
  1268. (setq dl (cdr dl)))
  1269. (if (<= 1 speedbar-verbosity-level)
  1270. (speedbar-message "Refreshing speedbar..."))
  1271. (speedbar-update-contents)
  1272. (speedbar-stealthy-updates)
  1273. ;; Reset the timer in case it got really hosed for some reason...
  1274. (speedbar-set-timer dframe-update-speed)
  1275. (if (<= 1 speedbar-verbosity-level)
  1276. (speedbar-message "Refreshing speedbar...done"))))
  1277. (defun speedbar-item-load ()
  1278. "Load the item under the cursor or mouse if it is a Lisp file."
  1279. (interactive)
  1280. (let ((f (speedbar-line-file)))
  1281. (if (and (file-exists-p f) (string-match "\\.el\\'" f))
  1282. (if (and (file-exists-p (concat f "c"))
  1283. (speedbar-y-or-n-p (format "Load %sc? " f)))
  1284. ;; If the compiled version exists, load that instead...
  1285. (load-file (concat f "c"))
  1286. (load-file f))
  1287. (error "Not a loadable file"))))
  1288. (defun speedbar-item-byte-compile ()
  1289. "Byte compile the item under the cursor or mouse if it is a Lisp file."
  1290. (interactive)
  1291. (let ((f (speedbar-line-file))
  1292. (sf (selected-frame)))
  1293. (if (and (file-exists-p f) (string-match "\\.el\\'" f))
  1294. (progn
  1295. (dframe-select-attached-frame speedbar-frame)
  1296. (byte-compile-file f nil)
  1297. (select-frame sf)
  1298. (speedbar-reset-scanners)))
  1299. ))
  1300. (defun speedbar-mouse-item-info (event)
  1301. "Provide information about what the user clicked on.
  1302. This should be bound to a mouse EVENT."
  1303. (interactive "e")
  1304. (mouse-set-point event)
  1305. (speedbar-item-info))
  1306. (defun speedbar-generic-item-info ()
  1307. "Attempt to derive, and then display information about this line item.
  1308. File style information is displayed with `speedbar-item-info'."
  1309. (save-excursion
  1310. (beginning-of-line)
  1311. ;; Skip invisible number info.
  1312. (if (looking-at "\\([0-9]+\\):") (goto-char (match-end 0)))
  1313. ;; Skip items in "folder" type text characters.
  1314. (if (looking-at "\\s-*[[<({].[]>)}] ") (goto-char (match-end 0)))
  1315. ;; Get the text
  1316. (speedbar-message "Text: %s" (buffer-substring-no-properties
  1317. (point) (line-end-position)))))
  1318. (defun speedbar-item-info ()
  1319. "Display info in the minibuffer about the button the mouse is over.
  1320. This function can be replaced in `speedbar-mode-functions-list' as
  1321. `speedbar-item-info'."
  1322. (interactive)
  1323. (let (message-log-max)
  1324. (funcall (or (speedbar-fetch-replacement-function 'speedbar-item-info)
  1325. 'speedbar-generic-item-info))))
  1326. (defun speedbar-item-info-file-helper (&optional filename)
  1327. "Display info about a file that is on the current line.
  1328. Return nil if not applicable. If FILENAME, then use that
  1329. instead of reading it from the speedbar buffer."
  1330. (let* ((item (or filename (speedbar-line-file)))
  1331. (attr (if item (file-attributes item) nil)))
  1332. (if (and item attr) (speedbar-message "%s %-6d %s" (nth 8 attr)
  1333. (nth 7 attr) item)
  1334. nil)))
  1335. (defun speedbar-item-info-tag-helper ()
  1336. "Display info about a tag that is on the current line.
  1337. Return nil if not applicable."
  1338. (save-excursion
  1339. (beginning-of-line)
  1340. (if (re-search-forward " [-+=]?> \\([^\n]+\\)" (line-end-position) t)
  1341. (let* ((tag (match-string 1))
  1342. (attr (speedbar-line-token))
  1343. (item nil)
  1344. (semantic-tagged (if (fboundp 'semantic-tag-p)
  1345. (semantic-tag-p attr))))
  1346. (if semantic-tagged
  1347. (with-no-warnings
  1348. (save-excursion
  1349. (when (and (semantic-tag-overlay attr)
  1350. (semantic-tag-buffer attr))
  1351. (set-buffer (semantic-tag-buffer attr)))
  1352. (speedbar-message
  1353. (funcall semantic-sb-info-format-tag-function attr)
  1354. )))
  1355. (looking-at "\\([0-9]+\\):")
  1356. (setq item (file-name-nondirectory (speedbar-line-directory)))
  1357. (speedbar-message "Tag: %s in %s" tag item)))
  1358. (if (re-search-forward "{[+-]} \\([^\n]+\\)$" (line-end-position) t)
  1359. (speedbar-message "Group of tags \"%s\"" (match-string 1))
  1360. (if (re-search-forward " [+-]?[()|@] \\([^\n]+\\)$" nil t)
  1361. (let* ((detailtext (match-string 1))
  1362. (detail (or (speedbar-line-token) detailtext))
  1363. (parent (save-excursion
  1364. (beginning-of-line)
  1365. (let ((dep (if (looking-at "[0-9]+:")
  1366. (1- (string-to-number (match-string 0)))
  1367. 0)))
  1368. (re-search-backward (concat "^"
  1369. (int-to-string dep)
  1370. ":")
  1371. nil t))
  1372. (if (looking-at "[0-9]+: +[-+=>]> \\([^\n]+\\)$")
  1373. (speedbar-line-token)
  1374. nil))))
  1375. (if (featurep 'semantic)
  1376. (with-no-warnings
  1377. (if (semantic-tag-p detail)
  1378. (speedbar-message
  1379. (funcall semantic-sb-info-format-tag-function detail parent))
  1380. (if parent
  1381. (speedbar-message "Detail: %s of tag %s" detail
  1382. (if (semantic-tag-p parent)
  1383. (semantic-format-tag-name parent nil t)
  1384. parent))
  1385. (speedbar-message "Detail: %s" detail))))
  1386. ;; Not using `semantic':
  1387. (if parent
  1388. (speedbar-message "Detail: %s of tag %s" detail parent)
  1389. (speedbar-message "Detail: %s" detail))))
  1390. nil)))))
  1391. (defun speedbar-files-item-info ()
  1392. "Display info in the minibuffer about the button the mouse is over."
  1393. (if (not speedbar-shown-directories)
  1394. (speedbar-generic-item-info)
  1395. (or (speedbar-item-info-file-helper)
  1396. (speedbar-item-info-tag-helper)
  1397. (speedbar-generic-item-info))))
  1398. (defun speedbar-item-copy ()
  1399. "Copy the item under the cursor.
  1400. Files can be copied to new names or places."
  1401. (interactive)
  1402. (let ((f (speedbar-line-file)))
  1403. (if (not f) (error "Not a file"))
  1404. (if (file-directory-p f)
  1405. (error "Cannot copy directory")
  1406. (let* ((rt (read-file-name (format "Copy %s to: "
  1407. (file-name-nondirectory f))
  1408. (file-name-directory f)))
  1409. (refresh (member (expand-file-name (file-name-directory rt))
  1410. speedbar-shown-directories)))
  1411. ;; Create the right file name part
  1412. (if (file-directory-p rt)
  1413. (setq rt
  1414. (concat (expand-file-name rt)
  1415. (if (string-match "[/\\]$" rt) "" "/")
  1416. (file-name-nondirectory f))))
  1417. (if (or (not (file-exists-p rt))
  1418. (speedbar-y-or-n-p (format "Overwrite %s with %s? " rt f)
  1419. t))
  1420. (progn
  1421. (copy-file f rt t t)
  1422. ;; refresh display if the new place is currently displayed.
  1423. (if refresh
  1424. (progn
  1425. (speedbar-refresh)
  1426. (if (not (speedbar-goto-this-file rt))
  1427. (speedbar-goto-this-file f))))
  1428. ))))))
  1429. (defun speedbar-item-rename ()
  1430. "Rename the item under the cursor or mouse.
  1431. Files can be renamed to new names or moved to new directories."
  1432. (interactive)
  1433. (let ((f (speedbar-line-file)))
  1434. (if f
  1435. (let* ((rt (read-file-name (format "Rename %s to: "
  1436. (file-name-nondirectory f))
  1437. (file-name-directory f)))
  1438. (refresh (member (expand-file-name (file-name-directory rt))
  1439. speedbar-shown-directories)))
  1440. ;; Create the right file name part
  1441. (if (file-directory-p rt)
  1442. (setq rt
  1443. (concat (expand-file-name rt)
  1444. (if (string-match "[/\\]\\'" rt) "" "/")
  1445. (file-name-nondirectory f))))
  1446. (if (or (not (file-exists-p rt))
  1447. (speedbar-y-or-n-p (format "Overwrite %s with %s? " rt f)
  1448. t))
  1449. (progn
  1450. (rename-file f rt t)
  1451. ;; refresh display if the new place is currently displayed.
  1452. (if refresh
  1453. (progn
  1454. (speedbar-refresh)
  1455. (speedbar-goto-this-file rt)
  1456. )))))
  1457. (error "Not a file"))))
  1458. (defun speedbar-create-directory ()
  1459. "Create a directory in speedbar."
  1460. (interactive)
  1461. (let ((f (speedbar-line-file)))
  1462. (if f
  1463. (let* ((basedir (file-name-directory f))
  1464. (nd (read-directory-name "Create directory: "
  1465. basedir)))
  1466. ;; Make the directory
  1467. (make-directory nd t)
  1468. (speedbar-refresh)
  1469. (speedbar-goto-this-file nd)
  1470. )
  1471. (error "Not a file"))))
  1472. (defun speedbar-item-delete ()
  1473. "Delete the item under the cursor. Files are removed from disk."
  1474. (interactive)
  1475. (let ((f (speedbar-line-file)))
  1476. (if (not f) (error "Not a file"))
  1477. (if (speedbar-y-or-n-p (format "Delete %s? " f) t)
  1478. (progn
  1479. (if (file-directory-p f)
  1480. (delete-directory f t t)
  1481. (delete-file f t))
  1482. (speedbar-message "Okie dokie.")
  1483. (let ((p (point)))
  1484. (speedbar-refresh)
  1485. (goto-char p))
  1486. ))
  1487. ))
  1488. (defun speedbar-item-object-delete ()
  1489. "Delete the object associated from the item under the cursor.
  1490. The file is removed from disk. The object is determined from the
  1491. variable `speedbar-obj-alist'."
  1492. (interactive)
  1493. (let* ((f (speedbar-line-file))
  1494. (obj nil)
  1495. (oa speedbar-obj-alist))
  1496. (if (not f) (error "Not a file"))
  1497. (while (and oa (not (string-match (car (car oa)) f)))
  1498. (setq oa (cdr oa)))
  1499. (setq obj (concat (file-name-sans-extension f) (cdr (car oa))))
  1500. (if (and oa (file-exists-p obj)
  1501. (speedbar-y-or-n-p (format "Delete %s? " obj) t))
  1502. (progn
  1503. (delete-file obj)
  1504. (speedbar-reset-scanners)))))
  1505. (defun speedbar-enable-update ()
  1506. "Enable automatic updating in speedbar via timers."
  1507. (interactive)
  1508. (setq speedbar-update-flag t)
  1509. (speedbar-set-mode-line-format)
  1510. (speedbar-set-timer dframe-update-speed))
  1511. (defun speedbar-disable-update ()
  1512. "Disable automatic updating and stop consuming resources."
  1513. (interactive)
  1514. (setq speedbar-update-flag nil)
  1515. (speedbar-set-mode-line-format)
  1516. (speedbar-set-timer nil))
  1517. (defun speedbar-toggle-updates ()
  1518. "Toggle automatic update for the speedbar frame."
  1519. (interactive)
  1520. (if speedbar-update-flag
  1521. (speedbar-disable-update)
  1522. (speedbar-enable-update)))
  1523. (defun speedbar-toggle-images ()
  1524. "Toggle use of images in the speedbar frame."
  1525. (interactive)
  1526. (setq speedbar-use-images (not speedbar-use-images))
  1527. (speedbar-refresh))
  1528. (defun speedbar-toggle-sorting ()
  1529. "Toggle tag sorting."
  1530. (interactive)
  1531. (setq speedbar-sort-tags (not speedbar-sort-tags)))
  1532. (defun speedbar-toggle-show-all-files ()
  1533. "Toggle display of files speedbar can not tag."
  1534. (interactive)
  1535. (setq speedbar-show-unknown-files (not speedbar-show-unknown-files))
  1536. (speedbar-refresh))
  1537. (defmacro speedbar-with-writable (&rest forms)
  1538. "Allow the buffer to be writable and evaluate FORMS."
  1539. (list 'let '((inhibit-read-only t))
  1540. (cons 'progn forms)))
  1541. (put 'speedbar-with-writable 'lisp-indent-function 0)
  1542. (defun speedbar-insert-button (text face mouse function
  1543. &optional token prevline)
  1544. "Insert TEXT as the next logical speedbar button.
  1545. FACE is the face to put on the button, MOUSE is the highlight face to use.
  1546. When the user clicks on TEXT, FUNCTION is called with the TOKEN parameter.
  1547. This function assumes that the current buffer is the speedbar buffer.
  1548. If PREVLINE, then put this button on the previous line.
  1549. This is a convenience function for special modes that create their own
  1550. specialized speedbar displays."
  1551. (goto-char (point-max))
  1552. (let ((start (point)))
  1553. (if (/= (current-column) 0) (insert "\n"))
  1554. (put-text-property start (point) 'invisible nil))
  1555. (if prevline (progn (delete-char -1)
  1556. (insert " ") ;back up if desired...
  1557. (put-text-property (1- (point)) (point) 'invisible nil)))
  1558. (let ((start (point)))
  1559. (insert text)
  1560. (speedbar-make-button start (point) face mouse function token))
  1561. (let ((start (point)))
  1562. (insert "\n")
  1563. (add-text-properties
  1564. start (point) '(face nil invisible nil mouse-face nil))))
  1565. (defun speedbar-insert-separator (text)
  1566. "Insert a separation label of TEXT.
  1567. Separators are not active, have no labels, depth, or actions."
  1568. (if speedbar-use-images
  1569. (let ((start (point)))
  1570. (insert "//")
  1571. (speedbar-insert-image-button-maybe start 2)))
  1572. (let ((start (point)))
  1573. (insert text "\n")
  1574. (speedbar-make-button start (point)
  1575. 'speedbar-separator-face
  1576. nil nil nil)))
  1577. (defun speedbar-make-button (start end face mouse function &optional token)
  1578. "Create a button from START to END, with FACE as the display face.
  1579. MOUSE is the mouse face. When this button is clicked on FUNCTION
  1580. will be run with the TOKEN parameter (any Lisp object). If FACE
  1581. is t use the text properties of the string that is passed as an
  1582. argument."
  1583. (unless (eq face t)
  1584. (put-text-property start end 'face face))
  1585. (add-text-properties
  1586. start end `(mouse-face ,mouse invisible nil
  1587. speedbar-text ,(buffer-substring-no-properties start end)))
  1588. (if speedbar-use-tool-tips-flag
  1589. (put-text-property start end 'help-echo #'dframe-help-echo))
  1590. (if function (put-text-property start end 'speedbar-function function))
  1591. (if token (put-text-property start end 'speedbar-token token))
  1592. ;; So far the only text we have is less that 3 chars.
  1593. (if (<= (- end start) 3)
  1594. (speedbar-insert-image-button-maybe start (- end start)))
  1595. )
  1596. ;;; Initial Expansion list management
  1597. ;;
  1598. (defun speedbar-initial-expansion-list ()
  1599. "Return the current default expansion list.
  1600. This is based on `speedbar-initial-expansion-list-name' referencing
  1601. `speedbar-initial-expansion-mode-alist'."
  1602. ;; cdr1 - name, cdr2 - menu
  1603. (cdr (cdr (cdr (assoc speedbar-initial-expansion-list-name
  1604. speedbar-initial-expansion-mode-alist)))))
  1605. (defun speedbar-initial-menu ()
  1606. "Return the current default menu data.
  1607. This is based on `speedbar-initial-expansion-list-name' referencing
  1608. `speedbar-initial-expansion-mode-alist'."
  1609. (symbol-value
  1610. (car (cdr (assoc speedbar-initial-expansion-list-name
  1611. speedbar-initial-expansion-mode-alist)))))
  1612. (defun speedbar-initial-keymap ()
  1613. "Return the current default menu data.
  1614. This is based on `speedbar-initial-expansion-list-name' referencing
  1615. `speedbar-initial-expansion-mode-alist'."
  1616. (symbol-value
  1617. (car (cdr (cdr (assoc speedbar-initial-expansion-list-name
  1618. speedbar-initial-expansion-mode-alist))))))
  1619. (defun speedbar-initial-stealthy-functions ()
  1620. "Return a list of functions to call stealthily.
  1621. This is based on `speedbar-initial-expansion-list-name' referencing
  1622. `speedbar-stealthy-function-list'."
  1623. (cdr (assoc speedbar-initial-expansion-list-name
  1624. speedbar-stealthy-function-list)))
  1625. (defun speedbar-add-expansion-list (new-list)
  1626. "Add NEW-LIST to the list of expansion lists."
  1627. (add-to-list 'speedbar-initial-expansion-mode-alist new-list))
  1628. (defun speedbar-change-initial-expansion-list (new-default)
  1629. "Change speedbar's default expansion list to NEW-DEFAULT."
  1630. (interactive
  1631. (list
  1632. (completing-read (format "Speedbar Mode (default %s): "
  1633. speedbar-previously-used-expansion-list-name)
  1634. speedbar-initial-expansion-mode-alist
  1635. nil t "" nil
  1636. speedbar-previously-used-expansion-list-name)))
  1637. (setq speedbar-previously-used-expansion-list-name
  1638. speedbar-initial-expansion-list-name
  1639. speedbar-initial-expansion-list-name new-default)
  1640. (if (and (speedbar-current-frame) (frame-live-p (speedbar-current-frame)))
  1641. (progn
  1642. (speedbar-refresh)
  1643. (speedbar-reconfigure-keymaps))))
  1644. (defun speedbar-fetch-replacement-function (function)
  1645. "Return a current mode-specific replacement for function, or nil.
  1646. Scans `speedbar-mode-functions-list' first for the current mode, then
  1647. for FUNCTION."
  1648. (cdr (assoc function
  1649. (cdr (assoc speedbar-initial-expansion-list-name
  1650. speedbar-mode-functions-list)))))
  1651. (defun speedbar-add-mode-functions-list (new-list)
  1652. "Add NEW-LIST to the list of mode functions.
  1653. See `speedbar-mode-functions-list' for details."
  1654. (add-to-list 'speedbar-mode-functions-list new-list))
  1655. ;;; Special speedbar display management
  1656. ;;
  1657. (defun speedbar-maybe-add-localized-support (buffer)
  1658. "Quick check function called on BUFFERs by the speedbar timer function.
  1659. Maintains the value of local variables which control speedbar's use
  1660. of the special mode functions."
  1661. (or speedbar-special-mode-expansion-list
  1662. (speedbar-add-localized-speedbar-support buffer)))
  1663. (defun speedbar-add-localized-speedbar-support (buffer)
  1664. "Add localized speedbar support to BUFFER's mode if it is available."
  1665. (interactive "bBuffer: ")
  1666. (if (stringp buffer) (setq buffer (get-buffer buffer)))
  1667. (if (not (buffer-live-p buffer))
  1668. nil
  1669. (with-current-buffer buffer
  1670. (save-match-data
  1671. (let ((ms (symbol-name major-mode)) v)
  1672. (if (not (string-match "-mode$" ms))
  1673. nil ;; do nothing to broken mode
  1674. (setq ms (substring ms 0 (match-beginning 0)))
  1675. (setq v (intern-soft (concat ms "-speedbar-buttons")))
  1676. (make-local-variable 'speedbar-special-mode-expansion-list)
  1677. (if (not v)
  1678. (setq speedbar-special-mode-expansion-list t)
  1679. ;; If it is autoloaded, we need to load it now so that
  1680. ;; we have access to the variable -speedbar-menu-items.
  1681. ;; Is this XEmacs safe?
  1682. (let ((sf (symbol-function v)))
  1683. (if (and (listp sf) (eq (car sf) 'autoload))
  1684. (load-library (car (cdr sf)))))
  1685. (setq speedbar-special-mode-expansion-list (list v))
  1686. (setq v (intern-soft (concat ms "-speedbar-key-map")))
  1687. (if (not v)
  1688. nil ;; don't add special keymap
  1689. (make-local-variable 'speedbar-special-mode-key-map)
  1690. (setq speedbar-special-mode-key-map
  1691. (symbol-value v)))
  1692. (setq v (intern-soft (concat ms "-speedbar-menu-items")))
  1693. (if (not v)
  1694. nil ;; don't add special menus
  1695. (make-local-variable 'speedbar-easymenu-definition-special)
  1696. (setq speedbar-easymenu-definition-special
  1697. (symbol-value v)))
  1698. )))))))
  1699. (defun speedbar-remove-localized-speedbar-support (buffer)
  1700. "Remove any traces that BUFFER supports speedbar in a specialized way."
  1701. (with-current-buffer buffer
  1702. (kill-local-variable 'speedbar-special-mode-expansion-list)
  1703. (kill-local-variable 'speedbar-special-mode-key-map)
  1704. (kill-local-variable 'speedbar-easymenu-definition-special)))
  1705. ;;; File button management
  1706. ;;
  1707. (defun speedbar-file-lists (directory)
  1708. "Create file lists for DIRECTORY.
  1709. The car is the list of directories, the cdr is list of files not
  1710. matching ignored headers. Cache any directory files found in
  1711. `speedbar-directory-contents-alist' and use that cache before scanning
  1712. the file-system."
  1713. (setq directory (expand-file-name directory))
  1714. ;; If in powerclick mode, then the directory we are getting
  1715. ;; should be rescanned.
  1716. (if dframe-power-click
  1717. (adelete 'speedbar-directory-contents-alist directory))
  1718. ;; find the directory, either in the cache, or build it.
  1719. (or (cdr-safe (assoc directory speedbar-directory-contents-alist))
  1720. (let ((default-directory directory)
  1721. (dir (directory-files directory nil))
  1722. (dirs nil)
  1723. (files nil))
  1724. (while dir
  1725. (if (not
  1726. (or (string-match speedbar-file-unshown-regexp (car dir))
  1727. (member (car dir) vc-directory-exclusion-list)
  1728. (string-match speedbar-directory-unshown-regexp (car dir))))
  1729. (if (file-directory-p (car dir))
  1730. (setq dirs (cons (car dir) dirs))
  1731. (setq files (cons (car dir) files))))
  1732. (setq dir (cdr dir)))
  1733. (let ((nl (cons (nreverse dirs) (list (nreverse files)))))
  1734. (aput 'speedbar-directory-contents-alist directory nl)
  1735. nl))
  1736. ))
  1737. (defun speedbar-directory-buttons (directory _index)
  1738. "Insert a single button group at point for DIRECTORY.
  1739. Each directory part is a different button. If part of the directory
  1740. matches the user directory ~, then it is replaced with a ~.
  1741. INDEX is not used, but is required by the caller."
  1742. (let* ((tilde (expand-file-name "~/"))
  1743. (dd (expand-file-name directory))
  1744. (junk (string-match (regexp-quote tilde) dd))
  1745. (displayme (if junk
  1746. (concat "~/" (substring dd (match-end 0)))
  1747. dd))
  1748. (p (point)))
  1749. (if (string-match "^~[/\\]?\\'" displayme) (setq displayme tilde))
  1750. (insert displayme)
  1751. (save-excursion
  1752. (goto-char p)
  1753. (while (re-search-forward "\\([^/\\]+\\)[/\\]" nil t)
  1754. (speedbar-make-button (match-beginning 1) (match-end 1)
  1755. 'speedbar-directory-face
  1756. 'speedbar-highlight-face
  1757. 'speedbar-directory-buttons-follow
  1758. (if (and (= (match-beginning 1) p)
  1759. (not (char-equal (char-after (+ p 1)) ?:)))
  1760. (expand-file-name "~/") ;the tilde
  1761. (buffer-substring-no-properties
  1762. p (match-end 0)))))
  1763. ;; Nuke the beginning of the directory if it's too long...
  1764. (cond ((eq speedbar-directory-button-trim-method 'span)
  1765. (beginning-of-line)
  1766. (let ((ww (or (speedbar-frame-width) 20)))
  1767. (move-to-column ww nil)
  1768. (while (>= (current-column) ww)
  1769. (re-search-backward "[/\\]" nil t)
  1770. (if (<= (current-column) 2)
  1771. (progn
  1772. (re-search-forward "[/\\]" nil t)
  1773. (if (< (current-column) 4)
  1774. (re-search-forward "[/\\]" nil t))
  1775. (forward-char -1)))
  1776. (if (looking-at "[/\\]?$")
  1777. (beginning-of-line)
  1778. (insert "/...\n ")
  1779. (move-to-column ww nil)))))
  1780. ((eq speedbar-directory-button-trim-method 'trim)
  1781. (end-of-line)
  1782. (let ((ww (or (speedbar-frame-width) 20))
  1783. (tl (current-column)))
  1784. (if (< ww tl)
  1785. (progn
  1786. (move-to-column (- tl ww))
  1787. (if (re-search-backward "[/\\]" nil t)
  1788. (progn
  1789. (delete-region (point-min) (point))
  1790. (insert "$")
  1791. )))))))
  1792. )
  1793. (if (string-match "\\`[/\\][^/\\]+[/\\]\\'" displayme)
  1794. (progn
  1795. (insert " ")
  1796. (let ((p (point)))
  1797. (insert "<root>")
  1798. (speedbar-make-button p (point)
  1799. 'speedbar-directory-face
  1800. 'speedbar-highlight-face
  1801. 'speedbar-directory-buttons-follow
  1802. "/"))))
  1803. (end-of-line)
  1804. (insert-char ?\n 1 nil)))
  1805. (defun speedbar-make-tag-line (exp-button-type
  1806. exp-button-char exp-button-function
  1807. exp-button-data
  1808. tag-button tag-button-function tag-button-data
  1809. tag-button-face depth)
  1810. "Create a tag line with EXP-BUTTON-TYPE for the small expansion button.
  1811. This is the button that expands or contracts a node (if applicable),
  1812. and EXP-BUTTON-CHAR the character in it (+, -, ?, etc). EXP-BUTTON-FUNCTION
  1813. is the function to call if it's clicked on. Button types are
  1814. 'bracket, 'angle, 'curly, 'expandtag, 'statictag, t, or nil.
  1815. EXP-BUTTON-DATA is extra data attached to the text forming the expansion
  1816. button.
  1817. Next, TAG-BUTTON is the text of the tag. TAG-BUTTON-FUNCTION is the
  1818. function to call if clicked on, and TAG-BUTTON-DATA is the data to
  1819. attach to the text field (such a tag positioning, etc).
  1820. TAG-BUTTON-FACE is a face used for this type of tag.
  1821. Lastly, DEPTH shows the depth of expansion.
  1822. This function assumes that the cursor is in the speedbar window at the
  1823. position to insert a new item, and that the new item will end with a CR."
  1824. (let ((start (point))
  1825. (end (progn
  1826. (insert (int-to-string depth) ":")
  1827. (point)))
  1828. (depthspacesize (* depth speedbar-indentation-width)))
  1829. (put-text-property start end 'invisible t)
  1830. (insert-char ? depthspacesize nil)
  1831. (put-text-property (- (point) depthspacesize) (point) 'invisible nil)
  1832. (let* ((exp-button (cond ((eq exp-button-type 'bracket) "[%c]")
  1833. ((eq exp-button-type 'angle) "<%c>")
  1834. ((eq exp-button-type 'curly) "{%c}")
  1835. ((eq exp-button-type 'expandtag) " %c>")
  1836. ((eq exp-button-type 'statictag) " =>")
  1837. (t ">")))
  1838. (buttxt (format exp-button exp-button-char))
  1839. (start (point))
  1840. (end (progn (insert buttxt) (point)))
  1841. (bf (if (and exp-button-type (not (eq exp-button-type 'statictag)))
  1842. 'speedbar-button-face nil))
  1843. (mf (if exp-button-function 'speedbar-highlight-face nil))
  1844. )
  1845. (speedbar-make-button start end bf mf exp-button-function exp-button-data)
  1846. (if speedbar-hide-button-brackets-flag
  1847. (progn
  1848. (put-text-property start (1+ start) 'invisible t)
  1849. (put-text-property end (1- end) 'invisible t)))
  1850. )
  1851. (insert-char ? 1 nil)
  1852. (put-text-property (1- (point)) (point) 'invisible nil)
  1853. (let ((start (point))
  1854. (end (progn (insert tag-button) (point))))
  1855. (insert-char ?\n 1 nil)
  1856. (put-text-property (1- (point)) (point) 'invisible nil)
  1857. (speedbar-make-button start end tag-button-face
  1858. (if tag-button-function 'speedbar-highlight-face nil)
  1859. tag-button-function tag-button-data))
  1860. ))
  1861. (defun speedbar-change-expand-button-char (char)
  1862. "Change the expansion button character to CHAR for the current line."
  1863. (save-excursion
  1864. (beginning-of-line)
  1865. (if (re-search-forward ":\\s-*.\\([-+?]\\)" (line-end-position) t)
  1866. (speedbar-with-writable
  1867. (goto-char (match-end 1))
  1868. (insert-char char 1 t)
  1869. (forward-char -1)
  1870. (delete-char -1)
  1871. ;;(put-text-property (point) (1- (point)) 'invisible nil)
  1872. ;; make sure we fix the image on the text here.
  1873. (speedbar-insert-image-button-maybe (- (point) 1) 3)))))
  1874. ;;; Build button lists
  1875. ;;
  1876. (defun speedbar-insert-files-at-point (files level)
  1877. "Insert list of FILES starting at point, and indenting all files to LEVEL.
  1878. Tag expandable items with a +, otherwise a ?. Don't highlight ? as we
  1879. don't know how to manage them. The input parameter FILES is a cons
  1880. cell of the form ( 'DIRLIST . 'FILELIST )."
  1881. ;; Start inserting all the directories
  1882. (let ((dirs (car files)))
  1883. (while dirs
  1884. (speedbar-make-tag-line 'angle ?+ 'speedbar-dired (car dirs)
  1885. (car dirs) 'speedbar-dir-follow nil
  1886. 'speedbar-directory-face level)
  1887. (setq dirs (cdr dirs))))
  1888. (let ((lst (car (cdr files)))
  1889. (case-fold-search t))
  1890. (while lst
  1891. (let* ((known (string-match speedbar-file-regexp (car lst)))
  1892. (expchar (if known ?+ ??))
  1893. (fn (if known 'speedbar-tag-file nil)))
  1894. (if (or speedbar-show-unknown-files (/= expchar ??))
  1895. (speedbar-make-tag-line 'bracket expchar fn (car lst)
  1896. (car lst) 'speedbar-find-file nil
  1897. 'speedbar-file-face level)))
  1898. (setq lst (cdr lst)))))
  1899. (defun speedbar-default-directory-list (directory index)
  1900. "Insert files for DIRECTORY with level INDEX at point."
  1901. (speedbar-insert-files-at-point
  1902. (speedbar-file-lists directory) index)
  1903. (speedbar-reset-scanners)
  1904. (if (= index 0)
  1905. ;; If the shown files variable has extra directories, then
  1906. ;; it is our responsibility to redraw them all
  1907. ;; Luckily, the nature of inserting items into this list means
  1908. ;; that by reversing it, we can easily go in the right order
  1909. (let ((sf (cdr (reverse speedbar-shown-directories))))
  1910. (setq speedbar-shown-directories
  1911. (list (expand-file-name default-directory)))
  1912. ;; Expand them all as we find them.
  1913. (while sf
  1914. (if (speedbar-goto-this-file (car sf))
  1915. (progn
  1916. (beginning-of-line)
  1917. (if (looking-at "[0-9]+:[ ]*<")
  1918. (progn
  1919. (goto-char (match-end 0))
  1920. (speedbar-do-function-pointer)))))
  1921. (setq sf (cdr sf)))
  1922. )))
  1923. ;;; Generic List support
  1924. ;;
  1925. ;; Generic lists are hierarchies of tags which we may need to permute
  1926. ;; in order to make it look nice.
  1927. ;;
  1928. ;; A generic list is of the form:
  1929. ;; ( ("name" . marker-or-number) <-- one tag at this level
  1930. ;; ("name" ("name" . mon) ("name" . mon) ) <-- one group of tags
  1931. ;; ("name" mon ("name" . mon) ) <-- group w/ a position and tags
  1932. (defun speedbar-generic-list-group-p (sublst)
  1933. "Non-nil if SUBLST is a group.
  1934. Groups may optionally contain a position."
  1935. (and (stringp (car-safe sublst))
  1936. (or (and (listp (cdr-safe sublst))
  1937. (or (speedbar-generic-list-tag-p (car-safe (cdr-safe sublst)))
  1938. (speedbar-generic-list-group-p (car-safe (cdr-safe sublst))
  1939. )))
  1940. (and (number-or-marker-p (car-safe (cdr-safe sublst)))
  1941. (listp (cdr-safe (cdr-safe sublst)))
  1942. (speedbar-generic-list-tag-p
  1943. (car-safe (cdr-safe (cdr-safe sublst)))))
  1944. )))
  1945. (defun speedbar-generic-list-positioned-group-p (sublst)
  1946. "Non-nil if SUBLST is a group with a position."
  1947. (and (stringp (car-safe sublst))
  1948. (number-or-marker-p (car-safe (cdr-safe sublst)))
  1949. (listp (cdr-safe (cdr-safe sublst)))
  1950. (let ((rest (car-safe (cdr-safe (cdr-safe sublst)))))
  1951. (or (speedbar-generic-list-tag-p rest)
  1952. (speedbar-generic-list-group-p rest)
  1953. (speedbar-generic-list-positioned-group-p rest)
  1954. ))))
  1955. (defun speedbar-generic-list-tag-p (sublst)
  1956. "Non-nil if SUBLST is a tag."
  1957. (and (stringp (car-safe sublst))
  1958. (or (and (number-or-marker-p (cdr-safe sublst))
  1959. (not (cdr-safe (cdr-safe sublst))))
  1960. ;; For semantic/bovine items, this is needed
  1961. (symbolp (car-safe (cdr-safe sublst))))
  1962. ))
  1963. (defun speedbar-sort-tag-hierarchy (lst)
  1964. "Sort all elements of tag hierarchy LST."
  1965. (sort (copy-alist lst)
  1966. (lambda (a b) (string< (car a) (car b)))))
  1967. (defun speedbar-try-completion (string alist)
  1968. "A wrapper for `try-completion'.
  1969. Passes STRING and ALIST to `try-completion' if ALIST
  1970. passes some tests."
  1971. (if (and (consp alist)
  1972. (listp (car alist)) (stringp (car (car alist))))
  1973. (try-completion string alist)
  1974. nil))
  1975. (defun speedbar-prefix-group-tag-hierarchy (lst)
  1976. "Prefix group names for tag hierarchy LST."
  1977. (let ((newlst nil)
  1978. (sublst nil)
  1979. (work-list nil)
  1980. (junk-list nil)
  1981. (short-group-list nil)
  1982. (short-start-name nil)
  1983. (short-end-name nil)
  1984. (num-shorts-grouped 0)
  1985. (bins (make-vector 256 nil))
  1986. (diff-idx 0))
  1987. (if (<= (length lst) speedbar-tag-regroup-maximum-length)
  1988. ;; Do nothing. Too short to bother with.
  1989. lst
  1990. ;; Break out sub-lists
  1991. (while lst
  1992. (if (speedbar-generic-list-group-p (car-safe lst))
  1993. (setq newlst (cons (car lst) newlst))
  1994. (setq sublst (cons (car lst) sublst)))
  1995. (setq lst (cdr lst)))
  1996. ;; Reverse newlst because it was made backwards.
  1997. ;; Sublist doesn't need reversing because the act
  1998. ;; of binning things will reverse it for us.
  1999. (setq newlst (nreverse newlst)
  2000. sublst sublst)
  2001. ;; Now, first find out how long our list is. Never let a
  2002. ;; list get-shorter than our minimum.
  2003. (if (<= (length sublst) speedbar-tag-split-minimum-length)
  2004. (setq work-list sublst)
  2005. (setq diff-idx (length (speedbar-try-completion "" sublst)))
  2006. ;; Sort the whole list into bins.
  2007. (while sublst
  2008. (let ((e (car sublst))
  2009. (s (car (car sublst))))
  2010. (cond ((<= (length s) diff-idx)
  2011. ;; 0 storage bin for shorty.
  2012. (aset bins 0 (cons e (aref bins 0))))
  2013. (t
  2014. ;; stuff into a bin based on ascii value at diff
  2015. (aset bins (aref s diff-idx)
  2016. (cons e (aref bins (aref s diff-idx)))))))
  2017. (setq sublst (cdr sublst)))
  2018. ;; Go through all our bins Stick singles into our
  2019. ;; junk-list, everything else as sublsts in work-list.
  2020. ;; If two neighboring lists are both small, make a grouped
  2021. ;; group combining those two sub-lists.
  2022. (setq diff-idx 0)
  2023. (while (> 256 diff-idx)
  2024. ;; The bins contents are currently in forward order.
  2025. (let ((l (aref bins diff-idx)))
  2026. (if l
  2027. (let ((tmp (cons (speedbar-try-completion "" l) l)))
  2028. (if (or (> (length l) speedbar-tag-regroup-maximum-length)
  2029. (> (+ (length l) (length short-group-list))
  2030. speedbar-tag-split-minimum-length))
  2031. (progn
  2032. ;; We have reached a longer list, so we
  2033. ;; must finish off a grouped group.
  2034. (cond
  2035. ((and short-group-list
  2036. (= (length short-group-list)
  2037. num-shorts-grouped))
  2038. ;; All singles? Junk list
  2039. (setq junk-list (append (nreverse short-group-list)
  2040. junk-list)))
  2041. ((= num-shorts-grouped 1)
  2042. ;; Only one short group? Just stick it in
  2043. ;; there by itself. Make a group, and find
  2044. ;; a subexpression
  2045. (let ((subexpression (speedbar-try-completion
  2046. "" short-group-list)))
  2047. (if (< (length subexpression)
  2048. speedbar-tag-group-name-minimum-length)
  2049. (setq subexpression
  2050. (concat short-start-name
  2051. " ("
  2052. (substring
  2053. (car (car short-group-list))
  2054. (length short-start-name))
  2055. ")")))
  2056. (setq work-list
  2057. (cons (cons subexpression
  2058. short-group-list)
  2059. work-list ))))
  2060. (short-group-list
  2061. ;; Multiple groups to be named in a special
  2062. ;; way by displaying the range over which we
  2063. ;; have grouped them.
  2064. (setq work-list
  2065. (cons (cons (concat short-start-name
  2066. " to "
  2067. short-end-name)
  2068. short-group-list)
  2069. work-list))))
  2070. ;; Reset short group list information every time.
  2071. (setq short-group-list nil
  2072. short-start-name nil
  2073. short-end-name nil
  2074. num-shorts-grouped 0)))
  2075. ;; Ok, now that we cleaned up the short-group-list,
  2076. ;; we can deal with this new list, to decide if it
  2077. ;; should go on one of these sub-lists or not.
  2078. (if (< (length l) speedbar-tag-regroup-maximum-length)
  2079. (setq short-group-list (append l short-group-list)
  2080. num-shorts-grouped (1+ num-shorts-grouped)
  2081. short-end-name (car tmp)
  2082. short-start-name (if short-start-name
  2083. short-start-name
  2084. (car tmp)))
  2085. (setq work-list (cons tmp work-list))))))
  2086. (setq diff-idx (1+ diff-idx))))
  2087. ;; Did we run out of things? Drop our new list onto the end.
  2088. (cond
  2089. ((and short-group-list (= (length short-group-list) num-shorts-grouped))
  2090. ;; All singles? Junk list
  2091. (setq junk-list (append short-group-list junk-list)))
  2092. ((= num-shorts-grouped 1)
  2093. ;; Only one short group? Just stick it in
  2094. ;; there by itself.
  2095. (setq work-list
  2096. (cons (cons (speedbar-try-completion "" short-group-list)
  2097. short-group-list)
  2098. work-list)))
  2099. (short-group-list
  2100. ;; Multiple groups to be named in a special
  2101. ;; way by displaying the range over which we
  2102. ;; have grouped them.
  2103. (setq work-list
  2104. (cons (cons (concat short-start-name " to " short-end-name)
  2105. short-group-list)
  2106. work-list))))
  2107. ;; Reverse the work list nreversed when consing.
  2108. (setq work-list (nreverse work-list))
  2109. ;; Now, stick our new list onto the end of
  2110. (if work-list
  2111. (if junk-list
  2112. (append newlst work-list junk-list)
  2113. (append newlst work-list))
  2114. (append newlst junk-list)))))
  2115. (defun speedbar-trim-words-tag-hierarchy (lst)
  2116. "Trim all words in a tag hierarchy.
  2117. Base trimming information on word separators, and group names.
  2118. Argument LST is the list of tags to trim."
  2119. (let ((newlst nil)
  2120. (sublst nil)
  2121. (trim-prefix nil)
  2122. (trim-chars 0)
  2123. (trimlst nil))
  2124. (while lst
  2125. (if (speedbar-generic-list-group-p (car-safe lst))
  2126. (setq newlst (cons (car lst) newlst))
  2127. (setq sublst (cons (car lst) sublst)))
  2128. (setq lst (cdr lst)))
  2129. ;; Get the prefix to trim by. Make sure that we don't trim
  2130. ;; off silly pieces, only complete understandable words.
  2131. (setq trim-prefix (speedbar-try-completion "" sublst)
  2132. newlst (nreverse newlst))
  2133. (if (or (= (length sublst) 1)
  2134. (not trim-prefix)
  2135. (not (string-match "\\(\\w+\\W+\\)+" trim-prefix)))
  2136. (append newlst (nreverse sublst))
  2137. (setq trim-prefix (substring trim-prefix (match-beginning 0)
  2138. (match-end 0)))
  2139. (setq trim-chars (length trim-prefix))
  2140. (while sublst
  2141. (setq trimlst (cons
  2142. (cons (substring (car (car sublst)) trim-chars)
  2143. (cdr (car sublst)))
  2144. trimlst)
  2145. sublst (cdr sublst)))
  2146. ;; Put the lists together
  2147. (append newlst trimlst))))
  2148. (defun speedbar-simple-group-tag-hierarchy (lst)
  2149. "Create a simple 'Tags' group with orphaned tags.
  2150. Argument LST is the list of tags to sort into groups."
  2151. (let ((newlst nil)
  2152. (sublst nil))
  2153. (while lst
  2154. (if (speedbar-generic-list-group-p (car-safe lst))
  2155. (setq newlst (cons (car lst) newlst))
  2156. (setq sublst (cons (car lst) sublst)))
  2157. (setq lst (cdr lst)))
  2158. (if (not newlst)
  2159. (nreverse sublst)
  2160. (setq newlst (cons (cons "Tags" (nreverse sublst)) newlst))
  2161. (nreverse newlst))))
  2162. (defun speedbar-create-tag-hierarchy (lst)
  2163. "Adjust the tag hierarchy in LST, and return it.
  2164. This uses `speedbar-tag-hierarchy-method' to determine how to adjust
  2165. the list."
  2166. (let* ((f (save-excursion
  2167. (forward-line -1)
  2168. (or (speedbar-line-file)
  2169. (speedbar-line-directory))))
  2170. (methods (if (get-file-buffer f)
  2171. (with-current-buffer (get-file-buffer f)
  2172. speedbar-tag-hierarchy-method)
  2173. speedbar-tag-hierarchy-method))
  2174. (lst (if (fboundp 'copy-tree)
  2175. (copy-tree lst)
  2176. lst)))
  2177. (while methods
  2178. (setq lst (funcall (car methods) lst)
  2179. methods (cdr methods)))
  2180. lst))
  2181. (defvar speedbar-generic-list-group-expand-button-type 'curly
  2182. "The type of button created for groups of tags.
  2183. Good values for this are `curly' and `expandtag'.
  2184. Make buffer local for your mode.")
  2185. (defvar speedbar-generic-list-tag-button-type nil
  2186. "The type of button created for tags in generic lists.
  2187. Good values for this are nil and `statictag'.
  2188. Make buffer local for your mode.")
  2189. (defun speedbar-insert-generic-list (level lst expand-fun find-fun)
  2190. "At LEVEL, insert a generic multi-level alist LST.
  2191. Associations with lists get {+} tags (to expand into more nodes) and
  2192. those with positions just get a > as the indicator. {+} buttons will
  2193. have the function EXPAND-FUN and the token is the cdr list. The token
  2194. name will have the function FIND-FUN and not token."
  2195. ;; Remove imenu rescan button
  2196. (if (string= (car (car lst)) "*Rescan*")
  2197. (setq lst (cdr lst)))
  2198. ;; Get, and set up variables that define how we treat these tags.
  2199. (let ((f (save-excursion (forward-line -1)
  2200. (or (speedbar-line-file)
  2201. (speedbar-line-directory))))
  2202. expand-button tag-button)
  2203. (save-excursion
  2204. (if (get-file-buffer f)
  2205. (set-buffer (get-file-buffer f)))
  2206. (setq expand-button speedbar-generic-list-group-expand-button-type
  2207. tag-button speedbar-generic-list-tag-button-type))
  2208. ;; Adjust the list.
  2209. (setq lst (speedbar-create-tag-hierarchy lst))
  2210. ;; insert the parts
  2211. (while lst
  2212. (cond ((null (car-safe lst)) nil) ;this would be a separator
  2213. ((speedbar-generic-list-tag-p (car lst))
  2214. (speedbar-make-tag-line tag-button
  2215. nil nil nil ;no expand button data
  2216. (car (car lst)) ;button name
  2217. find-fun ;function
  2218. (cdr (car lst)) ;token is position
  2219. 'speedbar-tag-face
  2220. (1+ level)))
  2221. ((speedbar-generic-list-positioned-group-p (car lst))
  2222. (speedbar-make-tag-line expand-button
  2223. ?+ expand-fun (cdr (cdr (car lst)))
  2224. (car (car lst)) ;button name
  2225. find-fun ;function
  2226. (car (cdr (car lst))) ;token is posn
  2227. 'speedbar-tag-face
  2228. (1+ level)))
  2229. ((speedbar-generic-list-group-p (car lst))
  2230. (speedbar-make-tag-line expand-button
  2231. ?+ expand-fun (cdr (car lst))
  2232. (car (car lst)) ;button name
  2233. nil nil 'speedbar-tag-face
  2234. (1+ level)))
  2235. (t (speedbar-message "speedbar-insert-generic-list: malformed list!")
  2236. ))
  2237. (setq lst (cdr lst)))))
  2238. (defun speedbar-insert-imenu-list (indent lst)
  2239. "At level INDENT, insert the imenu generated LST."
  2240. (speedbar-insert-generic-list indent lst
  2241. 'speedbar-tag-expand
  2242. 'speedbar-tag-find))
  2243. (defun speedbar-insert-etags-list (indent lst)
  2244. "At level INDENT, insert the etags generated LST."
  2245. (speedbar-insert-generic-list indent lst
  2246. 'speedbar-tag-expand
  2247. 'speedbar-tag-find))
  2248. ;;; Timed functions
  2249. ;;
  2250. (defun speedbar-update-contents ()
  2251. "Generically update the contents of the speedbar buffer."
  2252. (interactive)
  2253. ;; Set the current special buffer
  2254. (setq speedbar-desired-buffer nil)
  2255. ;; Check for special modes
  2256. (speedbar-maybe-add-localized-support (current-buffer))
  2257. ;; Choose the correct method of doodling.
  2258. (if (and speedbar-mode-specific-contents-flag
  2259. (consp speedbar-special-mode-expansion-list)
  2260. (local-variable-p
  2261. 'speedbar-special-mode-expansion-list
  2262. (current-buffer)))
  2263. ;;(eq (get major-mode 'mode-class 'special)))
  2264. (speedbar-update-special-contents)
  2265. (speedbar-update-directory-contents)))
  2266. (defun speedbar-update-localized-contents ()
  2267. "Update the contents of the speedbar buffer for the current situation."
  2268. ;; Due to the historical growth of speedbar, we need to do something
  2269. ;; special for "files" mode. Too bad.
  2270. (let ((name speedbar-initial-expansion-list-name)
  2271. (funclst (speedbar-initial-expansion-list))
  2272. )
  2273. (if (string= name "files")
  2274. ;; Do all the files type work. It still goes through the
  2275. ;; expansion list stuff. :(
  2276. (if (or (member (expand-file-name default-directory)
  2277. speedbar-shown-directories)
  2278. (and speedbar-ignored-directory-regexp
  2279. (string-match
  2280. speedbar-ignored-directory-regexp
  2281. (expand-file-name default-directory))))
  2282. nil
  2283. (if (<= 1 speedbar-verbosity-level)
  2284. (speedbar-message "Updating speedbar to: %s..."
  2285. default-directory))
  2286. (speedbar-update-directory-contents)
  2287. (if (<= 1 speedbar-verbosity-level)
  2288. (progn
  2289. (speedbar-message "Updating speedbar to: %s...done"
  2290. default-directory)
  2291. (speedbar-message nil))))
  2292. ;; Else, we can do a short cut. No text cache.
  2293. (let ((cbd (expand-file-name default-directory)))
  2294. (set-buffer speedbar-buffer)
  2295. (speedbar-with-writable
  2296. (let* ((window (get-buffer-window speedbar-buffer 0))
  2297. (p (window-point window))
  2298. (start (window-start window)))
  2299. (erase-buffer)
  2300. (dolist (func funclst)
  2301. (setq default-directory cbd)
  2302. (funcall func cbd 0))
  2303. (speedbar-reconfigure-keymaps)
  2304. (set-window-point window p)
  2305. (set-window-start window start)))))))
  2306. (defun speedbar-update-directory-contents ()
  2307. "Update the contents of the speedbar buffer based on the current directory."
  2308. (let ((cbd (expand-file-name default-directory))
  2309. cbd-parent
  2310. (funclst (speedbar-initial-expansion-list))
  2311. (cache speedbar-full-text-cache)
  2312. ;; disable stealth during update
  2313. (speedbar-stealthy-function-list nil)
  2314. (use-cache nil)
  2315. (expand-local nil)
  2316. ;; Because there is a bug I can't find just yet
  2317. (inhibit-quit nil))
  2318. (set-buffer speedbar-buffer)
  2319. ;; If we are updating contents to where we are, then this is
  2320. ;; really a request to update existing contents, so we must be
  2321. ;; careful with our text cache!
  2322. (if (member cbd speedbar-shown-directories)
  2323. (progn
  2324. (setq cache nil)
  2325. ;; If the current directory is not the last element in the dir
  2326. ;; list, then we ALSO need to zap the list of expanded directories
  2327. (if (/= (length (member cbd speedbar-shown-directories)) 1)
  2328. (setq speedbar-shown-directories (list cbd))))
  2329. ;; Build cbd-parent, and see if THAT is in the current shown
  2330. ;; directories. First, go through pains to get the parent directory
  2331. (if (and speedbar-smart-directory-expand-flag
  2332. (save-match-data
  2333. (setq cbd-parent cbd)
  2334. (if (string-match "[/\\]$" cbd-parent)
  2335. (setq cbd-parent (substring cbd-parent 0
  2336. (match-beginning 0))))
  2337. (setq cbd-parent (file-name-directory cbd-parent)))
  2338. (member cbd-parent speedbar-shown-directories))
  2339. (setq expand-local t)
  2340. ;; If this directory is NOT in the current list of available
  2341. ;; directories, then use the cache, and set the cache to our new
  2342. ;; value. Make sure to unhighlight the current file, or if we
  2343. ;; come back to this directory, it might be a different file
  2344. ;; and then we get a mess!
  2345. (if (> (point-max) 1)
  2346. (progn
  2347. (speedbar-clear-current-file)
  2348. (setq speedbar-full-text-cache
  2349. (cons speedbar-shown-directories (buffer-string)))))
  2350. ;; Check if our new directory is in the list of directories
  2351. ;; shown in the text-cache
  2352. (if (member cbd (car cache))
  2353. (setq speedbar-shown-directories (car cache)
  2354. use-cache t)
  2355. ;; default the shown directories to this list...
  2356. (setq speedbar-shown-directories (list cbd)))
  2357. ))
  2358. (if (not expand-local) (setq speedbar-last-selected-file nil))
  2359. (speedbar-with-writable
  2360. (if (and expand-local
  2361. ;; Find this directory as a speedbar node.
  2362. (speedbar-directory-line cbd))
  2363. ;; Open it.
  2364. (speedbar-expand-line)
  2365. (let* ((window (get-buffer-window speedbar-buffer 0))
  2366. (p (window-point window))
  2367. (start (window-start window)))
  2368. (erase-buffer)
  2369. (cond (use-cache
  2370. (setq default-directory
  2371. (nth (1- (length speedbar-shown-directories))
  2372. speedbar-shown-directories))
  2373. (insert (cdr cache)))
  2374. (t
  2375. (dolist (func funclst)
  2376. (setq default-directory cbd)
  2377. (funcall func cbd 0))))
  2378. (set-window-point window p)
  2379. (set-window-start window start)))))
  2380. (speedbar-reconfigure-keymaps))
  2381. (defun speedbar-update-special-contents ()
  2382. "Use the mode-specific variable to fill in the speedbar buffer.
  2383. This should only be used by modes classified as special."
  2384. (let ((funclst speedbar-special-mode-expansion-list)
  2385. (specialbuff (current-buffer)))
  2386. (setq speedbar-desired-buffer specialbuff)
  2387. (with-current-buffer speedbar-buffer
  2388. ;; If we are leaving a directory, cache it.
  2389. (if (not speedbar-shown-directories)
  2390. ;; Do nothing
  2391. nil
  2392. ;; Clean up directory maintenance stuff
  2393. (speedbar-clear-current-file)
  2394. (setq speedbar-full-text-cache
  2395. (cons speedbar-shown-directories (buffer-string))
  2396. speedbar-shown-directories nil))
  2397. ;; Now fill in the buffer with our newly found specialized list.
  2398. (speedbar-with-writable
  2399. (dolist (func funclst)
  2400. ;; We do not erase the buffer because these functions may
  2401. ;; decide NOT to update themselves.
  2402. (funcall func specialbuff)))))
  2403. (speedbar-reconfigure-keymaps))
  2404. (defun speedbar-set-timer (timeout)
  2405. "Set up the speedbar timer with TIMEOUT.
  2406. Uses `dframe-set-timer'.
  2407. Also resets scanner functions."
  2408. (dframe-set-timer timeout 'speedbar-timer-fn 'speedbar-update-flag)
  2409. ;; Apply a revert hook that will reset the scanners. We attach to revert
  2410. ;; because most reverts occur during VC state change, and this lets our
  2411. ;; VC scanner fix itself.
  2412. (if timeout
  2413. (add-hook 'after-revert-hook 'speedbar-reset-scanners)
  2414. (remove-hook 'after-revert-hook 'speedbar-reset-scanners))
  2415. ;; change this if it changed for some reason
  2416. (speedbar-set-mode-line-format))
  2417. (defun speedbar-timer-fn ()
  2418. "Run whenever Emacs is idle to update the speedbar item."
  2419. (if (or (not (speedbar-current-frame))
  2420. (not (frame-live-p (speedbar-current-frame))))
  2421. (speedbar-set-timer nil)
  2422. ;; Save all the match data so that we don't mess up executing fns
  2423. (save-match-data
  2424. ;; Only do stuff if the frame is visible, not an icon, and if
  2425. ;; it is currently flagged to do something.
  2426. (if (and speedbar-update-flag
  2427. (speedbar-current-frame)
  2428. (frame-visible-p (speedbar-current-frame))
  2429. (not (eq (frame-visible-p (speedbar-current-frame)) 'icon)))
  2430. (let ((af (selected-frame)))
  2431. (dframe-select-attached-frame speedbar-frame)
  2432. ;; make sure we at least choose a window to
  2433. ;; get a good directory from
  2434. (if (window-minibuffer-p (selected-window))
  2435. nil
  2436. ;; Check for special modes
  2437. (speedbar-maybe-add-localized-support (current-buffer))
  2438. ;; Update for special mode all the time!
  2439. (if (and speedbar-mode-specific-contents-flag
  2440. (consp speedbar-special-mode-expansion-list)
  2441. (local-variable-p
  2442. 'speedbar-special-mode-expansion-list
  2443. (current-buffer)))
  2444. ;;(eq (get major-mode 'mode-class 'special)))
  2445. (progn
  2446. (if (<= 2 speedbar-verbosity-level)
  2447. (speedbar-message
  2448. "Updating speedbar to special mode: %s..."
  2449. major-mode))
  2450. (speedbar-update-special-contents)
  2451. (if (<= 2 speedbar-verbosity-level)
  2452. (progn
  2453. (speedbar-message
  2454. "Updating speedbar to special mode: %s...done"
  2455. major-mode)
  2456. (speedbar-message nil))))
  2457. ;; Update all the contents if directories change!
  2458. (unless (and (or (member major-mode speedbar-ignored-modes)
  2459. (eq af (speedbar-current-frame))
  2460. (not (buffer-file-name)))
  2461. ;; Always update for GUD.
  2462. (not (string-equal "GUD"
  2463. speedbar-initial-expansion-list-name)))
  2464. (speedbar-update-localized-contents)))
  2465. (select-frame af))
  2466. ;; Now run stealthy updates of time-consuming items
  2467. (speedbar-stealthy-updates)))))
  2468. (run-hooks 'speedbar-timer-hook))
  2469. ;;; Stealthy activities
  2470. ;;
  2471. (defvar speedbar-stealthy-update-recurse nil
  2472. "Recursion avoidance variable for stealthy update.")
  2473. (defun speedbar-stealthy-updates ()
  2474. "For a given speedbar, run all items in the stealthy function list.
  2475. Each item returns t if it completes successfully, or nil if
  2476. interrupted by the user."
  2477. (if (not speedbar-stealthy-update-recurse)
  2478. (let ((l (speedbar-initial-stealthy-functions))
  2479. (speedbar-stealthy-update-recurse t))
  2480. (unwind-protect
  2481. (speedbar-with-writable
  2482. (while (and l (funcall (car l)))
  2483. ;;(sit-for 0)
  2484. (setq l (cdr l))))
  2485. ;;(speedbar-message "Exit with %S" (car l))
  2486. ))))
  2487. (defun speedbar-reset-scanners ()
  2488. "Reset any variables used by functions in the stealthy list as state.
  2489. If new functions are added, their state needs to be updated here."
  2490. (setq speedbar-vc-to-do-point t
  2491. speedbar-obj-to-do-point t
  2492. speedbar-ro-to-do-point t)
  2493. (run-hooks 'speedbar-scanner-reset-hook)
  2494. )
  2495. (defun speedbar-find-selected-file (file)
  2496. "Go to the line where FILE is."
  2497. (set-buffer speedbar-buffer)
  2498. (goto-char (point-min))
  2499. (let ((m nil))
  2500. (while (and (setq m (re-search-forward
  2501. (concat " \\(" (regexp-quote (file-name-nondirectory file))
  2502. "\\)\\(" speedbar-indicator-regex "\\)?\n")
  2503. nil t))
  2504. (not (string= file
  2505. (concat
  2506. (speedbar-line-directory
  2507. (save-excursion
  2508. (goto-char (match-beginning 0))
  2509. (beginning-of-line)
  2510. (save-match-data
  2511. (looking-at "[0-9]+:")
  2512. (string-to-number (match-string 0)))))
  2513. (match-string 1))))))
  2514. (if m
  2515. (progn
  2516. (goto-char (match-beginning 1))
  2517. (match-string 1)))))
  2518. (defun speedbar-clear-current-file ()
  2519. "Locate the file thought to be current, and remove its highlighting."
  2520. (save-excursion
  2521. ;;(set-buffer speedbar-buffer)
  2522. (if speedbar-last-selected-file
  2523. (speedbar-with-writable
  2524. (if (speedbar-find-selected-file speedbar-last-selected-file)
  2525. (put-text-property (match-beginning 1)
  2526. (match-end 1)
  2527. 'face
  2528. 'speedbar-file-face))))))
  2529. (defun speedbar-update-current-file ()
  2530. "Find the current file, and update our visuals to indicate its name.
  2531. This is specific to file names. If the file name doesn't show up, but
  2532. it should be in the list, then the directory cache needs to be updated."
  2533. (let* ((lastf (selected-frame))
  2534. (newcfd (save-excursion
  2535. (dframe-select-attached-frame speedbar-frame)
  2536. (let ((rf (if (buffer-file-name)
  2537. (buffer-file-name)
  2538. nil)))
  2539. (select-frame lastf)
  2540. rf)))
  2541. (newcf (if newcfd newcfd))
  2542. (lastb (current-buffer))
  2543. (sucf-recursive (boundp 'sucf-recursive))
  2544. (case-fold-search t))
  2545. (if (and newcf
  2546. ;; check here, that way we won't refresh to newcf until
  2547. ;; its been written, thus saving ourselves some time
  2548. (file-exists-p newcf)
  2549. (not (string= newcf speedbar-last-selected-file)))
  2550. (progn
  2551. ;; It is important to select the frame, otherwise the window
  2552. ;; we want the cursor to move in will not be updated by the
  2553. ;; search-forward command.
  2554. (select-frame (speedbar-current-frame))
  2555. ;; Remove the old file...
  2556. (speedbar-clear-current-file)
  2557. ;; now highlight the new one.
  2558. ;; (set-buffer speedbar-buffer)
  2559. (speedbar-with-writable
  2560. (if (speedbar-find-selected-file newcf)
  2561. ;; put the property on it
  2562. (put-text-property (match-beginning 1)
  2563. (match-end 1)
  2564. 'face
  2565. 'speedbar-selected-face)
  2566. ;; Oops, it's not in the list. Should it be?
  2567. (if (and (string-match speedbar-file-regexp newcf)
  2568. (string= (file-name-directory newcfd)
  2569. (expand-file-name default-directory)))
  2570. ;; yes, it is (we will ignore unknowns for now...)
  2571. (progn
  2572. (speedbar-refresh)
  2573. (if (speedbar-find-selected-file newcf)
  2574. ;; put the property on it
  2575. (put-text-property (match-beginning 1)
  2576. (match-end 1)
  2577. 'face
  2578. 'speedbar-selected-face)))
  2579. ;; if it's not in there now, whatever...
  2580. ))
  2581. (setq speedbar-last-selected-file newcf))
  2582. (if (not sucf-recursive)
  2583. (progn
  2584. ;;Sat Dec 15 2001 12:40 AM (burton@openprivacy.org): this
  2585. ;;doesn't need to be in. We don't want to recenter when we are
  2586. ;;updating files.
  2587. ;;(speedbar-center-buffer-smartly)
  2588. (speedbar-position-cursor-on-line)
  2589. ))
  2590. (set-buffer lastb)
  2591. (select-frame lastf)
  2592. )))
  2593. ;; return that we are done with this activity.
  2594. t)
  2595. (defun speedbar-add-indicator (indicator-string &optional replace-this)
  2596. "Add INDICATOR-STRING to the end of this speedbar line.
  2597. If INDICATOR-STRING is space, and REPLACE-THIS is a character,
  2598. then the existing indicator is removed. If there is already an
  2599. indicator, then do not add a space."
  2600. (beginning-of-line)
  2601. ;; The nature of the beast: Assume we are in "the right place"
  2602. (end-of-line)
  2603. (skip-chars-backward (concat " " speedbar-vc-indicator
  2604. speedbar-object-read-only-indicator
  2605. (car speedbar-obj-indicator)
  2606. (cdr speedbar-obj-indicator)))
  2607. (if (and (not (looking-at speedbar-indicator-regex))
  2608. (not (string= indicator-string " ")))
  2609. (insert speedbar-indicator-separator))
  2610. (speedbar-with-writable
  2611. (save-excursion
  2612. (if (and replace-this
  2613. (re-search-forward replace-this (line-end-position) t))
  2614. (delete-region (match-beginning 0) (match-end 0))))
  2615. (end-of-line)
  2616. (if (not (string= " " indicator-string))
  2617. (let ((start (point)))
  2618. (insert indicator-string)
  2619. (speedbar-insert-image-button-maybe start (length indicator-string))
  2620. ))))
  2621. (defun speedbar-check-read-only ()
  2622. "Scan all the files in a directory, and for each see if it is read only."
  2623. ;; Check for to-do to be reset. If reset but no RCS is available
  2624. ;; then set to nil (do nothing) otherwise, start at the beginning
  2625. (save-excursion
  2626. (if speedbar-buffer (set-buffer speedbar-buffer))
  2627. (if (eq speedbar-ro-to-do-point t)
  2628. (setq speedbar-ro-to-do-point 0))
  2629. (if (numberp speedbar-ro-to-do-point)
  2630. (progn
  2631. (goto-char speedbar-ro-to-do-point)
  2632. (while (and (not (input-pending-p))
  2633. (re-search-forward "^\\([0-9]+\\):\\s-*[[<][+-\?][]>] "
  2634. nil t))
  2635. (setq speedbar-ro-to-do-point (point))
  2636. (let ((f (speedbar-line-file)))
  2637. (if f
  2638. (if (not (file-writable-p f))
  2639. (speedbar-add-indicator
  2640. speedbar-object-read-only-indicator
  2641. (regexp-quote speedbar-object-read-only-indicator))
  2642. (speedbar-add-indicator
  2643. " " (regexp-quote
  2644. speedbar-object-read-only-indicator))))))
  2645. (if (input-pending-p)
  2646. ;; return that we are incomplete
  2647. nil
  2648. ;; we are done, set to-do to nil
  2649. (setq speedbar-ro-to-do-point nil)
  2650. ;; and return t
  2651. t))
  2652. t)))
  2653. (defun speedbar-check-vc ()
  2654. "Scan all files in a directory, and for each see if it's checked out.
  2655. See `speedbar-this-file-in-vc' and `speedbar-vc-check-dir-p' for how
  2656. to add more types of version control systems."
  2657. ;; Check for to-do to be reset. If reset but no RCS is available
  2658. ;; then set to nil (do nothing) otherwise, start at the beginning
  2659. (save-excursion
  2660. (if speedbar-buffer (set-buffer speedbar-buffer))
  2661. (if (and speedbar-vc-do-check (eq speedbar-vc-to-do-point t)
  2662. (speedbar-vc-check-dir-p default-directory)
  2663. (not (or (and (featurep 'ange-ftp)
  2664. (string-match
  2665. (car (symbol-value
  2666. (if (featurep 'xemacs)
  2667. 'ange-ftp-directory-format
  2668. 'ange-ftp-name-format)))
  2669. (expand-file-name default-directory)))
  2670. ;; efs support: Bob Weiner
  2671. (and (featurep 'efs)
  2672. (string-match
  2673. (let ((reg (symbol-value 'efs-directory-regexp)))
  2674. (if (stringp reg)
  2675. reg
  2676. (car reg)))
  2677. (expand-file-name default-directory))))))
  2678. (setq speedbar-vc-to-do-point 0))
  2679. (if (numberp speedbar-vc-to-do-point)
  2680. (progn
  2681. (goto-char speedbar-vc-to-do-point)
  2682. (while (and (not (input-pending-p))
  2683. (re-search-forward "^\\([0-9]+\\):\\s-*\\[[+-?]\\] "
  2684. nil t))
  2685. (setq speedbar-vc-to-do-point (point))
  2686. (if (speedbar-check-vc-this-line (match-string 1))
  2687. (speedbar-add-indicator speedbar-vc-indicator
  2688. (regexp-quote speedbar-vc-indicator))
  2689. (speedbar-add-indicator " "
  2690. (regexp-quote speedbar-vc-indicator))))
  2691. (if (input-pending-p)
  2692. ;; return that we are incomplete
  2693. nil
  2694. ;; we are done, set to-do to nil
  2695. (setq speedbar-vc-to-do-point nil)
  2696. ;; and return t
  2697. t))
  2698. t)))
  2699. (defun speedbar-check-vc-this-line (depth)
  2700. "Return t if the file on this line is checked out of a version control system.
  2701. Parameter DEPTH is a string with the current depth of indentation of
  2702. the file being checked."
  2703. (let* ((d (string-to-number depth))
  2704. (f (speedbar-line-directory d))
  2705. (fn (buffer-substring-no-properties
  2706. ;; Skip-chars: thanks ptype@dra.hmg.gb
  2707. (point) (progn
  2708. (skip-chars-forward "^ " (line-end-position))
  2709. (point))))
  2710. (fulln (concat f fn)))
  2711. (if (<= 2 speedbar-verbosity-level)
  2712. (speedbar-message "Speedbar vc check...%s" fulln))
  2713. (and (file-writable-p fulln)
  2714. (speedbar-this-file-in-vc f fn))))
  2715. (defun speedbar-vc-check-dir-p (directory)
  2716. "Return t if we should bother checking DIRECTORY for version control files.
  2717. This can be overloaded to add new types of version control systems."
  2718. (or
  2719. (catch t (dolist (vcd vc-directory-exclusion-list)
  2720. (if (file-exists-p (concat directory vcd)) (throw t t))) nil)
  2721. ;; User extension
  2722. (run-hook-with-args-until-success 'speedbar-vc-directory-enable-hook
  2723. directory)
  2724. ))
  2725. (defun speedbar-this-file-in-vc (directory name)
  2726. "Check to see if the file in DIRECTORY with NAME is in a version control system.
  2727. Automatically recognizes all VCs supported by VC mode. You can
  2728. optimize this function by overriding it and only doing those checks
  2729. that will occur on your system."
  2730. (or
  2731. (vc-backend (concat directory "/" name))
  2732. ;; User extension
  2733. (run-hook-with-args 'speedbar-vc-in-control-hook directory name)
  2734. ))
  2735. ;; Objet File scanning
  2736. (defun speedbar-check-objects ()
  2737. "Scan all files in a directory, and for each see if there is an object.
  2738. See `speedbar-check-obj-this-line' and `speedbar-obj-alist' for how
  2739. to add more object types."
  2740. ;; Check for to-do to be reset. If reset but no RCS is available
  2741. ;; then set to nil (do nothing) otherwise, start at the beginning
  2742. (save-excursion
  2743. (if speedbar-buffer (set-buffer speedbar-buffer))
  2744. (if (and speedbar-obj-do-check (eq speedbar-obj-to-do-point t))
  2745. (setq speedbar-obj-to-do-point 0))
  2746. (if (numberp speedbar-obj-to-do-point)
  2747. (progn
  2748. (goto-char speedbar-obj-to-do-point)
  2749. (while (and (not (input-pending-p))
  2750. (re-search-forward "^\\([0-9]+\\):\\s-*\\[[+-]\\] "
  2751. nil t))
  2752. (setq speedbar-obj-to-do-point (point))
  2753. (let ((ind (speedbar-check-obj-this-line (match-string 1))))
  2754. (if (not ind) (setq ind " "))
  2755. (speedbar-add-indicator ind (concat
  2756. (car speedbar-obj-indicator)
  2757. "\\|"
  2758. (cdr speedbar-obj-indicator)))))
  2759. (if (input-pending-p)
  2760. ;; return that we are incomplete
  2761. nil
  2762. ;; we are done, set to-do to nil
  2763. (setq speedbar-obj-to-do-point nil)
  2764. ;; and return t
  2765. t))
  2766. t)))
  2767. (defun speedbar-check-obj-this-line (depth)
  2768. "Return t if the file on this line has an associated object.
  2769. Parameter DEPTH is a string with the current depth of indentation of
  2770. the file being checked."
  2771. (let* ((d (string-to-number depth))
  2772. (f (speedbar-line-directory d))
  2773. (fn (buffer-substring-no-properties
  2774. ;; Skip-chars: thanks ptype@dra.hmg.gb
  2775. (point) (progn
  2776. (skip-chars-forward "^ " (line-end-position))
  2777. (point))))
  2778. (fulln (concat f fn)))
  2779. (if (<= 2 speedbar-verbosity-level)
  2780. (speedbar-message "Speedbar obj check...%s" fulln))
  2781. (let ((oa speedbar-obj-alist))
  2782. (while (and oa (not (string-match (car (car oa)) fulln)))
  2783. (setq oa (cdr oa)))
  2784. (if (not (and oa (file-exists-p (concat (file-name-sans-extension fulln)
  2785. (cdr (car oa))))))
  2786. nil
  2787. ;; Find out if the object is out of date or not.
  2788. (let ((date1 (nth 5 (file-attributes fulln)))
  2789. (date2 (nth 5 (file-attributes (concat
  2790. (file-name-sans-extension fulln)
  2791. (cdr (car oa)))))))
  2792. (if (or (< (car date1) (car date2))
  2793. (and (= (car date1) (car date2))
  2794. (< (nth 1 date1) (nth 1 date2))))
  2795. (car speedbar-obj-indicator)
  2796. (cdr speedbar-obj-indicator)))))))
  2797. ;;; Clicking Activity
  2798. ;;
  2799. (defun speedbar-position-cursor-on-line ()
  2800. "Position the cursor on a line."
  2801. (let ((oldpos (point)))
  2802. (beginning-of-line)
  2803. (if (looking-at "[0-9]+:\\s-*..?.? ")
  2804. (goto-char (1- (match-end 0)))
  2805. (goto-char oldpos))))
  2806. (defun speedbar-click (e)
  2807. "Activate any speedbar buttons where the mouse is clicked.
  2808. This must be bound to a mouse event. A button is any location of text
  2809. with a mouse face that has a text property called `speedbar-function'.
  2810. Argument E is the click event."
  2811. ;; Backward compatibility let statement.
  2812. (let ((speedbar-power-click dframe-power-click))
  2813. (speedbar-do-function-pointer))
  2814. (dframe-quick-mouse e))
  2815. (defun speedbar-do-function-pointer ()
  2816. "Look under the cursor and examine the text properties.
  2817. From this extract the file/tag name, token, indentation level and call
  2818. a function if appropriate."
  2819. (let* ((speedbar-frame (speedbar-current-frame))
  2820. (fn (get-text-property (point) 'speedbar-function))
  2821. (tok (get-text-property (point) 'speedbar-token))
  2822. ;; The 1-,+ is safe because scanning starts AFTER the point
  2823. ;; specified. This lets the search include the character the
  2824. ;; cursor is on.
  2825. (tp (previous-single-property-change
  2826. (1+ (point)) 'speedbar-function))
  2827. (np (next-single-property-change
  2828. (point) 'speedbar-function))
  2829. (txt (buffer-substring-no-properties (or tp (point-min))
  2830. (or np (point-max))))
  2831. (dent (save-excursion (beginning-of-line)
  2832. (string-to-number
  2833. (if (looking-at "[0-9]+")
  2834. (buffer-substring-no-properties
  2835. (match-beginning 0) (match-end 0))
  2836. "0")))))
  2837. ;;(speedbar-message "%S:%S:%S:%s" fn tok txt dent)
  2838. (and fn (funcall fn txt tok dent)))
  2839. (speedbar-position-cursor-on-line))
  2840. ;;; Reading info from the speedbar buffer
  2841. ;;
  2842. (defun speedbar-line-text (&optional p)
  2843. "Retrieve the text after prefix junk for the current line.
  2844. Optional argument P is where to start the search from."
  2845. (save-excursion
  2846. (if p (goto-char p))
  2847. (beginning-of-line)
  2848. (if (looking-at (concat
  2849. "\\([0-9]+\\): *[[<{]?[-+?= ][]>}@()|] \\([^ \n]+\\)"))
  2850. (get-text-property (match-beginning 2) 'speedbar-text)
  2851. nil)))
  2852. (defun speedbar-line-token (&optional p)
  2853. "Retrieve the token information after the prefix junk for the current line.
  2854. Optional argument P is where to start the search from."
  2855. (save-excursion
  2856. (if p (goto-char p))
  2857. (beginning-of-line)
  2858. (if (looking-at (concat
  2859. "\\([0-9]+\\): *[[<{]?[-+?= ][]>}@()|] \\([^ \n]+\\)\\("
  2860. speedbar-indicator-regex "\\)?"))
  2861. (progn
  2862. (goto-char (match-beginning 2))
  2863. (get-text-property (point) 'speedbar-token))
  2864. nil)))
  2865. (defun speedbar-line-file (&optional p)
  2866. "Retrieve the file or whatever from the line at point P.
  2867. The return value is a string representing the file. If it is a
  2868. directory, then it is the directory name."
  2869. (save-match-data
  2870. (save-restriction
  2871. (widen)
  2872. (let ((f (speedbar-line-text p)))
  2873. (if f
  2874. (let* ((depth (string-to-number (match-string 1)))
  2875. (directory (speedbar-line-directory depth)))
  2876. (if (file-exists-p (concat directory f))
  2877. (concat directory f)
  2878. nil))
  2879. nil)))))
  2880. (defun speedbar-goto-this-file (file)
  2881. "If FILE is displayed, go to this line and return t.
  2882. Otherwise do not move and return nil."
  2883. (let ((directory (substring (file-name-directory (expand-file-name file))
  2884. (length (expand-file-name default-directory))))
  2885. (dest (point)))
  2886. (save-match-data
  2887. (goto-char (point-min))
  2888. ;; scan all the directories
  2889. (while (and directory (not (eq directory t)))
  2890. (if (string-match "^[/\\]?\\([^/\\]+\\)" directory)
  2891. (let ((pp (match-string 1 directory)))
  2892. (if (save-match-data
  2893. (re-search-forward (concat "> " (regexp-quote pp) "$")
  2894. nil t))
  2895. (setq directory (substring directory (match-end 1)))
  2896. (setq directory nil)))
  2897. (setq directory t)))
  2898. ;; find the file part
  2899. (if (or (not directory) (string= (file-name-nondirectory file) ""))
  2900. ;; only had a dir part
  2901. (if directory
  2902. (progn
  2903. (speedbar-position-cursor-on-line)
  2904. t)
  2905. (goto-char dest) nil)
  2906. ;; find the file part
  2907. (let ((nd (file-name-nondirectory file)))
  2908. (if (re-search-forward
  2909. (concat "] \\(" (regexp-quote nd)
  2910. "\\)\\(" speedbar-indicator-regex "\\)$")
  2911. nil t)
  2912. (progn
  2913. (speedbar-position-cursor-on-line)
  2914. t)
  2915. (goto-char dest)
  2916. nil))))))
  2917. (defun speedbar-line-directory (&optional depth)
  2918. "Retrieve the directory name associated with the current line.
  2919. This may require traversing backwards from DEPTH and combining the default
  2920. directory with these items. This function is replaceable in
  2921. `speedbar-mode-functions-list' as `speedbar-line-directory'."
  2922. (save-restriction
  2923. (widen)
  2924. (let ((rf (speedbar-fetch-replacement-function 'speedbar-line-directory)))
  2925. (if rf (funcall rf depth) default-directory))))
  2926. (defun speedbar-files-line-directory (&optional depth)
  2927. "Retrieve the directory associated with the current line.
  2928. This may require traversing backwards from DEPTH and combining the default
  2929. directory with these items."
  2930. (save-excursion
  2931. (save-match-data
  2932. (if (not depth)
  2933. (progn
  2934. (beginning-of-line)
  2935. (looking-at "^\\([0-9]+\\):")
  2936. (setq depth (string-to-number (match-string 1)))))
  2937. (let ((directory nil))
  2938. (setq depth (1- depth))
  2939. (while (/= depth -1)
  2940. (if (not (re-search-backward (format "^%d:" depth) nil t))
  2941. (error "Error building filename of tag")
  2942. (cond ((looking-at "[0-9]+:\\s-*<->\\s-+\\([^\n]+\\)")
  2943. (setq directory (concat (speedbar-line-text)
  2944. "/"
  2945. directory)))
  2946. ((looking-at "[0-9]+:\\s-*[-]\\s-+\\([^\n]+\\)")
  2947. ;; This is the start of our directory.
  2948. (setq directory (speedbar-line-text)))))
  2949. (setq depth (1- depth)))
  2950. (if (and directory
  2951. (string-match (concat speedbar-indicator-regex "$")
  2952. directory))
  2953. (setq directory (substring directory 0 (match-beginning 0))))
  2954. (concat default-directory directory)))))
  2955. (defun speedbar-directory-line (directory)
  2956. "Position the cursor on the line specified by DIRECTORY."
  2957. (save-match-data
  2958. (if (string-match "[/\\]$" directory)
  2959. (setq directory (substring directory 0 (match-beginning 0))))
  2960. (let ((nomatch t) (depth 0)
  2961. (fname (file-name-nondirectory directory))
  2962. (pname (file-name-directory directory)))
  2963. (if (not (member pname speedbar-shown-directories))
  2964. (error "Internal Error: File %s not shown in speedbar" directory))
  2965. (goto-char (point-min))
  2966. (while (and nomatch
  2967. (re-search-forward
  2968. (concat "[]>] \\(" (regexp-quote fname)
  2969. "\\)\\(" speedbar-indicator-regex "\\)?$")
  2970. nil t))
  2971. (beginning-of-line)
  2972. (looking-at "\\([0-9]+\\):")
  2973. (setq depth (string-to-number (match-string 0))
  2974. nomatch (not (string= pname (speedbar-line-directory depth))))
  2975. (end-of-line))
  2976. (beginning-of-line)
  2977. (not nomatch))))
  2978. (defun speedbar-edit-line ()
  2979. "Edit whatever tag or file is on the current speedbar line."
  2980. (interactive)
  2981. (or (save-excursion
  2982. (beginning-of-line)
  2983. ;; If this fails, then it is a non-standard click, and as such,
  2984. ;; perfectly allowed.
  2985. (if (re-search-forward "[]>?}] [^ ]"
  2986. (line-end-position)
  2987. t)
  2988. (progn
  2989. (forward-char -1)
  2990. (speedbar-do-function-pointer))
  2991. nil))
  2992. (speedbar-do-function-pointer)))
  2993. (defun speedbar-expand-line (&optional arg)
  2994. "Expand the line under the cursor.
  2995. With universal argument ARG, flush cached data."
  2996. (interactive "P")
  2997. (beginning-of-line)
  2998. (let* ((dframe-power-click arg)
  2999. (speedbar-power-click arg))
  3000. (condition-case nil
  3001. (progn
  3002. (re-search-forward ":\\s-*.\\+. "
  3003. (line-end-position))
  3004. (forward-char -2)
  3005. (speedbar-do-function-pointer))
  3006. (error (speedbar-position-cursor-on-line)))))
  3007. (defun speedbar-flush-expand-line ()
  3008. "Expand the line under the cursor and flush any cached information."
  3009. (interactive)
  3010. (speedbar-expand-line 1))
  3011. (defun speedbar-contract-line ()
  3012. "Contract the line under the cursor."
  3013. (interactive)
  3014. (beginning-of-line)
  3015. (condition-case nil
  3016. (progn
  3017. (re-search-forward ":\\s-*.-. "
  3018. (line-end-position))
  3019. (forward-char -2)
  3020. (speedbar-do-function-pointer))
  3021. (error (speedbar-position-cursor-on-line))))
  3022. (defun speedbar-toggle-line-expansion ()
  3023. "Contract or expand the line under the cursor."
  3024. (interactive)
  3025. (beginning-of-line)
  3026. (condition-case nil
  3027. (progn
  3028. (re-search-forward ":\\s-*.[-+]. "
  3029. (line-end-position))
  3030. (forward-char -2)
  3031. (speedbar-do-function-pointer))
  3032. (error (speedbar-position-cursor-on-line))))
  3033. (defun speedbar-expand-line-descendants (&optional arg)
  3034. "Expand the line under the cursor and all descendants.
  3035. Optional argument ARG indicates that any cache should be flushed."
  3036. (interactive "P")
  3037. (speedbar-expand-line arg)
  3038. ;; Now, inside the area expanded here, expand all subnodes of
  3039. ;; the same descendant type.
  3040. (save-excursion
  3041. (speedbar-next 1) ;; Move into the list.
  3042. (let ((err nil))
  3043. (while (not err)
  3044. (condition-case nil
  3045. (progn
  3046. (speedbar-expand-line-descendants arg)
  3047. (speedbar-restricted-next 1))
  3048. (error (setq err t))))))
  3049. )
  3050. (defun speedbar-contract-line-descendants ()
  3051. "Expand the line under the cursor and all descendants."
  3052. (interactive)
  3053. (speedbar-contract-line)
  3054. ;; Don't need to do anything else since all descendants are
  3055. ;; hidden by default anyway. Yay! It's easy.
  3056. )
  3057. (defun speedbar-find-file (text _token indent)
  3058. "Speedbar click handler for filenames.
  3059. TEXT, the file will be displayed in the attached frame.
  3060. TOKEN is unused, but required by the click handler. INDENT is the
  3061. current indentation level."
  3062. (let ((cdd (speedbar-line-directory indent)))
  3063. ;; Run before visiting file hook here.
  3064. (let ((f (selected-frame)))
  3065. (dframe-select-attached-frame speedbar-frame)
  3066. (run-hooks 'speedbar-before-visiting-file-hook)
  3067. (select-frame f))
  3068. (speedbar-find-file-in-frame (concat cdd text))
  3069. (speedbar-stealthy-updates)
  3070. (run-hooks 'speedbar-visiting-file-hook)
  3071. ;; Reset the timer with a new timeout when clicking a file
  3072. ;; in case the user was navigating directories, we can cancel
  3073. ;; that other timer.
  3074. (speedbar-set-timer dframe-update-speed))
  3075. (dframe-maybee-jump-to-attached-frame))
  3076. (defun speedbar-dir-follow (text _token indent)
  3077. "Speedbar click handler for directory names.
  3078. Clicking a directory will cause the speedbar to list files in
  3079. the subdirectory TEXT. TOKEN is an unused requirement. The
  3080. subdirectory chosen will be at INDENT level."
  3081. (setq default-directory
  3082. (concat (expand-file-name (concat (speedbar-line-directory indent) text))
  3083. "/"))
  3084. ;; Because we leave speedbar as the current buffer,
  3085. ;; update contents will change directory without
  3086. ;; having to touch the attached frame. Turn off smart expand just
  3087. ;; in case.
  3088. (let ((speedbar-smart-directory-expand-flag nil))
  3089. (speedbar-update-contents))
  3090. (speedbar-set-timer speedbar-navigating-speed)
  3091. (setq speedbar-last-selected-file nil)
  3092. (speedbar-stealthy-updates))
  3093. (defun speedbar-delete-subblock (indent)
  3094. "Delete text from point to indentation level INDENT or greater.
  3095. Handles end-of-sublist smartly."
  3096. (speedbar-with-writable
  3097. (save-excursion
  3098. (end-of-line) (forward-char 1)
  3099. (let ((start (point)))
  3100. (while (and (looking-at "^\\([0-9]+\\):")
  3101. (> (string-to-number (match-string 1)) indent)
  3102. (not (eobp)))
  3103. (forward-line 1)
  3104. (beginning-of-line))
  3105. (delete-region start (point))))))
  3106. (defun speedbar-dired (text token indent)
  3107. "Speedbar click handler for directory expand button.
  3108. Clicking this button expands or contracts a directory. TEXT is the
  3109. button clicked which has either a + or -. TOKEN is the directory to be
  3110. expanded. INDENT is the current indentation level."
  3111. (cond ((string-match "+" text) ;we have to expand this dir
  3112. (setq speedbar-shown-directories
  3113. (cons (expand-file-name
  3114. (concat (speedbar-line-directory indent) token "/"))
  3115. speedbar-shown-directories))
  3116. (speedbar-change-expand-button-char ?-)
  3117. (speedbar-reset-scanners)
  3118. (save-excursion
  3119. (end-of-line) (forward-char 1)
  3120. (speedbar-with-writable
  3121. (speedbar-default-directory-list
  3122. (concat (speedbar-line-directory indent) token "/")
  3123. (1+ indent)))))
  3124. ((string-match "-" text) ;we have to contract this node
  3125. (speedbar-reset-scanners)
  3126. (let ((oldl speedbar-shown-directories)
  3127. (newl nil)
  3128. (td (expand-file-name
  3129. (concat (speedbar-line-directory indent) token))))
  3130. (while oldl
  3131. (if (not (string-match (concat "^" (regexp-quote td)) (car oldl)))
  3132. (setq newl (cons (car oldl) newl)))
  3133. (setq oldl (cdr oldl)))
  3134. (setq speedbar-shown-directories (nreverse newl)))
  3135. (speedbar-change-expand-button-char ?+)
  3136. (speedbar-delete-subblock indent)
  3137. )
  3138. (t (error "Ooops... not sure what to do")))
  3139. (speedbar-center-buffer-smartly)
  3140. (save-excursion (speedbar-stealthy-updates)))
  3141. (defun speedbar-directory-buttons-follow (_text token _indent)
  3142. "Speedbar click handler for default directory buttons.
  3143. TEXT is the button clicked on. TOKEN is the directory to follow.
  3144. INDENT is the current indentation level and is unused."
  3145. (if (string-match "^[A-z]:$" token)
  3146. (setq default-directory (concat token "/"))
  3147. (setq default-directory token))
  3148. ;; Because we leave speedbar as the current buffer,
  3149. ;; update contents will change directory without
  3150. ;; having to touch the attached frame.
  3151. (speedbar-update-contents)
  3152. (speedbar-set-timer speedbar-navigating-speed))
  3153. (defun speedbar-tag-file (text token indent)
  3154. "The cursor is on a selected line. Expand the tags in the specified file.
  3155. The parameter TEXT and TOKEN are required, where TEXT is the button
  3156. clicked, and TOKEN is the file to expand. INDENT is the current
  3157. indentation level."
  3158. (cond ((string-match "+" text) ;we have to expand this file
  3159. (let* ((fn (expand-file-name (concat (speedbar-line-directory indent)
  3160. token)))
  3161. (lst (speedbar-fetch-dynamic-tags fn)))
  3162. ;; if no list, then remove expando button
  3163. (if (not lst)
  3164. (speedbar-change-expand-button-char ??)
  3165. (speedbar-change-expand-button-char ?-)
  3166. (speedbar-with-writable
  3167. (save-excursion
  3168. (end-of-line) (forward-char 1)
  3169. (funcall (car lst) indent (cdr lst)))))))
  3170. ((string-match "-" text) ;we have to contract this node
  3171. (speedbar-change-expand-button-char ?+)
  3172. (speedbar-delete-subblock indent))
  3173. (t (error "Ooops... not sure what to do")))
  3174. (speedbar-center-buffer-smartly))
  3175. (defun speedbar-tag-find (_text token indent)
  3176. "For the tag TEXT in a file TOKEN, go to that position.
  3177. INDENT is the current indentation level."
  3178. (let ((file (speedbar-line-directory indent)))
  3179. (let ((f (selected-frame)))
  3180. (dframe-select-attached-frame speedbar-frame)
  3181. (run-hooks 'speedbar-before-visiting-tag-hook)
  3182. (select-frame f))
  3183. (speedbar-find-file-in-frame file)
  3184. (save-excursion (speedbar-stealthy-updates))
  3185. ;; Reset the timer with a new timeout when clicking a file
  3186. ;; in case the user was navigating directories, we can cancel
  3187. ;; that other timer.
  3188. (speedbar-set-timer dframe-update-speed)
  3189. (goto-char token)
  3190. (run-hooks 'speedbar-visiting-tag-hook)
  3191. (dframe-maybee-jump-to-attached-frame)
  3192. ))
  3193. (defun speedbar-tag-expand (text token indent)
  3194. "Expand a tag sublist. Imenu will return sub-lists of specialized tag types.
  3195. Etags does not support this feature. TEXT will be the button string.
  3196. TOKEN will be the list, and INDENT is the current indentation level."
  3197. (cond ((string-match "+" text) ;we have to expand this file
  3198. (speedbar-change-expand-button-char ?-)
  3199. (speedbar-with-writable
  3200. (save-excursion
  3201. (end-of-line) (forward-char 1)
  3202. (speedbar-insert-generic-list indent token 'speedbar-tag-expand
  3203. 'speedbar-tag-find))))
  3204. ((string-match "-" text) ;we have to contract this node
  3205. (speedbar-change-expand-button-char ?+)
  3206. (speedbar-delete-subblock indent))
  3207. (t (error "Ooops... not sure what to do")))
  3208. (speedbar-center-buffer-smartly))
  3209. ;;; Loading files into the attached frame.
  3210. ;;
  3211. (defcustom speedbar-select-frame-method 'attached
  3212. "Specify how to select a frame for displaying a file.
  3213. A value of 'attached means to use the attached frame (the frame
  3214. that speedbar was started from.) A number such as 1 or -1 means to
  3215. pass that number to `other-frame' while selecting a frame from speedbar."
  3216. :group 'speedbar
  3217. :type 'sexp)
  3218. (defun speedbar-find-file-in-frame (file)
  3219. "This will load FILE into the speedbar attached frame.
  3220. If the file is being displayed in a different frame already, then raise that
  3221. frame instead."
  3222. (let* ((buff (find-file-noselect file))
  3223. (bwin (get-buffer-window buff 0)))
  3224. (if bwin
  3225. (progn
  3226. (select-window bwin)
  3227. (raise-frame (window-frame bwin)))
  3228. (if dframe-power-click
  3229. (let ((pop-up-frames t)) (select-window (display-buffer buff)))
  3230. (if (numberp speedbar-select-frame-method)
  3231. (other-frame speedbar-select-frame-method)
  3232. (dframe-select-attached-frame speedbar-frame))
  3233. (switch-to-buffer buff))))
  3234. )
  3235. ;;; Centering Utility
  3236. ;;
  3237. (defun speedbar-center-buffer-smartly ()
  3238. "Recenter a speedbar buffer so the current indentation level is all visible.
  3239. This assumes that the cursor is on a file, or tag of a file which the user is
  3240. interested in."
  3241. (save-selected-window
  3242. (select-window (get-buffer-window speedbar-buffer t))
  3243. (set-buffer speedbar-buffer)
  3244. (if (<= (count-lines (point-min) (point-max))
  3245. (1- (window-height (selected-window))))
  3246. ;; whole buffer fits
  3247. (let ((cp (point)))
  3248. (goto-char (point-min))
  3249. (recenter 0)
  3250. (goto-char cp))
  3251. ;; too big
  3252. (let (depth start end exp p)
  3253. (save-excursion
  3254. (beginning-of-line)
  3255. (setq depth (if (looking-at "[0-9]+")
  3256. (string-to-number (buffer-substring-no-properties
  3257. (match-beginning 0) (match-end 0)))
  3258. 0))
  3259. (setq exp (format "^%d:" depth)))
  3260. (save-excursion
  3261. (end-of-line)
  3262. (if (re-search-backward exp nil t)
  3263. (setq start (point))
  3264. (setq start (point-min)))
  3265. (save-excursion ;Not sure about this part.
  3266. (end-of-line)
  3267. (setq p (point))
  3268. (while (and (not (re-search-forward exp nil t))
  3269. (>= depth 0))
  3270. (setq depth (1- depth))
  3271. (setq exp (format "^%d:" depth)))
  3272. (if (/= (point) p)
  3273. (setq end (point))
  3274. (setq end (point-max)))))
  3275. ;; Now work out the details of centering
  3276. (let ((nl (count-lines start end))
  3277. (wl (1- (window-height (selected-window))))
  3278. (cp (point)))
  3279. (if (> nl wl)
  3280. ;; We can't fit it all, so just center on cursor
  3281. (progn (goto-char start)
  3282. (recenter 1))
  3283. ;; we can fit everything on the screen, but...
  3284. (if (and (pos-visible-in-window-p start (selected-window))
  3285. (pos-visible-in-window-p end (selected-window)))
  3286. ;; we are all set!
  3287. nil
  3288. ;; we need to do something...
  3289. (goto-char start)
  3290. (let ((newcent (/ (- (window-height (selected-window)) nl) 2))
  3291. (lte (count-lines start (point-max))))
  3292. (if (and (< (+ newcent lte) (window-height (selected-window)))
  3293. (> (- (window-height (selected-window)) lte 1)
  3294. newcent))
  3295. (setq newcent (- (window-height (selected-window))
  3296. lte 1)))
  3297. (recenter newcent))))
  3298. (goto-char cp))))))
  3299. ;;; Tag Management -- List of expanders:
  3300. ;;
  3301. (defun speedbar-fetch-dynamic-tags (file)
  3302. "Return a list of tags generated dynamically from FILE.
  3303. This uses the entries in `speedbar-dynamic-tags-function-list'
  3304. to find the proper tags. It is up to each of those individual
  3305. functions to do caching and flushing if appropriate."
  3306. (save-excursion
  3307. ;; If a file is in memory, switch to that buffer. This allows
  3308. ;; us to use the local variable. If the file is on disk, we
  3309. ;; can try a few of the defaults that can get tags without
  3310. ;; opening the file.
  3311. (if (get-file-buffer file)
  3312. (set-buffer (get-file-buffer file)))
  3313. ;; If there is a buffer-local value of
  3314. ;; speedbar-dynamic-tags-function-list, it will now be available.
  3315. (let ((dtf speedbar-dynamic-tags-function-list)
  3316. (ret t))
  3317. (while (and (eq ret t) dtf)
  3318. (setq ret
  3319. (if (fboundp (car (car dtf)))
  3320. (funcall (car (car dtf)) file)
  3321. t))
  3322. (if (eq ret t)
  3323. (setq dtf (cdr dtf))))
  3324. (if (eq ret t)
  3325. ;; No valid tag list, return nil
  3326. nil
  3327. ;; We have some tags. Return the list with the insert fn
  3328. ;; prepended
  3329. (cons (cdr (car dtf)) ret)))))
  3330. ;;; Tag Management -- Imenu
  3331. ;;
  3332. (if (not speedbar-use-imenu-flag)
  3333. nil
  3334. (eval-when-compile (condition-case nil (require 'imenu) (error nil)))
  3335. (defun speedbar-fetch-dynamic-imenu (file)
  3336. "Load FILE into a buffer, and generate tags using Imenu.
  3337. Returns the tag list, or t for an error."
  3338. ;; Load this AND compile it in
  3339. (require 'imenu)
  3340. (set-buffer (find-file-noselect file))
  3341. (if dframe-power-click (setq imenu--index-alist nil))
  3342. (condition-case nil
  3343. (let ((index-alist (imenu--make-index-alist t)))
  3344. (if speedbar-sort-tags
  3345. (sort (copy-alist index-alist)
  3346. (lambda (a b) (string< (car a) (car b))))
  3347. index-alist))
  3348. (error t)))
  3349. )
  3350. ;;; Tag Management -- etags (old XEmacs compatibility part)
  3351. ;;
  3352. (defvar speedbar-fetch-etags-parse-list
  3353. '(;; Note that java has the same parse-group as c
  3354. ("\\.\\([cChH]\\|c\\+\\+\\|cpp\\|cc\\|hh\\|java\\|cxx\\|hxx\\)\\'" .
  3355. speedbar-parse-c-or-c++tag)
  3356. ("^\\.emacs$\\|.\\(el\\|l\\|lsp\\)\\'" .
  3357. "def[^i]+\\s-+\\(\\(\\w\\|[-_]\\)+\\)\\s-*\C-?")
  3358. ; ("\\.\\([fF]\\|for\\|FOR\\|77\\|90\\)\\'" .
  3359. ; speedbar-parse-fortran77-tag)
  3360. ("\\.tex\\'" . speedbar-parse-tex-string)
  3361. ("\\.p\\'" .
  3362. "\\(\\(FUNCTION\\|function\\|PROCEDURE\\|procedure\\)\\s-+\\([a-zA-Z0-9_.:]+\\)\\)\\s-*(?^?")
  3363. )
  3364. "Associations of file extensions and expressions for extracting tags.
  3365. To add a new file type, you would want to add a new association to the
  3366. list, where the car is the file match, and the cdr is the way to
  3367. extract an element from the tags output. If the output is complex,
  3368. use a function symbol instead of regexp. The function should expect
  3369. to be at the beginning of a line in the etags buffer.
  3370. This variable is ignored if `speedbar-use-imenu-flag' is non-nil.")
  3371. (defcustom speedbar-fetch-etags-command "etags"
  3372. "Command used to create an etags file.
  3373. This variable is ignored if `speedbar-use-imenu-flag' is t."
  3374. :group 'speedbar
  3375. :type 'string)
  3376. (defcustom speedbar-fetch-etags-arguments '("-D" "-I" "-o" "-")
  3377. "List of arguments to use with `speedbar-fetch-etags-command'.
  3378. This creates an etags output buffer. Use `speedbar-toggle-etags' to
  3379. modify this list conveniently.
  3380. This variable is ignored if `speedbar-use-imenu-flag' is t."
  3381. :group 'speedbar
  3382. :type '(choice (const nil)
  3383. (repeat :tag "List of arguments" string)))
  3384. (defun speedbar-toggle-etags (flag)
  3385. "Toggle FLAG in `speedbar-fetch-etags-arguments'.
  3386. FLAG then becomes a member of etags command line arguments. If flag
  3387. is \"sort\", then toggle the value of `speedbar-sort-tags'. If its
  3388. value is \"show\" then toggle the value of
  3389. `speedbar-show-unknown-files'.
  3390. This function is a convenience function for XEmacs menu created by
  3391. Farzin Guilak <farzin@protocol.com>."
  3392. (interactive)
  3393. (cond
  3394. ((equal flag "sort")
  3395. (setq speedbar-sort-tags (not speedbar-sort-tags)))
  3396. ((equal flag "show")
  3397. (setq speedbar-show-unknown-files (not speedbar-show-unknown-files)))
  3398. ((or (equal flag "-C")
  3399. (equal flag "-S")
  3400. (equal flag "-D"))
  3401. (if (member flag speedbar-fetch-etags-arguments)
  3402. (setq speedbar-fetch-etags-arguments
  3403. (delete flag speedbar-fetch-etags-arguments))
  3404. (add-to-list 'speedbar-fetch-etags-arguments flag)))
  3405. (t nil)))
  3406. (defun speedbar-fetch-dynamic-etags (file)
  3407. "For FILE, run etags and create a list of symbols extracted.
  3408. Each symbol will be associated with its line position in FILE."
  3409. (let ((newlist nil))
  3410. (unwind-protect
  3411. (save-excursion
  3412. (if (get-buffer "*etags tmp*")
  3413. (kill-buffer "*etags tmp*")) ;kill to clean it up
  3414. (if (<= 1 speedbar-verbosity-level)
  3415. (speedbar-message "Fetching etags..."))
  3416. (set-buffer (get-buffer-create "*etags tmp*"))
  3417. (apply 'call-process speedbar-fetch-etags-command nil
  3418. (current-buffer) nil
  3419. (append speedbar-fetch-etags-arguments (list file)))
  3420. (goto-char (point-min))
  3421. (if (<= 1 speedbar-verbosity-level)
  3422. (speedbar-message "Fetching etags..."))
  3423. (let ((expr
  3424. (let ((exprlst speedbar-fetch-etags-parse-list)
  3425. (ans nil))
  3426. (while (and (not ans) exprlst)
  3427. (if (string-match (car (car exprlst)) file)
  3428. (setq ans (car exprlst)))
  3429. (setq exprlst (cdr exprlst)))
  3430. (cdr ans))))
  3431. (if expr
  3432. (let (tnl)
  3433. (set-buffer (get-buffer-create "*etags tmp*"))
  3434. (while (not (save-excursion (end-of-line) (eobp)))
  3435. (save-excursion
  3436. (setq tnl (speedbar-extract-one-symbol expr)))
  3437. (if tnl (setq newlist (cons tnl newlist)))
  3438. (forward-line 1)))
  3439. (speedbar-message
  3440. "Sorry, no support for a file of that extension"))))
  3441. )
  3442. (if speedbar-sort-tags
  3443. (sort newlist (lambda (a b) (string< (car a) (car b))))
  3444. (reverse newlist))))
  3445. ;; This bit donated by Farzin Guilak <farzin@protocol.com> but I'm not
  3446. ;; sure it's needed with the different sorting method.
  3447. ;;
  3448. ;(defun speedbar-clean-etags()
  3449. ; "Removes spaces before the ^? character, and removes `#define',
  3450. ;return types, etc. preceding tags. This ensures that the sort operation
  3451. ;works on the tags, not the return types."
  3452. ; (save-excursion
  3453. ; (goto-char (point-min))
  3454. ; (while
  3455. ; (re-search-forward "(?[ \t](?\C-?" nil t)
  3456. ; (replace-match "\C-?" nil nil))
  3457. ; (goto-char (point-min))
  3458. ; (while
  3459. ; (re-search-forward "\\(.*[ \t]+\\)\\([^ \t\n]+.*\C-?\\)" nil t)
  3460. ; (delete-region (match-beginning 1) (match-end 1)))))
  3461. (defun speedbar-extract-one-symbol (expr)
  3462. "At point, return nil, or one alist in the form (SYMBOL . POSITION).
  3463. The line should contain output from etags. Parse the output using the
  3464. regular expression EXPR."
  3465. (let* ((sym (if (stringp expr)
  3466. (if (save-excursion
  3467. (re-search-forward expr (line-end-position) t))
  3468. (buffer-substring-no-properties (match-beginning 1)
  3469. (match-end 1)))
  3470. (funcall expr)))
  3471. (pos (let ((j (re-search-forward "[\C-?\C-a]\\([0-9]+\\),\\([0-9]+\\)"
  3472. (line-end-position) t)))
  3473. (if (and j sym)
  3474. (1+ (string-to-number (buffer-substring-no-properties
  3475. (match-beginning 2)
  3476. (match-end 2))))
  3477. 0))))
  3478. (if (/= pos 0)
  3479. (cons sym pos)
  3480. nil)))
  3481. (defun speedbar-parse-c-or-c++tag ()
  3482. "Parse a C or C++ tag, which tends to be a little complex."
  3483. (save-excursion
  3484. (let ((bound (line-end-position)))
  3485. (cond ((re-search-forward "\C-?\\([^\C-a]+\\)\C-a" bound t)
  3486. (buffer-substring-no-properties (match-beginning 1)
  3487. (match-end 1)))
  3488. ((re-search-forward "\\<\\([^ \t]+\\)\\s-+new(" bound t)
  3489. (buffer-substring-no-properties (match-beginning 1)
  3490. (match-end 1)))
  3491. ((re-search-forward "\\<\\([^ \t(]+\\)\\s-*(\C-?" bound t)
  3492. (buffer-substring-no-properties (match-beginning 1)
  3493. (match-end 1)))
  3494. (t nil))
  3495. )))
  3496. (defun speedbar-parse-tex-string ()
  3497. "Parse a Tex string. Only find data which is relevant."
  3498. (save-excursion
  3499. (let ((bound (line-end-position)))
  3500. (cond ((re-search-forward "\\(\\(sub\\)*section\\|chapter\\|cite\\)\\s-*{[^\C-?}]*}?" bound t)
  3501. (buffer-substring-no-properties (match-beginning 0)
  3502. (match-end 0)))
  3503. (t nil)))))
  3504. ;;; BUFFER DISPLAY mode.
  3505. ;;
  3506. (defvar speedbar-buffers-key-map nil
  3507. "Keymap used when in the buffers display mode.")
  3508. (if speedbar-buffers-key-map
  3509. nil
  3510. (setq speedbar-buffers-key-map (speedbar-make-specialized-keymap))
  3511. ;; Basic tree features
  3512. (define-key speedbar-buffers-key-map "e" 'speedbar-edit-line)
  3513. (define-key speedbar-buffers-key-map "\C-m" 'speedbar-edit-line)
  3514. (define-key speedbar-buffers-key-map "+" 'speedbar-expand-line)
  3515. (define-key speedbar-buffers-key-map "=" 'speedbar-expand-line)
  3516. (define-key speedbar-buffers-key-map "-" 'speedbar-contract-line)
  3517. (define-key speedbar-buffers-key-map " " 'speedbar-toggle-line-expansion)
  3518. ;; Buffer specific keybindings
  3519. (define-key speedbar-buffers-key-map "k" 'speedbar-buffer-kill-buffer)
  3520. (define-key speedbar-buffers-key-map "r" 'speedbar-buffer-revert-buffer)
  3521. )
  3522. (defvar speedbar-buffer-easymenu-definition
  3523. '(["Jump to buffer" speedbar-edit-line t]
  3524. ["Expand File Tags" speedbar-expand-line
  3525. (save-excursion (beginning-of-line)
  3526. (looking-at "[0-9]+: *.\\+. "))]
  3527. ["Flush Cache & Expand" speedbar-flush-expand-line
  3528. (save-excursion (beginning-of-line)
  3529. (looking-at "[0-9]+: *.\\+. "))]
  3530. ["Contract File Tags" speedbar-contract-line
  3531. (save-excursion (beginning-of-line)
  3532. (looking-at "[0-9]+: *.-. "))]
  3533. "----"
  3534. ["Kill Buffer" speedbar-buffer-kill-buffer
  3535. (save-excursion (beginning-of-line)
  3536. (looking-at "[0-9]+: *.[-+?]. "))]
  3537. ["Revert Buffer" speedbar-buffer-revert-buffer
  3538. (save-excursion (beginning-of-line)
  3539. (looking-at "[0-9]+: *.[-+?]. "))]
  3540. )
  3541. "Menu item elements shown when displaying a buffer list.")
  3542. (defun speedbar-buffer-buttons (_directory _zero)
  3543. "Create speedbar buttons based on the buffers currently loaded.
  3544. DIRECTORY is the directory of the currently active buffer, and ZERO is 0."
  3545. (speedbar-buffer-buttons-engine nil))
  3546. (defun speedbar-buffer-buttons-temp (_directory _zero)
  3547. "Create speedbar buttons based on the buffers currently loaded.
  3548. DIRECTORY is the directory of the currently active buffer, and ZERO is 0."
  3549. (speedbar-buffer-buttons-engine t))
  3550. (defun speedbar-buffer-buttons-engine (temp)
  3551. "Create speedbar buffer buttons.
  3552. If TEMP is non-nil, then clicking on a buffer restores the previous display."
  3553. (speedbar-insert-separator "Active Buffers:")
  3554. (let ((bl (buffer-list))
  3555. (case-fold-search t))
  3556. (while bl
  3557. (if (string-match "^[ *]" (buffer-name (car bl)))
  3558. nil
  3559. (let* ((known (string-match speedbar-file-regexp
  3560. (buffer-name (car bl))))
  3561. (expchar (if known ?+ ??))
  3562. (fn (if known 'speedbar-tag-file nil))
  3563. (fname (with-current-buffer (car bl)
  3564. (buffer-file-name))))
  3565. (speedbar-make-tag-line 'bracket expchar fn
  3566. (if fname (file-name-nondirectory fname))
  3567. (buffer-name (car bl))
  3568. 'speedbar-buffer-click temp
  3569. 'speedbar-file-face 0)
  3570. (speedbar-buffers-tail-notes (car bl))))
  3571. (setq bl (cdr bl)))
  3572. (setq bl (buffer-list))
  3573. (speedbar-insert-separator "Scratch Buffers:")
  3574. (while bl
  3575. (if (not (string-match "^\\*" (buffer-name (car bl))))
  3576. nil
  3577. (if (eq (car bl) speedbar-buffer)
  3578. nil
  3579. (speedbar-make-tag-line 'bracket ?? nil nil
  3580. (buffer-name (car bl))
  3581. 'speedbar-buffer-click temp
  3582. 'speedbar-file-face 0)
  3583. (speedbar-buffers-tail-notes (car bl))))
  3584. (setq bl (cdr bl)))
  3585. (setq bl (buffer-list))
  3586. ;;(speedbar-insert-separator "Hidden Buffers:")
  3587. ;;(while bl
  3588. ;; (if (not (string-match "^ " (buffer-name (car bl))))
  3589. ;; nil
  3590. ;; (if (eq (car bl) speedbar-buffer)
  3591. ;; nil
  3592. ;; (speedbar-make-tag-line 'bracket ?? nil nil
  3593. ;; (buffer-name (car bl))
  3594. ;; 'speedbar-buffer-click temp
  3595. ;; 'speedbar-file-face 0)
  3596. ;; (speedbar-buffers-tail-notes (car bl))))
  3597. ;; (setq bl (cdr bl)))
  3598. ))
  3599. (defun speedbar-buffers-tail-notes (buffer)
  3600. "Add a note to the end of the last tag line.
  3601. Argument BUFFER is the buffer being tested."
  3602. (when (with-current-buffer buffer buffer-read-only)
  3603. (speedbar-insert-button "%" nil nil nil nil t)))
  3604. (defun speedbar-buffers-item-info ()
  3605. "Display information about the current buffer on the current line."
  3606. (or (speedbar-item-info-tag-helper)
  3607. (let* ((item (speedbar-line-text))
  3608. (buffer (if item (get-buffer item) nil)))
  3609. (and buffer
  3610. (speedbar-message "%s%s %S %d %s"
  3611. (if (buffer-modified-p buffer) "* " "")
  3612. item
  3613. (with-current-buffer buffer major-mode)
  3614. (with-current-buffer buffer (buffer-size))
  3615. (or (buffer-file-name buffer) "<No file>"))))))
  3616. (defun speedbar-buffers-line-directory (&optional _depth)
  3617. "Fetch the directory of the file (buffer) specified on the current line.
  3618. Optional argument DEPTH specifies the current depth of the back search."
  3619. (save-excursion
  3620. (end-of-line)
  3621. (let ((start (point)))
  3622. ;; Buffers are always at level 0
  3623. (if (not (re-search-backward "^0:" nil t))
  3624. nil
  3625. (let* ((bn (speedbar-line-text))
  3626. (buffer (if bn (get-buffer bn))))
  3627. (if buffer
  3628. (if (eq start (line-end-position))
  3629. (or (with-current-buffer buffer default-directory)
  3630. "")
  3631. (buffer-file-name buffer))))))))
  3632. (defun speedbar-buffer-click (text token _indent)
  3633. "When the users clicks on a buffer-button in speedbar.
  3634. TEXT is the buffer's name, TOKEN and INDENT are unused."
  3635. (if dframe-power-click
  3636. (let ((pop-up-frames t)) (select-window (display-buffer text)))
  3637. (dframe-select-attached-frame speedbar-frame)
  3638. (switch-to-buffer text)
  3639. (if token (speedbar-change-initial-expansion-list
  3640. speedbar-previously-used-expansion-list-name))))
  3641. (defun speedbar-buffer-kill-buffer ()
  3642. "Kill the buffer the cursor is on in the speedbar buffer."
  3643. (interactive)
  3644. (or (save-excursion
  3645. (let ((text (speedbar-line-text)))
  3646. (if (and (get-buffer text)
  3647. (speedbar-y-or-n-p (format "Kill buffer %s? " text)))
  3648. (kill-buffer text))
  3649. (speedbar-refresh)))))
  3650. (defun speedbar-buffer-revert-buffer ()
  3651. "Revert the buffer the cursor is on in the speedbar buffer."
  3652. (interactive)
  3653. (save-excursion
  3654. (beginning-of-line)
  3655. ;; If this fails, then it is a non-standard click, and as such,
  3656. ;; perfectly allowed
  3657. (if (re-search-forward "[]>?}] [^ ]" (line-end-position) t)
  3658. (let ((text (progn
  3659. (forward-char -1)
  3660. (buffer-substring (point) (line-end-position)))))
  3661. (if (get-buffer text)
  3662. (progn
  3663. (set-buffer text)
  3664. (revert-buffer t)))))))
  3665. ;;; Useful hook values and such.
  3666. ;;
  3667. (defvar speedbar-highlight-one-tag-line nil
  3668. "Overlay used for highlighting the most recently jumped to tag line.")
  3669. (defun speedbar-highlight-one-tag-line ()
  3670. "Highlight the current line, unhighlighting a previously jumped to line."
  3671. (speedbar-unhighlight-one-tag-line)
  3672. (setq speedbar-highlight-one-tag-line
  3673. (speedbar-make-overlay (line-beginning-position)
  3674. (1+ (line-end-position))))
  3675. (speedbar-overlay-put speedbar-highlight-one-tag-line 'face
  3676. 'speedbar-highlight-face)
  3677. (add-hook 'pre-command-hook 'speedbar-unhighlight-one-tag-line))
  3678. (defun speedbar-unhighlight-one-tag-line ()
  3679. "Unhighlight the currently highlighted line."
  3680. (when (and speedbar-highlight-one-tag-line
  3681. (not (eq this-command 'handle-switch-frame)))
  3682. (speedbar-delete-overlay speedbar-highlight-one-tag-line)
  3683. (setq speedbar-highlight-one-tag-line nil)
  3684. (remove-hook 'pre-command-hook 'speedbar-unhighlight-one-tag-line)))
  3685. (defun speedbar-recenter-to-top ()
  3686. "Recenter the current buffer so point is on the top of the window."
  3687. (recenter 1))
  3688. (defun speedbar-recenter ()
  3689. "Recenter the current buffer so point is in the center of the window."
  3690. (recenter (/ (window-height (selected-window)) 2)))
  3691. ;;; Color loading section.
  3692. ;;
  3693. (defface speedbar-button-face '((((class color) (background light))
  3694. (:foreground "green4"))
  3695. (((class color) (background dark))
  3696. (:foreground "green3")))
  3697. "Face used for +/- buttons."
  3698. :group 'speedbar-faces)
  3699. (defface speedbar-file-face '((((class color) (background light))
  3700. (:foreground "cyan4"))
  3701. (((class color) (background dark))
  3702. (:foreground "cyan"))
  3703. (t (:bold t)))
  3704. "Face used for file names."
  3705. :group 'speedbar-faces)
  3706. (defface speedbar-directory-face '((((class color) (background light))
  3707. (:foreground "blue4"))
  3708. (((class color) (background dark))
  3709. (:foreground "light blue")))
  3710. "Face used for directory names."
  3711. :group 'speedbar-faces)
  3712. (defface speedbar-tag-face '((((class color) (background light))
  3713. (:foreground "brown"))
  3714. (((class color) (background dark))
  3715. (:foreground "yellow")))
  3716. "Face used for displaying tags."
  3717. :group 'speedbar-faces)
  3718. (defface speedbar-selected-face '((((class color) (background light))
  3719. (:foreground "red" :underline t))
  3720. (((class color) (background dark))
  3721. (:foreground "red" :underline t))
  3722. (t (:underline t)))
  3723. "Face used to underline the file in the active window."
  3724. :group 'speedbar-faces)
  3725. (defface speedbar-highlight-face '((((class color) (background light))
  3726. (:background "green"))
  3727. (((class color) (background dark))
  3728. (:background "sea green"))
  3729. (((class grayscale monochrome)
  3730. (background light))
  3731. (:background "black"))
  3732. (((class grayscale monochrome)
  3733. (background dark))
  3734. (:background "white")))
  3735. "Face used for highlighting buttons with the mouse."
  3736. :group 'speedbar-faces)
  3737. (defface speedbar-separator-face '((((class color) (background light))
  3738. (:background "blue"
  3739. :foreground "white"
  3740. :overline "gray"))
  3741. (((class color) (background dark))
  3742. (:background "blue"
  3743. :foreground "white"
  3744. :overline "gray"))
  3745. (((class grayscale monochrome)
  3746. (background light))
  3747. (:background "black"
  3748. :foreground "white"
  3749. :overline "white"))
  3750. (((class grayscale monochrome)
  3751. (background dark))
  3752. (:background "white"
  3753. :foreground "black"
  3754. :overline "black")))
  3755. "Face used for separator labels in a display."
  3756. :group 'speedbar-faces)
  3757. ;; some edebug hooks
  3758. (add-hook 'edebug-setup-hook
  3759. (lambda ()
  3760. (def-edebug-spec speedbar-with-writable def-body)))
  3761. ;; Fix a font lock problem for some versions of Emacs
  3762. (and (boundp 'font-lock-global-modes)
  3763. font-lock-global-modes
  3764. (if (eq font-lock-global-modes t)
  3765. (setq font-lock-global-modes '(not speedbar-mode))
  3766. (if (eq (car font-lock-global-modes) 'not)
  3767. (add-to-list 'font-lock-global-modes 'speedbar-mode t)
  3768. (setq font-lock-global-modes (delq 'speedbar-mode
  3769. font-lock-global-modes)))))
  3770. ;;; Obsolete variables and functions
  3771. (define-obsolete-variable-alias
  3772. 'speedbar-ignored-path-regexp 'speedbar-ignored-directory-regexp "22.1")
  3773. (define-obsolete-function-alias 'speedbar-add-ignored-path-regexp
  3774. 'speedbar-add-ignored-directory-regexp "22.1")
  3775. (define-obsolete-function-alias 'speedbar-line-path
  3776. 'speedbar-line-directory "22.1")
  3777. (define-obsolete-function-alias 'speedbar-buffers-line-path
  3778. 'speedbar-buffers-line-directory "22.1")
  3779. (define-obsolete-function-alias 'speedbar-path-line
  3780. 'speedbar-directory-line "22.1")
  3781. (define-obsolete-function-alias 'speedbar-buffers-line-path
  3782. 'speedbar-buffers-line-directory "22.1")
  3783. (provide 'speedbar)
  3784. ;; run load-time hooks
  3785. (run-hooks 'speedbar-load-hook)
  3786. ;;; speedbar ends here