Function: diff-no-select

diff-no-select is a byte-compiled function defined in diff.el.gz.

Signature

(diff-no-select OLD NEW &optional SWITCHES NO-ASYNC BUF)

Documentation

Compare the OLD and NEW file/buffer.

If the optional SWITCHES is nil, the switches specified in the variable diff-switches(var)/diff-switches(fun) are passed to the diff command, otherwise SWITCHES is used. SWITCHES can be a string or a list of strings.

If NO-ASYNC is non-nil, call diff synchronously.

By default, this function creates the diff in the "*Diff*" buffer. If BUF is non-nil, BUF is used instead. This function returns the buffer used.

Source Code

;; Defined in /usr/src/emacs/lisp/vc/diff.el.gz
(defun diff-no-select (old new &optional switches no-async buf)
  ;; Noninteractive helper for creating and reverting diff buffers
  "Compare the OLD and NEW file/buffer.
If the optional SWITCHES is nil, the switches specified in the
variable `diff-switches' are passed to the diff command,
otherwise SWITCHES is used.  SWITCHES can be a string or a list
of strings.

If NO-ASYNC is non-nil, call diff synchronously.

By default, this function creates the diff in the \"*Diff*\"
buffer.  If BUF is non-nil, BUF is used instead.  This function
returns the buffer used."
  (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.
  (setq switches (ensure-list switches))
  (or buf (setq buf (get-buffer-create "*Diff*")))
  (diff-check-labels)
  (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
                                  (and (or old-alt new-alt)
				       (eq diff-use-labels t)
				       (list "--label"
					     (if (stringp old) old
					       (prin1-to-string old))
					     "--label"
					     (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)
      (setq-local revert-buffer-function
                  (lambda (_ignore-auto _noconfirm)
                    (diff-no-select old new switches no-async (current-buffer))))
      (setq default-directory thisdir)
      (setq diff-default-directory default-directory)
      (let ((inhibit-read-only t))
	(insert command "\n"))
      (with-file-modes #o600
        (if (and (not no-async) (fboundp 'make-process))
	    (let* ((default-directory temporary-file-directory)
                   (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)
                                       old-alt new-alt)))))
	  ;; Async processes aren't available.
	  (let* ((default-directory temporary-file-directory)
                 (inhibit-read-only t))
	    (diff-sentinel
	     (call-process shell-file-name nil buf nil
			   shell-command-switch command)
             old-alt new-alt)))))
    buf))