1 ;;; ecb-autogen.el --- Auto load statement generator
3 ;; Copyright (C) 2000 - 2003 Jesper Nordenberg,
6 ;; Free Software Foundation, Inc.
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
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.
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
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.
29 ;; $Id: ecb-autogen.el,v 1.14 2004-12-10 16:34:19 berndl Exp $
33 ;; Automatically generate autoloads for ECB
35 ;; This code is based onto semantic-autogen.el, the autoload generator of
41 ;; For the ChangeLog of this file see the CVS-repository. For a complete
42 ;; history of the ECB-package see the file NEWS.
52 (require 'silentcomp))
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)
61 'find-file-hooks) nil)
62 (setq find-file-suppress-same-file-warnings t)
66 (defconst ecb-autogen-header
67 "Auto-generated ecb autoloads"
68 "Header of the auto-generated autoloads file.")
70 (defconst ecb-autogen-file "ecb-autoloads.el"
71 "Name of the auto-generated autoloads file.")
73 (defconst ecb-autoload-feature "ecb-autoloads"
74 "Feature-name of the autoloads")
76 (defvar ecb-autogen-subdirs nil
77 "Sub-directories to scan for autoloads.")
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))
88 ;; Replace existing header line
89 ((re-search-forward (concat "^" (regexp-quote tag)) nil t)
93 ;; Insert header before first ^L encountered (XEmacs)
94 ((re-search-forward "^
\f" nil t)
97 (insert tag " " ecb-autogen-header)
99 (message "Updating header...done")
100 nil ;; Say not already written.
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))))
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)
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
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)
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))
146 (ecb-batch-update-autoloads))
147 ;; XEmacs adds autom. the provide statement but for GNU Emacs we must do
149 (when (not ecb-running-xemacs)
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))
158 (kill-buffer (current-buffer)))))))
160 (silentcomp-provide 'ecb-autogen)
162 ;;; ecb-autogen.el ends here