comparison lisp/hyperbole/hhist.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:376386a54a3c
1 ;;!emacs
2 ;;
3 ;; FILE: hhist.el
4 ;; SUMMARY: Maintains history of Hyperbole buttons selected.
5 ;; USAGE: GNU Emacs Lisp Library
6 ;; KEYWORDS: hypermedia
7 ;;
8 ;; AUTHOR: Bob Weiner
9 ;; ORG: Brown U.
10 ;;
11 ;; ORIG-DATE: 24-Apr-91 at 03:36:23
12 ;; LAST-MOD: 14-Apr-95 at 16:02:05 by Bob Weiner
13 ;;
14 ;; This file is part of Hyperbole.
15 ;; Available for use and distribution under the same terms as GNU Emacs.
16 ;;
17 ;; Copyright (C) 1991-1995, Free Software Foundation, Inc.
18 ;; Developed with support from Motorola Inc.
19 ;;
20 ;; DESCRIPTION:
21 ;;
22 ;; This is minimal right now and will be extended.
23 ;; Currently, it implements a push-pop stack of traversed locations.
24 ;;
25 ;; It will be extended to allow random access to previous locations
26 ;; and to store traversal histories for later recall.
27 ;;
28 ;; DESCRIP-END.
29
30 ;;; ************************************************************************
31 ;;; Public functions
32 ;;; ************************************************************************
33
34 (defun hhist:add (elt)
35 "Adds ELT to hyper-history list if not the same as current or previous loc.
36 ELT must have been created via a call to 'hhist:element'."
37 ;; Even though this next line looks useless, it cures a problem with
38 ;; window buffer correspondences on startup, so don't remove it.
39 (set-buffer (window-buffer (selected-window)))
40 (let ((prev-buf (car elt)))
41 (if (or (equal prev-buf (buffer-name))
42 (equal prev-buf (car (car *hhist*))))
43 nil
44 (setq *hhist* (cons elt *hhist*)))))
45
46 (defun hhist:element ()
47 "Returns a history element for current point location."
48 (list (current-buffer) (point)))
49
50 (defun hhist:remove (&optional arg)
51 "Removes optional prefix ARG entries from history, returns to ARGth location.
52 The command is ignored with ARG < 1."
53 (interactive "p")
54 (setq arg (or arg 1))
55 (let ((prev-buf-line))
56 (if (null *hhist*)
57 (and (> arg 0)
58 (message "(hhist:remove): No previous source to which to return.")
59 (beep))
60 (while (and (> arg 0) *hhist*)
61 (setq prev-buf-line (car *hhist*)
62 *hhist* (cdr *hhist*)
63 arg (1- arg)))
64 (switch-to-buffer (car prev-buf-line))
65 (goto-char (car (cdr prev-buf-line)))
66 )))
67
68 (defun hhist:init ()
69 "Resets history list."
70 (interactive)
71 (setq *hhist* nil))
72
73 ;;; ************************************************************************
74 ;;; Private functions
75 ;;; ************************************************************************
76
77 (defun hhist:wind-line ()
78 "Returns window relative line number that point is on."
79 (max 0 (1- (- (count-lines 1 (1+ (point)))
80 (count-lines 1 (window-start))))))
81
82 ;;; ************************************************************************
83 ;;; Private variables
84 ;;; ************************************************************************
85
86 (defconst *hhist* nil
87 "List of previously visited Hyperbole button source locations.
88 Car of list is most recent.")
89
90 (provide 'hhist)