3 (defun my-find-file-at-point-with-line ()
4 "Opens the file at point and goes to line-number."
6 (let ((fname (ffap-file-at-point)))
10 (goto-char (cadr ffap-string-at-point-region))
11 (and (re-search-backward ":\\([0-9]+\\)"
12 (line-beginning-position) t)
13 (string-to-int (match-string 1))))))
14 ;; (message "file:%s,line:%s" fname line)
15 (when (and (tramp-tramp-file-p default-directory)
16 (= ?/ (aref fname 0)))
17 ;; if fname is an absolute path in remote machine, it will not return a tramp path,fix it here.
18 (let ((pos (position ?: default-directory)))
19 (if (not pos) (error "failed find first tramp indentifier ':'"))
20 (setf pos (position ?: default-directory :start (1+ pos)))
21 (if (not pos) (error "failed find second tramp indentifier ':'"))
22 (setf fname (concat (substring default-directory 0 (1+ pos)) fname))))
23 (message "fname:%s" fname)
24 (find-file-existing fname)
25 (when line (goto-line line)))
26 (error "File does not exist."))))
28 (global-set-key (kbd "C-c C-x C-f") 'my-find-file-at-point-with-line)