Prevent paredit from inserting a space when inserting parentheses - and other issues

StackOverflow https://stackoverflow.com/questions/11135315

  •  16-06-2021
  •  | 
  •  

質問

I love paredit. But there are a couple of things I hate, and have not yet come around to fixing them:

  • Opening a parenthesis inserts a space before the parenthesis. I understand this is probably the preferred style of the whole internet, but it is not mine. How can avoid this?
  • When inside a quoted area (''), I am not able to back-delete. Also, typing a double quote (") will insert a backslash (obviously to escape the double quote - only that this is not needed, at least in python. So I do not want the backslash. How to configure this?
  • Actually, paredit tries (and fails) to be very wise relating backspace. My backspace should always delete the previous character, no matter whether I am in an unfinished quoting area (paredit just refuses to do anything if the quotes do not match. Try to delete here: "helloo). The only situation where a delete makes sense to be treated specially is when the point is just before an opening parenthesis.
役に立ちましたか?

解決

This is not an answer, but too long for a comment...

Paredit is intended for languages where not having a space before a ( would be horrible, and ones that do not have python's "quote-cleverness". You could probably hack it for these issues, but the syntax of python is sufficiently different that making it work there would be a non-trivial project.

As for your last point, that sounds like you don't want paredit at all, since it's very intentionally trying to keep your parens & quotations balanced, so maybe it's not the right tool for you. IOW, you might prefer auto pairs or electric pair or a bunch of other similar tools.

他のヒント

You can customize paredit's insertion of space around delimiters via the paredit-space-for-delimiter-predicates variable -- see the docstring for details. There are some examples of its use kicking around the internet, but I don't remember where they are.

Paredit's handling of strings is limited to the string notation common to many Lisps, and changing it is not trivial, so if you want to use it with exotic syntax such as Python's various one-or-three-delimiter single-or-double-quote formats, you'll need to mess around deep inside paredit.

Example code bellow works for scheme:

(defun paredit-space-for-delimiter-predicates-scheme (endp delimiter)
  "Do not automatically insert a space when a '#' precedes parentheses."
  (or endp
      (cond ((eq (char-syntax delimiter) ?\()
             (not (looking-back "#\\|#hash")))
            (else t))))

(defun scheme-mode-paredit-hook ()
  (enable-paredit-mode)
  (add-to-list (make-local-variable 'paredit-space-for-delimiter-predicates)
               'paredit-space-for-delimiter-predicates-scheme))

(add-hook 'scheme-mode-hook 'scheme-mode-paredit-hook)

To force a delete of a character you have to select it and C-w it. To force the insertion of one character only, say an opening quote, you have to use C-q (.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top