From c9078c505b017f6caded2c07741145f174418fed Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Tue, 5 May 2026 19:45:28 +0300 Subject: [PATCH] Improve 'context-menu-send-to' (bug#79512) * lisp/mouse.el (context-menu-functions): Add missing 'context-menu-send-to' to :type. (context-menu-send-to): Get non-nil items to avoid useless message "Nothing to send". * lisp/send-to.el (send-to-handlers): Change from 'defvar-local' to 'defvar' to allow easier global configuration. (send-to-supported-p): Check for non-nil handler. --- lisp/mouse.el | 13 +++++++++---- lisp/send-to.el | 16 +++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lisp/mouse.el b/lisp/mouse.el index 24fe57cdc50..20c819ee0a8 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el @@ -407,6 +407,7 @@ and should return the same menu with changes such as added new menu items." (function-item context-menu-global) (function-item context-menu-local) (function-item context-menu-minor) + (function-item context-menu-send-to) (function-item context-menu-buffers) (function-item context-menu-project) (function-item context-menu-vc) @@ -541,12 +542,16 @@ Some context functions add menu items below the separator." (defun context-menu-send-to (menu _click) "Add a \"Send to...\" context MENU entry on supported platforms." (run-hooks 'activate-menubar-hook 'menu-bar-update-hook) - (when (send-to-supported-p) + (when-let* ((_ (send-to-supported-p)) + (handler (send-to--resolve-handler)) + (collect (map-elt handler :collect)) + (items (funcall collect))) (define-key-after menu [separator-send] menu-bar-separator) (define-key-after menu [send] - '(menu-item "Send to..." (lambda () - (interactive) - (send-to)) + `(menu-item "Send to..." + ,(lambda () + (interactive) + (send-to items)) :help "Send item (region, buffer file, or Dired files) to applications or service"))) menu) diff --git a/lisp/send-to.el b/lisp/send-to.el index b4c3c339029..f1795cfa7a0 100644 --- a/lisp/send-to.el +++ b/lisp/send-to.el @@ -47,12 +47,13 @@ :group 'external :version "31.1") -(defvar-local send-to-handlers '(((:supported . send-to--ns-supported-p) - (:collect . send-to--collect-items) - (:send . send-to--ns-send-items)) - ((:supported . send-to--open-externally-supported-p) - (:collect . send-to--collect-items) - (:send . send-to--open-externally))) +(defvar send-to-handlers + '(((:supported . send-to--ns-supported-p) + (:collect . send-to--collect-items) + (:send . send-to--ns-send-items)) + ((:supported . send-to--open-externally-supported-p) + (:collect . send-to--collect-items) + (:send . send-to--open-externally))) "A list of handlers that may be able to send files to applications or services. Sending is handled by the first supported handler from `send-to-handlers' whose @@ -82,7 +83,8 @@ paths known to exist. In these instances, files will be sent instead.\" ;;;###autoload (defun send-to-supported-p () "Return non-nil for platforms where `send-to' is supported." - (funcall (map-elt (send-to--resolve-handler) :supported))) + (when-let* ((handler (send-to--resolve-handler))) + (funcall (map-elt handler :supported)))) ;;;###autoload (defun send-to (&optional items)