Hi Antoine,
2016-02-11 21:19 GMT+01:00 Antoine Levitt <[email protected]>:
> Close: (when (equal "evince" app) :uint32 0) returns nil if app != evince,
> which gets transmitted to dbus as the boolean false. I'm not sure how to do
> this without duplicating the call?
>
> Other than that, works great under my version of atril. Thanks!
Thank you so much for reporting this problem. Looking better at that
function I also noticed that only "0" was actually passed as argument
of `dbus-call-method', as 0 is the last form of `when''s body. I
think the attached patch cures both bugs. Please, tell me if it works
for you.
Bye,
Mosè
diff --git a/tex.el b/tex.el
index 090965e..f8de86b 100644
--- a/tex.el
+++ b/tex.el
@@ -1178,28 +1178,38 @@ The following built-in predicates are available:
:group 'TeX-view
:type '(alist :key-type symbol :value-type (group sexp)))
+;; XXX: Atril is a fork of Evince and shares an almost identical interface with
+;; it. Instead of having different functions for each program, we keep the
+;; original *-evince-* functions and make them accept arguments to specify the
+;; actual name of the program and the desktop environment, that will be used to
+;; set up DBUS communication.
+
;; Require dbus at compile time to prevent errors due to `dbus-ignore-errors'
;; not being defined.
(eval-when-compile (and (featurep 'dbusbind)
(require 'dbus nil :no-error)))
-(defun TeX-evince-dbus-p (&rest options)
- "Return non-nil, if evince is installed and accessible via DBUS.
+(defun TeX-evince-dbus-p (de app &rest options)
+ "Return non-nil, if atril or evince are installed and accessible via DBUS.
Additional OPTIONS may be given to extend the check. If none are
given, only the minimal requirements needed by backward search
are checked. If OPTIONS include `:forward', which is currently
the only option, then additional requirements needed by forward
-search are checked, too."
+search are checked, too.
+
+DE is the name of the desktop environment, either \"gnome\" or
+\"mate\", APP is the name of viewer, either \"evince\" or
+\"atril\"."
(let ((dbus-debug nil))
(and (featurep 'dbusbind)
(require 'dbus nil :no-error)
(dbus-ignore-errors (dbus-get-unique-name :session))
- (dbus-ping :session "org.gnome.evince.Daemon")
- (executable-find "evince")
+ (dbus-ping :session (format "org.%s.%s.Daemon" de app))
+ (executable-find app)
(or (not (memq :forward options))
(let ((spec (dbus-introspect-get-method
- :session "org.gnome.evince.Daemon"
- "/org/gnome/evince/Daemon"
- "org.gnome.evince.Daemon"
+ :session (format "org.%s.%s.Daemon" de app)
+ (format "/org/%s/%s/Daemon" de app)
+ (format "org.%s.%s.Daemon" de app)
"FindDocument")))
;; FindDocument must exist, and its signature must be (String,
;; Boolean, String). Evince versions between 2.30 and 2.91.x
@@ -1236,19 +1246,23 @@ entry in `TeX-view-program-list-builtin'."
(defvar url-unreserved-chars)
-(defun TeX-evince-sync-view ()
+(defun TeX-evince-sync-view-1 (de app)
"Focus the focused page/paragraph in Evince with the position
of point in emacs by using Evince's DBUS API. Used by default
-for the Evince viewer entry in `TeX-view-program-list-builtin' if
-the requirements are met."
+for the Atril or Evince entries in
+`TeX-view-program-list-builtin' if the requirements are met.
+
+DE is the name of the desktop environment, either \"gnome\" or
+\"mate\", APP is the name of viewer, either \"evince\" or
+\"atril\"."
(require 'url-util)
(let* ((uri (concat "file://" (url-encode-url
(expand-file-name
(concat file "." (TeX-output-extension))))))
(owner (dbus-call-method
- :session "org.gnome.evince.Daemon"
- "/org/gnome/evince/Daemon"
- "org.gnome.evince.Daemon"
+ :session (format "org.%s.%s.Daemon" de app)
+ (format "/org/%s/%s/Daemon" de app)
+ (format "org.%s.%s.Daemon" de app)
"FindDocument"
uri
t)))
@@ -1256,15 +1270,27 @@ the requirements are met."
(with-current-buffer (or (when TeX-current-process-region-p
(get-file-buffer (TeX-region-file t)))
(current-buffer))
- (dbus-call-method
- :session owner
- "/org/gnome/evince/Window/0"
- "org.gnome.evince.Window"
- "SyncView"
- (buffer-file-name)
- (list :struct :int32 (line-number-at-pos) :int32 (1+ (current-column)))
- :uint32 0))
- (error "Couldn't find the Evince instance for %s" uri))))
+ (apply
+ #'dbus-call-method
+ (append
+ `(:session ,owner
+ ,(format "/org/%s/%s/Window/0" de app)
+ ,(format "org.%s.%s.Window" de app)
+ "SyncView"
+ ,(buffer-file-name)
+ ,(list :struct :int32 (line-number-at-pos)
+ :int32 (1+ (current-column))))
+ ;; Atril doesn't want this addional argument.
+ (when (equal "evince" app) '(:uint32 0)))))
+ (error "Couldn't find the %s instance for %s" (capitalize app) uri))))
+
+(defun TeX-atril-sync-view ()
+ "Run `TeX-evince-sync-view-1', which see, set up for Atril."
+ (TeX-evince-sync-view-1 "mate" "atril"))
+
+(defun TeX-evince-sync-view ()
+ "Run `TeX-evince-sync-view-1', which see, set up for Evince."
+ (TeX-evince-sync-view-1 "gnome" "evince"))
(defvar TeX-view-program-list-builtin
(cond
@@ -1298,7 +1324,7 @@ the requirements are met."
("dvips and gv" "%(o?)dvips %d -o && gv %f" ,(list "%(o?)dvips" "gv"))
("gv" "gv %o" "gv")
("xpdf" ("xpdf -remote %s -raise %o" (mode-io-correlate " %(outpage)")) "xpdf")
- ("Evince" ,(if (TeX-evince-dbus-p :forward)
+ ("Evince" ,(if (TeX-evince-dbus-p "gnome" "evince" :forward)
'TeX-evince-sync-view
`("evince" (mode-io-correlate
;; With evince 3, -p N opens the page *labeled* N,
@@ -1307,6 +1333,15 @@ the requirements are met."
(shell-command-to-string "evince --help"))
" -i %(outpage)"
" -p %(outpage)")) " %o")) "evince")
+ ("Atril" ,(if (TeX-evince-dbus-p "mate" "atril" :forward)
+ 'TeX-atril-sync-view
+ `("atril" (mode-io-correlate
+ ;; With evince 3, -p N opens the page *labeled* N,
+ ;; and -i,--page-index the physical page N.
+ ,(if (string-match "--page-index"
+ (shell-command-to-string "atril --help"))
+ " -i %(outpage)"
+ " -p %(outpage)")) " %o")) "atril")
("Okular" ("okular --unique %o" (mode-io-correlate "#src:%n%a")) "okular")
("xdg-open" "xdg-open %o" "xdg-open")
("PDF Tools" TeX-pdf-tools-sync-view)
@@ -1314,7 +1349,7 @@ the requirements are met."
("zathura %o"
(mode-io-correlate
" --synctex-forward %n:0:%b -x \"emacsclient +%{line} %{input}\""))
- "zathura"))))
+ "zathura"))))
"Alist of built-in viewer specifications.
This variable should not be changed by the user who can use
`TeX-view-program-list' to add new viewers or overwrite the
@@ -1822,12 +1857,14 @@ SyncTeX are recognized."
TeX-source-correlate-map))
(TeX-set-mode-name 'TeX-source-correlate-mode t t)
(setq TeX-source-correlate-start-server-flag TeX-source-correlate-mode)
- ;; Register Emacs for the SyncSource DBUS signal emitted by Evince.
- (when (TeX-evince-dbus-p)
- (dbus-register-signal
- :session nil "/org/gnome/evince/Window/0"
- "org.gnome.evince.Window" "SyncSource"
- 'TeX-source-correlate-sync-source)))
+ ;; Register Emacs for the SyncSource DBUS signal emitted by Evince or Atril.
+ (dolist (de-app '(("gnome" "evince") ("mate" "atril")))
+ (when (TeX-evince-dbus-p (car de-app) (cadr de-app))
+ (dbus-register-signal
+ :session nil (format "/org/%s/%s/Window/0" (car de-app) (cadr de-app))
+ (format "org.%s.%s.Window" (car de-app) (cadr de-app))
+ "SyncSource"
+ 'TeX-source-correlate-sync-source))))
(defalias 'TeX-source-specials-mode 'TeX-source-correlate-mode)
(make-obsolete 'TeX-source-specials-mode 'TeX-source-correlate-mode "11.86")
_______________________________________________
bug-auctex mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-auctex