annotate lisp/gnats/send-pr.el @ 112:48d667d6f17f r20-1b8

Import from CVS: tag r20-1b8
author cvs
date Mon, 13 Aug 2007 09:20:48 +0200
parents fe104dbd9147
children 7d55a9ba150c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
1 ;;;; -*-emacs-lisp-*-
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
2 ;;;;---------------------------------------------------------------------------
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
3 ;;;; EMACS interface for send-pr (by Heinz G. Seidl, hgs@cygnus.com)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
4 ;;;; Slightly hacked by Brendan Kehoe (brendan@cygnus.com).
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
5 ;;;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
6 ;;;; This file is part of the Problem Report Management System (GNATS)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
7 ;;;; Copyright 1992, 1993 Cygnus Support
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
8 ;;;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
9 ;;;; This program is free software; you can redistribute it and/or
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
10 ;;;; modify it under the terms of the GNU General Public
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
11 ;;;; License as published by the Free Software Foundation; either
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
12 ;;;; version 2 of the License, or (at your option) any later version.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
13 ;;;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
14 ;;;; This program is distributed in the hope that it will be useful,
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
15 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
16 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
17 ;;;; General Public License for more details.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
18 ;;;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
19 ;;;; You should have received a copy of the GNU Library General Public
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
20 ;;;; License along with this program; if not, write to the Free
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
21 ;;;; Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
22 ;;;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
23 ;;;;---------------------------------------------------------------------------
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
24 ;;;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
25 ;;;; This file contains the EMACS interface to the Problem Report Management
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
26 ;;;; System (GNATS):
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
27 ;;;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
28 ;;;; - The `send-pr' command and the `send-pr-mode' for sending
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
29 ;;;; Problem Reports (PRs).
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
30 ;;;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
31 ;;;; For more information about how to send a PR see send-pr(1).
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
32 ;;;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
33 ;;;;---------------------------------------------------------------------------
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
34 ;;;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
35 ;;;; Configuration: the symbol `DEFAULT-RELEASE' can be replaced by
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
36 ;;;; site/release specific strings during the configuration/installation
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
37 ;;;; process.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
38 ;;;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
39 ;;;; Install this file in your EMACS library directory.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
40 ;;;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
41 ;;;;---------------------------------------------------------------------------
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
42
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
43 (provide 'send-pr)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
44
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
45 ;;;;---------------------------------------------------------------------------
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
46 ;;;; Customization: put the following forms into your default.el file
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
47 ;;;; (or into your .emacs)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
48 ;;;;---------------------------------------------------------------------------
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
49
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
50 ;(autoload 'send-pr-mode "send-pr"
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
51 ; "Major mode for sending problem reports." t)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
52
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
53 ;(autoload 'send-pr "send-pr"
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
54 ; "Command to create and send a problem report." t)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
55
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
56 ;;;;---------------------------------------------------------------------------
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
57 ;;;; End of Customization Section
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
58 ;;;;---------------------------------------------------------------------------
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
59
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
60 (autoload 'server-buffer-done "server")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
61 (defvar server-buffer-clients nil)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
62 (defvar mail-self-blind nil)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
63 (defvar mail-default-reply-to nil)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
64
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
65 (defconst send-pr::version "3.101")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
66
112
48d667d6f17f Import from CVS: tag r20-1b8
cvs
parents: 110
diff changeset
67 (defvar gnats:root "/usr/lib/gnats/gnats-db"
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
68 "*The top of the tree containing the GNATS database.")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
69
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
70 ;;;;---------------------------------------------------------------------------
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
71 ;;;; hooks
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
72 ;;;;---------------------------------------------------------------------------
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
73
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
74 (defvar text-mode-hook nil) ; we define it here in case it's not defined
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
75 (defvar send-pr-mode-hook text-mode-hook "Called when send-pr is invoked.")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
76
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
77 ;;;;---------------------------------------------------------------------------
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
78 ;;;; Domains and default values for (some of) the Problem Report fields;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
79 ;;;; constants and definitions.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
80 ;;;;---------------------------------------------------------------------------
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
81
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
82 (defconst gnats::emacs-19p
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
83 (not (or (and (boundp 'epoch::version) epoch::version)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
84 (string-lessp emacs-version "19")))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
85 "Is this emacs v19?")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
86
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
87 ;;; This has to be here rather than at the bottom of this file with
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
88 ;;; the other utility functions because it is used by
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
89 ;;; gnats::get-config, which is called when send-pr.el is being
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
90 ;;; loaded (see the "defconst" below), before the whole file has been
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
91 ;;; loaded.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
92
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
93 (defun gnats::find-safe-default-directory (&optional buffer)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
94 "If the directory referred to by `default-directory' for the current
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
95 buffer (or for optional argument BUFFER) does not exist, set it to the home
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
96 directory of the current user if that exists, or to `/'.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
97
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
98 Returns the final value of default-directory in the buffer."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
99 (let ((homedir (expand-file-name "~/")))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
100 (save-excursion
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
101 (if buffer (set-buffer buffer))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
102 (if (not (file-exists-p default-directory))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
103 (if (file-exists-p homedir)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
104 (setq default-directory homedir)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
105 (setq default-directory "/")))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
106 default-directory)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
107
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
108 ;;; These may be changed during configuration/installation or by the individual
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
109 ;;; user in his/her .emacs file.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
110 ;;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
111 (defun gnats::get-config (var)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
112 (let ((shell-file-name "/bin/sh")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
113 (buf (generate-new-buffer " *GNATS config*"))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
114 ret)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
115 (save-excursion
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
116 (set-buffer buf)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
117 (shell-command-on-region
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
118 (point-min) (point-max)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
119 (concat ". " gnats:root "/gnats-adm/config; echo $" var ) t)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
120 (goto-char (point-min))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
121 ; We have to use get-buffer, since shell-command-on-region will wipe
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
122 ; out the buffer if there's no output from the command.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
123 (if (or (not (get-buffer "*Shell Command Output*"))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
124 (looking-at "/bin/sh:\\|\.:\\|\n"))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
125 (setq ret nil)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
126 (setq ret (buffer-substring (point-min) (- (point-max) 1)))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
127 (if (and ret (string-equal ret "")) (setq ret nil))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
128 (kill-buffer buf)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
129 ret))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
130
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
131 ;; const because it must match the script's value
112
48d667d6f17f Import from CVS: tag r20-1b8
cvs
parents: 110
diff changeset
132 (defconst send-pr:datadir (or (gnats::get-config "DATADIR") "/usr/share")
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
133 "*Where the `gnats' subdirectory containing category lists lives.")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
134
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
135 (defvar send-pr::sites nil
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
136 "List of GNATS support sites; computed at runtime.")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
137 (defvar send-pr:default-site
112
48d667d6f17f Import from CVS: tag r20-1b8
cvs
parents: 110
diff changeset
138 (or (gnats::get-config "GNATS_SITE") "altair.xemacs.org")
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
139 "Default site to send bugs to.")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
140 (defvar send-pr:::site send-pr:default-site
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
141 "The site to which a problem report is currently being submitted, or NIL
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
142 if using the default site (buffer local).")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
143
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
144 (defvar send-pr:::categories nil
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
145 "Buffer local list of available categories, derived at runtime from
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
146 send-pr:::site and send-pr::category-alist.")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
147 (defvar send-pr::category-alist nil
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
148 "Alist of GNATS support sites and the categories supported at each; computed
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
149 at runtime.")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
150
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
151 ;;; Ideally we would get all the following values from a central database
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
152 ;;; during runtime instead of having them here in the code.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
153 ;;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
154 (defconst send-pr::fields
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
155 (` (("Category" send-pr::set-categories
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
156 (, (or (gnats::get-config "DEFAULT_CATEGORY") nil)) enum)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
157 ("Class" (("sw-bug") ("doc-bug") ("change-request") ("support"))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
158 (, (or (gnats::get-config "DEFAULT_CLASS") 0)) enum)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
159 ("Confidential" (("yes") ("no"))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
160 (, (or (gnats::get-config "DEFAULT_CONFIDENTIAL") 1)) enum)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
161 ("Severity" (("non-critical") ("serious") ("critical"))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
162 (, (or (gnats::get-config "DEFAULT_SEVERITY") 1)) enum)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
163 ("Priority" (("low") ("medium") ("high"))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
164 (, (or (gnats::get-config "DEFAULT_PRIORITY") 1)) enum)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
165 ("Release" nil
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
166 (, (or (gnats::get-config "DEFAULT_RELEASE") "gnats-3.101"))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
167 text)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
168 ("Submitter-Id" nil
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
169 (, (or (gnats::get-config "SUBMITTER") "xSUBMITTERx")) text)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
170 ("Synopsis" nil nil text
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
171 (lambda (a b c) (gnats::set-mail-field "Subject" c)))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
172 "AList, keyed on the name of the field, of:
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
173 1) The field name.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
174 2) The list of completions. This can be a list, a function to call, or nil.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
175 3) The default value.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
176 4) The type of the field.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
177 5) A sub-function to call when changed.")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
178
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
179 (defvar gnats::fields nil)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
180
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
181 (defmacro gnats::push (i l)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
182 (` (setq (, l) (cons (,@ (list i l))))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
183
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
184 (defun send-pr::set-categories (&optional arg)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
185 "Get the list of categories for the current site out of
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
186 send-pr::category-alist if there or from send-pr if not. With arg, force
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
187 update."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
188 ;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
189 (let ((entry (assoc send-pr:::site send-pr::category-alist)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
190 (or (and entry (null arg))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
191 (let ((oldpr (getenv "GNATS_ROOT")) cats)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
192 (send-pr::set-sites arg)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
193 (setenv "GNATS_ROOT" gnats:root)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
194 (setq cats (gnats::get-value-from-shell
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
195 "send-pr" "-CL" send-pr:::site))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
196 (setenv "GNATS_ROOT" oldpr)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
197 (if entry (setcdr entry cats)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
198 (setq entry (cons send-pr:::site cats))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
199 (gnats::push entry send-pr::category-alist))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
200 (setq send-pr:::categories (cdr entry))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
201
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
202 (defun send-pr::set-sites (&optional arg)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
203 "Get the list of sites (by listing the contents of DATADIR/gnats) and assign
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
204 it to send-pr::sites. With arg, force update."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
205 (or (and (null arg) send-pr::sites)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
206 (progn
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
207 (setq send-pr::sites nil)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
208 (mapcar
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
209 (function
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
210 (lambda (file)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
211 (or (memq t (mapcar (function (lambda (x) (string= x file)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
212 '("." ".." "pr-edit" "pr-addr")))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
213 (not (file-readable-p file))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
214 (gnats::push (list (file-name-nondirectory file))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
215 send-pr::sites))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
216 (directory-files (format "%s/gnats" send-pr:datadir) t))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
217 (setq send-pr::sites (reverse send-pr::sites)))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
218
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
219 (defconst send-pr::pr-buffer-name "*send-pr*"
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
220 "Name of the temporary buffer, where the problem report gets composed.")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
221
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
222 (defconst send-pr::err-buffer-name "*send-pr-error*"
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
223 "Name of the temporary buffer, where send-pr error messages appear.")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
224
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
225 (defvar send-pr:::err-buffer nil
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
226 "The error buffer used by the current PR buffer.")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
227
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
228 (defvar send-pr:::spawn-to-send nil
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
229 "Whether or not send-pr-mode should spawn a send-pr process to send the PR.")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
230
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
231 (defconst gnats::indent 17 "Indent for formatting the value.")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
232
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
233 ;;;;---------------------------------------------------------------------------
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
234 ;;;; `send-pr' - command for creating and sending of problem reports
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
235 ;;;;---------------------------------------------------------------------------
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
236
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
237 ;;;###autoload
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
238 (fset 'send-pr 'send-pr:send-pr)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
239 ;;;###autoload
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
240 (defun send-pr:send-pr (&optional site)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
241 "Create a buffer and read in the result of `send-pr -P'.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
242 When finished with editing the problem report use \\[send-pr:submit-pr]
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
243 to send the PR with `send-pr -b -f -'."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
244 ;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
245 (interactive
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
246 (if current-prefix-arg
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
247 (list (completing-read "Site: " (send-pr::set-sites 'recheck) nil t
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
248 send-pr:default-site))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
249 (or site (setq site send-pr:default-site))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
250 (let ((buf (get-buffer send-pr::pr-buffer-name)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
251 (if (or (not buf)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
252 (progn (switch-to-buffer buf)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
253 (cond ((or (not (buffer-modified-p buf))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
254 (y-or-n-p "Erase previous problem report? "))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
255 (erase-buffer) t)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
256 (t nil))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
257 (send-pr::start-up site))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
258
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
259 (defun send-pr::start-up (site)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
260 (switch-to-buffer (get-buffer-create send-pr::pr-buffer-name))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
261 (setq default-directory (expand-file-name "~/"))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
262 (auto-save-mode auto-save-default)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
263 (let ((oldpr (getenv "GNATS_ROOT"))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
264 (case-fold-search nil))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
265 (setenv "GNATS_ROOT" gnats:root)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
266 (send-pr::insert-template site)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
267 (setenv "GNATS_ROOT" oldpr)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
268 (goto-char (point-min))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
269 (if (looking-at "send-pr:")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
270 (cond ((looking-at "send-pr: .* does not have a categories list")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
271 (setq send-pr::sites nil)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
272 (error "send-pr: the GNATS site %s does not have a categories list" site))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
273 (t (error (buffer-substring (point-min) (point-max)))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
274 (save-excursion
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
275 ;; Clear cruft inserted by bdamaged .cshrcs
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
276 (goto-char 1)
112
48d667d6f17f Import from CVS: tag r20-1b8
cvs
parents: 110
diff changeset
277 ;; XEmacs change
48d667d6f17f Import from CVS: tag r20-1b8
cvs
parents: 110
diff changeset
278 (when (re-search-forward "^SEND-PR:" nil t)
48d667d6f17f Import from CVS: tag r20-1b8
cvs
parents: 110
diff changeset
279 (delete-region 1 (match-beginning 0))))))
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
280 (set-buffer-modified-p nil)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
281 (send-pr:send-pr-mode)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
282 (setq send-pr:::site site)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
283 (setq send-pr:::spawn-to-send t)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
284 (send-pr::set-categories)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
285 (if (null send-pr:::categories)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
286 (progn
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
287 (and send-pr:::err-buffer (kill-buffer send-pr:::err-buffer))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
288 (kill-buffer nil)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
289 (message "send-pr: no categories found"))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
290 (or (stringp mail-default-reply-to)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
291 (setq mail-default-reply-to (getenv "REPLYTO")))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
292 (and mail-default-reply-to
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
293 (gnats::set-mail-field "Reply-To" mail-default-reply-to))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
294 (and mail-self-blind
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
295 (gnats::set-mail-field "BCC" (user-login-name)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
296 (mapcar 'send-pr::maybe-change-field send-pr::fields)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
297 (gnats::position-on-field "Description")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
298 (message (substitute-command-keys
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
299 "To send the problem report use: \\[send-pr:submit-pr]"))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
300
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
301 (defvar send-pr::template-alist nil
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
302 "An alist containing the output of send-pr -P <sitename> for various sites.")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
303
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
304 (defun send-pr::insert-template (site)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
305 (let ((elt (assoc site send-pr::template-alist)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
306 (if elt
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
307 (save-excursion (insert (cdr elt)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
308 (call-process "send-pr" nil t nil "-P" site)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
309 (save-excursion
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
310 (setq send-pr::template-alist
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
311 (cons (cons site (buffer-substring (point-min) (point-max)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
312 send-pr::template-alist))))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
313
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
314 (fset 'do-send-pr 'send-pr:submit-pr) ;backward compat
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
315 (defun send-pr:submit-pr ()
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
316 "Pipe the contents of the buffer *send-pr* to `send-pr -f -.' unless this
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
317 buffer was loaded with emacsclient, in which case save the buffer and exit."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
318 ;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
319 (interactive)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
320 (cond
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
321 ((and (boundp 'server-buffer-clients)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
322 server-buffer-clients)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
323 (let ((buffer (current-buffer))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
324 (version-control nil) (buffer-backed-up nil))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
325 (save-buffer buffer)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
326 (kill-buffer buffer)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
327 (server-buffer-done buffer)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
328 (send-pr:::spawn-to-send
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
329 (or (and send-pr:::err-buffer
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
330 (buffer-name send-pr:::err-buffer))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
331 (setq send-pr:::err-buffer
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
332 (get-buffer-create send-pr::err-buffer-name)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
333 (let ((err-buffer send-pr:::err-buffer) mesg ok)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
334 (save-excursion (set-buffer err-buffer) (erase-buffer))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
335 (message "running send-pr...")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
336 (let ((oldpr (getenv "GNATS_ROOT")))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
337 (setenv "GNATS_ROOT" gnats:root)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
338 (call-process-region (point-min) (point-max) "send-pr"
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
339 nil err-buffer nil send-pr:::site
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
340 "-b" "-f" "-")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
341 (setenv "GNATS_ROOT" oldpr))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
342 (message "running send-pr...done")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
343 ;; stupidly we cannot check the return value in EMACS 18.57, thus we need
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
344 ;; this kluge to find out whether send-pr succeeded.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
345 (if (save-excursion
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
346 (set-buffer err-buffer)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
347 (goto-char (point-min))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
348 (setq mesg (buffer-substring (point-min) (- (point-max) 1)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
349 (search-forward "problem report sent" nil t))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
350 (progn (message mesg)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
351 (kill-buffer err-buffer)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
352 (delete-auto-save-file-if-necessary)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
353 (set-buffer-modified-p nil)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
354 (bury-buffer))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
355 (pop-to-buffer err-buffer))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
356 ))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
357 (t
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
358 (save-buffer)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
359 (message "Exit emacs to send the PR."))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
360
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
361 ;;;;---------------------------------------------------------------------------
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
362 ;;;; send-pr:send-pr-mode mode
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
363 ;;;;---------------------------------------------------------------------------
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
364
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
365 (defvar send-pr-mode-map
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
366 (let ((map (make-sparse-keymap)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
367 (define-key map "\C-c\C-c" 'send-pr:submit-pr)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
368 (define-key map "\C-c\C-f" 'gnats:change-field)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
369 (define-key map "\M-n" 'gnats:next-field)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
370 (define-key map "\M-p" 'gnats:previous-field)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
371 (define-key map "\C-\M-f" 'gnats:forward-field)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
372 (define-key map "\C-\M-b" 'gnats:backward-field)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
373 map)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
374 "Keymap for send-pr mode.")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
375
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
376 (defconst gnats::keyword "^>\\([-a-zA-Z]+\\):")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
377 (defconst gnats::before-keyword "[ \t\n\f]*[\n\f]+>\\([-a-zA-Z]+\\):")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
378 (defconst gnats::after-keyword "^>\\([-a-zA-Z]+\\):[ \t\n\f]+")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
379
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
380 ;;;###autoload
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
381 (fset 'send-pr-mode 'send-pr:send-pr-mode)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
382 ;;;###autoload
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
383 (defun send-pr:send-pr-mode ()
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
384 "Major mode for submitting problem reports.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
385 For information about the form see gnats(1) and send-pr(1).
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
386 Special commands: \\{send-pr-mode-map}
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
387 Turning on send-pr-mode calls the value of the variable send-pr-mode-hook,
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
388 if it is not nil."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
389 (interactive)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
390 (gnats::patch-exec-path)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
391 (put 'send-pr:send-pr-mode 'mode-class 'special)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
392 (kill-all-local-variables)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
393 (setq major-mode 'send-pr:send-pr-mode)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
394 (setq mode-name "send-pr")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
395 (use-local-map send-pr-mode-map)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
396 (set-syntax-table text-mode-syntax-table)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
397 (setq local-abbrev-table text-mode-abbrev-table)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
398 (setq buffer-offer-save t)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
399 (make-local-variable 'send-pr:::site)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
400 (make-local-variable 'send-pr:::categories)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
401 (make-local-variable 'send-pr:::err-buffer)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
402 (make-local-variable 'send-pr:::spawn-to-send)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
403 (make-local-variable 'paragraph-separate)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
404 (setq paragraph-separate (concat (default-value 'paragraph-separate)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
405 "\\|" gnats::keyword "[ \t\n\f]*$"))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
406 (make-local-variable 'paragraph-start)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
407 (setq paragraph-start (concat (default-value 'paragraph-start)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
408 "\\|" gnats::keyword))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
409 (run-hooks 'send-pr-mode-hook)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
410 t)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
411
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
412 ;;;;---------------------------------------------------------------------------
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
413 ;;;; Functions to read and replace field values.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
414 ;;;;---------------------------------------------------------------------------
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
415
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
416 (defun gnats::position-on-field (field &optional quiet)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
417 (goto-char (point-min))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
418 (if (not (re-search-forward (concat "^>" field ":") nil t))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
419 (if quiet
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
420 nil
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
421 (error "Field `>%s:' not found." field))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
422 (re-search-forward "[ \t\n\f]*")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
423 (if (looking-at gnats::keyword)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
424 (backward-char 1))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
425 t))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
426
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
427 (defun gnats::mail-position-on-field (field)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
428 (let (end
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
429 (case-fold-search t))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
430 (goto-char (point-min))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
431 (re-search-forward "^$")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
432 (setq end (match-beginning 0))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
433 (goto-char (point-min))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
434 (if (not (re-search-forward (concat "^" field ":") end 'go-to-end))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
435 (insert field ": \n")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
436 (re-search-forward "[ \t\n\f]*"))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
437 (skip-chars-backward "\n")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
438 t))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
439
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
440 (defun gnats::field-contents (field &optional elem move)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
441 (let (pos)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
442 (unwind-protect
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
443 (save-excursion
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
444 (if (not (gnats::position-on-field field t))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
445 nil
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
446 (setq pos (point-marker))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
447 (if (or (looking-at "<.*>$") (eolp))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
448 t
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
449 (looking-at ".*$") ; to set match-{beginning,end}
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
450 (gnats::nth-word
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
451 (buffer-substring (match-beginning 0) (match-end 0))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
452 elem))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
453 (and move pos (goto-char pos)))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
454
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
455 (defun gnats::functionp (thing)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
456 (or (and (symbolp thing) (fboundp thing))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
457 (and (listp thing) (eq (car thing) 'lambda))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
458
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
459 (defun gnats::field-values (field)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
460 "Return the possible (known) values for field FIELD."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
461 (let* ((fields (if (eq major-mode 'gnats:gnats-mode) gnats::fields
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
462 send-pr::fields))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
463 (thing (elt (assoc field fields) 1)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
464 (cond ((gnats::functionp thing) (funcall thing))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
465 ((listp thing) thing)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
466 (t (error "ACK")))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
467
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
468 (defun gnats::field-default (field)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
469 "Return the default value for field FIELD."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
470 (let* ((fields (if (eq major-mode 'gnats:gnats-mode) gnats::fields
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
471 send-pr::fields))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
472 (thing (elt (assoc field fields) 2)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
473 (cond ((stringp thing) thing)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
474 ((null thing) "")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
475 ((numberp thing) (car (elt (gnats::field-values field) thing)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
476 ((gnats::functionp thing)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
477 (funcall thing (gnats::field-contents field)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
478 ((eq thing t) (gnats::field-contents field))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
479 (t (error "ACK")))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
480
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
481 (defun gnats::field-type (field)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
482 "Return the type of field FIELD."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
483 (let* ((fields (if (eq major-mode 'gnats:gnats-mode) gnats::fields
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
484 send-pr::fields))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
485 (thing (elt (assoc field fields) 3)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
486 thing))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
487
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
488 (defun gnats::field-action (field)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
489 "Return the extra handling function for field FIELD."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
490 (let* ((fields (if (eq major-mode 'gnats:gnats-mode) gnats::fields
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
491 send-pr::fields))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
492 (thing (elt (assoc field fields) 4)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
493 (cond ((null thing) 'ignore)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
494 ((gnats::functionp thing) thing)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
495 (t (error "ACK")))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
496
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
497 ;;;;---------------------------------------------------------------------------
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
498 ;;;; Point movement functions
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
499 ;;;;---------------------------------------------------------------------------
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
500
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
501 (or (fboundp 'defsubst) (fset 'defsubst 'defun))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
502
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
503 (defun send-pr::maybe-change-field (field)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
504 (setq field (car field))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
505 (let ((thing (gnats::field-contents field)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
506 (and thing (eq t thing)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
507 (not (eq 'multi-text (gnats::field-type field)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
508 (gnats:change-field field))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
509
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
510 (defun gnats:change-field (&optional field default)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
511 "Change the value of the field containing the cursor. With arg, ask the
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
512 user for the field to change. From a program, the function takes optional
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
513 arguments of the field to change and the default value to use."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
514 (interactive)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
515 (or field current-prefix-arg (setq field (gnats::current-field)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
516 (or field
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
517 (setq field
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
518 (completing-read "Field: "
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
519 (if (eq major-mode 'gnats:gnats-mode)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
520 gnats::fields
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
521 send-pr::fields)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
522 nil t)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
523 (gnats::position-on-field field)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
524 (sit-for 0)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
525 (let* ((old (gnats::field-contents field))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
526 new)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
527 (if (null old)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
528 (error "ACK")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
529 (if (or (interactive-p) t)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
530 (let ((prompt (concat ">" field ": "))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
531 (domain (gnats::field-values field))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
532 (type (gnats::field-type field)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
533 (or default (setq default (gnats::field-default field)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
534 (setq new
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
535 (if (eq type 'enum)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
536 (completing-read prompt domain nil t
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
537 (if gnats::emacs-19p (cons default 0)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
538 default))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
539 (read-string prompt (if gnats::emacs-19p (cons default 1)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
540 default)))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
541 (setq new default))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
542 (gnats::set-field field new)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
543 (funcall (gnats::field-action field) field old new)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
544 new)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
545
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
546 (defun gnats::set-field (field value)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
547 (save-excursion
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
548 (gnats::position-on-field field)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
549 (delete-horizontal-space)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
550 (looking-at ".*$")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
551 (replace-match
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
552 (concat (make-string (- gnats::indent (length field) 2) ?\40 ) value) t)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
553
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
554 (defun gnats::set-mail-field (field value)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
555 (save-excursion
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
556 (gnats::mail-position-on-field field)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
557 (delete-horizontal-space)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
558 (looking-at ".*$")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
559 (replace-match (concat " " value) t)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
560
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
561 (defun gnats::before-keyword (&optional where)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
562 "Returns t if point is in some white space before a keyword.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
563 If where is nil, then point is not changed; if where is t then point is moved
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
564 to the beginning of the keyword, otherwise it is moved to the beginning
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
565 of the white space it was in."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
566 ;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
567 (if (looking-at gnats::before-keyword)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
568 (prog1 t
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
569 (cond ((eq where t)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
570 (re-search-forward "^>") (backward-char))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
571 ((not (eq where nil))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
572 (re-search-backward "[^ \t\n\f]") (forward-char))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
573 nil))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
574
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
575 (defun gnats::after-keyword (&optional where)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
576 "Returns t if point is in some white space after a keyword.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
577 If where is nil, then point is not changed; if where is t then point is moved
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
578 to the beginning of the keyword, otherwise it is moved to the end of the white
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
579 space it was in."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
580 ;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
581 (if (gnats::looking-after gnats::after-keyword)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
582 (prog1 t
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
583 (cond ((eq where t)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
584 (re-search-backward "^>"))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
585 ((not (eq where nil))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
586 (re-search-forward "[^ \t\n\f]") (backward-char))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
587 nil))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
588
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
589 (defun gnats::in-keyword (&optional where)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
590 "Returns t if point is within a keyword.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
591 If where is nil, then point is not changed; if where is t then point is moved
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
592 to the beginning of the keyword."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
593 ;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
594 (let ((old-point (point-marker)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
595 (beginning-of-line)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
596 (cond ((and (looking-at gnats::keyword)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
597 (< old-point (match-end 0)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
598 (prog1 t
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
599 (if (eq where t)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
600 t
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
601 (goto-char old-point))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
602 (t (goto-char old-point)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
603 nil))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
604
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
605 (defun gnats::forward-bofield ()
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
606 "Moves point to the beginning of a field. Assumes that point is in the
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
607 keyword."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
608 ;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
609 (if (re-search-forward "[ \t\n\f]+[^ \t\n\f]" (point-max) '-)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
610 (backward-char)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
611 t))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
612
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
613 (defun gnats::backward-eofield ()
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
614 "Moves point to the end of a field. Assumes point is in the keyword."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
615 ;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
616 (if (re-search-backward "[^ \t\n\f][ \t\n\f]+" (point-min) '-)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
617 (forward-char)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
618 t))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
619
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
620 (defun gnats::forward-eofield ()
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
621 "Moves point to the end of a field. Assumes that point is in the field."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
622 ;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
623 ;; look for the next field
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
624 (if (re-search-forward gnats::keyword (point-max) '-)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
625 (progn (beginning-of-line) (gnats::backward-eofield))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
626 (re-search-backward "[^ \t\n\f][ \t\n\f]*" (point-min) '-)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
627 (forward-char)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
628
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
629 (defun gnats::backward-bofield ()
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
630 "Moves point to the beginning of a field. Assumes that point is in the
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
631 field."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
632 ;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
633 ;;look for previous field
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
634 (if (re-search-backward gnats::keyword (point-min) '-)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
635 (gnats::forward-bofield)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
636 t))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
637
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
638
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
639 (defun gnats:forward-field ()
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
640 "Move point forward to the end of the field or to the beginning of the next
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
641 field."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
642 ;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
643 (interactive)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
644 (if (or (gnats::before-keyword t) (gnats::in-keyword t)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
645 (gnats::after-keyword t))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
646 (gnats::forward-bofield)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
647 (gnats::forward-eofield)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
648
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
649 (defun gnats:backward-field ()
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
650 "Move point backward to the beginning/end of a field."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
651 ;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
652 (interactive)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
653 (backward-char)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
654 (if (or (gnats::before-keyword t) (gnats::in-keyword t)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
655 (gnats::after-keyword t))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
656 (gnats::backward-eofield)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
657 (gnats::backward-bofield)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
658
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
659 (defun gnats:next-field ()
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
660 "Move point to the beginning of the next field."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
661 ;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
662 (interactive)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
663 (if (or (gnats::before-keyword t) (gnats::in-keyword t)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
664 (gnats::after-keyword t))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
665 (gnats::forward-bofield)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
666 (if (re-search-forward gnats::keyword (point-max) '-)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
667 (gnats::forward-bofield)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
668 t)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
669
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
670 (defun gnats:previous-field ()
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
671 "Move point to the beginning of the previous field."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
672 ;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
673 (interactive)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
674 (backward-char)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
675 (if (or (gnats::after-keyword t) (gnats::in-keyword t)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
676 (gnats::before-keyword t))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
677 (progn (re-search-backward gnats::keyword (point-min) '-)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
678 (gnats::forward-bofield))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
679 (gnats::backward-bofield)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
680
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
681 (defun gnats:beginning-of-field ()
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
682 "Move point to the beginning of the current field."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
683 (interactive)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
684 (cond ((gnats::in-keyword t)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
685 (gnats::forward-bofield))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
686 ((gnats::after-keyword 0))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
687 (t
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
688 (gnats::backward-bofield))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
689
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
690 (defun gnats::current-field ()
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
691 (save-excursion
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
692 (if (cond ((or (gnats::in-keyword t) (gnats::after-keyword t))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
693 (looking-at gnats::keyword))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
694 ((re-search-backward gnats::keyword nil t)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
695 (buffer-substring (match-beginning 1) (match-end 1))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
696 nil)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
697
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
698 ;;;;---------------------------------------------------------------------------
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
699 ;;;; Support functions
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
700 ;;;;---------------------------------------------------------------------------
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
701
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
702 (defun gnats::looking-after (regex)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
703 "Returns t if point is after regex."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
704 ;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
705 (let* ((old-point (point))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
706 (start (if (eobp)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
707 old-point
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
708 (forward-char) (point))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
709 (cond ((re-search-backward regex (point-min) t)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
710 (goto-char old-point)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
711 (cond ((eq (match-end 0) start)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
712 t))))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
713
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
714 (defun gnats::nth-word (string &optional elem)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
715 "Returns the elem-th word of the string.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
716 If elem is nil, then the first wort is returned, if elem is 0 then
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
717 the whole string is returned."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
718 ;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
719 (if (integerp elem)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
720 (cond ((eq elem 0) string)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
721 ((eq elem 1) (gnats::first-word string))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
722 ((equal string "") "")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
723 ((>= elem 2)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
724 (let ((i 0) (value ""))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
725 (setq string ; strip leading blanks
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
726 (substring string (or (string-match "[^ \t]" string) 0)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
727 (while (< i elem)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
728 (setq value
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
729 (substring string 0
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
730 (string-match "[ \t]*$\\|[ \t]+" string)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
731 (setq string
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
732 (substring string (match-end 0)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
733 (setq i (+ i 1)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
734 value)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
735 (gnats::first-word string)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
736
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
737 (defun gnats::first-word (string)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
738 (setq string
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
739 (substring string (or (string-match "[^ \t]" string) 0)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
740 (substring string 0 (string-match "[ \t]*$\\|[ \t]+" string)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
741
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
742 ;;;;---------------------------------------------------------------------------
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
743
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
744 (defun gnats::patch-exec-path ()
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
745 ;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
746 "Replaces `//' by `/' in `exec-path'."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
747 ;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
748 ;(make-local-variable 'exec-path)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
749 (let ((err-buffer (get-buffer-create " *gnats::patch-exec-path*"))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
750 (ret))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
751 (setq exec-path (save-excursion (set-buffer err-buffer)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
752 (prin1 exec-path err-buffer)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
753 (goto-char (point-min))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
754 (while (search-forward "//" nil t)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
755 (replace-match "/" nil t))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
756 (goto-char (point-min))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
757 (setq ret (read err-buffer))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
758 (kill-buffer err-buffer)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
759 ret
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
760 ))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
761
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
762 (defun gnats::get-value-from-shell (&rest command)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
763 "Execute shell command to get a list of valid values for `variable'."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
764 ;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
765 (let ((err-buffer (get-buffer-create " *gnats::get-value-from-shell*")))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
766 (save-excursion
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
767 (set-buffer err-buffer)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
768 (unwind-protect
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
769 (condition-case var
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
770 (progn
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
771 (apply 'call-process
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
772 (car command) nil err-buffer nil (cdr command))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
773 (goto-char (point-min))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
774 (if (looking-at "[-a-z]+: ")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
775 (error (buffer-substring (point-min) (point-max))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
776 (read err-buffer))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
777 (error nil))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
778 (kill-buffer err-buffer)))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
779
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
780 (or (fboundp 'setenv)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
781 (defun setenv (variable &optional value)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
782 "Set the value of the environment variable named VARIABLE to VALUE.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
783 VARIABLE should be a string. VALUE is optional; if not provided or is
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
784 `nil', the environment variable VARIABLE will be removed.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
785 This function works by modifying `process-environment'."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
786 (interactive "sSet environment variable: \nsSet %s to value: ")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
787 (if (string-match "=" variable)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
788 (error "Environment variable name `%s' contains `='" variable)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
789 (let ((pattern (concat "\\`" (regexp-quote (concat variable "="))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
790 (case-fold-search nil)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
791 (scan process-environment))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
792 (while scan
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
793 (cond
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
794 ((string-match pattern (car scan))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
795 (if (eq nil value)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
796 (setq process-environment (delq (car scan)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
797 process-environment))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
798 (setcar scan (concat variable "=" value)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
799 (setq scan nil))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
800 ((null (setq scan (cdr scan)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
801 (setq process-environment
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
802 (cons (concat variable "=" value)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
803 process-environment)))))))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
804
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents:
diff changeset
805 ;;;; end of send-pr.el