Source

hyperbole / wconfig.el

Diff from to

wconfig.el

-;;!emacs
-;;
-;; FILE:         wconfig.el
-;; SUMMARY:      Saves and yanks from save ring of window configurations.
-;; USAGE:        GNU Emacs Lisp Library
-;; KEYWORDS:     frames, hypermedia
-;;
-;; AUTHOR:       Bob Weiner
-;; ORG:          BeOpen.com
-;;
-;; ORIG-DATE:    15-Mar-89
-;; LAST-MOD:     13-Jun-99 at 01:54:58 by Bob Weiner
-;;
-;; Copyright (C) 1989-1995, BeOpen.com and the Free Software Foundation, Inc.
-;; See the "HY-COPY" file for license information.
-;;
-;; This file is part of Hyperbole.
-;;
-;; DESCRIPTION:  
+;;; wconfig.el --- Saves and yanks from save ring of window configurations.
+
+;; Copyright (C) 1989-1995, Free Software Foundation, Inc.
+;; Developed with support from Motorola Inc.
+
+;; Author: Bob Weiner, Brown U.
+;; Maintainer: Mats Lidell <matsl@contactor.se>
+;; Keywords: frames, hypermedia
+
+;; This file is part of GNU Hyperbole.
+
+;; GNU Hyperbole is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as
+;; published by the Free Software Foundation; either version 2, or (at
+;; your option) any later version.
+
+;; GNU Hyperbole is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
+
+;;; Commentary:
 ;;
 ;;   This library provides two unrelated means of managing window
 ;;   configurations, (the set of windows and associated buffers within a
 ;;      wconfig-delete-by-name
 ;;      wconfig-restore-by-name
 ;;
-;;   The second means of window configuration management is through the use
-;;   of a ring structure, just like the Emacs kill ring except the elements
-;;   stored are window configurations instead of textual regions.  The
-;;   following functions support storage and sequential retrieval of window
+;;   The second means of window configuration management is through
+;;   the use of a ring structure, just like the Emacs kill ring except
+;;   the elements stored are window configurations instead of textual
+;;   regions. These configurations are local for a frame so there is a
+;;   ring of configurations for each frame.  The following functions
+;;   support storage and sequential retrieval of window
 ;;   configurations:
 ;;
 ;;      wconfig-ring-save
 ;;
 ;;   Based in part on kill-ring code from simple.el.
 ;;
-;; DESCRIP-END.
 
-;;; ************************************************************************
+;;; Code:
+
+;;;
 ;;; Recommended key bindings
-;;; ************************************************************************
+;;;
 
 ;;; Set up in local "hyperbole.el".
 
-;;; ************************************************************************
+;;;
 ;;; Other required Elisp libraries
-;;; ************************************************************************
+;;;
+(require 'ring)
 (require 'hargs)
 (require 'set)
 
-;;; ************************************************************************
+;;;
 ;;; Public variables
-;;; ************************************************************************
+;;;
 
 (defconst wconfig-ring-max 10
   "*Maximum length of window configuration ring before oldest elements are deleted.")
 
-(defvar wconfig-names (set:create)
-  "Set of (name . window-configuration) elements.")
-
-(defvar wconfig-ring nil
-  "List of window configurations saved in a ring.")
-
-(defvar wconfig-ring-yank-pointer nil
-  "The tail of the window configuration ring whose car is the last thing yanked.")
-
-;;; ************************************************************************
+;;;
 ;;; Public functions
-;;; ************************************************************************
+;;;
 
 ;;; Handling of name associations with each stored window configuration.
 ;;;###autoload
     (if (or (not (interactive-p))
 	    (not (set:member name wconfig-names))
 	    (y-or-n-p
-	      (format "Replace existing `%s' window configuration: " name)))
+	      (format "Replace existing '%s' window configuration: " name)))
 	(progn (setq wconfig-names
 		     (set:replace name (current-window-configuration)
 				  wconfig-names))
 	       (if (interactive-p)
-		   (message
-		    (substitute-command-keys
-		     (format "Window configuration `%s' saved.  Use {\\[wconfig-restore-by-name]} to restore." name))))))))
+		   (message "Window configuration '%s' saved.  Use 'wconfig-restore-by-name' to restore." name))))))
 
 ;;;###autoload
 (defun wconfig-delete-by-name (name)
   (let ((wconfig (set:get name wconfig-names)))
     (if wconfig
 	(set-window-configuration wconfig)
-      (error "(wconfig-restore-by-name): No window configuration named `%s'" name))))
+      (error "(wconfig-restore-by-name): No window configuration named '%s'" name))))
 
 ;;; Window configuration ring management (like text kill ring).
 ;;;###autoload
   "Replaces current window config with most recently saved config in ring.
 Then deletes this new configuration from the ring."
   (interactive)
-  (if (not wconfig-ring)
-      (error "(wconfig-delete-pop): Window configuration save ring is empty")
-    (set-window-configuration (car wconfig-ring))
-    (and (eq wconfig-ring wconfig-ring-yank-pointer)
-	 (setq wconfig-ring-yank-pointer (cdr wconfig-ring)))
-    (setq wconfig-ring (cdr wconfig-ring))))
+  (let ((ring (wconfig-get-ring)))
+    (if (ring-empty-p ring)
+	(error "(wconfig-delete-pop): Window configuration save ring is empty")
+      (ring-remove ring 0)
+      (if (ring-empty-p ring)
+	  (message "(wconfig-delete-pop): Window configuration save ring is empty")
+	(set-window-configuration (ring-ref ring 0))))))
 
 ;;;###autoload
 (defun wconfig-ring-save ()
   "Saves the current window configuration onto the save ring.
 Use {\\[wconfig-yank-pop]} to restore it at a later time."
   (interactive)
-  (setq wconfig-ring (cons (current-window-configuration) wconfig-ring))
-  (if (> (length wconfig-ring) wconfig-ring-max)
-      (setcdr (nthcdr (1- wconfig-ring-max) wconfig-ring) nil))
-  (setq wconfig-ring-yank-pointer wconfig-ring)
-  (wconfig-rotate-yank-pointer (1- (length wconfig-ring-yank-pointer)))
+  (ring-insert (wconfig-get-ring) (current-window-configuration))
   (if (interactive-p)
-      (message
-       (substitute-command-keys
-	"Window configuration saved.  Use {\\[wconfig-yank-pop]} to restore."))))
-
-(defun wconfig-rotate-yank-pointer (arg)
-  "Rotates the yanking point prefix ARG elements in the window configuration save ring.
-Interactively, default value of ARG = 1."
-  (interactive "p")
-  (let ((length (length wconfig-ring)))
-    (if (zerop length)
-	(error "(wconfig-rotate-yank-pointer): Window configuration save ring is empty")
-      (setq wconfig-ring-yank-pointer
-	    (nthcdr (% (+ arg (- length (length wconfig-ring-yank-pointer)))
-		       length)
-		    wconfig-ring)))))
+      (message "Window configuration saved.  Use 'wconfig-yank-pop' to restore.")))
 
 ;;;###autoload
 (defun wconfig-yank-pop (n)
 The sequence of window configurations wraps around, so that after the oldest
 one comes the newest one."
   (interactive "p")
-  (wconfig-rotate-yank-pointer n)
-  (set-window-configuration (car wconfig-ring-yank-pointer)))
+  (let ((ring (wconfig-get-ring)))
+    (if (ring-empty-p ring)
+	(error "(wconfig-yank-pop): Window configuration save ring is empty")
+      (let ((prev (ring-remove ring (- 1 n))))
+	(ring-insert-at-beginning ring prev)
+	(set-window-configuration (ring-ref ring 0))))))
 
-;;; ************************************************************************
+;;; Frames
+(defun wconfig-get-ring ()
+  (let* ((frame (selected-frame))
+	 (ring (frame-property frame 'wconfig-ring)))
+    (if (not ring)
+	(set-frame-property frame 'wconfig-ring (setq ring (make-ring wconfig-ring-max))))
+    ring))
+
+;;;
 ;;; Private variables
-;;; ************************************************************************
+;;;
+
+(defvar wconfig-names (set:create)
+  "Set of (name . window-configuration) elements.")
 
 (run-hooks 'wconfig-load-hook)
 
 (provide 'wconfig)
+
+;;; wconfig.el ends here
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 ProjectModifiedEvent.java.
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.