~vm/vm/before-save-hook

« back to all changes in this revision

Viewing changes to lisp/vm-folder.el

  • Committer: Uday S Reddy
  • Date: 2013-02-07 09:57:37 UTC
  • Revision ID: u.s.reddy@cs.bham.ac.uk-20130207095737-khueat0wr798p4cm
A first cut at a before-save-hook for updating servers when M-x save-some-buffers is done.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3733
3733
  (intern (buffer-name) vm-buffers-needing-display-update)
3734
3734
  (setq vm-block-new-mail nil)
3735
3735
  (vm-display nil nil '(vm-save-buffer) '(vm-save-buffer))
3736
 
  (if (and vm-folders-summary-database buffer-file-name)
3737
 
      (progn
3738
 
        (vm-compute-totals)
3739
 
        (vm-store-folder-totals buffer-file-name (cdr vm-totals))))
 
3736
  (when (and vm-folders-summary-database buffer-file-name)
 
3737
    (vm-compute-totals)
 
3738
    (vm-store-folder-totals buffer-file-name (cdr vm-totals)))
3740
3739
  (vm-update-summary-and-mode-line)
3741
3740
  (vm-write-index-file-maybe))
3742
3741
 
3756
3755
                            vm-default-folder-permission-bits))
3757
3756
          (call-interactively 'write-file))
3758
3757
      (and oldmodebits (set-default-file-modes oldmodebits)))
3759
 
    (if (and vm-folders-summary-database buffer-file-name)
3760
 
        (progn
3761
 
          (vm-compute-totals)
3762
 
          (vm-store-folder-totals buffer-file-name (cdr vm-totals))))
3763
 
    (if (not (equal (buffer-name) old-buffer-name))
3764
 
        (progn
3765
 
          (vm-check-for-killed-summary)
3766
 
          (if vm-summary-buffer
3767
 
              (save-excursion
3768
 
                (let ((name (buffer-name)))
3769
 
                  (set-buffer vm-summary-buffer)
3770
 
                  (rename-buffer (format "%s Summary" name) t))))
3771
 
          (vm-check-for-killed-presentation)
3772
 
          (if vm-presentation-buffer-handle
3773
 
              (save-excursion
3774
 
                (let ((name (buffer-name)))
3775
 
                  (set-buffer vm-presentation-buffer-handle)
3776
 
                  (rename-buffer (format "%s Presentation" name) t)))))))
 
3758
    (when (and vm-folders-summary-database buffer-file-name)
 
3759
      (vm-compute-totals)
 
3760
      (vm-store-folder-totals buffer-file-name (cdr vm-totals)))
 
3761
    (when (not (equal (buffer-name) old-buffer-name))
 
3762
      (vm-check-for-killed-summary)
 
3763
      (when vm-summary-buffer
 
3764
        (save-excursion
 
3765
          (let ((name (buffer-name)))
 
3766
            (set-buffer vm-summary-buffer)
 
3767
            (rename-buffer (format "%s Summary" name) t))))
 
3768
      (vm-check-for-killed-presentation)
 
3769
      (when vm-presentation-buffer-handle
 
3770
        (save-excursion
 
3771
          (let ((name (buffer-name)))
 
3772
            (set-buffer vm-presentation-buffer-handle)
 
3773
            (rename-buffer (format "%s Presentation" name) t))))))
3777
3774
  (intern (buffer-name) vm-buffers-needing-display-update)
3778
3775
  (setq vm-block-new-mail nil)
3779
3776
  (vm-display nil nil '(vm-write-file) '(vm-write-file))
3798
3795
  (let ((vm-expunge-before-save nil))
3799
3796
    (vm-save-folder prefix)))
3800
3797
 
 
3798
;;;###autoload
 
3799
(defun vm-save-buffer-hook ()
 
3800
  "Before a folder is saved to disk, synchronize with the POP/IMAP
 
3801
servers if applicable."
 
3802
  (cond ((eq vm-folder-access-method 'pop)
 
3803
         (vm-pop-synchronize-folder :interactive t 
 
3804
                                    :do-remote-expunges t 
 
3805
                                    :do-local-expunges t 
 
3806
                                    :do-retrieves nil))
 
3807
        ((eq vm-folder-access-method 'imap)
 
3808
         (vm-imap-synchronize-folder :interactive t 
 
3809
                                     :do-remote-expunges t 
 
3810
                                     :do-local-expunges t 
 
3811
                                     :do-retrieves nil
 
3812
                                     :save-attributes t)))  
 
3813
  )
3801
3814
 
3802
3815
;;;###autoload
3803
3816
(defun vm-save-folder (&optional prefix)
3915
3928
;;;###autoload
3916
3929
(defun vm-save-and-expunge-folder (&optional prefix)
3917
3930
  "Expunge folder, then save it to disk.
3918
 
Prefix arg is handled the same as for the command `save-buffer'.
3919
 
Expunge won't be done if folder is read-only.
 
3931
Prefix arg is handled the same way as in `save-buffer'.
3920
3932
 
3921
 
When applied to a virtual folder, this command works as if you had
3922
 
run `vm-expunge-folder' followed by `vm-save-folder'."
 
3933
This command works as if you had run `vm-expunge-folder' followed by
 
3934
`vm-save-folder'.   An exception is when the folder is read-only, in
 
3935
which case `vm-expunge-folder' is omitted."
3923
3936
  (interactive (list current-prefix-arg))
3924
3937
  (vm-select-folder-buffer-and-validate 0 (vm-interactive-p))
3925
3938
  (vm-display nil nil '(vm-save-and-expunge-folder)
4985
4998
           (setq vm-folder-access-data 
4986
4999
                 (make-vector vm-folder-imap-access-data-length nil)))))
4987
5000
  (use-local-map vm-mode-map)
 
5001
  (vm-make-local-hook 'before-save-hook)
 
5002
  (add-hook 'before-save-hook 'vm-save-buffer-hook)
4988
5003
  ;; if the user saves after M-x recover-file, let them get new
4989
5004
  ;; mail again.
4990
5005
  (vm-make-local-hook 'after-save-hook)