(mm-charset-override-alist): Declare for compiler.
[emacs.git] / lisp / gnus / gnus-eform.el
blob0f09e5eddabea42029fa466e86e02b097d75ef4b
1 ;;; gnus-eform.el --- a mode for editing forms for Gnus
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;;; Code:
28 (require 'gnus)
29 (require 'gnus-win)
31 ;;;
32 ;;; Editing forms
33 ;;;
35 (defgroup gnus-edit-form nil
36 "A mode for editing forms."
37 :group 'gnus)
39 (defcustom gnus-edit-form-mode-hook nil
40 "Hook run in `gnus-edit-form-mode' buffers."
41 :group 'gnus-edit-form
42 :type 'hook)
44 (defcustom gnus-edit-form-menu-hook nil
45 "Hook run when creating menus in `gnus-edit-form-mode' buffers."
46 :group 'gnus-edit-form
47 :type 'hook)
49 ;;; Internal variables
51 (defvar gnus-edit-form-buffer "*Gnus edit form*")
52 (defvar gnus-edit-form-done-function nil)
54 (defvar gnus-edit-form-mode-map nil)
55 (unless gnus-edit-form-mode-map
56 (setq gnus-edit-form-mode-map (make-sparse-keymap))
57 (set-keymap-parent gnus-edit-form-mode-map emacs-lisp-mode-map)
58 (gnus-define-keys gnus-edit-form-mode-map
59 "\C-c\C-c" gnus-edit-form-done
60 "\C-c\C-k" gnus-edit-form-exit))
62 (defun gnus-edit-form-make-menu-bar ()
63 (unless (boundp 'gnus-edit-form-menu)
64 (easy-menu-define
65 gnus-edit-form-menu gnus-edit-form-mode-map ""
66 '("Edit Form"
67 ["Exit and save changes" gnus-edit-form-done t]
68 ["Exit" gnus-edit-form-exit t]))
69 (gnus-run-hooks 'gnus-edit-form-menu-hook)))
71 (defun gnus-edit-form-mode ()
72 "Major mode for editing forms.
73 It is a slightly enhanced emacs-lisp-mode.
75 \\{gnus-edit-form-mode-map}"
76 (interactive)
77 (when (gnus-visual-p 'group-menu 'menu)
78 (gnus-edit-form-make-menu-bar))
79 (kill-all-local-variables)
80 (setq major-mode 'gnus-edit-form-mode)
81 (setq mode-name "Edit Form")
82 (use-local-map gnus-edit-form-mode-map)
83 (make-local-variable 'gnus-edit-form-done-function)
84 (make-local-variable 'gnus-prev-winconf)
85 (gnus-run-mode-hooks 'gnus-edit-form-mode-hook))
87 (defun gnus-edit-form (form documentation exit-func &optional layout)
88 "Edit FORM in a new buffer.
89 Call EXIT-FUNC on exit. Display DOCUMENTATION in the beginning
90 of the buffer.
91 The optional LAYOUT overrides the `edit-form' window layout."
92 (let ((winconf (current-window-configuration)))
93 (set-buffer (gnus-get-buffer-create gnus-edit-form-buffer))
94 (gnus-configure-windows (or layout 'edit-form))
95 (gnus-edit-form-mode)
96 (setq gnus-prev-winconf winconf)
97 (setq gnus-edit-form-done-function exit-func)
98 (erase-buffer)
99 (insert documentation)
100 (unless (bolp)
101 (insert "\n"))
102 (goto-char (point-min))
103 (while (not (eobp))
104 (insert ";;; ")
105 (forward-line 1))
106 (insert ";; Type `C-c C-c' after you've finished editing.\n")
107 (insert "\n")
108 (let ((p (point)))
109 (gnus-pp form)
110 (insert "\n")
111 (goto-char p))))
113 (defun gnus-edit-form-done ()
114 "Update changes and kill the current buffer."
115 (interactive)
116 (goto-char (point-min))
117 (let ((form (condition-case nil
118 (read (current-buffer))
119 (end-of-file nil)))
120 (func gnus-edit-form-done-function))
121 (gnus-edit-form-exit)
122 (funcall func form)))
124 (defun gnus-edit-form-exit ()
125 "Kill the current buffer."
126 (interactive)
127 (let ((winconf gnus-prev-winconf))
128 (kill-buffer (current-buffer))
129 (set-window-configuration winconf)))
131 (provide 'gnus-eform)
133 ;; arch-tag: ef50678c-2c28-49ef-affc-e53b3b2c0bf6
134 ;;; gnus-eform.el ends here