Reputation: 21152
I want to know what "thing" is at point in a dired buffer.
For instance Debug is a "directory":
drwxrwxrwx 0 10-08-2009 17:50 Debug
Makefile is a "file":
-rw-rw-rw- 15k 6-03-2009 13:02 Makefile
and this is a "header"
d:/foo/bar/Debug:
One way to find a thing is to look what face is at point. Is there another way to do it? How can I determine bounds-of-thing-at-point?
The standard (thing-at-point 'filename) does not handle spaces in a filename.
Upvotes: 3
Views: 708
Reputation: 30701
There is never (almost never?) a single thing at point. There are thing-at-point functions that can retrieve some text at or near point that is a thing of a particular type. So you have a fundamental misconception here.
In Dired, as elsewhere, depending on where point is, you can retrieve a symbol name at point, a file name at point, and several other kinds of things -- all from the same position.
Others have answered how to determine whether a given line is for an ordinary file or a directory.
If you use Dired+, then you can use C-h RET (command diredp-describe-file
) to get information about the file or directory on the current line -- its type, attributes, etc.
If you want to get a thing at or near point programmatically, see Thing At Point+.
Upvotes: 1
Reputation: 26519
These functions might be helpful in concocting what you want:
Upvotes: 6
Reputation: 5254
You can highlight text using overlays. Here are a couple of functions you could add to your .emacs file to do this. The key is that we name all of the overlays created this way 'my-highlights so that we can remove just those overlays later.
(defun highlight-thing-at-point ()
(interactive)
(let* ((my-thing (bounds-of-thing-at-point 'sexp))
(my-overlay (make-overlay (first my-thing) (rest my-thing))))
(overlay-put my-overlay 'name 'my-highlights)
(overlay-put my-overlay 'face 'highlight)))
(defun unhighlight-all-of-mine ()
(interactive)
(remove-overlays nil nil 'my-highlights))
EDIT:
You can add a custom function for returning the bounds of a filename at point that has spaces in it. See this EmacsWiki article for an example. So if you write a function named my-bounds-of-filename-at-point you can set it as the default for (bounds-of-thing-at-point 'filename) and (thing-at-point 'filename) like this:
(put 'filename 'bounds-of-thing-at-point 'my-bounds-of-filename-at-point)
Upvotes: 1
Reputation: 2718
The first character of the listing is d for directories, l for links, - for ordinary files. There are characters representing character and block devices, processes, etc. What more did you want to know? (I've never seen your "header" type. How did you produce that?)
Upvotes: 1