1

We can open a file in gVim at line 99:

$ gvim file +99 &

With the same file open in Emacs, I can open it in gVim:

(when (eq system-type 'gnu/linux)
    (global-set-key (kbd "C-c g") (lambda ()
        (interactive)
        (call-process "gvim" nil 0 nil buffer-file-name)
        (message "opened in gVim"))))

We can get the line number at point:

(string-to-number (format-mode-line "%l"))

I can't figure how to add that line number into my Emacs call to gVim such that the latter opens at the same line number. I suppose it's something like this:

(call-process "gvim" nil 0 nil (buffer-file-name +(string-to-number (format-mode-line "%l"))))

Any ideas how to correctly add in that line number?

joharr
  • 113
  • 4

1 Answers1

2

Use the format function to construct a string from pieces. Also, use line-number-at-pos to get the current line numbers, which lets you get the correct number even if the buffer is narrowed.

(call-process "gvim" nil 0 nil
              buffer-file-name
              (format "+%d" (line-number-at-pos nil t)))