Kabira  K
Kabira K

Reputation: 2007

emacs buffer bind to key

I don't know why but currently emacs opens only one copy of w3m. If w3m is already open then retyping the command to open w3m takes me to the already opened buffer. I would like to configure ansi-term similarly i.e. typing C-x C-a (command open ansi-term) should take me to already opened ansi-term instead of opening a new buffer altogether.

How can I achieve this in emacs?

Upvotes: 1

Views: 229

Answers (1)

Sean
Sean

Reputation: 29790

You could write a wrapper function around ansi-term that checks to see if there already is an existing terminal buffer, and recycles that buffer if it exists:

(defun green-ansi-term ()
  "Show an existing buffer called \"*ansi-term*\" if one exists, otherwise
call function ansi-term interactively."
  (interactive)
  (let ((existing-buffer (get-buffer "*ansi-term*")))
    (if existing-buffer
        (switch-to-buffer existing-buffer)
      (call-interactively 'ansi-term))))

Upvotes: 3

Related Questions