hyperbole / hhist.el

;; FILE:         hhist.el
;; SUMMARY:      Maintains history of Hyperbole buttons selected.
;; USAGE:        GNU Emacs Lisp Library
;; KEYWORDS:     hypermedia
;; AUTHOR:       Bob Weiner
;; ORG:
;; ORIG-DATE:    24-Apr-91 at 03:36:23
;; LAST-MOD:     13-Jun-99 at 01:12:03 by Bob Weiner
;; Copyright (C) 1991-1995, 1998
;; See the HY-COPY (Hyperbole) or BR-COPY (OO-Browser) file for license
;; information.
;; This file is part of Hyperbole and the OO-Browser.
;;   This is minimal right now and will be extended.
;;   Currently, it implements a push-pop stack of traversed locations.
;;   It will be extended to allow random access to previous locations
;;   and to store traversal histories for later recall.

;;; ************************************************************************
;;; Public functions
;;; ************************************************************************

(defun hhist:add (elt)
  "Adds ELT to hyper-history list if not the same as current or previous loc.
ELT must have been created via a call to 'hhist:element'."
  ;; Even though this next line looks useless, it cures a problem with
  ;; window buffer correspondences on startup, so don't remove it.
  (set-buffer (window-buffer (selected-window)))
  (let ((prev-buf (car elt)))
    (if (or (equal prev-buf (buffer-name))
	    (equal prev-buf (car (car *hhist*))))
      (setq *hhist* (cons elt *hhist*)))))

(defun hhist:element ()
  "Returns a history element for current point location."
  (list (current-buffer) (point)))

(defun hhist:remove (&optional arg)
  "Removes optional prefix ARG entries from history, returns to ARGth location.
The command is ignored with ARG < 1."
  (interactive "p")
  (setq arg (or arg 1))
  (let ((prev-buf-line))
    (if (null *hhist*)
	(and (> arg 0)
	     (message "(hhist:remove): No previous source to which to return.")
      (while (and (> arg 0) *hhist*)
	(setq prev-buf-line (car *hhist*)
	      *hhist* (cdr *hhist*)
	      arg (1- arg)))
      (switch-to-buffer (car prev-buf-line))
      (goto-char (car (cdr prev-buf-line)))

(defun hhist:init ()
  "Resets history list."
  (setq *hhist* nil))

;;; ************************************************************************
;;; Private functions
;;; ************************************************************************

(defun hhist:wind-line ()
  "Returns window relative line number that point is on."
  (max 0 (1- (- (count-lines 1 (1+ (point)))
		(count-lines 1 (window-start))))))

;;; ************************************************************************
;;; Private variables
;;; ************************************************************************

(defconst *hhist* nil
  "List of previously visited Hyperbole button source locations.
Car of list is most recent.")

(provide 'hhist)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.