Add arch taglines
[bpt/emacs.git] / lisp / gnus / gnus-eform.el
CommitLineData
eec82323 1;;; gnus-eform.el --- a mode for editing forms for Gnus
16409b0b
GM
2;; Copyright (C) 1996, 1997, 1998, 1999, 2000
3;; Free Software Foundation, Inc.
eec82323 4
6748645f 5;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
eec82323
LMI
6;; Keywords: news
7
8;; This file is part of GNU Emacs.
9
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)
13;; any later version.
14
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.
19
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.
24
25;;; Commentary:
26
27;;; Code:
28
29(require 'gnus)
30(require 'gnus-win)
31
32;;;
33;;; Editing forms
34;;;
35
36(defgroup gnus-edit-form nil
37 "A mode for editing forms."
38 :group 'gnus)
39
40(defcustom gnus-edit-form-mode-hook nil
41 "Hook run in `gnus-edit-form-mode' buffers."
42 :group 'gnus-edit-form
43 :type 'hook)
44
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
48 :type 'hook)
49
50;;; Internal variables
51
eec82323 52(defvar gnus-edit-form-buffer "*Gnus edit form*")
6748645f 53(defvar gnus-edit-form-done-function nil)
eec82323
LMI
54
55(defvar gnus-edit-form-mode-map nil)
56(unless gnus-edit-form-mode-map
16409b0b
GM
57 (setq gnus-edit-form-mode-map (make-sparse-keymap))
58 (set-keymap-parent gnus-edit-form-mode-map emacs-lisp-mode-map)
eec82323
LMI
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))
62
63(defun gnus-edit-form-make-menu-bar ()
64 (unless (boundp 'gnus-edit-form-menu)
65 (easy-menu-define
66 gnus-edit-form-menu gnus-edit-form-mode-map ""
67 '("Edit Form"
68 ["Exit and save changes" gnus-edit-form-done t]
69 ["Exit" gnus-edit-form-exit t]))
6748645f 70 (gnus-run-hooks 'gnus-edit-form-menu-hook)))
eec82323
LMI
71
72(defun gnus-edit-form-mode ()
73 "Major mode for editing forms.
74It is a slightly enhanced emacs-lisp-mode.
75
76\\{gnus-edit-form-mode-map}"
77 (interactive)
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)
6748645f 86 (gnus-run-hooks 'gnus-edit-form-mode-hook))
eec82323
LMI
87
88(defun gnus-edit-form (form documentation exit-func)
89 "Edit FORM in a new buffer.
90Call EXIT-FUNC on exit. Display DOCUMENTATION in the beginning
91of the buffer."
92 (let ((winconf (current-window-configuration)))
6748645f 93 (set-buffer (gnus-get-buffer-create gnus-edit-form-buffer))
eec82323 94 (gnus-configure-windows 'edit-form)
eec82323
LMI
95 (gnus-edit-form-mode)
96 (setq gnus-prev-winconf winconf)
97 (setq gnus-edit-form-done-function exit-func)
98 (erase-buffer)
99 (insert documentation)
100 (unless (bolp)
101 (insert "\n"))
102 (goto-char (point-min))
103 (while (not (eobp))
104 (insert ";;; ")
105 (forward-line 1))
106 (insert ";; Type `C-c C-c' after you've finished editing.\n")
107 (insert "\n")
108 (let ((p (point)))
109 (pp form (current-buffer))
110 (insert "\n")
111 (goto-char p))))
112
113(defun gnus-edit-form-done ()
114 "Update changes and kill the current buffer."
115 (interactive)
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)))
121
122(defun gnus-edit-form-exit ()
123 "Kill the current buffer."
124 (interactive)
125 (let ((winconf gnus-prev-winconf))
126 (kill-buffer (current-buffer))
127 (set-window-configuration winconf)))
128
129(provide 'gnus-eform)
130
ab5796a9 131;;; arch-tag: ef50678c-2c28-49ef-affc-e53b3b2c0bf6
eec82323 132;;; gnus-eform.el ends here