diff options
| author | Chong Yidong | 2009-01-22 04:52:49 +0000 |
|---|---|---|
| committer | Chong Yidong | 2009-01-22 04:52:49 +0000 |
| commit | 104a1c701bb8cfbde0f60c54b34c1423a958b43c (patch) | |
| tree | 631b602335c9be99ff11ce4c3f7dcb48b39249f0 | |
| parent | f1f2094bb476f00d8eb085f89bee6c4c3463af69 (diff) | |
| download | emacs-104a1c701bb8cfbde0f60c54b34c1423a958b43c.tar.gz emacs-104a1c701bb8cfbde0f60c54b34c1423a958b43c.zip | |
(buffer-swapped-with): Var removed.
(pmail-buffer-swapped): New var.
(pmail-write-region-annotate): New function.
(pmail-save-buffer): New function.
| -rw-r--r-- | lisp/mail/pmail.el | 78 |
1 files changed, 24 insertions, 54 deletions
diff --git a/lisp/mail/pmail.el b/lisp/mail/pmail.el index 229c6a43cec..7787f762f7d 100644 --- a/lisp/mail/pmail.el +++ b/lisp/mail/pmail.el | |||
| @@ -41,44 +41,6 @@ | |||
| 41 | (require 'mail-utils) | 41 | (require 'mail-utils) |
| 42 | (eval-when-compile (require 'mule-util)) ; for detect-coding-with-priority | 42 | (eval-when-compile (require 'mule-util)) ; for detect-coding-with-priority |
| 43 | 43 | ||
| 44 | |||
| 45 | ;; The buffer-swapped-with feature has been moved here temporarily. | ||
| 46 | ;; When pmail is merged, this advice must be eliminated and the | ||
| 47 | ;; functionality somehow reimplemented. | ||
| 48 | |||
| 49 | (defvar buffer-swapped-with nil | ||
| 50 | "Buffer that this buffer's contents are temporarily swapped with. | ||
| 51 | You should only set this variable in file-visiting buffers, | ||
| 52 | because it only affects how to save the buffer in its file.") | ||
| 53 | (make-variable-buffer-local 'buffer-swapped-with) | ||
| 54 | (put 'buffer-swapped-with 'permanent-local t) | ||
| 55 | |||
| 56 | (defadvice basic-save-buffer | ||
| 57 | (around check-swap activate) | ||
| 58 | "If this buffer's real contents are swapped with some other buffer, | ||
| 59 | temporarily unswap in order to save the real contents. This | ||
| 60 | advice is temporarily used by pmail until a satisfactory solution | ||
| 61 | can be written." | ||
| 62 | (if (not buffer-swapped-with) | ||
| 63 | (progn | ||
| 64 | ;;; (if (and (string= "PMAIL" (buffer-name)) | ||
| 65 | ;;; (< (buffer-size) 1000000)) | ||
| 66 | ;;; (debug)) | ||
| 67 | ad-do-it) | ||
| 68 | (unwind-protect | ||
| 69 | (let ((modp (buffer-modified-p))) | ||
| 70 | ;;; (save-match-data | ||
| 71 | ;;; (let ((case-fold-search nil)) | ||
| 72 | ;;; (unless (or (string-match "PMAIL" (buffer-name)) | ||
| 73 | ;;; (string-match "xmail" (buffer-name)) | ||
| 74 | ;;; (string-match "mbox" (buffer-name))) | ||
| 75 | ;;; (debug)))) | ||
| 76 | (buffer-swap-text buffer-swapped-with) | ||
| 77 | (set-buffer-modified-p modp) | ||
| 78 | ad-do-it) | ||
| 79 | (buffer-swap-text buffer-swapped-with) | ||
| 80 | (set-buffer-modified-p nil)))) | ||
| 81 | |||
| 82 | (defconst pmail-attribute-header "X-RMAIL-ATTRIBUTES" | 44 | (defconst pmail-attribute-header "X-RMAIL-ATTRIBUTES" |
| 83 | "The header that stores the Pmail attribute data.") | 45 | "The header that stores the Pmail attribute data.") |
| 84 | 46 | ||
| @@ -615,6 +577,12 @@ by substituting the new message number into the existing list.") | |||
| 615 | (defvar pmail-summary-vector nil) | 577 | (defvar pmail-summary-vector nil) |
| 616 | (put 'pmail-summary-vector 'permanent-local t) | 578 | (put 'pmail-summary-vector 'permanent-local t) |
| 617 | 579 | ||
| 580 | ;; Pmail buffer swapping variables. | ||
| 581 | |||
| 582 | (defvar pmail-buffer-swapped nil | ||
| 583 | "If non-nil, `pmail-buffer' is swapped with `pmail-view-buffer'.") | ||
| 584 | (make-variable-buffer-local 'pmail-buffer-swapped) | ||
| 585 | |||
| 618 | (defvar pmail-view-buffer nil | 586 | (defvar pmail-view-buffer nil |
| 619 | "Buffer which holds PMAIL message for MIME displaying.") | 587 | "Buffer which holds PMAIL message for MIME displaying.") |
| 620 | (put 'pmail-view-buffer 'permanent-local t) | 588 | (put 'pmail-view-buffer 'permanent-local t) |
| @@ -1299,7 +1267,9 @@ Instead, these commands are available: | |||
| 1299 | (use-local-map pmail-mode-map) | 1267 | (use-local-map pmail-mode-map) |
| 1300 | (set-syntax-table text-mode-syntax-table) | 1268 | (set-syntax-table text-mode-syntax-table) |
| 1301 | (setq local-abbrev-table text-mode-abbrev-table) | 1269 | (setq local-abbrev-table text-mode-abbrev-table) |
| 1302 | ;; First attempt at adding hook functions to support buffer swapping... | 1270 | ;; Functions to support buffer swapping: |
| 1271 | (add-hook 'write-region-annotate-functions | ||
| 1272 | 'pmail-write-region-annotate nil t) | ||
| 1303 | (add-hook 'kill-buffer-hook 'pmail-mode-kill-buffer-hook nil t) | 1273 | (add-hook 'kill-buffer-hook 'pmail-mode-kill-buffer-hook nil t) |
| 1304 | (add-hook 'change-major-mode-hook 'pmail-change-major-mode-hook nil t)) | 1274 | (add-hook 'change-major-mode-hook 'pmail-change-major-mode-hook nil t)) |
| 1305 | 1275 | ||
| @@ -1314,23 +1284,17 @@ Create the buffer if necessary." | |||
| 1314 | 1284 | ||
| 1315 | (defun pmail-change-major-mode-hook () | 1285 | (defun pmail-change-major-mode-hook () |
| 1316 | ;; Bring the actual Pmail messages back into the main buffer. | 1286 | ;; Bring the actual Pmail messages back into the main buffer. |
| 1317 | (if buffer-swapped-with | 1287 | (when (pmail-buffers-swapped-p) |
| 1318 | (when (pmail-buffers-swapped-p) | 1288 | (setq pmail-buffer-swapped nil) |
| 1319 | (setq buffer-swapped-with nil) | 1289 | (let ((modp (buffer-modified-p))) |
| 1320 | (let ((modp (buffer-modified-p))) | 1290 | (buffer-swap-text pmail-view-buffer) |
| 1321 | (buffer-swap-text pmail-view-buffer) | 1291 | (set-buffer-modified-p modp)))) |
| 1322 | (set-buffer-modified-p modp))))) | ||
| 1323 | ;; Throw away the summary. | ||
| 1324 | ;;(when (buffer-live-p pmail-view-buffer) (kill-buffer pmail-view-buffer))) | ||
| 1325 | 1292 | ||
| 1326 | (defun pmail-buffers-swapped-p () | 1293 | (defun pmail-buffers-swapped-p () |
| 1327 | "Return non-nil if the message collection is in `pmail-view-buffer'." | 1294 | "Return non-nil if the message collection is in `pmail-view-buffer'." |
| 1328 | ;; We need to be careful to keep track of which buffer holds the | 1295 | ;; This is analogous to tar-data-swapped-p in tar-mode.el. |
| 1329 | ;; message collection, since we swap the collection the view of the | ||
| 1330 | ;; current message back and forth. This model is based on Stefan | ||
| 1331 | ;; Monnier's solution for tar-mode. | ||
| 1332 | (and (buffer-live-p pmail-view-buffer) | 1296 | (and (buffer-live-p pmail-view-buffer) |
| 1333 | (> (buffer-size pmail-view-buffer) (buffer-size)))) | 1297 | pmail-buffer-swapped)) |
| 1334 | 1298 | ||
| 1335 | (defun pmail-swap-buffers-maybe () | 1299 | (defun pmail-swap-buffers-maybe () |
| 1336 | "Determine if the Pmail buffer is showing a message. | 1300 | "Determine if the Pmail buffer is showing a message. |
| @@ -1340,7 +1304,7 @@ If so restore the actual mbox message collection." | |||
| 1340 | (let ((modp (buffer-modified-p))) | 1304 | (let ((modp (buffer-modified-p))) |
| 1341 | (buffer-swap-text pmail-view-buffer) | 1305 | (buffer-swap-text pmail-view-buffer) |
| 1342 | (set-buffer-modified-p modp)) | 1306 | (set-buffer-modified-p modp)) |
| 1343 | (setq buffer-swapped-with nil)))) | 1307 | (setq pmail-buffer-swapped nil)))) |
| 1344 | 1308 | ||
| 1345 | (defun pmail-mode-kill-buffer-hook () | 1309 | (defun pmail-mode-kill-buffer-hook () |
| 1346 | (if (buffer-live-p pmail-view-buffer) (kill-buffer pmail-view-buffer))) | 1310 | (if (buffer-live-p pmail-view-buffer) (kill-buffer pmail-view-buffer))) |
| @@ -2601,7 +2565,7 @@ The current mail message becomes the message displayed." | |||
| 2601 | (let ((modp (buffer-modified-p))) | 2565 | (let ((modp (buffer-modified-p))) |
| 2602 | (buffer-swap-text pmail-view-buffer) | 2566 | (buffer-swap-text pmail-view-buffer) |
| 2603 | (set-buffer-modified-p modp)) | 2567 | (set-buffer-modified-p modp)) |
| 2604 | (setq buffer-swapped-with pmail-view-buffer) | 2568 | (setq pmail-buffer-swapped t) |
| 2605 | (run-hooks 'pmail-show-message-hook)) | 2569 | (run-hooks 'pmail-show-message-hook)) |
| 2606 | blurb)) | 2570 | blurb)) |
| 2607 | 2571 | ||
| @@ -3912,6 +3876,12 @@ encoded string (and the same mask) will decode the string." | |||
| 3912 | (add-to-list 'desktop-buffer-mode-handlers | 3876 | (add-to-list 'desktop-buffer-mode-handlers |
| 3913 | '(pmail-mode . pmail-restore-desktop-buffer)) | 3877 | '(pmail-mode . pmail-restore-desktop-buffer)) |
| 3914 | 3878 | ||
| 3879 | ;; Used in `write-region-annotate-functions' to write pmail files. | ||
| 3880 | (defun pmail-write-region-annotate (start end) | ||
| 3881 | (when (pmail-buffers-swapped-p) | ||
| 3882 | (set-buffer pmail-view-buffer) | ||
| 3883 | (widen) | ||
| 3884 | nil)) | ||
| 3915 | 3885 | ||
| 3916 | (provide 'pmail) | 3886 | (provide 'pmail) |
| 3917 | 3887 | ||