From: sasmsr@zinfande.unx.sas.com (Mark S. Riggle)
Subject: Re: linenumbers.el : Continuously display current line number.
Originator: sasmsr@zinfande.unx.sas.com
Date: Fri, 2 Oct 1992 17:29:20 GMT
Distribution: na
Organization: SAS Institute Inc. Cary NC


In article <1992Oct2.134720.13218@maccs.dcss.mcmaster.ca>, xenidis@maccs.dcss.mcmaster.ca (Jimi X) writes:
|> In article <MAD.92Sep28094149@spirit.clearpoint.com> mad@spirit.clearpoint.com (Michael Davis) writes:
|> >
|> >Hi Emacs Hackers,
|> >
|> >When Ajay posted his sources for linenumbers.el, he included one known bug:
|> >
|> >;; Some known bugs:
|> >;;       It updates the status line of all the buffers, regardless of which 
|> >;; buffer you are in.
|> >
|> >This is an easy bug to cure.  At line 63 (right after (defvar
|> >global-line-numbers ... )) insert the following code:
|> >
|> >(make-variable-buffer-local 'line-number)
|> >
|> >This works for me.  Let me know if it does anything for you (or more
|> >particularly if it doesn't)
|> >
|> 
|> 	great now how do I get it to update using the cursor keys or C-v M-v 
|> and M-< M-> etc...
|> 


; 
; 
; The line number package by Ajay Shekhawat can be made much
; smoother by redefining all the basic cursor motion functions so
; that they first call their original definition, then check if
; it is an interactive call and if so update the line number.
; Then all key bindings may be left alone since the function is
; changed.
; 
; 
; This is best done with a macro that creates a new function name
; to hold the prior function and then redefines the orginal
; function.
; 
; The macro is called new-moves and for example:
; 
; (macroexpand '(new-moves scroll-down)) ==>
; (progn 
;   (if (symbol-function (quote scroll-down*)) 
;       nil 
;     (fset (quote scroll-down*) (symbol-function (quote scroll-down)))) 
;   (defun scroll-down (arg) 
;     (interactive "P") 
;     (scroll-down* arg) 
;     (if (interactive-p) 
;         (setq line-number (what-line*)))))))
; 
; 

;;;;;;===================================================================


;;; from Ajay Shekhawat <ajay@cs.Buffalo.EDU> code supplied 
;;;  in linenumbers.el


(defvar global-line-numbers t "TRUE if we want line-numbers to be shown \
in every mode")

(setq mode-line-buffer-identification '("Emacs: %1b" "--" line-number "--"))

(setq global-mode-string '(""  display-time-string))

(defun what-line* ()
  "RETURN the current line number (in the buffer) of point."
  (interactive)
  (save-restriction
    (widen)
    (save-excursion
      (beginning-of-line)
      (concat " " (1+ (count-lines 1 (point))) " "))))

(setq line-number (what-line*))
(make-variable-buffer-local 'line-number)


;;;=====================================================================
;;  My macro definition and macro calls

(defmacro new-moves (function-name)
  (let ((new-name (intern (concat (symbol-name function-name) "*"))))
    (list 'progn
          (list 'if (list 'symbol-function 
                          (list 'quote new-name))
                nil  ; if already defined, an fset may capture itself
                (list 'fset  (list 'quote new-name)
                      (list 'symbol-function (list 'quote function-name))))
          (list 'defun function-name (list 'arg)
                (list 'interactive "P")
                (list new-name 'arg)
                '(if (interactive-p)
                     (setq line-number (what-line*)))))))

(new-moves backward-char)
(new-moves backward-page)
(new-moves previous-line)
(new-moves backward-word)
(new-moves beginning-of-buffer)
(new-moves scroll-down)
(new-moves scroll-up)
(new-moves next-line)
(new-moves forward-char)
(new-moves forward-page)
(new-moves end-of-buffer)
(new-moves forward-word)
(new-moves newline)
(new-moves newline)
(new-moves open-line)
(new-moves split-line)
(new-moves delete-blank-lines)
(new-moves newline-and-indent)
(new-moves goto-line)
(new-moves kill-line)
(new-moves kill-region)
(new-moves yank-pop)
(new-moves yank)
-- 
=========================================================
Mark Riggle                         | "Give me a  LAMBDA large  enough
sasmsr@unx.sas.com                  |  and a place to put it, and 
SAS Institute Inc.,                 |  I can move the world"
SAS Campus Drive, Cary, NC, 27513   |   Arthimedeth 
(919) 677-8000                      |   (Archimedes on a lisp machine)
Newsgroups: gnu.emacs.sources