[net.emacs] Lining a function up.

karl@dartvax.UUCP (S. Delage.) (06/25/84)

Recently someone asked about getting line numbers in Emacs. ( I don't
recall who. ) Someone else ( ditto ) answered for CCA Emacs, which
has a variable. Gosling Emacs doesn't, but at the end of this article
is a function that computes the current line. ( Albeit slowly. )

I have two questions, as well.
1. Is it possible to bind-to-key not just a function invocation
   but a function invocation with argument? For example,
   (bind-to-key "function-name first-arg" "\^C")

2. Is it possible to input a variable-name from the keyboard
   ( via get-tty-variable, most likely. ) and then use that
   variable's value somehow? Something like
   (setq var (get-tty-variable "Variable name? ") ) gives the
   string he inputs, so that var = "variable-name". What I
   want is for var to be the variable variable-name, which has
   some other value.

Thanks for your consideration.
karl@dartmouth = {decvax,cornell,astrovax,uvm-gen,colby}!dartvax!colby

; This returns the number indicating what line dot is on in the
; current buffer.
(defun	(current-line-number line
	(save-excursion
		(set-mark)
		(beginning-of-file)
		(narrow-region)
		; Now we're only looking at the first N lines.
		(setq line 1)
		(end-of-line)
		(while (! (eobp))
			(setq line (+ line 1))
			(next-line)
		)
	)
	(widen-region) ; Put back the rest of the file.
	line
	)
)

chris@umcp-cs.UUCP (06/29/84)

*	From: karl@dartvax.UUCP

	Recently someone asked about getting line numbers in Emacs. ...

If you mean ``on the display'', I have (after many requests) put line
numbers into the Emacs window code.  It was surprisingly easy to do
for #85, and surprisingly harder to do for #264 (which has fancier
optimization).  This should appear at UniPress sometime in the near
future.  (What will happen after that is anyone's guess ...)

	I have two questions, as well.
	1. Is it possible to bind-to-key not just a function invocation
	   but a function invocation with argument? For example,
	   (bind-to-key "function-name first-arg" "\^C")

No.  The solution I generally use is to bind the key to a helper function
that calls the main function after getting the argument(s).

	2. Is it possible to input a variable-name from the keyboard
	   ( via get-tty-variable, most likely. ) and then use that
	   variable's value somehow?

Sure:

(defun (print-variable &v
	(setq &v (get-tty-variable ": print "))
	(message &v " => " (execute-mlisp-line &v))))

(execute-mlisp-line) is the MLisp equivalent of a real ``eval'' function.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci (301) 454-7690
UUCP:	{seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet:	chris@umcp-cs		ARPA:	chris@maryland