1 ;;; gnus-eform.el --- a mode for editing forms for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
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 2, or (at your option)
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; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
36 (defgroup gnus-edit-form nil
37 "A mode for editing forms."
40 (defcustom gnus-edit-form-mode-hook nil
41 "Hook run in `gnus-edit-form-mode' buffers."
42 :group
'gnus-edit-form
45 (defcustom gnus-edit-form-menu-hook nil
46 "Hook run when creating menus in `gnus-edit-form-mode' buffers."
47 :group
'gnus-edit-form
50 ;;; Internal variables
52 (defvar gnus-edit-form-buffer
"*Gnus edit form*")
53 (defvar gnus-edit-form-done-function nil
)
55 (defvar gnus-edit-form-mode-map nil
)
56 (unless gnus-edit-form-mode-map
57 (setq gnus-edit-form-mode-map
(make-sparse-keymap))
58 (set-keymap-parent gnus-edit-form-mode-map emacs-lisp-mode-map
)
59 (gnus-define-keys gnus-edit-form-mode-map
60 "\C-c\C-c" gnus-edit-form-done
61 "\C-c\C-k" gnus-edit-form-exit
))
63 (defun gnus-edit-form-make-menu-bar ()
64 (unless (boundp 'gnus-edit-form-menu
)
66 gnus-edit-form-menu gnus-edit-form-mode-map
""
68 ["Exit and save changes" gnus-edit-form-done t
]
69 ["Exit" gnus-edit-form-exit t
]))
70 (gnus-run-hooks 'gnus-edit-form-menu-hook
)))
72 (defun gnus-edit-form-mode ()
73 "Major mode for editing forms.
74 It is a slightly enhanced emacs-lisp-mode.
76 \\{gnus-edit-form-mode-map}"
78 (when (gnus-visual-p 'group-menu
'menu
)
79 (gnus-edit-form-make-menu-bar))
80 (kill-all-local-variables)
81 (setq major-mode
'gnus-edit-form-mode
)
82 (setq mode-name
"Edit Form")
83 (use-local-map gnus-edit-form-mode-map
)
84 (make-local-variable 'gnus-edit-form-done-function
)
85 (make-local-variable 'gnus-prev-winconf
)
86 (gnus-run-hooks 'gnus-edit-form-mode-hook
))
88 (defun gnus-edit-form (form documentation exit-func
)
89 "Edit FORM in a new buffer.
90 Call EXIT-FUNC on exit. Display DOCUMENTATION in the beginning
92 (let ((winconf (current-window-configuration)))
93 (set-buffer (gnus-get-buffer-create gnus-edit-form-buffer
))
94 (gnus-configure-windows 'edit-form
)
96 (setq gnus-prev-winconf winconf
)
97 (setq gnus-edit-form-done-function exit-func
)
99 (insert documentation
)
102 (goto-char (point-min))
106 (insert ";; Type `C-c C-c' after you've finished editing.\n")
109 (pp form
(current-buffer))
113 (defun gnus-edit-form-done ()
114 "Update changes and kill the current buffer."
116 (goto-char (point-min))
117 (let ((form (read (current-buffer)))
118 (func gnus-edit-form-done-function
))
119 (gnus-edit-form-exit)
120 (funcall func form
)))
122 (defun gnus-edit-form-exit ()
123 "Kill the current buffer."
125 (let ((winconf gnus-prev-winconf
))
126 (kill-buffer (current-buffer))
127 (set-window-configuration winconf
)))
129 (provide 'gnus-eform
)
131 ;;; gnus-eform.el ends here