I frequently use TRAMP with emacs to edit files remotely. However, I sometimes have files open from both my production and development server. When I have the same file open on both servers, TRAMP will name the buffers bar</ssh:stable:>
and bar</ssh:dev:>
. Is there a way I can get this behavior for all buffers, even if they’re currently only open from one of the servers? For instance, if I’m visiting /foo/bar on only the development server and /baz/qux on only the production server, I would like the buffers to be named bar</ssh:dev:>
and qux</ssh:stable:>
, respectively.
Okay, the following appears to work exactly the way I want as described above. Just put these in your .emacs:
(defun add-server-postfix ()
"Add the name of the connection type and server to the buffer name"
(if (string-match "^/ssh:.*?:" (buffer-file-name (current-buffer)))
(rename-buffer (concat (buffer-name (current-buffer)) "<" (match-string 0 (buffer-file-name (current-buffer))) ">")) nil))
(add-hook 'find-file-hook 'add-server-postfix)
find-file-hook
, the functionrename-buffer
, and the test described by phils in the related thread, along with my comments underneath his answer -- Emacs — dired-mode test to determine remote server name / address: stackoverflow.com/questions/24481381/… – lawlist Aug 22 '16 at 0:43