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 ;; Attempt to pickup the additional load-path(s).
55 (load (expand-file-name "./dgnuspath.el") nil nil t)
57 (load "~/.lpath.el" t nil t)
58 (error (message "Error in \"~/.lpath.el\" file: %s" err)))
61 (load "./lpath.el" nil t)
65 (wrong-number-of-arguments
66 ;; Optimize byte code for `char-after',
67 (put 'char-after 'byte-optimizer 'byte-optimize-char-after)
68 (defun byte-optimize-char-after (form)
75 (wrong-number-of-arguments
76 ;; Optimize byte code for `char-before',
77 (put 'char-before 'byte-optimizer 'byte-optimize-char-before)
78 (defun byte-optimize-char-before (form)
80 '(char-before (point))
83 (unless (fboundp 'byte-compile-file-form-custom-declare-variable)
84 ;; Bind defcustom'ed variables.
85 (put 'custom-declare-variable 'byte-hunk-handler
86 'byte-compile-file-form-custom-declare-variable)
87 (defun byte-compile-file-form-custom-declare-variable (form)
88 (if (memq 'free-vars byte-compile-warnings)
89 (setq byte-compile-bound-variables
90 (cons (nth 1 (nth 1 form)) byte-compile-bound-variables)))
93 ;; Bind functions defined by `defun-maybe'.
94 (put 'defun-maybe 'byte-hunk-handler 'byte-compile-file-form-defun-maybe)
95 (defun byte-compile-file-form-defun-maybe (form)
96 (if (and (not (fboundp (nth 1 form)))
97 (memq 'unresolved byte-compile-warnings))
98 (setq byte-compile-function-environment
99 (cons (cons (nth 1 form)
100 (cons 'lambda (cdr (cdr form))))
101 byte-compile-function-environment)))
105 :symbol-for-testing-whether-colon-keyword-is-available-or-not
108 (mapcar (lambda (keyword) (set keyword keyword))
110 :data :file :mime-handle :path :predicate :user))))
112 ;; Unknown variables and functions.
113 (unless (boundp 'buffer-file-coding-system)
114 (defvar buffer-file-coding-system (symbol-value 'file-coding-system)))
115 (autoload 'font-lock-set-defaults "font-lock")
116 (unless (fboundp 'coding-system-get)
117 (defalias 'coding-system-get 'ignore))
119 (defalias 'find-coding-system 'ignore))
120 (unless (fboundp 'get-charset-property)
121 (defalias 'get-charset-property 'ignore))
122 (unless (featurep 'xemacs)
123 (defalias 'Custom-make-dependencies 'ignore)
124 (defalias 'toolbar-gnus 'ignore)
125 (defalias 'update-autoloads-from-directory 'ignore))
127 (unless (fboundp 'with-temp-buffer)
128 ;; Pickup some macros.
131 (defalias 'device-sound-enabled-p 'ignore)
132 (defalias 'play-sound-file 'ignore)
133 (defalias 'nndb-request-article 'ignore)
134 (defalias 'efs-re-read-dir 'ignore)
135 (defalias 'ange-ftp-re-read-dir 'ignore)
136 (defalias 'define-mail-user-agent 'ignore)
139 (unless (string-match "XEmacs" emacs-version)
140 (fset 'get-popup-menu-response 'ignore)
141 (fset 'event-object 'ignore)
142 (fset 'x-defined-colors 'ignore)
143 (fset 'read-color 'ignore)))
145 (defun dgnushack-compile (&optional warn)
146 ;;(setq byte-compile-dynamic t)
148 (setq byte-compile-warnings
149 '(free-vars unresolved callargs redefine)))
150 (unless (locate-library "cus-edit")
151 (error "You do not seem to have Custom installed.
152 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
153 You also then need to add the following to the lisp/dgnushack.el file:
155 (push \"~/lisp/custom\" load-path)
157 Modify to suit your needs."))
158 (let ((files (delete "dgnuspath.el"
159 (directory-files "." nil "^[^=].*\\.el$")))
160 (xemacs (string-match "XEmacs" emacs-version))
161 ;;(byte-compile-generate-call-tree t)
165 (error (setq files (delete "nnweb.el" (delete "nnlistserv.el" files)))))
168 (error (setq files (delete "gnus-bbdb.el" files))))
169 (while (setq file (pop files))
170 (when (or (and (not xemacs)
171 (not (member file '("gnus-xmas.el" "gnus-picon.el"
172 "messagexmas.el" "nnheaderxm.el"
173 "smiley.el" "x-overlay.el"))))
175 (not (member file '("md5.el")))))
176 (when (or (not (file-exists-p (setq elc (concat file "c"))))
177 (file-newer-than-file-p file elc))
179 (byte-compile-file file)))))))
181 (defun dgnushack-recompile ()
183 (byte-recompile-directory "." 0))
186 ;; Avoid byte-compile warnings.
187 (defvar gnus-product-name)
188 (defvar early-package-load-path)
189 (defvar early-packages)
190 (defvar last-package-load-path)
191 (defvar last-packages)
192 (defvar late-package-load-path)
193 (defvar late-packages)
195 (defconst dgnushack-info-file-regexp
196 (concat "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)"
197 "\\.info\\(-[0-9]+\\)?$"))
199 (defconst dgnushack-texi-file-regexp
200 "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)\\.texi$")
202 (defun dgnushack-make-package ()
204 (let* ((product-name (downcase gnus-product-name))
205 (lisp-dir (concat "lisp/" product-name "/"))
208 (message "Updating autoloads for directory %s..." default-directory)
209 (let ((generated-autoload-file "auto-autoloads.el")
211 (omsg (symbol-function 'message)))
212 (defun message (fmt &rest args)
213 (cond ((and (string-equal "Generating autoloads for %s..." fmt)
214 (file-exists-p (file-name-nondirectory (car args))))
215 (funcall omsg fmt (file-name-nondirectory (car args))))
216 ((string-equal "No autoloads found in %s" fmt))
217 ((string-equal "Generating autoloads for %s...done" fmt))
218 (t (apply omsg fmt args))))
220 (update-autoloads-from-directory default-directory)
221 (fset 'message omsg)))
222 (byte-compile-file "auto-autoloads.el")
225 (let ((standard-output (current-buffer)))
226 (Custom-make-dependencies "."))
227 (message (buffer-string)))
229 (byte-compile-file "custom-load.el")
231 (message "Generating MANIFEST.%s for the package..." product-name)
233 (insert "pkginfo/MANIFEST." product-name "\n"
237 (sort (delete "dgnuspath.el"
239 (directory-files "." nil "\\.elc?$")))
241 (concat "\n" lisp-dir))
245 (sort (directory-files "../texi/"
246 nil dgnushack-info-file-regexp)
250 (write-file (concat "../MANIFEST." product-name)))))
252 (defun dgnushack-install-package ()
253 (let ((package-dir (car command-line-args-left))
254 dirs info-dir pkginfo-dir product-name lisp-dir manifest files)
256 (when (boundp 'early-packages)
257 (setq dirs (delq nil (append (when early-package-load-path
259 (when late-package-load-path
261 (when last-package-load-path
263 (while (and dirs (not package-dir))
264 (when (file-exists-p (car dirs))
265 (setq package-dir (car dirs)
269 You must specify the name of the package path as follows:
271 % make install-package PACKAGEDIR=/usr/local/lib/xemacs/xemacs-packages
274 (setq info-dir (expand-file-name "info/" package-dir)
275 pkginfo-dir (expand-file-name "pkginfo/" package-dir))
277 (setq product-name (downcase gnus-product-name)
278 lisp-dir (expand-file-name (concat "lisp/" product-name "/")
280 manifest (concat "MANIFEST." product-name))
282 (unless (file-directory-p lisp-dir)
283 (make-directory lisp-dir t))
284 (unless (file-directory-p info-dir)
285 (make-directory info-dir))
286 (unless (file-directory-p pkginfo-dir)
287 (make-directory pkginfo-dir))
290 (sort (delete "dgnuspath.el"
291 (delete "dgnuspath.elc"
292 (directory-files "." nil "\\.elc?$")))
296 (unless (member file files)
297 (setq file (expand-file-name file lisp-dir))
298 (message "Removing %s..." file)
302 (directory-files lisp-dir nil nil nil t))
305 (message "Copying %s to %s..." file lisp-dir)
306 (copy-file file (expand-file-name file lisp-dir) t t))
311 (message "Copying ../texi/%s to %s..." file info-dir)
312 (copy-file (expand-file-name file "../texi/")
313 (expand-file-name file info-dir)
315 (sort (directory-files "../texi/" nil dgnushack-info-file-regexp)
318 (message "Copying ../%s to %s..." manifest pkginfo-dir)
319 (copy-file (expand-file-name manifest "../")
320 (expand-file-name manifest pkginfo-dir) t t)
324 (defun dgnushack-texi-add-suffix-and-format ()
325 (dgnushack-texi-format t))
327 (defun dgnushack-texi-format (&optional addsuffix)
328 (if (not noninteractive)
329 (error "batch-texinfo-format may only be used -batch."))
331 (let ((auto-save-default nil)
332 (find-file-run-dired nil)
333 coding-system-for-write)
337 (while command-line-args-left
338 (setq file (expand-file-name (car command-line-args-left)))
339 (cond ((not (file-exists-p file))
340 (message ">> %s does not exist!" file)
342 command-line-args-left (cdr command-line-args-left)))
343 ((file-directory-p file)
344 (setq command-line-args-left
345 (nconc (directory-files file)
346 (cdr command-line-args-left))))
348 (setq files (cons file files)
349 command-line-args-left (cdr command-line-args-left)))))
351 (setq file (car files)
355 (if buffer-file-name (kill-buffer (current-buffer)))
357 (setq coding-system-for-write buffer-file-coding-system)
360 "^@setfilename[\t ]+\\([^\t\n ]+\\)" nil t)
361 (not (string-match "\\.info$" (match-string 1))))
363 (buffer-disable-undo (current-buffer))
364 ;; process @include before updating node
365 ;; This might produce some problem if we use @lowersection or such.
366 (let ((input-directory default-directory)
367 (texinfo-command-end))
368 (while (re-search-forward "^@include" nil t)
369 (setq texinfo-command-end (point))
370 (let ((filename (concat input-directory
371 (texinfo-parse-line-arg))))
372 (re-search-backward "^@include")
373 (delete-region (point) (save-excursion (forward-line 1) (point)))
374 (message "Reading included file: %s" filename)
379 (+ (point) (car (cdr (insert-file-contents filename)))))
380 (goto-char (point-min))
381 ;; Remove `@setfilename' line from included file, if any,
382 ;; so @setfilename command not duplicated.
383 (if (re-search-forward
384 "^@setfilename" (save-excursion (forward-line 100) (point)) t)
388 (point) (save-excursion (forward-line 1) (point))))))))))
390 (texinfo-every-node-update)
391 (set-buffer-modified-p nil)
392 (message "texinfo formatting %s..." file)
393 (texinfo-format-buffer nil)
394 (if (buffer-modified-p)
395 (progn (message "Saving modified %s" (buffer-file-name))
398 (message ">> Error: %s" (prin1-to-string err))
399 (message ">> point at")
400 (let ((s (buffer-substring (point)
404 (while (setq tem (string-match "\n+" s tem))
405 (setq s (concat (substring s 0 (match-beginning 0))
407 (substring s (match-end 0)))
411 (kill-emacs error))))
413 ;;; dgnushack.el ends here