home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / misc / linenumbers.el < prev    next >
Encoding:
Text File  |  1992-09-23  |  10.6 KB  |  314 lines

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;
  3. ;; linenumbers.el
  4. ;; Written by: Ajay Shekhawat <ajay@cs.Buffalo.EDU>
  5. ;; Written sometime in 1989.
  6. ;; Released (unleashed? :-) on Wed Sep 23 10:47:46 EDT 1992
  7. ;; Copyright (c) 1992, Ajay Shekhawat <ajay@cs.Buffalo.EDU>
  8. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9. ;;
  10. ;; General Description.
  11. ;; Load this file, and the line number that you are on gets displayed in your
  12. ;; status line. It gets updated continuously as you move around (well, almost
  13. ;; always. Sometimes it fails, and hitting C-p/C-n fixes that). Please read
  14. ;; the History and Disclaimer below, *before* you start using it.
  15. ;; 
  16. ;; 
  17. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  18. ;; DISCLAIMER: This file is provided as-is, with no warranties whatsoever,
  19. ;; either explicit or implied. Use at your own risk. 
  20. ;; - - - - - - - - - - - - - - 
  21. ;; Everyone is granted permission to copy, modify and redistribute
  22. ;; this code, but only under the conditions described in the
  23. ;; GNU Emacs General Public License.   A copy of this license is
  24. ;; supposed to have been given to you along with GNU Emacs so you
  25. ;; can know your rights and responsibilities.  It should be in a
  26. ;; file named COPYING.  Among other things, the copyright notice
  27. ;; and this notice must be preserved on all copies.
  28. ;; - - - - - - - - - - - - - - 
  29. ;;
  30. ;; History:  During my early Emacs days, I was sometimes in the need to see
  31. ;; the current line number while editing (continuosly). I hacked out this
  32. ;; piece of Elisp code (actually , "hack" is too strong a word. There's
  33. ;; almost nothing elegant in this code), to do the job. 
  34. ;; My demands were (and still are) limited, so I'm satisified by what this
  35. ;; does.
  36. ;; Some friends of mine here have found this to be pretty useful (not that
  37. ;; they have a choice ;-) , so upon their urging I'm releasing this to
  38. ;; the wide world, with the request that
  39. ;;    - if you have gripes about the way it is written, I don't want to hear
  40. ;;      about them. I know this code is pretty shoddy.
  41. ;;    - if you find a serious bug, _and_ can come up with a fix, I'd like
  42. ;;      to hear about it.
  43. ;;    - if you improve this code, or write your own with this functionality,
  44. ;;      please drop me a line.
  45. ;;   
  46. ;; I won't be modifying this further on my own (well, most probably not :-)),
  47. ;; so please don't send me mail asking for "a newer version". There won't be
  48. ;; any, atleast from me.  I'm sorry, but...
  49. ;;
  50. ;; Some known bugs:
  51. ;;       It updates the status line of all the buffers, regardless of which 
  52. ;; buffer you are in.
  53. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  54. ;; LCD Archive Entry:
  55. ;; linenumbers|Ajay Shekhawat|ajay@cs.Buffalo.EDU|
  56. ;; Continuous display of current line number in the status line|
  57. ;; 92-09-23|1.0|~/misc/linenumbers.el|
  58. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  59.  
  60.  
  61. (defvar global-line-numbers t "TRUE if we want line-numbers to be shown \
  62. in every mode")
  63.  
  64. (setq mode-line-buffer-identification '("Emacs: %1b" "--" line-number "--"))
  65.  
  66. (setq global-mode-string '(""  display-time-string))
  67.  
  68. (defun what-line* ()
  69.   "RETURN the current line number (in the buffer) of point."
  70.   (interactive)
  71.   (save-restriction
  72.     (widen)
  73.     (save-excursion
  74.       (beginning-of-line)
  75.       (concat " " (1+ (count-lines 1 (point))) " "))))
  76.  
  77. (setq line-number (what-line*))
  78.  
  79.  
  80. (cond
  81.   (global-line-numbers
  82.     (or
  83. ;    (global-set-key "\C-?"             'backward-delete-char-untabify*)
  84.      (global-set-key "\C-o"             'open-line*)
  85.      (global-set-key "\e\C-o"           'split-line*)
  86.      (global-set-key "\C-x\C-o"         'delete-blank-lines*)
  87.      (global-set-key "\C-j"             'newline-and-indent*)
  88.      (global-set-key "\C-cg"            'goto-line*)
  89.      (global-set-key "\C-k"             'kill-line*)
  90.      (global-set-key "\C-m"             'newline*)
  91.      (global-set-key "\C-b"             'backward-char*)
  92.      (global-set-key "\C-w"             'kill-region*)
  93.      (global-set-key "\C-y"             'yank*)
  94.      (global-set-key "\C-x["            'backward-page*)
  95.      (global-set-key "\C-p"             'previous-line*)
  96.      (global-set-key "\eb"              'backward-word*)
  97.      (global-set-key "\e<"              'beginning-of-buffer*)
  98.      (global-set-key "\ev"              'scroll-down*)
  99.      (global-set-key "\ey"              'yank-pop*)
  100.      (global-set-key "\C-v"             'scroll-up*)
  101.      (global-set-key "\C-n"             'next-line*)
  102.      (global-set-key "\C-f"             'forward-char*)
  103.      (global-set-key "\C-x]"            'forward-page*)
  104.      (global-set-key "\e>"             'end-of-buffer*)
  105.      (global-set-key "\ef"             'forward-word*)))
  106.   (t
  107.     (or
  108. ;    (local-set-key "\C-?"             'backward-delete-char-untabify*)
  109.      (local-set-key "\C-o"             'open-line*)
  110.      (local-set-key "\e\C-o"           'split-line*)
  111.      (local-set-key "\C-x\C-o"         'delete-blank-lines*)
  112.      (local-set-key "\C-j"             'newline-and-indent*)
  113.      (local-set-key "\C-cg"            'goto-line*)
  114.      (local-set-key "\C-k"             'kill-line*)
  115.      (local-set-key "\C-m"             'newline*)
  116.      (local-set-key "\C-b"             'backward-char*)
  117.      (local-set-key "\C-w"             'kill-region*)
  118.      (local-set-key "\C-y"             'yank*)
  119.      (local-set-key "\C-x["            'backward-page*)
  120.      (local-set-key "\C-p"             'previous-line*)
  121.      (local-set-key "\eb"              'backward-word*)
  122.      (local-set-key "\e<"              'beginning-of-buffer*)
  123.      (local-set-key "\ev"              'scroll-down*)
  124.      (local-set-key "\ey"              'yank-pop*)
  125.      (local-set-key "\C-v"             'scroll-up*)
  126.      (local-set-key "\C-n"             'next-line*)
  127.      (local-set-key "\C-f"             'forward-char*)
  128.      (local-set-key "\C-x]"            'forward-page*)
  129.      (local-set-key "\e>"             'end-of-buffer*)
  130.      (local-set-key "\ef"             'forward-word*))))
  131.  
  132.  
  133. (defun backward-char* (arg)
  134.   "same as \\[backward-char] , but display line-number also."
  135.   (interactive "p")
  136.   (backward-char arg)
  137.   (setq line-number (what-line*)))
  138.  
  139. (defun backward-page* (arg)
  140.   "See backward-page for documentation.  "
  141.   (interactive "p")
  142.   (backward-page arg)
  143.   (setq line-number (what-line*)))
  144.  
  145. (defun previous-line* (arg)
  146.   "See previous-line for documentation. "
  147.   (interactive "p")
  148.   (previous-line arg)
  149.   (setq line-number (what-line*)))
  150.  
  151. (defun backward-word* (arg)
  152.   "See backward-word for documentation. "
  153.   (interactive "p")
  154.   (backward-word arg)
  155.   (setq line-number (what-line*)))
  156.  
  157. (defun beginning-of-buffer* (arg)
  158.   "See beginning-of-buffer for documentation. "
  159.   (interactive "P")
  160.   (beginning-of-buffer arg)
  161.   (setq line-number (what-line*)))
  162.  
  163. (defun scroll-down* (arg)
  164.   "See scroll-down for documentation. "
  165.   (interactive "P")
  166.   (scroll-down arg)
  167.   (setq line-number (what-line*)))
  168.  
  169. (defun scroll-up* (arg)
  170.   "See scroll-up for documentation. "
  171.   (interactive "P")
  172.   (scroll-up arg)
  173.   (setq line-number (what-line*)))
  174.  
  175. (defun next-line* (arg)
  176.   "See next-line for documentation. "
  177.   (interactive "p")
  178.   (next-line arg)
  179.   (setq line-number (what-line*)))
  180.  
  181.  
  182. (defun forward-char* (arg)
  183.   "See forward-char for documentation. "
  184.   (interactive "p")
  185.   (forward-char arg)
  186.   (setq line-number (what-line*)))
  187.  
  188. (defun forward-page* (arg)
  189.   "See forward-page for documentation. "
  190.   (interactive "p")
  191.   (forward-page arg)
  192.   (setq line-number (what-line*)))
  193.  
  194. (defun end-of-buffer* (arg)
  195.   "See end-of-buffer for documentation. "
  196.   (interactive "P")
  197.   (message (concat " " arg))
  198.   (end-of-buffer arg)
  199.   (setq line-number (what-line*)))
  200.  
  201. (defun forward-word* (arg)
  202.   "See forward-word for documentation. "
  203.   (interactive "p")
  204.   (forward-word arg)
  205.   (setq line-number (what-line*)))
  206.  
  207. ;(defun newline+ (arg)
  208. ;  " Redefine \\[backward-delete-char-untabify] , and then redefine itself"
  209. ;  (interactive "p")
  210. ;(cond
  211. ;  (global-line-numbers
  212. ;    (or 
  213. ;      (global-set-key "\C-?" 'backward-delete-char-untabify*)
  214. ;      (global-set-key "\C-m" 'newline*)))
  215. ;  (t 
  216. ;    (or
  217. ;      (local-set-key "\C-?" 'backward-delete-char-untabify*)
  218. ;      (local-set-key "\C-m" 'newline*))))
  219. ;  (global-set-key "\C-m" 'newline*)
  220. ;  (newline* arg))
  221.  
  222.  
  223. (defun newline* (arg)
  224.   "See newline for documentation. "
  225.   (interactive "p")
  226.   (newline arg)
  227.   (setq line-number (what-line*)))
  228.  
  229.  
  230.  
  231. (defun open-line* (arg)
  232.   " See open-line for documentation "
  233.   (interactive "*p")
  234.   (open-line arg)
  235.   (setq line-number (what-line*)))
  236.  
  237. (defun split-line* (arg)
  238.   "See split-line for documentation. "
  239.   (interactive "*")
  240.   (split-line arg)
  241.   (setq line-number (what-line*)))
  242.  
  243. (defun delete-blank-lines* (arg)
  244.   "See delete-blank-lines for documentation. "
  245.   (interactive "*" )
  246.   (delete-blank-lines arg)
  247.   (setq line-number (what-line*)))
  248.  
  249. (defun newline-and-indent* ()
  250.   "See newline-and-indent for documentation. "
  251.   (interactive "*" )
  252.   (newline-and-indent)
  253.   (setq line-number (what-line*)))
  254.  
  255. (defun goto-line* (arg)
  256.   "See goto-line for documentation. "
  257.   (interactive "Ngoto? ")
  258.   (goto-line arg)
  259.   (setq line-number (what-line*)))
  260.  
  261. (defun kill-line* (arg)
  262.   "See kill-line for documentation. "
  263.   (interactive "*P")
  264.   (setq this-command 'kill-line)
  265.   (kill-line arg)
  266.   (setq line-number (what-line*)))
  267.  
  268. (defun kill-region* (beg end)
  269.   "See kill-region for documentation. "
  270.   (interactive "*r")
  271.   (setq this-command 'kill-region)
  272.   (kill-region beg end)
  273.   (setq line-number (what-line*)))
  274.  
  275. (defun yank-pop* (arg)
  276.   "See yank-pop for documentation. "
  277.   (interactive "*p")
  278.   (setq this-command 'yank-pop)
  279.   (yank-pop arg)
  280.   (setq line-number (what-line*)))
  281.  
  282. (defun yank* (arg)
  283.   "See yank for documentation. "
  284.   (interactive "*P")
  285.   (setq this-command 'yank)
  286.   (yank arg)
  287.   (setq line-number (what-line*)))
  288.  
  289. ;;(defun backward-delete-char-untabify* (arg &optional killp)
  290. ;;  "See backward-delete-char-untabify for documentation. "
  291. ;;  (interactive "*p\nP")
  292. ;;  (backward-delete-char-untabify arg killp)
  293. ;;  (setq line-number (what-line*)))
  294.  
  295. (defun backward-delete-char-untabify (arg &optional killp)
  296.   "Delete characters backward, changing tabs into spaces, and display line-number
  297. Delete ARG chars, and kill (save in kill ring) if KILLP is non-nil.
  298. Interactively, ARG is the prefix arg (default 1)
  299. and KILLP is t if prefix arg is was specified."
  300.   (interactive "*p\nP")
  301.   (let ((count arg))
  302.     (save-excursion
  303.       (while (and (> count 0) (not (bobp)))
  304.     (if (= (preceding-char) ?\t)
  305.         (let ((col (current-column)))
  306.           (forward-char -1)
  307.           (setq col (- col (current-column)))
  308.           (insert-char ?\ col)
  309.           (delete-char 1)))
  310.     (forward-char -1)
  311.     (setq count (1- count)))))
  312.   (delete-backward-char arg killp)
  313.   (setq line-number (what-line*)))
  314.