Add arch taglines
[gnus] / lisp / gnus-eform.el
1 ;;; gnus-eform.el --- a mode for editing forms for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
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
52 (defvar gnus-edit-form-buffer "*Gnus edit form*")
53 (defvar gnus-edit-form-done-function nil)
54
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))
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]))
70     (gnus-run-hooks 'gnus-edit-form-menu-hook)))
71
72 (defun gnus-edit-form-mode ()
73   "Major mode for editing forms.
74 It 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)
86   (gnus-run-hooks 'gnus-edit-form-mode-hook))
87
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
91 of the buffer."
92   (let ((winconf (current-window-configuration)))
93     (set-buffer (gnus-get-buffer-create gnus-edit-form-buffer))
94     (gnus-configure-windows 'edit-form)
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 (condition-case nil
118                   (read (current-buffer))
119                 (end-of-file nil)))
120         (func gnus-edit-form-done-function))
121     (gnus-edit-form-exit)
122     (funcall func form)))
123
124 (defun gnus-edit-form-exit ()
125   "Kill the current buffer."
126   (interactive)
127   (let ((winconf gnus-prev-winconf))
128     (kill-buffer (current-buffer))
129     (set-window-configuration winconf)))
130
131 (provide 'gnus-eform)
132
133 ;;; arch-tag: ef50678c-2c28-49ef-affc-e53b3b2c0bf6
134 ;;; gnus-eform.el ends here