There’s various mode-specific features hiding in ffap,
Here are some other libraries and modes extending
‘M-x anything-for-files’use ffap and much more
ffap-c-pathfrom GCC include path
(setq ffap-rfc-path "/email@example.com:/in-notes/rfc%s.txt")
(defvar my-texlive-db-path '("D:\\texlive\\2009\\texmf" "D:\\texlive\\2009\\texmf-dist")) (defun ffap-locate-tex-path (pakname) (save-excursion (save-match-data (when (re-search-forward (concat "^" pakname "$") nil t) ;; if we found (re-search-backward "\\(\\..*\\):$" nil t) (concat (file-name-as-directory (concat (file-name-as-directory dbpath) (match-string 1))) pakname))))) (defun ffap-locate-tex-file (pakname suffix paths) (catch 'break (let (r) (dolist (dbpath paths) (with-temp-buffer (condition-case nil (progn (insert-file-contents (concat (file-name-as-directory dbpath) "ls-R")) (dolist (suf suffix) (setq r (ffap-locate-tex-path (concat pakname suf))) (if r (throw 'break r)))) (error nil))))))) (eval-after-load "ffap" '(progn (defun ffap-tex-mode (name) (ffap-tex-init) (ffap-locate-tex-file name '(".tex" "") my-texlive-db-path)) (defun ffap-latex-mode (name) (ffap-tex-init) ;; only rare need for "" (ffap-locate-tex-file name '(".cls" ".sty" ".tex" "") my-texlive-db-path)) ))
On unix based systems, / is the root path. So all string starts with / is recognized as a path.
This is annoying especially when editing HTML or XML. The following advice ignore / as a wrong result.
(defadvice ffap-file-at-point (after ffap-file-at-point-after-advice ()) (if (string= ad-return-value "/") (setq ad-return-value nil))) (ad-activate 'ffap-file-at-point) ;; (ad-deactivate 'ffap-file-at-point)
– tomykaira, feel free to use this snippet in any way.
At this time when you open an absolute path in a remote tramp buffer, it will open this file locally. I wrote a new function to fix this and make the line number recognition enhanced.
(defun my-find-file-at-point-with-line () "Opens the file at point and goes to line-number." (interactive) (let ((fname (ffap-file-at-point))) (if fname (let ((line (save-excursion (goto-char (cadr ffap-string-at-point-region)) (and (re-search-backward ":\\([0-9]+\\)" (line-beginning-position) t) (string-to-int (match-string 1)))))) ;; (message "file:%s,line:%s" fname line) (when (and (tramp-tramp-file-p default-directory) (= ?/ (aref fname 0))) ;; if fname is an absolute path in remote machine, it will not return a tramp path,fix it here. (let ((pos (position ?: default-directory))) (if (not pos) (error "failed find first tramp indentifier ':'")) (setf pos (position ?: default-directory :start (1+ pos))) (if (not pos) (error "failed find second tramp indentifier ':'")) (setf fname (concat (substring default-directory 0 (1+ pos)) fname)))) (message "fname:%s" fname) (find-file-existing fname) (when line (goto-line line))) (error "File does not exist."))))
Maybe I’m missing something, but it sounds like you are reporting an Emacs (Tramp) bug here, together with a workaround/fix. If so, why don’t you report the bug to the Tramp maintainer?
‘M-x report-emacs-bug’ – DrewAdams