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 "/firstname.lastname@example.org:/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-number (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
You can open a Java source file or directory from the import statement in Java. The location of the source must be known to work via
ffap-java/source-directories. The source should be either a directory name that contains the sources, or a jar archive name that contains the sources. Download the source here. – cinsk
Useful e.g. for output from
grep -nH. Expects
(defvar ffap-file-at-point-line-number nil "Variable to hold line number from the last `ffap-file-at-point' call.") (defadvice ffap-file-at-point (after ffap-store-line-number activate) "Search `ffap-string-at-point' for a line number pattern and save it in `ffap-file-at-point-line-number' variable." (let* ((string (ffap-string-at-point)) ;; string/name definition copied from `ffap-string-at-point' (name (or (condition-case nil (and (not (string-match "//" string)) ; foo.com://bar (substitute-in-file-name string)) (error nil)) string)) (line-number-string (and (string-match ":[0-9]+" name) (substring name (1+ (match-beginning 0)) (match-end 0)))) (line-number (and line-number-string (string-to-number line-number-string)))) (if (and line-number (> line-number 0)) (setq ffap-file-at-point-line-number line-number) (setq ffap-file-at-point-line-number nil)))) (defadvice find-file-at-point (after ffap-goto-line-number activate) "If `ffap-file-at-point-line-number' is non-nil goto this line." (when ffap-file-at-point-line-number (goto-line ffap-file-at-point-line-number) (setq ffap-file-at-point-line-number nil)))