;; lisp-initd.el - rc.d inspired configuration management for
;; SXEmacs-lisp
;;
-;; Copyright (C) 2007, Nelson Ferreira
+;; Copyright (C) 2007-2012, Nelson Ferreira
;; Maintainer: Nelson Ferreira
;;
;; This file is part of SXEmacs
;; This file is dumped with SXEmacs
(require 'cl-extra)
-;(require 'bytecomp)
-;(require 'byte-optimize)
-;(require 'bytecomp-runtime)
-(eval-when-compile
- (defvar lisp-initd-dir)) ; Now in startup.el
+(defvar lisp-initd-basename "init.d"
+ "The default basename for the compiled init file.")
+
+(defvar lisp-initd-dir
+ (file-name-as-directory
+ (paths-construct-path (list user-init-directory lisp-initd-basename)))
+ "The default directory for the init files.")
-(defvar lisp-initd-prefix ""
- "The default prefix for the compiled init file.")
(defvar lisp-initd-keep-elisp t
"If TRUE the initd resulting lisp file is kept.
"Kill the byte-compile Compile Log buffers")
-(defvar lisp-initd-gather-func #'directory-files
+(defvar lisp-initd-gather-func #'directory-files
"Function used to gather the files used in init. For acceptable
arguments see `directory-files'. The function is expected to return a
sorted list of absolute pathnames, accept and honor the MATCH argument
and return files only.")
-(defun lisp-initd-compile (&optional dir prefix do-init)
- "Compile the lisp files in DIR into a file named {DIR}/{PREFIX}init.d.el.
+(defun lisp-initd-compile (&optional dir file do-init)
+ "Compile the lisp files in DIR into a file named {DIR}/{FILE}.
If DIR is nil `lisp-initd-dir' is used.
-If PREFIX is nil `lisp-initd-prefix' is used.
+If FILE is nil `lisp-initd-basename' is used.
If DO-INIT is non-nil the file is loaded."
- (let* ((initd-dir (or dir lisp-initd-dir))
- (initd-file (concat (or prefix lisp-initd-prefix)
- "init.d"))
+ (let* ((initd-dir (file-name-as-directory
+ (expand-file-name
+ (or dir lisp-initd-dir))))
+ (initd-file (or file lisp-initd-basename))
(initd-el (expand-file-name (concat initd-file ".el")
- (paths-construct-path
+ (paths-construct-path
(list initd-dir ".."))))
- (initd-elc (concat initd-el "c"))
- (initd-files (funcall lisp-initd-gather-func initd-dir
- t "^.*\.el$" nil t))
+ (initd-elc (concat initd-el "c"))
+ (initd-files (funcall lisp-initd-gather-func initd-dir
+ t "^.*\\.el$" nil t))
(init-file (if lisp-initd-byte-compile-elisp initd-elc initd-el))
- init-buffer)
+ init-buffer)
;; No use in keeping an outdate byte-compiled file...
(when (and (file-exists-p initd-el)
(message "Recompiling init files....")
(setq init-buffer (generate-new-buffer (concat "*" initd-el "*")))
(with-current-buffer init-buffer
- (set-visited-file-name initd-el)
+ (set-visited-file-name initd-el)
(insert ";; This is an automatically generated file.\n"
";; DO NOT EDIT\n"
";;\n")
(insert "(message \"Compiled " initd-dir " loading started\")\n")
- (mapc
+ (mapc
#'(lambda (current)
(condition-case err
(insert "(condition-case err (progn\n"
";; ------------------------------------\n"
";; " current "\n"
- (save-excursion
- (save-restriction
+ (save-excursion
+ (save-restriction
(with-temp-buffer
(insert-file-contents current)
(eval-buffer)
"\n"
";; ----------------------------------\n"
")\n"
- "(error (message \"Error loading " current
+ "(error (message \"Error loading " current
": \\\"%S\\\" (signal:\'%S\' . data:\'%S\')\" "
"err (car err) (cdr err))))\n"
";; ----------------------------------\n\n")
(error
(progn
- (insert "(message \"\\\"" current
+ (insert "(warn \"\\\"" current
"\\\" not inserted "
- (replace-regexp-in-string
+ (replace-regexp-in-string
"\"" "\\\""
(format (concat "due to syntax error: %S"
" (signal:%S . data:%S)")
(load init-file nil nil t))))
-(defun lisp-initd-compile-and-load (&optional dir prefix)
- "Compile and load the lisp files in DIR into a file named {DIR}/{PREFIX}init.d.el.
+(defun lisp-initd-compile-and-load (&optional dir file)
+ "Compile and load the lisp files in DIR into a file named {DIR}/{FILE}.el.
If DIR, a string, is omitted `lisp-initd-dir' is used. DIR can be
either a complete path, or the last element of a path. If the latter,
DIR is expanded against the _parent_ directory of `lisp-initd-dir'.
-Optional prefix arg, PREFIX is a string that is prepended to the generated
-filename to be loaded. If it is omitted, `lisp-initd-prefix' is used.
+Optional file arg, FILE is the name of the file to be loaded.
+If it is omitted, `lisp-initd-basename' is used.
See `lisp-initd-compile'."
(interactive (list (expand-file-name (read-directory-name
(when dir
(unless (string-match "/" dir)
(setq dir (file-name-as-directory
- (expand-file-name dir (paths-construct-path
+ (expand-file-name dir (paths-construct-path
(list lisp-initd-dir "..")))))))
(when current-prefix-arg
- (setq prefix (read-string "Prefix: ")))
-
- (lisp-initd-compile dir prefix t))
+ (setq file (read-string "File: ")))
-(provide 'lisp-initd)
+ (lisp-initd-compile dir file t))
+(provide 'lisp-initd)