1 ":" ; @EMACS@ -batch -l $0 "$@" ; status=$? ; : '--*-Emacs-Lisp-*--' <<';'
3 ;; Copyright (C) 1998 Ian Zimmerman <itz@transbay.net>
4 ;; This program is free software; you can redistribute it and/or
5 ;; modify it under the terms of the GNU General Public License as
6 ;; published by the Free Software Foundation; either version 2 of the
7 ;; License, or (at your option) any later version.
9 ;; This program is distributed in the hope that it will be useful,
10 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ;; General Public License for more details.
13 ;; $Id: ocamltags.in,v 1.5 1999/11/29 19:03:30 doligez Exp $
17 ;;itz Fri Oct 30 13:08:37 PST 1998 support for creating TAGS files
18 ;; itz Sun Dec 27 10:26:08 PST 1998 adapted very slightly from
19 ;; Jacques' caml-create-index-function
20 (defun caml-tags-create-index-function ()
21 (let (all-alist index)
22 (goto-char (point-max))
23 ;; collect definitions
24 (while (caml-prev-index-position-function)
25 (if (looking-at "[ \t]*val") nil
26 (setq index (cons (caml-match-string 5) (point)))
27 (setq all-alist (cons index all-alist))))
30 (defun caml-tags-file (filename)
31 (let* ((output-buffer (current-buffer))
32 (basename (file-name-nondirectory filename))
34 (insert "
\f\n" basename)
36 (find-file-read-only filename)
38 (let ((all-alist (caml-tags-create-index-function))
41 (last-point (point-min)))
44 (let ((tag-name (car pair)) (tag-pos (cdr pair)))
47 (+ current-line (count-lines last-point (point))))
48 (setq last-point (point))
50 (let ((output-line (format "%s
\7f%s
\ 1%d,%d\n"
51 (buffer-substring last-point (point))
52 tag-name current-line tag-pos)))
54 (set-buffer output-buffer)
55 (insert output-line)))))
57 (kill-buffer (current-buffer))
58 (set-buffer output-buffer)
59 (let ((index-size (- (point) backpatch)))
61 (insert "," (int-to-string index-size) "\n")
62 (goto-char (point-max)))))
64 (defsubst prefix-p (prefix str)
65 (and (<= (length prefix) (length str))
66 (string= prefix (substring str 0 (length prefix)))))
68 (defsubst eat-args (n)
69 (setq command-line-args-left (nthcdr n command-line-args-left)))
71 ;; see Emacs source file print.c
72 (defun print-error-message (data)
73 (let ((errname (car data)) errmsg is-file-error tail i)
74 (if (eq errname 'error)
76 (setq data (cdr data))
77 (if (not (consp data)) (setq data nil))
78 (setq errmsg (car data))
79 (setq is-file-error nil))
80 (setq errmsg (get errname 'error-message))
81 (setq is-file-error (memq 'file-error (get errname 'error-conditions))))
82 (setq tail (cdr-safe data))
83 (if (and is-file-error tail)
84 (setq errmsg (car tail) tail (cdr tail)))
85 (if (stringp errmsg) (princ errmsg)
86 (princ "peculiar error"))
89 (princ (if (eq i 0) ": " ", "))
90 (if is-file-error (princ (car tail))
92 (setq tail (cdr tail) i (1+ i)))
96 (setq gc-cons-threshold 1000000)
98 (setq output-file "TAGS")
99 (setq append-flag nil)
102 (condition-case foobar
104 (while (and command-line-args-left
105 (let ((arg (car command-line-args-left)))
107 ((prefix-p arg "-output-file")
108 (setq output-file (nth 1 command-line-args-left))
110 ((prefix-p arg "-append")
115 (find-file output-file)
116 (if append-flag (goto-char (point-max))
118 (while command-line-args-left
119 (caml-tags-file (car command-line-args-left))
120 (setq command-line-args-left (cdr command-line-args-left)))
122 (error (setq status 1) (print-error-message foobar)))