I use to edit LaTeX
documents with okular
as pdf viewer in Ubuntu Linux. I have this code:
(defun okular-forward-search ()
(interactive)
(start-process
"okular"
"okular-output"
"okular" ;;; src-args
;;; args for -sourceposition:
"--unique"
(concat
"file:"
(concat (file-name-sans-extension (buffer-file-name)) ".pdf")
"#src:"
(number-to-string (line-number-at-pos (point)))
(buffer-file-name))))
that performs forward-search from LaTeX
code in emacs
to the corresponding page in the generated .pdf
file. My problem is that this shift the "focus" from emacs
to okular
and this is, for me, very annoying.
Is there a hack to keep the focus on emacs?
EDIT I modified the function:
(defun okular-forward-search-mod ()
(interactive)
(call-process-shell-command
(concat "okular --unique file:" (concat (file-name-sans-extension (buffer-file-name)) ".pdf")
"#src:"
(number-to-string (line-number-at-pos (point)))
(buffer-file-name))
)
(call-process-shell-command "wmctrl -a emacs"))
But I still have an issue. If more instances of emacs
are open the focus is on the first opened.
How can I get the window PID of the current emacs
' process?