Skip to main content
added 1620 characters in body
Source Link

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.")))))

Lisp function org-show-context works.

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.")))))
Notice added Needs detailed answers by user12563
added 2 characters in body
Source Link
Drew
  • 79.1k
  • 10
  • 123
  • 257

lispLisp function org-show-contextorg-show-context works.

lisp function org-show-context works.

Lisp function org-show-context works.

Source Link

lisp function org-show-context works.