1
\$\begingroup\$

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
 (interactive "cJump to register: \n")
 (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)
asked Jul 30, 2013 at 0:54
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

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)))
answered Jul 30, 2013 at 4:59
\$\endgroup\$
3
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Jul 31, 2013 at 19:12
  • \$\begingroup\$ 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) \$\endgroup\$ Commented Jul 31, 2013 at 19:32
  • 1
    \$\begingroup\$ Edited to use save-window-excursion instead, thanks! \$\endgroup\$ Commented Jul 31, 2013 at 19:40

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.