Skip to content

Commit

Permalink
surround-function improvement for lisp modes (#134)
Browse files Browse the repository at this point in the history
surround-function improvement for lisp modes
  • Loading branch information
Dickby authored and ninrod committed Jan 2, 2018
1 parent 6e1da76 commit 5a20c97
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
35 changes: 32 additions & 3 deletions evil-surround.el
Expand Up @@ -76,6 +76,34 @@ This only affects inserting pairs, not deleting or changing them."
(function :tag "Function"))))
(make-variable-buffer-local 'evil-surround-pairs-alist)

(defcustom evil-surround-lisp-modes '(
cider-repl-mode
clojure-mode
clojurec-mode
clojurescript-mode
clojurex-mode
common-lisp-mode
emacs-lisp-mode
eshell-mode
geiser-repl-mode
inf-clojure-mode
inferior-emacs-lisp-mode
inferior-lisp-mode
inferior-scheme-mode
lisp-interaction-mode
lisp-mode
monroe-mode
racket-mode
racket-repl-mode
scheme-interaction-mode
scheme-mode
slime-repl-mode
stumpwm-mode
)
"List of Lisp-related modes."
:type '(repeat symbol)
:group 'evil-surround)

(defcustom evil-surround-operator-alist
'((evil-change . change)
(evil-delete . delete))
Expand Down Expand Up @@ -105,8 +133,9 @@ Each item is of the form (OPERATOR . OPERATION)."
(defun evil-surround-function ()
"Read a functionname from the minibuffer and wrap selection in function call"
(let ((fname (evil-surround-read-from-minibuffer "" "")))
(cons (format "%s(" (or fname ""))
")")))
(cons (format (if (member major-mode evil-surround-lisp-modes)
"(%s " "%s(")
(or fname "")) ")")))

(defun evil-surround-read-tag ()
"Read a XML tag from the minibuffer."
Expand Down Expand Up @@ -157,7 +186,7 @@ See also `evil-surround-inner-overlay'."
(while (looking-at regexp) (forward-char))
(evil-set-range-beginning range (point))
(goto-char (evil-range-end range))
(while (looking-back regexp) (backward-char))
(while (looking-back regexp nil) (backward-char))
(evil-set-range-end range (point))))))

(defun evil-surround-inner-overlay (char)
Expand Down
13 changes: 12 additions & 1 deletion test/evil-surround-test.el
Expand Up @@ -55,10 +55,21 @@
:visual-end nil
"argument1 argument2"
(turn-on-evil-surround-mode)
(c-mode)
("ysiwffunction" [return])
"function(argument1) argument2"
("W.")
"function(argument1) function(argument2)"))
"function(argument1) function(argument2)")
(evil-test-buffer
:visual-start nil
:visual-end nil
"argument1 argument2"
(turn-on-evil-surround-mode)
(emacs-lisp-mode)
("ysiwffunction" [return])
"(function argument1) argument2"
("$.")
"(function argument1) (function argument2)"))
(ert-info ("even more examples from readme: tag surrounding with dot repeat")
(evil-test-buffer
:visual-start nil
Expand Down

0 comments on commit 5a20c97

Please sign in to comment.