Skip to content

Commit

Permalink
Make "O" work for vectors
Browse files Browse the repository at this point in the history
* lispy.el (lispy--oneline): Update.

* lispy-test.el (lispy-oneline): Add test.
  • Loading branch information
abo-abo committed May 29, 2015
1 parent 0ba8c22 commit 7756a8f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
4 changes: 3 additions & 1 deletion lispy-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,9 @@ Insert KEY if there's no command."
(should (string= (lispy-with "(defun abc (x)\n \"def.\"\n (+ x\n x\n x))|" "O")
"(defun abc (x) \"def.\" (+ x x x))|"))
(should (string= (lispy-with "|(defun foo ()\n ;; comment\n (bar)\n (baz))" "O")
";; comment\n|(defun foo () (bar) (baz))")))
";; comment\n|(defun foo () (bar) (baz))"))
(should (string= (lispy-with "[1\n 2\n 3\n 4\n 5]|" "O")
"[1 2 3 4 5]|")))

(ert-deftest lispy-multiline ()
(should (string= (lispy-with "|(defun abc (x) \"def.\" (+ x x x) (foo) (bar))"
Expand Down
42 changes: 22 additions & 20 deletions lispy.el
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

;; Author: Oleh Krehel <[email protected]>
;; URL: https://github.com/abo-abo/lispy
;; Version: 0.23.0
;; Version: 0.26.0
;; Keywords: lisp

;; This file is not part of GNU Emacs
Expand Down Expand Up @@ -2456,25 +2456,27 @@ When the sexp is top-level, insert an additional newline."
"Remove newlines from EXPR.
When IGNORE-COMMENTS is not nil, don't remove comments.
Instead keep them, with a newline after each comment."
(lispy-mapcan-tree
(lambda (x y)
(cond ((equal x '(ly-raw newline))
y)
((lispy--raw-comment-p x)
(if (null ignore-comments)
(progn
(push x lispy--oneline-comments)
y)
(if (equal (car y) '(ly-raw newline))
(cons x y)
`(,x (ly-raw newline) ,@y))))
((and (lispy--raw-string-p x)
(null ignore-comments))
(cons `(ly-raw string ,(replace-regexp-in-string "\n" "\\\\n" (caddr x)))
y))
(t
(cons x y))))
expr))
(if (vectorp expr)
(apply #'vector (lispy--oneline (mapcar #'identity expr)))
(lispy-mapcan-tree
(lambda (x y)
(cond ((equal x '(ly-raw newline))
y)
((lispy--raw-comment-p x)
(if (null ignore-comments)
(progn
(push x lispy--oneline-comments)
y)
(if (equal (car y) '(ly-raw newline))
(cons x y)
`(,x (ly-raw newline) ,@y))))
((and (lispy--raw-string-p x)
(null ignore-comments))
(cons `(ly-raw string ,(replace-regexp-in-string "\n" "\\\\n" (caddr x)))
y))
(t
(cons x y))))
expr)))

(defun lispy-oneline ()
"Squeeze current sexp into one line.
Expand Down

0 comments on commit 7756a8f

Please sign in to comment.