all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Andrea Greselin <greselin.andrea@gmail.com>
To: 57179@debbugs.gnu.org
Subject: bug#57179: 29.0.50: 'wrong-number-of-arguments' for function of two arguments called from 'window-scroll-functions'
Date: Sat, 13 Aug 2022 18:17:54 +0200	[thread overview]
Message-ID: <CAJ_oJbbKd19f0Lj2MSpdct9k3JpJaaHZYaUvbDhkdZG+fJ3mXg@mail.gmail.com> (raw)

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

Hi all,
I have this function (the part at issue here should be the first
line):

    (defun my-recenter-after-jump (window _window-start-after)
      "Recenter the point after a non-scroll command brings it out of view.
    This function is meant to be called from the hook
    ‘window-scroll-functions’."
      (with-selected-window window
        (unless (or (> 0.001 (float-time (time-subtract (current-time)
buffer-display-time))) ; Don’t run this function after a change of buffer.
Non-nil here means the selected window displayed the current buffer less
than a thousandth of a second ago, so it was most likely a change of buffer
that triggered ‘window-scroll-functions’, not a scroll. See also
https://emacs.stackexchange.com/questions/63558/how-to-distinguish-a-scroll-from-a-change-of-buffer-in-a-function-called-from-w
                    ;; Don’t recenter for these
                    ;;   - major modes
                    (memq major-mode '(help-mode ;
           ‘my-recenter-after-jump’ breaks scrolling with SPC/<backspace>
in Help mode and Info mode because they don’t obey
‘scroll-preserve-screen-position’ and ‘scroll-error-top-bottom’.
                                       Info-mode))
                    ;;   - minor modes
                    isearch-mode ;
           For Isearch, change the value of ‘scroll-conservatively’ and
‘hscroll-step’ in ‘isearch-update-post-hook’ and ‘isearch-mode-end-hook’.
Doing so allows recentering the point even after a purely horizontal scroll.
                    (bound-and-true-p view-mode) ;
           ‘my-recenter-after-jump’ breaks scrolling with SPC/<backspace>
in View mode because View mode doesn’t obey
‘scroll-preserve-screen-position’ and ‘scroll-error-top-bottom’.
                    (bound-and-true-p follow-mode)
                    ;;   - commands
                    (and (symbolp last-command) (get last-command
'scroll-command)) ; Don’t check the value of the ‘scroll-command’ property
for anonymous commands (it can’t be t anyway).
                    (memq last-command '(recenter-top-bottom
                                         query-replace query-replace-regexp
;         Query replacement is taken care of by the ‘recentering-on-jump’
advice to ‘perform-replace’, which allows recentering the point after a
purely horizontal scroll.
                                         previous-line next-line ;
           Don’t let these commands trigger ‘my-recenter-after-jump’. It
happens when Emacs has a moment of lag during which the point slips beyond
the scroll margin.
                                         previous-logical-line
next-logical-line)))
          (let* ((bottom-line-before (line-number-at-pos (window-end)))
                 (bottom-line-after (line-number-at-pos (window-end nil
'update))) ; NB: ‘window-start’ doesn’t take the ‘update’ argument.
                 (vertical-displacement (- bottom-line-after
bottom-line-before)))
            (unless (> 2 (abs vertical-displacement)) ; The purpose of
having the first ‘unless’ separate from this one is to call
‘line-number-at-pos’ only when it’s needed, because it can be slow. See (2
links)
https://emacs.stackexchange.com/questions/51648/how-to-detect-the-number-of-lines-scrolled-from-scroll-up-down/51664#51664,
https://emacs.stackexchange.com/questions/3821/a-faster-method-to-obtain-line-number-at-pos-in-large-buffers
              (recenter)
              (when truncate-lines
                (my-horizontal-recenter))))))) ; REVIEW: Isn’t there a
built-in function for recentering the point horizontally?

which I call from `window-scroll-functions` like this

    (add-hook 'window-scroll-functions #'my-recenter-after-jump)


It's worked until I upgraded from v. 28.1 (from Fedora’s repos) to
29.0.50 (commit 6de88b6b02). Now I get

    Error in window-scroll-functions (my-recenter-after-jump):
(wrong-number-of-arguments (lambda (window _window-start-after) "Recenter
the point after a non-scroll command brings it out of view.
    This function is meant to be called from the hook
    ‘window-scroll-functions’." (let ((save-selected-window--state
(internal--before-with-selected-window window))) (save-current-buffer
(unwind-protect (progn (select-window (car save-selected-window--state)
'norecord) (if (or (> 0.001 (float-time (time-subtract (current-time)
buffer-display-time))) (memq major-mode '(help-mode Info-mode))
isearch-mode (and (boundp 'view-mode) view-mode) (and (boundp 'follow-mode)
follow-mode) (and (symbolp last-command) (get last-command
'scroll-command)) (memq last-command '(recenter-top-bottom query-replace
query-replace-regexp previous-line next-line previous-logical-line
next-logical-line))) nil (let* ((bottom-line-before (line-number-at-pos
(window-end))) (bottom-line-after (line-number-at-pos (window-end nil
'update))) (vertical-displacement (- bottom-line-after
bottom-line-before))) (if (> 2 (abs vertical-displacement)) nil (recenter)
(if truncate-lines (progn (my-horizontal-recenter)))))))
(internal--after-with-selected-window save-selected-window--state))))) 0)

All the best,
Andrea

[-- Attachment #2: Type: text/html, Size: 6326 bytes --]

             reply	other threads:[~2022-08-13 16:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-13 16:17 Andrea Greselin [this message]
2022-08-13 17:30 ` bug#57179: 29.0.50: 'wrong-number-of-arguments' for function of two arguments called from 'window-scroll-functions' Eli Zaretskii
2022-08-13 20:50   ` Michael Heerdegen
2022-08-14  0:19     ` Michael Heerdegen
2022-08-14  7:18       ` Eli Zaretskii
2022-08-14 13:22       ` Alan Mackenzie
2022-08-14 23:00         ` Michael Heerdegen
2022-08-15  9:42         ` Andrea Greselin
2022-08-15 12:24     ` Alan Mackenzie
2022-08-13 23:07   ` Andrea Greselin

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=CAJ_oJbbKd19f0Lj2MSpdct9k3JpJaaHZYaUvbDhkdZG+fJ3mXg@mail.gmail.com \
    --to=greselin.andrea@gmail.com \
    --cc=57179@debbugs.gnu.org \
    /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.