(Finsert_file_contents): Use xfree instead of free.
[emacs.git] / lisp / gnus / gnus-eform.el
blob6a93242feafefa1ff552a81127cb8b263b8fbfcc
1 ;;; gnus-eform.el --- a mode for editing forms for Gnus
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; Keywords: news
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
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 (copy-keymap emacs-lisp-mode-map))
57 (gnus-define-keys gnus-edit-form-mode-map
58 "\C-c\C-c" gnus-edit-form-done
59 "\C-c\C-k" gnus-edit-form-exit))
61 (defun gnus-edit-form-make-menu-bar ()
62 (unless (boundp 'gnus-edit-form-menu)
63 (easy-menu-define
64 gnus-edit-form-menu gnus-edit-form-mode-map ""
65 '("Edit Form"
66 ["Exit and save changes" gnus-edit-form-done t]
67 ["Exit" gnus-edit-form-exit t]))
68 (gnus-run-hooks 'gnus-edit-form-menu-hook)))
70 (defun gnus-edit-form-mode ()
71 "Major mode for editing forms.
72 It is a slightly enhanced emacs-lisp-mode.
74 \\{gnus-edit-form-mode-map}"
75 (interactive)
76 (when (gnus-visual-p 'group-menu 'menu)
77 (gnus-edit-form-make-menu-bar))
78 (kill-all-local-variables)
79 (setq major-mode 'gnus-edit-form-mode)
80 (setq mode-name "Edit Form")
81 (use-local-map gnus-edit-form-mode-map)
82 (make-local-variable 'gnus-edit-form-done-function)
83 (make-local-variable 'gnus-prev-winconf)
84 (gnus-run-hooks 'gnus-edit-form-mode-hook))
86 (defun gnus-edit-form (form documentation exit-func)
87 "Edit FORM in a new buffer.
88 Call EXIT-FUNC on exit. Display DOCUMENTATION in the beginning
89 of the buffer."
90 (let ((winconf (current-window-configuration)))
91 (set-buffer (gnus-get-buffer-create gnus-edit-form-buffer))
92 (gnus-configure-windows 'edit-form)
93 (gnus-edit-form-mode)
94 (setq gnus-prev-winconf winconf)
95 (setq gnus-edit-form-done-function exit-func)
96 (erase-buffer)
97 (insert documentation)
98 (unless (bolp)
99 (insert "\n"))
100 (goto-char (point-min))
101 (while (not (eobp))
102 (insert ";;; ")
103 (forward-line 1))
104 (insert ";; Type `C-c C-c' after you've finished editing.\n")
105 (insert "\n")
106 (let ((p (point)))
107 (pp form (current-buffer))
108 (insert "\n")
109 (goto-char p))))
111 (defun gnus-edit-form-done ()
112 "Update changes and kill the current buffer."
113 (interactive)
114 (goto-char (point-min))
115 (let ((form (read (current-buffer)))
116 (func gnus-edit-form-done-function))
117 (gnus-edit-form-exit)
118 (funcall func form)))
120 (defun gnus-edit-form-exit ()
121 "Kill the current buffer."
122 (interactive)
123 (let ((winconf gnus-prev-winconf))
124 (kill-buffer (current-buffer))
125 (set-window-configuration winconf)))
127 (provide 'gnus-eform)
129 ;;; gnus-eform.el ends here