home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / misc / dired-adds.el < prev    next >
Encoding:
Text File  |  1990-07-22  |  6.9 KB  |  195 lines

  1. ;From ark1!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!mips!bridge2!mdb Thu Feb  1 18:45:24 EST 1990
  2. ;Article 668 of gnu.emacs.bug:
  3. ;Path: ark1!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!mips!bridge2!mdb
  4. ;>From: mdb@ESD.3Com.COM (Mark D. Baushke)
  5. ;Newsgroups: gnu.emacs.bug
  6. ;Subject: Re: dired-listing-switches
  7. ;Message-ID: <MDB.90Feb1143533@kosciusko.ESD.3Com.COM>
  8. ;Date: 1 Feb 90 22:35:33 GMT
  9. ;References: <9001301547.AA10682@wpmstr.wp>
  10. ;Sender: news@bridge2.ESD.3Com.COM
  11. ;Distribution: gnu
  12. ;Organization: 3Com Corp., Mountain View, CA.
  13. ;Lines: 177
  14. ;In-reply-to: wpmstr!fpb@sunpitt.east.sun.com's message of 30 Jan 90 15:47:06 GMT
  15. ;
  16. ;[I tried to reply directly, but the mail bounced from
  17. ;sunpitt.East.Sun.COM with an 'Unknown host : wmpstr' -- mdb]
  18. ;
  19. ;On 30 Jan 90 15:47:06 GMT, wpmstr!fpb@sunpitt.east.sun.com (Frank P. Bresz) said:
  20. ;
  21. ;Frank> In GNU Emacs 18.52.3 of Tue Apr 11 1989 on omaha1 (berkeley-unix)
  22. ;
  23. ;Frank> Shouldn't this variable be buffer local?
  24. ;
  25. ;Feel free to hack your environment to your own taste. I am including
  26. ;the hacks that I use at the end of this messge.
  27. ;
  28. ;Frank> Often times I want to look at a certain directory sorted by
  29. ;Frank> time i.e.  "-alt" instead of the default "-al" setting of this
  30. ;Frank> variable.  But this doesn't mean I want to look at all
  31. ;Frank> directories this way.
  32. ;
  33. ;Frank> Many variables state that they automatically become bufer local
  34. ;Frank> when set in any way.  How can I make dired-listing-switches be
  35. ;Frank> one of them.
  36. ;
  37. ;I use the following in my ~/.emacs (I am including
  38. ;my-dired-mode-hook.el after my .signature):
  39. ;
  40. ;    (setq dired-mode-hook '(my-dired-mode-hook))
  41. ;    (autoload 'my-dired-mode-hook "my-dired-mode-hook"
  42. ;          "Add new features to dired." t) 
  43. ;
  44. ;Then typing an 's' toggles between the two flavors (-al and -alt) for
  45. ;a given buffer.
  46. ;
  47. ;(Suggestions for additions welcome!)
  48. ;
  49. ;Enjoy!
  50. ;-- 
  51. ;Mark D. Baushke
  52. ;Internet:   mdb@ESD.3Com.COM
  53. ;UUCP:        {3comvax,auspex,sun}!bridge2!mdb
  54.  
  55.  
  56.  
  57. ;;;;;;;;;;;;;;;;;;;;;;;;;;; -*- Mode: Emacs-Lisp -*- ;;;;;;;;;;;;;;;;;;;;;;;;;;
  58. ;; my-dired-mode-hook.el --- additons to dired mode
  59. ;; 
  60. ;; Author          : Mark D. Baushke
  61. ;; Created On      : Mon Mar  6 14:09:43 1989
  62. ;; Last Modified By: Mark D. Baushke
  63. ;; Last Modified On: Tue Aug 29 12:11:40 1989
  64. ;; Update Count    : 7
  65. ;; Status          : Works for me!
  66. ;; 
  67. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  68.  
  69.  
  70. ;;
  71. ;; Ze'ev Wurman <zeev@silvlis.com>, Aug. 88
  72. ;; (now at Amdahl -- new e-mail address <zeev@vlss.amdahl.com>)
  73. ;;
  74. (defun my-dired-mode-hook()
  75.   (define-key dired-mode-map "a" 'dired-run-command)
  76.   (define-key dired-mode-map "q" 'dired-exit)
  77.   (define-key dired-mode-map "s" 'dired-toggle-sort)
  78.   (define-key dired-mode-map "S" 'dired-byuser-mode)
  79.   (define-key dired-mode-map "D" 'dired-run-backup-diff)
  80.   (define-key dired-mode-map "\C-d" 'dired-run-diff)
  81.   (require 'compile "compile")
  82.   (make-local-variable 'byname-mode)
  83.   (set-default 'byname-mode nil)
  84.   (make-local-variable 'bydate-mode)
  85.   (set-default 'bydate-mode nil)
  86.   (make-local-variable 'byuser-mode)
  87.   (set-default 'byuser-mode nil)
  88.   (make-local-variable 'user-string)
  89.   (set-default 'user-string nil)
  90.   (make-local-variable 'minor-mode-alist)
  91.   (make-local-variable 'dired-listing-switches)
  92.   (setq minor-mode-alist (cons '(bydate-mode " ByDate") minor-mode-alist))
  93.   (setq minor-mode-alist (cons '(byname-mode " ByName") minor-mode-alist))
  94.   (setq minor-mode-alist (cons '(byuser-mode user-string) minor-mode-alist))
  95.   (if (string-equal dired-listing-switches "-alt") (bydate-mode) 
  96.     (if (string-equal dired-listing-switches "-al") (byname-mode) 
  97.     (dired-byuser-mode dired-listing-switches)
  98.     )
  99.   )
  100. )
  101.  
  102. (defun dired-toggle-sort ()
  103.   "Toggle dired sorting by-name/by-date. Initial setting is based
  104.    on 'dired-listing-switches'. The known values are '-alt' (ByDate)
  105.    and '-al' (ByName). Any other option really belongs to 'dired-byuser-mode'"
  106.   (interactive)
  107.   (if (string-equal dired-listing-switches "-alt") (byname-mode) (bydate-mode))
  108.   (revert-buffer))
  109.  
  110. (defun bydate-mode()
  111.   (setq dired-listing-switches "-alt")
  112.   (setq bydate-mode t byname-mode nil byuser-mode nil)
  113.   (set-buffer-modified-p (buffer-modified-p)) ;No-op, but updates mode line.
  114. )
  115.  
  116. (defun byname-mode()
  117.   (setq dired-listing-switches "-al")
  118.   (setq byname-mode t bydate-mode nil byuser-mode nil)
  119.   (set-buffer-modified-p (buffer-modified-p)) ;No-op, but updates mode line.
  120. )
  121.  
  122. (defun dired-byuser-mode(&optional user-str)
  123.   "Let user specify his dired-listing-switches for dired-mode"
  124.   (interactive)
  125.   (if (not user-str)
  126.     (setq user-string (read-string "ls switches (must contain -l): " 
  127.                                      dired-listing-switches))
  128.     (setq user-string user-str)
  129.   )
  130.   (setq dired-listing-switches user-string)
  131.   (setq user-string (concat " '" user-string "'"))
  132.   (setq byname-mode nil bydate-mode nil byuser-mode t)
  133.   (set-buffer-modified-p (buffer-modified-p)) ;No-op, but updates mode line.
  134.   (revert-buffer)
  135. )
  136.  
  137. (defun dired-run-backup-diff()
  138.     "Run diff on this file and its backup version"
  139.     (interactive)
  140.     (setq to-file (dired-get-filename))
  141.     (setq to-file1 (car (find-backup-file-name to-file)))
  142.     (if (file-exists-p to-file1) ()
  143.         (setq to-file1 (file-name-sans-versions to-file)))
  144.     (if (and (file-exists-p to-file1) (not (string-equal to-file to-file1))) ()
  145.         (setq to-file1 (read-file-name "diff with file: " to-file to-file 1)))
  146.     (setq command (concat "diff " to-file " " to-file1))
  147.     (compile1 command "No more diff's" "diff")
  148.       (dired-redisplay to-file)
  149. )
  150.  
  151. (defun dired-run-diff(to-file1)
  152.     "Run diff on this file and another one"
  153.     (interactive "fdiff with file:")
  154.     (setq to-file (dired-get-filename))
  155.     (setq command (concat "diff " to-file " " to-file1))
  156.     (compile1 command "No more diff's" "diff")
  157.       (dired-redisplay to-file)
  158. )
  159. (defun kill-diff ()
  160.   "Kill the process made by the \\[diff] command."
  161.   (interactive)
  162.   (if compilation-process
  163.       (interrupt-process compilation-process)))
  164.  
  165. ;;; command to quit a dired session...
  166. (defun dired-exit ()
  167.   "Quit editing this directory."
  168.   (interactive)
  169.   (kill-buffer (current-buffer)))
  170.  
  171.  
  172. ;; modified rename
  173. (defun dired-rename-file (to-file)
  174.   "Rename this file to TO-FILE."
  175.   (interactive
  176.    (list (read-file-name (format "Rename %s to: "
  177.                  (file-name-nondirectory (dired-get-filename)))
  178.              nil (dired-get-filename))))
  179.   (setq to-file (expand-file-name to-file))
  180.   ;; Added this `if' to handle moving a file to another directory
  181.   ;; the original code only contained the `else' clause.
  182.   (if (file-directory-p to-file)
  183.       (rename-file (dired-get-filename)
  184.            (concat (directory-file-name to-file) "/"
  185.                (file-name-nondirectory (dired-get-filename))))
  186.     (rename-file (dired-get-filename) to-file))
  187.   (let ((buffer-read-only nil))
  188.     (beginning-of-line)
  189.     (delete-region (point) (progn (forward-line 1) (point)))
  190.     (setq to-file (expand-file-name to-file))
  191.     (dired-add-entry (file-name-directory to-file)
  192.              (file-name-nondirectory to-file))))
  193.  
  194.  
  195.