Re: Suggestion for efs
Daniel Finster (df@Pollux.ACS.Oakland.Edu)
Thu, 11 Aug 1994 03:04:47 -0500
From: Denis Howe <dbh@doc.ic.ac.uk>
Date: Wed, 10 Aug 94 12:39:36 BST
You can almost achieve this with my function find-file-at-point:
[ lisp code deleted ]
As distributed, this code does not work (At least for me). You use
three fns (last, init-string, and save-syntax-excursion), that my
emacs doesn't recognize. I spent a few minutes to create the
following version that works for me (maybe it'll help others too).
Since your code to take a plain hostname and surround it with `/' and
`:' depends on two of those fns, I've had to remove it. I also
patched word-at-point to save the match-data. If I messed something
up, please accept my apologies; it's 0300 here and I'm about to go to
sleep.
So if anyone else out there had problems with Denis' code, try the
following:
(defun find-file-at-point ()
"Find the file named around or before point.
Pass the name it to find-file as initial input. A file name is
assumed to consist of alphanumerics and [/.-:@]."
(interactive)
(let ((file (concat "/" (word-at-point "-._/:~@"))))
(find-file-other-window (read-file-name "Find file: " file file))))
(defun word-at-point (&optional chars)
"Return the word the point is on or after. If there is no word at or
before point, the empty string is returned. Optional argument CHARS
is a string of characters to consider as part of a word in addition to
those in the syntax class 'w'."
(let ((wordre "\\<\\w+"))
(save-match-data
(mapcar (function (lambda (char) (modify-syntax-entry char "w"))) chars)
(looking-at "") ; Empty match data
(save-excursion
(or (looking-at wordre)
(and (not (bobp))
(re-search-backward wordre nil t)
(looking-at wordre)))) ; Look again to set match-end
(buffer-substring (match-beginning 0) (match-end 0)))))