summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2021-07-30 16:00:24 +0800
committerJSDurand <mmemmew@gmail.com>2021-07-30 16:00:24 +0800
commit2dd587b640f65d3932f295514644e7bd990e04ca (patch)
tree7b879b2a43bcd0e87c5e2a59f93c9c21092a7d13
parent88ff5a4581174cd06279104a5e7695e582ec913f (diff)
new: add a dwim function for viewing diff
* text-conf.el (durand-diff-dwim): Either diff with file or vc-diff, depending on whether the buffer is modified, whether the file is associated with a registered file, whether the argument is (list 16). (global-map): Bind to the global map.
-rw-r--r--text-conf.el21
1 files changed, 21 insertions, 0 deletions
diff --git a/text-conf.el b/text-conf.el
index c25a2bf..a035593 100644
--- a/text-conf.el
+++ b/text-conf.el
@@ -124,5 +124,26 @@ If ARG is non-nil, use a more verbose format."
(define-key global-map (vector ?\H-=) #'durand-insert-timestamp)
+;; a diff-dwim
+
+;;;###autoload
+(defun durand-diff-dwim (&optional arg)
+ "Run `diff-buffer-with-file' or `vc-diff'."
+ (interactive "P")
+ (cond
+ ((and (or (not (buffer-modified-p))
+ (equal arg (list 16)))
+ (vc-registered (buffer-file-name)))
+ (vc-diff arg t))
+ ((buffer-modified-p)
+ (diff-buffer-with-file
+ (cond
+ (arg (read-buffer "Choose a buffer to diff: "
+ (current-buffer) t))
+ ((current-buffer)))))
+ ((user-error "No reasonable way to diff"))))
+
+(define-key global-map (vector ?\C-\M-=) #'durand-diff-dwim)
+
(provide 'text-conf)
;;; text-conf.el ends here.