home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / functions / counter.el < prev    next >
Encoding:
Text File  |  1992-11-12  |  1.3 KB  |  43 lines

  1. ;;; $Id: counter.el,v 1.4 1992/11/12 23:23:46 rwhitby Exp $ 
  2. ;;; $Copyright: (c) 1992  Rod Whitby, <rwhitby@research.canon.oz.au> $ 
  3.  
  4. ;;; LCD Archive Entry:
  5. ;;; counter|Rod Whitby|rwhitby@research.canon.oz.au|
  6. ;;; Provides a counter for use in keyboard macros|
  7. ;;; 92/11/12|1.4|~/functions/counter.el.Z|
  8.  
  9. ;;; Based on a news article by robert@cogsci.ed.ac.uk (Robert Inder)
  10.  
  11. ;;; This file contains some simple functions for providing the
  12. ;;; user with access to a counter, for use in keyboard macros and
  13. ;;; the like.
  14. ;;;
  15. ;;; ESC := sets the counter to its argument, or 1
  16. ;;; ESC + increments the counter by its argument, or 1
  17. ;;; ESC * inserts counter value and increments by its argument, or 1
  18.  
  19. (provide 'counter)
  20.  
  21. (defvar counter-value 1 "*Counter value")
  22.  
  23. (make-variable-buffer-local 'counter-value)
  24.  
  25. (defun counter-set (initial) 
  26.   "Set the counter to the argument value (default 1)"
  27.   (interactive "p")
  28.   (setq counter-value initial))
  29.  
  30. (defun counter-increment (inc)
  31.    "Increments the counter by the argument value, if given, or 1"
  32.    (interactive "p")
  33.    (setq counter-value (+ counter-value inc)))
  34.  
  35. (defun counter-insert (increment)
  36.   (interactive "*p")
  37.   (insert (format "%d" counter-value))
  38.   (counter-increment increment))
  39.  
  40. (define-key esc-map ":=" 'counter-set)
  41. (define-key esc-map "+" 'counter-increment)
  42. (define-key esc-map "*" 'counter-insert)
  43.