[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] /srv/bzr/emacs/trunk r102425: * lisp/electric.el (electric
From: |
Stefan Monnier |
Subject: |
[Emacs-diffs] /srv/bzr/emacs/trunk r102425: * lisp/electric.el (electric-pair-pairs): New var. |
Date: |
Wed, 17 Nov 2010 21:43:42 -0500 |
User-agent: |
Bazaar (2.0.3) |
------------------------------------------------------------
revno: 102425
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Wed 2010-11-17 21:43:42 -0500
message:
* lisp/electric.el (electric-pair-pairs): New var.
(electric-pair-post-self-insert-function): Use it.
(electric-layout-post-self-insert-function): Don't insert a before
newline unless it's actually needed.
modified:
lisp/ChangeLog
lisp/electric.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog 2010-11-17 15:07:48 +0000
+++ b/lisp/ChangeLog 2010-11-18 02:43:42 +0000
@@ -1,3 +1,10 @@
+2010-11-18 Stefan Monnier <address@hidden>
+
+ * electric.el (electric-pair-pairs): New var.
+ (electric-pair-post-self-insert-function): Use it.
+ (electric-layout-post-self-insert-function): Don't insert a before
+ newline unless it's actually needed.
+
2010-11-17 Stefan Monnier <address@hidden>
* progmodes/python.el (run-python): Explain why we remove the current
=== modified file 'lisp/electric.el'
--- a/lisp/electric.el 2010-11-16 21:14:46 +0000
+++ b/lisp/electric.el 2010-11-18 02:43:42 +0000
@@ -261,6 +261,11 @@
;; Electric pairing.
+(defcustom electric-pair-pairs
+ '((?\" . ?\"))
+ "Alist of pairs that should be used regardless of major mode."
+ :type '(repeat (cons character character)))
+
(defcustom electric-pair-skip-self t
"If non-nil, skip char instead of inserting a second closing paren.
When inserting a closing paren character right before the same character,
@@ -271,13 +276,18 @@
(defun electric-pair-post-self-insert-function ()
(let* ((syntax (and (eq (char-before) last-command-event) ; Sanity check.
- (char-syntax last-command-event)))
+ (let ((x (assq last-command-event electric-pair-pairs)))
+ (cond
+ (x (if (eq (car x) (cdr x)) ?\" ?\())
+ ((rassq last-command-event electric-pair-pairs) ?\))
+ (t (char-syntax last-command-event))))))
;; FIXME: when inserting the closer, we should maybe use
;; self-insert-command, although it may prove tricky running
;; post-self-insert-hook recursively, and we wouldn't want to trigger
;; blink-matching-open.
(closer (if (eq syntax ?\()
- (cdr (aref (syntax-table) last-command-event))
+ (cdr (or (assq last-command-event electric-pair-pairs)
+ (aref (syntax-table) last-command-event)))
last-command-event)))
(cond
;; Wrap a pair around the active region.
@@ -351,10 +361,13 @@
;; It happened to make electric-indent-mode work automatically with
;; electric-layout-mode (at the cost of re-indenting lines
;; multiple times), but I'm not sure it's what we want.
- (before (goto-char (1- pos)) (insert "\n"))
- (after (insert "\n"))
- (around (goto-char (1- pos)) (insert "\n")
- (forward-char 1) (insert "\n")))
+ (before (goto-char (1- pos)) (skip-chars-backward " \t")
+ (unless (bolp) (insert "\n")))
+ (after (insert "\n")) ; FIXME: check eolp before inserting \n?
+ (around (save-excursion
+ (goto-char (1- pos)) (skip-chars-backward " \t")
+ (unless (bolp) (insert "\n")))
+ (insert "\n"))) ; FIXME: check eolp before inserting \n?
(goto-char end)))))
;;;###autoload
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] /srv/bzr/emacs/trunk r102425: * lisp/electric.el (electric-pair-pairs): New var.,
Stefan Monnier <=