From 1c7113cbd8b742b78a0a33d18290d536f4333e19 Mon Sep 17 00:00:00 2001 From: Benson Chu Date: Mon, 1 Sep 2025 10:52:38 -0500 Subject: [PATCH] ERC's which-func modeline thing is read-only, very bad Will fix later I guess --- config-look-and-feel.org | 3 +- lisp/erc-doom-modeline-hack.el | 55 ++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 lisp/erc-doom-modeline-hack.el diff --git a/config-look-and-feel.org b/config-look-and-feel.org index 7d669fe..2d1e9a8 100644 --- a/config-look-and-feel.org +++ b/config-look-and-feel.org @@ -57,7 +57,8 @@ (advice-add #'doom-modeline-project-p :around #'my/dont-check-project-samba) - ) + + (require 'erc-doom-modeline-hack)) ;; Modeline display useful information (setq global-mode-string '(" ")) diff --git a/lisp/erc-doom-modeline-hack.el b/lisp/erc-doom-modeline-hack.el new file mode 100644 index 0000000..f33bf9b --- /dev/null +++ b/lisp/erc-doom-modeline-hack.el @@ -0,0 +1,55 @@ +;;; erc-doom-modeline-hack.el --- -*- lexical-binding: t -*- + +;; Copyright (C) 2025 Benson Chu + +;; Author: Benson Chu +;; Created: [2025-09-01 10:50] + +;; This file is not part of GNU Emacs + +;; This program is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;;; Code: + +(defun my/string-pixel-width (string) + "Return the width of STRING in pixels. + +If you call this function to measure pixel width of a string +with embedded newlines, it returns the width of the widest +substring that does not include newlines." + (declare (important-return-value t)) + (if (zerop (length string)) + 0 + ;; Keeping a work buffer around is more efficient than creating a + ;; new temporary buffer. + (let ((inhibit-read-only t)) + (with-current-buffer (get-buffer-create " *string-pixel-width*") + ;; If `display-line-numbers' is enabled in internal buffers + ;; (e.g. globally), it breaks width calculation (bug#59311) + (setq-local display-line-numbers nil) + (delete-region (point-min) (point-max)) + ;; Disable line-prefix and wrap-prefix, for the same reason. + (setq line-prefix nil + wrap-prefix nil) + (insert (propertize string 'line-prefix nil 'wrap-prefix nil)) + (car (buffer-text-pixel-size nil nil t)))))) + +(advice-add #'string-pixel-width + :override + #'my/string-pixel-width) + +(provide 'erc-doom-modeline-hack) +;;; erc-doom-modeline-hack.el ends here