home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / gnu / emacs / help / 5120 < prev    next >
Encoding:
Text File  |  1992-12-18  |  10.6 KB  |  308 lines

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