reddit / emacs

emacs 29 native smooth scrolling pixel-scroll-precision-mode

slk_g500 · 2022-08-25 07:49
Today I've build emacs from master: ./configure --with-pgtk --with-xwidgets --with-xinput2 Turned on pixel-scroll-precision-mode but as I understand by default it works only for mouse scroll? How could I turn on it for keyboard, moving cursor?
JosephFerano · 2022-08-26 08:02
Here's about 30 minutes worth of me messing about with whats in pixel-scroll.el. (require 'pixel-scroll) (setq pixel-scroll-precision-large-scroll-height 10.0) (setq pixel-scroll-precision-interpolation-factor 30) (defun joe/smooth-scroll-half-page-down () "Smooth scroll down" (interactive) (let ((half-height (/ (window-height) 2))) (pixel-scroll-precision-interpolate (* 5 (- half-height))))) (defun joe/smooth-scroll-half-page-up () "Smooth scroll down" (interactive) (let ((half-height (/ (window-height) 2))) (pixel-scroll-precision-interpolate (* 5 half-height)))) ;; scroll-up-command (global-set-key (kbd "C-v") #'joe/smooth-scroll-half-page-down) (global-set-key (kbd "M-v") #'joe/smooth-scroll-half-page-up) It doesn't work all that well, when you're at the very top or bottom, you have to do the scroll twice. Certainly hacky given my limited elisp skills. But it's a start.
arthurno1 · 2022-08-28 13:44
> It doesn't work all that well, when you're at the very top or bottom, you have to do the scroll twice. Here you have a fast and dirty hack to fix double scroll at the top and bottom (just detect top or bottom and scroll twice): (defun pixel-scroll-kbd-up () (interactive) (let ((half-height (/ (window-height) 2))) (unless (pos-visible-in-window-p (point-min)) (pixel-scroll-precision-interpolate (* 5 half-height))) (pixel-scroll-precision-interpolate (* 5 half-height)))) (defun pixel-scroll-kbd-down () (interactive) (let ((half-height (/ (window-height) 2))) (unless (pos-visible-in-window-p (point-max)) (pixel-scroll-precision-interpolate (* 5 (- half-height)))) (pixel-scroll-precision-interpolate (* 5 (- half-height))))) Sorry I took me freedom to rename the functions to smth slightly less verbose. > (global-set-key (kbd "C-v") #'joe/smooth-scroll-half-page-down) > (global-set-key (kbd "M-v") #'joe/smooth-scroll-half-page-up) I personally prefer to put those in pixel-scroll-precision-mode-map, so they are inactive if I for some reason turn off the pixel-scroll mode: (define-key pixel-scroll-precision-mode-map (kbd "M-p") #'pixel-scroll-kbd-up) (define-key pixel-scroll-precision-mode-map (kbd "M-n") #'pixel-scroll-kbd-down) (define-key pixel-scroll-precision-mode-map (kbd "M-S-p") #'pixel-scroll-interpolate-up) (define-key pixel-scroll-precision-mode-map (kbd "M-S-u") #'pixel-scroll-interpolate-down) > Certainly hacky Yes indeed. When I scroll through a file with several differently sized bigger images it is "jumpy" and not very smooth. But it is still better than popping in and out the entire image from the screen. Good work, thank you. I have tried a bit of different approach, similar to yours, just to scroll a certain amount. (defun pixel-scroll-kbd-up () (interactive) (pixel-scroll-precision-scroll-down-page 20)) (defun pixel-scroll-kbd-down () (interactive) (pixel-scroll-precision-scroll-up-page 20)) Works for me, but I think interpolating as you do is still nicer. The hard-coded value is just for the test, of course it should be put into some customize variable if someone is interested into that route. Both versions are not really in the sync with mouse scrolling, visually it is a bit distracting. It would be nice if we could scroll by keyboard visually similar to mouse wheel. So I tried the idea of programmatically create a mouse-wheel event and send it to Emacs to trick it was a mouse-wheel input. But I didn't get that one to work. If anyone knows how to get that one to work, I appreciate if you let me know. This is what I played with: (defun pixel-scroll-kbd-up () (interactive) (mwheel-scroll `(,mouse-wheel-up-event (,(selected-window) ,(point) ,(mouse-pixel-position) ,(current-time) nil ,(point) ,(mouse-position))))) (defun pixel-scroll-kbd-down () (interactive) (mwheel-scroll `(,mouse-wheel-down-event (,(selected-window) ,(point) ,(mouse-pixel-position) ,(current-time) nil ,(point) ,(mouse-position)))))