summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTaylor R Campbell <campbell@mumble.net>2013-04-07 16:58:40 +0000
committerTaylor R Campbell <campbell@mumble.net>2013-04-07 17:06:58 +0000
commit9e5688e77e0e067be8d3526cb5a744afd13602e8 (patch)
tree55ec85dee5bb55a37d7cff615aaf2b5c160a6473
parent6cb5747b0973c36e0e21da4851f35a66c106a327 (diff)
Add some miscellaneous S-expression parsing utilities.
`paredit-enclosing-list-start' and `paredit-enclosing-list-end' give the start and end points of the enclosing list. `paredit-prefix-numeric-value' is like `prefix-numeric-value', but truncates numeric values to the number of S-expressions that can actually be moved over before hitting an enclosing delimiter.
-rw-r--r--paredit.el56
1 files changed, 47 insertions, 9 deletions
diff --git a/paredit.el b/paredit.el
index 3e7cc5f..176494d 100644
--- a/paredit.el
+++ b/paredit.el
@@ -1986,15 +1986,6 @@ By default OPEN and CLOSE are round delimiters."
(backward-char)))
(save-excursion (backward-up-list) (indent-sexp)))
-(defun paredit-count-sexps-forward ()
- (save-excursion
- (let ((n 0) (p nil)) ;hurk
- (paredit-ignore-sexp-errors
- (while (setq p (scan-sexps (point) +1))
- (goto-char p)
- (setq n (+ n 1))))
- n)))
-
(defun paredit-yank-pop (&optional argument)
"Replace just-yanked text with the next item in the kill ring.
If this command follows a `yank', just run `yank-pop'.
@@ -2605,6 +2596,16 @@ This assumes that `paredit-in-string-p' has already returned true, i.e.
(defun paredit-enclosing-string-end ()
(+ 1 (cdr (paredit-string-start+end-points))))
+(defun paredit-enclosing-list-start ()
+ (save-excursion
+ (backward-up-list)
+ (point)))
+
+(defun paredit-enclosing-list-end ()
+ (save-excursion
+ (up-list)
+ (point)))
+
(defun paredit-in-comment-p (&optional state)
"True if parse state STATE is within a comment.
If no parse state is supplied, compute one from the beginning of the
@@ -2613,6 +2614,43 @@ If no parse state is supplied, compute one from the beginning of the
;; else an integer (the current comment nesting)
(and (nth 4 (or state (paredit-current-parse-state)))
t))
+
+(defun paredit-prefix-numeric-value (argument)
+ ;++ Kludgerific.
+ (cond ((integerp argument) argument)
+ ((eq argument '-) -1)
+ ((consp argument)
+ (cond ((equal argument '(4)) (paredit-count-sexps-forward)) ;C-u
+ ((equal argument '(16)) (paredit-count-sexps-backward)) ;C-u C-u
+ (t (error "Invalid prefix argument: %S" argument))))
+ ((paredit-region-active-p)
+ (save-excursion
+ (save-restriction
+ (narrow-to-region (region-beginning) (region-end))
+ (cond ((= (point) (point-min)) (paredit-count-sexps-forward))
+ ((= (point) (point-max)) (paredit-count-sexps-backward))
+ (t
+ (error "Point %S is not start or end of region: %S..%S"
+ (point) (region-beginning) (region-end)))))))
+ (t 1)))
+
+(defun paredit-count-sexps-forward ()
+ (save-excursion
+ (let ((n 0) (p nil)) ;hurk
+ (paredit-ignore-sexp-errors
+ (while (setq p (scan-sexps (point) +1))
+ (goto-char p)
+ (setq n (+ n 1))))
+ n)))
+
+(defun paredit-count-sexps-backward ()
+ (save-excursion
+ (let ((n 0) (p nil)) ;hurk
+ (paredit-ignore-sexp-errors
+ (while (setq p (scan-sexps (point) -1))
+ (goto-char p)
+ (setq n (+ n 1))))
+ n)))
(defun paredit-point-at-sexp-boundary (n)
(cond ((< n 0) (paredit-point-at-sexp-start))