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