home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / AP / JED / JED097-1.TAR / jed / lib / dired.sl < prev    next >
Encoding:
Text File  |  1994-12-12  |  15.0 KB  |  632 lines

  1. %
  2. %  Simple dired mode for JED.
  3. %
  4. %
  5. % To invoke Dired, do `C-x d' or `M-x dired'.
  6. %
  7. %  Moving around
  8. %  =============
  9. %
  10. %  All the usual motion commands plus some extras:
  11. %
  12. %  `C-n' `n' SPC
  13. %       move point to the next line (at the beginning of the file name)
  14. %
  15. %  `C-p' `p'
  16. %       move point to the previous line (at the beginning of the file name)
  17. %
  18. %  DEL
  19. %       move up and unflag
  20. %
  21. %  `^K'
  22. %    dired_kill_line - removes a line from the dired buffer 
  23. %       (This must be set from the dired hook)
  24. %
  25. %  ==============
  26. %
  27. %     The primary use of Dired is to "flag" files for deletion and then
  28. %  delete the previously flagged files.
  29. %
  30. %  `d'
  31. %       Flag this file for deletion.
  32. %
  33. %  `u'
  34. %       Remove deletion flag on this line.
  35. %
  36. %  `DEL'
  37. %       Move point to previous line and remove the deletion flag on that
  38. %       line.
  39. %
  40. %  `~'
  41. %       Flag all backup files (files whose names end with `~') for deletion
  42. %
  43. %  `g'
  44. %       Update the entire contents of the Dired buffer
  45. %
  46. %  Deleting Files
  47. %  ==============
  48. %
  49. %  `x'
  50. %       expunge all flagged files.  Displays a list of all the file names
  51. %       flagged for deletion, and requests confirmation with `yes'.
  52. %       After confirmation, all the flagged files are deleted and then
  53. %       their lines are deleted from the Dired buffer.
  54. %
  55. %  File Manipulations
  56. %  ==================
  57. %
  58. %  `f'
  59. %       Visit the file described on the current line, like typing `C-x C-f'
  60. %       and supplying that file name
  61. %
  62. %  `v'
  63. %       View the file described on the current line
  64. %
  65. %  `r'
  66. %       rename - prompts for a new name for the file on the current line
  67. %
  68. %  'm'
  69. %       move - move a group of flagged files to an new directory
  70. %
  71. % `M-x dired_search'
  72. %       use fsearch with the contents of LAST_SEARCH to perform a search 
  73. %       through the files listed in the dired buffer from the current point 
  74. %       forward.  Since it stops in the file where the search string is
  75. %       encountered, it is structured so that `M-x dired_search' from the 
  76. %       visited file will revert back to the dired buffer and continue the 
  77. %       dired_search from the next file in the list.
  78. %
  79.  
  80. .  "DiredMap" keymap_p 
  81. .     {
  82. .    "DiredMap" make_keymap
  83. .    "dired_find"        "f"    "DiredMap"    definekey
  84. .    "dired_find"        "F"    "DiredMap"    definekey
  85. .    "dired_view"        "v"    "DiredMap"    definekey
  86. .    "dired_view"        "V"    "DiredMap"    definekey
  87. .    "dired_tag"        "d"    "DiredMap"    definekey
  88. .    "dired_tag"        "D"    "DiredMap"    definekey
  89. .    "dired_untag"        "u"    "DiredMap"    definekey
  90. .    "dired_untag"        "U"    "DiredMap"    definekey
  91. .    "dired_move"        "M"    "DiredMap"    definekey
  92. .    "dired_move"        "m"    "DiredMap"    definekey
  93. .    "dired_delete"        "X"    "DiredMap"    definekey
  94. .    "dired_delete"        "x"    "DiredMap"    definekey
  95. .    "dired_next_file"    "^N"    "DiredMap"    definekey
  96. .    "dired_next_file"    "N"    "DiredMap"    definekey
  97. .    "dired_next_file"    "n"    "DiredMap"    definekey
  98. .    "dired_next_file"    " "    "DiredMap"    definekey
  99. .    "dired_prev_file"    "^P"    "DiredMap"    definekey
  100. .    "dired_prev_file"    "P"    "DiredMap"    definekey
  101. .    "dired_prev_file"    "p"    "DiredMap"    definekey
  102. #ifdef MSDOS
  103. .    "dired_untag_last"    "^@S"    "DiredMap"    definekey
  104. #endif   
  105. #ifdef UNIX
  106. .    "dired_untag_last"    "^?"    "DiredMap"    definekey % DEL key
  107. #endif   
  108. .    "dired_flag_backup"    "~"    "DiredMap"    definekey
  109. .    "dired_rename"        "R"    "DiredMap"    definekey
  110. .    "dired_rename"        "r"    "DiredMap"    definekey
  111. .    "dired_reread_dir"    "g"    "DiredMap"    definekey
  112. .    "dired_reread_dir"    "G"    "DiredMap"    definekey
  113. .    "describe_mode"        "H"    "DiredMap"    definekey
  114. .    "describe_mode"        "h"    "DiredMap"    definekey
  115. .    "dired_quick_help"    "?"    "DiredMap"    definekey
  116. .     } !if
  117.  
  118.  
  119. . [Dired_Buffer] "*dired*" =Dired_Buffer
  120. . [Dired_Current_Directory]
  121.  
  122. #ifdef VMS
  123. % takes somthing like dev:[a.b.c] and converts it to dev:[a.b]c.dir
  124. . ( [dir] =dir
  125. .   [cdir last this]  Null_String =cdir  Null_String =last
  126. .   [n file ch]
  127. .   dir strlen =n
  128. .   dir n 1 substr int ']' != {dir return} if
  129.   
  130. .   { --n n {break} !if
  131. .     dir n 1 substr int =ch
  132. .     ch '.' == ch '[' == or {break} if
  133. .   } forever
  134. .   ch '[' == 
  135. .     {
  136. .        dir 1 n substr 
  137. .        "000000]" strcat
  138. .     }
  139. .     {
  140. .        dir 1 n 1 - substr
  141. .        "]" strcat
  142. .     } 
  143. .    else =cdir
  144.    
  145. .   dir n 1 + dir strlen substr =file
  146. .   file 1 file strlen 1 - substr ".dir" strcat =file
  147. .   cdir file strcat
  148. . ) dired_convert_vms_dir
  149. #endif
  150.  
  151.  
  152. . (
  153. .   [dir] =dir
  154. .   [ls flags]
  155. .   [kmap] "DiredMap" =kmap
  156. .   [spaces] "  " =spaces
  157.  
  158.   %
  159.   %  put dir in canonical form--- using trick
  160.   %
  161. #ifdef MSDOS OS2
  162. .  dir expand_filename =dir
  163. #ifdef MSDOS
  164. .  dir msdos_fixup_dirspec =dir
  165. #endif
  166. #endif
  167.  
  168. #ifdef VMS
  169. .   dir dired_convert_vms_dir =dir
  170. #endif
  171. .   dir file_status 2 == {
  172. .      dir kmap dircat 
  173. .      parse_filename pop =Dired_Current_Directory
  174. #ifdef VMS
  175. .      Dired_Current_Directory =dir
  176. #endif
  177. .   }{
  178. .      dir parse_filename =dir =Dired_Current_Directory
  179. .   } else
  180. .   Dired_Current_Directory change_default_dir {"Failed to chdir." error} if
  181.  
  182. .   Dired_Buffer sw2buf 
  183. .   getbuf_info =flags exch pop Dired_Current_Directory exch flags setbuf_info 
  184.   
  185. .   " DIRED: %b   (%m%n)  (%p)  |  press '?' for help." 0 set_status_line
  186. .   0 set_readonly erase_buffer
  187. .   kmap use_keymap
  188. .   "dired" 0 setmode  
  189. #ifdef UNIX
  190. .   "ls -al "  =ls
  191. #endif
  192. #ifdef MSDOS
  193. .   "dir/l/ogne " =ls
  194. #endif
  195. #ifdef OS2
  196. .   "dir /n " =ls
  197. #endif
  198. #ifdef VMS
  199. .   "directory/size/date/prot/notrail " =ls
  200. #endif
  201.  
  202. %"Getting listing..." flush
  203. .   ls dir strcat shell_cmd
  204. .   bob
  205. #ifdef OS2
  206.    % kill 4 lines of header junk and 2 lines of trailer junk
  207. .   push_mark 4 down pop
  208. .   eol what_column 1 == {1 down pop} if
  209. .   bol del_region
  210. .   eob push_mark 3 up pop eol del_region
  211. .   bob
  212. #endif
  213. #ifdef MSDOS
  214. .   push_mark 4 down pop bol del_region        % kill 4 lines of header junk
  215. .   eob "bytes free" bsearch {bol push_mark eob del_region} if
  216. .   bob
  217. #endif
  218. #ifdef VMS
  219. .   push_mark 3 down pop bol del_region
  220. #endif
  221.  
  222. .   {bol spaces insert 1 down}{} while
  223. .   bob
  224. #ifdef UNIX
  225. .   "  total " looking_at
  226. .     {push_mark eol 1 right pop del_region} if
  227. #endif
  228. .   "This Directory: " insert Dired_Current_Directory insert newline     
  229. .   0 set_buffer_modified_flag 1 set_readonly
  230. .   spaces message
  231. . ) dired_read_dir
  232.  
  233. . [Dired_Quick_Help]
  234. . "d:tag file, u:untag, x:delete tagged files, r:rename, h:more help, ?:this help"
  235. . =Dired_Quick_Help
  236.  
  237. . (
  238. .   Dired_Quick_Help message
  239. . ) dired_quick_help
  240.  
  241.  
  242. . ( Dired_Current_Directory dired_read_dir
  243. . ) dired_reread_dir
  244.  
  245. . (
  246. #ifdef UNIX OS2
  247. .    eol " " bfind right pop
  248. #endif
  249. #ifdef VMS MSDOS
  250. .    bol 2 right pop
  251. #endif
  252. . )  dired_point_file
  253.   
  254. . (
  255. .   1 down pop
  256. .   dired_point_file
  257. . )  dired_next_file
  258.   
  259. . (
  260. .   1 up pop
  261. .   dired_point_file
  262. . )  dired_prev_file
  263.  
  264. #ifndef VMS
  265. . (
  266. .   whatline 1 == {      % don't remove top line!
  267. .     0 set_readonly
  268. .     bol push_mark 1 down pop del_region
  269. .     0 set_buffer_modified_flag 1 set_readonly
  270. .   } !if
  271. . ) dired_kill_line
  272. #endif
  273.  
  274. . (
  275. .   0 set_readonly
  276. #ifdef UNIX
  277. .   bol "This " looking_at
  278. .   "  d" looking_at    or      % do not tag a directory
  279. #endif
  280. #ifdef MSDOS OS2
  281. .   bol "This " looking_at
  282. .   "<DIR>" ffind or          % do not tag a directory
  283. #endif
  284. #ifdef VMS
  285. .   bol ".DIR" ffind
  286. .   bol skip_white what_column 4 > or
  287. #endif
  288. .   bol skip_white eolp or
  289. .   {
  290. .     bol 'D' insert_char del
  291. .   } !if
  292. .   1 down pop bol
  293. .   dired_point_file
  294. .   0 set_buffer_modified_flag 1 set_readonly
  295. . ) dired_tag
  296.  
  297. . (
  298. .   0 set_readonly
  299. .   bol 
  300. .   'D' looking_at_char {insert_single_space del} if
  301. .   1 down pop bol
  302. .   dired_point_file
  303. .   0 set_buffer_modified_flag 1 set_readonly
  304. . ) dired_untag
  305.  
  306.  
  307. . (
  308. .   dired_point_file
  309. .   push_mark
  310. #ifdef MSDOS
  311. .   12 goto_column " " bskip_chars bufsubstr 
  312. .   skip_white 
  313. .   what_column 14 > { "." strcat push_mark " " ffind pop bufsubstr strcat} !if
  314. #endif
  315. #ifdef UNIX OS2
  316. .   eol bufsubstr
  317. #endif
  318. #ifdef VMS
  319. .   ";" ffind pop ";0-9" skip_chars bufsubstr
  320. #endif  
  321. . ) dired_extract_file
  322.  
  323.  
  324.  
  325. % perform operation on tagged files--- 4 parameters
  326. . (
  327. .   [op_function] =op_function
  328. .   [msg_str] =msg_str
  329. .   [op_string] =op_string
  330.   
  331. .   [lbuf]  " *Deletions*" =lbuf
  332. .   [stack n fails]  Null_String =fails
  333. .   [file]
  334.   
  335. .   Dired_Buffer setbuf push_spot
  336. .   bob
  337.   
  338. .   _stkdepth =stack
  339. .   { _stkdepth stack - {pop} loop
  340. .     Dired_Buffer sw2buf
  341. .     0 set_readonly
  342. .     bob
  343. .     { "D%" bol_fsearch}{del del "D " insert} while
  344. .     pop_spot
  345. .     0 set_buffer_modified_flag 1 set_readonly
  346. .   } ERROR_BLOCK
  347.   
  348. .   0 set_readonly
  349.  
  350. .   { "D" bol_fsearch }
  351. .   {
  352. .     "D%" insert del del
  353. .     dired_extract_file
  354. .   } while
  355.  
  356. .   _stkdepth stack - =n
  357. .   n {"No tags!" error} !if
  358.   
  359. .   lbuf sw2buf erase_buffer
  360. .   n { insert newline } loop    % tagged files on stack
  361. .   bob
  362. .   buffer_format_in_columns
  363. .   op_string get_yes_no {
  364. .     Dired_Buffer sw2buf bob
  365. .     {"D%" bol_fsearch}{
  366. .       dired_extract_file =file 
  367. .     bol
  368. .       Dired_Current_Directory file dircat =file
  369. .     file op_function {
  370. .       msg_str file strcat flush
  371. .       push_mark
  372. .       eol 1 right pop
  373. .       del_region 1 left pop
  374. .     }{
  375. .       fails " " strcat file strcat =fails
  376. .       del del "  " insert
  377. .       } else
  378. .     } while
  379. .   } if
  380. .   EXECUTE_ERROR_BLOCK
  381. .   fails strlen {"Operation Failed:" fails strcat message } if
  382. . ) dired_xop_tagged_files
  383.  
  384. . (
  385. .   "Delete these files" "Deleted " &delete_file dired_xop_tagged_files
  386. . ) dired_delete
  387.  
  388. . [Dired_Move_Target_Dir]
  389.  
  390. . (
  391. .   [file] =file
  392. .   [name] file extract_filename =name
  393.   
  394. .   file Dired_Move_Target_Dir name dircat rename_file not
  395. . ) dired_do_move
  396.  
  397. . (
  398. .   [dir]
  399. .   "Move to dir" read_file_from_mini =dir
  400. .   dir file_status 2 != {"Expecting directory name" error } if
  401. .   dir =Dired_Move_Target_Dir
  402.  
  403. .   "Move these to " dir strcat "Moved " &dired_do_move dired_xop_tagged_files
  404. . ) dired_move
  405.  
  406. . (
  407. .   1 up {"Top of Buffer."  error} !if
  408. .   dired_untag
  409. .   1 up pop 
  410. .   dired_point_file
  411. . ) dired_untag_last
  412.  
  413. #ifndef VMS
  414. . (
  415. .   [f]
  416. .   push_spot bob
  417. .   0 set_readonly
  418. .   {"~" fsearch} {
  419. .      dired_extract_file =f
  420. .      f "~" f strlen string_match {
  421. .         bol 'D' insert_char del           % is a backup file
  422. .      } if
  423. .      eol
  424. .   } while
  425. .   pop_spot
  426. .   0 set_buffer_modified_flag 1 set_readonly
  427. . ) dired_flag_backup
  428. #endif
  429.  
  430.  
  431. . (
  432. .   [oldf f n nf nd gone od status]
  433. .   dired_extract_file =oldf
  434. .   "Rename " oldf strcat " to" strcat read_file_from_mini =n
  435.   %
  436.   %  Lets be smart about this.  If new name is a dir, move it to the dir
  437.   %  with oldname.  If file is not a directory and exists, signal error.
  438.   %
  439. .   n file_status =status
  440. .   status 1 == { "File already exists.  Not renamed." error} if
  441. .   status 2 == { n oldf dircat =n } if
  442.  
  443.   %
  444.   %  Check to see if rename to new directory  -- gone = 0 if so.
  445.   %
  446. .   n parse_filename =nf =nd
  447. .   Dired_Current_Directory oldf dircat =f 
  448. .   f parse_filename pop =od
  449. #ifdef UNIX
  450. .   od nd strcmp =gone
  451. #endif
  452. #ifdef VMS MSDOS OS2
  453. .   od strup nd strup strcmp =gone
  454. #endif
  455.   
  456. .   f n rename_file
  457. .     { "Operation Failed!" error } if
  458. .   0 set_readonly
  459. .   gone {
  460. .     bol push_mark eol 1 right pop del_region
  461. .   }{
  462. #ifdef MSDOS
  463. .     [len]       
  464. .        nf strlen =len
  465. .        12 len - =len
  466. .        dired_point_file
  467. .        push_mark 12 right pop del_region
  468. .        nf insert
  469. .     1 len 1 {" " insert} _for
  470. .        1 down pop
  471. #else
  472. .        dired_point_file 
  473. .        push_mark oldf strlen right pop del_region
  474. .        nf insert 1 down pop
  475. #endif
  476. .    } else
  477. .    dired_point_file
  478. .    0 set_buffer_modified_flag 1 set_readonly
  479. . ) dired_rename
  480.  
  481. %!%Mode designed for maintaining and editing a directory.
  482. %!%
  483. %!%To invoke Dired, do `M-x dired' or `C-x d' (emacs)
  484. %!%
  485. %!%Dired will prompt for a directory name and get a listing of files in the
  486. %!%requested directory.
  487. %!%
  488. %!%The primary use of Dired is to "flag" files for deletion and then delete
  489. %!%the previously flagged files.
  490. %!%
  491. %!%'d'        Flag this file for deletion.
  492. %!%'u'        Remove deletion flag on this line.
  493. %!%DEL        Move point to previous line and remove deletion flag.
  494. %!%'~'        Flag all backup files for deletion.
  495. %!%
  496. %!%'x'        eXpunge all flagged files.  Dired will show a list of the
  497. %!%    files tagged for deletion and ask for confirmation before actually 
  498. %!%    deleting the files.
  499. %!%
  500. %!%'r'        Rename file on the current line; prompts for a newname
  501. %!%'m'        Move tagged files to a new dir; prompts for dir name
  502. %!%
  503. %!%`g'        Update the entire contents of the Dired buffer
  504. %!%
  505. %!%`f'        Visit the file described on the current line, like typing
  506. %!%    `M-x find_file' and supplying that file name.  If current line is a
  507. %!%    directory, runs dired on the directory and the old buffer is killed.
  508. %!%
  509. %!%`v'        View the file described on the current line in MOST mode.
  510. %!%
  511. %!%`M-x dired_search'
  512. %!%    use fsearch to perform a search through the files listed in the
  513. %!%    dired buffer from the current point forward.  `M-x dired_search' 
  514. %!%    from the visited file will revert to the dired buffer and continue 
  515. %!%    the search from the next file in the list.
  516. %!%
  517. %!%all the usual motion commands plus some extras:
  518. %!%
  519. %!%`C-n' `n' SPC
  520. %!%    move point to the next line (at the beginning of the file name)
  521. %!%
  522. %!%`C-p' `p'
  523. %!%    move point to the previous line (at the beginning of the file name)
  524. %!%
  525. %!%`M-x dired_kill_line'    `^K' (emacs) 
  526. %!%    removes a line from the dired buffer
  527. define dired ()
  528. {
  529. .   "Directory:"  read_file_from_mini dired_read_dir
  530. .   dired_quick_help
  531. .   "dired_hook" runhooks   
  532. }
  533.  
  534.  
  535. . (
  536. .   bol bobp 2 right pop eobp or {return} if
  537. #ifdef UNIX
  538. .   'd' looking_at_char
  539. #endif
  540. #ifdef MSDOS OS2
  541. .   "<DIR>" ffind
  542. #endif
  543. #ifdef VMS
  544. .   ".DIR" ffind
  545. #endif
  546. .     {
  547. .       Dired_Current_Directory
  548. .       dired_extract_file
  549. .       dircat dired_read_dir
  550. .       return
  551. .     } if
  552. .   Dired_Current_Directory  
  553. .   dired_extract_file
  554. .   dircat read_file {"Unable to read file." error } !if
  555. .   whatbuf pop2buf
  556. . ) dired_find
  557.  
  558. . (
  559. .   bol bobp
  560. #ifdef UNIX
  561. .   2 right pop 'd' looking_at_char
  562. #endif
  563. #ifdef MSDOS OS2
  564. .   "<DIR>" ffind
  565. #endif
  566. #ifdef VMS
  567. .   ".DIR" ffind
  568. #endif
  569. .   or {return} if
  570. .   Dired_Current_Directory
  571. .   dired_extract_file
  572. .   dircat read_file {"Unable to read file." error } !if
  573. .   whatbuf pop2buf
  574. .   most_mode
  575. . ) dired_view
  576.  
  577.  
  578. #ifndef VMS
  579. . (
  580. .   [obuf]
  581. .   LAST_SEARCH looking_at { 1 right } if
  582. .   LAST_SEARCH fsearch {
  583. .      1                % found - return 1
  584. .   }{
  585. .      buffer_modified { "buffer has been modified" message
  586. .        1                % cannot continue - return 1
  587. .      }{
  588. .        whatbuf =obuf
  589. .        Dired_Buffer pop2buf
  590. .        obuf delbuf
  591. .     0                % okay - return 0
  592. .      } else
  593. .   } else
  594. . ) dired_search_files
  595.  
  596. . (
  597. .   [dirstr]
  598. .   Dired_Buffer bufferp {
  599. .      LAST_SEARCH =dirstr
  600. .      Dired_Buffer whatbuf strcmp {    % continue last search
  601. .         dirstr strlen {"No specified search string" message return} !if
  602. .         dired_search_files {return} if
  603. .         1 down pop
  604. .      }{
  605. .         Dired_Buffer pop2buf
  606. .         "dired_search:" LAST_SEARCH Null_String read_mini =dirstr
  607. .         dirstr strlen {"Specify search string" message return} !if
  608. .         dirstr save_search_string
  609. .      } else
  610. .      {
  611. .      bol
  612. #ifdef UNIX
  613. .         "  d" looking_at
  614. #endif
  615. #ifdef MSDOS OS2
  616. .         "<DIR>" ffind
  617. #endif
  618. #ifdef VMS
  619. .         ".DIR"  ffind
  620. #endif
  621. .         { 
  622. .            Dired_Current_Directory 
  623. .            dired_extract_file
  624. .            dircat read_file {"Unable to read file." error } !if
  625. .            dired_search_files { whatbuf pop2buf return} if
  626. .         } !if                %  don't attempt directories !
  627. .         1 down {return} !if
  628. .      } forever
  629. .   } if
  630. . ) dired_search
  631. #endif
  632.