From 2dd587b640f65d3932f295514644e7bd990e04ca Mon Sep 17 00:00:00 2001 From: JSDurand Date: Fri, 30 Jul 2021 16:00:24 +0800 Subject: 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. --- text-conf.el | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'text-conf.el') 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. -- cgit v1.2.3-18-g5258