Is it possible to automatically fill in parentheses or quotes in emacs?

I used Xcode and Netbeans, and I noticed that they have the function of automatically filling quotes or parentheses (and I assume other IDEs do this too). I donโ€™t know what this function is called, but is there any way to do this in Emacs?

For example, when I print

printf(" 

I would like it to automatically enter

 printf("") 

placing the cursor between quotation marks.

Thanks.

+6
emacs ide code-completion
source share
6 answers

The main option would be AutoPairs . The same effect, but a bit more complex, can also be achieved with YASnippet .

+7
source share

If you type M- (which will insert both (and a) and leave a point between them, if you then type M-), this will move the point to close). I use it all the time.

There is also a mode called "paredit" (available from http://mumble.net/~campbell/emacs/paredit.el ) that does similar things for quotes, as well as probably other things.

+3
source share

Paredit-mode inserts the corresponding closure elements by default, so when typing you will see something like printf() then printf("") , and the cursor will be placed inside quotation marks.

+3
source share

I use the code http://cmarcelo.wordpress.com/2008/04/26/a-little-emacs-experiment/ to make "electric pairs". As I describe my blog , other modes have issues with Python triple quotes. (Python Feature)

+2
source share

My 5 cents is here.

 (setq skeleton-pair t) (defvar skeletons-alist '((?\( . ?\)) (?\" . ?\") (?[ . ?]) (?{ . ?}) (?$ . ?$))) (global-set-key (kbd "(") 'skeleton-pair-insert-maybe) (global-set-key (kbd "[") 'skeleton-pair-insert-maybe) (global-set-key (kbd "\"") 'skeleton-pair-insert-maybe) (global-set-key (kbd "\'") 'skeleton-pair-insert-maybe) 

The following tip will allow backspace to remove pairs: a (|) b โ†’ ab

 (defadvice delete-backward-char (before delete-empty-pair activate) (if (eq (cdr (assq (char-before) skeletons-alist)) (char-after)) (and (char-after) (delete-char 1)))) 

The following tip will make backward-kill-word (for me M-backspace ) remove the corresponding pair, even if it is separated by other text; very comfortably.

 (defadvice backward-kill-word (around delete-pair activate) (if (eq (char-syntax (char-before)) ?\() (progn (backward-char 1) (save-excursion (forward-sexp 1) (delete-char -1)) (forward-char 1) (append-next-kill) (kill-backward-chars 1)) ad-do-it)) 

Now I'm trying to move to work.

+2
source share

autopair secondary mode does exactly what you ask for.

0
source share

All Articles