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 (cons 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 ;; If we are building w3 in a different directory than the source
95 ;; directory, we must read *.el from source directory and write *.elc
96 ;; into the building directory. For that, we define this function
97 ;; before loading bytecomp. Bytecomp doesn't overwrite this function.
98 (defun byte-compile-dest-file (filename)
99 "Convert an Emacs Lisp source file name to a compiled file name.
100 In addition, remove directory name part from FILENAME."
101 (setq filename (byte-compiler-base-file-name filename))
102 (setq filename (file-name-sans-versions filename))
103 (setq filename (file-name-nondirectory filename))
104 (if (memq system-type '(win32 w32 mswindows windows-nt))
105 (setq filename (downcase filename)))
106 (cond ((eq system-type 'vax-vms)
107 (concat (substring filename 0 (string-match ";" filename)) "c"))
108 ((string-match emacs-lisp-file-regexp filename)
109 (concat (substring filename 0 (match-beginning 0)) ".elc"))
110 (t (concat filename ".elc"))))
114 (defvar srcdir (or (getenv "srcdir") "."))
116 (push srcdir load-path)
118 ;; Attempt to pickup the additional load-path(s).
119 (load (expand-file-name "dgnuspath.el" srcdir) nil nil t)
121 (load "~/.lpath.el" t nil t)
122 (error (message "Error in \"~/.lpath.el\" file: %s" err)))
126 (wrong-number-of-arguments
127 ;; Optimize byte code for `char-after'.
128 (put 'char-after 'byte-optimizer 'byte-optimize-char-after)
129 (defun byte-optimize-char-after (form)
130 (if (null (cdr form))
131 '(char-after (point))
133 (byte-defop-compiler char-after 0-1)))
137 (wrong-number-of-arguments
138 ;; Optimize byte code for `char-before'.
139 (put 'char-before 'byte-optimizer 'byte-optimize-char-before)
140 (defun byte-optimize-char-before (form)
141 (if (null (cdr form))
142 '(char-before (point))
145 ;; `char-after' and `char-before' must be well-behaved before lpath.el
146 ;; is loaded. Because it requires `poe' via `path-util'.
147 (load (expand-file-name "lpath.el" srcdir) nil t t)
149 (unless (fboundp 'byte-compile-file-form-custom-declare-variable)
150 ;; Bind defcustom'ed variables.
151 (put 'custom-declare-variable 'byte-hunk-handler
152 'byte-compile-file-form-custom-declare-variable)
153 (defun byte-compile-file-form-custom-declare-variable (form)
154 (if (memq 'free-vars byte-compile-warnings)
155 (setq byte-compile-bound-variables
156 (cons (nth 1 (nth 1 form)) byte-compile-bound-variables)))
159 ;; Bind functions defined by `defun-maybe'.
160 (put 'defun-maybe 'byte-hunk-handler 'byte-compile-file-form-defun-maybe)
161 (defun byte-compile-file-form-defun-maybe (form)
162 (if (and (not (fboundp (nth 1 form)))
163 (memq 'unresolved byte-compile-warnings))
164 (setq byte-compile-function-environment
165 (cons (cons (nth 1 form)
166 (cons 'lambda (cdr (cdr form))))
167 byte-compile-function-environment)))
171 :symbol-for-testing-whether-colon-keyword-is-available-or-not
174 (mapcar (lambda (keyword) (set keyword keyword))
175 '(:button-keymap :data :file :mime-handle))))
177 ;; Unknown variables and functions.
178 (unless (boundp 'buffer-file-coding-system)
179 (defvar buffer-file-coding-system (symbol-value 'file-coding-system)))
180 (autoload 'font-lock-set-defaults "font-lock")
181 (unless (fboundp 'coding-system-get)
182 (defalias 'coding-system-get 'ignore))
184 (defalias 'find-coding-system 'ignore))
185 (unless (fboundp 'get-charset-property)
186 (defalias 'get-charset-property 'ignore))
187 (unless (featurep 'xemacs)
188 (defalias 'Custom-make-dependencies 'ignore)
189 (defalias 'toolbar-gnus 'ignore)
190 (defalias 'update-autoloads-from-directory 'ignore))
191 (autoload 'texinfo-parse-line-arg "texinfmt")
193 (unless (fboundp 'with-temp-buffer)
194 ;; Pickup some macros.
197 (defalias 'device-sound-enabled-p 'ignore)
198 (defalias 'play-sound-file 'ignore)
199 (defalias 'nndb-request-article 'ignore)
200 (defalias 'efs-re-read-dir 'ignore)
201 (defalias 'ange-ftp-re-read-dir 'ignore)
202 (defalias 'define-mail-user-agent 'ignore)
205 (unless (string-match "XEmacs" emacs-version)
206 (fset 'get-popup-menu-response 'ignore)
207 (fset 'event-object 'ignore)
208 (fset 'x-defined-colors 'ignore)
209 (fset 'read-color 'ignore)))
211 (defun dgnushack-compile (&optional warn)
212 ;;(setq byte-compile-dynamic t)
214 (setq byte-compile-warnings
215 '(free-vars unresolved callargs redefine)))
216 (unless (locate-library "cus-edit")
217 (error "You do not seem to have Custom installed.
218 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
219 You also then need to add the following to the lisp/dgnushack.el file:
221 (push \"~/lisp/custom\" load-path)
223 Modify to suit your needs."))
224 (let ((files (delete "dgnuspath.el"
225 (directory-files srcdir nil "^[^=].*\\.el$")))
226 (xemacs (string-match "XEmacs" emacs-version))
227 ;;(byte-compile-generate-call-tree t)
232 (dolist (file '("nnweb.el" "nnlistserv.el" "nnultimate.el"
233 "nnslashdot.el" "nnwarchive.el" "webmail.el"))
234 (setq files (delete file files)))))
237 (error (setq files (delete "gnus-bbdb.el" files))))
238 (while (setq file (pop files))
239 (unless (or (and (not xemacs)
241 '("gnus-xmas.el" "gnus-picon.el"
242 "messagexmas.el" "nnheaderxm.el"
243 "smiley.el" "x-overlay.el")))
244 (and (string-equal file "md5.el")
245 (not (and (fboundp 'md5)
246 (subrp (symbol-function 'md5))))))
247 (setq file (expand-file-name file srcdir))
248 (when (or (not (file-exists-p (setq elc (concat file "c"))))
249 (file-newer-than-file-p file elc))
251 (byte-compile-file file)))))))
253 (defun dgnushack-recompile ()
255 (byte-recompile-directory "." 0))
258 ;; Avoid byte-compile warnings.
259 (defvar gnus-product-name)
260 (defvar early-package-load-path)
261 (defvar early-packages)
262 (defvar last-package-load-path)
263 (defvar last-packages)
264 (defvar late-package-load-path)
265 (defvar late-packages)
267 (defconst dgnushack-info-file-regexp
268 (concat "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)"
269 "\\.info\\(-[0-9]+\\)?$"))
271 (defconst dgnushack-texi-file-regexp
272 "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)\\.texi$")
274 (defun dgnushack-make-package ()
276 (let* ((product-name (downcase gnus-product-name))
277 (lisp-dir (concat "lisp/" product-name "/"))
280 (message "Updating autoloads for directory %s..." default-directory)
281 (let ((generated-autoload-file "auto-autoloads.el")
283 (omsg (symbol-function 'message)))
284 (defun message (fmt &rest args)
285 (cond ((and (string-equal "Generating autoloads for %s..." fmt)
286 (file-exists-p (file-name-nondirectory (car args))))
287 (funcall omsg fmt (file-name-nondirectory (car args))))
288 ((string-equal "No autoloads found in %s" fmt))
289 ((string-equal "Generating autoloads for %s...done" fmt))
290 (t (apply omsg fmt args))))
292 (update-autoloads-from-directory default-directory)
293 (fset 'message omsg)))
294 (byte-compile-file "auto-autoloads.el")
297 (let ((standard-output (current-buffer)))
298 (Custom-make-dependencies "."))
299 (message (buffer-string)))
301 (byte-compile-file "custom-load.el")
303 (message "Generating MANIFEST.%s for the package..." product-name)
305 (insert "pkginfo/MANIFEST." product-name "\n"
309 (sort (delete "dgnuspath.el"
311 (directory-files "." nil "\\.elc?$")))
313 (concat "\n" lisp-dir))
317 (sort (directory-files "../texi/"
318 nil dgnushack-info-file-regexp)
322 (write-file (concat "../MANIFEST." product-name)))))
324 (defun dgnushack-install-package ()
325 (let ((package-dir (car command-line-args-left))
326 dirs info-dir pkginfo-dir product-name lisp-dir manifest files)
328 (when (boundp 'early-packages)
329 (setq dirs (delq nil (append (when early-package-load-path
331 (when late-package-load-path
333 (when last-package-load-path
335 (while (and dirs (not package-dir))
336 (when (file-exists-p (car dirs))
337 (setq package-dir (car dirs)
341 You must specify the name of the package path as follows:
343 % make install-package PACKAGEDIR=/usr/local/lib/xemacs/xemacs-packages
346 (setq info-dir (expand-file-name "info/" package-dir)
347 pkginfo-dir (expand-file-name "pkginfo/" package-dir))
349 (setq product-name (downcase gnus-product-name)
350 lisp-dir (expand-file-name (concat "lisp/" product-name "/")
352 manifest (concat "MANIFEST." product-name))
354 (unless (file-directory-p lisp-dir)
355 (make-directory lisp-dir t))
356 (unless (file-directory-p info-dir)
357 (make-directory info-dir))
358 (unless (file-directory-p pkginfo-dir)
359 (make-directory pkginfo-dir))
362 (sort (delete "dgnuspath.el"
363 (delete "dgnuspath.elc"
364 (directory-files "." nil "\\.elc?$")))
368 (unless (member file files)
369 (setq file (expand-file-name file lisp-dir))
370 (message "Removing %s..." file)
374 (directory-files lisp-dir nil nil nil t))
377 (message "Copying %s to %s..." file lisp-dir)
378 (copy-file file (expand-file-name file lisp-dir) t t))
383 (message "Copying ../texi/%s to %s..." file info-dir)
384 (copy-file (expand-file-name file "../texi/")
385 (expand-file-name file info-dir)
387 (sort (directory-files "../texi/" nil dgnushack-info-file-regexp)
390 (message "Copying ../%s to %s..." manifest pkginfo-dir)
391 (copy-file (expand-file-name manifest "../")
392 (expand-file-name manifest pkginfo-dir) t t)
396 (defun dgnushack-texi-add-suffix-and-format ()
397 (dgnushack-texi-format t))
399 (defun dgnushack-texi-format (&optional addsuffix)
400 (if (not noninteractive)
401 (error "batch-texinfo-format may only be used -batch."))
403 (let ((auto-save-default nil)
404 (find-file-run-dired nil)
405 coding-system-for-write)
409 (while command-line-args-left
410 (setq file (expand-file-name (car command-line-args-left)))
411 (cond ((not (file-exists-p file))
412 (message ">> %s does not exist!" file)
414 command-line-args-left (cdr command-line-args-left)))
415 ((file-directory-p file)
416 (setq command-line-args-left
417 (nconc (directory-files file)
418 (cdr command-line-args-left))))
420 (setq files (cons file files)
421 command-line-args-left (cdr command-line-args-left)))))
423 (setq file (car files)
427 (if buffer-file-name (kill-buffer (current-buffer)))
429 (setq coding-system-for-write buffer-file-coding-system)
432 "^@setfilename[\t ]+\\([^\t\n ]+\\)" nil t)
433 (not (string-match "\\.info$" (match-string 1))))
435 (buffer-disable-undo (current-buffer))
436 ;; process @include before updating node
437 ;; This might produce some problem if we use @lowersection or
439 (let ((input-directory default-directory)
440 (texinfo-command-end))
441 (while (re-search-forward "^@include" nil t)
442 (setq texinfo-command-end (point))
443 (let ((filename (concat input-directory
444 (texinfo-parse-line-arg))))
445 (re-search-backward "^@include")
446 (delete-region (point) (save-excursion
449 (message "Reading included file: %s" filename)
455 (car (cdr (insert-file-contents filename)))))
456 (goto-char (point-min))
457 ;; Remove `@setfilename' line from included file,
458 ;; if any, so @setfilename command not duplicated.
459 (if (re-search-forward "^@setfilename"
466 (delete-region (point) (save-excursion
470 (texinfo-every-node-update)
471 (set-buffer-modified-p nil)
472 (message "texinfo formatting %s..." file)
473 (texinfo-format-buffer nil)
474 (if (buffer-modified-p)
475 (progn (message "Saving modified %s" (buffer-file-name))
478 (message ">> Error: %s" (prin1-to-string err))
479 (message ">> point at")
480 (let ((s (buffer-substring (point)
484 (while (setq tem (string-match "\n+" s tem))
485 (setq s (concat (substring s 0 (match-beginning 0))
487 (substring s (match-end 0)))
491 (kill-emacs error))))
493 ;;; dgnushack.el ends here