gnu-emacs-sources
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

square-braces-as-parens minor mode


From: thi
Subject: square-braces-as-parens minor mode
Date: Fri, 10 Nov 2000 11:25:47 -0800

;;; ID: square-braces-as-parens.el,v 1.5 2000/10/13 20:36:58 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.

;;;###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
(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")
                         (square-braces-as-parens-insert n ")" "]")))
  (unless noninteractive
    (message "Square braces as parens mode: %s"
             (if square-braces-as-parens-mode "on" "off"))))

;; load time action
(make-variable-buffer-local 'square-braces-as-parens-mode)
(put 'square-braces-as-parens-mode 'permanent-local t)

;; that's it
(provide 'square-braces-as-parens)

;;; square-braces-as-parens.el,v1.5 ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]