[net.emacs] what-line-number command in Gosling's Emacs

randy@uw-june (William Randy Day) (12/07/84)

Does anyone have a macro for Gosling's Emacs that will tell me
the line number of the line the cursor is on? Probably displaying
it on the message line at the bottom of the screen.

Randy Day.
UUCP: {decvax|ihnp4}!uw-beaver!uw-june!randy
ARPA: randy@washington
CSNET: randy%washington@csnet-relay

wmb@sun.uucp (Mitch Bradley) (12/10/84)

> Does anyone have a macro for Gosling's Emacs that will tell me
> the line number of the line the cursor is on? Probably displaying
> it on the message line at the bottom of the screen.

Here's one.  Maybe there's a better way to do it, but this
one works, albeit somewhat slowly.  It also tells you the line number
in the window.  I think Craig Taylor wrote it, but my memory is hazy.

(declare-buffer-specific line place-in-window)
(defun
    (line-number
	(save-excursion 
	    (setq line 1)
	    (beginning-of-line)	
	    (while (! (bobp))
		   (previous-line)
		   (setq line (+ line 1))
	    )
	)
	(message "Line Number " line)
    )
    (line-number-in-window
	(save-excursion 
	    (setq line 1)
	    (beginning-of-line)
	    (setq place-in-window (dot))
	    (beginning-of-window)
	    (while (< (dot) place-in-window)
		   (next-line)
		   (setq line (+ line 1))
	    )
	)
	(message "Line Number in Window " line)
    )
)

koomen@rochester.UUCP (Hans Koomen) (12/10/84)

Here are three functions I have used for quite some time:

"current-line"		(fast)
"where-am-i"		(bound to "\ew")
"position-dot-at-line"	(bound to "\ep")

Enjoy!

-- Hans

(defun
    (current-line lcnt incr
	(save-excursion
	    (setq lcnt 1)
	    (setq incr (/ (dot) 80))
	    (while (> incr 1)
		   (while (! (error-occured
				 (provide-prefix-argument incr
				     (search-reverse "\^J"))))
			  (setq lcnt (+ lcnt incr)))
		   (setq incr (/ incr 4)))
	    (while (! (error-occured (search-reverse "\^J")))
		   (setq lcnt (+ lcnt 1)))
	lcnt)
    )

    (where-am-i
	(message "line " (current-line) ", column " (current-column))
	(novalue))
    
    (position-dot-at-line n
	(setq n (get-tty-string ": position-dot-at-line "))
	(beginning-of-file)
	(provide-prefix-argument (- n 1) (next-line)))