dired-x.el 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616
  1. ;;; dired-x.el --- extra Dired functionality
  2. ;; Copyright (C) 1993-1994, 1997, 2001-2012 Free Software Foundation, Inc.
  3. ;; Author: Sebastian Kremer <sk@thp.uni-koeln.de>
  4. ;; Lawrence R. Dodd <dodd@roebling.poly.edu>
  5. ;; Maintainer: Romain Francoise <rfrancoise@gnu.org>
  6. ;; Keywords: dired extensions 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 based on Sebastian Kremer's excellent dired-x.el (Dired Extra),
  21. ;; version 1.191, adapted for GNU Emacs. See the `dired-x' info pages.
  22. ;; USAGE: In your ~/.emacs,
  23. ;;
  24. ;; (add-hook 'dired-load-hook
  25. ;; (lambda ()
  26. ;; (load "dired-x")
  27. ;; ;; Set global variables here. For example:
  28. ;; ;; (setq dired-guess-shell-gnutar "gtar")
  29. ;; ))
  30. ;; (add-hook 'dired-mode-hook
  31. ;; (lambda ()
  32. ;; ;; Set buffer-local variables here. For example:
  33. ;; ;; (dired-omit-mode 1)
  34. ;; ))
  35. ;;
  36. ;; At load time dired-x.el will install itself and bind some dired keys.
  37. ;; Some dired.el and dired-aux.el functions have extra features if
  38. ;; dired-x is loaded.
  39. ;; User customization: M-x customize-group RET dired-x RET.
  40. ;; *Please* see the `dired-x' info pages for more details.
  41. ;;; Code:
  42. ;; This is a no-op if dired-x is being loaded via `dired-load-hook',
  43. ;; but maybe not if a dired-x function is being autoloaded.
  44. (require 'dired)
  45. ;;; User-defined variables.
  46. (defgroup dired-x nil
  47. "Extended directory editing (dired-x)."
  48. :group 'dired)
  49. (defgroup dired-keys nil
  50. "Dired keys customizations."
  51. :prefix "dired-"
  52. :group 'dired-x)
  53. (defcustom dired-bind-vm nil
  54. "Non-nil means \"V\" runs `dired-vm', otherwise \"V\" runs `dired-rmail'.
  55. RMAIL files in the old Babyl format (used before before Emacs 23.1)
  56. contain \"-*- rmail -*-\" at the top, so `dired-find-file'
  57. will run `rmail' on these files. New RMAIL files use the standard
  58. mbox format, and so cannot be distinguished in this way."
  59. :type 'boolean
  60. :group 'dired-keys)
  61. (defcustom dired-bind-jump t
  62. "Non-nil means bind `dired-jump' to C-x C-j, otherwise do not.
  63. Setting this variable directly after dired-x is loaded has no effect -
  64. use \\[customize]."
  65. :type 'boolean
  66. :set (lambda (sym val)
  67. (if (set sym val)
  68. (progn
  69. (define-key ctl-x-map "\C-j" 'dired-jump)
  70. (define-key ctl-x-4-map "\C-j" 'dired-jump-other-window))
  71. (if (eq 'dired-jump (lookup-key ctl-x-map "\C-j"))
  72. (define-key ctl-x-map "\C-j" nil))
  73. (if (eq 'dired-jump-other-window (lookup-key ctl-x-4-map "\C-j"))
  74. (define-key ctl-x-4-map "\C-j" nil))))
  75. :group 'dired-keys)
  76. (defcustom dired-bind-man t
  77. "Non-nil means bind `dired-man' to \"N\" in dired-mode, otherwise do not.
  78. Setting this variable directly after dired-x is loaded has no effect -
  79. use \\[customize]."
  80. :type 'boolean
  81. :set (lambda (sym val)
  82. (if (set sym val)
  83. (define-key dired-mode-map "N" 'dired-man)
  84. (if (eq 'dired-man (lookup-key dired-mode-map "N"))
  85. (define-key dired-mode-map "N" nil))))
  86. :group 'dired-keys)
  87. (defcustom dired-bind-info t
  88. "Non-nil means bind `dired-info' to \"I\" in dired-mode, otherwise do not.
  89. Setting this variable directly after dired-x is loaded has no effect -
  90. use \\[customize]."
  91. :type 'boolean
  92. :set (lambda (sym val)
  93. (if (set sym val)
  94. (define-key dired-mode-map "I" 'dired-info)
  95. (if (eq 'dired-info (lookup-key dired-mode-map "I"))
  96. (define-key dired-mode-map "I" nil))))
  97. :group 'dired-keys)
  98. (defcustom dired-vm-read-only-folders nil
  99. "If non-nil, \\[dired-vm] will visit all folders read-only.
  100. If neither nil nor t, e.g. the symbol `if-file-read-only', only
  101. files not writable by you are visited read-only."
  102. :type '(choice (const :tag "off" nil)
  103. (const :tag "on" t)
  104. (other :tag "non-writable only" if-file-read-only))
  105. :group 'dired-x)
  106. (defcustom dired-omit-size-limit 30000
  107. "Maximum size for the \"omitting\" feature.
  108. If nil, there is no maximum size."
  109. :type '(choice (const :tag "no maximum" nil) integer)
  110. :group 'dired-x)
  111. (define-minor-mode dired-omit-mode
  112. "Toggle omission of uninteresting files in Dired (Dired-Omit mode).
  113. With a prefix argument ARG, enable Dired-Omit mode if ARG is
  114. positive, and disable it otherwise. If called from Lisp, enable
  115. the mode if ARG is omitted or nil.
  116. Dired-Omit mode is a buffer-local minor mode. When enabled in a
  117. Dired buffer, Dired does not list files whose filenames match
  118. regexp `dired-omit-files', nor files ending with extensions in
  119. `dired-omit-extensions'.
  120. To enable omitting in every Dired buffer, you can put this in
  121. your init file:
  122. (add-hook 'dired-mode-hook (lambda () (dired-omit-mode)))
  123. See Info node `(dired-x) Omitting Variables' for more information."
  124. :group 'dired-x
  125. (if dired-omit-mode
  126. ;; This will mention how many lines were omitted:
  127. (let ((dired-omit-size-limit nil)) (dired-omit-expunge))
  128. (revert-buffer)))
  129. (put 'dired-omit-mode 'safe-local-variable 'booleanp)
  130. ;; For backward compatibility
  131. (define-obsolete-variable-alias 'dired-omit-files-p 'dired-omit-mode "22.1")
  132. (defcustom dired-omit-files "^\\.?#\\|^\\.$\\|^\\.\\.$"
  133. "Filenames matching this regexp will not be displayed.
  134. This only has effect when `dired-omit-mode' is t. See interactive function
  135. `dired-omit-mode' \(\\[dired-omit-mode]\) and variable
  136. `dired-omit-extensions'. The default is to omit `.', `..', auto-save
  137. files and lock files."
  138. :type 'regexp
  139. :group 'dired-x)
  140. (defcustom dired-omit-verbose t
  141. "When non-nil, show messages when omitting files.
  142. When nil, don't show messages."
  143. :version "24.1"
  144. :type 'boolean
  145. :group 'dired-x)
  146. (defcustom dired-find-subdir nil ; t is pretty near to DWIM...
  147. "If non-nil, Dired always finds a directory in a buffer of its own.
  148. If nil, Dired finds the directory as a subdirectory in some other buffer
  149. if it is present as one.
  150. If there are several dired buffers for a directory, the most recently
  151. used is chosen.
  152. Dired avoids switching to the current buffer, so that if you have
  153. a normal and a wildcard buffer for the same directory, \\[dired] will
  154. toggle between those two."
  155. :type 'boolean
  156. :group 'dired-x)
  157. (defcustom dired-enable-local-variables t
  158. "Control use of local-variables lists in Dired.
  159. This temporarily overrides the value of `enable-local-variables' when
  160. listing a directory. See also `dired-local-variables-file'."
  161. :risky t
  162. :type '(choice (const :tag "Query Unsafe" t)
  163. (const :tag "Safe Only" :safe)
  164. (const :tag "Do all" :all)
  165. (const :tag "Ignore" nil)
  166. (other :tag "Query" other))
  167. :group 'dired-x)
  168. (make-obsolete-variable 'dired-enable-local-variables
  169. "use a standard `dir-locals-file' instead." "24.1")
  170. (defcustom dired-guess-shell-gnutar
  171. (catch 'found
  172. (dolist (exe '("tar" "gtar"))
  173. (if (with-temp-buffer
  174. (ignore-errors (call-process exe nil t nil "--version"))
  175. (and (re-search-backward "GNU tar" nil t) t))
  176. (throw 'found exe))))
  177. "If non-nil, name of GNU tar executable.
  178. \(E.g., \"tar\" or \"gtar\"). The `z' switch will be used with it for
  179. compressed or gzip'ed tar files. If you don't have GNU tar, set this
  180. to nil: a pipe using `zcat' or `gunzip -c' will be used."
  181. ;; Changed from system-type test to testing --version output.
  182. ;; Maybe test --help for -z instead?
  183. :version "24.1"
  184. :type '(choice (const :tag "Not GNU tar" nil)
  185. (string :tag "Command name"))
  186. :group 'dired-x)
  187. (defcustom dired-guess-shell-gzip-quiet t
  188. "Non-nil says pass -q to gzip overriding verbose GZIP environment."
  189. :type 'boolean
  190. :group 'dired-x)
  191. (defcustom dired-guess-shell-znew-switches nil
  192. "If non-nil, then string of switches passed to `znew', example: \"-K\"."
  193. :type '(choice (const :tag "None" nil)
  194. (string :tag "Switches"))
  195. :group 'dired-x)
  196. (defcustom dired-clean-up-buffers-too t
  197. "Non-nil means offer to kill buffers visiting files and dirs deleted in Dired."
  198. :type 'boolean
  199. :group 'dired-x)
  200. ;;; KEY BINDINGS.
  201. (define-key dired-mode-map "\M-o" 'dired-omit-mode)
  202. (define-key dired-mode-map "*O" 'dired-mark-omitted)
  203. (define-key dired-mode-map "\M-(" 'dired-mark-sexp)
  204. (define-key dired-mode-map "*(" 'dired-mark-sexp)
  205. (define-key dired-mode-map "*." 'dired-mark-extension)
  206. (define-key dired-mode-map "\M-!" 'dired-smart-shell-command)
  207. (define-key dired-mode-map "\M-G" 'dired-goto-subdir)
  208. (define-key dired-mode-map "F" 'dired-do-find-marked-files)
  209. (define-key dired-mode-map "Y" 'dired-do-relsymlink)
  210. (define-key dired-mode-map "%Y" 'dired-do-relsymlink-regexp)
  211. (define-key dired-mode-map "V" 'dired-do-run-mail)
  212. ;;; MENU BINDINGS
  213. (require 'easymenu)
  214. (let ((menu (lookup-key dired-mode-map [menu-bar])))
  215. (easy-menu-add-item menu '("Operate")
  216. ["Find Files" dired-do-find-marked-files
  217. :help "Find current or marked files"]
  218. "Shell Command...")
  219. (easy-menu-add-item menu '("Operate")
  220. ["Relative Symlink to..." dired-do-relsymlink
  221. :visible (fboundp 'make-symbolic-link)
  222. :help "Make relative symbolic links for current or \
  223. marked files"]
  224. "Hardlink to...")
  225. (easy-menu-add-item menu '("Mark")
  226. ["Flag Extension..." dired-flag-extension
  227. :help "Flag files with a certain extension for deletion"]
  228. "Mark Executables")
  229. (easy-menu-add-item menu '("Mark")
  230. ["Mark Extension..." dired-mark-extension
  231. :help "Mark files with a certain extension"]
  232. "Unmark All")
  233. (easy-menu-add-item menu '("Mark")
  234. ["Mark Omitted" dired-mark-omitted
  235. :help "Mark files matching `dired-omit-files' \
  236. and `dired-omit-extensions'"]
  237. "Unmark All")
  238. (easy-menu-add-item menu '("Regexp")
  239. ["Relative Symlink..." dired-do-relsymlink-regexp
  240. :visible (fboundp 'make-symbolic-link)
  241. :help "Make relative symbolic links for files \
  242. matching regexp"]
  243. "Hardlink...")
  244. (easy-menu-add-item menu '("Immediate")
  245. ["Omit Mode" dired-omit-mode
  246. :style toggle :selected dired-omit-mode
  247. :help "Enable or disable omitting \"uninteresting\" \
  248. files"]
  249. "Refresh"))
  250. ;; Install into appropriate hooks.
  251. (add-hook 'dired-mode-hook 'dired-extra-startup)
  252. (add-hook 'dired-after-readin-hook 'dired-omit-expunge)
  253. (defun dired-extra-startup ()
  254. "Automatically put on `dired-mode-hook' to get extra Dired features:
  255. \\<dired-mode-map>
  256. \\[dired-do-run-mail]\t-- run mail on folder (see `dired-bind-vm')
  257. \\[dired-info]\t-- run info on file
  258. \\[dired-man]\t-- run man on file
  259. \\[dired-do-find-marked-files]\t-- visit all marked files simultaneously
  260. \\[dired-omit-mode]\t-- toggle omitting of files
  261. \\[dired-mark-sexp]\t-- mark by Lisp expression
  262. To see the options you can set, use M-x customize-group RET dired-x RET.
  263. See also the functions:
  264. `dired-flag-extension'
  265. `dired-virtual'
  266. `dired-jump'
  267. `dired-man'
  268. `dired-vm'
  269. `dired-rmail'
  270. `dired-info'
  271. `dired-do-find-marked-files'"
  272. (interactive)
  273. ;; These must be done in each new dired buffer.
  274. (dired-hack-local-variables)
  275. (dired-omit-startup))
  276. ;;; EXTENSION MARKING FUNCTIONS.
  277. ;; Mark files with some extension.
  278. (defun dired-mark-extension (extension &optional marker-char)
  279. "Mark all files with a certain EXTENSION for use in later commands.
  280. A `.' is *not* automatically prepended to the string entered."
  281. ;; EXTENSION may also be a list of extensions instead of a single one.
  282. ;; Optional MARKER-CHAR is marker to use.
  283. (interactive "sMarking extension: \nP")
  284. (or (listp extension)
  285. (setq extension (list extension)))
  286. (dired-mark-files-regexp
  287. (concat ".";; don't match names with nothing but an extension
  288. "\\("
  289. (mapconcat 'regexp-quote extension "\\|")
  290. "\\)$")
  291. marker-char))
  292. (defun dired-flag-extension (extension)
  293. "In dired, flag all files with a certain EXTENSION for deletion.
  294. A `.' is *not* automatically prepended to the string entered."
  295. (interactive "sFlagging extension: ")
  296. (dired-mark-extension extension dired-del-marker))
  297. ;; Define some unpopular file extensions. Used for cleaning and omitting.
  298. (defvar dired-patch-unclean-extensions
  299. '(".rej" ".orig")
  300. "List of extensions of dispensable files created by the `patch' program.")
  301. (defvar dired-tex-unclean-extensions
  302. '(".toc" ".log" ".aux");; these are already in completion-ignored-extensions
  303. "List of extensions of dispensable files created by TeX.")
  304. (defvar dired-latex-unclean-extensions
  305. '(".idx" ".lof" ".lot" ".glo")
  306. "List of extensions of dispensable files created by LaTeX.")
  307. (defvar dired-bibtex-unclean-extensions
  308. '(".blg" ".bbl")
  309. "List of extensions of dispensable files created by BibTeX.")
  310. (defvar dired-texinfo-unclean-extensions
  311. '(".cp" ".cps" ".fn" ".fns" ".ky" ".kys" ".pg" ".pgs"
  312. ".tp" ".tps" ".vr" ".vrs")
  313. "List of extensions of dispensable files created by texinfo.")
  314. (defun dired-clean-patch ()
  315. "Flag dispensable files created by patch for deletion.
  316. See variable `dired-patch-unclean-extensions'."
  317. (interactive)
  318. (dired-flag-extension dired-patch-unclean-extensions))
  319. (defun dired-clean-tex ()
  320. "Flag dispensable files created by [La]TeX etc. for deletion.
  321. See variables `dired-tex-unclean-extensions',
  322. `dired-latex-unclean-extensions', `dired-bibtex-unclean-extensions' and
  323. `dired-texinfo-unclean-extensions'."
  324. (interactive)
  325. (dired-flag-extension (append dired-texinfo-unclean-extensions
  326. dired-latex-unclean-extensions
  327. dired-bibtex-unclean-extensions
  328. dired-tex-unclean-extensions)))
  329. (defun dired-very-clean-tex ()
  330. "Flag dispensable files created by [La]TeX *and* \".dvi\" for deletion.
  331. See variables `dired-texinfo-unclean-extensions',
  332. `dired-latex-unclean-extensions', `dired-bibtex-unclean-extensions' and
  333. `dired-texinfo-unclean-extensions'."
  334. (interactive)
  335. (dired-flag-extension (append dired-texinfo-unclean-extensions
  336. dired-latex-unclean-extensions
  337. dired-bibtex-unclean-extensions
  338. dired-tex-unclean-extensions
  339. (list ".dvi"))))
  340. ;;; JUMP.
  341. ;;;###autoload
  342. (defun dired-jump (&optional other-window file-name)
  343. "Jump to dired buffer corresponding to current buffer.
  344. If in a file, dired the current directory and move to file's line.
  345. If in Dired already, pop up a level and goto old directory's line.
  346. In case the proper dired file line cannot be found, refresh the dired
  347. buffer and try again.
  348. When OTHER-WINDOW is non-nil, jump to dired buffer in other window.
  349. Interactively with prefix argument, read FILE-NAME and
  350. move to its line in dired."
  351. (interactive
  352. (list nil (and current-prefix-arg
  353. (read-file-name "Jump to dired file: "))))
  354. (let* ((file (or file-name buffer-file-name))
  355. (dir (if file (file-name-directory file) default-directory)))
  356. (if (and (eq major-mode 'dired-mode) (null file-name))
  357. (progn
  358. (setq dir (dired-current-directory))
  359. (dired-up-directory other-window)
  360. (unless (dired-goto-file dir)
  361. ;; refresh and try again
  362. (dired-insert-subdir (file-name-directory dir))
  363. (dired-goto-file dir)))
  364. (if other-window
  365. (dired-other-window dir)
  366. (dired dir))
  367. (if file
  368. (or (dired-goto-file file)
  369. ;; refresh and try again
  370. (progn
  371. (dired-insert-subdir (file-name-directory file))
  372. (dired-goto-file file))
  373. ;; Toggle omitting, if it is on, and try again.
  374. (when dired-omit-mode
  375. (dired-omit-mode)
  376. (dired-goto-file file)))))))
  377. ;;;###autoload
  378. (defun dired-jump-other-window (&optional file-name)
  379. "Like \\[dired-jump] (`dired-jump') but in other window."
  380. (interactive
  381. (list (and current-prefix-arg
  382. (read-file-name "Jump to dired file: "))))
  383. (dired-jump t file-name))
  384. ;;; OMITTING.
  385. ;; Enhanced omitting of lines from directory listings.
  386. ;; Marked files are never omitted.
  387. ;; should probably get rid of this and always use 'no-dir.
  388. ;; sk 28-Aug-1991 09:37
  389. (defvar dired-omit-localp 'no-dir
  390. "The LOCALP argument `dired-omit-expunge' passes to `dired-get-filename'.
  391. If it is `no-dir', omitting is much faster, but you can only match
  392. against the non-directory part of the file name. Set it to nil if you
  393. need to match the entire file name.")
  394. ;; \017=^O for Omit - other packages can chose other control characters.
  395. (defvar dired-omit-marker-char ?\017
  396. "Temporary marker used by Dired-Omit.
  397. Should never be used as marker by the user or other packages.")
  398. (defun dired-omit-startup ()
  399. (or (assq 'dired-omit-mode minor-mode-alist)
  400. (setq minor-mode-alist
  401. (append '((dired-omit-mode
  402. (:eval (if (eq major-mode 'dired-mode)
  403. " Omit" ""))))
  404. minor-mode-alist))))
  405. (defun dired-mark-omitted ()
  406. "Mark files matching `dired-omit-files' and `dired-omit-extensions'."
  407. (interactive)
  408. (let ((dired-omit-mode nil)) (revert-buffer)) ;; Show omitted files
  409. (dired-mark-unmarked-files (dired-omit-regexp) nil nil dired-omit-localp))
  410. (defcustom dired-omit-extensions
  411. (append completion-ignored-extensions
  412. dired-latex-unclean-extensions
  413. dired-bibtex-unclean-extensions
  414. dired-texinfo-unclean-extensions)
  415. "If non-nil, a list of extensions \(strings\) to omit from Dired listings.
  416. Defaults to elements of `completion-ignored-extensions',
  417. `dired-latex-unclean-extensions', `dired-bibtex-unclean-extensions', and
  418. `dired-texinfo-unclean-extensions'.
  419. See interactive function `dired-omit-mode' \(\\[dired-omit-mode]\) and
  420. variables `dired-omit-mode' and `dired-omit-files'."
  421. :type '(repeat string)
  422. :group 'dired-x)
  423. (defun dired-omit-expunge (&optional regexp)
  424. "Erases all unmarked files matching REGEXP.
  425. Does nothing if global variable `dired-omit-mode' is nil, or if called
  426. non-interactively and buffer is bigger than `dired-omit-size-limit'.
  427. If REGEXP is nil or not specified, uses `dired-omit-files', and also omits
  428. filenames ending in `dired-omit-extensions'.
  429. If REGEXP is the empty string, this function is a no-op.
  430. This functions works by temporarily binding `dired-marker-char' to
  431. `dired-omit-marker-char' and calling `dired-do-kill-lines'."
  432. (interactive "sOmit files (regexp): ")
  433. (if (and dired-omit-mode
  434. (or (called-interactively-p 'interactive)
  435. (not dired-omit-size-limit)
  436. (< (buffer-size) dired-omit-size-limit)
  437. (progn
  438. (when dired-omit-verbose
  439. (message "Not omitting: directory larger than %d characters."
  440. dired-omit-size-limit))
  441. (setq dired-omit-mode nil)
  442. nil)))
  443. (let ((omit-re (or regexp (dired-omit-regexp)))
  444. (old-modified-p (buffer-modified-p))
  445. count)
  446. (or (string= omit-re "")
  447. (let ((dired-marker-char dired-omit-marker-char))
  448. (when dired-omit-verbose (message "Omitting..."))
  449. (if (dired-mark-unmarked-files omit-re nil nil dired-omit-localp)
  450. (progn
  451. (setq count (dired-do-kill-lines
  452. nil
  453. (if dired-omit-verbose "Omitted %d line%s." "")))
  454. (force-mode-line-update))
  455. (when dired-omit-verbose (message "(Nothing to omit)")))))
  456. ;; Try to preserve modified state of buffer. So `%*' doesn't appear
  457. ;; in mode-line of omitted buffers.
  458. (set-buffer-modified-p (and old-modified-p
  459. (save-excursion
  460. (goto-char (point-min))
  461. (re-search-forward dired-re-mark nil t))))
  462. count)))
  463. (defun dired-omit-regexp ()
  464. (concat (if dired-omit-files (concat "\\(" dired-omit-files "\\)") "")
  465. (if (and dired-omit-files dired-omit-extensions) "\\|" "")
  466. (if dired-omit-extensions
  467. (concat ".";; a non-extension part should exist
  468. "\\("
  469. (mapconcat 'regexp-quote dired-omit-extensions "\\|")
  470. "\\)$")
  471. "")))
  472. ;; Returns t if any work was done, nil otherwise.
  473. (defun dired-mark-unmarked-files (regexp msg &optional unflag-p localp)
  474. "Mark unmarked files matching REGEXP, displaying MSG.
  475. REGEXP is matched against the entire file name. When called
  476. interactively, prompt for REGEXP.
  477. With prefix argument, unflag all those files.
  478. Optional fourth argument LOCALP is as in `dired-get-filename'."
  479. (interactive
  480. (list (dired-read-regexp
  481. "Mark unmarked files matching regexp (default all): ")
  482. nil current-prefix-arg nil))
  483. (let ((dired-marker-char (if unflag-p ?\s dired-marker-char)))
  484. (dired-mark-if
  485. (and
  486. ;; not already marked
  487. (looking-at " ")
  488. ;; uninteresting
  489. (let ((fn (dired-get-filename localp t)))
  490. (and fn (string-match regexp fn))))
  491. msg)))
  492. ;;; VIRTUAL DIRED MODE.
  493. ;; For browsing `ls -lR' listings in a dired-like fashion.
  494. (defalias 'virtual-dired 'dired-virtual)
  495. (defun dired-virtual (dirname &optional switches)
  496. "Put this buffer into Virtual Dired mode.
  497. In Virtual Dired mode, all commands that do not actually consult the
  498. filesystem will work.
  499. This is useful if you want to peruse and move around in an ls -lR
  500. output file, for example one you got from an ftp server. With
  501. ange-ftp, you can even dired a directory containing an ls-lR file,
  502. visit that file and turn on virtual dired mode. But don't try to save
  503. this file, as dired-virtual indents the listing and thus changes the
  504. buffer.
  505. If you have save a Dired buffer in a file you can use \\[dired-virtual] to
  506. resume it in a later session.
  507. Type \\<dired-mode-map>\\[revert-buffer] \
  508. in the Virtual Dired buffer and answer `y' to convert
  509. the virtual to a real dired buffer again. You don't have to do this, though:
  510. you can relist single subdirs using \\[dired-do-redisplay]."
  511. ;; DIRNAME is the top level directory of the buffer. It will become
  512. ;; its `default-directory'. If nil, the old value of
  513. ;; default-directory is used.
  514. ;; Optional SWITCHES are the ls switches to use.
  515. ;; Shell wildcards will be used if there already is a `wildcard'
  516. ;; line in the buffer (thus it is a saved Dired buffer), but there
  517. ;; is no other way to get wildcards. Insert a `wildcard' line by
  518. ;; hand if you want them.
  519. (interactive
  520. (list (read-string "Virtual Dired directory: " (dired-virtual-guess-dir))))
  521. (goto-char (point-min))
  522. (or (looking-at " ")
  523. ;; if not already indented, do it now:
  524. (indent-region (point-min) (point-max) 2))
  525. (or dirname (setq dirname default-directory))
  526. (setq dirname (expand-file-name (file-name-as-directory dirname)))
  527. (setq default-directory dirname) ; contains no wildcards
  528. (let ((wildcard (save-excursion
  529. (goto-char (point-min))
  530. (forward-line 1)
  531. (and (looking-at "^ wildcard ")
  532. (buffer-substring (match-end 0)
  533. (line-end-position))))))
  534. (if wildcard
  535. (setq dirname (expand-file-name wildcard default-directory))))
  536. ;; If raw ls listing (not a saved old dired buffer), give it a
  537. ;; decent subdir headerline:
  538. (goto-char (point-min))
  539. (or (looking-at dired-subdir-regexp)
  540. (insert " "
  541. (directory-file-name (file-name-directory default-directory))
  542. ":\n"))
  543. (dired-mode dirname (or switches dired-listing-switches))
  544. (setq mode-name "Virtual Dired"
  545. revert-buffer-function 'dired-virtual-revert)
  546. (set (make-local-variable 'dired-subdir-alist) nil)
  547. (dired-build-subdir-alist)
  548. (goto-char (point-min))
  549. (dired-initial-position dirname))
  550. (defun dired-virtual-guess-dir ()
  551. "Guess and return appropriate working directory of this buffer.
  552. The buffer is assumed to be in Dired or ls -lR format. The guess is
  553. based upon buffer contents. If nothing could be guessed, returns
  554. nil."
  555. (let ((regexp "^\\( \\)?\\([^ \n\r]*\\)\\(:\\)[\n\r]")
  556. (subexpr 2))
  557. (goto-char (point-min))
  558. (cond ((looking-at regexp)
  559. ;; If a saved dired buffer, look to which dir and
  560. ;; perhaps wildcard it belongs:
  561. (let ((dir (buffer-substring (match-beginning subexpr)
  562. (match-end subexpr))))
  563. (file-name-as-directory dir)))
  564. ;; Else no match for headerline found. It's a raw ls listing.
  565. ;; In raw ls listings the directory does not have a headerline
  566. ;; try parent of first subdir, if any
  567. ((re-search-forward regexp nil t)
  568. (file-name-directory
  569. (directory-file-name
  570. (file-name-as-directory
  571. (buffer-substring (match-beginning subexpr)
  572. (match-end subexpr))))))
  573. (t ; if all else fails
  574. nil))))
  575. (defun dired-virtual-revert (&optional _arg _noconfirm)
  576. (if (not
  577. (y-or-n-p "Cannot revert a Virtual Dired buffer - switch to Real Dired mode? "))
  578. (error "Cannot revert a Virtual Dired buffer")
  579. (setq mode-name "Dired"
  580. revert-buffer-function 'dired-revert)
  581. (revert-buffer)))
  582. ;; A zero-arg version of dired-virtual.
  583. (defun dired-virtual-mode ()
  584. "Put current buffer into Virtual Dired mode (see `dired-virtual').
  585. Useful on `magic-mode-alist' with the regexp
  586. \"^ \\\\(/[^ /]+\\\\)+/?:$\"
  587. to put saved dired buffers automatically into Virtual Dired mode.
  588. Also useful for `auto-mode-alist' like this:
  589. (add-to-list 'auto-mode-alist
  590. '(\"[^/]\\\\.dired\\\\'\" . dired-virtual-mode))"
  591. (interactive)
  592. (dired-virtual (dired-virtual-guess-dir)))
  593. ;;; SMART SHELL.
  594. ;; An Emacs buffer can have but one working directory, stored in the
  595. ;; buffer-local variable `default-directory'. A Dired buffer may have
  596. ;; several subdirectories inserted, but still has but one working directory:
  597. ;; that of the top level Dired directory in that buffer. For some commands
  598. ;; it is appropriate that they use the current Dired directory instead of
  599. ;; `default-directory', e.g., `find-file' and `compile'. This is a general
  600. ;; mechanism is provided for special handling of the working directory in
  601. ;; special major modes.
  602. (define-obsolete-variable-alias 'default-directory-alist
  603. 'dired-default-directory-alist "24.1")
  604. ;; It's easier to add to this alist than redefine function
  605. ;; default-directory while keeping the old information.
  606. (defconst dired-default-directory-alist
  607. '((dired-mode . (if (fboundp 'dired-current-directory)
  608. (dired-current-directory)
  609. default-directory)))
  610. "Alist of major modes and their opinion on `default-directory'.
  611. Each element has the form (MAJOR . EXPRESSION).
  612. The function `dired-default-directory' evaluates EXPRESSION to
  613. determine a default directory.")
  614. (put 'dired-default-directory-alist 'risky-local-variable t) ; gets eval'd
  615. (make-obsolete-variable 'dired-default-directory-alist
  616. "this feature is due to be removed." "24.1")
  617. (defun dired-default-directory ()
  618. "Return the `dired-default-directory-alist' entry for the current major-mode.
  619. If none, return `default-directory'."
  620. (or (eval (cdr (assq major-mode dired-default-directory-alist)))
  621. default-directory))
  622. ;; It looks like this was intended to be something of a "general" feature,
  623. ;; but it only ever seems to have been used in dired-smart-shell-command,
  624. ;; and does not seem worth keeping around (?).
  625. (make-obsolete 'dired-default-directory
  626. "this feature is due to be removed." "24.1")
  627. (defun dired-smart-shell-command (command &optional output-buffer error-buffer)
  628. "Like function `shell-command', but in the current Virtual Dired directory."
  629. (interactive
  630. (list
  631. (read-shell-command "Shell command: " nil nil
  632. (cond
  633. (buffer-file-name (file-relative-name buffer-file-name))
  634. ((eq major-mode 'dired-mode) (dired-get-filename t t))))
  635. current-prefix-arg
  636. shell-command-default-error-buffer))
  637. (let ((default-directory (or (and (eq major-mode 'dired-mode)
  638. (dired-current-directory))
  639. default-directory)))
  640. (shell-command command output-buffer error-buffer)))
  641. ;;; LOCAL VARIABLES FOR DIRED BUFFERS.
  642. ;; Brief Description (This feature is obsolete as of Emacs 24.1)
  643. ;;
  644. ;; * `dired-extra-startup' is part of the `dired-mode-hook'.
  645. ;;
  646. ;; * `dired-extra-startup' calls `dired-hack-local-variables'
  647. ;;
  648. ;; * `dired-hack-local-variables' checks the value of
  649. ;; `dired-local-variables-file'
  650. ;;
  651. ;; * Check if `dired-local-variables-file' is a non-nil string and is a
  652. ;; filename found in the directory of the Dired Buffer being created.
  653. ;;
  654. ;; * If `dired-local-variables-file' satisfies the above, then temporarily
  655. ;; include it in the Dired Buffer at the bottom.
  656. ;;
  657. ;; * Set `enable-local-variables' temporarily to the user variable
  658. ;; `dired-enable-local-variables' and run `hack-local-variables' on the
  659. ;; Dired Buffer.
  660. (defcustom dired-local-variables-file (convert-standard-filename ".dired")
  661. "Filename, as string, containing local dired buffer variables to be hacked.
  662. If this file found in current directory, then it will be inserted into dired
  663. buffer and `hack-local-variables' will be run. See Info node
  664. `(emacs)File Variables' for more information on local variables.
  665. See also `dired-enable-local-variables'."
  666. :type 'file
  667. :group 'dired)
  668. (make-obsolete-variable 'dired-local-variables-file 'dir-locals-file "24.1")
  669. (defun dired-hack-local-variables ()
  670. "Evaluate local variables in `dired-local-variables-file' for dired buffer."
  671. (and (stringp dired-local-variables-file)
  672. (file-exists-p dired-local-variables-file)
  673. (let ((opoint (point-max))
  674. (inhibit-read-only t)
  675. ;; In case user has `enable-local-variables' set to nil we
  676. ;; override it locally with dired's variable.
  677. (enable-local-variables dired-enable-local-variables))
  678. ;; Insert 'em.
  679. (save-excursion
  680. (goto-char opoint)
  681. (insert "\^L\n")
  682. (insert-file-contents dired-local-variables-file))
  683. ;; Hack 'em.
  684. (unwind-protect
  685. (let ((buffer-file-name dired-local-variables-file))
  686. (hack-local-variables))
  687. ;; Delete this stuff: `eobp' is used to find last subdir by dired.el.
  688. (delete-region opoint (point-max)))
  689. ;; Make sure that the modeline shows the proper information.
  690. (dired-sort-set-modeline))))
  691. (make-obsolete 'dired-hack-local-variables
  692. 'hack-dir-local-variables-non-file-buffer "24.1")
  693. ;; Does not seem worth a dedicated command.
  694. ;; See the more general features in files-x.el.
  695. (defun dired-omit-here-always ()
  696. "Create `dir-locals-file' setting `dired-omit-mode' to t in `dired-mode'.
  697. If in a Dired buffer, reverts it."
  698. (interactive)
  699. (if (file-exists-p dired-local-variables-file)
  700. (error "Old-style dired-local-variables-file `./%s' found;
  701. replace it with a dir-locals-file `./%s'"
  702. dired-local-variables-file
  703. dir-locals-file))
  704. (if (file-exists-p dir-locals-file)
  705. (message "File `./%s' already exists." dir-locals-file)
  706. (with-temp-buffer
  707. (insert "\
  708. \((dired-mode . ((subdirs . nil)
  709. (dired-omit-mode . t))))\n")
  710. (write-file dir-locals-file))
  711. ;; Run extra-hooks and revert directory.
  712. (when (derived-mode-p 'dired-mode)
  713. (hack-dir-local-variables-non-file-buffer)
  714. (dired-extra-startup)
  715. (dired-revert))))
  716. (make-obsolete 'dired-omit-here-always 'add-dir-local-variable "24.1")
  717. ;;; GUESS SHELL COMMAND.
  718. ;; Brief Description:
  719. ;;;
  720. ;; * `dired-do-shell-command' is bound to `!' by dired.el.
  721. ;;;
  722. ;; * `dired-guess-shell-command' provides smarter defaults for
  723. ;;; dired-aux.el's `dired-read-shell-command'.
  724. ;;;
  725. ;; * `dired-guess-shell-command' calls `dired-guess-default' with list of
  726. ;;; marked files.
  727. ;;;
  728. ;; * Parse `dired-guess-shell-alist-user' and
  729. ;;; `dired-guess-shell-alist-default' (in that order) for the first REGEXP
  730. ;;; that matches the first file in the file list.
  731. ;;;
  732. ;; * If the REGEXP matches all the entries of the file list then evaluate
  733. ;;; COMMAND, which is either a string or a Lisp expression returning a
  734. ;;; string. COMMAND may be a list of commands.
  735. ;;;
  736. ;; * Return this command to `dired-guess-shell-command' which prompts user
  737. ;;; with it. The list of commands is put into the list of default values.
  738. ;;; If a command is used successfully then it is stored permanently in
  739. ;;; `dired-shell-command-history'.
  740. ;; Guess what shell command to apply to a file.
  741. (defvar dired-shell-command-history nil
  742. "History list for commands that read dired-shell commands.")
  743. ;; Default list of shell commands.
  744. ;; NOTE: Use `gunzip -c' instead of `zcat' on `.gz' files. Some do not
  745. ;; install GNU zip's version of zcat.
  746. (autoload 'Man-support-local-filenames "man")
  747. (defvar dired-guess-shell-alist-default
  748. (list
  749. (list "\\.tar\\'"
  750. '(if dired-guess-shell-gnutar
  751. (concat dired-guess-shell-gnutar " xvf")
  752. "tar xvf")
  753. ;; Extract files into a separate subdirectory
  754. '(if dired-guess-shell-gnutar
  755. (concat "mkdir " (file-name-sans-extension file)
  756. "; " dired-guess-shell-gnutar " -C "
  757. (file-name-sans-extension file) " -xvf")
  758. (concat "mkdir " (file-name-sans-extension file)
  759. "; tar -C " (file-name-sans-extension file) " -xvf"))
  760. ;; List archive contents.
  761. '(if dired-guess-shell-gnutar
  762. (concat dired-guess-shell-gnutar " tvf")
  763. "tar tvf"))
  764. ;; REGEXPS for compressed archives must come before the .Z rule to
  765. ;; be recognized:
  766. (list "\\.tar\\.Z\\'"
  767. ;; Untar it.
  768. '(if dired-guess-shell-gnutar
  769. (concat dired-guess-shell-gnutar " zxvf")
  770. (concat "zcat * | tar xvf -"))
  771. ;; Optional conversion to gzip format.
  772. '(concat "znew" (if dired-guess-shell-gzip-quiet " -q")
  773. " " dired-guess-shell-znew-switches))
  774. ;; gzip'ed archives
  775. (list "\\.t\\(ar\\.\\)?gz\\'"
  776. '(if dired-guess-shell-gnutar
  777. (concat dired-guess-shell-gnutar " zxvf")
  778. (concat "gunzip -qc * | tar xvf -"))
  779. ;; Extract files into a separate subdirectory
  780. '(if dired-guess-shell-gnutar
  781. (concat "mkdir " (file-name-sans-extension file)
  782. "; " dired-guess-shell-gnutar " -C "
  783. (file-name-sans-extension file) " -zxvf")
  784. (concat "mkdir " (file-name-sans-extension file)
  785. "; gunzip -qc * | tar -C "
  786. (file-name-sans-extension file) " -xvf -"))
  787. ;; Optional decompression.
  788. '(concat "gunzip" (if dired-guess-shell-gzip-quiet " -q" ""))
  789. ;; List archive contents.
  790. '(if dired-guess-shell-gnutar
  791. (concat dired-guess-shell-gnutar " ztvf")
  792. (concat "gunzip -qc * | tar tvf -")))
  793. ;; bzip2'ed archives
  794. (list "\\.t\\(ar\\.bz2\\|bz\\)\\'"
  795. "bunzip2 -c * | tar xvf -"
  796. ;; Extract files into a separate subdirectory
  797. '(concat "mkdir " (file-name-sans-extension file)
  798. "; bunzip2 -c * | tar -C "
  799. (file-name-sans-extension file) " -xvf -")
  800. ;; Optional decompression.
  801. "bunzip2")
  802. ;; xz'ed archives
  803. (list "\\.t\\(ar\\.\\)?xz\\'"
  804. "unxz -c * | tar xvf -"
  805. ;; Extract files into a separate subdirectory
  806. '(concat "mkdir " (file-name-sans-extension file)
  807. "; unxz -c * | tar -C "
  808. (file-name-sans-extension file) " -xvf -")
  809. ;; Optional decompression.
  810. "unxz")
  811. '("\\.shar\\.Z\\'" "zcat * | unshar")
  812. '("\\.shar\\.g?z\\'" "gunzip -qc * | unshar")
  813. '("\\.e?ps\\'" "ghostview" "xloadimage" "lpr")
  814. (list "\\.e?ps\\.g?z\\'" "gunzip -qc * | ghostview -"
  815. ;; Optional decompression.
  816. '(concat "gunzip" (if dired-guess-shell-gzip-quiet " -q")))
  817. (list "\\.e?ps\\.Z\\'" "zcat * | ghostview -"
  818. ;; Optional conversion to gzip format.
  819. '(concat "znew" (if dired-guess-shell-gzip-quiet " -q")
  820. " " dired-guess-shell-znew-switches))
  821. '("\\.patch\\'" "cat * | patch")
  822. (list "\\.patch\\.g?z\\'" "gunzip -qc * | patch"
  823. ;; Optional decompression.
  824. '(concat "gunzip" (if dired-guess-shell-gzip-quiet " -q")))
  825. (list "\\.patch\\.Z\\'" "zcat * | patch"
  826. ;; Optional conversion to gzip format.
  827. '(concat "znew" (if dired-guess-shell-gzip-quiet " -q")
  828. " " dired-guess-shell-znew-switches))
  829. ;; The following four extensions are useful with dired-man ("N" key)
  830. ;; FIXME "man ./" does not work with dired-do-shell-command,
  831. ;; because there seems to be no way for us to modify the filename,
  832. ;; only the command. Hmph. `dired-man' works though.
  833. (list "\\.\\(?:[0-9]\\|man\\)\\'"
  834. '(let ((loc (Man-support-local-filenames)))
  835. (cond ((eq loc 'man-db) "man -l")
  836. ((eq loc 'man) "man ./")
  837. (t
  838. "cat * | tbl | nroff -man -h | col -b"))))
  839. (list "\\.\\(?:[0-9]\\|man\\)\\.g?z\\'"
  840. '(let ((loc (Man-support-local-filenames)))
  841. (cond ((eq loc 'man-db)
  842. "man -l")
  843. ((eq loc 'man)
  844. "man ./")
  845. (t "gunzip -qc * | tbl | nroff -man -h | col -b")))
  846. ;; Optional decompression.
  847. '(concat "gunzip" (if dired-guess-shell-gzip-quiet " -q")))
  848. (list "\\.[0-9]\\.Z\\'"
  849. '(let ((loc (Man-support-local-filenames)))
  850. (cond ((eq loc 'man-db) "man -l")
  851. ((eq loc 'man) "man ./")
  852. (t "zcat * | tbl | nroff -man -h | col -b")))
  853. ;; Optional conversion to gzip format.
  854. '(concat "znew" (if dired-guess-shell-gzip-quiet " -q")
  855. " " dired-guess-shell-znew-switches))
  856. '("\\.pod\\'" "perldoc" "pod2man * | nroff -man")
  857. '("\\.dvi\\'" "xdvi" "dvips") ; preview and printing
  858. '("\\.au\\'" "play") ; play Sun audiofiles
  859. '("\\.mpe?g\\'\\|\\.avi\\'" "xine -p")
  860. '("\\.ogg\\'" "ogg123")
  861. '("\\.mp3\\'" "mpg123")
  862. '("\\.wav\\'" "play")
  863. '("\\.uu\\'" "uudecode") ; for uudecoded files
  864. '("\\.hqx\\'" "mcvert")
  865. '("\\.sh\\'" "sh") ; execute shell scripts
  866. '("\\.xbm\\'" "bitmap") ; view X11 bitmaps
  867. '("\\.gp\\'" "gnuplot")
  868. '("\\.p[bgpn]m\\'" "xloadimage")
  869. '("\\.gif\\'" "xloadimage") ; view gif pictures
  870. '("\\.tif\\'" "xloadimage")
  871. '("\\.png\\'" "display") ; xloadimage 4.1 doesn't grok PNG
  872. '("\\.jpe?g\\'" "xloadimage")
  873. '("\\.fig\\'" "xfig") ; edit fig pictures
  874. '("\\.out\\'" "xgraph") ; for plotting purposes.
  875. '("\\.tex\\'" "latex" "tex")
  876. '("\\.texi\\(nfo\\)?\\'" "makeinfo" "texi2dvi")
  877. '("\\.pdf\\'" "xpdf")
  878. '("\\.doc\\'" "antiword" "strings")
  879. '("\\.rpm\\'" "rpm -qilp" "rpm -ivh")
  880. '("\\.dia\\'" "dia")
  881. '("\\.mgp\\'" "mgp")
  882. ;; Some other popular archivers.
  883. (list "\\.zip\\'" "unzip" "unzip -l"
  884. ;; Extract files into a separate subdirectory
  885. '(concat "unzip" (if dired-guess-shell-gzip-quiet " -q")
  886. " -d " (file-name-sans-extension file)))
  887. '("\\.zoo\\'" "zoo x//")
  888. '("\\.lzh\\'" "lharc x")
  889. '("\\.arc\\'" "arc x")
  890. '("\\.shar\\'" "unshar")
  891. '("\\.rar\\'" "unrar x")
  892. '("\\.7z\\'" "7z x")
  893. ;; Compression.
  894. (list "\\.g?z\\'" '(concat "gunzip" (if dired-guess-shell-gzip-quiet " -q")))
  895. (list "\\.dz\\'" "dictunzip")
  896. (list "\\.bz2\\'" "bunzip2")
  897. (list "\\.xz\\'" "unxz")
  898. (list "\\.Z\\'" "uncompress"
  899. ;; Optional conversion to gzip format.
  900. '(concat "znew" (if dired-guess-shell-gzip-quiet " -q")
  901. " " dired-guess-shell-znew-switches))
  902. '("\\.sign?\\'" "gpg --verify"))
  903. "Default alist used for shell command guessing.
  904. See `dired-guess-shell-alist-user'.")
  905. (defcustom dired-guess-shell-alist-user nil
  906. "User-defined alist of rules for suggested commands.
  907. These rules take precedence over the predefined rules in the variable
  908. `dired-guess-shell-alist-default' (to which they are prepended).
  909. Each element of this list looks like
  910. \(REGEXP COMMAND...\)
  911. where each COMMAND can either be a string or a Lisp expression that evaluates
  912. to a string. If several COMMANDs are given, the first one will be the default
  913. and the rest will be added temporarily to the history and can be retrieved
  914. with \\[previous-history-element] (M-p) .
  915. The variable `dired-guess-shell-case-fold-search' controls whether
  916. REGEXP is matched case-sensitively.
  917. You can set this variable in your ~/.emacs. For example, to add rules for
  918. `.foo' and `.bar' files, write
  919. \(setq dired-guess-shell-alist-user
  920. '((\"\\\\.foo\\\\'\" \"FOO-COMMAND\")
  921. (\"\\\\.bar\\\\'\"
  922. (if condition
  923. \"BAR-COMMAND-1\"
  924. \"BAR-COMMAND-2\"))))"
  925. :group 'dired-x
  926. :type '(alist :key-type regexp :value-type (repeat sexp)))
  927. (defcustom dired-guess-shell-case-fold-search t
  928. "If non-nil, `dired-guess-shell-alist-default' and
  929. `dired-guess-shell-alist-user' are matched case-insensitively."
  930. :group 'dired-x
  931. :type 'boolean)
  932. (defun dired-guess-default (files)
  933. "Return a shell command, or a list of commands, appropriate for FILES.
  934. See `dired-guess-shell-alist-user'."
  935. (let* ((case-fold-search dired-guess-shell-case-fold-search)
  936. ;; Prepend the user's alist to the default alist.
  937. (alist (append dired-guess-shell-alist-user
  938. dired-guess-shell-alist-default))
  939. (file (car files))
  940. (flist (cdr files))
  941. elt regexp cmds)
  942. ;; Find the first match in the alist for first file in FILES.
  943. (while alist
  944. (setq elt (car alist)
  945. regexp (car elt)
  946. alist (cdr alist))
  947. (if (string-match regexp file)
  948. (setq cmds (cdr elt)
  949. alist nil)))
  950. ;; If more than one file, see if all of FILES match regular expression.
  951. (while (and flist
  952. (string-match regexp (car flist)))
  953. (setq flist (cdr flist)))
  954. ;; If flist is still non-nil, then do not guess since this means that not
  955. ;; all the files in FILES were matched by the regexp.
  956. (setq cmds (and (not flist) cmds))
  957. ;; Return commands or nil if flist is still non-nil.
  958. ;; Evaluate the commands in order that any logical testing will be done.
  959. (if (cdr cmds)
  960. (delete-dups (mapcar #'eval cmds))
  961. (eval (car cmds))))) ; single command
  962. (defun dired-guess-shell-command (prompt files)
  963. "Ask user with PROMPT for a shell command, guessing a default from FILES."
  964. (let ((default (dired-guess-default files))
  965. default-list val)
  966. (if (null default)
  967. ;; Nothing to guess
  968. (read-shell-command prompt nil 'dired-shell-command-history)
  969. (if (listp default)
  970. ;; More than one guess
  971. (setq default-list default
  972. default (car default)
  973. prompt (concat
  974. prompt
  975. (format "{%d guesses} " (length default-list))))
  976. ;; Just one guess
  977. (setq default-list (list default)))
  978. ;; Put the first guess in the prompt but not in the initial value.
  979. (setq prompt (concat prompt (format "[%s] " default)))
  980. ;; All guesses can be retrieved with M-n
  981. (setq val (read-shell-command prompt nil
  982. 'dired-shell-command-history
  983. default-list))
  984. ;; If we got a return, then return default.
  985. (if (equal val "") default val))))
  986. ;;; RELATIVE SYMBOLIC LINKS.
  987. (declare-function make-symbolic-link "fileio.c")
  988. (defvar dired-keep-marker-relsymlink ?S
  989. "See variable `dired-keep-marker-move'.")
  990. (defun dired-make-relative-symlink (file1 file2 &optional ok-if-already-exists)
  991. "Make a symbolic link (pointing to FILE1) in FILE2.
  992. The link is relative (if possible), for example
  993. \"/vol/tex/bin/foo\" \"/vol/local/bin/foo\"
  994. results in
  995. \"../../tex/bin/foo\" \"/vol/local/bin/foo\""
  996. (interactive "FRelSymLink: \nFRelSymLink %s: \np")
  997. (let (name1 name2 len1 len2 (index 0) sub)
  998. (setq file1 (expand-file-name file1)
  999. file2 (expand-file-name file2)
  1000. len1 (length file1)
  1001. len2 (length file2))
  1002. ;; Find common initial file name components:
  1003. (let (next)
  1004. (while (and (setq next (string-match "/" file1 index))
  1005. (< (setq next (1+ next)) (min len1 len2))
  1006. ;; For the comparison, both substrings must end in
  1007. ;; `/', so NEXT is *one plus* the result of the
  1008. ;; string-match.
  1009. ;; E.g., consider the case of linking "/tmp/a/abc"
  1010. ;; to "/tmp/abc" erroneously giving "/tmp/a" instead
  1011. ;; of "/tmp/" as common initial component
  1012. (string-equal (substring file1 0 next)
  1013. (substring file2 0 next)))
  1014. (setq index next))
  1015. (setq name2 file2
  1016. sub (substring file1 0 index)
  1017. name1 (substring file1 index)))
  1018. (if (string-equal sub "/")
  1019. ;; No common initial file name found
  1020. (setq name1 file1)
  1021. ;; Else they have a common parent directory
  1022. (let ((tem (substring file2 index))
  1023. (start 0)
  1024. (count 0))
  1025. ;; Count number of slashes we must compensate for ...
  1026. (while (setq start (string-match "/" tem start))
  1027. (setq count (1+ count)
  1028. start (1+ start)))
  1029. ;; ... and prepend a "../" for each slash found:
  1030. (dotimes (_n count)
  1031. (setq name1 (concat "../" name1)))))
  1032. (make-symbolic-link
  1033. (directory-file-name name1) ; must not link to foo/
  1034. ; (trailing slash!)
  1035. name2 ok-if-already-exists)))
  1036. (autoload 'dired-do-create-files "dired-aux")
  1037. ;;;###autoload
  1038. (defun dired-do-relsymlink (&optional arg)
  1039. "Relative symlink all marked (or next ARG) files into a directory.
  1040. Otherwise make a relative symbolic link to the current file.
  1041. This creates relative symbolic links like
  1042. foo -> ../bar/foo
  1043. not absolute ones like
  1044. foo -> /ugly/file/name/that/may/change/any/day/bar/foo
  1045. For absolute symlinks, use \\[dired-do-symlink]."
  1046. (interactive "P")
  1047. (dired-do-create-files 'relsymlink #'dired-make-relative-symlink
  1048. "RelSymLink" arg dired-keep-marker-relsymlink))
  1049. (autoload 'dired-mark-read-regexp "dired-aux")
  1050. (autoload 'dired-do-create-files-regexp "dired-aux")
  1051. (defun dired-do-relsymlink-regexp (regexp newname &optional arg whole-name)
  1052. "RelSymlink all marked files containing REGEXP to NEWNAME.
  1053. See functions `dired-do-rename-regexp' and `dired-do-relsymlink'
  1054. for more info."
  1055. (interactive (dired-mark-read-regexp "RelSymLink"))
  1056. (dired-do-create-files-regexp
  1057. #'dired-make-relative-symlink
  1058. "RelSymLink" arg regexp newname whole-name dired-keep-marker-relsymlink))
  1059. ;;; VISIT ALL MARKED FILES SIMULTANEOUSLY.
  1060. ;; Brief Description:
  1061. ;;;
  1062. ;; `dired-do-find-marked-files' is bound to `F' by dired-x.el.
  1063. ;;;
  1064. ;; * Use `dired-get-marked-files' to collect the marked files in the current
  1065. ;;; Dired Buffer into a list of filenames `FILE-LIST'.
  1066. ;;;
  1067. ;; * Pass FILE-LIST to `dired-simultaneous-find-file' all with
  1068. ;;; `dired-do-find-marked-files''s prefix argument NOSELECT.
  1069. ;;;
  1070. ;; * `dired-simultaneous-find-file' runs through FILE-LIST decrementing the
  1071. ;;; list each time.
  1072. ;;;
  1073. ;; * If NOSELECT is non-nil then just run `find-file-noselect' on each
  1074. ;;; element of FILE-LIST.
  1075. ;;;
  1076. ;; * If NOSELECT is nil then calculate the `size' of the window for each file
  1077. ;;; by dividing the `window-height' by length of FILE-LIST. Thus, `size' is
  1078. ;;; cognizant of the window-configuration.
  1079. ;;;
  1080. ;; * If `size' is too small abort, otherwise run `find-file' on each element
  1081. ;;; of FILE-LIST giving each a window of height `size'.
  1082. (defun dired-do-find-marked-files (&optional noselect)
  1083. "Find all marked files displaying all of them simultaneously.
  1084. With optional NOSELECT just find files but do not select them.
  1085. The current window is split across all files marked, as evenly as possible.
  1086. Remaining lines go to bottom-most window. The number of files that can be
  1087. displayed this way is restricted by the height of the current window and
  1088. `window-min-height'.
  1089. To keep dired buffer displayed, type \\[split-window-below] first.
  1090. To display just marked files, type \\[delete-other-windows] first."
  1091. (interactive "P")
  1092. (dired-simultaneous-find-file (dired-get-marked-files) noselect))
  1093. (defun dired-simultaneous-find-file (file-list noselect)
  1094. "Visit all files in FILE-LIST and display them simultaneously.
  1095. The current window is split across all files in FILE-LIST, as evenly as
  1096. possible. Remaining lines go to the bottom-most window. The number of
  1097. files that can be displayed this way is restricted by the height of the
  1098. current window and the variable `window-min-height'. With non-nil
  1099. NOSELECT the files are merely found but not selected."
  1100. ;; We don't make this function interactive because it is usually too clumsy
  1101. ;; to specify FILE-LIST interactively unless via dired.
  1102. (let (size)
  1103. (if noselect
  1104. ;; Do not select the buffer.
  1105. (find-file-noselect (car file-list))
  1106. ;; We will have to select the buffer. Calculate and check window size.
  1107. (setq size (/ (window-height) (length file-list)))
  1108. (or (<= window-min-height size)
  1109. (error "Too many files to visit simultaneously. Try C-u prefix"))
  1110. (find-file (car file-list)))
  1111. ;; Decrement.
  1112. (dolist (file (cdr file-list))
  1113. (if noselect
  1114. ;; Do not select the buffer.
  1115. (find-file-noselect file)
  1116. ;; Vertically split off a window of desired size. Upper window will
  1117. ;; have SIZE lines. Select lower (larger) window. We split it again.
  1118. (select-window (split-window nil size))
  1119. (find-file file)))))
  1120. ;;; MISCELLANEOUS COMMANDS.
  1121. ;; Run man on files.
  1122. (declare-function Man-getpage-in-background "man" (topic))
  1123. (defvar manual-program) ; from man.el
  1124. (defun dired-man ()
  1125. "Run `man' on this file."
  1126. ;; Used also to say: "Display old buffer if buffer name matches filename."
  1127. ;; but I have no idea what that means.
  1128. (interactive)
  1129. (require 'man)
  1130. (let* ((file (dired-get-filename))
  1131. (manual-program (replace-regexp-in-string "\\*" "%s"
  1132. (dired-guess-shell-command
  1133. "Man command: " (list file)))))
  1134. (Man-getpage-in-background file)))
  1135. ;; Run Info on files.
  1136. (defun dired-info ()
  1137. "Run `info' on this file."
  1138. (interactive)
  1139. (info (dired-get-filename)))
  1140. ;; Run mail on mail folders.
  1141. (declare-function vm-visit-folder "ext:vm" (folder &optional read-only))
  1142. (defvar vm-folder-directory)
  1143. (defun dired-vm (&optional read-only)
  1144. "Run VM on this file.
  1145. With optional prefix argument, visits the folder read-only.
  1146. Otherwise obeys the value of `dired-vm-read-only-folders'."
  1147. (interactive "P")
  1148. (let ((dir (dired-current-directory))
  1149. (fil (dired-get-filename)))
  1150. (vm-visit-folder fil (or read-only
  1151. (eq t dired-vm-read-only-folders)
  1152. (and dired-vm-read-only-folders
  1153. (not (file-writable-p fil)))))
  1154. ;; So that pressing `v' inside VM does prompt within current directory:
  1155. (set (make-local-variable 'vm-folder-directory) dir)))
  1156. (defun dired-rmail ()
  1157. "Run RMAIL on this file."
  1158. (interactive)
  1159. (rmail (dired-get-filename)))
  1160. (defun dired-do-run-mail ()
  1161. "If `dired-bind-vm' is non-nil, call `dired-vm', else call `dired-rmail'."
  1162. (interactive)
  1163. (if dired-bind-vm
  1164. ;; Read mail folder using vm.
  1165. (dired-vm)
  1166. ;; Read mail folder using rmail.
  1167. (dired-rmail)))
  1168. ;;; MISCELLANEOUS INTERNAL FUNCTIONS.
  1169. ;; This should be a builtin
  1170. (defun dired-buffer-more-recently-used-p (buffer1 buffer2)
  1171. "Return t if BUFFER1 is more recently used than BUFFER2.
  1172. Considers buffers closer to the car of `buffer-list' to be more recent."
  1173. (and (not (equal buffer1 buffer2))
  1174. (memq buffer1 (buffer-list))
  1175. (not (memq buffer1 (memq buffer2 (buffer-list))))))
  1176. ;; Same thing as `dired-buffers-for-dir' of dired.el? - lrd 11/23/93
  1177. ;; (defun dired-buffers-for-dir-exact (dir)
  1178. ;; ;; Return a list of buffers that dired DIR (a directory or wildcard)
  1179. ;; ;; at top level, or as subdirectory.
  1180. ;; ;; Top level matches must match the wildcard part too, if any.
  1181. ;; ;; The list is in reverse order of buffer creation, most recent last.
  1182. ;; ;; As a side effect, killed dired buffers for DIR are removed from
  1183. ;; ;; dired-buffers.
  1184. ;; (let ((alist dired-buffers) result elt)
  1185. ;; (while alist
  1186. ;; (setq elt (car alist)
  1187. ;; alist (cdr alist))
  1188. ;; (let ((buf (cdr elt)))
  1189. ;; (if (buffer-name buf)
  1190. ;; ;; Top level must match exactly against dired-directory in
  1191. ;; ;; case one of them is a wildcard.
  1192. ;; (if (or (equal dir (with-current-buffer buf dired-directory))
  1193. ;; (assoc dir (with-current-buffer buf dired-subdir-alist)))
  1194. ;; (setq result (cons buf result)))
  1195. ;; ;; else buffer is killed - clean up:
  1196. ;; (setq dired-buffers (delq elt dired-buffers)))))
  1197. ;; result))
  1198. ;; Does anyone use this? - lrd 6/29/93.
  1199. ;; Apparently people do use it. - lrd 12/22/97.
  1200. (with-no-warnings
  1201. ;; Warnings are suppressed to avoid "global/dynamic var `X' lacks a prefix".
  1202. ;; This is unbearably ugly, but not more than having global variables
  1203. ;; named size, time, name or s, however practical it can be while writing
  1204. ;; `dired-mark-sexp' predicates.
  1205. (defvar inode)
  1206. (defvar s)
  1207. (defvar mode)
  1208. (defvar nlink)
  1209. (defvar uid)
  1210. (defvar gid)
  1211. (defvar size)
  1212. (defvar time)
  1213. (defvar name)
  1214. (defvar sym))
  1215. (defun dired-mark-sexp (predicate &optional unflag-p)
  1216. "Mark files for which PREDICATE returns non-nil.
  1217. With a prefix arg, unmark or unflag those files instead.
  1218. PREDICATE is a lisp expression that can refer to the following symbols:
  1219. inode [integer] the inode of the file (only for ls -i output)
  1220. s [integer] the size of the file for ls -s output
  1221. (usually in blocks or, with -k, in KByte)
  1222. mode [string] file permission bits, e.g. \"-rw-r--r--\"
  1223. nlink [integer] number of links to file
  1224. uid [string] owner
  1225. gid [string] group (If the gid is not displayed by ls,
  1226. this will still be set (to the same as uid))
  1227. size [integer] file size in bytes
  1228. time [string] the time that ls displays, e.g. \"Feb 12 14:17\"
  1229. name [string] the name of the file
  1230. sym [string] if file is a symbolic link, the linked-to name, else \"\"
  1231. For example, use
  1232. (equal 0 size)
  1233. to mark all zero length files."
  1234. ;; Using sym="" instead of nil avoids the trap of
  1235. ;; (string-match "foo" sym) into which a user would soon fall.
  1236. ;; Give `equal' instead of `=' in the example, as this works on
  1237. ;; integers and strings.
  1238. (interactive "xMark if (lisp expr): \nP")
  1239. (message "%s" predicate)
  1240. (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char))
  1241. inode s mode nlink uid gid size time name sym)
  1242. (dired-mark-if
  1243. (save-excursion
  1244. (and
  1245. ;; Sets vars
  1246. ;; inode s mode nlink uid gid size time name sym
  1247. ;; according to current file line. Returns t for success, nil if
  1248. ;; there is no file line. Upon success, all variables are set, either
  1249. ;; to nil or the appropriate value, so they need not be initialized.
  1250. ;; Moves point within the current line.
  1251. (dired-move-to-filename)
  1252. (let (pos
  1253. (mode-len 10) ; length of mode string
  1254. ;; like in dired.el, but with subexpressions \1=inode, \2=s:
  1255. (dired-re-inode-size "\\s *\\([0-9]*\\)\\s *\\([0-9]*\\) ?"))
  1256. (beginning-of-line)
  1257. (forward-char 2)
  1258. (if (looking-at dired-re-inode-size)
  1259. (progn
  1260. (goto-char (match-end 0))
  1261. (setq inode (string-to-number
  1262. (buffer-substring (match-beginning 1)
  1263. (match-end 1)))
  1264. s (string-to-number
  1265. (buffer-substring (match-beginning 2)
  1266. (match-end 2)))))
  1267. (setq inode nil
  1268. s nil))
  1269. (setq mode (buffer-substring (point) (+ mode-len (point))))
  1270. (forward-char mode-len)
  1271. (setq nlink (read (current-buffer)))
  1272. ;; Karsten Wenger <kw@cis.uni-muenchen.de> fixed uid.
  1273. (setq uid (buffer-substring (1+ (point))
  1274. (progn (forward-word 1) (point))))
  1275. (re-search-forward directory-listing-before-filename-regexp)
  1276. (goto-char (match-beginning 1))
  1277. (forward-char -1)
  1278. (setq size (string-to-number
  1279. (buffer-substring (save-excursion
  1280. (backward-word 1)
  1281. (setq pos (point)))
  1282. (point))))
  1283. (goto-char pos)
  1284. (backward-word 1)
  1285. ;; if no gid is displayed, gid will be set to uid
  1286. ;; but user will then not reference it anyway in PREDICATE.
  1287. (setq gid (buffer-substring (save-excursion
  1288. (forward-word 1) (point))
  1289. (point))
  1290. time (buffer-substring (match-beginning 1)
  1291. (1- (dired-move-to-filename)))
  1292. name (buffer-substring (point)
  1293. (or
  1294. (dired-move-to-end-of-filename t)
  1295. (point)))
  1296. sym (if (looking-at " -> ")
  1297. (buffer-substring (progn (forward-char 4) (point))
  1298. (line-end-position))
  1299. ""))
  1300. t)
  1301. (eval predicate)))
  1302. (format "'%s file" predicate))))
  1303. ;;; FIND FILE AT POINT.
  1304. (defcustom dired-x-hands-off-my-keys t
  1305. "Non-nil means don't remap `find-file' to `dired-x-find-file'.
  1306. Similarly for `find-file-other-window' and `dired-x-find-file-other-window'.
  1307. If you change this variable without using \\[customize] after `dired-x.el'
  1308. is loaded then call \\[dired-x-bind-find-file]."
  1309. :type 'boolean
  1310. :initialize 'custom-initialize-default
  1311. :set (lambda (symbol value)
  1312. (set symbol value)
  1313. (dired-x-bind-find-file))
  1314. :group 'dired-x)
  1315. (defun dired-x-bind-find-file ()
  1316. "Bind `dired-x-find-file' in place of `find-file' (or vice-versa).
  1317. Similarly for `dired-x-find-file-other-window' and `find-file-other-window'.
  1318. Binding direction based on `dired-x-hands-off-my-keys'."
  1319. (interactive)
  1320. (if (called-interactively-p 'interactive)
  1321. (setq dired-x-hands-off-my-keys
  1322. (not (y-or-n-p "Bind dired-x-find-file over find-file? "))))
  1323. (define-key (current-global-map) [remap find-file]
  1324. (if (not dired-x-hands-off-my-keys) 'dired-x-find-file))
  1325. (define-key (current-global-map) [remap find-file-other-window]
  1326. (if (not dired-x-hands-off-my-keys) 'dired-x-find-file-other-window)))
  1327. ;; Now call it so binding is correct. This could go in the :initialize
  1328. ;; slot, but then dired-x-bind-find-file has to be defined before the
  1329. ;; defcustom, and we get free variable warnings.
  1330. (dired-x-bind-find-file)
  1331. (defun dired-x-find-file (filename)
  1332. "Edit file FILENAME.
  1333. Like `find-file', except that when called interactively with a
  1334. prefix argument, it offers the filename near point as a default."
  1335. (interactive (list (dired-x-read-filename-at-point "Find file: ")))
  1336. (find-file filename))
  1337. (defun dired-x-find-file-other-window (filename)
  1338. "Edit file FILENAME, in another window.
  1339. Like `find-file-other-window', except that when called interactively with
  1340. a prefix argument, when it offers the filename near point as a default."
  1341. (interactive (list (dired-x-read-filename-at-point "Find file: ")))
  1342. (find-file-other-window filename))
  1343. ;;; Internal functions.
  1344. ;; Fixme: This should probably use `thing-at-point'. -- fx
  1345. (defun dired-filename-at-point ()
  1346. "Return the filename closest to point, expanded.
  1347. Point should be in or after a filename."
  1348. (save-excursion
  1349. ;; First see if just past a filename.
  1350. (or (eobp) ; why?
  1351. (when (looking-at "[] \t\n[{}()]") ; whitespace or some parens
  1352. (skip-chars-backward " \n\t\r({[]})")
  1353. (or (bobp) (backward-char 1))))
  1354. (let ((filename-chars "-.[:alnum:]_/:$+@")
  1355. start prefix)
  1356. (if (looking-at (format "[%s]" filename-chars))
  1357. (progn
  1358. (skip-chars-backward filename-chars)
  1359. (setq start (point)
  1360. prefix
  1361. ;; This is something to do with ange-ftp filenames.
  1362. ;; It convert foo@bar to /foo@bar.
  1363. ;; But when does the former occur in dired buffers?
  1364. (and (string-match
  1365. "^\\w+@"
  1366. (buffer-substring start (line-end-position)))
  1367. "/"))
  1368. (if (string-match "[/~]" (char-to-string (preceding-char)))
  1369. (setq start (1- start)))
  1370. (skip-chars-forward filename-chars))
  1371. (error "No file found around point!"))
  1372. ;; Return string.
  1373. (expand-file-name (concat prefix (buffer-substring start (point)))))))
  1374. (defun dired-x-read-filename-at-point (prompt)
  1375. "Return filename prompting with PROMPT with completion.
  1376. If `current-prefix-arg' is non-nil, uses name at point as guess."
  1377. (if current-prefix-arg
  1378. (let ((guess (dired-filename-at-point)))
  1379. (read-file-name prompt
  1380. (file-name-directory guess)
  1381. guess
  1382. nil (file-name-nondirectory guess)))
  1383. (read-file-name prompt default-directory)))
  1384. (define-obsolete-function-alias 'read-filename-at-point
  1385. 'dired-x-read-filename-at-point "24.1") ; is this even needed?
  1386. ;;; BUG REPORTS
  1387. (define-obsolete-function-alias 'dired-x-submit-report 'report-emacs-bug "24.1")
  1388. ;; As Barry Warsaw would say: "This might be useful..."
  1389. (provide 'dired-x)
  1390. ;; Local Variables:
  1391. ;; byte-compile-dynamic: t
  1392. ;; generated-autoload-file: "dired.el"
  1393. ;; End:
  1394. ;;; dired-x.el ends here