diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index b46eeb8e374..20678ec8d1a 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -1960,8 +1960,11 @@ version, the function does nothing." "Return contents of BUFFER. If BUFFER is not a buffer or a buffer name, return the contents of `current-buffer'." - (with-current-buffer (or buffer (current-buffer)) - (substring-no-properties (buffer-string)))) + (or (let ((buf (or buffer (current-buffer)))) + (when (bufferp buf) + (with-current-buffer (or buffer (current-buffer)) + (substring-no-properties (buffer-string))))) + "")) (defun tramp-debug-buffer-name (vec) "A name for the debug buffer for VEC."