aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuanma Barranquero2013-08-08 11:54:29 +0200
committerJuanma Barranquero2013-08-08 11:54:29 +0200
commit76c5e5ab36d7f05f34c1bcca4b3ec6d1fcbfce86 (patch)
tree882dbad1682aab479a1fb45d95ca891e695eb867
parent628fdc567a63c5cc6959ca5a4e09eb9b1d3e6092 (diff)
downloademacs-76c5e5ab36d7f05f34c1bcca4b3ec6d1fcbfce86.tar.gz
emacs-76c5e5ab36d7f05f34c1bcca4b3ec6d1fcbfce86.zip
lisp/frameset.el: Revert to built-in frameset-p; document slot accessors.
(frameset): Do not disable creation of the default frameset-p predicate. Doc fix. (frameset-valid-p): New function, copied from the old predicate-p. Add additional checks. (frameset-restore): Check with frameset-valid-p. (frameset-p, frameset-version, frameset-timestamp, frameset-app) (frameset-name, frameset-description, frameset-properties) (frameset-states): Add docstring.
-rw-r--r--lisp/ChangeLog11
-rw-r--r--lisp/frameset.el172
2 files changed, 116 insertions, 67 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 5968298904e..b7964fa4517 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,16 @@
12013-08-08 Juanma Barranquero <lekktu@gmail.com> 12013-08-08 Juanma Barranquero <lekktu@gmail.com>
2 2
3 * frameset.el (frameset): Do not disable creation of the default
4 frameset-p predicate. Doc fix.
5 (frameset-valid-p): New function, copied from the old predicate-p.
6 Add additional checks.
7 (frameset-restore): Check with frameset-valid-p.
8 (frameset-p, frameset-version, frameset-timestamp, frameset-app)
9 (frameset-name, frameset-description, frameset-properties)
10 (frameset-states): Add docstring.
11
122013-08-08 Juanma Barranquero <lekktu@gmail.com>
13
3 * frameset.el (frameset-p, frameset-prop): Doc fixes. 14 * frameset.el (frameset-p, frameset-prop): Doc fixes.
4 15
52013-08-08 Stefan Monnier <monnier@iro.umontreal.ca> 162013-08-08 Stefan Monnier <monnier@iro.umontreal.ca>
diff --git a/lisp/frameset.el b/lisp/frameset.el
index 43f0e929c6c..52d01c70d64 100644
--- a/lisp/frameset.el
+++ b/lisp/frameset.el
@@ -42,9 +42,8 @@
42 42
43 43
44(cl-defstruct (frameset (:type vector) :named 44(cl-defstruct (frameset (:type vector) :named
45 ;; Copier and predicate functions are defined below. 45 ;; Copier is defined below.
46 (:copier nil) 46 (:copier nil))
47 (:predicate nil))
48 47
49 "A frameset encapsulates a serializable view of a set of frames and windows. 48 "A frameset encapsulates a serializable view of a set of frames and windows.
50 49
@@ -81,9 +80,8 @@ A frameset is intended to be used through the following simple API:
81 live frames, and returns a serializable snapshot of them (a frameset). 80 live frames, and returns a serializable snapshot of them (a frameset).
82 - `frameset-restore' takes a frameset, and restores the frames and windows 81 - `frameset-restore' takes a frameset, and restores the frames and windows
83 it describes, as faithfully as possible. 82 it describes, as faithfully as possible.
84 - `frameset-p' is the predicate for the frameset type. It returns nil 83 - `frameset-p' is the predicate for the frameset type.
85 for non-frameset objects, and the frameset version number (see below) 84 - `frameset-valid-p' checks a frameset's validity.
86 for frameset objects.
87 - `frameset-copy' returns a deep copy of a frameset. 85 - `frameset-copy' returns a deep copy of a frameset.
88 - `frameset-prop' is a `setf'able accessor for the contents of the 86 - `frameset-prop' is a `setf'able accessor for the contents of the
89 `properties' slot. 87 `properties' slot.
@@ -97,23 +95,63 @@ A frameset is intended to be used through the following simple API:
97 (properties nil) 95 (properties nil)
98 (states nil)) 96 (states nil))
99 97
98;; Add nicer docstrings for built-in predicate and accessors.
99(put 'frameset-p 'function-documentation
100 "Return non-nil if OBJECT is a frameset, nil otherwise.\n\n(fn OBJECT)")
101(put 'frameset-version 'function-documentation
102 "Return the version number of FRAMESET.\n
103It is an integer that identifies the format of the frameset struct.
104This slot cannot be modified.\n\n(fn FRAMESET)")
105(put 'frameset-timestamp 'function-documentation
106 "Return the creation timestamp of FRAMESET.\n
107The value is in the format returned by `current-time'.
108This slot cannot be modified.\n\n(fn FRAMESET)")
109(put 'frameset-app 'function-documentation
110 "Return the application identifier for FRAMESET.\n
111The value is either a symbol, like `my-app', or a list
112\(my-app ADDITIONAL-DATA...).\n\n(fn FRAMESET)")
113(put 'frameset-name 'function-documentation
114 "Return the name of FRAMESET (a string).\n\n(fn FRAMESET)")
115(put 'frameset-description 'function-documentation
116 "Return the description of FRAMESET (a string).\n\n(fn FRAMESET)")
117(put 'frameset-properties 'function-documentation
118 "Return the property list of FRAMESET.\n
119This list is useful to store both frameset-specific and user-defined
120serializable data. The simplest way to access and modify it is
121through `frameset-prop' (which see).\n\n(fn FRAMESET)")
122(put 'frameset-states 'function-documentation
123 "Return the list of frame states of FRAMESET.\n
124A frame state is a pair (FRAME-PARAMETERS . WINDOW-STATE), where
125FRAME-PARAMETERS is a frame's parameter alist, extracted with
126\(frame-parameters FRAME) and filtered through `frameset-filter-params',
127and WINDOW-STATE is the output of `window-state-get' applied to the
128root window of the frame.\n
129IMPORTANT: Modifying this slot may cause frameset functions to fail,
130unless the type constraints defined above are respected.\n\n(fn FRAMESET)")
131
100(defun frameset-copy (frameset) 132(defun frameset-copy (frameset)
101 "Return a deep copy of FRAMESET. 133 "Return a deep copy of FRAMESET.
102FRAMESET is copied with `copy-tree'." 134FRAMESET is copied with `copy-tree'."
103 (copy-tree frameset t)) 135 (copy-tree frameset t))
104 136
105;;;###autoload 137;;;###autoload
106(defun frameset-p (object) 138(defun frameset-valid-p (object)
107 "Return non-nil if OBJECT is a frameset, nil otherwise." 139 "Return non-nil if OBJECT is a valid frameset, nil otherwise."
108 (and (vectorp object) ; a vector 140 (and (vectorp object) ; a vector
109 (eq (aref object 0) 'frameset) ; tagged as `frameset' 141 (eq (aref object 0) 'frameset) ; tagged as `frameset'
110 (integerp (aref object 1)) ; version is an int 142 (integerp (aref object 1)) ; VERSION is an int
111 (consp (aref object 2)) ; timestamp is a non-null list 143 (consp (aref object 2)) ; TIMESTAMP is a non-null list
112 (stringp (or (aref object 4) "")) ; name is a string or null 144 (let ((app (aref object 3)))
113 (stringp (or (aref object 5) "")) ; description is a string or null 145 (or (null app) ; APP is nil
114 (listp (aref object 6)) ; properties is a list 146 (symbolp app) ; or a symbol
115 (consp (aref object 7)) ; and states is non-null 147 (and (consp app) ; or a list
116 (aref object 1))) ; return version 148 (symbolp (car app))))) ; starting with a symbol
149 (stringp (or (aref object 4) "")) ; NAME is a string or nil
150 (stringp (or (aref object 5) "")) ; DESCRIPTION is a string or nil
151 (listp (aref object 6)) ; PROPERTIES is a list
152 (consp (aref object 7)) ; and STATES is non-nil
153 (cl-every #'consp (aref object 7)) ; and an alist
154 (aref object 1))) ; return VERSION
117 155
118;; A setf'able accessor to the frameset's properties 156;; A setf'able accessor to the frameset's properties
119(defun frameset-prop (frameset property) 157(defun frameset-prop (frameset property)
@@ -174,14 +212,14 @@ Properties can be set with
174;; what `frameset-filter-params' and the `frameset-*-filter-alist' variables 212;; what `frameset-filter-params' and the `frameset-*-filter-alist' variables
175;; are for. 213;; are for.
176;; 214;;
177;; First, a clarification: the word "filter" in these names refers to both 215;; First, a clarification. The word "filter" in these names refers to both
178;; common meanings of filter: to filter out (i.e., to remove), and to pass 216;; common meanings of filter: to filter out (i.e., to remove), and to pass
179;; through a transformation function (think `filter-buffer-substring'). 217;; through a transformation function (think `filter-buffer-substring').
180;; 218;;
181;; `frameset-filter-params' takes a parameter alist PARAMETERS, a filtering 219;; `frameset-filter-params' takes a parameter alist PARAMETERS, a filtering
182;; alist FILTER-ALIST, and a flag SAVING to indicate whether we are filtering 220;; alist FILTER-ALIST, and a flag SAVING to indicate whether we are filtering
183;; parameters with the intent of saving a frame or restoring it. It then 221;; parameters with the intent of saving a frame or restoring it. It then
184;; accumulates an output list, FILTERED, by checking each parameter in 222;; accumulates an output alist, FILTERED, by checking each parameter in
185;; PARAMETERS against FILTER-ALIST and obeying any rule found there. The 223;; PARAMETERS against FILTER-ALIST and obeying any rule found there. The
186;; absence of a rule just means the parameter/value pair (called CURRENT in 224;; absence of a rule just means the parameter/value pair (called CURRENT in
187;; filtering functions) is copied to FILTERED as is. Keyword values :save, 225;; filtering functions) is copied to FILTERED as is. Keyword values :save,
@@ -232,7 +270,7 @@ Properties can be set with
232;; a graphical display. 270;; a graphical display.
233;; 271;;
234;; - `tty', `tty-type': These are tty-specific. When switching to a GUI 272;; - `tty', `tty-type': These are tty-specific. When switching to a GUI
235;; display they do no harm, but they clutter the parameter list. 273;; display they do no harm, but they clutter the parameter alist.
236;; 274;;
237;; - `minibuffer': It can contain a reference to a live window, which cannot 275;; - `minibuffer': It can contain a reference to a live window, which cannot
238;; be serialized. Because of Emacs' idiosyncratic treatment of this 276;; be serialized. Because of Emacs' idiosyncratic treatment of this
@@ -249,7 +287,7 @@ Properties can be set with
249;; surely there are applications that will want to override this filter. 287;; surely there are applications that will want to override this filter.
250;; 288;;
251;; - `font', `fullscreen', `height' and `width': These parameters suffer 289;; - `font', `fullscreen', `height' and `width': These parameters suffer
252;; from the fact that they are badly manged when going through a 290;; from the fact that they are badly mangled when going through a
253;; tty session, though not all in the same way. When saving a GUI frame 291;; tty session, though not all in the same way. When saving a GUI frame
254;; and restoring it in a tty, the height and width of the new frame are 292;; and restoring it in a tty, the height and width of the new frame are
255;; those of the tty screen (let's say 80x25, for example); going back 293;; those of the tty screen (let's say 80x25, for example); going back
@@ -389,35 +427,35 @@ Properties can be set with
389 427
390;;;###autoload 428;;;###autoload
391(defvar frameset-session-filter-alist 429(defvar frameset-session-filter-alist
392 '((name . :never) 430 '((name . :never)
393 (left . frameset-filter-iconified) 431 (left . frameset-filter-iconified)
394 (minibuffer . frameset-filter-minibuffer) 432 (minibuffer . frameset-filter-minibuffer)
395 (top . frameset-filter-iconified)) 433 (top . frameset-filter-iconified))
396 "Minimum set of parameters to filter for live (on-session) framesets. 434 "Minimum set of parameters to filter for live (on-session) framesets.
397See `frameset-filter-alist' for a full description.") 435See `frameset-filter-alist' for a full description.")
398 436
399;;;###autoload 437;;;###autoload
400(defvar frameset-persistent-filter-alist 438(defvar frameset-persistent-filter-alist
401 (nconc 439 (nconc
402 '((background-color . frameset-filter-sanitize-color) 440 '((background-color . frameset-filter-sanitize-color)
403 (buffer-list . :never) 441 (buffer-list . :never)
404 (buffer-predicate . :never) 442 (buffer-predicate . :never)
405 (buried-buffer-list . :never) 443 (buried-buffer-list . :never)
406 (font . frameset-filter-shelve-param) 444 (font . frameset-filter-shelve-param)
407 (foreground-color . frameset-filter-sanitize-color) 445 (foreground-color . frameset-filter-sanitize-color)
408 (fullscreen . frameset-filter-shelve-param) 446 (fullscreen . frameset-filter-shelve-param)
409 (GUI:font . frameset-filter-unshelve-param) 447 (GUI:font . frameset-filter-unshelve-param)
410 (GUI:fullscreen . frameset-filter-unshelve-param) 448 (GUI:fullscreen . frameset-filter-unshelve-param)
411 (GUI:height . frameset-filter-unshelve-param) 449 (GUI:height . frameset-filter-unshelve-param)
412 (GUI:width . frameset-filter-unshelve-param) 450 (GUI:width . frameset-filter-unshelve-param)
413 (height . frameset-filter-shelve-param) 451 (height . frameset-filter-shelve-param)
414 (outer-window-id . :never) 452 (outer-window-id . :never)
415 (parent-id . :never) 453 (parent-id . :never)
416 (tty . frameset-filter-tty-to-GUI) 454 (tty . frameset-filter-tty-to-GUI)
417 (tty-type . frameset-filter-tty-to-GUI) 455 (tty-type . frameset-filter-tty-to-GUI)
418 (width . frameset-filter-shelve-param) 456 (width . frameset-filter-shelve-param)
419 (window-id . :never) 457 (window-id . :never)
420 (window-system . :never)) 458 (window-system . :never))
421 frameset-session-filter-alist) 459 frameset-session-filter-alist)
422 "Parameters to filter for persistent framesets. 460 "Parameters to filter for persistent framesets.
423See `frameset-filter-alist' for a full description.") 461See `frameset-filter-alist' for a full description.")
@@ -442,9 +480,9 @@ parameter), and ACTION can be:
442 480
443 nil The parameter is copied to FILTERED. 481 nil The parameter is copied to FILTERED.
444 :never The parameter is never copied to FILTERED. 482 :never The parameter is never copied to FILTERED.
445 :save The parameter is copied only when saving the frame. 483 :save The parameter is copied only when saving the frame.
446 :restore The parameter is copied only when restoring the frame. 484 :restore The parameter is copied only when restoring the frame.
447 FILTER A filter function. 485 FILTER A filter function.
448 486
449FILTER can be a symbol FILTER-FUN, or a list (FILTER-FUN ARGS...). 487FILTER can be a symbol FILTER-FUN, or a list (FILTER-FUN ARGS...).
450FILTER-FUN is invoked with 488FILTER-FUN is invoked with
@@ -457,14 +495,14 @@ where
457 filtered and VALUE is its current value. 495 filtered and VALUE is its current value.
458 FILTERED The resulting alist (so far). 496 FILTERED The resulting alist (so far).
459 PARAMETERS The complete alist of parameters being filtered, 497 PARAMETERS The complete alist of parameters being filtered,
460 SAVING Non-nil if filtering before saving state, nil if filtering 498 SAVING Non-nil if filtering before saving state, nil if filtering
461 before restoring it. 499 before restoring it.
462 ARGS Any additional arguments specified in the ACTION. 500 ARGS Any additional arguments specified in the ACTION.
463 501
464FILTER-FUN is allowed to modify items in FILTERED, but no other arguments. 502FILTER-FUN is allowed to modify items in FILTERED, but no other arguments.
465It must return: 503It must return:
466 nil Skip CURRENT (do not add it to FILTERED). 504 nil Skip CURRENT (do not add it to FILTERED).
467 t Add CURRENT to FILTERED as is. 505 t Add CURRENT to FILTERED as is.
468 (NEW-PARAM . NEW-VALUE) Add this to FILTERED instead of CURRENT. 506 (NEW-PARAM . NEW-VALUE) Add this to FILTERED instead of CURRENT.
469 507
470Frame parameters not on this alist are passed intact, as if they were 508Frame parameters not on this alist are passed intact, as if they were
@@ -485,9 +523,9 @@ Return non-nil if the parameter alist PARAMETERS describes a frame on a
485text-only terminal, and the frame is being restored on a graphic display; 523text-only terminal, and the frame is being restored on a graphic display;
486otherwise return nil. Only meaningful when called from a filtering 524otherwise return nil. Only meaningful when called from a filtering
487function in `frameset-filter-alist'." 525function in `frameset-filter-alist'."
488 (and frameset--target-display ; we're switching 526 (and frameset--target-display ; we're switching
489 (null (cdr (assq 'display parameters))) ; from a tty 527 (null (cdr (assq 'display parameters))) ; from a tty
490 (cdr frameset--target-display))) ; to a GUI display 528 (cdr frameset--target-display))) ; to a GUI display
491 529
492(defun frameset-switch-to-tty-p (parameters) 530(defun frameset-switch-to-tty-p (parameters)
493 "True when switching to a text-only terminal. 531 "True when switching to a text-only terminal.
@@ -495,9 +533,9 @@ Return non-nil if the parameter alist PARAMETERS describes a frame on a
495graphic display, and the frame is being restored on a text-only terminal; 533graphic display, and the frame is being restored on a text-only terminal;
496otherwise return nil. Only meaningful when called from a filtering 534otherwise return nil. Only meaningful when called from a filtering
497function in `frameset-filter-alist'." 535function in `frameset-filter-alist'."
498 (and frameset--target-display ; we're switching 536 (and frameset--target-display ; we're switching
499 (cdr (assq 'display parameters)) ; from a GUI display 537 (cdr (assq 'display parameters)) ; from a GUI display
500 (null (cdr frameset--target-display)))) ; to a tty 538 (null (cdr frameset--target-display)))) ; to a tty
501 539
502(defun frameset-filter-tty-to-GUI (_current _filtered parameters saving) 540(defun frameset-filter-tty-to-GUI (_current _filtered parameters saving)
503 "Remove CURRENT when switching from tty to a graphic display. 541 "Remove CURRENT when switching from tty to a graphic display.
@@ -762,14 +800,14 @@ NOTE: This only works for non-iconified frames."
762 (list fr-left fr-top fr-width fr-height) 800 (list fr-left fr-top fr-width fr-height)
763 (list left top width height))) 801 (list left top width height)))
764 ;; Any corner is outside the screen. 802 ;; Any corner is outside the screen.
765 (:all (or (< fr-bottom top) (> fr-bottom bottom) 803 (:all (or (< fr-bottom top) (> fr-bottom bottom)
766 (< fr-left left) (> fr-left right) 804 (< fr-left left) (> fr-left right)
767 (< fr-right left) (> fr-right right) 805 (< fr-right left) (> fr-right right)
768 (< fr-top top) (> fr-top bottom))) 806 (< fr-top top) (> fr-top bottom)))
769 ;; Displaced to the left, right, above or below the screen. 807 ;; Displaced to the left, right, above or below the screen.
770 (`t (or (> fr-left right) 808 (`t (or (> fr-left right)
771 (< fr-right left) 809 (< fr-right left)
772 (> fr-top bottom) 810 (> fr-top bottom)
773 (< fr-bottom top))) 811 (< fr-bottom top)))
774 ;; Fully inside, no need to do anything. 812 ;; Fully inside, no need to do anything.
775 (_ nil)) 813 (_ nil))
@@ -981,27 +1019,27 @@ FILTERS is an alist of parameter filters; if nil, the value of
981`frameset-filter-alist' is used instead. 1019`frameset-filter-alist' is used instead.
982 1020
983REUSE-FRAMES selects the policy to use to reuse frames when restoring: 1021REUSE-FRAMES selects the policy to use to reuse frames when restoring:
984 t Reuse existing frames if possible, and delete those not reused. 1022 t Reuse existing frames if possible, and delete those not reused.
985 nil Restore frameset in new frames and delete existing frames. 1023 nil Restore frameset in new frames and delete existing frames.
986 :keep Restore frameset in new frames and keep the existing ones. 1024 :keep Restore frameset in new frames and keep the existing ones.
987 LIST A list of frames to reuse; only these are reused (if possible). 1025 LIST A list of frames to reuse; only these are reused (if possible).
988 Remaining frames in this list are deleted; other frames not 1026 Remaining frames in this list are deleted; other frames not
989 included on the list are left untouched. 1027 included on the list are left untouched.
990 1028
991FORCE-DISPLAY can be: 1029FORCE-DISPLAY can be:
992 t Frames are restored in the current display. 1030 t Frames are restored in the current display.
993 nil Frames are restored, if possible, in their original displays. 1031 nil Frames are restored, if possible, in their original displays.
994 :delete Frames in other displays are deleted instead of restored. 1032 :delete Frames in other displays are deleted instead of restored.
995 PRED A function called with two arguments, the parameter alist and 1033 PRED A function called with two arguments, the parameter alist and
996 the window state (in that order). It must return t, nil or 1034 the window state (in that order). It must return t, nil or
997 `:delete', as above but affecting only the frame that will 1035 `:delete', as above but affecting only the frame that will
998 be created from that parameter alist. 1036 be created from that parameter alist.
999 1037
1000FORCE-ONSCREEN can be: 1038FORCE-ONSCREEN can be:
1001 t Force onscreen only those frames that are fully offscreen. 1039 t Force onscreen only those frames that are fully offscreen.
1002 nil Do not force any frame back onscreen. 1040 nil Do not force any frame back onscreen.
1003 :all Force onscreen any frame fully or partially offscreen. 1041 :all Force onscreen any frame fully or partially offscreen.
1004 PRED A function called with three arguments, 1042 PRED A function called with three arguments,
1005 - the live frame just restored, 1043 - the live frame just restored,
1006 - a list (LEFT TOP WIDTH HEIGHT), describing the frame, 1044 - a list (LEFT TOP WIDTH HEIGHT), describing the frame,
1007 - a list (LEFT TOP WIDTH HEIGHT), describing the workarea. 1045 - a list (LEFT TOP WIDTH HEIGHT), describing the workarea.
@@ -1014,7 +1052,7 @@ it has been restored.
1014 1052
1015All keyword parameters default to nil." 1053All keyword parameters default to nil."
1016 1054
1017 (cl-assert (frameset-p frameset)) 1055 (cl-assert (frameset-valid-p frameset))
1018 1056
1019 (let (other-frames) 1057 (let (other-frames)
1020 1058