Fix up comment convention on the arch-tag lines.
[bpt/emacs.git] / lisp / gnus / gnus-eform.el
CommitLineData
eec82323 1;;; gnus-eform.el --- a mode for editing forms for Gnus
e84b4b86
TTN
2
3;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
e3fe4da0 4;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
eec82323 5
6748645f 6;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
eec82323
LMI
7;; Keywords: news
8
9;; This file is part of GNU Emacs.
10
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
5a9dffec 13;; the Free Software Foundation; either version 3, or (at your option)
eec82323
LMI
14;; any later version.
15
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.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs; see the file COPYING. If not, write to the
3a35cf56
LK
23;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24;; Boston, MA 02110-1301, USA.
eec82323
LMI
25
26;;; Commentary:
27
28;;; Code:
29
30(require 'gnus)
31(require 'gnus-win)
32
33;;;
34;;; Editing forms
35;;;
36
37(defgroup gnus-edit-form nil
38 "A mode for editing forms."
39 :group 'gnus)
40
41(defcustom gnus-edit-form-mode-hook nil
42 "Hook run in `gnus-edit-form-mode' buffers."
43 :group 'gnus-edit-form
44 :type 'hook)
45
46(defcustom gnus-edit-form-menu-hook nil
47 "Hook run when creating menus in `gnus-edit-form-mode' buffers."
48 :group 'gnus-edit-form
49 :type 'hook)
50
51;;; Internal variables
52
eec82323 53(defvar gnus-edit-form-buffer "*Gnus edit form*")
6748645f 54(defvar gnus-edit-form-done-function nil)
eec82323
LMI
55
56(defvar gnus-edit-form-mode-map nil)
57(unless gnus-edit-form-mode-map
16409b0b
GM
58 (setq gnus-edit-form-mode-map (make-sparse-keymap))
59 (set-keymap-parent gnus-edit-form-mode-map emacs-lisp-mode-map)
eec82323
LMI
60 (gnus-define-keys gnus-edit-form-mode-map
61 "\C-c\C-c" gnus-edit-form-done
62 "\C-c\C-k" gnus-edit-form-exit))
63
64(defun gnus-edit-form-make-menu-bar ()
65 (unless (boundp 'gnus-edit-form-menu)
66 (easy-menu-define
67 gnus-edit-form-menu gnus-edit-form-mode-map ""
68 '("Edit Form"
69 ["Exit and save changes" gnus-edit-form-done t]
70 ["Exit" gnus-edit-form-exit t]))
6748645f 71 (gnus-run-hooks 'gnus-edit-form-menu-hook)))
eec82323
LMI
72
73(defun gnus-edit-form-mode ()
74 "Major mode for editing forms.
75It is a slightly enhanced emacs-lisp-mode.
76
77\\{gnus-edit-form-mode-map}"
78 (interactive)
79 (when (gnus-visual-p 'group-menu 'menu)
80 (gnus-edit-form-make-menu-bar))
81 (kill-all-local-variables)
82 (setq major-mode 'gnus-edit-form-mode)
83 (setq mode-name "Edit Form")
84 (use-local-map gnus-edit-form-mode-map)
85 (make-local-variable 'gnus-edit-form-done-function)
86 (make-local-variable 'gnus-prev-winconf)
cfcd5c91 87 (gnus-run-mode-hooks 'gnus-edit-form-mode-hook))
eec82323 88
01c52d31 89(defun gnus-edit-form (form documentation exit-func &optional layout)
eec82323
LMI
90 "Edit FORM in a new buffer.
91Call EXIT-FUNC on exit. Display DOCUMENTATION in the beginning
01c52d31
MB
92of the buffer.
93The optional LAYOUT overrides the `edit-form' window layout."
eec82323 94 (let ((winconf (current-window-configuration)))
6748645f 95 (set-buffer (gnus-get-buffer-create gnus-edit-form-buffer))
01c52d31 96 (gnus-configure-windows (or layout 'edit-form))
eec82323
LMI
97 (gnus-edit-form-mode)
98 (setq gnus-prev-winconf winconf)
99 (setq gnus-edit-form-done-function exit-func)
100 (erase-buffer)
101 (insert documentation)
102 (unless (bolp)
103 (insert "\n"))
104 (goto-char (point-min))
105 (while (not (eobp))
106 (insert ";;; ")
107 (forward-line 1))
108 (insert ";; Type `C-c C-c' after you've finished editing.\n")
109 (insert "\n")
110 (let ((p (point)))
23f87bed 111 (gnus-pp form)
eec82323
LMI
112 (insert "\n")
113 (goto-char p))))
114
115(defun gnus-edit-form-done ()
116 "Update changes and kill the current buffer."
117 (interactive)
118 (goto-char (point-min))
23f87bed
MB
119 (let ((form (condition-case nil
120 (read (current-buffer))
121 (end-of-file nil)))
eec82323
LMI
122 (func gnus-edit-form-done-function))
123 (gnus-edit-form-exit)
124 (funcall func form)))
125
126(defun gnus-edit-form-exit ()
127 "Kill the current buffer."
128 (interactive)
129 (let ((winconf gnus-prev-winconf))
130 (kill-buffer (current-buffer))
131 (set-window-configuration winconf)))
132
133(provide 'gnus-eform)
134
cbee283d 135;; arch-tag: ef50678c-2c28-49ef-affc-e53b3b2c0bf6
eec82323 136;;; gnus-eform.el ends here