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)
\$\endgroup\$
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)))
\$\endgroup\$
  • \$\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\$ – Squidly Jul 31 '13 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\$ – Squidly Jul 31 '13 at 19:32
  • 1
    \$\begingroup\$ Edited to use save-window-excursion instead, thanks! \$\endgroup\$ – sds Jul 31 '13 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.