开发者

Emacs buffer creation/switching function

开发者 https://www.devze.com 2023-02-05 22:21 出处:网络
I would like to开发者_运维问答 make function that creates a buffer named \'console\', if it does not exist and runs a few commands.If the buffer already exists I want it to only switch to it.get-buffe

I would like to开发者_运维问答 make function that creates a buffer named 'console', if it does not exist and runs a few commands. If the buffer already exists I want it to only switch to it.


get-buffer-create ("Return the buffer specified by BUFFER-OR-NAME, creating a new one if needed.") will handle creating the buffer if one doesn't exist. Then use switch-to-buffer ("Make BUFFER-OR-NAME current and display it in selected window.") to switch to the buffer.

So something like this will do the trick:

(switch-to-buffer (get-buffer-create "console"))


Try this, obviously replacing (insert "something\n") with the commands you want to run:

(defun jump-to-console ()
  "go to console buffer if it exists, otherwise create"
  (interactive)
  (let ((buffer-name "console"))
    (if (get-buffer buffer-name)
        (pop-to-buffer buffer-name)
      (pop-to-buffer (get-buffer-create buffer-name))
      (insert "something\n"))))
0

精彩评论

暂无评论...
验证码 换一张
取 消