From 5c1edde613b14c114bbc2ccb42ef0686c7b40972 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 23 Jan 2019 15:54:12 -0500 Subject: [PATCH] app/irc: general refactor --- modules/app/irc/autoload/irc.el | 7 ++++ modules/app/irc/config.el | 39 ++++++++--------------- modules/config/default/+emacs-bindings.el | 2 +- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/modules/app/irc/autoload/irc.el b/modules/app/irc/autoload/irc.el index a630fb61d..47d0f95f5 100644 --- a/modules/app/irc/autoload/irc.el +++ b/modules/app/irc/autoload/irc.el @@ -84,3 +84,10 @@ argument) is non-nil only show channels in current server." (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 () + "Dissables switching to an unread buffer unless in the irc workspace." + (interactive) + (when (derived-mode-p 'circe-mode) + (tracking-next-buffer))) diff --git a/modules/app/irc/config.el b/modules/app/irc/config.el index 0edb517ab..a89f6163c 100644 --- a/modules/app/irc/config.el +++ b/modules/app/irc/config.el @@ -96,9 +96,6 @@ playback.") (run-hooks '+irc-disconnect-hook)) (advice-add 'circe--irc-conn-disconnected :after #'+irc*circe-disconnect-hook) - ;; Let `+irc/quit' and `circe' handle buffer cleanup - (define-key circe-mode-map [remap kill-buffer] #'bury-buffer) - (defun +irc*circe-truncate-nicks () "Truncate long nicknames in chat output non-destructively." (when-let* ((beg (text-property-any (point-min) (point-max) 'lui-format-argument 'nick))) @@ -111,12 +108,6 @@ playback.") +irc-truncate-nick-char))))) (add-hook 'lui-pre-output-hook #'+irc*circe-truncate-nicks) - (defun +irc|circe-message-option-bot (nick &rest ignored) - "Fontify known bots and mark them to not be tracked." - (when (member nick +irc-bot-list) - '((text-properties . (face circe-fool-face lui-do-not-track t))))) - (add-hook 'circe-message-option-functions #'+irc|circe-message-option-bot) - (defun +circe-buffer-p (buf) "Return non-nil if BUF is a `circe-mode' buffer." (with-current-buffer buf @@ -125,33 +116,31 @@ playback.") +irc--workspace-name)))) (add-hook 'doom-real-buffer-functions #'+circe-buffer-p) + (defun +irc|circe-message-option-bot (nick &rest ignored) + "Fontify known bots and mark them to not be tracked." + (when (member nick +irc-bot-list) + '((text-properties . (face circe-fool-face lui-do-not-track t))))) + (add-hook 'circe-message-option-functions #'+irc|circe-message-option-bot) + (defun +irc|add-circe-buffer-to-persp () (let ((persp (get-current-persp)) (buf (current-buffer))) - ;; only add a new circe buffer to the irc workspace when we're in another - ;; workspace + ;; Add a new circe buffer to irc workspace when we're in another workspace (unless (eq (safe-persp-name persp) +irc--workspace-name) - ;; add new circe buffers to the persp containing circe buffers - (persp-add-buffer buf - (persp-get-by-name +irc--workspace-name)) - ;; remove new buffer from accidental workspace + ;; Add new circe buffers to the persp containing circe buffers + (persp-add-buffer buf (persp-get-by-name +irc--workspace-name)) + ;; Remove new buffer from accidental workspace (persp-remove-buffer buf persp)))) (add-hook 'circe-mode-hook #'+irc|add-circe-buffer-to-persp) - (defun +irc/tracking-next-buffer () - "Dissables switching to an unread buffer unless in the irc workspace." - (interactive) - (when (derived-mode-p 'circe-mode) - (tracking-next-buffer))) + ;; Let `+irc/quit' and `circe' handle buffer cleanup + (define-key circe-mode-map [remap kill-buffer] #'bury-buffer) + ;; Fail gracefully if not in a circe buffer (global-set-key [remap tracking-next-buffer] #'+irc/tracking-next-buffer) - (after! solaire-mode - ;; distinguish chat/channel buffers from server buffers. - (add-hook 'circe-chat-mode-hook #'solaire-mode)) - (map! :localleader (:map circe-mode-map - "a" #'+irc/tracking-next-buffer + "a" #'tracking-next-buffer "j" #'circe-command-JOIN "m" #'+irc/send-message "p" #'circe-command-PART diff --git a/modules/config/default/+emacs-bindings.el b/modules/config/default/+emacs-bindings.el index 0edd2786e..3dcc0b2a7 100644 --- a/modules/config/default/+emacs-bindings.el +++ b/modules/config/default/+emacs-bindings.el @@ -172,7 +172,7 @@ (:when (featurep! :app irc) (:prefix ("I" . "irc") :desc "Open irc app" "i" #'=irc - :desc "Next unread buffer" "a" #'+irc/tracking-next-buffer + :desc "Next unread buffer" "a" #'tracking-next-buffer :desc "Quit irc" "q" #'+irc/quit :desc "Reconnect all" "r" #'circe-reconnect-all :desc "Send message" "s" #'+irc/send-message