summaryrefslogtreecommitdiff
path: root/mms-misc-irc.org
diff options
context:
space:
mode:
authormms <michal@sapka.me>2024-06-13 17:39:47 +0200
committermms <michal@sapka.me>2024-06-13 17:39:47 +0200
commitb5122e9e53085897d3deca4b835c3806558c5302 (patch)
tree6132aa73f927399ddf23779288f330f3947187dc /mms-misc-irc.org
parenta6f933fe524f544ec02afe9bd08a1c8ee909c784 (diff)
feat: more erc
Diffstat (limited to 'mms-misc-irc.org')
-rw-r--r--mms-misc-irc.org114
1 files changed, 107 insertions, 7 deletions
diff --git a/mms-misc-irc.org b/mms-misc-irc.org
index f531d5f..38696f1 100644
--- a/mms-misc-irc.org
+++ b/mms-misc-irc.org
@@ -14,14 +14,114 @@
* ERC setup
#+begin_src emacs-lisp
- (setq erc-autojoin-channels-alist
- '(("tilde.chat" "#emacs.ch")))
+ (setq erc-autojoin-channels-alist
+ '(("tilde.chat" "#emacs.ch")))
- (defun mms-irc-mode()
- "use this instance of Emacs for IRC"
- (interactive)
+#+end_src
+
+Show mew where I left off:
+url: https://www.emacswiki.org/emacs/ErcBar
+
+#+begin_src emacs-lisp
+ (eval-after-load 'erc-track
+ '(progn
+ (defun erc-bar-move-back (n)
+ "Moves back n message lines. Ignores wrapping, and server messages."
+ (interactive "nHow many lines ? ")
+ (re-search-backward "^.*<.*>" nil t n))
+
+ (defun erc-bar-update-overlay ()
+ "Update the overlay for current buffer, based on the content of
+ erc-modified-channels-alist. Should be executed on window change."
+ (interactive)
+ (let* ((info (assq (current-buffer) erc-modified-channels-alist))
+ (count (cadr info)))
+ (if (and info (> count erc-bar-threshold))
+ (save-excursion
+ (end-of-buffer)
+ (when (erc-bar-move-back count)
+ (let ((inhibit-field-text-motion t))
+ (move-overlay erc-bar-overlay
+ (line-beginning-position)
+ (line-end-position)
+ (current-buffer)))))
+ (delete-overlay erc-bar-overlay))))
+
+ (defvar erc-bar-threshold 1
+ "Display bar when there are more than erc-bar-threshold unread messages.")
+ (defvar erc-bar-overlay nil
+ "Overlay used to set bar")
+ (setq erc-bar-overlay (make-overlay 0 0))
+ (overlay-put erc-bar-overlay 'face '(:underline "black"))
+ ;;put the hook before erc-modified-channels-update
+ (defadvice erc-track-mode (after erc-bar-setup-hook
+ (&rest args) activate)
+ ;;remove and add, so we know it's in the first place
+ (remove-hook 'window-configuration-change-hook 'erc-bar-update-overlay)
+ (add-hook 'window-configuration-change-hook 'erc-bar-update-overlay))
+ (add-hook 'erc-send-completed-hook (lambda (str)
+ (erc-bar-update-overlay)))))
+
+#+end_src
+
+Color nicks
+src:https://www.emacswiki.org/emacs/ErcNickColors
+#+begin_src emacs-lisp
+(defmacro unpack-color (color red green blue &rest body)
+ `(let ((,red (car ,color))
+ (,green (car (cdr ,color)))
+ (,blue (car (cdr (cdr ,color)))))
+ ,@body))
+
+(defun rgb-to-html (color)
+ (unpack-color color red green blue
+ (concat "#" (format "%02x%02x%02x" red green blue))))
+
+(defun hexcolor-luminance (color)
+ (unpack-color color red green blue
+ (floor (+ (* 0.299 red) (* 0.587 green) (* 0.114 blue)))))
+
+(defun invert-color (color)
+ (unpack-color color red green blue
+ `(,(- 255 red) ,(- 255 green) ,(- 255 blue))))
+
+(defun erc-get-color-for-nick (nick dark)
+ (let* ((hash (md5 (downcase nick)))
+ (red (mod (string-to-number (substring hash 0 10) 16) 256))
+ (blue (mod (string-to-number (substring hash 10 20) 16) 256))
+ (green (mod (string-to-number (substring hash 20 30) 16) 256))
+ (color `(,red ,green ,blue)))
+ (rgb-to-html (if (if dark (< (hexcolor-luminance color) 85)
+ (> (hexcolor-luminance color) 170))
+ (invert-color color)
+ color))))
+
+(defun erc-highlight-nicknames ()
+ (save-excursion
+ (goto-char (point-min))
+ (while (re-search-forward "\\w+" nil t)
+ (let* ((bounds (bounds-of-thing-at-point 'symbol))
+ (nick (buffer-substring-no-properties (car bounds) (cdr bounds))))
+ (when (erc-get-server-user nick)
+ (put-text-property
+ (car bounds) (cdr bounds) 'face
+ (cons 'foreground-color (erc-get-color-for-nick nick 't))))))))
+
+(add-hook 'erc-insert-modify-hook 'erc-highlight-nicknames)
+#+end_src
+
+
+
+#+begin_src emacs-lisp
+ (defun mms-irc-mode()
+ "use this instance of Emacs for IRC"
+ (interactive)
+
+ (setq mms-bright-theme 'ef-cyprus
+ mms-dark-theme 'ef-bio)
+ (mms-dark-room-mode)
- (erc-tls :server "irc.tilde.chat" :port "6697"
- :nick "mms" :full-name "https://michal.sapka.me"))
+ (erc-tls :server "irc.tilde.chat" :port "6697"
+ :nick "mms" :full-name "https://michal.sapka.me"))
#+end_src