# A small emacs-lisp snippet for opening a register in another window

I'd like to get some feedback on whether this is idiomatic elisp, whether it's any good, and any small modifications that would be useful. Thanks

(defun jump-to-register-other-window (register-name)
"Open a register in the other window if file"
;; Should also display register contents if register is text
;; jump-to-register allows it to fail silently if non-legit
;; register is passed in

(let ((cur-buff (buffer-name)))
(jump-to-register register-name)
(let ((register-buffer (buffer-name)))
(switch-to-buffer cur-buff)
(switch-to-buffer-other-window register-buffer))))

(global-set-key (kbd "C-x 4 j") 'jump-to-register-other-window)


The first things which jump into my face are the broken indentation and a dangling parenthesis. Please fix them, otherwise the code is not very readable.

More to the point, I think it is better to replace the body with

(switch-to-buffer-other-window (register-buffer register-name))


and define

(defun register-buffer (register-name)
(save-window-excursion
(jump-to-register register-name)
(current-buffer)))

• I fixed the indentation and dangling bracket (I think, perhaps I've missed something). Thanks for save-excursion - I think that's what I was looking for. – Squidly Jul 31 '13 at 19:12
• save-excursion does not restore the buffer to the window it was in though (from gnu.org/software/emacs/manual/html_node/elisp/Excursions.html) – Squidly Jul 31 '13 at 19:32
• Edited to use save-window-excursion instead, thanks! – sds Jul 31 '13 at 19:40