Compare commits

..

3 Commits

Author SHA1 Message Date
8831ded178
Merge pull request #8 from torenord/master
`try-and-refresh' should take the same arguments as `try'
2018-12-04 03:36:08 +01:00
Tore Sund Norderud
e515e3373a try-and-refresh' should take the same arguments as try' 2018-12-03 13:42:48 +01:00
2fcfcbd9b0 Fix #7 2018-11-29 23:58:18 +01:00

14
try.el
View File

@ -36,9 +36,6 @@
(require 'package) (require 'package)
(require 'url) (require 'url)
(defvar try-tmp-dir (make-temp-file "try" t)
"A temporary directory for storing packages.")
(defun try-raw-link-p (url) (defun try-raw-link-p (url)
"Returns non-nil if this looks like an URL to a .el file." "Returns non-nil if this looks like an URL to a .el file."
(string-match-p "[^:]*://\\([^?\r\n]+\\).*\.el?$" url)) (string-match-p "[^:]*://\\([^?\r\n]+\\).*\.el?$" url))
@ -68,10 +65,10 @@
(completing-read "url or package: " pkgs))) (completing-read "url or package: " pkgs)))
;;;###autoload ;;;###autoload
(defun try-and-refresh () (defun try-and-refresh (&optional url-or-package)
"Refreshes package-list before calling `try'." "Refreshes package-list before calling `try'."
(interactive) (interactive)
(package-refresh-contents) (try)) (package-refresh-contents) (try url-or-package))
;;;###autoload ;;;###autoload
(defun try (&optional url-or-package) (defun try (&optional url-or-package)
@ -87,11 +84,12 @@ to a raw .el file. Packages are stored in `try-tmp-dir' and raw
(package-symbol (intern url-or-package))) (package-symbol (intern url-or-package)))
(cond ((try-raw-link-p url-or-package) (try-raw-link url-or-package)) (cond ((try-raw-link-p url-or-package) (try-raw-link url-or-package))
((try-package-exists-p package-symbol) ((try-package-exists-p package-symbol)
(let ((package-user-dir try-tmp-dir) (let* ((tmp-dir (make-temp-file (concat url-or-package "-") t))
(package-alist nil)) (package-user-dir tmp-dir)
(package-alist nil))
(if (version< emacs-version "25.1") (if (version< emacs-version "25.1")
(package-install package-symbol) (package-install package-symbol)
(package-install package-symbol 'dont-select)) (package-install package-symbol 'dont-select))
(message "Trying %s!" url-or-package))) (message "Trying %s!" url-or-package)))
(t (message (concat "Couldn't find a sensible way to try this. " (t (message (concat "Couldn't find a sensible way to try this. "
"Try running `package-refresh-contents'!")))))) "Try running `package-refresh-contents'!"))))))