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 (defvar srcdir (or (getenv "srcdir") "."))
56 (push (or (getenv "W3DIR") (expand-file-name "../../w3/lisp/" srcdir))
58 (load (expand-file-name "dgnuspath.el" srcdir) nil nil t)
60 ;; If we are building w3 in a different directory than the source
61 ;; directory, we must read *.el from source directory and write *.elc
62 ;; into the building directory. For that, we define this function
63 ;; before loading bytecomp. Bytecomp doesn't overwrite this function.
64 (defun byte-compile-dest-file (filename)
65 "Convert an Emacs Lisp source file name to a compiled file name.
66 In addition, remove directory name part from FILENAME."
67 (setq filename (byte-compiler-base-file-name filename))
68 (setq filename (file-name-sans-versions filename))
69 (setq filename (file-name-nondirectory filename))
70 (if (memq system-type '(win32 w32 mswindows windows-nt))
71 (setq filename (downcase filename)))
72 (cond ((eq system-type 'vax-vms)
73 (concat (substring filename 0 (string-match ";" filename)) "c"))
74 ((string-match emacs-lisp-file-regexp filename)
75 (concat (substring filename 0 (match-beginning 0)) ".elc"))
76 (t (concat filename ".elc"))))
80 (unless (fboundp 'si:byte-optimize-form-code-walker)
81 (byte-optimize-form nil);; Load `byte-opt' or `byte-optimize'.
82 (setq max-specpdl-size 3000)
83 (fset 'si:byte-optimize-form-code-walker
84 (symbol-function 'byte-optimize-form-code-walker))
85 (defun byte-optimize-form-code-walker (form for-effect)
86 (if (and for-effect (memq (car-safe form) '(and or)))
87 ;; Fix bug in and/or forms.
89 (backwards (reverse (cdr form))))
91 (null (setcar backwards
92 (byte-optimize-form (car backwards) t))))
93 (setq backwards (cdr backwards)))
94 (if (and (cdr form) (null backwards))
96 " all subforms of %s called for effect; deleted" form))
98 (let ((head backwards))
99 (while (setq backwards (cdr backwards))
100 (setcar backwards (byte-optimize-form (car backwards)
102 (cons fn (nreverse head)))))
103 (si:byte-optimize-form-code-walker form for-effect)))
104 (byte-compile 'byte-optimize-form-code-walker))
106 (load (expand-file-name "gnus-clfns.el" srcdir) nil t t)
109 (load "~/.lpath.el" t nil t)
110 (error (message "Error in \"~/.lpath.el\" file: %s" err)))
114 (wrong-number-of-arguments
115 ;; Optimize byte code for `char-after'.
116 (put 'char-after 'byte-optimizer 'byte-optimize-char-after)
117 (defun byte-optimize-char-after (form)
118 (if (null (cdr form))
119 '(char-after (point))
125 (wrong-number-of-arguments
126 ;; Optimize byte code for `char-before'.
127 (put 'char-before 'byte-optimizer 'byte-optimize-char-before)
128 (defun byte-optimize-char-before (form)
129 (if (null (cdr form))
130 '(char-before (point))
134 ;; `char-after' and `char-before' must be well-behaved before lpath.el
135 ;; is loaded. Because it requires `poe' via `path-util'.
136 (load (expand-file-name "lpath.el" srcdir) nil t t)
138 (unless (fboundp 'byte-compile-file-form-custom-declare-variable)
139 ;; Bind defcustom'ed variables.
140 (put 'custom-declare-variable 'byte-hunk-handler
141 'byte-compile-file-form-custom-declare-variable)
142 (defun byte-compile-file-form-custom-declare-variable (form)
143 (if (memq 'free-vars byte-compile-warnings)
144 (setq byte-compile-bound-variables
145 (cons (nth 1 (nth 1 form)) byte-compile-bound-variables)))
148 ;; Bind functions defined by `defun-maybe'.
149 (put 'defun-maybe 'byte-hunk-handler 'byte-compile-file-form-defun-maybe)
150 (defun byte-compile-file-form-defun-maybe (form)
151 (if (and (not (fboundp (nth 1 form)))
152 (memq 'unresolved byte-compile-warnings))
153 (setq byte-compile-function-environment
154 (cons (cons (nth 1 form)
155 (cons 'lambda (cdr (cdr form))))
156 byte-compile-function-environment)))
160 :symbol-for-testing-whether-colon-keyword-is-available-or-not
163 (mapcar (lambda (keyword) (set keyword keyword))
164 '(:button-keymap :data :file :mime-handle))))
166 ;; Unknown variables and functions.
167 (unless (boundp 'buffer-file-coding-system)
168 (defvar buffer-file-coding-system (symbol-value 'file-coding-system)))
169 (unless (featurep 'xemacs)
170 (defalias 'Custom-make-dependencies 'ignore)
171 (defalias 'update-autoloads-from-directory 'ignore))
172 (autoload 'texinfo-parse-line-arg "texinfmt")
174 (unless (fboundp 'with-temp-buffer)
175 ;; Pickup some macros.
178 (defalias 'device-sound-enabled-p 'ignore)
179 (defalias 'play-sound-file 'ignore)
180 (defalias 'nndb-request-article 'ignore)
181 (defalias 'efs-re-read-dir 'ignore)
182 (defalias 'ange-ftp-re-read-dir 'ignore)
183 (defalias 'define-mail-user-agent 'ignore)
185 (defun dgnushack-compile (&optional warn)
186 ;;(setq byte-compile-dynamic t)
188 (setq byte-compile-warnings
189 '(free-vars unresolved callargs redefine)))
190 (unless (locate-library "cus-edit")
191 (error "You do not seem to have Custom installed.
192 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
193 You also then need to add the following to the lisp/dgnushack.el file:
195 (push \"~/lisp/custom\" load-path)
197 Modify to suit your needs."))
198 (let ((files (delete "dgnuspath.el"
199 (directory-files srcdir nil "^[^=].*\\.el$")))
200 (xemacs (string-match "XEmacs" emacs-version))
201 ;;(byte-compile-generate-call-tree t)
206 (dolist (file '("nnweb.el" "nnlistserv.el" "nnultimate.el"
207 "nnslashdot.el" "nnwarchive.el" "webmail.el"))
208 (setq files (delete file files)))))
211 (error (setq files (delete "gnus-bbdb.el" files))))
212 (while (setq file (pop files))
213 (unless (or (and (not xemacs)
215 '("gnus-xmas.el" "gnus-picon.el"
216 "messagexmas.el" "nnheaderxm.el"
217 "smiley.el" "x-overlay.el")))
218 (and (string-equal file "md5.el")
219 (not (and (fboundp 'md5)
220 (subrp (symbol-function 'md5))))))
221 (setq file (expand-file-name file srcdir))
222 (when (or (not (file-exists-p (setq elc (concat file "c"))))
223 (file-newer-than-file-p file elc))
225 (byte-compile-file file)))))))
227 (defun dgnushack-recompile ()
229 (byte-recompile-directory "." 0))
232 ;; Avoid byte-compile warnings.
233 (defvar gnus-product-name)
234 (defvar early-package-load-path)
235 (defvar early-packages)
236 (defvar last-package-load-path)
237 (defvar last-packages)
238 (defvar late-package-load-path)
239 (defvar late-packages)
241 (defconst dgnushack-info-file-regexp
242 (concat "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)"
243 "\\.info\\(-[0-9]+\\)?$"))
245 (defconst dgnushack-texi-file-regexp
246 "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)\\.texi$")
248 (defun dgnushack-make-package ()
250 (let* ((product-name (downcase gnus-product-name))
251 (lisp-dir (concat "lisp/" product-name "/"))
254 (message "Updating autoloads for directory %s..." default-directory)
255 (let ((generated-autoload-file "auto-autoloads.el")
257 (omsg (symbol-function 'message)))
258 (defun message (fmt &rest args)
259 (cond ((and (string-equal "Generating autoloads for %s..." fmt)
260 (file-exists-p (file-name-nondirectory (car args))))
261 (funcall omsg fmt (file-name-nondirectory (car args))))
262 ((string-equal "No autoloads found in %s" fmt))
263 ((string-equal "Generating autoloads for %s...done" fmt))
264 (t (apply omsg fmt args))))
266 (update-autoloads-from-directory default-directory)
267 (fset 'message omsg)))
268 (byte-compile-file "auto-autoloads.el")
271 (let ((standard-output (current-buffer)))
272 (Custom-make-dependencies "."))
273 (message "%s" (buffer-string)))
275 (byte-compile-file "custom-load.el")
277 (message "Generating MANIFEST.%s for the package..." product-name)
279 (insert "pkginfo/MANIFEST." product-name "\n"
283 (sort (delete "dgnuspath.el"
285 (directory-files "." nil "\\.elc?$")))
287 (concat "\n" lisp-dir))
291 (sort (directory-files "../texi/"
292 nil dgnushack-info-file-regexp)
296 (write-file (concat "../MANIFEST." product-name)))))
298 (defun dgnushack-install-package ()
299 (let ((package-dir (car command-line-args-left))
300 dirs info-dir pkginfo-dir product-name lisp-dir manifest files)
302 (when (boundp 'early-packages)
303 (setq dirs (delq nil (append (when early-package-load-path
305 (when late-package-load-path
307 (when last-package-load-path
309 (while (and dirs (not package-dir))
310 (when (file-exists-p (car dirs))
311 (setq package-dir (car dirs)
315 You must specify the name of the package path as follows:
317 % make install-package PACKAGEDIR=/usr/local/lib/xemacs/xemacs-packages
320 (setq info-dir (expand-file-name "info/" package-dir)
321 pkginfo-dir (expand-file-name "pkginfo/" package-dir))
323 (setq product-name (downcase gnus-product-name)
324 lisp-dir (expand-file-name (concat "lisp/" product-name "/")
326 manifest (concat "MANIFEST." product-name))
328 (unless (file-directory-p lisp-dir)
329 (make-directory lisp-dir t))
330 (unless (file-directory-p info-dir)
331 (make-directory info-dir))
332 (unless (file-directory-p pkginfo-dir)
333 (make-directory pkginfo-dir))
336 (sort (delete "dgnuspath.el"
337 (delete "dgnuspath.elc"
338 (directory-files "." nil "\\.elc?$")))
342 (unless (or (member file files)
343 (not (string-match "\\.elc?$" file)))
344 (setq file (expand-file-name file lisp-dir))
345 (message "Removing %s..." file)
349 (directory-files lisp-dir nil nil nil t))
352 (message "Copying %s to %s..." file lisp-dir)
353 (copy-file file (expand-file-name file lisp-dir) t t))
358 (message "Copying ../texi/%s to %s..." file info-dir)
359 (copy-file (expand-file-name file "../texi/")
360 (expand-file-name file info-dir)
362 (sort (directory-files "../texi/" nil dgnushack-info-file-regexp)
365 (message "Copying ../%s to %s..." manifest pkginfo-dir)
366 (copy-file (expand-file-name manifest "../")
367 (expand-file-name manifest pkginfo-dir) t t)
371 (defun dgnushack-texi-add-suffix-and-format ()
372 (dgnushack-texi-format t))
374 (defun dgnushack-texi-format (&optional addsuffix)
375 (if (not noninteractive)
376 (error "batch-texinfo-format may only be used -batch."))
378 (let ((auto-save-default nil)
379 (find-file-run-dired nil)
380 coding-system-for-write
381 output-coding-system)
385 (while command-line-args-left
386 (setq file (expand-file-name (car command-line-args-left)))
387 (cond ((not (file-exists-p file))
388 (message ">> %s does not exist!" file)
390 command-line-args-left (cdr command-line-args-left)))
391 ((file-directory-p file)
392 (setq command-line-args-left
393 (nconc (directory-files file)
394 (cdr command-line-args-left))))
396 (setq files (cons file files)
397 command-line-args-left (cdr command-line-args-left)))))
399 (setq file (car files)
403 (if buffer-file-name (kill-buffer (current-buffer)))
406 (setq output-coding-system (symbol-value
407 'file-coding-system))
408 (setq coding-system-for-write buffer-file-coding-system))
411 "^@setfilename[\t ]+\\([^\t\n ]+\\)" nil t)
412 (not (string-match "\\.info$" (match-string 1))))
414 (buffer-disable-undo (current-buffer))
415 ;; process @include before updating node
416 ;; This might produce some problem if we use @lowersection or
418 (let ((input-directory default-directory)
419 (texinfo-command-end))
420 (while (re-search-forward "^@include" nil t)
421 (setq texinfo-command-end (point))
422 (let ((filename (concat input-directory
423 (texinfo-parse-line-arg))))
424 (re-search-backward "^@include")
425 (delete-region (point) (save-excursion
428 (message "Reading included file: %s" filename)
434 (car (cdr (insert-file-contents filename)))))
435 (goto-char (point-min))
436 ;; Remove `@setfilename' line from included file,
437 ;; if any, so @setfilename command not duplicated.
438 (if (re-search-forward "^@setfilename"
445 (delete-region (point) (save-excursion
449 (texinfo-every-node-update)
450 (set-buffer-modified-p nil)
451 (message "texinfo formatting %s..." file)
452 (texinfo-format-buffer nil)
453 (if (buffer-modified-p)
454 (progn (message "Saving modified %s" (buffer-file-name))
457 (message ">> Error: %s" (prin1-to-string err))
458 (message ">> point at")
459 (let ((s (buffer-substring (point)
463 (while (setq tem (string-match "\n+" s tem))
464 (setq s (concat (substring s 0 (match-beginning 0))
466 (substring s (match-end 0)))
470 (kill-emacs error))))
472 ;; Mule-2.3@19.34 fails to make info from texi.
474 (put 'detailmenu 'texinfo-format 'texinfo-discard-line)
475 (put 'detailmenu 'texinfo-end 'texinfo-discard-command))
477 ;;; dgnushack.el ends here