When one invoke org-edit-special at the line containing an #+INCLUDE, it opens a new buffer with the referenced file. Although, if an #+INCLUDE contains the :lines clause it will not respect what is written in it.

Is there a method to enforce opening file at the place referenced by the :lines parameter?

1 Answer 1


If you look at the source code for org-edit-special, you'll see that all it's doing when called on a line containing #+INCLUDE, is calling org-open-link-from-string with the filename as a string.

In that sense the answer is no, there is currently no Org built-in setting you can change to have org-edit-special respect the :lines clause.

You could hack org-open-link-from-string such that it takes an additional optional argument linenum, and hack org-edit-special to read the line number from your :lines clause and pass it to org-open-link-from-string.

Something like (UNTESTED):

(defun org-open-link-from-string (s &optional arg reference-buffer linenum)
  "Open a link in the string S, as if it was in Org mode."
  (interactive "sLink: \nP")
  (let ((reference-buffer (or reference-buffer (current-buffer))))
      (let ((org-inhibit-startup (not reference-buffer)))
    (insert s)
    (goto-char (point-min))
    (goto-line linenum)  ;;;;;;;; ADD THIS LINE ;;;;;;;;;;;
    (when reference-buffer
      (setq org-link-abbrev-alist-local
        (with-current-buffer reference-buffer
    (org-open-at-point arg reference-buffer)))))

and in org-edit-special change this line:

(t (user-error "No valid file specified")))))))

to something like this:

(t (user-error "No valid file specified"))))))
  nil nil ((string-match ":lines +\"\\(\\(?:[0-9]+\\)?-\\(?:[0-9]+\\)?\\)\"" value)
            (match-string 1 value))

I guess this could be done with simple advices, but I wouldn't know how.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.