├── screenie.gif └── point-stack.el /screenie.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattharrison/point-stack/master/screenie.gif -------------------------------------------------------------------------------- /point-stack.el: -------------------------------------------------------------------------------- 1 | ;;; point-stack.el --- A forward/back stack for point 2 | 3 | ;; Author: Matt Harrison 4 | ;; Dmitry Gutov 5 | 6 | ;;; Commentary: 7 | 8 | ;; Provides forward/back stack for point. I use load it like so: 9 | ;; 10 | ;; (add-to-list 'load-path "/home/matt/work/emacs/point-stack") 11 | ;; (require 'point-stack) 12 | ;; (global-set-key '[(f5)] 'point-stack-push) 13 | ;; (global-set-key '[(f6)] 'point-stack-pop) 14 | ;; (global-set-key '[(f7)] 'point-stack-forward-stack-pop) 15 | ;; 16 | ;; Then when I know I'm going to want to come back to where I am I hit 17 | ;; f5. This stores the location of of the point. When I want to come 18 | ;; back to that point hit f6. I can go forward by hitting f7. 19 | ;; 20 | ;; based on http://www.emacswiki.org/emacs/JohnConnors 21 | ;; enhanced with forward-stack 22 | 23 | ;;; Code: 24 | 25 | (defvar point-stack-stack nil) 26 | ;; after you pop put it on the forward stack 27 | (defvar point-stack-forward-stack nil) 28 | 29 | ;;;###autoload 30 | (defun point-stack-push () 31 | "Push current buffer, point, and scroll position onto stack." 32 | (interactive) 33 | (point-stack-store 'point-stack-stack) 34 | (setq point-stack-forward-stack nil) ; new step resets forward history 35 | (message "Location marked.")) 36 | 37 | ;;;###autoload 38 | (defun point-stack-pop () 39 | "Push current location onto forward stack, move to previous location." 40 | (interactive) 41 | (if (null point-stack-stack) 42 | (message "Stack is empty.") 43 | (point-stack-store 'point-stack-forward-stack) 44 | (point-stack-go (car point-stack-stack)) 45 | (setq point-stack-stack (cdr point-stack-stack)))) 46 | 47 | ;;;###autoload 48 | (defun point-stack-forward-stack-pop () 49 | "Push current location onto stack, pop and move to location from forward stack." 50 | (interactive) 51 | (if (null point-stack-forward-stack) 52 | (message "forward Stack is empty.") 53 | (point-stack-store 'point-stack-stack) 54 | (point-stack-go (car point-stack-forward-stack)) 55 | (setq point-stack-forward-stack (cdr point-stack-forward-stack)))) 56 | 57 | (defun point-stack-store (stack) 58 | (let ((loc (car (symbol-value stack)))) 59 | ;; don't push the same location twice 60 | (unless (and (eq (current-buffer) (car loc)) 61 | (eq (point) (cadr loc))) 62 | (add-to-list stack (list (current-buffer) (point) (window-start)))))) 63 | 64 | (defun point-stack-go (loc) 65 | (switch-to-buffer (car loc)) 66 | (set-window-start nil (caddr loc)) 67 | (goto-char (cadr loc))) 68 | 69 | (provide 'point-stack) 70 | 71 | ;;; point-stack.el ends here 72 | --------------------------------------------------------------------------------