Refactor rcirc layer for lazy loading
Rename layer variables to - rcirc-enable-authinfo-support - rcirc-enable-znc-support
This commit is contained in:
parent
6e348c0a54
commit
13d7326685
|
@ -103,8 +103,8 @@ The way to enable ZNC with authinfo support is to have this on your
|
|||
|
||||
In `dotspacemacs/init`
|
||||
```elisp
|
||||
(setq rcirc-authinfo-support t
|
||||
rcirc-uses-znc t)
|
||||
(setq rcirc-enable-authinfo-support t
|
||||
rcirc-enable-znc-support t)
|
||||
```
|
||||
|
||||
In `dotspacemacs/config`
|
||||
|
|
|
@ -12,75 +12,42 @@ which require an initialization must be listed explicitly in the list.")
|
|||
|
||||
(defun rcirc/init-rcirc ()
|
||||
(use-package rcirc
|
||||
:ensure rcirc-color
|
||||
:config
|
||||
:defer t
|
||||
:init
|
||||
(progn
|
||||
(setq rcirc-fill-column 80
|
||||
rcirc-buffer-maximum-lines 2048
|
||||
rcirc-omit-responses '("JOIN" "PART" "QUIT" "NICK" "AWAY" "MODE")
|
||||
rcirc-time-format "%Y-%m-%d %H:%M "
|
||||
rcirc-omit-threshold 20)
|
||||
(add-to-hook 'rcirc-mode-hook '(flyspell-mode rcirc-omit-mode))
|
||||
|
||||
;; add a key for EMMS integration
|
||||
(when (boundp 'emms-track-description)
|
||||
(defun rcirc/insert-current-emms-track ()
|
||||
(interactive)
|
||||
(insert (emms-track-description (emms-playlist-current-selected-track))))
|
||||
|
||||
(define-key rcirc-mode-map (kbd "C-c C-e") 'rcirc/insert-current-emms-track)
|
||||
)
|
||||
|
||||
;; Exclude rcirc properties when yanking, in order to be able to send mails
|
||||
;; for example.
|
||||
(add-to-list 'yank-excluded-properties 'rcirc-text)
|
||||
;;###autoload
|
||||
(add-hook 'rcirc-mode-hook '(lambda ()
|
||||
;; Turn on spell checking.
|
||||
(flyspell-mode 1)
|
||||
(rcirc-omit-mode)
|
||||
;; (set-input-method "latin-1-prefix")
|
||||
(set (make-local-variable 'scroll-conservatively) 8192)
|
||||
))
|
||||
|
||||
(let ((dir (configuration-layer/get-layer-property 'rcirc :ext-dir)))
|
||||
(require 'rcirc-reconnect
|
||||
(concat dir "rcirc-reconnect/rcirc-reconnect.el")))
|
||||
(require 'pinit-rcirc nil 'noerror)
|
||||
|
||||
(define-key rcirc-mode-map (kbd "C-j") 'rcirc-insert-prev-input)
|
||||
(define-key rcirc-mode-map (kbd "C-k") 'rcirc-insert-next-input)
|
||||
|
||||
;; Join these channels at startup.
|
||||
;; (setq rcirc-server-alist
|
||||
;; '(("irc.freenode.net"
|
||||
;; :user "spacemacs_user"
|
||||
;; :port "1337"
|
||||
;; :password "le_passwd"
|
||||
;; :channels ("#emacs"))))
|
||||
|
||||
(if (and rcirc-authinfo-support
|
||||
(defun spacemacs/rcirc (arg)
|
||||
"Configure rcirc"
|
||||
(interactive "P")
|
||||
(when (and rcirc-enable-authinfo-support
|
||||
(file-exists-p "~/.authinfo.gpg"))
|
||||
(progn
|
||||
(defun barebones-rcirc-config ()
|
||||
(defadvice rcirc (before rcirc-read-from-authinfo activate)
|
||||
"Allow rcirc to read authinfo from ~/.authinfo.gpg via the auth-source API.
|
||||
This doesn't support the chanserv auth method"
|
||||
(unless arg
|
||||
(dolist (p (auth-source-search :port '("nickserv" "bitlbee" "quakenet")
|
||||
;; Allow rcirc to read authinfo from ~/.authinfo.gpg
|
||||
;; via the auth-source API. This doesn't support the
|
||||
;; chanserv auth method.
|
||||
(unless arg (spacemacs//rcirc-authinfo-config))
|
||||
;; znc need
|
||||
(when rcirc-enable-znc-support (spacemacs//rcirc-znc-config)))
|
||||
(rcirc arg))
|
||||
(evil-leader/set-key "ai" 'spacemacs/rcirc)
|
||||
|
||||
(defun spacemacs//rcirc-authinfo-config ()
|
||||
"Initialize authinfo."
|
||||
(dolist (p (auth-source-search
|
||||
:port '("nickserv" "bitlbee" "quakenet")
|
||||
:require '(:port :user :secret)))
|
||||
(let ((secret (plist-get
|
||||
p :secret))
|
||||
(let ((secret (plist-get p :secret))
|
||||
(method (intern (plist-get p :port))))
|
||||
(add-to-list 'rcirc-authinfo
|
||||
(list (plist-get p :host)
|
||||
method
|
||||
(plist-get p :user)
|
||||
(if (functionp secret)
|
||||
(add-to-list
|
||||
'rcirc-authinfo
|
||||
(list (plist-get p :host) method
|
||||
(plist-get p :user) (if (functionp secret)
|
||||
(funcall secret)
|
||||
secret)))))))
|
||||
(rcirc nil)
|
||||
)
|
||||
(defun znc-rcirc-config ()
|
||||
secret))))))
|
||||
|
||||
(defun spacemacs//rcirc-znc-config ()
|
||||
"Initialize ZNC, requires authinfo."
|
||||
|
||||
(defun dim:auth-source-fetch-password (server)
|
||||
"Given a server with at least :host :port :login, return the :password"
|
||||
(destructuring-bind (&key host auth &allow-other-keys)
|
||||
|
@ -103,9 +70,7 @@ This doesn't support the chanserv auth method"
|
|||
(pass (dim:auth-source-fetch-password server)))
|
||||
(when auth
|
||||
(plist-put plist
|
||||
:password (format "%s:%s" auth pass)))
|
||||
))
|
||||
)
|
||||
:password (format "%s:%s" auth pass))))))
|
||||
|
||||
;; rcirc does not know how to connect to the same server more than once, so
|
||||
;; we build our own connection routine from our own rcirc-server-alist,
|
||||
|
@ -141,40 +106,43 @@ This doesn't support the chanserv auth method"
|
|||
;; doc for that function
|
||||
(dim:rcirc-server-alist-get-authinfo
|
||||
rcirc-server-alist))
|
||||
(dim:rcirc)))
|
||||
:config
|
||||
(progn
|
||||
;; (set-input-method "latin-1-prefix")
|
||||
(set (make-local-variable 'scroll-conservatively) 8192)
|
||||
|
||||
;; you should have sth like this in your dotfile
|
||||
;; (setq rcirc-server-alist
|
||||
;; '(("freenode"
|
||||
;; :host "freenode.spacemacsserver.me"
|
||||
;; :port "1337"
|
||||
;; :auth "spacemacs_user/freenode"
|
||||
;; :channels ("#emacs"))
|
||||
;; ("geekshed"
|
||||
;; :host "geekshed.spacemacsserver.me"
|
||||
;; :port "1337"
|
||||
;; :auth "spacemacs_user/geekshed"
|
||||
;; :channels ("#jupiterbroadcasting")))
|
||||
;; )
|
||||
(setq rcirc-fill-column 80
|
||||
rcirc-buffer-maximum-lines 2048
|
||||
rcirc-omit-responses '("JOIN" "PART" "QUIT" "NICK" "AWAY" "MODE")
|
||||
rcirc-time-format "%Y-%m-%d %H:%M "
|
||||
rcirc-omit-threshold 20)
|
||||
|
||||
;; This is what the line on the ~/.authinfo.gpg file should look like
|
||||
;; machine freenode.spacemacsserver.me port irc user spacemacs_user/freenode password my_znc_passwd
|
||||
;; machine geekshed.spacemacsserver.me port irc user spacemacs_user/geekshed password my_znc_passwd
|
||||
(dim:rcirc)
|
||||
)
|
||||
(defun rcirc-config()
|
||||
;; Exclude rcirc properties when yanking, in order to be able to send mails
|
||||
;; for example.
|
||||
(add-to-list 'yank-excluded-properties 'rcirc-text)
|
||||
|
||||
;; rcirc-reconnect
|
||||
(let ((dir (configuration-layer/get-layer-property 'rcirc :ext-dir)))
|
||||
(require 'rcirc-reconnect
|
||||
(concat dir "rcirc-reconnect/rcirc-reconnect.el")))
|
||||
|
||||
;; load this file from the dropbox location load-path
|
||||
;; this is where you can store personal information
|
||||
(require 'pinit-rcirc nil 'noerror)
|
||||
|
||||
(define-key rcirc-mode-map (kbd "C-j") 'rcirc-insert-prev-input)
|
||||
(define-key rcirc-mode-map (kbd "C-k") 'rcirc-insert-next-input)
|
||||
|
||||
;; add a key for EMMS integration
|
||||
(when (boundp 'emms-track-description)
|
||||
(defun rcirc/insert-current-emms-track ()
|
||||
(interactive)
|
||||
(if rcirc-uses-znc
|
||||
(znc-rcirc-config)
|
||||
(barebones-rcirc-config)))
|
||||
(evil-leader/set-key
|
||||
"ai" 'rcirc-config))
|
||||
(evil-leader/set-leader
|
||||
"ai" 'irc)
|
||||
)
|
||||
(insert (emms-track-description (emms-playlist-current-selected-track))))
|
||||
(define-key rcirc-mode-map (kbd "C-c C-e") 'rcirc/insert-current-emms-track))
|
||||
|
||||
;; Minimal logging to `~/.rcirc-logs/channel'
|
||||
;; by courtesy of Trent Buck.
|
||||
(add-hook 'rcirc-print-hooks 'rcirc-write-log)
|
||||
(setq rcirc-log-directory "~/.emacs/.cache/rcirc-logs/")
|
||||
(setq rcirc-log-flag t)
|
||||
(defun rcirc-write-log (process sender response target text)
|
||||
|
@ -196,19 +164,26 @@ This doesn't support the chanserv auth method"
|
|||
(write-region (point-min) (point-max)
|
||||
(concat rcirc-log-directory (downcase target))
|
||||
t 'quietly))))))
|
||||
)
|
||||
))
|
||||
(add-hook 'rcirc-print-hooks 'rcirc-write-log)
|
||||
|
||||
;; dependencies
|
||||
;; will autoload rcirc-notify
|
||||
(rcirc-notify-add-hooks)
|
||||
(require 'rcirc-color))))
|
||||
|
||||
(defun rcirc/init-rcirc-notify ()
|
||||
(use-package rcirc-notify
|
||||
:init
|
||||
:defer t
|
||||
:config
|
||||
(progn
|
||||
(rcirc-notify-add-hooks)
|
||||
(add-hook 'rcirc-notify-page-me-hooks
|
||||
(lambda (msg)
|
||||
(start-process "beep-process" nil
|
||||
"mplayer" "~/.emacs.d/site-misc/startup.ogg" )))
|
||||
)
|
||||
)
|
||||
)
|
||||
(defun spacemacs/rcirc-notify-beep (msg)
|
||||
"Beep when notifying."
|
||||
(let ((player "mplayer")
|
||||
(sound "~/.emacs.d/site-misc/startup.ogg"))
|
||||
(when (and (executable-find player)
|
||||
(file-exists-p sound)))
|
||||
(start-process "beep-process" nil player sound)))
|
||||
(add-hook 'rcirc-notify-page-me-hooks 'spacemacs/rcirc-notify-beep))))
|
||||
|
||||
(defun rcirc/init-rcirc-color ()
|
||||
(use-package rcirc-color :defer t))
|
||||
|
|
Loading…
Reference in a new issue