7

I am using paredit. Sometimes I accidentely wrap something in curly braces or I have a situation where I want unwrap something for some other reason? What ist the right command to use when undo does not work?

I am looking for a command which turns something like this:

(hello) world

into this:

hello world

while the cursor is at the front.

Witek
  • 335
  • 1
  • 11

2 Answers2

7

I think paredit-splice, M-s, will do that. Point may need to be inside the expression you want to 'unwrap'.

Tyler
  • 21,719
  • 1
  • 52
  • 92
0

I have the following function bound to M-D. Hitting M-D RET makes a pair of brackets disappear.

(defun yf/replace-or-delete-pair (open)
  "Replace pair at point by OPEN and its corresponding closing character.
The closing character is lookup in the syntax table or asked to
the user if not found."
  (interactive
   (list
    (read-char
     (format "Replacing pair %c%c by (or hit RET to delete pair):"
             (char-after)
             (save-excursion
               (forward-sexp 1)
               (char-before))))))
  (if (memq open '(?\n ?\r))
      (delete-pair)
    (let ((close (cdr (aref (syntax-table) open))))
      (when (not close)
        (setq close
              (read-char
               (format "Don't know how to close character %s (#%d) ; please provide a closing character: "
                       (single-key-description open 'no-angles)
                       open))))
      (yf/replace-pair open close))))

(defun yf/replace-pair (open close)
  "Replace pair at point by respective chars OPEN and CLOSE.
If CLOSE is nil, lookup the syntax table. If that fails, signal
an error."
  (let ((close (or close
                   (cdr-safe (aref (syntax-table) open))
                   (error "No matching closing char for character %s (#%d)"
                          (single-key-description open t)
                          open)))
        (parens-require-spaces))
    (insert-pair 1 open close))
  (delete-pair)
  (backward-char 1))
YoungFrog
  • 3,496
  • 15
  • 27