From 5ddf8b9b51c8e4053889207d335b2c785c8214e1 Mon Sep 17 00:00:00 2001 From: "Itai Y. Efrat" Date: Fri, 21 May 2021 00:43:27 +0300 Subject: [PATCH] featuregate ivy dependent autoloads for irc, pass previously these functions would get autoloaded even when another completion framework was active --- modules/app/irc/autoload/irc.el | 37 ++++------------------------- modules/app/irc/autoload/ivy.el | 30 +++++++++++++++++++++++ modules/app/irc/config.el | 3 +-- modules/tools/pass/autoload/ivy.el | 21 ++++++++++++++++ modules/tools/pass/autoload/pass.el | 32 ------------------------- 5 files changed, 57 insertions(+), 66 deletions(-) create mode 100644 modules/app/irc/autoload/ivy.el create mode 100644 modules/tools/pass/autoload/ivy.el diff --git a/modules/app/irc/autoload/irc.el b/modules/app/irc/autoload/irc.el index 2f6434af6f3..8f701d648dc 100644 --- a/modules/app/irc/autoload/irc.el +++ b/modules/app/irc/autoload/irc.el @@ -63,40 +63,13 @@ workspace for it." (+workspace/delete +irc--workspace-name))))) ;;;###autoload -(defun +irc/ivy-jump-to-channel (&optional this-server) - "Jump to an open channel or server buffer with ivy. If THIS-SERVER (universal +(defun +irc/jump-to-channel (&optional this-server) + "Jump to an open channel or server buffer. If THIS-SERVER (universal argument) is non-nil only show channels in current server." (interactive "P") - (if (not (circe-server-buffers)) - (message "No circe buffers available") - (when (and this-server (not circe-server-buffer)) - (setq this-server nil)) - (ivy-read (format "Jump to%s: " (if this-server (format " (%s)" (buffer-name circe-server-buffer)) "")) - (cl-loop with servers = (if this-server (list circe-server-buffer) (circe-server-buffers)) - with current-buffer = (current-buffer) - for server in servers - collect (buffer-name server) - nconc - (with-current-buffer server - (cl-loop for buf in (circe-server-chat-buffers) - unless (eq buf current-buffer) - collect (format " %s" (buffer-name buf))))) - :action #'+irc--ivy-switch-to-buffer-action - :preselect (buffer-name (current-buffer)) - :keymap ivy-switch-buffer-map - :caller '+irc/ivy-jump-to-channel))) - -(defun +irc--ivy-switch-to-buffer-action (buffer) - (when (stringp buffer) - (ivy--switch-buffer-action (string-trim-left buffer)))) - -;;;###autoload -(defun +irc/tracking-next-buffer () - "Disables switching to an unread buffer unless in the irc workspace." - (interactive) - (when (derived-mode-p 'circe-mode) - (tracking-next-buffer))) - + (call-interactively + (cond ((featurep! :completion ivy) #'+irc/ivy-jump-to-channel) + ((user-error "No jump-to-channel backend is enabled. Enable ivy!"))))) ;; ;;; Hooks/fns diff --git a/modules/app/irc/autoload/ivy.el b/modules/app/irc/autoload/ivy.el new file mode 100644 index 00000000000..7fc06fc138a --- /dev/null +++ b/modules/app/irc/autoload/ivy.el @@ -0,0 +1,30 @@ +;;; app/irc/autoload/ivy.el -*- lexical-binding: t; -*- +;;;###if (featurep! :completion ivy) + +;;;###autoload +(defun +irc/ivy-jump-to-channel (&optional this-server) + "Jump to an open channel or server buffer with ivy. If THIS-SERVER (universal +argument) is non-nil only show channels in current server." + (interactive "P") + (if (not (circe-server-buffers)) + (message "No circe buffers available") + (when (and this-server (not circe-server-buffer)) + (setq this-server nil)) + (ivy-read (format "Jump to%s: " (if this-server (format " (%s)" (buffer-name circe-server-buffer)) "")) + (cl-loop with servers = (if this-server (list circe-server-buffer) (circe-server-buffers)) + with current-buffer = (current-buffer) + for server in servers + collect (buffer-name server) + nconc + (with-current-buffer server + (cl-loop for buf in (circe-server-chat-buffers) + unless (eq buf current-buffer) + collect (format " %s" (buffer-name buf))))) + :action #'+irc--ivy-switch-to-buffer-action + :preselect (buffer-name (current-buffer)) + :keymap ivy-switch-buffer-map + :caller '+irc/ivy-jump-to-channel))) + +(defun +irc--ivy-switch-to-buffer-action (buffer) + (when (stringp buffer) + (ivy--switch-buffer-action (string-trim-left buffer)))) diff --git a/modules/app/irc/config.el b/modules/app/irc/config.el index 6730d59398f..a232c9fa250 100644 --- a/modules/app/irc/config.el +++ b/modules/app/irc/config.el @@ -149,8 +149,7 @@ playback.") "p" #'circe-command-PART "Q" #'+irc/quit "R" #'circe-reconnect - (:when (featurep! :completion ivy) - "c" #'+irc/ivy-jump-to-channel)) + "c" #'+irc/jump-to-channel) (:map circe-channel-mode-map "n" #'circe-command-NAMES))) diff --git a/modules/tools/pass/autoload/ivy.el b/modules/tools/pass/autoload/ivy.el new file mode 100644 index 00000000000..91079f92c33 --- /dev/null +++ b/modules/tools/pass/autoload/ivy.el @@ -0,0 +1,21 @@ +;;; tools/pass/autoload/ivy.el -*- lexical-binding: t; -*- +;;;###if (featurep! :completion ivy) + +;;;###autoload +(defun +pass/ivy (arg) + "TODO" + (interactive "P") + (ivy-read "Pass: " (password-store-list) + :action (if arg + #'password-store-url + #'password-store-copy) + :caller '+pass/ivy)) + +(after! ivy + (ivy-add-actions + '+pass/ivy + '(("o" password-store-copy "copy password") + ("e" +pass/edit-entry "edit entry") + ("u" +pass/copy-user "copy username") + ("b" +pass/copy-url "open url in browser") + ("f" +pass/copy-field "get field")))) diff --git a/modules/tools/pass/autoload/pass.el b/modules/tools/pass/autoload/pass.el index 42ee2f707f0..d3fbc9f461a 100644 --- a/modules/tools/pass/autoload/pass.el +++ b/modules/tools/pass/autoload/pass.el @@ -106,35 +106,3 @@ fields in `+pass-url-fields' is used to find the url field." (interactive (list (password-store--completing-read))) (+pass--open-url entry)) - - -;; -;; Ivy interface - -;;;###autoload -(defun +pass/ivy (arg) - "TODO" - (interactive "P") - (ivy-read "Pass: " (password-store-list) - :action (if arg - #'password-store-url - #'password-store-copy) - :caller '+pass/ivy)) - -(after! ivy - (ivy-add-actions - '+pass/ivy - '(("o" password-store-copy "copy password") - ("e" +pass/edit-entry "edit entry") - ("u" +pass/copy-user "copy username") - ("b" +pass/copy-url "open url in browser") - ("f" +pass/copy-field "get field")))) - - -;; -;; TODO Helm interface - -;; (defun +pass/helm () -;; (interactive) -;; ) -