auto-install.el 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228
  1. ;;; auto-install.el --- Auto install elisp file
  2. ;; Filename: auto-install.el
  3. ;; Description: Auto install elisp file
  4. ;; Author: Andy Stewart <lazycat.manatee@gmail.com>
  5. ;; rubikitch <rubikitch@ruby-lang.org>
  6. ;; Maintainer: rubikitch <rubikitch@ruby-lang.org>
  7. ;; Copyright (C) 2008, 2009, Andy Stewart, all rights reserved.
  8. ;; Copyright (C) 2009, rubikitch, all rights reserved.
  9. ;; Created: 2008-12-11 13:56:50
  10. ;; Version: $Revision: 1.24 $
  11. ;; Last-Updated: Fri May 22 13:07:04 2009 (-0700)
  12. ;; By: dradams
  13. ;; URL: http://www.emacswiki.org/emacs/download/auto-install.el
  14. ;; Keywords: auto-install
  15. ;; Compatibility: GNU Emacs 22 ~ 23
  16. ;;
  17. ;; Features that might be required by this library:
  18. ;;
  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'.
  25. ;;
  26. (defvar auto-install-version "$Id: auto-install.el,v 1.24 2010/01/05 09:40:04 rubikitch Exp $")
  27. ;;; This file is NOT part of GNU Emacs
  28. ;;; License
  29. ;;
  30. ;; This program is free software; you can redistribute it and/or modify
  31. ;; it under the terms of the GNU General Public License as published by
  32. ;; the Free Software Foundation; either version 3, or (at your option)
  33. ;; any later version.
  34. ;; This program is distributed in the hope that it will be useful,
  35. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  36. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  37. ;; GNU General Public License for more details.
  38. ;; You should have received a copy of the GNU General Public License
  39. ;; along with this program; see the file COPYING. If not, write to
  40. ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  41. ;; Floor, Boston, MA 02110-1301, USA.
  42. ;;; Commentary:
  43. ;;
  44. ;; Automates the installation of Emacs Lisp files and packages.
  45. ;;
  46. ;; `auto-install' provides an automated way to:
  47. ;;
  48. ;; (1) Download Emacs Lisp files and packages from common sources
  49. ;; (2) View them (diff) and save them to your repository
  50. ;; (3) Compile and Load them
  51. ;;
  52. ;;; Commands:
  53. ;;
  54. ;; Below are complete command list:
  55. ;;
  56. ;; `auto-install-minor-mode'
  57. ;; Auto Install minor mode.
  58. ;; `auto-install-from-buffer'
  59. ;; Install the elisp file in the current buffer.
  60. ;; `auto-install-from-url'
  61. ;; Install an elisp file from a given url.
  62. ;; `auto-install-from-emacswiki'
  63. ;; Install an elisp file from EmacsWiki.org.
  64. ;; `auto-install-from-gist'
  65. ;; Install an elisp file from gist.github.com.
  66. ;; `auto-install-from-library'
  67. ;; Update an elisp LIBRARY.
  68. ;; `auto-install-from-directory'
  69. ;; Update elisp files under DIRECTORY from EmacsWiki.
  70. ;; `auto-install-from-dired'
  71. ;; Update dired marked elisp files from EmacsWiki.org.
  72. ;; `auto-install-update-emacswiki-package-name'
  73. ;; Update the list of elisp package names from `EmacsWiki'.
  74. ;; `auto-install-dired-mark-files'
  75. ;; Mark dired files that contain at `EmacsWiki.org'.
  76. ;; `auto-install-mode'
  77. ;; Major mode for auto-installing elisp code.
  78. ;; `auto-install-buffer-quit'
  79. ;; Quit from `auto-install' temporary buffer.
  80. ;; `auto-install-compatibility-setup'
  81. ;; Install Compatibility commands for install-elisp.el users.
  82. ;; `auto-install-batch'
  83. ;; Batch install many libraries in some extension.
  84. ;; `auto-install-buffer-diff'
  85. ;; View different between old version.
  86. ;; `auto-install-buffer-save'
  87. ;; Save downloaded content to file FILENAME.
  88. ;;
  89. ;;; Customizable Options:
  90. ;;
  91. ;; Below are customizable option list:
  92. ;;
  93. ;; `auto-install-directory'
  94. ;; The directory for saving elisp files.
  95. ;; default = "~/.emacs.d/auto-install/"
  96. ;; `auto-install-buffer-name'
  97. ;; The temporary buffer for storing download content.
  98. ;; default = "auto-install"
  99. ;; `auto-install-emacswiki-base-url'
  100. ;; The base emacswiki.org url from which to download elisp files.
  101. ;; default = "http://www.emacswiki.org/cgi-bin/wiki/download/"
  102. ;; `auto-install-gist-base-url'
  103. ;; The base gist.github.com url from which to download elisp files.
  104. ;; default = "http://gist.github.com/"
  105. ;; `auto-install-filter-url'
  106. ;; Alist mapping filter url for library.
  107. ;; default = (quote (("color-grep" "http://www.bookshelf.jp/elc/")))
  108. ;; `auto-install-save-confirm'
  109. ;; Whether confirmation is needed to save downloaded content.
  110. ;; default = t
  111. ;; `auto-install-replace-confirm'
  112. ;; Whether confirmation is needed to replace an existing elisp file.
  113. ;; default = nil
  114. ;; `auto-install-install-confirm'
  115. ;; Whether confirmation is needed to install a downloaded elisp file.
  116. ;; default = nil
  117. ;; `auto-install-from-dired-confirm'
  118. ;; Whether confirmation is needed to download marked files from Dired.
  119. ;; default = t
  120. ;; `auto-install-batch-list'
  121. ;; This list contain packages information for batch install.
  122. ;; default = (quote (("icicles" 21 10 ...) ("auto-complete development version" nil nil ...) ("anything" nil nil ...) ("sdcv" nil nil ...) ("lazy-search" nil nil ...) ...))
  123. ;;; Tips:
  124. ;;
  125. ;; Downloading is asynchronous: you can do your work and download
  126. ;; files at the same time. The download process won't hang
  127. ;; Emacs.
  128. ;;
  129. ;; `auto-install-from-url' remembers previous installations. So if
  130. ;; your search is the same as the previous search, you don't need
  131. ;; to type it in, just hit RETURN.
  132. ;;
  133. ;; `auto-install-from-emacswiki' will complete then names of
  134. ;; packages from those in the Elisp area in `EmacsWiki'.
  135. ;;
  136. ;; `auto-install-from-library' will prompt you library name in
  137. ;; you load-path, then it try to download from EmacsWiki if it
  138. ;; can't find match in `auto-install-filter-url'.
  139. ;;
  140. ;; `auto-install-from-directory' can install elisp file
  141. ;; under specify directory.
  142. ;;
  143. ;; `auto-install-from-dired' can install marked files using dired.
  144. ;; You can mark the files you want in dired and then use
  145. ;; `auto-install-from-dired' to download those files
  146. ;; asynchronously.
  147. ;;
  148. ;; `auto-install-from-buffer' can save and install the contents of
  149. ;; the current buffer as a file. You need a valid elisp file name.
  150. ;; The default name is the buffer name.
  151. ;;
  152. ;; `auto-install-from-emacswiki' and `auto-install-from-library'
  153. ;; will try to pick up file around point, you can move
  154. ;; cursor to file name, and just hit RET for install.
  155. ;;
  156. ;; Some extension (such as icicles) have many libraries to need install,
  157. ;; and install one by one is painful, you can use command
  158. ;; `auto-install-batch' install all icicles libraries.
  159. ;; And `auto-install-batch' handle max connect limit with some website
  160. ;; (such as EmacsWiki) to avoid download failed.
  161. ;;
  162. ;; All of the above functions support a filename filter. You can
  163. ;; input any url to download an elisp file, if the file name suffix is
  164. ;; `.el', it will download and install the file automatically.
  165. ;; Otherwise, it won't install it unless you input a valid elisp
  166. ;; file name.
  167. ;;
  168. ;; By default, if a file that you download does not exist on your
  169. ;; system the file is downloaded to `auto-install-directory'. If
  170. ;; you already have a file with the same name in your load
  171. ;; directory, `auto-install' will try to replace that file.
  172. ;;
  173. ;; You can use command `auto-install-dired-mark-files' to mark files
  174. ;; that contain at `EmacsWiki.org' for fast update.
  175. ;;
  176. ;; By default, command `auto-install-from-emacswiki' will initialization
  177. ;; current symbol as default value, if default value is you want,
  178. ;; just hit RET, so lazy!
  179. ;;
  180. ;;; Installation:
  181. ;;
  182. ;; (1) Put auto-install.el somewhere in your load-path.
  183. ;;
  184. ;; For example, put it into ~/elisp/.
  185. ;; Then add the following to your ~/.emacs:
  186. ;;
  187. ;; (add-to-list 'load-path (expand-file-name "~/elisp"))
  188. ;;
  189. ;; (2) And put the following in your ~/.emacs startup file:
  190. ;;
  191. ;; (require 'auto-install)
  192. ;;
  193. ;; (3) Add this to your ~/.emacs to optionally specify a download directory:
  194. ;;
  195. ;; (setq auto-install-directory "~/.emacs.d/auto-install/")
  196. ;;
  197. ;; If you don't set this, "~/.emacs.d/auto-install/" will be used as the default,
  198. ;; and will be created as needed.
  199. ;;
  200. ;; (4) Optionally, if your computer is always connected Internet when Emacs start up,
  201. ;; I recommend you add below to your ~/.emacs, to update package name when start up:
  202. ;;
  203. ;; (auto-install-update-emacswiki-package-name t)
  204. ;;
  205. ;; And above setup is not necessary, because AutoInstall will automatically update
  206. ;; package name when you just first call `auto-install-from-emacswiki',
  207. ;; above setup just avoid *delay* when you first call `auto-install-from-emacswiki'.
  208. ;;
  209. ;; (5) I recommend you add below to your ~/.emacs for install-elisp users:
  210. ;;
  211. ;; (auto-install-compatibility-setup)
  212. ;;
  213. ;; This command `defalias'es `install-elisp',
  214. ;; `install-elisp-from-emacswiki' and `install-elisp-from-gist' to
  215. ;; `auto-install' ones.
  216. ;;
  217. ;; (6) If you want to use proxy server, set `url-proxy-services'. For example:
  218. ;;
  219. ;; (setq url-proxy-services '(("http" . "localhost:8339")))
  220. ;;; Customize:
  221. ;;
  222. ;; `auto-install-directory'
  223. ;; The default directory for keeping auto-downloaded elisp files.
  224. ;;
  225. ;; `auto-install-buffer-name'
  226. ;; The base buffer name for temporarily storing downloaded download content.
  227. ;;
  228. ;; `auto-install-emacswiki-base-url'
  229. ;; The base url for downloading from EmacsWiki.org.
  230. ;;
  231. ;; `auto-install-gist-base-url'
  232. ;; The base url for downloading from gist.github.com
  233. ;;
  234. ;; `auto-install-filter-url'
  235. ;; Filter url for downloading a special library.
  236. ;;
  237. ;; `auto-install-save-confirm'
  238. ;; Whether to require confirmation when saving downloaded content.
  239. ;;
  240. ;; `auto-install-replace-confirm'
  241. ;; Whether to require confirmation when replacing an already-installed
  242. ;; file.
  243. ;;
  244. ;; `auto-install-install-confirm'
  245. ;; Whether to require confirmation when installing a file.
  246. ;;
  247. ;; `auto-install-from-dired-confirm'
  248. ;; Whether to require confirmation when downloading files marked in dired.
  249. ;;
  250. ;; `auto-install-batch-list'
  251. ;; This list contain packages information for batch install.
  252. ;; Anyone can add packages information in this list for batch install.
  253. ;;
  254. ;; And all above option can customize easy through:
  255. ;; M-x RET customize-group RET auto-install RET
  256. ;;
  257. ;;; Change log:
  258. ;;
  259. ;; $Log: auto-install.el,v $
  260. ;; Revision 1.24 2010/01/05 09:40:04 rubikitch
  261. ;; fixed error of auto-complete development version in `auto-install-batch-list'
  262. ;;
  263. ;; Revision 1.23 2009/12/29 09:31:23 rubikitch
  264. ;; add Text Translator to auto-install-batch-list
  265. ;;
  266. ;; Revision 1.22 2009/12/21 12:51:56 rubikitch
  267. ;; Update auto-install-batch anything
  268. ;;
  269. ;; Revision 1.21 2009/12/21 12:26:54 rubikitch
  270. ;; New URL for auto-complete development version
  271. ;;
  272. ;; Revision 1.20 2009/05/22 20:17:24 rubikitch
  273. ;; Merged from dradams' change
  274. ;;
  275. ;; Revision 1.19 2009/05/22 13:04:56 dadams
  276. ;; Split icicles-cmd.el into icicles-cmd[12].el.
  277. ;;
  278. ;; Revision 1.18 2009/05/20 15:42:54 rubikitch
  279. ;; Add php-completion / perl-completion to auto-install-batch-list
  280. ;;
  281. ;; Revision 1.17 2009/05/20 01:19:15 rubikitch
  282. ;; Add document for proxy server
  283. ;;
  284. ;; Revision 1.16 2009/05/15 20:28:18 rubikitch
  285. ;; More readable temporary buffer name.
  286. ;;
  287. ;; Revision 1.15 2009/05/15 20:12:49 rubikitch
  288. ;; Added missing require
  289. ;;
  290. ;; Revision 1.14 2009/05/15 20:11:44 rubikitch
  291. ;; How to save
  292. ;;
  293. ;; Revision 1.13 2009/05/15 20:09:07 rubikitch
  294. ;; Code cleanup
  295. ;;
  296. ;; Revision 1.12 2009/05/15 19:59:30 rubikitch
  297. ;; Fixed a bug of single file installation
  298. ;;
  299. ;; Revision 1.11 2009/05/15 19:44:32 rubikitch
  300. ;; Ordering `auto-install-batch'
  301. ;;
  302. ;; Revision 1.10 2009/05/15 17:48:09 rubikitch
  303. ;; Replace `message' with `error' for error messages.
  304. ;;
  305. ;; Revision 1.9 2009/05/15 17:40:37 rubikitch
  306. ;; refactoring
  307. ;;
  308. ;; Revision 1.8 2009/05/15 17:19:47 rubikitch
  309. ;; refactoring
  310. ;;
  311. ;; Revision 1.7 2009/05/15 17:17:03 rubikitch
  312. ;; Use `view-mode' if `view-read-only'.
  313. ;;
  314. ;; Revision 1.6 2009/05/15 17:10:22 rubikitch
  315. ;; Adjust docstrings of commands to auto-document.
  316. ;; Delete `It provides the following commands:' section because of duplication.
  317. ;;
  318. ;; Revision 1.5 2009/05/15 17:03:13 rubikitch
  319. ;; Show downloaded URL in header-line.
  320. ;;
  321. ;; Revision 1.4 2009/05/15 16:59:32 rubikitch
  322. ;; New internal variable: `auto-install-add-load-path-flag'
  323. ;;
  324. ;; Revision 1.3 2009/05/09 02:41:32 rubikitch
  325. ;; Add `auto-install-directory' automatically.
  326. ;;
  327. ;; Revision 1.2 2009/05/09 02:37:14 rubikitch
  328. ;; Changed `auto-install-get-buffer' format (including URL)
  329. ;;
  330. ;; Revision 1.1 2009/05/09 02:33:09 rubikitch
  331. ;; Initial revision
  332. ;;
  333. ;; 2009/05/01
  334. ;; * Andy Stewart:
  335. ;; * Take over by rubikitch.
  336. ;;
  337. ;; 2009/04/15
  338. ;; * rubikitch:
  339. ;; * Encoding detection support.
  340. ;;
  341. ;; 2009/04/07
  342. ;; * Andy Stewart:
  343. ;; * Fix bug of `auto-install-batch'.
  344. ;; * Add more sources to `auto-install-batch-list'.
  345. ;;
  346. ;; 2009/03/30
  347. ;; * Andy Stewart:
  348. ;; * Add new command: `auto-install-batch'.
  349. ;; * Add new option: `auto-install-batch-list'.
  350. ;;
  351. ;; 2009/03/29
  352. ;; * Andy Stewart:
  353. ;; * Add new function: `auto-install-from-url-list'.
  354. ;;
  355. ;; 2009/03/11
  356. ;; * Andy Stewart:
  357. ;; * Fix bug of `auto-install-download'.
  358. ;;
  359. ;; 2009/03/03
  360. ;; * rubikitch
  361. ;; * Add new command `auto-install-compatibility-setup'
  362. ;; for install-elisp users.
  363. ;; * Andy Stewart:
  364. ;; * `auto-install-region-or-thing' return region string
  365. ;; just when `transient-mark-mode' is on.
  366. ;; * Fix doc.
  367. ;;
  368. ;; 2009/02/17
  369. ;; * Andy Stewart:
  370. ;; * Modified keybindings, make it more easy to remember.
  371. ;; * Make `auto-install-save-confirm' default with `t'
  372. ;; for security problem.
  373. ;; * Pick up current symbol when use `auto-install-from-library'.
  374. ;; * Remove unnecessary completion name from `auto-install-from-library'.
  375. ;; * Refactory code.
  376. ;; * Fix doc.
  377. ;;
  378. ;; 2009/02/12
  379. ;; * Andy Stewart:
  380. ;; * Remove option `auto-install-update-emacswiki-package-name-when-startup'.
  381. ;; * Make current symbol as initialization of `auto-install-from-emacswiki'.
  382. ;; * Add option `unforced' to function `auto-install-update-emacswiki-package-name'.
  383. ;; * Fix doc.
  384. ;; * Fix bug of `auto-install-from-library'.
  385. ;;
  386. ;; 2009/02/10
  387. ;; * Andy Stewart:
  388. ;; * Automatically download package name list when
  389. ;; variable `auto-install-package-name-list' is nil.
  390. ;; * Reverse `auto-install-package-name-list' for `anything' interface.
  391. ;; * New command `auto-install-dired-mark-files',
  392. ;; mark files that contain at `EmacsWiki.org'.
  393. ;; * New command `auto-install-buffer-diff',
  394. ;; view different between current version and old version.
  395. ;;
  396. ;; 2009/02/06
  397. ;; * Andy Stewart:
  398. ;; * Add new command `auto-install-from-directory'.
  399. ;; * Remove option `auto-install-create-directory', not necessary.
  400. ;; * Documentation improvements (thanks Scot Becker)
  401. ;;
  402. ;; 2009/02/01
  403. ;; * Andy Stewart:
  404. ;; * Make command `auto-install-from-emacswiki' can
  405. ;; completing package name for input.
  406. ;; * Add new command `auto-install-update-emacswiki-package-name'.
  407. ;; * Add new option `auto-install-update-emacswiki-package-name-when-startup'
  408. ;;
  409. ;; 2009/01/30
  410. ;; * Andy Stewart:
  411. ;; * Compatibility with GNU Emacs 22.
  412. ;;
  413. ;; 2009/01/26
  414. ;; * Andy Stewart:
  415. ;; * Add new command `auto-install-from-gist'.
  416. ;;
  417. ;; 2009/01/21
  418. ;; * Andy Stewart:
  419. ;; * Add emacs-lisp syntax highlight for download buffer.
  420. ;; * Make notify message display at mode-line instead echo-area.
  421. ;;
  422. ;; 2009/01/10
  423. ;; * Andy Stewart:
  424. ;; * Add new option `auto-install-filter-url' and new function
  425. ;; `auto-install-from-library', try to use it. ;)
  426. ;;
  427. ;; 2009/01/08
  428. ;; * Andy Stewart:
  429. ;; * Fix coding bug.
  430. ;;
  431. ;; 2009/01/07
  432. ;; * Andy Stewart:
  433. ;; * Move `w3m' code to file `auto-install-extension.el' to make all
  434. ;; user can use this package with standard emacs.
  435. ;;
  436. ;; 2009/01/06
  437. ;; * Andy Stewart:
  438. ;; * Clean code.
  439. ;;
  440. ;; 2009/01/02
  441. ;; * Andy Stewart:
  442. ;; * Add new option `auto-install-create-directory' for create install directory
  443. ;; automatically if it doesn't exist.
  444. ;; * Improve many document make it more clear.
  445. ;; * Thanks document improve and create directory advice of 'Drew Adams'!
  446. ;;
  447. ;; 2008/12/24
  448. ;; * Andy Stewart:
  449. ;; * Remove `auto-install-window-configuration-before-download', `auto-install-init-window-layout'
  450. ;; and `auto-install-revert-window-layout'.
  451. ;; It's not necessary to revert window layout, `winner-mode' can revert window layout more better,
  452. ;; just type `winner-undo'.
  453. ;;
  454. ;; 2008/12/15
  455. ;; * Andy Stewart:
  456. ;; * Fix a little bug of `auto-install-window-configuration-before-download'.
  457. ;;
  458. ;; 2008/12/11
  459. ;; * Andy Stewart:
  460. ;; * Add new function `auto-install-from-buffer', to install elisp file from current buffer.
  461. ;; Modified `auto-install-buffer-save' to use `auto-install-from-buffer'.
  462. ;;
  463. ;; * First released.
  464. ;;
  465. ;;; Acknowledgements:
  466. ;;
  467. ;; rubikitch <rubikitch@ruby-lang.org>
  468. ;; For install-elisp.el
  469. ;; Drew Adams <drew.adams@oracle.com>
  470. ;; Scot Becker <scot.becker@gmail.com>
  471. ;; Richard Riley <rileyrgdev@gmail.com>
  472. ;; For documentation improvements and advices.
  473. ;;
  474. ;;; TODO
  475. ;;
  476. ;; Fix the problem parallel install process with recursive prompt.
  477. ;; Redesign and give more friendly user interface.
  478. ;; Scan RSS track package update and notify.
  479. ;;
  480. ;;; Require
  481. (require 'url)
  482. (require 'dired)
  483. (require 'find-func)
  484. (require 'bytecomp)
  485. (require 'thingatpt)
  486. (eval-when-compile (require 'cl))
  487. (when (<= emacs-major-version 22) ;Compatibility with 22.
  488. (autoload 'ignore-errors "cl-macs"))
  489. ;;; Code:
  490. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Customize ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  491. (defgroup auto-install nil
  492. "Auto install elisp files."
  493. :group 'external)
  494. (defcustom auto-install-directory "~/.emacs.d/auto-install/"
  495. "The directory for saving elisp files.
  496. This directory is used when a downloaded
  497. elisp file does not already exist in other directory.
  498. Otherwise, the existing file of the same name is replaced."
  499. :type 'string
  500. :group 'auto-install)
  501. (defcustom auto-install-buffer-name "auto-install"
  502. "The temporary buffer for storing download content."
  503. :type 'string
  504. :group 'auto-install)
  505. (defcustom auto-install-emacswiki-base-url "http://www.emacswiki.org/cgi-bin/wiki/download/"
  506. "The base emacswiki.org url from which to download elisp files."
  507. :type 'string
  508. :group 'auto-install)
  509. (defcustom auto-install-gist-base-url "http://gist.github.com/"
  510. "The base gist.github.com url from which to download elisp files."
  511. :type 'string
  512. :group 'auto-install)
  513. (defcustom auto-install-filter-url
  514. '(("color-grep" "http://www.bookshelf.jp/elc/"))
  515. "Alist mapping filter url for library.
  516. Default command `auto-install-from-library' will install from EmacsWiki,
  517. if it can't find match in this alist."
  518. :type '(repeat (list (string :tag "Library")
  519. (string :tag "Download URL")))
  520. :group 'auto-install)
  521. (defcustom auto-install-save-confirm t
  522. "Whether confirmation is needed to save downloaded content.
  523. Nil means no confirmation is needed.
  524. If non-nil, the downloaded content is shown in a buffer and you are
  525. prompted to confirm saving it to a file."
  526. :type 'boolean
  527. :group 'auto-install)
  528. (defcustom auto-install-replace-confirm nil
  529. "Whether confirmation is needed to replace an existing elisp file.
  530. Nil means no confirmation is needed."
  531. :type 'boolean
  532. :group 'auto-install)
  533. (defcustom auto-install-install-confirm nil
  534. "Whether confirmation is needed to install a downloaded elisp file.
  535. Nil means no confirmation is needed."
  536. :type 'boolean
  537. :group 'auto-install)
  538. (defcustom auto-install-from-dired-confirm t
  539. "Whether confirmation is needed to download marked files from Dired.
  540. Nil means no confirmation is needed."
  541. :type 'boolean
  542. :group 'auto-install)
  543. (defcustom auto-install-batch-list
  544. '(
  545. ;; Icicles.
  546. ("icicles" 21 10
  547. (
  548. "http://www.emacswiki.org/emacs/download/icicles.el" ; Main library
  549. "http://www.emacswiki.org/emacs/download/icicles-chg.el" ; Change logs
  550. "http://www.emacswiki.org/emacs/download/icicles-cmd1.el" ; Top-level Icicles commands, part 1
  551. "http://www.emacswiki.org/emacs/download/icicles-cmd2.el" ; Top-level Icicles commands, part 2
  552. "http://www.emacswiki.org/emacs/download/icicles-doc1.el" ; Doc, part 1
  553. "http://www.emacswiki.org/emacs/download/icicles-doc2.el" ; Doc, part 2
  554. "http://www.emacswiki.org/emacs/download/icicles-face.el" ; Faces
  555. "http://www.emacswiki.org/emacs/download/icicles-fn.el" ; Non-interactive functions
  556. "http://www.emacswiki.org/emacs/download/icicles-mac.el" ; Macros
  557. "http://www.emacswiki.org/emacs/download/icicles-mcmd.el" ; Minibuffer commands
  558. "http://www.emacswiki.org/emacs/download/icicles-mode.el" ; Icicle (Icy) mode
  559. "http://www.emacswiki.org/emacs/download/icicles-opt.el" ; User options
  560. "http://www.emacswiki.org/emacs/download/icicles-var.el" ; Internal variables
  561. "http://www.emacswiki.org/emacs/download/lacarte.el" ; Menu-bar access from keyboard
  562. "http://www.emacswiki.org/emacs/download/icomplete+.el" ; Enhancements to `icomplete.el'
  563. "http://www.emacswiki.org/emacs/download/hexrgb.el" ; Color manipulation
  564. "http://www.emacswiki.org/emacs/download/synonyms.el" ; Look up synonyms
  565. ))
  566. ;; AutoComplete development version.
  567. ("auto-complete development version" nil nil
  568. (
  569. "http://github.com/m2ym/auto-complete/raw/master/popup.el"
  570. "http://github.com/m2ym/auto-complete/raw/master/auto-complete.el"
  571. "http://github.com/m2ym/auto-complete/raw/master/auto-complete-config.el"
  572. ))
  573. ;; Anything
  574. ("anything" nil nil
  575. (
  576. "http://www.emacswiki.org/emacs/download/anything.el" ; Main library
  577. "http://www.emacswiki.org/emacs/download/anything-config.el" ; Configuration for anything.el
  578. "http://www.emacswiki.org/emacs/download/anything-match-plugin.el" ; Matching algorithm humanely
  579. "http://www.emacswiki.org/emacs/download/anything-migemo.el" ; Migemo extension for Japanese
  580. "http://www.emacswiki.org/emacs/download/anything-complete.el" ; Completion
  581. "http://www.emacswiki.org/emacs/download/anything-show-completion.el" ; Show completion prettily
  582. "http://www.emacswiki.org/emacs/download/anything-auto-install.el" ; auto-install extension
  583. "http://www.emacswiki.org/emacs/download/descbinds-anything.el" ; describe-key replacement
  584. "http://www.emacswiki.org/emacs/download/anything-grep.el" ; Grep with anything
  585. "http://www.emacswiki.org/emacs/download/anything-startup.el" ; Startup file
  586. ))
  587. ;; SDCV (Interface for StartDict console version)
  588. ("sdcv" nil nil
  589. (
  590. "http://www.emacswiki.org/emacs/download/showtip.el" ; Basic tooltip show library
  591. "http://www.emacswiki.org/emacs/download/sdcv.el" ; sdcv.el
  592. ))
  593. ;; Lazy search
  594. ("lazy-search" nil nil
  595. (
  596. "http://www.emacswiki.org/emacs/download/one-key.el" ; Basic library for lazy-search.el
  597. "http://www.emacswiki.org/emacs/download/lazy-search.el" ; Main library
  598. ))
  599. ;; PHP completion
  600. ("php-completion" nil nil
  601. (
  602. "http://www.emacswiki.org/emacs/download/anything.el"
  603. "http://www.emacswiki.org/emacs/download/anything-match-plugin.el"
  604. "http://www.emacswiki.org/emacs/download/anything-show-completion.el"
  605. "http://www.emacswiki.org/emacs/download/php-completion.el"
  606. ))
  607. ;; Perl completion
  608. ("perl-completion" nil nil
  609. (
  610. "http://www.emacswiki.org/emacs/download/anything.el"
  611. "http://www.emacswiki.org/emacs/download/anything-match-plugin.el"
  612. "http://www.emacswiki.org/emacs/download/anything-show-completion.el"
  613. "http://www.emacswiki.org/emacs/download/perl-completion.el"
  614. ))
  615. ;; Text Translator
  616. ("text translator" nil nil
  617. (
  618. "http://www.emacswiki.org/emacs/download/text-translator.el"
  619. "http://www.emacswiki.org/emacs/download/text-translator-vars.el"
  620. "http://www.emacswiki.org/emacs/download/text-translator-load.el"
  621. ))
  622. )
  623. "This list contain packages information for batch install.
  624. Have four arguments per list:
  625. First argument is extension name.
  626. Second argument is delay time for batch install.
  627. Third argument is libraries number limit in delay time.
  628. Fourth argument is libraries url list.
  629. Anyone can add information in this list for batch install."
  630. :group 'auto-install)
  631. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Variable ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  632. (defvar auto-install-download-buffer nil
  633. "The download buffer used by `url-retrieve'.
  634. This variable is always buffer-local.")
  635. (make-variable-buffer-local 'auto-install-download-buffer)
  636. (defvar auto-install-download-url nil
  637. "The url from which to download files.
  638. This variable is always buffer-local.")
  639. (make-variable-buffer-local 'auto-install-download-url)
  640. (defvar auto-install-last-url nil
  641. "The last url used in `auto-install-from-url'.")
  642. (defvar auto-install-last-gist-id nil
  643. "The last gist id you visit in `auto-install-from-gist'.")
  644. (defvar auto-install-package-name-list nil
  645. "The package name list for completion input.")
  646. (defvar auto-install-minor-mode-map
  647. (let ((map (make-sparse-keymap)))
  648. (define-key map (kbd "C-c C-d") 'auto-install-buffer-diff) ;diff
  649. (define-key map (kbd "C-c C-c") 'auto-install-buffer-save) ;save
  650. (define-key map (kbd "C-c C-q") 'auto-install-buffer-quit) ;quit
  651. map)
  652. "Keymap used by variable `auto-install-minor-mode'.")
  653. (defvar auto-install-add-load-path-flag t
  654. "If non-nil, add `auto-install-directory' to `load-path'.
  655. This variable is intended to be used in test.")
  656. (defvar auto-install-waiting-url-list nil
  657. "URLs in downloading.")
  658. (defvar auto-install-url-queue nil
  659. "Installation order.")
  660. (defvar auto-install-download-buffer-alist nil
  661. "Pairs of URL and downloaded buffer.")
  662. (define-minor-mode auto-install-minor-mode
  663. "Auto Install minor mode."
  664. :init-value nil
  665. :lighter " Auto-Install"
  666. :keymap auto-install-minor-mode-map
  667. :group 'auto-install)
  668. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  669. (defun auto-install-from-buffer ()
  670. "Install the elisp file in the current buffer."
  671. (interactive)
  672. (let (filename)
  673. (setq filename (read-string (format "Filename (%s): " (buffer-name)) nil nil (buffer-name)))
  674. (auto-install-mode)
  675. (auto-install-buffer-save filename)))
  676. (defun auto-install-from-url (&optional url)
  677. "Install an elisp file from a given url."
  678. (interactive)
  679. (or url (setq url (read-string (format "URL (%s): " (or auto-install-last-url "")) nil nil auto-install-last-url)))
  680. (setq auto-install-last-url url)
  681. (auto-install-download url))
  682. (defun auto-install-from-emacswiki (&optional file)
  683. "Install an elisp file from EmacsWiki.org."
  684. (interactive)
  685. (cond (auto-install-package-name-list
  686. ;; Install package if `auto-install-package-name-list' is non-nil.
  687. (or file (setq file (auto-install-get-candidate "Package" auto-install-package-name-list)))
  688. (auto-install-download (concat auto-install-emacswiki-base-url file)))
  689. (t
  690. ;; Otherwise update package name and install.
  691. (auto-install-download "http://www.emacswiki.org/cgi-bin/emacs?action=index;raw=1"
  692. 'auto-install-handle-emacswiki-package-install))))
  693. (defun auto-install-from-gist (&optional gistid)
  694. "Install an elisp file from gist.github.com.
  695. Optional argument GISTID is gist ID for download elisp file from gist.github.com."
  696. (interactive)
  697. (or gistid (setq gistid (read-string (format "Gist ID (%s): " (or auto-install-last-gist-id ""))
  698. nil nil
  699. auto-install-last-gist-id)))
  700. (setq auto-install-last-gist-id gistid)
  701. (auto-install-download (format "%s%s.txt" auto-install-gist-base-url gistid)))
  702. (defun auto-install-from-library (&optional library)
  703. "Update an elisp LIBRARY.
  704. Default this function will found 'download url' from `auto-install-filter-url',
  705. if not found, try to download from EmacsWiki."
  706. (interactive
  707. (let* ((dirs load-path)
  708. (suffixes (find-library-suffixes)))
  709. (list (auto-install-get-candidate "Library name" (auto-install-get-library-list)))))
  710. (let ((filename (file-name-nondirectory (find-library-name library)))
  711. (base-url auto-install-emacswiki-base-url)
  712. (library-name (replace-regexp-in-string "\\(\\.el.*$\\)" "" library)))
  713. (if (assoc library-name auto-install-filter-url)
  714. (setq base-url (cadr (assoc library-name auto-install-filter-url))))
  715. (auto-install-download (concat base-url filename))))
  716. (defun auto-install-from-directory (directory)
  717. "Update elisp files under DIRECTORY from EmacsWiki.
  718. You can use this command to update elisp file under DIRECTORY."
  719. (interactive "DDirectory: ")
  720. (let (filename)
  721. (dolist (file (directory-files directory t))
  722. (if (file-directory-p file)
  723. ;; Don't match . or .. directory.
  724. (unless (string-match "^\\.\\.?$" (file-name-nondirectory file))
  725. ;; Find files in sub-directory.
  726. (auto-install-from-directory file))
  727. ;; Get file name.
  728. (setq filename (file-name-nondirectory file))
  729. ;; Not backup file.
  730. (unless (string-match "^\\.?#" filename)
  731. ;; Match elisp file.
  732. (if (string-match "^.*\\.el" filename)
  733. (auto-install-download (concat auto-install-emacswiki-base-url filename))))))))
  734. (defun auto-install-from-dired ()
  735. "Update dired marked elisp files from EmacsWiki.org.
  736. You can use this to download marked files in Dired asynchronously."
  737. (interactive)
  738. (if (eq major-mode 'dired-mode)
  739. (if (or (not auto-install-from-dired-confirm)
  740. (yes-or-no-p "Do you want install marked files from EmacsWiki.org?"))
  741. (dolist (file (dired-get-marked-files))
  742. (auto-install-download (concat auto-install-emacswiki-base-url (file-name-nondirectory file)))))
  743. (error "This command is only for `dired-mode'.")))
  744. (defun auto-install-update-emacswiki-package-name (&optional unforced)
  745. "Update the list of elisp package names from `EmacsWiki'.
  746. By default, this function will update package name forcibly.
  747. If UNFORCED is non-nil, just update package name when `auto-install-package-name-list' is nil."
  748. (interactive)
  749. (unless (and unforced
  750. auto-install-package-name-list)
  751. (auto-install-download "http://www.emacswiki.org/cgi-bin/emacs?action=index;raw=1"
  752. 'auto-install-handle-emacswiki-package-name)))
  753. (defun auto-install-dired-mark-files ()
  754. "Mark dired files that contain at `EmacsWiki.org'."
  755. (interactive)
  756. (if (eq major-mode 'dired-mode)
  757. (if auto-install-package-name-list
  758. ;; Mark files that exist at `EmacsWiki'.
  759. (auto-install-dired-mark-files-internal)
  760. ;; Or get package name list and match files.
  761. (auto-install-download "http://www.emacswiki.org/cgi-bin/emacs?action=index;raw=1"
  762. 'auto-install-handle-dired-mark-files))
  763. (error "This command just use in `dired-mode'.")))
  764. (defun auto-install-mode ()
  765. "Major mode for auto-installing elisp code."
  766. (interactive)
  767. ;; Load emacs-lisp syntax highlight.
  768. (set-syntax-table emacs-lisp-mode-syntax-table)
  769. (lisp-mode-variables)
  770. (setq font-lock-mode t)
  771. (font-lock-fontify-buffer)
  772. ;; Read only.
  773. (setq buffer-read-only t)
  774. (and view-read-only (view-mode 1))
  775. ;; Load `auto-install' mode.
  776. (auto-install-minor-mode t)
  777. (setq major-mode 'auto-install-minor-mode))
  778. (defun auto-install-buffer-quit ()
  779. "Quit from `auto-install' temporary buffer."
  780. (interactive)
  781. ;; Quit buffer.
  782. (if (eq major-mode 'auto-install-minor-mode)
  783. (auto-install-quit)
  784. (error "This command just use in `auto-install-minor-mode'.")))
  785. (defun auto-install-compatibility-setup ()
  786. "Install Compatibility commands for install-elisp.el users."
  787. (interactive)
  788. (defalias 'install-elisp 'auto-install-from-url)
  789. (if (require 'anything-auto-install nil t)
  790. (defalias 'install-elisp-from-emacswiki 'anything-auto-install-from-emacswiki)
  791. (defalias 'install-elisp-from-emacswiki 'auto-install-from-emacswiki))
  792. (defalias 'install-elisp-from-gist 'auto-install-from-gist)
  793. (message "Install-elisp compatibility installed.
  794. install-elisp = %s
  795. install-elisp-from-emacswiki = %s
  796. install-elisp-from-gist = %s"
  797. (symbol-function 'install-elisp)
  798. (symbol-function 'install-elisp-from-emacswiki)
  799. (symbol-function 'install-elisp-from-gist)))
  800. (defun auto-install-batch (&optional extension-name)
  801. "Batch install many libraries in some extension.
  802. EXTENSION-NAME is extension name for batch install."
  803. (interactive)
  804. (let (extension-info-list)
  805. ;; Get extension information list.
  806. (setq extension-info-list
  807. (assoc (or
  808. ;; Get information list from give extension name.
  809. extension-name
  810. ;; Otherwise completion from user select.
  811. (completing-read "Extension name: " (mapcar 'car auto-install-batch-list)))
  812. auto-install-batch-list))
  813. (if extension-info-list
  814. ;; Install extension libraries.
  815. (let ((extension-delay-time (nth 1 extension-info-list))
  816. (extension-limit-number (nth 2 extension-info-list))
  817. (extension-library-list (car (last extension-info-list))))
  818. (setq auto-install-waiting-url-list extension-library-list
  819. auto-install-url-queue extension-library-list)
  820. (if (not (and
  821. ;; Delay time is above 0.
  822. extension-delay-time
  823. (> extension-delay-time 0)
  824. ;; Limit number is above 0.
  825. extension-limit-number
  826. (> extension-limit-number 0)))
  827. (auto-install-from-url-list extension-library-list)
  828. (let ((delay-counter 0)
  829. install-list)
  830. (while extension-library-list
  831. (if (> (length extension-library-list) extension-limit-number)
  832. ;; Install apart libraries list under `extension-limit-number'
  833. (progn
  834. (setq install-list (nthcar extension-limit-number extension-library-list))
  835. (run-with-timer
  836. (* delay-counter extension-delay-time)
  837. nil
  838. 'auto-install-from-url-list install-list)
  839. (setq extension-library-list (nthcdr+ extension-limit-number extension-library-list))
  840. (incf delay-counter))
  841. ;; Install remain libraries list.
  842. (setq install-list extension-library-list)
  843. (run-with-timer
  844. (* delay-counter extension-delay-time)
  845. nil
  846. 'auto-install-from-url-list install-list)
  847. (setq extension-library-list nil))))))
  848. ;; Notify message when haven't install information
  849. ;; for libraries that user given.
  850. (message "Haven't install information for `%s'." extension-name))))
  851. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Utilities Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  852. (defun auto-install-download (url &optional handle-function)
  853. "Download elisp file from URL.
  854. HANDLE-FUNCTION for handle download content,
  855. default is `auto-install-handle-download-content'."
  856. ;; Check and create install directory.
  857. (unless (file-exists-p auto-install-directory)
  858. (make-directory auto-install-directory)
  859. (when auto-install-add-load-path-flag
  860. (add-to-list 'load-path auto-install-directory))
  861. (message "Create directory %s for install elisp file." auto-install-directory))
  862. ;; Download.
  863. (let* ((url-request-method "GET")
  864. (url-request-extra-headers nil)
  865. (url-mime-accept-string "*/*")
  866. (parsed-url (url-generic-parse-url url))
  867. (download-buffer (auto-install-get-buffer url))
  868. (download-buffer-name (buffer-name download-buffer)))
  869. (with-current-buffer download-buffer
  870. ;; Bind download url with local buffer.
  871. (setq auto-install-download-url url)
  872. ;; Bind download buffer with local buffer.
  873. ;;
  874. ;; Use buffer-local variable receive
  875. ;; data from `url-retrieve' to make asynchronously
  876. ;; download file with special buffer.
  877. ;;
  878. ;; Because the buffer name is unique that generate
  879. ;; through `current-time', so can download many elisp file
  880. ;; asynchronously and won't conflict each other.
  881. (setq auto-install-download-buffer
  882. (url-retrieve parsed-url
  883. 'auto-install-download-callback
  884. (list download-buffer-name handle-function))))))
  885. (defun auto-install-download-callback (&optional redirect download-buffer-name handle-function)
  886. "The callback for `auto-install-download'.
  887. With `auto-install-download', this downloads elisp files asynchronously.
  888. REDIRECT is the argument for check download status.
  889. DOWNLOAD-BUFFER-NAME is the name of download buffer.
  890. HANDLE-FUNCTION is function for handle download content."
  891. (if (eq (car redirect) ':error)
  892. ;; Notify user and kill buffer when occur error.
  893. (with-current-buffer (get-buffer download-buffer-name)
  894. (message "Download from '%s' failed." auto-install-download-url)
  895. (kill-buffer download-buffer-name))
  896. ;; Otherwise continue install process.
  897. (auto-install-retrieve-decode download-buffer-name) ;decode retrieve information.
  898. (with-current-buffer (get-buffer download-buffer-name)
  899. ;; Show successful message
  900. (message "Download from '%s' successful." auto-install-download-url)
  901. ;; Handle download content.
  902. (funcall (or handle-function 'auto-install-handle-download-content)
  903. (current-buffer)))))
  904. (defun auto-install-retrieve-decode (retrieve-buffer-name)
  905. "Decode the RETRIEVE-BUFFER-NAME with coding detection."
  906. (declare (special url-http-end-of-headers))
  907. (with-current-buffer (get-buffer retrieve-buffer-name)
  908. (insert
  909. (with-current-buffer auto-install-download-buffer
  910. (set-buffer-multibyte t)
  911. (goto-char (1+ url-http-end-of-headers))
  912. (decode-coding-region
  913. (point) (point-max)
  914. (coding-system-change-eol-conversion
  915. ;; rubikitch: encoding detection is better because of
  916. ;; non-utf8 Japanese encodings.
  917. (detect-coding-region (point-min) (point-max) t) 'dos))
  918. (buffer-substring (point) (point-max))))
  919. (goto-char (point-min))))
  920. (defun auto-install-handle-download-content (download-buffer)
  921. "Handle the content downloaded to buffer DOWNLOAD-BUFFER."
  922. (with-current-buffer download-buffer
  923. ;; Load mode.
  924. (auto-install-mode)
  925. ;; Display help information in mode-line.
  926. (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."))
  927. (setq header-line-format (list auto-install-download-url))
  928. (setq auto-install-download-buffer-alist
  929. (cons (cons auto-install-download-url download-buffer)
  930. auto-install-download-buffer-alist))
  931. (setq auto-install-waiting-url-list
  932. (remove auto-install-download-url auto-install-waiting-url-list))
  933. ;; When all files are downloaded
  934. (unless auto-install-waiting-url-list
  935. ;; Select first file
  936. (switch-to-buffer (or (assoc-default (car auto-install-url-queue)
  937. auto-install-download-buffer-alist)
  938. ;; if single file
  939. download-buffer))
  940. (unless auto-install-save-confirm
  941. (auto-install-buffer-save)))))
  942. (defun auto-install-handle-emacswiki-package-name (download-buffer &optional prompt-install)
  943. "Handle elisp package name from `EmacsWiki'.
  944. DOWNLOAD-BUFFER is the name of download buffer.
  945. PROMPT-INSTALL is non-nil, will prompt package name for install."
  946. ;; Update package name list.
  947. (auto-install-update-emacswiki-package-list download-buffer)
  948. ;; Prompt package name for install.
  949. (when prompt-install
  950. (auto-install-download
  951. (concat auto-install-emacswiki-base-url
  952. (auto-install-get-candidate "Package" auto-install-package-name-list)))))
  953. (defun auto-install-handle-dired-mark-files (download-buffer)
  954. "Handle dired mark files that exist at `EmacsWiki'.
  955. DOWNLOAD-BUFFER is the name of download buffer."
  956. ;; Update package name list.
  957. (auto-install-update-emacswiki-package-list download-buffer)
  958. ;; Mark dired files.
  959. (auto-install-dired-mark-files-internal))
  960. (defun auto-install-handle-emacswiki-package-install (download-buffer)
  961. "Handle elisp package install from `EmacsWiki'.
  962. DOWNLOAD-BUFFER is the name of download buffer."
  963. (auto-install-handle-emacswiki-package-name download-buffer t))
  964. (defun auto-install-update-emacswiki-package-list (download-buffer)
  965. "Filter and update package name list from `EmacsWiki'.
  966. DOWNLOAD-BUFFER is the name of download buffer."
  967. (goto-char (point-min))
  968. (setq auto-install-package-name-list
  969. (loop while (re-search-forward "^.*\\.el$" nil t)
  970. collect (match-string 0)))
  971. ;; Kill buffer.
  972. (kill-buffer download-buffer)
  973. ;; Display successful message.
  974. (message "Update package name from `EmacsWiki' successful."))
  975. (defun auto-install-buffer-diff ()
  976. "View different between old version.
  977. This command just run when have exist old version."
  978. (interactive)
  979. (let* ((new-file (url-file-nondirectory auto-install-download-url))
  980. (old-file (auto-install-get-path new-file)))
  981. (if old-file
  982. ;; View different when have old version exist.
  983. (ediff-buffers (current-buffer) (find-file-noselect old-file))
  984. ;; Otherwise notify user.
  985. (message "Haven't old version exist."))))
  986. (defun auto-install-buffer-save (&optional filename)
  987. "Save downloaded content to file FILENAME."
  988. (interactive)
  989. (if (eq major-mode 'auto-install-minor-mode)
  990. (let (file-path)
  991. ;; Get filename
  992. (unless filename
  993. (setq filename (url-file-nondirectory auto-install-download-url)))
  994. ;; Make sure file suffix with `.el'.
  995. (while (not (string-match ".*\.el$" filename))
  996. (setq filename (read-string "Please input file name suffix with `.el': ")))
  997. ;; Get file path.
  998. (setq file-path
  999. (or
  1000. ;; Replace file if have exist.
  1001. (auto-install-get-path filename)
  1002. ;; Otherwise, install in directory `auto-install-directory'.
  1003. (concat auto-install-directory filename)))
  1004. ;; Save file.
  1005. (if (and (file-exists-p file-path)
  1006. auto-install-replace-confirm
  1007. (not (yes-or-no-p (format "Do you want replace file: '%s' ?" file-path))))
  1008. (auto-install-quit)
  1009. (write-file file-path)
  1010. (auto-install-install file-path)))
  1011. (error "This command just use in `auto-install-minor-mode'.")))
  1012. (defun auto-install-install (file-path)
  1013. "Install elisp file FILE-PATH."
  1014. (if (and auto-install-install-confirm
  1015. (not (yes-or-no-p (format "Do you want install file: '%s' ?" file-path))))
  1016. (auto-install-quit)
  1017. (let (byte-compile-warnings) ;; suppress compile warnings
  1018. ;; Compile and load file.
  1019. (setq auto-install-url-queue (cdr auto-install-url-queue))
  1020. (unless (ignore-errors (byte-compile-file file-path t))
  1021. ;; Show `ERROR' message if compile failed.
  1022. (message (format "Auto-Install ERROR: Compiled file '%s' failed." file-path)))
  1023. ;; Install next file.
  1024. (cond ((car auto-install-url-queue)
  1025. (switch-to-buffer (assoc-default (car auto-install-url-queue)
  1026. auto-install-download-buffer-alist))
  1027. (unless auto-install-save-confirm
  1028. (auto-install-buffer-save)))
  1029. (t ;completed
  1030. ;; cleanup
  1031. (setq auto-install-url-queue nil)
  1032. (setq auto-install-download-buffer-alist nil)
  1033. (message "Installation is completed."))))))
  1034. (defun auto-install-quit ()
  1035. "Quit auto-install."
  1036. ;; Kill buffer
  1037. (kill-buffer (current-buffer))
  1038. ;; Show quit message.
  1039. (message "Quit auto-install process."))
  1040. (defun auto-install-get-path (library)
  1041. "Return the absolute file path of the Lisp source of LIBRARY."
  1042. ;; If the library is byte-compiled, try to find a source library by
  1043. ;; the same name.
  1044. (if (string-match "\\.el\\(c\\(\\..*\\)?\\)\\'" library)
  1045. (setq library (replace-match "" t t library)))
  1046. (or
  1047. (locate-file library
  1048. (or find-function-source-path load-path)
  1049. (find-library-suffixes))
  1050. (locate-file library
  1051. (or find-function-source-path load-path)
  1052. load-file-rep-suffixes)))
  1053. (defun auto-install-get-buffer (url)
  1054. "Get a buffer for temporary storage of downloaded content.
  1055. Uses `current-time' to make buffer name unique."
  1056. (get-buffer-create (format "*%s %s <%s>*"
  1057. auto-install-buffer-name url
  1058. (format-time-string "%m/%d %H:%M:%S"))))
  1059. (defun auto-install-dired-mark-files-internal ()
  1060. "Mark files that match `auto-install-package-name-list'."
  1061. ;; Set buffer visible in select window.
  1062. (set-buffer (window-buffer))
  1063. ;; Get mark files.
  1064. (save-excursion
  1065. (let (filename)
  1066. ;; Unmark all markes.
  1067. (dired-unmark-all-marks)
  1068. ;; Try to mark files.
  1069. (goto-char (point-min))
  1070. (while (not (eobp))
  1071. (setq filename (dired-get-filename nil t))
  1072. (if (and filename
  1073. (not (file-directory-p filename))
  1074. (member (file-name-nondirectory filename) auto-install-package-name-list))
  1075. (dired-mark 1))
  1076. (dired-next-line 1)))))
  1077. (defun auto-install-region-or-thing (&optional thing)
  1078. "Return region or thing around point.
  1079. If `mark-active' and variable `transient-mark-mode', return region.
  1080. If THING is non-nil, return THING around point;
  1081. otherwise return symbol around point."
  1082. ;; Return string.
  1083. (if (and mark-active
  1084. transient-mark-mode)
  1085. ;; Return region string just when
  1086. ;; `mark-active' and `transient-mark-mode' is on.
  1087. (buffer-substring-no-properties (region-beginning)
  1088. (region-end))
  1089. ;; Otherwise try to pick-up THING around point.
  1090. (setq thing (or thing 'symbol))
  1091. (ignore-errors
  1092. (save-excursion
  1093. (buffer-substring-no-properties (beginning-of-thing thing)
  1094. (end-of-thing thing))))))
  1095. (defun auto-install-get-library-list (&optional dirs string)
  1096. "Do completion for file names passed to `locate-file'.
  1097. DIRS is directory to search path.
  1098. STRING is string to match."
  1099. ;; Use `load-path' as path when ignore `dirs'.
  1100. (or dirs (setq dirs load-path))
  1101. ;; Init with blank when ignore `string'.
  1102. (or string (setq string ""))
  1103. ;; Get library list.
  1104. (let ((string-dir (file-name-directory string))
  1105. name
  1106. names)
  1107. (dolist (dir dirs)
  1108. (unless dir
  1109. (setq dir default-directory))
  1110. (if string-dir
  1111. (setq dir (expand-file-name string-dir dir)))
  1112. (when (file-directory-p dir)
  1113. (dolist (file (file-name-all-completions
  1114. (file-name-nondirectory string) dir))
  1115. ;; Suffixes match `load-file-rep-suffixes'.
  1116. (setq name (if string-dir (concat string-dir file) file))
  1117. (if (string-match (format "^.*\\.el%s$" (regexp-opt load-file-rep-suffixes)) name)
  1118. (add-to-list 'names name)))))
  1119. names))
  1120. (defun auto-install-get-candidate (prompt collection)
  1121. "Get candidate from completing list.
  1122. PROMPT is string for prompt.
  1123. COLLECTION is list for completing candidates."
  1124. (completing-read (format "%s (%s): " prompt (or (auto-install-region-or-thing) ""))
  1125. collection
  1126. nil nil nil nil
  1127. (auto-install-region-or-thing)))
  1128. (defun auto-install-from-url-list (&optional url-list)
  1129. "Batch install many packages form URL-LIST."
  1130. (if (listp url-list)
  1131. (dolist (url url-list)
  1132. (auto-install-from-url url))
  1133. (error "Invalid url list for install.")))
  1134. (defun nthcdr+ (n list)
  1135. "Take cdr N times on LIST, return the result.
  1136. If LIST length below N, return entire list.
  1137. If LIST is nil, return nil."
  1138. (if (or (null list)
  1139. (> n (length list)))
  1140. list
  1141. (nthcdr n list)))
  1142. (defun nthcar (n list)
  1143. "Return first N elements of LIST.
  1144. If LIST length below N, return entire list.
  1145. If LIST is nil, return nil."
  1146. (reverse (nthcdr (- (length list) n) (reverse list))))
  1147. (provide 'auto-install)
  1148. ;; How to save (DO NOT REMOVE!!)
  1149. ;; (emacswiki-post "auto-install.el")
  1150. ;;; auto-install.el ends here
  1151. ;;; LocalWords: el eol dirs fontify gistid txt func bytecomp DDirectory ediff
  1152. ;;; LocalWords: noselect Unmark unmark AutoInstall keybindings defalias'es