emacsd / init-point.el

;;; init-point.el
;; Copyright (C) Yagnesh Raghava Yakkala.
;;    File: init-point.el
;; Created: Tuesday, August 30 2011
;; License: GPL v3 or later. You should get a copy from <>

;;; Description:

;; point-stack
;; -----------
;; Alternative *simple* mechanism for recording points and buffers and
;; switching back to them later.  Points are stored on a stack with push
;; and pop bound to really easy keys for quick use.  If something heavier
;; duty is needed, use registers (C-x r SPC and C-x r j).
(defvar point-stack nil
  "Stack to store point locations")

(defun push-point ()
  "Push the current point onto the stack."
  (setq point-stack (cons (point-marker) point-stack))
  (message "point pushed"))

(define-key global-map [(control ?z) ?,] 'push-point)         ; Bind to C-z ,

(defun pop-point ()
  "Try to pop a point from the stack and return to it."
  (if (not (null point-stack))
      (let ((m (car point-stack)))
        (setq point-stack (cdr point-stack))
        (if (not (marker-buffer m))
          (switch-to-buffer (marker-buffer m))
          (goto-char m))
        (message "point poped"))
    (message "No point in the stack")))

(define-key global-map [(control ?z) ?.] 'pop-point)          ; Bind to C-z .

;;; init-point.el ends here