Move lisp/emacs-lisp/authors.el to admin/
[bpt/emacs.git] / lisp / gnus / gnus-eform.el
CommitLineData
eec82323 1;;; gnus-eform.el --- a mode for editing forms for Gnus
e84b4b86 2
ba318903 3;; Copyright (C) 1996-2014 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
5e809f55 10;; GNU Emacs is free software: you can redistribute it and/or modify
eec82323 11;; it under the terms of the GNU General Public License as published by
5e809f55
GM
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
eec82323
LMI
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
5e809f55 17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
eec82323
LMI
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
5e809f55 21;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
eec82323
LMI
22
23;;; Commentary:
24
25;;; Code:
26
27(require 'gnus)
28(require 'gnus-win)
29
30;;;
31;;; Editing forms
32;;;
33
34(defgroup gnus-edit-form nil
35 "A mode for editing forms."
36 :group 'gnus)
37
38(defcustom gnus-edit-form-mode-hook nil
39 "Hook run in `gnus-edit-form-mode' buffers."
40 :group 'gnus-edit-form
41 :type 'hook)
42
43(defcustom gnus-edit-form-menu-hook nil
44 "Hook run when creating menus in `gnus-edit-form-mode' buffers."
45 :group 'gnus-edit-form
46 :type 'hook)
47
48;;; Internal variables
49
eec82323 50(defvar gnus-edit-form-buffer "*Gnus edit form*")
6748645f 51(defvar gnus-edit-form-done-function nil)
eec82323
LMI
52
53(defvar gnus-edit-form-mode-map nil)
54(unless gnus-edit-form-mode-map
16409b0b
GM
55 (setq gnus-edit-form-mode-map (make-sparse-keymap))
56 (set-keymap-parent gnus-edit-form-mode-map emacs-lisp-mode-map)
eec82323
LMI
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))
60
61(defun gnus-edit-form-make-menu-bar ()
62 (unless (boundp 'gnus-edit-form-menu)
63 (easy-menu-define
64 gnus-edit-form-menu gnus-edit-form-mode-map ""
65 '("Edit Form"
66 ["Exit and save changes" gnus-edit-form-done t]
67 ["Exit" gnus-edit-form-exit t]))
6748645f 68 (gnus-run-hooks 'gnus-edit-form-menu-hook)))
eec82323 69
c2e9e9ef 70(define-derived-mode gnus-edit-form-mode fundamental-mode "Edit Form"
eec82323
LMI
71 "Major mode for editing forms.
72It is a slightly enhanced emacs-lisp-mode.
73
74\\{gnus-edit-form-mode-map}"
eec82323
LMI
75 (when (gnus-visual-p 'group-menu 'menu)
76 (gnus-edit-form-make-menu-bar))
eec82323 77 (make-local-variable 'gnus-edit-form-done-function)
c2e9e9ef 78 (make-local-variable 'gnus-prev-winconf))
eec82323 79
01c52d31 80(defun gnus-edit-form (form documentation exit-func &optional layout)
eec82323
LMI
81 "Edit FORM in a new buffer.
82Call EXIT-FUNC on exit. Display DOCUMENTATION in the beginning
01c52d31
MB
83of the buffer.
84The optional LAYOUT overrides the `edit-form' window layout."
eec82323 85 (let ((winconf (current-window-configuration)))
6748645f 86 (set-buffer (gnus-get-buffer-create gnus-edit-form-buffer))
01c52d31 87 (gnus-configure-windows (or layout 'edit-form))
eec82323
LMI
88 (gnus-edit-form-mode)
89 (setq gnus-prev-winconf winconf)
90 (setq gnus-edit-form-done-function exit-func)
91 (erase-buffer)
92 (insert documentation)
93 (unless (bolp)
94 (insert "\n"))
95 (goto-char (point-min))
96 (while (not (eobp))
97 (insert ";;; ")
98 (forward-line 1))
99 (insert ";; Type `C-c C-c' after you've finished editing.\n")
100 (insert "\n")
101 (let ((p (point)))
23f87bed 102 (gnus-pp form)
eec82323
LMI
103 (insert "\n")
104 (goto-char p))))
105
106(defun gnus-edit-form-done ()
107 "Update changes and kill the current buffer."
108 (interactive)
109 (goto-char (point-min))
23f87bed
MB
110 (let ((form (condition-case nil
111 (read (current-buffer))
112 (end-of-file nil)))
eec82323
LMI
113 (func gnus-edit-form-done-function))
114 (gnus-edit-form-exit)
115 (funcall func form)))
116
117(defun gnus-edit-form-exit ()
118 "Kill the current buffer."
119 (interactive)
120 (let ((winconf gnus-prev-winconf))
121 (kill-buffer (current-buffer))
122 (set-window-configuration winconf)))
123
124(provide 'gnus-eform)
125
126;;; gnus-eform.el ends here