diff options
| author | Jakob L. Kreuze | 2019-01-06 15:12:24 -0500 |
|---|---|---|
| committer | Jakob L. Kreuze | 2019-01-06 15:12:24 -0500 |
| commit | 8144985f4f9617a9ca70de419c9c56e89d5ba9b3 (patch) | |
| tree | c750ab4ea186ce04c46499493fb199382107d817 /jakob.org | |
| parent | 6f1904c4d310a012258ec7302f16c624628a9397 (diff) | |
Clean up custom IRC functions and bind keys to them
Diffstat (limited to 'jakob.org')
| -rw-r--r-- | jakob.org | 316 |
1 files changed, 193 insertions, 123 deletions
@@ -218,6 +218,148 @@ Enable the default-disabled functions that I use. (column-number-mode t) #+END_SRC +* Custom Functionality + +This section is for any nontrivial Elisp functions written by me. + +** Utilities + +A wrapper for =completing-read= that passes in an argument for DEF. + +#+BEGIN_SRC elisp +(defun completing-read-with-default (prompt collection default) + "Invoke `completing-read' with DEFAULT as the DEF argument." + (completing-read prompt collection nil nil nil nil default)) +#+END_SRC + +** IRC + +Convenience functions for connecting to and authenticating with my IRC bouncer. + +#+BEGIN_SRC elisp +(defun read-bouncer-password () + "Get the password for my bouncer from authinfo" + (let ((auth (auth-source-search :host "jakob.space" :user "jakob" :port 26969))) + (unless auth + (error "No auth entry for bouncer.")) + (let ((secretf (plist-get (car auth) :secret))) + (unless secretf + (error "No secret for bouncer's auth entry.")) + (funcall secretf)))) + +(defun connect-bouncer (server) + "Connect to `SERVER' on the bouncer and rename the buffer" + (let ((password (format "%s/%s:%s" "jakob" server (read-bouncer-password)))) + (erc-tls :server "jakob.space" :port 26969 :password password) + (erc-with-buffer ((get-buffer "jakob.space:26969") + (rename-buffer server))))) +#+END_SRC + +Interactive function for automatically connecting to a local Bitlbee instance +and all of the networks I have my bouncer connected to. + +#+BEGIN_SRC elisp +(defvar irc-autoconnect-networks '("bitlbee" "freenode" "tildetown" "tildechat") + "List of networks to automatically connect to when 'irc' is invoked.") + +(defun irc () + "Automatically connect to IRC networks." + (interactive) + (dolist (network irc-autoconnect-networks) + (if (string= network "bitlbee") + (bitlbee-start) + (connect-bouncer network)))) + +(defun irc-quit () + "Disconnects from and kills all buffers associated with ERC, +and ends the Bitlbee process." + (interactive) + (let ((server-buffers (remove-if-not #'erc-server-buffer-p (erc-buffer-list)))) + (dolist (buffer server-buffers) + (erc-with-buffer (buffer) + (erc-quit-server (funcall erc-quit-reason nil))))) + (bitlbee-stop)) +#+END_SRC + +Interactive functions for manipulating =erc-track-exclude=. + +#+BEGIN_SRC elisp +(defvar irc-important-channels '("&bitlbee" "#tildetown" "#lobsters") + "Channels that I don't want shutting up.") + +(defun list-irc-channels () + "Returns a list of the names of the ERC channel buffers." + (map 'list #'buffer-name (remove-if #'erc-server-buffer-p (erc-buffer-list)))) + +(defun silence-channels () + "Add all channels to `erc-track-exclude'. if they are not a +member of `irc-important-channels'." + (interactive) + (setq --old-track-exclude erc-track-exclude) + (let ((channels (list-irc-channels))) + (when (boundp 'irc-important-channels) + (dolist (channel channels) + (if (and (not (find channel irc-important-channels :test #'string=)) + (not (find channel erc-track-exclude :test #'string=))) + (push channel erc-track-exclude))))) + (setq erc-modified-channels-alist nil) + (erc-modified-channels-display)) + +(defun unsilence-channels () + "Reset the state of `erc-track-exclude'." + (interactive) + (setq erc-track-exclude + (remove-if-not #'(lambda (channel) + (find channel --old-track-exclude)) + erc-track-exclude))) + +(defun ignore-channel () + "Use `completing-read' to ask the user for a channel to ignore." + (interactive) + (let* ((candidates (remove-if #'(lambda (channel) + (find channel erc-track-exclude)) + (list-irc-channels))) + (default (if (and (eq major-mode 'erc-mode) + (not (member (buffer-name) erc-track-exclude))) + (buffer-name))) + (channel (if default + (completing-read-with-default "Channel:" candidates default) + (completing-read "Channel: " candidates)))) + (push channel erc-track-exclude) + (erc-modified-channels-display))) + +(defun unignore-channel () + "Use `completing-read' to ask the user for a channel to remove +from the list of ignored channels." + (interactive) + (let* ((candidates erc-track-exclude) + (default (if (and (eq major-mode 'erc-mode) + (member (buffer-name) erc-track-exclude)) + (buffer-name))) + (channel (if default + (completing-read-with-default "Channel:" candidates default) + (completing-read "Channel: " candidates)))) + (setq erc-track-exclude + (remove-if #'(lambda (channel) + (string= channel buffer)) + erc-track-exclude)))) +#+END_SRC + +Interactive function for switching to a channel's buffer. + +#+BEGIN_SRC elisp +(defun irc-switch-buffer () + "Use `completing-read' to ask for a channel buffer to visit." + (interactive) + (let* ((candidates (list-irc-channels)) + (default (if erc-modified-channels-alist + (buffer-name (first (first erc-modified-channels-alist))))) + (channel (if default + (completing-read-with-default "Channel: " candidates default) + (completing-read "Channel: " candidates)))) + (switch-to-buffer channel))) +#+END_SRC + * Appearance ** Windowing @@ -531,7 +673,25 @@ Enable Ivy globally. #+BEGIN_SRC elisp :config - (ivy-mode 1)) + (ivy-mode 1) +#+END_SRC + +Transformer to highlight channels in the =completing-read= of +=irc-switch-buffer= that have had activity recently. + +#+BEGIN_SRC elisp + :config + (defun irc-switch-buffer-transformer (str) + "Transform channels with activity with `ivy-virtual' face." + (let ((modified (map 'list + (lambda (channel) + (buffer-name (first channel))) + erc-modified-channels-alist))) + (if (member str modified) + (propertize str 'face 'ivy-virtual) + str))) + (ivy-set-display-transformer 'irc-switch-buffer + 'irc-switch-buffer-transformer)) #+END_SRC * Dired @@ -552,7 +712,7 @@ Set up keybindings for =imenu=. #+BEGIN_SRC elisp (use-package imenu - :bind ("C-c i" . imenu)) + :bind ("C-c s" . imenu)) #+END_SRC * EXWM @@ -982,126 +1142,6 @@ available [[http://jakob.space/links/][on my website]] with links to the sites i * ERC -Set up some convenience functions for connecting to and authenticating with my -IRC bouncer. - -#+BEGIN_SRC elisp -(defun read-bouncer-password () - "Get the password from my bouncer from authinfo" - (let ((auth (auth-source-search :host "jakob.space" :user "jakob" :port 26969))) - (unless auth - (error "No auth entry for bouncer.")) - (let ((secretf (plist-get (car auth) :secret))) - (unless secretf - (error "No secret for bouncer's auth entry.")) - (funcall secretf)))) - -(defun connect-bouncer (server) - "Connect to `SERVER' on the bouncer and rename the buffer" - (let ((password (format "%s/%s:%s" "jakob" server (read-bouncer-password)))) - (erc-tls :server "jakob.space" :port 26969 :password password) - (erc-with-buffer ((get-buffer "jakob.space:26969") - (rename-buffer server))))) -#+END_SRC - -Define an interactive function for automatically connecting to a local Bitlbee -instance and all of the networks I have my bouncer connected to. - -#+BEGIN_SRC elisp -(defvar irc-autoconnect-networks '("bitlbee" "freenode" "tildetown" "tildechat") - "List of networks to automatically connect to when 'irc' is invoked.") - -(defun irc () - "Automatically connect to IRC networks." - (interactive) - (dolist (network irc-autoconnect-networks) - (if (string= network "bitlbee") - (bitlbee-start) - (connect-bouncer network)))) - -(defun irc-quit () - "Disconnects from and kills all buffers associated with ERC." - (interactive) - (let ((server-buffers (remove-if-not #'erc-server-buffer-p (erc-buffer-list)))) - (dolist (buffer server-buffers) - (erc-with-buffer (buffer) - (erc-quit-server (funcall erc-quit-reason nil))))) - (bitlbee-stop)) -#+END_SRC - -Define some interactive functions for manipulating =erc-track-exclude=. - -#+BEGIN_SRC elisp -(defvar irc-important-channels '("&bitlbee" "#tildetown" "#lobsters") - "Channels that I don't want shutting up.") - -(defun list-irc-channels () - "Returns a list of the names of the ERC channel buffers" - (map 'list #'buffer-name (remove-if #'erc-server-buffer-p (erc-buffer-list)))) - -(defun silence-channels () - "Add all channels to `ERC-TRACK-EXCLUDE' if they are not a -member of `IRC-IMPORTANT-CHANNELS'." - (interactive) - (setq --old-track-exclude erc-track-exclude) - (let ((channels (list-irc-channels))) - (when (boundp 'irc-important-channels) - (dolist (channel channels) - (if (and (not (find channel irc-important-channels :test #'string=)) - (not (find channel erc-track-exclude :test #'string=))) - (push channel erc-track-exclude))))) - (setq erc-modified-channels-alist nil) - (erc-modified-channels-display) - (minibuffer-message "Silence!")) - -(defun unsilence-channels () - "Reset the state of `ERC-TRACK-EXCLUDE'." - (interactive) - (setq erc-track-exclude - (remove-if-not #'(lambda (channel) - (find channel --old-track-exclude)) - erc-track-exclude)) - (minibuffer-message "Okay, you may speak again.")) - -(defun list-ignored-channels () - "Prints the currently ignored channels to the minibuffer." - (interactive) - (if erc-track-exclude - (minibuffer-message (format "Currently ignoring: %s" - (reduce #'(lambda (a b) (concatenate 'string a ", " b)) erc-track-exclude))) - (minibuffer-message "Not ignoring any channels"))) - -(defun ignore-channel () - "Use completing-read to ask the user for a channel to ignore." - (interactive) - (let* ((current-mode (with-current-buffer (current-buffer) major-mode)) - (current-channel (if (eq current-mode 'erc-mode) (buffer-name (current-buffer)))) - (channels (if current-channel - (cons current-channel - (remove-if #'(lambda (chan) (string= chan current-channel)) (list-irc-channels))) - (list-irc-channels))) - (channels (remove-if #'(lambda (channel) (find channel erc-track-exclude)) channels)) - (buffer (completing-read "Channel: " channels))) - (push buffer erc-track-exclude) - (erc-modified-channels-display))) - -(defun unignore-channel () - "Use completing-read to ask the user for a channel to ignore." - (interactive) - (let* ((current-mode (with-current-buffer (current-buffer) major-mode)) - (current-channel (if (eq current-mode 'erc-mode) (buffer-name (current-buffer)))) - (channels (if current-channel - (cons current-channel - (remove-if #'(lambda (chan) (string= chan current-channel)) (list-irc-channels))) - (list-irc-channels))) - (channels (remove-if-not #'(lambda (channel) (find channel erc-track-exclude)) channels)) - (buffer (completing-read "Channel: " channels))) - (setq erc-track-exclude - (remove-if #'(lambda (channel) - (string= channel buffer)) - erc-track-exclude)))) -#+END_SRC - Only load the modules I actually use. This list deviates from the default by including =keep-place= and =truncate=, but omitting =autojoin=. @@ -1117,6 +1157,13 @@ including =keep-place= and =truncate=, but omitting =autojoin=. (erc-update-modules) #+END_SRC +Begin with unimportant channels silenced by default. + +#+BEGIN_SRC elisp + :config + (silence-channels) +#+END_SRC + Configure some personal details. #+BEGIN_SRC elisp @@ -1242,7 +1289,30 @@ Let =erc-fill= handle filling. #+BEGIN_SRC elisp :hook - (erc-mode . (lambda () (auto-fill-mode 0)))) + (erc-mode . (lambda () (auto-fill-mode 0))) +#+END_SRC + +Sadly =:bind= is limited when it comes to defining keystrokes with prefixes, so +I've done it manually here. These are the more frequently used of the functions +in [[IRC]]. + +#+BEGIN_SRC elisp + :config + (defvar irc-map (make-sparse-keymap) + "Prefix keymap for bindings related to IRC.") + (bind-key "C-c i" irc-map) + (dolist (chord '("C-c i b" + "C-c i i" + "C-c i s" + "C-c i q" + "C-c i u")) + (bind-key chord irc-map)) + + (bind-key "C-c i b" #'irc-switch-buffer) + (bind-key "C-c i i" #'ignore-channel) + (bind-key "C-c i s" #'irc) + (bind-key "C-c i q" #'irc-quit) + (bind-key "C-c i u" #'unignore-channel)) #+END_SRC Ensure a package for colorizing nicks. |