Skip to content

puni-wrap-pair function #47

@tpeacock19

Description

@tpeacock19

I currently use the below configuration to emulate insert-pair from lisp.el with puni-wrap-next-sexps. I figured it may be useful to add to puni itself. I'm happy to open a PR, but wanted to get your opinion first. This allows for the delimiter to be defined after calling the function, so there would be less need for puni-wrap-{round,square,curly,angle}.

Note: I currently use insert-pair-alist, but perhaps adding an alist specific to puni would be better.

(setf insert-pair-alist '((?\( ?\)) (?\[ ?\]) (?\{ ?\}) (?\< ?\>)
                               (?\" ?\") (?\' ?\') (?\` ?\') (?r "(" ")")
                               (?R "( " " )") (?c "{" "}") (?C "{ " " }")
                               (?b "[" "]") (?B "[ " " ]") (?o "<" ">")
                               (?O "< " " >") (?s "\"" "\"") (?t "\'" "\'")
                               (?v "`" "`")))

(defun +puni-wrap-pair (&optional n open close)
  (interactive "P")
  (let ((pair (or (assq last-command-event insert-pair-alist)
                  (assq (event-basic-type last-command-event)
                        insert-pair-alist))))
    (if pair
        (if (nth 2 pair)
            (setq open (nth 1 pair) close (nth 2 pair))
          (setq open (nth 0 pair) close (nth 1 pair)))))
  (puni-wrap-next-sexps
   (puni--parse-interactive-argument-for-wrap n)
   open close))

(defvar-keymap insert-pair-map
    :prefix 'insert-pair-map
    "<t>" #'+puni-wrap-pair)

(keymap-global-set "C-S-w" insert-pair-map)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions