Skip to content

Commit 86c6984

Browse files
basil-contowsnyder
authored andcommitted
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. Avoid race condition between file existence check and deletion. Handle list-valued diff-switches. Avoid passing empty argument to diff-command.
1 parent 5fd4c8a commit 86c6984

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

verilog-mode.el

+29-25
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,9 @@ wherever possible, since it is slow."
356356
(eval-and-compile
357357
;; Both xemacs and emacs
358358
(condition-case nil
359-
(require 'diff) ; diff-command and diff-switches
359+
;; `diff-command' and `diff-switches',
360+
;; although XEmacs lacks the former.
361+
(require 'diff)
360362
(error nil))
361363
(condition-case nil
362364
(require 'compile) ; compilation-error-regexp-alist-alist
@@ -11896,31 +11898,33 @@ If optional REGEXP, ignore differences matching it."
1189611898
This requires the external program `diff-command' to be in your `exec-path',
1189711899
and uses `diff-switches' in which you may want to have \"-u\" flag.
1189811900
Ignores WHITESPACE if t, and writes output to stdout if SHOW."
11899-
;; Similar to `diff-buffer-with-file' but works on XEmacs, and doesn't
11900-
;; call `diff' as `diff' has different calling semantics on different
11901-
;; versions of Emacs.
11901+
;; Similar to `diff-buffer-with-file' but works on Emacs 21, and
11902+
;; doesn't call `diff' as `diff' has different calling semantics on
11903+
;; different versions of Emacs.
1190211904
(if (not (file-exists-p f1))
11903-
(message "Buffer `%s' has no associated file on disk" (buffer-name b2))
11904-
(with-temp-buffer "*Verilog-Diff*"
11905-
(let ((outbuf (current-buffer))
11906-
(f2 (make-temp-file "vm-diff-auto-")))
11907-
(unwind-protect
11908-
(progn
11909-
(with-current-buffer b2
11910-
(save-restriction
11911-
(widen)
11912-
(write-region (point-min) (point-max) f2 nil 'nomessage)))
11913-
(call-process diff-command nil outbuf t
11914-
diff-switches ; User may want -u in diff-switches
11915-
(if whitespace "-b" "")
11916-
f1 f2)
11917-
;; Print out results. Alternatively we could have call-processed
11918-
;; ourself, but this way we can reuse diff switches
11919-
(when show
11920-
(with-current-buffer outbuf (message "%s" (buffer-string))))))
11921-
(sit-for 0)
11922-
(when (file-exists-p f2)
11923-
(delete-file f2))))))
11905+
(message "Buffer `%s' has no associated file on disk" b2)
11906+
(let ((outbuf (get-buffer "*Verilog-Diff*"))
11907+
(f2 (make-temp-file "vm-diff-auto-")))
11908+
(unwind-protect
11909+
;; User may want -u in `diff-switches'.
11910+
(let ((args `(,@(if (listp diff-switches)
11911+
diff-switches
11912+
(list diff-switches))
11913+
,@(and whitespace '("-b"))
11914+
,f1 ,f2)))
11915+
(with-current-buffer b2
11916+
(save-restriction
11917+
(widen)
11918+
(write-region (point-min) (point-max) f2 nil 'nomessage)))
11919+
(apply #'call-process diff-command nil outbuf t args)
11920+
;; Print out results. Alternatively we could have call-processed
11921+
;; ourself, but this way we can reuse diff switches.
11922+
(when show
11923+
(with-current-buffer outbuf (message "%s" (buffer-string)))))
11924+
(sit-for 0)
11925+
(condition-case nil
11926+
(delete-file f2)
11927+
(error nil))))))
1192411928

1192511929
(defun verilog-diff-report (b1 b2 diffpt)
1192611930
"Report differences detected with `verilog-diff-auto'.

0 commit comments

Comments
 (0)