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 (define-compiler-macro union (&whole form list1 list2)
117 (if (and (fboundp 'union)
118 (subrp (symbol-function 'union)))
126 (or (>= (length a) (length b))
127 (setq a (prog1 b (setq b a))))
134 ;; If we are building w3 in a different directory than the source
135 ;; directory, we must read *.el from source directory and write *.elc
136 ;; into the building directory. For that, we define this function
137 ;; before loading bytecomp. Bytecomp doesn't overwrite this function.
138 (defun byte-compile-dest-file (filename)
139 "Convert an Emacs Lisp source file name to a compiled file name.
140 In addition, remove directory name part from FILENAME."
141 (setq filename (byte-compiler-base-file-name filename))
142 (setq filename (file-name-sans-versions filename))
143 (setq filename (file-name-nondirectory filename))
144 (if (memq system-type '(win32 w32 mswindows windows-nt))
145 (setq filename (downcase filename)))
146 (cond ((eq system-type 'vax-vms)
147 (concat (substring filename 0 (string-match ";" filename)) "c"))
148 ((string-match emacs-lisp-file-regexp filename)
149 (concat (substring filename 0 (match-beginning 0)) ".elc"))
150 (t (concat filename ".elc"))))
154 (unless (fboundp 'si:byte-optimize-form-code-walker)
155 (byte-optimize-form nil);; Load `byte-opt' or `byte-optimize'.
156 (setq max-specpdl-size 3000)
157 (fset 'si:byte-optimize-form-code-walker
158 (symbol-function 'byte-optimize-form-code-walker))
159 (defun byte-optimize-form-code-walker (form for-effect)
160 (if (and for-effect (memq (car-safe form) '(and or)))
161 ;; Fix bug in and/or forms.
162 (let ((fn (car form))
163 (backwards (reverse (cdr form))))
164 (while (and backwards
165 (null (setcar backwards
166 (byte-optimize-form (car backwards) t))))
167 (setq backwards (cdr backwards)))
168 (if (and (cdr form) (null backwards))
170 " all subforms of %s called for effect; deleted" form))
172 (let ((head backwards))
173 (while (setq backwards (cdr backwards))
174 (setcar backwards (byte-optimize-form (car backwards)
176 (cons fn (nreverse head)))))
177 (si:byte-optimize-form-code-walker form for-effect)))
178 (byte-compile 'byte-optimize-form-code-walker))
180 (defvar srcdir (or (getenv "srcdir") "."))
182 ;(push "/usr/share/emacs/site-lisp" load-path)
184 ;; Attempt to pickup the additional load-path(s).
185 (load (expand-file-name "dgnuspath.el" srcdir) nil nil t)
187 (load "~/.lpath.el" t nil t)
188 (error (message "Error in \"~/.lpath.el\" file: %s" err)))
192 (wrong-number-of-arguments
193 ;; Optimize byte code for `char-after'.
194 (put 'char-after 'byte-optimizer 'byte-optimize-char-after)
195 (defun byte-optimize-char-after (form)
196 (if (null (cdr form))
197 '(char-after (point))
203 (wrong-number-of-arguments
204 (define-compiler-macro char-before (&whole form &optional pos)
206 '(char-before (point))
209 ;; `char-after' and `char-before' must be well-behaved before lpath.el
210 ;; is loaded. Because it requires `poe' via `path-util'.
211 (load (expand-file-name "lpath.el" srcdir) nil t t)
213 (unless (fboundp 'byte-compile-file-form-custom-declare-variable)
214 ;; Bind defcustom'ed variables.
215 (put 'custom-declare-variable 'byte-hunk-handler
216 'byte-compile-file-form-custom-declare-variable)
217 (defun byte-compile-file-form-custom-declare-variable (form)
218 (if (memq 'free-vars byte-compile-warnings)
219 (setq byte-compile-bound-variables
220 (cons (nth 1 (nth 1 form)) byte-compile-bound-variables)))
223 ;; Bind functions defined by `defun-maybe'.
224 (put 'defun-maybe 'byte-hunk-handler 'byte-compile-file-form-defun-maybe)
225 (defun byte-compile-file-form-defun-maybe (form)
226 (if (and (not (fboundp (nth 1 form)))
227 (memq 'unresolved byte-compile-warnings))
228 (setq byte-compile-function-environment
229 (cons (cons (nth 1 form)
230 (cons 'lambda (cdr (cdr form))))
231 byte-compile-function-environment)))
235 :symbol-for-testing-whether-colon-keyword-is-available-or-not
238 (mapcar (lambda (keyword) (set keyword keyword))
239 '(:button-keymap :data :file :mime-handle))))
241 ;; Unknown variables and functions.
242 (unless (boundp 'buffer-file-coding-system)
243 (defvar buffer-file-coding-system (symbol-value 'file-coding-system)))
244 (autoload 'font-lock-set-defaults "font-lock")
245 (unless (fboundp 'coding-system-get)
246 (defalias 'coding-system-get 'ignore))
248 (defalias 'find-coding-system 'ignore))
249 (unless (fboundp 'get-charset-property)
250 (defalias 'get-charset-property 'ignore))
251 (unless (featurep 'xemacs)
252 (defalias 'Custom-make-dependencies 'ignore)
253 (defalias 'toolbar-gnus 'ignore)
254 (defalias 'update-autoloads-from-directory 'ignore))
255 (autoload 'texinfo-parse-line-arg "texinfmt")
257 (unless (fboundp 'with-temp-buffer)
258 ;; Pickup some macros.
261 (defalias 'device-sound-enabled-p 'ignore)
262 (defalias 'play-sound-file 'ignore)
263 (defalias 'nndb-request-article 'ignore)
264 (defalias 'efs-re-read-dir 'ignore)
265 (defalias 'ange-ftp-re-read-dir 'ignore)
266 (defalias 'define-mail-user-agent 'ignore)
269 (unless (string-match "XEmacs" emacs-version)
270 (fset 'get-popup-menu-response 'ignore)
271 (fset 'event-object 'ignore)
272 (fset 'x-defined-colors 'ignore)
273 (fset 'read-color 'ignore)))
275 (defun dgnushack-compile (&optional warn)
276 ;;(setq byte-compile-dynamic t)
278 (setq byte-compile-warnings
279 '(free-vars unresolved callargs redefine)))
280 (unless (locate-library "cus-edit")
281 (error "You do not seem to have Custom installed.
282 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
283 You also then need to add the following to the lisp/dgnushack.el file:
285 (push \"~/lisp/custom\" load-path)
287 Modify to suit your needs."))
288 (let ((files (delete "dgnuspath.el"
289 (directory-files srcdir nil "^[^=].*\\.el$")))
290 (xemacs (string-match "XEmacs" emacs-version))
291 ;;(byte-compile-generate-call-tree t)
296 (dolist (file '("nnweb.el" "nnlistserv.el" "nnultimate.el"
297 "nnslashdot.el" "nnwarchive.el" "webmail.el"))
298 (setq files (delete file files)))))
301 (error (setq files (delete "gnus-bbdb.el" files))))
302 (while (setq file (pop files))
303 (unless (or (and (not xemacs)
305 '("gnus-xmas.el" "gnus-picon.el"
306 "messagexmas.el" "nnheaderxm.el"
307 "smiley.el" "x-overlay.el")))
308 (and (string-equal file "md5.el")
309 (not (and (fboundp 'md5)
310 (subrp (symbol-function 'md5))))))
311 (setq file (expand-file-name file srcdir))
312 (when (or (not (file-exists-p (setq elc (concat file "c"))))
313 (file-newer-than-file-p file elc))
315 (byte-compile-file file)))))))
317 (defun dgnushack-recompile ()
319 (byte-recompile-directory "." 0))
322 ;; Avoid byte-compile warnings.
323 (defvar gnus-product-name)
324 (defvar early-package-load-path)
325 (defvar early-packages)
326 (defvar last-package-load-path)
327 (defvar last-packages)
328 (defvar late-package-load-path)
329 (defvar late-packages)
331 (defconst dgnushack-info-file-regexp
332 (concat "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)"
333 "\\.info\\(-[0-9]+\\)?$"))
335 (defconst dgnushack-texi-file-regexp
336 "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)\\.texi$")
338 (defun dgnushack-make-package ()
340 (let* ((product-name (downcase gnus-product-name))
341 (lisp-dir (concat "lisp/" product-name "/"))
344 (message "Updating autoloads for directory %s..." default-directory)
345 (let ((generated-autoload-file "auto-autoloads.el")
347 (omsg (symbol-function 'message)))
348 (defun message (fmt &rest args)
349 (cond ((and (string-equal "Generating autoloads for %s..." fmt)
350 (file-exists-p (file-name-nondirectory (car args))))
351 (funcall omsg fmt (file-name-nondirectory (car args))))
352 ((string-equal "No autoloads found in %s" fmt))
353 ((string-equal "Generating autoloads for %s...done" fmt))
354 (t (apply omsg fmt args))))
356 (update-autoloads-from-directory default-directory)
357 (fset 'message omsg)))
358 (byte-compile-file "auto-autoloads.el")
361 (let ((standard-output (current-buffer)))
362 (Custom-make-dependencies "."))
363 (message (buffer-string)))
365 (byte-compile-file "custom-load.el")
367 (message "Generating MANIFEST.%s for the package..." product-name)
369 (insert "pkginfo/MANIFEST." product-name "\n"
373 (sort (delete "dgnuspath.el"
375 (directory-files "." nil "\\.elc?$")))
377 (concat "\n" lisp-dir))
381 (sort (directory-files "../texi/"
382 nil dgnushack-info-file-regexp)
386 (write-file (concat "../MANIFEST." product-name)))))
388 (defun dgnushack-install-package ()
389 (let ((package-dir (car command-line-args-left))
390 dirs info-dir pkginfo-dir product-name lisp-dir manifest files)
392 (when (boundp 'early-packages)
393 (setq dirs (delq nil (append (when early-package-load-path
395 (when late-package-load-path
397 (when last-package-load-path
399 (while (and dirs (not package-dir))
400 (when (file-exists-p (car dirs))
401 (setq package-dir (car dirs)
405 You must specify the name of the package path as follows:
407 % make install-package PACKAGEDIR=/usr/local/lib/xemacs/xemacs-packages
410 (setq info-dir (expand-file-name "info/" package-dir)
411 pkginfo-dir (expand-file-name "pkginfo/" package-dir))
413 (setq product-name (downcase gnus-product-name)
414 lisp-dir (expand-file-name (concat "lisp/" product-name "/")
416 manifest (concat "MANIFEST." product-name))
418 (unless (file-directory-p lisp-dir)
419 (make-directory lisp-dir t))
420 (unless (file-directory-p info-dir)
421 (make-directory info-dir))
422 (unless (file-directory-p pkginfo-dir)
423 (make-directory pkginfo-dir))
426 (sort (delete "dgnuspath.el"
427 (delete "dgnuspath.elc"
428 (directory-files "." nil "\\.elc?$")))
432 (unless (or (member file files)
433 (not (string-match "\\.elc?$" file)))
434 (setq file (expand-file-name file lisp-dir))
435 (message "Removing %s..." file)
439 (directory-files lisp-dir nil nil nil t))
442 (message "Copying %s to %s..." file lisp-dir)
443 (copy-file file (expand-file-name file lisp-dir) t t))
448 (message "Copying ../texi/%s to %s..." file info-dir)
449 (copy-file (expand-file-name file "../texi/")
450 (expand-file-name file info-dir)
452 (sort (directory-files "../texi/" nil dgnushack-info-file-regexp)
455 (message "Copying ../%s to %s..." manifest pkginfo-dir)
456 (copy-file (expand-file-name manifest "../")
457 (expand-file-name manifest pkginfo-dir) t t)
461 (defun dgnushack-texi-add-suffix-and-format ()
462 (dgnushack-texi-format t))
464 (defun dgnushack-texi-format (&optional addsuffix)
465 (if (not noninteractive)
466 (error "batch-texinfo-format may only be used -batch."))
468 (let ((auto-save-default nil)
469 (find-file-run-dired nil)
470 coding-system-for-write)
474 (while command-line-args-left
475 (setq file (expand-file-name (car command-line-args-left)))
476 (cond ((not (file-exists-p file))
477 (message ">> %s does not exist!" file)
479 command-line-args-left (cdr command-line-args-left)))
480 ((file-directory-p file)
481 (setq command-line-args-left
482 (nconc (directory-files file)
483 (cdr command-line-args-left))))
485 (setq files (cons file files)
486 command-line-args-left (cdr command-line-args-left)))))
488 (setq file (car files)
492 (if buffer-file-name (kill-buffer (current-buffer)))
494 (setq coding-system-for-write buffer-file-coding-system)
497 "^@setfilename[\t ]+\\([^\t\n ]+\\)" nil t)
498 (not (string-match "\\.info$" (match-string 1))))
500 (buffer-disable-undo (current-buffer))
501 ;; process @include before updating node
502 ;; This might produce some problem if we use @lowersection or
504 (let ((input-directory default-directory)
505 (texinfo-command-end))
506 (while (re-search-forward "^@include" nil t)
507 (setq texinfo-command-end (point))
508 (let ((filename (concat input-directory
509 (texinfo-parse-line-arg))))
510 (re-search-backward "^@include")
511 (delete-region (point) (save-excursion
514 (message "Reading included file: %s" filename)
520 (car (cdr (insert-file-contents filename)))))
521 (goto-char (point-min))
522 ;; Remove `@setfilename' line from included file,
523 ;; if any, so @setfilename command not duplicated.
524 (if (re-search-forward "^@setfilename"
531 (delete-region (point) (save-excursion
535 (texinfo-every-node-update)
536 (set-buffer-modified-p nil)
537 (message "texinfo formatting %s..." file)
538 (texinfo-format-buffer nil)
539 (if (buffer-modified-p)
540 (progn (message "Saving modified %s" (buffer-file-name))
543 (message ">> Error: %s" (prin1-to-string err))
544 (message ">> point at")
545 (let ((s (buffer-substring (point)
549 (while (setq tem (string-match "\n+" s tem))
550 (setq s (concat (substring s 0 (match-beginning 0))
552 (substring s (match-end 0)))
556 (kill-emacs error))))
558 ;;; dgnushack.el ends here