From 1053f3acfc21f24fc994ae85adff6779838b0ce7 Mon Sep 17 00:00:00 2001 From: Aaron Ecay Date: Sat, 17 Nov 2012 19:26:43 -0500 Subject: [PATCH] lisp/ob.el: add a size check to `org-babel-import-elisp-from-file' Reading large results can cause emacs to hang for a long time. Ask the user whether to proceed in such cases. Signed-off-by: Aaron Ecay --- lisp/ob.el | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/lisp/ob.el b/lisp/ob.el index bf4b455..b2385e9 100644 --- a/lisp/ob.el +++ b/lisp/ob.el @@ -2462,24 +2462,30 @@ appropriate." (defun org-babel-import-elisp-from-file (file-name &optional separator) "Read the results located at FILE-NAME into an elisp table. If the table is trivial, then return it as a scalar." - (let (result) - (save-window-excursion - (with-temp-buffer - (condition-case err - (progn - (org-table-import file-name separator) - (delete-file file-name) - (setq result (mapcar (lambda (row) - (mapcar #'org-babel-string-read row)) - (org-table-to-lisp)))) - (error (message "Error reading results: %s" err) nil))) - (if (null (cdr result)) ;; if result is trivial vector, then scalarize it - (if (consp (car result)) - (if (null (cdr (car result))) - (caar result) - result) - (car result)) - result)))) + (let* ((file-size (nth 7 (file-attributes file-name))) + (can-load (or (< file-size (* 10 1024)) ; 10kb + (not (y-or-n-p (concat "Displaying the block's large " + "results may hang emacs; skip " + "reading them?")))))) + (when can-load + (let (result) + (save-window-excursion + (with-temp-buffer + (condition-case err + (progn + (org-table-import file-name separator) + (delete-file file-name) + (setq result (mapcar (lambda (row) + (mapcar #'org-babel-string-read row)) + (org-table-to-lisp)))) + (error (message "Error reading results: %s" err) nil))) + (if (null (cdr result)) ;; if result is trivial vector, then scalarize it + (if (consp (car result)) + (if (null (cdr (car result))) + (caar result) + result) + (car result)) + result)))))) (defun org-babel-string-read (cell) "Strip nested \"s from around strings." -- 1.8.0