all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: martin rudalics <rudalics@gmx.at>
Cc: hw <hw@adminart.net>, 32536@debbugs.gnu.org
Subject: bug#32536: displayed width of man pages
Date: Sun, 02 Sep 2018 01:27:20 +0300	[thread overview]
Message-ID: <87d0twam5z.fsf@mail.linkov.net> (raw)
In-Reply-To: <5B88E62F.20504@gmx.at> (martin rudalics's message of "Fri, 31 Aug 2018 08:54:39 +0200")

[-- Attachment #1: Type: text/plain, Size: 1675 bytes --]

> While you're there could you please do some idiomatic changes that
> avoid selecting a window in order to calculate its width:
>
> For example, replace
>
> (let ((width
>        (if (window-live-p (get-buffer-window (current-buffer) t))
> 	   (with-selected-window (get-buffer-window (current-buffer) t)
> 	     (window-width))
> 	 (window-width)))))
>
> with something like
>
> (window-width (get-buffer-window nil t))
>
> and
>
> (if (window-live-p (get-buffer-window (current-buffer) t))
>     (with-selected-window (get-buffer-window (current-buffer) t)
>       (frame-width))
>   (frame-width))
>
> with something like
>
> (let ((window (get-buffer-window nil t)))
>   (frame-width (and window (window-frame window))))
>
> Probably you also want to add a version tag for 'Man-width'.

Right, fixed in the next patch where a version tag is added not to
`Man-width', but to the new customizable variable `Man-width-max'.
This is better since like when man-pages are formatted in their
web versions they limit the width using the CSS property `max-width',
so like CSS has both `width' and `max-width', man.el will have
`Man-width' and `Man-width-max'.

Regarding the request for dynamic reformatting, I'm not sure if
man pages should be reformatted on resizing windows (I remember
seeing a window resize hook, but can't find it now).

Such window resize is necessary also for some other modes,
for example, when a visited image is saved to the desktop file,
it has a wrong size after loading the desktop, because the
image size is calculated when the image file is not yet displayed
in a window.  The image size should be recalculated after
displaying the image buffer.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: man-maximum-width.2.patch --]
[-- Type: text/x-diff, Size: 2625 bytes --]

diff --git a/lisp/man.el b/lisp/man.el
index 1a6eda13b7..08a913b119 100644
--- a/lisp/man.el
+++ b/lisp/man.el
@@ -182,6 +182,20 @@ Man-width
                  (integer :tag "Fixed width" :value 65))
   :group 'man)
 
+(defcustom Man-width-max nil
+  "Maximum number of columns allowed for the width of manual pages.
+It defines the maximum width for the case when `Man-width' is customized
+to a dynamically calculated value depending on the frame/window width.
+If the width calculated for `Man-width' is larger than the maximum width,
+it will be automatically reduced to the width defined by this variable.
+If the calculated width is smaller than the maximum width, the value
+of this variable has no effect.
+When nil, there is no limit on maximum width."
+  :type '(choice (const :tag "No limit" nil)
+                 (integer :tag "Max width" :value 80))
+  :version "27.1"
+  :group 'man)
+
 (defcustom Man-frame-parameters nil
   "Frame parameter list for creating a new frame for a manual page."
   :type '(repeat (cons :format "%v"
@@ -1041,20 +1055,19 @@ Man-start-calling
 	      (not (or (getenv "MANWIDTH") (getenv "COLUMNS"))))
       ;; Since the page buffer is displayed beforehand,
       ;; we can select its window and get the window/frame width.
-      (setenv "COLUMNS" (number-to-string
-			 (cond
-			  ((and (integerp Man-width) (> Man-width 0))
-			   Man-width)
-			  (Man-width
-			   (if (window-live-p (get-buffer-window (current-buffer) t))
-			       (with-selected-window (get-buffer-window (current-buffer) t)
-				 (frame-width))
-			     (frame-width)))
-			  (t
-			   (if (window-live-p (get-buffer-window (current-buffer) t))
-			       (with-selected-window (get-buffer-window (current-buffer) t)
-				 (window-width))
-			     (window-width)))))))
+      (let ((width (cond
+                    ((and (integerp Man-width) (> Man-width 0))
+                     Man-width)
+                    (Man-width
+                     (let ((window (get-buffer-window nil t)))
+                       (frame-width (and window (window-frame window)))))
+                    (t
+                     (window-width (get-buffer-window nil t))))))
+        (when (and (integerp Man-width-max)
+                   (> Man-width-max 0)
+                   (> width Man-width-max))
+          (setq width (min width Man-width-max)))
+        (setenv "COLUMNS" (number-to-string width))))
     ;; Since man-db 2.4.3-1, man writes plain text with no escape
     ;; sequences when stdout is not a tty.	In 2.5.0, the following
     ;; env-var was added to allow control of this (see Debian Bug#340673).

  reply	other threads:[~2018-09-01 22:27 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-26 12:42 bug#32536: 24.3; Feature Request: change defaults or behaviour hw
2018-08-30 23:35 ` bug#32536: displayed width of man pages Juri Linkov
2018-08-31  6:54   ` martin rudalics
2018-09-01 22:27     ` Juri Linkov [this message]
2018-09-02  7:14       ` martin rudalics
2018-09-02 22:19         ` Juri Linkov
2018-09-03  7:31           ` martin rudalics
2018-09-03 22:23             ` Juri Linkov
2018-09-04  7:51               ` martin rudalics
2018-09-04 21:27                 ` Juri Linkov
2018-09-05  7:47                   ` martin rudalics
2018-11-25 20:42                   ` Juri Linkov
2018-11-26  9:32                     ` martin rudalics
2018-11-27  0:01                       ` Juri Linkov
2018-11-27  8:08                         ` martin rudalics
2018-11-27 23:58                           ` Juri Linkov
2018-09-04  5:46           ` hw
2018-09-04 21:20             ` Juri Linkov
2018-09-05  2:50               ` hw
2018-09-05 22:20                 ` Juri Linkov
2018-09-07 14:03                   ` hw
2018-09-02 22:30         ` Juri Linkov
2018-09-03  7:31           ` martin rudalics
2018-09-03 22:25             ` Juri Linkov
2018-09-04  7:51               ` martin rudalics
2018-09-02 14:55       ` hw
2018-09-02 22:12         ` Juri Linkov
2018-09-04  3:34           ` hw
2018-09-03 18:20       ` Filipp Gunbin
2018-12-26 23:36 ` Juri Linkov
2018-12-27 15:46   ` Eli Zaretskii
2018-12-27 20:54     ` Juri Linkov
2018-12-28  4:50       ` Eli Zaretskii
2019-12-07 22:37         ` Juri Linkov

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

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

  git send-email \
    --in-reply-to=87d0twam5z.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=32536@debbugs.gnu.org \
    --cc=hw@adminart.net \
    --cc=rudalics@gmx.at \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.