1 ;;; dgnushack.el --- a hack to set the load path for byte-compiling
2 ;; Copyright (C) 1994,95,96,97,98,99 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; Katsumi Yamaoka <yamaoka@jpl.org>
7 ;; Keywords: news, path
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
30 ;; Set coding priority of Shift-JIS to the bottom.
31 (defvar *predefined-category*)
32 (defvar coding-category-list)
33 (if (featurep 'xemacs)
34 (fset 'set-coding-priority 'ignore)
35 (fset 'coding-priority-list 'ignore)
36 (fset 'set-coding-priority-list 'ignore))
37 (cond ((and (featurep 'xemacs) (featurep 'mule))
38 (if (memq 'shift-jis (coding-priority-list))
39 (set-coding-priority-list
40 (nconc (delq 'shift-jis (coding-priority-list)) '(shift-jis)))))
42 (put '*coding-category-sjis* 'priority (length *predefined-category*)))
44 (if (memq 'coding-category-sjis coding-category-list)
46 (nconc (delq 'coding-category-sjis coding-category-list)
47 '(coding-category-sjis))))))
53 ;; Emulating cl functions.
54 (unless (featurep 'xemacs)
55 (define-compiler-macro last (&whole form x &optional n)
56 (if (and (fboundp 'last)
57 (subrp (symbol-function 'last)))
73 (while (consp (cdr x))
77 (define-compiler-macro mapc (&whole form fn seq &rest rest)
78 (if (and (fboundp 'mapc)
79 (subrp (symbol-function 'mapc)))
84 (args (list seq ,@rest))
85 (m (apply (function min) (mapcar (function length) args)))
88 (apply fn (mapcar (function (lambda (arg) (nth n arg))) args))
95 (define-compiler-macro mapcon (&whole form fn seq &rest rest)
96 (if (and (fboundp 'mapcon)
97 (subrp (symbol-function 'mapcon)))
102 (args (list ,seq ,@rest))
104 (while (not (memq nil args))
105 (push (apply ,fn args) res)
108 (setcar p (cdr (pop p)))
110 (apply (function nconc) (nreverse res)))
115 (push (funcall ,fn arg) res)
116 (setq arg (cdr arg)))
117 (apply (function nconc) (nreverse res))))))
119 (define-compiler-macro member-if (&whole form pred list)
120 (if (and (fboundp 'member-if)
121 (subrp (symbol-function 'member-if)))
126 (not (funcall fn (car seq))))
130 (define-compiler-macro union (&whole form list1 list2)
131 (if (and (fboundp 'union)
132 (subrp (symbol-function 'union)))
140 (or (>= (length a) (length b))
141 (setq a (prog1 b (setq b a))))
149 ;; If we are building w3 in a different directory than the source
150 ;; directory, we must read *.el from source directory and write *.elc
151 ;; into the building directory. For that, we define this function
152 ;; before loading bytecomp. Bytecomp doesn't overwrite this function.
153 (defun byte-compile-dest-file (filename)
154 "Convert an Emacs Lisp source file name to a compiled file name.
155 In addition, remove directory name part from FILENAME."
156 (setq filename (byte-compiler-base-file-name filename))
157 (setq filename (file-name-sans-versions filename))
158 (setq filename (file-name-nondirectory filename))
159 (if (memq system-type '(win32 w32 mswindows windows-nt))
160 (setq filename (downcase filename)))
161 (cond ((eq system-type 'vax-vms)
162 (concat (substring filename 0 (string-match ";" filename)) "c"))
163 ((string-match emacs-lisp-file-regexp filename)
164 (concat (substring filename 0 (match-beginning 0)) ".elc"))
165 (t (concat filename ".elc"))))
169 (unless (fboundp 'si:byte-optimize-form-code-walker)
170 (byte-optimize-form nil);; Load `byte-opt' or `byte-optimize'.
171 (setq max-specpdl-size 3000)
172 (fset 'si:byte-optimize-form-code-walker
173 (symbol-function 'byte-optimize-form-code-walker))
174 (defun byte-optimize-form-code-walker (form for-effect)
175 (if (and for-effect (memq (car-safe form) '(and or)))
176 ;; Fix bug in and/or forms.
177 (let ((fn (car form))
178 (backwards (reverse (cdr form))))
179 (while (and backwards
180 (null (setcar backwards
181 (byte-optimize-form (car backwards) t))))
182 (setq backwards (cdr backwards)))
183 (if (and (cdr form) (null backwards))
185 " all subforms of %s called for effect; deleted" form))
187 (let ((head backwards))
188 (while (setq backwards (cdr backwards))
189 (setcar backwards (byte-optimize-form (car backwards)
191 (cons fn (nreverse head)))))
192 (si:byte-optimize-form-code-walker form for-effect)))
193 (byte-compile 'byte-optimize-form-code-walker))
195 (defvar srcdir (or (getenv "srcdir") "."))
197 ;(push "/usr/share/emacs/site-lisp" load-path)
199 ;; Attempt to pickup the additional load-path(s).
200 (load (expand-file-name "dgnuspath.el" srcdir) nil nil t)
202 (load "~/.lpath.el" t nil t)
203 (error (message "Error in \"~/.lpath.el\" file: %s" err)))
207 (wrong-number-of-arguments
208 ;; Optimize byte code for `char-after'.
209 (put 'char-after 'byte-optimizer 'byte-optimize-char-after)
210 (defun byte-optimize-char-after (form)
211 (if (null (cdr form))
212 '(char-after (point))
218 (wrong-number-of-arguments
219 ;; Optimize byte code for `char-before'.
220 (put 'char-before 'byte-optimizer 'byte-optimize-char-before)
221 (defun byte-optimize-char-before (form)
222 (if (null (cdr form))
223 '(char-before (point))
227 ;; `char-after' and `char-before' must be well-behaved before lpath.el
228 ;; is loaded. Because it requires `poe' via `path-util'.
229 (load (expand-file-name "lpath.el" srcdir) nil t t)
231 (unless (fboundp 'byte-compile-file-form-custom-declare-variable)
232 ;; Bind defcustom'ed variables.
233 (put 'custom-declare-variable 'byte-hunk-handler
234 'byte-compile-file-form-custom-declare-variable)
235 (defun byte-compile-file-form-custom-declare-variable (form)
236 (if (memq 'free-vars byte-compile-warnings)
237 (setq byte-compile-bound-variables
238 (cons (nth 1 (nth 1 form)) byte-compile-bound-variables)))
241 ;; Bind functions defined by `defun-maybe'.
242 (put 'defun-maybe 'byte-hunk-handler 'byte-compile-file-form-defun-maybe)
243 (defun byte-compile-file-form-defun-maybe (form)
244 (if (and (not (fboundp (nth 1 form)))
245 (memq 'unresolved byte-compile-warnings))
246 (setq byte-compile-function-environment
247 (cons (cons (nth 1 form)
248 (cons 'lambda (cdr (cdr form))))
249 byte-compile-function-environment)))
253 :symbol-for-testing-whether-colon-keyword-is-available-or-not
256 (mapcar (lambda (keyword) (set keyword keyword))
257 '(:button-keymap :data :file :mime-handle))))
259 ;; Unknown variables and functions.
260 (unless (boundp 'buffer-file-coding-system)
261 (defvar buffer-file-coding-system (symbol-value 'file-coding-system)))
262 (unless (featurep 'xemacs)
263 (defalias 'Custom-make-dependencies 'ignore)
264 (defalias 'update-autoloads-from-directory 'ignore))
265 (autoload 'texinfo-parse-line-arg "texinfmt")
267 (unless (fboundp 'with-temp-buffer)
268 ;; Pickup some macros.
271 (defalias 'device-sound-enabled-p 'ignore)
272 (defalias 'play-sound-file 'ignore)
273 (defalias 'nndb-request-article 'ignore)
274 (defalias 'efs-re-read-dir 'ignore)
275 (defalias 'ange-ftp-re-read-dir 'ignore)
276 (defalias 'define-mail-user-agent 'ignore)
278 (defun dgnushack-compile (&optional warn)
279 ;;(setq byte-compile-dynamic t)
281 (setq byte-compile-warnings
282 '(free-vars unresolved callargs redefine)))
283 (unless (locate-library "cus-edit")
284 (error "You do not seem to have Custom installed.
285 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
286 You also then need to add the following to the lisp/dgnushack.el file:
288 (push \"~/lisp/custom\" load-path)
290 Modify to suit your needs."))
291 (let ((files (delete "dgnuspath.el"
292 (directory-files srcdir nil "^[^=].*\\.el$")))
293 (xemacs (string-match "XEmacs" emacs-version))
294 ;;(byte-compile-generate-call-tree t)
299 (dolist (file '("nnweb.el" "nnlistserv.el" "nnultimate.el"
300 "nnslashdot.el" "nnwarchive.el" "webmail.el"))
301 (setq files (delete file files)))))
304 (error (setq files (delete "gnus-bbdb.el" files))))
305 (while (setq file (pop files))
306 (unless (or (and (not xemacs)
308 '("gnus-xmas.el" "gnus-picon.el"
309 "messagexmas.el" "nnheaderxm.el"
310 "smiley.el" "x-overlay.el")))
311 (and (string-equal file "md5.el")
312 (not (and (fboundp 'md5)
313 (subrp (symbol-function 'md5))))))
314 (setq file (expand-file-name file srcdir))
315 (when (or (not (file-exists-p (setq elc (concat file "c"))))
316 (file-newer-than-file-p file elc))
318 (byte-compile-file file)))))))
320 (defun dgnushack-recompile ()
322 (byte-recompile-directory "." 0))
325 ;; Avoid byte-compile warnings.
326 (defvar gnus-product-name)
327 (defvar early-package-load-path)
328 (defvar early-packages)
329 (defvar last-package-load-path)
330 (defvar last-packages)
331 (defvar late-package-load-path)
332 (defvar late-packages)
334 (defconst dgnushack-info-file-regexp
335 (concat "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)"
336 "\\.info\\(-[0-9]+\\)?$"))
338 (defconst dgnushack-texi-file-regexp
339 "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)\\.texi$")
341 (defun dgnushack-make-package ()
343 (let* ((product-name (downcase gnus-product-name))
344 (lisp-dir (concat "lisp/" product-name "/"))
347 (message "Updating autoloads for directory %s..." default-directory)
348 (let ((generated-autoload-file "auto-autoloads.el")
350 (omsg (symbol-function 'message)))
351 (defun message (fmt &rest args)
352 (cond ((and (string-equal "Generating autoloads for %s..." fmt)
353 (file-exists-p (file-name-nondirectory (car args))))
354 (funcall omsg fmt (file-name-nondirectory (car args))))
355 ((string-equal "No autoloads found in %s" fmt))
356 ((string-equal "Generating autoloads for %s...done" fmt))
357 (t (apply omsg fmt args))))
359 (update-autoloads-from-directory default-directory)
360 (fset 'message omsg)))
361 (byte-compile-file "auto-autoloads.el")
364 (let ((standard-output (current-buffer)))
365 (Custom-make-dependencies "."))
366 (message (buffer-string)))
368 (byte-compile-file "custom-load.el")
370 (message "Generating MANIFEST.%s for the package..." product-name)
372 (insert "pkginfo/MANIFEST." product-name "\n"
376 (sort (delete "dgnuspath.el"
378 (directory-files "." nil "\\.elc?$")))
380 (concat "\n" lisp-dir))
384 (sort (directory-files "../texi/"
385 nil dgnushack-info-file-regexp)
389 (write-file (concat "../MANIFEST." product-name)))))
391 (defun dgnushack-install-package ()
392 (let ((package-dir (car command-line-args-left))
393 dirs info-dir pkginfo-dir product-name lisp-dir manifest files)
395 (when (boundp 'early-packages)
396 (setq dirs (delq nil (append (when early-package-load-path
398 (when late-package-load-path
400 (when last-package-load-path
402 (while (and dirs (not package-dir))
403 (when (file-exists-p (car dirs))
404 (setq package-dir (car dirs)
408 You must specify the name of the package path as follows:
410 % make install-package PACKAGEDIR=/usr/local/lib/xemacs/xemacs-packages
413 (setq info-dir (expand-file-name "info/" package-dir)
414 pkginfo-dir (expand-file-name "pkginfo/" package-dir))
416 (setq product-name (downcase gnus-product-name)
417 lisp-dir (expand-file-name (concat "lisp/" product-name "/")
419 manifest (concat "MANIFEST." product-name))
421 (unless (file-directory-p lisp-dir)
422 (make-directory lisp-dir t))
423 (unless (file-directory-p info-dir)
424 (make-directory info-dir))
425 (unless (file-directory-p pkginfo-dir)
426 (make-directory pkginfo-dir))
429 (sort (delete "dgnuspath.el"
430 (delete "dgnuspath.elc"
431 (directory-files "." nil "\\.elc?$")))
435 (unless (or (member file files)
436 (not (string-match "\\.elc?$" file)))
437 (setq file (expand-file-name file lisp-dir))
438 (message "Removing %s..." file)
442 (directory-files lisp-dir nil nil nil t))
445 (message "Copying %s to %s..." file lisp-dir)
446 (copy-file file (expand-file-name file lisp-dir) t t))
451 (message "Copying ../texi/%s to %s..." file info-dir)
452 (copy-file (expand-file-name file "../texi/")
453 (expand-file-name file info-dir)
455 (sort (directory-files "../texi/" nil dgnushack-info-file-regexp)
458 (message "Copying ../%s to %s..." manifest pkginfo-dir)
459 (copy-file (expand-file-name manifest "../")
460 (expand-file-name manifest pkginfo-dir) t t)
464 (defun dgnushack-texi-add-suffix-and-format ()
465 (dgnushack-texi-format t))
467 (defun dgnushack-texi-format (&optional addsuffix)
468 (if (not noninteractive)
469 (error "batch-texinfo-format may only be used -batch."))
471 (let ((auto-save-default nil)
472 (find-file-run-dired nil)
473 coding-system-for-write)
477 (while command-line-args-left
478 (setq file (expand-file-name (car command-line-args-left)))
479 (cond ((not (file-exists-p file))
480 (message ">> %s does not exist!" file)
482 command-line-args-left (cdr command-line-args-left)))
483 ((file-directory-p file)
484 (setq command-line-args-left
485 (nconc (directory-files file)
486 (cdr command-line-args-left))))
488 (setq files (cons file files)
489 command-line-args-left (cdr command-line-args-left)))))
491 (setq file (car files)
495 (if buffer-file-name (kill-buffer (current-buffer)))
497 (setq coding-system-for-write buffer-file-coding-system)
500 "^@setfilename[\t ]+\\([^\t\n ]+\\)" nil t)
501 (not (string-match "\\.info$" (match-string 1))))
503 (buffer-disable-undo (current-buffer))
504 ;; process @include before updating node
505 ;; This might produce some problem if we use @lowersection or
507 (let ((input-directory default-directory)
508 (texinfo-command-end))
509 (while (re-search-forward "^@include" nil t)
510 (setq texinfo-command-end (point))
511 (let ((filename (concat input-directory
512 (texinfo-parse-line-arg))))
513 (re-search-backward "^@include")
514 (delete-region (point) (save-excursion
517 (message "Reading included file: %s" filename)
523 (car (cdr (insert-file-contents filename)))))
524 (goto-char (point-min))
525 ;; Remove `@setfilename' line from included file,
526 ;; if any, so @setfilename command not duplicated.
527 (if (re-search-forward "^@setfilename"
534 (delete-region (point) (save-excursion
538 (texinfo-every-node-update)
539 (set-buffer-modified-p nil)
540 (message "texinfo formatting %s..." file)
541 (texinfo-format-buffer nil)
542 (if (buffer-modified-p)
543 (progn (message "Saving modified %s" (buffer-file-name))
546 (message ">> Error: %s" (prin1-to-string err))
547 (message ">> point at")
548 (let ((s (buffer-substring (point)
552 (while (setq tem (string-match "\n+" s tem))
553 (setq s (concat (substring s 0 (match-beginning 0))
555 (substring s (match-end 0)))
559 (kill-emacs error))))
561 ;;; dgnushack.el ends here