The following Elisp code enables you to open files at specified lines with emacsclient via
The format of the
org-protocol is like you specified it with the addition of the key
read-only. You can give that key any value to open the file in
(defvar org-protocol-open-file-at-line nil
"A property list used by `org-protocol-server-visit-hook-fun'.")
(defun org-protocol-server-visit-hook-fun ()
"Jump to line number detected by `org-protocol-open-file'.
Transferred from `org-protocol-open-file' via variable `org-protocol-open-file-at-line'."
(let ((file (plist-get org-protocol-open-file-at-line :file))
(line (1- (string-to-number (or (plist-get org-protocol-open-file-at-line :line) "1")))))
(when (file-equal-p file (buffer-file-name))
(unless (plist-get org-protocol-open-file-at-line :read-only)
(goto-char (point-min)) ;; should actually already be there...
(add-hook 'server-visit-hook #'org-protocol-server-visit-hook-fun)
(defun org-protocol-open-file (pars)
"Act as org-protocol-protocol-alist function with PARS as args.
Handle links like: org-protocol://open-file?file=/foo/ss/subdir/foo.js&line=132"
(let ((file (plist-get pars :file)))
(setq org-protocol-open-file-at-line pars)
(and (file-exists-p file)
My previous answer was:
See the the page on External Links in the org manual.
There you find the entry:
file:sometextfile::NNN file, jump to line number
NNNN stands for a number.
Your example would look like follows: