annotate lisp/hyperbole/wconfig.el @ 80:1ce6082ce73f r20-0b90

Import from CVS: tag r20-0b90
author cvs
date Mon, 13 Aug 2007 09:06:37 +0200
parents 131b0175ea99
children 4be1180a9e89
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
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
9 ;; ORG: Brown U.
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
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
12 ;; LAST-MOD: 14-Apr-95 at 16:26:27 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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;;; Public functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;;; Handling of name associations with each stored window configuration.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (defun wconfig-add-by-name (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 "Saves the current window configuration under the string NAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 When called interactively and a window configuration already exists under
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 NAME, confirms whether or not to replace it."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (interactive "sName for current window configuration: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (or (stringp name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (error "(wconfig-add-by-name): NAME argument is not a string: %s" name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (let ((set:equal-op (function (lambda (key elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (equal key (car elt))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (if (or (not (interactive-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (not (set:member name wconfig-names))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (y-or-n-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (format "Replace existing '%s' window configuration: " name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (progn (setq wconfig-names
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (set:replace name (current-window-configuration)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 wconfig-names))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (message "Window configuration '%s' saved. Use 'wconfig-restore-by-name' to restore." name))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (defun wconfig-delete-by-name (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 "Deletes window configuration saved under NAME."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (interactive (list (hargs:read-match "Delete window configuration named: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 wconfig-names nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (or (stringp name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (error "(wconfig-delete-by-name): NAME argument is not a string: %s" name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (let ((set:equal-op (function (lambda (key elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (equal key (car elt))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (setq wconfig-names (set:remove name wconfig-names))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (defun wconfig-restore-by-name (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 "Restores window configuration saved under NAME."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (interactive (list (hargs:read-match "Restore window configuration named: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 wconfig-names nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (or (stringp name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (error "(wconfig-restore-by-name): NAME argument is not a string: %s" name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (let ((wconfig (set:get name wconfig-names)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (if wconfig
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (set-window-configuration wconfig)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (error "(wconfig-restore-by-name): No window configuration named '%s'" name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;;; Window configuration ring management (like text kill ring).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (defun wconfig-delete-pop ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 "Replaces current window config with most recently saved config in ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 Then deletes this new configuration from the ring."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (if (not wconfig-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (error "(wconfig-delete-pop): Window configuration save ring is empty")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (set-window-configuration (car wconfig-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (and (eq wconfig-ring wconfig-ring-yank-pointer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (setq wconfig-ring-yank-pointer (cdr wconfig-ring)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (setq wconfig-ring (cdr wconfig-ring))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (defun wconfig-ring-save ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 "Saves the current window configuration onto the save ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 Use {\\[wconfig-yank-pop]} to restore it at a later time."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (setq wconfig-ring (cons (current-window-configuration) wconfig-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (if (> (length wconfig-ring) wconfig-ring-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (setcdr (nthcdr (1- wconfig-ring-max) wconfig-ring) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (setq wconfig-ring-yank-pointer wconfig-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (wconfig-rotate-yank-pointer (1- (length wconfig-ring-yank-pointer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 "Window configuration saved. Use 'wconfig-yank-pop' to restore.")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (defun wconfig-rotate-yank-pointer (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 "Rotates the yanking point prefix ARG elements in the window configuration save ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 Interactively, default value of ARG = 1."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (let ((length (length wconfig-ring)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (if (zerop length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (error "(wconfig-rotate-yank-pointer): Window configuration save ring is empty")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (setq wconfig-ring-yank-pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (nthcdr (% (+ arg (- length (length wconfig-ring-yank-pointer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 wconfig-ring)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (defun wconfig-yank-pop (n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 "Replaces current window config with prefix arg Nth prior one in save ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 Interactively, default value of N = 1, meaning the last saved window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 configuration is displayed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 The sequence of window configurations wraps around, so that after the oldest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 one comes the newest one."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (wconfig-rotate-yank-pointer n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (set-window-configuration (car wconfig-ring-yank-pointer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 ;;; Private variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 ;;; ************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
171 (defvar wconfig-names (set:create)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
172 "Set of (name . window-configuration) elements.")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
173
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
174 (defvar wconfig-ring nil
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
175 "List of window configurations saved in a ring.")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
176
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
177 (defvar wconfig-ring-yank-pointer nil
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
178 "The tail of the window configuration ring whose car is the last thing yanked.")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
179
0
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)