[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
square-braces-as-parens.el 1.7
From: |
thi |
Subject: |
square-braces-as-parens.el 1.7 |
Date: |
Mon, 13 Nov 2000 14:34:43 -0800 |
as a response to some feedback, i've added close-everything
functionality, w/ an added twist that the closing is not immediate, but
human-time-scale incremental and cleanly interruptable. the gist is
that close-everything can be used for "close-lots-but-not-everything".
see new var `sbap-close-everything-magic-char' for customization.
also, the description now says "per buffer".
thi
__________________________________
;;; ID: square-braces-as-parens.el,v 1.7 2000/11/13 22:32:08 ttn Rel
;;;
;;; Copyright (C) 2000 Thien-Thi Nguyen
;;; This file is part of ttn's personal elisp library, released under GNU
;;; GPL with ABSOLUTELY NO WARRANTY. See the file COPYING for details.
;;; Description: Minor mode to bind parens to square-braces keys, per buffer.
;;;###autoload
(defvar square-braces-as-parens-mode nil
"If non-nil, \"[\" and \"]\" insert \"(\" and \")\", respectively.")
(defun square-braces-as-parens-insert (n yes no)
(while (< 0 n)
(insert (if square-braces-as-parens-mode yes no))
(setq n (1- n))))
;;;###autoload
(defvar sbap-close-everything-magic-char 32
"When closing, if preceding char is this char, delete the char and
close everything (so that the top-level form is closed) one paren at a
time w/ a delay between each paren. Any input before the closing is
finished cancels the rest of the parens. A value of nil means never do
close-everything behavior. Default value is 32 (space).")
;; This function adapted from gnu.emacs.help post
;; <address@hidden> by Kevin Rodgers.
(defun square-braces-as-parens-close-everything ()
(interactive)
(let ((last-command-char ?\))
(depth (car (parse-partial-sexp (save-excursion
(beginning-of-defun)
(point))
(point)))))
(while (and (not (input-pending-p))
(< 0 depth))
;; why is this better than using `insert'? --ttn
(call-interactively 'self-insert-command)
(sit-for (* 0.05 (setq depth (1- depth)))))))
;;;###autoload
(defun square-braces-as-parens-mode (&optional arg)
(interactive "P")
(setq square-braces-as-parens-mode
(if (null arg)
(not square-braces-as-parens-mode)
(> (prefix-numeric-value arg) 0)))
(local-set-key "[" #'(lambda (n)
(interactive "p")
(square-braces-as-parens-insert n "(" "[")))
(local-set-key "]" #'(lambda (n)
(interactive "p")
(if (or (not sbap-close-everything-magic-char)
(/= sbap-close-everything-magic-char
(char-before))
(not square-braces-as-parens-mode))
(square-braces-as-parens-insert n ")" "]")
(delete-char -1)
(square-braces-as-parens-close-everything))))
(unless noninteractive
(message "Square braces as parens mode: %s"
(if square-braces-as-parens-mode "on" "off"))))
;; load time action
(mapcar (lambda (var)
(make-variable-buffer-local var)
(put var 'permanent-local t))
'(square-braces-as-parens-mode
sbap-close-everything-magic-char))
;; that's it
(provide 'square-braces-as-parens)
;;; square-braces-as-parens.el,v1.7 ends here
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- square-braces-as-parens.el 1.7,
thi <=