branch: elpa/paredit
commit f27c480fdb1f525177036f93cab454a40197df4e
Author: Taylor R Campbell <[email protected]>
Commit: Taylor R Campbell <[email protected]>
Implement `paredit-override-check-parens-function'.
Ignore-this: 8fa60f5bd8c398aa31f91b26c4affb12
Set to `paredit-override-check-parens-interactively' if you want to
be prompted whether to enable Paredit Mode rather than to have `M-x
paredit-mode RET' simply barf if there are unbalanced parentheses.
(Someone suggested this to me months ago, but I have forgotten who.)
Assume we have `check-parens'. No more GNU Emacs 20.
darcs-hash:20110320185342-00fcc-30abf28738cf76cca1d16f02b2f26f3f46525c44
---
paredit.el | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)
diff --git a/paredit.el b/paredit.el
index 726fd09..4c4f9e2 100644
--- a/paredit.el
+++ b/paredit.el
@@ -210,6 +210,10 @@ Signal an error if no clause matches."
(defvar paredit-mode-map (make-sparse-keymap)
"Keymap for the paredit minor mode.")
+(defvar paredit-override-check-parens-function
+ (lambda (condition) condition nil)
+ "Function to tell whether unbalanced text should inhibit Paredit Mode.")
+
;;;###autoload
(define-minor-mode paredit-mode
"Minor mode for pseudo-structurally editing Lisp code.
@@ -220,21 +224,18 @@ Paredit behaves badly if parentheses are imbalanced, so
exercise
fixing imbalanced parentheses instead.
\\<paredit-mode-map>"
:lighter " Paredit"
- ;; If we're enabling paredit-mode, the prefix to this code that
- ;; DEFINE-MINOR-MODE inserts will have already set PAREDIT-MODE to
- ;; true. If this is the case, then first check the parentheses, and
- ;; if there are any imbalanced ones we must inhibit the activation of
- ;; paredit mode. We skip the check, though, if the user supplied a
- ;; prefix argument interactively.
+ ;; Setting `paredit-mode' to false here aborts enabling Paredit Mode.
(if (and paredit-mode
(not current-prefix-arg))
- (if (not (fboundp 'check-parens))
- (paredit-warn "`check-parens' is not defined; %s"
- "be careful of malformed S-expressions.")
- (condition-case condition
- (check-parens)
- (error (setq paredit-mode nil)
- (signal (car condition) (cdr condition)))))))
+ (condition-case condition
+ (check-parens)
+ (error
+ (if (not (funcall paredit-override-check-parens-function condition))
+ (progn (setq paredit-mode nil)
+ (signal (car condition) (cdr condition))))))))
+
+(defun paredit-override-check-parens-interactively (condition)
+ (y-or-n-p (format "Enable Paredit Mode despite condition %S? " condition)))
(defun enable-paredit-mode ()
"Turn on pseudo-structural editing of Lisp code."