dired.el 165 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247
  1. ;;; dired.el --- directory-browsing commands -*- lexical-binding: t -*-
  2. ;; Copyright (C) 1985-1986, 1992-1997, 2000-2012
  3. ;; Free Software Foundation, Inc.
  4. ;; Author: Sebastian Kremer <sk@thp.uni-koeln.de>
  5. ;; Maintainer: FSF
  6. ;; Keywords: files
  7. ;; Package: emacs
  8. ;; This file is part of GNU Emacs.
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;; Commentary:
  20. ;; This is a major mode for directory browsing and editing.
  21. ;; It is documented in the Emacs manual.
  22. ;; Rewritten in 1990/1991 to add tree features, file marking and
  23. ;; sorting by Sebastian Kremer <sk@thp.uni-koeln.de>.
  24. ;; Finished up by rms in 1992.
  25. ;;; Code:
  26. (eval-when-compile (require 'cl))
  27. ;;; Customizable variables
  28. (defgroup dired nil
  29. "Directory editing."
  30. :link '(custom-manual "(emacs)Dired")
  31. :group 'files)
  32. (defgroup dired-mark nil
  33. "Handling marks in Dired."
  34. :prefix "dired-"
  35. :group 'dired)
  36. ;;;###autoload
  37. (defcustom dired-listing-switches (purecopy "-al")
  38. "Switches passed to `ls' for Dired. MUST contain the `l' option.
  39. May contain all other options that don't contradict `-l';
  40. may contain even `F', `b', `i' and `s'. See also the variable
  41. `dired-ls-F-marks-symlinks' concerning the `F' switch.
  42. On systems such as MS-DOS and MS-Windows, which use `ls' emulation in Lisp,
  43. some of the `ls' switches are not supported; see the doc string of
  44. `insert-directory' in `ls-lisp.el' for more details."
  45. :type 'string
  46. :group 'dired)
  47. (defcustom dired-subdir-switches nil
  48. "If non-nil, switches passed to `ls' for inserting subdirectories.
  49. If nil, `dired-listing-switches' is used."
  50. :group 'dired
  51. :type '(choice (const :tag "Use dired-listing-switches" nil)
  52. (string :tag "Switches")))
  53. (defcustom dired-chown-program
  54. (purecopy (cond ((executable-find "chown") "chown")
  55. ((file-executable-p "/usr/sbin/chown") "/usr/sbin/chown")
  56. ((file-executable-p "/etc/chown") "/etc/chown")
  57. (t "chown")))
  58. "Name of chown command (usually `chown')."
  59. :group 'dired
  60. :type 'file)
  61. (defcustom dired-use-ls-dired 'unspecified
  62. "Non-nil means Dired should pass the \"--dired\" option to \"ls\".
  63. The special value of `unspecified' means to check explicitly, and
  64. save the result in this variable. This is performed the first
  65. time `dired-insert-directory' is called.
  66. Note that if you set this option to nil, either through choice or
  67. because your \"ls\" program does not support \"--dired\", Dired
  68. will fail to parse some \"unusual\" file names, e.g. those with leading
  69. spaces. You might want to install ls from GNU Coreutils, which does
  70. support this option. Alternatively, you might want to use Emacs's
  71. own emulation of \"ls\", by using:
  72. \(setq ls-lisp-use-insert-directory-program nil)
  73. \(require 'ls-lisp)
  74. This is used by default on MS Windows, which does not have an \"ls\" program.
  75. Note that `ls-lisp' does not support as many options as GNU ls, though.
  76. For more details, see Info node `(emacs)ls in Lisp'."
  77. :group 'dired
  78. :type '(choice (const :tag "Check for --dired support" unspecified)
  79. (const :tag "Do not use --dired" nil)
  80. (other :tag "Use --dired" t)))
  81. (defcustom dired-chmod-program "chmod"
  82. "Name of chmod command (usually `chmod')."
  83. :group 'dired
  84. :type 'file)
  85. (defcustom dired-touch-program "touch"
  86. "Name of touch command (usually `touch')."
  87. :group 'dired
  88. :type 'file)
  89. (defcustom dired-ls-F-marks-symlinks nil
  90. "Informs Dired about how `ls -lF' marks symbolic links.
  91. Set this to t if `ls' (or whatever program is specified by
  92. `insert-directory-program') with `-lF' marks the symbolic link
  93. itself with a trailing @ (usually the case under Ultrix).
  94. Example: if `ln -s foo bar; ls -F bar' gives `bar -> foo', set it to
  95. nil (the default), if it gives `bar@ -> foo', set it to t.
  96. Dired checks if there is really a @ appended. Thus, if you have a
  97. marking `ls' program on one host and a non-marking on another host, and
  98. don't care about symbolic links which really end in a @, you can
  99. always set this variable to t."
  100. :type 'boolean
  101. :group 'dired-mark)
  102. (defcustom dired-trivial-filenames (purecopy "^\\.\\.?$\\|^#")
  103. "Regexp of files to skip when finding first file of a directory.
  104. A value of nil means move to the subdir line.
  105. A value of t means move to first file."
  106. :type '(choice (const :tag "Move to subdir" nil)
  107. (const :tag "Move to first" t)
  108. regexp)
  109. :group 'dired)
  110. (defcustom dired-keep-marker-rename t
  111. ;; Use t as default so that moved files "take their markers with them".
  112. "Controls marking of renamed files.
  113. If t, files keep their previous marks when they are renamed.
  114. If a character, renamed files (whether previously marked or not)
  115. are afterward marked with that character."
  116. :type '(choice (const :tag "Keep" t)
  117. (character :tag "Mark"))
  118. :group 'dired-mark)
  119. (defcustom dired-keep-marker-copy ?C
  120. "Controls marking of copied files.
  121. If t, copied files are marked if and as the corresponding original files were.
  122. If a character, copied files are unconditionally marked with that character."
  123. :type '(choice (const :tag "Keep" t)
  124. (character :tag "Mark"))
  125. :group 'dired-mark)
  126. (defcustom dired-keep-marker-hardlink ?H
  127. "Controls marking of newly made hard links.
  128. If t, they are marked if and as the files linked to were marked.
  129. If a character, new links are unconditionally marked with that character."
  130. :type '(choice (const :tag "Keep" t)
  131. (character :tag "Mark"))
  132. :group 'dired-mark)
  133. (defcustom dired-keep-marker-symlink ?Y
  134. "Controls marking of newly made symbolic links.
  135. If t, they are marked if and as the files linked to were marked.
  136. If a character, new links are unconditionally marked with that character."
  137. :type '(choice (const :tag "Keep" t)
  138. (character :tag "Mark"))
  139. :group 'dired-mark)
  140. (defcustom dired-dwim-target nil
  141. "If non-nil, Dired tries to guess a default target directory.
  142. This means: if there is a dired buffer displayed in the next window,
  143. use its current subdir, instead of the current subdir of this dired buffer.
  144. The target is used in the prompt for file copy, rename etc."
  145. :type 'boolean
  146. :group 'dired)
  147. (defcustom dired-copy-preserve-time t
  148. "If non-nil, Dired preserves the last-modified time in a file copy.
  149. \(This works on only some systems.)"
  150. :type 'boolean
  151. :group 'dired)
  152. ; These variables were deleted and the replacements are on files.el.
  153. ; We leave aliases behind for back-compatibility.
  154. (defvaralias 'dired-free-space-program 'directory-free-space-program)
  155. (defvaralias 'dired-free-space-args 'directory-free-space-args)
  156. ;;; Hook variables
  157. (defcustom dired-load-hook nil
  158. "Run after loading Dired.
  159. You can customize key bindings or load extensions with this."
  160. :group 'dired
  161. :type 'hook)
  162. (defcustom dired-mode-hook nil
  163. "Run at the very end of `dired-mode'."
  164. :group 'dired
  165. :type 'hook)
  166. (defcustom dired-before-readin-hook nil
  167. "This hook is run before a dired buffer is read in (created or reverted)."
  168. :group 'dired
  169. :type 'hook)
  170. (defcustom dired-after-readin-hook nil
  171. "Hook run after each time a file or directory is read by Dired.
  172. After each listing of a file or directory, this hook is run
  173. with the buffer narrowed to the listing."
  174. :group 'dired
  175. :type 'hook)
  176. ;; Note this can't simply be run inside function `dired-ls' as the hook
  177. ;; functions probably depend on the dired-subdir-alist to be OK.
  178. (defcustom dired-dnd-protocol-alist
  179. '(("^file:///" . dired-dnd-handle-local-file)
  180. ("^file://" . dired-dnd-handle-file)
  181. ("^file:" . dired-dnd-handle-local-file))
  182. "The functions to call when a drop in `dired-mode' is made.
  183. See `dnd-protocol-alist' for more information. When nil, behave
  184. as in other buffers. Changing this option is effective only for
  185. new dired buffers."
  186. :type '(choice (repeat (cons (regexp) (function)))
  187. (const :tag "Behave as in other buffers" nil))
  188. :version "22.1"
  189. :group 'dired)
  190. ;; Internal variables
  191. (defvar dired-marker-char ?* ; the answer is 42
  192. ;; so that you can write things like
  193. ;; (let ((dired-marker-char ?X))
  194. ;; ;; great code using X markers ...
  195. ;; )
  196. ;; For example, commands operating on two sets of files, A and B.
  197. ;; Or marking files with digits 0-9. This could implicate
  198. ;; concentric sets or an order for the marked files.
  199. ;; The code depends on dynamic scoping on the marker char.
  200. "In Dired, the current mark character.
  201. This is what the do-commands look for, and what the mark-commands store.")
  202. (defvar dired-del-marker ?D
  203. "Character used to flag files for deletion.")
  204. (defvar dired-shrink-to-fit t
  205. ;; I see no reason ever to make this nil -- rms.
  206. ;; (> baud-rate search-slow-speed)
  207. "Non-nil means Dired shrinks the display buffer to fit the marked files.")
  208. (defvar dired-file-version-alist)
  209. ;;;###autoload
  210. (defvar dired-directory nil
  211. "The directory name or wildcard spec that this dired directory lists.
  212. Local to each dired buffer. May be a list, in which case the car is the
  213. directory name and the cdr is the list of files to mention.
  214. The directory name must be absolute, but need not be fully expanded.")
  215. ;; Beware of "-l;reboot" etc. See bug#3230.
  216. (defun dired-safe-switches-p (switches)
  217. "Return non-nil if string SWITCHES does not look risky for dired."
  218. (or (not switches)
  219. (and (stringp switches)
  220. (< (length switches) 100) ; arbitrary
  221. (string-match "\\` *-[- [:alnum:]]+\\'" switches))))
  222. (defvar dired-actual-switches nil
  223. "The value of `dired-listing-switches' used to make this buffer's text.")
  224. (put 'dired-actual-switches 'safe-local-variable 'dired-safe-switches-p)
  225. (defvar dired-re-inode-size "[0-9 \t]*"
  226. "Regexp for optional initial inode and file size as made by `ls -i -s'.")
  227. ;; These regexps must be tested at beginning-of-line, but are also
  228. ;; used to search for next matches, so neither omitting "^" nor
  229. ;; replacing "^" by "\n" (to make it slightly faster) will work.
  230. (defvar dired-re-mark "^[^ \n]")
  231. ;; "Regexp matching a marked line.
  232. ;; Important: the match ends just after the marker."
  233. (defvar dired-re-maybe-mark "^. ")
  234. ;; The [^:] part after "d" and "l" is to avoid confusion with the
  235. ;; DOS/Windows-style drive letters in directory names, like in "d:/foo".
  236. (defvar dired-re-dir (concat dired-re-maybe-mark dired-re-inode-size "d[^:]"))
  237. (defvar dired-re-sym (concat dired-re-maybe-mark dired-re-inode-size "l[^:]"))
  238. (defvar dired-re-exe;; match ls permission string of an executable file
  239. (mapconcat (function
  240. (lambda (x)
  241. (concat dired-re-maybe-mark dired-re-inode-size x)))
  242. '("-[-r][-w][xs][-r][-w].[-r][-w]."
  243. "-[-r][-w].[-r][-w][xs][-r][-w]."
  244. "-[-r][-w].[-r][-w].[-r][-w][xst]")
  245. "\\|"))
  246. (defvar dired-re-perms "[-bcdlps][-r][-w].[-r][-w].[-r][-w].")
  247. (defvar dired-re-dot "^.* \\.\\.?/?$")
  248. ;; The subdirectory names in the next two lists are expanded.
  249. (defvar dired-subdir-alist nil
  250. "Association list of subdirectories and their buffer positions.
  251. Each subdirectory has an element: (DIRNAME . STARTMARKER).
  252. The order of elements is the reverse of the order in the buffer.
  253. In simple cases, this list contains one element.")
  254. (defvar dired-switches-alist nil
  255. "Keeps track of which switches to use for inserted subdirectories.
  256. This is an alist of the form (SUBDIR . SWITCHES).")
  257. (make-variable-buffer-local 'dired-switches-alist)
  258. (defvaralias 'dired-move-to-filename-regexp
  259. 'directory-listing-before-filename-regexp)
  260. (defvar dired-subdir-regexp "^. \\([^\n\r]+\\)\\(:\\)[\n\r]"
  261. "Regexp matching a maybe hidden subdirectory line in `ls -lR' output.
  262. Subexpression 1 is the subdirectory proper, no trailing colon.
  263. The match starts at the beginning of the line and ends after the end
  264. of the line (\\n or \\r).
  265. Subexpression 2 must end right before the \\n or \\r.")
  266. (defgroup dired-faces nil
  267. "Faces used by Dired."
  268. :group 'dired
  269. :group 'faces)
  270. (defface dired-header
  271. '((t (:inherit font-lock-type-face)))
  272. "Face used for directory headers."
  273. :group 'dired-faces
  274. :version "22.1")
  275. (defvar dired-header-face 'dired-header
  276. "Face name used for directory headers.")
  277. (defface dired-mark
  278. '((t (:inherit font-lock-constant-face)))
  279. "Face used for dired marks."
  280. :group 'dired-faces
  281. :version "22.1")
  282. (defvar dired-mark-face 'dired-mark
  283. "Face name used for dired marks.")
  284. (defface dired-marked
  285. '((t (:inherit warning)))
  286. "Face used for marked files."
  287. :group 'dired-faces
  288. :version "22.1")
  289. (defvar dired-marked-face 'dired-marked
  290. "Face name used for marked files.")
  291. (defface dired-flagged
  292. '((t (:inherit error)))
  293. "Face used for files flagged for deletion."
  294. :group 'dired-faces
  295. :version "22.1")
  296. (defvar dired-flagged-face 'dired-flagged
  297. "Face name used for files flagged for deletion.")
  298. (defface dired-warning
  299. ;; Inherit from font-lock-warning-face since with min-colors 8
  300. ;; font-lock-comment-face is not colored any more.
  301. '((t (:inherit font-lock-warning-face)))
  302. "Face used to highlight a part of a buffer that needs user attention."
  303. :group 'dired-faces
  304. :version "22.1")
  305. (defvar dired-warning-face 'dired-warning
  306. "Face name used for a part of a buffer that needs user attention.")
  307. (defface dired-perm-write
  308. '((((type w32 pc)) :inherit default) ;; These default to rw-rw-rw.
  309. ;; Inherit from font-lock-comment-delimiter-face since with min-colors 8
  310. ;; font-lock-comment-face is not colored any more.
  311. (t (:inherit font-lock-comment-delimiter-face)))
  312. "Face used to highlight permissions of group- and world-writable files."
  313. :group 'dired-faces
  314. :version "22.2")
  315. (defvar dired-perm-write-face 'dired-perm-write
  316. "Face name used for permissions of group- and world-writable files.")
  317. (defface dired-directory
  318. '((t (:inherit font-lock-function-name-face)))
  319. "Face used for subdirectories."
  320. :group 'dired-faces
  321. :version "22.1")
  322. (defvar dired-directory-face 'dired-directory
  323. "Face name used for subdirectories.")
  324. (defface dired-symlink
  325. '((t (:inherit font-lock-keyword-face)))
  326. "Face used for symbolic links."
  327. :group 'dired-faces
  328. :version "22.1")
  329. (defvar dired-symlink-face 'dired-symlink
  330. "Face name used for symbolic links.")
  331. (defface dired-ignored
  332. '((t (:inherit shadow)))
  333. "Face used for files suffixed with `completion-ignored-extensions'."
  334. :group 'dired-faces
  335. :version "22.1")
  336. (defvar dired-ignored-face 'dired-ignored
  337. "Face name used for files suffixed with `completion-ignored-extensions'.")
  338. (defvar dired-font-lock-keywords
  339. (list
  340. ;;
  341. ;; Dired marks.
  342. (list dired-re-mark '(0 dired-mark-face))
  343. ;;
  344. ;; We make heavy use of MATCH-ANCHORED, since the regexps don't identify the
  345. ;; file name itself. We search for Dired defined regexps, and then use the
  346. ;; Dired defined function `dired-move-to-filename' before searching for the
  347. ;; simple regexp ".+". It is that regexp which matches the file name.
  348. ;;
  349. ;; Marked files.
  350. (list (concat "^[" (char-to-string dired-marker-char) "]")
  351. '(".+" (dired-move-to-filename) nil (0 dired-marked-face)))
  352. ;;
  353. ;; Flagged files.
  354. (list (concat "^[" (char-to-string dired-del-marker) "]")
  355. '(".+" (dired-move-to-filename) nil (0 dired-flagged-face)))
  356. ;; People who are paranoid about security would consider this more
  357. ;; important than other things such as whether it is a directory.
  358. ;; But we don't want to encourage paranoia, so our default
  359. ;; should be what's most useful for non-paranoids. -- rms.
  360. ;;; ;;
  361. ;;; ;; Files that are group or world writable.
  362. ;;; (list (concat dired-re-maybe-mark dired-re-inode-size
  363. ;;; "\\([-d]\\(....w....\\|.......w.\\)\\)")
  364. ;;; '(1 dired-warning-face)
  365. ;;; '(".+" (dired-move-to-filename) nil (0 dired-warning-face)))
  366. ;; However, we don't need to highlight the file name, only the
  367. ;; permissions, to win generally. -- fx.
  368. ;; Fixme: we could also put text properties on the permission
  369. ;; fields with keymaps to frob the permissions, somewhat a la XEmacs.
  370. (list (concat dired-re-maybe-mark dired-re-inode-size
  371. "[-d]....\\(w\\)....") ; group writable
  372. '(1 dired-perm-write-face))
  373. (list (concat dired-re-maybe-mark dired-re-inode-size
  374. "[-d].......\\(w\\).") ; world writable
  375. '(1 dired-perm-write-face))
  376. ;;
  377. ;; Subdirectories.
  378. (list dired-re-dir
  379. '(".+" (dired-move-to-filename) nil (0 dired-directory-face)))
  380. ;;
  381. ;; Symbolic links.
  382. (list dired-re-sym
  383. '(".+" (dired-move-to-filename) nil (0 dired-symlink-face)))
  384. ;;
  385. ;; Files suffixed with `completion-ignored-extensions'.
  386. '(eval .
  387. ;; It is quicker to first find just an extension, then go back to the
  388. ;; start of that file name. So we do this complex MATCH-ANCHORED form.
  389. (list (concat "\\(" (regexp-opt completion-ignored-extensions) "\\|#\\)$")
  390. '(".+" (dired-move-to-filename) nil (0 dired-ignored-face))))
  391. ;;
  392. ;; Files suffixed with `completion-ignored-extensions'
  393. ;; plus a character put in by -F.
  394. '(eval .
  395. (list (concat "\\(" (regexp-opt completion-ignored-extensions)
  396. "\\|#\\)[*=|]$")
  397. '(".+" (progn
  398. (end-of-line)
  399. ;; If the last character is not part of the filename,
  400. ;; move back to the start of the filename
  401. ;; so it can be fontified.
  402. ;; Otherwise, leave point at the end of the line;
  403. ;; that way, nothing is fontified.
  404. (unless (get-text-property (1- (point)) 'mouse-face)
  405. (dired-move-to-filename)))
  406. nil (0 dired-ignored-face))))
  407. ;;
  408. ;; Explicitly put the default face on file names ending in a colon to
  409. ;; avoid fontifying them as directory header.
  410. (list (concat dired-re-maybe-mark dired-re-inode-size dired-re-perms ".*:$")
  411. '(".+" (dired-move-to-filename) nil (0 'default)))
  412. ;;
  413. ;; Directory headers.
  414. (list dired-subdir-regexp '(1 dired-header-face))
  415. )
  416. "Additional expressions to highlight in Dired mode.")
  417. (defvar dnd-protocol-alist)
  418. ;;; Macros must be defined before they are used, for the byte compiler.
  419. (defmacro dired-mark-if (predicate msg)
  420. "Mark all files for which PREDICATE evals to non-nil.
  421. PREDICATE is evaluated on each line, with point at beginning of line.
  422. MSG is a noun phrase for the type of files being marked.
  423. It should end with a noun that can be pluralized by adding `s'.
  424. Return value is the number of files marked, or nil if none were marked."
  425. `(let ((inhibit-read-only t) count)
  426. (save-excursion
  427. (setq count 0)
  428. (when ,msg
  429. (message "%s %ss%s..."
  430. (cond ((eq dired-marker-char ?\040) "Unmarking")
  431. ((eq dired-del-marker dired-marker-char)
  432. "Flagging")
  433. (t "Marking"))
  434. ,msg
  435. (if (eq dired-del-marker dired-marker-char)
  436. " for deletion"
  437. "")))
  438. (goto-char (point-min))
  439. (while (not (eobp))
  440. (if ,predicate
  441. (progn
  442. (delete-char 1)
  443. (insert dired-marker-char)
  444. (setq count (1+ count))))
  445. (forward-line 1))
  446. (if ,msg (message "%s %s%s %s%s."
  447. count
  448. ,msg
  449. (dired-plural-s count)
  450. (if (eq dired-marker-char ?\040) "un" "")
  451. (if (eq dired-marker-char dired-del-marker)
  452. "flagged" "marked"))))
  453. (and (> count 0) count)))
  454. (defmacro dired-map-over-marks (body arg &optional show-progress
  455. distinguish-one-marked)
  456. "Eval BODY with point on each marked line. Return a list of BODY's results.
  457. If no marked file could be found, execute BODY on the current
  458. line. ARG, if non-nil, specifies the files to use instead of the
  459. marked files.
  460. If ARG is an integer, use the next ARG (or previous -ARG, if
  461. ARG<0) files. In that case, point is dragged along. This is so
  462. that commands on the next ARG (instead of the marked) files can
  463. be chained easily.
  464. For any other non-nil value of ARG, use the current file.
  465. If optional third arg SHOW-PROGRESS evaluates to non-nil,
  466. redisplay the dired buffer after each file is processed.
  467. No guarantee is made about the position on the marked line. BODY
  468. must ensure this itself if it depends on this.
  469. Search starts at the beginning of the buffer, thus the car of the
  470. list corresponds to the line nearest to the buffer's bottom.
  471. This is also true for (positive and negative) integer values of
  472. ARG.
  473. BODY should not be too long as it is expanded four times.
  474. If DISTINGUISH-ONE-MARKED is non-nil, then if we find just one
  475. marked file, return (t FILENAME) instead of (FILENAME)."
  476. ;;
  477. ;;Warning: BODY must not add new lines before point - this may cause an
  478. ;;endless loop.
  479. ;;This warning should not apply any longer, sk 2-Sep-1991 14:10.
  480. `(prog1
  481. (let ((inhibit-read-only t) case-fold-search found results)
  482. (if ,arg
  483. (if (integerp ,arg)
  484. (progn ;; no save-excursion, want to move point.
  485. (dired-repeat-over-lines
  486. ,arg
  487. (function (lambda ()
  488. (if ,show-progress (sit-for 0))
  489. (setq results (cons ,body results)))))
  490. (if (< ,arg 0)
  491. (nreverse results)
  492. results))
  493. ;; non-nil, non-integer ARG means use current file:
  494. (list ,body))
  495. (let ((regexp (dired-marker-regexp)) next-position)
  496. (save-excursion
  497. (goto-char (point-min))
  498. ;; remember position of next marked file before BODY
  499. ;; can insert lines before the just found file,
  500. ;; confusing us by finding the same marked file again
  501. ;; and again and...
  502. (setq next-position (and (re-search-forward regexp nil t)
  503. (point-marker))
  504. found (not (null next-position)))
  505. (while next-position
  506. (goto-char next-position)
  507. (if ,show-progress (sit-for 0))
  508. (setq results (cons ,body results))
  509. ;; move after last match
  510. (goto-char next-position)
  511. (forward-line 1)
  512. (set-marker next-position nil)
  513. (setq next-position (and (re-search-forward regexp nil t)
  514. (point-marker)))))
  515. (if (and ,distinguish-one-marked (= (length results) 1))
  516. (setq results (cons t results)))
  517. (if found
  518. results
  519. (list ,body)))))
  520. ;; save-excursion loses, again
  521. (dired-move-to-filename)))
  522. (defun dired-get-marked-files (&optional localp arg filter distinguish-one-marked)
  523. "Return the marked files' names as list of strings.
  524. The list is in the same order as the buffer, that is, the car is the
  525. first marked file.
  526. Values returned are normally absolute file names.
  527. Optional arg LOCALP as in `dired-get-filename'.
  528. Optional second argument ARG, if non-nil, specifies files near
  529. point instead of marked files. It usually comes from the prefix
  530. argument.
  531. If ARG is an integer, use the next ARG files.
  532. Any other non-nil value means to use the current file instead.
  533. Optional third argument FILTER, if non-nil, is a function to select
  534. some of the files--those for which (funcall FILTER FILENAME) is non-nil.
  535. If DISTINGUISH-ONE-MARKED is non-nil, then if we find just one marked file,
  536. return (t FILENAME) instead of (FILENAME).
  537. Don't use that together with FILTER."
  538. (let* ((all-of-them
  539. (save-excursion
  540. (dired-map-over-marks
  541. (dired-get-filename localp)
  542. arg nil distinguish-one-marked)))
  543. result)
  544. (if (not filter)
  545. (if (and distinguish-one-marked (eq (car all-of-them) t))
  546. all-of-them
  547. (nreverse all-of-them))
  548. (dolist (file all-of-them)
  549. (if (funcall filter file)
  550. (push file result)))
  551. result)))
  552. ;; The dired command
  553. (defun dired-read-dir-and-switches (str)
  554. ;; For use in interactive.
  555. (reverse (list
  556. (if current-prefix-arg
  557. (read-string "Dired listing switches: "
  558. dired-listing-switches))
  559. ;; If a dialog is used, call `read-directory-name' so the
  560. ;; dialog code knows we want directories. Some dialogs
  561. ;; can only select directories or files when popped up,
  562. ;; not both. If no dialog is used, call `read-file-name'
  563. ;; because the user may want completion of file names for
  564. ;; use in a wildcard pattern.
  565. (if (next-read-file-uses-dialog-p)
  566. (read-directory-name (format "Dired %s(directory): " str)
  567. nil default-directory nil)
  568. (read-file-name (format "Dired %s(directory): " str)
  569. nil default-directory nil)))))
  570. ;; We want to switch to a more sophisticated version of
  571. ;; dired-read-dir-and-switches like the following, if there is a way
  572. ;; to make it more intuitive. See bug#1285.
  573. ;; (defun dired-read-dir-and-switches (str)
  574. ;; ;; For use in interactive.
  575. ;; (reverse
  576. ;; (list
  577. ;; (if current-prefix-arg
  578. ;; (read-string "Dired listing switches: "
  579. ;; dired-listing-switches))
  580. ;; ;; If a dialog is about to be used, call read-directory-name so
  581. ;; ;; the dialog code knows we want directories. Some dialogs can
  582. ;; ;; only select directories or files when popped up, not both.
  583. ;; (if (next-read-file-uses-dialog-p)
  584. ;; (read-directory-name (format "Dired %s(directory): " str)
  585. ;; nil default-directory nil)
  586. ;; (let ((cie ()))
  587. ;; (dolist (ext completion-ignored-extensions)
  588. ;; (if (eq ?/ (aref ext (1- (length ext)))) (push ext cie)))
  589. ;; (setq cie (concat (regexp-opt cie "\\(?:") "\\'"))
  590. ;; (lexical-let* ((default (and buffer-file-name
  591. ;; (abbreviate-file-name buffer-file-name)))
  592. ;; (cie cie)
  593. ;; (completion-table
  594. ;; ;; We need a mix of read-file-name and
  595. ;; ;; read-directory-name so that completion to directories
  596. ;; ;; is preferred, but if the user wants to enter a global
  597. ;; ;; pattern, he can still use completion on filenames to
  598. ;; ;; help him write the pattern.
  599. ;; ;; Essentially, we want to use
  600. ;; ;; (completion-table-with-predicate
  601. ;; ;; 'read-file-name-internal 'file-directory-p nil)
  602. ;; ;; but that doesn't work because read-file-name-internal
  603. ;; ;; does not obey its `predicate' argument.
  604. ;; (completion-table-in-turn
  605. ;; (lambda (str pred action)
  606. ;; (let ((read-file-name-predicate
  607. ;; (lambda (f)
  608. ;; (and (not (member f '("./" "../")))
  609. ;; ;; Hack! Faster than file-directory-p!
  610. ;; (eq (aref f (1- (length f))) ?/)
  611. ;; (not (string-match cie f))))))
  612. ;; (complete-with-action
  613. ;; action 'read-file-name-internal str nil)))
  614. ;; 'read-file-name-internal)))
  615. ;; (minibuffer-with-setup-hook
  616. ;; (lambda ()
  617. ;; (setq minibuffer-default default)
  618. ;; (setq minibuffer-completion-table completion-table))
  619. ;; (read-file-name (format "Dired %s(directory): " str)
  620. ;; nil default-directory nil))))))))
  621. (defun dired-file-name-at-point ()
  622. "Try to get a file name at point in the current dired buffer.
  623. This hook is intended to be put in `file-name-at-point-functions'."
  624. (let ((filename (dired-get-filename nil t)))
  625. (when filename
  626. (if (file-directory-p filename)
  627. (file-name-as-directory (abbreviate-file-name filename))
  628. (abbreviate-file-name filename)))))
  629. ;;;###autoload (define-key ctl-x-map "d" 'dired)
  630. ;;;###autoload
  631. (defun dired (dirname &optional switches)
  632. "\"Edit\" directory DIRNAME--delete, rename, print, etc. some files in it.
  633. Optional second argument SWITCHES specifies the `ls' options used.
  634. \(Interactively, use a prefix argument to be able to specify SWITCHES.)
  635. Dired displays a list of files in DIRNAME (which may also have
  636. shell wildcards appended to select certain files). If DIRNAME is a cons,
  637. its first element is taken as the directory name and the rest as an explicit
  638. list of files to make directory entries for.
  639. \\<dired-mode-map>\
  640. You can flag files for deletion with \\[dired-flag-file-deletion] and then
  641. delete them by typing \\[dired-do-flagged-delete].
  642. Type \\[describe-mode] after entering Dired for more info.
  643. If DIRNAME is already in a dired buffer, that buffer is used without refresh."
  644. ;; Cannot use (interactive "D") because of wildcards.
  645. (interactive (dired-read-dir-and-switches ""))
  646. (switch-to-buffer (dired-noselect dirname switches)))
  647. ;;;###autoload (define-key ctl-x-4-map "d" 'dired-other-window)
  648. ;;;###autoload
  649. (defun dired-other-window (dirname &optional switches)
  650. "\"Edit\" directory DIRNAME. Like `dired' but selects in another window."
  651. (interactive (dired-read-dir-and-switches "in other window "))
  652. (switch-to-buffer-other-window (dired-noselect dirname switches)))
  653. ;;;###autoload (define-key ctl-x-5-map "d" 'dired-other-frame)
  654. ;;;###autoload
  655. (defun dired-other-frame (dirname &optional switches)
  656. "\"Edit\" directory DIRNAME. Like `dired' but makes a new frame."
  657. (interactive (dired-read-dir-and-switches "in other frame "))
  658. (switch-to-buffer-other-frame (dired-noselect dirname switches)))
  659. ;;;###autoload
  660. (defun dired-noselect (dir-or-list &optional switches)
  661. "Like `dired' but returns the dired buffer as value, does not select it."
  662. (or dir-or-list (setq dir-or-list default-directory))
  663. ;; This loses the distinction between "/foo/*/" and "/foo/*" that
  664. ;; some shells make:
  665. (let (dirname initially-was-dirname)
  666. (if (consp dir-or-list)
  667. (setq dirname (car dir-or-list))
  668. (setq dirname dir-or-list))
  669. (setq initially-was-dirname
  670. (string= (file-name-as-directory dirname) dirname))
  671. (setq dirname (abbreviate-file-name
  672. (expand-file-name (directory-file-name dirname))))
  673. (if find-file-visit-truename
  674. (setq dirname (file-truename dirname)))
  675. ;; If the argument was syntactically a directory name not a file name,
  676. ;; or if it happens to name a file that is a directory,
  677. ;; convert it syntactically to a directory name.
  678. ;; The reason for checking initially-was-dirname
  679. ;; and not just file-directory-p
  680. ;; is that file-directory-p is slow over ftp.
  681. (if (or initially-was-dirname (file-directory-p dirname))
  682. (setq dirname (file-name-as-directory dirname)))
  683. (if (consp dir-or-list)
  684. (setq dir-or-list (cons dirname (cdr dir-or-list)))
  685. (setq dir-or-list dirname))
  686. (dired-internal-noselect dir-or-list switches)))
  687. ;; The following is an internal dired function. It returns non-nil if
  688. ;; the directory visited by the current dired buffer has changed on
  689. ;; disk. DIRNAME should be the directory name of that directory.
  690. (defun dired-directory-changed-p (dirname)
  691. (not (let ((attributes (file-attributes dirname))
  692. (modtime (visited-file-modtime)))
  693. (or (eq modtime 0)
  694. (not (eq (car attributes) t))
  695. (equal (nth 5 attributes) modtime)))))
  696. (defun dired-buffer-stale-p (&optional noconfirm)
  697. "Return non-nil if current dired buffer needs updating.
  698. If NOCONFIRM is non-nil, then this function always returns nil
  699. for a remote directory. This feature is used by Auto Revert Mode."
  700. (let ((dirname
  701. (if (consp dired-directory) (car dired-directory) dired-directory)))
  702. (and (stringp dirname)
  703. (not (when noconfirm (file-remote-p dirname)))
  704. (file-readable-p dirname)
  705. ;; Do not auto-revert when the dired buffer can be currently
  706. ;; written by the user as in `wdired-mode'.
  707. buffer-read-only
  708. (dired-directory-changed-p dirname))))
  709. (defcustom dired-auto-revert-buffer nil
  710. "Automatically revert dired buffer on revisiting.
  711. If t, revisiting an existing dired buffer automatically reverts it.
  712. If its value is a function, call this function with the directory
  713. name as single argument and revert the buffer if it returns non-nil.
  714. Otherwise, a message offering to revert the changed dired buffer
  715. is displayed.
  716. Note that this is not the same as `auto-revert-mode' that
  717. periodically reverts at specified time intervals."
  718. :type '(choice
  719. (const :tag "Don't revert" nil)
  720. (const :tag "Always revert visited dired buffer" t)
  721. (const :tag "Revert changed dired buffer" dired-directory-changed-p)
  722. (function :tag "Predicate function"))
  723. :group 'dired
  724. :version "23.2")
  725. (defun dired-internal-noselect (dir-or-list &optional switches mode)
  726. ;; If there is an existing dired buffer for DIRNAME, just leave
  727. ;; buffer as it is (don't even call dired-revert).
  728. ;; This saves time especially for deep trees or with ange-ftp.
  729. ;; The user can type `g' easily, and it is more consistent with find-file.
  730. ;; But if SWITCHES are given they are probably different from the
  731. ;; buffer's old value, so call dired-sort-other, which does
  732. ;; revert the buffer.
  733. ;; A pity we can't possibly do "Directory has changed - refresh? "
  734. ;; like find-file does.
  735. ;; Optional argument MODE is passed to dired-find-buffer-nocreate,
  736. ;; see there.
  737. (let* ((old-buf (current-buffer))
  738. (dirname (if (consp dir-or-list) (car dir-or-list) dir-or-list))
  739. ;; Look for an existing buffer.
  740. (buffer (dired-find-buffer-nocreate dirname mode))
  741. ;; Note that buffer already is in dired-mode, if found.
  742. (new-buffer-p (null buffer)))
  743. (or buffer
  744. (setq buffer (create-file-buffer (directory-file-name dirname))))
  745. (set-buffer buffer)
  746. (if (not new-buffer-p) ; existing buffer ...
  747. (cond (switches ; ... but new switches
  748. ;; file list may have changed
  749. (setq dired-directory dir-or-list)
  750. ;; this calls dired-revert
  751. (dired-sort-other switches))
  752. ;; Always revert regardless of whether it has changed or not.
  753. ((eq dired-auto-revert-buffer t)
  754. (revert-buffer))
  755. ;; Revert when predicate function returns non-nil.
  756. ((functionp dired-auto-revert-buffer)
  757. (when (funcall dired-auto-revert-buffer dirname)
  758. (revert-buffer)
  759. (message "Changed directory automatically updated")))
  760. ;; If directory has changed on disk, offer to revert.
  761. ((when (dired-directory-changed-p dirname)
  762. (message "%s"
  763. (substitute-command-keys
  764. "Directory has changed on disk; type \\[revert-buffer] to update Dired")))))
  765. ;; Else a new buffer
  766. (setq default-directory
  767. ;; We can do this unconditionally
  768. ;; because dired-noselect ensures that the name
  769. ;; is passed in directory name syntax
  770. ;; if it was the name of a directory at all.
  771. (file-name-directory dirname))
  772. (or switches (setq switches dired-listing-switches))
  773. (if mode (funcall mode)
  774. (dired-mode dir-or-list switches))
  775. ;; default-directory and dired-actual-switches are set now
  776. ;; (buffer-local), so we can call dired-readin:
  777. (let ((failed t))
  778. (unwind-protect
  779. (progn (dired-readin)
  780. (setq failed nil))
  781. ;; dired-readin can fail if parent directories are inaccessible.
  782. ;; Don't leave an empty buffer around in that case.
  783. (if failed (kill-buffer buffer))))
  784. (goto-char (point-min))
  785. (dired-initial-position dirname))
  786. (set-buffer old-buf)
  787. buffer))
  788. (defvar dired-buffers nil
  789. ;; Enlarged by dired-advertise
  790. ;; Queried by function dired-buffers-for-dir. When this detects a
  791. ;; killed buffer, it is removed from this list.
  792. "Alist of expanded directories and their associated dired buffers.")
  793. (defvar dired-find-subdir)
  794. ;; FIXME add a doc-string, and document dired-x extensions.
  795. (defun dired-find-buffer-nocreate (dirname &optional mode)
  796. ;; This differs from dired-buffers-for-dir in that it does not consider
  797. ;; subdirs of default-directory and searches for the first match only.
  798. ;; Also, the major mode must be MODE.
  799. (if (and (featurep 'dired-x)
  800. dired-find-subdir
  801. ;; Don't try to find a wildcard as a subdirectory.
  802. (string-equal dirname (file-name-directory dirname)))
  803. (let* ((cur-buf (current-buffer))
  804. (buffers (nreverse
  805. (dired-buffers-for-dir (expand-file-name dirname))))
  806. (cur-buf-matches (and (memq cur-buf buffers)
  807. ;; Wildcards must match, too:
  808. (equal dired-directory dirname))))
  809. ;; We don't want to switch to the same buffer---
  810. (setq buffers (delq cur-buf buffers))
  811. (or (car (sort buffers #'dired-buffer-more-recently-used-p))
  812. ;; ---unless it's the only possibility:
  813. (and cur-buf-matches cur-buf)))
  814. ;; No dired-x, or dired-find-subdir nil.
  815. (setq dirname (expand-file-name dirname))
  816. (let (found (blist dired-buffers)) ; was (buffer-list)
  817. (or mode (setq mode 'dired-mode))
  818. (while blist
  819. (if (null (buffer-name (cdr (car blist))))
  820. (setq blist (cdr blist))
  821. (with-current-buffer (cdr (car blist))
  822. (if (and (eq major-mode mode)
  823. dired-directory ;; nil during find-alternate-file
  824. (equal dirname
  825. (expand-file-name
  826. (if (consp dired-directory)
  827. (car dired-directory)
  828. dired-directory))))
  829. (setq found (cdr (car blist))
  830. blist nil)
  831. (setq blist (cdr blist))))))
  832. found)))
  833. ;; Read in a new dired buffer
  834. (defun dired-readin ()
  835. "Read in a new dired buffer.
  836. Differs from `dired-insert-subdir' in that it accepts
  837. wildcards, erases the buffer, and builds the subdir-alist anew
  838. \(including making it buffer-local and clearing it first)."
  839. ;; default-directory and dired-actual-switches must be buffer-local
  840. ;; and initialized by now.
  841. (let (dirname
  842. ;; This makes readin much much faster.
  843. ;; In particular, it prevents the font lock hook from running
  844. ;; until the directory is all read in.
  845. (inhibit-modification-hooks t))
  846. (if (consp dired-directory)
  847. (setq dirname (car dired-directory))
  848. (setq dirname dired-directory))
  849. (setq dirname (expand-file-name dirname))
  850. (save-excursion
  851. ;; This hook which may want to modify dired-actual-switches
  852. ;; based on dired-directory, e.g. with ange-ftp to a SysV host
  853. ;; where ls won't understand -Al switches.
  854. (run-hooks 'dired-before-readin-hook)
  855. (if (consp buffer-undo-list)
  856. (setq buffer-undo-list nil))
  857. (make-local-variable 'file-name-coding-system)
  858. (setq file-name-coding-system
  859. (or coding-system-for-read file-name-coding-system))
  860. (let ((inhibit-read-only t)
  861. ;; Don't make undo entries for readin.
  862. (buffer-undo-list t))
  863. (widen)
  864. (erase-buffer)
  865. (dired-readin-insert))
  866. (goto-char (point-min))
  867. ;; Must first make alist buffer local and set it to nil because
  868. ;; dired-build-subdir-alist will call dired-clear-alist first
  869. (set (make-local-variable 'dired-subdir-alist) nil)
  870. (dired-build-subdir-alist)
  871. (let ((attributes (file-attributes dirname)))
  872. (if (eq (car attributes) t)
  873. (set-visited-file-modtime (nth 5 attributes))))
  874. (set-buffer-modified-p nil)
  875. ;; No need to narrow since the whole buffer contains just
  876. ;; dired-readin's output, nothing else. The hook can
  877. ;; successfully use dired functions (e.g. dired-get-filename)
  878. ;; as the subdir-alist has been built in dired-readin.
  879. (run-hooks 'dired-after-readin-hook))))
  880. ;; Subroutines of dired-readin
  881. (defun dired-readin-insert ()
  882. ;; Insert listing for the specified dir (and maybe file list)
  883. ;; already in dired-directory, assuming a clean buffer.
  884. (let (dir file-list)
  885. (if (consp dired-directory)
  886. (setq dir (car dired-directory)
  887. file-list (cdr dired-directory))
  888. (setq dir dired-directory
  889. file-list nil))
  890. (setq dir (expand-file-name dir))
  891. (if (and (equal "" (file-name-nondirectory dir))
  892. (not file-list))
  893. ;; If we are reading a whole single directory...
  894. (dired-insert-directory dir dired-actual-switches nil nil t)
  895. (if (not (file-readable-p
  896. (directory-file-name (file-name-directory dir))))
  897. (error "Directory %s inaccessible or nonexistent" dir)
  898. ;; Else treat it as a wildcard spec
  899. ;; unless we have an explicit list of files.
  900. (dired-insert-directory dir dired-actual-switches
  901. file-list (not file-list) t)))))
  902. (defun dired-align-file (beg end)
  903. "Align the fields of a file to the ones of surrounding lines.
  904. BEG..END is the line where the file info is located."
  905. ;; Some versions of ls try to adjust the size of each field so as to just
  906. ;; hold the largest element ("largest" in the current invocation, of
  907. ;; course). So when a single line is output, the size of each field is
  908. ;; just big enough for that one output. Thus when dired refreshes one
  909. ;; line, the alignment if this line w.r.t the rest is messed up because
  910. ;; the fields of that one line will generally be smaller.
  911. ;;
  912. ;; To work around this problem, we here add spaces to try and
  913. ;; re-align the fields as needed. Since this is purely aesthetic,
  914. ;; it is of utmost importance that it doesn't mess up anything like
  915. ;; `dired-move-to-filename'. To this end, we limit ourselves to
  916. ;; adding spaces only, and to only add them at places where there
  917. ;; was already at least one space. This way, as long as
  918. ;; `directory-listing-before-filename-regexp' always matches spaces
  919. ;; with "*" or "+", we know we haven't made anything worse. There
  920. ;; is one spot where the exact number of spaces is important, which
  921. ;; is just before the actual filename, so we refrain from adding
  922. ;; spaces there (and within the filename as well, of course).
  923. (save-excursion
  924. (let (file file-col other other-col)
  925. ;; Check that there is indeed a file, and that there is another adjacent
  926. ;; file with which to align, and that additional spaces are needed to
  927. ;; align the filenames.
  928. (when (and (setq file (progn (goto-char beg)
  929. (dired-move-to-filename nil end)))
  930. (setq file-col (current-column))
  931. (setq other
  932. (or (and (goto-char beg)
  933. (zerop (forward-line -1))
  934. (dired-move-to-filename))
  935. (and (goto-char beg)
  936. (zerop (forward-line 1))
  937. (dired-move-to-filename))))
  938. (setq other-col (current-column))
  939. (/= file other)
  940. ;; Make sure there is some work left to do.
  941. (> other-col file-col))
  942. ;; If we've only looked at the line above, check to see if the line
  943. ;; below exists as well and if so, align with the shorter one.
  944. (when (and (< other file)
  945. (goto-char beg)
  946. (zerop (forward-line 1))
  947. (dired-move-to-filename))
  948. (let ((alt-col (current-column)))
  949. (when (< alt-col other-col)
  950. (setq other-col alt-col)
  951. (setq other (point)))))
  952. ;; Keep positions uptodate when we insert stuff.
  953. (if (> other file) (setq other (copy-marker other)))
  954. (setq file (copy-marker file))
  955. ;; Main loop.
  956. (goto-char beg)
  957. (skip-chars-forward " ") ;Skip to the first field.
  958. (while (and (> other-col file-col)
  959. ;; Don't touch anything just before (and after) the
  960. ;; beginning of the filename.
  961. (> file (point)))
  962. ;; We're now just in front of a field, with a space behind us.
  963. (let* ((curcol (current-column))
  964. ;; Nums are right-aligned.
  965. (num-align (looking-at "[0-9]"))
  966. ;; Let's look at the other line, in the same column: we
  967. ;; should be either near the end of the previous field, or
  968. ;; in the space between that field and the next.
  969. ;; [ Of course, it's also possible that we're already within
  970. ;; the next field or even past it, but that's unlikely since
  971. ;; other-col > file-col. ]
  972. ;; Let's find the distance to the alignment-point (either
  973. ;; the beginning or the end of the next field, depending on
  974. ;; whether this field is left or right aligned).
  975. (align-pt-offset
  976. (save-excursion
  977. (goto-char other)
  978. (move-to-column curcol)
  979. (when (looking-at
  980. (concat
  981. (if (eq (char-before) ?\s) " *" "[^ ]* *")
  982. (if num-align "[0-9][^ ]*")))
  983. (- (match-end 0) (match-beginning 0)))))
  984. ;; Now, the number of spaces to insert is align-pt-offset
  985. ;; minus the distance to the equivalent point on the
  986. ;; current line.
  987. (spaces
  988. (if (not num-align)
  989. align-pt-offset
  990. (and align-pt-offset
  991. (save-excursion
  992. (skip-chars-forward "^ ")
  993. (- align-pt-offset (- (current-column) curcol)))))))
  994. (when (and spaces (> spaces 0))
  995. (setq file-col (+ spaces file-col))
  996. (if (> file-col other-col)
  997. (setq spaces (- spaces (- file-col other-col))))
  998. (insert-char ?\s spaces)
  999. ;; Let's just make really sure we did not mess up.
  1000. (unless (save-excursion
  1001. (eq (dired-move-to-filename) (marker-position file)))
  1002. ;; Damn! We messed up: let's revert the change.
  1003. (delete-char (- spaces)))))
  1004. ;; Now skip to next field.
  1005. (skip-chars-forward "^ ") (skip-chars-forward " "))
  1006. (set-marker file nil)))))
  1007. (defvar ls-lisp-use-insert-directory-program)
  1008. (defun dired-switches-escape-p (switches)
  1009. "Return non-nil if the string SWITCHES contains -b or --escape."
  1010. ;; Do not match things like "--block-size" that happen to contain "b".
  1011. (string-match "\\(\\`\\| \\)-[[:alnum:]]*b\\|--escape\\>" switches))
  1012. (defun dired-insert-directory (dir switches &optional file-list wildcard hdr)
  1013. "Insert a directory listing of DIR, Dired style.
  1014. Use SWITCHES to make the listings.
  1015. If FILE-LIST is non-nil, list only those files.
  1016. Otherwise, if WILDCARD is non-nil, expand wildcards;
  1017. in that case, DIR should be a file name that uses wildcards.
  1018. In other cases, DIR should be a directory name or a directory filename.
  1019. If HDR is non-nil, insert a header line with the directory name."
  1020. (let ((opoint (point))
  1021. (process-environment (copy-sequence process-environment))
  1022. end)
  1023. (if (and
  1024. ;; Don't try to invoke `ls' if we are on DOS/Windows where
  1025. ;; ls-lisp emulation is used, except if they want to use `ls'
  1026. ;; as indicated by `ls-lisp-use-insert-directory-program'.
  1027. (not (and (featurep 'ls-lisp)
  1028. (null ls-lisp-use-insert-directory-program)))
  1029. (or (if (eq dired-use-ls-dired 'unspecified)
  1030. ;; Check whether "ls --dired" gives exit code 0, and
  1031. ;; save the answer in `dired-use-ls-dired'.
  1032. (or (setq dired-use-ls-dired
  1033. (eq 0 (call-process insert-directory-program
  1034. nil nil nil "--dired")))
  1035. (progn
  1036. (message "ls does not support --dired; \
  1037. see `dired-use-ls-dired' for more details.")
  1038. nil))
  1039. dired-use-ls-dired)
  1040. (file-remote-p dir)))
  1041. (setq switches (concat "--dired " switches)))
  1042. ;; We used to specify the C locale here, to force English month names;
  1043. ;; but this should not be necessary any more,
  1044. ;; with the new value of `directory-listing-before-filename-regexp'.
  1045. (if file-list
  1046. (dolist (f file-list)
  1047. (let ((beg (point)))
  1048. (insert-directory f switches nil nil)
  1049. ;; Re-align fields, if necessary.
  1050. (dired-align-file beg (point))))
  1051. (insert-directory dir switches wildcard (not wildcard)))
  1052. ;; Quote certain characters, unless ls quoted them for us.
  1053. (if (not (dired-switches-escape-p dired-actual-switches))
  1054. (save-excursion
  1055. (setq end (point-marker))
  1056. (goto-char opoint)
  1057. (while (search-forward "\\" end t)
  1058. (replace-match (apply #'propertize
  1059. "\\\\"
  1060. (text-properties-at (match-beginning 0)))
  1061. nil t))
  1062. (goto-char opoint)
  1063. (while (search-forward "\^m" end t)
  1064. (replace-match (apply #'propertize
  1065. "\\015"
  1066. (text-properties-at (match-beginning 0)))
  1067. nil t))
  1068. (set-marker end nil))
  1069. ;; Replace any newlines in DIR with literal "\n"s, for the sake
  1070. ;; of the header line. To disambiguate a literal "\n" in the
  1071. ;; actual dirname, we also replace "\" with "\\".
  1072. ;; Personally, I think this should always be done, irrespective
  1073. ;; of the value of dired-actual-switches, because:
  1074. ;; i) Dired simply does not work with an unescaped newline in
  1075. ;; the directory name used in the header (bug=10469#28), and
  1076. ;; ii) "\" is always replaced with "\\" in the listing, so doing
  1077. ;; it in the header as well makes things consistent.
  1078. ;; But at present it is only done if "-b" is in ls-switches,
  1079. ;; because newlines in dirnames are uncommon, and people may
  1080. ;; have gotten used to seeing unescaped "\" in the headers.
  1081. ;; Note: adjust dired-build-subdir-alist if you change this.
  1082. (setq dir (replace-regexp-in-string "\\\\" "\\\\" dir nil t)
  1083. dir (replace-regexp-in-string "\n" "\\n" dir nil t)))
  1084. (dired-insert-set-properties opoint (point))
  1085. ;; If we used --dired and it worked, the lines are already indented.
  1086. ;; Otherwise, indent them.
  1087. (unless (save-excursion
  1088. (goto-char opoint)
  1089. (looking-at " "))
  1090. (let ((indent-tabs-mode nil))
  1091. (indent-rigidly opoint (point) 2)))
  1092. ;; Insert text at the beginning to standardize things.
  1093. (save-excursion
  1094. (goto-char opoint)
  1095. (if (and (or hdr wildcard)
  1096. (not (and (looking-at "^ \\(.*\\):$")
  1097. (file-name-absolute-p (match-string 1)))))
  1098. ;; Note that dired-build-subdir-alist will replace the name
  1099. ;; by its expansion, so it does not matter whether what we insert
  1100. ;; here is fully expanded, but it should be absolute.
  1101. (insert " " (directory-file-name (file-name-directory dir)) ":\n"))
  1102. (when wildcard
  1103. ;; Insert "wildcard" line where "total" line would be for a full dir.
  1104. (insert " wildcard " (file-name-nondirectory dir) "\n")))))
  1105. (defun dired-insert-set-properties (beg end)
  1106. "Add various text properties to the lines in the region."
  1107. (save-excursion
  1108. (goto-char beg)
  1109. (while (< (point) end)
  1110. (condition-case nil
  1111. (if (dired-move-to-filename)
  1112. (add-text-properties
  1113. (point)
  1114. (save-excursion
  1115. (dired-move-to-end-of-filename)
  1116. (point))
  1117. '(mouse-face highlight
  1118. dired-filename t
  1119. help-echo "mouse-2: visit this file in other window")))
  1120. (error nil))
  1121. (forward-line 1))))
  1122. ;; Reverting a dired buffer
  1123. (defun dired-revert (&optional _arg _noconfirm)
  1124. "Reread the dired buffer.
  1125. Must also be called after `dired-actual-switches' have changed.
  1126. Should not fail even on completely garbaged buffers.
  1127. Preserves old cursor, marks/flags, hidden-p.
  1128. Dired sets `revert-buffer-function' to this function. The args
  1129. ARG and NOCONFIRM, passed from `revert-buffer', are ignored."
  1130. (widen) ; just in case user narrowed
  1131. (let ((modflag (buffer-modified-p))
  1132. (positions (dired-save-positions))
  1133. (mark-alist nil) ; save marked files
  1134. (hidden-subdirs (dired-remember-hidden))
  1135. (old-subdir-alist (cdr (reverse dired-subdir-alist))) ; except pwd
  1136. (case-fold-search nil) ; we check for upper case ls flags
  1137. (inhibit-read-only t))
  1138. (goto-char (point-min))
  1139. (setq mark-alist;; only after dired-remember-hidden since this unhides:
  1140. (dired-remember-marks (point-min) (point-max)))
  1141. ;; treat top level dir extra (it may contain wildcards)
  1142. (if (not (consp dired-directory))
  1143. (dired-uncache dired-directory)
  1144. (dired-uncache (car dired-directory))
  1145. (dolist (dir (cdr dired-directory))
  1146. (if (file-name-absolute-p dir)
  1147. (dired-uncache dir))))
  1148. ;; Run dired-after-readin-hook just once, below.
  1149. (let ((dired-after-readin-hook nil))
  1150. (dired-readin)
  1151. (dired-insert-old-subdirs old-subdir-alist))
  1152. (dired-mark-remembered mark-alist) ; mark files that were marked
  1153. ;; ... run the hook for the whole buffer, and only after markers
  1154. ;; have been reinserted (else omitting in dired-x would omit marked files)
  1155. (run-hooks 'dired-after-readin-hook) ; no need to narrow
  1156. (dired-restore-positions positions)
  1157. (save-excursion ; hide subdirs that were hidden
  1158. (dolist (dir hidden-subdirs)
  1159. (if (dired-goto-subdir dir)
  1160. (dired-hide-subdir 1))))
  1161. (unless modflag (restore-buffer-modified-p nil)))
  1162. ;; outside of the let scope
  1163. ;;; Might as well not override the user if the user changed this.
  1164. ;;; (setq buffer-read-only t)
  1165. )
  1166. ;; Subroutines of dired-revert
  1167. ;; Some of these are also used when inserting subdirs.
  1168. (defun dired-save-positions ()
  1169. "Return current positions in the buffer and all windows with this directory.
  1170. The positions have the form (BUFFER-POSITION WINDOW-POSITIONS).
  1171. BUFFER-POSITION is the point position in the current dired buffer.
  1172. It has the form (BUFFER DIRED-FILENAME BUFFER-POINT).
  1173. WINDOW-POSITIONS are current positions in all windows displaying
  1174. this dired buffer. The window positions have the form (WINDOW
  1175. DIRED-FILENAME WINDOW-POINT)."
  1176. (list
  1177. (list (current-buffer) (dired-get-filename nil t) (point))
  1178. (mapcar (lambda (w)
  1179. (list w
  1180. (with-selected-window w
  1181. (dired-get-filename nil t))
  1182. (window-point w)))
  1183. (get-buffer-window-list nil 0 t))))
  1184. (defun dired-restore-positions (positions)
  1185. "Restore POSITIONS saved with `dired-save-positions'."
  1186. (let* ((buf-file-pos (nth 0 positions))
  1187. (buffer (nth 0 buf-file-pos)))
  1188. (unless (and (nth 1 buf-file-pos)
  1189. (dired-goto-file (nth 1 buf-file-pos)))
  1190. (goto-char (nth 2 buf-file-pos))
  1191. (dired-move-to-filename))
  1192. (dolist (win-file-pos (nth 1 positions))
  1193. ;; Ensure that window still displays the original buffer.
  1194. (when (eq (window-buffer (nth 0 win-file-pos)) buffer)
  1195. (with-selected-window (nth 0 win-file-pos)
  1196. (unless (and (nth 1 win-file-pos)
  1197. (dired-goto-file (nth 1 win-file-pos)))
  1198. (goto-char (nth 2 win-file-pos))
  1199. (dired-move-to-filename)))))))
  1200. (defun dired-remember-marks (beg end)
  1201. "Return alist of files and their marks, from BEG to END."
  1202. (if selective-display ; must unhide to make this work.
  1203. (let ((inhibit-read-only t))
  1204. (subst-char-in-region beg end ?\r ?\n)))
  1205. (let (fil chr alist)
  1206. (save-excursion
  1207. (goto-char beg)
  1208. (while (re-search-forward dired-re-mark end t)
  1209. (if (setq fil (dired-get-filename nil t))
  1210. (setq chr (preceding-char)
  1211. alist (cons (cons fil chr) alist)))))
  1212. alist))
  1213. (defun dired-mark-remembered (alist)
  1214. "Mark all files remembered in ALIST.
  1215. Each element of ALIST looks like (FILE . MARKERCHAR)."
  1216. (let (elt fil chr)
  1217. (while alist
  1218. (setq elt (car alist)
  1219. alist (cdr alist)
  1220. fil (car elt)
  1221. chr (cdr elt))
  1222. (if (dired-goto-file fil)
  1223. (save-excursion
  1224. (beginning-of-line)
  1225. (delete-char 1)
  1226. (insert chr))))))
  1227. (defun dired-remember-hidden ()
  1228. "Return a list of names of subdirs currently hidden."
  1229. (let ((l dired-subdir-alist) dir pos result)
  1230. (while l
  1231. (setq dir (car (car l))
  1232. pos (cdr (car l))
  1233. l (cdr l))
  1234. (goto-char pos)
  1235. (skip-chars-forward "^\r\n")
  1236. (if (eq (following-char) ?\r)
  1237. (setq result (cons dir result))))
  1238. result))
  1239. (defun dired-insert-old-subdirs (old-subdir-alist)
  1240. "Try to insert all subdirs that were displayed before.
  1241. Do so according to the former subdir alist OLD-SUBDIR-ALIST."
  1242. (or (string-match "R" dired-actual-switches)
  1243. (let (elt dir)
  1244. (while old-subdir-alist
  1245. (setq elt (car old-subdir-alist)
  1246. old-subdir-alist (cdr old-subdir-alist)
  1247. dir (car elt))
  1248. (condition-case ()
  1249. (progn
  1250. (dired-uncache dir)
  1251. (dired-insert-subdir dir))
  1252. (error nil))))))
  1253. (defun dired-uncache (dir)
  1254. "Remove directory DIR from any directory cache."
  1255. (let ((handler (find-file-name-handler dir 'dired-uncache)))
  1256. (if handler
  1257. (funcall handler 'dired-uncache dir))))
  1258. ;; dired mode key bindings and initialization
  1259. (defvar dired-mode-map
  1260. ;; This looks ugly when substitute-command-keys uses C-d instead d:
  1261. ;; (define-key dired-mode-map "\C-d" 'dired-flag-file-deletion)
  1262. (let ((map (make-keymap)))
  1263. (set-keymap-parent map special-mode-map)
  1264. (define-key map [mouse-2] 'dired-mouse-find-file-other-window)
  1265. (define-key map [follow-link] 'mouse-face)
  1266. ;; Commands to mark or flag certain categories of files
  1267. (define-key map "#" 'dired-flag-auto-save-files)
  1268. (define-key map "." 'dired-clean-directory)
  1269. (define-key map "~" 'dired-flag-backup-files)
  1270. ;; Upper case keys (except !) for operating on the marked files
  1271. (define-key map "A" 'dired-do-search)
  1272. (define-key map "C" 'dired-do-copy)
  1273. (define-key map "B" 'dired-do-byte-compile)
  1274. (define-key map "D" 'dired-do-delete)
  1275. (define-key map "G" 'dired-do-chgrp)
  1276. (define-key map "H" 'dired-do-hardlink)
  1277. (define-key map "L" 'dired-do-load)
  1278. (define-key map "M" 'dired-do-chmod)
  1279. (define-key map "O" 'dired-do-chown)
  1280. (define-key map "P" 'dired-do-print)
  1281. (define-key map "Q" 'dired-do-query-replace-regexp)
  1282. (define-key map "R" 'dired-do-rename)
  1283. (define-key map "S" 'dired-do-symlink)
  1284. (define-key map "T" 'dired-do-touch)
  1285. (define-key map "X" 'dired-do-shell-command)
  1286. (define-key map "Z" 'dired-do-compress)
  1287. (define-key map "!" 'dired-do-shell-command)
  1288. (define-key map "&" 'dired-do-async-shell-command)
  1289. ;; Comparison commands
  1290. (define-key map "=" 'dired-diff)
  1291. (define-key map "\M-=" 'dired-backup-diff)
  1292. ;; Tree Dired commands
  1293. (define-key map "\M-\C-?" 'dired-unmark-all-files)
  1294. (define-key map "\M-\C-d" 'dired-tree-down)
  1295. (define-key map "\M-\C-u" 'dired-tree-up)
  1296. (define-key map "\M-\C-n" 'dired-next-subdir)
  1297. (define-key map "\M-\C-p" 'dired-prev-subdir)
  1298. ;; move to marked files
  1299. (define-key map "\M-{" 'dired-prev-marked-file)
  1300. (define-key map "\M-}" 'dired-next-marked-file)
  1301. ;; Make all regexp commands share a `%' prefix:
  1302. ;; We used to get to the submap via a symbol dired-regexp-prefix,
  1303. ;; but that seems to serve little purpose, and copy-keymap
  1304. ;; does a better job without it.
  1305. (define-key map "%" nil)
  1306. (define-key map "%u" 'dired-upcase)
  1307. (define-key map "%l" 'dired-downcase)
  1308. (define-key map "%d" 'dired-flag-files-regexp)
  1309. (define-key map "%g" 'dired-mark-files-containing-regexp)
  1310. (define-key map "%m" 'dired-mark-files-regexp)
  1311. (define-key map "%r" 'dired-do-rename-regexp)
  1312. (define-key map "%C" 'dired-do-copy-regexp)
  1313. (define-key map "%H" 'dired-do-hardlink-regexp)
  1314. (define-key map "%R" 'dired-do-rename-regexp)
  1315. (define-key map "%S" 'dired-do-symlink-regexp)
  1316. (define-key map "%&" 'dired-flag-garbage-files)
  1317. ;; Commands for marking and unmarking.
  1318. (define-key map "*" nil)
  1319. (define-key map "**" 'dired-mark-executables)
  1320. (define-key map "*/" 'dired-mark-directories)
  1321. (define-key map "*@" 'dired-mark-symlinks)
  1322. (define-key map "*%" 'dired-mark-files-regexp)
  1323. (define-key map "*c" 'dired-change-marks)
  1324. (define-key map "*s" 'dired-mark-subdir-files)
  1325. (define-key map "*m" 'dired-mark)
  1326. (define-key map "*u" 'dired-unmark)
  1327. (define-key map "*?" 'dired-unmark-all-files)
  1328. (define-key map "*!" 'dired-unmark-all-marks)
  1329. (define-key map "U" 'dired-unmark-all-marks)
  1330. (define-key map "*\177" 'dired-unmark-backward)
  1331. (define-key map "*\C-n" 'dired-next-marked-file)
  1332. (define-key map "*\C-p" 'dired-prev-marked-file)
  1333. (define-key map "*t" 'dired-toggle-marks)
  1334. ;; Lower keys for commands not operating on all the marked files
  1335. (define-key map "a" 'dired-find-alternate-file)
  1336. (define-key map "d" 'dired-flag-file-deletion)
  1337. (define-key map "e" 'dired-find-file)
  1338. (define-key map "f" 'dired-find-file)
  1339. (define-key map "\C-m" 'dired-find-file)
  1340. (put 'dired-find-file :advertised-binding "\C-m")
  1341. (define-key map "g" 'revert-buffer)
  1342. (define-key map "i" 'dired-maybe-insert-subdir)
  1343. (define-key map "j" 'dired-goto-file)
  1344. (define-key map "k" 'dired-do-kill-lines)
  1345. (define-key map "l" 'dired-do-redisplay)
  1346. (define-key map "m" 'dired-mark)
  1347. (define-key map "n" 'dired-next-line)
  1348. (define-key map "o" 'dired-find-file-other-window)
  1349. (define-key map "\C-o" 'dired-display-file)
  1350. (define-key map "p" 'dired-previous-line)
  1351. (define-key map "s" 'dired-sort-toggle-or-edit)
  1352. (define-key map "t" 'dired-toggle-marks)
  1353. (define-key map "u" 'dired-unmark)
  1354. (define-key map "v" 'dired-view-file)
  1355. (define-key map "w" 'dired-copy-filename-as-kill)
  1356. (define-key map "x" 'dired-do-flagged-delete)
  1357. (define-key map "y" 'dired-show-file-type)
  1358. (define-key map "+" 'dired-create-directory)
  1359. ;; moving
  1360. (define-key map "<" 'dired-prev-dirline)
  1361. (define-key map ">" 'dired-next-dirline)
  1362. (define-key map "^" 'dired-up-directory)
  1363. (define-key map " " 'dired-next-line)
  1364. (define-key map [remap next-line] 'dired-next-line)
  1365. (define-key map [remap previous-line] 'dired-previous-line)
  1366. ;; hiding
  1367. (define-key map "$" 'dired-hide-subdir)
  1368. (define-key map "\M-$" 'dired-hide-all)
  1369. ;; isearch
  1370. (define-key map (kbd "M-s a C-s") 'dired-do-isearch)
  1371. (define-key map (kbd "M-s a M-C-s") 'dired-do-isearch-regexp)
  1372. (define-key map (kbd "M-s f C-s") 'dired-isearch-filenames)
  1373. (define-key map (kbd "M-s f M-C-s") 'dired-isearch-filenames-regexp)
  1374. ;; misc
  1375. (define-key map [remap toggle-read-only] 'dired-toggle-read-only)
  1376. (define-key map "?" 'dired-summary)
  1377. (define-key map "\177" 'dired-unmark-backward)
  1378. (define-key map [remap undo] 'dired-undo)
  1379. (define-key map [remap advertised-undo] 'dired-undo)
  1380. ;; thumbnail manipulation (image-dired)
  1381. (define-key map "\C-td" 'image-dired-display-thumbs)
  1382. (define-key map "\C-tt" 'image-dired-tag-files)
  1383. (define-key map "\C-tr" 'image-dired-delete-tag)
  1384. (define-key map "\C-tj" 'image-dired-jump-thumbnail-buffer)
  1385. (define-key map "\C-ti" 'image-dired-dired-display-image)
  1386. (define-key map "\C-tx" 'image-dired-dired-display-external)
  1387. (define-key map "\C-ta" 'image-dired-display-thumbs-append)
  1388. (define-key map "\C-t." 'image-dired-display-thumb)
  1389. (define-key map "\C-tc" 'image-dired-dired-comment-files)
  1390. (define-key map "\C-tf" 'image-dired-mark-tagged-files)
  1391. (define-key map "\C-t\C-t" 'image-dired-dired-toggle-marked-thumbs)
  1392. (define-key map "\C-te" 'image-dired-dired-edit-comment-and-tags)
  1393. ;; encryption and decryption (epa-dired)
  1394. (define-key map ":d" 'epa-dired-do-decrypt)
  1395. (define-key map ":v" 'epa-dired-do-verify)
  1396. (define-key map ":s" 'epa-dired-do-sign)
  1397. (define-key map ":e" 'epa-dired-do-encrypt)
  1398. ;; Make menu bar items.
  1399. ;; No need to fo this, now that top-level items are fewer.
  1400. ;;;;
  1401. ;; Get rid of the Edit menu bar item to save space.
  1402. ;(define-key map [menu-bar edit] 'undefined)
  1403. (define-key map [menu-bar subdir]
  1404. (cons "Subdir" (make-sparse-keymap "Subdir")))
  1405. (define-key map [menu-bar subdir hide-all]
  1406. '(menu-item "Hide All" dired-hide-all
  1407. :help "Hide all subdirectories, leave only header lines"))
  1408. (define-key map [menu-bar subdir hide-subdir]
  1409. '(menu-item "Hide/UnHide Subdir" dired-hide-subdir
  1410. :help "Hide or unhide current directory listing"))
  1411. (define-key map [menu-bar subdir tree-down]
  1412. '(menu-item "Tree Down" dired-tree-down
  1413. :help "Go to first subdirectory header down the tree"))
  1414. (define-key map [menu-bar subdir tree-up]
  1415. '(menu-item "Tree Up" dired-tree-up
  1416. :help "Go to first subdirectory header up the tree"))
  1417. (define-key map [menu-bar subdir up]
  1418. '(menu-item "Up Directory" dired-up-directory
  1419. :help "Edit the parent directory"))
  1420. (define-key map [menu-bar subdir prev-subdir]
  1421. '(menu-item "Prev Subdir" dired-prev-subdir
  1422. :help "Go to previous subdirectory header line"))
  1423. (define-key map [menu-bar subdir next-subdir]
  1424. '(menu-item "Next Subdir" dired-next-subdir
  1425. :help "Go to next subdirectory header line"))
  1426. (define-key map [menu-bar subdir prev-dirline]
  1427. '(menu-item "Prev Dirline" dired-prev-dirline
  1428. :help "Move to next directory-file line"))
  1429. (define-key map [menu-bar subdir next-dirline]
  1430. '(menu-item "Next Dirline" dired-next-dirline
  1431. :help "Move to previous directory-file line"))
  1432. (define-key map [menu-bar subdir insert]
  1433. '(menu-item "Insert This Subdir" dired-maybe-insert-subdir
  1434. :help "Insert contents of subdirectory"
  1435. :enable (let ((f (dired-get-filename nil t)))
  1436. (and f (file-directory-p f)))))
  1437. (define-key map [menu-bar immediate]
  1438. (cons "Immediate" (make-sparse-keymap "Immediate")))
  1439. (define-key map
  1440. [menu-bar immediate image-dired-dired-display-external]
  1441. '(menu-item "Display Image Externally" image-dired-dired-display-external
  1442. :help "Display image in external viewer"))
  1443. (define-key map
  1444. [menu-bar immediate image-dired-dired-display-image]
  1445. '(menu-item "Display Image" image-dired-dired-display-image
  1446. :help "Display sized image in a separate window"))
  1447. (define-key map
  1448. [menu-bar immediate image-dired-dired-toggle-marked-thumbs]
  1449. '(menu-item "Toggle Image Thumbnails in This Buffer" image-dired-dired-toggle-marked-thumbs
  1450. :help "Add or remove image thumbnails in front of marked file names"))
  1451. (define-key map [menu-bar immediate revert-buffer]
  1452. '(menu-item "Refresh" revert-buffer
  1453. :help "Update contents of shown directories"))
  1454. (define-key map [menu-bar immediate dashes]
  1455. '("--"))
  1456. (define-key map [menu-bar immediate isearch-filenames-regexp]
  1457. '(menu-item "Isearch Regexp in File Names..." dired-isearch-filenames-regexp
  1458. :help "Incrementally search for regexp in file names only"))
  1459. (define-key map [menu-bar immediate isearch-filenames]
  1460. '(menu-item "Isearch in File Names..." dired-isearch-filenames
  1461. :help "Incrementally search for string in file names only."))
  1462. (define-key map [menu-bar immediate compare-directories]
  1463. '(menu-item "Compare Directories..." dired-compare-directories
  1464. :help "Mark files with different attributes in two dired buffers"))
  1465. (define-key map [menu-bar immediate backup-diff]
  1466. '(menu-item "Compare with Backup" dired-backup-diff
  1467. :help "Diff file at cursor with its latest backup"))
  1468. (define-key map [menu-bar immediate diff]
  1469. '(menu-item "Diff..." dired-diff
  1470. :help "Compare file at cursor with another file"))
  1471. (define-key map [menu-bar immediate view]
  1472. '(menu-item "View This File" dired-view-file
  1473. :help "Examine file at cursor in read-only mode"))
  1474. (define-key map [menu-bar immediate display]
  1475. '(menu-item "Display in Other Window" dired-display-file
  1476. :help "Display file at cursor in other window"))
  1477. (define-key map [menu-bar immediate find-file-other-window]
  1478. '(menu-item "Find in Other Window" dired-find-file-other-window
  1479. :help "Edit file at cursor in other window"))
  1480. (define-key map [menu-bar immediate find-file]
  1481. '(menu-item "Find This File" dired-find-file
  1482. :help "Edit file at cursor"))
  1483. (define-key map [menu-bar immediate create-directory]
  1484. '(menu-item "Create Directory..." dired-create-directory
  1485. :help "Create a directory"))
  1486. (define-key map [menu-bar immediate wdired-mode]
  1487. '(menu-item "Edit File Names" wdired-change-to-wdired-mode
  1488. :help "Put a dired buffer in a mode in which filenames are editable"
  1489. :keys "C-x C-q"
  1490. :filter (lambda (x) (if (eq major-mode 'dired-mode) x))))
  1491. (define-key map [menu-bar regexp]
  1492. (cons "Regexp" (make-sparse-keymap "Regexp")))
  1493. (define-key map
  1494. [menu-bar regexp image-dired-mark-tagged-files]
  1495. '(menu-item "Mark From Image Tag..." image-dired-mark-tagged-files
  1496. :help "Mark files whose image tags matches regexp"))
  1497. (define-key map [menu-bar regexp dashes-1]
  1498. '("--"))
  1499. (define-key map [menu-bar regexp downcase]
  1500. '(menu-item "Downcase" dired-downcase
  1501. ;; When running on plain MS-DOS, there's only one
  1502. ;; letter-case for file names.
  1503. :enable (or (not (fboundp 'msdos-long-file-names))
  1504. (msdos-long-file-names))
  1505. :help "Rename marked files to lower-case name"))
  1506. (define-key map [menu-bar regexp upcase]
  1507. '(menu-item "Upcase" dired-upcase
  1508. :enable (or (not (fboundp 'msdos-long-file-names))
  1509. (msdos-long-file-names))
  1510. :help "Rename marked files to upper-case name"))
  1511. (define-key map [menu-bar regexp hardlink]
  1512. '(menu-item "Hardlink..." dired-do-hardlink-regexp
  1513. :help "Make hard links for files matching regexp"))
  1514. (define-key map [menu-bar regexp symlink]
  1515. '(menu-item "Symlink..." dired-do-symlink-regexp
  1516. :visible (fboundp 'make-symbolic-link)
  1517. :help "Make symbolic links for files matching regexp"))
  1518. (define-key map [menu-bar regexp rename]
  1519. '(menu-item "Rename..." dired-do-rename-regexp
  1520. :help "Rename marked files matching regexp"))
  1521. (define-key map [menu-bar regexp copy]
  1522. '(menu-item "Copy..." dired-do-copy-regexp
  1523. :help "Copy marked files matching regexp"))
  1524. (define-key map [menu-bar regexp flag]
  1525. '(menu-item "Flag..." dired-flag-files-regexp
  1526. :help "Flag files matching regexp for deletion"))
  1527. (define-key map [menu-bar regexp mark]
  1528. '(menu-item "Mark..." dired-mark-files-regexp
  1529. :help "Mark files matching regexp for future operations"))
  1530. (define-key map [menu-bar regexp mark-cont]
  1531. '(menu-item "Mark Containing..." dired-mark-files-containing-regexp
  1532. :help "Mark files whose contents matches regexp"))
  1533. (define-key map [menu-bar mark]
  1534. (cons "Mark" (make-sparse-keymap "Mark")))
  1535. (define-key map [menu-bar mark prev]
  1536. '(menu-item "Previous Marked" dired-prev-marked-file
  1537. :help "Move to previous marked file"))
  1538. (define-key map [menu-bar mark next]
  1539. '(menu-item "Next Marked" dired-next-marked-file
  1540. :help "Move to next marked file"))
  1541. (define-key map [menu-bar mark marks]
  1542. '(menu-item "Change Marks..." dired-change-marks
  1543. :help "Replace marker with another character"))
  1544. (define-key map [menu-bar mark unmark-all]
  1545. '(menu-item "Unmark All" dired-unmark-all-marks))
  1546. (define-key map [menu-bar mark symlinks]
  1547. '(menu-item "Mark Symlinks" dired-mark-symlinks
  1548. :visible (fboundp 'make-symbolic-link)
  1549. :help "Mark all symbolic links"))
  1550. (define-key map [menu-bar mark directories]
  1551. '(menu-item "Mark Directories" dired-mark-directories
  1552. :help "Mark all directories except `.' and `..'"))
  1553. (define-key map [menu-bar mark directory]
  1554. '(menu-item "Mark Old Backups" dired-clean-directory
  1555. :help "Flag old numbered backups for deletion"))
  1556. (define-key map [menu-bar mark executables]
  1557. '(menu-item "Mark Executables" dired-mark-executables
  1558. :help "Mark all executable files"))
  1559. (define-key map [menu-bar mark garbage-files]
  1560. '(menu-item "Flag Garbage Files" dired-flag-garbage-files
  1561. :help "Flag unneeded files for deletion"))
  1562. (define-key map [menu-bar mark backup-files]
  1563. '(menu-item "Flag Backup Files" dired-flag-backup-files
  1564. :help "Flag all backup files for deletion"))
  1565. (define-key map [menu-bar mark auto-save-files]
  1566. '(menu-item "Flag Auto-save Files" dired-flag-auto-save-files
  1567. :help "Flag auto-save files for deletion"))
  1568. (define-key map [menu-bar mark deletion]
  1569. '(menu-item "Flag" dired-flag-file-deletion
  1570. :help "Flag current line's file for deletion"))
  1571. (define-key map [menu-bar mark unmark]
  1572. '(menu-item "Unmark" dired-unmark
  1573. :help "Unmark or unflag current line's file"))
  1574. (define-key map [menu-bar mark mark]
  1575. '(menu-item "Mark" dired-mark
  1576. :help "Mark current line's file for future operations"))
  1577. (define-key map [menu-bar mark toggle-marks]
  1578. '(menu-item "Toggle Marks" dired-toggle-marks
  1579. :help "Mark unmarked files, unmark marked ones"))
  1580. (define-key map [menu-bar operate]
  1581. (cons "Operate" (make-sparse-keymap "Operate")))
  1582. (define-key map
  1583. [menu-bar operate image-dired-delete-tag]
  1584. '(menu-item "Delete Image Tag..." image-dired-delete-tag
  1585. :help "Delete image tag from current or marked files"))
  1586. (define-key map
  1587. [menu-bar operate image-dired-tag-files]
  1588. '(menu-item "Add Image Tags..." image-dired-tag-files
  1589. :help "Add image tags to current or marked files"))
  1590. (define-key map
  1591. [menu-bar operate image-dired-dired-comment-files]
  1592. '(menu-item "Add Image Comment..." image-dired-dired-comment-files
  1593. :help "Add image comment to current or marked files"))
  1594. (define-key map
  1595. [menu-bar operate image-dired-display-thumbs]
  1596. '(menu-item "Display Image Thumbnails" image-dired-display-thumbs
  1597. :help "Display image thumbnails for current or marked image files"))
  1598. (define-key map [menu-bar operate dashes-4]
  1599. '("--"))
  1600. (define-key map
  1601. [menu-bar operate epa-dired-do-decrypt]
  1602. '(menu-item "Decrypt" epa-dired-do-decrypt
  1603. :help "Decrypt file at cursor"))
  1604. (define-key map
  1605. [menu-bar operate epa-dired-do-verify]
  1606. '(menu-item "Verify" epa-dired-do-verify
  1607. :help "Verify digital signature of file at cursor"))
  1608. (define-key map
  1609. [menu-bar operate epa-dired-do-sign]
  1610. '(menu-item "Sign" epa-dired-do-sign
  1611. :help "Create digital signature of file at cursor"))
  1612. (define-key map
  1613. [menu-bar operate epa-dired-do-encrypt]
  1614. '(menu-item "Encrypt" epa-dired-do-encrypt
  1615. :help "Encrypt file at cursor"))
  1616. (define-key map [menu-bar operate dashes-3]
  1617. '("--"))
  1618. (define-key map [menu-bar operate query-replace]
  1619. '(menu-item "Query Replace in Files..." dired-do-query-replace-regexp
  1620. :help "Replace regexp in marked files"))
  1621. (define-key map [menu-bar operate search]
  1622. '(menu-item "Search Files..." dired-do-search
  1623. :help "Search marked files for regexp"))
  1624. (define-key map [menu-bar operate isearch-regexp]
  1625. '(menu-item "Isearch Regexp Files..." dired-do-isearch-regexp
  1626. :help "Incrementally search marked files for regexp"))
  1627. (define-key map [menu-bar operate isearch]
  1628. '(menu-item "Isearch Files..." dired-do-isearch
  1629. :help "Incrementally search marked files for string"))
  1630. (define-key map [menu-bar operate chown]
  1631. '(menu-item "Change Owner..." dired-do-chown
  1632. :visible (not (memq system-type '(ms-dos windows-nt)))
  1633. :help "Change the owner of marked files"))
  1634. (define-key map [menu-bar operate chgrp]
  1635. '(menu-item "Change Group..." dired-do-chgrp
  1636. :visible (not (memq system-type '(ms-dos windows-nt)))
  1637. :help "Change the group of marked files"))
  1638. (define-key map [menu-bar operate chmod]
  1639. '(menu-item "Change Mode..." dired-do-chmod
  1640. :help "Change mode (attributes) of marked files"))
  1641. (define-key map [menu-bar operate touch]
  1642. '(menu-item "Change Timestamp..." dired-do-touch
  1643. :help "Change timestamp of marked files"))
  1644. (define-key map [menu-bar operate load]
  1645. '(menu-item "Load" dired-do-load
  1646. :help "Load marked Emacs Lisp files"))
  1647. (define-key map [menu-bar operate compile]
  1648. '(menu-item "Byte-compile" dired-do-byte-compile
  1649. :help "Byte-compile marked Emacs Lisp files"))
  1650. (define-key map [menu-bar operate compress]
  1651. '(menu-item "Compress" dired-do-compress
  1652. :help "Compress/uncompress marked files"))
  1653. (define-key map [menu-bar operate print]
  1654. '(menu-item "Print..." dired-do-print
  1655. :help "Ask for print command and print marked files"))
  1656. (define-key map [menu-bar operate hardlink]
  1657. '(menu-item "Hardlink to..." dired-do-hardlink
  1658. :help "Make hard links for current or marked files"))
  1659. (define-key map [menu-bar operate symlink]
  1660. '(menu-item "Symlink to..." dired-do-symlink
  1661. :visible (fboundp 'make-symbolic-link)
  1662. :help "Make symbolic links for current or marked files"))
  1663. (define-key map [menu-bar operate async-command]
  1664. '(menu-item "Asynchronous Shell Command..." dired-do-async-shell-command
  1665. :help "Run a shell command asynchronously on current or marked files"))
  1666. (define-key map [menu-bar operate command]
  1667. '(menu-item "Shell Command..." dired-do-shell-command
  1668. :help "Run a shell command on current or marked files"))
  1669. (define-key map [menu-bar operate delete]
  1670. '(menu-item "Delete" dired-do-delete
  1671. :help "Delete current file or all marked files"))
  1672. (define-key map [menu-bar operate rename]
  1673. '(menu-item "Rename to..." dired-do-rename
  1674. :help "Rename current file or move marked files"))
  1675. (define-key map [menu-bar operate copy]
  1676. '(menu-item "Copy to..." dired-do-copy
  1677. :help "Copy current file or all marked files"))
  1678. map)
  1679. "Local keymap for `dired-mode' buffers.")
  1680. ;; Dired mode is suitable only for specially formatted data.
  1681. (put 'dired-mode 'mode-class 'special)
  1682. ;; Autoload cookie needed by desktop.el
  1683. ;;;###autoload
  1684. (defun dired-mode (&optional dirname switches)
  1685. "\
  1686. Mode for \"editing\" directory listings.
  1687. In Dired, you are \"editing\" a list of the files in a directory and
  1688. \(optionally) its subdirectories, in the format of `ls -lR'.
  1689. Each directory is a page: use \\[backward-page] and \\[forward-page] to move pagewise.
  1690. \"Editing\" means that you can run shell commands on files, visit,
  1691. compress, load or byte-compile them, change their file attributes
  1692. and insert subdirectories into the same buffer. You can \"mark\"
  1693. files for later commands or \"flag\" them for deletion, either file
  1694. by file or all files matching certain criteria.
  1695. You can move using the usual cursor motion commands.\\<dired-mode-map>
  1696. The buffer is read-only. Digits are prefix arguments.
  1697. Type \\[dired-flag-file-deletion] to flag a file `D' for deletion.
  1698. Type \\[dired-mark] to Mark a file or subdirectory for later commands.
  1699. Most commands operate on the marked files and use the current file
  1700. if no files are marked. Use a numeric prefix argument to operate on
  1701. the next ARG (or previous -ARG if ARG<0) files, or just `1'
  1702. to operate on the current file only. Prefix arguments override marks.
  1703. Mark-using commands display a list of failures afterwards. Type \\[dired-summary]
  1704. to see why something went wrong.
  1705. Type \\[dired-unmark] to Unmark a file or all files of an inserted subdirectory.
  1706. Type \\[dired-unmark-backward] to back up one line and unmark or unflag.
  1707. Type \\[dired-do-flagged-delete] to delete (eXecute) the files flagged `D'.
  1708. Type \\[dired-find-file] to Find the current line's file
  1709. (or dired it in another buffer, if it is a directory).
  1710. Type \\[dired-find-file-other-window] to find file or dired directory in Other window.
  1711. Type \\[dired-maybe-insert-subdir] to Insert a subdirectory in this buffer.
  1712. Type \\[dired-do-rename] to Rename a file or move the marked files to another directory.
  1713. Type \\[dired-do-copy] to Copy files.
  1714. Type \\[dired-sort-toggle-or-edit] to toggle Sorting by name/date or change the `ls' switches.
  1715. Type \\[revert-buffer] to read all currently expanded directories aGain.
  1716. This retains all marks and hides subdirs again that were hidden before.
  1717. Use `SPC' and `DEL' to move down and up by lines.
  1718. If Dired ever gets confused, you can either type \\[revert-buffer] \
  1719. to read the
  1720. directories again, type \\[dired-do-redisplay] \
  1721. to relist the file at point or the marked files or a
  1722. subdirectory, or type \\[dired-build-subdir-alist] to parse the buffer
  1723. again for the directory tree.
  1724. Customization variables (rename this buffer and type \\[describe-variable] on each line
  1725. for more info):
  1726. `dired-listing-switches'
  1727. `dired-trivial-filenames'
  1728. `dired-shrink-to-fit'
  1729. `dired-marker-char'
  1730. `dired-del-marker'
  1731. `dired-keep-marker-rename'
  1732. `dired-keep-marker-copy'
  1733. `dired-keep-marker-hardlink'
  1734. `dired-keep-marker-symlink'
  1735. Hooks (use \\[describe-variable] to see their documentation):
  1736. `dired-before-readin-hook'
  1737. `dired-after-readin-hook'
  1738. `dired-mode-hook'
  1739. `dired-load-hook'
  1740. Keybindings:
  1741. \\{dired-mode-map}"
  1742. ;; Not to be called interactively (e.g. dired-directory will be set
  1743. ;; to default-directory, which is wrong with wildcards).
  1744. (kill-all-local-variables)
  1745. (use-local-map dired-mode-map)
  1746. (dired-advertise) ; default-directory is already set
  1747. (setq major-mode 'dired-mode
  1748. mode-name "Dired"
  1749. ;; case-fold-search nil
  1750. buffer-read-only t
  1751. selective-display t ; for subdirectory hiding
  1752. mode-line-buffer-identification
  1753. (propertized-buffer-identification "%17b"))
  1754. (set (make-local-variable 'revert-buffer-function)
  1755. (function dired-revert))
  1756. (set (make-local-variable 'buffer-stale-function)
  1757. (function dired-buffer-stale-p))
  1758. (set (make-local-variable 'page-delimiter)
  1759. "\n\n")
  1760. (set (make-local-variable 'dired-directory)
  1761. (or dirname default-directory))
  1762. ;; list-buffers uses this to display the dir being edited in this buffer.
  1763. (setq list-buffers-directory
  1764. (expand-file-name (if (listp dired-directory)
  1765. (car dired-directory)
  1766. dired-directory)))
  1767. (set (make-local-variable 'dired-actual-switches)
  1768. (or switches dired-listing-switches))
  1769. (set (make-local-variable 'font-lock-defaults)
  1770. '(dired-font-lock-keywords t nil nil beginning-of-line))
  1771. (set (make-local-variable 'desktop-save-buffer)
  1772. 'dired-desktop-buffer-misc-data)
  1773. (setq dired-switches-alist nil)
  1774. (hack-dir-local-variables-non-file-buffer) ; before sorting
  1775. (dired-sort-other dired-actual-switches t)
  1776. (when (featurep 'dnd)
  1777. (set (make-local-variable 'dnd-protocol-alist)
  1778. (append dired-dnd-protocol-alist dnd-protocol-alist)))
  1779. (add-hook 'file-name-at-point-functions 'dired-file-name-at-point nil t)
  1780. (add-hook 'isearch-mode-hook 'dired-isearch-filenames-setup nil t)
  1781. (run-mode-hooks 'dired-mode-hook))
  1782. ;; Idiosyncratic dired commands that don't deal with marks.
  1783. (defun dired-summary ()
  1784. "Summarize basic Dired commands and show recent dired errors."
  1785. (interactive)
  1786. (dired-why)
  1787. ;>> this should check the key-bindings and use substitute-command-keys if non-standard
  1788. (message
  1789. "d-elete, u-ndelete, x-punge, f-ind, o-ther window, R-ename, C-opy, h-elp"))
  1790. (defun dired-undo ()
  1791. "Undo in a dired buffer.
  1792. This doesn't recover lost files, it just undoes changes in the buffer itself.
  1793. You can use it to recover marks, killed lines or subdirs."
  1794. (interactive)
  1795. (let ((inhibit-read-only t))
  1796. (undo))
  1797. (dired-build-subdir-alist)
  1798. (message "Change in dired buffer undone.
  1799. Actual changes in files cannot be undone by Emacs."))
  1800. (defun dired-toggle-read-only ()
  1801. "Edit dired buffer with Wdired, or set it read-only.
  1802. Call `wdired-change-to-wdired-mode' in dired buffers whose editing is
  1803. supported by Wdired (the major mode of the dired buffer is `dired-mode').
  1804. Otherwise, for buffers inheriting from dired-mode, call `toggle-read-only'."
  1805. (interactive)
  1806. (if (eq major-mode 'dired-mode)
  1807. (wdired-change-to-wdired-mode)
  1808. (with-no-warnings
  1809. (toggle-read-only))))
  1810. (defun dired-next-line (arg)
  1811. "Move down lines then position at filename.
  1812. Optional prefix ARG says how many lines to move; default is one line."
  1813. (interactive "p")
  1814. (forward-line arg)
  1815. (dired-move-to-filename))
  1816. (defun dired-previous-line (arg)
  1817. "Move up lines then position at filename.
  1818. Optional prefix ARG says how many lines to move; default is one line."
  1819. (interactive "p")
  1820. (forward-line (- arg))
  1821. (dired-move-to-filename))
  1822. (defun dired-next-dirline (arg &optional opoint)
  1823. "Goto ARG'th next directory file line."
  1824. (interactive "p")
  1825. (or opoint (setq opoint (point)))
  1826. (if (if (> arg 0)
  1827. (re-search-forward dired-re-dir nil t arg)
  1828. (beginning-of-line)
  1829. (re-search-backward dired-re-dir nil t (- arg)))
  1830. (dired-move-to-filename) ; user may type `i' or `f'
  1831. (goto-char opoint)
  1832. (error "No more subdirectories")))
  1833. (defun dired-prev-dirline (arg)
  1834. "Goto ARG'th previous directory file line."
  1835. (interactive "p")
  1836. (dired-next-dirline (- arg)))
  1837. (defun dired-up-directory (&optional other-window)
  1838. "Run Dired on parent directory of current directory.
  1839. Find the parent directory either in this buffer or another buffer.
  1840. Creates a buffer if necessary."
  1841. (interactive "P")
  1842. (let* ((dir (dired-current-directory))
  1843. (up (file-name-directory (directory-file-name dir))))
  1844. (or (dired-goto-file (directory-file-name dir))
  1845. ;; Only try dired-goto-subdir if buffer has more than one dir.
  1846. (and (cdr dired-subdir-alist)
  1847. (dired-goto-subdir up))
  1848. (progn
  1849. (if other-window
  1850. (dired-other-window up)
  1851. (dired up))
  1852. (dired-goto-file dir)))))
  1853. (defun dired-get-file-for-visit ()
  1854. "Get the current line's file name, with an error if file does not exist."
  1855. (interactive)
  1856. ;; We pass t for second arg so that we don't get error for `.' and `..'.
  1857. (let ((raw (dired-get-filename nil t))
  1858. file-name)
  1859. (if (null raw)
  1860. (error "No file on this line"))
  1861. (setq file-name (file-name-sans-versions raw t))
  1862. (if (file-exists-p file-name)
  1863. file-name
  1864. (if (file-symlink-p file-name)
  1865. (error "File is a symlink to a nonexistent target")
  1866. (error "File no longer exists; type `g' to update dired buffer")))))
  1867. ;; Force C-m keybinding rather than `f' or `e' in the mode doc:
  1868. (define-obsolete-function-alias 'dired-advertised-find-file 'dired-find-file "23.2")
  1869. (defun dired-find-file ()
  1870. "In Dired, visit the file or directory named on this line."
  1871. (interactive)
  1872. ;; Bind `find-file-run-dired' so that the command works on directories
  1873. ;; too, independent of the user's setting.
  1874. (let ((find-file-run-dired t))
  1875. (find-file (dired-get-file-for-visit))))
  1876. (defun dired-find-alternate-file ()
  1877. "In Dired, visit this file or directory instead of the dired buffer."
  1878. (interactive)
  1879. (set-buffer-modified-p nil)
  1880. (find-alternate-file (dired-get-file-for-visit)))
  1881. ;; Don't override the setting from .emacs.
  1882. ;;;###autoload (put 'dired-find-alternate-file 'disabled t)
  1883. (defun dired-mouse-find-file-other-window (event)
  1884. "In Dired, visit the file or directory name you click on."
  1885. (interactive "e")
  1886. (let (window pos file)
  1887. (save-excursion
  1888. (setq window (posn-window (event-end event))
  1889. pos (posn-point (event-end event)))
  1890. (if (not (windowp window))
  1891. (error "No file chosen"))
  1892. (set-buffer (window-buffer window))
  1893. (goto-char pos)
  1894. (setq file (dired-get-file-for-visit)))
  1895. (if (file-directory-p file)
  1896. (or (and (cdr dired-subdir-alist)
  1897. (dired-goto-subdir file))
  1898. (progn
  1899. (select-window window)
  1900. (dired-other-window file)))
  1901. (select-window window)
  1902. (find-file-other-window (file-name-sans-versions file t)))))
  1903. (defun dired-view-file ()
  1904. "In Dired, examine a file in view mode, returning to Dired when done.
  1905. When file is a directory, show it in this buffer if it is inserted.
  1906. Otherwise, display it in another buffer."
  1907. (interactive)
  1908. (let ((file (dired-get-file-for-visit)))
  1909. (if (file-directory-p file)
  1910. (or (and (cdr dired-subdir-alist)
  1911. (dired-goto-subdir file))
  1912. (dired file))
  1913. (view-file file))))
  1914. (defun dired-find-file-other-window ()
  1915. "In Dired, visit this file or directory in another window."
  1916. (interactive)
  1917. (find-file-other-window (dired-get-file-for-visit)))
  1918. (defun dired-display-file ()
  1919. "In Dired, display this file or directory in another window."
  1920. (interactive)
  1921. (display-buffer (find-file-noselect (dired-get-file-for-visit))))
  1922. ;;; Functions for extracting and manipulating file names in Dired buffers.
  1923. (defun dired-get-filename (&optional localp no-error-if-not-filep)
  1924. "In Dired, return name of file mentioned on this line.
  1925. Value returned normally includes the directory name.
  1926. Optional arg LOCALP with value `no-dir' means don't include directory
  1927. name in result. A value of `verbatim' means to return the name exactly as
  1928. it occurs in the buffer, and a value of t means construct name relative to
  1929. `default-directory', which still may contain slashes if in a subdirectory.
  1930. Optional arg NO-ERROR-IF-NOT-FILEP means treat `.' and `..' as
  1931. regular filenames and return nil if no filename on this line.
  1932. Otherwise, an error occurs in these cases."
  1933. (let (case-fold-search file p1 p2 already-absolute)
  1934. (save-excursion
  1935. (if (setq p1 (dired-move-to-filename (not no-error-if-not-filep)))
  1936. (setq p2 (dired-move-to-end-of-filename no-error-if-not-filep))))
  1937. ;; nil if no file on this line, but no-error-if-not-filep is t:
  1938. (if (setq file (and p1 p2 (buffer-substring p1 p2)))
  1939. (progn
  1940. ;; Get rid of the mouse-face property that file names have.
  1941. (set-text-properties 0 (length file) nil file)
  1942. ;; Unquote names quoted by ls or by dired-insert-directory.
  1943. ;; This code was written using `read' to unquote, because
  1944. ;; it's faster than substituting \007 (4 chars) -> ^G (1
  1945. ;; char) etc. in a lisp loop. Unfortunately, this decision
  1946. ;; has necessitated hacks such as dealing with filenames
  1947. ;; with quotation marks in their names.
  1948. (while (string-match "\\(?:[^\\]\\|\\`\\)\\(\"\\)" file)
  1949. (setq file (replace-match "\\\"" nil t file 1)))
  1950. ;; Unescape any spaces escaped by ls -b (bug#10469).
  1951. ;; Other -b quotes, eg \t, \n, work transparently.
  1952. (if (dired-switches-escape-p dired-actual-switches)
  1953. (let ((start 0)
  1954. (rep "")
  1955. (shift -1))
  1956. (if (eq localp 'verbatim)
  1957. (setq rep "\\\\"
  1958. shift +1))
  1959. (while (string-match "\\(\\\\\\) " file start)
  1960. (setq file (replace-match rep nil t file 1)
  1961. start (+ shift (match-end 0))))))
  1962. (when (eq system-type 'windows-nt)
  1963. (save-match-data
  1964. (let ((start 0))
  1965. (while (string-match "\\\\" file start)
  1966. (aset file (match-beginning 0) ?/)
  1967. (setq start (match-end 0))))))
  1968. ;; Hence we don't need to worry about converting `\\' back to `\'.
  1969. (setq file (read (concat "\"" file "\"")))
  1970. ;; The above `read' will return a unibyte string if FILE
  1971. ;; contains eight-bit-control/graphic characters.
  1972. (if (and enable-multibyte-characters
  1973. (not (multibyte-string-p file)))
  1974. (setq file (string-to-multibyte file)))))
  1975. (and file (file-name-absolute-p file)
  1976. ;; A relative file name can start with ~.
  1977. ;; Don't treat it as absolute in this context.
  1978. (not (eq (aref file 0) ?~))
  1979. (setq already-absolute t))
  1980. (cond
  1981. ((null file)
  1982. nil)
  1983. ((eq localp 'verbatim)
  1984. file)
  1985. ((and (not no-error-if-not-filep)
  1986. (member file '("." "..")))
  1987. (error "Cannot operate on `.' or `..'"))
  1988. ((and (eq localp 'no-dir) already-absolute)
  1989. (file-name-nondirectory file))
  1990. (already-absolute
  1991. (let ((handler (find-file-name-handler file nil)))
  1992. ;; check for safe-magic property so that we won't
  1993. ;; put /: for names that don't really need them.
  1994. ;; For instance, .gz files when auto-compression-mode is on.
  1995. (if (and handler (not (get handler 'safe-magic)))
  1996. (concat "/:" file)
  1997. file)))
  1998. ((eq localp 'no-dir)
  1999. file)
  2000. ((equal (dired-current-directory) "/")
  2001. (setq file (concat (dired-current-directory localp) file))
  2002. (let ((handler (find-file-name-handler file nil)))
  2003. ;; check for safe-magic property so that we won't
  2004. ;; put /: for names that don't really need them.
  2005. ;; For instance, .gz files when auto-compression-mode is on.
  2006. (if (and handler (not (get handler 'safe-magic)))
  2007. (concat "/:" file)
  2008. file)))
  2009. (t
  2010. (concat (dired-current-directory localp) file)))))
  2011. (defun dired-string-replace-match (regexp string newtext
  2012. &optional literal global)
  2013. "Replace first match of REGEXP in STRING with NEWTEXT.
  2014. If it does not match, nil is returned instead of the new string.
  2015. Optional arg LITERAL means to take NEWTEXT literally.
  2016. Optional arg GLOBAL means to replace all matches."
  2017. (if global
  2018. (let ((start 0) ret)
  2019. (while (string-match regexp string start)
  2020. (let ((from-end (- (length string) (match-end 0))))
  2021. (setq ret (setq string (replace-match newtext t literal string)))
  2022. (setq start (- (length string) from-end))))
  2023. ret)
  2024. (if (not (string-match regexp string 0))
  2025. nil
  2026. (replace-match newtext t literal string))))
  2027. (defun dired-make-absolute (file &optional dir)
  2028. ;;"Convert FILE (a file name relative to DIR) to an absolute file name."
  2029. ;; We can't always use expand-file-name as this would get rid of `.'
  2030. ;; or expand in / instead default-directory if DIR=="".
  2031. ;; This should be good enough for ange-ftp.
  2032. ;; It should be reasonably fast, though, as it is called in
  2033. ;; dired-get-filename.
  2034. (concat (or dir default-directory) file))
  2035. (defun dired-make-relative (file &optional dir _ignore)
  2036. "Convert FILE (an absolute file name) to a name relative to DIR.
  2037. If this is impossible, return FILE unchanged.
  2038. DIR must be a directory name, not a file name."
  2039. (or dir (setq dir default-directory))
  2040. ;; This case comes into play if default-directory is set to
  2041. ;; use ~.
  2042. (if (and (> (length dir) 0) (= (aref dir 0) ?~))
  2043. (setq dir (expand-file-name dir)))
  2044. (if (string-match (concat "^" (regexp-quote dir)) file)
  2045. (substring file (match-end 0))
  2046. ;;; (or no-error
  2047. ;;; (error "%s: not in directory tree growing at %s" file dir))
  2048. file))
  2049. ;;; Functions for finding the file name in a dired buffer line.
  2050. (defvar dired-permission-flags-regexp
  2051. "\\([^ ]\\)[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)"
  2052. "Regular expression to match the permission flags in `ls -l'.")
  2053. ;; Move to first char of filename on this line.
  2054. ;; Returns position (point) or nil if no filename on this line."
  2055. (defun dired-move-to-filename (&optional raise-error eol)
  2056. "Move to the beginning of the filename on the current line.
  2057. Return the position of the beginning of the filename, or nil if none found."
  2058. ;; This is the UNIX version.
  2059. (or eol (setq eol (line-end-position)))
  2060. (beginning-of-line)
  2061. ;; First try assuming `ls --dired' was used.
  2062. (let ((change (next-single-property-change (point) 'dired-filename nil eol)))
  2063. (cond
  2064. ((and change (< change eol))
  2065. (goto-char change))
  2066. ((re-search-forward directory-listing-before-filename-regexp eol t)
  2067. (goto-char (match-end 0)))
  2068. ((re-search-forward dired-permission-flags-regexp eol t)
  2069. ;; Ha! There *is* a file. Our regexp-from-hell just failed to find it.
  2070. (if raise-error
  2071. (error "Unrecognized line! Check directory-listing-before-filename-regexp"))
  2072. (beginning-of-line)
  2073. nil)
  2074. (raise-error
  2075. (error "No file on this line")))))
  2076. (defun dired-move-to-end-of-filename (&optional no-error)
  2077. ;; Assumes point is at beginning of filename,
  2078. ;; thus the rwx bit re-search-backward below will succeed in *this*
  2079. ;; line if at all. So, it should be called only after
  2080. ;; (dired-move-to-filename t).
  2081. ;; On failure, signals an error (with non-nil NO-ERROR just returns nil).
  2082. ;; This is the UNIX version.
  2083. (if (get-text-property (point) 'dired-filename)
  2084. (goto-char (next-single-property-change (point) 'dired-filename))
  2085. (let (opoint file-type executable symlink hidden case-fold-search used-F eol)
  2086. ;; case-fold-search is nil now, so we can test for capital F:
  2087. (setq used-F (string-match "F" dired-actual-switches)
  2088. opoint (point)
  2089. eol (line-end-position)
  2090. hidden (and selective-display
  2091. (save-excursion (search-forward "\r" eol t))))
  2092. (if hidden
  2093. nil
  2094. (save-excursion ;; Find out what kind of file this is:
  2095. ;; Restrict perm bits to be non-blank,
  2096. ;; otherwise this matches one char to early (looking backward):
  2097. ;; "l---------" (some systems make symlinks that way)
  2098. ;; "----------" (plain file with zero perms)
  2099. (if (re-search-backward
  2100. dired-permission-flags-regexp nil t)
  2101. (setq file-type (char-after (match-beginning 1))
  2102. symlink (eq file-type ?l)
  2103. ;; Only with -F we need to know whether it's an executable
  2104. executable (and
  2105. used-F
  2106. (string-match
  2107. "[xst]" ;; execute bit set anywhere?
  2108. (concat
  2109. (match-string 2)
  2110. (match-string 3)
  2111. (match-string 4)))))
  2112. (or no-error (error "No file on this line"))))
  2113. ;; Move point to end of name:
  2114. (if symlink
  2115. (if (search-forward " -> " eol t)
  2116. (progn
  2117. (forward-char -4)
  2118. (and used-F
  2119. dired-ls-F-marks-symlinks
  2120. (eq (preceding-char) ?@) ;; did ls really mark the link?
  2121. (forward-char -1))))
  2122. (goto-char eol) ;; else not a symbolic link
  2123. ;; ls -lF marks dirs, sockets, fifos and executables with exactly
  2124. ;; one trailing character. (Executable bits on symlinks ain't mean
  2125. ;; a thing, even to ls, but we know it's not a symlink.)
  2126. (and used-F
  2127. (or (memq file-type '(?d ?s ?p))
  2128. executable)
  2129. (forward-char -1))))
  2130. (or no-error
  2131. (not (eq opoint (point)))
  2132. (error "%s" (if hidden
  2133. (substitute-command-keys
  2134. "File line is hidden, type \\[dired-hide-subdir] to unhide")
  2135. "No file on this line")))
  2136. (if (eq opoint (point))
  2137. nil
  2138. (point)))))
  2139. ;;; COPY NAMES OF MARKED FILES INTO KILL-RING.
  2140. (defun dired-copy-filename-as-kill (&optional arg)
  2141. "Copy names of marked (or next ARG) files into the kill ring.
  2142. The names are separated by a space.
  2143. With a zero prefix arg, use the absolute file name of each marked file.
  2144. With \\[universal-argument], use the file name relative to the dired buffer's
  2145. `default-directory'. (This still may contain slashes if in a subdirectory.)
  2146. If on a subdir headerline, use absolute subdirname instead;
  2147. prefix arg and marked files are ignored in this case.
  2148. You can then feed the file name(s) to other commands with \\[yank]."
  2149. (interactive "P")
  2150. (let ((string
  2151. (or (dired-get-subdir)
  2152. (mapconcat (function identity)
  2153. (if arg
  2154. (cond ((zerop (prefix-numeric-value arg))
  2155. (dired-get-marked-files))
  2156. ((consp arg)
  2157. (dired-get-marked-files t))
  2158. (t
  2159. (dired-get-marked-files
  2160. 'no-dir (prefix-numeric-value arg))))
  2161. (dired-get-marked-files 'no-dir))
  2162. " "))))
  2163. (if (eq last-command 'kill-region)
  2164. (kill-append string nil)
  2165. (kill-new string))
  2166. (message "%s" string)))
  2167. ;; Keeping Dired buffers in sync with the filesystem and with each other
  2168. (defun dired-buffers-for-dir (dir &optional file)
  2169. ;; Return a list of buffers for DIR (top level or in-situ subdir).
  2170. ;; If FILE is non-nil, include only those whose wildcard pattern (if any)
  2171. ;; matches FILE.
  2172. ;; The list is in reverse order of buffer creation, most recent last.
  2173. ;; As a side effect, killed dired buffers for DIR are removed from
  2174. ;; dired-buffers.
  2175. (setq dir (file-name-as-directory dir))
  2176. (let (result buf)
  2177. (dolist (elt dired-buffers)
  2178. (setq buf (cdr elt))
  2179. (cond
  2180. ((null (buffer-name buf))
  2181. ;; Buffer is killed - clean up:
  2182. (setq dired-buffers (delq elt dired-buffers)))
  2183. ((dired-in-this-tree dir (car elt))
  2184. (with-current-buffer buf
  2185. (and (assoc dir dired-subdir-alist)
  2186. (or (null file)
  2187. (if (stringp dired-directory)
  2188. (let ((wildcards (file-name-nondirectory
  2189. dired-directory)))
  2190. (or (= 0 (length wildcards))
  2191. (string-match (dired-glob-regexp wildcards)
  2192. file)))
  2193. (member (expand-file-name file dir)
  2194. (cdr dired-directory))))
  2195. (setq result (cons buf result)))))))
  2196. result))
  2197. (defun dired-glob-regexp (pattern)
  2198. "Convert glob-pattern PATTERN to a regular expression."
  2199. (let ((matched-in-pattern 0) ;; How many chars of PATTERN we've handled.
  2200. regexp)
  2201. (while (string-match "[[?*]" pattern matched-in-pattern)
  2202. (let ((op-end (match-end 0))
  2203. (next-op (aref pattern (match-beginning 0))))
  2204. (setq regexp (concat regexp
  2205. (regexp-quote
  2206. (substring pattern matched-in-pattern
  2207. (match-beginning 0)))))
  2208. (cond ((= next-op ??)
  2209. (setq regexp (concat regexp "."))
  2210. (setq matched-in-pattern op-end))
  2211. ((= next-op ?\[)
  2212. ;; Fails to handle ^ yet ????
  2213. (let* ((set-start (match-beginning 0))
  2214. (set-cont
  2215. (if (= (aref pattern (1+ set-start)) ?^)
  2216. (+ 3 set-start)
  2217. (+ 2 set-start)))
  2218. (set-end (string-match "]" pattern set-cont))
  2219. (set (substring pattern set-start (1+ set-end))))
  2220. (setq regexp (concat regexp set))
  2221. (setq matched-in-pattern (1+ set-end))))
  2222. ((= next-op ?*)
  2223. (setq regexp (concat regexp ".*"))
  2224. (setq matched-in-pattern op-end)))))
  2225. (concat "\\`"
  2226. regexp
  2227. (regexp-quote
  2228. (substring pattern matched-in-pattern))
  2229. "\\'")))
  2230. (defun dired-advertise ()
  2231. ;;"Advertise in variable `dired-buffers' that we dired `default-directory'."
  2232. ;; With wildcards we actually advertise too much.
  2233. (let ((expanded-default (expand-file-name default-directory)))
  2234. (if (memq (current-buffer) (dired-buffers-for-dir expanded-default))
  2235. t ; we have already advertised ourselves
  2236. (setq dired-buffers
  2237. (cons (cons expanded-default (current-buffer))
  2238. dired-buffers)))))
  2239. (defun dired-unadvertise (dir)
  2240. ;; Remove DIR from the buffer alist in variable dired-buffers.
  2241. ;; This has the effect of removing any buffer whose main directory is DIR.
  2242. ;; It does not affect buffers in which DIR is a subdir.
  2243. ;; Removing is also done as a side-effect in dired-buffer-for-dir.
  2244. (setq dired-buffers
  2245. (delq (assoc (expand-file-name dir) dired-buffers) dired-buffers)))
  2246. ;; Tree Dired
  2247. ;;; utility functions
  2248. (defun dired-in-this-tree (file dir)
  2249. ;;"Is FILE part of the directory tree starting at DIR?"
  2250. (let (case-fold-search)
  2251. (string-match (concat "^" (regexp-quote dir)) file)))
  2252. (defun dired-normalize-subdir (dir)
  2253. ;; Prepend default-directory to DIR if relative file name.
  2254. ;; dired-get-filename must be able to make a valid file name from a
  2255. ;; file and its directory DIR.
  2256. (file-name-as-directory
  2257. (if (file-name-absolute-p dir)
  2258. dir
  2259. (expand-file-name dir default-directory))))
  2260. (defun dired-get-subdir ()
  2261. ;;"Return the subdir name on this line, or nil if not on a headerline."
  2262. ;; Look up in the alist whether this is a headerline.
  2263. (save-excursion
  2264. (let ((cur-dir (dired-current-directory)))
  2265. (beginning-of-line) ; alist stores b-o-l positions
  2266. (and (zerop (- (point)
  2267. (dired-get-subdir-min (assoc cur-dir
  2268. dired-subdir-alist))))
  2269. cur-dir))))
  2270. ;(defun dired-get-subdir-min (elt)
  2271. ; (cdr elt))
  2272. ;; can't use macro, must be redefinable for other alist format in dired-nstd.
  2273. (defalias 'dired-get-subdir-min 'cdr)
  2274. (defun dired-get-subdir-max (elt)
  2275. (save-excursion
  2276. (goto-char (dired-get-subdir-min elt))
  2277. (dired-subdir-max)))
  2278. (defun dired-clear-alist ()
  2279. (while dired-subdir-alist
  2280. (set-marker (dired-get-subdir-min (car dired-subdir-alist)) nil)
  2281. (setq dired-subdir-alist (cdr dired-subdir-alist))))
  2282. (defun dired-subdir-index (dir)
  2283. ;; Return an index into alist for use with nth
  2284. ;; for the sake of subdir moving commands.
  2285. (let (found (index 0) (alist dired-subdir-alist))
  2286. (while alist
  2287. (if (string= dir (car (car alist)))
  2288. (setq alist nil found t)
  2289. (setq alist (cdr alist) index (1+ index))))
  2290. (if found index nil)))
  2291. (defun dired-next-subdir (arg &optional no-error-if-not-found no-skip)
  2292. "Go to next subdirectory, regardless of level."
  2293. ;; Use 0 arg to go to this directory's header line.
  2294. ;; NO-SKIP prevents moving to end of header line, returning whatever
  2295. ;; position was found in dired-subdir-alist.
  2296. (interactive "p")
  2297. (let ((this-dir (dired-current-directory))
  2298. pos index)
  2299. ;; nth with negative arg does not return nil but the first element
  2300. (setq index (- (dired-subdir-index this-dir) arg))
  2301. (setq pos (if (>= index 0)
  2302. (dired-get-subdir-min (nth index dired-subdir-alist))))
  2303. (if pos
  2304. (progn
  2305. (goto-char pos)
  2306. (or no-skip (skip-chars-forward "^\n\r"))
  2307. (point))
  2308. (if no-error-if-not-found
  2309. nil ; return nil if not found
  2310. (error "%s directory" (if (> arg 0) "Last" "First"))))))
  2311. (defun dired-build-subdir-alist (&optional switches)
  2312. "Build `dired-subdir-alist' by parsing the buffer.
  2313. Returns the new value of the alist.
  2314. If optional arg SWITCHES is non-nil, use its value
  2315. instead of `dired-actual-switches'."
  2316. (interactive)
  2317. (dired-clear-alist)
  2318. (save-excursion
  2319. (let* ((count 0)
  2320. (inhibit-read-only t)
  2321. (buffer-undo-list t)
  2322. (switches (or switches dired-actual-switches))
  2323. new-dir-name
  2324. (R-ftp-base-dir-regex
  2325. ;; Used to expand subdirectory names correctly in recursive
  2326. ;; ange-ftp listings.
  2327. (and (string-match "R" switches)
  2328. (string-match "\\`/.*:\\(/.*\\)" default-directory)
  2329. (concat "\\`" (match-string 1 default-directory)))))
  2330. (goto-char (point-min))
  2331. (setq dired-subdir-alist nil)
  2332. (while (re-search-forward dired-subdir-regexp nil t)
  2333. ;; Avoid taking a file name ending in a colon
  2334. ;; as a subdir name.
  2335. (unless (save-excursion
  2336. (goto-char (match-beginning 0))
  2337. (beginning-of-line)
  2338. (forward-char 2)
  2339. (save-match-data (looking-at dired-re-perms)))
  2340. (save-excursion
  2341. (goto-char (match-beginning 1))
  2342. (setq new-dir-name
  2343. (buffer-substring-no-properties (point) (match-end 1))
  2344. new-dir-name
  2345. (save-match-data
  2346. (if (and R-ftp-base-dir-regex
  2347. (not (string= new-dir-name default-directory))
  2348. (string-match R-ftp-base-dir-regex new-dir-name))
  2349. (concat default-directory
  2350. (substring new-dir-name (match-end 0)))
  2351. (expand-file-name new-dir-name))))
  2352. (delete-region (point) (match-end 1))
  2353. (insert new-dir-name))
  2354. (setq count (1+ count))
  2355. ;; Undo any escaping of newlines and \ by dired-insert-directory.
  2356. ;; Convert "n" preceded by odd number of \ to newline, and \\ to \.
  2357. (when (and (dired-switches-escape-p switches)
  2358. (string-match-p "\\\\" new-dir-name))
  2359. (let (temp res)
  2360. (mapc (lambda (char)
  2361. (cond ((equal char ?\\)
  2362. (if temp
  2363. (setq res (concat res "\\")
  2364. temp nil)
  2365. (setq temp "\\")))
  2366. ((and temp (equal char ?n))
  2367. (setq res (concat res "\n")
  2368. temp nil))
  2369. (t
  2370. (setq res (concat res temp (char-to-string char))
  2371. temp nil))))
  2372. new-dir-name)
  2373. (setq new-dir-name res)))
  2374. (dired-alist-add-1 new-dir-name
  2375. ;; Place a sub directory boundary between lines.
  2376. (save-excursion
  2377. (goto-char (match-beginning 0))
  2378. (beginning-of-line)
  2379. (point-marker)))))
  2380. (if (and (> count 1) (called-interactively-p 'interactive))
  2381. (message "Buffer includes %d directories" count)))
  2382. ;; We don't need to sort it because it is in buffer order per
  2383. ;; constructionem. Return new alist:
  2384. dired-subdir-alist))
  2385. (defun dired-alist-add-1 (dir new-marker)
  2386. ;; Add new DIR at NEW-MARKER. Don't sort.
  2387. (setq dired-subdir-alist
  2388. (cons (cons (dired-normalize-subdir dir) new-marker)
  2389. dired-subdir-alist)))
  2390. (defun dired-goto-next-nontrivial-file ()
  2391. ;; Position point on first nontrivial file after point.
  2392. (dired-goto-next-file);; so there is a file to compare with
  2393. (if (stringp dired-trivial-filenames)
  2394. (while (and (not (eobp))
  2395. (string-match dired-trivial-filenames
  2396. (file-name-nondirectory
  2397. (or (dired-get-filename nil t) ""))))
  2398. (forward-line 1)
  2399. (dired-move-to-filename))))
  2400. (defun dired-goto-next-file ()
  2401. (let ((max (1- (dired-subdir-max))))
  2402. (while (and (not (dired-move-to-filename)) (< (point) max))
  2403. (forward-line 1))))
  2404. (defun dired-goto-file (file)
  2405. "Go to line describing file FILE in this dired buffer."
  2406. ;; Return value of point on success, else nil.
  2407. ;; FILE must be an absolute file name.
  2408. ;; Loses if FILE contains control chars like "\007" for which ls
  2409. ;; either inserts "?" or "\\007" into the buffer, so we won't find
  2410. ;; it in the buffer.
  2411. (interactive
  2412. (prog1 ; let push-mark display its message
  2413. (list (expand-file-name
  2414. (read-file-name "Goto file: "
  2415. (dired-current-directory))))
  2416. (push-mark)))
  2417. (unless (file-name-absolute-p file)
  2418. (error "File name `%s' is not absolute" file))
  2419. (setq file (directory-file-name file)) ; does no harm if not a directory
  2420. (let* ((case-fold-search nil)
  2421. (dir (file-name-directory file))
  2422. (found (or
  2423. ;; First, look for a listing under the absolute name.
  2424. (save-excursion
  2425. (goto-char (point-min))
  2426. (dired-goto-file-1 file file (point-max)))
  2427. ;; Otherwise, look for it as a relative name. The
  2428. ;; hair is to get the result of `dired-goto-subdir'
  2429. ;; without calling it if we don't have any subdirs.
  2430. (save-excursion
  2431. (when (if (string= dir (expand-file-name default-directory))
  2432. (goto-char (point-min))
  2433. (and (cdr dired-subdir-alist)
  2434. (dired-goto-subdir dir)))
  2435. (dired-goto-file-1 (file-name-nondirectory file)
  2436. file
  2437. (dired-subdir-max)))))))
  2438. ;; Return buffer position, if found.
  2439. (if found
  2440. (goto-char found))))
  2441. (defun dired-goto-file-1 (file full-name limit)
  2442. "Advance to the Dired listing labeled by FILE; return its position.
  2443. Return nil if the listing is not found. If FILE contains
  2444. characters that would not appear in a Dired buffer, search using
  2445. the quoted forms of those characters.
  2446. FULL-NAME specifies the actual file name the listing must have,
  2447. as returned by `dired-get-filename'. LIMIT is the search limit."
  2448. (let (str)
  2449. (setq str (replace-regexp-in-string "\^m" "\\^m" file nil t))
  2450. (setq str (replace-regexp-in-string "\\\\" "\\\\" str nil t))
  2451. (and (dired-switches-escape-p dired-actual-switches)
  2452. (string-match "[ \t\n]" str)
  2453. ;; FIXME: to fix this for embedded control characters etc, we
  2454. ;; should escape everything that `ls -b' does.
  2455. (setq str (replace-regexp-in-string " " "\\ " str nil t)
  2456. str (replace-regexp-in-string "\t" "\\t" str nil t)
  2457. str (replace-regexp-in-string "\n" "\\n" str nil t)))
  2458. (let ((found nil)
  2459. ;; filenames are preceded by SPC, this makes the search faster
  2460. ;; (e.g. for the filename "-").
  2461. (search-string (concat " " str)))
  2462. (while (and (not found)
  2463. (search-forward search-string limit 'move))
  2464. ;; Check that we are in the right place. Match could have
  2465. ;; BASE just as initial substring or in permission bits etc.
  2466. (if (equal full-name (dired-get-filename nil t))
  2467. (setq found (dired-move-to-filename))
  2468. (forward-line 1)))
  2469. found)))
  2470. (defvar dired-find-subdir)
  2471. ;; FIXME document whatever dired-x is doing.
  2472. (defun dired-initial-position (dirname)
  2473. "Where point should go in a new listing of DIRNAME.
  2474. Point assumed at beginning of new subdir line."
  2475. (end-of-line)
  2476. (and (featurep 'dired-x) dired-find-subdir
  2477. (dired-goto-subdir dirname))
  2478. (if dired-trivial-filenames (dired-goto-next-nontrivial-file)))
  2479. ;; These are hooks which make tree dired work.
  2480. ;; They are in this file because other parts of dired need to call them.
  2481. ;; But they don't call the rest of tree dired unless there are subdirs loaded.
  2482. ;; This function is called for each retrieved filename.
  2483. ;; It could stand to be faster, though it's mostly function call
  2484. ;; overhead. Avoiding the function call seems to save about 10% in
  2485. ;; dired-get-filename. Make it a defsubst?
  2486. (defun dired-current-directory (&optional localp)
  2487. "Return the name of the subdirectory to which this line belongs.
  2488. This returns a string with trailing slash, like `default-directory'.
  2489. Optional argument means return a file name relative to `default-directory'."
  2490. (let ((here (point))
  2491. (alist (or dired-subdir-alist
  2492. ;; probably because called in a non-dired buffer
  2493. (error "No subdir-alist in %s" (current-buffer))))
  2494. elt dir)
  2495. (while alist
  2496. (setq elt (car alist)
  2497. dir (car elt)
  2498. ;; use `<=' (not `<') as subdir line is part of subdir
  2499. alist (if (<= (dired-get-subdir-min elt) here)
  2500. nil ; found
  2501. (cdr alist))))
  2502. (if localp
  2503. (dired-make-relative dir default-directory)
  2504. dir)))
  2505. ;; Subdirs start at the beginning of their header lines and end just
  2506. ;; before the beginning of the next header line (or end of buffer).
  2507. (defun dired-subdir-max ()
  2508. (save-excursion
  2509. (if (or (null (cdr dired-subdir-alist)) (not (dired-next-subdir 1 t t)))
  2510. (point-max)
  2511. (point))))
  2512. ;; Deleting files
  2513. (defcustom dired-recursive-deletes 'top
  2514. "Decide whether recursive deletes are allowed.
  2515. A value of nil means no recursive deletes.
  2516. `always' means delete recursively without asking. This is DANGEROUS!
  2517. `top' means ask for each directory at top level, but delete its subdirectories
  2518. without asking.
  2519. Anything else means ask for each directory."
  2520. :type '(choice :tag "Delete non-empty directories"
  2521. (const :tag "Yes" always)
  2522. (const :tag "No--only delete empty directories" nil)
  2523. (const :tag "Confirm for each directory" t)
  2524. (const :tag "Confirm for each top directory only" top))
  2525. :group 'dired)
  2526. ;; Match anything but `.' and `..'.
  2527. (defvar dired-re-no-dot "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*")
  2528. ;; Delete file, possibly delete a directory and all its files.
  2529. ;; This function is useful outside of dired. One could change its name
  2530. ;; to e.g. recursive-delete-file and put it somewhere else.
  2531. (defun dired-delete-file (file &optional recursive trash) "\
  2532. Delete FILE or directory (possibly recursively if optional RECURSIVE is true.)
  2533. RECURSIVE determines what to do with a non-empty directory. If RECURSIVE is:
  2534. nil, do not delete.
  2535. `always', delete recursively without asking.
  2536. `top', ask for each directory at top level.
  2537. Anything else, ask for each sub-directory."
  2538. ;; This test is equivalent to
  2539. ;; (and (file-directory-p fn) (not (file-symlink-p fn)))
  2540. ;; but more efficient
  2541. (if (not (eq t (car (file-attributes file))))
  2542. (delete-file file trash)
  2543. (if (and recursive
  2544. (directory-files file t dired-re-no-dot) ; Not empty.
  2545. (or (eq recursive 'always)
  2546. (yes-or-no-p (format "Recursively %s %s? "
  2547. (if (and trash
  2548. delete-by-moving-to-trash)
  2549. "trash"
  2550. "delete")
  2551. (dired-make-relative file)))))
  2552. (if (eq recursive 'top) (setq recursive 'always)) ; Don't ask again.
  2553. (setq recursive nil))
  2554. (delete-directory file recursive trash)))
  2555. (defun dired-do-flagged-delete (&optional nomessage)
  2556. "In Dired, delete the files flagged for deletion.
  2557. If NOMESSAGE is non-nil, we don't display any message
  2558. if there are no flagged files.
  2559. `dired-recursive-deletes' controls whether deletion of
  2560. non-empty directories is allowed."
  2561. (interactive)
  2562. (let* ((dired-marker-char dired-del-marker)
  2563. (regexp (dired-marker-regexp))
  2564. case-fold-search)
  2565. (if (save-excursion (goto-char (point-min))
  2566. (re-search-forward regexp nil t))
  2567. (dired-internal-do-deletions
  2568. ;; this can't move point since ARG is nil
  2569. (dired-map-over-marks (cons (dired-get-filename) (point))
  2570. nil)
  2571. nil t)
  2572. (or nomessage
  2573. (message "(No deletions requested)")))))
  2574. (defun dired-do-delete (&optional arg)
  2575. "Delete all marked (or next ARG) files.
  2576. `dired-recursive-deletes' controls whether deletion of
  2577. non-empty directories is allowed."
  2578. ;; This is more consistent with the file marking feature than
  2579. ;; dired-do-flagged-delete.
  2580. (interactive "P")
  2581. (dired-internal-do-deletions
  2582. ;; this may move point if ARG is an integer
  2583. (dired-map-over-marks (cons (dired-get-filename) (point))
  2584. arg)
  2585. arg t))
  2586. (defvar dired-deletion-confirmer 'yes-or-no-p) ; or y-or-n-p?
  2587. (defun dired-internal-do-deletions (l arg &optional trash)
  2588. ;; L is an alist of files to delete, with their buffer positions.
  2589. ;; ARG is the prefix arg.
  2590. ;; Filenames are absolute.
  2591. ;; (car L) *must* be the *last* (bottommost) file in the dired buffer.
  2592. ;; That way as changes are made in the buffer they do not shift the
  2593. ;; lines still to be changed, so the (point) values in L stay valid.
  2594. ;; Also, for subdirs in natural order, a subdir's files are deleted
  2595. ;; before the subdir itself - the other way around would not work.
  2596. (let* ((files (mapcar (function car) l))
  2597. (count (length l))
  2598. (succ 0)
  2599. (trashing (and trash delete-by-moving-to-trash))
  2600. (progress-reporter
  2601. (make-progress-reporter
  2602. (if trashing "Trashing..." "Deleting...")
  2603. succ count)))
  2604. ;; canonicalize file list for pop up
  2605. (setq files (nreverse (mapcar (function dired-make-relative) files)))
  2606. (if (dired-mark-pop-up
  2607. " *Deletions*" 'delete files dired-deletion-confirmer
  2608. (format "%s %s "
  2609. (if trashing "Trash" "Delete")
  2610. (dired-mark-prompt arg files)))
  2611. (save-excursion
  2612. (let (failures);; files better be in reverse order for this loop!
  2613. (while l
  2614. (goto-char (cdr (car l)))
  2615. (let ((inhibit-read-only t))
  2616. (condition-case err
  2617. (let ((fn (car (car l))))
  2618. (dired-delete-file fn dired-recursive-deletes trash)
  2619. ;; if we get here, removing worked
  2620. (setq succ (1+ succ))
  2621. (progress-reporter-update progress-reporter succ)
  2622. (dired-fun-in-all-buffers
  2623. (file-name-directory fn) (file-name-nondirectory fn)
  2624. (function dired-delete-entry) fn))
  2625. (error;; catch errors from failed deletions
  2626. (dired-log "%s\n" err)
  2627. (setq failures (cons (car (car l)) failures)))))
  2628. (setq l (cdr l)))
  2629. (if (not failures)
  2630. (progress-reporter-done progress-reporter)
  2631. (dired-log-summary
  2632. (format "%d of %d deletion%s failed"
  2633. (length failures) count
  2634. (dired-plural-s count))
  2635. failures))))
  2636. (message "(No deletions performed)")))
  2637. (dired-move-to-filename))
  2638. (defun dired-fun-in-all-buffers (directory file fun &rest args)
  2639. ;; In all buffers dired'ing DIRECTORY, run FUN with ARGS.
  2640. ;; If the buffer has a wildcard pattern, check that it matches FILE.
  2641. ;; (FILE does not include a directory component.)
  2642. ;; FILE may be nil, in which case ignore it.
  2643. ;; Return list of buffers where FUN succeeded (i.e., returned non-nil).
  2644. (let (success-list)
  2645. (dolist (buf (dired-buffers-for-dir (expand-file-name directory)
  2646. file))
  2647. (with-current-buffer buf
  2648. (if (apply fun args)
  2649. (setq success-list (cons (buffer-name buf) success-list)))))
  2650. success-list))
  2651. ;; Delete the entry for FILE from
  2652. (defun dired-delete-entry (file)
  2653. (save-excursion
  2654. (and (dired-goto-file file)
  2655. (let ((inhibit-read-only t))
  2656. (delete-region (progn (beginning-of-line) (point))
  2657. (save-excursion (forward-line 1) (point))))))
  2658. (dired-clean-up-after-deletion file))
  2659. (defvar dired-clean-up-buffers-too)
  2660. (defun dired-clean-up-after-deletion (fn)
  2661. "Clean up after a deleted file or directory FN.
  2662. Removes any expanded subdirectory of deleted directory.
  2663. If `dired-x' is loaded and `dired-clean-up-buffers-too' is non-nil,
  2664. also offers to kill buffers visiting deleted files and directories."
  2665. (save-excursion (and (cdr dired-subdir-alist)
  2666. (dired-goto-subdir fn)
  2667. (dired-kill-subdir)))
  2668. ;; Offer to kill buffer of deleted file FN.
  2669. (when (and (featurep 'dired-x) dired-clean-up-buffers-too)
  2670. (let ((buf (get-file-buffer fn)))
  2671. (and buf
  2672. (funcall #'y-or-n-p
  2673. (format "Kill buffer of %s, too? "
  2674. (file-name-nondirectory fn)))
  2675. (kill-buffer buf)))
  2676. (let ((buf-list (dired-buffers-for-dir (expand-file-name fn))))
  2677. (and buf-list
  2678. (y-or-n-p (format "Kill dired buffer%s of %s, too? "
  2679. (dired-plural-s (length buf-list))
  2680. (file-name-nondirectory fn)))
  2681. (dolist (buf buf-list)
  2682. (kill-buffer buf))))))
  2683. ;; Confirmation
  2684. (defun dired-marker-regexp ()
  2685. (concat "^" (regexp-quote (char-to-string dired-marker-char))))
  2686. (defun dired-plural-s (count)
  2687. (if (= 1 count) "" "s"))
  2688. (defun dired-mark-prompt (arg files)
  2689. "Return a string suitable for use in a Dired prompt.
  2690. ARG is normally the prefix argument for the calling command.
  2691. FILES should be a list of file names.
  2692. The return value has a form like \"foo.txt\", \"[next 3 files]\",
  2693. or \"* [3 files]\"."
  2694. ;; distinguish-one-marked can cause the first element to be just t.
  2695. (if (eq (car files) t) (setq files (cdr files)))
  2696. (let ((count (length files)))
  2697. (if (= count 1)
  2698. (car files)
  2699. ;; more than 1 file:
  2700. (if (integerp arg)
  2701. ;; abs(arg) = count
  2702. ;; Perhaps this is nicer, but it also takes more screen space:
  2703. ;;(format "[%s %d files]" (if (> arg 0) "next" "previous")
  2704. ;; count)
  2705. (format "[next %d files]" arg)
  2706. (format "%c [%d files]" dired-marker-char count)))))
  2707. (defun dired-pop-to-buffer (buf)
  2708. "Pop up buffer BUF in a way suitable for Dired."
  2709. (let ((split-window-preferred-function
  2710. (lambda (window)
  2711. (or (and (let ((split-height-threshold 0))
  2712. (window-splittable-p (selected-window)))
  2713. ;; Try to split the selected window vertically if
  2714. ;; that's possible. (Bug#1806)
  2715. (split-window-below))
  2716. ;; Otherwise, try to split WINDOW sensibly.
  2717. (split-window-sensibly window))))
  2718. pop-up-frames)
  2719. (pop-to-buffer (get-buffer-create buf)))
  2720. ;; If dired-shrink-to-fit is t, make its window fit its contents.
  2721. (when dired-shrink-to-fit
  2722. ;; Try to not delete window when we want to display less than
  2723. ;; `window-min-height' lines.
  2724. (fit-window-to-buffer (get-buffer-window buf) nil 1)))
  2725. (defcustom dired-no-confirm nil
  2726. "A list of symbols for commands Dired should not confirm, or t.
  2727. Command symbols are `byte-compile', `chgrp', `chmod', `chown', `compress',
  2728. `copy', `delete', `hardlink', `load', `move', `print', `shell', `symlink',
  2729. `touch' and `uncompress'.
  2730. If t, confirmation is never needed."
  2731. :group 'dired
  2732. :type '(choice (const :tag "Confirmation never needed" t)
  2733. (set (const byte-compile) (const chgrp)
  2734. (const chmod) (const chown) (const compress)
  2735. (const copy) (const delete) (const hardlink)
  2736. (const load) (const move) (const print)
  2737. (const shell) (const symlink) (const touch)
  2738. (const uncompress))))
  2739. (defun dired-mark-pop-up (bufname op-symbol files function &rest args)
  2740. "Return FUNCTION's result on ARGS after showing which files are marked.
  2741. Displays the file names in a buffer named BUFNAME;
  2742. nil gives \" *Marked Files*\".
  2743. This uses function `dired-pop-to-buffer' to do that.
  2744. FUNCTION should not manipulate files, just read input
  2745. (an argument or confirmation).
  2746. The window is not shown if there is just one file or
  2747. OP-SYMBOL is a member of the list in `dired-no-confirm'.
  2748. FILES is the list of marked files. It can also be (t FILENAME)
  2749. in the case of one marked file, to distinguish that from using
  2750. just the current file."
  2751. (or bufname (setq bufname " *Marked Files*"))
  2752. (if (or (eq dired-no-confirm t)
  2753. (memq op-symbol dired-no-confirm)
  2754. ;; If FILES defaulted to the current line's file.
  2755. (= (length files) 1))
  2756. (apply function args)
  2757. (with-current-buffer (get-buffer-create bufname)
  2758. (erase-buffer)
  2759. ;; Handle (t FILE) just like (FILE), here.
  2760. ;; That value is used (only in some cases), to mean
  2761. ;; just one file that was marked, rather than the current line file.
  2762. (dired-format-columns-of-files (if (eq (car files) t) (cdr files) files))
  2763. (remove-text-properties (point-min) (point-max)
  2764. '(mouse-face nil help-echo nil)))
  2765. (save-window-excursion
  2766. (dired-pop-to-buffer bufname)
  2767. (apply function args))))
  2768. (defun dired-format-columns-of-files (files)
  2769. (let ((beg (point)))
  2770. (completion--insert-strings files)
  2771. (put-text-property beg (point) 'mouse-face nil)))
  2772. ;; Commands to mark or flag file(s) at or near current line.
  2773. (defun dired-repeat-over-lines (arg function)
  2774. ;; This version skips non-file lines.
  2775. (let ((pos (make-marker)))
  2776. (beginning-of-line)
  2777. (while (and (> arg 0) (not (eobp)))
  2778. (setq arg (1- arg))
  2779. (beginning-of-line)
  2780. (while (and (not (eobp)) (dired-between-files)) (forward-line 1))
  2781. (save-excursion
  2782. (forward-line 1)
  2783. (move-marker pos (1+ (point))))
  2784. (save-excursion (funcall function))
  2785. ;; Advance to the next line--actually, to the line that *was* next.
  2786. ;; (If FUNCTION inserted some new lines in between, skip them.)
  2787. (goto-char pos))
  2788. (while (and (< arg 0) (not (bobp)))
  2789. (setq arg (1+ arg))
  2790. (forward-line -1)
  2791. (while (and (not (bobp)) (dired-between-files)) (forward-line -1))
  2792. (beginning-of-line)
  2793. (save-excursion (funcall function)))
  2794. (move-marker pos nil)
  2795. (dired-move-to-filename)))
  2796. (defun dired-between-files ()
  2797. ;; This used to be a regexp match of the `total ...' line output by
  2798. ;; ls, which is slightly faster, but that is not very robust; notably,
  2799. ;; it fails for non-english locales.
  2800. (save-excursion (not (dired-move-to-filename))))
  2801. (defun dired-next-marked-file (arg &optional wrap opoint)
  2802. "Move to the next marked file, wrapping around the end of the buffer."
  2803. (interactive "p\np")
  2804. (or opoint (setq opoint (point)));; return to where interactively started
  2805. (if (if (> arg 0)
  2806. (re-search-forward dired-re-mark nil t arg)
  2807. (beginning-of-line)
  2808. (re-search-backward dired-re-mark nil t (- arg)))
  2809. (dired-move-to-filename)
  2810. (if (null wrap)
  2811. (progn
  2812. (goto-char opoint)
  2813. (error "No next marked file"))
  2814. (message "(Wraparound for next marked file)")
  2815. (goto-char (if (> arg 0) (point-min) (point-max)))
  2816. (dired-next-marked-file arg nil opoint))))
  2817. (defun dired-prev-marked-file (arg &optional wrap)
  2818. "Move to the previous marked file, wrapping around the end of the buffer."
  2819. (interactive "p\np")
  2820. (dired-next-marked-file (- arg) wrap))
  2821. (defun dired-file-marker (file)
  2822. ;; Return FILE's marker, or nil if unmarked.
  2823. (save-excursion
  2824. (and (dired-goto-file file)
  2825. (progn
  2826. (beginning-of-line)
  2827. (if (not (equal ?\040 (following-char)))
  2828. (following-char))))))
  2829. (defun dired-mark-files-in-region (start end)
  2830. (let ((inhibit-read-only t))
  2831. (if (> start end)
  2832. (error "start > end"))
  2833. (goto-char start) ; assumed at beginning of line
  2834. (while (< (point) end)
  2835. ;; Skip subdir line and following garbage like the `total' line:
  2836. (while (and (< (point) end) (dired-between-files))
  2837. (forward-line 1))
  2838. (if (and (not (looking-at dired-re-dot))
  2839. (dired-get-filename nil t))
  2840. (progn
  2841. (delete-char 1)
  2842. (insert dired-marker-char)))
  2843. (forward-line 1))))
  2844. (defun dired-mark (arg)
  2845. "Mark the current (or next ARG) files.
  2846. If on a subdir headerline, mark all its files except `.' and `..'.
  2847. Use \\[dired-unmark-all-files] to remove all marks
  2848. and \\[dired-unmark] on a subdir to remove the marks in
  2849. this subdir."
  2850. (interactive "P")
  2851. (if (dired-get-subdir)
  2852. (save-excursion (dired-mark-subdir-files))
  2853. (let ((inhibit-read-only t))
  2854. (dired-repeat-over-lines
  2855. (prefix-numeric-value arg)
  2856. (function (lambda () (delete-char 1) (insert dired-marker-char)))))))
  2857. (defun dired-unmark (arg)
  2858. "Unmark the current (or next ARG) files.
  2859. If looking at a subdir, unmark all its files except `.' and `..'."
  2860. (interactive "P")
  2861. (let ((dired-marker-char ?\040))
  2862. (dired-mark arg)))
  2863. (defun dired-flag-file-deletion (arg)
  2864. "In Dired, flag the current line's file for deletion.
  2865. With prefix arg, repeat over several lines.
  2866. If on a subdir headerline, mark all its files except `.' and `..'."
  2867. (interactive "P")
  2868. (let ((dired-marker-char dired-del-marker))
  2869. (dired-mark arg)))
  2870. (defun dired-unmark-backward (arg)
  2871. "In Dired, move up lines and remove marks or deletion flags there.
  2872. Optional prefix ARG says how many lines to unmark/unflag; default
  2873. is one line."
  2874. (interactive "p")
  2875. (dired-unmark (- arg)))
  2876. (defun dired-toggle-marks ()
  2877. "Toggle marks: marked files become unmarked, and vice versa.
  2878. Files marked with other flags (such as `D') are not affected.
  2879. `.' and `..' are never toggled.
  2880. As always, hidden subdirs are not affected."
  2881. (interactive)
  2882. (save-excursion
  2883. (goto-char (point-min))
  2884. (let ((inhibit-read-only t))
  2885. (while (not (eobp))
  2886. (or (dired-between-files)
  2887. (looking-at dired-re-dot)
  2888. ;; use subst instead of insdel because it does not move
  2889. ;; the gap and thus should be faster and because
  2890. ;; other characters are left alone automatically
  2891. (apply 'subst-char-in-region
  2892. (point) (1+ (point))
  2893. (if (eq ?\040 (following-char)) ; SPC
  2894. (list ?\040 dired-marker-char)
  2895. (list dired-marker-char ?\040))))
  2896. (forward-line 1)))))
  2897. ;;; Commands to mark or flag files based on their characteristics or names.
  2898. (defvar dired-regexp-history nil
  2899. "History list of regular expressions used in Dired commands.")
  2900. (defun dired-read-regexp (prompt)
  2901. (read-from-minibuffer prompt nil nil nil 'dired-regexp-history))
  2902. (defun dired-mark-files-regexp (regexp &optional marker-char)
  2903. "Mark all files matching REGEXP for use in later commands.
  2904. A prefix argument means to unmark them instead.
  2905. `.' and `..' are never marked.
  2906. REGEXP is an Emacs regexp, not a shell wildcard. Thus, use `\\.o$' for
  2907. object files--just `.o' will mark more than you might think."
  2908. (interactive
  2909. (list (dired-read-regexp (concat (if current-prefix-arg "Unmark" "Mark")
  2910. " files (regexp): "))
  2911. (if current-prefix-arg ?\040)))
  2912. (let ((dired-marker-char (or marker-char dired-marker-char)))
  2913. (dired-mark-if
  2914. (and (not (looking-at dired-re-dot))
  2915. (not (eolp)) ; empty line
  2916. (let ((fn (dired-get-filename t t)))
  2917. (and fn (string-match regexp fn))))
  2918. "matching file")))
  2919. (defun dired-mark-files-containing-regexp (regexp &optional marker-char)
  2920. "Mark all files with contents containing REGEXP for use in later commands.
  2921. A prefix argument means to unmark them instead.
  2922. `.' and `..' are never marked."
  2923. (interactive
  2924. (list (dired-read-regexp (concat (if current-prefix-arg "Unmark" "Mark")
  2925. " files containing (regexp): "))
  2926. (if current-prefix-arg ?\040)))
  2927. (let ((dired-marker-char (or marker-char dired-marker-char)))
  2928. (dired-mark-if
  2929. (and (not (looking-at dired-re-dot))
  2930. (not (eolp)) ; empty line
  2931. (let ((fn (dired-get-filename nil t)))
  2932. (when (and fn (file-readable-p fn)
  2933. (not (file-directory-p fn)))
  2934. (let ((prebuf (get-file-buffer fn)))
  2935. (message "Checking %s" fn)
  2936. ;; For now we do it inside emacs
  2937. ;; Grep might be better if there are a lot of files
  2938. (if prebuf
  2939. (with-current-buffer prebuf
  2940. (save-excursion
  2941. (goto-char (point-min))
  2942. (re-search-forward regexp nil t)))
  2943. (with-temp-buffer
  2944. (insert-file-contents fn)
  2945. (goto-char (point-min))
  2946. (re-search-forward regexp nil t))))
  2947. )))
  2948. "matching file")))
  2949. (defun dired-flag-files-regexp (regexp)
  2950. "In Dired, flag all files containing the specified REGEXP for deletion.
  2951. The match is against the non-directory part of the filename. Use `^'
  2952. and `$' to anchor matches. Exclude subdirs by hiding them.
  2953. `.' and `..' are never flagged."
  2954. (interactive (list (dired-read-regexp "Flag for deletion (regexp): ")))
  2955. (dired-mark-files-regexp regexp dired-del-marker))
  2956. (defun dired-mark-symlinks (unflag-p)
  2957. "Mark all symbolic links.
  2958. With prefix argument, unmark or unflag all those files."
  2959. (interactive "P")
  2960. (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)))
  2961. (dired-mark-if (looking-at dired-re-sym) "symbolic link")))
  2962. (defun dired-mark-directories (unflag-p)
  2963. "Mark all directory file lines except `.' and `..'.
  2964. With prefix argument, unmark or unflag all those files."
  2965. (interactive "P")
  2966. (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)))
  2967. (dired-mark-if (and (looking-at dired-re-dir)
  2968. (not (looking-at dired-re-dot)))
  2969. "directory file")))
  2970. (defun dired-mark-executables (unflag-p)
  2971. "Mark all executable files.
  2972. With prefix argument, unmark or unflag all those files."
  2973. (interactive "P")
  2974. (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)))
  2975. (dired-mark-if (looking-at dired-re-exe) "executable file")))
  2976. ;; dired-x.el has a dired-mark-sexp interactive command: mark
  2977. ;; files for which PREDICATE returns non-nil.
  2978. (defun dired-flag-auto-save-files (&optional unflag-p)
  2979. "Flag for deletion files whose names suggest they are auto save files.
  2980. A prefix argument says to unmark or unflag those files instead."
  2981. (interactive "P")
  2982. (let ((dired-marker-char (if unflag-p ?\040 dired-del-marker)))
  2983. (dired-mark-if
  2984. ;; It is less than general to check for # here,
  2985. ;; but it's the only way this runs fast enough.
  2986. (and (save-excursion (end-of-line)
  2987. (or
  2988. (eq (preceding-char) ?#)
  2989. ;; Handle executables in case of -F option.
  2990. ;; We need not worry about the other kinds
  2991. ;; of markings that -F makes, since they won't
  2992. ;; appear on real auto-save files.
  2993. (if (eq (preceding-char) ?*)
  2994. (progn
  2995. (forward-char -1)
  2996. (eq (preceding-char) ?#)))))
  2997. (not (looking-at dired-re-dir))
  2998. (let ((fn (dired-get-filename t t)))
  2999. (if fn (auto-save-file-name-p
  3000. (file-name-nondirectory fn)))))
  3001. "auto save file")))
  3002. (defcustom dired-garbage-files-regexp
  3003. ;; `log' here is dubious, since it's typically used for useful log
  3004. ;; files, not just TeX stuff. -- fx
  3005. (concat (regexp-opt
  3006. '(".log" ".toc" ".dvi" ".bak" ".orig" ".rej" ".aux"))
  3007. "\\'")
  3008. "Regular expression to match \"garbage\" files for `dired-flag-garbage-files'."
  3009. :type 'regexp
  3010. :group 'dired)
  3011. (defun dired-flag-garbage-files ()
  3012. "Flag for deletion all files that match `dired-garbage-files-regexp'."
  3013. (interactive)
  3014. (dired-flag-files-regexp dired-garbage-files-regexp))
  3015. (defun dired-flag-backup-files (&optional unflag-p)
  3016. "Flag all backup files (names ending with `~') for deletion.
  3017. With prefix argument, unmark or unflag these files."
  3018. (interactive "P")
  3019. (let ((dired-marker-char (if unflag-p ?\s dired-del-marker)))
  3020. (dired-mark-if
  3021. ;; Don't call backup-file-name-p unless the last character looks like
  3022. ;; it might be the end of a backup file name. This isn't very general,
  3023. ;; but it's the only way this runs fast enough.
  3024. (and (save-excursion (end-of-line)
  3025. ;; Handle executables in case of -F option.
  3026. ;; We need not worry about the other kinds
  3027. ;; of markings that -F makes, since they won't
  3028. ;; appear on real backup files.
  3029. (if (eq (preceding-char) ?*)
  3030. (forward-char -1))
  3031. (eq (preceding-char) ?~))
  3032. (not (looking-at dired-re-dir))
  3033. (let ((fn (dired-get-filename t t)))
  3034. (if fn (backup-file-name-p fn))))
  3035. "backup file")))
  3036. (defun dired-change-marks (&optional old new)
  3037. "Change all OLD marks to NEW marks.
  3038. OLD and NEW are both characters used to mark files."
  3039. (interactive
  3040. (let* ((cursor-in-echo-area t)
  3041. (old (progn (message "Change (old mark): ") (read-char)))
  3042. (new (progn (message "Change %c marks to (new mark): " old)
  3043. (read-char))))
  3044. (list old new)))
  3045. (if (or (eq old ?\r) (eq new ?\r))
  3046. (ding)
  3047. (let ((string (format "\n%c" old))
  3048. (inhibit-read-only t))
  3049. (save-excursion
  3050. (goto-char (point-min))
  3051. (while (search-forward string nil t)
  3052. (if (if (= old ?\s)
  3053. (save-match-data
  3054. (dired-get-filename 'no-dir t))
  3055. t)
  3056. (subst-char-in-region (match-beginning 0)
  3057. (match-end 0) old new)))))))
  3058. (defun dired-unmark-all-marks ()
  3059. "Remove all marks from all files in the dired buffer."
  3060. (interactive)
  3061. (dired-unmark-all-files ?\r))
  3062. (defun dired-unmark-all-files (mark &optional arg)
  3063. "Remove a specific mark (or any mark) from every file.
  3064. After this command, type the mark character to remove,
  3065. or type RET to remove all marks.
  3066. With prefix arg, query for each marked file.
  3067. Type \\[help-command] at that time for help."
  3068. (interactive "cRemove marks (RET means all): \nP")
  3069. (save-excursion
  3070. (let* ((count 0)
  3071. (inhibit-read-only t) case-fold-search
  3072. (string (format "\n%c" mark))
  3073. (help-form "\
  3074. Type SPC or `y' to unmark one file, DEL or `n' to skip to next,
  3075. `!' to unmark all remaining files with no more questions."))
  3076. (goto-char (point-min))
  3077. (while (if (eq mark ?\r)
  3078. (re-search-forward dired-re-mark nil t)
  3079. (search-forward string nil t))
  3080. (if (or (not arg)
  3081. (let ((file (dired-get-filename t t)))
  3082. (and file
  3083. (dired-query 'query "Unmark file `%s'? "
  3084. file))))
  3085. (progn (subst-char-in-region (1- (point)) (point)
  3086. (preceding-char) ?\s)
  3087. (setq count (1+ count)))))
  3088. (message (if (= count 1) "1 mark removed"
  3089. "%d marks removed")
  3090. count))))
  3091. ;; Logging failures operating on files, and showing the results.
  3092. (defvar dired-log-buffer "*Dired log*")
  3093. (defun dired-why ()
  3094. "Pop up a buffer with error log output from Dired.
  3095. A group of errors from a single command ends with a formfeed.
  3096. Thus, use \\[backward-page] to find the beginning of a group of errors."
  3097. (interactive)
  3098. (if (get-buffer dired-log-buffer)
  3099. (let ((owindow (selected-window))
  3100. (window (display-buffer (get-buffer dired-log-buffer))))
  3101. (unwind-protect
  3102. (progn
  3103. (select-window window)
  3104. (goto-char (point-max))
  3105. (forward-line -1)
  3106. (backward-page 1)
  3107. (recenter 0))
  3108. (select-window owindow)))))
  3109. (defun dired-log (log &rest args)
  3110. ;; Log a message or the contents of a buffer.
  3111. ;; If LOG is a string and there are more args, it is formatted with
  3112. ;; those ARGS. Usually the LOG string ends with a \n.
  3113. ;; End each bunch of errors with (dired-log t):
  3114. ;; this inserts the current time and buffer at the start of the page,
  3115. ;; and \f (formfeed) at the end.
  3116. (let ((obuf (current-buffer)))
  3117. (with-current-buffer (get-buffer-create dired-log-buffer)
  3118. (goto-char (point-max))
  3119. (let ((inhibit-read-only t))
  3120. (cond ((stringp log)
  3121. (insert (if args
  3122. (apply (function format) log args)
  3123. log)))
  3124. ((bufferp log)
  3125. (insert-buffer-substring log))
  3126. ((eq t log)
  3127. (backward-page 1)
  3128. (unless (bolp)
  3129. (insert "\n"))
  3130. (insert (current-time-string)
  3131. "\tBuffer `" (buffer-name obuf) "'\n")
  3132. (goto-char (point-max))
  3133. (insert "\f\n")))))))
  3134. (defun dired-log-summary (string failures)
  3135. "State a summary of a command's failures, in echo area and log buffer.
  3136. STRING is an overall summary of the failures.
  3137. FAILURES is a list of file names that we failed to operate on,
  3138. or nil if file names are not applicable."
  3139. (if (= (length failures) 1)
  3140. (message "%s"
  3141. (with-current-buffer dired-log-buffer
  3142. (goto-char (point-max))
  3143. (backward-page 1)
  3144. (if (eolp) (forward-line 1))
  3145. (buffer-substring (point) (point-max))))
  3146. (message (if failures "%s--type ? for details (%s)"
  3147. "%s--type ? for details")
  3148. string failures))
  3149. ;; Log a summary describing a bunch of errors.
  3150. (dired-log (concat "\n" string "\n"))
  3151. (dired-log t))
  3152. ;;; Sorting
  3153. ;; Most ls can only sort by name or by date (with -t), nothing else.
  3154. ;; GNU ls sorts on size with -S, on extension with -X, and unsorted with -U.
  3155. ;; So anything that does not contain these is sort "by name".
  3156. (defvar dired-ls-sorting-switches "SXU"
  3157. "String of `ls' switches \(single letters\) except \"t\" that influence sorting.
  3158. This indicates to Dired which option switches to watch out for because they
  3159. will change the sorting order behavior of `ls'.
  3160. To change the default sorting order \(e.g. add a `-v' option\), see the
  3161. variable `dired-listing-switches'. To temporarily override the listing
  3162. format, use `\\[universal-argument] \\[dired]'.")
  3163. (defvar dired-sort-by-date-regexp
  3164. (concat "\\(\\`\\| \\)-[^- ]*t"
  3165. ;; `dired-ls-sorting-switches' after -t overrides -t.
  3166. "[^ " dired-ls-sorting-switches "]*"
  3167. "\\(\\(\\`\\| +\\)\\(--[^ ]+\\|-[^- t"
  3168. dired-ls-sorting-switches "]+\\)\\)* *$")
  3169. "Regexp recognized by Dired to set `by date' mode.")
  3170. (defvar dired-sort-by-name-regexp
  3171. (concat "\\`\\(\\(\\`\\| +\\)\\(--[^ ]+\\|"
  3172. "-[^- t" dired-ls-sorting-switches "]+\\)\\)* *$")
  3173. "Regexp recognized by Dired to set `by name' mode.")
  3174. (defvar dired-sort-inhibit nil
  3175. "Non-nil means the Dired sort command is disabled.
  3176. The idea is to set this buffer-locally in special dired buffers.")
  3177. (defun dired-sort-set-modeline ()
  3178. ;; Set modeline display according to dired-actual-switches.
  3179. ;; Modeline display of "by name" or "by date" guarantees the user a
  3180. ;; match with the corresponding regexps. Non-matching switches are
  3181. ;; shown literally.
  3182. (when (eq major-mode 'dired-mode)
  3183. (setq mode-name
  3184. (let (case-fold-search)
  3185. (cond ((string-match
  3186. dired-sort-by-name-regexp dired-actual-switches)
  3187. "Dired by name")
  3188. ((string-match
  3189. dired-sort-by-date-regexp dired-actual-switches)
  3190. "Dired by date")
  3191. (t
  3192. (concat "Dired " dired-actual-switches)))))
  3193. (force-mode-line-update)))
  3194. (defun dired-sort-toggle-or-edit (&optional arg)
  3195. "Toggle sorting by date, and refresh the Dired buffer.
  3196. With a prefix argument, edit the current listing switches instead."
  3197. (interactive "P")
  3198. (when dired-sort-inhibit
  3199. (error "Cannot sort this dired buffer"))
  3200. (if arg
  3201. (dired-sort-other
  3202. (read-string "ls switches (must contain -l): " dired-actual-switches))
  3203. (dired-sort-toggle)))
  3204. (defun dired-sort-toggle ()
  3205. ;; Toggle between sort by date/name. Reverts the buffer.
  3206. (let ((sorting-by-date (string-match dired-sort-by-date-regexp
  3207. dired-actual-switches))
  3208. ;; Regexp for finding (possibly embedded) -t switches.
  3209. (switch-regexp "\\(\\`\\| \\)-\\([a-su-zA-Z]*\\)\\(t\\)\\([^ ]*\\)")
  3210. case-fold-search)
  3211. ;; Remove the -t switch.
  3212. (while (string-match switch-regexp dired-actual-switches)
  3213. (if (and (equal (match-string 2 dired-actual-switches) "")
  3214. (equal (match-string 4 dired-actual-switches) ""))
  3215. ;; Remove a stand-alone -t switch.
  3216. (setq dired-actual-switches
  3217. (replace-match "" t t dired-actual-switches))
  3218. ;; Remove a switch of the form -XtY for some X and Y.
  3219. (setq dired-actual-switches
  3220. (replace-match "" t t dired-actual-switches 3))))
  3221. ;; Now, if we weren't sorting by date before, add the -t switch.
  3222. (unless sorting-by-date
  3223. (setq dired-actual-switches (concat dired-actual-switches " -t"))))
  3224. (dired-sort-set-modeline)
  3225. (revert-buffer))
  3226. ;; Some user code loads dired especially for this.
  3227. ;; Don't do that--use replace-regexp-in-string instead.
  3228. (defun dired-replace-in-string (regexp newtext string)
  3229. ;; Replace REGEXP with NEWTEXT everywhere in STRING and return result.
  3230. ;; NEWTEXT is taken literally---no \\DIGIT escapes will be recognized.
  3231. (let ((result "") (start 0) mb me)
  3232. (while (string-match regexp string start)
  3233. (setq mb (match-beginning 0)
  3234. me (match-end 0)
  3235. result (concat result (substring string start mb) newtext)
  3236. start me))
  3237. (concat result (substring string start))))
  3238. (defun dired-sort-other (switches &optional no-revert)
  3239. "Specify new `ls' SWITCHES for current dired buffer.
  3240. Values matching `dired-sort-by-date-regexp' or `dired-sort-by-name-regexp'
  3241. set the minor mode accordingly, others appear literally in the mode line.
  3242. With optional second arg NO-REVERT, don't refresh the listing afterwards."
  3243. (dired-sort-R-check switches)
  3244. (setq dired-actual-switches switches)
  3245. (dired-sort-set-modeline)
  3246. (or no-revert (revert-buffer)))
  3247. (defvar dired-subdir-alist-pre-R nil
  3248. "Value of `dired-subdir-alist' before -R switch added.")
  3249. (make-variable-buffer-local 'dired-subdir-alist-pre-R)
  3250. (defun dired-sort-R-check (switches)
  3251. "Additional processing of -R in ls option string SWITCHES.
  3252. Saves `dired-subdir-alist' when R is set and restores saved value
  3253. minus any directories explicitly deleted when R is cleared.
  3254. To be called first in body of `dired-sort-other', etc."
  3255. (cond
  3256. ((and (string-match "R" switches)
  3257. (not (string-match "R" dired-actual-switches)))
  3258. ;; Adding -R to ls switches -- save `dired-subdir-alist':
  3259. (setq dired-subdir-alist-pre-R dired-subdir-alist))
  3260. ((and (string-match "R" dired-actual-switches)
  3261. (not (string-match "R" switches)))
  3262. ;; Deleting -R from ls switches -- revert to pre-R subdirs
  3263. ;; that are still present:
  3264. (setq dired-subdir-alist
  3265. (if dired-subdir-alist-pre-R
  3266. (let (subdirs)
  3267. (while dired-subdir-alist-pre-R
  3268. (if (assoc (caar dired-subdir-alist-pre-R)
  3269. dired-subdir-alist)
  3270. ;; subdir still present...
  3271. (setq subdirs
  3272. (cons (car dired-subdir-alist-pre-R)
  3273. subdirs)))
  3274. (setq dired-subdir-alist-pre-R
  3275. (cdr dired-subdir-alist-pre-R)))
  3276. (reverse subdirs))
  3277. ;; No pre-R subdir alist, so revert to main directory
  3278. ;; listing:
  3279. (list (car (reverse dired-subdir-alist))))))))
  3280. ;;;; Drag and drop support
  3281. (defcustom dired-recursive-copies 'top
  3282. "Decide whether recursive copies are allowed.
  3283. A value of nil means no recursive copies.
  3284. `always' means copy recursively without asking.
  3285. `top' means ask for each directory at top level.
  3286. Anything else means ask for each directory."
  3287. :type '(choice :tag "Copy directories"
  3288. (const :tag "No recursive copies" nil)
  3289. (const :tag "Ask for each directory" t)
  3290. (const :tag "Ask for each top directory only" top)
  3291. (const :tag "Copy directories without asking" always))
  3292. :group 'dired)
  3293. (defun dired-dnd-popup-notice ()
  3294. (message-box
  3295. "Dired recursive copies are currently disabled.\nSee the variable `dired-recursive-copies'."))
  3296. (declare-function x-popup-menu "menu.c" (position menu))
  3297. (defun dired-dnd-do-ask-action (uri)
  3298. ;; No need to get actions and descriptions from the source,
  3299. ;; we only have three actions anyway.
  3300. (let ((action (x-popup-menu
  3301. t
  3302. (list "What action?"
  3303. (cons ""
  3304. '(("Copy here" . copy)
  3305. ("Move here" . move)
  3306. ("Link here" . link)
  3307. "--"
  3308. ("Cancel" . nil)))))))
  3309. (if action
  3310. (dired-dnd-handle-local-file uri action)
  3311. nil)))
  3312. (declare-function dired-relist-entry "dired-aux" (file))
  3313. (declare-function make-symbolic-link "fileio.c")
  3314. ;; Only used when (featurep 'dnd).
  3315. (declare-function dnd-get-local-file-name "dnd" (uri &optional must-exist))
  3316. (declare-function dnd-get-local-file-uri "dnd" (uri))
  3317. (defvar dired-overwrite-confirmed) ;Defined in dired-aux.
  3318. (defun dired-dnd-handle-local-file (uri action)
  3319. "Copy, move or link a file to the dired directory.
  3320. URI is the file to handle, ACTION is one of copy, move, link or ask.
  3321. Ask means pop up a menu for the user to select one of copy, move or link."
  3322. (require 'dired-aux)
  3323. (let* ((from (dnd-get-local-file-name uri t))
  3324. (to (when from
  3325. (concat (dired-current-directory)
  3326. (file-name-nondirectory from)))))
  3327. (when from
  3328. (cond ((eq action 'ask)
  3329. (dired-dnd-do-ask-action uri))
  3330. ;; If copying a directory and dired-recursive-copies is
  3331. ;; nil, dired-copy-file fails. Pop up a notice.
  3332. ((and (memq action '(copy private))
  3333. (file-directory-p from)
  3334. (not dired-recursive-copies))
  3335. (dired-dnd-popup-notice))
  3336. ((memq action '(copy private move link))
  3337. (let ((overwrite (and (file-exists-p to)
  3338. (y-or-n-p
  3339. (format "Overwrite existing file `%s'? " to))))
  3340. ;; Binding dired-overwrite-confirmed to nil makes
  3341. ;; dired-handle-overwrite a no-op. We instead use
  3342. ;; y-or-n-p, which pops a graphical menu.
  3343. dired-overwrite-confirmed backup-file)
  3344. (when (and overwrite
  3345. ;; d-b-o is defined in dired-aux.
  3346. (boundp 'dired-backup-overwrite)
  3347. dired-backup-overwrite
  3348. (setq backup-file
  3349. (car (find-backup-file-name to)))
  3350. (or (eq dired-backup-overwrite 'always)
  3351. (y-or-n-p
  3352. (format
  3353. "Make backup for existing file `%s'? " to))))
  3354. (rename-file to backup-file 0)
  3355. (dired-relist-entry backup-file))
  3356. (cond ((memq action '(copy private))
  3357. (dired-copy-file from to overwrite))
  3358. ((eq action 'move)
  3359. (dired-rename-file from to overwrite))
  3360. ((eq action 'link)
  3361. (make-symbolic-link from to overwrite)))
  3362. (dired-relist-entry to)
  3363. action))))))
  3364. (defun dired-dnd-handle-file (uri action)
  3365. "Copy, move or link a file to the dired directory if it is a local file.
  3366. URI is the file to handle. If the hostname in the URI isn't local, do nothing.
  3367. ACTION is one of copy, move, link or ask.
  3368. Ask means pop up a menu for the user to select one of copy, move or link."
  3369. (let ((local-file (dnd-get-local-file-uri uri)))
  3370. (if local-file (dired-dnd-handle-local-file local-file action)
  3371. nil)))
  3372. ;;;; Desktop support
  3373. (eval-when-compile (require 'desktop))
  3374. (defun dired-desktop-buffer-misc-data (dirname)
  3375. "Auxiliary information to be saved in desktop file."
  3376. (cons
  3377. ;; Value of `dired-directory'.
  3378. (if (consp dired-directory)
  3379. ;; Directory name followed by list of files.
  3380. (cons (desktop-file-name (car dired-directory) dirname)
  3381. (cdr dired-directory))
  3382. ;; Directory name, optionally with shell wildcard.
  3383. (desktop-file-name dired-directory dirname))
  3384. ;; Subdirectories in `dired-subdir-alist'.
  3385. (cdr
  3386. (nreverse
  3387. (mapcar
  3388. (function (lambda (f) (desktop-file-name (car f) dirname)))
  3389. dired-subdir-alist)))))
  3390. (defun dired-restore-desktop-buffer (_file-name
  3391. _buffer-name
  3392. misc-data)
  3393. "Restore a dired buffer specified in a desktop file."
  3394. ;; First element of `misc-data' is the value of `dired-directory'.
  3395. ;; This value is a directory name, optionally with shell wildcard or
  3396. ;; a directory name followed by list of files.
  3397. (let* ((dired-dir (car misc-data))
  3398. (dir (if (consp dired-dir) (car dired-dir) dired-dir)))
  3399. (if (file-directory-p (file-name-directory dir))
  3400. (progn
  3401. (dired dired-dir)
  3402. ;; The following elements of `misc-data' are the keys
  3403. ;; from `dired-subdir-alist'.
  3404. (mapc 'dired-maybe-insert-subdir (cdr misc-data))
  3405. (current-buffer))
  3406. (message "Desktop: Directory %s no longer exists." dir)
  3407. (when desktop-missing-file-warning (sit-for 1))
  3408. nil)))
  3409. (add-to-list 'desktop-buffer-mode-handlers
  3410. '(dired-mode . dired-restore-desktop-buffer))
  3411. ;;; Start of automatically extracted autoloads.
  3412. ;;;### (autoloads (dired-show-file-type dired-do-query-replace-regexp
  3413. ;;;;;; dired-do-search dired-do-isearch-regexp dired-do-isearch
  3414. ;;;;;; dired-isearch-filenames-regexp dired-isearch-filenames dired-isearch-filenames-setup
  3415. ;;;;;; dired-hide-all dired-hide-subdir dired-tree-down dired-tree-up
  3416. ;;;;;; dired-kill-subdir dired-mark-subdir-files dired-goto-subdir
  3417. ;;;;;; dired-prev-subdir dired-insert-subdir dired-maybe-insert-subdir
  3418. ;;;;;; dired-downcase dired-upcase dired-do-symlink-regexp dired-do-hardlink-regexp
  3419. ;;;;;; dired-do-copy-regexp dired-do-rename-regexp dired-do-rename
  3420. ;;;;;; dired-do-hardlink dired-do-symlink dired-do-copy dired-create-directory
  3421. ;;;;;; dired-rename-file dired-copy-file dired-relist-file dired-remove-file
  3422. ;;;;;; dired-add-file dired-do-redisplay dired-do-load dired-do-byte-compile
  3423. ;;;;;; dired-do-compress dired-query dired-compress-file dired-do-kill-lines
  3424. ;;;;;; dired-run-shell-command dired-do-shell-command dired-do-async-shell-command
  3425. ;;;;;; dired-clean-directory dired-do-print dired-do-touch dired-do-chown
  3426. ;;;;;; dired-do-chgrp dired-do-chmod dired-compare-directories dired-backup-diff
  3427. ;;;;;; dired-diff) "dired-aux" "dired-aux.el" "58d623eb8e68e472e6164a1bcae83360")
  3428. ;;; Generated autoloads from dired-aux.el
  3429. (autoload 'dired-diff "dired-aux" "\
  3430. Compare file at point with file FILE using `diff'.
  3431. FILE defaults to the file at the mark. (That's the mark set by
  3432. \\[set-mark-command], not by Dired's \\[dired-mark] command.)
  3433. The prompted-for FILE is the first file given to `diff'.
  3434. With prefix arg, prompt for second argument SWITCHES,
  3435. which is the string of command switches for `diff'.
  3436. \(fn FILE &optional SWITCHES)" t nil)
  3437. (autoload 'dired-backup-diff "dired-aux" "\
  3438. Diff this file with its backup file or vice versa.
  3439. Uses the latest backup, if there are several numerical backups.
  3440. If this file is a backup, diff it with its original.
  3441. The backup file is the first file given to `diff'.
  3442. With prefix arg, prompt for argument SWITCHES which is options for `diff'.
  3443. \(fn &optional SWITCHES)" t nil)
  3444. (autoload 'dired-compare-directories "dired-aux" "\
  3445. Mark files with different file attributes in two dired buffers.
  3446. Compare file attributes of files in the current directory
  3447. with file attributes in directory DIR2 using PREDICATE on pairs of files
  3448. with the same name. Mark files for which PREDICATE returns non-nil.
  3449. Mark files with different names if PREDICATE is nil (or interactively
  3450. with empty input at the predicate prompt).
  3451. PREDICATE is a Lisp expression that can refer to the following variables:
  3452. size1, size2 - file size in bytes
  3453. mtime1, mtime2 - last modification time in seconds, as a float
  3454. fa1, fa2 - list of file attributes
  3455. returned by function `file-attributes'
  3456. where 1 refers to attribute of file in the current dired buffer
  3457. and 2 to attribute of file in second dired buffer.
  3458. Examples of PREDICATE:
  3459. (> mtime1 mtime2) - mark newer files
  3460. (not (= size1 size2)) - mark files with different sizes
  3461. (not (string= (nth 8 fa1) (nth 8 fa2))) - mark files with different modes
  3462. (not (and (= (nth 2 fa1) (nth 2 fa2)) - mark files with different UID
  3463. (= (nth 3 fa1) (nth 3 fa2)))) and GID.
  3464. \(fn DIR2 PREDICATE)" t nil)
  3465. (autoload 'dired-do-chmod "dired-aux" "\
  3466. Change the mode of the marked (or next ARG) files.
  3467. Symbolic modes like `g+w' are allowed.
  3468. \(fn &optional ARG)" t nil)
  3469. (autoload 'dired-do-chgrp "dired-aux" "\
  3470. Change the group of the marked (or next ARG) files.
  3471. \(fn &optional ARG)" t nil)
  3472. (autoload 'dired-do-chown "dired-aux" "\
  3473. Change the owner of the marked (or next ARG) files.
  3474. \(fn &optional ARG)" t nil)
  3475. (autoload 'dired-do-touch "dired-aux" "\
  3476. Change the timestamp of the marked (or next ARG) files.
  3477. This calls touch.
  3478. \(fn &optional ARG)" t nil)
  3479. (autoload 'dired-do-print "dired-aux" "\
  3480. Print the marked (or next ARG) files.
  3481. Uses the shell command coming from variables `lpr-command' and
  3482. `lpr-switches' as default.
  3483. \(fn &optional ARG)" t nil)
  3484. (autoload 'dired-clean-directory "dired-aux" "\
  3485. Flag numerical backups for deletion.
  3486. Spares `dired-kept-versions' latest versions, and `kept-old-versions' oldest.
  3487. Positive prefix arg KEEP overrides `dired-kept-versions';
  3488. Negative prefix arg KEEP overrides `kept-old-versions' with KEEP made positive.
  3489. To clear the flags on these files, you can use \\[dired-flag-backup-files]
  3490. with a prefix argument.
  3491. \(fn KEEP)" t nil)
  3492. (autoload 'dired-do-async-shell-command "dired-aux" "\
  3493. Run a shell command COMMAND on the marked files asynchronously.
  3494. Like `dired-do-shell-command' but if COMMAND doesn't end in ampersand,
  3495. adds `* &' surrounded by whitespace and executes the command asynchronously.
  3496. The output appears in the buffer `*Async Shell Command*'.
  3497. \(fn COMMAND &optional ARG FILE-LIST)" t nil)
  3498. (autoload 'dired-do-shell-command "dired-aux" "\
  3499. Run a shell command COMMAND on the marked files.
  3500. If no files are marked or a specific numeric prefix arg is given,
  3501. the next ARG files are used. Just \\[universal-argument] means the current file.
  3502. The prompt mentions the file(s) or the marker, as appropriate.
  3503. If there is a `*' in COMMAND, surrounded by whitespace, this runs
  3504. COMMAND just once with the entire file list substituted there.
  3505. If there is no `*', but there is a `?' in COMMAND, surrounded by
  3506. whitespace, this runs COMMAND on each file individually with the
  3507. file name substituted for `?'.
  3508. Otherwise, this runs COMMAND on each file individually with the
  3509. file name added at the end of COMMAND (separated by a space).
  3510. `*' and `?' when not surrounded by whitespace have no special
  3511. significance for `dired-do-shell-command', and are passed through
  3512. normally to the shell, but you must confirm first.
  3513. If you want to use `*' as a shell wildcard with whitespace around
  3514. it, write `*\"\"' in place of just `*'. This is equivalent to just
  3515. `*' in the shell, but avoids Dired's special handling.
  3516. If COMMAND produces output, it goes to a separate buffer.
  3517. This feature does not try to redisplay Dired buffers afterward, as
  3518. there's no telling what files COMMAND may have changed.
  3519. Type \\[dired-do-redisplay] to redisplay the marked files.
  3520. When COMMAND runs, its working directory is the top-level directory
  3521. of the Dired buffer, so output files usually are created there
  3522. instead of in a subdir.
  3523. In a noninteractive call (from Lisp code), you must specify
  3524. the list of file names explicitly with the FILE-LIST argument, which
  3525. can be produced by `dired-get-marked-files', for example.
  3526. \(fn COMMAND &optional ARG FILE-LIST)" t nil)
  3527. (autoload 'dired-run-shell-command "dired-aux" "\
  3528. \(fn COMMAND)" nil nil)
  3529. (autoload 'dired-do-kill-lines "dired-aux" "\
  3530. Kill all marked lines (not the files).
  3531. With a prefix argument, kill that many lines starting with the current line.
  3532. \(A negative argument kills backward.)
  3533. If you use this command with a prefix argument to kill the line
  3534. for a file that is a directory, which you have inserted in the
  3535. Dired buffer as a subdirectory, then it deletes that subdirectory
  3536. from the buffer as well.
  3537. To kill an entire subdirectory (without killing its line in the
  3538. parent directory), go to its directory header line and use this
  3539. command with a prefix argument (the value does not matter).
  3540. \(fn &optional ARG FMT)" t nil)
  3541. (autoload 'dired-compress-file "dired-aux" "\
  3542. \(fn FILE)" nil nil)
  3543. (autoload 'dired-query "dired-aux" "\
  3544. Format PROMPT with ARGS, query user, and store the result in SYM.
  3545. The return value is either nil or t.
  3546. The user may type y or SPC to accept once; n or DEL to skip once;
  3547. ! to accept this and subsequent queries; or q or ESC to decline
  3548. this and subsequent queries.
  3549. If SYM is already bound to a non-nil value, this function may
  3550. return automatically without querying the user. If SYM is !,
  3551. return t; if SYM is q or ESC, return nil.
  3552. \(fn SYM PROMPT &rest ARGS)" nil nil)
  3553. (autoload 'dired-do-compress "dired-aux" "\
  3554. Compress or uncompress marked (or next ARG) files.
  3555. \(fn &optional ARG)" t nil)
  3556. (autoload 'dired-do-byte-compile "dired-aux" "\
  3557. Byte compile marked (or next ARG) Emacs Lisp files.
  3558. \(fn &optional ARG)" t nil)
  3559. (autoload 'dired-do-load "dired-aux" "\
  3560. Load the marked (or next ARG) Emacs Lisp files.
  3561. \(fn &optional ARG)" t nil)
  3562. (autoload 'dired-do-redisplay "dired-aux" "\
  3563. Redisplay all marked (or next ARG) files.
  3564. If on a subdir line, redisplay that subdirectory. In that case,
  3565. a prefix arg lets you edit the `ls' switches used for the new listing.
  3566. Dired remembers switches specified with a prefix arg, so that reverting
  3567. the buffer will not reset them. However, using `dired-undo' to re-insert
  3568. or delete subdirectories can bypass this machinery. Hence, you sometimes
  3569. may have to reset some subdirectory switches after a `dired-undo'.
  3570. You can reset all subdirectory switches to the default using
  3571. \\<dired-mode-map>\\[dired-reset-subdir-switches].
  3572. See Info node `(emacs)Subdir switches' for more details.
  3573. \(fn &optional ARG TEST-FOR-SUBDIR)" t nil)
  3574. (autoload 'dired-add-file "dired-aux" "\
  3575. \(fn FILENAME &optional MARKER-CHAR)" nil nil)
  3576. (autoload 'dired-remove-file "dired-aux" "\
  3577. \(fn FILE)" nil nil)
  3578. (autoload 'dired-relist-file "dired-aux" "\
  3579. Create or update the line for FILE in all Dired buffers it would belong in.
  3580. \(fn FILE)" nil nil)
  3581. (autoload 'dired-copy-file "dired-aux" "\
  3582. \(fn FROM TO OK-FLAG)" nil nil)
  3583. (autoload 'dired-rename-file "dired-aux" "\
  3584. \(fn FILE NEWNAME OK-IF-ALREADY-EXISTS)" nil nil)
  3585. (autoload 'dired-create-directory "dired-aux" "\
  3586. Create a directory called DIRECTORY.
  3587. If DIRECTORY already exists, signal an error.
  3588. \(fn DIRECTORY)" t nil)
  3589. (autoload 'dired-do-copy "dired-aux" "\
  3590. Copy all marked (or next ARG) files, or copy the current file.
  3591. This normally preserves the last-modified date when copying.
  3592. When operating on just the current file, you specify the new name.
  3593. When operating on multiple or marked files, you specify a directory,
  3594. and new copies of these files are made in that directory
  3595. with the same names that the files currently have. The default
  3596. suggested for the target directory depends on the value of
  3597. `dired-dwim-target', which see.
  3598. This command copies symbolic links by creating new ones,
  3599. like `cp -d'.
  3600. \(fn &optional ARG)" t nil)
  3601. (autoload 'dired-do-symlink "dired-aux" "\
  3602. Make symbolic links to current file or all marked (or next ARG) files.
  3603. When operating on just the current file, you specify the new name.
  3604. When operating on multiple or marked files, you specify a directory
  3605. and new symbolic links are made in that directory
  3606. with the same names that the files currently have. The default
  3607. suggested for the target directory depends on the value of
  3608. `dired-dwim-target', which see.
  3609. For relative symlinks, use \\[dired-do-relsymlink].
  3610. \(fn &optional ARG)" t nil)
  3611. (autoload 'dired-do-hardlink "dired-aux" "\
  3612. Add names (hard links) current file or all marked (or next ARG) files.
  3613. When operating on just the current file, you specify the new name.
  3614. When operating on multiple or marked files, you specify a directory
  3615. and new hard links are made in that directory
  3616. with the same names that the files currently have. The default
  3617. suggested for the target directory depends on the value of
  3618. `dired-dwim-target', which see.
  3619. \(fn &optional ARG)" t nil)
  3620. (autoload 'dired-do-rename "dired-aux" "\
  3621. Rename current file or all marked (or next ARG) files.
  3622. When renaming just the current file, you specify the new name.
  3623. When renaming multiple or marked files, you specify a directory.
  3624. This command also renames any buffers that are visiting the files.
  3625. The default suggested for the target directory depends on the value
  3626. of `dired-dwim-target', which see.
  3627. \(fn &optional ARG)" t nil)
  3628. (autoload 'dired-do-rename-regexp "dired-aux" "\
  3629. Rename selected files whose names match REGEXP to NEWNAME.
  3630. With non-zero prefix argument ARG, the command operates on the next ARG
  3631. files. Otherwise, it operates on all the marked files, or the current
  3632. file if none are marked.
  3633. As each match is found, the user must type a character saying
  3634. what to do with it. For directions, type \\[help-command] at that time.
  3635. NEWNAME may contain \\=\\<n> or \\& as in `query-replace-regexp'.
  3636. REGEXP defaults to the last regexp used.
  3637. With a zero prefix arg, renaming by regexp affects the absolute file name.
  3638. Normally, only the non-directory part of the file name is used and changed.
  3639. \(fn REGEXP NEWNAME &optional ARG WHOLE-NAME)" t nil)
  3640. (autoload 'dired-do-copy-regexp "dired-aux" "\
  3641. Copy selected files whose names match REGEXP to NEWNAME.
  3642. See function `dired-do-rename-regexp' for more info.
  3643. \(fn REGEXP NEWNAME &optional ARG WHOLE-NAME)" t nil)
  3644. (autoload 'dired-do-hardlink-regexp "dired-aux" "\
  3645. Hardlink selected files whose names match REGEXP to NEWNAME.
  3646. See function `dired-do-rename-regexp' for more info.
  3647. \(fn REGEXP NEWNAME &optional ARG WHOLE-NAME)" t nil)
  3648. (autoload 'dired-do-symlink-regexp "dired-aux" "\
  3649. Symlink selected files whose names match REGEXP to NEWNAME.
  3650. See function `dired-do-rename-regexp' for more info.
  3651. \(fn REGEXP NEWNAME &optional ARG WHOLE-NAME)" t nil)
  3652. (autoload 'dired-upcase "dired-aux" "\
  3653. Rename all marked (or next ARG) files to upper case.
  3654. \(fn &optional ARG)" t nil)
  3655. (autoload 'dired-downcase "dired-aux" "\
  3656. Rename all marked (or next ARG) files to lower case.
  3657. \(fn &optional ARG)" t nil)
  3658. (autoload 'dired-maybe-insert-subdir "dired-aux" "\
  3659. Insert this subdirectory into the same dired buffer.
  3660. If it is already present, just move to it (type \\[dired-do-redisplay] to refresh),
  3661. else inserts it at its natural place (as `ls -lR' would have done).
  3662. With a prefix arg, you may edit the ls switches used for this listing.
  3663. You can add `R' to the switches to expand the whole tree starting at
  3664. this subdirectory.
  3665. This function takes some pains to conform to `ls -lR' output.
  3666. Dired remembers switches specified with a prefix arg, so that reverting
  3667. the buffer will not reset them. However, using `dired-undo' to re-insert
  3668. or delete subdirectories can bypass this machinery. Hence, you sometimes
  3669. may have to reset some subdirectory switches after a `dired-undo'.
  3670. You can reset all subdirectory switches to the default using
  3671. \\<dired-mode-map>\\[dired-reset-subdir-switches].
  3672. See Info node `(emacs)Subdir switches' for more details.
  3673. \(fn DIRNAME &optional SWITCHES NO-ERROR-IF-NOT-DIR-P)" t nil)
  3674. (autoload 'dired-insert-subdir "dired-aux" "\
  3675. Insert this subdirectory into the same dired buffer.
  3676. If it is already present, overwrites previous entry,
  3677. else inserts it at its natural place (as `ls -lR' would have done).
  3678. With a prefix arg, you may edit the `ls' switches used for this listing.
  3679. You can add `R' to the switches to expand the whole tree starting at
  3680. this subdirectory.
  3681. This function takes some pains to conform to `ls -lR' output.
  3682. \(fn DIRNAME &optional SWITCHES NO-ERROR-IF-NOT-DIR-P)" t nil)
  3683. (autoload 'dired-prev-subdir "dired-aux" "\
  3684. Go to previous subdirectory, regardless of level.
  3685. When called interactively and not on a subdir line, go to this subdir's line.
  3686. \(fn ARG &optional NO-ERROR-IF-NOT-FOUND NO-SKIP)" t nil)
  3687. (autoload 'dired-goto-subdir "dired-aux" "\
  3688. Go to end of header line of DIR in this dired buffer.
  3689. Return value of point on success, otherwise return nil.
  3690. The next char is either \\n, or \\r if DIR is hidden.
  3691. \(fn DIR)" t nil)
  3692. (autoload 'dired-mark-subdir-files "dired-aux" "\
  3693. Mark all files except `.' and `..' in current subdirectory.
  3694. If the Dired buffer shows multiple directories, this command
  3695. marks the files listed in the subdirectory that point is in.
  3696. \(fn)" t nil)
  3697. (autoload 'dired-kill-subdir "dired-aux" "\
  3698. Remove all lines of current subdirectory.
  3699. Lower levels are unaffected.
  3700. \(fn &optional REMEMBER-MARKS)" t nil)
  3701. (autoload 'dired-tree-up "dired-aux" "\
  3702. Go up ARG levels in the dired tree.
  3703. \(fn ARG)" t nil)
  3704. (autoload 'dired-tree-down "dired-aux" "\
  3705. Go down in the dired tree.
  3706. \(fn)" t nil)
  3707. (autoload 'dired-hide-subdir "dired-aux" "\
  3708. Hide or unhide the current subdirectory and move to next directory.
  3709. Optional prefix arg is a repeat factor.
  3710. Use \\[dired-hide-all] to (un)hide all directories.
  3711. \(fn ARG)" t nil)
  3712. (autoload 'dired-hide-all "dired-aux" "\
  3713. Hide all subdirectories, leaving only their header lines.
  3714. If there is already something hidden, make everything visible again.
  3715. Use \\[dired-hide-subdir] to (un)hide a particular subdirectory.
  3716. \(fn &optional IGNORED)" t nil)
  3717. (autoload 'dired-isearch-filenames-setup "dired-aux" "\
  3718. Set up isearch to search in Dired file names.
  3719. Intended to be added to `isearch-mode-hook'.
  3720. \(fn)" nil nil)
  3721. (autoload 'dired-isearch-filenames "dired-aux" "\
  3722. Search for a string using Isearch only in file names in the Dired buffer.
  3723. \(fn)" t nil)
  3724. (autoload 'dired-isearch-filenames-regexp "dired-aux" "\
  3725. Search for a regexp using Isearch only in file names in the Dired buffer.
  3726. \(fn)" t nil)
  3727. (autoload 'dired-do-isearch "dired-aux" "\
  3728. Search for a string through all marked files using Isearch.
  3729. \(fn)" t nil)
  3730. (autoload 'dired-do-isearch-regexp "dired-aux" "\
  3731. Search for a regexp through all marked files using Isearch.
  3732. \(fn)" t nil)
  3733. (autoload 'dired-do-search "dired-aux" "\
  3734. Search through all marked files for a match for REGEXP.
  3735. Stops when a match is found.
  3736. To continue searching for next match, use command \\[tags-loop-continue].
  3737. \(fn REGEXP)" t nil)
  3738. (autoload 'dired-do-query-replace-regexp "dired-aux" "\
  3739. Do `query-replace-regexp' of FROM with TO, on all marked files.
  3740. Third arg DELIMITED (prefix arg) means replace only word-delimited matches.
  3741. If you exit (\\[keyboard-quit], RET or q), you can resume the query replace
  3742. with the command \\[tags-loop-continue].
  3743. \(fn FROM TO &optional DELIMITED)" t nil)
  3744. (autoload 'dired-show-file-type "dired-aux" "\
  3745. Print the type of FILE, according to the `file' command.
  3746. If you give a prefix to this command, and FILE is a symbolic
  3747. link, then the type of the file linked to by FILE is printed
  3748. instead.
  3749. \(fn FILE &optional DEREF-SYMLINKS)" t nil)
  3750. ;;;***
  3751. ;;;### (autoloads (dired-do-relsymlink dired-jump-other-window dired-jump)
  3752. ;;;;;; "dired-x" "dired-x.el" "2a39a8306a5541c304bc4ab602876f92")
  3753. ;;; Generated autoloads from dired-x.el
  3754. (autoload 'dired-jump "dired-x" "\
  3755. Jump to dired buffer corresponding to current buffer.
  3756. If in a file, dired the current directory and move to file's line.
  3757. If in Dired already, pop up a level and goto old directory's line.
  3758. In case the proper dired file line cannot be found, refresh the dired
  3759. buffer and try again.
  3760. When OTHER-WINDOW is non-nil, jump to dired buffer in other window.
  3761. Interactively with prefix argument, read FILE-NAME and
  3762. move to its line in dired.
  3763. \(fn &optional OTHER-WINDOW FILE-NAME)" t nil)
  3764. (autoload 'dired-jump-other-window "dired-x" "\
  3765. Like \\[dired-jump] (`dired-jump') but in other window.
  3766. \(fn &optional FILE-NAME)" t nil)
  3767. (autoload 'dired-do-relsymlink "dired-x" "\
  3768. Relative symlink all marked (or next ARG) files into a directory.
  3769. Otherwise make a relative symbolic link to the current file.
  3770. This creates relative symbolic links like
  3771. foo -> ../bar/foo
  3772. not absolute ones like
  3773. foo -> /ugly/file/name/that/may/change/any/day/bar/foo
  3774. For absolute symlinks, use \\[dired-do-symlink].
  3775. \(fn &optional ARG)" t nil)
  3776. ;;;***
  3777. ;;; End of automatically extracted autoloads.
  3778. (provide 'dired)
  3779. (run-hooks 'dired-load-hook) ; for your customizations
  3780. ;;; dired.el ends here