Bind [?\S-\ ] to previous line command in Dired-like modes.
[emacs.git] / lisp / gnus / gnus-vm.el
blob3777a906d09944b8db9af6009466c4f92b9f3fa3
1 ;;; gnus-vm.el --- vm interface for Gnus
3 ;; Copyright (C) 1994-2015 Free Software Foundation, Inc.
5 ;; Author: Per Persson <pp@gnu.ai.mit.edu>
6 ;; Keywords: news, mail
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;; Major contributors:
26 ;; Christian Limpach <Christian.Limpach@nice.ch>
27 ;; Some code stolen from:
28 ;; Rick Sladkey <jrs@world.std.com>
30 ;;; Code:
32 (require 'sendmail)
33 (require 'message)
34 (require 'gnus)
35 (require 'gnus-msg)
37 (eval-when-compile
38 (require 'cl))
40 (autoload 'vm-mode "vm")
41 (autoload 'vm-save-message "vm")
43 (defvar gnus-vm-inhibit-window-system nil
44 "Inhibit loading `win-vm' if using a window-system.
45 Has to be set before gnus-vm is loaded.")
47 (unless gnus-vm-inhibit-window-system
48 (ignore-errors
49 (when window-system
50 (require 'win-vm))))
52 (defun gnus-vm-make-folder (&optional buffer)
53 (require 'vm)
54 (let ((article (or buffer (current-buffer)))
55 (tmp-folder (generate-new-buffer " *tmp-folder*"))
56 (start (point-min))
57 (end (point-max)))
58 (set-buffer tmp-folder)
59 (insert-buffer-substring article start end)
60 (goto-char (point-min))
61 (if (looking-at "^\\(From [^ ]+ \\).*$")
62 (replace-match (concat "\\1" (current-time-string)))
63 (insert "From " gnus-newsgroup-name " "
64 (current-time-string) "\n"))
65 (while (re-search-forward "\n\nFrom " nil t)
66 (replace-match "\n\n>From "))
67 ;; insert a newline, otherwise the last line gets lost
68 (goto-char (point-max))
69 (insert "\n")
70 (vm-mode)
71 tmp-folder))
73 (defun gnus-summary-save-article-vm (&optional arg)
74 "Append the current article to a vm folder.
75 If N is a positive number, save the N next articles.
76 If N is a negative number, save the N previous articles.
77 If N is nil and any articles have been marked with the process mark,
78 save those articles instead."
79 (interactive "P")
80 (require 'gnus-art)
81 (let ((gnus-default-article-saver 'gnus-summary-save-in-vm))
82 (gnus-summary-save-article arg)))
84 (defun gnus-summary-save-in-vm (&optional folder)
85 (interactive)
86 (require 'vm)
87 (setq folder
88 (gnus-read-save-file-name
89 "Save %s in VM folder:" folder
90 gnus-mail-save-name gnus-newsgroup-name
91 gnus-current-headers 'gnus-newsgroup-last-mail))
92 (gnus-eval-in-buffer-window gnus-original-article-buffer
93 (save-excursion
94 (save-restriction
95 (widen)
96 (let ((vm-folder (gnus-vm-make-folder)))
97 (vm-save-message folder)
98 (kill-buffer vm-folder))))))
100 (provide 'gnus-vm)
102 ;;; gnus-vm.el ends here