1

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.

  • The answer (whatever it will end up being) may entail using the find-file-hook, the function rename-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
1

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.