How to get emacs to highlight and link file paths

Solution 1:

There's probably a package that does this already, but I don't know of it.

This bit of code adds buttons to text it thinks looks like a path to a file. You can add the function 'buttonize-buffer to find-file-hooks or run it manually (or conditionally).

(define-button-type 'find-file-button
  'follow-link t
  'action #'find-file-button)

(defun find-file-button (button)
  (find-file (buffer-substring (button-start button) (button-end button))))

(defun buttonize-buffer ()
  "turn all file paths into buttons"
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (while (re-search-forward "/[^ \t]*" nil t)
      (make-button (match-beginning 0) (match-end 0) :type 'find-file-button))))

; (add-hook 'find-file-hook 'buttonize-buffer)   ; uncomment to add to find file

Solution 2:

Try the built-in package ffap (find file at point):

http://www.emacswiki.org/emacs/FindFileAtPoint

http://www.gnu.org/software/emacs/manual/html_node/emacs/FFAP.html

I don't use the minor mode, instead binding a key to ffap that I hit when on a filename.