Question: I'm using doom Emacs in case that's relevant.

I want a key binding to go back to the most recently used buffer in the window. When I'm in that buffer and hit the key binding, it should go back to the buffer I stared out in. So hitting the key binding repeatedly should toggle between the 2 most recently used buffers.

So far I've tried several approaches from what I've found on the internet. `next-buffer` and `privious-buffer` both do nothing.

I've also tried this function:

```
(defun switch-to-previous-buffer ()
  (interactive)
  (switch-to-buffer (other-buffer (current-buffer) 1)))

```

When I call this function, no matter what buffers I've had opened previously, it goes to the scratch buffer (Fallback buffer), and hitting it again does nothing.

I'm now looking for an alternative, I'm new to Emacs and a total noob in elisp, so a brief explanation would be appreciated.

Edit:

The function I gave as an example actually does work, the problem is in fact with doom Emacs, more specifically with org-roam. When org-roam is installed, and I open emacsclient, I don't get a dashboard, which is part of the issue. For now, I've removed org-roam, this has solved the issue.

Answer: 
I use the built-in `mode-line-other-buffer` command to toggle between the two most recent buffers, with a convenient key binding since I use this all the time.

You may want to compare what that function is doing with your own attempt. Note that `other-buffer` does what I believe you want without the additional arguments you are passing in your attempt.
Does this do what you want?

```lisp
(defun my-switch-buf (buffer)
  "Switch to BUFFER.
Like `switch-to-buffer', but don't change buffer-list order."
  (interactive "BBuf: ")
  (switch-to-buffer buffer 'no-record))

(global-set-key (kbd "C-x b") 'my-switch-buf)

```

`C-h f switch-to-buffer` says this about optional arg `NORECORD` (which you used in your trial command):

> 
> If optional argument `NORECORD` is non-`nil`, do not put the buffer
> at the front of the buffer list, and do not make the window
> displaying it the most recently selected one.
> 
> 
> 

But maybe you don't want to have to hit `RET`. This simple command makes you hit `RET`, to accept the default value. So to go back and forth you'd use `C-x b RET`, not just `C-x b`.