1 ;;; gnus-eform.el --- a mode for editing forms for Gnus
2 ;; Copyright (C) 1996 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
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)
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.
36 (defvar gnus-edit-form-mode-hook nil
37 "Hook run in `gnus-edit-form-mode' buffers.")
39 (defvar gnus-edit-form-menu-hook nil
40 "Hook run when creating menus in `gnus-edit-form-mode' buffers.")
42 ;;; Internal variables
44 (defvar gnus-edit-form-done-function nil)
45 (defvar gnus-edit-form-buffer "*Gnus edit form*")
47 (defvar gnus-edit-form-mode-map nil)
48 (unless gnus-edit-form-mode-map
49 (set gnus-edit-form-mode-map (copy-keymap emacs-lisp-mode-map))
50 (gnus-define-keys gnus-edit-form-mode-map
51 "\C-c\C-c" gnus-edit-form-done
52 "\C-c\C-k" gnus-edit-form-exit))
54 (defun gnus-edit-form-make-menu-bar ()
55 (unless (boundp 'gnus-edit-form-menu)
57 gnus-edit-form-menu gnus-edit-form-mode-map ""
59 ["Exit and save changes" gnus-edit-form-done t]
60 ["Exit" gnus-edit-form-exit t]))
61 (run-hooks 'gnus-edit-form-menu-hook)))
63 (defun gnus-edit-form-mode ()
64 "Major mode for editing forms.
65 It is a slightly enhanced emacs-lisp-mode.
67 \\{gnus-edit-form-mode-map}"
69 (when (and menu-bar-mode
70 (gnus-visual-p 'group-menu 'menu))
71 (gnus-edit-form-make-menu-bar))
72 (kill-all-local-variables)
73 (setq major-mode 'gnus-edit-form-mode)
74 (setq mode-name "Edit Form")
75 (use-local-map gnus-edit-form-mode-map)
76 (make-local-variable 'gnus-edit-form-done-function)
77 (make-local-variable 'gnus-prev-winconf)
78 (run-hooks 'gnus-edit-form-mode-hook))
80 (defun gnus-edit-form (form documentation exit-func)
81 "Edit FORM in a new buffer.
82 Call EXIT-FUNC on exit. Display DOCUMENTATION in the beginning
84 (let ((winconf (current-window-configuration)))
85 (set-buffer (setq gnus-edit-form-buffer
86 (get-buffer-create gnus-edit-form-buffer)))
87 (gnus-configure-windows 'edit-form)
88 (gnus-add-current-to-buffer-list)
90 (setq gnus-prev-winconf winconf)
91 (setq gnus-edit-form-done-function exit-func)
93 (insert documentation)
96 (goto-char (point-min))
100 (insert ";; Type `C-c C-c' after you've finished editing.\n")
103 (pp form (current-buffer))
107 (defun gnus-edit-form-done ()
108 "Update changes and kill the current buffer."
110 (goto-char (point-min))
111 (let ((form (read (current-buffer))))
112 (gnus-edit-form-exit)
113 (funcall gnus-edit-form-done-function form)))
115 (defun gnus-edit-form-exit ()
116 "Kill the current buffer."
118 (let ((winconf gnus-prev-winconf))
119 (kill-buffer (current-buffer))
120 (set-window-configuration winconf)))
122 (provide 'gnus-eform)
124 ;;; gnus-eform.el ends here