1;;; pair-mode.el --- insertion of paired characters
3;; Copyright (C) 2004 Dave Love
5;; Author: Dave Love <fx@gnu.org>
6;; Keywords: convenience
8;; URL: http://www.loveshack.ukfsn.org/emacs
10;; This file is free software; you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation; either version 2, or (at your option)
15;; This file is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs; see the file COPYING. If not, write to
22;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23;; Boston, MA 02111-1307, USA.
27;; A trivial (local) minor mode, and a global version, which binds
28;; suitable characters to `skeleton-pair-insert-maybe'. Thus typing
29;; `(' will normally insert `()' and put point between them.
30;; Otherwise, when the region is active, it will be wrapped in the
38 "Insertion of paired characters"
42(defvar pair-mode-map (make-sparse-keymap))
44(defcustom pair-mode-chars
45 (if (boundp 'skeleton-pair-default-alist) ; Emacs 22
46 (delete nil (mapcar (lambda (elt)
47 (if (= 3 (length elt))
49 skeleton-pair-default-alist))
50 '(?\( ?\[ ?\{ ?\< ?`)) ; Emacs 21.3's hardwired list
51 "List of characters which self-insert pairs in Pair mode."
52 :type '(repeat character)
53 :set (lambda (symbol value)
54 (if (boundp 'pair-mode-chars) ; empty existing map
55 (dolist (c pair-mode-chars)
56 (define-key pair-mode-map (vector c) nil)))
57 (set-default symbol value)
58 (dolist (c value) ; repopulate map from new list
59 (define-key pair-mode-map (vector c) 'skeleton-pair-insert-maybe)))
62(define-minor-mode pair-mode
64See `pair-mode-chars' for the characters concerned and
65`skeleton-pair-insert-maybe' for the behaviour when you type one
68 (setq skeleton-pair pair-mode))
70(define-minor-mode global-pair-mode
72See `pair-mode-chars' for the characters concerned and
73`skeleton-pair-insert-maybe' for the behaviour when you type one
78 (setq-default skeleton-pair global-pair-mode))
81;;; pair-mode.el ends here