Function: claude-code-ide-mcp--create-diff-buffers

claude-code-ide-mcp--create-diff-buffers is a natively compiled function defined in claude-code-ide-mcp-handlers.el.

Signature

(claude-code-ide-mcp--create-diff-buffers OLD-FILE-PATH NEW-FILE-CONTENTS TAB-NAME)

Documentation

Create buffers for diff comparison.

OLD-FILE-PATH is the path to the original file. NEW-FILE-CONTENTS is the new content to diff against. TAB-NAME is used for naming the new buffer. Returns a cons cell (buffer-A . buffer-B).

Source Code

;; Defined in /nix/store/yjvbhwl7p6zrbw9xlnni7y4hra8sa3pl-emacs-packages-deps/share/emacs/site-lisp/claude-code-ide-mcp-handlers.el
(defun claude-code-ide-mcp--create-diff-buffers (old-file-path new-file-contents tab-name)
  "Create buffers for diff comparison.
OLD-FILE-PATH is the path to the original file.
NEW-FILE-CONTENTS is the new content to diff against.
TAB-NAME is used for naming the new buffer.
Returns a cons cell (buffer-A . buffer-B)."
  (let ((file-exists (file-exists-p old-file-path))
        buffer-A buffer-B)
    ;; Create or find buffer A (original file)
    (if file-exists
        ;; File exists - use it
        (setq buffer-A (find-file-noselect old-file-path))
      ;; New file - create empty buffer
      (setq buffer-A (generate-new-buffer (format "*New file: %s*"
                                                  (file-name-nondirectory old-file-path))))
      (with-current-buffer buffer-A
        (setq buffer-file-name old-file-path)))

    ;; Create buffer B (new content)
    (setq buffer-B (generate-new-buffer (format "*%s*" tab-name)))
    (with-current-buffer buffer-B
      (insert new-file-contents)
      ;; Set the mode based on the file extension
      (let ((mode (assoc-default old-file-path auto-mode-alist 'string-match)))
        (when mode
          (condition-case err
              (funcall mode)
            (error
             ;; If mode activation fails (e.g., syntax errors), use fundamental-mode
             (claude-code-ide-debug "Failed to activate %s for diff buffer: %s. Using fundamental-mode."
                                    mode (error-message-string err))
             (fundamental-mode))))))

    (cons buffer-A buffer-B)))