Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Paredit Formatting

When using paredit in programming modes such as C, typing ( will insert a space before the paren when I'm trying to call a function, leaving me with:

foo ()

Is there a way to disable the insertion of the space without changing paredit's source?

like image 688
Nathaniel Flath Avatar asked May 27 '09 00:05

Nathaniel Flath


3 Answers

Well, the way paredit appears to work is that it checks the syntax tables to see if you're inserting a pair right after a word/symbol/etc., in which case it forces a space to be inserted. You need to override that functionality - which can be done a number of different ways: advice, redefine the function determining space, changing the syntax table, etc.

I'd try the straight forward:

(defun paredit-space-for-delimiter-p (endp delimiter)
  (and (not (if endp (eobp) (bobp)))
       (memq (char-syntax (if endp (char-after) (char-before)))
             (list ?\"  ;; REMOVED ?w ?_
                   (let ((matching (matching-paren delimiter)))
                     (and matching (char-syntax matching)))))))

This will obviously apply to all places where you use paredit. If you want something more mode specific, you can add some conditions to that and statement (e.g. (and ... (memq major-mode '(c-mode lisp-mode)))).

So... I guess I did change the "source", but you can do the same thing with a piece of defadvice ... it's all elisp, so the difference is minimal. There doesn't appear to be a setting to control this type of behavior.

like image 198
Trey Jackson Avatar answered Nov 09 '22 13:11

Trey Jackson


See paredit-space-for-delimiter-predicates

like image 38
5fec Avatar answered Nov 09 '22 14:11

5fec


Well, Paredit is ideal for editing languages built of S-expressions. If you just like how it automatically inserts the closing paren, use feature skeleton-pair.

(setq skeleton-pair t)
(global-set-key "(" 'skeleton-pair-insert-maybe)
like image 38
viam0Zah Avatar answered Nov 09 '22 13:11

viam0Zah