annotate lisp/hyperbole/wconfig.el @ 100:4be1180a9e89 r20-1b2

Import from CVS: tag r20-1b2
author cvs
date Mon, 13 Aug 2007 09:15:11 +0200
parents 131b0175ea99
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;!emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; FILE: wconfig.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; SUMMARY: Saves and yanks from save ring of window configurations.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; USAGE: GNU Emacs Lisp Library
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; KEYWORDS: frames, hypermedia
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; AUTHOR: Bob Weiner
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
9 ;; ORG: InfoDock Associates
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; ORIG-DATE: 15-Mar-89
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
12 ;; LAST-MOD: 9-Dec-96 at 18:39:50 by Bob Weiner
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; This file is part of Hyperbole.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; Available for use and distribution under the same terms as GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; Copyright (C) 1989-1995, Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; Developed with support from Motorola Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; DESCRIPTION:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; This library provides two unrelated means of managing window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; configurations, (the set of windows and associated buffers within a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;; frame). The first means associates a name with each stored window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;; configuration. The name can then be used to retrieve the window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; configuration later. The following functions provide this behavior:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; wconfig-add-by-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; wconfig-delete-by-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; wconfig-restore-by-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; The second means of window configuration management is through the use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; of a ring structure, just like the Emacs kill ring except the elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; stored are window configurations instead of textual regions. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; following functions support storage and sequential retrieval of window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; configurations:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; wconfig-ring-save
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; wconfig-yank-pop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; wconfig-delete-pop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;; None of this information is stored between Emacs sessions, so your
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;; window configurations will last only through a single session of use.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;; Based in part on kill-ring code from simple.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; DESCRIP-END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;;; Recommended key bindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;; Set up in local "hyperbole.el".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;;; Other required Elisp libraries
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (require 'hargs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (require 'set)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;;; Public variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (defconst wconfig-ring-max 10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 "*Maximum length of window configuration ring before oldest elements are deleted.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
68 (defvar wconfig-names (set:create)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
69 "Set of (name . window-configuration) elements.")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
70
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
71 (defvar wconfig-ring nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
72 "List of window configurations saved in a ring.")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
73
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
74 (defvar wconfig-ring-yank-pointer nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
75 "The tail of the window configuration ring whose car is the last thing yanked.")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
76
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;;; Public functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;;; Handling of name associations with each stored window configuration.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (defun wconfig-add-by-name (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 "Saves the current window configuration under the string NAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 When called interactively and a window configuration already exists under
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 NAME, confirms whether or not to replace it."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (interactive "sName for current window configuration: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (or (stringp name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (error "(wconfig-add-by-name): NAME argument is not a string: %s" name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (let ((set:equal-op (function (lambda (key elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (equal key (car elt))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (if (or (not (interactive-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (not (set:member name wconfig-names))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (y-or-n-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (format "Replace existing '%s' window configuration: " name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (progn (setq wconfig-names
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (set:replace name (current-window-configuration)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 wconfig-names))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (message "Window configuration '%s' saved. Use 'wconfig-restore-by-name' to restore." name))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (defun wconfig-delete-by-name (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 "Deletes window configuration saved under NAME."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (interactive (list (hargs:read-match "Delete window configuration named: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 wconfig-names nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (or (stringp name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (error "(wconfig-delete-by-name): NAME argument is not a string: %s" name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (let ((set:equal-op (function (lambda (key elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (equal key (car elt))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (setq wconfig-names (set:remove name wconfig-names))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (defun wconfig-restore-by-name (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 "Restores window configuration saved under NAME."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (interactive (list (hargs:read-match "Restore window configuration named: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 wconfig-names nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (or (stringp name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (error "(wconfig-restore-by-name): NAME argument is not a string: %s" name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (let ((wconfig (set:get name wconfig-names)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (if wconfig
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (set-window-configuration wconfig)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (error "(wconfig-restore-by-name): No window configuration named '%s'" name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 ;;; Window configuration ring management (like text kill ring).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (defun wconfig-delete-pop ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 "Replaces current window config with most recently saved config in ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 Then deletes this new configuration from the ring."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (if (not wconfig-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (error "(wconfig-delete-pop): Window configuration save ring is empty")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (set-window-configuration (car wconfig-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (and (eq wconfig-ring wconfig-ring-yank-pointer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (setq wconfig-ring-yank-pointer (cdr wconfig-ring)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (setq wconfig-ring (cdr wconfig-ring))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (defun wconfig-ring-save ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 "Saves the current window configuration onto the save ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 Use {\\[wconfig-yank-pop]} to restore it at a later time."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (setq wconfig-ring (cons (current-window-configuration) wconfig-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (if (> (length wconfig-ring) wconfig-ring-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (setcdr (nthcdr (1- wconfig-ring-max) wconfig-ring) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (setq wconfig-ring-yank-pointer wconfig-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (wconfig-rotate-yank-pointer (1- (length wconfig-ring-yank-pointer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 "Window configuration saved. Use 'wconfig-yank-pop' to restore.")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (defun wconfig-rotate-yank-pointer (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 "Rotates the yanking point prefix ARG elements in the window configuration save ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 Interactively, default value of ARG = 1."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (let ((length (length wconfig-ring)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (if (zerop length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (error "(wconfig-rotate-yank-pointer): Window configuration save ring is empty")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (setq wconfig-ring-yank-pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (nthcdr (% (+ arg (- length (length wconfig-ring-yank-pointer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 wconfig-ring)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (defun wconfig-yank-pop (n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 "Replaces current window config with prefix arg Nth prior one in save ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 Interactively, default value of N = 1, meaning the last saved window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 configuration is displayed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 The sequence of window configurations wraps around, so that after the oldest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 one comes the newest one."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (wconfig-rotate-yank-pointer n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (set-window-configuration (car wconfig-ring-yank-pointer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 ;;; Private variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (run-hooks 'wconfig-load-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (provide 'wconfig)