diff options
| -rw-r--r-- | lisp/ChangeLog | 8 | ||||
| -rw-r--r-- | lisp/frameset.el | 76 |
2 files changed, 56 insertions, 28 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 31c5414cae0..0843ca2398a 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,13 @@ | |||
| 1 | 2013-08-06 Juanma Barranquero <lekktu@gmail.com> | 1 | 2013-08-06 Juanma Barranquero <lekktu@gmail.com> |
| 2 | 2 | ||
| 3 | * frameset.el (frameset, frameset-filter-alist) | ||
| 4 | (frameset-filter-params, frameset-save, frameset--reuse-frame) | ||
| 5 | (frameset--minibufferless-last-p, frameset-restore): Doc fixes. | ||
| 6 | (frameset-compute-pos): Rename from frameset--compute-pos, | ||
| 7 | and add docstring. | ||
| 8 | (frameset-move-onscreen): Use frameset-compute-pos. | ||
| 9 | Most changes suggested by Drew Adams <drew.adams@oracle.com>. | ||
| 10 | |||
| 3 | * find-lisp.el (find-lisp-line-indent, find-lisp-find-dired-filter): | 11 | * find-lisp.el (find-lisp-line-indent, find-lisp-find-dired-filter): |
| 4 | Fix typos in docstrings. | 12 | Fix typos in docstrings. |
| 5 | 13 | ||
diff --git a/lisp/frameset.el b/lisp/frameset.el index 71c26112917..45cf86eb3cc 100644 --- a/lisp/frameset.el +++ b/lisp/frameset.el | |||
| @@ -42,9 +42,12 @@ | |||
| 42 | 42 | ||
| 43 | 43 | ||
| 44 | (cl-defstruct (frameset (:type list) :named | 44 | (cl-defstruct (frameset (:type list) :named |
| 45 | ;; Copier and predicate functions are defined below. | ||
| 45 | (:copier nil) | 46 | (:copier nil) |
| 46 | (:predicate nil) | 47 | (:predicate nil) |
| 47 | ;; A BOA constructor, not the default "keywordy" one. | 48 | ;; A BOA constructor, not the default "keywordy" one. |
| 49 | ;; This is for internal use; to create a frameset, | ||
| 50 | ;; the "right" way to do it is with frameset-save. | ||
| 48 | (:constructor make-frameset (properties states))) | 51 | (:constructor make-frameset (properties states))) |
| 49 | 52 | ||
| 50 | "A frameset encapsulates a serializable view of a set of frames and windows. | 53 | "A frameset encapsulates a serializable view of a set of frames and windows. |
| @@ -55,11 +58,10 @@ It contains the following slots, which can be accessed with | |||
| 55 | version A non-modifiable version number, identifying the format | 58 | version A non-modifiable version number, identifying the format |
| 56 | of the frameset struct. Currently its value is 1. | 59 | of the frameset struct. Currently its value is 1. |
| 57 | properties A property list, to store both frameset-specific and | 60 | properties A property list, to store both frameset-specific and |
| 58 | user-defined serializable data (some suggested properties | 61 | user-defined serializable data (see suggestions below). |
| 59 | are described below). | ||
| 60 | states An alist of items (FRAME-PARAMETERS . WINDOW-STATE), in no | 62 | states An alist of items (FRAME-PARAMETERS . WINDOW-STATE), in no |
| 61 | particular order. Each item represents a frame to be | 63 | particular order. Each item represents a frame to be |
| 62 | restored. FRAME-PARAMETERS is a frame's parameter list, | 64 | restored. FRAME-PARAMETERS is a frame's parameter alist, |
| 63 | extracted with (frame-parameters FRAME) and filtered through | 65 | extracted with (frame-parameters FRAME) and filtered through |
| 64 | `frame-parameters-alist' or a similar filter alist. | 66 | `frame-parameters-alist' or a similar filter alist. |
| 65 | WINDOW-STATE is the output of `window-state-get', when | 67 | WINDOW-STATE is the output of `window-state-get', when |
| @@ -75,10 +77,14 @@ Some suggested properties: | |||
| 75 | :desc TEXT A description for user consumption (to show in a menu to | 77 | :desc TEXT A description for user consumption (to show in a menu to |
| 76 | choose among framesets, etc.); a string. | 78 | choose among framesets, etc.); a string. |
| 77 | 79 | ||
| 80 | To avoid collisions, it is recommended that applications wanting to add | ||
| 81 | private serializable data to `properties' either store all info under a | ||
| 82 | single, distinctive name, or use property names with a well-chosen prefix. | ||
| 83 | |||
| 78 | A frameset is intended to be used through the following simple API: | 84 | A frameset is intended to be used through the following simple API: |
| 79 | 85 | ||
| 80 | - `frameset-save' captures all or a subset of the live frames, and returns | 86 | - `frameset-save', the type's constructor, captures all or a subset of the |
| 81 | a serializable snapshot of them (a frameset). | 87 | live frames, and returns a serializable snapshot of them (a frameset). |
| 82 | - `frameset-restore' takes a frameset, and restores the frames and windows | 88 | - `frameset-restore' takes a frameset, and restores the frames and windows |
| 83 | it describes, as faithfully as possible. | 89 | it describes, as faithfully as possible. |
| 84 | - `frameset-p' is the predicate for the frameset type. It returns nil | 90 | - `frameset-p' is the predicate for the frameset type. It returns nil |
| @@ -166,15 +172,15 @@ See `frameset-filter-alist' for a full description.") | |||
| 166 | 172 | ||
| 167 | This alist is the default value of the :filters arguments of | 173 | This alist is the default value of the :filters arguments of |
| 168 | `frameset-save' and `frameset-restore' (which see). On saving, | 174 | `frameset-save' and `frameset-restore' (which see). On saving, |
| 169 | PARAMETERS is the parameter list of each frame processed, and | 175 | PARAMETERS is the parameter alist of each frame processed, and |
| 170 | FILTERED is the parameter list that gets saved to the frameset. | 176 | FILTERED is the parameter alist that gets saved to the frameset. |
| 171 | On restoring, PARAMETERS is the parameter list extracted from the | 177 | On restoring, PARAMETERS is the parameter alist extracted from the |
| 172 | frameset, and FILTERED is the resulting frame parameter list used | 178 | frameset, and FILTERED is the resulting frame parameter alist used |
| 173 | to restore the frame. | 179 | to restore the frame. |
| 174 | 180 | ||
| 175 | Elements of this alist are conses (PARAM . ACTION), where PARAM | 181 | Elements of `frameset-filter-alist' are conses (PARAM . ACTION), |
| 176 | is a parameter name (a symbol identifying a frame parameter), and | 182 | where PARAM is a parameter name (a symbol identifying a frame |
| 177 | ACTION can be: | 183 | parameter), and ACTION can be: |
| 178 | 184 | ||
| 179 | nil The parameter is copied to FILTERED. | 185 | nil The parameter is copied to FILTERED. |
| 180 | :never The parameter is never copied to FILTERED. | 186 | :never The parameter is never copied to FILTERED. |
| @@ -183,8 +189,11 @@ ACTION can be: | |||
| 183 | FILTER A filter function. | 189 | FILTER A filter function. |
| 184 | 190 | ||
| 185 | FILTER can be a symbol FILTER-FUN, or a list (FILTER-FUN ARGS...). | 191 | FILTER can be a symbol FILTER-FUN, or a list (FILTER-FUN ARGS...). |
| 186 | FILTER-FUN is called with four arguments CURRENT, FILTERED, PARAMETERS and | 192 | FILTER-FUN is invoked with |
| 187 | SAVING, plus any additional ARGS: | 193 | |
| 194 | (apply FILTER-FUN CURRENT FILTERED PARAMETERS SAVING ARGS) | ||
| 195 | |||
| 196 | where | ||
| 188 | 197 | ||
| 189 | CURRENT A cons (PARAM . VALUE), where PARAM is the one being | 198 | CURRENT A cons (PARAM . VALUE), where PARAM is the one being |
| 190 | filtered and VALUE is its current value. | 199 | filtered and VALUE is its current value. |
| @@ -192,6 +201,7 @@ SAVING, plus any additional ARGS: | |||
| 192 | PARAMETERS The complete alist of parameters being filtered, | 201 | PARAMETERS The complete alist of parameters being filtered, |
| 193 | SAVING Non-nil if filtering before saving state, nil if filtering | 202 | SAVING Non-nil if filtering before saving state, nil if filtering |
| 194 | before restoring it. | 203 | before restoring it. |
| 204 | ARGS Any additional arguments specified in the ACTION. | ||
| 195 | 205 | ||
| 196 | FILTER-FUN is allowed to modify items in FILTERED, but no other arguments. | 206 | FILTER-FUN is allowed to modify items in FILTERED, but no other arguments. |
| 197 | It must return: | 207 | It must return: |
| @@ -308,15 +318,15 @@ see the docstring of `frameset-filter-alist'." | |||
| 308 | (not (and saving (eq (cdr (assq 'visibility parameters)) 'icon)))) | 318 | (not (and saving (eq (cdr (assq 'visibility parameters)) 'icon)))) |
| 309 | 319 | ||
| 310 | (defun frameset-filter-params (parameters filter-alist saving) | 320 | (defun frameset-filter-params (parameters filter-alist saving) |
| 311 | "Filter parameter list PARAMETERS and return a filtered list. | 321 | "Filter parameter alist PARAMETERS and return a filtered alist. |
| 312 | FILTER-ALIST is an alist of parameter filters, in the format of | 322 | FILTER-ALIST is an alist of parameter filters, in the format of |
| 313 | `frameset-filter-alist' (which see). | 323 | `frameset-filter-alist' (which see). |
| 314 | SAVING is non-nil while filtering parameters to save a frameset, | 324 | SAVING is non-nil while filtering parameters to save a frameset, |
| 315 | nil while the filtering is done to restore it." | 325 | nil while the filtering is done to restore it." |
| 316 | (let ((filtered nil)) | 326 | (let ((filtered nil)) |
| 317 | (dolist (current parameters) | 327 | (dolist (current parameters) |
| 318 | ;; When saving, the parameter list is temporary, so modifying it | 328 | ;; When saving, the parameter alist is temporary, so modifying it |
| 319 | ;; is not a problem. When restoring, the parameter list is part | 329 | ;; is not a problem. When restoring, the parameter alist is part |
| 320 | ;; of a frameset, so we must copy parameters to avoid inadvertent | 330 | ;; of a frameset, so we must copy parameters to avoid inadvertent |
| 321 | ;; modifications. | 331 | ;; modifications. |
| 322 | (pcase (cdr (assq (car current) filter-alist)) | 332 | (pcase (cdr (assq (car current) filter-alist)) |
| @@ -417,9 +427,9 @@ FRAME-LIST is a list of frames. Internal use only." | |||
| 417 | "Return the frameset of FRAME-LIST, a list of frames. | 427 | "Return the frameset of FRAME-LIST, a list of frames. |
| 418 | Dead frames and non-frame objects are silently removed from the list. | 428 | Dead frames and non-frame objects are silently removed from the list. |
| 419 | If nil, FRAME-LIST defaults to the output of `frame-list' (all live frames). | 429 | If nil, FRAME-LIST defaults to the output of `frame-list' (all live frames). |
| 420 | FILTERS is an alist of parameter filters; defaults to `frameset-filter-alist'. | 430 | FILTERS is an alist of parameter filters, or `frameset-filter-alist' if nil. |
| 421 | PREDICATE is a predicate function, which must return non-nil for frames that | 431 | PREDICATE is a predicate function, which must return non-nil for frames that |
| 422 | should be saved; it defaults to saving all frames from FRAME-LIST. | 432 | should be saved; if PREDICATE is nil, all frames from FRAME-LIST are saved. |
| 423 | PROPERTIES is a user-defined property list to add to the frameset." | 433 | PROPERTIES is a user-defined property list to add to the frameset." |
| 424 | (let* ((list (or (copy-sequence frame-list) (frame-list))) | 434 | (let* ((list (or (copy-sequence frame-list) (frame-list))) |
| 425 | (frames (cl-delete-if-not #'frame-live-p | 435 | (frames (cl-delete-if-not #'frame-live-p |
| @@ -445,7 +455,16 @@ PROPERTIES is a user-defined property list to add to the frameset." | |||
| 445 | Its value is only meaningful during execution of `frameset-restore'. | 455 | Its value is only meaningful during execution of `frameset-restore'. |
| 446 | Internal use only.") | 456 | Internal use only.") |
| 447 | 457 | ||
| 448 | (defun frameset--compute-pos (value left/top right/bottom) | 458 | (defun frameset-compute-pos (value left/top right/bottom) |
| 459 | "Return an absolute positioning value for a frame. | ||
| 460 | VALUE is the value of a positional frame parameter (`left' or `top'). | ||
| 461 | If VALUE is relative to the screen edges (like (+ -35) or (-200), it is | ||
| 462 | converted to absolute by adding it to the corresponding edge; if it is | ||
| 463 | an absolute position, it is returned unmodified. | ||
| 464 | LEFT/TOP and RIGHT/BOTTOM indicate the dimensions of the screen in | ||
| 465 | pixels along the relevant direction: either the position of the left | ||
| 466 | and right edges for a `left' positional parameter, or the position of | ||
| 467 | the top and bottom edges for a `top' parameter." | ||
| 449 | (pcase value | 468 | (pcase value |
| 450 | (`(+ ,val) (+ left/top val)) | 469 | (`(+ ,val) (+ left/top val)) |
| 451 | (`(- ,val) (+ right/bottom val)) | 470 | (`(- ,val) (+ right/bottom val)) |
| @@ -460,8 +479,8 @@ NOTE: This only works for non-iconified frames." | |||
| 460 | (pcase-let* ((`(,left ,top ,width ,height) (cl-cdadr (frame-monitor-attributes frame))) | 479 | (pcase-let* ((`(,left ,top ,width ,height) (cl-cdadr (frame-monitor-attributes frame))) |
| 461 | (right (+ left width -1)) | 480 | (right (+ left width -1)) |
| 462 | (bottom (+ top height -1)) | 481 | (bottom (+ top height -1)) |
| 463 | (fr-left (frameset--compute-pos (frame-parameter frame 'left) left right)) | 482 | (fr-left (frameset-compute-pos (frame-parameter frame 'left) left right)) |
| 464 | (fr-top (frameset--compute-pos (frame-parameter frame 'top) top bottom)) | 483 | (fr-top (frameset-compute-pos (frame-parameter frame 'top) top bottom)) |
| 465 | (ch-width (frame-char-width frame)) | 484 | (ch-width (frame-char-width frame)) |
| 466 | (ch-height (frame-char-height frame)) | 485 | (ch-height (frame-char-height frame)) |
| 467 | (fr-width (max (frame-pixel-width frame) (* ch-width (frame-width frame)))) | 486 | (fr-width (max (frame-pixel-width frame) (* ch-width (frame-width frame)))) |
| @@ -529,7 +548,7 @@ If PREDICATE is nil, it is always satisfied. Internal use only." | |||
| 529 | (defun frameset--reuse-frame (display frame-cfg) | 548 | (defun frameset--reuse-frame (display frame-cfg) |
| 530 | "Look for an existing frame to reuse. | 549 | "Look for an existing frame to reuse. |
| 531 | DISPLAY is the display where the frame will be shown, and FRAME-CFG | 550 | DISPLAY is the display where the frame will be shown, and FRAME-CFG |
| 532 | is the parameter list of the frame being restored. Internal use only." | 551 | is the parameter alist of the frame being restored. Internal use only." |
| 533 | (let ((frame nil) | 552 | (let ((frame nil) |
| 534 | mini) | 553 | mini) |
| 535 | ;; There are no fancy heuristics there. We could implement some | 554 | ;; There are no fancy heuristics there. We could implement some |
| @@ -591,7 +610,7 @@ Internal use only." | |||
| 591 | (defun frameset--restore-frame (frame-cfg window-cfg filters force-onscreen) | 610 | (defun frameset--restore-frame (frame-cfg window-cfg filters force-onscreen) |
| 592 | "Set up and return a frame according to its saved state. | 611 | "Set up and return a frame according to its saved state. |
| 593 | That means either reusing an existing frame or creating one anew. | 612 | That means either reusing an existing frame or creating one anew. |
| 594 | FRAME-CFG is the frame's parameter list; WINDOW-CFG is its window state. | 613 | FRAME-CFG is the frame's parameter alist; WINDOW-CFG is its window state. |
| 595 | For the meaning of FILTERS and FORCE-ONSCREEN, see `frameset-restore'. | 614 | For the meaning of FILTERS and FORCE-ONSCREEN, see `frameset-restore'. |
| 596 | Internal use only." | 615 | Internal use only." |
| 597 | (let* ((fullscreen (cdr (assq 'fullscreen frame-cfg))) | 616 | (let* ((fullscreen (cdr (assq 'fullscreen frame-cfg))) |
| @@ -631,7 +650,7 @@ Internal use only." | |||
| 631 | ;; If a frame needs to be created and it falls partially or fully offscreen, | 650 | ;; If a frame needs to be created and it falls partially or fully offscreen, |
| 632 | ;; sometimes it gets "pushed back" onscreen; however, moving it afterwards is | 651 | ;; sometimes it gets "pushed back" onscreen; however, moving it afterwards is |
| 633 | ;; allowed. So we create the frame as invisible and then reapply the full | 652 | ;; allowed. So we create the frame as invisible and then reapply the full |
| 634 | ;; parameter list (including position and size parameters). | 653 | ;; parameter alist (including position and size parameters). |
| 635 | (setq frame (or (and frameset--reuse-list | 654 | (setq frame (or (and frameset--reuse-list |
| 636 | (frameset--reuse-frame display filtered-cfg)) | 655 | (frameset--reuse-frame display filtered-cfg)) |
| 637 | (make-frame-on-display display | 656 | (make-frame-on-display display |
| @@ -659,7 +678,8 @@ Internal use only." | |||
| 659 | 678 | ||
| 660 | (defun frameset--minibufferless-last-p (state1 state2) | 679 | (defun frameset--minibufferless-last-p (state1 state2) |
| 661 | "Predicate to sort frame states in an order suitable for creating frames. | 680 | "Predicate to sort frame states in an order suitable for creating frames. |
| 662 | It sorts minibuffer-owning frames before minibufferless ones." | 681 | It sorts minibuffer-owning frames before minibufferless ones. |
| 682 | Internal use only." | ||
| 663 | (pcase-let ((`(,hasmini1 ,id-def1) (assq 'frameset--mini (car state1))) | 683 | (pcase-let ((`(,hasmini1 ,id-def1) (assq 'frameset--mini (car state1))) |
| 664 | (`(,hasmini2 ,id-def2) (assq 'frameset--mini (car state2)))) | 684 | (`(,hasmini2 ,id-def2) (assq 'frameset--mini (car state2)))) |
| 665 | (cond ((eq id-def1 t) t) | 685 | (cond ((eq id-def1 t) t) |
| @@ -697,9 +717,9 @@ FORCE-DISPLAY can be: | |||
| 697 | t Frames are restored in the current display. | 717 | t Frames are restored in the current display. |
| 698 | nil Frames are restored, if possible, in their original displays. | 718 | nil Frames are restored, if possible, in their original displays. |
| 699 | :delete Frames in other displays are deleted instead of restored. | 719 | :delete Frames in other displays are deleted instead of restored. |
| 700 | PRED A function called with one argument, the parameter list; | 720 | PRED A function called with one argument, the parameter alist; |
| 701 | it must return t, nil or `:delete', as above but affecting | 721 | it must return t, nil or `:delete', as above but affecting |
| 702 | only the frame that will be created from that parameter list. | 722 | only the frame that will be created from that parameter alist. |
| 703 | 723 | ||
| 704 | FORCE-ONSCREEN can be: | 724 | FORCE-ONSCREEN can be: |
| 705 | t Force onscreen only those frames that are fully offscreen. | 725 | t Force onscreen only those frames that are fully offscreen. |