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

自闭症网瘾萝莉.ら 提交于 2020-08-26 04:21:40

问题


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.

回答1:


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.




回答2:


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.




回答3:


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)



回答4:


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 (.



来源:https://stackoverflow.com/questions/11135315/prevent-paredit-from-inserting-a-space-when-inserting-parentheses-and-other-is

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!