File: dired-diff.el

package info (click to toggle)
xemacs20 20.4-13
  • links: PTS
  • area: main
  • in suites: slink
  • size: 67,324 kB
  • ctags: 57,643
  • sloc: lisp: 586,197; ansic: 184,662; sh: 4,296; asm: 3,179; makefile: 2,021; perl: 1,059; csh: 96; sed: 22
file content (164 lines) | stat: -rw-r--r-- 5,556 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
;; -*-Emacs-Lisp-*-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; File:           dired-diff.el
;; RCS:
;; Dired Version:  #Revision: 7.9 $
;; Description:    Support for diff and related commands.
;; Author:         Sandy Rutherford <sandy@ibm550.sissa.it>
;; Created:        Fri Jun 24 08:50:20 1994 by sandy on ibm550
;; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 1, or (at your option)
;;; any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; A copy of the GNU General Public License can be obtained from this
;;; program's author (send electronic mail to sandy@ibm550.sissa.it) or
;;; from the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
;;; MA 02139, USA.

(provide 'dired-diff)
(require 'dired)

(defvar emerge-last-dir-input)
(defvar emerge-last-dir-output)
(defvar emerge-last-dir-ancestor)
(defvar diff-switches)

(defun dired-diff-read-file-name (prompt)
  ;; Read and return a file name for diff.
  (let* ((mark-active t)
	 (default (and (mark)
		       (save-excursion
			 (goto-char (mark))
			 (dired-get-filename nil t)))))
    (read-file-name (format "%s %s with: %s"
			    prompt (dired-get-filename 'no-dir)
			    (if default
				(concat "["
					(dired-make-relative
					 default
					 (dired-current-directory) t)
					"] ")
			      ""))
		    (default-directory) default t)))

(defun dired-diff-read-switches (switchprompt)
  ;; Read and return a list of switches
  (or (boundp 'diff-switches)
      (require 'diff)) ; Make sure that `diff-switches' is defined.
  (let* ((default (if (listp diff-switches)
		      (mapconcat 'identity diff-switches " ")
		    diff-switches))
	 (switches
	  (read-string (format switchprompt default) default)))
    (let (result (start 0))
      (while (string-match "\\(\\S-+\\)" switches start)
	(setq result (cons (substring switches (match-beginning 1)
				      (match-end 1))
			   result)
	      start (match-end 0)))
      (nreverse result))))

(defun dired-diff (file &optional switches)
  "Compare file at point with file FILE using `diff'.
FILE defaults to the file at the mark.
The prompted-for file is the first file given to `diff'.
With a prefix allows the switches for the diff program to be edited."
  (interactive
   (list
    (dired-diff-read-file-name "Diff") 
    (and current-prefix-arg (dired-diff-read-switches "Options for diff: "))))
  (if switches
      (diff file (dired-get-filename) switches)
    (diff file (dired-get-filename))))

(defun dired-backup-diff (&optional switches)
  "Diff this file with its backup file or vice versa.
Uses the latest backup, if there are several numerical backups.
If this file is a backup, diff it with its original.
The backup file is the first file given to `diff'."
  (interactive (list (and current-prefix-arg
			  (dired-diff-read-switches "Diff with switches: "))))
  (if switches
      (diff-backup (dired-get-filename) switches)
    (diff-backup (dired-get-filename))))

(defun dired-emerge (arg file out-file)
  "Merge file at point with FILE using `emerge'.
FILE defaults to the file at the mark."
  (interactive
   (let ((file (dired-diff-read-file-name "Merge")))
     (list
      current-prefix-arg
      file
      (and current-prefix-arg (emerge-read-file-name
			       "Output file"
			       emerge-last-dir-output
			       (dired-abbreviate-file-name file) file)))))
  (emerge-files arg file (dired-get-filename) out-file))

(defun dired-emerge-with-ancestor (arg file ancestor file-out)
  "Merge file at point with FILE, using a common ANCESTOR file.
FILE defaults to the file at the mark."
  (interactive
   (let ((file (dired-diff-read-file-name "Merge")))
     (list
      current-prefix-arg
      file
      (emerge-read-file-name "Ancestor file" emerge-last-dir-ancestor nil file)
      (and current-prefix-arg (emerge-read-file-name
			       "Output file"
			       emerge-last-dir-output
			       (dired-abbreviate-file-name file) file)))))
  (emerge-files-with-ancestor arg file (dired-get-filename)
			      ancestor file-out))

(defun dired-ediff (file)
  "Ediff file at point with FILE.
FILE defaults to the file at the mark."
  (interactive (list (dired-diff-read-file-name "Ediff")))
  (ediff-files file (dired-get-filename)))

(defun dired-epatch (file)
  "Patch file at point using `epatch'."
  (interactive
   (let ((file (dired-get-filename)))
     (list
      (and (or (memq 'patch dired-no-confirm)
	       (y-or-n-p (format "Patch %s? "
				(file-name-nondirectory file))))
	   file))))
  (if file
      (ediff-patch-file file)
    (message "No file patched.")))

;;; Autoloads

;;; Diff (diff)

(autoload 'diff "diff" "Diff two files." t)
(autoload 'diff-backup "diff"
	  "Diff this file with its backup or vice versa." t)

;;; Emerge

(autoload 'emerge-files "emerge" "Merge two files." t)
(autoload 'emerge-files-with-ancestor "emerge"
	 "Merge two files having a common ancestor." t)
(autoload 'emerge-read-file-name "emerge")

;; Ediff

(autoload 'ediff-files "ediff" "Ediff two files." t)
(autoload 'ediff-patch-file "ediff" "Patch a file." t)

;;; end of dired-diff.el