Lisp function org-show-context
works.
This is the command used by me to open file at point.
(defun my-find-file-at-point-with-line ()
"Opens the file at point and goes to line-number."
(interactive)
;; TODO: support file like "d:\\asbc\\dd.txt"
(if (eq major-mode 'org-mode)
(org-open-at-point)
(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))))
(find-file-existing fname)
(when line (goto-line line))
;; make sure context in point is visible.
(when (and buffer-file-name (string-match "\\.org$" buffer-file-name))
(org-show-context)))
(warn "File does not exist.")))))