Remove old and crusty Sun pkg
[packages] / xemacs-packages / ecb / ecb-autogen.el
1 ;;; ecb-autogen.el --- Auto load statement generator
2
3 ;; Copyright (C) 2000 - 2003 Jesper Nordenberg,
4 ;;                           Klaus Berndl,
5 ;;                           Kevin A. Burton,
6 ;;                           Free Software Foundation, Inc.
7
8 ;; Author: Jesper Nordenberg <mayhem@home.se>
9 ;;         Klaus Berndl <klaus.berndl@sdm.de>
10 ;;         Kevin A. Burton <burton@openprivacy.org>
11 ;; Maintainer: Klaus Berndl <klaus.berndl@sdm.de>
12 ;;             Kevin A. Burton <burton@openprivacy.org>
13 ;; Keywords: browser, code, programming, tools
14 ;; Created: 2003
15
16 ;; This program is free software; you can redistribute it and/or modify it under
17 ;; the terms of the GNU General Public License as published by the Free Software
18 ;; Foundation; either version 2, or (at your option) any later version.
19
20 ;; This program is distributed in the hope that it will be useful, but WITHOUT
21 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 ;; FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
23 ;; details.
24
25 ;; You should have received a copy of the GNU General Public License along with
26 ;; GNU Emacs; see the file COPYING.  If not, write to the Free Software
27 ;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28
29 ;; $Id: ecb-autogen.el,v 1.14 2004-12-10 16:34:19 berndl Exp $
30
31 ;;; Commentary:
32 ;;
33 ;; Automatically generate autoloads for ECB
34 ;;
35 ;; This code is based onto semantic-autogen.el, the autoload generator of
36 ;; semantic.
37 ;;
38
39 ;;; History
40 ;;
41 ;; For the ChangeLog of this file see the CVS-repository. For a complete
42 ;; history of the ECB-package see the file NEWS.
43
44 ;;; Code
45 ;;
46
47 (require 'autoload)
48
49 (require 'ecb-util)
50
51 (eval-when-compile
52   (require 'silentcomp))
53
54
55 (when (ecb-noninteractive)
56   ;; If the user is doing this non-interactively, we need to set up
57   ;; these conveniences.
58   (add-to-list 'load-path nil)
59   (set (if (boundp 'find-file-hook)
60            'find-file-hook
61          'find-file-hooks) nil)
62   (setq find-file-suppress-same-file-warnings t)
63   )
64
65
66 (defconst ecb-autogen-header
67   "Auto-generated ecb autoloads"
68   "Header of the auto-generated autoloads file.")
69
70 (defconst ecb-autogen-file "ecb-autoloads.el"
71   "Name of the auto-generated autoloads file.")
72
73 (defconst ecb-autoload-feature "ecb-autoloads"
74   "Feature-name of the autoloads")
75
76 (defvar ecb-autogen-subdirs nil
77   "Sub-directories to scan for autoloads.")
78
79 (defun ecb-autogen-update-header ()
80   "Update header of the auto-generated autoloads file.
81 Run as `write-contents-hooks'."
82   (when (ecb-string= generated-autoload-file (buffer-file-name))
83     (let ((tag (format ";;; %s ---" (file-name-nondirectory
84                                      (buffer-file-name)))))
85       (message "Updating header...")
86       (goto-char (point-min))
87       (cond
88        ;; Replace existing header line
89        ((re-search-forward (concat "^" (regexp-quote tag)) nil t)
90         (beginning-of-line)
91         (kill-line 1)
92         )
93        ;; Insert header before first ^L encountered (XEmacs)
94        ((re-search-forward "^\f" nil t)
95         (beginning-of-line)
96         ))
97       (insert tag " " ecb-autogen-header)
98       (newline)
99       (message "Updating header...done")
100       nil ;; Say not already written.
101       )))
102
103 ;; We code this so clumsy to silence the bytecompiler of GNU Emacs >= 21.4 not
104 ;; to complain about obsoleteness of `write-contents-hooks'.
105 (defun ecb-batch-update-autoloads ()
106   (let ((old-val (symbol-value (if (boundp 'write-contents-functions)
107                                    'write-contents-functions
108                                  'write-contents-hooks))))
109     (unwind-protect
110         (progn
111           (set (if (boundp 'write-contents-functions)
112                    'write-contents-functions
113                  'write-contents-hooks)
114                '(ecb-autogen-update-header))
115           (batch-update-autoloads))
116       (set (if (boundp 'write-contents-functions)
117                'write-contents-functions
118              'write-contents-hooks)
119            old-val)))) 
120
121 (defun ecb-update-autoloads ()
122   "Update ecb autoloads from sources.
123 Autoloads file name is defined in variable `ecb-autogen-file'. If ECB is
124 installed as regular XEmacs-package then this function reports an error and
125 does nothing."
126   (interactive)
127   (if ecb-regular-xemacs-package-p
128       (ecb-error "Updating autoloads not possible for regular XEmacs-packages!")
129     (if (file-exists-p (expand-file-name ecb-autogen-file))
130         (delete-file (expand-file-name ecb-autogen-file)))
131     (when (not ecb-running-xemacs)
132       ;; generate a new one but do this not for XEmacs because XEmacs must(!)
133       ;; handle this itself
134       (with-temp-file (expand-file-name ecb-autogen-file)
135         (insert "\f")))
136     (let* ((default-directory (file-name-directory (locate-library "ecb")))
137            (generated-autoload-file (expand-file-name ecb-autogen-file))
138            ;; needed for XEmacs to ensure that always a feature 'ecb-autoloads
139            ;; is provided and not a feature like 'ecb-1.91.2-autoloads (XEmacs
140            ;; uses the installation-directory of ECB as feature prefix if
141            ;; autoload-package-name is not provided.
142            (autoload-package-name "ecb")
143            (subdirs (mapcar 'expand-file-name ecb-autogen-subdirs))
144            (command-line-args-left (cons default-directory subdirs))
145            )
146       (ecb-batch-update-autoloads))
147     ;; XEmacs adds autom. the provide statement but for GNU Emacs we must do
148     ;; this:
149     (when (not ecb-running-xemacs)
150       (save-excursion
151         (set-buffer (find-file-noselect (expand-file-name ecb-autogen-file)))
152         (goto-char (point-min))
153         (when (not (re-search-forward (format "^(provide '%s)"
154                                               ecb-autoload-feature) nil t))
155           (goto-char (point-max))
156           (insert (format "\n(provide '%s)\n" ecb-autoload-feature))
157           (save-buffer)
158           (kill-buffer (current-buffer)))))))
159
160 (silentcomp-provide 'ecb-autogen)
161
162 ;;; ecb-autogen.el ends here