emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/evil-surround 1d6b1bac4e 027/175: Add wrap in function cal


From: ELPA Syncer
Subject: [nongnu] elpa/evil-surround 1d6b1bac4e 027/175: Add wrap in function call
Date: Mon, 9 Oct 2023 13:01:01 -0400 (EDT)

branch: elpa/evil-surround
commit 1d6b1bac4e63cee94599ccf91fddec4034465f0d
Author: IsoLinearCHiP <isolin.chip@gmail.com>
Commit: Tim Harper <timcharper@gmail.com>

    Add wrap in function call
    
    - new modifier "f" after cs , ys or v[sS] . Prompts for function name and 
then wraps it as fname(selection)
    - docs
    
    TODO?
    
    - use "F" to make (e)lisp style function calls?
    - do mode detection?
---
 README.md   | 12 ++++++++++++
 surround.el |  9 ++++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index fd9a68deab..a01aca40cb 100644
--- a/README.md
+++ b/README.md
@@ -114,3 +114,15 @@ visual mode) followed by `S<p class="important">`.
     <p class="important">
       <em>Hello</em> world!
     </p>
+
+Suppose you want to call a function on your visual selection or a text
+object. You can simply press `f` instead of the aforementioned keys
+and are then prompted for a functionname in the minibuffer, like with
+the tags. So with:
+
+       "Hello world!"
+
+... after selecting the string, then pressing `sf`, entering `print`
+and pressing return you would get
+
+    print("Hello world!")
diff --git a/surround.el b/surround.el
index 746462b54c..72d726df7f 100644
--- a/surround.el
+++ b/surround.el
@@ -54,7 +54,8 @@
     (?B . ("{" . "}"))
     (?> . ("<" . ">"))
     (?t . surround-read-tag)
-    (?< . surround-read-tag))
+    (?< . surround-read-tag)
+    (?f . surround-function))
   "Association list of surround items.
 Each item is of the form (TRIGGER . (LEFT . RIGHT)), all strings.
 Alternatively, a function can be put in place of (LEFT . RIGHT).
@@ -70,6 +71,12 @@ This only affects inserting pairs, not deleting or changing 
them."
     map)
   "Keymap used by `surround-read-tag'.")
 
+(defun surround-function ()
+  "Read a functionname from the minibuffer and wrap selection in function call"
+  (let ((fname (read-from-minibuffer "" "" )))
+    (cons (format "%s(" (or fname ""))
+          ")")))
+
 (defun surround-read-tag ()
   "Read a XML tag from the minibuffer."
   (let* ((input (read-from-minibuffer "<" "" surround-read-tag-map))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]