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))))))
54 (define-compiler-macro mapc (&whole form fn seq &rest rest)
55 (if (and (fboundp 'mapc)
56 (subrp (symbol-function 'mapc)))
61 (args (list seq ,@rest))
62 (m (apply (function min) (mapcar (function length) args)))
65 (apply fn (mapcar (function (lambda (arg) (nth n arg))) args))
72 (define-compiler-macro last (&whole form x &optional n)
73 (if (and (fboundp 'last)
74 (subrp (symbol-function 'last)))
90 (while (consp (cdr x))
94 (define-compiler-macro mapcon (&whole form fn seq &rest rest)
95 (if (and (fboundp 'mapcon)
96 (subrp (symbol-function 'mapcon)))
100 (args (list ,seq ,@rest))
102 (while (not (memq nil args))
103 (push (apply ,fn args) res)
106 (setcar p (cdr (pop p)))
108 (apply (function nconc) (nreverse res)))
112 (push (funcall ,fn arg) res)
113 (setq arg (cdr arg)))
114 (apply (function nconc) (nreverse res))))))
116 ;; If we are building w3 in a different directory than the source
117 ;; directory, we must read *.el from source directory and write *.elc
118 ;; into the building directory. For that, we define this function
119 ;; before loading bytecomp. Bytecomp doesn't overwrite this function.
120 (defun byte-compile-dest-file (filename)
121 "Convert an Emacs Lisp source file name to a compiled file name.
122 In addition, remove directory name part from FILENAME."
123 (setq filename (byte-compiler-base-file-name filename))
124 (setq filename (file-name-sans-versions filename))
125 (setq filename (file-name-nondirectory filename))
126 (if (memq system-type '(win32 w32 mswindows windows-nt))
127 (setq filename (downcase filename)))
128 (cond ((eq system-type 'vax-vms)
129 (concat (substring filename 0 (string-match ";" filename)) "c"))
130 ((string-match emacs-lisp-file-regexp filename)
131 (concat (substring filename 0 (match-beginning 0)) ".elc"))
132 (t (concat filename ".elc"))))
136 (unless (fboundp 'si:byte-optimize-form-code-walker)
137 (byte-optimize-form nil);; Load `byte-opt' or `byte-optimize'.
138 (setq max-specpdl-size 3000)
139 (fset 'si:byte-optimize-form-code-walker
140 (symbol-function 'byte-optimize-form-code-walker))
141 (defun byte-optimize-form-code-walker (form for-effect)
142 (if (and for-effect (memq (car-safe form) '(and or)))
143 ;; Fix bug in and/or forms.
144 (let ((fn (car form))
145 (backwards (reverse (cdr form))))
146 (while (and backwards
147 (null (setcar backwards
148 (byte-optimize-form (car backwards) t))))
149 (setq backwards (cdr backwards)))
150 (if (and (cdr form) (null backwards))
152 " all subforms of %s called for effect; deleted" form))
154 (let ((head backwards))
155 (while (setq backwards (cdr backwards))
156 (setcar backwards (byte-optimize-form (car backwards)
158 (cons fn (nreverse head)))))
159 (si:byte-optimize-form-code-walker form for-effect)))
160 (byte-compile 'byte-optimize-form-code-walker))
162 (defvar srcdir (or (getenv "srcdir") "."))
164 ;(push "/usr/share/emacs/site-lisp" load-path)
166 ;; Attempt to pickup the additional load-path(s).
167 (load (expand-file-name "dgnuspath.el" srcdir) nil nil t)
169 (load "~/.lpath.el" t nil t)
170 (error (message "Error in \"~/.lpath.el\" file: %s" err)))
174 (wrong-number-of-arguments
175 ;; Optimize byte code for `char-after'.
176 (put 'char-after 'byte-optimizer 'byte-optimize-char-after)
177 (defun byte-optimize-char-after (form)
178 (if (null (cdr form))
179 '(char-after (point))
185 (wrong-number-of-arguments
186 (define-compiler-macro char-before (&whole form &optional pos)
188 '(char-before (point))
191 ;; `char-after' and `char-before' must be well-behaved before lpath.el
192 ;; is loaded. Because it requires `poe' via `path-util'.
193 (load (expand-file-name "lpath.el" srcdir) nil t t)
195 (unless (fboundp 'byte-compile-file-form-custom-declare-variable)
196 ;; Bind defcustom'ed variables.
197 (put 'custom-declare-variable 'byte-hunk-handler
198 'byte-compile-file-form-custom-declare-variable)
199 (defun byte-compile-file-form-custom-declare-variable (form)
200 (if (memq 'free-vars byte-compile-warnings)
201 (setq byte-compile-bound-variables
202 (cons (nth 1 (nth 1 form)) byte-compile-bound-variables)))
205 ;; Bind functions defined by `defun-maybe'.
206 (put 'defun-maybe 'byte-hunk-handler 'byte-compile-file-form-defun-maybe)
207 (defun byte-compile-file-form-defun-maybe (form)
208 (if (and (not (fboundp (nth 1 form)))
209 (memq 'unresolved byte-compile-warnings))
210 (setq byte-compile-function-environment
211 (cons (cons (nth 1 form)
212 (cons 'lambda (cdr (cdr form))))
213 byte-compile-function-environment)))
217 :symbol-for-testing-whether-colon-keyword-is-available-or-not
220 (mapcar (lambda (keyword) (set keyword keyword))
221 '(:button-keymap :data :file :mime-handle))))
223 ;; Unknown variables and functions.
224 (unless (boundp 'buffer-file-coding-system)
225 (defvar buffer-file-coding-system (symbol-value 'file-coding-system)))
226 (autoload 'font-lock-set-defaults "font-lock")
227 (unless (fboundp 'coding-system-get)
228 (defalias 'coding-system-get 'ignore))
230 (defalias 'find-coding-system 'ignore))
231 (unless (fboundp 'get-charset-property)
232 (defalias 'get-charset-property 'ignore))
233 (unless (featurep 'xemacs)
234 (defalias 'Custom-make-dependencies 'ignore)
235 (defalias 'toolbar-gnus 'ignore)
236 (defalias 'update-autoloads-from-directory 'ignore))
237 (autoload 'texinfo-parse-line-arg "texinfmt")
239 (unless (fboundp 'with-temp-buffer)
240 ;; Pickup some macros.
243 (defalias 'device-sound-enabled-p 'ignore)
244 (defalias 'play-sound-file 'ignore)
245 (defalias 'nndb-request-article 'ignore)
246 (defalias 'efs-re-read-dir 'ignore)
247 (defalias 'ange-ftp-re-read-dir 'ignore)
248 (defalias 'define-mail-user-agent 'ignore)
251 (unless (string-match "XEmacs" emacs-version)
252 (fset 'get-popup-menu-response 'ignore)
253 (fset 'event-object 'ignore)
254 (fset 'x-defined-colors 'ignore)
255 (fset 'read-color 'ignore)))
257 (defun dgnushack-compile (&optional warn)
258 ;;(setq byte-compile-dynamic t)
260 (setq byte-compile-warnings
261 '(free-vars unresolved callargs redefine)))
262 (unless (locate-library "cus-edit")
263 (error "You do not seem to have Custom installed.
264 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
265 You also then need to add the following to the lisp/dgnushack.el file:
267 (push \"~/lisp/custom\" load-path)
269 Modify to suit your needs."))
270 (let ((files (delete "dgnuspath.el"
271 (directory-files srcdir nil "^[^=].*\\.el$")))
272 (xemacs (string-match "XEmacs" emacs-version))
273 ;;(byte-compile-generate-call-tree t)
278 (dolist (file '("nnweb.el" "nnlistserv.el" "nnultimate.el"
279 "nnslashdot.el" "nnwarchive.el" "webmail.el"))
280 (setq files (delete file files)))))
283 (error (setq files (delete "gnus-bbdb.el" files))))
284 (while (setq file (pop files))
285 (unless (or (and (not xemacs)
287 '("gnus-xmas.el" "gnus-picon.el"
288 "messagexmas.el" "nnheaderxm.el"
289 "smiley.el" "x-overlay.el")))
290 (and (string-equal file "md5.el")
291 (not (and (fboundp 'md5)
292 (subrp (symbol-function 'md5))))))
293 (setq file (expand-file-name file srcdir))
294 (when (or (not (file-exists-p (setq elc (concat file "c"))))
295 (file-newer-than-file-p file elc))
297 (byte-compile-file file)))))))
299 (defun dgnushack-recompile ()
301 (byte-recompile-directory "." 0))
304 ;; Avoid byte-compile warnings.
305 (defvar gnus-product-name)
306 (defvar early-package-load-path)
307 (defvar early-packages)
308 (defvar last-package-load-path)
309 (defvar last-packages)
310 (defvar late-package-load-path)
311 (defvar late-packages)
313 (defconst dgnushack-info-file-regexp
314 (concat "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)"
315 "\\.info\\(-[0-9]+\\)?$"))
317 (defconst dgnushack-texi-file-regexp
318 "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)\\.texi$")
320 (defun dgnushack-make-package ()
322 (let* ((product-name (downcase gnus-product-name))
323 (lisp-dir (concat "lisp/" product-name "/"))
326 (message "Updating autoloads for directory %s..." default-directory)
327 (let ((generated-autoload-file "auto-autoloads.el")
329 (omsg (symbol-function 'message)))
330 (defun message (fmt &rest args)
331 (cond ((and (string-equal "Generating autoloads for %s..." fmt)
332 (file-exists-p (file-name-nondirectory (car args))))
333 (funcall omsg fmt (file-name-nondirectory (car args))))
334 ((string-equal "No autoloads found in %s" fmt))
335 ((string-equal "Generating autoloads for %s...done" fmt))
336 (t (apply omsg fmt args))))
338 (update-autoloads-from-directory default-directory)
339 (fset 'message omsg)))
340 (byte-compile-file "auto-autoloads.el")
343 (let ((standard-output (current-buffer)))
344 (Custom-make-dependencies "."))
345 (message (buffer-string)))
347 (byte-compile-file "custom-load.el")
349 (message "Generating MANIFEST.%s for the package..." product-name)
351 (insert "pkginfo/MANIFEST." product-name "\n"
355 (sort (delete "dgnuspath.el"
357 (directory-files "." nil "\\.elc?$")))
359 (concat "\n" lisp-dir))
363 (sort (directory-files "../texi/"
364 nil dgnushack-info-file-regexp)
368 (write-file (concat "../MANIFEST." product-name)))))
370 (defun dgnushack-install-package ()
371 (let ((package-dir (car command-line-args-left))
372 dirs info-dir pkginfo-dir product-name lisp-dir manifest files)
374 (when (boundp 'early-packages)
375 (setq dirs (delq nil (append (when early-package-load-path
377 (when late-package-load-path
379 (when last-package-load-path
381 (while (and dirs (not package-dir))
382 (when (file-exists-p (car dirs))
383 (setq package-dir (car dirs)
387 You must specify the name of the package path as follows:
389 % make install-package PACKAGEDIR=/usr/local/lib/xemacs/xemacs-packages
392 (setq info-dir (expand-file-name "info/" package-dir)
393 pkginfo-dir (expand-file-name "pkginfo/" package-dir))
395 (setq product-name (downcase gnus-product-name)
396 lisp-dir (expand-file-name (concat "lisp/" product-name "/")
398 manifest (concat "MANIFEST." product-name))
400 (unless (file-directory-p lisp-dir)
401 (make-directory lisp-dir t))
402 (unless (file-directory-p info-dir)
403 (make-directory info-dir))
404 (unless (file-directory-p pkginfo-dir)
405 (make-directory pkginfo-dir))
408 (sort (delete "dgnuspath.el"
409 (delete "dgnuspath.elc"
410 (directory-files "." nil "\\.elc?$")))
414 (unless (or (member file files)
415 (not (string-match "\\.elc?$" file)))
416 (setq file (expand-file-name file lisp-dir))
417 (message "Removing %s..." file)
421 (directory-files lisp-dir nil nil nil t))
424 (message "Copying %s to %s..." file lisp-dir)
425 (copy-file file (expand-file-name file lisp-dir) t t))
430 (message "Copying ../texi/%s to %s..." file info-dir)
431 (copy-file (expand-file-name file "../texi/")
432 (expand-file-name file info-dir)
434 (sort (directory-files "../texi/" nil dgnushack-info-file-regexp)
437 (message "Copying ../%s to %s..." manifest pkginfo-dir)
438 (copy-file (expand-file-name manifest "../")
439 (expand-file-name manifest pkginfo-dir) t t)
443 (defun dgnushack-texi-add-suffix-and-format ()
444 (dgnushack-texi-format t))
446 (defun dgnushack-texi-format (&optional addsuffix)
447 (if (not noninteractive)
448 (error "batch-texinfo-format may only be used -batch."))
450 (let ((auto-save-default nil)
451 (find-file-run-dired nil)
452 coding-system-for-write)
456 (while command-line-args-left
457 (setq file (expand-file-name (car command-line-args-left)))
458 (cond ((not (file-exists-p file))
459 (message ">> %s does not exist!" file)
461 command-line-args-left (cdr command-line-args-left)))
462 ((file-directory-p file)
463 (setq command-line-args-left
464 (nconc (directory-files file)
465 (cdr command-line-args-left))))
467 (setq files (cons file files)
468 command-line-args-left (cdr command-line-args-left)))))
470 (setq file (car files)
474 (if buffer-file-name (kill-buffer (current-buffer)))
476 (setq coding-system-for-write buffer-file-coding-system)
479 "^@setfilename[\t ]+\\([^\t\n ]+\\)" nil t)
480 (not (string-match "\\.info$" (match-string 1))))
482 (buffer-disable-undo (current-buffer))
483 ;; process @include before updating node
484 ;; This might produce some problem if we use @lowersection or
486 (let ((input-directory default-directory)
487 (texinfo-command-end))
488 (while (re-search-forward "^@include" nil t)
489 (setq texinfo-command-end (point))
490 (let ((filename (concat input-directory
491 (texinfo-parse-line-arg))))
492 (re-search-backward "^@include")
493 (delete-region (point) (save-excursion
496 (message "Reading included file: %s" filename)
502 (car (cdr (insert-file-contents filename)))))
503 (goto-char (point-min))
504 ;; Remove `@setfilename' line from included file,
505 ;; if any, so @setfilename command not duplicated.
506 (if (re-search-forward "^@setfilename"
513 (delete-region (point) (save-excursion
517 (texinfo-every-node-update)
518 (set-buffer-modified-p nil)
519 (message "texinfo formatting %s..." file)
520 (texinfo-format-buffer nil)
521 (if (buffer-modified-p)
522 (progn (message "Saving modified %s" (buffer-file-name))
525 (message ">> Error: %s" (prin1-to-string err))
526 (message ">> point at")
527 (let ((s (buffer-substring (point)
531 (while (setq tem (string-match "\n+" s tem))
532 (setq s (concat (substring s 0 (match-beginning 0))
534 (substring s (match-end 0)))
538 (kill-emacs error))))
540 ;;; dgnushack.el ends here