简体   繁体   中英

Paredit ignore comments when closing parens

Often I run into situations like the following while using paredit , with the point at the | in the following snippet where I want to close the dangling paren, eg.

(let ((foo 1)| ; blag
      )
  nil)

becomes

(let ((foo 1)) ; blag
  nil)

after type ) aka paredit-close-parenthesis at the point.

If the comment wasn't on the line, paredit would close the paren and remove the space. Does anyone have a nice way to enable this feature?

Looking at the code, paredit appears to catch errors where I could add handlers, so I'm wondering if there is a simple solution out there.

I guess overriding it seems to work so far.

(defun my-paredit-close-round (&optional arg)
  (interactive "P")
  (if arg (paredit-close-round)
    (let ((beg (point)) ;keep comment on same line
          (cmt (paredit-find-comment-on-line)))
      (paredit-move-past-close ?\))
      (and cmt (save-excursion
                 (unless (eq (line-number-at-pos) (line-number-at-pos beg))
                   (goto-char beg))
                 (insert (car cmt)))))))
(advice-add 'paredit-close-round :override #'my-paredit-close-round)

However paredit-backward-barf-sexp still gets stuck at comments and would need to be overriden as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM