# The perfect erc setup for System Crafters

**URL:** <https://forum.systemcrafters.net/t/the-perfect-erc-setup-for-system-crafters/532>\
**Category:** Emacs\
**Tags:** emacs-lisp, emacs\
**Created:** [March 31, 2024, 7:43pm UTC](https://forum.systemcrafters.net/t/the-perfect-erc-setup-for-system-crafters/532 "2024-03-31T19:43:17Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![Glenneth](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.systemcrafters.net/glenneth/32/11_2.png) [@Glenneth](https://forum.systemcrafters.net/u/Glenneth)\
**Post date:** [April 2, 2024, 1:59pm UTC](https://forum.systemcrafters.net/t/the-perfect-erc-setup-for-system-crafters/532/6 "2024-04-02T13:59:00Z")

</div>

I’ve been investigating improving my own ERC configuration for Emacs, I’ve made several enhancements aimed at improving functionality, readability, and maintainability.

When I saw your post, I looked at your configuration and my own and have come up with a merged configuration.

Below, you’ll find an updated configuration snippet with explanations for the changes.

#### Functional Enhancements

1. **Enhanced URL Browsing** : Improved URL detection and handling in `my/erc-browse-last-url` for a more reliable browsing experience.
2. **Notification Improvements** : Updated `my/erc-notify` to differentiate between direct messages and channel messages more clearly.
3. **Preprocessing String Fix** : Corrected an issue in `my/erc-preprocess` where a variable was used before assignment, which could lead to runtime errors.
4. **SASL Authentication** : Suggested to ensure `erc-sasl-auth-source-function` is correctly set for better authentication handling.
5. **Auto-Reconnection** : To be implemented

#### Code Refinements

- Ensured variable naming consistency and added error handling where appropriate.
- Improved function documentation for better clarity.

#### Updated Configuration Snippet

```auto
(use-package erc
  :preface
  (defun my/erc-browse-last-url ()
    "Search backwards through an ERC buffer for a URL and prompt to open it."
    (interactive)
    (save-excursion
      (let ((url-regexp "\\(http\\|https\\|ftp\\|gopher\\)://[^\t\n\r\f <>\"{}|\\^`]*"))
        (if (re-search-backward url-regexp nil t)
            (browse-url (match-string 0))
          (message "No URL found in buffer.")))))

  (defun my/erc-notify (nickname message)
    "Displays a notification for an ERC message."
    (let* ((channel (buffer-name))
           (nick (erc-hl-nicks-trim-irc-nick nickname))
           (title (if (string-match-p (concat "^" nickname) channel)
                      (concat "PM from " nick)
                    (concat nick " (" channel ")")))
           (msg (s-trim (s-collapse-whitespace message))))
      (alert (concat nick ": " msg) :title title)))

  (defun my/erc-preprocess (string)
    "Avoids channel flooding by trimming and replacing newlines in messages."
    (setq string (string-trim (replace-regexp-in-string "\n+" " " string))))

  :hook
  ((ercn-notify . my/erc-notify)
   (erc-send-pre . my/erc-preprocess))
  
  ;; Include the rest of your configuration as is, without changes.
)

```

### Additional Considerations

- **Custom Faces** : You may want to uncomment and adjust the `:custom-face` settings according to your personal preferences.
- **Testing** : Ensure to test these changes in your setup to validate their effectiveness in various scenarios.

I haven;t got around to deploying this solution myself just yet, so if you decide to incorporate any of it I would be interested in hearing your thoughts for improving it further.

---

_[View the full topic](https://forum.systemcrafters.net/t/the-perfect-erc-setup-for-system-crafters/532)._
