diff options
| author | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2010-11-08 06:07:12 +0100 | 
|---|---|---|
| committer | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2010-11-08 06:07:12 +0100 | 
| commit | a3743f25313498e96563e3622422bc62d9b80178 (patch) | |
| tree | fac9f3732489f735a4c61d18fef6ff17e3c1990c | |
| parent | 06ade45ac52d5597dc04655f4668b02f9b3ebdf2 (diff) | |
| download | geiser-a3743f25313498e96563e3622422bc62d9b80178.tar.gz geiser-a3743f25313498e96563e3622422bc62d9b80178.tar.bz2 | |
squarify again, now with numeric prefix
| -rw-r--r-- | doc/parens.texi | 4 | ||||
| -rw-r--r-- | elisp/geiser-mode.el | 35 | 
2 files changed, 26 insertions, 13 deletions
| diff --git a/doc/parens.texi b/doc/parens.texi index 9839892..101ece5 100644 --- a/doc/parens.texi +++ b/doc/parens.texi @@ -484,7 +484,9 @@ backtick).  There's also this little command, @code{geiser-squarify}, which will  toggle the delimiters of the innermost list around point between round -and square brackets. It is bound to @key{C-c C-e [}. +and square brackets. It is bound to @kbd{C-c C-e [}. With numeric a +prefix (as in, say @kbd{M-2 C-c C-e [}), it will perform that many +toggles, forward for positive values and backward for negative ones.  @c Local Variables:  @c mode: texinfo diff --git a/elisp/geiser-mode.el b/elisp/geiser-mode.el index 3575474..1645ba2 100644 --- a/elisp/geiser-mode.el +++ b/elisp/geiser-mode.el @@ -176,22 +176,33 @@ With prefix, try to enter the current's buffer module."      (goto-char (point-max))      (pop-to-buffer b))) -(defun geiser-squarify () -  "Toggle between () and [] for current form." -  (interactive) -  (let ((pared (and (boundp 'paredit-mode) paredit-mode))) +(defun geiser-squarify (n) +  "Toggle between () and [] for current form. +With numeric prefix, perform that many toggles, forward for +positive values and backward for negative." +  (interactive "p") +  (let ((pared (and (boundp 'paredit-mode) paredit-mode)) +        (fwd (> n 0)) +        (steps (abs n)))      (when pared (paredit-mode -1))      (unwind-protect          (save-excursion            (unless (looking-at-p "\\s(") (backward-up-list)) -          (let ((p (point)) -                (round (looking-at-p "("))) -            (forward-sexp) -            (backward-delete-char 1) -            (insert (if round "]" ")")) -            (goto-char p) -            (delete-char 1) -            (insert (if round "[" "(")))) +          (while (> steps 0) +            (let ((p (point)) +                  (round (looking-at-p "("))) +              (forward-sexp) +              (backward-delete-char 1) +              (insert (if round "]" ")")) +              (goto-char p) +              (delete-char 1) +              (insert (if round "[" "(")) +              (setq steps (1- steps)) +              (backward-char) +              (condition-case nil +                  (progn (when fwd (forward-sexp 2)) +                         (backward-sexp)) +                (error (setq steps 0))))))        (when pared (paredit-mode 1))))) | 
