Function: package-install-from-buffer
package-install-from-buffer is an autoloaded, interactive and
byte-compiled function defined in package.el.gz.
Signature
(package-install-from-buffer)
Documentation
Install a package from the current buffer.
The current buffer is assumed to be a single .el or .tar file or a directory. These must follow the packaging guidelines (see info node (elisp)Packaging).
Specially, if current buffer is a directory, the -pkg.el description file is not mandatory, in which case the information is derived from the main .el file in the directory. Using Dired, you can restrict what files to install by marking specific files.
Downloads and installs required packages as needed.
Probably introduced at or before Emacs version 25.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/package.el.gz
;;;###autoload
(defun package-install-from-buffer ()
"Install a package from the current buffer.
The current buffer is assumed to be a single .el or .tar file or
a directory. These must follow the packaging guidelines (see
info node `(elisp)Packaging').
Specially, if current buffer is a directory, the -pkg.el
description file is not mandatory, in which case the information
is derived from the main .el file in the directory. Using Dired,
you can restrict what files to install by marking specific files.
Downloads and installs required packages as needed."
(interactive)
(let* ((pkg-desc
(cond
((derived-mode-p 'dired-mode)
;; This is the only way a package-desc object with a `dir'
;; desc-kind can be created. Such packages can't be
;; uploaded or installed from archives, they can only be
;; installed from local buffers or directories.
(package-dir-info))
((derived-mode-p 'tar-mode)
(package-tar-file-info))
(t
;; Package headers should be parsed from decoded text
;; (see Bug#48137) where possible.
(if (and (eq buffer-file-coding-system 'no-conversion)
buffer-file-name)
(let* ((package-buffer (current-buffer))
(decoding-system
(car (find-operation-coding-system
'insert-file-contents
(cons buffer-file-name
package-buffer)))))
(with-temp-buffer
(insert-buffer-substring package-buffer)
(decode-coding-region (point-min) (point-max)
decoding-system)
(package-buffer-info)))
(save-excursion
(package-buffer-info))))))
(name (package-desc-name pkg-desc)))
;; Download and install the dependencies.
(let* ((requires (package-desc-reqs pkg-desc))
(transaction (package-compute-transaction nil requires)))
(package-download-transaction transaction))
;; Install the package itself.
(package-unpack pkg-desc)
(unless (package--user-selected-p name)
(package--save-selected-packages
(cons name package-selected-packages)))
(package--quickstart-maybe-refresh)
pkg-desc))