1 ;;; auto-install.el --- Auto install elisp file
2 ;; $Id: auto-install.el,v 1.53 2011/04/12 06:28:20 rubikitch Exp $
4 ;; Filename: auto-install.el
5 ;; Description: Auto install elisp file
6 ;; Author: Andy Stewart <lazycat.manatee@gmail.com>
7 ;; rubikitch <rubikitch@ruby-lang.org>
8 ;; Maintainer: rubikitch <rubikitch@ruby-lang.org>
9 ;; Copyright (C) 2008, 2009, Andy Stewart, all rights reserved.
10 ;; Copyright (C) 2009, rubikitch, all rights reserved.
11 ;; Created: 2008-12-11 13:56:50
12 ;; Version: $Revision: 1.53 $
13 ;; URL: http://www.emacswiki.org/emacs/download/auto-install.el
14 ;; Keywords: auto-install
15 ;; Compatibility: GNU Emacs 22 ~ 23
17 ;; Features that might be required by this library:
19 ;; `backquote', `bytecomp', `dired', `find-func', `ietf-drums',
20 ;; `loadhist', `mail-parse', `mail-prsvr', `mailcap', `mm-util',
21 ;; `qp', `rfc2045', `rfc2047', `rfc2231', `thingatpt', `time-date',
22 ;; `timezone', `url', `url-cookie', `url-expand', `url-history',
23 ;; `url-methods', `url-parse', `url-privacy', `url-proxy',
24 ;; `url-util', `url-vars'.
27 (defvar auto-install-version "$Id: auto-install.el,v 1.53 2011/04/12 06:28:20 rubikitch Exp $")
28 ;;; This file is NOT part of GNU Emacs
32 ;; This program is free software; you can redistribute it and/or modify
33 ;; it under the terms of the GNU General Public License as published by
34 ;; the Free Software Foundation; either version 3, or (at your option)
37 ;; This program is distributed in the hope that it will be useful,
38 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
39 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 ;; GNU General Public License for more details.
42 ;; You should have received a copy of the GNU General Public License
43 ;; along with this program; see the file COPYING. If not, write to
44 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
45 ;; Floor, Boston, MA 02110-1301, USA.
49 ;; Automates the installation of Emacs Lisp files and packages.
51 ;; `auto-install' provides an automated way to:
53 ;; (1) Download Emacs Lisp files and packages from common sources
54 ;; (2) View them (diff) and save them to your repository
55 ;; (3) Compile and Load them
60 ;; Below are complete command list:
62 ;; `auto-install-minor-mode'
63 ;; Auto Install minor mode.
64 ;; `auto-install-from-buffer'
65 ;; Install the elisp file in the current buffer.
66 ;; `auto-install-from-url'
67 ;; Install an elisp file from a given url.
68 ;; `auto-install-from-emacswiki'
69 ;; Install an elisp file from EmacsWiki.org.
70 ;; `auto-install-from-gist'
71 ;; Install an elisp file from gist.github.com.
72 ;; `auto-install-from-library'
73 ;; Update an elisp LIBRARY.
74 ;; `auto-install-from-directory'
75 ;; Update elisp files under DIRECTORY from EmacsWiki.
76 ;; `auto-install-from-dired'
77 ;; Update dired marked elisp files from EmacsWiki.org.
78 ;; `auto-install-update-emacswiki-package-name'
79 ;; Update the list of elisp package names from `EmacsWiki'.
80 ;; `auto-install-dired-mark-files'
81 ;; Mark dired files that contain at `EmacsWiki.org'.
82 ;; `auto-install-mode'
83 ;; Major mode for auto-installing elisp code.
84 ;; `auto-install-buffer-quit'
85 ;; Quit from `auto-install' temporary buffer.
86 ;; `auto-install-compatibility-setup'
87 ;; Install Compatibility commands for install-elisp.el users.
88 ;; `auto-install-batch'
89 ;; Batch install many files (libraries and non-elisp files) in some extension.
90 ;; `auto-install-batch-edit'
91 ;; Edit auto-install-batch-list.el
92 ;; `auto-install-buffer-diff'
93 ;; View different between old version.
94 ;; `auto-install-buffer-save'
95 ;; Save downloaded content to file FILENAME.
97 ;;; Customizable Options:
99 ;; Below are customizable option list:
101 ;; `auto-install-directory'
102 ;; The directory for saving elisp files.
103 ;; default = "~/.emacs.d/auto-install/"
104 ;; `auto-install-buffer-name'
105 ;; The temporary buffer for storing download content.
106 ;; default = "auto-install"
107 ;; `auto-install-emacswiki-base-url'
108 ;; The base emacswiki.org url from which to download elisp files.
109 ;; default = "http://www.emacswiki.org/cgi-bin/wiki/download/"
110 ;; `auto-install-gist-base-url'
111 ;; The base gist.github.com url from which to download elisp files.
112 ;; default = "http://gist.github.com/"
113 ;; `auto-install-filter-url'
114 ;; Alist mapping filter url for library.
115 ;; default = (quote (("color-grep" "http://www.bookshelf.jp/elc/")))
116 ;; `auto-install-save-confirm'
117 ;; Whether confirmation is needed to save downloaded content.
119 ;; `auto-install-replace-confirm'
120 ;; Whether confirmation is needed to replace an existing elisp file.
122 ;; `auto-install-install-confirm'
123 ;; Whether confirmation is needed to install a downloaded elisp file.
125 ;; `auto-install-from-dired-confirm'
126 ;; Whether confirmation is needed to download marked files from Dired.
128 ;; `auto-install-wget-command'
129 ;; *Wget command. Use only if `auto-install-use-wget' is non-nil.
131 ;; `auto-install-use-wget'
132 ;; *Use wget instead of `url-retrieve'.
134 ;; `auto-install-batch-list'
135 ;; This list contain packages information for batch install.
140 ;; Downloading is asynchronous: you can do your work and download
141 ;; files at the same time. The download process won't hang
144 ;; `auto-install-from-url' remembers previous installations. So if
145 ;; your search is the same as the previous search, you don't need
146 ;; to type it in, just hit RETURN.
148 ;; `auto-install-from-emacswiki' will complete then names of
149 ;; packages from those in the Elisp area in `EmacsWiki'.
151 ;; `auto-install-from-library' will prompt you library name in
152 ;; you load-path, then it try to download from EmacsWiki if it
153 ;; can't find match in `auto-install-filter-url'.
155 ;; `auto-install-from-directory' can install elisp file
156 ;; under specify directory.
158 ;; `auto-install-from-dired' can install marked files using dired.
159 ;; You can mark the files you want in dired and then use
160 ;; `auto-install-from-dired' to download those files
163 ;; `auto-install-from-buffer' can save and install the contents of
164 ;; the current buffer as a file. You need a valid elisp file name.
165 ;; The default name is the buffer name.
167 ;; `auto-install-from-emacswiki' and `auto-install-from-library'
168 ;; will try to pick up file around point, you can move
169 ;; cursor to file name, and just hit RET for install.
171 ;; Some extension (such as icicles) have many libraries to need install,
172 ;; and install one by one is painful, you can use command
173 ;; `auto-install-batch' install all icicles libraries.
174 ;; And `auto-install-batch' handle max connect limit with some website
175 ;; (such as EmacsWiki) to avoid download failed.
177 ;; All of the above functions support a filename filter. You can
178 ;; input any url to download an elisp file, if the file name suffix is
179 ;; `.el', it will download and install the file automatically.
180 ;; Otherwise, it won't install it unless you input a valid elisp
183 ;; By default, if a file that you download does not exist on your
184 ;; system the file is downloaded to `auto-install-directory'. If
185 ;; you already have a file with the same name in your load
186 ;; directory, `auto-install' will try to replace that file.
188 ;; You can use command `auto-install-dired-mark-files' to mark files
189 ;; that contain at `EmacsWiki.org' for fast update.
191 ;; By default, command `auto-install-from-emacswiki' will initialization
192 ;; current symbol as default value, if default value is you want,
193 ;; just hit RET, so lazy!
198 ;; (1) Put auto-install.el somewhere in your load-path.
200 ;; For example, put it into ~/elisp/.
201 ;; Then add the following to your ~/.emacs:
203 ;; (add-to-list 'load-path (expand-file-name "~/elisp"))
205 ;; (2) And put the following in your ~/.emacs startup file:
207 ;; (require 'auto-install)
209 ;; (3) Add this to your ~/.emacs to optionally specify a download directory:
211 ;; (setq auto-install-directory "~/.emacs.d/auto-install/")
213 ;; If you don't set this, "~/.emacs.d/auto-install/" will be used as the default,
214 ;; and will be created as needed.
216 ;; (4) Optionally, if your computer is always connected Internet when Emacs start up,
217 ;; I recommend you add below to your ~/.emacs, to update package name when start up:
219 ;; (auto-install-update-emacswiki-package-name t)
221 ;; And above setup is not necessary, because AutoInstall will automatically update
222 ;; package name when you just first call `auto-install-from-emacswiki',
223 ;; above setup just avoid *delay* when you first call `auto-install-from-emacswiki'.
225 ;; (5) I recommend you add below to your ~/.emacs for install-elisp users:
227 ;; (auto-install-compatibility-setup)
229 ;; This command `defalias'es `install-elisp',
230 ;; `install-elisp-from-emacswiki' and `install-elisp-from-gist' to
231 ;; `auto-install' ones.
233 ;; (6) If you want to use proxy server, set `url-proxy-services'. For example:
235 ;; (setq url-proxy-services '(("http" . "localhost:8339")))
239 ;; `auto-install-directory'
240 ;; The default directory for keeping auto-downloaded elisp files.
242 ;; `auto-install-buffer-name'
243 ;; The base buffer name for temporarily storing downloaded download content.
245 ;; `auto-install-emacswiki-base-url'
246 ;; The base url for downloading from EmacsWiki.org.
248 ;; `auto-install-gist-base-url'
249 ;; The base url for downloading from gist.github.com
251 ;; `auto-install-filter-url'
252 ;; Filter url for downloading a special library.
254 ;; `auto-install-save-confirm'
255 ;; Whether to require confirmation when saving downloaded content.
257 ;; `auto-install-replace-confirm'
258 ;; Whether to require confirmation when replacing an already-installed
261 ;; `auto-install-install-confirm'
262 ;; Whether to require confirmation when installing a file.
264 ;; `auto-install-from-dired-confirm'
265 ;; Whether to require confirmation when downloading files marked in dired.
267 ;; `auto-install-batch-list'
268 ;; This list contain packages information for batch install.
269 ;; Anyone can add packages information in this list for batch install.
271 ;; And all above option can customize easy through:
272 ;; M-x RET customize-group RET auto-install RET
278 ;; If you have problem, send a bug report via M-x auto-install-send-bug-report.
280 ;; 0) Setup mail in Emacs, the easiest way is:
281 ;; (setq user-mail-address "your@mail.address")
282 ;; (setq user-full-name "Your Full Name")
283 ;; (setq smtpmail-smtp-server "your.smtp.server.jp")
284 ;; (setq mail-user-agent 'message-user-agent)
285 ;; (setq message-send-mail-function 'message-smtpmail-send-it)
286 ;; 1) Be sure to use the LATEST version of auto-install.el.
287 ;; 2) Enable debugger. M-x toggle-debug-on-error or (setq debug-on-error t)
288 ;; 3) Use Lisp version instead of compiled one: (load "auto-install.el")
290 ;; 5) If you got an error, please do not close *Backtrace* buffer.
291 ;; 6) M-x auto-install-send-bug-report and M-x insert-buffer *Backtrace*
292 ;; 7) Describe the bug using a precise recipe.
293 ;; 8) Type C-c C-c to send.
294 ;; # If you are a Japanese, please write in Japanese:-)
298 ;; $Log: auto-install.el,v $
299 ;; Revision 1.53 2011/04/12 06:28:20 rubikitch
302 ;; Revision 1.52 2011/01/29 11:11:47 rubikitch
303 ;; bugfix: auto-install-buffer-save cannot treat auto-install-directory properly if it doesn't end with `/'
305 ;; patched by MaskRay thanks!
307 ;; Revision 1.51 2010/12/10 10:30:58 rubikitch
308 ;; Bugfix when wget is not installed
310 ;; replace auto-install-use-wget with (auto-install-use-wget-p)
312 ;; Revision 1.50 2010/11/29 15:52:57 rubikitch
313 ;; compatibility code for emacs21.1
315 ;; Revision 1.49 2010/11/10 13:32:37 rubikitch
316 ;; Use `wget -q -O- --no-check-certificate' if wget is available.
317 ;; Change default value: `auto-install-use-wget' = t
319 ;; Revision 1.48 2010/05/20 23:29:10 rubikitch
320 ;; `auto-install-update-emacswiki-package-name': Check whether network is reachable
322 ;; Revision 1.47 2010/05/14 00:09:08 rubikitch
323 ;; Fixed a bug of `auto-install-batch' with argument.
325 ;; Pass extension-name argument to `auto-install-batch-real'.
327 ;; Revision 1.46 2010/05/04 08:46:21 rubikitch
328 ;; Added bug report command
330 ;; Revision 1.45 2010/05/01 01:24:25 rubikitch
331 ;; auto-install-batch: Dependency support
333 ;; Revision 1.44 2010/05/01 00:53:48 rubikitch
334 ;; auto-install-batch-real: refactoring
336 ;; Revision 1.43 2010/04/30 23:41:48 rubikitch
337 ;; Changed default value of `auto-install-use-wget' to nil.
339 ;; Revision 1.42 2010/04/25 02:30:27 rubikitch
340 ;; Avoid `auto-async-byte-compile'
342 ;; Revision 1.41 2010/04/25 01:59:20 rubikitch
343 ;; *** empty log message ***
345 ;; Revision 1.40 2010/04/25 01:58:17 rubikitch
346 ;; Do not save/compile up-to-date files from `auto-install-batch'.
348 ;; Revision 1.39 2010/04/25 01:11:33 rubikitch
349 ;; If downloaded file is not updated, kill download buffer.
350 ;; (auto-install-batch support is not yet)
352 ;; Revision 1.38 2010/04/25 00:10:49 rubikitch
353 ;; code cleanup: remove unneeded `format'
355 ;; Revision 1.37 2010/04/24 23:59:11 rubikitch
356 ;; comment change (no code change)
358 ;; Revision 1.36 2010/04/19 07:10:36 rubikitch
359 ;; Avoid updating time-stamp
361 ;; Revision 1.35 2010/04/07 20:16:10 rubikitch
364 ;; Revision 1.34 2010/04/05 21:34:07 rubikitch
365 ;; `auto-install-from-gist' can accept gist URL.
367 ;; Revision 1.33 2010/04/05 21:27:30 rubikitch
368 ;; `auto-install-use-wget' is enabled by default when wget command (`auto-install-wget-command') is found.
370 ;; Revision 1.32 2010/04/05 21:24:30 rubikitch
371 ;; * `auto-install-batch' can install non-elisp files because some elisp requires external scripts.
372 ;; * New option: `auto-install-add-exec-path-flag'
374 ;; Revision 1.31 2010/04/01 03:43:17 rubikitch
377 ;; Revision 1.30 2010/04/01 03:42:34 rubikitch
380 ;; Revision 1.29 2010/04/01 03:28:39 rubikitch
381 ;; New command: `auto-install-batch-edit'
383 ;; Revision 1.28 2010/04/01 03:10:38 rubikitch
384 ;; The real value of `auto-install-batch-list' is moved to
385 ;; auto-install-batch-list.el to split program and data.
387 ;; Revision 1.27 2010/03/29 07:36:39 rubikitch
388 ;; Stupid bug fix in auto-install-use-wget
390 ;; Revision 1.26 2010/03/29 02:38:46 rubikitch
391 ;; New option: `auto-install-use-wget', `auto-install-wget-command'
393 ;; Revision 1.25 2010/03/26 00:07:27 rubikitch
394 ;; `url-http-end-of-headers' workaround
396 ;; Revision 1.24 2010/01/05 09:40:04 rubikitch
397 ;; fixed error of auto-complete development version in `auto-install-batch-list'
399 ;; Revision 1.23 2009/12/29 09:31:23 rubikitch
400 ;; add Text Translator to auto-install-batch-list
402 ;; Revision 1.22 2009/12/21 12:51:56 rubikitch
403 ;; Update auto-install-batch anything
405 ;; Revision 1.21 2009/12/21 12:26:54 rubikitch
406 ;; New URL for auto-complete development version
408 ;; Revision 1.20 2009/05/22 20:17:24 rubikitch
409 ;; Merged from dradams' change
411 ;; Revision 1.19 2009/05/22 13:04:56 dadams
412 ;; Split icicles-cmd.el into icicles-cmd[12].el.
414 ;; Revision 1.18 2009/05/20 15:42:54 rubikitch
415 ;; Add php-completion / perl-completion to auto-install-batch-list
417 ;; Revision 1.17 2009/05/20 01:19:15 rubikitch
418 ;; Add document for proxy server
420 ;; Revision 1.16 2009/05/15 20:28:18 rubikitch
421 ;; More readable temporary buffer name.
423 ;; Revision 1.15 2009/05/15 20:12:49 rubikitch
424 ;; Added missing require
426 ;; Revision 1.14 2009/05/15 20:11:44 rubikitch
429 ;; Revision 1.13 2009/05/15 20:09:07 rubikitch
432 ;; Revision 1.12 2009/05/15 19:59:30 rubikitch
433 ;; Fixed a bug of single file installation
435 ;; Revision 1.11 2009/05/15 19:44:32 rubikitch
436 ;; Ordering `auto-install-batch'
438 ;; Revision 1.10 2009/05/15 17:48:09 rubikitch
439 ;; Replace `message' with `error' for error messages.
441 ;; Revision 1.9 2009/05/15 17:40:37 rubikitch
444 ;; Revision 1.8 2009/05/15 17:19:47 rubikitch
447 ;; Revision 1.7 2009/05/15 17:17:03 rubikitch
448 ;; Use `view-mode' if `view-read-only'.
450 ;; Revision 1.6 2009/05/15 17:10:22 rubikitch
451 ;; Adjust docstrings of commands to auto-document.
452 ;; Delete `It provides the following commands:' section because of duplication.
454 ;; Revision 1.5 2009/05/15 17:03:13 rubikitch
455 ;; Show downloaded URL in header-line.
457 ;; Revision 1.4 2009/05/15 16:59:32 rubikitch
458 ;; New internal variable: `auto-install-add-load-path-flag'
460 ;; Revision 1.3 2009/05/09 02:41:32 rubikitch
461 ;; Add `auto-install-directory' automatically.
463 ;; Revision 1.2 2009/05/09 02:37:14 rubikitch
464 ;; Changed `auto-install-get-buffer' format (including URL)
466 ;; Revision 1.1 2009/05/09 02:33:09 rubikitch
471 ;; * Take over by rubikitch.
475 ;; * Encoding detection support.
479 ;; * Fix bug of `auto-install-batch'.
480 ;; * Add more sources to `auto-install-batch-list'.
484 ;; * Add new command: `auto-install-batch'.
485 ;; * Add new option: `auto-install-batch-list'.
489 ;; * Add new function: `auto-install-from-url-list'.
493 ;; * Fix bug of `auto-install-download'.
497 ;; * Add new command `auto-install-compatibility-setup'
498 ;; for install-elisp users.
500 ;; * `auto-install-region-or-thing' return region string
501 ;; just when `transient-mark-mode' is on.
506 ;; * Modified keybindings, make it more easy to remember.
507 ;; * Make `auto-install-save-confirm' default with `t'
508 ;; for security problem.
509 ;; * Pick up current symbol when use `auto-install-from-library'.
510 ;; * Remove unnecessary completion name from `auto-install-from-library'.
516 ;; * Remove option `auto-install-update-emacswiki-package-name-when-startup'.
517 ;; * Make current symbol as initialization of `auto-install-from-emacswiki'.
518 ;; * Add option `unforced' to function `auto-install-update-emacswiki-package-name'.
520 ;; * Fix bug of `auto-install-from-library'.
524 ;; * Automatically download package name list when
525 ;; variable `auto-install-package-name-list' is nil.
526 ;; * Reverse `auto-install-package-name-list' for `anything' interface.
527 ;; * New command `auto-install-dired-mark-files',
528 ;; mark files that contain at `EmacsWiki.org'.
529 ;; * New command `auto-install-buffer-diff',
530 ;; view different between current version and old version.
534 ;; * Add new command `auto-install-from-directory'.
535 ;; * Remove option `auto-install-create-directory', not necessary.
536 ;; * Documentation improvements (thanks Scot Becker)
540 ;; * Make command `auto-install-from-emacswiki' can
541 ;; completing package name for input.
542 ;; * Add new command `auto-install-update-emacswiki-package-name'.
543 ;; * Add new option `auto-install-update-emacswiki-package-name-when-startup'
547 ;; * Compatibility with GNU Emacs 22.
551 ;; * Add new command `auto-install-from-gist'.
555 ;; * Add emacs-lisp syntax highlight for download buffer.
556 ;; * Make notify message display at mode-line instead echo-area.
560 ;; * Add new option `auto-install-filter-url' and new function
561 ;; `auto-install-from-library', try to use it. ;)
569 ;; * Move `w3m' code to file `auto-install-extension.el' to make all
570 ;; user can use this package with standard emacs.
578 ;; * Add new option `auto-install-create-directory' for create install directory
579 ;; automatically if it doesn't exist.
580 ;; * Improve many document make it more clear.
581 ;; * Thanks document improve and create directory advice of 'Drew Adams'!
585 ;; * Remove `auto-install-window-configuration-before-download', `auto-install-init-window-layout'
586 ;; and `auto-install-revert-window-layout'.
587 ;; It's not necessary to revert window layout, `winner-mode' can revert window layout more better,
588 ;; just type `winner-undo'.
592 ;; * Fix a little bug of `auto-install-window-configuration-before-download'.
596 ;; * Add new function `auto-install-from-buffer', to install elisp file from current buffer.
597 ;; Modified `auto-install-buffer-save' to use `auto-install-from-buffer'.
602 ;;; Acknowledgements:
604 ;; rubikitch <rubikitch@ruby-lang.org>
605 ;; For install-elisp.el
606 ;; Drew Adams <drew.adams@oracle.com>
607 ;; Scot Becker <scot.becker@gmail.com>
608 ;; Richard Riley <rileyrgdev@gmail.com>
609 ;; For documentation improvements and advices.
614 ;; Fix the problem parallel install process with recursive prompt.
615 ;; Redesign and give more friendly user interface.
616 ;; Scan RSS track package update and notify.
626 (eval-when-compile (require 'cl))
627 (when (<= emacs-major-version 22) ;Compatibility with 22.
628 (autoload 'ignore-errors "cl-macs")
629 (unless (fboundp 'url-file-nondirectory)
630 (defun url-file-nondirectory (file)
631 "Return the nondirectory part of FILE, for a URL."
634 ((string-match (eval-when-compile (regexp-quote "?")) file)
635 (file-name-nondirectory (substring file 0 (match-beginning 0))))
636 (t (file-name-nondirectory file))))))
640 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Customize ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
641 (defgroup auto-install nil
642 "Auto install elisp files."
645 (defcustom auto-install-directory "~/.emacs.d/auto-install/"
646 "The directory for saving elisp files.
647 This directory is used when a downloaded
648 elisp file does not already exist in other directory.
649 Otherwise, the existing file of the same name is replaced."
651 :group 'auto-install)
653 (defcustom auto-install-buffer-name "auto-install"
654 "The temporary buffer for storing download content."
656 :group 'auto-install)
658 (defcustom auto-install-emacswiki-base-url "http://www.emacswiki.org/cgi-bin/wiki/download/"
659 "The base emacswiki.org url from which to download elisp files."
661 :group 'auto-install)
663 (defcustom auto-install-gist-base-url "http://gist.github.com/"
664 "The base gist.github.com url from which to download elisp files."
666 :group 'auto-install)
668 (defcustom auto-install-filter-url
669 '(("color-grep" "http://www.bookshelf.jp/elc/"))
670 "Alist mapping filter url for library.
671 Default command `auto-install-from-library' will install from EmacsWiki,
672 if it can't find match in this alist."
673 :type '(repeat (list (string :tag "Library")
674 (string :tag "Download URL")))
675 :group 'auto-install)
677 (defcustom auto-install-save-confirm t
678 "Whether confirmation is needed to save downloaded content.
679 Nil means no confirmation is needed.
680 If non-nil, the downloaded content is shown in a buffer and you are
681 prompted to confirm saving it to a file."
683 :group 'auto-install)
685 (defcustom auto-install-replace-confirm nil
686 "Whether confirmation is needed to replace an existing elisp file.
687 Nil means no confirmation is needed."
689 :group 'auto-install)
691 (defcustom auto-install-install-confirm nil
692 "Whether confirmation is needed to install a downloaded elisp file.
693 Nil means no confirmation is needed."
695 :group 'auto-install)
697 (defcustom auto-install-from-dired-confirm t
698 "Whether confirmation is needed to download marked files from Dired.
699 Nil means no confirmation is needed."
701 :group 'auto-install)
703 (defcustom auto-install-wget-command "wget"
704 "*Wget command. Use only if `auto-install-use-wget' is non-nil."
706 :group 'auto-install)
708 (defcustom auto-install-use-wget t
709 "*Use wget instead of `url-retrieve'.
711 It is enabled by default when wget is found."
713 :group 'auto-install)
715 (defcustom auto-install-batch-list
717 "This list contain packages information for batch install.
719 Have four arguments per list:
720 First argument is extension name.
721 Second argument is delay time for batch install.
722 Third argument is libraries number limit in delay time.
723 Fourth argument is list of libraries url or extension name.
725 If you want to add files, please edit auto-install-batch-list.el in EmacsWiki.
726 Use M-x `auto-install-batch-edit'. "
727 :group 'auto-install)
729 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Variable ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
730 (defvar auto-install-batch-list-internal nil
731 "The real value of `auto-install-batch-list'. ")
733 (defvar auto-install-batch-list-el-url
734 "http://www.rubyist.net/~rubikitch/archive/auto-install-batch-list.el"
735 "The url of auto-install-batch-list.el.
736 It is downloaded and evaluated just after M-x `auto-install-batch'. ")
738 (defvar auto-install-download-buffer nil
739 "The download buffer used by `url-retrieve'.
740 This variable is always buffer-local.")
741 (make-variable-buffer-local 'auto-install-download-buffer)
743 (defvar auto-install-download-url nil
744 "The url from which to download files.
745 This variable is always buffer-local.")
746 (make-variable-buffer-local 'auto-install-download-url)
748 (defvar auto-install-last-url nil
749 "The last url used in `auto-install-from-url'.")
751 (defvar auto-install-last-gist-id nil
752 "The last gist id you visit in `auto-install-from-gist'.")
754 (defvar auto-install-package-name-list nil
755 "The package name list for completion input.")
757 (defvar auto-install-minor-mode-map
758 (let ((map (make-sparse-keymap)))
759 (define-key map (kbd "C-c C-d") 'auto-install-buffer-diff) ;diff
760 (define-key map (kbd "C-c C-c") 'auto-install-buffer-save) ;save
761 (define-key map (kbd "C-c C-q") 'auto-install-buffer-quit) ;quit
763 "Keymap used by variable `auto-install-minor-mode'.")
765 (defvar auto-install-add-load-path-flag t
766 "If non-nil, add `auto-install-directory' to `load-path'.
767 This variable is intended to be used in test.")
769 (defvar auto-install-add-exec-path-flag t
770 "If non-nil, add `auto-install-directory' to `exec-path'.
771 This variable is intended to be used in test.
773 It is needed because `auto-install-batch' can install non-elisp files.")
775 (defvar auto-install-waiting-url-list nil
776 "URLs in downloading.")
777 (defvar auto-install-url-queue nil
778 "Installation order.")
779 (defvar auto-install-download-buffer-alist nil
780 "Pairs of URL and downloaded buffer.")
781 (defvar auto-install-batch-using nil)
783 (define-minor-mode auto-install-minor-mode
784 "Auto Install minor mode."
786 :lighter " Auto-Install"
787 :keymap auto-install-minor-mode-map
788 :group 'auto-install)
790 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
791 (defun auto-install-from-buffer ()
792 "Install the elisp file in the current buffer."
795 (setq filename (read-string (format "Filename (%s): " (buffer-name)) nil nil (buffer-name)))
797 (auto-install-buffer-save filename)))
799 (defun auto-install-from-url (&optional url)
800 "Install an elisp file from a given url."
802 (or url (setq url (read-string (format "URL (%s): " (or auto-install-last-url "")) nil nil auto-install-last-url)))
803 (setq auto-install-last-url url)
804 (auto-install-download url))
806 (defun auto-install-from-emacswiki (&optional file)
807 "Install an elisp file from EmacsWiki.org."
809 (cond (auto-install-package-name-list
810 ;; Install package if `auto-install-package-name-list' is non-nil.
811 (or file (setq file (auto-install-get-candidate "Package" auto-install-package-name-list)))
812 (auto-install-download (concat auto-install-emacswiki-base-url file)))
814 ;; Otherwise update package name and install.
815 (auto-install-download "http://www.emacswiki.org/cgi-bin/emacs?action=index;raw=1"
816 'auto-install-handle-emacswiki-package-install))))
818 (defun auto-install-from-gist (&optional gistid-or-url)
819 "Install an elisp file from gist.github.com.
821 Optional argument GISTID-OR-URL is gist ID or URL for download
822 elisp file from gist.github.com."
825 (setq gistid-or-url (read-string (format "Gist ID or URL (%s): " (or auto-install-last-gist-id ""))
827 auto-install-last-gist-id)))
828 (let ((gistid (file-name-sans-extension (file-name-nondirectory gistid-or-url))))
829 (setq auto-install-last-gist-id gistid)
830 (auto-install-download (format "%s%s.txt" auto-install-gist-base-url gistid))))
832 (defun auto-install-from-library (&optional library)
833 "Update an elisp LIBRARY.
834 Default this function will found 'download url' from `auto-install-filter-url',
835 if not found, try to download from EmacsWiki."
837 (let* ((dirs load-path)
838 (suffixes (find-library-suffixes)))
839 (list (auto-install-get-candidate "Library name" (auto-install-get-library-list)))))
840 (let ((filename (file-name-nondirectory (find-library-name library)))
841 (base-url auto-install-emacswiki-base-url)
842 (library-name (replace-regexp-in-string "\\(\\.el.*$\\)" "" library)))
843 (if (assoc library-name auto-install-filter-url)
844 (setq base-url (cadr (assoc library-name auto-install-filter-url))))
845 (auto-install-download (concat base-url filename))))
847 (defun auto-install-from-directory (directory)
848 "Update elisp files under DIRECTORY from EmacsWiki.
849 You can use this command to update elisp file under DIRECTORY."
850 (interactive "DDirectory: ")
852 (dolist (file (directory-files directory t))
853 (if (file-directory-p file)
854 ;; Don't match . or .. directory.
855 (unless (string-match "^\\.\\.?$" (file-name-nondirectory file))
856 ;; Find files in sub-directory.
857 (auto-install-from-directory file))
859 (setq filename (file-name-nondirectory file))
861 (unless (string-match "^\\.?#" filename)
863 (if (string-match "^.*\\.el" filename)
864 (auto-install-download (concat auto-install-emacswiki-base-url filename))))))))
866 (defun auto-install-from-dired ()
867 "Update dired marked elisp files from EmacsWiki.org.
868 You can use this to download marked files in Dired asynchronously."
870 (if (eq major-mode 'dired-mode)
871 (if (or (not auto-install-from-dired-confirm)
872 (yes-or-no-p "Do you want install marked files from EmacsWiki.org?"))
873 (dolist (file (dired-get-marked-files))
874 (auto-install-download (concat auto-install-emacswiki-base-url (file-name-nondirectory file)))))
875 (error "This command is only for `dired-mode'.")))
877 (defun auto-install-network-available-p (host)
878 (if auto-install-use-wget
879 (eq (call-process auto-install-wget-command nil nil nil "-q" "--spider" host) 0)
880 (with-current-buffer (url-retrieve-synchronously (concat "http://" host))
881 (prog1 (not (zerop (buffer-size)))
882 (kill-buffer (current-buffer))))))
883 ;; (auto-install-network-available-p "www.emacswiki.org")
885 (defun auto-install-update-emacswiki-package-name (&optional unforced)
886 "Update the list of elisp package names from `EmacsWiki'.
887 By default, this function will update package name forcibly.
888 If UNFORCED is non-nil, just update package name when `auto-install-package-name-list' is nil."
890 (unless (and unforced
891 auto-install-package-name-list)
892 (if (auto-install-network-available-p "www.emacswiki.org")
893 (auto-install-download "http://www.emacswiki.org/cgi-bin/emacs?action=index;raw=1"
894 'auto-install-handle-emacswiki-package-name)
896 (concat "Network unreachable!\n"
897 "Try M-x auto-install-handle-emacswiki-package-name afterward."))
900 (defun auto-install-dired-mark-files ()
901 "Mark dired files that contain at `EmacsWiki.org'."
903 (if (eq major-mode 'dired-mode)
904 (if auto-install-package-name-list
905 ;; Mark files that exist at `EmacsWiki'.
906 (auto-install-dired-mark-files-internal)
907 ;; Or get package name list and match files.
908 (auto-install-download "http://www.emacswiki.org/cgi-bin/emacs?action=index;raw=1"
909 'auto-install-handle-dired-mark-files))
910 (error "This command just use in `dired-mode'.")))
912 (defun auto-install-mode ()
913 "Major mode for auto-installing elisp code."
915 ;; Load emacs-lisp syntax highlight.
916 (set-syntax-table emacs-lisp-mode-syntax-table)
917 (lisp-mode-variables)
918 (setq font-lock-mode t)
919 (font-lock-fontify-buffer)
921 (setq buffer-read-only t)
922 (and view-read-only (view-mode 1))
923 ;; Load `auto-install' mode.
924 (auto-install-minor-mode t)
925 (setq major-mode 'auto-install-minor-mode))
927 (defun auto-install-buffer-quit ()
928 "Quit from `auto-install' temporary buffer."
931 (if (eq major-mode 'auto-install-minor-mode)
933 (error "This command just use in `auto-install-minor-mode'.")))
935 (defun auto-install-compatibility-setup ()
936 "Install Compatibility commands for install-elisp.el users."
938 (defalias 'install-elisp 'auto-install-from-url)
939 (if (require 'anything-auto-install nil t)
940 (defalias 'install-elisp-from-emacswiki 'anything-auto-install-from-emacswiki)
941 (defalias 'install-elisp-from-emacswiki 'auto-install-from-emacswiki))
942 (defalias 'install-elisp-from-gist 'auto-install-from-gist)
943 (message "Install-elisp compatibility installed.
945 install-elisp-from-emacswiki = %s
946 install-elisp-from-gist = %s"
947 (symbol-function 'install-elisp)
948 (symbol-function 'install-elisp-from-emacswiki)
949 (symbol-function 'install-elisp-from-gist)))
951 (defun auto-install-batch (&optional extension-name)
952 "Batch install many files (libraries and non-elisp files) in some extension.
953 EXTENSION-NAME is extension name for batch install.
955 Note that non-elisp can be installed only via `auto-install-batch'"
957 (if (and auto-install-batch-list-internal extension-name)
958 (auto-install-batch-real extension-name)
959 (auto-install-download
960 auto-install-batch-list-el-url
961 (lexical-let ((extension-name extension-name))
963 (with-current-buffer buf
965 (run-at-time 0 nil 'auto-install-batch-real extension-name)))))))
967 (defun auto-install-batch-edit ()
968 "Edit auto-install-batch-list.el"
970 (cond ((fboundp 'yaoddmuse-edit)
971 (yaoddmuse-edit "EmacsWiki" "auto-install-batch-list.el"))
972 ((fboundp 'oddmuse-edit)
973 (oddmuse-edit "EmacsWiki" "auto-install-batch-list.el"))
975 (browse-url "http://www.emacswiki.org/emacs/?action=edit;id=auto-install-batch-list.el"))))
977 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Utilities Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
978 (defun auto-install-batch-real (&optional extension-name)
979 (setq auto-install-batch-using t)
980 (when auto-install-add-exec-path-flag
981 (add-to-list 'exec-path auto-install-directory))
982 (destructuring-bind (name delay-time limit-number (&rest urls))
983 (auto-install-batch-get-info
985 ;; Get information list from give extension name.
987 ;; Otherwise completion from user select.
988 (completing-read "Extension name: " (mapcar 'car auto-install-batch-list-internal)))
989 auto-install-batch-list-internal)
990 (or name (error "Haven't install information for `%s'." extension-name))
991 (setq auto-install-waiting-url-list urls
992 auto-install-url-queue urls)
994 ;; Delay time is above 0.
997 ;; Limit number is above 0.
1000 (auto-install-from-url-list urls)
1001 (let ((delay-counter 0)
1004 (if (> (length urls) limit-number)
1005 ;; Install apart libraries list under `limit-number'
1007 (setq install-list (nthcar limit-number urls))
1009 (* delay-counter delay-time)
1011 'auto-install-from-url-list install-list)
1012 (setq urls (nthcdr+ limit-number urls))
1013 (incf delay-counter))
1014 ;; Install remain libraries list.
1015 (setq install-list urls)
1017 (* delay-counter delay-time)
1019 'auto-install-from-url-list install-list)
1020 (setq urls nil)))))))
1022 ;;; borrowed from eev.el
1023 (defun auto-install-flatten (obj &rest rest)
1024 (cond (rest (append (auto-install-flatten obj) (auto-install-flatten rest)))
1026 ((listp obj) (append (auto-install-flatten (car obj)) (auto-install-flatten (cdr obj))))
1029 (defun auto-install-batch-get-info (extension batch-list)
1030 (let* ((it (assoc extension batch-list))
1031 (urls (car (last it)))
1032 (urlp (lambda (url) (string-match "^https?://" url))))
1034 '(nil nil nil (nil)))
1035 ((loop for url in urls always (funcall urlp url))
1040 (list (auto-install-flatten
1041 (loop for url in urls collect
1042 (if (funcall urlp url)
1044 (car (last (auto-install-batch-get-info url batch-list))))))))))))
1047 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
1048 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
1050 (when (fboundp 'expectations)
1052 (desc "auto-install-flatten")
1053 (expect '(1 2 3 4 5 6 7 8 9)
1054 (auto-install-flatten '((1 2 3) (4 5) (((6)) 7) nil nil 8 9)))
1055 (expect '(1 2 3 4 5 6 7 8 9)
1056 (auto-install-flatten '(1 2 3) '(4 5) '(((6)) 7) nil nil 8 9))
1057 (desc "auto-install-batch-get-info")
1058 (expect '(nil nil nil (nil))
1059 (auto-install-batch-get-info
1061 '(("foo" nil nil ("https://example.com/1.el")))))
1062 (expect '("foo" nil nil ("http://example.com/1.el"))
1063 (auto-install-batch-get-info
1065 '(("foo" nil nil ("http://example.com/1.el")))))
1066 (expect '("withdep" nil nil ("http://example.com/1.el"
1067 "http://example.com/2.el"))
1068 (auto-install-batch-get-info
1070 '(("foo" nil nil ("http://example.com/1.el"))
1071 ("withdep" nil nil ("foo" "http://example.com/2.el")))))
1072 (expect '("withdep-recursive" nil nil ("http://example.com/1.el"
1073 "http://example.com/2.el"
1074 "http://example.com/3.el"))
1075 (auto-install-batch-get-info
1077 '(("foo" nil nil ("http://example.com/1.el"))
1078 ("withdep" nil nil ("foo" "http://example.com/2.el"))
1079 ("withdep-recursive" nil nil ("withdep" "http://example.com/3.el")))))
1083 (defun auto-install-use-wget-p ()
1084 (and auto-install-use-wget
1085 (executable-find auto-install-wget-command)))
1086 (defun auto-install-download (url &optional handle-function)
1087 "Download elisp file from URL.
1088 HANDLE-FUNCTION for handle download content,
1089 default is `auto-install-handle-download-content'."
1090 ;; Check and create install directory.
1091 (unless (file-exists-p auto-install-directory)
1092 (make-directory auto-install-directory)
1093 (when auto-install-add-load-path-flag
1094 (add-to-list 'load-path auto-install-directory))
1095 (message "Create directory %s for install elisp file." auto-install-directory))
1098 (if (auto-install-use-wget-p)
1099 'auto-install-download-by-wget
1100 'auto-install-download-by-url-retrieve)
1101 url handle-function (auto-install-get-buffer url)))
1103 (defun auto-install-download-by-wget (url handle-function download-buffer)
1104 (with-current-buffer download-buffer
1105 (setq auto-install-download-buffer (get-buffer-create (concat (buffer-name download-buffer)
1107 (setq auto-install-download-url url)
1108 (set-process-sentinel
1109 (start-process "auto-install-wget" (current-buffer)
1110 auto-install-wget-command "-q" "-O-" "--no-check-certificate" url)
1111 (lexical-let ((handle-function handle-function))
1113 (auto-install-download-callback-continue (buffer-name (process-buffer proc))
1114 handle-function))))))
1116 (defun auto-install-download-by-url-retrieve (url handle-function download-buffer)
1117 (let* ((url-request-method "GET")
1118 (url-request-extra-headers nil)
1119 (url-mime-accept-string "*/*")
1120 (parsed-url (url-generic-parse-url url))
1121 (download-buffer-name (buffer-name download-buffer)))
1122 (with-current-buffer download-buffer
1123 ;; Bind download url with local buffer.
1124 (setq auto-install-download-url url)
1125 ;; Bind download buffer with local buffer.
1127 ;; Use buffer-local variable receive
1128 ;; data from `url-retrieve' to make asynchronously
1129 ;; download file with special buffer.
1131 ;; Because the buffer name is unique that generate
1132 ;; through `current-time', so can download many elisp file
1133 ;; asynchronously and won't conflict each other.
1134 (setq auto-install-download-buffer
1135 (url-retrieve parsed-url
1136 'auto-install-download-callback
1137 (list download-buffer-name handle-function))))))
1139 (defun auto-install-download-callback (&optional redirect download-buffer-name handle-function)
1140 "The callback for `auto-install-download'.
1141 With `auto-install-download', this downloads elisp files asynchronously.
1142 REDIRECT is the argument for check download status.
1143 DOWNLOAD-BUFFER-NAME is the name of download buffer.
1144 HANDLE-FUNCTION is function for handle download content."
1145 (if (eq (car redirect) ':error)
1146 ;; Notify user and kill buffer when occur error.
1147 (with-current-buffer (get-buffer download-buffer-name)
1148 (message "Download from '%s' failed." auto-install-download-url)
1149 (kill-buffer download-buffer-name))
1150 ;; Otherwise continue install process.
1151 (auto-install-download-callback-continue download-buffer-name handle-function)))
1153 (defun auto-install-download-callback-continue (download-buffer-name handle-function)
1154 (auto-install-retrieve-decode download-buffer-name) ;decode retrieve information.
1155 (with-current-buffer (get-buffer download-buffer-name)
1156 ;; Show successful message
1157 (message "Download from '%s' successful." auto-install-download-url)
1158 ;; Handle download content.
1159 (funcall (or handle-function 'auto-install-handle-download-content)
1162 (defun auto-install-retrieve-decode (retrieve-buffer-name)
1163 "Decode the RETRIEVE-BUFFER-NAME with coding detection."
1164 (declare (special url-http-end-of-headers))
1165 (with-current-buffer (get-buffer retrieve-buffer-name)
1167 (with-current-buffer auto-install-download-buffer
1168 (set-buffer-multibyte t)
1169 ;; I do not know why the case url-http-end-of-headers is nil exists!!
1170 ;; I HATE url-retrieve.
1171 (if (and (boundp 'url-http-end-of-headers)
1172 (numberp url-http-end-of-headers))
1173 (goto-char (1+ url-http-end-of-headers))
1175 (if (auto-install-use-wget-p)
1176 (goto-char (point-min))
1177 (search-forward "\n\n" nil t)))
1178 (decode-coding-region
1180 (coding-system-change-eol-conversion
1181 ;; rubikitch: encoding detection is better because of
1182 ;; non-utf8 Japanese encodings.
1183 (detect-coding-region (point-min) (point-max) t) 'dos))
1184 (buffer-substring (point) (point-max))))
1185 (goto-char (point-min))))
1187 (defun auto-install-handle-download-content (download-buffer)
1188 "Handle the content downloaded to buffer DOWNLOAD-BUFFER."
1189 (with-current-buffer download-buffer
1192 ;; Display help information in mode-line.
1193 (setq mode-line-format (list "Type C-c C-c to continue; Type C-c C-d for view diff; Type C-c C-q to quit."))
1195 (setq header-line-format (list auto-install-download-url))
1196 (setq auto-install-download-buffer-alist
1197 (cons (cons auto-install-download-url download-buffer)
1198 auto-install-download-buffer-alist))
1199 (setq auto-install-waiting-url-list
1200 (remove auto-install-download-url auto-install-waiting-url-list))
1201 ;; When all files are downloaded
1202 (unless auto-install-waiting-url-list
1203 ;; Select first file
1204 (switch-to-buffer (or (assoc-default (car auto-install-url-queue)
1205 auto-install-download-buffer-alist)
1208 (if (not (and (not auto-install-batch-using) (auto-install-check-update)))
1209 (unless auto-install-save-confirm
1210 (auto-install-buffer-save))
1211 (message "%s is up-to-date" (url-file-nondirectory auto-install-download-url))
1213 ;; (unless auto-install-save-confirm
1214 ;; (auto-install-buffer-save))
1217 (defun auto-install-check-update ()
1218 (let* ((new-file (url-file-nondirectory auto-install-download-url))
1219 (old-file (auto-install-get-path new-file))
1220 (old-content (and old-file
1222 (insert-file-contents-literally old-file)
1224 (equal old-content (buffer-string))))
1226 (defun auto-install-handle-emacswiki-package-name (download-buffer &optional prompt-install)
1227 "Handle elisp package name from `EmacsWiki'.
1228 DOWNLOAD-BUFFER is the name of download buffer.
1229 PROMPT-INSTALL is non-nil, will prompt package name for install."
1230 ;; Update package name list.
1231 (auto-install-update-emacswiki-package-list download-buffer)
1232 ;; Prompt package name for install.
1233 (when prompt-install
1234 (auto-install-download
1235 (concat auto-install-emacswiki-base-url
1236 (auto-install-get-candidate "Package" auto-install-package-name-list)))))
1238 (defun auto-install-handle-dired-mark-files (download-buffer)
1239 "Handle dired mark files that exist at `EmacsWiki'.
1240 DOWNLOAD-BUFFER is the name of download buffer."
1241 ;; Update package name list.
1242 (auto-install-update-emacswiki-package-list download-buffer)
1243 ;; Mark dired files.
1244 (auto-install-dired-mark-files-internal))
1246 (defun auto-install-handle-emacswiki-package-install (download-buffer)
1247 "Handle elisp package install from `EmacsWiki'.
1248 DOWNLOAD-BUFFER is the name of download buffer."
1249 (auto-install-handle-emacswiki-package-name download-buffer t))
1251 (defun auto-install-update-emacswiki-package-list (download-buffer)
1252 "Filter and update package name list from `EmacsWiki'.
1253 DOWNLOAD-BUFFER is the name of download buffer."
1254 (goto-char (point-min))
1255 (setq auto-install-package-name-list
1256 (loop while (re-search-forward "^.*\\.el$" nil t)
1257 collect (match-string 0)))
1259 (kill-buffer download-buffer)
1260 ;; Display successful message.
1261 (message "Update package name from `EmacsWiki' successful."))
1263 (defun auto-install-buffer-diff ()
1264 "View different between old version.
1265 This command just run when have exist old version."
1267 (let* ((new-file (url-file-nondirectory auto-install-download-url))
1268 (old-file (auto-install-get-path new-file)))
1270 ;; View different when have old version exist.
1271 (ediff-buffers (current-buffer) (find-file-noselect old-file))
1272 ;; Otherwise notify user.
1273 (message "Haven't old version exist."))))
1275 (defun auto-install-buffer-save (&optional filename)
1276 "Save downloaded content to file FILENAME."
1278 (if (eq major-mode 'auto-install-minor-mode)
1282 (setq filename (url-file-nondirectory auto-install-download-url)))
1283 (unless auto-install-batch-using
1284 ;; Make sure file suffix with `.el'.
1285 (while (not (string-match ".*\.el$" filename))
1286 (setq filename (read-string "Please input file name suffix with `.el': "))))
1290 ;; Replace file if have exist.
1291 (auto-install-get-path filename)
1292 ;; Otherwise, install in directory `auto-install-directory'.
1293 (expand-file-name filename auto-install-directory)))
1295 (if (and (file-exists-p file-path)
1296 (file-writable-p file-path)
1297 auto-install-replace-confirm
1298 (not (yes-or-no-p (format "Do you want replace file: '%s' ?" file-path))))
1300 (if (auto-install-check-update)
1301 (auto-install-install-next-file)
1302 (let ((before-save-hook before-save-hook)
1303 (auto-async-byte-compile-exclude-files-regexp
1304 (regexp-quote file-path)))
1305 (remove-hook 'before-save-hook 'time-stamp)
1306 (write-file file-path)
1307 (auto-install-install file-path)))))
1308 (error "This command just use in `auto-install-minor-mode'.")))
1310 (defun auto-install-install (file-path)
1311 "Install elisp file FILE-PATH."
1312 (if (and auto-install-install-confirm
1313 (not (yes-or-no-p (format "Do you want install file: '%s' ?" file-path))))
1315 (let (byte-compile-warnings) ;; suppress compile warnings
1316 ;; Compile and load file.
1317 (when (and (string= "el" (file-name-extension file-path))
1318 (not (ignore-errors (byte-compile-file file-path t))))
1319 ;; Show `ERROR' message if compile failed.
1320 (message "Auto-Install ERROR: Compiled file '%s' failed." file-path))
1321 (auto-install-install-next-file))))
1323 (defun auto-install-install-next-file ()
1324 (setq auto-install-url-queue (cdr auto-install-url-queue))
1325 (let (byte-compile-warnings)
1326 (cond ((car auto-install-url-queue)
1327 (switch-to-buffer (assoc-default (car auto-install-url-queue)
1328 auto-install-download-buffer-alist))
1329 (unless auto-install-save-confirm
1330 (auto-install-buffer-save)))
1332 (auto-install-cleanup)
1333 (message "Installation is completed.")))))
1335 (defun auto-install-cleanup ()
1336 (while auto-install-minor-mode
1338 (setq auto-install-url-queue nil)
1339 (setq auto-install-download-buffer-alist nil)
1340 (setq auto-install-batch-using nil))
1342 (defun auto-install-quit ()
1343 "Quit auto-install."
1345 (kill-buffer (current-buffer))
1346 ;; Show quit message.
1347 (message "Quit auto-install process."))
1349 (defun auto-install-get-path (library)
1350 "Return the absolute file path of the Lisp source of LIBRARY."
1351 ;; If the library is byte-compiled, try to find a source library by
1353 (if (string-match "\\.el\\(c\\(\\..*\\)?\\)\\'" library)
1354 (setq library (replace-match "" t t library)))
1356 (locate-file library
1357 (or find-function-source-path load-path)
1358 (find-library-suffixes))
1359 (locate-file library
1360 (or find-function-source-path load-path)
1361 load-file-rep-suffixes)))
1363 (defun auto-install-get-buffer (url)
1364 "Get a buffer for temporary storage of downloaded content.
1365 Uses `current-time' to make buffer name unique."
1366 (get-buffer-create (format "*%s %s <%s>*"
1367 auto-install-buffer-name url
1368 (format-time-string "%m/%d %H:%M:%S"))))
1370 (defun auto-install-dired-mark-files-internal ()
1371 "Mark files that match `auto-install-package-name-list'."
1372 ;; Set buffer visible in select window.
1373 (set-buffer (window-buffer))
1377 ;; Unmark all markes.
1378 (dired-unmark-all-marks)
1379 ;; Try to mark files.
1380 (goto-char (point-min))
1382 (setq filename (dired-get-filename nil t))
1384 (not (file-directory-p filename))
1385 (member (file-name-nondirectory filename) auto-install-package-name-list))
1387 (dired-next-line 1)))))
1389 (defun auto-install-region-or-thing (&optional thing)
1390 "Return region or thing around point.
1391 If `mark-active' and variable `transient-mark-mode', return region.
1392 If THING is non-nil, return THING around point;
1393 otherwise return symbol around point."
1395 (if (and mark-active
1396 transient-mark-mode)
1397 ;; Return region string just when
1398 ;; `mark-active' and `transient-mark-mode' is on.
1399 (buffer-substring-no-properties (region-beginning)
1401 ;; Otherwise try to pick-up THING around point.
1402 (setq thing (or thing 'symbol))
1405 (buffer-substring-no-properties (beginning-of-thing thing)
1406 (end-of-thing thing))))))
1408 (defun auto-install-get-library-list (&optional dirs string)
1409 "Do completion for file names passed to `locate-file'.
1410 DIRS is directory to search path.
1411 STRING is string to match."
1412 ;; Use `load-path' as path when ignore `dirs'.
1413 (or dirs (setq dirs load-path))
1414 ;; Init with blank when ignore `string'.
1415 (or string (setq string ""))
1416 ;; Get library list.
1417 (let ((string-dir (file-name-directory string))
1422 (setq dir default-directory))
1424 (setq dir (expand-file-name string-dir dir)))
1425 (when (file-directory-p dir)
1426 (dolist (file (file-name-all-completions
1427 (file-name-nondirectory string) dir))
1428 ;; Suffixes match `load-file-rep-suffixes'.
1429 (setq name (if string-dir (concat string-dir file) file))
1430 (if (string-match (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)) name)
1431 (add-to-list 'names name)))))
1434 (defun auto-install-get-candidate (prompt collection)
1435 "Get candidate from completing list.
1436 PROMPT is string for prompt.
1437 COLLECTION is list for completing candidates."
1438 (completing-read (format "%s (%s): " prompt (or (auto-install-region-or-thing) ""))
1441 (auto-install-region-or-thing)))
1443 (defun auto-install-from-url-list (&optional url-list)
1444 "Batch install many packages form URL-LIST."
1445 (if (listp url-list)
1446 (dolist (url url-list)
1447 (auto-install-from-url url))
1448 (error "Invalid url list for install.")))
1450 (defun nthcdr+ (n list)
1451 "Take cdr N times on LIST, return the result.
1452 If LIST length below N, return entire list.
1453 If LIST is nil, return nil."
1455 (> n (length list)))
1459 (defun nthcar (n list)
1460 "Return first N elements of LIST.
1461 If LIST length below N, return entire list.
1462 If LIST is nil, return nil."
1463 (reverse (nthcdr (- (length list) n) (reverse list))))
1466 (defvar auto-install-maintainer-mail-address
1467 (concat "rubiki" "tch@ru" "by-lang.org"))
1468 (defvar auto-install-bug-report-salutation
1469 "Describe bug below, using a precise recipe.
1471 When I executed M-x ...
1473 How to send a bug report:
1474 1) Be sure to use the LATEST version of auto-install.el.
1475 2) Enable debugger. M-x toggle-debug-on-error or (setq debug-on-error t)
1476 3) Use Lisp version instead of compiled one: (load \"auto-install.el\")
1477 4) If you got an error, please paste *Backtrace* buffer.
1478 5) Type C-c C-c to send.
1479 # If you are a Japanese, please write in Japanese:-)")
1480 (defun auto-install-send-bug-report ()
1482 (reporter-submit-bug-report
1483 auto-install-maintainer-mail-address
1485 (apropos-internal "^auto-install-" 'boundp)
1487 auto-install-bug-report-salutation))
1490 (provide 'auto-install)
1493 ;; (find-file-other-window "~/memo/junk/2010-04-25-094621.auto-install-check-update.test.el")
1495 ;; How to save (DO NOT REMOVE!!)
1496 ;; (emacswiki-post "auto-install.el")
1497 ;;; auto-install.el ends here
1499 ;;; LocalWords: el eol dirs fontify gistid txt func bytecomp DDirectory ediff
1500 ;;; LocalWords: noselect Unmark unmark AutoInstall keybindings defalias'es