Skip to content
Evaluate expressions in a separate Emacs process
Emacs Lisp Makefile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
.travis.yml
LICENSE
Makefile
README.md
with-emacs-test.el
with-emacs.el

README.md

Build Status MELPA

with-emacs.el

Evaluate expressions in a separate Emacs process.

Installation

Clone this repository, or install from MELPA. Add the following to your .emacs:

(require 'with-emacs)

Usage

;; Use the same version of current Emacs
(with-emacs 
  (do-something)
  ...)

;; Use the specified version of Emacs and enable lexical binding
(with-emacs :path "/path/to/version/emacs" :lexical t
  (do-something)
  ...)

Examples

Determine if a function exists in a specific version of Emacs

(with-emacs :path "/Applications/Emacs-24.3.app/Contents/MacOS/Emacs"
  (fboundp 'string-suffix-p))
;; => nil

Get doc string from a specific version of Emacs

(with-emacs :path "/Applications/Emacs-24.4.app/Contents/MacOS/Emacs"
  (unless (fboundp 'elisp--company-doc-buffer)
    (defun elisp--company-doc-buffer (str)
      (let ((symbol (intern-soft str)))
        ;; FIXME: we really don't want to "display-buffer and then undo it".
        (save-window-excursion
          ;; Make sure we don't display it in another frame, otherwise
          ;; save-window-excursion won't be able to undo it.
          (let ((display-buffer-overriding-action
                 '(nil . ((inhibit-switch-frame . t)))))
            (ignore-errors
              (cond
               ((fboundp symbol) (describe-function symbol))
               ((boundp symbol) (describe-variable symbol))
               ((featurep symbol) (describe-package symbol))
               ((facep symbol) (describe-face symbol))
               (t (signal 'user-error nil)))
              (help-buffer)
              ))))))
  ;; avoid help buttons
  (defun help-window-display-message (quit-part window &optional scroll) nil)
  (message "%s" (with-current-buffer (elisp--company-doc-buffer "assoc")
                  (buffer-substring-no-properties (point-min)
                                                  (point-max)))))
;; => 
;; "assoc is a built-in function in `C source code'.
;;
;; (assoc KEY LIST)
;;
;; Return non-nil if KEY is `equal' to the car of an element of LIST.
;; The value is actually the first element of LIST whose car equals KEY.
;; "

Run test code in isolated scope

(defun greet (name)
  (message "Hello, %s" name))

(with-emacs
  (defun greet (name)
    (message "Hi, %s" name))
  (greet "Tom"))
;; => "Hi, Tom"

(greet "Tom")
;; => "Hello, Tom"
You can’t perform that action at this time.