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 (push srcdir load-path)
137 ;; `char-after' and `char-before' must be well-behaved before lpath.el
138 ;; is loaded. Because it requires `poe' via `path-util'.
139 (load (expand-file-name "lpath.el" srcdir) nil t t)
141 (unless (fboundp 'byte-compile-file-form-custom-declare-variable)
142 ;; Bind defcustom'ed variables.
143 (put 'custom-declare-variable 'byte-hunk-handler
144 'byte-compile-file-form-custom-declare-variable)
145 (defun byte-compile-file-form-custom-declare-variable (form)
146 (if (memq 'free-vars byte-compile-warnings)
147 (setq byte-compile-bound-variables
148 (cons (nth 1 (nth 1 form)) byte-compile-bound-variables)))
151 ;; Bind functions defined by `defun-maybe'.
152 (put 'defun-maybe 'byte-hunk-handler 'byte-compile-file-form-defun-maybe)
153 (defun byte-compile-file-form-defun-maybe (form)
154 (if (and (not (fboundp (nth 1 form)))
155 (memq 'unresolved byte-compile-warnings))
156 (setq byte-compile-function-environment
157 (cons (cons (nth 1 form)
158 (cons 'lambda (cdr (cdr form))))
159 byte-compile-function-environment)))
163 :symbol-for-testing-whether-colon-keyword-is-available-or-not
166 (mapcar (lambda (keyword) (set keyword keyword))
167 '(:button-keymap :data :file :mime-handle))))
169 ;; Unknown variables and functions.
170 (unless (boundp 'buffer-file-coding-system)
171 (defvar buffer-file-coding-system (symbol-value 'file-coding-system)))
172 (unless (featurep 'xemacs)
173 (defalias 'Custom-make-dependencies 'ignore)
174 (defalias 'update-autoloads-from-directory 'ignore))
175 (autoload 'texinfo-parse-line-arg "texinfmt")
177 (unless (fboundp 'with-temp-buffer)
178 ;; Pickup some macros.
181 (defalias 'device-sound-enabled-p 'ignore)
182 (defalias 'play-sound-file 'ignore)
183 (defalias 'nndb-request-article 'ignore)
184 (defalias 'efs-re-read-dir 'ignore)
185 (defalias 'ange-ftp-re-read-dir 'ignore)
186 (defalias 'define-mail-user-agent 'ignore)
188 (defconst dgnushack-tool-files
189 '("dgnushack.el" "dgnuspath.el" "lpath.el" "ptexinfmt.el"))
190 (defconst dgnushack-unexported-files
191 '("dgnuspath.el" "ptexinfmt.el"))
193 (defun dgnushack-compile (&optional warn)
194 ;;(setq byte-compile-dynamic t)
196 (setq byte-compile-warnings
197 '(free-vars unresolved callargs redefine)))
198 (unless (locate-library "cus-edit")
199 (error "You do not seem to have Custom installed.
200 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
201 You also then need to add the following to the lisp/dgnushack.el file:
203 (push \"~/lisp/custom\" load-path)
205 Modify to suit your needs."))
206 (let ((files (directory-files srcdir nil "^[^=].*\\.el$"))
207 ;;(byte-compile-generate-call-tree t)
210 (lambda (el) (setq files (delete el files)))
214 (progn (require 'w3-forms) nil)
215 (error '("nnweb.el" "nnlistserv.el" "nnultimate.el"
216 "nnslashdot.el" "nnwarchive.el" "webmail.el")))
218 (progn (require 'bbdb) nil)
219 (error '("gnus-bbdb.el")))
220 (unless (featurep 'xemacs)
221 '("gnus-xmas.el" "gnus-picon.el" "messagexmas.el"
222 "nnheaderxm.el" "smiley.el"))
223 (when (or (featurep 'xemacs) (<= emacs-major-version 20))
225 (when (and (fboundp 'md5) (subrp (symbol-function 'md5)))
227 (while (setq file (pop files))
228 (setq file (expand-file-name file srcdir))
229 (when (or (not (file-exists-p (setq elc (concat file "c"))))
230 (file-newer-than-file-p file elc))
232 (byte-compile-file file))))))
234 (defun dgnushack-recompile ()
236 (byte-recompile-directory "." 0))
239 ;; Avoid byte-compile warnings.
240 (defvar gnus-product-name)
241 (defvar early-package-load-path)
242 (defvar early-packages)
243 (defvar last-package-load-path)
244 (defvar last-packages)
245 (defvar late-package-load-path)
246 (defvar late-packages)
248 (defconst dgnushack-info-file-regexp
249 (concat "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)"
250 "\\.info\\(-[0-9]+\\)?$"))
252 (defconst dgnushack-texi-file-regexp
253 "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)\\.texi$")
255 (defun dgnushack-make-package ()
257 (let* ((product-name (downcase gnus-product-name))
258 (lisp-dir (concat "lisp/" product-name "/"))
261 (message "Updating autoloads for directory %s..." default-directory)
262 (let ((generated-autoload-file "auto-autoloads.el")
264 (omsg (symbol-function 'message)))
265 (defun message (fmt &rest args)
266 (cond ((and (string-equal "Generating autoloads for %s..." fmt)
267 (file-exists-p (file-name-nondirectory (car args))))
268 (funcall omsg fmt (file-name-nondirectory (car args))))
269 ((string-equal "No autoloads found in %s" fmt))
270 ((string-equal "Generating autoloads for %s...done" fmt))
271 (t (apply omsg fmt args))))
273 (update-autoloads-from-directory default-directory)
274 (fset 'message omsg)))
275 (byte-compile-file "auto-autoloads.el")
278 (let ((standard-output (current-buffer)))
279 (Custom-make-dependencies "."))
280 (message "%s" (buffer-string)))
282 (byte-compile-file "custom-load.el")
284 (message "Generating MANIFEST.%s for the package..." product-name)
286 (insert "pkginfo/MANIFEST." product-name "\n")
289 (unless (member file dgnushack-unexported-files)
290 (insert lisp-dir file "\n")))
291 (sort (directory-files "." nil "\\.elc?$") 'string-lessp))
293 (lambda (file) (insert "info/" file "\n"))
294 (sort (directory-files "../texi/" 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))
335 (setq files (sort (directory-files "." nil "\\.elc?$") 'string-lessp))
336 (mapcar (lambda (el) (setq files (delete el files)))
337 dgnushack-unexported-files)
340 (unless (or (member file files)
341 (not (string-match "\\.elc?$" file)))
342 (setq file (expand-file-name file lisp-dir))
343 (message "Removing %s..." file)
347 (directory-files lisp-dir nil nil nil t))
350 (message "Copying %s to %s..." file lisp-dir)
351 (copy-file file (expand-file-name file lisp-dir) t t))
356 (message "Copying ../texi/%s to %s..." file info-dir)
357 (copy-file (expand-file-name file "../texi/")
358 (expand-file-name file info-dir)
360 (sort (directory-files "../texi/" nil dgnushack-info-file-regexp)
363 (message "Copying ../%s to %s..." manifest pkginfo-dir)
364 (copy-file (expand-file-name manifest "../")
365 (expand-file-name manifest pkginfo-dir) t t)
369 (defun dgnushack-texi-add-suffix-and-format ()
370 (dgnushack-texi-format t))
372 (defun dgnushack-texi-format (&optional addsuffix)
373 (if (not noninteractive)
374 (error "batch-texinfo-format may only be used -batch."))
376 (let ((auto-save-default nil)
377 (find-file-run-dired nil)
378 coding-system-for-write
379 output-coding-system)
383 (while command-line-args-left
384 (setq file (expand-file-name (car command-line-args-left)))
385 (cond ((not (file-exists-p file))
386 (message ">> %s does not exist!" file)
388 command-line-args-left (cdr command-line-args-left)))
389 ((file-directory-p file)
390 (setq command-line-args-left
391 (nconc (directory-files file)
392 (cdr command-line-args-left))))
394 (setq files (cons file files)
395 command-line-args-left (cdr command-line-args-left)))))
397 (setq file (car files)
401 (if buffer-file-name (kill-buffer (current-buffer)))
404 (setq output-coding-system (symbol-value
405 'file-coding-system))
406 (setq coding-system-for-write buffer-file-coding-system))
409 "^@setfilename[\t ]+\\([^\t\n ]+\\)" nil t)
410 (not (string-match "\\.info$" (match-string 1))))
412 (buffer-disable-undo (current-buffer))
413 ;; process @include before updating node
414 ;; This might produce some problem if we use @lowersection or
416 (let ((input-directory default-directory)
417 (texinfo-command-end))
418 (while (re-search-forward "^@include" nil t)
419 (setq texinfo-command-end (point))
420 (let ((filename (concat input-directory
421 (texinfo-parse-line-arg))))
422 (re-search-backward "^@include")
423 (delete-region (point) (save-excursion
426 (message "Reading included file: %s" filename)
432 (car (cdr (insert-file-contents filename)))))
433 (goto-char (point-min))
434 ;; Remove `@setfilename' line from included file,
435 ;; if any, so @setfilename command not duplicated.
436 (if (re-search-forward "^@setfilename"
443 (delete-region (point) (save-excursion
447 (texinfo-every-node-update)
448 (set-buffer-modified-p nil)
449 (message "texinfo formatting %s..." file)
450 (texinfo-format-buffer nil)
451 (if (buffer-modified-p)
452 (progn (message "Saving modified %s" (buffer-file-name))
455 (message ">> Error: %s" (prin1-to-string err))
456 (message ">> point at")
457 (let ((s (buffer-substring (point)
461 (while (setq tem (string-match "\n+" s tem))
462 (setq s (concat (substring s 0 (match-beginning 0))
464 (substring s (match-end 0)))
468 (kill-emacs error))))
470 ;;; dgnushack.el ends here