17493
|
1 ;;; gnus-eform.el --- a mode for editing forms for Gnus
|
|
2 ;; Copyright (C) 1996,97 Free Software Foundation, Inc.
|
|
3
|
|
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
|
|
5 ;; Keywords: news
|
|
6
|
|
7 ;; This file is part of GNU Emacs.
|
|
8
|
|
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
10 ;; it under the terms of the GNU General Public License as published by
|
|
11 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
12 ;; any later version.
|
|
13
|
|
14 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 ;; GNU General Public License for more details.
|
|
18
|
|
19 ;; You should have received a copy of the GNU General Public License
|
|
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 ;; Boston, MA 02111-1307, USA.
|
|
23
|
|
24 ;;; Commentary:
|
|
25
|
|
26 ;;; Code:
|
|
27
|
|
28 (require 'gnus)
|
|
29 (require 'gnus-win)
|
|
30
|
|
31 ;;;
|
|
32 ;;; Editing forms
|
|
33 ;;;
|
|
34
|
|
35 (defgroup gnus-edit-form nil
|
|
36 "A mode for editing forms."
|
|
37 :group 'gnus)
|
|
38
|
|
39 (defcustom gnus-edit-form-mode-hook nil
|
|
40 "Hook run in `gnus-edit-form-mode' buffers."
|
|
41 :group 'gnus-edit-form
|
|
42 :type 'hook)
|
|
43
|
|
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
|
|
47 :type 'hook)
|
|
48
|
|
49 ;;; Internal variables
|
|
50
|
|
51 (defvar gnus-edit-form-done-function nil)
|
|
52 (defvar gnus-edit-form-buffer "*Gnus edit form*")
|
|
53
|
|
54 (defvar gnus-edit-form-mode-map nil)
|
|
55 (unless gnus-edit-form-mode-map
|
|
56 (setq gnus-edit-form-mode-map (copy-keymap emacs-lisp-mode-map))
|
|
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]))
|
|
68 (run-hooks 'gnus-edit-form-menu-hook)))
|
|
69
|
|
70 (defun gnus-edit-form-mode ()
|
|
71 "Major mode for editing forms.
|
|
72 It is a slightly enhanced emacs-lisp-mode.
|
|
73
|
|
74 \\{gnus-edit-form-mode-map}"
|
|
75 (interactive)
|
|
76 (when (gnus-visual-p 'group-menu 'menu)
|
|
77 (gnus-edit-form-make-menu-bar))
|
|
78 (kill-all-local-variables)
|
|
79 (setq major-mode 'gnus-edit-form-mode)
|
|
80 (setq mode-name "Edit Form")
|
|
81 (use-local-map gnus-edit-form-mode-map)
|
|
82 (make-local-variable 'gnus-edit-form-done-function)
|
|
83 (make-local-variable 'gnus-prev-winconf)
|
|
84 (run-hooks 'gnus-edit-form-mode-hook))
|
|
85
|
|
86 (defun gnus-edit-form (form documentation exit-func)
|
|
87 "Edit FORM in a new buffer.
|
|
88 Call EXIT-FUNC on exit. Display DOCUMENTATION in the beginning
|
|
89 of the buffer."
|
|
90 (let ((winconf (current-window-configuration)))
|
|
91 (set-buffer (get-buffer-create gnus-edit-form-buffer))
|
|
92 (gnus-configure-windows 'edit-form)
|
|
93 (gnus-add-current-to-buffer-list)
|
|
94 (gnus-edit-form-mode)
|
|
95 (setq gnus-prev-winconf winconf)
|
|
96 (setq gnus-edit-form-done-function exit-func)
|
|
97 (erase-buffer)
|
|
98 (insert documentation)
|
|
99 (unless (bolp)
|
|
100 (insert "\n"))
|
|
101 (goto-char (point-min))
|
|
102 (while (not (eobp))
|
|
103 (insert ";;; ")
|
|
104 (forward-line 1))
|
|
105 (insert ";; Type `C-c C-c' after you've finished editing.\n")
|
|
106 (insert "\n")
|
|
107 (let ((p (point)))
|
|
108 (pp form (current-buffer))
|
|
109 (insert "\n")
|
|
110 (goto-char p))))
|
|
111
|
|
112 (defun gnus-edit-form-done ()
|
|
113 "Update changes and kill the current buffer."
|
|
114 (interactive)
|
|
115 (goto-char (point-min))
|
|
116 (let ((form (read (current-buffer)))
|
|
117 (func gnus-edit-form-done-function))
|
|
118 (gnus-edit-form-exit)
|
|
119 (funcall func form)))
|
|
120
|
|
121 (defun gnus-edit-form-exit ()
|
|
122 "Kill the current buffer."
|
|
123 (interactive)
|
|
124 (let ((winconf gnus-prev-winconf))
|
|
125 (kill-buffer (current-buffer))
|
|
126 (set-window-configuration winconf)))
|
|
127
|
|
128 (provide 'gnus-eform)
|
|
129
|
|
130 ;;; gnus-eform.el ends here
|