emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] org-agenda: Use `window-max-chars-per-line' instead of `window-w


From: Ihor Radchenko
Subject: [PATCH] org-agenda: Use `window-max-chars-per-line' instead of `window-width'
Date: Thu, 21 Apr 2022 13:25:18 +0800

"N. Jackson" <nljlistbox2@gmail.com> writes:

> No, I'm not saying Org shouldn't use window-max-chars-per-line --
> rather the opposite in fact. I'm just saying it maybe needs to be
> thought about carefully first.

Indeed. There is no point using w-m-c-p-l when we actually need the full
window size with fringes.

> If it works as advertised it would seem to be the right choice as
> long as Emacs bug #19395 exists (which looks like it will be
> forever). My reservations about the function are only that its spec
> is more ambitious than that of window-width (because it handles
> faces) and the added complexity might potentially introduce more
> corner cases where it doesn't work. But perhaps that's just the
> paranoia of someone who thinks that text editors should restrict
> themselves to monospaced fonts!

There is at least one workaround in org-agenda trying to account for the
face width. w-m-c-p-l should do better than that.

Attaching the patch.

Best,
Ihor

>From 5de3de87872ddae994f5b68eba74d915d5f73201 Mon Sep 17 00:00:00 2001
Message-Id: 
<5de3de87872ddae994f5b68eba74d915d5f73201.1650518543.git.yantar92@gmail.com>
From: Ihor Radchenko <yantar92@gmail.com>
Date: Thu, 21 Apr 2022 13:18:39 +0800
Subject: [PATCH] org-agenda: Use `window-max-chars-per-line' instead of
 `window-width'

* lisp/org-agenda.el (org-agenda-prepare):
(org-todo-list):
(org-agenda-show-new-time): Calculate the maximum number of chars
fitting into window via `window-max-chars-per-line' instead of
`window-with'.  The latter can return larger number when fringes are
disabled [1].

[1] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19395

Reported in https://orgmode.org/list/87czhdqi9p.fsf_-_@moondust.localdomain
---
 lisp/org-agenda.el | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index a09b53563..9ddee81ee 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -3925,7 +3925,7 @@ (defun org-agenda-prepare (&optional name)
              (insert "\n"
                      (if (stringp org-agenda-block-separator)
                          org-agenda-block-separator
-                       (make-string (window-width) org-agenda-block-separator))
+                       (make-string (window-max-chars-per-line) 
org-agenda-block-separator))
                      "\n"))
            (narrow-to-region (point) (point-max)))
        (setq org-done-keywords-for-agenda nil)
@@ -4944,7 +4944,7 @@ (defun org-todo-list (&optional arg)
            (let ((n 0))
               (dolist (k kwds)
                 (let ((s (format "(%d)%s" (cl-incf n) k)))
-                  (when (> (+ (current-column) (string-width s) 1) 
(window-width))
+                  (when (> (+ (current-column) (string-width s) 1) 
(window-max-chars-per-line))
                     (insert "\n                     "))
                   (insert " " s))))
            (insert "\n"))
@@ -10301,10 +10301,7 @@ (defun org-agenda-show-new-time (marker stamp 
&optional prefix)
                                  (line-end-position)
                                  '(display nil))
          (org-move-to-column
-           (- (if (fboundp 'window-font-width)
-                  (/ (window-width nil t) (window-font-width))
-                ;; Fall back to pre-9.3.3 behavior on Emacs <25.
-                (window-width))
+           (- (window-max-chars-per-line)
               (length stamp))
            t)
           (add-text-properties
-- 
2.35.1


reply via email to

[Prev in Thread] Current Thread [Next in Thread]