Skip to content

Commit 3360f41

Browse files
committed
lispy.el: Update
1 parent 7e4250a commit 3360f41

File tree

2 files changed

+152
-147
lines changed

2 files changed

+152
-147
lines changed

lispy-pkg.el

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
(iedit "0.9.9")
66
(swiper "0.13.4")
77
(hydra "0.14.0")
8-
(zoutline "0.1.0")))
8+
(zoutline "0.2.0")))

lispy.el

+151-146
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
(require 'ediff-util)
141141
(require 'semantic)
142142
(require 'semantic/db))
143+
(require 'zoutline)
143144
(require 'mode-local)
144145
(require 'lispy-tags)
145146
(require 'help-fns)
@@ -2156,7 +2157,7 @@ When ARG is nagative, add them above instead"
21562157
(lvl (lispy-outline-level)))
21572158
(cond ((lispy--in-comment-p)
21582159
(goto-char (cdr (zo-bnd-subtree)))
2159-
(when (looking-back "\n+")
2160+
(when (looking-back "\n+" (point-min))
21602161
(delete-region (match-beginning 0) (match-end 0)))
21612162
(insert "\n\n"))
21622163
((and (lispy-bolp)
@@ -4217,7 +4218,7 @@ SYMBOL is a string."
42174218

42184219
(define-error 'eval-error "Eval error")
42194220

4220-
(defun lispy-eval (arg)
4221+
(defun lispy-eval (arg &optional e-str)
42214222
"Eval the current sexp and display the result.
42224223
When ARG is 2, insert the result as a comment.
42234224
When at an outline, eval the outline."
@@ -4230,7 +4231,7 @@ When at an outline, eval the outline."
42304231
(looking-at lispy-outline-header))
42314232
(lispy-eval-outline))
42324233
(t
4233-
(let ((res (lispy--eval nil)))
4234+
(let ((res (lispy--eval e-str)))
42344235
(when (memq major-mode lispy-clojure-modes)
42354236
(setq res (lispy--clojure-pretty-string res)))
42364237
(when lispy-eval-output
@@ -4699,8 +4700,8 @@ When ARG is non-nil, force select the window."
46994700
(lispy-eval 1))
47004701
(t
47014702
(with-selected-window target-window
4702-
(setq res (lispy--eval-elisp-form expr lexical-binding)))
4703-
(lispy--print-object res)))))
4703+
(setq res (lispy--eval-elisp-form expr lexical-binding))
4704+
(lispy--print-object res))))))
47044705

47054706
(defun lispy-follow ()
47064707
"Follow to `lispy--current-function'."
@@ -5744,52 +5745,57 @@ ARG is 4: `eval-defun' on the function from this sexp."
57445745
(let* ((ldsi-sxp (lispy--setq-expression))
57455746
(ldsi-fun (car ldsi-sxp)))
57465747
(cond
5747-
((memq ldsi-fun '(mapcar mapc mapcan
5748-
cl-remove-if cl-remove-if-not
5749-
cl-find-if cl-find-if-not
5750-
cl-some cl-every cl-any cl-notany))
5751-
(let ((fn (nth 1 ldsi-sxp))
5752-
(lst (nth 2 ldsi-sxp)))
5753-
(when (eq (car-safe fn) 'lambda)
5754-
(set (car (cadr fn)) (car (eval lst)))
5755-
(lispy-flow 2))))
5756-
((or (functionp ldsi-fun)
5757-
(macrop ldsi-fun))
5758-
(when (eq ldsi-fun 'funcall)
5759-
(setq ldsi-fun (eval (cadr ldsi-sxp)))
5760-
(setq ldsi-sxp (cons ldsi-fun (cddr ldsi-sxp))))
5761-
(let ((ldsi-args
5762-
(copy-sequence
5763-
(help-function-arglist
5764-
(if (ad-is-advised ldsi-fun)
5765-
(ad-get-orig-definition ldsi-fun)
5766-
ldsi-fun)
5767-
t)))
5768-
(ldsi-vals (cdr ldsi-sxp))
5769-
ldsi-arg
5770-
ldsi-val)
5771-
(catch 'done
5772-
(while (setq ldsi-arg (pop ldsi-args))
5773-
(cond ((eq ldsi-arg '&optional)
5774-
(setq ldsi-arg (pop ldsi-args))
5775-
(set ldsi-arg (eval (pop ldsi-vals))))
5776-
((eq ldsi-arg '&rest)
5777-
(setq ldsi-arg (pop ldsi-args))
5778-
(set ldsi-arg
5779-
(if (functionp ldsi-fun)
5780-
(mapcar #'eval ldsi-vals)
5781-
ldsi-vals))
5782-
(throw 'done t))
5783-
(t
5784-
(setq ldsi-val (pop ldsi-vals))
5785-
(set ldsi-arg
5786-
(if (functionp ldsi-fun)
5787-
(eval ldsi-val)
5788-
ldsi-val))))))
5789-
(lispy-goto-symbol ldsi-fun)))
5790-
(t
5791-
(lispy-complain
5792-
(format "%S isn't a function" ldsi-fun))))))
5748+
((memq ldsi-fun '(mapcar mapc mapcan
5749+
cl-remove-if cl-remove-if-not
5750+
cl-find-if cl-find-if-not
5751+
cl-some cl-every cl-any cl-notany))
5752+
(let ((fn (nth 1 ldsi-sxp))
5753+
(lst (nth 2 ldsi-sxp)))
5754+
(when (eq (car-safe fn) 'lambda)
5755+
(set (car (cadr fn)) (car (eval lst)))
5756+
(lispy-flow 2))))
5757+
((or (functionp ldsi-fun)
5758+
(macrop ldsi-fun))
5759+
(cond ((eq ldsi-fun 'funcall)
5760+
(setq ldsi-fun (eval (cadr ldsi-sxp)))
5761+
(setq ldsi-sxp (cons ldsi-fun (cddr ldsi-sxp))))
5762+
((eq ldsi-fun 'apply)
5763+
(setq ldsi-fun (eval (nth 1 ldsi-sxp)))
5764+
(let ((vals (mapcar #'eval (cddr ldsi-sxp))))
5765+
(setq ldsi-sxp
5766+
(cons ldsi-fun (append (butlast vals) (car (last vals))))))))
5767+
(let ((ldsi-args
5768+
(copy-sequence
5769+
(help-function-arglist
5770+
(if (ad-is-advised ldsi-fun)
5771+
(ad-get-orig-definition ldsi-fun)
5772+
ldsi-fun)
5773+
t)))
5774+
(ldsi-vals (cdr ldsi-sxp))
5775+
ldsi-arg
5776+
ldsi-val)
5777+
(catch 'done
5778+
(while (setq ldsi-arg (pop ldsi-args))
5779+
(cond ((eq ldsi-arg '&optional)
5780+
(setq ldsi-arg (pop ldsi-args))
5781+
(set ldsi-arg (eval (pop ldsi-vals))))
5782+
((eq ldsi-arg '&rest)
5783+
(setq ldsi-arg (pop ldsi-args))
5784+
(set ldsi-arg
5785+
(if (functionp ldsi-fun)
5786+
(mapcar #'eval ldsi-vals)
5787+
ldsi-vals))
5788+
(throw 'done t))
5789+
(t
5790+
(setq ldsi-val (pop ldsi-vals))
5791+
(set ldsi-arg
5792+
(if (functionp ldsi-fun)
5793+
(eval ldsi-val)
5794+
ldsi-val))))))
5795+
(lispy-goto-symbol ldsi-fun)))
5796+
(t
5797+
(lispy-complain
5798+
(format "%S isn't a function" ldsi-fun))))))
57935799
((eq major-mode 'clojure-mode)
57945800
(require 'le-clojure)
57955801
(lispy--clojure-debug-step-in))
@@ -7343,7 +7349,7 @@ See https://clojure.org/guides/weird_characters#_character_literal.")
73437349
((eq major-mode 'hy-mode)
73447350
(lispy--read-replace "[[:alnum:]-/*<>_?.,\\\\:!@#]+" "clojure-symbol"))
73457351
((memq major-mode lispy-clojure-modes)
7346-
(lispy--read-replace "[[:alnum:]-/*<>_?.\\\\:!@#=]+" "clojure-symbol"))
7352+
(lispy--read-replace "[[:alnum:]-+/*<>_?.\\\\:!@#=]+" "clojure-symbol"))
73477353
(t
73487354
(while (re-search-forward "\\(?:\\s-\\|\\s(\\)\\?" nil t)
73497355
(unless (lispy--in-string-or-comment-p)
@@ -7965,6 +7971,7 @@ Try to refresh if nil is returned."
79657971

79667972
(defvar helm-update-blacklist-regexps)
79677973
(defvar helm-candidate-number-limit)
7974+
(declare-function helm "ext:helm")
79687975

79697976
(defvar lispy-tag-history nil
79707977
"History for tags.")
@@ -8661,100 +8668,98 @@ Return an appropriate `setq' expression when in `let', `dolist',
86618668
(when tsexp
86628669
(lispy-different)
86638670
(cond
8664-
((looking-back "(\\(?:lexical-\\)?let\\(?:\\*\\|-when-compile\\)?[ \t\n]*"
8665-
(line-beginning-position 0))
8666-
(cons 'setq
8667-
(cl-mapcan
8668-
(lambda (x) (unless (listp x) (list x nil)))
8669-
tsexp)))
8670-
8671-
((lispy-after-string-p "(dolist ")
8672-
`(lispy--dolist-item-expr ',tsexp))
8673-
8674-
((and (consp tsexp)
8675-
(eq (car tsexp) 'lambda)
8676-
(eq (length (cadr tsexp)) 1)
8677-
(looking-back "(map\\sw* +"
8678-
(line-beginning-position)))
8679-
`(lispy--mapcar-item-expr ,tsexp
8680-
,(save-excursion
8681-
(lispy-different)
8682-
(read (current-buffer)))))
8683-
((and (consp tsexp)
8684-
(eq (car tsexp) 'find-file-noselect))
8685-
`(switch-to-buffer ,tsexp))
8686-
8687-
;; point moves
8688-
((progn
8689-
(lispy--out-backward 1)
8690-
(looking-back
8691-
"(\\(?:lexical-\\|if-\\|when-\\)?let\\(?:\\*\\|-when-compile\\)?[ \t\n]*"
8692-
(line-beginning-position 0)))
8693-
(cons
8694-
(if (eq major-mode 'scheme-mode)
8695-
'define
8696-
'setq)
8697-
tsexp))
8698-
8699-
((looking-back
8700-
"(\\(?:cl-\\)?labels[ \t\n]*"
8701-
(line-beginning-position 0))
8702-
(cons 'defun tsexp))
8703-
8704-
((looking-at
8705-
"(cond\\b")
8706-
(let ((re tsexp))
8707-
(if (cdr re)
8708-
`(if ,(car re)
8709-
(progn
8710-
,@(cdr re))
8711-
lispy--eval-cond-msg)
8712-
`(or ,(car re)
8713-
lispy--eval-cond-msg))))
8714-
((looking-at "(pcase\\s-*")
8715-
(goto-char (match-end 0))
8716-
(if (eval (pcase--expand (read (lispy--string-dwim))
8717-
`((,(car tsexp) t))))
8718-
(let ((pexpr (funcall (lispy--pcase-pattern-matcher (car tsexp))
8719-
(eval (read (lispy--string-dwim))))))
8720-
8721-
`(progn
8722-
,pexpr
8723-
',pexpr))
8724-
lispy--eval-pcase-msg))
8725-
((looking-at "(cl-destructuring-bind")
8726-
(let* ((x-expr (read (lispy--string-dwim)))
8727-
(x-parts (eval (nth 2 x-expr))))
8728-
(cl-mapc
8729-
#'set (nth 1 x-expr) x-parts)
8730-
(cons 'list (nth 1 x-expr))))
8731-
((looking-at "(with-current-buffer")
8732-
`(switch-to-buffer ,tsexp))
8733-
((and (looking-at "(\\(?:cl-\\)?\\(?:defun\\|defmacro\\)")
8734-
(save-excursion
8735-
(lispy-flow 1)
8736-
(eq (point) origin)))
8737-
(let* ((fn-name (save-excursion
8738-
(forward-char)
8739-
(forward-sexp 2)
8740-
(lispy--preceding-sexp)))
8741-
(int-form
8742-
(and (fboundp fn-name)
8743-
(interactive-form fn-name)))
8744-
(int-form (when (eq (car int-form) 'interactive)
8745-
(cond ((listp (cadr int-form))
8746-
(cadr int-form))
8747-
((equal (cadr int-form) "p")
8748-
''(1))))))
8749-
(if int-form
8750-
`(lispy-destructuring-setq ,tsexp
8751-
,int-form)
8752-
`(progn
8753-
,@(mapcar
8754-
(lambda (x)
8755-
(list 'setq x nil))
8756-
(delq '&key (delq '&optional (delq '&rest tsexp))))))))
8757-
(t tsexp))))))
8671+
((looking-back "(\\(?:lexical-\\)?let\\(?:\\*\\|-when-compile\\)?[ \t\n]*"
8672+
(line-beginning-position 0))
8673+
(cons 'setq
8674+
(cl-mapcan
8675+
(lambda (x) (unless (listp x) (list x nil)))
8676+
tsexp)))
8677+
8678+
((lispy-after-string-p "(dolist ")
8679+
`(lispy--dolist-item-expr ',tsexp))
8680+
8681+
((and (consp tsexp)
8682+
(eq (car tsexp) 'lambda)
8683+
(eq (length (cadr tsexp)) 1)
8684+
(looking-back "(map\\sw* +"
8685+
(line-beginning-position)))
8686+
`(lispy--mapcar-item-expr ,tsexp
8687+
,(save-excursion
8688+
(lispy-different)
8689+
(read (current-buffer)))))
8690+
((and (consp tsexp)
8691+
(eq (car tsexp) 'find-file-noselect))
8692+
`(switch-to-buffer ,tsexp))
8693+
8694+
;; point moves
8695+
((progn
8696+
(lispy--out-backward 1)
8697+
(looking-back
8698+
"(\\(?:lexical-\\|if-\\|when-\\)?let\\(?:\\*\\|-when-compile\\)?[ \t\n]*"
8699+
(line-beginning-position 0)))
8700+
(cons
8701+
(if (eq major-mode 'scheme-mode)
8702+
'define
8703+
'setq)
8704+
tsexp))
8705+
8706+
((looking-back
8707+
"(\\(?:cl-\\)?labels[ \t\n]*"
8708+
(line-beginning-position 0))
8709+
(cons 'defun tsexp))
8710+
8711+
((looking-at
8712+
"(cond\\b")
8713+
(let ((re tsexp))
8714+
(if (cdr re)
8715+
`(if ,(car re)
8716+
(progn
8717+
,@(cdr re))
8718+
lispy--eval-cond-msg)
8719+
`(or ,(car re)
8720+
lispy--eval-cond-msg))))
8721+
((looking-at "(pcase\\s-*")
8722+
(goto-char (match-end 0))
8723+
(if (eval (pcase--expand (read (lispy--string-dwim))
8724+
`((,(car tsexp) t))))
8725+
(let ((pexpr (funcall (lispy--pcase-pattern-matcher (car tsexp))
8726+
(eval (read (lispy--string-dwim))))))
8727+
8728+
`(progn
8729+
,pexpr
8730+
',pexpr))
8731+
lispy--eval-pcase-msg))
8732+
((looking-at "(cl-destructuring-bind")
8733+
(let* ((x-expr (read (lispy--string-dwim)))
8734+
(x-parts (eval (nth 2 x-expr))))
8735+
(cl-mapc
8736+
#'set (nth 1 x-expr) x-parts)
8737+
(cons 'list (nth 1 x-expr))))
8738+
((and (looking-at "(\\(?:cl-\\)?\\(?:defun\\|defmacro\\)")
8739+
(save-excursion
8740+
(lispy-flow 1)
8741+
(eq (point) origin)))
8742+
(let* ((fn-name (save-excursion
8743+
(forward-char)
8744+
(forward-sexp 2)
8745+
(lispy--preceding-sexp)))
8746+
(int-form
8747+
(and (fboundp fn-name)
8748+
(interactive-form fn-name)))
8749+
(int-form (when (eq (car int-form) 'interactive)
8750+
(cond ((listp (cadr int-form))
8751+
(cadr int-form))
8752+
((equal (cadr int-form) "p")
8753+
''(1))))))
8754+
(if int-form
8755+
`(lispy-destructuring-setq ,tsexp
8756+
,int-form)
8757+
`(progn
8758+
,@(mapcar
8759+
(lambda (x)
8760+
(list 'setq x nil))
8761+
(delq '&key (delq '&optional (delq '&rest tsexp))))))))
8762+
(t tsexp))))))
87588763

87598764
(defun lispy--find-unmatched-delimiters (beg end)
87608765
"Return the positions of unmatched delimiters between BEG and END.

0 commit comments

Comments
 (0)