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@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.
35 (defgroup gnus-edit-form nil
36 "A mode for editing forms."
39 (defcustom gnus-edit-form-mode-hook nil
40 "Hook run in `gnus-edit-form-mode' buffers."
41 :group 'gnus-edit-form
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
49 ;;; Internal variables
51 (defvar gnus-edit-form-done-function nil)
53 (defvar gnus-edit-form-mode-map nil)
54 (unless gnus-edit-form-mode-map
55 (setq gnus-edit-form-mode-map (copy-keymap emacs-lisp-mode-map))
56 (gnus-define-keys gnus-edit-form-mode-map
57 "\C-c\C-c" gnus-edit-form-done
58 "\C-c\C-k" gnus-edit-form-exit))
60 (defun gnus-edit-form-make-menu-bar ()
61 (unless (boundp 'gnus-edit-form-menu)
63 gnus-edit-form-menu gnus-edit-form-mode-map ""
65 ["Exit and save changes" gnus-edit-form-done t]
66 ["Exit" gnus-edit-form-exit t]))
67 (gnus-run-hooks 'gnus-edit-form-menu-hook)))
69 (defun gnus-edit-form-mode ()
70 "Major mode for editing forms.
71 It is a slightly enhanced emacs-lisp-mode.
73 \\{gnus-edit-form-mode-map}"
75 (when (gnus-visual-p 'group-menu 'menu)
76 (gnus-edit-form-make-menu-bar))
77 (kill-all-local-variables)
78 (setq major-mode 'gnus-edit-form-mode)
79 (setq mode-name "Edit Form")
80 (use-local-map gnus-edit-form-mode-map)
81 (make-local-variable 'gnus-edit-form-done-function)
82 (make-local-variable 'gnus-prev-winconf)
83 (gnus-run-hooks 'gnus-edit-form-mode-hook))
85 (defun gnus-edit-form (form documentation exit-func)
86 "Edit FORM in a new buffer.
87 Call EXIT-FUNC on exit. Display DOCUMENTATION in the beginning
89 (let ((winconf (current-window-configuration)))
90 (set-buffer (get-buffer-create gnus-edit-form-buffer))
91 (gnus-configure-windows 'edit-form)
92 (gnus-add-current-to-buffer-list)
94 (setq gnus-prev-winconf winconf)
95 (setq gnus-edit-form-done-function exit-func)
97 (insert documentation)
100 (goto-char (point-min))
104 (insert ";; Type `C-c C-c' after you've finished editing.\n")
107 (pp form (current-buffer))
111 (defun gnus-edit-form-done ()
112 "Update changes and kill the current buffer."
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."
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