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 (nconc (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 (nconc (delq 'coding-category-sjis coding-category-list)
48 '(coding-category-sjis))))))
54 (push "/usr/share/emacs/site-lisp" load-path)
56 (unless (featurep 'xemacs)
57 (define-compiler-macro last (&whole form x &optional n)
58 (if (and (fboundp 'last)
59 (subrp (symbol-function 'last)))
75 (while (consp (cdr x))
79 (define-compiler-macro mapcon (&whole form fn seq &rest rest)
80 (if (and (fboundp 'mapcon)
81 (subrp (symbol-function 'mapcon)))
85 (args (list ,seq ,@rest))
87 (while (not (memq nil args))
88 (push (apply ,fn args) res)
91 (setcar p (cdr (pop p)))
93 (apply (function nconc) (nreverse res)))
97 (push (funcall ,fn arg) res)
99 (apply (function nconc) (nreverse res))))))
101 (define-compiler-macro member-if (&whole form pred list)
102 (if (and (fboundp 'member-if)
103 (subrp (symbol-function 'member-if)))
108 (not (funcall fn (car seq))))
112 (define-compiler-macro union (&whole form list1 list2)
113 (if (and (fboundp 'union)
114 (subrp (symbol-function 'union)))
122 (or (>= (length a) (length b))
123 (setq a (prog1 b (setq b a))))
131 ;; If we are building w3 in a different directory than the source
132 ;; directory, we must read *.el from source directory and write *.elc
133 ;; into the building directory. For that, we define this function
134 ;; before loading bytecomp. Bytecomp doesn't overwrite this function.
135 (defun byte-compile-dest-file (filename)
136 "Convert an Emacs Lisp source file name to a compiled file name.
137 In addition, remove directory name part from FILENAME."
138 (setq filename (byte-compiler-base-file-name filename))
139 (setq filename (file-name-sans-versions filename))
140 (setq filename (file-name-nondirectory filename))
141 (if (memq system-type '(win32 w32 mswindows windows-nt))
142 (setq filename (downcase filename)))
143 (cond ((eq system-type 'vax-vms)
144 (concat (substring filename 0 (string-match ";" filename)) "c"))
145 ((string-match emacs-lisp-file-regexp filename)
146 (concat (substring filename 0 (match-beginning 0)) ".elc"))
147 (t (concat filename ".elc"))))
151 (unless (fboundp 'si:byte-optimize-form-code-walker)
152 (byte-optimize-form nil);; Load `byte-opt' or `byte-optimize'.
153 (setq max-specpdl-size 3000)
154 (fset 'si:byte-optimize-form-code-walker
155 (symbol-function 'byte-optimize-form-code-walker))
156 (defun byte-optimize-form-code-walker (form for-effect)
157 (if (and for-effect (memq (car-safe form) '(and or)))
158 ;; Fix bug in and/or forms.
159 (let ((fn (car form))
160 (backwards (reverse (cdr form))))
161 (while (and backwards
162 (null (setcar backwards
163 (byte-optimize-form (car backwards) t))))
164 (setq backwards (cdr backwards)))
165 (if (and (cdr form) (null backwards))
167 " all subforms of %s called for effect; deleted" form))
169 (let ((head backwards))
170 (while (setq backwards (cdr backwards))
171 (setcar backwards (byte-optimize-form (car backwards)
173 (cons fn (nreverse head)))))
174 (si:byte-optimize-form-code-walker form for-effect)))
175 (byte-compile 'byte-optimize-form-code-walker))
177 (defvar srcdir (or (getenv "srcdir") "."))
179 (load (expand-file-name "gnus-clfns.el" srcdir) nil t t)
181 ;(push "/usr/share/emacs/site-lisp" load-path)
183 ;; Attempt to pickup the additional load-path(s).
184 (load (expand-file-name "dgnuspath.el" srcdir) nil nil t)
186 (load "~/.lpath.el" t nil t)
187 (error (message "Error in \"~/.lpath.el\" file: %s" err)))
191 (wrong-number-of-arguments
192 ;; Optimize byte code for `char-after'.
193 (put 'char-after 'byte-optimizer 'byte-optimize-char-after)
194 (defun byte-optimize-char-after (form)
195 (if (null (cdr form))
196 '(char-after (point))
202 (wrong-number-of-arguments
203 ;; Optimize byte code for `char-before'.
204 (put 'char-before 'byte-optimizer 'byte-optimize-char-before)
205 (defun byte-optimize-char-before (form)
206 (if (null (cdr form))
207 '(char-before (point))
211 ;; `char-after' and `char-before' must be well-behaved before lpath.el
212 ;; is loaded. Because it requires `poe' via `path-util'.
213 (load (expand-file-name "lpath.el" srcdir) nil t t)
215 (unless (fboundp 'byte-compile-file-form-custom-declare-variable)
216 ;; Bind defcustom'ed variables.
217 (put 'custom-declare-variable 'byte-hunk-handler
218 'byte-compile-file-form-custom-declare-variable)
219 (defun byte-compile-file-form-custom-declare-variable (form)
220 (if (memq 'free-vars byte-compile-warnings)
221 (setq byte-compile-bound-variables
222 (cons (nth 1 (nth 1 form)) byte-compile-bound-variables)))
225 ;; Bind functions defined by `defun-maybe'.
226 (put 'defun-maybe 'byte-hunk-handler 'byte-compile-file-form-defun-maybe)
227 (defun byte-compile-file-form-defun-maybe (form)
228 (if (and (not (fboundp (nth 1 form)))
229 (memq 'unresolved byte-compile-warnings))
230 (setq byte-compile-function-environment
231 (cons (cons (nth 1 form)
232 (cons 'lambda (cdr (cdr form))))
233 byte-compile-function-environment)))
237 :symbol-for-testing-whether-colon-keyword-is-available-or-not
240 (mapcar (lambda (keyword) (set keyword keyword))
241 '(:button-keymap :data :file :mime-handle))))
243 ;; Unknown variables and functions.
244 (unless (boundp 'buffer-file-coding-system)
245 (defvar buffer-file-coding-system (symbol-value 'file-coding-system)))
246 (unless (featurep 'xemacs)
247 (defalias 'Custom-make-dependencies 'ignore)
248 (defalias 'update-autoloads-from-directory 'ignore))
249 (autoload 'texinfo-parse-line-arg "texinfmt")
251 (unless (fboundp 'with-temp-buffer)
252 ;; Pickup some macros.
255 (defalias 'device-sound-enabled-p 'ignore)
256 (defalias 'play-sound-file 'ignore)
257 (defalias 'nndb-request-article 'ignore)
258 (defalias 'efs-re-read-dir 'ignore)
259 (defalias 'ange-ftp-re-read-dir 'ignore)
260 (defalias 'define-mail-user-agent 'ignore)
262 (defun dgnushack-compile (&optional warn)
263 ;;(setq byte-compile-dynamic t)
265 (setq byte-compile-warnings
266 '(free-vars unresolved callargs redefine)))
267 (unless (locate-library "cus-edit")
268 (error "You do not seem to have Custom installed.
269 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
270 You also then need to add the following to the lisp/dgnushack.el file:
272 (push \"~/lisp/custom\" load-path)
274 Modify to suit your needs."))
275 (let ((files (delete "dgnuspath.el"
276 (directory-files srcdir nil "^[^=].*\\.el$")))
277 (xemacs (string-match "XEmacs" emacs-version))
278 ;;(byte-compile-generate-call-tree t)
283 (dolist (file '("nnweb.el" "nnlistserv.el" "nnultimate.el"
284 "nnslashdot.el" "nnwarchive.el" "webmail.el"))
285 (setq files (delete file files)))))
288 (error (setq files (delete "gnus-bbdb.el" files))))
289 (while (setq file (pop files))
290 (unless (or (and (not xemacs)
292 '("gnus-xmas.el" "gnus-picon.el"
293 "messagexmas.el" "nnheaderxm.el"
294 "smiley.el" "x-overlay.el")))
295 (and (string-equal file "md5.el")
296 (not (and (fboundp 'md5)
297 (subrp (symbol-function 'md5))))))
298 (setq file (expand-file-name file srcdir))
299 (when (or (not (file-exists-p (setq elc (concat file "c"))))
300 (file-newer-than-file-p file elc))
302 (byte-compile-file file)))))))
304 (defun dgnushack-recompile ()
306 (byte-recompile-directory "." 0))
309 ;; Avoid byte-compile warnings.
310 (defvar gnus-product-name)
311 (defvar early-package-load-path)
312 (defvar early-packages)
313 (defvar last-package-load-path)
314 (defvar last-packages)
315 (defvar late-package-load-path)
316 (defvar late-packages)
318 (defconst dgnushack-info-file-regexp
319 (concat "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)"
320 "\\.info\\(-[0-9]+\\)?$"))
322 (defconst dgnushack-texi-file-regexp
323 "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)\\.texi$")
325 (defun dgnushack-make-package ()
327 (let* ((product-name (downcase gnus-product-name))
328 (lisp-dir (concat "lisp/" product-name "/"))
331 (message "Updating autoloads for directory %s..." default-directory)
332 (let ((generated-autoload-file "auto-autoloads.el")
334 (omsg (symbol-function 'message)))
335 (defun message (fmt &rest args)
336 (cond ((and (string-equal "Generating autoloads for %s..." fmt)
337 (file-exists-p (file-name-nondirectory (car args))))
338 (funcall omsg fmt (file-name-nondirectory (car args))))
339 ((string-equal "No autoloads found in %s" fmt))
340 ((string-equal "Generating autoloads for %s...done" fmt))
341 (t (apply omsg fmt args))))
343 (update-autoloads-from-directory default-directory)
344 (fset 'message omsg)))
345 (byte-compile-file "auto-autoloads.el")
348 (let ((standard-output (current-buffer)))
349 (Custom-make-dependencies "."))
350 (message "%s" (buffer-string)))
352 (byte-compile-file "custom-load.el")
354 (message "Generating MANIFEST.%s for the package..." product-name)
356 (insert "pkginfo/MANIFEST." product-name "\n"
360 (sort (delete "dgnuspath.el"
362 (directory-files "." nil "\\.elc?$")))
364 (concat "\n" lisp-dir))
368 (sort (directory-files "../texi/"
369 nil dgnushack-info-file-regexp)
373 (write-file (concat "../MANIFEST." product-name)))))
375 (defun dgnushack-install-package ()
376 (let ((package-dir (car command-line-args-left))
377 dirs info-dir pkginfo-dir product-name lisp-dir manifest files)
379 (when (boundp 'early-packages)
380 (setq dirs (delq nil (append (when early-package-load-path
382 (when late-package-load-path
384 (when last-package-load-path
386 (while (and dirs (not package-dir))
387 (when (file-exists-p (car dirs))
388 (setq package-dir (car dirs)
392 You must specify the name of the package path as follows:
394 % make install-package PACKAGEDIR=/usr/local/lib/xemacs/xemacs-packages
397 (setq info-dir (expand-file-name "info/" package-dir)
398 pkginfo-dir (expand-file-name "pkginfo/" package-dir))
400 (setq product-name (downcase gnus-product-name)
401 lisp-dir (expand-file-name (concat "lisp/" product-name "/")
403 manifest (concat "MANIFEST." product-name))
405 (unless (file-directory-p lisp-dir)
406 (make-directory lisp-dir t))
407 (unless (file-directory-p info-dir)
408 (make-directory info-dir))
409 (unless (file-directory-p pkginfo-dir)
410 (make-directory pkginfo-dir))
413 (sort (delete "dgnuspath.el"
414 (delete "dgnuspath.elc"
415 (directory-files "." nil "\\.elc?$")))
419 (unless (or (member file files)
420 (not (string-match "\\.elc?$" file)))
421 (setq file (expand-file-name file lisp-dir))
422 (message "Removing %s..." file)
426 (directory-files lisp-dir nil nil nil t))
429 (message "Copying %s to %s..." file lisp-dir)
430 (copy-file file (expand-file-name file lisp-dir) t t))
435 (message "Copying ../texi/%s to %s..." file info-dir)
436 (copy-file (expand-file-name file "../texi/")
437 (expand-file-name file info-dir)
439 (sort (directory-files "../texi/" nil dgnushack-info-file-regexp)
442 (message "Copying ../%s to %s..." manifest pkginfo-dir)
443 (copy-file (expand-file-name manifest "../")
444 (expand-file-name manifest pkginfo-dir) t t)
448 (defun dgnushack-texi-add-suffix-and-format ()
449 (dgnushack-texi-format t))
451 (defun dgnushack-texi-format (&optional addsuffix)
452 (if (not noninteractive)
453 (error "batch-texinfo-format may only be used -batch."))
455 (let ((auto-save-default nil)
456 (find-file-run-dired nil)
457 coding-system-for-write)
461 (while command-line-args-left
462 (setq file (expand-file-name (car command-line-args-left)))
463 (cond ((not (file-exists-p file))
464 (message ">> %s does not exist!" file)
466 command-line-args-left (cdr command-line-args-left)))
467 ((file-directory-p file)
468 (setq command-line-args-left
469 (nconc (directory-files file)
470 (cdr command-line-args-left))))
472 (setq files (cons file files)
473 command-line-args-left (cdr command-line-args-left)))))
475 (setq file (car files)
479 (if buffer-file-name (kill-buffer (current-buffer)))
481 (setq coding-system-for-write buffer-file-coding-system)
484 "^@setfilename[\t ]+\\([^\t\n ]+\\)" nil t)
485 (not (string-match "\\.info$" (match-string 1))))
487 (buffer-disable-undo (current-buffer))
488 ;; process @include before updating node
489 ;; This might produce some problem if we use @lowersection or
491 (let ((input-directory default-directory)
492 (texinfo-command-end))
493 (while (re-search-forward "^@include" nil t)
494 (setq texinfo-command-end (point))
495 (let ((filename (concat input-directory
496 (texinfo-parse-line-arg))))
497 (re-search-backward "^@include")
498 (delete-region (point) (save-excursion
501 (message "Reading included file: %s" filename)
507 (car (cdr (insert-file-contents filename)))))
508 (goto-char (point-min))
509 ;; Remove `@setfilename' line from included file,
510 ;; if any, so @setfilename command not duplicated.
511 (if (re-search-forward "^@setfilename"
518 (delete-region (point) (save-excursion
522 (texinfo-every-node-update)
523 (set-buffer-modified-p nil)
524 (message "texinfo formatting %s..." file)
525 (texinfo-format-buffer nil)
526 (if (buffer-modified-p)
527 (progn (message "Saving modified %s" (buffer-file-name))
530 (message ">> Error: %s" (prin1-to-string err))
531 (message ">> point at")
532 (let ((s (buffer-substring (point)
536 (while (setq tem (string-match "\n+" s tem))
537 (setq s (concat (substring s 0 (match-beginning 0))
539 (substring s (match-end 0)))
543 (kill-emacs error))))
545 ;;; dgnushack.el ends here