\$\begingroup\$
\$\endgroup\$
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)
1 Answer 1
\$\begingroup\$
\$\endgroup\$
3
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)))
-
\$\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– Squidly2013年07月31日 19:12:14 +00:00Commented 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\$Squidly– Squidly2013年07月31日 19:32:59 +00:00Commented Jul 31, 2013 at 19:32 -
1\$\begingroup\$ Edited to use
save-window-excursion
instead, thanks! \$\endgroup\$sds– sds2013年07月31日 19:40:58 +00:00Commented Jul 31, 2013 at 19:40
lang-lisp