changelog shortlog tags changeset files revisions annotate raw

pair-mode.el

changeset 66: 5b737eefe5ea
author: kim.vanwyk
date: Wed Nov 10 15:19:03 2010 +0200 (18 months ago)
permissions: -rw-r--r--
description: Adding CSharp Mode and Google Weather
1;;; pair-mode.el --- insertion of paired characters
2
3;; Copyright (C) 2004 Dave Love
4
5;; Author: Dave Love <fx@gnu.org>
6;; Keywords: convenience
7;; $Revision: 1.3 $
8;; URL: http://www.loveshack.ukfsn.org/emacs
9
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)
13;; any later version.
14
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.
19
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.
24
25;;; Commentary:
26
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
31;; parentheses.
32
33;;; Code:
34
35(require 'skeleton)
36
37(defgroup pair-mode ()
38 "Insertion of paired characters"
39 :group 'convenience
40 :group 'editing)
41
42(defvar pair-mode-map (make-sparse-keymap))
43
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))
48 (car 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)))
60 :group 'pair-mode)
61
62(define-minor-mode pair-mode
63 "Toggle Pair mode.
64See `pair-mode-chars' for the characters concerned and
65`skeleton-pair-insert-maybe' for the behaviour when you type one
66of them."
67 :group 'pair-mode
68 (setq skeleton-pair pair-mode))
69
70(define-minor-mode global-pair-mode
71 "Toggle Pair mode.
72See `pair-mode-chars' for the characters concerned and
73`skeleton-pair-insert-maybe' for the behaviour when you type one
74of them."
75 nil nil pair-mode-map
76 :group 'pair-mode
77 :global t
78 (setq-default skeleton-pair global-pair-mode))
79
80(provide 'pair-mode)
81;;; pair-mode.el ends here