;;; elec-pair.el --- Automatic parenthesis pairing -*- lexical-binding:t -*-
-;; Copyright (C) 2013-2014 Free Software Foundation, Inc.
+;; Copyright (C) 2013-2016 Free Software Foundation, Inc.
;; Author: João Távora <joaotavora@gmail.com>
when to fallback to `parse-partial-sexp'."
(let* ((pos (or pos (point)))
(where (or where '(string comment)))
- (quick-ppss (syntax-ppss))
- (quick-ppss-at-pos (syntax-ppss pos))
- (in-string (and (nth 3 quick-ppss-at-pos) (memq 'string where)))
- (in-comment (and (nth 4 quick-ppss-at-pos) (memq 'comment where)))
+ (quick-ppss (syntax-ppss pos))
+ (in-string (and (nth 3 quick-ppss) (memq 'string where)))
+ (in-comment (and (nth 4 quick-ppss) (memq 'comment where)))
(s-or-c-start (cond (in-string
(1+ (nth 8 quick-ppss)))
(in-comment
;; HACK! cc-mode apparently has some `syntax-ppss' bugs
(if (memq major-mode '(c-mode c++ mode))
(parse-partial-sexp (point-min) pos)
- quick-ppss-at-pos))))
+ quick-ppss))))
;; Balancing means controlling pairing and skipping of parentheses
;; so that, if possible, the buffer ends up at least as balanced as
(when (and (not (and unconditional
(eq syntax ?\")))
(setq skip-whitespace-info
- (if (functionp electric-pair-skip-whitespace)
+ (if (and (not (eq electric-pair-skip-whitespace 'chomp))
+ (functionp electric-pair-skip-whitespace))
(funcall electric-pair-skip-whitespace)
electric-pair-skip-whitespace)))
(electric-pair--skip-whitespace))
(not (funcall electric-pair-inhibit-predicate
last-command-event))))
(save-excursion (electric-pair--insert pair)))))
- (t
+ (_
(when (and (if (functionp electric-pair-open-newline-between-pairs)
(funcall electric-pair-open-newline-between-pairs)
electric-pair-open-newline-between-pairs)
Electric Pair mode is a global minor mode. When enabled, typing
an open parenthesis automatically inserts the corresponding
-closing parenthesis. (Likewise for brackets, etc.)."
+closing parenthesis. (Likewise for brackets, etc.). To toggle
+the mode in a single buffer, use `electric-pair-local-mode'."
:global t :group 'electricity
(if electric-pair-mode
(progn
(remove-hook 'self-insert-uses-region-functions
#'electric-pair-will-use-region)))
+;;;###autoload
+(define-minor-mode electric-pair-local-mode
+ "Toggle `electric-pair-mode' only in this buffer."
+ :variable (buffer-local-value 'electric-pair-mode (current-buffer))
+ (cond
+ ((eq electric-pair-mode (default-value 'electric-pair-mode))
+ (kill-local-variable 'electric-pair-mode))
+ ((not (default-value 'electric-pair-mode))
+ ;; Locally enabled, but globally disabled.
+ (electric-pair-mode 1) ; Setup the hooks.
+ (setq-default electric-pair-mode nil) ; But keep it globally disabled.
+ )))
+
(provide 'elec-pair)
;;; elec-pair.el ends here