diff options
| author | Martin Rudalics | 2007-11-10 09:52:30 +0000 |
|---|---|---|
| committer | Martin Rudalics | 2007-11-10 09:52:30 +0000 |
| commit | 78ddc123db626d7475df907bd87b7f2c3d0c1e84 (patch) | |
| tree | e873098159c6446051c8c7c07dd4a04a957e842a | |
| parent | 70f4194508a971101163af3e4dc02438a83b68c9 (diff) | |
| download | emacs-78ddc123db626d7475df907bd87b7f2c3d0c1e84.tar.gz emacs-78ddc123db626d7475df907bd87b7f2c3d0c1e84.zip | |
(view-remove-frame-by-deleting): Change default value to t.
Add autoload cookie.
(view-exit-action, view-file, view-file-other-window)
(view-file-other-frame, view-buffer, view-buffer-other-window)
(view-buffer-other-frame): Rewrite doc strings.
(view-return-to-alist-update): New function to remove stale entries
from view-return-to-alist.
(view-mode-enter): Rewrite doc string and simplify code.
(view-mode-exit): Handle new case 'keep-frame. Don't reset
view-exit-action to nil. Simplify code and rewrite doc string.
| -rw-r--r-- | lisp/view.el | 347 |
1 files changed, 204 insertions, 143 deletions
diff --git a/lisp/view.el b/lisp/view.el index c152383a48b..ad6ca9371b8 100644 --- a/lisp/view.el +++ b/lisp/view.el | |||
| @@ -77,11 +77,15 @@ for all scroll commands in view mode." | |||
| 77 | :type 'boolean | 77 | :type 'boolean |
| 78 | :group 'view) | 78 | :group 'view) |
| 79 | 79 | ||
| 80 | (defcustom view-remove-frame-by-deleting nil | 80 | ;;;###autoload |
| 81 | (defcustom view-remove-frame-by-deleting t | ||
| 81 | "*Determine how View mode removes a frame no longer needed. | 82 | "*Determine how View mode removes a frame no longer needed. |
| 82 | If nil, make an icon of the frame. If non-nil, delete the frame." | 83 | If nil, make an icon of the frame. If non-nil, delete the frame." |
| 83 | :type 'boolean | 84 | :type 'boolean |
| 84 | :group 'view) | 85 | :group 'view |
| 86 | ;; Changed the default of this to t for Emacs 23. Users consider | ||
| 87 | ;; frame iconification annoying. | ||
| 88 | :version "23.1") | ||
| 85 | 89 | ||
| 86 | (defcustom view-exits-all-viewing-windows nil | 90 | (defcustom view-exits-all-viewing-windows nil |
| 87 | "*Non-nil means restore all windows used to view buffer. | 91 | "*Non-nil means restore all windows used to view buffer. |
| @@ -146,10 +150,11 @@ See RETURN-TO-ALIST argument of function `view-mode-exit' for the format of | |||
| 146 | (put 'view-return-to-alist 'permanent-local t) | 150 | (put 'view-return-to-alist 'permanent-local t) |
| 147 | 151 | ||
| 148 | (defvar view-exit-action nil | 152 | (defvar view-exit-action nil |
| 149 | "nil or a function with one argument (a buffer) called when finished viewing. | 153 | "If non-nil, a function with one argument (a buffer) called when finished viewing. |
| 150 | This is local in each buffer being viewed. | 154 | Commands like \\[view-file] and \\[view-file-other-window] may |
| 151 | The \\[view-file] and \\[view-file-other-window] commands may set this to | 155 | set this to bury or kill the viewed buffer. |
| 152 | `kill-buffer'.") | 156 | Observe that the buffer viewed might not appear in any window at |
| 157 | the time this function is called.") | ||
| 153 | (make-variable-buffer-local 'view-exit-action) | 158 | (make-variable-buffer-local 'view-exit-action) |
| 154 | 159 | ||
| 155 | (defvar view-no-disable-on-exit nil | 160 | (defvar view-no-disable-on-exit nil |
| @@ -241,11 +246,11 @@ This is local in each buffer, once it is used.") | |||
| 241 | ;;;###autoload | 246 | ;;;###autoload |
| 242 | (defun view-file (file) | 247 | (defun view-file (file) |
| 243 | "View FILE in View mode, returning to previous buffer when done. | 248 | "View FILE in View mode, returning to previous buffer when done. |
| 244 | Emacs commands editing the buffer contents are not available; instead, | 249 | Emacs commands editing the buffer contents are not available; instead, a |
| 245 | a special set of commands (mostly letters and punctuation) | 250 | special set of commands (mostly letters and punctuation) are defined for |
| 246 | are defined for moving around in the buffer. | 251 | moving around in the buffer. |
| 247 | Space scrolls forward, Delete scrolls backward. | 252 | Space scrolls forward, Delete scrolls backward. |
| 248 | For list of all View commands, type H or h while viewing. | 253 | For a list of all View commands, type H or h while viewing. |
| 249 | 254 | ||
| 250 | This command runs the normal hook `view-mode-hook'." | 255 | This command runs the normal hook `view-mode-hook'." |
| 251 | (interactive "fView file: ") | 256 | (interactive "fView file: ") |
| @@ -263,12 +268,12 @@ This command runs the normal hook `view-mode-hook'." | |||
| 263 | ;;;###autoload | 268 | ;;;###autoload |
| 264 | (defun view-file-other-window (file) | 269 | (defun view-file-other-window (file) |
| 265 | "View FILE in View mode in another window. | 270 | "View FILE in View mode in another window. |
| 266 | Return that window to its previous buffer when done. | 271 | Return that window to its previous buffer when done. Emacs commands |
| 267 | Emacs commands editing the buffer contents are not available; instead, | 272 | editing the buffer contents are not available; instead, a special set of |
| 268 | a special set of commands (mostly letters and punctuation) | 273 | commands (mostly letters and punctuation) are defined for moving around |
| 269 | are defined for moving around in the buffer. | 274 | in the buffer. |
| 270 | Space scrolls forward, Delete scrolls backward. | 275 | Space scrolls forward, Delete scrolls backward. |
| 271 | For list of all View commands, type H or h while viewing. | 276 | For a list of all View commands, type H or h while viewing. |
| 272 | 277 | ||
| 273 | This command runs the normal hook `view-mode-hook'." | 278 | This command runs the normal hook `view-mode-hook'." |
| 274 | (interactive "fIn other window view file: ") | 279 | (interactive "fIn other window view file: ") |
| @@ -281,11 +286,11 @@ This command runs the normal hook `view-mode-hook'." | |||
| 281 | (defun view-file-other-frame (file) | 286 | (defun view-file-other-frame (file) |
| 282 | "View FILE in View mode in another frame. | 287 | "View FILE in View mode in another frame. |
| 283 | Maybe delete other frame and/or return to previous buffer when done. | 288 | Maybe delete other frame and/or return to previous buffer when done. |
| 284 | Emacs commands editing the buffer contents are not available; instead, | 289 | Emacs commands editing the buffer contents are not available; instead, a |
| 285 | a special set of commands (mostly letters and punctuation) | 290 | special set of commands (mostly letters and punctuation) are defined for |
| 286 | are defined for moving around in the buffer. | 291 | moving around in the buffer. |
| 287 | Space scrolls forward, Delete scrolls backward. | 292 | Space scrolls forward, Delete scrolls backward. |
| 288 | For list of all View commands, type H or h while viewing. | 293 | For a list of all View commands, type H or h while viewing. |
| 289 | 294 | ||
| 290 | This command runs the normal hook `view-mode-hook'." | 295 | This command runs the normal hook `view-mode-hook'." |
| 291 | (interactive "fIn other frame view file: ") | 296 | (interactive "fIn other frame view file: ") |
| @@ -298,18 +303,17 @@ This command runs the normal hook `view-mode-hook'." | |||
| 298 | ;;;###autoload | 303 | ;;;###autoload |
| 299 | (defun view-buffer (buffer &optional exit-action) | 304 | (defun view-buffer (buffer &optional exit-action) |
| 300 | "View BUFFER in View mode, returning to previous buffer when done. | 305 | "View BUFFER in View mode, returning to previous buffer when done. |
| 301 | Emacs commands editing the buffer contents are not available; instead, | 306 | Emacs commands editing the buffer contents are not available; instead, a |
| 302 | a special set of commands (mostly letters and punctuation) | 307 | special set of commands (mostly letters and punctuation) are defined for |
| 303 | are defined for moving around in the buffer. | 308 | moving around in the buffer. |
| 304 | Space scrolls forward, Delete scrolls backward. | 309 | Space scrolls forward, Delete scrolls backward. |
| 305 | For list of all View commands, type H or h while viewing. | 310 | For a list of all View commands, type H or h while viewing. |
| 306 | 311 | ||
| 307 | This command runs the normal hook `view-mode-hook'. | 312 | This command runs the normal hook `view-mode-hook'. |
| 308 | 313 | ||
| 309 | Optional argument EXIT-ACTION is either nil or a function with buffer as | 314 | Optional argument EXIT-ACTION is either nil or a function with buffer as |
| 310 | argument. This function is called when finished viewing buffer. | 315 | argument. This function is called when finished viewing buffer. Use |
| 311 | Use this argument instead of explicitly setting `view-exit-action'." | 316 | this argument instead of explicitly setting `view-exit-action'." |
| 312 | |||
| 313 | (interactive "bView buffer: ") | 317 | (interactive "bView buffer: ") |
| 314 | (let ((undo-window (list (window-buffer) (window-start) (window-point)))) | 318 | (let ((undo-window (list (window-buffer) (window-start) (window-point)))) |
| 315 | (switch-to-buffer buffer) | 319 | (switch-to-buffer buffer) |
| @@ -319,18 +323,18 @@ Use this argument instead of explicitly setting `view-exit-action'." | |||
| 319 | ;;;###autoload | 323 | ;;;###autoload |
| 320 | (defun view-buffer-other-window (buffer &optional not-return exit-action) | 324 | (defun view-buffer-other-window (buffer &optional not-return exit-action) |
| 321 | "View BUFFER in View mode in another window. | 325 | "View BUFFER in View mode in another window. |
| 322 | Return to previous buffer when done, unless optional NOT-RETURN is non-nil. | 326 | Return to previous buffer when done, unless optional NOT-RETURN is |
| 323 | Emacs commands editing the buffer contents are not available; instead, | 327 | non-nil. Emacs commands editing the buffer contents are not available; |
| 324 | a special set of commands (mostly letters and punctuation) | 328 | instead, a special set of commands (mostly letters and punctuation) are |
| 325 | are defined for moving around in the buffer. | 329 | defined for moving around in the buffer. |
| 326 | Space scrolls forward, Delete scrolls backward. | 330 | Space scrolls forward, Delete scrolls backward. |
| 327 | For list of all View commands, type H or h while viewing. | 331 | For a list of all View commands, type H or h while viewing. |
| 328 | 332 | ||
| 329 | This command runs the normal hook `view-mode-hook'. | 333 | This command runs the normal hook `view-mode-hook'. |
| 330 | 334 | ||
| 331 | Optional argument EXIT-ACTION is either nil or a function with buffer as | 335 | Optional argument EXIT-ACTION is either nil or a function with buffer as |
| 332 | argument. This function is called when finished viewing buffer. | 336 | argument. This function is called when finished viewing buffer. Use |
| 333 | Use this argument instead of explicitly setting `view-exit-action'." | 337 | this argument instead of explicitly setting `view-exit-action'." |
| 334 | (interactive "bIn other window view buffer:\nP") | 338 | (interactive "bIn other window view buffer:\nP") |
| 335 | (let* ((win ; This window will be selected by | 339 | (let* ((win ; This window will be selected by |
| 336 | (get-lru-window)) ; switch-to-buffer-other-window below. | 340 | (get-lru-window)) ; switch-to-buffer-other-window below. |
| @@ -350,18 +354,18 @@ Use this argument instead of explicitly setting `view-exit-action'." | |||
| 350 | ;;;###autoload | 354 | ;;;###autoload |
| 351 | (defun view-buffer-other-frame (buffer &optional not-return exit-action) | 355 | (defun view-buffer-other-frame (buffer &optional not-return exit-action) |
| 352 | "View BUFFER in View mode in another frame. | 356 | "View BUFFER in View mode in another frame. |
| 353 | Return to previous buffer when done, unless optional NOT-RETURN is non-nil. | 357 | Return to previous buffer when done, unless optional NOT-RETURN is |
| 354 | Emacs commands editing the buffer contents are not available; instead, | 358 | non-nil. Emacs commands editing the buffer contents are not available; |
| 355 | a special set of commands (mostly letters and punctuation) | 359 | instead, a special set of commands (mostly letters and punctuation) are |
| 356 | are defined for moving around in the buffer. | 360 | defined for moving around in the buffer. |
| 357 | Space scrolls forward, Delete scrolls backward. | 361 | Space scrolls forward, Delete scrolls backward. |
| 358 | For list of all View commands, type H or h while viewing. | 362 | For a list of all View commands, type H or h while viewing. |
| 359 | 363 | ||
| 360 | This command runs the normal hook `view-mode-hook'. | 364 | This command runs the normal hook `view-mode-hook'. |
| 361 | 365 | ||
| 362 | Optional argument EXIT-ACTION is either nil or a function with buffer as | 366 | Optional argument EXIT-ACTION is either nil or a function with buffer as |
| 363 | argument. This function is called when finished viewing buffer. | 367 | argument. This function is called when finished viewing buffer. Use |
| 364 | Use this argument instead of explicitly setting `view-exit-action'." | 368 | this argument instead of explicitly setting `view-exit-action'." |
| 365 | (interactive "bView buffer in other frame: \nP") | 369 | (interactive "bView buffer in other frame: \nP") |
| 366 | (let ((return-to | 370 | (let ((return-to |
| 367 | (and (not not-return) (cons (selected-window) t)))) ; Old window. | 371 | (and (not not-return) (cons (selected-window) t)))) ; Old window. |
| @@ -495,34 +499,73 @@ Entry to view-mode runs the normal hook `view-mode-hook'." | |||
| 495 | (setq buffer-read-only view-old-buffer-read-only))) | 499 | (setq buffer-read-only view-old-buffer-read-only))) |
| 496 | 500 | ||
| 497 | ;;;###autoload | 501 | ;;;###autoload |
| 498 | (defun view-mode-enter (&optional return-to exit-action) "\ | 502 | (defun view-return-to-alist-update (buffer &optional item) |
| 499 | Enter View mode and set up exit from view mode depending on optional arguments. | 503 | "Update `view-return-to-alist' of buffer BUFFER. |
| 500 | If RETURN-TO is non-nil it is added as an element to the buffer local alist | 504 | Remove from `view-return-to-alist' all entries referencing dead |
| 501 | `view-return-to-alist'. | 505 | windows. Optional argument ITEM non-nil means add ITEM to |
| 502 | Save EXIT-ACTION in buffer local variable `view-exit-action'. | 506 | `view-return-to-alist' after purging. For a decsription of items |
| 503 | It should be either nil or a function that takes a buffer as argument. | 507 | that can be added see the RETURN-TO-ALIST argument of the |
| 504 | This function will be called by `view-mode-exit'. | 508 | function `view-mode-exit'. If `view-return-to-alist' contains an |
| 505 | 509 | entry for the selected window, purge that entry from | |
| 506 | RETURN-TO is either nil, meaning do nothing when exiting view mode, or | 510 | `view-return-to-alist' before adding ITEM." |
| 507 | it has the format (WINDOW OLD-WINDOW . OLD-BUF-INFO). | 511 | (with-current-buffer buffer |
| 508 | WINDOW is a window used for viewing. | 512 | (when view-return-to-alist |
| 509 | OLD-WINDOW is nil or the window to select after viewing. | 513 | (let* ((list view-return-to-alist) |
| 510 | OLD-BUF-INFO tells what to do with WINDOW when exiting. It is one of: | 514 | entry entry-window last) |
| 511 | 1) nil Do nothing. | 515 | (while list |
| 512 | 2) t Delete WINDOW or, if it is the only window, its frame. | 516 | (setq entry (car list)) |
| 517 | (setq entry-window (car entry)) | ||
| 518 | (if (and (windowp entry-window) | ||
| 519 | (or (and item (eq entry-window (selected-window))) | ||
| 520 | (not (window-live-p entry-window)))) | ||
| 521 | ;; Remove that entry. | ||
| 522 | (if last | ||
| 523 | (setcdr last (cdr list)) | ||
| 524 | (setq view-return-to-alist | ||
| 525 | (cdr view-return-to-alist))) | ||
| 526 | ;; Leave entry alone. | ||
| 527 | (setq last entry)) | ||
| 528 | (setq list (cdr list))))) | ||
| 529 | ;; Add ITEM. | ||
| 530 | (when item | ||
| 531 | (setq view-return-to-alist | ||
| 532 | (cons item view-return-to-alist))))) | ||
| 533 | |||
| 534 | ;;;###autoload | ||
| 535 | (defun view-mode-enter (&optional return-to exit-action) | ||
| 536 | "Enter View mode and set up exit from view mode depending on optional arguments. | ||
| 537 | RETURN-TO non-nil means add RETURN-TO as an element to the buffer | ||
| 538 | local alist `view-return-to-alist'. Save EXIT-ACTION in buffer | ||
| 539 | local variable `view-exit-action'. It should be either nil or a | ||
| 540 | function that takes a buffer as argument. This function will be | ||
| 541 | called by `view-mode-exit'. | ||
| 542 | |||
| 543 | RETURN-TO is either nil, meaning do nothing when exiting view | ||
| 544 | mode, or must have the format (WINDOW OLD-WINDOW . OLD-BUF-INFO). | ||
| 545 | WINDOW is the window used for viewing. OLD-WINDOW is nil or the | ||
| 546 | window to select after viewing. OLD-BUF-INFO tells what to do | ||
| 547 | with WINDOW when exiting. It is one of: | ||
| 548 | 1) nil Do nothing. | ||
| 549 | 2) t Delete WINDOW or, if it is the only window and | ||
| 550 | `view-remove-frame-by-deleting' is non-nil, its | ||
| 551 | frame. | ||
| 513 | 3) (OLD-BUFF START POINT) Display buffer OLD-BUFF with displayed text | 552 | 3) (OLD-BUFF START POINT) Display buffer OLD-BUFF with displayed text |
| 514 | starting at START and point at POINT in WINDOW. | 553 | starting at START and point at POINT in WINDOW. |
| 515 | 4) quit-window Do `quit-window' in WINDOW. | 554 | 4) quit-window Do `quit-window' in WINDOW. |
| 555 | 5) keep-frame Like case 2) but do not delete the frame. | ||
| 516 | 556 | ||
| 517 | For list of all View commands, type H or h while viewing. | 557 | For a list of all View commands, type H or h while viewing. |
| 518 | 558 | ||
| 519 | This function runs the normal hook `view-mode-hook'." | 559 | This function runs the normal hook `view-mode-hook'." |
| 520 | (if return-to | 560 | (when return-to |
| 521 | (let ((entry (assq (car return-to) view-return-to-alist))) | 561 | (let ((entry (assq (car return-to) view-return-to-alist))) |
| 522 | (if entry (setcdr entry (cdr return-to)) | 562 | (if entry |
| 523 | (setq view-return-to-alist (cons return-to view-return-to-alist))))) | 563 | (setcdr entry (cdr return-to)) |
| 524 | (if exit-action (setq view-exit-action exit-action)) | 564 | (setq view-return-to-alist (cons return-to view-return-to-alist))))) |
| 525 | (unless view-mode ; Do nothing if already in view mode. | 565 | (when exit-action |
| 566 | (setq view-exit-action exit-action)) | ||
| 567 | |||
| 568 | (unless view-mode | ||
| 526 | (view-mode-enable) | 569 | (view-mode-enable) |
| 527 | (force-mode-line-update) | 570 | (force-mode-line-update) |
| 528 | (unless view-inhibit-help-message | 571 | (unless view-inhibit-help-message |
| @@ -532,88 +575,106 @@ View mode: type \\[help-command] for help, \\[describe-mode] for commands, \\[Vi | |||
| 532 | 575 | ||
| 533 | (defun view-mode-exit (&optional return-to-alist exit-action all-win) | 576 | (defun view-mode-exit (&optional return-to-alist exit-action all-win) |
| 534 | "Exit View mode in various ways, depending on optional arguments. | 577 | "Exit View mode in various ways, depending on optional arguments. |
| 535 | RETURN-TO-ALIST, EXIT-ACTION and ALL-WIN determine what to do after exit. | 578 | RETURN-TO-ALIST, EXIT-ACTION and ALL-WIN determine what to do |
| 536 | EXIT-ACTION is nil or a function that is called with current buffer as | 579 | after exit. EXIT-ACTION is nil or a function that is called with |
| 537 | argument. | 580 | current buffer as argument. |
| 538 | RETURN-TO-ALIST is an alist that for some of the windows displaying the | 581 | |
| 539 | current buffer, associate information on what to do with those windows. | 582 | RETURN-TO-ALIST is an alist that, for some of the windows |
| 540 | If ALL-WIN or the variable `view-exits-all-viewing-windows' is non-nil, | 583 | displaying the current buffer, maintains information on what to |
| 541 | then all windows on RETURN-TO-ALIST are restored to their old state. | 584 | do when exiting those windows. If ALL-WIN is non-nil or the |
| 542 | Otherwise only the selected window is affected (if it is on RETURN-TO-ALIST). | 585 | variable `view-exits-all-viewing-windows' is non-nil, |
| 543 | 586 | view-mode-exit attempts to restore all windows showing the | |
| 544 | Elements of RETURN-TO-ALIST have the format (WINDOW OLD-WINDOW . OLD-BUF-INFO). | 587 | current buffer to their old state. Otherwise, only the selected |
| 545 | WINDOW is a window displaying the current buffer. | 588 | window is affected (provided it is on RETURN-TO-ALIST). |
| 546 | OLD-WINDOW is nil or a window to select after viewing. | 589 | |
| 547 | OLD-BUF-INFO is information on what to do with WINDOW and is one of: | 590 | Elements of RETURN-TO-ALIST must have the format |
| 548 | 1) nil Do nothing. | 591 | (WINDOW OLD-WINDOW . OLD-BUF-INFO) where |
| 549 | 2) t Delete WINDOW and, if it is the only window, its frame. | 592 | |
| 593 | WINDOW is a window displaying the current buffer and OLD-WINDOW | ||
| 594 | is either nil or a window to select after viewing. OLD-BUF-INFO | ||
| 595 | provides information on what to do with WINDOW and may be one of: | ||
| 596 | 1) nil Do nothing. | ||
| 597 | 2) t Delete WINDOW and, if it is the only window and | ||
| 598 | `view-remove-frame-by-deleting' is non-nil, its | ||
| 599 | frame. | ||
| 550 | 3) (OLD-BUF START POINT) Display buffer OLD-BUF with displayed text | 600 | 3) (OLD-BUF START POINT) Display buffer OLD-BUF with displayed text |
| 551 | starting at START and point at POINT in WINDOW. | 601 | starting at START and point at POINT in WINDOW. |
| 552 | 4) quit-window Do `quit-window' in WINDOW. | 602 | 4) quit-window Do `quit-window' in WINDOW. |
| 553 | 603 | 5) keep-frame Like case 2) but do not delete the frame. | |
| 554 | If one of the WINDOW in RETURN-TO-ALIST is the selected window and the | 604 | |
| 555 | corresponding OLD-WINDOW is a live window, then select OLD-WINDOW." | 605 | If one of the WINDOW in RETURN-TO-ALIST is the selected window |
| 556 | (setq all-win | 606 | and the corresponding OLD-WINDOW is a live window, then select |
| 557 | (and return-to-alist (or all-win view-exits-all-viewing-windows))) | 607 | OLD-WINDOW." |
| 558 | (if view-mode ; Only do something if in view mode. | 608 | (when view-mode ; Only do something if in view mode. |
| 559 | (let* ((buffer (current-buffer)) | 609 | (setq all-win |
| 560 | window notlost | 610 | (and return-to-alist |
| 561 | (sel-old (assq (selected-window) return-to-alist)) | 611 | (or all-win view-exits-all-viewing-windows))) |
| 562 | (alist (cond | 612 | (let* ((buffer (current-buffer)) |
| 563 | (all-win ; Try to restore all windows. | 613 | window notlost |
| 564 | (append return-to-alist nil)) ; Copy. | 614 | (sel-old (assq (selected-window) return-to-alist)) |
| 565 | (sel-old ; Only selected window. | 615 | (alist (cond |
| 566 | (list sel-old)))) | 616 | (all-win ; Try to restore all windows. |
| 567 | (old-window (if sel-old (car (cdr sel-old))))) | 617 | (append return-to-alist nil)) ; Copy. |
| 568 | (if all-win ; Follow chains of old-windows. | 618 | (sel-old ; Only selected window. |
| 569 | (let ((c (length alist)) a) | 619 | (list sel-old)))) |
| 570 | (while (and (> c 0) ; Safety if mutually refering windows. | 620 | (old-window (if sel-old (car (cdr sel-old))))) |
| 571 | (or (not (window-live-p old-window)) | 621 | (if all-win ; Follow chains of old-windows. |
| 572 | (eq buffer (window-buffer old-window))) | 622 | (let ((c (length alist)) a) |
| 573 | (setq a (assq old-window alist))) | 623 | (while (and (> c 0) ; Safety if mutually refering windows. |
| 574 | (setq c (1- c)) | 624 | (or (not (window-live-p old-window)) |
| 575 | (setq old-window (car (cdr a)))) | 625 | (eq buffer (window-buffer old-window))) |
| 576 | (if (or (zerop c) (not (window-live-p old-window))) | 626 | (setq a (assq old-window alist))) |
| 577 | (setq old-window (selected-window))))) | 627 | (setq c (1- c)) |
| 578 | (or view-no-disable-on-exit | 628 | (setq old-window (car (cdr a)))) |
| 579 | (view-mode-disable)) | 629 | (if (or (zerop c) (not (window-live-p old-window))) |
| 580 | (while alist ; Restore windows with info. | 630 | (setq old-window (selected-window))))) |
| 581 | (setq notlost nil) | 631 | (unless view-no-disable-on-exit |
| 582 | (if (and (window-live-p (setq window (car (car alist)))) | 632 | (view-mode-disable)) |
| 633 | (while alist ; Restore windows with info. | ||
| 634 | (setq notlost nil) | ||
| 635 | (when (and (window-live-p (setq window (car (car alist)))) | ||
| 583 | (eq buffer (window-buffer window))) | 636 | (eq buffer (window-buffer window))) |
| 584 | (let ((frame (window-frame window)) | 637 | (let ((frame (window-frame window)) |
| 585 | (old-buf-info (cdr (cdr (car alist))))) | 638 | (old-buf-info (cdr (cdr (car alist))))) |
| 586 | (if all-win (select-window window)) | 639 | (if all-win (select-window window)) |
| 587 | (cond | 640 | (cond |
| 588 | ((and (consp old-buf-info) ; Case 3. | 641 | ((and (consp old-buf-info) ; Case 3. |
| 589 | (buffer-live-p (car old-buf-info))) | 642 | (buffer-live-p (car old-buf-info))) |
| 590 | (set-window-buffer window (car old-buf-info)) ; old-buf | 643 | (set-window-buffer window (car old-buf-info)) ; old-buf |
| 591 | (set-window-start window (car (cdr old-buf-info))) | 644 | (set-window-start window (car (cdr old-buf-info))) |
| 592 | (set-window-point window (car (cdr (cdr old-buf-info))))) | 645 | (set-window-point window (car (cdr (cdr old-buf-info))))) |
| 593 | ((eq old-buf-info 'quit-window) | 646 | ((eq old-buf-info 'quit-window) |
| 594 | (quit-window)) ; Case 4. | 647 | (quit-window)) ; Case 4. |
| 595 | ((not (eq old-buf-info t)) nil) ; Not case 2, do nothing. | 648 | (old-buf-info ; Case 2 or 5. |
| 596 | ((not (one-window-p t)) (delete-window)) | 649 | (cond |
| 597 | ((not (eq frame (next-frame))) | 650 | ((not (one-window-p t)) ; Not only window. |
| 598 | ;; Not the only frame, so can safely be removed. | 651 | (delete-window)) |
| 599 | (if view-remove-frame-by-deleting | 652 | ((eq old-buf-info 'keep-frame) ; Case 5. |
| 600 | (delete-frame frame) | 653 | (bury-buffer)) |
| 601 | (setq notlost t) ; Keep the window. See below. | 654 | ((not (eq frame (next-frame))) ; Case 2 and only window. |
| 602 | (iconify-frame frame)))))) | 655 | ;; Not the only frame, so can safely be removed. |
| 603 | ;; If a frame is removed by iconifying it, then the window is not | 656 | (if view-remove-frame-by-deleting |
| 604 | ;; really lost. In this case we keep the entry in | 657 | (delete-frame frame) |
| 605 | ;; view-return-to-alist so that if the user deiconifies the frame | 658 | (setq notlost t) ; Keep the window. See below. |
| 606 | ;; and then press q, then the frame is iconified again. | 659 | (iconify-frame frame)))))))) |
| 607 | (unless notlost | 660 | ;; If a frame is removed by iconifying it, the window is not |
| 661 | ;; really lost. In this case we keep the entry in | ||
| 662 | ;; `view-return-to-alist' so that if the user deiconifies the | ||
| 663 | ;; frame and then hits q, the frame is iconified again. | ||
| 664 | (unless notlost | ||
| 665 | (with-current-buffer buffer | ||
| 608 | (setq view-return-to-alist | 666 | (setq view-return-to-alist |
| 609 | (delete (car alist) view-return-to-alist))) | 667 | (delete (car alist) view-return-to-alist)))) |
| 610 | (setq alist (cdr alist))) | 668 | (setq alist (cdr alist))) |
| 611 | (if (window-live-p old-window) ; still existing window | 669 | (when (window-live-p old-window) |
| 612 | (select-window old-window)) | 670 | ;; old-window is still alive => select it. |
| 613 | (when exit-action | 671 | (select-window old-window)) |
| 614 | (setq view-exit-action nil) | 672 | (when exit-action |
| 615 | (funcall exit-action buffer)) | 673 | ;; Don't do that: If the user wants to quit the *Help* buffer a |
| 616 | (force-mode-line-update)))) | 674 | ;; second time it won't have any effect. |
| 675 | ;;; (setq view-exit-action nil) | ||
| 676 | (funcall exit-action buffer)) | ||
| 677 | (force-mode-line-update)))) | ||
| 617 | 678 | ||
| 618 | (defun View-exit () | 679 | (defun View-exit () |
| 619 | "Exit View mode but stay in current buffer." | 680 | "Exit View mode but stay in current buffer." |