tags:

views:

140

answers:

3

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.

+1  A: 

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)
Harold L
My question was not about highlighting but about finding what is at point. (bounds-of-thing-at-point 'sexp) does not handle spaces in filename in dired buffer.
Oleg Pavliv
Yes, you are right, I can define my own parser. Even easier, I can loop forward (then backward) one character at time until it changed the face. This way I can find bounds. But my question was about using something existing, a standard solution for this seemingly standard task.
Oleg Pavliv
+1  A: 

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?)

PanCrit
Dired buffer is displayed using different faces - dired-header (e.g. the very first line in dired buffer), dired-directory, etc. My question was what "thing" is at point and how to determine bounds (beginning and end) of the thing.
Oleg Pavliv
Oleg, you're repeating your question using the same words. If you want a different answer, it would be useful to provide more or different information. Why do you care about point rather than the current line? Why do you want to know the bounds, when you could use a regex to find the entire file name?
PanCrit
+1  A: 

These functions might be helpful in concocting what you want:

  • dired-get-filename
  • dired-move-to-filename
  • dired-move-to-end-of-filename
  • file-directory-p and friends
huaiyuan
yes, it's what i was looking for. thanks a lot
Oleg Pavliv