views:

421

answers:

2

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?

+5  A: 

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.

Trey Jackson
+1  A: 

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)
Török Gábor
Good point. I forgot about skeleton-pair. I'm so used to Paredit for mucking around with emacs lisp. I need to set that up for my non-lispy languages..
Ton as in Anton
Actually, paredit mode is extremely useful outside s-expression-based languages as well for enforcing validity of matched delimiters; it's not just about insertion.
technomancy