From 7756a8fbbadbebbd5e20768569ed92ad6c402c5c Mon Sep 17 00:00:00 2001 From: Oleh Krehel Date: Fri, 29 May 2015 14:26:54 +0200 Subject: [PATCH] Make "O" work for vectors * lispy.el (lispy--oneline): Update. * lispy-test.el (lispy-oneline): Add test. --- lispy-test.el | 4 +++- lispy.el | 42 ++++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/lispy-test.el b/lispy-test.el index 91ce39cf..cbaa7222 100644 --- a/lispy-test.el +++ b/lispy-test.el @@ -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))" diff --git a/lispy.el b/lispy.el index a0d01a86..11f6d55f 100644 --- a/lispy.el +++ b/lispy.el @@ -4,7 +4,7 @@ ;; Author: Oleh Krehel ;; 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 @@ -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.