diff options
author | Taylor R Campbell <campbell@mumble.net> | 2011-03-20 18:53:42 +0000 |
---|---|---|
committer | Taylor R Campbell <campbell@mumble.net> | 2011-03-20 18:53:42 +0000 |
commit | f27c480fdb1f525177036f93cab454a40197df4e (patch) | |
tree | e8477261969eb20849d467ed877145569725c4a1 /paredit.el | |
parent | 4d3ad1edcbd29358ac343a0e5fbe137e4fdf90fd (diff) |
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
Diffstat (limited to 'paredit.el')
-rw-r--r-- | paredit.el | 27 |
1 files changed, 14 insertions, 13 deletions
@@ -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." |