Permalink
Browse files

Make "3e" a plain (silent) eval for Python

* lispy.el (lispy-eval): Check arg =3.

* le-python.el (lispy-eval-python-str): Trim string from left, remove
  the usual left space.
(lispy-bounds-python-block): Extend.
(lispy-eval-python): New optional arg.

* lispy-test.el (lispy-eval-python-str): Update.

* le-julia.el (lispy-eval-julia): New optional arg.

Motivation: use "3e" to eval expressions that would otherwise produce
megabytes of output, blocking the inferior Python.
  • Loading branch information...
1 parent 1871e5c commit 11a1fd6cccf87e35c38b0e65ae64bf6c1c03727f @abo-abo committed Sep 14, 2016
Showing with 23 additions and 20 deletions.
  1. +1 −1 le-julia.el
  2. +20 −17 le-python.el
  3. +1 −1 lispy-test.el
  4. +1 −1 lispy.el
View
@@ -32,7 +32,7 @@
(string-trim-right (julia-shell-collect-command-output str)))
;; TODO: simplify
-(defun lispy-eval-julia ()
+(defun lispy-eval-julia (&optional _plain)
(let (str bnd res)
(setq str
(save-excursion
View
@@ -67,8 +67,9 @@ Stripping them will produce code that's valid for an eval."
(lispy--string-dwim bnd))
"\n"))
((lispy-bolp)
- (lispy--string-dwim
- (lispy--bounds-c-toplevel)))
+ (string-trim-left
+ (lispy--string-dwim
+ (lispy--bounds-c-toplevel))))
(t
(cond ((lispy-left-p))
((lispy-right-p)
@@ -84,23 +85,25 @@ Stripping them will produce code that's valid for an eval."
(lispy--string-dwim bnd))))))
(defun lispy-bounds-python-block ()
- (when (save-excursion
- (when (looking-at " ")
- (forward-char))
- (python-info-beginning-of-block-p))
- (let ((indent (1+ (- (point) (line-beginning-position)))))
- (cons
- (line-beginning-position)
- (save-excursion
- (python-nav-end-of-block)
- (while (looking-at (format "[\n ]\\{%d,\\}\\(except\\|else\\)" indent))
- (goto-char (match-beginning 1))
- (python-nav-end-of-block))
- (point))))))
+ (if (save-excursion
+ (when (looking-at " ")
+ (forward-char))
+ (python-info-beginning-of-block-p))
+ (let ((indent (1+ (- (point) (line-beginning-position)))))
+ (cons
+ (line-beginning-position)
+ (save-excursion
+ (python-nav-end-of-block)
+ (while (looking-at (format "[\n ]\\{%d,\\}\\(except\\|else\\)" indent))
+ (goto-char (match-beginning 1))
+ (python-nav-end-of-block))
+ (point))))
+ (cons (point) (line-end-position))))
-(defun lispy-eval-python ()
+(defun lispy-eval-python (&optional plain)
(let ((res (lispy--eval-python
- (lispy-eval-python-str))))
+ (lispy-eval-python-str)
+ plain)))
(if (and res (not (equal res "")))
(lispy-message
(replace-regexp-in-string
View
@@ -2981,7 +2981,7 @@ Insert KEY if there's no command."
"|x = 42 # comment\n# comment\ny = 43"
(let ((forward-sexp-function nil))
(lispy-eval-python-str)))
- "x = 42 # comment"))
+ "x = 42 # comment\n"))
(unless (version< emacs-version "24.4.1")
(should (equal (progn
;; skip initialization msg
View
@@ -3985,7 +3985,7 @@ When ARG is 2, insert the result as a comment."
((setq handler (cdr (assoc major-mode lispy-eval-alist)))
(when (cadr handler)
(require (cadr handler)))
- (funcall (car handler)))
+ (funcall (car handler) (eq arg 3)))
(t
(save-excursion
(unless (or (lispy-right-p) (region-active-p))

0 comments on commit 11a1fd6

Please sign in to comment.