Skip to content

Instantly share code, notes, and snippets.

@jorgenschaefer
Created November 24, 2012 23:52
Show Gist options
  • Select an option

  • Save jorgenschaefer/4141848 to your computer and use it in GitHub Desktop.

Select an option

Save jorgenschaefer/4141848 to your computer and use it in GitHub Desktop.
(defun ngz/copy-buffer (oldbuf new-name)
"Create a new buffer named NEW-NAME as a copy of OLDBUF.
Will copy the contents and all buffer-local variables.
Returns the newly-created buffer"
(let ((newbuf (get-buffer-create new-name)))
(with-current-buffer oldbuf
(copy-to-buffer newbuf (point-min) (point-max)))
(with-current-buffer newbuf
(dolist (varspec (buffer-local-variables oldbuf))
(set (car varspec) (cdr varspec))))
newbuf))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment