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))
126 (autoload 'texinfo-parse-line-arg "texinfmt")
128 (unless (fboundp 'with-temp-buffer)
129 ;; Pickup some macros.
132 (defalias 'device-sound-enabled-p 'ignore)
133 (defalias 'play-sound-file 'ignore)
134 (defalias 'nndb-request-article 'ignore)
135 (defalias 'efs-re-read-dir 'ignore)
136 (defalias 'ange-ftp-re-read-dir 'ignore)
137 (defalias 'define-mail-user-agent 'ignore)
140 (unless (string-match "XEmacs" emacs-version)
141 (fset 'get-popup-menu-response 'ignore)
142 (fset 'event-object 'ignore)
143 (fset 'x-defined-colors 'ignore)
144 (fset 'read-color 'ignore)))
146 (defun dgnushack-compile (&optional warn)
147 ;;(setq byte-compile-dynamic t)
149 (setq byte-compile-warnings
150 '(free-vars unresolved callargs redefine)))
151 (unless (locate-library "cus-edit")
152 (error "You do not seem to have Custom installed.
153 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
154 You also then need to add the following to the lisp/dgnushack.el file:
156 (push \"~/lisp/custom\" load-path)
158 Modify to suit your needs."))
159 (let ((files (delete "dgnuspath.el"
160 (directory-files "." nil "^[^=].*\\.el$")))
161 (xemacs (string-match "XEmacs" emacs-version))
162 ;;(byte-compile-generate-call-tree t)
166 (error (setq files (delete "nnweb.el" (delete "nnlistserv.el" files)))))
169 (error (setq files (delete "gnus-bbdb.el" files))))
170 (while (setq file (pop files))
171 (when (or (and (not xemacs)
172 (not (member file '("gnus-xmas.el" "gnus-picon.el"
173 "messagexmas.el" "nnheaderxm.el"
174 "smiley.el" "x-overlay.el"))))
176 (not (member file '("md5.el")))))
177 (when (or (not (file-exists-p (setq elc (concat file "c"))))
178 (file-newer-than-file-p file elc))
180 (byte-compile-file file)))))))
182 (defun dgnushack-recompile ()
184 (byte-recompile-directory "." 0))
187 ;; Avoid byte-compile warnings.
188 (defvar gnus-product-name)
189 (defvar early-package-load-path)
190 (defvar early-packages)
191 (defvar last-package-load-path)
192 (defvar last-packages)
193 (defvar late-package-load-path)
194 (defvar late-packages)
196 (defconst dgnushack-info-file-regexp
197 (concat "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)"
198 "\\.info\\(-[0-9]+\\)?$"))
200 (defconst dgnushack-texi-file-regexp
201 "^\\(gnus\\|message\\|emacs-mime\\|gnus-ja\\|message-ja\\)\\.texi$")
203 (defun dgnushack-make-package ()
205 (let* ((product-name (downcase gnus-product-name))
206 (lisp-dir (concat "lisp/" product-name "/"))
209 (message "Updating autoloads for directory %s..." default-directory)
210 (let ((generated-autoload-file "auto-autoloads.el")
212 (omsg (symbol-function 'message)))
213 (defun message (fmt &rest args)
214 (cond ((and (string-equal "Generating autoloads for %s..." fmt)
215 (file-exists-p (file-name-nondirectory (car args))))
216 (funcall omsg fmt (file-name-nondirectory (car args))))
217 ((string-equal "No autoloads found in %s" fmt))
218 ((string-equal "Generating autoloads for %s...done" fmt))
219 (t (apply omsg fmt args))))
221 (update-autoloads-from-directory default-directory)
222 (fset 'message omsg)))
223 (byte-compile-file "auto-autoloads.el")
226 (let ((standard-output (current-buffer)))
227 (Custom-make-dependencies "."))
228 (message (buffer-string)))
230 (byte-compile-file "custom-load.el")
232 (message "Generating MANIFEST.%s for the package..." product-name)
234 (insert "pkginfo/MANIFEST." product-name "\n"
238 (sort (delete "dgnuspath.el"
240 (directory-files "." nil "\\.elc?$")))
242 (concat "\n" lisp-dir))
246 (sort (directory-files "../texi/"
247 nil dgnushack-info-file-regexp)
251 (write-file (concat "../MANIFEST." product-name)))))
253 (defun dgnushack-install-package ()
254 (let ((package-dir (car command-line-args-left))
255 dirs info-dir pkginfo-dir product-name lisp-dir manifest files)
257 (when (boundp 'early-packages)
258 (setq dirs (delq nil (append (when early-package-load-path
260 (when late-package-load-path
262 (when last-package-load-path
264 (while (and dirs (not package-dir))
265 (when (file-exists-p (car dirs))
266 (setq package-dir (car dirs)
270 You must specify the name of the package path as follows:
272 % make install-package PACKAGEDIR=/usr/local/lib/xemacs/xemacs-packages
275 (setq info-dir (expand-file-name "info/" package-dir)
276 pkginfo-dir (expand-file-name "pkginfo/" package-dir))
278 (setq product-name (downcase gnus-product-name)
279 lisp-dir (expand-file-name (concat "lisp/" product-name "/")
281 manifest (concat "MANIFEST." product-name))
283 (unless (file-directory-p lisp-dir)
284 (make-directory lisp-dir t))
285 (unless (file-directory-p info-dir)
286 (make-directory info-dir))
287 (unless (file-directory-p pkginfo-dir)
288 (make-directory pkginfo-dir))
291 (sort (delete "dgnuspath.el"
292 (delete "dgnuspath.elc"
293 (directory-files "." nil "\\.elc?$")))
297 (unless (member file files)
298 (setq file (expand-file-name file lisp-dir))
299 (message "Removing %s..." file)
303 (directory-files lisp-dir nil nil nil t))
306 (message "Copying %s to %s..." file lisp-dir)
307 (copy-file file (expand-file-name file lisp-dir) t t))
312 (message "Copying ../texi/%s to %s..." file info-dir)
313 (copy-file (expand-file-name file "../texi/")
314 (expand-file-name file info-dir)
316 (sort (directory-files "../texi/" nil dgnushack-info-file-regexp)
319 (message "Copying ../%s to %s..." manifest pkginfo-dir)
320 (copy-file (expand-file-name manifest "../")
321 (expand-file-name manifest pkginfo-dir) t t)
325 (defun dgnushack-texi-add-suffix-and-format ()
326 (dgnushack-texi-format t))
328 (defun dgnushack-texi-format (&optional addsuffix)
329 (if (not noninteractive)
330 (error "batch-texinfo-format may only be used -batch."))
332 (let ((auto-save-default nil)
333 (find-file-run-dired nil)
334 coding-system-for-write)
338 (while command-line-args-left
339 (setq file (expand-file-name (car command-line-args-left)))
340 (cond ((not (file-exists-p file))
341 (message ">> %s does not exist!" file)
343 command-line-args-left (cdr command-line-args-left)))
344 ((file-directory-p file)
345 (setq command-line-args-left
346 (nconc (directory-files file)
347 (cdr command-line-args-left))))
349 (setq files (cons file files)
350 command-line-args-left (cdr command-line-args-left)))))
352 (setq file (car files)
356 (if buffer-file-name (kill-buffer (current-buffer)))
358 (setq coding-system-for-write buffer-file-coding-system)
361 "^@setfilename[\t ]+\\([^\t\n ]+\\)" nil t)
362 (not (string-match "\\.info$" (match-string 1))))
364 (buffer-disable-undo (current-buffer))
365 ;; process @include before updating node
366 ;; This might produce some problem if we use @lowersection or
368 (let ((input-directory default-directory)
369 (texinfo-command-end))
370 (while (re-search-forward "^@include" nil t)
371 (setq texinfo-command-end (point))
372 (let ((filename (concat input-directory
373 (texinfo-parse-line-arg))))
374 (re-search-backward "^@include")
375 (delete-region (point) (save-excursion
378 (message "Reading included file: %s" filename)
384 (car (cdr (insert-file-contents filename)))))
385 (goto-char (point-min))
386 ;; Remove `@setfilename' line from included file,
387 ;; if any, so @setfilename command not duplicated.
388 (if (re-search-forward "^@setfilename"
395 (delete-region (point) (save-excursion
399 (texinfo-every-node-update)
400 (set-buffer-modified-p nil)
401 (message "texinfo formatting %s..." file)
402 (texinfo-format-buffer nil)
403 (if (buffer-modified-p)
404 (progn (message "Saving modified %s" (buffer-file-name))
407 (message ">> Error: %s" (prin1-to-string err))
408 (message ">> point at")
409 (let ((s (buffer-substring (point)
413 (while (setq tem (string-match "\n+" s tem))
414 (setq s (concat (substring s 0 (match-beginning 0))
416 (substring s (match-end 0)))
420 (kill-emacs error))))
422 ;;; dgnushack.el ends here