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>
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-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
)
64 gnus-edit-form-menu gnus-edit-form-mode-map
""
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}"
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
90 (let ((winconf (current-window-configuration)))
91 (set-buffer (gnus-get-buffer-create gnus-edit-form-buffer
))
92 (gnus-configure-windows 'edit-form
)
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