[gnu.emacs] finger.el

trost@crl.labs.tek.com (Bill Trost) (07/20/89)

I posted this locally to tek without any reaction locally, so I guess
that means I can foist it off on the rest of the world....

Here's a little function that uses the TCP stuff to talk to finger
daemons.  Lots more pleasant than running who in a subshell or
users.el or any of those other hacks.  It was mostly inspired by the
fact that finger doesn't work on Tektronix boxes....

Enjoy!

(defun finger (who)
  "Display information about users."
  (interactive "sFinger: ")
  (cond
   ((null who) (setq who "@localhost"))
   ((not (string-match "@" who))
    (setq who (concat who "@localhost"))))
  (with-output-to-temp-buffer "*finger*"
      (let ((stream (open-network-stream
		     "finger" "*finger*"
		     (substring who (1+ (string-match "@" who)))
		     "finger")))
	(set-process-filter stream 'finger-process-filter)
	(set-process-sentinel stream 'ignore)
	(process-send-string stream
			     (concat (substring who 0
						(string-match "@" who))
				     "\n")))))

(defun finger-process-filter (process s)
  (save-excursion
    (set-buffer (process-buffer process))
    (while (< 0 (length s))
      (let ((l (string-match "\r" s)))
	(insert (substring s 0 l))
	(setq s (cond (l (substring s (1+ l)))
		      (t "")))))))

Bill Trost, Computer Research Labs, Tektronix
trost@crl.labs.tek.com / tektronix!crl.labs!trost
(trost@reed.bitnet, but probably tektronix!reed!trost)

cramer@sun.com (Sam Cramer) (07/21/89)

I modified finger.el, which didn't behave quite the way I wanted it to on
my system: the finger buffer was too small, and I had to resize it to see
the finger output.

Here's my modified version.  It has one misfeature: the window starts out
quite small, but is properly resized when the finger request has finished.
This looks a bit ugly.  I'm an elisp tyro, so I'd be happy to hear how to
fix this or otherwise improve the code.

Sam
-------
;
; finger.el, by trost@crl.labs.tek.com (Bill Trost)
;
; Mods by Sam Cramer (cramer@sun.com), Jul 20, 1989:
;  - In my environment, the temp buffer would be shown with
;  incomplete results.  I added a process sentinel to accept
;  pending process output and show the buffer after the process
;  receives a signal, and code to send an eof to the
;  process to generate such a signal on termination of processing 
;  of the finger request.
;  Also, I removed the process filter, and do post-processing in
;  sentinel to remove ugly C-m's.

(defun finger (who)
  "Display information about users."
  (interactive "sFinger: ")
  (cond
   ((null who) (setq who "@localhost"))
   ((not (string-match "@" who))
    (setq who (concat who "@localhost"))))
  (with-output-to-temp-buffer "*finger*"
      (let ((stream (open-network-stream
		     "finger" "*finger*"
		     (substring who (1+ (string-match "@" who)))
		     "finger")))
	(set-process-sentinel stream 'finger-process-sentinel)
	(process-send-string stream
			     (concat (substring who 0
						(string-match "@" who))
				     "\n"))
	(process-send-eof stream))))

(defun finger-process-sentinel (process s)
  (accept-process-output)
  (save-excursion
    (set-buffer "*finger*")
    (goto-char (point-min))
    (replace-string "\C-m" ""))
  (show-temp-buffer "*finger*"))

grunwald@flute.cs.uiuc.edu (Dirk Grunwald) (07/22/89)

I had also done a finger command once, and the someone pointed out
that ``M-!finger user@foo'' did the same thing.
--
Dirk Grunwald -- Univ. of Illinois 		  (grunwald@flute.cs.uiuc.edu)

bob@tinman.cis.ohio-state.edu (Bob Sutterfield) (07/22/89)

In article <GRUNWALD.89Jul21121442@flute.cs.uiuc.edu> grunwald@flute.cs.uiuc.edu (Dirk Grunwald) writes:
   I had also done a finger command once, and the someone pointed out
   that ``M-!finger user@foo'' did the same thing.

Nope, these little toys make TCP connections directly from Emacs to
the fingerd port on some remote machine.  They don't invoke a shell
and an application on your local machine.

grunwald@flute.cs.uiuc.edu (Dirk Grunwald) (07/25/89)

In article <BOB.89Jul21135756@tinman.cis.ohio-state.edu> bob@tinman.cis.ohio-state.edu (Bob Sutterfield) writes:

   In article <GRUNWALD.89Jul21121442@flute.cs.uiuc.edu> grunwald@flute.cs.uiuc.edu (Dirk Grunwald) writes:
      I had also done a finger command once, and the someone pointed out
      that ``M-!finger user@foo'' did the same thing.

   Nope, these little toys make TCP connections directly from Emacs to
   the fingerd port on some remote machine.  They don't invoke a shell
   and an application on your local machine.

----

too true, an too useful.

I hacked finger.el around a little to give mail-verify.el, a variant of
a C program I have occasion to use. It probes an SMTP mailer to verify
mailing addresses. If anyone extends this or makes it more useful,
please send mail.

;; Copyright (C) 1989 Free Software Foundation, if they want it

;; This file is part of GNU Emacs.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY.  No author or distributor
;; accepts responsibility to anyone for the consequences of using it
;; or for whether it serves any particular purpose or works at all,
;; unless he says so in writing.  Refer to the GNU Emacs General Public
;; License for full details.

;; Everyone is granted permission to copy, modify and redistribute
;; GNU Emacs, but only under the conditions described in the
;; GNU Emacs General Public License.   A copy of this license is
;; supposed to have been given to you along with GNU Emacs so you
;; can know your rights and responsibilities.  It should be in a
;; file named COPYING.  Among other things, the copyright notice
;; and this notice must be preserved on all copies.
;;
;; Author Dirk Grunwald (grunwald@cs.uiuc.edu)
;; modified from finger.el, but largely different.
;;

(defvar mail-verify-stream nil)

(defun mail-verify (who)
  "Verify mail address for users."
  (interactive "sVerify mail address for: ")
  (let
      (mail-query-system)
    (cond
     ((null who) (setq who "@localhost"))
     ((not (string-match "@" who))
      (setq who (concat who "@localhost"))))
    (setq mail-query-system
	  (read-string
	   (concat "Query which mailer?: ")
	   (substring who (1+ (string-match "@" who)))))
  (with-output-to-temp-buffer "*mail-verify*"
      (let ((stream (open-network-stream
		     "mail-verify" "*mail-verify*"
		     mail-query-system
		     "smtp")))
	(setq mail-verify-stream stream)
	(set-process-sentinel stream 'mail-verify-process-sentinel)
	(set-process-filter stream 'mail-verify-process-filter)
	(process-send-string
	 stream
	 (concat "VRFY "
		 (substring who 0 (string-match "@" who))
		 "\n"))
	))))

(defun mail-verify-process-sentinel (process s)
  (accept-process-output)
  (save-excursion
    (set-buffer "*mail-verify*")
    (goto-char (point-min))
    (replace-string "\C-m" "")))

(defun mail-verify-process-filter (process string)
  (let
      (( this-buffer (current-buffer)))
    (set-buffer "*mail-verify*")
    (goto-char (point-max))
    (cond
     ((string-match "^220 " string) t)
     ((string-match "^221 " string) t)
     ((string-match "^250 " string)
      (progn
	(insert (substring string 4))
	(process-send-string mail-verify-stream "QUIT\n")
	(process-send-eof mail-verify-stream)))
     ((string-match "^550-" string) (insert (substring string 4)))
     (t (insert string)))
     (goto-char (point-min))
     (replace-string "\C-m" "")

    ;;
    ;; if verify is visible, move the last line to the bottom of that window
    ;;
    (let ((here (selected-window)))
      (let ((webster-window (get-buffer-window "*mail-verify*")))
	(if (windowp webster-window)
	  (progn
	    (select-window webster-window)
	     (recenter -1)
	     (select-window here)))))

    (set-buffer this-buffer)))


--
Dirk Grunwald -- Univ. of Illinois 		  (grunwald@flute.cs.uiuc.edu)

cramer@sun.com (Sam Cramer) (07/26/89)

Several people have pointed out that the modified version of finger.el I
posted depends on a routine from the "help windows" package by Joe Wells.
If anyone needs a copy, send me email and I'll mail it out.

Sam

trost@crl.labs.tek.com (Bill Trost) (08/01/89)

Auughhh, all these version of finger!  Oof, what confusion.  I'm
surprised someone hasn't written an interface to the quote service yet
(gee, I think Mondays should be backquote days).

In any case, cramer@sun.com posted some mods dealing with the way
with-output-to-temp-buffer was dealing with window sizes, and somehow
hacked around the way this was being done.  Actually,
tale@pawl.rpi.edu had chastized me sometime before for using
with-output-to-temp buffer as I had.  Its use was totally
inappropriate and did not belong there at all, so I made the
appropriate replacements.  (Hazards of using someone else's code as a
skeleton for you own.)  As a side effect, the buffer is not cleared
between fingerings -- I consider this a feature.

Cramer also moved carriage-return replacement from the process filter
to the process sentinel -- a good idea, assuming the network
connection's fast enough.  I have put that in here.

Gee, if people start hacking at these things like this, someone ought
to sort of try to consolidate it all -- any volunteers?  (Hey, wait,
you're going to blame this on me??  Hold on a minute...)

[Warning -- there is probably a .signature at the bottom of this.
Sorry about that, but our postnews software is sort of strange.]

;
; finger.el
; Bill Trost (trost@crl.labs.tek.com)
; MCMLXXXIX
;
; This software is not officially a part of GNU emacs, but it should be,
; so consider it to be under the same licensing and warranty as GNU
; software.
;
; Questions or comments to trost@reed.bitnet or
; uunet!tektronix!reed!trost after 15 August 1989.
;
; Invoke a finger daemon through a network connection and stuff the reply
; in a buffer.
;
; Contains a clever mod made by Sam Cramer (cramer@sun.com) to remove
; carriage returns in the process sentinel instead of in a process
; filter.  Also, thanks to David Lawrence (tale@pawl.rpi.edu) for
; helpful suggestions.

(defun finger (who)
  "Display information about users."
  (interactive "sFinger: ")
  (cond
   ((null who) (setq who "@localhost"))
   ((not (string-match "@" who))
    (setq who (concat who "@localhost"))))
  (display-buffer (get-buffer-create "*finger*"))
  (let ((stream (open-network-stream
		 "finger" "*finger*"
		 (substring who (1+ (string-match "@" who)))
		 "finger")))
    (set-process-sentinel stream 'finger-process-sentinel)
    (process-send-string stream
			 (concat (substring who 0 (string-match "@" who))
				 "\n"))))

(defun finger-process-sentinel (process s)
  (accept-process-output)
  (save-excursion
    (set-buffer (process-buffer process))
    (goto-char (point-min))
    (replace-string "\C-m" "")
    (message "")))

Bill Trost, Computer Research Labs, Tektronix
trost@crl.labs.tek.com / tektronix!crl.labs!trost
(trost@reed.bitnet, but probably tektronix!reed!trost)