From: Alan M. <ac...@mu...> - 2002-06-23 14:35:11
|
On Sun, 23 Jun 2002, Klaus Leopold wrote: [ .... ] >Maybe you could answer me one more question? :) >I wrote some very simple lisp functions for autoparns. Everytime I open a >paren (, [, or { it's automatically closed with ), ], or ]. It's works fine >with some modes (text, tex, lisp, etc.) but it doesn't work for cc-mode. I >guess it's because cc-mode does some parsing (or whatever) on parens. Is it >somehow possible to use my lisp functions with cc-mode or maybe there is some >autoparen stuff implemented in cc-mode? (btw: I'm using global-set-key for >(,[ etc...) What's happening is that cc-mode creates its own local bindings for these characters. in cc-cmds.el (part of cc-mode), there are several lines like: (define-key c-mode-base-map "(" 'c-electric-paren) Whilst in a cc-mode buffer (i.e. C mode, C++ mode, ....), any entries in c-mode-base-map take priority over global bindings, so your functions will be getting shadowed out. You can verify this (with C-h k, of course :-). Incidentally, I believe that [ is not rebound by cc-mode. What c-electric-paren does is to add space, clean-up newlines, re-indent and such like, depending on the settings of various option variables. It probably wouldn't do much damage if you overrid (past-participle of override :-) these with your own functions. Alternatively you might want to look up the "advice" feature in emacs lisp. With advice, you tack on an extra bit of functionality to an existing function, to be executed before and/or after the existing function. So you could write something like: (defadvice 'c-electric-paren (after KLs-advice) "Add a closing paren whenever an opening paren is typed." (functionality comes here)) Be warned, however, that this is a LOT of work, and you will be spending many hours reading the elisp manual before it eventually works properly. Have fun! >Regards, >Klaus -- Alan Mackenzie (Munich, Germany) ac...@mu... |