From e28cbee448dfc5548d37fa6f9f76896529c3cecb Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Wed, 6 May 2026 14:59:52 -0700 Subject: [PATCH] emacs: disable dbus and gvfs backends --- dotfiles/emacs.d/README.org | 14 ++--- dotfiles/emacs.d/init.el | 9 +++ dotfiles/emacs.d/lisp/dbus.el | 93 +++++++++++++++++++++++++++++ dotfiles/emacs.d/lisp/tramp-gvfs.el | 41 +++++++++++++ 4 files changed, 148 insertions(+), 9 deletions(-) create mode 100644 dotfiles/emacs.d/lisp/dbus.el create mode 100644 dotfiles/emacs.d/lisp/tramp-gvfs.el diff --git a/dotfiles/emacs.d/README.org b/dotfiles/emacs.d/README.org index 1c44cc66..0f933cfa 100644 --- a/dotfiles/emacs.d/README.org +++ b/dotfiles/emacs.d/README.org @@ -3649,9 +3649,8 @@ I don't use iedit directly, but it is used by [[*emr][emr]] and I need to disabl :ensure nil :commands tramp :init - ;; Avoid TRAMP's GVFS backend on sessions where org.gtk.vfs.Daemon is not - ;; activatable. Buffer/recent-file completion can otherwise trigger noisy - ;; DBus ServiceUnknown errors while inspecting TRAMP candidates. + ;; Avoid TRAMP's GVFS backend entirely. It depends on D-Bus/GVFS desktop + ;; services, while this config uses ordinary TRAMP methods. (setq tramp-gvfs-methods nil) :config (setq tramp-default-method "scp") @@ -3668,12 +3667,9 @@ I don't use iedit directly, but it is used by [[*emr][emr]] and I need to disabl #+END_SRC ** dbus #+BEGIN_SRC emacs-lisp -(with-eval-after-load 'dbus - ;; This hook reports even handled DBus errors in the echo area. That is - ;; usually noise in this config, especially during completion paths which may - ;; probe optional desktop services. - (remove-hook 'dbus-event-error-functions - #'dbus-notice-synchronous-call-errors)) +;; D-Bus is disabled by lisp/dbus.el, which shadows Emacs' built-in dbus.el. +;; Keep the event hook empty in case another environment loads the real library. +(setq dbus-event-error-functions nil) #+END_SRC ** narrow-indirect #+BEGIN_SRC emacs-lisp diff --git a/dotfiles/emacs.d/init.el b/dotfiles/emacs.d/init.el index 0dc3e641..60a58a86 100644 --- a/dotfiles/emacs.d/init.el +++ b/dotfiles/emacs.d/init.el @@ -10,6 +10,15 @@ (defun emacs-directory-filepath (filename) (expand-file-name filename user-emacs-directory)) +(add-to-list 'load-path (emacs-directory-filepath "lisp")) + +;; Treat this Emacs as if it was built without D-Bus. The local +;; lisp/dbus.el shim prevents `require' from loading the built-in dbus.el, +;; whose top-level form eagerly opens system and session bus connections. +(setq features (delq 'dbusbind features)) +(setq dbus-compiled-version nil + dbus-runtime-version nil) + (load-file (expand-file-name "elpaca-installer.el" user-emacs-directory)) ;; Elpaca's initial queue logger can fire during self-bootstrap before its diff --git a/dotfiles/emacs.d/lisp/dbus.el b/dotfiles/emacs.d/lisp/dbus.el new file mode 100644 index 00000000..7a3e0e34 --- /dev/null +++ b/dotfiles/emacs.d/lisp/dbus.el @@ -0,0 +1,93 @@ +;;; dbus.el --- Disabled D-Bus shim -*- lexical-binding: t; -*- + +;;; Commentary: +;; This file intentionally shadows Emacs' built-in net/dbus.el. Loading the +;; built-in library initializes D-Bus connections at top level, which is noisy +;; and fragile in this configuration. + +;;; Code: + +(setq features (delq 'dbusbind features)) +(setq dbus-compiled-version nil + dbus-runtime-version nil) + +(unless (boundp 'dbus-error) + (define-error 'dbus-error "D-Bus disabled in this Emacs config")) + +(defvar dbus-debug nil) +(defvar dbus-event-error-functions nil) +(defvar dbus-registered-objects-table (make-hash-table :test #'equal)) + +(defconst dbus-service-dbus "org.freedesktop.DBus") +(defconst dbus-path-dbus "/org/freedesktop/DBus") +(defconst dbus-path-local "/org/freedesktop/DBus/Local") +(defconst dbus-interface-dbus "org.freedesktop.DBus") +(defconst dbus-interface-peer "org.freedesktop.DBus.Peer") +(defconst dbus-interface-introspectable "org.freedesktop.DBus.Introspectable") +(defconst dbus-interface-properties "org.freedesktop.DBus.Properties") +(defconst dbus-interface-objectmanager "org.freedesktop.DBus.ObjectManager") +(defconst dbus-interface-monitoring "org.freedesktop.DBus.Monitoring") +(defconst dbus-interface-local "org.freedesktop.DBus.Local") +(defconst dbus-service-emacs "org.gnu.Emacs") +(defconst dbus-path-emacs "/org/gnu/Emacs") +(defconst dbus-interface-emacs "org.gnu.Emacs") + +(defconst dbus-error-dbus "org.freedesktop.DBus.Error") +(defconst dbus-error-failed "org.freedesktop.DBus.Error.Failed") +(defconst dbus-error-service-unknown "org.freedesktop.DBus.Error.ServiceUnknown") + +(defmacro dbus-ignore-errors (&rest body) + "Execute BODY, suppressing `dbus-error' unless `dbus-debug' is non-nil." + (declare (indent 0) (debug t)) + `(condition-case err + (progn ,@body) + (dbus-error (when dbus-debug (signal (car err) (cdr err)))))) + +(defun imalison:dbus-disabled (&rest _args) + "Signal that D-Bus is intentionally unavailable in this config." + (signal 'dbus-error '("D-Bus disabled in this Emacs config"))) + +(dolist (function + '(dbus-call-method + dbus-call-method-asynchronously + dbus-send-signal + dbus-method-return-internal + dbus-method-error-internal + dbus-register-service + dbus-unregister-service + dbus-register-signal + dbus-register-method + dbus-unregister-object + dbus-register-property + dbus-register-monitor + dbus-init-bus + dbus-ping + dbus-introspect + dbus-introspect-xml + dbus-get-property + dbus-set-property + dbus-get-all-properties + dbus-get-all-managed-objects)) + (defalias function #'imalison:dbus-disabled)) + +(defun dbus-list-activatable-names (&optional _bus) nil) +(defun dbus-list-names (&optional _bus) nil) +(defun dbus-list-known-names (&optional _bus) nil) +(defun dbus-list-queued-owners (&rest _args) nil) +(defun dbus-get-name-owner (&rest _args) nil) +(defun dbus-list-hash-table () nil) + +(defun dbus-event-bus-name (_event) nil) +(defun dbus-event-message-type (_event) nil) +(defun dbus-event-serial-number (_event) nil) +(defun dbus-event-service-name (_event) nil) +(defun dbus-event-destination-name (_event) nil) +(defun dbus-event-path-name (_event) nil) +(defun dbus-event-interface-name (_event) nil) +(defun dbus-event-member-name (_event) nil) +(defun dbus-event-handler (_event) nil) +(defun dbus-event-arguments (_event) nil) + +(provide 'dbus) + +;;; dbus.el ends here diff --git a/dotfiles/emacs.d/lisp/tramp-gvfs.el b/dotfiles/emacs.d/lisp/tramp-gvfs.el new file mode 100644 index 00000000..bbc9b4e5 --- /dev/null +++ b/dotfiles/emacs.d/lisp/tramp-gvfs.el @@ -0,0 +1,41 @@ +;;; tramp-gvfs.el --- Disabled TRAMP GVFS backend -*- lexical-binding: t; -*- + +;;; Commentary: +;; This file intentionally shadows Emacs' built-in net/tramp-gvfs.el. The real +;; backend depends on D-Bus and GVFS desktop services; this config uses ordinary +;; TRAMP methods instead. + +;;; Code: + +(require 'tramp) + +(defconst tramp-gvfs-enabled nil + "Non-nil when the disabled GVFS backend is available.") + +(defvar tramp-gvfs-methods nil + "Disabled list of TRAMP methods handled through GVFS.") +(setq tramp-gvfs-methods nil) + +(defconst tramp-goa-methods nil + "Disabled list of GNOME Online Accounts TRAMP methods.") + +(defvar tramp-media-methods nil + "Disabled list of media-device TRAMP methods.") +(setq tramp-media-methods nil) + +(defvar tramp-gvfs-file-name-handler-alist nil + "Disabled GVFS file name handler alist.") + +(defun tramp-gvfs-file-name-p (_filename) + "Return nil because the GVFS backend is disabled." + nil) + +(defun tramp-gvfs-file-name-handler (operation &rest args) + "Signal an unsupported OPERATION for the disabled GVFS backend." + (signal 'file-error + (list "TRAMP GVFS backend disabled in this Emacs config" + operation args))) + +(provide 'tramp-gvfs) + +;;; tramp-gvfs.el ends here