;; Copyright (C) 2003 Erik Johansson ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation; either version 2 of ;; the License, or (at your option) any later version. ;; This program is distributed in the hope that it will be ;; useful, but WITHOUT ANY WARRANTY; without even the implied ;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ;; PURPOSE. See the GNU General Public License for more details. ;; You should have received a copy of the GNU General Public ;; License along with this program; if not, write to the Free ;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, ;; MA 02111-1307 USA ;; Changelog: ;; 2003-04-11 [0.1]: ;; * Created. ;; This script enables you to bookmark a position in a buffer ;; (default: C-S-<0-9>) and later return to it (default: C-<0-9>). ;; ;; Load it by adding this to your .emacs: ;; (load "/path/to/bookmarks.el") ;; ========== Settings ========== (defconst no-buffer-bookmarks 10) ;; Keys for going to bookmark. (global-set-key (kbd "C-1") (lambda () (interactive) (get-bookmark-pos 0))) (global-set-key (kbd "C-2") (lambda () (interactive) (get-bookmark-pos 1))) (global-set-key (kbd "C-3") (lambda () (interactive) (get-bookmark-pos 2))) (global-set-key (kbd "C-4") (lambda () (interactive) (get-bookmark-pos 3))) (global-set-key (kbd "C-5") (lambda () (interactive) (get-bookmark-pos 4))) (global-set-key (kbd "C-6") (lambda () (interactive) (get-bookmark-pos 5))) (global-set-key (kbd "C-7") (lambda () (interactive) (get-bookmark-pos 6))) (global-set-key (kbd "C-8") (lambda () (interactive) (get-bookmark-pos 7))) (global-set-key (kbd "C-9") (lambda () (interactive) (get-bookmark-pos 8))) (global-set-key (kbd "C-0") (lambda () (interactive) (get-bookmark-pos 9))) ;; Keys for seting bookmar. (global-set-key (kbd "s-1") (lambda () (interactive) (set-bookmark-pos (point-marker) 0))) (global-set-key (kbd "s-2") (lambda () (interactive) (set-bookmark-pos (point-marker) 1))) (global-set-key (kbd "s-3") (lambda () (interactive) (set-bookmark-pos (point-marker) 2))) (global-set-key (kbd "s-4") (lambda () (interactive) (set-bookmark-pos (point-marker) 3))) (global-set-key (kbd "s-5") (lambda () (interactive) (set-bookmark-pos (point-marker) 4))) (global-set-key (kbd "s-6") (lambda () (interactive) (set-bookmark-pos (point-marker) 5))) (global-set-key (kbd "s-7") (lambda () (interactive) (set-bookmark-pos (point-marker) 6))) (global-set-key (kbd "s-8") (lambda () (interactive) (set-bookmark-pos (point-marker) 7))) (global-set-key (kbd "s-9") (lambda () (interactive) (set-bookmark-pos (point-marker) 8))) (global-set-key (kbd "s-0") (lambda () (interactive) (set-bookmark-pos (point-marker) 9))) ;; ======== End settings ======== ;; Set bookmark nr to marker. (defun set-bookmark-pos (marker nr) "marker x nr ->" (if (and (boundp 'buffer-bookmarks) (vectorp buffer-bookmarks)) (when (markerp marker) (progn (aset buffer-bookmarks nr marker) (message "Saved as bookmark no. %i" (1+ nr)))) (progn (setq buffer-bookmarks (make-vector 10 'nil)) (set-bookmark-pos marker nr)))) ;; Activate buffer and goto position as described by bookmark nr (defun get-bookmark-pos (nr) "nr ->" (if (and (boundp 'buffer-bookmarks) (vectorp buffer-bookmarks)) (let ((marker (aref buffer-bookmarks nr))) (if (and (markerp marker) (marker-buffer marker)) (progn (switch-to-buffer (marker-buffer marker)) (goto-char (marker-position marker))) (message "No such bookmark."))) (message "No bookmark set.")))