bug#32536: 24.3; Feature Request: change defaults or behaviour

classic Classic list List threaded Threaded
34 messages Options
12
Reply | Threaded
Open this post in threaded view
|

bug#32536: 24.3; Feature Request: change defaults or behaviour

hw-2
This is not bug report but a change or a feature request:

Please change the default behaviour of the (man) function or the default
value of Man-width to 75 such that manual pages are formatted to a
reasonable width by default.  The same goes for other manuals that are
being formatted before displayed.

Text is best read when it is displayed in about 70--80 characters per
line.  The size of the window the text is displayed in does not change
this.  It is reasonable to assume that users rather have manual pages
displayed with line lengths that make them easy to read than having them
displayed at about 300 characters per line when the window happens to be
full screen or 140 when they have two windows side by side.  When a user
needs wider text, they can still change the default.


As a feature request:

How about changing the effect of Man-width, or an additional setting:
Emacs could usefully format manual pages to fit the window when the
window is narrower than the default width of manual pages (unless the
window is ridiculously narrow, in which case it could fall back to the
default width for manual pages) and format them no wider than the
default width of manual pages for windows that are wider.  It could
also, depending on a(nother) setting(s), dynamically re-format the
manual pages to

min(
    (width_of_window <= ridiculously_narrow) ?
    max_width_of_manual_pages : width_of_window,
    max_width_of_manual_pages
   )

when the window is resized and had been less wide than the maximal width
for manual pages before.

The "max_width_of_manual_pages" could be a range, like 70 to 100,
because it may be desirable to use a couple more characters per line
when the width of the window allows it, without going crazy.  The
default for "ridiculously_narrow" might be like 60.  Of course, this
can all be changed by the user.

This feature might be cool for those who like dynamic (re-)formatting; I
don't think it's much needed.



In GNU Emacs 24.3.1 (x86_64-redhat-linux-gnu, GTK+ Version 3.22.10)
 of 2017-09-20 on c1bm.rdu2.centos.org
Configured using:
 `configure '--build=x86_64-redhat-linux-gnu'
 '--host=x86_64-redhat-linux-gnu' '--program-prefix='
 '--disable-dependency-tracking' '--prefix=/usr' '--exec-prefix=/usr'
 '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc'
 '--datadir=/usr/share' '--includedir=/usr/include'
 '--libdir=/usr/lib64' '--libexecdir=/usr/libexec'
 '--localstatedir=/var' '--sharedstatedir=/var/lib'
 '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--with-dbus'
 '--with-gif' '--with-jpeg' '--with-png' '--with-rsvg' '--with-tiff'
 '--with-xft' '--with-xpm' '--with-x-toolkit=gtk3' '--with-gpm=no'
 'build_alias=x86_64-redhat-linux-gnu'
 'host_alias=x86_64-redhat-linux-gnu' 'CFLAGS=-DMAIL_USE_LOCKF -O2 -g
 -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions
 -fstack-protector-strong --param=ssp-buffer-size=4
 -grecord-gcc-switches -m64 -mtune=generic' 'LDFLAGS=-Wl,-z,relro ''

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8
  default enable-multibyte-characters: t

Major mode: Org

Minor modes in effect:
  diff-auto-refine-mode: t
  shell-dirtrack-mode: t
  show-paren-mode: t
  desktop-save-mode: t
  tags-mode: t
  tooltip-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  size-indication-mode: t
  column-number-mode: t
  line-number-mode: t
  auto-fill-function: org-auto-fill-function
  transient-mark-mode: t

Recent input:
O A ESC O A ESC O A ESC O A ESC O A ESC O A ESC O A
ESC O A ESC O A ESC O A ESC O A ESC O A ESC O A ESC
O A ESC O A ESC O B ESC O C ESC O B ESC O C C-x b *
G r TAB RET L C-s C-s ESC O D RET ESC < ESC > ESC O
A ESC O A ESC O A ESC O A ESC O A ESC O A ESC O A ESC
O A ESC O A ESC O A ESC O A ESC O A ESC O A ESC O A
ESC O A ESC O A ESC O A ESC O A ESC O A ESC O A ESC
O A ESC O A ESC O A ESC O A ESC O A ESC O B ESC O B
ESC O B ESC O B ESC O B ESC O B ESC O B ESC O B ESC
O B ESC O B ESC O B ESC O B ESC O B ESC O B ESC O B
ESC O B ESC O B ESC O B ESC O B ESC O B ESC O B ESC
O B ESC O A ESC O A ESC O A ESC O A ESC O A ESC O A
ESC O A ESC O A ESC O A ESC O A ESC O A ESC O A ESC
O A ESC O A RET C-x b RET C-x 1 C-x b e d TAB RET C-s
d e b C-s C-s C-s C-s C-s C-s C-s C-s C-a C-s g n u
C-s C-s C-s C-s C-a ESC x r e p o r TAB RET

Recent messages:
SUBTREE (NO CHILDREN)
FOLDED
Mark saved where search started
No more unseen articles
No more unread articles
Mark set [2 times]
Mark saved where search started [2 times]

Load-path shadows:
None found.

Features:
(shadow emacsbug bookmark shr browse-url gnus-dired pp etags man
mule-util network-stream starttls url-http url-gw url-cache url-auth url
url-proxy url-privacy url-expand url-methods url-history url-cookie
url-domsuf url-util url-parse url-vars linum tabify org-table asm-mode
info diff-mode jka-compr gnus-draft debug shell gnus-dup misearch
multi-isearch help-mode hi-lock cperl-mode flyspell ispell sort
gnus-cite flow-fill mm-archive mail-extr gnus-async gnus-bcklg
parse-time qp gnus-ml disp-table utf-7 utf7 rfc2104 tls imap auth-source
eieio nndraft nnmh nnfolder nnml gnus-agent gnus-srvr gnus-score
score-mode nnvirtual gnus-msg gnus-cache gnus-demon nntp gnus-diary
gnus-art mm-uu mml2015 epg-config mm-view mml-smime smime password-cache
dig mailcap nndiary gnus-sum gnus-group gnus-undo nnmail mail-source
nnoo gnus-start gnus-spec gnus-int gnus-range gnus-win gnus gnus-ems
nnheader wid-edit rst compile conf-mode cc-langs cl cc-mode cc-fonts
cc-guess cc-menus cc-cmds cc-styles cc-align cc-engine cc-vars cc-defs
sh-script smie executable eldoc python rx vc-git org-wl org-w3m org-vm
org-rmail org-mhe org-mew org-irc org-jsinfo org-infojs org-html org-exp
ob-exp org-exp-blocks org-agenda org-info org-gnus gnus-util org-docview
org-bibtex bibtex org-bbdb org byte-opt warnings bytecomp byte-compile
cconv ob-tangle ob-ref ob-lob ob-table org-footnote org-src ob-comint
ob-keys org-pcomplete pcomplete comint ansi-color ring org-list
org-faces org-entities noutline outline easy-mmode org-version
ob-emacs-lisp ob org-compat org-macs ob-eval org-loaddefs find-func
cal-menu calendar cal-loaddefs message sendmail format-spec rfc822 mml
mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 rfc2047 rfc2045
ietf-drums mm-util mail-prsvr mailabbrev mail-utils gmm-utils mailheader
finder-inf package uniquify advice help-fns cl-lib advice-preload server
two-column edmacro kmacro time-date paren cus-start cus-load desktop
dired fvwm-mode easymenu lsl-mode tooltip ediff-hook vc-hooks
lisp-float-type mwheel x-win x-dnd tool-bar dnd fontset image regexp-opt
fringe tabulated-list newcomment lisp-mode register page menu-bar
rfn-eshadow timer select scroll-bar mouse jit-lock font-lock syntax
facemenu font-core frame cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese hebrew greek romanian slovak
czech european ethiopic indian cyrillic chinese case-table epa-hook
jka-cmpr-hook help simple abbrev minibuffer loaddefs button faces
cus-face macroexp files text-properties overlay sha1 md5 base64 format
env code-pages mule custom widget hashtable-print-readable backquote
make-network-process dbusbind dynamic-setting system-font-setting
font-render-setting move-toolbar gtk x-toolkit x multi-tty emacs)

--



Reply | Threaded
Open this post in threaded view
|

bug#32536: displayed width of man pages

Juri Linkov-2
> As a feature request:
>
> How about changing the effect of Man-width, or an additional setting:
> Emacs could usefully format manual pages to fit the window when the
> window is narrower than the default width of manual pages (unless the
> window is ridiculously narrow, in which case it could fall back to the
> default width for manual pages) and format them no wider than the
> default width of manual pages for windows that are wider.

Thanks for the feature request.

As proposed in https://debbugs.gnu.org/cgi/bugreport.cgi?bug=9385
this patch implements a new option "Maximum width" as a hard limit
that prevents the width to grow over this value:


diff --git a/lisp/man.el b/lisp/man.el
index 1a6eda13b7..fcf9085d20 100644
--- a/lisp/man.el
+++ b/lisp/man.el
@@ -179,6 +179,7 @@ Man-width
 The value also can be a positive integer for a fixed width."
   :type '(choice (const :tag "Window width" nil)
                  (const :tag "Frame width" t)
+                 (cons :tag "Maximum width" (const :value max) (integer :value 80))
                  (integer :tag "Fixed width" :value 65))
   :group 'man)
 
@@ -1045,16 +1046,20 @@ Man-start-calling
  (cond
   ((and (integerp Man-width) (> Man-width 0))
    Man-width)
-  (Man-width
+  ((eq Man-width t)
    (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
+  (if (window-live-p (get-buffer-window (current-buffer) t))
+      (with-selected-window (get-buffer-window (current-buffer) t)
+ (window-width))
+    (window-width))))
+     (if (eq (car-safe Man-width) 'max)
+ (min width (cdr Man-width))
+       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 | Threaded
Open this post in threaded view
|

bug#32536: displayed width of man pages

martin rudalics
 > As proposed in https://debbugs.gnu.org/cgi/bugreport.cgi?bug=9385
 > this patch implements a new option "Maximum width" as a hard limit
 > that prevents the width to grow over this value:

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'.

Thanks, martin



Reply | Threaded
Open this post in threaded view
|

bug#32536: displayed width of man pages

Juri Linkov-2
> 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.


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 | Threaded
Open this post in threaded view
|

bug#32536: displayed width of man pages

martin rudalics
 > 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).

It's called 'window-size-change-functions'.

 > Such window resize is necessary also for some other modes,

Why "Such window resize"?  We talk about reformatting buffer contents
when a window gets resized for some reason.  We do not want to resize
the window when reformatting a man page because we know the length of
Man lines beforehand.

 > 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.

This would be probably about fitting a window to the image it
displays.  But why do we have to display the image first and then
recalculate its size?  Don't we know the image size in advance?

martin



Reply | Threaded
Open this post in threaded view
|

bug#32536: displayed width of man pages

hw-2
In reply to this post by Juri Linkov-2
Juri Linkov <[hidden email]> writes:

> [...]
> 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).

Perhaps if they /can/ be reformatted dynamically, have a variable like
`Man-dynamic-reformat-lines-max' so users can prevent the reformatting
for instances in which it takes too long.  Then a problem is that the
number of lines varies with the width of the page, and instead of the
number of lines, the size in bytes (kB, MB ...) of the page might be
more relevant for reformatting it.

Unfortunately, users usually have no idea what the size of a manual page
in bytes is, and the pages are even stored compressed.  Users would have
to try out what size makes sense to dynamically reformat on their
particular hardware and may end up simply turning the feature off
because they do not resize windows while reading manual pages anyway.

Does it take longer to format the same manual page into 2500 lines or
into 5000 lines?

Would it be possible to do the reformatting in the background, and
delayed, like fontifying a buffer?



Reply | Threaded
Open this post in threaded view
|

bug#32536: displayed width of man pages

Juri Linkov-2
> Perhaps if they /can/ be reformatted dynamically, have a variable like
> `Man-dynamic-reformat-lines-max' so users can prevent the reformatting
> for instances in which it takes too long.  Then a problem is that the
> number of lines varies with the width of the page, and instead of the
> number of lines, the size in bytes (kB, MB ...) of the page might be
> more relevant for reformatting it.
>
> Unfortunately, users usually have no idea what the size of a manual page
> in bytes is, and the pages are even stored compressed.  Users would have
> to try out what size makes sense to dynamically reformat on their
> particular hardware and may end up simply turning the feature off
> because they do not resize windows while reading manual pages anyway.
>
> Does it take longer to format the same manual page into 2500 lines or
> into 5000 lines?
>
> Would it be possible to do the reformatting in the background, and
> delayed, like fontifying a buffer?

Man pages are already formatted asynchronously in the background,
so actually reformatting on window resize should be quite responsible
even for large manuals (maybe an addition flag is needed to prevent
updating when a previous update is in progress).

You can try and see how fast it reformats, typing repeatedly the key `u'
(Man-update-manpage).



Reply | Threaded
Open this post in threaded view
|

bug#32536: displayed width of man pages

Juri Linkov-2
In reply to this post by martin rudalics
>> 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).
>
> It's called 'window-size-change-functions'.

Thanks, I tried window-size-change-functions, and it works pretty well
with the patch attached.  But there are a few problems:

1. In Man-mode we have to add hook window-size-change-functions only
   buffer-locally (using the arg LOCAL of add-hook) rather than globally,
   because otherwise we can't remove this hook when a Man buffer is
   not displayed anymore.  But the problem is that buffer-local
   window-size-change-functions is called only when the current buffer
   is in Man-mode.  If it's not, it's not called even when resizing of
   the current non-Man buffer causes the resize of a Man-mode buffer
   in an adjacent window.

2. What if the same Man-mode buffer is displayed in two adjacent windows
   side-by-side?  I guess we need to find all windows with the same buffer,
   compare their widths, and call Man-update-manpage only in the window
   with minimal width.  Also it seems window-size-change-functions is
   not called twice for every window with Man-mode buffer, this is good.

3. When windows are resized using the mouse, is it possible to call
   window-size-change-functions only when the mouse button is released?
   This will increase responsiveness.  But the same problem will remain
   for keyboard resizing with e.g. C-x } } }
   A debounce-like function could help, but I can't find its Emacs Lisp
   implementation anywhere.   I mean something similar to
   https://stackoverflow.com/questions/15927371/what-does-debounce-do
   It's easy to implement using timers, but better to have idiomatic
   implementation.


diff --git a/lisp/man.el b/lisp/man.el
index 1a6eda13b7..f737594de7 100644
--- a/lisp/man.el
+++ b/lisp/man.el
@@ -1524,7 +1537,17 @@ Man-mode
   (set (make-local-variable 'outline-regexp) Man-heading-regexp)
   (set (make-local-variable 'outline-level) (lambda () 1))
   (set (make-local-variable 'bookmark-make-record-function)
-       'Man-bookmark-make-record))
+       'Man-bookmark-make-record)
+  (add-hook 'window-size-change-functions 'Man-window-size-change nil t))
+
+(defun Man-window-size-change (frame)
+  (walk-windows (lambda (window)
+                  (when (/= (window-pixel-width-before-size-change window)
+                            (window-pixel-width window))
+                    (with-current-buffer (window-buffer window)
+                      (when (derived-mode-p 'Man-mode)
+                        (Man-update-manpage)))))
+                'nomini frame))
 
 (defun Man-build-section-list ()
   "Build the list of manpage sections."
Reply | Threaded
Open this post in threaded view
|

bug#32536: displayed width of man pages

Juri Linkov-2
In reply to this post by martin rudalics
>> 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.
>
> This would be probably about fitting a window to the image it
> displays.  But why do we have to display the image first and then
> recalculate its size?  Don't we know the image size in advance?

Currently image-mode resizes the displayed image to fit into the window.
It can't do this when an image buffer is restored from the desktop file
and not yet displayed.



Reply | Threaded
Open this post in threaded view
|

bug#32536: displayed width of man pages

martin rudalics
In reply to this post by Juri Linkov-2
 > 1. In Man-mode we have to add hook window-size-change-functions only
 >     buffer-locally (using the arg LOCAL of add-hook) rather than globally,
 >     because otherwise we can't remove this hook when a Man buffer is
 >     not displayed anymore.

I can't follow you here.  Shouldn't we remove the hook _when_ a Man
buffer is not displayed anymore.  That is, when
'Man-window-size-change' detects that no Man buffer is displayed
anymore, remove it from 'window-size-change-functions' and re-add it
as soon as a Man buffer gets displayed again.

 >     But the problem is that buffer-local
 >     window-size-change-functions is called only when the current buffer
 >     is in Man-mode.  If it's not, it's not called even when resizing of
 >     the current non-Man buffer causes the resize of a Man-mode buffer
 >     in an adjacent window.
 >
 > 2. What if the same Man-mode buffer is displayed in two adjacent windows
 >     side-by-side?  I guess we need to find all windows with the same buffer,
 >     compare their widths, and call Man-update-manpage only in the window
 >     with minimal width.  Also it seems window-size-change-functions is
 >     not called twice for every window with Man-mode buffer, this is good.

I think 'Man-window-size-change' will have to take care of such cases.
Also we'll have to look into how 'follow-mode' works when displaying a
Man buffer in several side-by-side windows.

 > 3. When windows are resized using the mouse, is it possible to call
 >     window-size-change-functions only when the mouse button is released?
 >     This will increase responsiveness.  But the same problem will remain
 >     for keyboard resizing with e.g. C-x } } }
 >     A debounce-like function could help, but I can't find its Emacs Lisp
 >     implementation anywhere.   I mean something similar to
 >     https://stackoverflow.com/questions/15927371/what-does-debounce-do
 >     It's easy to implement using timers, but better to have idiomatic
 >     implementation.

I used a timer in 'mouse-autoselect-window'.  It might be interesting
to come up with a generic function.

martin



Reply | Threaded
Open this post in threaded view
|

bug#32536: displayed width of man pages

martin rudalics
In reply to this post by Juri Linkov-2
 > Currently image-mode resizes the displayed image to fit into the window.
 > It can't do this when an image buffer is restored from the desktop file
 > and not yet displayed.

You mean that after frameset has established a window/buffer
association there's no way to inform image-mode about that?

martin



Reply | Threaded
Open this post in threaded view
|

bug#32536: displayed width of man pages

Filipp Gunbin
In reply to this post by Juri Linkov-2
Hi,

On 02/09/2018 01:27 +0300, Juri Linkov wrote:

> +      (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))
                      ^^^^^^^^^^^^^^^^^^^^^^
                      this check is not needed, as you call min in the
                      next line

> +          (setq width (min width Man-width-max)))
> +        (setenv "COLUMNS" (number-to-string width))))



Reply | Threaded
Open this post in threaded view
|

bug#32536: displayed width of man pages

Juri Linkov-2
In reply to this post by martin rudalics
>> 1. In Man-mode we have to add hook window-size-change-functions only
>>     buffer-locally (using the arg LOCAL of add-hook) rather than globally,
>>     because otherwise we can't remove this hook when a Man buffer is
>>     not displayed anymore.
>
> I can't follow you here.  Shouldn't we remove the hook _when_ a Man
> buffer is not displayed anymore.  That is, when
> 'Man-window-size-change' detects that no Man buffer is displayed
> anymore, remove it from 'window-size-change-functions' and re-add it
> as soon as a Man buffer gets displayed again.

How to know the moment when a Man buffer gets displayed again?
Is there a corresponding hook for this event?



Reply | Threaded
Open this post in threaded view
|

bug#32536: displayed width of man pages

Juri Linkov-2
In reply to this post by martin rudalics
>> Currently image-mode resizes the displayed image to fit into the window.
>> It can't do this when an image buffer is restored from the desktop file
>> and not yet displayed.
>
> You mean that after frameset has established a window/buffer
> association there's no way to inform image-mode about that?

image-mode can fit the image to the window sizes only when
the image buffer is displayed in a window.  Is there a hook
that is called when a buffer is displayed in a window?



Reply | Threaded
Open this post in threaded view
|

bug#32536: displayed width of man pages

hw-2
In reply to this post by Juri Linkov-2
Juri Linkov <[hidden email]> writes:

>> Perhaps if they /can/ be reformatted dynamically, have a variable like
>> `Man-dynamic-reformat-lines-max' so users can prevent the reformatting
>> for instances in which it takes too long.
> [...]
>> Would it be possible to do the reformatting in the background, and
>> delayed, like fontifying a buffer?
>
> Man pages are already formatted asynchronously in the background,
> so actually reformatting on window resize should be quite responsible
> even for large manuals (maybe an addition flag is needed to prevent
> updating when a previous update is in progress).

and maybe something that prevents multiple update requests piling up
while the window is being resized, unless the flag already takes care of
that

> You can try and see how fast it reformats, typing repeatedly the key `u'
> (Man-update-manpage).

Ah, hm, ok, that's maybe 0.25 seconds for the man page of fvwm with 9441
lines.  It may not be a good test because the width does not change in
my case, and I have fast hardware.

Is there a reason for not to skip such an update when the length of the
lines did not change?

I didn't know you could update; this is like perfect because who prefers
dynamic updates can use those and who doesn't can use `u' if need be :)



Reply | Threaded
Open this post in threaded view
|

bug#32536: displayed width of man pages

hw-2
In reply to this post by Juri Linkov-2
Juri Linkov <[hidden email]> writes:

>>> 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).
>>
>> It's called 'window-size-change-functions'.
>
> Thanks, I tried window-size-change-functions, and it works pretty well
> with the patch attached.  But there are a few problems:
>
> 1. In Man-mode we have to add hook window-size-change-functions only
> [...]
>
> 2. What if the same Man-mode buffer is displayed in two adjacent windows
>    side-by-side?  I guess we need to find all windows with the same buffer,
>    compare their widths, and call Man-update-manpage only in the window
>    with minimal width.  Also it seems window-size-change-functions is
>    not called twice for every window with Man-mode buffer, this is good.

How about a couple rules to make this simple:


A manual page should not be updated when


+ the size, or a change of the size, of a window displaying it does not
  require a change of the length of the lines

+ the desired length of the lines can not be determined.


Creating another window to display the same or a different buffer does
not require a change of the length of the lines.

Using multiple windows of different widths to display the same buffer
means that the desired length of the lines can not be determined.

When considering the width of each window displaying the same buffer, or
any buffer, leads to the same length of the lines, a length has been
determined.  This may be the desired length of the lines for Man-mode
buffers or not.


Above rules mean that you can ignore 1..

Just note this in the documentation so it becomes understandable why the
buffers in Man-mode are dynamically updated the way they are.  When
someone has a good idea how to figure out the desired length of lines
under all circumstances, they can always make a suggestion.

BTW, what is the default for the minimum length of the lines?  Is the
default for the maximum length the same?



Reply | Threaded
Open this post in threaded view
|

bug#32536: displayed width of man pages

martin rudalics
In reply to this post by Juri Linkov-2
 >> I can't follow you here.  Shouldn't we remove the hook _when_ a Man
 >> buffer is not displayed anymore.  That is, when
 >> 'Man-window-size-change' detects that no Man buffer is displayed
 >> anymore, remove it from 'window-size-change-functions' and re-add it
 >> as soon as a Man buffer gets displayed again.
 >
 > How to know the moment when a Man buffer gets displayed again?
 > Is there a corresponding hook for this event?

'window-configuration-change-hook' I presume.  Though this raises the
question how to remove anything from there when finishing browsing.

martin



Reply | Threaded
Open this post in threaded view
|

bug#32536: displayed width of man pages

martin rudalics
In reply to this post by Juri Linkov-2
 > image-mode can fit the image to the window sizes only when
 > the image buffer is displayed in a window.  Is there a hook
 > that is called when a buffer is displayed in a window?

'window-configuration-change-hook' traces the case where a different
buffer is displayed in a window.

martin



Reply | Threaded
Open this post in threaded view
|

bug#32536: displayed width of man pages

Juri Linkov-2
In reply to this post by hw-2
> BTW, what is the default for the minimum length of the lines?  Is the
> default for the maximum length the same?

Like the new Man-width-max, we could also add Man-width-min as well.



Reply | Threaded
Open this post in threaded view
|

bug#32536: displayed width of man pages

Juri Linkov-2
In reply to this post by martin rudalics
>>> I can't follow you here.  Shouldn't we remove the hook _when_ a Man
>>> buffer is not displayed anymore.  That is, when
>>> 'Man-window-size-change' detects that no Man buffer is displayed
>>> anymore, remove it from 'window-size-change-functions' and re-add it
>>> as soon as a Man buffer gets displayed again.
>>
>> How to know the moment when a Man buffer gets displayed again?
>> Is there a corresponding hook for this event?
>
> 'window-configuration-change-hook' I presume.  Though this raises the
> question how to remove anything from there when finishing browsing.

Using window-configuration-change-hook is a hugely cumbersome workaround
for deficiencies in window-size-change-functions.

I reported this in bug#32637, please see there.



12