emacs - Result value of elisp code stored in a file? -


looking way how evaluate elisp code stored in external file , pass result function argument. example demonstrating i'd achieve follows:

;; content of my_template.el '(this list)  ;; content of .emacs result of my_template.el has used (define-auto-insert "\.ext$"     ;; bellow attempt retrieve resulting list object     ;; getting nil instead     (with-temp-buffer       (insert-file-contents ("my_template.el"))       (eval-buffer)))) 

probably looking eval-like function besides side-effect returns result of last expression.

any idea ?

using variable share data easier , more common, example:

;; content of ~/my_template.el (defvar my-template '(this list))  ;; content of .emacs result of my_template.el has used (load-file "~/my_template.el") (define-auto-insert "\.ext$"   my-template) 

update function eval-file should want:

;; content of ~/my_template.el '(this list)  (defun eval-file (file)   "execute file , return result of last expression."   (load-file file)   (with-temp-buffer     (insert-file-contents file)     (emacs-lisp-mode)     (goto-char (point-max))     (backward-sexp)     (eval (sexp-at-point))))  (eval-file "~/my_template.el") => (this list) 

update two: without evaluate last expression twice

(defun eval-file (file)   "execute file , return result of last expression."   (eval    (ignore-errors      (read-from-whole-string       (with-temp-buffer         (insert-file-contents file)         (buffer-string))))))  (eval-file "~/my_template.el") => (this list) 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -