-;; Register commands for Emacs.
+;;; register.el --- register commands for Emacs.
+
;; Copyright (C) 1985 Free Software Foundation, Inc.
+;; Maintainer: FSF
+;; Keywords: internal
+
;; This file is part of GNU Emacs.
;; GNU Emacs 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 1, or (at your option)
+;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;;; Commentary:
+
+;; This package of functions emulates and somewhat extends the venerable
+;; TECO's `register' feature, which permits you to save various useful
+;; pieces of buffer state to named variables. The entry points are
+;; documented in the Emacs user's manual.
+
+;;; Code:
(defvar register-alist nil
"Alist of elements (NAME . CONTENTS), one for each Emacs register.
NAME is a character (a number). CONTENTS is a string, number,
-screen configuration, mark or list.
-A list represents a rectangle; its elements are strings.")
+frame configuration, mark or list.
+A list of strings represents a rectangle.
+A list of the form (file . NAME) represents the file named NAME.")
(defun get-register (char)
"Return contents of Emacs register named CHAR, or nil if none."
(cdr (assq char register-alist)))
(defun set-register (char value)
- "Set contents of Emacs register named CHAR to VALUE.
-Returns VALUE."
+ "Set contents of Emacs register named CHAR to VALUE. Returns VALUE.
+See the documentation of the variable `register-alist' for possible VALUE."
(let ((aelt (assq char register-alist)))
(if aelt
(setcdr aelt value)
(setq register-alist (cons aelt register-alist)))
value))
-(defun point-to-register (char arg)
+(defun point-to-register (char &optional arg)
"Store current location of point in register REGISTER.
-With prefix argument, store current screen configuration.
+With prefix argument, store current frame configuration.
Use \\[jump-to-register] to go to that location or restore that configuration.
Argument is a character, naming the register."
(interactive "cPoint to register: \nP")
- (set-register char (if arg (current-screen-configuration) (point-marker))))
+ (set-register char (if arg (current-frame-configuration) (point-marker))))
-(fset 'register-to-point 'jump-to-register)
+(defun window-configuration-to-register (char &optional arg)
+ "Store the window configuration of the selected frame in register REGISTER.
+Use \\[jump-to-register] to restore the configuration.
+Argument is a character, naming the register."
+ (interactive "cPoint to register: \nP")
+ (set-register char (current-window-configuration)))
+
+(defun frame-configuration-to-register (char &optional arg)
+ "Store the window configuration of all frames in register REGISTER.
+Use \\[jump-to-register] to restore the configuration.
+Argument is a character, naming the register."
+ (interactive "cPoint to register: \nP")
+ (set-register char (current-frame-configuration)))
+
+(defalias 'register-to-point 'jump-to-register)
(defun jump-to-register (char)
"Move point to location stored in a register.
+If the register contains a file name, find that file.
+ \(To put a file name in a register, you must use `set-register'.)
+If the register contains a window configuration (one frame) or a frame
+configuration (all frames), restore that frame or all frames accordingly.
Argument is a character, naming the register."
(interactive "cJump to register: ")
(let ((val (get-register char)))
- (condition-case ()
- (set-screen-configuration val)
- (error
- (if (markerp val)
- (progn
- (switch-to-buffer (marker-buffer val))
- (goto-char val))
- (error "Register doesn't contain a buffer position or screen configuration"))))))
+ (cond
+ ((frame-configuration-p val)
+ (set-frame-configuration val))
+ ((window-configuration-p val)
+ (set-window-configuration val))
+ ((markerp val)
+ (switch-to-buffer (marker-buffer val))
+ (goto-char val))
+ ((and (consp val) (eq (car val) 'file))
+ (find-file (cdr val)))
+ (t
+ (error "Register doesn't contain a buffer position or configuration")))))
;(defun number-to-register (arg char)
; "Store a number in a register.
(princ "Register ")
(princ (single-key-description char))
(princ " contains ")
- (if (integerp val)
- (princ val)
- (if (markerp val)
- (progn
- (princ "a buffer position:\nbuffer ")
- (princ (buffer-name (marker-buffer val)))
- (princ ", position ")
- (princ (+ 0 val)))
- (if (consp val)
- (progn
- (princ "the rectangle:\n")
- (while val
- (princ (car val))
- (terpri)
- (setq val (cdr val))))
- (princ "the string:\n")
- (princ val))))))))
+ (cond
+ ((integerp val)
+ (princ val))
+
+ ((markerp val)
+ (princ "a buffer position:\nbuffer ")
+ (princ (buffer-name (marker-buffer val)))
+ (princ ", position ")
+ (princ (+ 0 val)))
+
+ ((window-configuration-p val)
+ (princ "a window configuration."))
+
+ ((frame-configuration-p val)
+ (princ "a frame configuration."))
+
+ ((consp val)
+ (princ "the rectangle:\n")
+ (while val
+ (princ (car val))
+ (terpri)
+ (setq val (cdr val))))
+
+ ((stringp val)
+ (princ "the text:\n")
+ (princ val))
+
+ (t
+ (princ "Garbage:\n")
+ (prin1 val)))))))
(defun insert-register (char &optional arg)
"Insert contents of register REG. REG is a character.
(if (not arg) (exchange-point-and-mark)))
(defun copy-to-register (char start end &optional delete-flag)
- "Copy region into register REG.
-With prefix arg, delete as well.
-Called from program, takes four args:
-REG, START, END and DELETE-FLAG.
+ "Copy region into register REG. With prefix arg, delete as well.
+Called from program, takes four args: REG, START, END and DELETE-FLAG.
START and END are buffer positions indicating what to copy."
(interactive "cCopy to register: \nr\nP")
(set-register char (buffer-substring start end))
(if delete-flag (delete-region start end)))
(defun append-to-register (char start end &optional delete-flag)
- "Append region to text in register REG.
-With prefix arg, delete as well.
-Called from program, takes four args:
-REG, START, END and DELETE-FLAG.
+ "Append region to text in register REG. With prefix arg, delete as well.
+Called from program, takes four args: REG, START, END and DELETE-FLAG.
START and END are buffer positions indicating what to append."
(interactive "cAppend to register: \nr\nP")
(or (stringp (get-register char))
(if delete-flag (delete-region start end)))
(defun prepend-to-register (char start end &optional delete-flag)
- "Prepend region to text in register REG.
-With prefix arg, delete as well.
-Called from program, takes four args:
-REG, START, END and DELETE-FLAG.
+ "Prepend region to text in register REG. With prefix arg, delete as well.
+Called from program, takes four args: REG, START, END and DELETE-FLAG.
START and END are buffer positions indicating what to prepend."
(interactive "cPrepend to register: \nr\nP")
(or (stringp (get-register char))
(if delete-flag (delete-region start end)))
(defun copy-rectangle-to-register (char start end &optional delete-flag)
- "Copy rectangular region into register REG.
-With prefix arg, delete as well.
-Called from program, takes four args:
-REG, START, END and DELETE-FLAG.
+ "Copy rectangular region into register REG. With prefix arg, delete as well.
+Called from program, takes four args: REG, START, END and DELETE-FLAG.
START and END are buffer positions giving two corners of rectangle."
(interactive "cCopy rectangle to register: \nr\nP")
(set-register char
(if delete-flag
(delete-extract-rectangle start end)
(extract-rectangle start end))))
+
+;;; register.el ends here