lookup / install.el

;;; install.el --- Lookup installer
;; Copyright (C) 1999 NISHIDA Keisuke <knishida@ring.aist.go.jp>

;; $Id$

;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License
;; as published by the Free Software Foundation; either version 2
;; of the License, or (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

;;; Code:

(if (string< emacs-version "19.29")
    (setq command-line-args-left (cdr command-line-args-left)))

(defconst install-elisp-files
  '("evi.el" "evi-mule.el" "lookup.el" "lookup-utils.el" "lookup-types.el"
    "lookup-vars.el" "lookup-vse.el" "lookup-package.el"
    "lookup-entry.el" "lookup-content.el" "lookup-select.el"
    "ndic.el" "ndeb.el" "ndtp.el" "ndict.el" "ndkks.el" "ndsrd.el"
    "ndspell.el" "ndcookie.el" "ndmisc.el" "sdicf.el" "stem-english.el"))

(defconst install-info-files
  '("lookup.info" "lookup-guide.info"))

(defvar install-lisp-directory nil)
(defvar install-info-directory nil)
(defvar install-lookup-version "unknown")

(defun install-check-directory (directory)
  (and (not (file-exists-p directory))
       (y-or-n-p (format "Directory %s is not exist.  Creat it? " directory))
       (make-directory directory t))
  (if (not (file-directory-p directory))
      (error "%s is not directory" directory))
  (directory-file-name (expand-file-name directory)))

(or (fboundp 'with-current-buffer)
    (defmacro with-current-buffer (buffer &rest body)
      (` (save-current-buffer
	   (set-buffer (, buffer))
	   (,@ body)))))

;; get the version number of lookup
(with-current-buffer (get-buffer-create " *work lookup-version*")
  (setq install-lookup-version
	(condition-case nil
	      (insert-file-contents "VERSION")
	      (goto-char (point-min))
	      (buffer-substring (point-min) (progn (end-of-line) (point))))
	  (error "unknown")))
  (kill-buffer (current-buffer)))

;; message

(if noninteractive nil
  (switch-to-buffer (generate-new-buffer "*Lookup Installer*"))
  (insert "Lookup $B%$%s%9%H!<%i(B\n")
  (insert "===================\n\n")
  (insert "Lookup $B$N%$%s%9%H!<%k$r;O$a$^$9!#(B")
  (insert "$BESCf$GCfCG$9$k$K$O(B C-g $B$r2!$7$F2<$5$$!#(B\n\n"))

;; directory

(if noninteractive nil
  (insert "$B%G%#%l%/%H%j$N7hDj(B\n")
  (insert "------------------\n\n")
  (insert "elisp $B%U%!%$%k$N%G%#%l%/%H%j$rF~NO$7$F2<$5$$(B:\n"))
(let ((default "~/emacs/lisp/lookup/"))
  (setq install-lisp-directory
	 (if noninteractive
	     (or (car command-line-args-left) default)
	   (read-file-name "Lisp directory: " default default)))))
(if noninteractive nil
  (insert "    -> " install-lisp-directory "\n\n") (sit-for 0))

(if noninteractive nil
  (insert "info $B%U%!%$%k$N%G%#%l%/%H%j$rF~NO$7$F2<$5$$(B:\n"))
(let ((default "~/emacs/info/"))
  (setq install-info-directory
	 (if noninteractive
	     (or (car (cdr command-line-args-left)) default)
	   (read-file-name "Info directory: " default default)))))
(if noninteractive nil
  (insert "    -> " install-info-directory "\n\n") (sit-for 0))

;; lookup-vars.el

(if noninteractive nil
  (insert "$B%$%s%9%H!<%k$N<B9T(B\n")
  (insert "------------------\n\n")
  (insert "lookup-vars.el.in $B$+$i(B lookup-vars.el $B$r@8@.Cf(B...") (sit-for 0))
(with-current-buffer (find-file-noselect "lisp/lookup-vars.el.in" t)
  (if (search-forward "@VERSION@")
      (replace-match install-lookup-version))
  (if (search-forward "@pkgemacsdir@")	;needs to be fixed to the correct one
      (replace-match install-lisp-directory))
  (write-file "lookup-vars.el")
  (kill-buffer (current-buffer))
(message "Copied lookup-vars.el.in to lookup-vars.el")
(if (not noninteractive) (insert "done\n"))

;; compile

(if noninteractive nil
  (insert "elisp $B%U%!%$%k$N%3%s%Q%$%kCf(B...") (sit-for 0))
(let* ((default-directory (expand-file-name "lisp/"))
       (lookup-compile-directory default-directory)
       (command-line-args-left (if (string< emacs-version "19.29")
				   (cons nil install-elisp-files)
  (load (expand-file-name "lookup-compile.el")))
(if (not noninteractive) (insert "done\n"))

;; install

(if noninteractive nil
  (insert "elisp $B%U%!%$%k$N%$%s%9%H!<%kCf(B...") (sit-for 0))
(mapcar (lambda (file)
	  (copy-file (expand-file-name file "lisp/")
		     (expand-file-name file install-lisp-directory) t)
	  (message "Installed %s to %s" file install-lisp-directory)
	  (setq file (byte-compile-dest-file file))
	  (copy-file (expand-file-name file "lisp/")
		     (expand-file-name file install-lisp-directory) t)
	  (message "Installed %s to %s" file install-lisp-directory))
(if (not noninteractive) (insert "done\n"))

(if noninteractive nil
  (insert "info $B%U%!%$%k$N%U%)!<%^%C%HCf(B...") (sit-for 0))
(mapcar (lambda (info)
	  (if (file-readable-p (expand-file-name info "texi/"))
	    ;; the pre-formatted .info file does not exist; format it here
	    (let ((texi (concat (file-name-sans-extension info) ".texi")))
		      (let ((buf (find-file-noselect 
				  (expand-file-name texi "texi/") t)))
			(set-buffer buf)
			(texinfo-format-buffer t) ; t for nosplit
			(save-buffer 0)
			(kill-buffer (current-buffer))
			(kill-buffer buf))))))
(if (not noninteractive) (insert "done\n"))

(if noninteractive nil
  (insert "info $B%U%!%$%k$N%$%s%9%H!<%kCf(B...") (sit-for 0))
(mapcar (lambda (info)
	  (mapcar (lambda (file)
		    (copy-file (expand-file-name file "texi/")
			       (expand-file-name file install-info-directory)
		    (message "Installed %s to %s" file install-info-directory))
		  (directory-files "texi/" nil info)))
(if (not noninteractive) (insert "done\n"))

;; clean

(if noninteractive nil
  (insert "$B0l;~%U%!%$%k$N:o=|Cf(B...") (sit-for 0))
(let ((default-directory (expand-file-name "lisp/")))
  (delete-file "lookup-vars.el")
  (mapcar (lambda (file)
	    (delete-file (byte-compile-dest-file (expand-file-name file))))
(message "Removed lookup-vars.el, *.elc")
(if (not noninteractive) (insert "done\n"))

;; initialize

(if noninteractive nil
  (insert "Lookup $B$N=i4|2=Cf(B...")
  (sit-for 0)
  (insert "done\n")
  (kill-buffer (current-buffer)))

;; congratulate

(if noninteractive
    (message "\nSee etc/SETUP for the setup after installation")
  (switch-to-buffer (generate-new-buffer "*Congratulations!*"))
  (insert-file-contents "etc/SETUP")
  (if (search-forward "@install-lisp-directory@")
      (replace-match install-lisp-directory))
  (if (search-forward "@install-info-directory@")
      (replace-match install-info-directory))
  (goto-char (point-min))
  (set-buffer-modified-p nil)
  (local-set-key "\C-c\C-c" 'install-open-info))

(defun install-open-info ()
  (require 'info)
  (Info-find-node (expand-file-name "lookup-guide" install-info-directory)

;;; install.el ends here
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.