1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-07 15:00:34 -08:00

Fix verilog-diff-file-with-buffer

* lisp/progmodes/verilog-mode.el: Fix commentary to avoid implying
XEmacs defines diff-command.
(verilog-diff-file-with-buffer): Claim compatibility with Emacs 21
rather than XEmacs in commentary, since the latter does not seem to
define diff-command.  Use get-buffer in place of likely thinko
with-temp-buffer + BUFNAME + current-buffer.  Fix unused
unwind-protect: move temporary file deletion to its unwind
forms (bug#62620).  Avoid race condition between file existence
check and deletion.  Handle list-valued diff-switches.  Avoid
passing empty argument to diff-command.
This commit is contained in:
Basil L. Contovounesios 2023-04-02 16:46:33 +01:00
parent 0c99254a3d
commit 0d2fdf6e36

View file

@ -356,7 +356,9 @@ wherever possible, since it is slow."
(eval-and-compile (eval-and-compile
;; Both xemacs and emacs ;; Both xemacs and emacs
(condition-case nil (condition-case nil
(require 'diff) ; diff-command and diff-switches ;; `diff-command' and `diff-switches',
;; although XEmacs lacks the former.
(require 'diff)
(error nil)) (error nil))
(condition-case nil (condition-case nil
(require 'compile) ; compilation-error-regexp-alist-alist (require 'compile) ; compilation-error-regexp-alist-alist
@ -11883,31 +11885,33 @@ If optional REGEXP, ignore differences matching it."
This requires the external program `diff-command' to be in your `exec-path', This requires the external program `diff-command' to be in your `exec-path',
and uses `diff-switches' in which you may want to have \"-u\" flag. and uses `diff-switches' in which you may want to have \"-u\" flag.
Ignores WHITESPACE if t, and writes output to stdout if SHOW." Ignores WHITESPACE if t, and writes output to stdout if SHOW."
;; Similar to `diff-buffer-with-file' but works on XEmacs, and doesn't ;; Similar to `diff-buffer-with-file' but works on Emacs 21, and
;; call `diff' as `diff' has different calling semantics on different ;; doesn't call `diff' as `diff' has different calling semantics on
;; versions of Emacs. ;; different versions of Emacs.
(if (not (file-exists-p f1)) (if (not (file-exists-p f1))
(message "Buffer `%s' has no associated file on disk" (buffer-name b2)) (message "Buffer `%s' has no associated file on disk" b2)
(with-temp-buffer "*Verilog-Diff*" (let ((outbuf (get-buffer "*Verilog-Diff*"))
(let ((outbuf (current-buffer)) (f2 (make-temp-file "vm-diff-auto-")))
(f2 (make-temp-file "vm-diff-auto-"))) (unwind-protect
(unwind-protect ;; User may want -u in `diff-switches'.
(progn (let ((args `(,@(if (listp diff-switches)
(with-current-buffer b2 diff-switches
(save-restriction (list diff-switches))
(widen) ,@(and whitespace '("-b"))
(write-region (point-min) (point-max) f2 nil 'nomessage))) ,f1 ,f2)))
(call-process diff-command nil outbuf t (with-current-buffer b2
diff-switches ; User may want -u in diff-switches (save-restriction
(if whitespace "-b" "") (widen)
f1 f2) (write-region (point-min) (point-max) f2 nil 'nomessage)))
;; Print out results. Alternatively we could have call-processed (apply #'call-process diff-command nil outbuf t args)
;; ourself, but this way we can reuse diff switches ;; Print out results. Alternatively we could have call-processed
(when show ;; ourself, but this way we can reuse diff switches.
(with-current-buffer outbuf (message "%s" (buffer-string)))))) (when show
(sit-for 0) (with-current-buffer outbuf (message "%s" (buffer-string)))))
(when (file-exists-p f2) (sit-for 0)
(delete-file f2)))))) (condition-case nil
(delete-file f2)
(error nil))))))
(defun verilog-diff-report (b1 b2 diffpt) (defun verilog-diff-report (b1 b2 diffpt)
"Report differences detected with `verilog-diff-auto'. "Report differences detected with `verilog-diff-auto'.