1 ;;; gnus-eform.el --- a mode for editing forms for Gnus
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
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
(make-sparse-keymap))
57 (set-keymap-parent gnus-edit-form-mode-map emacs-lisp-mode-map
)
58 (gnus-define-keys gnus-edit-form-mode-map
59 "\C-c\C-c" gnus-edit-form-done
60 "\C-c\C-k" gnus-edit-form-exit
))
62 (defun gnus-edit-form-make-menu-bar ()
63 (unless (boundp 'gnus-edit-form-menu
)
65 gnus-edit-form-menu gnus-edit-form-mode-map
""
67 ["Exit and save changes" gnus-edit-form-done t
]
68 ["Exit" gnus-edit-form-exit t
]))
69 (gnus-run-hooks 'gnus-edit-form-menu-hook
)))
71 (defun gnus-edit-form-mode ()
72 "Major mode for editing forms.
73 It is a slightly enhanced emacs-lisp-mode.
75 \\{gnus-edit-form-mode-map}"
77 (when (gnus-visual-p 'group-menu
'menu
)
78 (gnus-edit-form-make-menu-bar))
79 (kill-all-local-variables)
80 (setq major-mode
'gnus-edit-form-mode
)
81 (setq mode-name
"Edit Form")
82 (use-local-map gnus-edit-form-mode-map
)
83 (make-local-variable 'gnus-edit-form-done-function
)
84 (make-local-variable 'gnus-prev-winconf
)
85 (gnus-run-mode-hooks 'gnus-edit-form-mode-hook
))
87 (defun gnus-edit-form (form documentation exit-func
&optional layout
)
88 "Edit FORM in a new buffer.
89 Call EXIT-FUNC on exit. Display DOCUMENTATION in the beginning
91 The optional LAYOUT overrides the `edit-form' window layout."
92 (let ((winconf (current-window-configuration)))
93 (set-buffer (gnus-get-buffer-create gnus-edit-form-buffer
))
94 (gnus-configure-windows (or layout
'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")
113 (defun gnus-edit-form-done ()
114 "Update changes and kill the current buffer."
116 (goto-char (point-min))
117 (let ((form (condition-case nil
118 (read (current-buffer))
120 (func gnus-edit-form-done-function
))
121 (gnus-edit-form-exit)
122 (funcall func form
)))
124 (defun gnus-edit-form-exit ()
125 "Kill the current buffer."
127 (let ((winconf gnus-prev-winconf
))
128 (kill-buffer (current-buffer))
129 (set-window-configuration winconf
)))
131 (provide 'gnus-eform
)
133 ;; arch-tag: ef50678c-2c28-49ef-affc-e53b3b2c0bf6
134 ;;; gnus-eform.el ends here