1 ;;; dgnushack.el --- a hack to set the load path for byte-compiling
2 ;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Katsumi Yamaoka <yamaoka@jpl.org>
8 ;; Keywords: news, path
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
31 ;; Set coding priority of Shift-JIS to the bottom.
32 (defvar *predefined-category*)
33 (defvar coding-category-list)
34 (if (featurep 'xemacs)
35 (fset 'set-coding-priority 'ignore)
36 (fset 'coding-priority-list 'ignore)
37 (fset 'set-coding-priority-list 'ignore))
38 (cond ((and (featurep 'xemacs) (featurep 'mule))
39 (if (memq 'shift-jis (coding-priority-list))
40 (set-coding-priority-list
41 (append (delq 'shift-jis (coding-priority-list)) '(shift-jis)))))
43 (put '*coding-category-sjis* 'priority (length *predefined-category*)))
45 (if (memq 'coding-category-sjis coding-category-list)
47 (append (delq 'coding-category-sjis
48 (copy-sequence coding-category-list))
49 '(coding-category-sjis))))))
55 (defvar srcdir (or (getenv "srcdir") "."))
57 (push (or (getenv "W3DIR") (expand-file-name "../../w3/lisp/" srcdir))
59 (load (expand-file-name "dgnuspath.el" srcdir) nil nil t)
61 ;; If we are building w3 in a different directory than the source
62 ;; directory, we must read *.el from source directory and write *.elc
63 ;; into the building directory. For that, we define this function
64 ;; before loading bytecomp. Bytecomp doesn't overwrite this function.
65 (defun byte-compile-dest-file (filename)
66 "Convert an Emacs Lisp source file name to a compiled file name.
67 In addition, remove directory name part from FILENAME."
68 (setq filename (byte-compiler-base-file-name filename))
69 (setq filename (file-name-sans-versions filename))
70 (setq filename (file-name-nondirectory filename))
71 (if (memq system-type '(win32 w32 mswindows windows-nt))
72 (setq filename (downcase filename)))
73 (cond ((eq system-type 'vax-vms)
74 (concat (substring filename 0 (string-match ";" filename)) "c"))
75 ((string-match emacs-lisp-file-regexp filename)
76 (concat (substring filename 0 (match-beginning 0)) ".elc"))
77 (t (concat filename ".elc"))))
81 (unless (fboundp 'si:byte-optimize-form-code-walker)
82 (byte-optimize-form nil);; Load `byte-opt' or `byte-optimize'.
83 (setq max-specpdl-size 3000)
84 (fset 'si:byte-optimize-form-code-walker
85 (symbol-function 'byte-optimize-form-code-walker))
86 (defun byte-optimize-form-code-walker (form for-effect)
87 (if (and for-effect (memq (car-safe form) '(and or)))
88 ;; Fix bug in and/or forms.
90 (backwards (reverse (cdr form))))
92 (null (setcar backwards
93 (byte-optimize-form (car backwards) t))))
94 (setq backwards (cdr backwards)))
95 (if (and (cdr form) (null backwards))
97 " all subforms of %s called for effect; deleted" form))
99 (let ((head backwards))
100 (while (setq backwards (cdr backwards))
101 (setcar backwards (byte-optimize-form (car backwards)
103 (cons fn (nreverse head)))))
104 (si:byte-optimize-form-code-walker form for-effect)))
105 (byte-compile 'byte-optimize-form-code-walker))
107 (load (expand-file-name "gnus-clfns.el" srcdir) nil t t)
110 (load "~/.lpath.el" t nil t)
111 (error (message "Error in \"~/.lpath.el\" file: %s" err)))
115 (wrong-number-of-arguments
116 ;; Optimize byte code for `char-after'.
117 (put 'char-after 'byte-optimizer 'byte-optimize-char-after)
118 (defun byte-optimize-char-after (form)
119 (if (null (cdr form))
120 '(char-after (point))
126 (wrong-number-of-arguments
127 ;; Optimize byte code for `char-before'.
128 (put 'char-before 'byte-optimizer 'byte-optimize-char-before)
129 (defun byte-optimize-char-before (form)
130 (if (null (cdr form))
131 '(char-before (point))
135 ;; `char-after' and `char-before' must be well-behaved before lpath.el
136 ;; is loaded. Because it requires `poe' via `path-util'.
137 (load (expand-file-name "lpath.el" srcdir) nil t t)
139 (unless (fboundp 'byte-compile-file-form-custom-declare-variable)
140 ;; Bind defcustom'ed variables.
141 (put 'custom-declare-variable 'byte-hunk-handler
142 'byte-compile-file-form-custom-declare-variable)
143 (defun byte-compile-file-form-custom-declare-variable (form)
144 (if (memq 'free-vars byte-compile-warnings)
145 (setq byte-compile-bound-variables
146 (cons (nth 1 (nth 1 form)) byte-compile-bound-variables)))
149 ;; Bind functions defined by `defun-maybe'.
150 (put 'defun-maybe 'byte-hunk-handler 'byte-compile-file-form-defun-maybe)
151 (defun byte-compile-file-form-defun-maybe (form)
152 (if (and (not (fboundp (nth 1 form)))
153 (memq 'unresolved byte-compile-warnings))
154 (setq byte-compile-function-environment
155 (cons (cons (nth 1 form)
156 (cons 'lambda (cdr (cdr form))))
157 byte-compile-function-environment)))
161 :symbol-for-testing-whether-colon-keyword-is-available-or-not
164 (mapcar (lambda (keyword) (set keyword keyword))
165 '(:button-keymap :data :file :mime-handle))))
167 ;; Unknown variables and functions.
168 (unless (boundp 'buffer-file-coding-system)
169 (defvar buffer-file-coding-system (symbol-value 'file-coding-system)))
170 (unless (featurep 'xemacs)
171 (defalias 'Custom-make-dependencies 'ignore)
172 (defalias 'update-autoloads-from-directory 'ignore))
173 (autoload 'texinfo-parse-line-arg "texinfmt")
175 (unless (fboundp 'with-temp-buffer)
176 ;; Pickup some macros.
179 (defalias 'device-sound-enabled-p 'ignore)
180 (defalias 'play-sound-file 'ignore)
181 (defalias 'nndb-request-article 'ignore)
182 (defalias 'efs-re-read-dir 'ignore)
183 (defalias 'ange-ftp-re-read-dir 'ignore)
184 (defalias 'define-mail-user-agent 'ignore)
186 (defconst dgnushack-tool-files
187 '("dgnushack.el" "dgnuspath.el" "ptexinfmt.el"))
188 (defconst dgnushack-unexported-files
189 '("dgnuspath.el" "ptexinfmt.el"))
191 (defun dgnushack-compile (&optional warn)
192 ;;(setq byte-compile-dynamic t)
194 (setq byte-compile-warnings
195 '(free-vars unresolved callargs redefine)))
196 (unless (locate-library "cus-edit")
197 (error "You do not seem to have Custom installed.
198 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
199 You also then need to add the following to the lisp/dgnushack.el file:
201 (push \"~/lisp/custom\" load-path)
203 Modify to suit your needs."))
204 (let ((files (directory-files srcdir nil "^[^=].*\\.el$"))
205 ;;(byte-compile-generate-call-tree t)
208 (lambda (el) (setq files (delete el files)))
212 (progn (require 'w3-forms) nil)
213 (error '("nnweb.el" "nnlistserv.el" "nnultimate.el"
214 "nnslashdot.el" "nnwarchive.el" "webmail.el")))
216 (progn (require 'bbdb) nil)
217 (error '("gnus-bbdb.el")))
218 (if (featurep 'xemacs)
220 '("gnus-xmas.el" "gnus-picon.el" "messagexmas.el"
221 "nnheaderxm.el" "smiley.el"))
222 (when (and (fboundp 'md5) (subrp (symbol-function 'md5)))
224 (while (setq file (pop files))
225 (setq file (expand-file-name file srcdir))
226 (when (or (not (file-exists-p (setq elc (concat file "c"))))
227 (file-newer-than-file-p file elc))
229 (byte-compile-file file))))))
231 (defun dgnushack-recompile ()
233 (byte-recompile-directory "." 0))
236 ;; Avoid byte-compile warnings.
237 (defvar gnus-product-name)
238 (defvar early-package-load-path)
239 (defvar early-packages)
240 (defvar last-package-load-path)
241 (defvar last-packages)
242 (defvar late-package-load-path)
243 (defvar late-packages)
245 (defconst dgnushack-info-file-regexp
246 (concat "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)"
247 "\\.info\\(-[0-9]+\\)?$"))
249 (defconst dgnushack-texi-file-regexp
250 "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)\\.texi$")
252 (defun dgnushack-make-package ()
254 (let* ((product-name (downcase gnus-product-name))
255 (lisp-dir (concat "lisp/" product-name "/"))
258 (message "Updating autoloads for directory %s..." default-directory)
259 (let ((generated-autoload-file "auto-autoloads.el")
261 (omsg (symbol-function 'message)))
262 (defun message (fmt &rest args)
263 (cond ((and (string-equal "Generating autoloads for %s..." fmt)
264 (file-exists-p (file-name-nondirectory (car args))))
265 (funcall omsg fmt (file-name-nondirectory (car args))))
266 ((string-equal "No autoloads found in %s" fmt))
267 ((string-equal "Generating autoloads for %s...done" fmt))
268 (t (apply omsg fmt args))))
270 (update-autoloads-from-directory default-directory)
271 (fset 'message omsg)))
272 (byte-compile-file "auto-autoloads.el")
275 (let ((standard-output (current-buffer)))
276 (Custom-make-dependencies "."))
277 (message "%s" (buffer-string)))
279 (byte-compile-file "custom-load.el")
281 (message "Generating MANIFEST.%s for the package..." product-name)
283 (insert "pkginfo/MANIFEST." product-name "\n")
286 (unless (member file dgnushack-unexported-files)
287 (insert lisp-dir file "\n")))
288 (sort (directory-files "." nil "\\.elc?$") 'string-lessp))
290 (lambda (file) (insert "info/" file "\n"))
291 (sort (directory-files "../texi/" nil dgnushack-info-file-regexp)
293 (write-file (concat "../MANIFEST." product-name)))))
295 (defun dgnushack-install-package ()
296 (let ((package-dir (car command-line-args-left))
297 dirs info-dir pkginfo-dir product-name lisp-dir manifest files)
299 (when (boundp 'early-packages)
300 (setq dirs (delq nil (append (when early-package-load-path
302 (when late-package-load-path
304 (when last-package-load-path
306 (while (and dirs (not package-dir))
307 (when (file-exists-p (car dirs))
308 (setq package-dir (car dirs)
312 You must specify the name of the package path as follows:
314 % make install-package PACKAGEDIR=/usr/local/lib/xemacs/xemacs-packages
317 (setq info-dir (expand-file-name "info/" package-dir)
318 pkginfo-dir (expand-file-name "pkginfo/" package-dir))
320 (setq product-name (downcase gnus-product-name)
321 lisp-dir (expand-file-name (concat "lisp/" product-name "/")
323 manifest (concat "MANIFEST." product-name))
325 (unless (file-directory-p lisp-dir)
326 (make-directory lisp-dir t))
327 (unless (file-directory-p info-dir)
328 (make-directory info-dir))
329 (unless (file-directory-p pkginfo-dir)
330 (make-directory pkginfo-dir))
332 (setq files (sort (directory-files "." nil "\\.elc?$") 'string-lessp))
333 (mapcar (lambda (el) (setq files (delete el files)))
334 dgnushack-unexported-files)
337 (unless (or (member file files)
338 (not (string-match "\\.elc?$" file)))
339 (setq file (expand-file-name file lisp-dir))
340 (message "Removing %s..." file)
344 (directory-files lisp-dir nil nil nil t))
347 (message "Copying %s to %s..." file lisp-dir)
348 (copy-file file (expand-file-name file lisp-dir) t t))
353 (message "Copying ../texi/%s to %s..." file info-dir)
354 (copy-file (expand-file-name file "../texi/")
355 (expand-file-name file info-dir)
357 (sort (directory-files "../texi/" nil dgnushack-info-file-regexp)
360 (message "Copying ../%s to %s..." manifest pkginfo-dir)
361 (copy-file (expand-file-name manifest "../")
362 (expand-file-name manifest pkginfo-dir) t t)
366 (defun dgnushack-texi-add-suffix-and-format ()
367 (dgnushack-texi-format t))
369 (defun dgnushack-texi-format (&optional addsuffix)
370 (if (not noninteractive)
371 (error "batch-texinfo-format may only be used -batch."))
373 (let ((auto-save-default nil)
374 (find-file-run-dired nil)
375 coding-system-for-write
376 output-coding-system)
380 (while command-line-args-left
381 (setq file (expand-file-name (car command-line-args-left)))
382 (cond ((not (file-exists-p file))
383 (message ">> %s does not exist!" file)
385 command-line-args-left (cdr command-line-args-left)))
386 ((file-directory-p file)
387 (setq command-line-args-left
388 (nconc (directory-files file)
389 (cdr command-line-args-left))))
391 (setq files (cons file files)
392 command-line-args-left (cdr command-line-args-left)))))
394 (setq file (car files)
398 (if buffer-file-name (kill-buffer (current-buffer)))
401 (setq output-coding-system (symbol-value
402 'file-coding-system))
403 (setq coding-system-for-write buffer-file-coding-system))
406 "^@setfilename[\t ]+\\([^\t\n ]+\\)" nil t)
407 (not (string-match "\\.info$" (match-string 1))))
409 (buffer-disable-undo (current-buffer))
410 ;; process @include before updating node
411 ;; This might produce some problem if we use @lowersection or
413 (let ((input-directory default-directory)
414 (texinfo-command-end))
415 (while (re-search-forward "^@include" nil t)
416 (setq texinfo-command-end (point))
417 (let ((filename (concat input-directory
418 (texinfo-parse-line-arg))))
419 (re-search-backward "^@include")
420 (delete-region (point) (save-excursion
423 (message "Reading included file: %s" filename)
429 (car (cdr (insert-file-contents filename)))))
430 (goto-char (point-min))
431 ;; Remove `@setfilename' line from included file,
432 ;; if any, so @setfilename command not duplicated.
433 (if (re-search-forward "^@setfilename"
440 (delete-region (point) (save-excursion
444 (texinfo-every-node-update)
445 (set-buffer-modified-p nil)
446 (message "texinfo formatting %s..." file)
447 (texinfo-format-buffer nil)
448 (if (buffer-modified-p)
449 (progn (message "Saving modified %s" (buffer-file-name))
452 (message ">> Error: %s" (prin1-to-string err))
453 (message ">> point at")
454 (let ((s (buffer-substring (point)
458 (while (setq tem (string-match "\n+" s tem))
459 (setq s (concat (substring s 0 (match-beginning 0))
461 (substring s (match-end 0)))
465 (kill-emacs error))))
467 ;;; dgnushack.el ends here