diff options
| author | Stefan Monnier | 2010-11-17 21:43:42 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2010-11-17 21:43:42 -0500 |
| commit | c51bb5d2c2f0e090e6c71309e393ace47d3061f4 (patch) | |
| tree | 3cdf87f464b150c6df5773c5cafbdfee9109a782 | |
| parent | 239661c0859d174f170a6c18977c534481d4a040 (diff) | |
| download | emacs-c51bb5d2c2f0e090e6c71309e393ace47d3061f4.tar.gz emacs-c51bb5d2c2f0e090e6c71309e393ace47d3061f4.zip | |
* 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.
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/electric.el | 25 |
2 files changed, 26 insertions, 6 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e63d12ffb3a..99dff70118a 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2010-11-18 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * electric.el (electric-pair-pairs): New var. | ||
| 4 | (electric-pair-post-self-insert-function): Use it. | ||
| 5 | (electric-layout-post-self-insert-function): Don't insert a before | ||
| 6 | newline unless it's actually needed. | ||
| 7 | |||
| 1 | 2010-11-17 Stefan Monnier <monnier@iro.umontreal.ca> | 8 | 2010-11-17 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 9 | ||
| 3 | * progmodes/python.el (run-python): Explain why we remove the current | 10 | * progmodes/python.el (run-python): Explain why we remove the current |
diff --git a/lisp/electric.el b/lisp/electric.el index b34d327c4f2..0ea8cb30010 100644 --- a/lisp/electric.el +++ b/lisp/electric.el | |||
| @@ -261,6 +261,11 @@ Returns nil when we can't find this char." | |||
| 261 | 261 | ||
| 262 | ;; Electric pairing. | 262 | ;; Electric pairing. |
| 263 | 263 | ||
| 264 | (defcustom electric-pair-pairs | ||
| 265 | '((?\" . ?\")) | ||
| 266 | "Alist of pairs that should be used regardless of major mode." | ||
| 267 | :type '(repeat (cons character character))) | ||
| 268 | |||
| 264 | (defcustom electric-pair-skip-self t | 269 | (defcustom electric-pair-skip-self t |
| 265 | "If non-nil, skip char instead of inserting a second closing paren. | 270 | "If non-nil, skip char instead of inserting a second closing paren. |
| 266 | When inserting a closing paren character right before the same character, | 271 | When inserting a closing paren character right before the same character, |
| @@ -271,13 +276,18 @@ This can be convenient for people who find it easier to hit ) than C-f." | |||
| 271 | 276 | ||
| 272 | (defun electric-pair-post-self-insert-function () | 277 | (defun electric-pair-post-self-insert-function () |
| 273 | (let* ((syntax (and (eq (char-before) last-command-event) ; Sanity check. | 278 | (let* ((syntax (and (eq (char-before) last-command-event) ; Sanity check. |
| 274 | (char-syntax last-command-event))) | 279 | (let ((x (assq last-command-event electric-pair-pairs))) |
| 280 | (cond | ||
| 281 | (x (if (eq (car x) (cdr x)) ?\" ?\()) | ||
| 282 | ((rassq last-command-event electric-pair-pairs) ?\)) | ||
| 283 | (t (char-syntax last-command-event)))))) | ||
| 275 | ;; FIXME: when inserting the closer, we should maybe use | 284 | ;; FIXME: when inserting the closer, we should maybe use |
| 276 | ;; self-insert-command, although it may prove tricky running | 285 | ;; self-insert-command, although it may prove tricky running |
| 277 | ;; post-self-insert-hook recursively, and we wouldn't want to trigger | 286 | ;; post-self-insert-hook recursively, and we wouldn't want to trigger |
| 278 | ;; blink-matching-open. | 287 | ;; blink-matching-open. |
| 279 | (closer (if (eq syntax ?\() | 288 | (closer (if (eq syntax ?\() |
| 280 | (cdr (aref (syntax-table) last-command-event)) | 289 | (cdr (or (assq last-command-event electric-pair-pairs) |
| 290 | (aref (syntax-table) last-command-event))) | ||
| 281 | last-command-event))) | 291 | last-command-event))) |
| 282 | (cond | 292 | (cond |
| 283 | ;; Wrap a pair around the active region. | 293 | ;; Wrap a pair around the active region. |
| @@ -351,10 +361,13 @@ one of those symbols.") | |||
| 351 | ;; It happened to make electric-indent-mode work automatically with | 361 | ;; It happened to make electric-indent-mode work automatically with |
| 352 | ;; electric-layout-mode (at the cost of re-indenting lines | 362 | ;; electric-layout-mode (at the cost of re-indenting lines |
| 353 | ;; multiple times), but I'm not sure it's what we want. | 363 | ;; multiple times), but I'm not sure it's what we want. |
| 354 | (before (goto-char (1- pos)) (insert "\n")) | 364 | (before (goto-char (1- pos)) (skip-chars-backward " \t") |
| 355 | (after (insert "\n")) | 365 | (unless (bolp) (insert "\n"))) |
| 356 | (around (goto-char (1- pos)) (insert "\n") | 366 | (after (insert "\n")) ; FIXME: check eolp before inserting \n? |
| 357 | (forward-char 1) (insert "\n"))) | 367 | (around (save-excursion |
| 368 | (goto-char (1- pos)) (skip-chars-backward " \t") | ||
| 369 | (unless (bolp) (insert "\n"))) | ||
| 370 | (insert "\n"))) ; FIXME: check eolp before inserting \n? | ||
| 358 | (goto-char end))))) | 371 | (goto-char end))))) |
| 359 | 372 | ||
| 360 | ;;;###autoload | 373 | ;;;###autoload |