[comp.emacs] How to read a word from a buffer for use as a variable in a function.

bjaspan@ATHENA.MIT.EDU ("Barr3y Jaspan") (01/03/91)

   Date: 2 Jan 91 18:11:08 GMT
   From: southern@neit.cgd.ucar.edu

   Typing the word into the minibuffer is proving cumbersome and I would
   like to find a way to make the function look up the documentation for
   the word that the cursor is currently on.

The following elisp (from tags.el in the standard emacs distribution)
does what you want, I think.  Of course, that assumes I correctly
understand what you want to do.

;; Return a default tag to search for, based on the text at point.
(defun find-tag-default ()
  (save-excursion
    (while (looking-at "\\sw\\|\\s_")
      (forward-char 1))
    (if (re-search-backward "\\sw\\|\\s_" nil t)
	(progn (forward-char 1)
	       (buffer-substring (point)
				 (progn (forward-sexp -1)
					(while (looking-at "\\s'")
					  (forward-char 1))
					(point))))
      nil)))

Barr3y Jaspan, bjaspan@mit.edu