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 ;; If we are building w3 in a different directory than the source
57 ;; directory, we must read *.el from source directory and write *.elc
58 ;; into the building directory. For that, we define this function
59 ;; before loading bytecomp. Bytecomp doesn't overwrite this function.
60 (defun byte-compile-dest-file (filename)
61 "Convert an Emacs Lisp source file name to a compiled file name.
62 In addition, remove directory name part from FILENAME."
63 (setq filename (byte-compiler-base-file-name filename))
64 (setq filename (file-name-sans-versions filename))
65 (setq filename (file-name-nondirectory filename))
66 (if (memq system-type '(win32 w32 mswindows windows-nt))
67 (setq filename (downcase filename)))
68 (cond ((eq system-type 'vax-vms)
69 (concat (substring filename 0 (string-match ";" filename)) "c"))
70 ((string-match emacs-lisp-file-regexp filename)
71 (concat (substring filename 0 (match-beginning 0)) ".elc"))
72 (t (concat filename ".elc"))))
76 (unless (fboundp 'si:byte-optimize-form-code-walker)
77 (byte-optimize-form nil);; Load `byte-opt' or `byte-optimize'.
78 (setq max-specpdl-size 3000)
79 (fset 'si:byte-optimize-form-code-walker
80 (symbol-function 'byte-optimize-form-code-walker))
81 (defun byte-optimize-form-code-walker (form for-effect)
82 (if (and for-effect (memq (car-safe form) '(and or)))
83 ;; Fix bug in and/or forms.
85 (backwards (reverse (cdr form))))
87 (null (setcar backwards
88 (byte-optimize-form (car backwards) t))))
89 (setq backwards (cdr backwards)))
90 (if (and (cdr form) (null backwards))
92 " all subforms of %s called for effect; deleted" form))
94 (let ((head backwards))
95 (while (setq backwards (cdr backwards))
96 (setcar backwards (byte-optimize-form (car backwards)
98 (cons fn (nreverse head)))))
99 (si:byte-optimize-form-code-walker form for-effect)))
100 (byte-compile 'byte-optimize-form-code-walker))
102 (defvar srcdir (or (getenv "srcdir") "."))
104 (load (expand-file-name "gnus-clfns.el" srcdir) nil t t)
106 ;(push "/usr/share/emacs/site-lisp" load-path)
108 ;; Attempt to pickup the additional load-path(s).
109 (load (expand-file-name "dgnuspath.el" srcdir) nil nil t)
111 (load "~/.lpath.el" t nil t)
112 (error (message "Error in \"~/.lpath.el\" file: %s" err)))
116 (wrong-number-of-arguments
117 ;; Optimize byte code for `char-after'.
118 (put 'char-after 'byte-optimizer 'byte-optimize-char-after)
119 (defun byte-optimize-char-after (form)
120 (if (null (cdr form))
121 '(char-after (point))
127 (wrong-number-of-arguments
128 ;; Optimize byte code for `char-before'.
129 (put 'char-before 'byte-optimizer 'byte-optimize-char-before)
130 (defun byte-optimize-char-before (form)
131 (if (null (cdr form))
132 '(char-before (point))
136 ;; `char-after' and `char-before' must be well-behaved before lpath.el
137 ;; is loaded. Because it requires `poe' via `path-util'.
138 (load (expand-file-name "lpath.el" srcdir) nil t t)
140 (unless (fboundp 'byte-compile-file-form-custom-declare-variable)
141 ;; Bind defcustom'ed variables.
142 (put 'custom-declare-variable 'byte-hunk-handler
143 'byte-compile-file-form-custom-declare-variable)
144 (defun byte-compile-file-form-custom-declare-variable (form)
145 (if (memq 'free-vars byte-compile-warnings)
146 (setq byte-compile-bound-variables
147 (cons (nth 1 (nth 1 form)) byte-compile-bound-variables)))
150 ;; Bind functions defined by `defun-maybe'.
151 (put 'defun-maybe 'byte-hunk-handler 'byte-compile-file-form-defun-maybe)
152 (defun byte-compile-file-form-defun-maybe (form)
153 (if (and (not (fboundp (nth 1 form)))
154 (memq 'unresolved byte-compile-warnings))
155 (setq byte-compile-function-environment
156 (cons (cons (nth 1 form)
157 (cons 'lambda (cdr (cdr form))))
158 byte-compile-function-environment)))
162 :symbol-for-testing-whether-colon-keyword-is-available-or-not
165 (mapcar (lambda (keyword) (set keyword keyword))
166 '(:button-keymap :data :file :mime-handle))))
168 ;; Unknown variables and functions.
169 (unless (boundp 'buffer-file-coding-system)
170 (defvar buffer-file-coding-system (symbol-value 'file-coding-system)))
171 (unless (featurep 'xemacs)
172 (defalias 'Custom-make-dependencies 'ignore)
173 (defalias 'update-autoloads-from-directory 'ignore))
174 (autoload 'texinfo-parse-line-arg "texinfmt")
176 (unless (fboundp 'with-temp-buffer)
177 ;; Pickup some macros.
180 (defalias 'device-sound-enabled-p 'ignore)
181 (defalias 'play-sound-file 'ignore)
182 (defalias 'nndb-request-article 'ignore)
183 (defalias 'efs-re-read-dir 'ignore)
184 (defalias 'ange-ftp-re-read-dir 'ignore)
185 (defalias 'define-mail-user-agent 'ignore)
187 (defun dgnushack-compile (&optional warn)
188 ;;(setq byte-compile-dynamic t)
190 (setq byte-compile-warnings
191 '(free-vars unresolved callargs redefine)))
192 (unless (locate-library "cus-edit")
193 (error "You do not seem to have Custom installed.
194 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
195 You also then need to add the following to the lisp/dgnushack.el file:
197 (push \"~/lisp/custom\" load-path)
199 Modify to suit your needs."))
200 (let ((files (delete "dgnuspath.el"
201 (directory-files srcdir nil "^[^=].*\\.el$")))
202 (xemacs (string-match "XEmacs" emacs-version))
203 ;;(byte-compile-generate-call-tree t)
208 (dolist (file '("nnweb.el" "nnlistserv.el" "nnultimate.el"
209 "nnslashdot.el" "nnwarchive.el" "webmail.el"))
210 (setq files (delete file files)))))
213 (error (setq files (delete "gnus-bbdb.el" files))))
214 (while (setq file (pop files))
215 (unless (or (and (not xemacs)
217 '("gnus-xmas.el" "gnus-picon.el"
218 "messagexmas.el" "nnheaderxm.el"
219 "smiley.el" "x-overlay.el")))
220 (and (string-equal file "md5.el")
221 (not (and (fboundp 'md5)
222 (subrp (symbol-function 'md5))))))
223 (setq file (expand-file-name file srcdir))
224 (when (or (not (file-exists-p (setq elc (concat file "c"))))
225 (file-newer-than-file-p file elc))
227 (byte-compile-file file)))))))
229 (defun dgnushack-recompile ()
231 (byte-recompile-directory "." 0))
234 ;; Avoid byte-compile warnings.
235 (defvar gnus-product-name)
236 (defvar early-package-load-path)
237 (defvar early-packages)
238 (defvar last-package-load-path)
239 (defvar last-packages)
240 (defvar late-package-load-path)
241 (defvar late-packages)
243 (defconst dgnushack-info-file-regexp
244 (concat "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)"
245 "\\.info\\(-[0-9]+\\)?$"))
247 (defconst dgnushack-texi-file-regexp
248 "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)\\.texi$")
250 (defun dgnushack-make-package ()
252 (let* ((product-name (downcase gnus-product-name))
253 (lisp-dir (concat "lisp/" product-name "/"))
256 (message "Updating autoloads for directory %s..." default-directory)
257 (let ((generated-autoload-file "auto-autoloads.el")
259 (omsg (symbol-function 'message)))
260 (defun message (fmt &rest args)
261 (cond ((and (string-equal "Generating autoloads for %s..." fmt)
262 (file-exists-p (file-name-nondirectory (car args))))
263 (funcall omsg fmt (file-name-nondirectory (car args))))
264 ((string-equal "No autoloads found in %s" fmt))
265 ((string-equal "Generating autoloads for %s...done" fmt))
266 (t (apply omsg fmt args))))
268 (update-autoloads-from-directory default-directory)
269 (fset 'message omsg)))
270 (byte-compile-file "auto-autoloads.el")
273 (let ((standard-output (current-buffer)))
274 (Custom-make-dependencies "."))
275 (message "%s" (buffer-string)))
277 (byte-compile-file "custom-load.el")
279 (message "Generating MANIFEST.%s for the package..." product-name)
281 (insert "pkginfo/MANIFEST." product-name "\n"
285 (sort (delete "dgnuspath.el"
287 (directory-files "." nil "\\.elc?$")))
289 (concat "\n" lisp-dir))
293 (sort (directory-files "../texi/"
294 nil dgnushack-info-file-regexp)
298 (write-file (concat "../MANIFEST." product-name)))))
300 (defun dgnushack-install-package ()
301 (let ((package-dir (car command-line-args-left))
302 dirs info-dir pkginfo-dir product-name lisp-dir manifest files)
304 (when (boundp 'early-packages)
305 (setq dirs (delq nil (append (when early-package-load-path
307 (when late-package-load-path
309 (when last-package-load-path
311 (while (and dirs (not package-dir))
312 (when (file-exists-p (car dirs))
313 (setq package-dir (car dirs)
317 You must specify the name of the package path as follows:
319 % make install-package PACKAGEDIR=/usr/local/lib/xemacs/xemacs-packages
322 (setq info-dir (expand-file-name "info/" package-dir)
323 pkginfo-dir (expand-file-name "pkginfo/" package-dir))
325 (setq product-name (downcase gnus-product-name)
326 lisp-dir (expand-file-name (concat "lisp/" product-name "/")
328 manifest (concat "MANIFEST." product-name))
330 (unless (file-directory-p lisp-dir)
331 (make-directory lisp-dir t))
332 (unless (file-directory-p info-dir)
333 (make-directory info-dir))
334 (unless (file-directory-p pkginfo-dir)
335 (make-directory pkginfo-dir))
338 (sort (delete "dgnuspath.el"
339 (delete "dgnuspath.elc"
340 (directory-files "." nil "\\.elc?$")))
344 (unless (or (member file files)
345 (not (string-match "\\.elc?$" file)))
346 (setq file (expand-file-name file lisp-dir))
347 (message "Removing %s..." file)
351 (directory-files lisp-dir nil nil nil t))
354 (message "Copying %s to %s..." file lisp-dir)
355 (copy-file file (expand-file-name file lisp-dir) t t))
360 (message "Copying ../texi/%s to %s..." file info-dir)
361 (copy-file (expand-file-name file "../texi/")
362 (expand-file-name file info-dir)
364 (sort (directory-files "../texi/" nil dgnushack-info-file-regexp)
367 (message "Copying ../%s to %s..." manifest pkginfo-dir)
368 (copy-file (expand-file-name manifest "../")
369 (expand-file-name manifest pkginfo-dir) t t)
373 (defun dgnushack-texi-add-suffix-and-format ()
374 (dgnushack-texi-format t))
376 (defun dgnushack-texi-format (&optional addsuffix)
377 (if (not noninteractive)
378 (error "batch-texinfo-format may only be used -batch."))
380 (let ((auto-save-default nil)
381 (find-file-run-dired nil)
382 coding-system-for-write
383 output-coding-system)
387 (while command-line-args-left
388 (setq file (expand-file-name (car command-line-args-left)))
389 (cond ((not (file-exists-p file))
390 (message ">> %s does not exist!" file)
392 command-line-args-left (cdr command-line-args-left)))
393 ((file-directory-p file)
394 (setq command-line-args-left
395 (nconc (directory-files file)
396 (cdr command-line-args-left))))
398 (setq files (cons file files)
399 command-line-args-left (cdr command-line-args-left)))))
401 (setq file (car files)
405 (if buffer-file-name (kill-buffer (current-buffer)))
408 (setq output-coding-system (symbol-value
409 'file-coding-system))
410 (setq coding-system-for-write buffer-file-coding-system))
413 "^@setfilename[\t ]+\\([^\t\n ]+\\)" nil t)
414 (not (string-match "\\.info$" (match-string 1))))
416 (buffer-disable-undo (current-buffer))
417 ;; process @include before updating node
418 ;; This might produce some problem if we use @lowersection or
420 (let ((input-directory default-directory)
421 (texinfo-command-end))
422 (while (re-search-forward "^@include" nil t)
423 (setq texinfo-command-end (point))
424 (let ((filename (concat input-directory
425 (texinfo-parse-line-arg))))
426 (re-search-backward "^@include")
427 (delete-region (point) (save-excursion
430 (message "Reading included file: %s" filename)
436 (car (cdr (insert-file-contents filename)))))
437 (goto-char (point-min))
438 ;; Remove `@setfilename' line from included file,
439 ;; if any, so @setfilename command not duplicated.
440 (if (re-search-forward "^@setfilename"
447 (delete-region (point) (save-excursion
451 (texinfo-every-node-update)
452 (set-buffer-modified-p nil)
453 (message "texinfo formatting %s..." file)
454 (texinfo-format-buffer nil)
455 (if (buffer-modified-p)
456 (progn (message "Saving modified %s" (buffer-file-name))
459 (message ">> Error: %s" (prin1-to-string err))
460 (message ">> point at")
461 (let ((s (buffer-substring (point)
465 (while (setq tem (string-match "\n+" s tem))
466 (setq s (concat (substring s 0 (match-beginning 0))
468 (substring s (match-end 0)))
472 (kill-emacs error))))
474 ;; Mule-2.3@19.34 fails to make info from texi.
476 (put 'detailmenu 'texinfo-format 'texinfo-discard-line)
477 (put 'detailmenu 'texinfo-end 'texinfo-discard-command))
479 ;;; dgnushack.el ends here