[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/undo-tree 81f1417 098/195: Added diff-no-select and dif
From: |
Stefan Monnier |
Subject: |
[elpa] externals/undo-tree 81f1417 098/195: Added diff-no-select and diff-file-local-copy compatibility hacks |
Date: |
Sat, 28 Nov 2020 13:41:30 -0500 (EST) |
branch: externals/undo-tree
commit 81f1417c0ec14b78ecb3d79365a13518524869fb
Author: Toby S. Cubitt <toby-undo-tree@dr-qubit.org>
Commit: Toby S. Cubitt <toby-undo-tree@dr-qubit.org>
Added diff-no-select and diff-file-local-copy compatibility hacks
for Emacs <= 23.
---
undo-tree.el | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 83 insertions(+), 6 deletions(-)
diff --git a/undo-tree.el b/undo-tree.el
index 14a3c9e..39a78c2 100644
--- a/undo-tree.el
+++ b/undo-tree.el
@@ -630,9 +630,9 @@
;; `undo-tree-visualizer-toggle-diff'
;; * added `undo-tree-visualizer-diff' customization option, to display diff
;; by default
-;; * added `called-interactively-p' compatibility hack for Emacs <= 23.1
-;; * added `registerv-make' and `registerv-data' compatibility hacks for
-;; Emacs <= 23
+;; * added `called-interactively-p', `registerv-make', `registerv-data',
+;; `diff-no-select' and `diff-file-local-copy' compatibility hacks for
+;; older Emacsen
;;
;; Version 0.4
;; * implemented persistent history storage: `undo-tree-save-history' and
@@ -777,11 +777,15 @@
(require 'diff)
-;; `characterp' isn't defined in Emacs versions <= 22
+
+;;; =====================================================================
+;;; Compatibility hacks for older Emacsen
+
+;; `characterp' isn't defined in Emacs versions < 23
(unless (fboundp 'characterp)
(defalias 'characterp 'char-valid-p))
-;; `region-active-p' isn't defined in Emacs versions <= 22
+;; `region-active-p' isn't defined in Emacs versions < 23
(unless (fboundp 'region-active-p)
(defun region-active-p () (and transient-mark-mode mark-active)))
@@ -795,13 +799,86 @@
(around undo-tree (&optional kind) activate compile preactivate)
ad-do-it)1)
-;; `registerv' defstruct isn't defined in Emacs versions <= 23
+
+;; `registerv' defstruct isn't defined in Emacs versions < 24
(unless (fboundp 'registerv-make)
(defmacro registerv-make (data &rest dummy) data))
+
(unless (fboundp 'registerv-data)
(defmacro registerv-data (data) data))
+;; `diff-no-select' and `diff-file-local-copy' aren't defined in Emacs
+;; versions < 24 (copied and adapted from Emacs 24)
+(unless (fboundp 'diff-no-select)
+ (defun diff-no-select (old new &optional switches no-async buf)
+ ;; Noninteractive helper for creating and reverting diff buffers
+ (unless (bufferp new) (setq new (expand-file-name new)))
+ (unless (bufferp old) (setq old (expand-file-name old)))
+ (or switches (setq switches diff-switches)) ; If not specified, use
default.
+ (unless (listp switches) (setq switches (list switches)))
+ (or buf (setq buf (get-buffer-create "*Diff*")))
+ (let* ((old-alt (diff-file-local-copy old))
+ (new-alt (diff-file-local-copy new))
+ (command
+ (mapconcat 'identity
+ `(,diff-command
+ ;; Use explicitly specified switches
+ ,@switches
+ ,@(mapcar #'shell-quote-argument
+ (nconc
+ (when (or old-alt new-alt)
+ (list "-L" (if (stringp old)
+ old (prin1-to-string old))
+ "-L" (if (stringp new)
+ new (prin1-to-string
new))))
+ (list (or old-alt old)
+ (or new-alt new)))))
+ " "))
+ (thisdir default-directory))
+ (with-current-buffer buf
+ (setq buffer-read-only t)
+ (buffer-disable-undo (current-buffer))
+ (let ((inhibit-read-only t))
+ (erase-buffer))
+ (buffer-enable-undo (current-buffer))
+ (diff-mode)
+ (set (make-local-variable 'revert-buffer-function)
+ (lambda (_ignore-auto _noconfirm)
+ (diff-no-select old new switches no-async (current-buffer))))
+ (setq default-directory thisdir)
+ (let ((inhibit-read-only t))
+ (insert command "\n"))
+ (if (and (not no-async) (fboundp 'start-process))
+ (let ((proc (start-process "Diff" buf shell-file-name
+ shell-command-switch command)))
+ (set-process-filter proc 'diff-process-filter)
+ (set-process-sentinel
+ proc (lambda (proc _msg)
+ (with-current-buffer (process-buffer proc)
+ (diff-sentinel (process-exit-status proc))
+ (if old-alt (delete-file old-alt))
+ (if new-alt (delete-file new-alt))))))
+ ;; Async processes aren't available.
+ (let ((inhibit-read-only t))
+ (diff-sentinel
+ (call-process shell-file-name nil buf nil
+ shell-command-switch command))
+ (if old-alt (delete-file old-alt))
+ (if new-alt (delete-file new-alt)))))
+ buf)))
+
+(unless (fboundp 'diff-file-local-copy)
+ (defun diff-file-local-copy (file-or-buf)
+ (if (bufferp file-or-buf)
+ (with-current-buffer file-or-buf
+ (let ((tempfile (make-temp-file "buffer-content-")))
+ (write-region nil nil tempfile nil 'nomessage)
+ tempfile))
+ (file-local-copy file-or-buf))))
+
+
+
;;; =====================================================================
;;; Global variables and customization options
- [elpa] externals/undo-tree 8697a0b 077/195: Clear registers referring to nodes being discarded from undo history., (continued)
- [elpa] externals/undo-tree 8697a0b 077/195: Clear registers referring to nodes being discarded from undo history., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree f956d55 074/195: Added autoload cookies, and other tweaks to prepare for ELPA packaging., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 4e558f8 088/195: Make various interactive commands signal an error if buffer is read-only., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree e001bd5 091/195: Implemented diff display in visualizer., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 1229460 095/195: Make visualizer diff buffer name into a defconst., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 7fef53f 092/195: Display diff with current node in visualizer selection mode., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree f3e7324 090/195: Use undo-tree-inhibit-kill-visualizer to inhibit undo-tree-kill-visualizer., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree bb92692 093/195: Don't override diff-switches customization option in visualizer diff display., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree a220a42 097/195: Added registerv-make and registerv-data compatibility macros in Emacs <= 23., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 95599db 100/195: Fixed bug in visualizer selection mode when timestamps are displayed., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 81f1417 098/195: Added diff-no-select and diff-file-local-copy compatibility hacks,
Stefan Monnier <=
- [elpa] externals/undo-tree aa7202c 103/195: Fix the way keymaps are defined., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree e69adb3 109/195: Remove now unnecessary compatibility hack for called-interactively-p., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 00ffbb6 121/195: Bump version number below which we warn against enabling persistent storage., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 5df6374 128/195: Switch to lexical binding., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 9b55464 126/195: Make undo history filename match docs., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree f566beb 106/195: Add customization option allowing timestamps to be displayed by default, Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree f3e0d93 119/195: Remove ChangeLog section from package headers., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 36b341b 112/195: Cope better if undo boundary before undo-tree-canary is missing., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 98dbabd 125/195: Implement visualizer commands to redo/undo to branch/register., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 85efe23 116/195: Ensure auto-compression-mode is enabled when reading undo history file., Stefan Monnier, 2020/11/28