summaryrefslogtreecommitdiff
path: root/mms-misc-irc.org
blob: 476d86bc62454e084396db78050415a91130555b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#+TITLE: mms Emacs Config - IRC
#+AUTHOR: MichaƂ Sapka (https://michal.sapka.me)
#+STARTUP: showall indent logdone

#+HUGO_BASE_DIR: ~/ghq/vcs.sapka.me/michal-sapka-me/
#+HUGO_WEIGHT: 20
#+HUGO_SECTION: emacs/config
#+HUGO_CATEGORIES: emacs emacs-config
#+HUGO_MENU :menu "emacs-config" :name GUI
#+HUGO_CUSTOM_FRONT_MATTER: :abstract "My emacs config - GUI look and feel"
#+HUGO_CUSTOM_FRONT_MATTER: :menu-abstract "The way Emacs look in gui mode"
#+EXPORT_FILE_NAME: gui

* ERC setup

#+begin_src emacs-lisp
    (setq erc-autojoin-channels-alist
          '(("tilde.chat" "#emacs.ch")
             ("libera.chat" "##bsd" "#emacs" "#erc" "##sci-fi" "##startrek" "##anime" "#usenet" "#poland")))
#+end_src

Handle nickserver:
#+begin_src emacs-lisp
  (require 'erc-services)
  (erc-services-mode 1)
  (setq erc-use-auth-source-for-nickserv-password "t")

#+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.libera.chat" :port "6697"
         :nick "mms" :full-name "https://michal.sapka.me")
    )
#+end_src