emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "N. Jackson" <nljlistbox2@gmail.com>
To: Ihor Radchenko <yantar92@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH v2] org-agenda: Use `window-max-chars-per-line' to calculate max text width
Date: Fri, 22 Apr 2022 04:42:54 -0400	[thread overview]
Message-ID: <87czh9ecfl.fsf@moondust.localdomain> (raw)
In-Reply-To: <875yn1u0at.fsf@localhost> (Ihor Radchenko's message of "Fri, 22 Apr 2022 13:58:18 +0800")

At 13:58 +0800 on Friday 2022-04-22, Ihor Radchenko wrote:
>
> Attaching the updated patch.

> @@ -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)

The fboundp version guard on window-font-width was added to Org recently:

  commit 94837fc6b5ca204962f3ed992e30cd998d66a9fe
  Author: Kyle Meyer <kyle@kyleam.com>
  Date:   Sat May 1 15:48:11 2021 -0400

      agenda: Fix org-agenda-show-new-time on Emacs 24

      * lisp/org-agenda.el (org-agenda-show-new-time): Add fallback for when
      window-font-width isn't available.

      efbf96389 (org-agenda.el: Fix display of agenda new time, 2020-02-02)
      reworked the column calculation to use window-font-width, but that
      function isn't available until Emacs 25, and it's definition can't be
      easily ported to org-compat.

      Instead just use the old logic, which had been in place since v8.2.6,
      when window-font-width isn't available.

      Reported-by: Ihor Radchenko <yantar92@gmail.com>
      Link: https://orgmode.org/list/87y2d2mqik.fsf@localhost

If Org needs to support versions of Emacs before 25.1 then I assume
you need the same guard on every instance of
window-max-chars-per-line -- because window-max-chars-per-line was
added to Emacs at the same time as window-font-width:

  commit 4a50af936e24b5f71df4079beb6dde82ed1955c2
  Author: Titus von der Malsburg <malsburg@posteo.de>
  Date:   Sat Mar 21 12:31:29 2015 +0200

      Add new functions for computing default font dimensions

       lisp/window.el (window-font-width, window-font-height)
       (window-max-chars-per-line): New functions.
       lisp/simple.el (default-font-height): Doc fix.
       (default-font-width): New function.

       etc/NEWS: Mention `default-font-width', `window-font-height',
       `window-font-width', and `window-max-chars-per-line'.

[These functions were new in Emacs 25.1:

  $ cat etc/NEWS.25 | grep -C 5  window-max-chars-per-line
  *** New functions 'window-font-height' and 'window-font-width' return
  the height and average width of characters in a specified face and
  window.  If FACE is remapped (see 'face-remapping-alist'), the
  function returns the information for the remapped face.

  *** A new function 'window-max-chars-per-line' returns the maximal
  number of characters that can be displayed on one line.  If a face
  and/or window are provided, these values are used for the
  calculation.  This function is different from 'window-body-width' in
  that it accounts for (i) continuation glyphs, (ii) the size of the
  font, and (iii) the specified window.
]


Perhaps this calls for a new wrapper function in Org, an
org--window-max-chars-per-line that wraps window-max-chars-per-line
in an fboundp and falls back to window-width -- rather than clutter
up the code with the fboundp guard.

Regards,
N.



  reply	other threads:[~2022-04-22  8:59 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-18 13:10 [BUG] Off-by-one error in width of Agenda window? [9.5.2 (release_9.5.2-25-gaf6f12 @ /data/installs/snapshots/emacs-28.1/lisp/org/)] N. Jackson
2022-04-18 13:39 ` Ihor Radchenko
2022-04-18 19:06   ` N. Jackson
2022-04-19  3:16     ` Ihor Radchenko
2022-04-19 14:06       ` [BUG] Off-by-one error in width of Agenda window? N. Jackson
2022-04-20  4:01         ` Ihor Radchenko
2022-04-20 10:07           ` N. Jackson
2022-04-21  5:25             ` [PATCH] org-agenda: Use `window-max-chars-per-line' instead of `window-width' Ihor Radchenko
2022-04-21  7:16               ` N. Jackson
2022-04-21  7:56                 ` N. Jackson
2022-04-22  5:58                   ` [PATCH v2] org-agenda: Use `window-max-chars-per-line' to calculate max text width Ihor Radchenko
2022-04-22  8:42                     ` N. Jackson [this message]
2022-04-22  9:27                       ` Ihor Radchenko
2022-04-22 15:46                         ` N. Jackson
2022-04-24  7:04                           ` Ihor Radchenko
2022-04-24 11:55                             ` Thank you " N. Jackson
2022-04-18 14:30 ` [BUG] Off-by-one error in width of Agenda window? [9.5.2 (release_9.5.2-25-gaf6f12 @ /data/installs/snapshots/emacs-28.1/lisp/org/)] Tory S. Anderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87czh9ecfl.fsf@moondust.localdomain \
    --to=nljlistbox2@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=yantar92@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).