aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorF. Jason Park2023-11-19 17:18:29 -0800
committerF. Jason Park2023-11-24 13:38:52 -0800
commit8bb68a522f3aad104b68ca4e479f4ccc3fc6cb03 (patch)
treeb525bb6dda51d88ee6e6ec966f24e771e192f979
parent0d6c8d41ab7172a496c6db951c270821807dce99 (diff)
downloademacs-8bb68a522f3aad104b68ca4e479f4ccc3fc6cb03.tar.gz
emacs-8bb68a522f3aad104b68ca4e479f4ccc3fc6cb03.zip
Optionally align prompt to prefix in erc-fill-wrap
* lisp/erc/erc-fill.el (erc-fill-wrap-align-prompt): New option for aligning prompt with leading portion of messages at the common "static center" pivot-column barrier, so it appears "dedented" along with all speaker name tags. Tests for this functionality appear in the subsequent patch of this same change set. (erc-fill-wrap-use-pixels): Demote from user option to normal variable because it has no practical use other than for testing. Don't rename as internal variable to spare the improbable user of ERC on HEAD who's already customized this. (erc-fill-wrap-mode, erc-fill-wrap-enable, erc-fill-wrap-disable): Take care to disable prompt-in-left-margin behavior when option `erc-fill-wrap-align-prompt' is non-nil. (erc-fill--wrap-measure): Improve doc string and always attempt to leverage `buffer-text-pixel-size', even when the variable `erc-fill-wrap-use-pixels' is nil. (erc-fill--wrap-indent-prompt): New function to massage prompt `line-prefix' after updates, such as changes to away status. (Bug#51082)
-rw-r--r--lisp/erc/erc-fill.el47
1 files changed, 40 insertions, 7 deletions
diff --git a/lisp/erc/erc-fill.el b/lisp/erc/erc-fill.el
index e48d5540c86..50b5aefd27a 100644
--- a/lisp/erc/erc-fill.el
+++ b/lisp/erc/erc-fill.el
@@ -138,6 +138,11 @@ user-defined functions."
138 :package-version '(ERC . "5.6") 138 :package-version '(ERC . "5.6")
139 :type '(choice (const nil) (const left) (const right))) 139 :type '(choice (const nil) (const left) (const right)))
140 140
141(defcustom erc-fill-wrap-align-prompt nil
142 "Whether to align the prompt at the common `wrap-prefix'."
143 :package-version '(ERC . "5.6")
144 :type 'boolean)
145
141(defcustom erc-fill-line-spacing nil 146(defcustom erc-fill-line-spacing nil
142 "Extra space between messages on graphical displays. 147 "Extra space between messages on graphical displays.
143Its value should be larger than that of the variable 148Its value should be larger than that of the variable
@@ -223,13 +228,11 @@ You can put this on `erc-insert-modify-hook' and/or `erc-send-modify-hook'."
223(defvar-local erc-fill--wrap-value nil) 228(defvar-local erc-fill--wrap-value nil)
224(defvar-local erc-fill--wrap-visual-keys nil) 229(defvar-local erc-fill--wrap-visual-keys nil)
225 230
226(defcustom erc-fill-wrap-use-pixels t 231(defvar erc-fill-wrap-use-pixels t
227 "Whether to calculate padding in pixels when possible. 232 "Whether to calculate padding in pixels when possible.
228A value of nil means ERC should use columns, which may happen 233A value of nil means ERC should use columns, which may happen
229regardless, depending on the Emacs version. This option only 234regardless, depending on the Emacs version. This option only
230matters when `erc-fill-wrap-mode' is enabled." 235matters when `erc-fill-wrap-mode' is enabled.")
231 :package-version '(ERC . "5.6")
232 :type 'boolean)
233 236
234(defcustom erc-fill-wrap-visual-keys 'non-input 237(defcustom erc-fill-wrap-visual-keys 'non-input
235 "Whether to retain keys defined by `visual-line-mode'. 238 "Whether to retain keys defined by `visual-line-mode'.
@@ -448,6 +451,13 @@ is not recommended."
448 (or (eq erc-fill-wrap-margin-side 'left) 451 (or (eq erc-fill-wrap-margin-side 'left)
449 (eq (default-value 'erc-insert-timestamp-function) 452 (eq (default-value 'erc-insert-timestamp-function)
450 #'erc-insert-timestamp-left))) 453 #'erc-insert-timestamp-left)))
454 (when erc-fill-wrap-align-prompt
455 (add-hook 'erc--refresh-prompt-hook
456 #'erc-fill--wrap-indent-prompt nil t))
457 (when erc-stamp--margin-left-p
458 (if erc-fill-wrap-align-prompt
459 (setq erc-stamp--skip-left-margin-prompt-p t)
460 (setq erc--inhibit-prompt-display-property-p t)))
451 (setq erc-fill--function #'erc-fill-wrap) 461 (setq erc-fill--function #'erc-fill-wrap)
452 (when erc-fill-wrap-merge 462 (when erc-fill-wrap-merge
453 (add-hook 'erc-button--prev-next-predicate-functions 463 (add-hook 'erc-button--prev-next-predicate-functions
@@ -460,6 +470,9 @@ is not recommended."
460 (kill-local-variable 'erc-fill--function) 470 (kill-local-variable 'erc-fill--function)
461 (kill-local-variable 'erc-fill--wrap-visual-keys) 471 (kill-local-variable 'erc-fill--wrap-visual-keys)
462 (kill-local-variable 'erc-fill--wrap-last-msg) 472 (kill-local-variable 'erc-fill--wrap-last-msg)
473 (kill-local-variable 'erc--inhibit-prompt-display-property-p)
474 (remove-hook 'erc--refresh-prompt-hook
475 #'erc-fill--wrap-indent-prompt)
463 (remove-hook 'erc-button--prev-next-predicate-functions 476 (remove-hook 'erc-button--prev-next-predicate-functions
464 #'erc-fill--wrap-merged-button-p t)) 477 #'erc-fill--wrap-merged-button-p t))
465 'local) 478 'local)
@@ -515,15 +528,20 @@ sender as that of the previous \"PRIVMSG\"."
515 528
516(defun erc-fill--wrap-measure (beg end) 529(defun erc-fill--wrap-measure (beg end)
517 "Return display spec width for inserted region between BEG and END. 530 "Return display spec width for inserted region between BEG and END.
518Ignore any `invisible' props that may be present when figuring." 531Ignore any `invisible' props that may be present when figuring.
519 (if (and erc-fill-wrap-use-pixels (fboundp 'buffer-text-pixel-size)) 532Expect the target region to be free of `line-prefix' and
533`wrap-prefix' properties, and expect `display-line-numbers-mode'
534to be disabled."
535 (if (fboundp 'buffer-text-pixel-size)
520 ;; `buffer-text-pixel-size' can move point! 536 ;; `buffer-text-pixel-size' can move point!
521 (save-excursion 537 (save-excursion
522 (save-restriction 538 (save-restriction
523 (narrow-to-region beg end) 539 (narrow-to-region beg end)
524 (let* ((buffer-invisibility-spec) 540 (let* ((buffer-invisibility-spec)
525 (rv (car (buffer-text-pixel-size)))) 541 (rv (car (buffer-text-pixel-size))))
526 (if (zerop rv) 0 (list rv))))) 542 (if erc-fill-wrap-use-pixels
543 (if (zerop rv) 0 (list rv))
544 (/ rv (frame-char-width))))))
527 (- end beg))) 545 (- end beg)))
528 546
529;; An escape hatch for third-party code expecting speakers of ACTION 547;; An escape hatch for third-party code expecting speakers of ACTION
@@ -575,6 +593,21 @@ See `erc-fill-wrap-mode' for details."
575 'erc-fill--wrap-value)) 593 'erc-fill--wrap-value))
576 wrap-prefix (space :width erc-fill--wrap-value)))))) 594 wrap-prefix (space :width erc-fill--wrap-value))))))
577 595
596(defun erc-fill--wrap-indent-prompt ()
597 "Recompute the `line-prefix' of the prompt."
598 ;; Clear an existing `line-prefix' before measuring (bug#64971).
599 (remove-text-properties erc-insert-marker erc-input-marker
600 '(line-prefix nil wrap-prefix nil))
601 ;; Restoring window configuration seems to prevent unwanted
602 ;; recentering reminiscent of `scrolltobottom'-related woes.
603 (let ((c (and (get-buffer-window) (current-window-configuration)))
604 (len (erc-fill--wrap-measure erc-insert-marker erc-input-marker)))
605 (when c
606 (set-window-configuration c))
607 (put-text-property erc-insert-marker erc-input-marker
608 'line-prefix
609 `(space :width (- erc-fill--wrap-value ,len)))))
610
578(defvar erc-fill--wrap-rejigger-last-message nil 611(defvar erc-fill--wrap-rejigger-last-message nil
579 "Temporary working instance of `erc-fill--wrap-last-msg'.") 612 "Temporary working instance of `erc-fill--wrap-last-msg'.")
580 613