Emacs: Extended point-to-register and jump-to-register

When working in Emacs, we may need to temporarily “bookmark” some places so that we can later jump to that line in the same session. For example, you want to search for something, but after done with that, you want to come back to the place you were initially. These routines allow to store upto 10 such points and later jump to those places.

The function upn-point-to-register stores the point to register ‘0′. It can be invoked with a numeric argument (0-9), and the point is saved in that register.

The function upn-jump-to-register jumps to register ‘0′. With a numeric argument, the cursor jumps to that register.

;; Quick point-to-register and jump-to-register
(defun upn-point-to-register (arg)
  "Puts point to register '0'.  With a numeric prefix argument, puts
point to the register given by the first digit of the argument."
  (interactive "P")
  (let ((register-name ?0))
    (if arg
        ;; There is some bug here
        (setq register-name (string-to-char (number-to-string arg))))
    (point-to-register register-name)))

(defun upn-jump-to-register (arg)
  "Jumps to register '0'.  With a numeric prefix argument, jumps to
the register given by the first digit of the argument."
  (interactive "P")
  (let ((register-name ?0))
    (if arg
        ;; There is some bug here
        (setq register-name (string-to-char (number-to-string arg))))
    (jump-to-register register-name)))

;; The following key-bindings are in upn-key-bindings.el
;; (global-set-key [C-f7]           'upn-point-to-register)
;; (global-set-key [M-f7]           'upn-jump-to-register)

I bound these two defuns to C-f7 and M-f7, so that I can easily provide the numeric argument. For example, C-4 C-f7 will put the current point into register ‘4′, while M-4 M-f7 will jump to register ‘4′.