I wanted to speed up jumping in the same buffer so I have written this bookmarking utility (Similar to built-in registers) and put it in my .emacs file.
(defvar bookmark-markers '()) (defun bookmark (bookmark) "Store current position for this buffer in bookmar-markers a-list" (interactive "nBookmark: ") (let* ((buffer (current-buffer)) (bookmarks (let ((pair (assoc buffer bookmark-markers))) (if (eq pair nil) (let ((new-pair (cons buffer '()))) (progn (setq bookmark-markers (append bookmark-markers (list new-pair))) new-pair)) pair)))) (let ((pair (assoc bookmark bookmarks))) (if (eq pair nil) (setf (cdr bookmarks) (append (cdr bookmarks) (list (cons bookmark (point))))) (setf (cdr pair) (point)))))) (defun jump-to-bookmark (bookmark) "Jump to previously stored bookmark position" (interactive "nJump To: ") (let ((pair-bookmars (assoc (current-buffer) bookmark-markers))) (if (not (eq pair-bookmars nil)) (let ((pair-point (assoc bookmark (cdr pair-bookmars)))) (if (not (eq pair-point nil)) (goto-char (cdr pair-point))))))) (defun range (n &optional list) "function return list of numbers from 1 to n" (if (eq n 0) list (let ((n (- n 1))) (range n (cons n list))))) (dolist (i (range 9)) (global-set-key (read-kbd-macro (concat "C-c " (number-to-string i))) ;; emacs lisp have no closures (lexical-let ((i i)) (lambda () (interactive) (jump-to-bookmark i))))) (global-set-key (kbd "C-c 0") 'bookmark)
Above code define 2 functions
bookmark bind to
C-c 0 and function
jump-to-bookmark this function create a bookmark, for currect position in a buffer, and assing it to the number (passed as argument or from minubuffer, if run interactively). You have 9 keyboard binding for keys from
C-c 1 to
You can use it go to specific location and type
C-c 0 1 RET go to another location and type
C-c 0 2 RET and now you can jump to locations with
C-c 1 or
Every buffer will have they own bookmarks.